diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-08-21 10:55:38 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-09-03 08:05:18 -0300 |
| commit | b4243f64c38796b21930bae90aae24dcf97d7f0c (patch) | |
| tree | dadc666cfee2cd7fd272178943d3da333895c838 /talpid-core | |
| parent | 5ad7d5cad6bce0346e242065250271428f52d58f (diff) | |
| download | mullvadvpn-b4243f64c38796b21930bae90aae24dcf97d7f0c.tar.xz mullvadvpn-b4243f64c38796b21930bae90aae24dcf97d7f0c.zip | |
Create `BlockedState` type
Diffstat (limited to 'talpid-core')
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/blocked_state.rs | 42 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/mod.rs | 6 |
2 files changed, 48 insertions, 0 deletions
diff --git a/talpid-core/src/tunnel_state_machine/blocked_state.rs b/talpid-core/src/tunnel_state_machine/blocked_state.rs new file mode 100644 index 0000000000..f4499c7b58 --- /dev/null +++ b/talpid-core/src/tunnel_state_machine/blocked_state.rs @@ -0,0 +1,42 @@ +use futures::sync::mpsc; +use futures::Stream; + +use super::{ + ConnectingState, DisconnectedState, EventConsequence, SharedTunnelStateValues, TunnelCommand, + TunnelState, TunnelStateTransition, TunnelStateWrapper, +}; + +/// No tunnel is running and all network connections are blocked. +pub struct BlockedState; + +impl TunnelState for BlockedState { + type Bootstrap = (); + + fn enter( + _: &mut SharedTunnelStateValues, + _: Self::Bootstrap, + ) -> (TunnelStateWrapper, TunnelStateTransition) { + ( + TunnelStateWrapper::from(BlockedState), + TunnelStateTransition::Blocked, + ) + } + + fn handle_event( + self, + commands: &mut mpsc::UnboundedReceiver<TunnelCommand>, + shared_values: &mut SharedTunnelStateValues, + ) -> EventConsequence<Self> { + use self::EventConsequence::*; + + match try_handle_event!(self, commands.poll()) { + Ok(TunnelCommand::Connect(parameters)) => { + NewState(ConnectingState::enter(shared_values, parameters)) + } + Ok(TunnelCommand::Disconnect) | Err(_) => { + NewState(DisconnectedState::enter(shared_values, ())) + } + _ => SameState(self), + } + } +} diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index 700f082146..20f1529b01 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -1,6 +1,7 @@ #[macro_use] mod macros; +mod blocked_state; mod connected_state; mod connecting_state; mod disconnected_state; @@ -19,6 +20,7 @@ use tokio_core::reactor::Core; use talpid_types::net::{TunnelEndpoint, TunnelOptions}; use talpid_types::tunnel::TunnelStateTransition; +use self::blocked_state::BlockedState; use self::connected_state::{ConnectedState, ConnectedStateBootstrap}; use self::connecting_state::ConnectingState; use self::disconnected_state::DisconnectedState; @@ -286,6 +288,7 @@ enum TunnelStateWrapper { Connecting(ConnectingState), Connected(ConnectedState), Disconnecting(DisconnectingState), + Blocked(BlockedState), } impl TunnelStateWrapper { @@ -321,6 +324,7 @@ impl TunnelStateWrapper { Connecting, Connected, Disconnecting, + Blocked, } } } @@ -339,6 +343,7 @@ impl_from_for_tunnel_state!(Disconnected(DisconnectedState)); impl_from_for_tunnel_state!(Connecting(ConnectingState)); impl_from_for_tunnel_state!(Connected(ConnectedState)); impl_from_for_tunnel_state!(Disconnecting(DisconnectingState)); +impl_from_for_tunnel_state!(Blocked(BlockedState)); impl Debug for TunnelStateWrapper { fn fmt(&self, formatter: &mut Formatter) -> FmtResult { @@ -349,6 +354,7 @@ impl Debug for TunnelStateWrapper { Connecting(_) => write!(formatter, "TunnelStateWrapper::Connecting(_)"), Connected(_) => write!(formatter, "TunnelStateWrapper::Connected(_)"), Disconnecting(_) => write!(formatter, "TunnelStateWrapper::Disconnecting(_)"), + Blocked(_) => write!(formatter, "TunnelStateWrapper::Blocked(_)"), } } } |
