diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-05-09 17:17:26 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-05-09 17:56:12 +0200 |
| commit | 7cb5f4713766b1b0632dcef053d84b3bacf82fe5 (patch) | |
| tree | 74ac2ed794ed59862126a0f725970067780f1c5b /mullvad_daemon/src/ipc_api.rs | |
| parent | 699e00b8882761171ae454fcf999eef51ab5d118 (diff) | |
| download | mullvadvpn-7cb5f4713766b1b0632dcef053d84b3bacf82fe5.tar.xz mullvadvpn-7cb5f4713766b1b0632dcef053d84b3bacf82fe5.zip | |
Change mullvad_daemon to new ipc with pubsub
Diffstat (limited to 'mullvad_daemon/src/ipc_api.rs')
| -rw-r--r-- | mullvad_daemon/src/ipc_api.rs | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/mullvad_daemon/src/ipc_api.rs b/mullvad_daemon/src/ipc_api.rs new file mode 100644 index 0000000000..84932a0b8f --- /dev/null +++ b/mullvad_daemon/src/ipc_api.rs @@ -0,0 +1,90 @@ +use jsonrpc_core::Error; +use jsonrpc_core::futures::BoxFuture; +use jsonrpc_macros::pubsub; +use jsonrpc_pubsub::SubscriptionId; + +use std::collections::HashMap; +use std::net::IpAddr; + +pub type AccountToken = String; +pub type CountryCode = String; + +build_rpc_trait! { + pub trait IpcApi { + type Metadata; + + /// Fetches and returns metadata about an account. Returns an error on non-existing + /// accounts. + #[rpc(name = "get_account_data")] + fn get_account_data(&self, AccountToken) -> Result<AccountData, Error>; + + /// Returns available countries. + #[rpc(name = "get_countries")] + fn get_countries(&self) -> Result<HashMap<CountryCode, String>, Error>; + + /// Set which account to connect with + #[rpc(name = "set_account")] + fn set_account(&self, AccountToken) -> Result<(), Error>; + + /// Set which country to connect to + #[rpc(name = "set_country")] + fn set_country(&self, CountryCode) -> Result<(), Error>; + + /// Set if the backend should automatically establish a tunnel on start or not. + #[rpc(name = "set_autoconnect")] + fn set_autoconnect(&self, bool) -> Result<(), Error>; + + /// Try to connect if disconnected, or do nothing if already connecting/connected. + #[rpc(name = "connect")] + fn connect(&self) -> Result<(), Error>; + + /// Disconnect the VPN tunnel if it is connecting/connected. Does nothing if already + /// disconnected. + #[rpc(name = "disconnect")] + fn disconnect(&self) -> Result<(), Error>; + + /// Returns the current security state of the Mullvad client. Changes to this state will + /// be announced to subscribers of `event`. + #[rpc(name = "get_state")] + fn get_state(&self) -> Result<SecurityState, Error>; + + /// Returns the current public IP of this computer. + #[rpc(name = "get_ip")] + fn get_ip(&self) -> Result<IpAddr, Error>; + + /// Performs a geoIP lookup and returns the current location as perceived by the public + /// internet. + #[rpc(name = "get_location")] + fn get_location(&self) -> Result<Location, Error>; + + #[pubsub(name = "event")] { + /// Subscribes to the `event` notifications. + #[rpc(name = "event_subscribe")] + fn subscribe(&self, Self::Metadata, pubsub::Subscriber<String>); + + /// Unsubscribes from the `event` notifications. + #[rpc(name = "event_unsubscribe")] + fn unsubscribe(&self, SubscriptionId) -> BoxFuture<bool, Error>; + } + } +} + +#[derive(Serialize)] +pub struct AccountData { + pub paid_until: String, +} + +#[derive(Serialize)] +pub struct Location { + pub latlong: [f64; 2], + pub country: String, + pub city: String, +} + +#[derive(Serialize)] +pub enum SecurityState { + Unsecured, + Securing, + Secured, + Unsecuring, +} |
