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 23, 2024
1 parent 29df1cc commit e113580
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 @@ -2337,14 +2337,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 @@ -2362,6 +2373,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 @@ -2370,8 +2383,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 e113580

Please sign in to comment.