summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2024-02-20 18:09:50 +0100
committerMarkus Pettersson <markus.pettersson@mullvad.net>2024-02-20 18:09:50 +0100
commite204cc78d748d40e7eab0cf0c0768107b19079cf (patch)
treeb78fb84b5c4f82b7af8033ae5e2b8bcfc8fe26b3
parentbde5c5d57d6a0c4f31a6e91eda2ca1d8b21eef41 (diff)
parent16831a2ce194ef9defad6c13bd80baf639d57490 (diff)
downloadmullvadvpn-e204cc78d748d40e7eab0cf0c0768107b19079cf.tar.xz
mullvadvpn-e204cc78d748d40e7eab0cf0c0768107b19079cf.zip
Merge branch 'remove-mullvad-relay-selector-dependencies'
-rw-r--r--Cargo.lock5
-rw-r--r--mullvad-daemon/src/lib.rs15
-rw-r--r--mullvad-daemon/src/relay_list/mod.rs3
-rw-r--r--mullvad-daemon/src/relay_list/updater.rs (renamed from mullvad-relay-selector/src/updater.rs)33
-rw-r--r--mullvad-relay-selector/Cargo.toml5
-rw-r--r--mullvad-relay-selector/src/lib.rs253
-rw-r--r--test/Cargo.lock13
7 files changed, 191 insertions, 136 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f34ef3c6bd..969b5f371e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2013,18 +2013,13 @@ version = "0.0.0"
dependencies = [
"chrono",
"err-derive",
- "futures",
"ipnetwork",
"log",
- "mullvad-api",
"mullvad-types",
"once_cell",
- "parking_lot",
"rand 0.8.5",
"serde_json",
- "talpid-future",
"talpid-types",
- "tokio",
]
[[package]]
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index fde4fc534b..55d1fed16e 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -17,6 +17,7 @@ mod macos;
#[cfg(not(target_os = "android"))]
pub mod management_interface;
mod migrations;
+mod relay_list;
#[cfg(not(target_os = "android"))]
pub mod rpc_uniqueness_check;
pub mod runtime;
@@ -36,10 +37,7 @@ use futures::{
StreamExt,
};
use geoip::GeoIpHandler;
-use mullvad_relay_selector::{
- updater::{RelayListUpdater, RelayListUpdaterHandle},
- RelaySelector, SelectorConfig,
-};
+use mullvad_relay_selector::{RelaySelector, SelectorConfig};
#[cfg(target_os = "android")]
use mullvad_types::account::{PlayPurchase, PlayPurchasePaymentToken};
use mullvad_types::{
@@ -58,6 +56,7 @@ use mullvad_types::{
version::{AppVersion, AppVersionInfo},
wireguard::{PublicKey, QuantumResistantState, RotationInterval},
};
+use relay_list::updater::{self, RelayListUpdater, RelayListUpdaterHandle};
use settings::SettingsPersister;
#[cfg(target_os = "android")]
use std::os::unix::io::RawFd;
@@ -698,7 +697,11 @@ where
let app_version_info = version_check::load_cache(&cache_dir).await;
let initial_selector_config = new_selector_config(&settings);
- let relay_selector = RelaySelector::new(initial_selector_config, &resource_dir, &cache_dir);
+ let relay_selector = RelaySelector::new(
+ initial_selector_config,
+ resource_dir.join(updater::RELAYS_FILENAME),
+ cache_dir.join(updater::RELAYS_FILENAME),
+ );
let settings_relay_selector = relay_selector.clone();
settings.register_change_listener(move |settings| {
@@ -1569,7 +1572,7 @@ where
}
fn on_get_relay_locations(&mut self, tx: oneshot::Sender<RelayList>) {
- Self::oneshot_send(tx, self.relay_selector.get_locations(), "relay locations");
+ Self::oneshot_send(tx, self.relay_selector.get_relays(), "relay locations");
}
async fn on_update_relay_locations(&mut self) {
diff --git a/mullvad-daemon/src/relay_list/mod.rs b/mullvad-daemon/src/relay_list/mod.rs
new file mode 100644
index 0000000000..8936941035
--- /dev/null
+++ b/mullvad-daemon/src/relay_list/mod.rs
@@ -0,0 +1,3 @@
+//! Relay list
+
+pub mod updater;
diff --git a/mullvad-relay-selector/src/updater.rs b/mullvad-daemon/src/relay_list/updater.rs
index 9e86cbb413..317dbd45cd 100644
--- a/mullvad-relay-selector/src/updater.rs
+++ b/mullvad-daemon/src/relay_list/updater.rs
@@ -1,20 +1,19 @@
-use super::{Error, ParsedRelays};
use futures::{
channel::mpsc,
future::{Fuse, FusedFuture},
Future, FutureExt, SinkExt, StreamExt,
};
-use mullvad_api::{availability::ApiAvailabilityHandle, rest::MullvadRestHandle, RelayListProxy};
-use mullvad_types::relay_list::RelayList;
-use parking_lot::Mutex;
use std::{
path::{Path, PathBuf},
- sync::Arc,
time::{Duration, SystemTime, UNIX_EPOCH},
};
+use tokio::fs::File;
+
+use mullvad_api::{availability::ApiAvailabilityHandle, rest::MullvadRestHandle, RelayListProxy};
+use mullvad_relay_selector::{Error, RelaySelector};
+use mullvad_types::relay_list::RelayList;
use talpid_future::retry::{retry_future, ExponentialBackoff, Jittered};
use talpid_types::ErrorExt;
-use tokio::fs::File;
/// How often the updater should wake up to check the cache of the in-memory cache of relays.
/// This check is very cheap. The only reason to not have it very often is because if downloading
@@ -28,6 +27,9 @@ const DOWNLOAD_RETRY_STRATEGY: Jittered<ExponentialBackoff> = Jittered::jitter(
.max_delay(Some(Duration::from_secs(2 * 60 * 60))),
);
+/// Where the relay list is cached on disk.
+pub(crate) const RELAYS_FILENAME: &str = "relays.json";
+
#[derive(Clone)]
pub struct RelayListUpdaterHandle {
tx: mpsc::Sender<()>,
@@ -52,7 +54,7 @@ impl RelayListUpdaterHandle {
pub struct RelayListUpdater {
api_client: RelayListProxy,
cache_path: PathBuf,
- parsed_relays: Arc<Mutex<ParsedRelays>>,
+ relay_selector: RelaySelector,
on_update: Box<dyn Fn(&RelayList) + Send + 'static>,
last_check: SystemTime,
api_availability: ApiAvailabilityHandle,
@@ -60,7 +62,7 @@ pub struct RelayListUpdater {
impl RelayListUpdater {
pub fn spawn(
- selector: super::RelaySelector,
+ selector: RelaySelector,
api_handle: MullvadRestHandle,
cache_dir: &Path,
on_update: impl Fn(&RelayList) + Send + 'static,
@@ -70,8 +72,8 @@ impl RelayListUpdater {
let api_client = RelayListProxy::new(api_handle);
let updater = RelayListUpdater {
api_client,
- cache_path: cache_dir.join(super::RELAYS_FILENAME),
- parsed_relays: selector.parsed_relays,
+ cache_path: cache_dir.join(RELAYS_FILENAME),
+ relay_selector: selector,
on_update: Box::new(on_update),
last_check: UNIX_EPOCH,
api_availability,
@@ -91,7 +93,7 @@ impl RelayListUpdater {
futures::select! {
_check_update = next_check => {
if download_future.is_terminated() && self.should_update() {
- let tag = self.parsed_relays.lock().parsed_list.etag.clone();
+ let tag = self.relay_selector.etag();
download_future = Box::pin(Self::download_relay_list(self.api_availability.clone(), self.api_client.clone(), tag).fuse());
self.last_check = SystemTime::now();
}
@@ -104,7 +106,7 @@ impl RelayListUpdater {
cmd = cmd_rx.next() => {
match cmd {
Some(()) => {
- let tag = self.parsed_relays.lock().parsed_list.etag.clone();
+ let tag = self.relay_selector.etag();
download_future = Box::pin(Self::download_relay_list(self.api_availability.clone(), self.api_client.clone(), tag).fuse());
self.last_check = SystemTime::now();
},
@@ -139,7 +141,7 @@ impl RelayListUpdater {
/// Returns true if the current parsed_relays is older than UPDATE_INTERVAL
fn should_update(&mut self) -> bool {
- let last_check = std::cmp::max(self.parsed_relays.lock().last_updated(), self.last_check);
+ let last_check = std::cmp::max(self.relay_selector.last_updated(), self.last_check);
match SystemTime::now().duration_since(last_check) {
Ok(duration) => duration >= UPDATE_INTERVAL,
// If the clock is skewed we have no idea by how much or when the last update
@@ -178,9 +180,8 @@ impl RelayListUpdater {
);
}
- let mut parsed_relays = self.parsed_relays.lock();
- parsed_relays.update(new_relay_list);
- (self.on_update)(&parsed_relays.original_list);
+ self.relay_selector.set_relays(new_relay_list.clone());
+ (self.on_update)(&new_relay_list);
Ok(())
}
diff --git a/mullvad-relay-selector/Cargo.toml b/mullvad-relay-selector/Cargo.toml
index 078415f31a..e38b44bd13 100644
--- a/mullvad-relay-selector/Cargo.toml
+++ b/mullvad-relay-selector/Cargo.toml
@@ -13,17 +13,12 @@ workspace = true
[dependencies]
chrono = { workspace = true }
err-derive = { workspace = true }
-futures = "0.3"
ipnetwork = "0.16"
log = { workspace = true }
-parking_lot = "0.12.0"
rand = "0.8.5"
serde_json = "1.0"
-tokio = { workspace = true, features = ["fs", "io-util", "time"] }
-talpid-future = { path = "../talpid-future" }
talpid-types = { path = "../talpid-types" }
-mullvad-api = { path = "../mullvad-api" }
mullvad-types = { path = "../mullvad-types" }
[dev-dependencies]
diff --git a/mullvad-relay-selector/src/lib.rs b/mullvad-relay-selector/src/lib.rs
index f006dea56e..196f0c8eef 100644
--- a/mullvad-relay-selector/src/lib.rs
+++ b/mullvad-relay-selector/src/lib.rs
@@ -18,14 +18,13 @@ use mullvad_types::{
settings::Settings,
CustomTunnelEndpoint,
};
-use parking_lot::{Mutex, MutexGuard};
use rand::{seq::SliceRandom, Rng};
use std::{
collections::HashMap,
io,
net::{IpAddr, SocketAddr},
path::Path,
- sync::Arc,
+ sync::{Arc, Mutex, MutexGuard},
time::{self, SystemTime},
};
use talpid_types::{
@@ -39,10 +38,8 @@ use talpid_types::{
use matcher::{BridgeMatcher, EndpointMatcher, OpenVpnMatcher, RelayMatcher, WireguardMatcher};
mod matcher;
-pub mod updater;
const DATE_TIME_FORMAT_STR: &str = "%Y-%m-%d %H:%M:%S%.3f";
-const RELAYS_FILENAME: &str = "relays.json";
const WIREGUARD_EXIT_PORT: Constraint<u16> = Constraint::Only(51820);
const WIREGUARD_EXIT_IP_VERSION: Constraint<IpVersion> = Constraint::Only(IpVersion::V4);
@@ -109,6 +106,10 @@ impl ParsedRelays {
self.last_updated
}
+ pub fn etag(&self) -> Option<String> {
+ self.parsed_list.etag.clone()
+ }
+
fn set_overrides(&mut self, new_overrides: &[RelayOverride]) {
self.parsed_list = Self::parse_relay_list(&self.original_list, new_overrides);
self.overrides = new_overrides.to_vec();
@@ -124,15 +125,15 @@ impl ParsedRelays {
}
/// Try to read the relays from disk, preferring the newer ones.
- fn from_dir(
- cache_path: &Path,
- resource_path: &Path,
+ fn from_file(
+ cache_path: impl AsRef<Path>,
+ resource_path: impl AsRef<Path>,
overrides: &[RelayOverride],
) -> Result<Self, Error> {
// prefer the resource path's relay list if the cached one doesn't exist or was modified
// before the resource one was created.
- let cached_relays = Self::from_file(cache_path, overrides);
- let bundled_relays = match Self::from_file(resource_path, overrides) {
+ let cached_relays = Self::from_file_inner(cache_path, overrides);
+ let bundled_relays = match Self::from_file_inner(resource_path, overrides) {
Ok(bundled_relays) => bundled_relays,
Err(e) => {
log::error!("Failed to load bundled relays: {}", e);
@@ -151,7 +152,7 @@ impl ParsedRelays {
}
}
- fn from_file(path: impl AsRef<Path>, overrides: &[RelayOverride]) -> Result<Self, Error> {
+ fn from_file_inner(path: impl AsRef<Path>, overrides: &[RelayOverride]) -> Result<Self, Error> {
log::debug!("Reading relays from {}", path.as_ref().display());
let (last_modified, file) =
Self::open_file(path.as_ref()).map_err(Error::OpenRelayCache)?;
@@ -254,11 +255,13 @@ pub struct RelaySelector {
impl RelaySelector {
/// Returns a new `RelaySelector` backed by relays cached on disk.
- pub fn new(config: SelectorConfig, resource_dir: &Path, cache_dir: &Path) -> Self {
- let cache_path = cache_dir.join(RELAYS_FILENAME);
- let resource_path = resource_dir.join(RELAYS_FILENAME);
+ pub fn new(
+ config: SelectorConfig,
+ resource_path: impl AsRef<Path>,
+ cache_path: impl AsRef<Path>,
+ ) -> Self {
let unsynchronized_parsed_relays =
- ParsedRelays::from_dir(&cache_path, &resource_path, &config.relay_overrides)
+ ParsedRelays::from_file(&cache_path, &resource_path, &config.relay_overrides)
.unwrap_or_else(|error| {
log::error!(
"{}",
@@ -291,15 +294,34 @@ impl RelaySelector {
}
pub fn set_config(&mut self, config: SelectorConfig) {
- let mut parsed_relays = self.parsed_relays.lock();
- parsed_relays.set_overrides(&config.relay_overrides);
- *self.config.lock() = config;
+ self.set_overrides(&config.relay_overrides);
+ let mut config_mutex = self.config.lock().unwrap();
+ *config_mutex = config;
+ }
+
+ pub fn set_relays(&self, relays: RelayList) {
+ let mut parsed_relays = self.parsed_relays.lock().unwrap();
+ parsed_relays.update(relays);
+ }
+
+ fn set_overrides(&mut self, relay_overrides: &[RelayOverride]) {
+ let mut parsed_relays = self.parsed_relays.lock().unwrap();
+ parsed_relays.set_overrides(relay_overrides);
}
/// Returns all countries and cities. The cities in the object returned does not have any
/// relays in them.
- pub fn get_locations(&mut self) -> RelayList {
- self.parsed_relays.lock().original_list.clone()
+ pub fn get_relays(&mut self) -> RelayList {
+ let parsed_relays = self.parsed_relays.lock().unwrap();
+ parsed_relays.original_list.clone()
+ }
+
+ pub fn etag(&self) -> Option<String> {
+ self.parsed_relays.lock().unwrap().etag()
+ }
+
+ pub fn last_updated(&self) -> SystemTime {
+ self.parsed_relays.lock().unwrap().last_updated()
}
/// Returns a random relay and relay endpoint matching the current constraints.
@@ -314,17 +336,17 @@ impl RelaySelector {
),
Error,
> {
- let config = self.config.lock();
- match &config.relay_settings {
+ let config_mutex = self.config.lock().unwrap();
+ match &config_mutex.relay_settings {
RelaySettings::CustomTunnelEndpoint(custom_relay) => {
Ok((SelectedRelay::Custom(custom_relay.clone()), None, None))
}
RelaySettings::Normal(constraints) => {
let relay = self.get_tunnel_endpoint(
constraints,
- config.bridge_state,
+ config_mutex.bridge_state,
retry_attempt,
- &config.custom_lists,
+ &config_mutex.custom_lists,
)?;
let bridge = match relay.endpoint {
MullvadEndpoint::OpenVpn(endpoint)
@@ -335,7 +357,12 @@ impl RelaySelector {
.location
.as_ref()
.expect("Relay has no location set");
- self.get_bridge_for(&config, location, retry_attempt, &config.custom_lists)?
+ self.get_bridge_for(
+ &config_mutex,
+ location,
+ retry_attempt,
+ &config_mutex.custom_lists,
+ )?
}
_ => None,
};
@@ -344,7 +371,7 @@ impl RelaySelector {
let obfuscator_relay =
relay.entry_relay.as_ref().unwrap_or(&relay.exit_relay);
self.get_obfuscator_inner(
- &config,
+ &config_mutex,
obfuscator_relay,
endpoint,
retry_attempt,
@@ -405,7 +432,7 @@ impl RelaySelector {
}
let (openvpn_data, wireguard_data) = {
- let relays = self.parsed_relays.lock();
+ let relays = self.parsed_relays.lock().unwrap();
(
relays.parsed_list.openvpn.clone(),
relays.parsed_list.wireguard.clone(),
@@ -419,12 +446,14 @@ impl RelaySelector {
custom_lists,
);
- let parsed_relays = self.parsed_relays.lock();
- let mut matching_locations: Vec<Location> = matcher
- .filter_matching_relay_list(parsed_relays.relays())
- .into_iter()
- .filter_map(|relay| relay.location)
- .collect();
+ let mut matching_locations: Vec<Location> = {
+ let parsed_relays = self.parsed_relays.lock().unwrap();
+ matcher
+ .filter_matching_relay_list(parsed_relays.relays())
+ .into_iter()
+ .filter_map(|relay| relay.location)
+ .collect()
+ };
matching_locations.dedup_by(|a, b| a.has_same_city(b));
if matching_locations.is_empty() {
@@ -450,10 +479,10 @@ impl RelaySelector {
),
providers: relay_constraints.providers.clone(),
ownership: relay_constraints.ownership,
- endpoint_matcher: OpenVpnMatcher::new(
- relay_constraints.openvpn_constraints,
- self.parsed_relays.lock().parsed_list.openvpn.clone(),
- ),
+ endpoint_matcher: OpenVpnMatcher::new(relay_constraints.openvpn_constraints, {
+ let parsed_relays = self.parsed_relays.lock().unwrap();
+ parsed_relays.parsed_list.openvpn.clone()
+ }),
};
if relay_matcher.endpoint_matcher.constraints.port.is_any()
@@ -560,7 +589,10 @@ impl RelaySelector {
retry_attempt: u32,
custom_lists: &CustomListsSettings,
) -> Result<NormalSelectedRelay, Error> {
- let wg_endpoint_data = self.parsed_relays.lock().parsed_list.wireguard.clone();
+ let wg_endpoint_data = {
+ let parsed_relays = self.parsed_relays.lock().unwrap();
+ parsed_relays.parsed_list.wireguard.clone()
+ };
// NOTE: If not using multihop then `location` is set as the only location constraint.
// If using multihop then location is the exit constraint and
@@ -626,7 +658,7 @@ impl RelaySelector {
custom_lists: &CustomListsSettings,
) -> Result<NormalSelectedRelay, Error> {
let (openvpn_data, wireguard_data) = {
- let relays = self.parsed_relays.lock();
+ let relays = self.parsed_relays.lock().unwrap();
(
relays.parsed_list.openvpn.clone(),
relays.parsed_list.wireguard.clone(),
@@ -840,10 +872,13 @@ impl RelaySelector {
&self,
matcher: &RelayMatcher<WireguardMatcher>,
) -> Result<(Relay, MullvadWireguardEndpoint), Error> {
- let matching_relays: Vec<Relay> = matcher
- .filter_matching_relay_list(self.parsed_relays.lock().relays())
- .into_iter()
- .collect();
+ let matching_relays: Vec<Relay> = {
+ let parsed_relays = self.parsed_relays.lock().unwrap();
+ matcher
+ .filter_matching_relay_list(parsed_relays.relays())
+ .into_iter()
+ .collect()
+ };
let relay = self
.pick_random_relay(&matching_relays)
@@ -917,16 +952,24 @@ impl RelaySelector {
/// Returns a non-custom bridge based on the relay and bridge constraints, ignoring the bridge
/// state.
pub fn get_bridge_forced(&self) -> Option<CustomProxy> {
- let config = self.config.lock();
+ let config = self.config.lock().unwrap();
+ // let relay_settings = {
+ // let config = self.config.lock().unwrap();
+ // config.relay_settings.clone()
+ // };
let near_location = match &config.relay_settings {
RelaySettings::Normal(settings) => {
- self.get_relay_midpoint(settings, &config.custom_lists)
+ let custom_lists = {
+ // let config = self.config.lock().unwrap();
+ config.custom_lists.clone()
+ };
+ self.get_relay_midpoint(settings, &custom_lists)
}
_ => None,
};
-
- let constraints = match config.bridge_settings.resolve() {
+ let bridge_settings = &config.bridge_settings;
+ let constraints = match bridge_settings.resolve() {
Ok(ResolvedBridgeSettings::Normal(settings)) => InternalBridgeConstraints {
location: settings.location.clone(),
providers: settings.providers.clone(),
@@ -941,7 +984,8 @@ impl RelaySelector {
},
};
- self.get_proxy_settings(&constraints, near_location, &config.custom_lists)
+ let custom_lists = &config.custom_lists;
+ self.get_proxy_settings(&constraints, near_location, custom_lists)
.map(|(settings, _relay)| settings)
}
@@ -970,8 +1014,11 @@ impl RelaySelector {
ownership: constraints.ownership,
endpoint_matcher: BridgeMatcher(()),
};
- let matching_relays: Vec<Relay> =
- matcher.filter_matching_relay_list(self.parsed_relays.lock().relays());
+
+ let matching_relays: Vec<Relay> = {
+ let parsed_relays = self.parsed_relays.lock().unwrap();
+ matcher.filter_matching_relay_list(parsed_relays.relays())
+ };
if matching_relays.is_empty() {
return None;
@@ -1021,7 +1068,9 @@ impl RelaySelector {
self.pick_random_relay(&matching_relays).cloned()
};
relay.and_then(|relay| {
- self.pick_random_bridge(&self.parsed_relays.lock().parsed_list.bridge, &relay)
+ let parsed_relays = self.parsed_relays.lock().unwrap();
+ let bridge = &parsed_relays.parsed_list.bridge;
+ self.pick_random_bridge(bridge, &relay)
.map(|bridge| (bridge, relay.clone()))
})
}
@@ -1084,12 +1133,15 @@ impl RelaySelector {
endpoint: &MullvadWireguardEndpoint,
retry_attempt: u32,
) -> Option<SelectedObfuscator> {
- let udp2tcp_ports = &self
- .parsed_relays
- .lock()
- .parsed_list
- .wireguard
- .udp2tcp_ports;
+ let udp2tcp_ports = {
+ &self
+ .parsed_relays
+ .lock()
+ .unwrap()
+ .parsed_list
+ .wireguard
+ .udp2tcp_ports
+ };
let udp2tcp_endpoint = if obfuscation_settings.port.is_only() {
udp2tcp_ports
.iter()
@@ -1115,18 +1167,22 @@ impl RelaySelector {
providers: &Constraint<Providers>,
ownership: Constraint<Ownership>,
) -> (Constraint<u16>, TransportProtocol, TunnelType) {
- let parsed_relays = self.parsed_relays.lock();
- let mut active_location_relays = parsed_relays.relays().filter(|relay| {
- relay.active
- && location.matches_with_opts(relay, true)
- && providers.matches(relay)
- && ownership.matches(relay)
- });
- let location_supports_wg = active_location_relays
- .clone()
- .any(|relay| matches!(relay.endpoint_data, RelayEndpointData::Wireguard(_)));
- let location_supports_openvpn = active_location_relays
- .any(|relay| matches!(relay.endpoint_data, RelayEndpointData::Openvpn));
+ let (location_supports_wg, location_supports_openvpn) = {
+ let parsed_relays = self.parsed_relays.lock().unwrap();
+ let mut active_location_relays = parsed_relays.relays().filter(|relay| {
+ relay.active
+ && location.matches_with_opts(relay, true)
+ && providers.matches(relay)
+ && ownership.matches(relay)
+ });
+ let location_supports_wg = active_location_relays
+ .clone()
+ .any(|relay| matches!(relay.endpoint_data, RelayEndpointData::Wireguard(_)));
+ let location_supports_openvpn = active_location_relays
+ .any(|relay| matches!(relay.endpoint_data, RelayEndpointData::Openvpn));
+
+ (location_supports_wg, location_supports_openvpn)
+ };
match (location_supports_wg, location_supports_openvpn) {
(true, true) | (false, false) => Self::preferred_tunnel_constraints(retry_attempt),
(true, false) => {
@@ -1191,10 +1247,13 @@ impl RelaySelector {
&self,
matcher: &RelayMatcher<T>,
) -> Result<NormalSelectedRelay, Error> {
- let matching_relays: Vec<Relay> = matcher
- .filter_matching_relay_list(self.parsed_relays.lock().relays())
- .into_iter()
- .collect();
+ let matching_relays: Vec<Relay> = {
+ let parsed_relays = self.parsed_relays.lock().unwrap();
+ matcher
+ .filter_matching_relay_list(parsed_relays.relays())
+ .into_iter()
+ .collect()
+ };
self.pick_random_relay(&matching_relays)
.and_then(|selected_relay| {
@@ -1264,9 +1323,15 @@ impl RelaySelector {
}
fn wireguard_exit_matcher(&self) -> WireguardMatcher {
- let mut tunnel = WireguardMatcher::from_endpoint(
- self.parsed_relays.lock().parsed_list.wireguard.clone(),
- );
+ let wg = {
+ self.parsed_relays
+ .lock()
+ .unwrap()
+ .parsed_list
+ .wireguard
+ .clone()
+ };
+ let mut tunnel = WireguardMatcher::from_endpoint(wg);
tunnel.ip_version = WIREGUARD_EXIT_IP_VERSION;
tunnel.port = WIREGUARD_EXIT_PORT;
tunnel
@@ -1347,7 +1412,7 @@ mod test {
endpoint: &MullvadWireguardEndpoint,
retry_attempt: u32,
) -> Result<Option<SelectedObfuscator>, Error> {
- self.get_obfuscator_inner(&self.config.lock(), relay, endpoint, retry_attempt)
+ self.get_obfuscator_inner(&self.config.lock().unwrap(), relay, endpoint, retry_attempt)
}
}
@@ -1974,10 +2039,12 @@ mod test {
assert!(result.entry_relay.is_none());
assert!(matches!(result.endpoint, MullvadEndpoint::Wireguard { .. }));
- relay_selector.config.lock().obfuscation_settings = ObfuscationSettings {
- selected_obfuscation: SelectedObfuscation::Udp2Tcp,
- ..ObfuscationSettings::default()
- };
+ {
+ relay_selector.config.lock().unwrap().obfuscation_settings = ObfuscationSettings {
+ selected_obfuscation: SelectedObfuscation::Udp2Tcp,
+ ..ObfuscationSettings::default()
+ };
+ }
let obfs_config = relay_selector
.get_obfuscator(&result.exit_relay, result.endpoint.unwrap_wireguard(), 0)
@@ -2003,10 +2070,12 @@ mod test {
assert!(result.entry_relay.is_none());
assert!(matches!(result.endpoint, MullvadEndpoint::Wireguard { .. }));
- relay_selector.config.lock().obfuscation_settings = ObfuscationSettings {
- selected_obfuscation: SelectedObfuscation::Auto,
- ..ObfuscationSettings::default()
- };
+ {
+ relay_selector.config.lock().unwrap().obfuscation_settings = ObfuscationSettings {
+ selected_obfuscation: SelectedObfuscation::Auto,
+ ..ObfuscationSettings::default()
+ };
+ }
assert!(relay_selector
.get_obfuscator(&result.exit_relay, result.endpoint.unwrap_wireguard(), 0,)
@@ -2030,10 +2099,12 @@ mod test {
const TCP2UDP_PORTS: [u16; 3] = [80, 443, 5001];
- relay_selector.config.lock().obfuscation_settings = ObfuscationSettings {
- selected_obfuscation: SelectedObfuscation::Udp2Tcp,
- ..ObfuscationSettings::default()
- };
+ {
+ relay_selector.config.lock().unwrap().obfuscation_settings = ObfuscationSettings {
+ selected_obfuscation: SelectedObfuscation::Udp2Tcp,
+ ..ObfuscationSettings::default()
+ };
+ }
for attempt in 0..1000 {
let result = relay_selector
@@ -2123,7 +2194,7 @@ mod test {
Constraint::Only(TunnelType::OpenVpn),
] {
{
- let mut config = relay_selector.config.lock();
+ let mut config = relay_selector.config.lock().unwrap();
config.relay_settings = RelaySettings::Normal(RelayConstraints {
tunnel_protocol,
location: Constraint::Only(LocationConstraint::from(
@@ -2194,7 +2265,7 @@ mod test {
let relay_selector = RelaySelector::from_list(SelectorConfig::default(), RELAYS.clone());
{
- let mut config = relay_selector.config.lock();
+ let mut config = relay_selector.config.lock().unwrap();
config.bridge_state = BridgeState::Auto;
}
@@ -2207,7 +2278,7 @@ mod test {
// Verify that bridges are ignored when tunnel protocol is WireGuard
{
- let mut config = relay_selector.config.lock();
+ let mut config = relay_selector.config.lock().unwrap();
config.relay_settings = RelaySettings::Normal(RelayConstraints {
tunnel_protocol: Constraint::Only(TunnelType::Wireguard),
..RelayConstraints::default()
diff --git a/test/Cargo.lock b/test/Cargo.lock
index 9be666c178..19d0d98bda 100644
--- a/test/Cargo.lock
+++ b/test/Cargo.lock
@@ -1789,17 +1789,12 @@ version = "0.0.0"
dependencies = [
"chrono",
"err-derive",
- "futures",
"ipnetwork 0.16.0",
"log",
- "mullvad-api",
"mullvad-types",
- "parking_lot 0.12.1",
"rand 0.8.5",
"serde_json",
- "talpid-future",
"talpid-types",
- "tokio",
]
[[package]]
@@ -3047,14 +3042,6 @@ dependencies = [
]
[[package]]
-name = "talpid-future"
-version = "0.0.0"
-dependencies = [
- "rand 0.8.5",
- "talpid-time",
-]
-
-[[package]]
name = "talpid-platform-metadata"
version = "0.0.0"
dependencies = [