diff --git a/mullvad-api/src/https_client_with_sni.rs b/mullvad-api/src/https_client_with_sni.rs index e7f3a8ff1280..e97a180423b4 100644 --- a/mullvad-api/src/https_client_with_sni.rs +++ b/mullvad-api/src/https_client_with_sni.rs @@ -82,7 +82,7 @@ enum InnerConnectionMode { impl InnerConnectionMode { async fn connect( - &self, + self, hostname: &str, addr: &SocketAddr, #[cfg(target_os = "android")] socket_bypass_tx: Option>, @@ -102,8 +102,7 @@ impl InnerConnectionMode { .await } // Set up a Shadowsocks-connection. - InnerConnectionMode::Shadowsocks(config) => { - let shadowsocks = config.clone(); + InnerConnectionMode::Shadowsocks(shadowsocks) => { let first_hop = shadowsocks.params.peer; let make_proxy_stream = |tcp_stream| async { Ok(ProxyClientStream::from_stream( @@ -123,8 +122,7 @@ impl InnerConnectionMode { .await } // Set up a SOCKS5-connection. - InnerConnectionMode::Socks5(config) => { - let socks = config.clone(); + InnerConnectionMode::Socks5(socks) => { let first_hop = socks.peer; let make_proxy_stream = |tcp_stream| async { tokio_socks::tcp::Socks5Stream::connect_with_socket(tcp_stream, addr) diff --git a/mullvad-daemon/src/api.rs b/mullvad-daemon/src/api.rs index d44bdd0849a7..c548f0a293c4 100644 --- a/mullvad-daemon/src/api.rs +++ b/mullvad-daemon/src/api.rs @@ -10,7 +10,7 @@ use mullvad_api::{ ApiEndpointUpdateCallback, }; use mullvad_relay_selector::RelaySelector; -use mullvad_types::access_method::AccessMethodSetting; +use mullvad_types::access_method::{AccessMethod, AccessMethodSetting, BuiltInAccessMethod}; use std::{ net::SocketAddr, path::PathBuf, @@ -106,10 +106,13 @@ impl ApiConnectionModeProvider { log::debug!("Rotating Access mode!"); let access_method = { let mut access_methods_picker = self.connection_modes.lock().unwrap(); - access_methods_picker.next() + access_methods_picker + .next() + .map(|access_method_setting| access_method_setting.access_method) + .unwrap_or(AccessMethod::from(BuiltInAccessMethod::Direct)) }; - let connection_mode = self.from(access_method.as_ref()); + let connection_mode = self.from(access_method); log::info!("New API connection mode selected: {}", connection_mode); connection_mode } @@ -118,45 +121,40 @@ impl ApiConnectionModeProvider { /// [`ApiConnectionMode`]s require extra logic/data from /// [`ApiConnectionModeProvider`] the standard [`std::convert::From`] trait /// can not be implemented. - fn from(&mut self, access_method: Option<&AccessMethodSetting>) -> ApiConnectionMode { - use mullvad_types::access_method::{self, AccessMethod, BuiltInAccessMethod}; + fn from(&mut self, access_method: AccessMethod) -> ApiConnectionMode { + use mullvad_types::access_method; match access_method { - None => ApiConnectionMode::Direct, - Some(access_method) => match &access_method.access_method { - AccessMethod::BuiltIn(access_method) => match access_method { - BuiltInAccessMethod::Direct => ApiConnectionMode::Direct, - BuiltInAccessMethod::Bridge => self - .relay_selector - .get_bridge_forced() - .and_then(|settings| match settings { - ProxySettings::Shadowsocks(ss_settings) => { - let ss_settings: access_method::Shadowsocks = - access_method::Shadowsocks::new( - ss_settings.peer, - ss_settings.cipher, - ss_settings.password, - ); - Some(ApiConnectionMode::Proxied(ProxyConfig::Shadowsocks( - ss_settings, - ))) - } - _ => { - log::error!("Received unexpected proxy settings type"); - None - } - }) - .unwrap_or(ApiConnectionMode::Direct), - }, - AccessMethod::Custom(access_method) => match &access_method { - access_method::CustomAccessMethod::Shadowsocks(shadowsocks_config) => { - ApiConnectionMode::Proxied(ProxyConfig::Shadowsocks( - shadowsocks_config.clone(), - )) - } - access_method::CustomAccessMethod::Socks5(socks_config) => { - ApiConnectionMode::Proxied(ProxyConfig::Socks(socks_config.clone())) - } - }, + AccessMethod::BuiltIn(access_method) => match access_method { + BuiltInAccessMethod::Direct => ApiConnectionMode::Direct, + BuiltInAccessMethod::Bridge => self + .relay_selector + .get_bridge_forced() + .and_then(|settings| match settings { + ProxySettings::Shadowsocks(ss_settings) => { + let ss_settings: access_method::Shadowsocks = + access_method::Shadowsocks::new( + ss_settings.peer, + ss_settings.cipher, + ss_settings.password, + ); + Some(ApiConnectionMode::Proxied(ProxyConfig::Shadowsocks( + ss_settings, + ))) + } + _ => { + log::error!("Received unexpected proxy settings type"); + None + } + }) + .unwrap_or(ApiConnectionMode::Direct), + }, + AccessMethod::Custom(access_method) => match access_method { + access_method::CustomAccessMethod::Shadowsocks(shadowsocks_config) => { + ApiConnectionMode::Proxied(ProxyConfig::Shadowsocks(shadowsocks_config)) + } + access_method::CustomAccessMethod::Socks5(socks_config) => { + ApiConnectionMode::Proxied(ProxyConfig::Socks(socks_config)) + } }, } }