diff options
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 13 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 25 | ||||
| -rw-r--r-- | mullvad-rpc/src/lib.rs | 8 |
3 files changed, 42 insertions, 4 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index b4ca11d32e..e6e6c39ab8 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -34,7 +34,7 @@ use futures::{ use log::{debug, error, info, warn}; use mullvad_rpc::{AccountsProxy, HttpHandle, WireguardKeyProxy}; use mullvad_types::{ - account::{AccountData, AccountToken}, + account::{AccountData, AccountToken, VoucherSubmission}, endpoint::MullvadEndpoint, location::GeoIpLocation, relay_constraints::{ @@ -781,6 +781,7 @@ where CreateNewAccount(tx) => self.on_create_new_account(tx), GetAccountData(tx, account_token) => self.on_get_account_data(tx, account_token), GetWwwAuthToken(tx) => self.on_get_www_auth_token(tx), + SubmitVoucher(tx, voucher) => self.on_submit_voucher(tx, voucher), GetRelayLocations(tx) => self.on_get_relay_locations(tx), UpdateRelayLocations => self.on_update_relay_locations(), SetAccount(tx, account_token) => self.on_set_account(tx, account_token), @@ -1022,6 +1023,16 @@ where } } + fn on_submit_voucher( + &mut self, + tx: oneshot::Sender<BoxFuture<VoucherSubmission, mullvad_rpc::Error>>, + voucher: String, + ) { + if let Some(account_token) = self.settings.get_account_token() { + let rpc_call = self.accounts_proxy.submit_voucher(account_token, voucher); + Self::oneshot_send(tx, Box::new(rpc_call), "submit_voucher response"); + } + } fn on_get_relay_locations(&mut self, tx: oneshot::Sender<RelayList>) { Self::oneshot_send(tx, self.relay_selector.get_locations(), "relay locations"); diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index afa6ad165e..56d1e100cb 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -13,7 +13,7 @@ use jsonrpc_pubsub::{PubSubHandler, PubSubMetadata, Session, SubscriptionId}; use mullvad_paths; use mullvad_rpc; use mullvad_types::{ - account::{AccountData, AccountToken}, + account::{AccountData, AccountToken, VoucherSubmission}, location::GeoIpLocation, relay_constraints::{BridgeSettings, BridgeState, RelaySettingsUpdate}, relay_list::RelayList, @@ -52,6 +52,10 @@ build_rpc_trait! { #[rpc(meta, name = "get_www_auth_token")] fn get_www_auth_token(&self, Self::Metadata) -> BoxFuture<String, Error>; + /// Submit voucher to add time to account + #[rpc(meta, name = "submit_voucher")] + fn submit_voucher(&self, Self::Metadata, String) -> BoxFuture<VoucherSubmission, Error>; + /// Returns available countries. #[rpc(meta, name = "get_relay_locations")] fn get_relay_locations(&self, Self::Metadata) -> BoxFuture<RelayList, Error>; @@ -195,6 +199,11 @@ pub enum ManagementCommand { ), /// Request www auth token for an account GetWwwAuthToken(OneshotSender<BoxFuture<String, mullvad_rpc::Error>>), + /// Submit voucher to add time to the current account. Returns time added in seconds + SubmitVoucher( + OneshotSender<BoxFuture<VoucherSubmission, mullvad_rpc::Error>>, + String, + ), /// Request account history GetAccountHistory(OneshotSender<Vec<AccountToken>>), /// Request account history @@ -441,6 +450,20 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi Box::new(future) } + fn submit_voucher( + &self, + _: Self::Metadata, + voucher: String, + ) -> BoxFuture<VoucherSubmission, Error> { + log::debug!("submit_voucher"); + let (tx, rx) = sync::oneshot::channel(); + let future = self + .send_command_to_daemon(ManagementCommand::SubmitVoucher(tx, voucher)) + .and_then(|_| rx.map_err(|_| Error::internal_error())) + .and_then(|f| f.map_err(|e| Self::map_rpc_error(&e))); + Box::new(future) + } + fn get_relay_locations(&self, _: Self::Metadata) -> BoxFuture<RelayList, Error> { log::debug!("get_relay_locations"); let (tx, rx) = sync::oneshot::channel(); diff --git a/mullvad-rpc/src/lib.rs b/mullvad-rpc/src/lib.rs index f3fcd4d209..d16029c16d 100644 --- a/mullvad-rpc/src/lib.rs +++ b/mullvad-rpc/src/lib.rs @@ -11,7 +11,11 @@ use chrono::{offset::Utc, DateTime}; use jsonrpc_client_core::{expand_params, jsonrpc_client}; use jsonrpc_client_http::{header::Host, HttpTransport, HttpTransportBuilder}; -use mullvad_types::{account::AccountToken, relay_list::RelayList, version}; +use mullvad_types::{ + account::{AccountToken, VoucherSubmission}, + relay_list::RelayList, + version, +}; use std::{ collections::BTreeMap, net::{IpAddr, Ipv4Addr}, @@ -107,7 +111,7 @@ jsonrpc_client!(pub struct AccountsProxy { pub fn create_account(&mut self) -> RpcRequest<AccountToken>; pub fn get_expiry(&mut self, account_token: AccountToken) -> RpcRequest<DateTime<Utc>>; pub fn get_www_auth_token(&mut self, account_token: AccountToken) -> RpcRequest<String>; - pub fn submit_voucher(&mut self, account_token: AccountToken) -> RpcRequest<String>; + pub fn submit_voucher(&mut self, account_token: AccountToken, voucher: String) -> RpcRequest<VoucherSubmission>; }); jsonrpc_client!(pub struct ProblemReportProxy { |
