From 995c002c263fc1dd92c8a6a43283c10c71889896 Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Thu, 22 Aug 2024 16:56:26 +0200 Subject: [PATCH] Fix daita rpc should-reconnect-check --- mullvad-daemon/src/lib.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index e795b1d116d1..781e25fabeb4 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -2324,6 +2324,8 @@ impl Daemon { #[cfg(daita)] async fn on_set_daita_enabled(&mut self, tx: ResponseTx<(), settings::Error>, value: bool) { + use mullvad_types::{constraints::Constraint, Intersection}; + match self .settings .update(|settings| settings.tunnel_options.wireguard.daita.enabled = value) @@ -2331,7 +2333,19 @@ impl Daemon { { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_daita_enabled response"); - if settings_changed && self.get_target_tunnel_type() != Some(TunnelType::OpenVpn) { + let should_reconnect = + if let RelaySettings::Normal(constraints) = &self.settings.relay_settings { + let wireguard_enabled = constraints + .tunnel_protocol + .intersection(Constraint::Only(TunnelType::Wireguard)) + .is_some(); + + settings_changed && wireguard_enabled + } else { + false // DAITA is not supported for custom relays + }; + + if should_reconnect { log::info!("Reconnecting because DAITA settings changed"); self.reconnect_tunnel(); } @@ -2349,6 +2363,8 @@ impl Daemon { tx: ResponseTx<(), settings::Error>, value: bool, ) { + use mullvad_types::{constraints::Constraint, Intersection}; + match self .settings .update(|settings| settings.tunnel_options.wireguard.daita.use_anywhere = value) @@ -2357,8 +2373,22 @@ impl Daemon { Ok(settings_changed) => { Self::oneshot_send(tx, Ok(()), "set_daita_use_anywhere response"); - // TODO: don't reconnect if multihop is enabled - if settings_changed && self.get_target_tunnel_type() != Some(TunnelType::OpenVpn) { + let should_reconnect = + if let RelaySettings::Normal(constraints) = &self.settings.relay_settings { + let wireguard_enabled = constraints + .tunnel_protocol + .intersection(Constraint::Only(TunnelType::Wireguard)) + .is_some(); + + let multihop_enabled = constraints.wireguard_constraints.use_multihop; + let daita_enabled = self.settings.tunnel_options.wireguard.daita.enabled; + + settings_changed && wireguard_enabled && daita_enabled && !multihop_enabled + } else { + false // DAITA is not supported for custom relays + }; + + if should_reconnect { log::info!("Reconnecting because DAITA settings changed"); self.reconnect_tunnel(); }