diff options
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | gui/packages/desktop/src/renderer/app.js | 26 | ||||
| -rw-r--r-- | gui/packages/desktop/src/renderer/lib/daemon-rpc.js | 30 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/status.rs | 26 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 33 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 25 | ||||
| -rw-r--r-- | mullvad-ipc-client/src/lib.rs | 6 | ||||
| -rw-r--r-- | mullvad-tests/Cargo.toml | 2 | ||||
| -rw-r--r-- | mullvad-tests/tests/connection.rs | 63 | ||||
| -rw-r--r-- | mullvad-tests/tests/startup.rs | 13 | ||||
| -rw-r--r-- | mullvad-types/src/states.rs | 19 | ||||
| -rw-r--r-- | talpid-types/src/tunnel.rs | 3 |
12 files changed, 98 insertions, 150 deletions
diff --git a/Cargo.lock b/Cargo.lock index 5a1b732b08..699e31e4a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1024,10 +1024,10 @@ dependencies = [ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "mullvad-ipc-client 0.1.0", "mullvad-paths 0.1.0", - "mullvad-types 0.1.0", "notify 4.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "openvpn-plugin 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "talpid-ipc 0.1.0", + "talpid-types 0.1.0", "tempfile 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/gui/packages/desktop/src/renderer/app.js b/gui/packages/desktop/src/renderer/app.js index e0374f05d5..03fae931dd 100644 --- a/gui/packages/desktop/src/renderer/app.js +++ b/gui/packages/desktop/src/renderer/app.js @@ -32,7 +32,7 @@ import type { ConnectionObserver as DaemonConnectionObserver, } from './lib/daemon-rpc'; import type { ReduxStore } from './redux/store'; -import type { AccountToken, BackendState, RelaySettingsUpdate } from './lib/daemon-rpc'; +import type { AccountToken, TunnelState, RelaySettingsUpdate } from './lib/daemon-rpc'; import type { ConnectionState } from './redux/connection/reducers'; import type { TrayIconType } from '../main/tray-icon-controller'; @@ -211,7 +211,7 @@ export default class AppRenderer { try { const currentState = await this._daemonRpc.getState(); - if (currentState.state === 'secured') { + if (currentState === 'connected' || currentState === 'connecting') { log.debug('Refusing to connect as connection is already secured'); actions.connection.connected(); } else { @@ -395,7 +395,7 @@ export default class AppRenderer { async _fetchSecurityState() { const securityState = await this._daemonRpc.getState(); - const connectionState = this._securityStateToConnectionState(securityState); + const connectionState = this._tunnelStateToConnectionState(securityState); this._updateConnectionState(connectionState); } @@ -493,13 +493,9 @@ export default class AppRenderer { } if (newState) { - const connectionState = this._securityStateToConnectionState(newState); + const connectionState = this._tunnelStateToConnectionState(newState); - log.debug( - `Got new state from daemon {state: ${newState.state}, target_state: ${ - newState.target_state - }}, translated to '${connectionState}'`, - ); + log.debug(`Got new state from daemon '${newState}', translated to '${connectionState}'`); this._updateConnectionState(connectionState); this._refreshStateOnChange(); @@ -539,15 +535,13 @@ export default class AppRenderer { } } - _securityStateToConnectionState(backendState: BackendState): ConnectionState { - if (backendState.state === 'unsecured' && backendState.target_state === 'secured') { - return 'connecting'; - } else if (backendState.state === 'secured' && backendState.target_state === 'secured') { - return 'connected'; - } else if (backendState.target_state === 'unsecured') { + _tunnelStateToConnectionState(tunnelState: TunnelState): ConnectionState { + if (tunnelState === 'disconnected' || tunnelState === 'disconnecting') { return 'disconnected'; + } else if (tunnelState === 'connected' || tunnelState === 'connecting') { + return tunnelState; } - throw new Error('Unsupported state/target state combination: ' + JSON.stringify(backendState)); + throw new Error('Unsupported state/target state combination: ' + JSON.stringify(tunnelState)); } _updateConnectionState(connectionState: ConnectionState) { diff --git a/gui/packages/desktop/src/renderer/lib/daemon-rpc.js b/gui/packages/desktop/src/renderer/lib/daemon-rpc.js index c403e3fa92..e590534d69 100644 --- a/gui/packages/desktop/src/renderer/lib/daemon-rpc.js +++ b/gui/packages/desktop/src/renderer/lib/daemon-rpc.js @@ -41,11 +41,7 @@ const LocationSchema = object({ mullvad_exit_ip: boolean, }); -export type SecurityState = 'secured' | 'unsecured'; -export type BackendState = { - state: SecurityState, - target_state: SecurityState, -}; +export type TunnelState = 'disconnected' | 'connecting' | 'connected' | 'disconnecting'; export type RelayProtocol = 'tcp' | 'udp'; export type RelayLocation = {| city: [string, string] |} | {| country: string |}; @@ -200,11 +196,13 @@ const AccountDataSchema = object({ expiry: string, }); -const allSecurityStates: Array<SecurityState> = ['secured', 'unsecured']; -const BackendStateSchema = object({ - state: enumeration(...allSecurityStates), - target_state: enumeration(...allSecurityStates), -}); +const allTunnelStates: Array<TunnelState> = [ + 'disconnected', + 'connecting', + 'connected', + 'disconnecting', +]; +const TunnelStateSchema = enumeration(...allTunnelStates); export type AppVersionInfo = { currentIsSupported: boolean, @@ -240,8 +238,8 @@ export interface DaemonRpcProtocol { connectTunnel(): Promise<void>; disconnectTunnel(): Promise<void>; getLocation(): Promise<Location>; - getState(): Promise<BackendState>; - subscribeStateListener((state: ?BackendState, error: ?Error) => void): Promise<void>; + getState(): Promise<TunnelState>; + subscribeStateListener((state: ?TunnelState, error: ?Error) => void): Promise<void>; addOpenConnectionObserver(() => void): ConnectionObserver; addCloseConnectionObserver((error: ?Error) => void): ConnectionObserver; authenticate(sharedSecret: string): Promise<void>; @@ -442,19 +440,19 @@ export class DaemonRpc implements DaemonRpcProtocol { } } - async getState(): Promise<BackendState> { + async getState(): Promise<TunnelState> { const response = await this._transport.send('get_state'); try { - return validate(BackendStateSchema, response); + return validate(TunnelStateSchema, response); } catch (error) { throw new ResponseParseError('Invalid response from get_state', error); } } - subscribeStateListener(listener: (state: ?BackendState, error: ?Error) => void): Promise<void> { + subscribeStateListener(listener: (state: ?TunnelState, error: ?Error) => void): Promise<void> { return this._transport.subscribe('new_state', (payload) => { try { - const newState = validate(BackendStateSchema, payload); + const newState = validate(TunnelStateSchema, payload); listener(newState, null); } catch (error) { listener(null, new ResponseParseError('Invalid payload from new_state', error)); diff --git a/mullvad-cli/src/cmds/status.rs b/mullvad-cli/src/cmds/status.rs index 1a5a2b29e4..7ebf8cd36b 100644 --- a/mullvad-cli/src/cmds/status.rs +++ b/mullvad-cli/src/cmds/status.rs @@ -4,17 +4,7 @@ use Command; use Result; use mullvad_ipc_client::DaemonRpcClient; -use mullvad_types::states::{DaemonState, SecurityState, TargetState}; - -const DISCONNECTED: DaemonState = DaemonState { - state: SecurityState::Unsecured, - target_state: TargetState::Unsecured, -}; - -const CONNECTED: DaemonState = DaemonState { - state: SecurityState::Secured, - target_state: TargetState::Secured, -}; +use talpid_types::tunnel::TunnelStateTransition::{self, *}; pub struct Status; @@ -41,7 +31,7 @@ impl Command for Status { for new_state in rpc.new_state_subscribe()? { print_state(new_state); - if new_state == CONNECTED || new_state == DISCONNECTED { + if new_state == Connected || new_state == Disconnected { print_location(&mut rpc)?; } } @@ -50,13 +40,13 @@ impl Command for Status { } } -fn print_state(state: DaemonState) { +fn print_state(state: TunnelStateTransition) { print!("Tunnel status: "); - match (state.state, state.target_state) { - (SecurityState::Unsecured, TargetState::Unsecured) => println!("Disconnected"), - (SecurityState::Unsecured, TargetState::Secured) => println!("Connecting..."), - (SecurityState::Secured, TargetState::Unsecured) => println!("Disconnecting..."), - (SecurityState::Secured, TargetState::Secured) => println!("Connected"), + match state { + Connected => println!("Connected"), + Connecting => println!("Connecting..."), + Disconnected => println!("Disconnected"), + Disconnecting => println!("Disconnecting..."), } } diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index cef1435236..9ed938649e 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -68,7 +68,7 @@ use mullvad_types::account::{AccountData, AccountToken}; use mullvad_types::location::GeoIpLocation; use mullvad_types::relay_constraints::{RelaySettings, RelaySettingsUpdate}; use mullvad_types::relay_list::{Relay, RelayList}; -use mullvad_types::states::{DaemonState, SecurityState, TargetState}; +use mullvad_types::states::TargetState; use mullvad_types::version::{AppVersion, AppVersionInfo}; use std::net::IpAddr; @@ -188,8 +188,6 @@ impl DaemonExecutionState { struct Daemon { tunnel_command_tx: SyncUnboundedSender<TunnelCommand>, tunnel_state: TunnelStateTransition, - security_state: SecurityState, - last_broadcasted_state: DaemonState, target_state: TargetState, state: DaemonExecutionState, rx: mpsc::Receiver<DaemonEvent>, @@ -248,12 +246,7 @@ impl Daemon { Ok(Daemon { tunnel_command_tx: Sink::wait(tunnel_command_tx), tunnel_state: TunnelStateTransition::Disconnected, - security_state: SecurityState::Unsecured, target_state, - last_broadcasted_state: DaemonState { - state: SecurityState::Unsecured, - target_state, - }, state: DaemonExecutionState::Running, rx, tx, @@ -348,12 +341,9 @@ impl Daemon { } self.tunnel_state = tunnel_state; - self.security_state = match tunnel_state { - Disconnected | Connecting => SecurityState::Unsecured, - Connected | Disconnecting => SecurityState::Secured, - }; - self.broadcast_state(); + self.management_interface_broadcaster + .notify_new_state(self.tunnel_state); Ok(()) } @@ -394,8 +384,8 @@ impl Daemon { } } - fn on_get_state(&self, tx: OneshotSender<DaemonState>) { - Self::oneshot_send(tx, self.last_broadcasted_state, "current state"); + fn on_get_state(&self, tx: OneshotSender<TunnelStateTransition>) { + Self::oneshot_send(tx, self.tunnel_state, "current state"); } fn on_get_current_location(&self, tx: OneshotSender<GeoIpLocation>) { @@ -607,25 +597,12 @@ impl Daemon { Ok(()) } - fn broadcast_state(&mut self) { - let new_daemon_state = DaemonState { - state: self.security_state, - target_state: self.target_state, - }; - if self.last_broadcasted_state != new_daemon_state { - self.last_broadcasted_state = new_daemon_state; - self.management_interface_broadcaster - .notify_new_state(new_daemon_state); - } - } - /// Set the target state of the client. If it changed trigger the operations needed to /// progress towards that state. fn set_target_state(&mut self, new_state: TargetState) -> Result<()> { if new_state != self.target_state { debug!("Target state {:?} => {:?}", self.target_state, new_state); self.target_state = new_state; - self.broadcast_state(); self.apply_target_state() } else { Ok(()) diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 4d7a509018..79f74989ff 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -14,7 +14,7 @@ use mullvad_types::location::GeoIpLocation; use mullvad_paths; use mullvad_types::relay_constraints::{RelaySettings, RelaySettingsUpdate}; use mullvad_types::relay_list::RelayList; -use mullvad_types::states::{DaemonState, TargetState}; +use mullvad_types::states::TargetState; use mullvad_types::version; use serde; @@ -27,6 +27,7 @@ use std::sync::{Arc, Mutex, RwLock}; use talpid_core::mpsc::IntoSender; use talpid_ipc; use talpid_types::net::TunnelOptions; +use talpid_types::tunnel::TunnelStateTransition; use uuid; use account_history::{AccountHistory, Error as AccountHistoryError}; @@ -100,7 +101,7 @@ build_rpc_trait! { /// Returns the current state of the Mullvad client. Changes to this state will /// be announced to subscribers of `new_state`. #[rpc(meta, name = "get_state")] - fn get_state(&self, Self::Metadata) -> BoxFuture<DaemonState, Error>; + fn get_state(&self, Self::Metadata) -> BoxFuture<TunnelStateTransition, Error>; /// Performs a geoIP lookup and returns the current location as perceived by the public /// internet. @@ -142,7 +143,11 @@ build_rpc_trait! { #[pubsub(name = "new_state")] { /// Subscribes to the `new_state` event notifications. #[rpc(name = "new_state_subscribe")] - fn new_state_subscribe(&self, Self::Metadata, pubsub::Subscriber<DaemonState>); + fn new_state_subscribe( + &self, + Self::Metadata, + pubsub::Subscriber<TunnelStateTransition> + ); /// Unsubscribes from the `new_state` event notifications. #[rpc(name = "new_state_unsubscribe")] @@ -167,7 +172,7 @@ pub enum ManagementCommand { /// Change target state. SetTargetState(TargetState), /// Request the current state. - GetState(OneshotSender<DaemonState>), + GetState(OneshotSender<TunnelStateTransition>), /// Get the current geographical location. GetCurrentLocation(OneshotSender<GeoIpLocation>), /// Request the metadata for an account. @@ -209,7 +214,7 @@ pub enum ManagementCommand { #[derive(Default)] struct ActiveSubscriptions { - new_state_subscriptions: RwLock<HashMap<SubscriptionId, pubsub::Sink<DaemonState>>>, + new_state_subscriptions: RwLock<HashMap<SubscriptionId, pubsub::Sink<TunnelStateTransition>>>, error_subscriptions: RwLock<HashMap<SubscriptionId, pubsub::Sink<Vec<String>>>>, } @@ -268,7 +273,7 @@ pub struct EventBroadcaster { impl EventBroadcaster { /// Sends a new state update to all `new_state` subscribers of the management interface. - pub fn notify_new_state(&self, new_state: DaemonState) { + pub fn notify_new_state(&self, new_state: TunnelStateTransition) { debug!("Broadcasting new state to listeners: {:?}", new_state); self.notify(&self.subscriptions.new_state_subscriptions, new_state); } @@ -519,7 +524,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi self.send_command_to_daemon(ManagementCommand::SetTargetState(TargetState::Unsecured)) } - fn get_state(&self, _: Self::Metadata) -> BoxFuture<DaemonState, Error> { + fn get_state(&self, _: Self::Metadata) -> BoxFuture<TunnelStateTransition, Error> { trace!("get_state"); let (state_tx, state_rx) = sync::oneshot::channel(); let future = self @@ -633,7 +638,11 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi Box::new(future) } - fn new_state_subscribe(&self, _: Self::Metadata, subscriber: pubsub::Subscriber<DaemonState>) { + fn new_state_subscribe( + &self, + _: Self::Metadata, + subscriber: pubsub::Subscriber<TunnelStateTransition>, + ) { trace!("new_state_subscribe"); Self::subscribe(subscriber, &self.subscriptions.new_state_subscriptions); } diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs index 62a829b4d0..79c73fd18a 100644 --- a/mullvad-ipc-client/src/lib.rs +++ b/mullvad-ipc-client/src/lib.rs @@ -25,10 +25,10 @@ use mullvad_types::account::{AccountData, AccountToken}; use mullvad_types::location::GeoIpLocation; use mullvad_types::relay_constraints::{RelaySettings, RelaySettingsUpdate}; use mullvad_types::relay_list::RelayList; -use mullvad_types::states::DaemonState; use mullvad_types::version::AppVersionInfo; use serde::{Deserialize, Serialize}; use talpid_types::net::TunnelOptions; +use talpid_types::tunnel::TunnelStateTransition; use futures::stream::{self, Stream}; use futures::sync::oneshot; @@ -177,7 +177,7 @@ impl DaemonRpcClient { self.call("get_relay_settings", &NO_ARGS) } - pub fn get_state(&mut self) -> Result<DaemonState> { + pub fn get_state(&mut self) -> Result<TunnelStateTransition> { self.call("get_state", &NO_ARGS) } @@ -220,7 +220,7 @@ impl DaemonRpcClient { .chain_err(|| ErrorKind::RpcCallError(method.to_owned())) } - pub fn new_state_subscribe(&mut self) -> Result<mpsc::Receiver<DaemonState>> { + pub fn new_state_subscribe(&mut self) -> Result<mpsc::Receiver<TunnelStateTransition>> { let client = self.rpc_client.clone(); let mut current_state = self.get_state()?; let first_message = stream::once(Ok(current_state.clone())); diff --git a/mullvad-tests/Cargo.toml b/mullvad-tests/Cargo.toml index 18f8b959d8..c9814f32b1 100644 --- a/mullvad-tests/Cargo.toml +++ b/mullvad-tests/Cargo.toml @@ -12,10 +12,10 @@ integration-tests = [] duct = "0.11" mullvad-ipc-client = { path = "../mullvad-ipc-client" } mullvad-paths = { path = "../mullvad-paths" } -mullvad-types = { path = "../mullvad-types" } notify = "4.0" openvpn-plugin = { version = "0.3", features = ["serde"] } talpid-ipc = { path = "../talpid-ipc" } +talpid-types = { path = "../talpid-types" } tempfile = "3.0" jsonrpc-client-core = { git = "https://github.com/mullvad/jsonrpc-client-rs", branch = "master" } jsonrpc-client-ipc = { git = "https://github.com/mullvad/jsonrpc-client-rs", branch = "master" } diff --git a/mullvad-tests/tests/connection.rs b/mullvad-tests/tests/connection.rs index 75ee04d788..e2b14be965 100644 --- a/mullvad-tests/tests/connection.rs +++ b/mullvad-tests/tests/connection.rs @@ -2,16 +2,17 @@ extern crate mullvad_ipc_client; extern crate mullvad_tests; -extern crate mullvad_types; +extern crate talpid_types; use std::fs; use std::path::Path; use std::sync::mpsc; use std::time::Duration; +use talpid_types::tunnel::TunnelStateTransition; + use mullvad_tests::mock_openvpn::search_openvpn_args; use mullvad_tests::{watch_event, DaemonRunner, MockOpenVpnPluginRpcClient, PathWatcher}; -use mullvad_types::states::{DaemonState, SecurityState, TargetState}; #[cfg(target_os = "linux")] const OPENVPN_PLUGIN_NAME: &str = "libtalpid_openvpn_plugin.so"; @@ -19,21 +20,6 @@ const OPENVPN_PLUGIN_NAME: &str = "libtalpid_openvpn_plugin.so"; #[cfg(windows)] const OPENVPN_PLUGIN_NAME: &str = "talpid_openvpn_plugin.dll"; -const DISCONNECTED_STATE: DaemonState = DaemonState { - state: SecurityState::Unsecured, - target_state: TargetState::Unsecured, -}; - -const CONNECTING_STATE: DaemonState = DaemonState { - state: SecurityState::Unsecured, - target_state: TargetState::Secured, -}; - -const CONNECTED_STATE: DaemonState = DaemonState { - state: SecurityState::Secured, - target_state: TargetState::Secured, -}; - #[test] fn spawns_openvpn() { let mut daemon = DaemonRunner::spawn(); @@ -81,8 +67,11 @@ fn changes_to_connecting_state() { rpc_client.set_account(Some("123456".to_owned())).unwrap(); rpc_client.connect().unwrap(); - assert_state_event(&state_events, CONNECTING_STATE); - assert_eq!(rpc_client.get_state().unwrap(), CONNECTING_STATE); + assert_state_event(&state_events, TunnelStateTransition::Connecting); + assert_eq!( + rpc_client.get_state().unwrap(), + TunnelStateTransition::Connecting + ); } #[test] @@ -96,15 +85,18 @@ fn changes_to_connected_state() { rpc_client.set_account(Some("123456".to_owned())).unwrap(); rpc_client.connect().unwrap(); - assert_state_event(&state_events, CONNECTING_STATE); + assert_state_event(&state_events, TunnelStateTransition::Connecting); openvpn_args_file_events.assert_create_write_close_sequence(); let mut mock_plugin_client = create_mock_openvpn_plugin_client(openvpn_args_file); mock_plugin_client.up().unwrap(); - assert_state_event(&state_events, CONNECTED_STATE); - assert_eq!(rpc_client.get_state().unwrap(), CONNECTED_STATE); + assert_state_event(&state_events, TunnelStateTransition::Connected); + assert_eq!( + rpc_client.get_state().unwrap(), + TunnelStateTransition::Connected + ); } #[test] @@ -118,14 +110,14 @@ fn returns_to_connecting_state() { rpc_client.set_account(Some("123456".to_owned())).unwrap(); rpc_client.connect().unwrap(); - assert_state_event(&state_events, CONNECTING_STATE); + assert_state_event(&state_events, TunnelStateTransition::Connecting); openvpn_args_file_events.assert_create_write_close_sequence(); let mut mock_plugin_client = create_mock_openvpn_plugin_client(openvpn_args_file); mock_plugin_client.up().unwrap(); - assert_state_event(&state_events, CONNECTED_STATE); + assert_state_event(&state_events, TunnelStateTransition::Connected); mock_plugin_client.route_predown().unwrap(); @@ -133,8 +125,11 @@ fn returns_to_connecting_state() { assert_eq!(openvpn_args_file_events.next(), Some(watch_event::REMOVE)); openvpn_args_file_events.assert_create_write_close_sequence(); - assert_state_event(&state_events, CONNECTING_STATE); - assert_eq!(rpc_client.get_state().unwrap(), CONNECTING_STATE); + assert_state_event(&state_events, TunnelStateTransition::Connecting); + assert_eq!( + rpc_client.get_state().unwrap(), + TunnelStateTransition::Connecting + ); } #[test] @@ -148,22 +143,28 @@ fn disconnects() { rpc_client.set_account(Some("123456".to_owned())).unwrap(); rpc_client.connect().unwrap(); - assert_state_event(&state_events, CONNECTING_STATE); + assert_state_event(&state_events, TunnelStateTransition::Connecting); openvpn_args_file_events.assert_create_write_close_sequence(); let mut mock_plugin_client = create_mock_openvpn_plugin_client(openvpn_args_file); mock_plugin_client.up().unwrap(); - assert_state_event(&state_events, CONNECTED_STATE); + assert_state_event(&state_events, TunnelStateTransition::Connected); rpc_client.disconnect().unwrap(); - assert_state_event(&state_events, DISCONNECTED_STATE); - assert_eq!(rpc_client.get_state().unwrap(), DISCONNECTED_STATE); + assert_state_event(&state_events, TunnelStateTransition::Disconnected); + assert_eq!( + rpc_client.get_state().unwrap(), + TunnelStateTransition::Disconnected + ); } -fn assert_state_event(receiver: &mpsc::Receiver<DaemonState>, expected_state: DaemonState) { +fn assert_state_event( + receiver: &mpsc::Receiver<TunnelStateTransition>, + expected_state: TunnelStateTransition, +) { let received_state = receiver .recv_timeout(Duration::from_secs(3)) .expect("Failed to receive new state event from daemon"); diff --git a/mullvad-tests/tests/startup.rs b/mullvad-tests/tests/startup.rs index 0424023515..3281489b6d 100644 --- a/mullvad-tests/tests/startup.rs +++ b/mullvad-tests/tests/startup.rs @@ -2,21 +2,18 @@ extern crate mullvad_paths; extern crate mullvad_tests; -extern crate mullvad_types; +extern crate talpid_types; + +use talpid_types::tunnel::TunnelStateTransition; use mullvad_tests::DaemonRunner; -use mullvad_types::states::{DaemonState, SecurityState, TargetState}; #[test] -fn starts_in_not_connected_state() { +fn starts_in_disconnected_state() { let mut daemon = DaemonRunner::spawn(); let mut rpc_client = daemon.rpc_client().expect("Failed to create RPC client"); let state = rpc_client.get_state().expect("Failed to read daemon state"); - let not_connected_state = DaemonState { - state: SecurityState::Unsecured, - target_state: TargetState::Unsecured, - }; - assert_eq!(state, not_connected_state); + assert_eq!(state, TunnelStateTransition::Disconnected); } diff --git a/mullvad-types/src/states.rs b/mullvad-types/src/states.rs index e40ab94b0b..9f83a9655d 100644 --- a/mullvad-types/src/states.rs +++ b/mullvad-types/src/states.rs @@ -1,22 +1,3 @@ -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] -pub struct DaemonState { - pub state: SecurityState, - pub target_state: TargetState, -} - -/// Security state of the computer. -/// TODO(linus): There is a difference between lockdown(firewall) and tunnel functionality. The -/// firewall can be set to prevent any leaks but the tunnel is not connected. Then we are secured, -/// but disconnected. The frontend should probably reflect these states in some way. I think it -/// be reasonable to have three states, since unsecured but tunnel is up is probably an invalid -/// state. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum SecurityState { - Unsecured, - Secured, -} - /// Represents the state the client strives towards. /// When in `Secured`, the client should keep the computer from leaking and try to /// establish a VPN tunnel if it is not up. diff --git a/talpid-types/src/tunnel.rs b/talpid-types/src/tunnel.rs index 3ae6857475..4727964fe6 100644 --- a/talpid-types/src/tunnel.rs +++ b/talpid-types/src/tunnel.rs @@ -1,5 +1,6 @@ /// Event resulting from a transition to a new tunnel state. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] pub enum TunnelStateTransition { /// No connection is established and network is unsecured. Disconnected, |
