summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSebastian Holmin <sebastian.holmin@mullvad.net>2024-11-14 11:43:42 +0100
committerSebastian Holmin <sebastian.holmin@mullvad.net>2024-11-14 17:31:40 +0100
commit3e603373b4f3d4a61aee003e996b589ea54a8f81 (patch)
treea71516a5d751f84c7966216f4a148ce7149233fc
parentcb38e9477f8a34e4f503dd447ce39d7ae44ddf3b (diff)
downloadmullvadvpn-3e603373b4f3d4a61aee003e996b589ea54a8f81.tar.xz
mullvadvpn-3e603373b4f3d4a61aee003e996b589ea54a8f81.zip
Move constructor for `SelectorConfig` to `mullvad-types`
-rw-r--r--mullvad-daemon/src/custom_list.rs9
-rw-r--r--mullvad-daemon/src/lib.rs40
-rw-r--r--mullvad-relay-selector/src/relay_selector/mod.rs34
3 files changed, 42 insertions, 41 deletions
diff --git a/mullvad-daemon/src/custom_list.rs b/mullvad-daemon/src/custom_list.rs
index b989a7fe56..ba662a2dac 100644
--- a/mullvad-daemon/src/custom_list.rs
+++ b/mullvad-daemon/src/custom_list.rs
@@ -1,4 +1,5 @@
-use crate::{new_selector_config, Daemon, Error};
+use crate::{Daemon, Error};
+use mullvad_relay_selector::SelectorConfig;
use mullvad_types::{
constraints::Constraint,
custom_list::{CustomList, Id},
@@ -38,7 +39,7 @@ impl Daemon {
if let Ok(true) = settings_changed {
self.relay_selector
- .set_config(new_selector_config(&self.settings));
+ .set_config(SelectorConfig::from_settings(&self.settings));
if self.change_should_cause_reconnect(Some(id)) {
log::info!("Initiating tunnel restart because a selected custom list was deleted");
@@ -65,7 +66,7 @@ impl Daemon {
if let Ok(true) = settings_changed {
self.relay_selector
- .set_config(new_selector_config(&self.settings));
+ .set_config(SelectorConfig::from_settings(&self.settings));
if self.change_should_cause_reconnect(Some(list_id)) {
log::info!("Initiating tunnel restart because a selected custom list changed");
@@ -89,7 +90,7 @@ impl Daemon {
if let Ok(true) = settings_changed {
self.relay_selector
- .set_config(new_selector_config(&self.settings));
+ .set_config(SelectorConfig::from_settings(&self.settings));
if self.change_should_cause_reconnect(None) {
log::info!("Initiating tunnel restart because a selected custom list was deleted");
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 7fb8193ba6..8299e1d20c 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -38,9 +38,7 @@ use futures::{
};
use geoip::GeoIpHandler;
use management_interface::ManagementInterfaceServer;
-use mullvad_relay_selector::{
- AdditionalRelayConstraints, AdditionalWireguardConstraints, RelaySelector, SelectorConfig,
-};
+use mullvad_relay_selector::{RelaySelector, SelectorConfig};
#[cfg(target_os = "android")]
use mullvad_types::account::{PlayPurchase, PlayPurchasePaymentToken};
#[cfg(any(windows, target_os = "android", target_os = "macos"))]
@@ -636,7 +634,7 @@ impl Daemon {
settings_event_listener.notify_settings(settings.to_owned());
});
- let initial_selector_config = new_selector_config(&settings);
+ let initial_selector_config = SelectorConfig::from_settings(&settings);
let relay_selector = RelaySelector::new(
initial_selector_config,
resource_dir.join(RELAYS_FILENAME),
@@ -648,7 +646,7 @@ impl Daemon {
// Notify relay selector of changes to the settings/selector config
settings_relay_selector
.clone()
- .set_config(new_selector_config(settings));
+ .set_config(SelectorConfig::from_settings(settings));
});
let (access_mode_handler, access_mode_provider) = api::AccessModeSelector::spawn(
@@ -3045,38 +3043,6 @@ impl DaemonShutdownHandle {
}
}
-fn new_selector_config(settings: &Settings) -> SelectorConfig {
- let additional_constraints = AdditionalRelayConstraints {
- wireguard: AdditionalWireguardConstraints {
- #[cfg(daita)]
- daita: settings.tunnel_options.wireguard.daita.enabled,
- #[cfg(daita)]
- daita_use_multihop_if_necessary: settings
- .tunnel_options
- .wireguard
- .daita
- .use_multihop_if_necessary,
-
- #[cfg(not(daita))]
- daita: false,
- #[cfg(not(daita))]
- daita_use_multihop_if_necessary: false,
-
- quantum_resistant: settings.tunnel_options.wireguard.quantum_resistant,
- },
- };
-
- SelectorConfig {
- relay_settings: settings.relay_settings.clone(),
- additional_constraints,
- bridge_state: settings.bridge_state,
- bridge_settings: settings.bridge_settings.clone(),
- obfuscation_settings: settings.obfuscation_settings.clone(),
- custom_lists: settings.custom_lists.clone(),
- relay_overrides: settings.relay_overrides.clone(),
- }
-}
-
/// Consume a oneshot sender of `T1` and return a sender that takes a different type `T2`.
/// `forwarder` should map `T1` back to `T2` and send the result back to the original receiver.
fn oneshot_map<T1: Send + 'static, T2: Send + 'static>(
diff --git a/mullvad-relay-selector/src/relay_selector/mod.rs b/mullvad-relay-selector/src/relay_selector/mod.rs
index 6a3e20605f..550d1955a0 100644
--- a/mullvad-relay-selector/src/relay_selector/mod.rs
+++ b/mullvad-relay-selector/src/relay_selector/mod.rs
@@ -118,6 +118,40 @@ pub struct SelectorConfig {
pub bridge_settings: BridgeSettings,
}
+impl SelectorConfig {
+ pub fn from_settings(settings: &Settings) -> Self {
+ let additional_constraints = AdditionalRelayConstraints {
+ wireguard: AdditionalWireguardConstraints {
+ #[cfg(daita)]
+ daita: settings.tunnel_options.wireguard.daita.enabled,
+ #[cfg(daita)]
+ daita_use_multihop_if_necessary: settings
+ .tunnel_options
+ .wireguard
+ .daita
+ .use_multihop_if_necessary,
+
+ #[cfg(not(daita))]
+ daita: false,
+ #[cfg(not(daita))]
+ daita_use_multihop_if_necessary: false,
+
+ quantum_resistant: settings.tunnel_options.wireguard.quantum_resistant,
+ },
+ };
+
+ Self {
+ relay_settings: settings.relay_settings.clone(),
+ additional_constraints,
+ bridge_state: settings.bridge_state,
+ bridge_settings: settings.bridge_settings.clone(),
+ obfuscation_settings: settings.obfuscation_settings.clone(),
+ custom_lists: settings.custom_lists.clone(),
+ relay_overrides: settings.relay_overrides.clone(),
+ }
+ }
+}
+
/// Extra relay constraints not specified in `relay_settings`.
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct AdditionalRelayConstraints {