summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-08-27 13:25:50 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-08-30 16:45:46 -0300
commitd818ff9c4ec54540bf10b09d9668eb7ad33336a5 (patch)
tree784d4517a079fc1f2088b4dac628daca26ada58f /mullvad-daemon/src
parentd3c677dd27415c37b8e0c353ce8e752605f71b5d (diff)
downloadmullvadvpn-d818ff9c4ec54540bf10b09d9668eb7ad33336a5.tar.xz
mullvadvpn-d818ff9c4ec54540bf10b09d9668eb7ad33336a5.zip
Replace `DaemonState` with `TunnelStateTransition`
Diffstat (limited to 'mullvad-daemon/src')
-rw-r--r--mullvad-daemon/src/main.rs33
-rw-r--r--mullvad-daemon/src/management_interface.rs25
2 files changed, 22 insertions, 36 deletions
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);
}