diff options
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 17 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 10 | ||||
| -rw-r--r-- | mullvad-ipc-client/src/lib.rs | 4 |
3 files changed, 30 insertions, 1 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 74383b43a4..ba6864db7b 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -206,6 +206,9 @@ pub enum DaemonCommand { FactoryReset(oneshot::Sender<()>), /// Makes the daemon exit the main loop and quit. Shutdown, + /// Saves the target tunnel state and quits in a blocking state. The state is restored + /// upon restart. + TemporaryShutdown, } /// All events that can happen in the daemon. Sent from various threads and exposed interfaces. @@ -438,6 +441,7 @@ pub struct Daemon<L: EventListener> { shutdown_callbacks: Vec<Box<dyn FnOnce()>>, /// oneshot channel that completes once the tunnel state machine has been shut down tunnel_state_machine_shutdown_signal: oneshot::Receiver<()>, + cache_dir: PathBuf, } impl<L> Daemon<L> @@ -515,7 +519,7 @@ where tunnel_parameters_generator, log_dir, resource_dir, - cache_dir, + cache_dir.clone(), internal_event_tx.to_specialized_sender(), tunnel_state_machine_shutdown_tx, #[cfg(target_os = "android")] @@ -554,6 +558,7 @@ where app_version_info, shutdown_callbacks: vec![], tunnel_state_machine_shutdown_signal, + cache_dir, }; daemon.ensure_wireguard_keys_for_current_account(); @@ -939,6 +944,7 @@ where #[cfg(not(target_os = "android"))] FactoryReset(tx) => self.on_factory_reset(tx), Shutdown => self.trigger_shutdown_event(), + TemporaryShutdown => self.on_temporary_shutdown(), } } @@ -1658,6 +1664,15 @@ where self.disconnect_tunnel(); } + fn on_temporary_shutdown(&mut self) { + // TODO: dump the target state to a file + + if self.target_state == TargetState::Secured { + self.send_tunnel_command(TunnelCommand::BlockWhenDisconnected(true)); + } + self.trigger_shutdown_event(); + } + /// Set the target state of the client. If it changed trigger the operations needed to /// progress towards that state. /// Returns an error if trying to set secured state, but no account token is present. diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index cf5d403e47..be4842dd43 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -108,6 +108,11 @@ build_rpc_trait! { #[rpc(meta, name = "shutdown")] fn shutdown(&self, Self::Metadata) -> BoxFuture<(), Error>; + /// Saves the target tunnel state and quits in a blocking state. The state is restored + /// upon restart. + #[rpc(meta, name = "temporary_shutdown")] + fn temporary_shutdown(&self, Self::Metadata) -> BoxFuture<(), Error>; + /// Get previously used account tokens from the account history #[rpc(meta, name = "get_account_history")] fn get_account_history(&self, Self::Metadata) -> BoxFuture<Vec<AccountToken>, Error>; @@ -530,6 +535,11 @@ impl ManagementInterfaceApi for ManagementInterface { Box::new(self.send_command_to_daemon(DaemonCommand::Shutdown)) } + fn temporary_shutdown(&self, _: Self::Metadata) -> BoxFuture<(), Error> { + log::debug!("temporary_shutdown"); + Box::new(self.send_command_to_daemon(DaemonCommand::TemporaryShutdown)) + } + fn get_account_history(&self, _: Self::Metadata) -> BoxFuture<Vec<AccountToken>, Error> { log::debug!("get_account_history"); let (tx, rx) = sync::oneshot::channel(); diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs index 631dbd054d..7f9709abcd 100644 --- a/mullvad-ipc-client/src/lib.rs +++ b/mullvad-ipc-client/src/lib.rs @@ -223,6 +223,10 @@ impl DaemonRpcClient { self.call("shutdown", &NO_ARGS) } + pub fn temporary_shutdown(&mut self) -> Result<()> { + self.call("temporary_shutdown", &NO_ARGS) + } + pub fn factory_reset(&mut self) -> Result<()> { self.call("factory_reset", &NO_ARGS) } |
