summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-daemon/src/lib.rs6
-rw-r--r--mullvad-daemon/src/relays.rs15
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,