From 2f31950fa5b21b23556be9859e3b2581c0ac64ef Mon Sep 17 00:00:00 2001 From: Sebastian Holmin Date: Mon, 7 Oct 2024 11:36:50 +0200 Subject: [PATCH] Set "Direct only" to `false` as default For android, it is set to true, as multihop is not supported. Note that in the daemon, the setting is called `use_multihop_if_necessary` and has the inverse meaning. --- .../lib/daemon/grpc/ManagementService.kt | 12 ++++++--- mullvad-types/src/wireguard.rs | 25 +++++++++++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt index 7961b5460c0a..851c92dad443 100644 --- a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt +++ b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt @@ -510,10 +510,14 @@ class ManagementService( suspend fun setDaitaEnabled(enabled: Boolean): Either = Either.catch { - val daitaSettings = - ManagementInterface.DaitaSettings.newBuilder().setEnabled(enabled).build() - grpc.setDaitaSettings(daitaSettings) - } + val daitaSettings = + ManagementInterface.DaitaSettings.newBuilder().setEnabled(enabled) + // TODO: Before Multihop is supported on Android, calling `setDirectOnly` with false + // will cause undefined behaviour. + .setDirectOnly(true) + .build() + grpc.setDaitaSettings(daitaSettings) + } .mapLeft(SetDaitaSettingsError::Unknown) .mapEmpty() diff --git a/mullvad-types/src/wireguard.rs b/mullvad-types/src/wireguard.rs index 77ed60e1b2d2..f6d9395c7e11 100644 --- a/mullvad-types/src/wireguard.rs +++ b/mullvad-types/src/wireguard.rs @@ -81,14 +81,35 @@ impl FromStr for QuantumResistantState { pub struct QuantumResistantStateParseError; #[cfg(daita)] -#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct DaitaSettings { pub enabled: bool, - #[serde(default)] + #[serde(default = "DaitaSettings::default_use_multihop_if_necessary")] + /// Whether to use multihop if the selected relay is not DAITA-compatible. Note that this is + /// the inverse of of "Direct only" in the GUI. pub use_multihop_if_necessary: bool, } +#[cfg(daita)] +impl DaitaSettings { + const fn default_use_multihop_if_necessary() -> bool { + cfg!(not(target_os = "android")) + } +} + +#[cfg(daita)] +impl Default for DaitaSettings { + fn default() -> Self { + Self { + enabled: false, + // This setting should be enabled by default, expect on Android where multihop is not + // supported. + use_multihop_if_necessary: Self::default_use_multihop_if_necessary(), + } + } +} + /// Contains account specific wireguard data #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct WireguardData {