diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-07-02 15:46:59 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-07-03 12:47:51 +0200 |
| commit | ce5aea0e616ae50f7c0ea4b14d945a842b46a726 (patch) | |
| tree | 31ab0f0632bc40c25afe4c647561daa5f2b9536a | |
| parent | df6c8a8a60a7fbbb971c02c8a5483430b1db029e (diff) | |
| download | mullvadvpn-ce5aea0e616ae50f7c0ea4b14d945a842b46a726.tar.xz mullvadvpn-ce5aea0e616ae50f7c0ea4b14d945a842b46a726.zip | |
Add get_state RPC call
| -rw-r--r-- | mullvad_daemon/src/main.rs | 5 | ||||
| -rw-r--r-- | mullvad_daemon/src/management_interface.rs | 17 |
2 files changed, 21 insertions, 1 deletions
diff --git a/mullvad_daemon/src/main.rs b/mullvad_daemon/src/main.rs index 2ac5922bee..5ba2f336fd 100644 --- a/mullvad_daemon/src/main.rs +++ b/mullvad_daemon/src/main.rs @@ -230,6 +230,11 @@ impl Daemon { } } TunnelCommand::SetAccount(account_token) => self.account_token = account_token, + TunnelCommand::GetAccount(tx) => { + if let Err(_) = tx.send(self.account_token.clone()) { + warn!("Unable to send current account to management interface client"); + } + } } Ok(()) } diff --git a/mullvad_daemon/src/management_interface.rs b/mullvad_daemon/src/management_interface.rs index 010ce807ec..44765f0ac5 100644 --- a/mullvad_daemon/src/management_interface.rs +++ b/mullvad_daemon/src/management_interface.rs @@ -48,10 +48,14 @@ build_rpc_trait! { #[rpc(name = "get_countries")] fn get_countries(&self) -> Result<HashMap<CountryCode, String>, Error>; - /// Set which account to connect with + /// Set which account to connect with. #[rpc(name = "set_account")] fn set_account(&self, AccountToken) -> Result<(), Error>; + /// Get which account is configured. + #[rpc(async, name = "get_account")] + fn get_account(&self) -> BoxFuture<AccountToken, Error>; + /// Set which country to connect to #[rpc(name = "set_country")] fn set_country(&self, CountryCode) -> Result<(), Error>; @@ -115,6 +119,8 @@ pub enum TunnelCommand { GetState(sync::oneshot::Sender<SecurityState>), /// Set which account token to use for subsequent connection attempts. SetAccount(AccountToken), + /// Request the current account token being used. + GetAccount(sync::oneshot::Sender<AccountToken>), } #[derive(Default)] @@ -263,6 +269,15 @@ impl<T: From<TunnelCommand> + 'static + Send> ManagementInterfaceApi for Managem .map_err(|_| Error::internal_error()) } + fn get_account(&self) -> BoxFuture<AccountToken, Error> { + trace!("get_account"); + let (tx, rx) = sync::oneshot::channel(); + match self.tx.lock().unwrap().send(TunnelCommand::GetAccount(tx)) { + Ok(()) => rx.map_err(|_| Error::internal_error()).boxed(), + Err(_) => future::err(Error::internal_error()).boxed(), + } + } + fn set_country(&self, _country_code: CountryCode) -> Result<(), Error> { trace!("set_country"); Ok(()) |
