diff --git a/netwatch/src/interfaces.rs b/netwatch/src/interfaces.rs index 9fbbe304..2077946b 100644 --- a/netwatch/src/interfaces.rs +++ b/netwatch/src/interfaces.rs @@ -2,6 +2,8 @@ use std::{collections::HashMap, fmt, net::IpAddr}; +use n0_future::time::Instant; + #[cfg(any( target_os = "freebsd", target_os = "openbsd", @@ -188,6 +190,9 @@ pub struct State { /// /// When set, its value is the map key into `interface` and `interface_ips`. pub default_route_interface: Option, + + /// Monotonic timestamp, when an unsuspend was detected. + pub last_unsuspend: Option, } impl fmt::Display for State { @@ -257,6 +262,7 @@ impl State { have_v6, is_expensive: false, default_route_interface, + last_unsuspend: None, } } @@ -273,6 +279,7 @@ impl State { have_v4: true, is_expensive: false, default_route_interface: Some(ifname), + last_unsuspend: None, } } diff --git a/netwatch/src/interfaces/wasm_browser.rs b/netwatch/src/interfaces/wasm_browser.rs index 7db072f5..782bb651 100644 --- a/netwatch/src/interfaces/wasm_browser.rs +++ b/netwatch/src/interfaces/wasm_browser.rs @@ -1,6 +1,7 @@ use std::{collections::HashMap, fmt}; use js_sys::{JsString, Reflect}; +use n0_future::time::Instant; pub const BROWSER_INTERFACE: &str = "browserif"; @@ -77,6 +78,9 @@ pub struct State { /// The URL to the Proxy Autoconfig URL, if applicable. pub(crate) pac: Option, + + /// Monotonic timestamp, when an unsuspend was detected. + pub last_unsuspend: Option, } impl fmt::Display for State { @@ -117,6 +121,7 @@ impl State { default_route_interface: Some(BROWSER_INTERFACE.to_string()), http_proxy: None, pac: None, + last_unsuspend: None, } } diff --git a/netwatch/src/netmon/actor.rs b/netwatch/src/netmon/actor.rs index e4dc0000..3ce5bf55 100644 --- a/netwatch/src/netmon/actor.rs +++ b/netwatch/src/netmon/actor.rs @@ -143,11 +143,13 @@ impl Actor { async fn handle_potential_change(&mut self, time_jumped: bool) { trace!("potential change"); - let new_state = State::new().await; + let mut new_state = State::new().await; let old_state = &self.interface_state.get(); - // No major changes, continue on - if !time_jumped && old_state == &new_state { + if time_jumped { + new_state.last_unsuspend.replace(Instant::now()); + } else if old_state == &new_state { + // No major changes, continue on debug!("no changes detected"); return; }