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

Constrain relay port with constrain_to_relay helper #6650

Merged
merged 1 commit into from
Aug 21, 2024
Merged
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
11 changes: 7 additions & 4 deletions test/test-manager/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use mullvad_types::{
constraints::Constraint,
location::Location,
relay_constraints::{
BridgeSettings, GeographicLocationConstraint, LocationConstraint, RelayConstraints,
RelaySettings,
BridgeSettings, GeographicLocationConstraint, LocationConstraint, OpenVpnConstraints,
RelayConstraints, RelaySettings, WireguardConstraints,
},
relay_list::Relay,
states::TunnelState,
Expand Down Expand Up @@ -688,6 +688,7 @@ pub async fn constrain_to_relay(
) -> anyhow::Result<Relay> {
/// Convert the result of invoking the relay selector to a relay constraint.
fn convert_to_relay_constraints(
query: RelayQuery,
selected_relay: GetRelay,
) -> anyhow::Result<(Relay, RelayConstraints)> {
match selected_relay {
Expand All @@ -699,6 +700,8 @@ pub async fn constrain_to_relay(
let location = into_constraint(&exit)?;
let relay_constraints = RelayConstraints {
location,
wireguard_constraints: WireguardConstraints::from(query.wireguard_constraints),
openvpn_constraints: OpenVpnConstraints::from(query.openvpn_constraints),
..Default::default()
};
Ok((exit, relay_constraints))
Expand All @@ -712,8 +715,8 @@ pub async fn constrain_to_relay(
let relay_selector = RelaySelector::from_list(SelectorConfig::default(), relay_list);
// Select an(y) appropriate relay for the given query and constrain the daemon to only connect
// to that specific relay (when connecting).
let relay = relay_selector.get_relay_by_query(query)?;
let (exit, relay_constraints) = convert_to_relay_constraints(relay)?;
let relay = relay_selector.get_relay_by_query(query.clone())?;
let (exit, relay_constraints) = convert_to_relay_constraints(query, relay)?;
set_relay_settings(mullvad_client, RelaySettings::Normal(relay_constraints)).await?;

Ok(exit)
Expand Down
Loading