Skip to content

Commit

Permalink
Fix daita rpc should-reconnect-check
Browse files Browse the repository at this point in the history
  • Loading branch information
hulthe committed Aug 22, 2024
1 parent b2f04ef commit 995c002
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions mullvad-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2324,14 +2324,28 @@ 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)
.await
{
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();
}
Expand All @@ -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)
Expand All @@ -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();
}
Expand Down

0 comments on commit 995c002

Please sign in to comment.