diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-04-18 19:25:51 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-08-23 15:00:04 -0300 |
| commit | 03e080066ca0e9bdbadb5cf192ff43efab1749ce (patch) | |
| tree | ff916df7743840205181e6133c05f26b2c6042bf | |
| parent | e073dabf8b37c87e3ac042996b0eedda9eadbc3b (diff) | |
| download | mullvadvpn-03e080066ca0e9bdbadb5cf192ff43efab1749ce.tar.xz mullvadvpn-03e080066ca0e9bdbadb5cf192ff43efab1749ce.zip | |
Disconnect and reconnect if parameters change
3 files changed, 31 insertions, 6 deletions
diff --git a/mullvad-daemon/src/tunnel_state_machine/connected_state.rs b/mullvad-daemon/src/tunnel_state_machine/connected_state.rs index 4a006153ba..f17eaf6ab8 100644 --- a/mullvad-daemon/src/tunnel_state_machine/connected_state.rs +++ b/mullvad-daemon/src/tunnel_state_machine/connected_state.rs @@ -6,13 +6,14 @@ use talpid_types::net::TunnelEndpoint; use super::{ AfterDisconnect, CloseHandle, DisconnectingState, EventConsequence, StateEntryResult, - TunnelCommand, TunnelState, TunnelStateTransition, TunnelStateWrapper, + TunnelCommand, TunnelParameters, TunnelState, TunnelStateTransition, TunnelStateWrapper, }; pub struct ConnectedStateBootstrap { pub metadata: TunnelMetadata, pub tunnel_events: mpsc::UnboundedReceiver<TunnelEvent>, pub tunnel_endpoint: TunnelEndpoint, + pub tunnel_parameters: TunnelParameters, pub close_handle: CloseHandle, } @@ -21,6 +22,7 @@ pub struct ConnectedState { metadata: TunnelMetadata, tunnel_events: mpsc::UnboundedReceiver<TunnelEvent>, tunnel_endpoint: TunnelEndpoint, + tunnel_parameters: TunnelParameters, close_handle: CloseHandle, } @@ -30,6 +32,7 @@ impl ConnectedState { metadata: bootstrap.metadata, tunnel_events: bootstrap.tunnel_events, tunnel_endpoint: bootstrap.tunnel_endpoint, + tunnel_parameters: bootstrap.tunnel_parameters, close_handle: bootstrap.close_handle, } } @@ -45,7 +48,16 @@ impl ConnectedState { use self::EventConsequence::*; match try_handle_event!(self, commands.poll()) { - Ok(TunnelCommand::Connect(_)) => SameState(self), + Ok(TunnelCommand::Connect(parameters)) => { + if parameters != self.tunnel_parameters { + NewState(DisconnectingState::enter(( + self.close_handle.close(), + AfterDisconnect::Reconnect(parameters), + ))) + } else { + SameState(self) + } + } Ok(TunnelCommand::Disconnect) | Err(_) => NewState(DisconnectingState::enter(( self.close_handle.close(), AfterDisconnect::Nothing, @@ -59,7 +71,7 @@ impl ConnectedState { match try_handle_event!(self, self.tunnel_events.poll()) { Ok(TunnelEvent::Down) | Err(_) => NewState(DisconnectingState::enter(( self.close_handle.close(), - AfterDisconnect::Nothing, + AfterDisconnect::Reconnect(self.tunnel_parameters), ))), Ok(_) => SameState(self), } diff --git a/mullvad-daemon/src/tunnel_state_machine/connecting_state.rs b/mullvad-daemon/src/tunnel_state_machine/connecting_state.rs index c9860a2105..9723e13728 100644 --- a/mullvad-daemon/src/tunnel_state_machine/connecting_state.rs +++ b/mullvad-daemon/src/tunnel_state_machine/connecting_state.rs @@ -31,13 +31,14 @@ pub struct ConnectingState { close_handle: CloseHandle, tunnel_events: mpsc::UnboundedReceiver<TunnelEvent>, tunnel_endpoint: TunnelEndpoint, + tunnel_parameters: TunnelParameters, } impl ConnectingState { fn new(parameters: TunnelParameters) -> Result<Self> { let (event_tx, event_rx) = mpsc::unbounded(); let tunnel_endpoint = parameters.endpoint; - let monitor = Self::spawn_tunnel_monitor(parameters, event_tx.wait())?; + let monitor = Self::spawn_tunnel_monitor(¶meters, event_tx.wait())?; let close_handle = CloseHandle::new(&monitor); Self::spawn_tunnel_monitor_wait_thread(monitor); @@ -46,11 +47,12 @@ impl ConnectingState { close_handle, tunnel_events: event_rx, tunnel_endpoint, + tunnel_parameters: parameters, }) } fn spawn_tunnel_monitor( - parameters: TunnelParameters, + parameters: &TunnelParameters, events: Wait<mpsc::UnboundedSender<TunnelEvent>>, ) -> Result<TunnelMonitor> { let event_tx = Mutex::new(events); @@ -116,6 +118,7 @@ impl ConnectingState { metadata, tunnel_events: self.tunnel_events, tunnel_endpoint: self.tunnel_endpoint, + tunnel_parameters: self.tunnel_parameters, close_handle: self.close_handle, } } @@ -131,7 +134,16 @@ impl ConnectingState { use self::EventConsequence::*; match try_handle_event!(self, commands.poll()) { - Ok(TunnelCommand::Connect(_)) => SameState(self), + Ok(TunnelCommand::Connect(parameters)) => { + if parameters != self.tunnel_parameters { + NewState(DisconnectingState::enter(( + self.close_handle.close(), + AfterDisconnect::Reconnect(parameters), + ))) + } else { + SameState(self) + } + } Ok(TunnelCommand::Disconnect) | Err(_) => NewState(DisconnectingState::enter(( self.close_handle.close(), AfterDisconnect::Nothing, diff --git a/mullvad-daemon/src/tunnel_state_machine/mod.rs b/mullvad-daemon/src/tunnel_state_machine/mod.rs index dc15c43b90..92cc064077 100644 --- a/mullvad-daemon/src/tunnel_state_machine/mod.rs +++ b/mullvad-daemon/src/tunnel_state_machine/mod.rs @@ -76,6 +76,7 @@ pub enum TunnelCommand { } /// Information necessary to open a tunnel. +#[derive(Debug, PartialEq)] pub struct TunnelParameters { pub endpoint: TunnelEndpoint, pub options: TunnelOptions, |
