summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-daemon/src/lib.rs3
-rw-r--r--mullvad-rpc/src/availability.rs29
-rw-r--r--mullvad-rpc/src/rest.rs11
3 files changed, 38 insertions, 5 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 7597f01020..cffef475d4 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -588,6 +588,7 @@ where
.map_err(Error::InitRpcFactory)?;
let rpc_handle = rpc_runtime.mullvad_rest_handle();
let api_availability = rpc_runtime.availability_handle();
+ api_availability.suspend();
let relay_list_listener = event_listener.clone();
let on_relay_list_update = move |relay_list: &RelayList| {
@@ -718,6 +719,8 @@ where
.await
.map_err(Error::TunnelError)?;
+ api_availability.unsuspend();
+
Self::forward_offline_state(&runtime, api_availability.clone(), offline_state_rx).await;
let tsm_api_address_change_tx = Arc::downgrade(&tunnel_command_tx);
diff --git a/mullvad-rpc/src/availability.rs b/mullvad-rpc/src/availability.rs
index 8b7df698fa..77803b44b2 100644
--- a/mullvad-rpc/src/availability.rs
+++ b/mullvad-rpc/src/availability.rs
@@ -18,13 +18,18 @@ pub enum Error {
#[derive(PartialEq, Eq, Clone, Copy, Debug, Default)]
pub struct State {
+ suspended: bool,
pause_background: bool,
offline: bool,
}
impl State {
+ pub fn is_suspended(&self) -> bool {
+ self.suspended
+ }
+
pub fn is_background_paused(&self) -> bool {
- self.pause_background
+ self.offline || self.pause_background || self.suspended
}
pub fn is_offline(&self) -> bool {
@@ -63,6 +68,22 @@ pub struct ApiAvailabilityHandle {
}
impl ApiAvailabilityHandle {
+ pub fn suspend(&self) {
+ let mut state = self.state.lock().unwrap();
+ if !state.suspended {
+ state.suspended = true;
+ let _ = self.tx.send(*state);
+ }
+ }
+
+ pub fn unsuspend(&self) {
+ let mut state = self.state.lock().unwrap();
+ if state.suspended {
+ state.suspended = false;
+ let _ = self.tx.send(*state);
+ }
+ }
+
pub fn pause_background(&self) {
let mut state = self.state.lock().unwrap();
if !state.pause_background {
@@ -91,8 +112,12 @@ impl ApiAvailabilityHandle {
*self.state.lock().unwrap()
}
+ pub fn wait_for_unsuspend(&self) -> impl Future<Output = Result<(), Error>> {
+ self.wait_for_state(|state| !state.is_suspended())
+ }
+
pub fn wait_background(&self) -> impl Future<Output = Result<(), Error>> {
- self.wait_for_state(|state| !state.is_offline() && !state.is_background_paused())
+ self.wait_for_state(|state| !state.is_background_paused())
}
pub fn wait_online(&self) -> impl Future<Output = Result<(), Error>> {
diff --git a/mullvad-rpc/src/rest.rs b/mullvad-rpc/src/rest.rs
index 64bc5d2204..cc2510f97f 100644
--- a/mullvad-rpc/src/rest.rs
+++ b/mullvad-rpc/src/rest.rs
@@ -142,11 +142,16 @@ impl RequestService {
let hyper_request = request.into_request();
let host_addr = get_request_socket_addr(&hyper_request);
- let (request_future, abort_handle) =
- abortable(self.client.request(hyper_request).map_err(Error::from));
+ let api_availability = self.api_availability.clone();
+ let suspend_fut = api_availability.wait_for_unsuspend();
+ let request_fut = self.client.request(hyper_request).map_err(Error::from);
+
+ let (request_future, abort_handle) = abortable(async move {
+ let _ = suspend_fut.await;
+ request_fut.await
+ });
let address_cache = self.address_cache.clone();
let handle = self.handle.clone();
- let api_availability = self.api_availability.clone();
let future = async move {
let response =