diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-06-05 17:37:38 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-06-06 12:00:30 +0100 |
| commit | 35a2f4db5734b27d0a47a24a641d55fe5d89afe9 (patch) | |
| tree | adf1c930d79523d8f75685b2946fb665d40bda8d /mullvad-daemon/src | |
| parent | 9ab06703eba719bafeef9495cd2aa16cfbd13d1e (diff) | |
| download | mullvadvpn-35a2f4db5734b27d0a47a24a641d55fe5d89afe9.tar.xz mullvadvpn-35a2f4db5734b27d0a47a24a641d55fe5d89afe9.zip | |
Add bridge_hostname to GeoIpLocation
Diffstat (limited to 'mullvad-daemon/src')
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 38 | ||||
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 12 |
2 files changed, 36 insertions, 14 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 88cd834969..42c87d0024 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -214,6 +214,7 @@ pub struct Daemon<L: EventListener = ManagementInterfaceEventBroadcaster> { tokio_remote: tokio_core::reactor::Remote, relay_selector: relays::RelaySelector, last_generated_relay: Option<Relay>, + last_generated_bridge_relay: Option<Relay>, version: String, } @@ -379,6 +380,7 @@ where tokio_remote, relay_selector, last_generated_relay: None, + last_generated_bridge_relay: None, version, }) } @@ -500,6 +502,7 @@ where ) -> Result<TunnelParameters> { let tunnel_options = self.settings.get_tunnel_options().clone(); let location = relay.location.as_ref().expect("Relay has no location set"); + self.last_generated_bridge_relay = None; match endpoint { MullvadEndpoint::OpenVpn(endpoint) => { let proxy_settings = match self.settings.get_bridge_settings() { @@ -509,16 +512,28 @@ where transport_protocol: Constraint::Only(endpoint.protocol), }; match self.settings.get_bridge_state() { - BridgeState::On => Some( - self.relay_selector + BridgeState::On => { + let (bridge_settings, bridge_relay) = self + .relay_selector .get_proxy_settings(&bridge_constraints, location) - .ok_or(Error::NoBridgeAvailable)?, - ), - BridgeState::Auto => self.relay_selector.get_auto_proxy_settings( - &bridge_constraints, - location, - retry_attempt, - ), + .ok_or(Error::NoBridgeAvailable)?; + self.last_generated_bridge_relay = Some(bridge_relay); + Some(bridge_settings) + } + BridgeState::Auto => { + if let Some((bridge_settings, bridge_relay)) = + self.relay_selector.get_auto_proxy_settings( + &bridge_constraints, + location, + retry_attempt, + ) + { + self.last_generated_bridge_relay = Some(bridge_relay); + Some(bridge_settings) + } else { + None + } + } BridgeState::Off => None, } } @@ -704,6 +719,10 @@ where fn build_location_from_relay(&self) -> Option<GeoIpLocation> { let relay = self.last_generated_relay.as_ref()?; + let bridge_hostname = self + .last_generated_bridge_relay + .as_ref() + .map(|bridge| bridge.hostname.clone()); let location = relay.location.as_ref().cloned().unwrap(); let hostname = relay.hostname.clone(); @@ -716,6 +735,7 @@ where longitude: location.longitude, mullvad_exit_ip: true, hostname: Some(hostname), + bridge_hostname, }) } diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs index 81874e4367..e9c02c6214 100644 --- a/mullvad-daemon/src/relays.rs +++ b/mullvad-daemon/src/relays.rs @@ -280,7 +280,7 @@ impl RelaySelector { bridge_constraints: &InternalBridgeConstraints, location: &Location, retry_attempt: u32, - ) -> Option<ProxySettings> { + ) -> Option<(ProxySettings, Relay)> { if !self.should_use_bridge(retry_attempt) { return None; } @@ -307,7 +307,7 @@ impl RelaySelector { &mut self, constraints: &InternalBridgeConstraints, location: &Location, - ) -> Option<ProxySettings> { + ) -> Option<(ProxySettings, Relay)> { let mut matching_relays: Vec<Relay> = self .lock_parsed_relays() .relays() @@ -322,9 +322,11 @@ impl RelaySelector { matching_relays.sort_by_cached_key(|relay| { (relay.location.as_ref().unwrap().distance_from(&location) * 1000.0) as i64 }); - return matching_relays - .get(0) - .and_then(|relay| self.pick_random_bridge(&relay)); + return matching_relays.get(0).and_then(|relay| { + (self + .pick_random_bridge(&relay) + .map(|bridge| (bridge, relay.clone()))) + }); } |
