Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions netwatch/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use std::{collections::HashMap, fmt, net::IpAddr};

use n0_future::time::Instant;

#[cfg(any(
target_os = "freebsd",
target_os = "openbsd",
Expand Down Expand Up @@ -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<String>,

/// Monotonic timestamp, when an unsuspend was detected.
pub last_unsuspend: Option<Instant>,
}

impl fmt::Display for State {
Expand Down Expand Up @@ -257,6 +262,7 @@ impl State {
have_v6,
is_expensive: false,
default_route_interface,
last_unsuspend: None,
}
}

Expand All @@ -273,6 +279,7 @@ impl State {
have_v4: true,
is_expensive: false,
default_route_interface: Some(ifname),
last_unsuspend: None,
}
}

Expand Down
5 changes: 5 additions & 0 deletions netwatch/src/interfaces/wasm_browser.rs
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -77,6 +78,9 @@ pub struct State {

/// The URL to the Proxy Autoconfig URL, if applicable.
pub(crate) pac: Option<String>,

/// Monotonic timestamp, when an unsuspend was detected.
pub last_unsuspend: Option<Instant>,
}

impl fmt::Display for State {
Expand Down Expand Up @@ -117,6 +121,7 @@ impl State {
default_route_interface: Some(BROWSER_INTERFACE.to_string()),
http_proxy: None,
pac: None,
last_unsuspend: None,
}
}

Expand Down
8 changes: 5 additions & 3 deletions netwatch/src/netmon/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading