summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoakim Hulthe <joakim.hulthe@mullvad.net>2024-08-13 17:16:08 +0200
committerJoakim Hulthe <joakim.hulthe@mullvad.net>2024-09-17 11:29:26 +0200
commit7b19fda8f280378a8237ed60e63c266188266711 (patch)
treefeefd87feaccb970aad5501ad21a21ec8a30d4c0
parent3373ca2c3f0df02da4ade50815f5654bc5dd7abf (diff)
downloadmullvadvpn-7b19fda8f280378a8237ed60e63c266188266711.tar.xz
mullvadvpn-7b19fda8f280378a8237ed60e63c266188266711.zip
Remove Option from Relay::location
-rw-r--r--mullvad-api/src/relay_list.rs2
-rw-r--r--mullvad-cli/src/cmds/relay.rs23
-rw-r--r--mullvad-daemon/src/tunnel.rs4
-rw-r--r--mullvad-management-interface/src/types/conversions/relay_list.rs34
-rw-r--r--mullvad-relay-selector/src/relay_selector/mod.rs7
-rw-r--r--mullvad-relay-selector/src/relay_selector/parsed_relays.rs4
-rw-r--r--mullvad-relay-selector/tests/relay_selector.rs30
-rw-r--r--mullvad-types/src/relay_constraints.rs21
-rw-r--r--mullvad-types/src/relay_list.rs11
-rw-r--r--test/test-manager/src/tests/dns.rs2
-rw-r--r--test/test-manager/src/tests/helpers.rs27
-rw-r--r--test/test-manager/src/tests/relay_ip_overrides.rs7
-rw-r--r--test/test-manager/src/tests/tunnel.rs5
13 files changed, 89 insertions, 88 deletions
diff --git a/mullvad-api/src/relay_list.rs b/mullvad-api/src/relay_list.rs
index afe71c829d..5f2b2d6d81 100644
--- a/mullvad-api/src/relay_list.rs
+++ b/mullvad-api/src/relay_list.rs
@@ -162,7 +162,7 @@ fn into_mullvad_relay(
provider: relay.provider,
weight: relay.weight,
endpoint_data,
- location: Some(location),
+ location,
}
}
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs
index 68292c0ad1..eaaa283411 100644
--- a/mullvad-cli/src/cmds/relay.rs
+++ b/mullvad-cli/src/cmds/relay.rs
@@ -4,7 +4,7 @@ use itertools::Itertools;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{
constraints::{Constraint, Match},
- location::{CountryCode, Location},
+ location::CountryCode,
relay_constraints::{
GeographicLocationConstraint, LocationConstraint, LocationConstraintFormatter,
OpenVpnConstraints, Ownership, Provider, Providers, RelayConstraints, RelayOverride,
@@ -921,15 +921,11 @@ fn parse_transport_port(
fn relay_to_geographical_constraint(
relay: mullvad_types::relay_list::Relay,
-) -> Option<GeographicLocationConstraint> {
- relay.location.map(
- |Location {
- country_code,
- city_code,
- ..
- }| {
- GeographicLocationConstraint::Hostname(country_code, city_code, relay.hostname)
- },
+) -> GeographicLocationConstraint {
+ GeographicLocationConstraint::Hostname(
+ relay.location.country_code,
+ relay.location.city_code,
+ relay.hostname,
)
}
@@ -952,10 +948,9 @@ pub async fn resolve_location_constraint(
.find(|relay| relay.hostname.to_lowercase() == location_constraint_args.country)
{
if relay_filter(&matching_relay) {
- Ok(Constraint::Only(
- relay_to_geographical_constraint(matching_relay)
- .context("Selected relay did not contain a valid location")?,
- ))
+ Ok(Constraint::Only(relay_to_geographical_constraint(
+ matching_relay,
+ )))
} else {
bail!(
"The relay `{}` is not valid for this operation",
diff --git a/mullvad-daemon/src/tunnel.rs b/mullvad-daemon/src/tunnel.rs
index 72ec5087fc..73bda59635 100644
--- a/mullvad-daemon/src/tunnel.rs
+++ b/mullvad-daemon/src/tunnel.rs
@@ -128,7 +128,7 @@ impl ParametersGenerator {
hostname = exit.hostname.clone();
obfuscator_hostname = take_hostname(obfuscator);
bridge_hostname = None;
- location = exit.location.as_ref().cloned().unwrap();
+ location = exit.location.clone();
}
#[cfg(not(target_os = "android"))]
LastSelectedRelays::OpenVpn { relay, bridge, .. } => {
@@ -136,7 +136,7 @@ impl ParametersGenerator {
bridge_hostname = take_hostname(bridge);
entry_hostname = None;
obfuscator_hostname = None;
- location = relay.location.as_ref().cloned().unwrap();
+ location = relay.location.clone();
}
};
diff --git a/mullvad-management-interface/src/types/conversions/relay_list.rs b/mullvad-management-interface/src/types/conversions/relay_list.rs
index a8b69d87fa..11718973c1 100644
--- a/mullvad-management-interface/src/types/conversions/relay_list.rs
+++ b/mullvad-management-interface/src/types/conversions/relay_list.rs
@@ -144,13 +144,13 @@ impl From<mullvad_types::relay_list::Relay> for proto::Relay {
)),
_ => None,
},
- location: relay.location.map(|location| proto::Location {
- country: location.country,
- country_code: location.country_code,
- city: location.city,
- city_code: location.city_code,
- latitude: location.latitude,
- longitude: location.longitude,
+ location: Some(proto::Location {
+ country: relay.location.country,
+ country_code: relay.location.country_code,
+ city: relay.location.city,
+ city_code: relay.location.city_code,
+ latitude: relay.location.latitude,
+ longitude: relay.location.longitude,
}),
}
}
@@ -299,14 +299,18 @@ impl TryFrom<proto::Relay> for mullvad_types::relay_list::Relay {
provider: relay.provider,
weight: relay.weight,
endpoint_data,
- location: relay.location.map(|location| MullvadLocation {
- country: location.country,
- country_code: location.country_code,
- city: location.city,
- city_code: location.city_code,
- latitude: location.latitude,
- longitude: location.longitude,
- }),
+ location: relay
+ .location
+ .map(|location| MullvadLocation {
+ country: location.country,
+ country_code: location.country_code,
+ city: location.city,
+ city_code: location.city_code,
+ latitude: location.latitude,
+ longitude: location.longitude,
+ })
+ .ok_or("missing relay location")
+ .map_err(FromProtobufTypeError::InvalidArgument)?,
})
}
}
diff --git a/mullvad-relay-selector/src/relay_selector/mod.rs b/mullvad-relay-selector/src/relay_selector/mod.rs
index 45268a8eae..f822f2045d 100644
--- a/mullvad-relay-selector/src/relay_selector/mod.rs
+++ b/mullvad-relay-selector/src/relay_selector/mod.rs
@@ -994,10 +994,9 @@ impl RelaySelector {
Err(Error::NoBridge)
}
TransportProtocol::Tcp => {
- let location = relay.location.as_ref().ok_or(Error::NoRelay)?;
Self::get_bridge_for(
bridge_query,
- location,
+ &relay.location,
// FIXME: This is temporary while talpid-core only supports TCP proxies
TransportProtocol::Tcp,
parsed_relays,
@@ -1077,7 +1076,7 @@ impl RelaySelector {
let matching_bridges: Vec<RelayWithDistance> = relays
.into_iter()
.map(|relay| RelayWithDistance {
- distance: relay.location.as_ref().unwrap().distance_from(&location),
+ distance: relay.location.distance_from(&location),
relay,
})
.sorted_unstable_by_key(|relay| relay.distance as usize)
@@ -1115,7 +1114,7 @@ impl RelaySelector {
let matching_locations: Vec<Location> =
filter_matching_relay_list(query, parsed_relays, custom_lists)
.into_iter()
- .filter_map(|relay| relay.location)
+ .map(|relay| relay.location)
.unique_by(|location| location.city.clone())
.collect();
diff --git a/mullvad-relay-selector/src/relay_selector/parsed_relays.rs b/mullvad-relay-selector/src/relay_selector/parsed_relays.rs
index 35c78a52aa..3a1663d9dd 100644
--- a/mullvad-relay-selector/src/relay_selector/parsed_relays.rs
+++ b/mullvad-relay-selector/src/relay_selector/parsed_relays.rs
@@ -168,14 +168,14 @@ impl ParsedRelays {
for city in &mut country.cities {
for relay in &mut city.relays {
// Append location data
- relay.location = Some(Location {
+ relay.location = Location {
country: country.name.clone(),
country_code: country.code.clone(),
city: city.name.clone(),
city_code: city.code.clone(),
latitude: city.latitude,
longitude: city.longitude,
- });
+ };
// Append overrides
if let Some(overrides) = remaining_overrides.remove(&relay.hostname) {
diff --git a/mullvad-relay-selector/tests/relay_selector.rs b/mullvad-relay-selector/tests/relay_selector.rs
index bdfd8e19d0..1349b5af26 100644
--- a/mullvad-relay-selector/tests/relay_selector.rs
+++ b/mullvad-relay-selector/tests/relay_selector.rs
@@ -21,6 +21,7 @@ use mullvad_relay_selector::{
use mullvad_types::{
constraints::Constraint,
endpoint::MullvadEndpoint,
+ location::Location,
relay_constraints::{
BridgeConstraints, BridgeState, GeographicLocationConstraint, Ownership, Providers,
RelayOverride, TransportPort,
@@ -32,6 +33,15 @@ use mullvad_types::{
},
};
+static DUMMY_LOCATION: LazyLock<Location> = LazyLock::new(|| Location {
+ country: "Sweden".to_string(),
+ country_code: "se".to_string(),
+ city: "Gothenburg".to_string(),
+ city_code: "got".to_string(),
+ latitude: 57.71,
+ longitude: 11.97,
+});
+
static RELAYS: LazyLock<RelayList> = LazyLock::new(|| RelayList {
etag: None,
countries: vec![RelayListCountry {
@@ -62,7 +72,7 @@ static RELAYS: LazyLock<RelayList> = LazyLock::new(|| RelayList {
daita: true,
shadowsocks_extra_addr_in: vec![],
}),
- location: None,
+ location: DUMMY_LOCATION.clone(),
},
Relay {
hostname: "se10-wireguard".to_string(),
@@ -83,7 +93,7 @@ static RELAYS: LazyLock<RelayList> = LazyLock::new(|| RelayList {
daita: false,
shadowsocks_extra_addr_in: vec![],
}),
- location: None,
+ location: DUMMY_LOCATION.clone(),
},
Relay {
hostname: "se-got-001".to_string(),
@@ -97,7 +107,7 @@ static RELAYS: LazyLock<RelayList> = LazyLock::new(|| RelayList {
provider: "provider2".to_string(),
weight: 1,
endpoint_data: RelayEndpointData::Openvpn,
- location: None,
+ location: DUMMY_LOCATION.clone(),
},
Relay {
hostname: "se-got-002".to_string(),
@@ -111,7 +121,7 @@ static RELAYS: LazyLock<RelayList> = LazyLock::new(|| RelayList {
provider: "provider0".to_string(),
weight: 1,
endpoint_data: RelayEndpointData::Openvpn,
- location: None,
+ location: DUMMY_LOCATION.clone(),
},
Relay {
hostname: "se-got-br-001".to_string(),
@@ -125,7 +135,7 @@ static RELAYS: LazyLock<RelayList> = LazyLock::new(|| RelayList {
provider: "provider3".to_string(),
weight: 1,
endpoint_data: RelayEndpointData::Bridge,
- location: None,
+ location: DUMMY_LOCATION.clone(),
},
SHADOWSOCKS_RELAY.clone(),
],
@@ -209,7 +219,7 @@ static SHADOWSOCKS_RELAY: LazyLock<Relay> = LazyLock::new(|| Relay {
daita: false,
shadowsocks_extra_addr_in: SHADOWSOCKS_RELAY_EXTRA_ADDRS.to_vec(),
}),
- location: None,
+ location: DUMMY_LOCATION.clone(),
});
const SHADOWSOCKS_RELAY_IPV4: Ipv4Addr = Ipv4Addr::new(123, 123, 123, 1);
const SHADOWSOCKS_RELAY_IPV6: Ipv6Addr = Ipv6Addr::new(0x123, 0, 0, 0, 0, 0, 0, 2);
@@ -497,7 +507,7 @@ fn test_wireguard_entry() {
daita: false,
shadowsocks_extra_addr_in: vec![],
}),
- location: None,
+ location: DUMMY_LOCATION.clone(),
},
Relay {
hostname: "se10-wireguard".to_string(),
@@ -518,7 +528,7 @@ fn test_wireguard_entry() {
daita: false,
shadowsocks_extra_addr_in: vec![],
}),
- location: None,
+ location: DUMMY_LOCATION.clone(),
},
],
}],
@@ -1169,7 +1179,7 @@ fn test_include_in_country() {
shadowsocks_extra_addr_in: vec![],
daita: false,
}),
- location: None,
+ location: DUMMY_LOCATION.clone(),
},
Relay {
hostname: "se10-wireguard".to_string(),
@@ -1190,7 +1200,7 @@ fn test_include_in_country() {
shadowsocks_extra_addr_in: vec![],
daita: false,
}),
- location: None,
+ location: DUMMY_LOCATION.clone(),
},
],
}],
diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs
index f3e38adc79..2b3d5099d2 100644
--- a/mullvad-types/src/relay_constraints.rs
+++ b/mullvad-types/src/relay_constraints.rs
@@ -210,21 +210,18 @@ impl GeographicLocationConstraint {
impl Match<Relay> for GeographicLocationConstraint {
fn matches(&self, relay: &Relay) -> bool {
match self {
- GeographicLocationConstraint::Country(ref country) => relay
- .location
- .as_ref()
- .map_or(false, |loc| loc.country_code == *country),
+ GeographicLocationConstraint::Country(ref country) => {
+ relay.location.country_code == *country
+ }
GeographicLocationConstraint::City(ref country, ref city) => {
- relay.location.as_ref().map_or(false, |loc| {
- loc.country_code == *country && loc.city_code == *city
- })
+ let loc = &relay.location;
+ loc.country_code == *country && loc.city_code == *city
}
GeographicLocationConstraint::Hostname(ref country, ref city, ref hostname) => {
- relay.location.as_ref().map_or(false, |loc| {
- loc.country_code == *country
- && loc.city_code == *city
- && relay.hostname == *hostname
- })
+ let loc = &relay.location;
+ loc.country_code == *country
+ && loc.city_code == *city
+ && relay.hostname == *hostname
}
}
}
diff --git a/mullvad-types/src/relay_list.rs b/mullvad-types/src/relay_list.rs
index 1693720d4a..afe8ba6378 100644
--- a/mullvad-types/src/relay_list.rs
+++ b/mullvad-types/src/relay_list.rs
@@ -90,7 +90,7 @@ pub struct Relay {
pub provider: String,
pub weight: u64,
pub endpoint_data: RelayEndpointData,
- pub location: Option<Location>,
+ pub location: Location,
}
impl Relay {
@@ -134,7 +134,14 @@ impl PartialEq for Relay {
/// # daita: false,
/// # shadowsocks_extra_addr_in: vec![],
/// # }),
- /// # location: None,
+ /// # location: mullvad_types::location::Location {
+ /// # country: "Sweden".to_string(),
+ /// # country_code: "se".to_string(),
+ /// # city: "Gothenburg".to_string(),
+ /// # city_code: "got".to_string(),
+ /// # latitude: 57.71,
+ /// # longitude: 11.97,
+ /// # },
/// };
///
/// let mut different_relay = relay.clone();
diff --git a/test/test-manager/src/tests/dns.rs b/test/test-manager/src/tests/dns.rs
index d7ea3d021d..69f98450ca 100644
--- a/test/test-manager/src/tests/dns.rs
+++ b/test/test-manager/src/tests/dns.rs
@@ -642,7 +642,7 @@ async fn connect_local_wg_relay(mullvad_client: &mut MullvadProxyClient) -> Resu
.set_quantum_resistant_tunnel(QuantumResistantState::Off)
.await?;
mullvad_client
- .set_daita_settings(DaitaSettings { enabled: false })
+ .set_daita_settings(DaitaSettings::default())
.await?;
let peer_addr: SocketAddr = SocketAddr::new(
diff --git a/test/test-manager/src/tests/helpers.rs b/test/test-manager/src/tests/helpers.rs
index 6c51b1f185..3eb0be0cc2 100644
--- a/test/test-manager/src/tests/helpers.rs
+++ b/test/test-manager/src/tests/helpers.rs
@@ -17,7 +17,6 @@ use mullvad_relay_selector::{
};
use mullvad_types::{
constraints::Constraint,
- location::Location,
relay_constraints::{
GeographicLocationConstraint, LocationConstraint, RelayConstraints, RelaySettings,
},
@@ -710,7 +709,7 @@ pub async fn constrain_to_relay(
..
}
| GetRelay::OpenVpn { exit, .. } => {
- let location = into_constraint(&exit)?;
+ let location = into_constraint(&exit);
let (mut relay_constraints, ..) = query.into_settings();
relay_constraints.location = location;
Ok((exit, relay_constraints))
@@ -736,22 +735,14 @@ pub async fn constrain_to_relay(
/// # Panics
///
/// The relay must have a location set.
-pub fn into_constraint(relay: &Relay) -> anyhow::Result<Constraint<LocationConstraint>> {
- relay
- .location
- .as_ref()
- .map(
- |Location {
- country_code,
- city_code,
- ..
- }| {
- GeographicLocationConstraint::hostname(country_code, city_code, &relay.hostname)
- },
- )
- .map(LocationConstraint::Location)
- .map(Constraint::Only)
- .ok_or(anyhow!("relay is missing location"))
+pub fn into_constraint(relay: &Relay) -> Constraint<LocationConstraint> {
+ let constraint = GeographicLocationConstraint::hostname(
+ relay.location.country_code.clone(),
+ relay.location.city_code.clone(),
+ &relay.hostname,
+ );
+
+ Constraint::Only(LocationConstraint::Location(constraint))
}
/// Ping monitoring made easy!
diff --git a/test/test-manager/src/tests/relay_ip_overrides.rs b/test/test-manager/src/tests/relay_ip_overrides.rs
index 48df8ff0e4..3805412ee9 100644
--- a/test/test-manager/src/tests/relay_ip_overrides.rs
+++ b/test/test-manager/src/tests/relay_ip_overrides.rs
@@ -298,12 +298,7 @@ async fn pick_a_relay(
let relay_ip = relay.ipv4_addr_in;
let hostname = relay.hostname.clone();
- let city = relay
- .location
- .as_ref()
- .ok_or(anyhow!("Got Relay with an unknown location"))?
- .city_code
- .clone();
+ let city = relay.location.city_code.clone();
log::info!("selected {hostname} ({relay_ip})");
let location = GeographicLocationConstraint::Hostname(country, city, hostname.clone()).into();
diff --git a/test/test-manager/src/tests/tunnel.rs b/test/test-manager/src/tests/tunnel.rs
index 575339c5a8..f5d8f6c959 100644
--- a/test/test-manager/src/tests/tunnel.rs
+++ b/test/test-manager/src/tests/tunnel.rs
@@ -410,7 +410,10 @@ pub async fn test_daita(
.await?;
mullvad_client
- .set_daita_settings(wireguard::DaitaSettings { enabled: true })
+ .set_daita_settings(wireguard::DaitaSettings {
+ enabled: true,
+ use_anywhere: false,
+ })
.await
.context("Failed to enable daita")?;