Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Intersection trait and implement it on RelayConstraints #5835

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ chrono = { version = "0.4.26", default-features = false}
clap = { version = "4.4.18", features = ["cargo", "derive"] }
once_cell = "1.13"

# Test dependencies
proptest = "1.4"

[profile.release]
opt-level = 3
Expand Down
5 changes: 3 additions & 2 deletions mullvad-cli/src/cmds/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use anyhow::{bail, Result};
use clap::Subcommand;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{
constraints::Constraint,
relay_constraints::{
BridgeConstraintsFormatter, BridgeState, BridgeType, Constraint, LocationConstraint,
Ownership, Provider, Providers,
BridgeConstraintsFormatter, BridgeState, BridgeType, LocationConstraint, Ownership,
Provider, Providers,
},
relay_list::RelayEndpointData,
};
Expand Down
3 changes: 1 addition & 2 deletions mullvad-cli/src/cmds/custom_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use anyhow::{anyhow, bail, Result};
use clap::Subcommand;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{
relay_constraints::{Constraint, GeographicLocationConstraint},
relay_list::RelayList,
constraints::Constraint, relay_constraints::GeographicLocationConstraint, relay_list::RelayList,
};

#[derive(Subcommand, Debug)]
Expand Down
5 changes: 4 additions & 1 deletion mullvad-cli/src/cmds/debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use anyhow::Result;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::relay_constraints::{Constraint, RelayConstraints, RelaySettings};
use mullvad_types::{
constraints::Constraint,
relay_constraints::{RelayConstraints, RelaySettings},
};

#[derive(clap::Subcommand, Debug)]
pub enum DebugCommands {
Expand Down
5 changes: 3 additions & 2 deletions mullvad-cli/src/cmds/obfuscation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::Result;
use clap::Subcommand;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::relay_constraints::{
Constraint, ObfuscationSettings, SelectedObfuscation, Udp2TcpObfuscationSettings,
use mullvad_types::{
constraints::Constraint,
relay_constraints::{ObfuscationSettings, SelectedObfuscation, Udp2TcpObfuscationSettings},
};

#[derive(Subcommand, Debug)]
Expand Down
9 changes: 5 additions & 4 deletions mullvad-cli/src/cmds/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use clap::Subcommand;
use itertools::Itertools;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{
constraints::{Constraint, Match},
location::{CountryCode, Location},
relay_constraints::{
Constraint, GeographicLocationConstraint, LocationConstraint, LocationConstraintFormatter,
Match, OpenVpnConstraints, Ownership, Provider, Providers, RelayConstraints, RelayOverride,
GeographicLocationConstraint, LocationConstraint, LocationConstraintFormatter,
OpenVpnConstraints, Ownership, Provider, Providers, RelayConstraints, RelayOverride,
RelaySettings, TransportPort, WireguardConstraints,
},
relay_list::{RelayEndpointData, RelayListCountry},
Expand Down Expand Up @@ -318,7 +319,7 @@ impl Relay {

print_option!(
"Multihop state",
if constraints.wireguard_constraints.use_multihop {
if constraints.wireguard_constraints.multihop() {
"enabled"
} else {
"disabled"
Expand Down Expand Up @@ -679,7 +680,7 @@ impl Relay {
wireguard_constraints.ip_version = ipv;
}
if let Some(use_multihop) = use_multihop {
wireguard_constraints.use_multihop = *use_multihop;
wireguard_constraints.use_multihop(*use_multihop);
}
match entry_location {
Some(EntryArgs::Location(location_args)) => {
Expand Down
3 changes: 2 additions & 1 deletion mullvad-cli/src/cmds/relay_constraints.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use clap::Args;
use mullvad_types::{
constraints::Constraint,
location::{CityCode, CountryCode, Hostname},
relay_constraints::{Constraint, GeographicLocationConstraint, LocationConstraint},
relay_constraints::{GeographicLocationConstraint, LocationConstraint},
};

#[derive(Args, Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion mullvad-cli/src/cmds/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use clap::Subcommand;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{
relay_constraints::Constraint,
constraints::Constraint,
wireguard::{QuantumResistantState, RotationInterval, DEFAULT_ROTATION_INTERVAL},
};

Expand Down
7 changes: 3 additions & 4 deletions mullvad-daemon/src/custom_list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{new_selector_config, Daemon, Error, EventListener};
use mullvad_types::{
constraints::Constraint,
custom_list::{CustomList, Id},
relay_constraints::{
BridgeState, Constraint, LocationConstraint, RelaySettings, ResolvedBridgeSettings,
},
relay_constraints::{BridgeState, LocationConstraint, RelaySettings, ResolvedBridgeSettings},
};
use talpid_types::net::TunnelType;

Expand Down Expand Up @@ -133,7 +132,7 @@ where
{
match endpoint.tunnel_type {
TunnelType::Wireguard => {
if relay_settings.wireguard_constraints.use_multihop {
if relay_settings.wireguard_constraints.multihop() {
if let Constraint::Only(LocationConstraint::CustomList { list_id }) =
&relay_settings.wireguard_constraints.entry_location
{
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ where
// Note that `Constraint::Any` corresponds to just IPv4
matches!(
relay_constraints.wireguard_constraints.ip_version,
mullvad_types::relay_constraints::Constraint::Only(IpVersion::V6)
mullvad_types::constraints::Constraint::Only(IpVersion::V6)
)
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/migrations/v1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Result;
use mullvad_types::{relay_constraints::Constraint, settings::SettingsVersion};
use mullvad_types::{constraints::Constraint, settings::SettingsVersion};
use serde::{Deserialize, Serialize};

// ======================================================
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/migrations/v4.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Error, Result};
use mullvad_types::{relay_constraints::Constraint, settings::SettingsVersion};
use mullvad_types::{constraints::Constraint, settings::SettingsVersion};
use serde::{Deserialize, Serialize};

// ======================================================
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/migrations/v5.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Error, Result};
use mullvad_types::{relay_constraints::Constraint, settings::SettingsVersion};
use mullvad_types::{constraints::Constraint, settings::SettingsVersion};
use serde::{Deserialize, Serialize};

// ======================================================
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/migrations/v6.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Error, Result};
use mullvad_types::{relay_constraints::Constraint, settings::SettingsVersion};
use mullvad_types::{constraints::Constraint, settings::SettingsVersion};
use serde::{Deserialize, Serialize};

// ======================================================
Expand Down
13 changes: 5 additions & 8 deletions mullvad-daemon/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,13 @@ impl<'a> Display for SettingsSummary<'a> {
write!(f, ", wg ip version: {ip_version}")?;
}

let multihop = matches!(
relay_settings,
let multihop = match relay_settings {
RelaySettings::Normal(RelayConstraints {
wireguard_constraints: WireguardConstraints {
use_multihop: true,
..
},
wireguard_constraints,
..
})
);
}) => wireguard_constraints.multihop(),
_ => false,
};

write!(
f,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::types::{conversions::net::try_tunnel_type_from_i32, proto, FromProtobufTypeError};
use mullvad_types::{
custom_list::Id,
relay_constraints::{Constraint, GeographicLocationConstraint},
constraints::Constraint, custom_list::Id, relay_constraints::GeographicLocationConstraint,
};
use std::str::FromStr;
use talpid_types::net::proxy::CustomProxy;
Expand Down Expand Up @@ -29,7 +28,7 @@ impl TryFrom<&proto::WireguardConstraints>
Ok(mullvad_constraints::WireguardConstraints {
port: Constraint::from(constraints.port.map(|port| port as u16)),
ip_version: Constraint::from(ip_version),
use_multihop: constraints.use_multihop,
use_multihop: Constraint::Only(constraints.use_multihop),
entry_location: constraints
.entry_location
.clone()
Expand Down Expand Up @@ -254,7 +253,7 @@ impl From<mullvad_types::relay_constraints::RelaySettings> for proto::RelaySetti
.ip_version
.option()
.map(|ipv| i32::from(proto::IpVersion::from(ipv))),
use_multihop: constraints.wireguard_constraints.use_multihop,
use_multihop: constraints.wireguard_constraints.multihop(),
entry_location: constraints
.wireguard_constraints
.entry_location
Expand Down
27 changes: 14 additions & 13 deletions mullvad-relay-selector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
use chrono::{DateTime, Local};
use ipnetwork::IpNetwork;
use mullvad_types::{
constraints::{Constraint, Match, Set},
custom_list::CustomListsSettings,
endpoint::{MullvadEndpoint, MullvadWireguardEndpoint},
location::{Coordinates, Location},
relay_constraints::{
BridgeSettings, BridgeState, Constraint, InternalBridgeConstraints, LocationConstraint,
Match, MissingCustomBridgeSettings, ObfuscationSettings, OpenVpnConstraints, Ownership,
Providers, RelayConstraints, RelayConstraintsFormatter, RelayOverride, RelaySettings,
ResolvedBridgeSettings, ResolvedLocationConstraint, SelectedObfuscation, Set,
TransportPort, Udp2TcpObfuscationSettings,
BridgeSettings, BridgeState, InternalBridgeConstraints, LocationConstraint,
MissingCustomBridgeSettings, ObfuscationSettings, OpenVpnConstraints, Ownership, Providers,
RelayConstraints, RelayConstraintsFormatter, RelayOverride, RelaySettings,
ResolvedBridgeSettings, ResolvedLocationConstraint, SelectedObfuscation, TransportPort,
Udp2TcpObfuscationSettings,
},
relay_list::{BridgeEndpointData, Relay, RelayEndpointData, RelayList},
settings::Settings,
Expand Down Expand Up @@ -596,7 +597,7 @@ impl RelaySelector {
// NOTE: If not using multihop then `location` is set as the only location constraint.
// If using multihop then location is the exit constraint and
// `wireguard_constraints.entry_location` is set as the entry location constraint.
if !relay_constraints.wireguard_constraints.use_multihop {
if !relay_constraints.wireguard_constraints.multihop() {
let relay_matcher = RelayMatcher {
locations: ResolvedLocationConstraint::from_constraint(
relay_constraints.location.clone(),
Expand Down Expand Up @@ -687,7 +688,7 @@ impl RelaySelector {
.into_wireguard_matcher();

// Pick the entry relay first if its location constraint is a subset of the exit location.
if relay_constraints.wireguard_constraints.use_multihop {
if relay_constraints.wireguard_constraints.multihop() {
matcher.endpoint_matcher.wireguard = self.wireguard_exit_matcher();
if entry_matcher.locations.is_subset(&matcher.locations) {
if let Ok((entry_relay, entry_endpoint)) = self.get_entry_endpoint(&entry_matcher) {
Expand All @@ -703,7 +704,7 @@ impl RelaySelector {
// Pick the entry relay last if its location constraint is NOT a subset of the exit
// location.
if matches!(selected_relay.endpoint, MullvadEndpoint::Wireguard(..))
&& relay_constraints.wireguard_constraints.use_multihop
&& relay_constraints.wireguard_constraints.multihop()
{
if !entry_matcher.locations.is_subset(&matcher.locations) {
entry_matcher.endpoint_matcher.peer = Some(selected_relay.exit_relay.clone());
Expand Down Expand Up @@ -1639,7 +1640,7 @@ mod test {
..RelayConstraints::default()
};

relay_constraints.wireguard_constraints.use_multihop = true;
relay_constraints.wireguard_constraints.use_multihop(true);
relay_constraints.wireguard_constraints.entry_location =
Constraint::Only(LocationConstraint::from(location1));

Expand Down Expand Up @@ -1689,7 +1690,7 @@ mod test {
..RelayConstraints::default()
};

relay_constraints.wireguard_constraints.use_multihop = true;
relay_constraints.wireguard_constraints.use_multihop(true);
relay_constraints.wireguard_constraints.entry_location =
Constraint::Only(location_specific.clone());

Expand Down Expand Up @@ -1965,7 +1966,7 @@ mod test {
fn test_selecting_any_relay_will_consider_multihop() {
let relay_constraints = RelayConstraints {
wireguard_constraints: WireguardConstraints {
use_multihop: true,
use_multihop: Constraint::Only(true),
..WireguardConstraints::default()
},
// This has to be explicit otherwise Android will chose WireGuard when default
Expand All @@ -1990,7 +1991,7 @@ mod test {
providers: Constraint::Any,
ownership: Constraint::Any,
wireguard_constraints: WireguardConstraints {
use_multihop: true,
use_multihop: Constraint::Only(true),
port: Constraint::Any,
ip_version: Constraint::Any,
entry_location: Constraint::Any,
Expand All @@ -2006,7 +2007,7 @@ mod test {
providers: Constraint::Any,
ownership: Constraint::Any,
wireguard_constraints: WireguardConstraints {
use_multihop: false,
use_multihop: Constraint::Only(false),
port: Constraint::Any,
ip_version: Constraint::Any,
entry_location: Constraint::Any,
Expand Down
5 changes: 3 additions & 2 deletions mullvad-relay-selector/src/matcher.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::CustomListsSettings;
use mullvad_types::{
constraints::{Constraint, Match},
endpoint::{MullvadEndpoint, MullvadWireguardEndpoint},
relay_constraints::{
Constraint, Match, OpenVpnConstraints, Ownership, Providers, RelayConstraints,
ResolvedLocationConstraint, WireguardConstraints,
OpenVpnConstraints, Ownership, Providers, RelayConstraints, ResolvedLocationConstraint,
WireguardConstraints,
},
relay_list::{
OpenVpnEndpoint, OpenVpnEndpointData, Relay, RelayEndpointData, WireguardEndpointData,
Expand Down
3 changes: 3 additions & 0 deletions mullvad-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ clap = { workspace = true , optional = true }

[target.'cfg(target_os = "android")'.dependencies]
jnix = { version = "0.5.1", features = ["derive"] }

[dev-dependencies]
proptest = { workspace = true }
Loading
Loading