Skip to content

Commit

Permalink
Remove superflous function
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Oct 17, 2024
1 parent ab99176 commit a9e7663
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions mullvad-relay-selector/src/relay_selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl RelaySelector {
Self::get_wireguard_relay(&query, custom_lists, parsed_relays)
}

/// Derive a valid Wireguard relay configuration from `query`.
/// Derive a valid relay configuration from `query`.
///
/// # Note
/// This function should *only* be called with a Wireguard query.
Expand Down Expand Up @@ -663,23 +663,35 @@ impl RelaySelector {
})
}

/// TODO: Document
/// Derive a valid Wireguard relay configuration from `query`.
///
/// # Returns
/// * An `Err` if no exit relay can be chosen
/// * An `Err` if no entry relay can be chosen (if multihop is enabled on `query`)
/// * `Ok(WireguardConfig)` otherwise
fn get_wireguard_relay_config(
query: &RelayQuery,
custom_lists: &CustomListsSettings,
parsed_relays: &ParsedRelays,
) -> Result<WireguardConfig, Error> {
// TODO: Make sure that this works differently on Android.
let inner = if query.singlehop() {
match Self::get_wireguard_singlehop_config(query, custom_lists, parsed_relays) {
Some(exit) => WireguardConfig::from(exit),
None => {
// No exit candidate was found.. Time to try smart routing!
let multihop = Self::select_daita_multihop_through_smart_routing(
query,
custom_lists,
parsed_relays,
)?;
WireguardConfig::from(multihop)
// If we found no matching relays because DAITA was enabled, and `use_multihop_if_necessary`
// is enabled, try enabling multihop and connecting using an automatically selected
// entry relay.
if query.using_daita() && query.use_multihop_if_necessary() {
let multihop = Self::get_wireguard_auto_multihop_config(
query,
custom_lists,
parsed_relays,
)?;
WireguardConfig::from(multihop)
} else {
return Err(Error::NoRelay);
}
}
}
} else {
Expand Down Expand Up @@ -714,33 +726,6 @@ impl RelaySelector {
.map(Singlehop::new)
}

/// TODO: Make sure to make a comment regarding the fact that we no longer check for 'empty'
/// candidates.
fn select_daita_multihop_through_smart_routing(
query: &RelayQuery,
custom_lists: &CustomListsSettings,
parsed_relays: &ParsedRelays,
) -> Result<Multihop, Error> {
// is the `candidates` list empty because DAITA is enabled?
let no_relay_because_daita = || {
let mut query = query.clone();
let mut wireguard_constraints = query.wireguard_constraints().clone();
wireguard_constraints.daita = Constraint::Any;
query.set_wireguard_constraints(wireguard_constraints)?;
let candidates = filter_matching_relay_list(&query, parsed_relays, custom_lists);
Result::<_, Error>::Ok(!candidates.is_empty())
};

// if we found no matching relays because DAITA was enabled, and `use_multihop_if_necessary`
// is enabled, try enabling multihop and connecting using an automatically selected
// entry relay.
if query.using_daita() && query.use_multihop_if_necessary() && no_relay_because_daita()? {
Self::get_wireguard_auto_multihop_config(query, custom_lists, parsed_relays)
} else {
Err(Error::NoRelay)
}
}

/// Select a valid Wireguard exit relay, together with with an automatically chosen entry relay.
///
/// # Returns
Expand Down

0 comments on commit a9e7663

Please sign in to comment.