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 Sep 16, 2024
1 parent 0e5af64 commit 7c78316
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions mullvad-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2333,14 +2333,25 @@ 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 RelaySettings::Normal(constraints) = &self.settings.relay_settings else {
return; // DAITA is not supported for custom relays
};

let wireguard_enabled = constraints
.tunnel_protocol
.intersection(Constraint::Only(TunnelType::Wireguard))
.is_some();

if settings_changed && wireguard_enabled {
log::info!("Reconnecting because DAITA settings changed");
self.reconnect_tunnel();
}
Expand All @@ -2358,6 +2369,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 @@ -2366,8 +2379,19 @@ 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 RelaySettings::Normal(constraints) = &self.settings.relay_settings else {
return; // DAITA is not supported for custom relays
};

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;

if settings_changed && wireguard_enabled && daita_enabled && !multihop_enabled {
log::info!("Reconnecting because DAITA settings changed");
self.reconnect_tunnel();
}
Expand Down

0 comments on commit 7c78316

Please sign in to comment.