diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-03-27 15:34:46 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-03-29 15:50:34 +0200 |
| commit | d630325c55920cb4c294812e40221fea7e6d7510 (patch) | |
| tree | ed9460a6213e9402d7a719b8a73c43af3175dfab | |
| parent | 2616889e0ab64afb98bf67056b4e5c977608b660 (diff) | |
| download | mullvadvpn-d630325c55920cb4c294812e40221fea7e6d7510.tar.xz mullvadvpn-d630325c55920cb4c294812e40221fea7e6d7510.zip | |
Remove getters and setters from SettingsPersister
| -rw-r--r-- | Cargo.lock | 13 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | mullvad-api/Cargo.toml | 3 | ||||
| -rw-r--r-- | mullvad-api/src/address_cache.rs | 2 | ||||
| -rw-r--r-- | mullvad-api/src/lib.rs | 1 | ||||
| -rw-r--r-- | mullvad-api/src/proxy.rs | 2 | ||||
| -rw-r--r-- | mullvad-daemon/Cargo.toml | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 121 | ||||
| -rw-r--r-- | mullvad-daemon/src/settings.rs | 203 | ||||
| -rw-r--r-- | mullvad-fs/Cargo.toml | 15 | ||||
| -rw-r--r-- | mullvad-fs/src/lib.rs (renamed from mullvad-api/src/fs.rs) | 3 | ||||
| -rw-r--r-- | mullvad-management-interface/src/types/conversions/settings.rs | 2 | ||||
| -rw-r--r-- | mullvad-types/src/settings/mod.rs | 26 | ||||
| -rw-r--r-- | mullvad-types/src/wireguard.rs | 2 |
14 files changed, 156 insertions, 239 deletions
diff --git a/Cargo.lock b/Cargo.lock index 87bef3c513..ce7e86ffe7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1644,6 +1644,7 @@ dependencies = [ "hyper", "ipnetwork", "log", + "mullvad-fs", "mullvad-types", "once_cell", "regex", @@ -1655,7 +1656,6 @@ dependencies = [ "talpid-types", "tokio", "tokio-rustls", - "uuid", ] [[package]] @@ -1702,6 +1702,7 @@ dependencies = [ "log", "log-panics", "mullvad-api", + "mullvad-fs", "mullvad-management-interface", "mullvad-paths", "mullvad-relay-selector", @@ -1739,6 +1740,16 @@ dependencies = [ ] [[package]] +name = "mullvad-fs" +version = "0.0.0" +dependencies = [ + "log", + "talpid-types", + "tokio", + "uuid", +] + +[[package]] name = "mullvad-jni" version = "0.0.0" dependencies = [ diff --git a/Cargo.toml b/Cargo.toml index 9cfeba5053..3e7a3bed2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "android/translations-converter", "mullvad-daemon", "mullvad-cli", + "mullvad-fs", "mullvad-setup", "mullvad-problem-report", "mullvad-jni", diff --git a/mullvad-api/Cargo.toml b/mullvad-api/Cargo.toml index 6699ab432c..c61b686823 100644 --- a/mullvad-api/Cargo.toml +++ b/mullvad-api/Cargo.toml @@ -27,10 +27,9 @@ tokio-rustls = "0.23" rustls-pemfile = "0.2" once_cell = "1.13" +mullvad-fs = { path = "../mullvad-fs" } mullvad-types = { path = "../mullvad-types" } talpid-types = { path = "../talpid-types" } talpid-time = { path = "../talpid-time" } shadowsocks = { version = "1.14.2", default-features = false, features = ["stream-cipher"] } - -uuid = { version = "0.8", features = ["v4"] } diff --git a/mullvad-api/src/address_cache.rs b/mullvad-api/src/address_cache.rs index d37d429e89..e4bcf9bde7 100644 --- a/mullvad-api/src/address_cache.rs +++ b/mullvad-api/src/address_cache.rs @@ -80,7 +80,7 @@ impl AddressCache { None => return Ok(()), }; - let mut file = crate::fs::AtomicFile::new(write_path.to_path_buf()) + let mut file = mullvad_fs::AtomicFile::new(&**write_path) .await .map_err(Error::Open)?; let mut contents = address.to_string(); diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index 68b582910a..5c9b4b726d 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -35,7 +35,6 @@ pub use crate::https_client_with_sni::SocketBypassRequest; mod access; mod address_cache; pub mod device; -mod fs; mod relay_list; pub use address_cache::AddressCache; pub use device::DevicesProxy; diff --git a/mullvad-api/src/proxy.rs b/mullvad-api/src/proxy.rs index 9a9a20d411..1e6ab41f80 100644 --- a/mullvad-api/src/proxy.rs +++ b/mullvad-api/src/proxy.rs @@ -86,7 +86,7 @@ impl ApiConnectionMode { /// Stores this config to `CURRENT_CONFIG_FILENAME`. pub async fn save(&self, cache_dir: &Path) -> io::Result<()> { - let mut file = crate::fs::AtomicFile::new(cache_dir.join(CURRENT_CONFIG_FILENAME)).await?; + let mut file = mullvad_fs::AtomicFile::new(cache_dir.join(CURRENT_CONFIG_FILENAME)).await?; let json = serde_json::to_string_pretty(self) .map_err(|_| io::Error::new(io::ErrorKind::Other, "serialization failed"))?; file.write_all(json.as_bytes()).await?; diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml index d427ac84f3..9c71d57eba 100644 --- a/mullvad-daemon/Cargo.toml +++ b/mullvad-daemon/Cargo.toml @@ -29,6 +29,7 @@ uuid = { version = "0.8", features = ["v4"] } mullvad-relay-selector = { path = "../mullvad-relay-selector" } mullvad-types = { path = "../mullvad-types" } mullvad-api = { path = "../mullvad-api" } +mullvad-fs = { path = "../mullvad-fs" } mullvad-version = { path = "../mullvad-version" } talpid-core = { path = "../talpid-core" } talpid-types = { path = "../talpid-types" } diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 34336b2c90..9f9ce5c4af 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -1160,12 +1160,12 @@ where let save_result = match update { ExcludedPathsUpdate::SetState(state) => self .settings - .set_split_tunnel_state(state) + .update(move |settings| settings.split_tunnel.enable_exclusions = state) .await .map_err(Error::SettingsError), ExcludedPathsUpdate::SetPaths(paths) => self .settings - .set_split_tunnel_apps(paths) + .update(move |settings| settings.split_tunnel.apps = paths) .await .map_err(Error::SettingsError), }; @@ -1730,12 +1730,11 @@ where #[cfg(windows)] async fn on_use_wireguard_nt(&mut self, tx: ResponseTx<(), Error>, state: bool) { - let save_result = self + match self .settings - .set_use_wireguard_nt(state) + .update(move |settings| settings.tunnel_options.wireguard.use_wireguard_nt = state) .await - .map_err(Error::SettingsError); - match save_result { + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "use_wireguard_nt response"); if settings_changed { @@ -1755,7 +1754,11 @@ where "{}", error.display_chain_with_msg("Unable to save settings") ); - Self::oneshot_send(tx, Err(error), "use_wireguard_nt response"); + Self::oneshot_send( + tx, + Err(Error::SettingsError(error)), + "use_wireguard_nt response", + ); } } } @@ -1772,8 +1775,11 @@ where tx: ResponseTx<(), settings::Error>, update: RelaySettingsUpdate, ) { - let save_result = self.settings.update_relay_settings(update).await; - match save_result { + match self + .settings + .update(move |settings| settings.update_relay_settings(update)) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "update_relay_settings response"); if settings_changed { @@ -1793,8 +1799,11 @@ where } async fn on_set_allow_lan(&mut self, tx: ResponseTx<(), settings::Error>, allow_lan: bool) { - let save_result = self.settings.set_allow_lan(allow_lan).await; - match save_result { + match self + .settings + .update(move |settings| settings.allow_lan = allow_lan) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_allow_lan response"); if settings_changed { @@ -1815,8 +1824,11 @@ where tx: ResponseTx<(), settings::Error>, enabled: bool, ) { - let save_result = self.settings.set_show_beta_releases(enabled).await; - match save_result { + match self + .settings + .update(move |settings| settings.show_beta_releases = enabled) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_show_beta_releases response"); if settings_changed { @@ -1838,11 +1850,11 @@ where tx: ResponseTx<(), settings::Error>, block_when_disconnected: bool, ) { - let save_result = self + match self .settings - .set_block_when_disconnected(block_when_disconnected) - .await; - match save_result { + .update(move |settings| settings.block_when_disconnected = block_when_disconnected) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_block_when_disconnected response"); if settings_changed { @@ -1865,8 +1877,11 @@ where tx: ResponseTx<(), settings::Error>, auto_connect: bool, ) { - let save_result = self.settings.set_auto_connect(auto_connect).await; - match save_result { + match self + .settings + .update(move |settings| settings.auto_connect = auto_connect) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set auto-connect response"); if settings_changed { @@ -1884,10 +1899,13 @@ where async fn on_set_openvpn_mssfix( &mut self, tx: ResponseTx<(), settings::Error>, - mssfix_arg: Option<u16>, + mssfix: Option<u16>, ) { - let save_result = self.settings.set_openvpn_mssfix(mssfix_arg).await; - match save_result { + match self + .settings + .update(move |settings| settings.tunnel_options.openvpn.mssfix = mssfix) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_openvpn_mssfix response"); if settings_changed { @@ -1916,7 +1934,11 @@ where tx: ResponseTx<(), settings::Error>, new_settings: BridgeSettings, ) { - match self.settings.set_bridge_settings(new_settings).await { + match self + .settings + .update(move |settings| settings.bridge_settings = new_settings) + .await + { Ok(settings_changes) => { if settings_changes { self.event_listener @@ -1946,7 +1968,11 @@ where tx: ResponseTx<(), settings::Error>, new_settings: ObfuscationSettings, ) { - match self.settings.set_obfuscation_settings(new_settings).await { + match self + .settings + .update(move |settings| settings.obfuscation_settings = new_settings) + .await + { Ok(settings_changed) => { if settings_changed { self.event_listener @@ -1972,7 +1998,11 @@ where tx: ResponseTx<(), settings::Error>, bridge_state: BridgeState, ) { - let result = match self.settings.set_bridge_state(bridge_state).await { + let result = match self + .settings + .update(move |settings| settings.bridge_state = bridge_state) + .await + { Ok(settings_changed) => { if settings_changed { self.event_listener @@ -1996,8 +2026,11 @@ where } async fn on_set_enable_ipv6(&mut self, tx: ResponseTx<(), settings::Error>, enable_ipv6: bool) { - let save_result = self.settings.set_enable_ipv6(enable_ipv6).await; - match save_result { + match self + .settings + .update(|settings| settings.tunnel_options.generic.enable_ipv6 = enable_ipv6) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_enable_ipv6 response"); if settings_changed { @@ -2022,11 +2055,13 @@ where tx: ResponseTx<(), settings::Error>, quantum_resistant: QuantumResistantState, ) { - let save_result = self + match self .settings - .set_quantum_resistant_tunnel(quantum_resistant) - .await; - match save_result { + .update(|settings| { + settings.tunnel_options.wireguard.quantum_resistant = quantum_resistant + }) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_quantum_resistant_tunnel response"); if settings_changed { @@ -2053,8 +2088,11 @@ where tx: ResponseTx<(), settings::Error>, dns_options: DnsOptions, ) { - let save_result = self.settings.set_dns_options(dns_options.clone()).await; - match save_result { + match self + .settings + .update(move |settings| settings.tunnel_options.dns_options = dns_options) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_dns_options response"); if settings_changed { @@ -2080,8 +2118,11 @@ where tx: ResponseTx<(), settings::Error>, mtu: Option<u16>, ) { - let save_result = self.settings.set_wireguard_mtu(mtu).await; - match save_result { + match self + .settings + .update(move |settings| settings.tunnel_options.wireguard.mtu = mtu) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_wireguard_mtu response"); if settings_changed { @@ -2110,11 +2151,11 @@ where tx: ResponseTx<(), settings::Error>, interval: Option<RotationInterval>, ) { - let save_result = self + match self .settings - .set_wireguard_rotation_interval(interval) - .await; - match save_result { + .update(move |settings| settings.tunnel_options.wireguard.rotation_interval = interval) + .await + { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_wireguard_rotation_interval response"); if settings_changed { @@ -2324,7 +2365,7 @@ fn new_selector_config( SelectorConfig { relay_settings: settings.get_relay_settings(), - bridge_state: settings.get_bridge_state(), + bridge_state: settings.bridge_state, bridge_settings: settings.bridge_settings.clone(), obfuscation_settings: settings.obfuscation_settings.clone(), default_tunnel_type, diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs index 2c1ea033f9..ecf2e4db7e 100644 --- a/mullvad-daemon/src/settings.rs +++ b/mullvad-daemon/src/settings.rs @@ -1,13 +1,7 @@ #[cfg(not(target_os = "android"))] use futures::TryFutureExt; -use mullvad_types::{ - relay_constraints::{BridgeSettings, BridgeState, ObfuscationSettings, RelaySettingsUpdate}, - settings::{DnsOptions, Settings}, - wireguard::{QuantumResistantState, RotationInterval}, -}; +use mullvad_types::settings::Settings; use rand::Rng; -#[cfg(target_os = "windows")] -use std::collections::HashSet; use std::{ ops::Deref, path::{Path, PathBuf}, @@ -46,6 +40,8 @@ pub struct SettingsPersister { path: PathBuf, } +pub type MadeChanges = bool; + impl SettingsPersister { /// Loads user settings from file. If it fails, it returns the defaults. pub async fn load(settings_dir: &Path) -> Self { @@ -78,11 +74,12 @@ impl SettingsPersister { // Force IPv6 to be enabled on Android if cfg!(target_os = "android") { - should_save |= - Self::update_field(&mut settings.tunnel_options.generic.enable_ipv6, true); + should_save |= !settings.tunnel_options.generic.enable_ipv6; + settings.tunnel_options.generic.enable_ipv6 = true; } if crate::version::is_beta_version() { - should_save |= Self::update_field(&mut settings.show_beta_releases, true); + should_save |= !settings.show_beta_releases; + settings.show_beta_releases = true; } let mut persister = SettingsPersister { settings, path }; @@ -120,24 +117,24 @@ impl SettingsPersister { serde_json::from_slice(bytes).map_err(Error::ParseError) } - /// Serializes the settings and saves them to the file it was loaded from. async fn save(&mut self) -> Result<(), Error> { - log::debug!("Writing settings to {}", self.path.display()); + Self::save_inner(&self.path, &self.settings).await + } - let buffer = serde_json::to_string_pretty(&self.settings).map_err(Error::SerializeError)?; - let mut file = fs::OpenOptions::new() - .create(true) - .write(true) - .truncate(true) - .open(&self.path) + /// Serializes the settings and saves them to the given file. + async fn save_inner(path: &Path, settings: &Settings) -> Result<(), Error> { + log::debug!("Writing settings to {}", path.display()); + + let buffer = serde_json::to_string_pretty(settings).map_err(Error::SerializeError)?; + let mut file = mullvad_fs::AtomicFile::new(path) .await - .map_err(|e| Error::WriteError(self.path.display().to_string(), e))?; + .map_err(|e| Error::WriteError(path.display().to_string(), e))?; file.write_all(&buffer.into_bytes()) .await - .map_err(|e| Error::WriteError(self.path.display().to_string(), e))?; - file.sync_all() + .map_err(|e| Error::WriteError(path.display().to_string(), e))?; + file.finalize() .await - .map_err(|e| Error::WriteError(self.path.display().to_string(), e))?; + .map_err(|e| Error::WriteError(path.display().to_string(), e))?; Ok(()) } @@ -176,158 +173,26 @@ impl SettingsPersister { settings } - pub async fn update_relay_settings( + /// Edit the settings in a closure, and write the changes, if any, to disk. + /// + /// On success, the function returns a boolean indicating whether any settings were changed. + /// If the settings could not be written to disk, all changes are rolled back, and an error is + /// returned. + pub async fn update( &mut self, - update: RelaySettingsUpdate, - ) -> Result<bool, Error> { - let should_save = self.settings.update_relay_settings(update); - self.update(should_save).await - } + update_fn: impl FnOnce(&mut Settings), + ) -> Result<MadeChanges, Error> { + let mut new_settings = self.settings.clone(); - pub async fn set_allow_lan(&mut self, allow_lan: bool) -> Result<bool, Error> { - let should_save = Self::update_field(&mut self.settings.allow_lan, allow_lan); - self.update(should_save).await - } + update_fn(&mut new_settings); - pub async fn set_block_when_disconnected( - &mut self, - block_when_disconnected: bool, - ) -> Result<bool, Error> { - let should_save = Self::update_field( - &mut self.settings.block_when_disconnected, - block_when_disconnected, - ); - self.update(should_save).await - } - - pub async fn set_auto_connect(&mut self, auto_connect: bool) -> Result<bool, Error> { - let should_save = Self::update_field(&mut self.settings.auto_connect, auto_connect); - self.update(should_save).await - } - - pub async fn set_openvpn_mssfix(&mut self, openvpn_mssfix: Option<u16>) -> Result<bool, Error> { - let should_save = Self::update_field( - &mut self.settings.tunnel_options.openvpn.mssfix, - openvpn_mssfix, - ); - self.update(should_save).await - } - - pub async fn set_enable_ipv6(&mut self, enable_ipv6: bool) -> Result<bool, Error> { - let should_save = Self::update_field( - &mut self.settings.tunnel_options.generic.enable_ipv6, - enable_ipv6, - ); - self.update(should_save).await - } - - pub async fn set_quantum_resistant_tunnel( - &mut self, - quantum_resistant: QuantumResistantState, - ) -> Result<bool, Error> { - let should_save = Self::update_field( - &mut self.settings.tunnel_options.wireguard.quantum_resistant, - quantum_resistant, - ); - self.update(should_save).await - } - - pub async fn set_dns_options(&mut self, options: DnsOptions) -> Result<bool, Error> { - let should_save = - Self::update_field(&mut self.settings.tunnel_options.dns_options, options); - self.update(should_save).await - } - - pub async fn set_wireguard_mtu(&mut self, mtu: Option<u16>) -> Result<bool, Error> { - let should_save = Self::update_field(&mut self.settings.tunnel_options.wireguard.mtu, mtu); - self.update(should_save).await - } - - pub async fn set_wireguard_rotation_interval( - &mut self, - interval: Option<RotationInterval>, - ) -> Result<bool, Error> { - let should_save = Self::update_field( - &mut self.settings.tunnel_options.wireguard.rotation_interval, - interval, - ); - self.update(should_save).await - } - - pub async fn set_show_beta_releases( - &mut self, - show_beta_releases: bool, - ) -> Result<bool, Error> { - let should_save = - Self::update_field(&mut self.settings.show_beta_releases, show_beta_releases); - self.update(should_save).await - } - - pub async fn set_bridge_settings( - &mut self, - bridge_settings: BridgeSettings, - ) -> Result<bool, Error> { - let should_save = Self::update_field(&mut self.settings.bridge_settings, bridge_settings); - self.update(should_save).await - } - - pub async fn set_bridge_state(&mut self, bridge_state: BridgeState) -> Result<bool, Error> { - let should_save = self.settings.set_bridge_state(bridge_state); - self.update(should_save).await - } - - #[cfg(windows)] - pub async fn set_split_tunnel_apps(&mut self, paths: HashSet<PathBuf>) -> Result<bool, Error> { - let should_save = paths != self.settings.split_tunnel.apps; - if should_save { - self.settings.split_tunnel.apps = paths; - } - self.update(should_save).await - } - - #[cfg(windows)] - pub async fn set_split_tunnel_state(&mut self, enabled: bool) -> Result<bool, Error> { - let should_save = - Self::update_field(&mut self.settings.split_tunnel.enable_exclusions, enabled); - self.update(should_save).await - } - - #[cfg(windows)] - pub async fn set_use_wireguard_nt(&mut self, state: bool) -> Result<bool, Error> { - let should_save = Self::update_field( - &mut self.settings.tunnel_options.wireguard.use_wireguard_nt, - state, - ); - self.update(should_save).await - } - - fn update_field<T: Eq>(field: &mut T, new_value: T) -> bool { - if *field != new_value { - *field = new_value; - true - } else { - false + if self.settings == new_settings { + return Ok(false); } - } - pub async fn set_obfuscation_settings( - &mut self, - obfuscation_settings: ObfuscationSettings, - ) -> Result<bool, Error> { - let should_save = Self::update_field( - &mut self.settings.obfuscation_settings, - obfuscation_settings, - ); - - self.update(should_save).await - } - - async fn update(&mut self, should_save: bool) -> Result<bool, Error> { - if should_save { - self.save().await.map(|_| true) - } else { - Ok(false) - } + Self::save_inner(&self.path, &new_settings).await?; + self.settings = new_settings; + Ok(true) } } diff --git a/mullvad-fs/Cargo.toml b/mullvad-fs/Cargo.toml new file mode 100644 index 0000000000..b2ae4176e0 --- /dev/null +++ b/mullvad-fs/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "mullvad-fs" +version = "0.0.0" +authors = ["Mullvad VPN"] +description = "File utility library" +license = "GPL-3.0" +edition = "2021" +publish = false + +[dependencies] +log = "0.4" +tokio = { version = "1.8", features = ["fs"] } +uuid = { version = "0.8", features = ["v4"] } + +talpid-types = { path = "../talpid-types" } diff --git a/mullvad-api/src/fs.rs b/mullvad-fs/src/lib.rs index d643563c9a..22c6a80588 100644 --- a/mullvad-api/src/fs.rs +++ b/mullvad-fs/src/lib.rs @@ -15,7 +15,8 @@ pub struct AtomicFile { } impl AtomicFile { - pub async fn new(target_path: PathBuf) -> io::Result<Self> { + pub async fn new<P: Into<PathBuf>>(target_path: P) -> io::Result<Self> { + let target_path = target_path.into(); let temp_path = target_path.with_file_name(uuid::Uuid::new_v4().to_string()); Ok(Self { file: Some(fs::File::create(&temp_path).await?), diff --git a/mullvad-management-interface/src/types/conversions/settings.rs b/mullvad-management-interface/src/types/conversions/settings.rs index 8a97c3b213..39ff2c05a2 100644 --- a/mullvad-management-interface/src/types/conversions/settings.rs +++ b/mullvad-management-interface/src/types/conversions/settings.rs @@ -28,7 +28,7 @@ impl From<&mullvad_types::settings::Settings> for proto::Settings { bridge_settings: Some(proto::BridgeSettings::from( settings.bridge_settings.clone(), )), - bridge_state: Some(proto::BridgeState::from(settings.get_bridge_state())), + bridge_state: Some(proto::BridgeState::from(settings.bridge_state)), allow_lan: settings.allow_lan, block_when_disconnected: settings.block_when_disconnected, auto_connect: settings.auto_connect, diff --git a/mullvad-types/src/settings/mod.rs b/mullvad-types/src/settings/mod.rs index 9b88baebc9..5d9c082e2e 100644 --- a/mullvad-types/src/settings/mod.rs +++ b/mullvad-types/src/settings/mod.rs @@ -60,7 +60,7 @@ impl Serialize for SettingsVersion { } /// Mullvad daemon settings. -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] #[serde(default)] #[cfg_attr(target_os = "android", derive(IntoJava))] #[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))] @@ -71,7 +71,7 @@ pub struct Settings { #[cfg_attr(target_os = "android", jnix(skip))] pub obfuscation_settings: ObfuscationSettings, #[cfg_attr(target_os = "android", jnix(skip))] - bridge_state: BridgeState, + pub bridge_state: BridgeState, /// If the daemon should allow communication with private (LAN) networks. pub allow_lan: bool, /// Extra level of kill switch. When this setting is on, the disconnected state will block @@ -106,7 +106,7 @@ fn out_of_range_wg_migration_rand_num() -> f32 { } #[cfg(windows)] -#[derive(Debug, Clone, Default, Deserialize, Serialize)] +#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq)] pub struct SplitTunnelSettings { /// Toggles split tunneling on or off pub enable_exclusions: bool, @@ -149,7 +149,7 @@ impl Settings { self.relay_settings.clone() } - pub fn update_relay_settings(&mut self, update: RelaySettingsUpdate) -> bool { + pub fn update_relay_settings(&mut self, update: RelaySettingsUpdate) { let update_supports_bridge = update.supports_bridge(); let new_settings = self.relay_settings.merge(update); if self.relay_settings != new_settings { @@ -163,22 +163,6 @@ impl Settings { ); self.relay_settings = new_settings; - true - } else { - false - } - } - - pub fn get_bridge_state(&self) -> BridgeState { - self.bridge_state - } - - pub fn set_bridge_state(&mut self, bridge_state: BridgeState) -> bool { - if self.bridge_state != bridge_state { - self.bridge_state = bridge_state; - true - } else { - false } } @@ -188,7 +172,7 @@ impl Settings { } /// TunnelOptions holds configuration data that applies to all kinds of tunnels. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(default)] #[cfg_attr(target_os = "android", derive(IntoJava))] #[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))] diff --git a/mullvad-types/src/wireguard.rs b/mullvad-types/src/wireguard.rs index 71b6fc4164..8b69af374b 100644 --- a/mullvad-types/src/wireguard.rs +++ b/mullvad-types/src/wireguard.rs @@ -122,7 +122,7 @@ impl Default for RotationInterval { } } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(default)] #[cfg_attr(target_os = "android", derive(IntoJava))] #[cfg_attr( |
