summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src
diff options
context:
space:
mode:
Diffstat (limited to 'mullvad-daemon/src')
-rw-r--r--mullvad-daemon/src/geoip.rs75
-rw-r--r--mullvad-daemon/src/lib.rs49
2 files changed, 52 insertions, 72 deletions
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);
}