diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-10-26 21:34:27 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-10-26 21:46:26 +0200 |
| commit | b31de5df85dedcb52e4b1bfc52a0ce85b61b9160 (patch) | |
| tree | 805e0b308412533841babc2d9797fb87492dad43 /mullvad-daemon/src | |
| parent | e8d90444b5b9bbd0bb8bbd1552c0c4844dde3451 (diff) | |
| download | mullvadvpn-b31de5df85dedcb52e4b1bfc52a0ce85b61b9160.tar.xz mullvadvpn-b31de5df85dedcb52e4b1bfc52a0ce85b61b9160.zip | |
Extract master RPC client code to own crate
Diffstat (limited to 'mullvad-daemon/src')
| -rw-r--r-- | mullvad-daemon/src/main.rs | 13 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 10 | ||||
| -rw-r--r-- | mullvad-daemon/src/master.rs | 16 |
3 files changed, 9 insertions, 30 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index e804dcace8..ad2850b926 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -20,9 +20,6 @@ extern crate serde; #[macro_use] extern crate serde_derive; -#[macro_use] -extern crate jsonrpc_client_core; -extern crate jsonrpc_client_http; extern crate jsonrpc_core; #[macro_use] extern crate jsonrpc_macros; @@ -32,6 +29,7 @@ extern crate jsonrpc_ws_server; extern crate lazy_static; extern crate uuid; +extern crate mullvad_rpc; extern crate mullvad_types; extern crate talpid_core; extern crate talpid_ipc; @@ -39,7 +37,6 @@ extern crate talpid_types; mod cli; mod management_interface; -mod master; mod rpc_info; mod settings; mod shutdown; @@ -47,10 +44,9 @@ mod shutdown; use error_chain::ChainedError; use futures::Future; -use jsonrpc_client_http::HttpHandle; use jsonrpc_core::futures::sync::oneshot::Sender as OneshotSender; use management_interface::{BoxFuture, ManagementInterfaceServer, TunnelCommand}; -use master::AccountsProxy; +use mullvad_rpc::{AccountsProxy, HttpHandle}; use mullvad_types::account::{AccountData, AccountToken}; use mullvad_types::relay_endpoint::RelayEndpoint; use mullvad_types::states::{DaemonState, SecurityState, TargetState}; @@ -206,8 +202,7 @@ impl Daemon { tx, management_interface_broadcaster, settings: settings::Settings::load().chain_err(|| "Unable to read settings")?, - accounts_proxy: master::create_account_proxy() - .chain_err(|| "Unable to bootstrap RPC client")?, + accounts_proxy: AccountsProxy::connect().chain_err(|| "Unable to connect RPC client")?, firewall: FirewallProxy::new().chain_err(|| ErrorKind::FirewallError)?, relay_endpoint: None, tunnel_metadata: None, @@ -339,7 +334,7 @@ impl Daemon { fn on_get_account_data( &mut self, - tx: OneshotSender<BoxFuture<AccountData, jsonrpc_client_core::Error>>, + tx: OneshotSender<BoxFuture<AccountData, mullvad_rpc::Error>>, account_token: AccountToken, ) { let rpc_call = self.accounts_proxy diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 829f843fca..43e55f4cb4 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -1,13 +1,13 @@ use error_chain; use error_chain::ChainedError; -use jsonrpc_client_core; use jsonrpc_core::{Error, ErrorCode, Metadata}; use jsonrpc_core::futures::{future, sync, Future}; use jsonrpc_core::futures::sync::oneshot::Sender as OneshotSender; use jsonrpc_macros::pubsub; use jsonrpc_pubsub::{PubSubHandler, PubSubMetadata, Session, SubscriptionId}; use jsonrpc_ws_server; +use mullvad_rpc; use mullvad_types::account::{AccountData, AccountToken}; use mullvad_types::location::{CountryCode, Location}; use mullvad_types::relay_endpoint::RelayEndpoint; @@ -126,7 +126,7 @@ pub enum TunnelCommand { GetState(OneshotSender<DaemonState>), /// Request the metadata for an account. GetAccountData( - OneshotSender<BoxFuture<AccountData, jsonrpc_client_core::Error>>, + OneshotSender<BoxFuture<AccountData, mullvad_rpc::Error>>, AccountToken, ), /// Set which account token to use for subsequent connection attempts. @@ -283,9 +283,9 @@ impl<T: From<TunnelCommand> + 'static + Send> ManagementInterface<T> { /// Converts the given error to an error that can be given to the caller of the API. /// Will let any actual RPC error through as is, any other error is changed to an internal /// error. - fn map_rpc_error(error: jsonrpc_client_core::Error) -> Error { + fn map_rpc_error(error: mullvad_rpc::Error) -> Error { match error.kind() { - &jsonrpc_client_core::ErrorKind::JsonRpcError(ref rpc_error) => { + &mullvad_rpc::ErrorKind::JsonRpcError(ref rpc_error) => { // We have to manually copy the error since we have different // versions of the jsonrpc_core library at the moment. Error { @@ -344,7 +344,7 @@ impl<T: From<TunnelCommand> + 'static + Send> ManagementInterfaceApi for Managem let future = self.send_command_to_daemon(TunnelCommand::GetAccountData(tx, account_token)) .and_then(|_| rx.map_err(|_| Error::internal_error())) .and_then(|rpc_future| { - rpc_future.map_err(|error: jsonrpc_client_core::Error| { + rpc_future.map_err(|error: mullvad_rpc::Error| { error!( "Unable to get account data from master: {}", error.display_chain() diff --git a/mullvad-daemon/src/master.rs b/mullvad-daemon/src/master.rs deleted file mode 100644 index 37bfbe65e5..0000000000 --- a/mullvad-daemon/src/master.rs +++ /dev/null @@ -1,16 +0,0 @@ -use chrono::DateTime; -use chrono::offset::Utc; -use jsonrpc_client_http::{Error as HttpError, HttpHandle, HttpTransport}; - -use mullvad_types::account::AccountToken; - -static MASTER_API_URI: &str = "https://api.mullvad.net/rpc/"; - -pub fn create_account_proxy() -> Result<AccountsProxy<HttpHandle>, HttpError> { - let transport = HttpTransport::new()?.handle(MASTER_API_URI)?; - Ok(AccountsProxy::new(transport)) -} - -jsonrpc_client!(pub struct AccountsProxy { - pub fn get_expiry(&mut self, account_token: AccountToken) -> RpcRequest<DateTime<Utc>>; -}); |
