diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-09-13 07:33:30 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-09-13 07:33:30 +0200 |
| commit | b572d0634b78d3de05ce39e5a49ce893c8065d6b (patch) | |
| tree | 9e955cb2ab5499eb97a76e9c4d22a384fae9b42b /mullvad-cli/src | |
| parent | 2bc13231538133ad452b1b72ac4bbfe67235df02 (diff) | |
| parent | c383938bf44bb0b045ec63871a4bb804921fb2db (diff) | |
| download | mullvadvpn-b572d0634b78d3de05ce39e5a49ce893c8065d6b.tar.xz mullvadvpn-b572d0634b78d3de05ce39e5a49ce893c8065d6b.zip | |
Merge branch 'set_custom_relay-endpoint'
Diffstat (limited to 'mullvad-cli/src')
| -rw-r--r-- | mullvad-cli/src/cmds/account.rs | 3 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/custom_relay.rs | 74 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/mod.rs | 4 | ||||
| -rw-r--r-- | mullvad-cli/src/main.rs | 1 |
4 files changed, 80 insertions, 2 deletions
diff --git a/mullvad-cli/src/cmds/account.rs b/mullvad-cli/src/cmds/account.rs index 553458e11a..f7cb106fc3 100644 --- a/mullvad-cli/src/cmds/account.rs +++ b/mullvad-cli/src/cmds/account.rs @@ -1,5 +1,4 @@ -use Command; -use Result; +use {Command, Result}; use clap; use mullvad_types::account::{AccountData, AccountToken}; diff --git a/mullvad-cli/src/cmds/custom_relay.rs b/mullvad-cli/src/cmds/custom_relay.rs new file mode 100644 index 0000000000..ab9a148fb3 --- /dev/null +++ b/mullvad-cli/src/cmds/custom_relay.rs @@ -0,0 +1,74 @@ +pub struct CustomRelay; + +use {Command, 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 or remove custom relay") + .setting(clap::AppSettings::SubcommandRequired) + .subcommand(clap::SubCommand::with_name("set") + .about("Set a custom relay") + .arg(clap::Arg::with_name("host") + .help("The host name or IP of the relay") + .required(true)) + .arg(clap::Arg::with_name("port") + .help("The port of the relay") + .required(true)) + .arg(clap::Arg::with_name("protocol") + .help("The transport protocol. UDP is recommended as it usually results in + higher throughput than TCP") + .possible_values(&["udp", "tcp"]) + .default_value("udp"))) + .subcommand(clap::SubCommand::with_name("remove") + .about("Remove the custom relay and use the default relays instead")) + } + + 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 if let Some(_) = matches.subcommand_matches("remove") { + self.remove() + } 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 relay set")) + } + + fn remove(&self) -> Result<()> { + rpc::call( + "remove_custom_relay", + &[] as &[u8; 0], + ) + .map(|_: Option<()>| println!("Custom relay removed")) + } +} 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; |
