Skip to content

Commit

Permalink
Remove WireguardMatcher::new_matcher
Browse files Browse the repository at this point in the history
By re-using existing functions for instantiating a `RelayMatcher` for a
given query the Wireguard-specific short-hand function
`WireguardMatcher::new_matcher` could simply be removed!
  • Loading branch information
MarkusPettersson98 committed Mar 15, 2024
1 parent 734ea29 commit c3aa205
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
16 changes: 0 additions & 16 deletions mullvad-relay-selector/src/relay_selector/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,6 @@ impl<'a> WireguardMatcher<'a> {
data,
}
}

pub fn new_matcher(
constraints: RelayQuery,
data: &'a WireguardEndpointData,
custom_lists: &CustomListsSettings,
) -> RelayMatcher<Self> {
RelayMatcher {
locations: ResolvedLocationConstraint::from_constraint(
constraints.location,
custom_lists,
),
providers: constraints.providers,
ownership: constraints.ownership,
endpoint_matcher: WireguardMatcher::new(constraints.wireguard_constraints, data),
}
}
}

impl<'a> EndpointMatcher for WireguardMatcher<'a> {
Expand Down
20 changes: 5 additions & 15 deletions mullvad-relay-selector/src/relay_selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
time::SystemTime,
};

use matcher::{BridgeMatcher, RelayMatcher, WireguardMatcher};
use matcher::{BridgeMatcher, RelayMatcher};
use mullvad_types::{
constraints::Constraint,
custom_list::CustomListsSettings,
Expand Down Expand Up @@ -571,20 +571,10 @@ impl RelaySelector {
let mut entry_relay_query = query.clone();
entry_relay_query.location = query.wireguard_constraints.entry_location.clone();
// After we have our two queries (one for the exit relay & one for the entry relay),
// we can construct our two matchers:
let exit_matcher = WireguardMatcher::new_matcher(
query.clone(),
&parsed_relays.parsed_list().wireguard,
config.custom_lists,
);
let entry_matcher = WireguardMatcher::new_matcher(
entry_relay_query.clone(),
&parsed_relays.parsed_list().wireguard,
config.custom_lists,
);
// .. and query for all exit & entry candidates! All candidates are needed for the next step.
let exit_candidates = exit_matcher.filter_matching_relay_list(parsed_relays.relays());
let entry_candidates = entry_matcher.filter_matching_relay_list(parsed_relays.relays());
// we can query for all exit & entry candidates! All candidates are needed for the next step.
let exit_candidates = Self::get_tunnel_endpoints(query, config, parsed_relays);
let entry_candidates =
Self::get_tunnel_endpoints(&entry_relay_query, config, parsed_relays);

// This algorithm gracefully handles a particular edge case that arise when a constraint on
// the exit relay is more specific than on the entry relay which forces the relay selector
Expand Down

0 comments on commit c3aa205

Please sign in to comment.