summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-09-08 13:03:44 +0200
committerErik Larkö <erik@mullvad.net>2017-09-13 07:32:26 +0200
commit6d724d021fb14a9885284c302fdbc9718b0338f9 (patch)
treea964b832c613e05ea4c117759878fbff4695f75a /mullvad-cli/src
parent4bc6b031bd7bd29d5bc084f07bd6096d205dc7d4 (diff)
downloadmullvadvpn-6d724d021fb14a9885284c302fdbc9718b0338f9.tar.xz
mullvadvpn-6d724d021fb14a9885284c302fdbc9718b0338f9.zip
Set custom relay in cli
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/cmds/custom_relay.rs62
-rw-r--r--mullvad-cli/src/cmds/mod.rs4
-rw-r--r--mullvad-cli/src/main.rs1
3 files changed, 67 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/custom_relay.rs b/mullvad-cli/src/cmds/custom_relay.rs
new file mode 100644
index 0000000000..2272f3b7c2
--- /dev/null
+++ b/mullvad-cli/src/cmds/custom_relay.rs
@@ -0,0 +1,62 @@
+pub struct CustomRelay;
+
+use Command;
+use Result;
+use clap;
+use mullvad_types::relay_endpoint::RelayEndpoint;
+
+use rpc;
+
+use talpid_types::net::TransportProtocol;
+
+impl Command for CustomRelay {
+ fn name(&self) -> &'static str {
+ "relay"
+ }
+
+ fn clap_subcommand(&self) -> clap::App<'static, 'static> {
+ clap::SubCommand::with_name(self.name())
+ .about("Set a custom remote relay to connect to")
+ .setting(clap::AppSettings::SubcommandRequired)
+ .subcommand(clap::SubCommand::with_name("set")
+ .about("Set a custom remote relay")
+ .arg(clap::Arg::with_name("host")
+ .help("The host name or IP of the remote relay")
+ .required(true))
+ .arg(clap::Arg::with_name("port")
+ .help("The port of the remote relay")
+ .required(true))
+ .arg(clap::Arg::with_name("protocol")
+ .help("The transport protocol. UDP is recommended as it usually results in higher throughput that TCP")
+ .possible_values(&["udp", "tcp"])
+ .default_value("udp")))
+ }
+
+ fn run(&self, matches: &clap::ArgMatches) -> Result<()> {
+ if let Some(set_matches) = matches.subcommand_matches("set") {
+ let host = value_t_or_exit!(set_matches.value_of("host"), String);
+ let port = value_t_or_exit!(set_matches.value_of("port"), u16);
+ let protocol = value_t_or_exit!(set_matches.value_of("protocol"), TransportProtocol);
+
+ self.set(host, port, protocol)
+ } else {
+ unreachable!("No sub command given");
+ }
+ }
+}
+
+impl CustomRelay {
+ fn set(&self, host: String, port: u16, protocol: TransportProtocol) -> Result<()> {
+ let relay_endpoint = RelayEndpoint {
+ host,
+ port,
+ protocol,
+ };
+
+ rpc::call(
+ "set_custom_relay",
+ &[relay_endpoint],
+ )
+ .map(|_: Option<()>| println!("Custom remote relay set"))
+ }
+}
diff --git a/mullvad-cli/src/cmds/mod.rs b/mullvad-cli/src/cmds/mod.rs
index c621c0840a..8061344b96 100644
--- a/mullvad-cli/src/cmds/mod.rs
+++ b/mullvad-cli/src/cmds/mod.rs
@@ -13,6 +13,9 @@ pub use self::connect::Connect;
mod disconnect;
pub use self::disconnect::Disconnect;
+mod custom_relay;
+pub use self::custom_relay::CustomRelay;
+
/// Returns a map of all available subcommands with their name as key.
pub fn get_commands() -> HashMap<&'static str, Box<Command>> {
let commands: Vec<Box<Command>> = vec![
@@ -20,6 +23,7 @@ pub fn get_commands() -> HashMap<&'static str, Box<Command>> {
Box::new(Status),
Box::new(Connect),
Box::new(Disconnect),
+ Box::new(CustomRelay),
];
let mut map = HashMap::new();
for cmd in commands {
diff --git a/mullvad-cli/src/main.rs b/mullvad-cli/src/main.rs
index 745d2aea34..8543f7eecb 100644
--- a/mullvad-cli/src/main.rs
+++ b/mullvad-cli/src/main.rs
@@ -10,6 +10,7 @@
#![recursion_limit = "1024"]
extern crate mullvad_types;
+extern crate talpid_types;
extern crate talpid_ipc;
#[macro_use]
extern crate clap;