summaryrefslogtreecommitdiffhomepage
path: root/mullvad-rpc/src
diff options
context:
space:
mode:
Diffstat (limited to 'mullvad-rpc/src')
-rw-r--r--mullvad-rpc/src/lib.rs33
-rw-r--r--mullvad-rpc/src/rest.rs17
2 files changed, 14 insertions, 36 deletions
diff --git a/mullvad-rpc/src/lib.rs b/mullvad-rpc/src/lib.rs
index 5e2e6f80fa..60e39f571e 100644
--- a/mullvad-rpc/src/lib.rs
+++ b/mullvad-rpc/src/lib.rs
@@ -1,7 +1,6 @@
#![deny(rust_2018_idioms)]
use chrono::{offset::Utc, DateTime};
-use futures01::future::Future as Future01;
use hyper::Method;
use mullvad_types::{
account::{AccountToken, VoucherSubmission},
@@ -126,7 +125,7 @@ impl AccountsProxy {
pub fn get_expiry(
&self,
account: AccountToken,
- ) -> impl Future01<Item = DateTime<Utc>, Error = rest::Error> {
+ ) -> impl Future<Output = Result<DateTime<Utc>, rest::Error>> {
let service = self.handle.service.clone();
let response = rest::send_request(
@@ -137,13 +136,13 @@ impl AccountsProxy {
Some(account),
StatusCode::OK,
);
- self.handle.service.compat_spawn(async move {
+ async move {
let account: AccountResponse = rest::deserialize_body(response.await?).await?;
Ok(account.expires)
- })
+ }
}
- pub fn create_account(&mut self) -> impl Future01<Item = AccountToken, Error = rest::Error> {
+ pub fn create_account(&mut self) -> impl Future<Output = Result<AccountToken, rest::Error>> {
let service = self.handle.service.clone();
let response = rest::send_request(
&self.handle.factory,
@@ -154,17 +153,17 @@ impl AccountsProxy {
StatusCode::CREATED,
);
- self.handle.service.compat_spawn(async move {
+ async move {
let account: AccountResponse = rest::deserialize_body(response.await?).await?;
Ok(account.token)
- })
+ }
}
pub fn submit_voucher(
&mut self,
account_token: AccountToken,
voucher_code: String,
- ) -> impl Future01<Item = VoucherSubmission, Error = rest::Error> {
+ ) -> impl Future<Output = Result<VoucherSubmission, rest::Error>> {
#[derive(serde::Serialize)]
struct VoucherSubmission {
voucher_code: String,
@@ -182,15 +181,13 @@ impl AccountsProxy {
StatusCode::OK,
);
- self.handle
- .service
- .compat_spawn(async move { rest::deserialize_body(response.await?).await })
+ async move { rest::deserialize_body(response.await?).await }
}
pub fn get_www_auth_token(
&self,
account: AccountToken,
- ) -> impl Future01<Item = String, Error = rest::Error> {
+ ) -> impl Future<Output = Result<String, rest::Error>> {
#[derive(serde::Deserialize)]
struct AuthTokenResponse {
auth_token: String,
@@ -206,12 +203,10 @@ impl AccountsProxy {
StatusCode::OK,
);
- let future = async move {
+ async move {
let response: AuthTokenResponse = rest::deserialize_body(response.await?).await?;
Ok(response.auth_token)
- };
-
- self.handle.service.compat_spawn(future)
+ }
}
}
@@ -230,7 +225,7 @@ impl ProblemReportProxy {
message: &str,
log: &str,
metadata: &BTreeMap<String, String>,
- ) -> impl Future01<Item = (), Error = rest::Error> {
+ ) -> impl Future<Output = Result<(), rest::Error>> {
#[derive(serde::Serialize)]
struct ProblemReport {
address: String,
@@ -257,10 +252,10 @@ impl ProblemReportProxy {
StatusCode::NO_CONTENT,
);
- self.handle.service.compat_spawn(async move {
+ async move {
request.await?;
Ok(())
- })
+ }
}
}
diff --git a/mullvad-rpc/src/rest.rs b/mullvad-rpc/src/rest.rs
index 0e8994b1c3..025c22eaa8 100644
--- a/mullvad-rpc/src/rest.rs
+++ b/mullvad-rpc/src/rest.rs
@@ -5,7 +5,6 @@ use futures::{
stream::StreamExt,
TryFutureExt,
};
-use futures01::Future as OldFuture;
use hyper::{
client::{connect::Connect, Client},
header::{self, HeaderValue},
@@ -194,22 +193,6 @@ impl RequestServiceHandle {
completion_rx.await.map_err(|_| Error::ReceiveError)?
}
- /// Spawns a future on the hyper runtime returning an old-style future that can be spawned on
- /// any runtime
- pub fn compat_spawn<T: Send + std::fmt::Debug + 'static>(
- &self,
- future: impl Future<Output = Result<T>> + Send + 'static,
- ) -> impl futures01::Future<Item = T, Error = Error> {
- let (tx, rx) = futures01::sync::oneshot::channel();
- let _ = self.handle.spawn(async move {
- let result = future.await;
- let _ = tx.send(result);
- });
-
-
- rx.map_err(|_| Error::ReceiveError).flatten()
- }
-
/// Spawns a future on the RPC runtime.
pub fn spawn<T: Send + 'static>(&self, future: impl Future<Output = T> + Send + 'static) {
let _ = self.handle.spawn(future);