diff options
| author | Linus Färnstrand <faern@faern.net> | 2022-04-13 14:35:51 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2022-04-14 13:17:15 +0200 |
| commit | e6b2e24c2a79b122a05dbfc90fa5a96a49a65bee (patch) | |
| tree | f413ac9be4e6bd16742af7be43cc84af53265551 | |
| parent | b98207961f1615014cb7b5d00d62c8a82145c8c1 (diff) | |
| download | mullvadvpn-e6b2e24c2a79b122a05dbfc90fa5a96a49a65bee.tar.xz mullvadvpn-e6b2e24c2a79b122a05dbfc90fa5a96a49a65bee.zip | |
Improve and change output of `mullvad obfuscation get`
Somewhat refactors how some obfuscation related types display themselves
| -rw-r--r-- | mullvad-cli/src/cmds/obfuscation.rs | 26 | ||||
| -rw-r--r-- | mullvad-types/src/relay_constraints.rs | 39 |
2 files changed, 20 insertions, 45 deletions
diff --git a/mullvad-cli/src/cmds/obfuscation.rs b/mullvad-cli/src/cmds/obfuscation.rs index 9316333e8c..3f015c896e 100644 --- a/mullvad-cli/src/cmds/obfuscation.rs +++ b/mullvad-cli/src/cmds/obfuscation.rs @@ -29,7 +29,7 @@ impl Command for Obfuscation { async fn run(&self, matches: &clap::ArgMatches) -> Result<()> { match matches.subcommand() { Some(("set", set_matches)) => Self::handle_set(set_matches).await, - Some(("get", get_matches)) => Self::handle_get(get_matches).await, + Some(("get", _get_matches)) => Self::handle_get().await, _ => unreachable!("unhandled command"), } } @@ -50,7 +50,7 @@ impl Obfuscation { }; Self::set_obfuscation_settings(&mut rpc, &settings).await?; } - Some(("udp2tcp-settings", settings_matches)) => { + Some(("udp2tcp", settings_matches)) => { let port: String = settings_matches.value_of_t_or_exit("port"); let mut rpc = new_rpc_client().await?; let mut settings = Self::get_obfuscation_settings(&mut rpc).await?; @@ -68,13 +68,14 @@ impl Obfuscation { Ok(()) } - async fn handle_get(matches: &clap::ArgMatches) -> Result<()> { + async fn handle_get() -> Result<()> { let mut rpc = new_rpc_client().await?; - let settings = Self::get_obfuscation_settings(&mut rpc).await?; - match matches.subcommand() { - Some(("udp2tcp-settings", _)) => println!("Udp2Tcp: {}", settings.udp2tcp), - _ => println!("Current settings: {}", settings), - } + let obfuscation_settings = Self::get_obfuscation_settings(&mut rpc).await?; + println!( + "Obfuscation mode: {}", + obfuscation_settings.selected_obfuscation + ); + println!("udp2tcp settings: {}", obfuscation_settings.udp2tcp); Ok(()) } @@ -119,7 +120,7 @@ fn create_obfuscation_set_subcommand() -> clap::App<'static> { ), ) .subcommand( - clap::App::new("udp2tcp-settings") + clap::App::new("udp2tcp") .about("Specifies the config for the udp2tcp obfuscator") .setting(clap::AppSettings::ArgRequiredElseHelp) .arg( @@ -132,10 +133,5 @@ fn create_obfuscation_set_subcommand() -> clap::App<'static> { } fn create_obfuscation_get_subcommand() -> clap::App<'static> { - clap::App::new("get") - .about("Get obfuscation settings") - .subcommand( - clap::App::new("udp2tcp-settings") - .about("Specifies the config for the udp2tcp obfuscator"), - ) + clap::App::new("get").about("Get current obfuscation settings") } diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index 96d1014592..e3fd854df3 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -480,15 +480,11 @@ impl Default for SelectedObfuscation { impl fmt::Display for SelectedObfuscation { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{}", - match self { - SelectedObfuscation::Auto => "auto", - SelectedObfuscation::Off => "off", - SelectedObfuscation::Udp2Tcp => "udp2tcp", - } - ) + match self { + SelectedObfuscation::Auto => "auto".fmt(f), + SelectedObfuscation::Off => "off".fmt(f), + SelectedObfuscation::Udp2Tcp => "udp2tcp".fmt(f), + } } } @@ -500,15 +496,10 @@ pub struct Udp2TcpObfuscationSettings { impl fmt::Display for Udp2TcpObfuscationSettings { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "port: {}", - match self.port { - Constraint::Any => "any".to_string(), - Constraint::Only(port) => port.to_string(), - } - )?; - Ok(()) + match self.port { + Constraint::Any => write!(f, "any port"), + Constraint::Only(port) => write!(f, "port {}", port), + } } } @@ -521,18 +512,6 @@ pub struct ObfuscationSettings { pub udp2tcp: Udp2TcpObfuscationSettings, } -impl fmt::Display for ObfuscationSettings { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - write!(f, "selected obfuscation: ")?; - match self.selected_obfuscation { - SelectedObfuscation::Auto => write!(f, "auto")?, - SelectedObfuscation::Off => write!(f, "off")?, - SelectedObfuscation::Udp2Tcp => write!(f, "Udp2Tcp ({})", self.udp2tcp)?, - }; - Ok(()) - } -} - /// Limits the set of bridge servers to use in `mullvad-daemon`. #[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)] #[serde(default)] |
