summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-09-08 09:47:10 +0200
committerDavid Lönnhager <david.l@mullvad.net>2020-09-08 09:47:10 +0200
commit8a76e509ec0abda73e40c6e5563d80098580bc14 (patch)
treefb3a1162dca265877fee3301bf4cb2bb9ac671d9
parent3923c6320152e12b01b52cbff9408a0bb80e057a (diff)
parent9f05c347a9d07911ffa4643f2f50cace0c331500 (diff)
downloadmullvadvpn-8a76e509ec0abda73e40c6e5563d80098580bc14.tar.xz
mullvadvpn-8a76e509ec0abda73e40c6e5563d80098580bc14.zip
Merge branch 'fix-problem-report-tool'
-rw-r--r--Cargo.lock3
-rw-r--r--mullvad-daemon/Cargo.toml3
-rw-r--r--mullvad-daemon/src/geoip.rs75
-rw-r--r--mullvad-daemon/src/lib.rs49
-rw-r--r--mullvad-problem-report/Cargo.toml1
-rw-r--r--mullvad-problem-report/src/lib.rs8
-rw-r--r--mullvad-rpc/Cargo.toml3
-rw-r--r--mullvad-rpc/src/lib.rs33
-rw-r--r--mullvad-rpc/src/rest.rs17
9 files changed, 71 insertions, 121 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0e500478ab..7ecd212fb1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1126,7 +1126,6 @@ dependencies = [
"duct 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)",
"err-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"fern 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
- "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ipnetwork 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1223,7 +1222,6 @@ dependencies = [
"duct 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"err-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mullvad-paths 0.1.0",
"mullvad-rpc 0.1.0",
@@ -1243,7 +1241,6 @@ dependencies = [
"chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
"err-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"filetime 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
- "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml
index dabaa1241a..2d3f28a196 100644
--- a/mullvad-daemon/Cargo.toml
+++ b/mullvad-daemon/Cargo.toml
@@ -13,8 +13,7 @@ chrono = { version = "0.4", features = ["serde"] }
clap = "2.25"
err-derive = "0.2.1"
fern = { version = "0.5", features = ["colored"] }
-futures01 = { package = "futures", version = "0.1" }
-futures = { package = "futures", version = "0.3", features = [ "compat" ]}
+futures = "0.3"
ipnetwork = "0.16"
lazy_static = "1.0"
log = "0.4"
diff --git a/mullvad-daemon/src/geoip.rs b/mullvad-daemon/src/geoip.rs
index 991ced7e5f..953780b6f2 100644
--- a/mullvad-daemon/src/geoip.rs
+++ b/mullvad-daemon/src/geoip.rs
@@ -1,53 +1,50 @@
-use futures01::{self, Future};
+use futures::join;
use mullvad_rpc::{self, rest::RequestServiceHandle};
use mullvad_types::location::{AmIMullvad, GeoIpLocation};
-
const URI_V4: &str = "https://ipv4.am.i.mullvad.net/json";
const URI_V6: &str = "https://ipv6.am.i.mullvad.net/json";
-pub fn send_location_request(
+pub async fn send_location_request(
request_sender: RequestServiceHandle,
-) -> impl Future<Item = GeoIpLocation, Error = mullvad_rpc::rest::Error> {
- let v4_future =
- send_location_request_internal(URI_V4, request_sender.clone()).map(GeoIpLocation::from);
- let v6_future = send_location_request_internal(URI_V6, request_sender).map(GeoIpLocation::from);
+) -> Result<GeoIpLocation, mullvad_rpc::rest::Error> {
+ let v4_sender = request_sender.clone();
+ let v4_future = async move {
+ let location = send_location_request_internal(URI_V4, v4_sender).await?;
+ Ok(GeoIpLocation::from(location))
+ };
+ let v6_sender = request_sender.clone();
+ let v6_future = async move {
+ let location = send_location_request_internal(URI_V6, v6_sender).await?;
+ Ok::<GeoIpLocation, mullvad_rpc::rest::Error>(GeoIpLocation::from(location))
+ };
- v4_future.then(
- |v4_result: Result<GeoIpLocation, mullvad_rpc::rest::Error>| {
- v6_future.then(
- |v6_result: Result<GeoIpLocation, mullvad_rpc::rest::Error>| match (
- v4_result, v6_result,
- ) {
- (Ok(mut v4), Ok(v6)) => {
- v4.ipv6 = v6.ipv6;
- v4.mullvad_exit_ip = v4.mullvad_exit_ip && v6.mullvad_exit_ip;
- Ok(v4)
- }
- (Ok(v4), Err(e)) => {
- log::debug!("Unable to fetch IPv6 GeoIP location: {}", e);
- Ok(v4)
- }
- (Err(e), Ok(v6)) => {
- log::debug!("Unable to fetch IPv4 GeoIP location: {}", e);
- Ok(v6)
- }
- (Err(e_v4), Err(_)) => Err(e_v4),
- },
- )
- },
- )
+ let (v4_result, v6_result) = join!(v4_future, v6_future);
+
+ match (v4_result, v6_result) {
+ (Ok(mut v4), Ok(v6)) => {
+ v4.ipv6 = v6.ipv6;
+ v4.mullvad_exit_ip = v4.mullvad_exit_ip && v6.mullvad_exit_ip;
+ Ok(v4)
+ }
+ (Ok(v4), Err(e)) => {
+ log::debug!("Unable to fetch IPv6 GeoIP location: {}", e);
+ Ok(v4)
+ }
+ (Err(e), Ok(v6)) => {
+ log::debug!("Unable to fetch IPv4 GeoIP location: {}", e);
+ Ok(v6)
+ }
+ (Err(e_v4), Err(_)) => Err(e_v4),
+ }
}
-fn send_location_request_internal(
+async fn send_location_request_internal(
uri: &'static str,
service: RequestServiceHandle,
-) -> impl Future<Item = AmIMullvad, Error = mullvad_rpc::rest::Error> {
+) -> Result<AmIMullvad, mullvad_rpc::rest::Error> {
let future_service = service.clone();
- let future = async move {
- let request = mullvad_rpc::rest::RestRequest::get(uri)?;
- let response = future_service.request(request).await?;
- mullvad_rpc::rest::deserialize_body(response).await
- };
- service.compat_spawn(future)
+ let request = mullvad_rpc::rest::RestRequest::get(uri)?;
+ let response = future_service.request(request).await?;
+ mullvad_rpc::rest::deserialize_body(response).await
}
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 0c5f11ab9d..430ace18f0 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -21,11 +21,9 @@ mod version_check;
use futures::{
channel::{mpsc, oneshot},
- compat::Future01CompatExt,
future::{abortable, AbortHandle, Future},
StreamExt,
};
-use futures01::Future as Future01;
use log::{debug, error, info, warn};
use mullvad_rpc::AccountsProxy;
use mullvad_types::{
@@ -1207,11 +1205,10 @@ where
async {
geoip::send_location_request(https_handle)
+ .await
.map_err(|e| {
warn!("Unable to fetch GeoIP location: {}", e.display_chain());
})
- .compat()
- .await
}
}
@@ -1242,25 +1239,16 @@ where
tx: oneshot::Sender<Result<String, mullvad_rpc::rest::Error>>,
) {
let daemon_tx = self.tx.clone();
- let future = self
- .accounts_proxy
- .create_account()
- .then(move |result| -> Result<(), ()> {
- match result {
- Ok(account_token) => {
- let _ =
- daemon_tx.send(InternalDaemonEvent::NewAccountEvent(account_token, tx));
- }
- Err(err) => {
- let _ = tx.send(Err(err));
- }
- };
- Ok(())
- });
+ let future = self.accounts_proxy.create_account();
- tokio::spawn(async {
- if future.compat().await.is_err() {
- log::error!("Failed to spawn future for creating a new account");
+ tokio::spawn(async move {
+ match future.await {
+ Ok(account_token) => {
+ let _ = daemon_tx.send(InternalDaemonEvent::NewAccountEvent(account_token, tx));
+ }
+ Err(err) => {
+ let _ = tx.send(Err(err));
+ }
}
});
}
@@ -1270,12 +1258,9 @@ where
tx: oneshot::Sender<Result<AccountData, mullvad_rpc::rest::Error>>,
account_token: AccountToken,
) {
- let expiry_old_fut = self.accounts_proxy.get_expiry(account_token);
+ let expiry_fut = self.accounts_proxy.get_expiry(account_token);
let rpc_call = async {
- let result = expiry_old_fut
- .compat()
- .await
- .map(|expiry| AccountData { expiry });
+ let result = expiry_fut.await.map(|expiry| AccountData { expiry });
Self::oneshot_send(tx, result, "account data");
};
tokio::spawn(rpc_call);
@@ -1286,10 +1271,9 @@ where
tx: oneshot::Sender<Result<String, mullvad_rpc::rest::Error>>,
) {
if let Some(account_token) = self.settings.get_account_token() {
- let old_future = self.accounts_proxy.get_www_auth_token(account_token);
+ let future = self.accounts_proxy.get_www_auth_token(account_token);
let rpc_call = async {
- let result = old_future.compat().await;
- Self::oneshot_send(tx, result, "get_www_auth_token response");
+ Self::oneshot_send(tx, future.await, "get_www_auth_token response");
};
tokio::spawn(rpc_call);
}
@@ -1301,10 +1285,9 @@ where
voucher: String,
) {
if let Some(account_token) = self.settings.get_account_token() {
- let old_future = self.accounts_proxy.submit_voucher(account_token, voucher);
+ let future = self.accounts_proxy.submit_voucher(account_token, voucher);
let rpc_call = async {
- let result = old_future.compat().await;
- Self::oneshot_send(tx, result, "submit_voucher response");
+ Self::oneshot_send(tx, future.await, "submit_voucher response");
};
tokio::spawn(rpc_call);
}
diff --git a/mullvad-problem-report/Cargo.toml b/mullvad-problem-report/Cargo.toml
index d7738b52de..d73a5fc08b 100644
--- a/mullvad-problem-report/Cargo.toml
+++ b/mullvad-problem-report/Cargo.toml
@@ -12,7 +12,6 @@ clap = "2.25"
dirs = "2.0"
env_logger = "0.7"
err-derive = "0.2.1"
-futures01 = { version = "0.1", package = "futures" }
lazy_static = "1.0"
regex = "1.0"
uuid = { version = "0.8", features = ["v4"] }
diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs
index 4265d70268..1c3fa00461 100644
--- a/mullvad-problem-report/src/lib.rs
+++ b/mullvad-problem-report/src/lib.rs
@@ -1,6 +1,5 @@
#![deny(rust_2018_idioms)]
-use futures01::Future;
use lazy_static::lazy_static;
use regex::Regex;
use std::{
@@ -266,7 +265,7 @@ pub fn send_problem_report(
let metadata =
ProblemReport::parse_metadata(&report_content).unwrap_or_else(|| metadata::collect());
- let runtime = tokio::runtime::Builder::new()
+ let mut runtime = tokio::runtime::Builder::new()
.basic_scheduler()
.enable_all()
.build()
@@ -276,9 +275,8 @@ pub fn send_problem_report(
.map_err(Error::CreateRpcClientError)?;
let rpc_client = mullvad_rpc::ProblemReportProxy::new(rpc_manager.mullvad_rest_handle());
- rpc_client
- .problem_report(user_email, user_message, &report_content, &metadata)
- .wait()
+ runtime
+ .block_on(rpc_client.problem_report(user_email, user_message, &report_content, &metadata))
.map_err(Error::SendRpcError)
}
diff --git a/mullvad-rpc/Cargo.toml b/mullvad-rpc/Cargo.toml
index 46c3dcded4..2c98bc5017 100644
--- a/mullvad-rpc/Cargo.toml
+++ b/mullvad-rpc/Cargo.toml
@@ -10,8 +10,7 @@ publish = false
[dependencies]
chrono = { version = "0.4", features = ["serde"] }
err-derive = "0.2.1"
-futures = { version = "0.3", features = [ "default", "compat" ] }
-futures01 = { package = "futures", version = "0.1" }
+futures = "0.3"
http = "0.2"
hyper = "0.13"
ipnetwork = "0.16"
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);