Skip to content

Commit

Permalink
fixup: simplify get_udp2tcp_obfuscator_port
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Jul 30, 2024
1 parent a6b5d34 commit b9e7a97
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mullvad-relay-selector/src/relay_selector/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ pub fn get_udp2tcp_obfuscator(
}

pub fn get_udp2tcp_obfuscator_port(
obfuscation_settings_constraint: &Udp2TcpObfuscationSettings,
obfuscation_settings: &Udp2TcpObfuscationSettings,
udp2tcp_ports: &[u16],
) -> Option<u16> {
match obfuscation_settings_constraint {
obfuscation_settings if obfuscation_settings.port.is_only() => udp2tcp_ports
if let Constraint::Only(desired_port) = obfuscation_settings.port {
udp2tcp_ports
.iter()
.find(|&candidate| obfuscation_settings.port == Constraint::Only(*candidate))
.copied(),
.find(|&candidate| desired_port == *candidate)
.copied()
} else {
// There are no specific obfuscation settings to take into consideration in this case.
_ => udp2tcp_ports.choose(&mut thread_rng()).copied(),
udp2tcp_ports.choose(&mut thread_rng()).copied()
}
}

0 comments on commit b9e7a97

Please sign in to comment.