File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed
mullvad-relay-selector/src/relay_selector Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -36,8 +36,8 @@ pub enum Error {
3636 MissingPublicKey ,
3737 #[ error( "The selected relay does not support IPv6" ) ]
3838 NoIPv6 ( Box < Relay > ) ,
39- #[ error( "Failed to select port" ) ]
40- PortSelectionError ,
39+ #[ error( "Failed to select port ({port}) " ) ]
40+ PortSelectionError { port : Constraint < u16 > } ,
4141}
4242
4343/// Constructs a [`MullvadWireguardEndpoint`] with details for how to connect to a Wireguard relay.
@@ -189,15 +189,16 @@ fn get_port_for_wireguard_relay(
189189 //
190190 // TODO: Enable the same behaviour on Android sometime later. For now, keep the old behaviour.
191191 // If only || was supported in if-let-chains ..
192- let desired_port = if cfg ! ( target_os = "android" ) {
192+ let port = if cfg ! ( target_os = "android" ) {
193193 query. port
194194 } else if let ObfuscationQuery :: Port = query. obfuscation {
195195 query. port
196196 } else {
197197 Constraint :: Any
198198 } ;
199- super :: helpers:: desired_or_random_port_from_range ( & data. port_ranges , desired_port)
200- . map_err ( |_err| Error :: PortSelectionError )
199+
200+ super :: helpers:: desired_or_random_port_from_range ( & data. port_ranges , port)
201+ . map_err ( |_err| Error :: PortSelectionError { port } )
201202}
202203
203204/// Read the [`PublicKey`] of a relay. This will only succeed if [relay][`Relay`] is a
Original file line number Diff line number Diff line change @@ -274,9 +274,10 @@ pub fn desired_or_random_port_from_range<R: RangeBounds<u16> + Iterator<Item = u
274274 port_ranges : & [ R ] ,
275275 desired_port : Constraint < u16 > ,
276276) -> Result < u16 , Error > {
277- desired_port
278- . map ( |port| port_if_in_range ( port_ranges, port) )
279- . unwrap_or_else ( || select_random_port ( port_ranges) )
277+ match desired_port {
278+ Constraint :: Only ( port) => port_if_in_range ( port_ranges, port) ,
279+ Constraint :: Any => select_random_port ( port_ranges) ,
280+ }
280281}
281282
282283/// Return `Ok(port)`, if and only if `port` is in `port_ranges`. Otherwise, return an error.
You can’t perform that action at this time.
0 commit comments