diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-08-08 14:48:26 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-08-09 11:54:10 +0100 |
| commit | 9c5c3f45c1629ab14edc4b241e6feee907c1fa22 (patch) | |
| tree | 9b5d844ed86c3a0fe2fbbda1bb8629907610b5da | |
| parent | 0b7d250e9c4783f80e5ffe925f99df0503e80a83 (diff) | |
| download | mullvadvpn-9c5c3f45c1629ab14edc4b241e6feee907c1fa22.tar.xz mullvadvpn-9c5c3f45c1629ab14edc4b241e6feee907c1fa22.zip | |
Use bridge state to determine preferred relay constraints
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 6 | ||||
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 15 |
2 files changed, 16 insertions, 5 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 21c6f0ea11..1184971692 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -554,7 +554,11 @@ where } RelaySettings::Normal(constraints) => self .relay_selector - .get_tunnel_endpoint(&constraints, retry_attempt) + .get_tunnel_endpoint( + &constraints, + self.settings.get_bridge_state(), + retry_attempt, + ) .map_err(|e| { e.display_chain_with_msg( "No valid relay servers match the current settings", diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs index 1dd922d396..ea1bcc3114 100644 --- a/mullvad-daemon/src/relays.rs +++ b/mullvad-daemon/src/relays.rs @@ -5,8 +5,8 @@ use mullvad_types::{ endpoint::MullvadEndpoint, location::Location, relay_constraints::{ - Constraint, InternalBridgeConstraints, LocationConstraint, Match, OpenVpnConstraints, - RelayConstraints, TunnelProtocol, WireguardConstraints, + BridgeState, Constraint, InternalBridgeConstraints, LocationConstraint, Match, + OpenVpnConstraints, RelayConstraints, TunnelProtocol, WireguardConstraints, }, relay_list::{OpenVpnEndpointData, Relay, RelayList, RelayTunnels, WireguardEndpointData}, }; @@ -204,9 +204,11 @@ impl RelaySelector { pub fn get_tunnel_endpoint( &mut self, relay_constraints: &RelayConstraints, + bridge_state: &BridgeState, retry_attempt: u32, ) -> Result<(Relay, MullvadEndpoint), Error> { - let preferred_constraints = Self::preferred_constraints(relay_constraints, retry_attempt); + let preferred_constraints = + Self::preferred_constraints(relay_constraints, bridge_state, retry_attempt); if let Some((relay, endpoint)) = self.get_tunnel_endpoint_internal(&preferred_constraints) { debug!( "Relay matched on highest preference for retry attempt {}", @@ -228,16 +230,20 @@ impl RelaySelector { fn preferred_constraints( original_constraints: &RelayConstraints, + bridge_state: &BridgeState, retry_attempt: u32, ) -> RelayConstraints { // Prefer UDP by default. But if that has failed a couple of times, then try TCP port 443, // which works for many with UDP problems. After that, just alternate between protocols. - let (preferred_port, preferred_protocol) = match retry_attempt { + let (preferred_port, mut preferred_protocol) = match retry_attempt { 0 | 1 => (Constraint::Any, TransportProtocol::Udp), 2 | 3 => (Constraint::Only(443), TransportProtocol::Tcp), attempt if attempt % 2 == 0 => (Constraint::Any, TransportProtocol::Udp), _ => (Constraint::Any, TransportProtocol::Tcp), }; + if *bridge_state == BridgeState::On { + preferred_protocol = TransportProtocol::Tcp; + } let mut relay_constraints = RelayConstraints { location: original_constraints.location.clone(), @@ -251,6 +257,7 @@ impl RelaySelector { Constraint::Any => { if original_constraints.openvpn_constraints.port.is_any() && original_constraints.openvpn_constraints.protocol.is_any() + || *bridge_state == BridgeState::On { relay_constraints.openvpn_constraints = OpenVpnConstraints { port: preferred_port, |
