Skip to content

Commit ae976c4

Browse files
switch to last_unsuspend
1 parent cf51715 commit ae976c4

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

netwatch/src/interfaces.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ pub struct State {
189189
/// When set, its value is the map key into `interface` and `interface_ips`.
190190
pub default_route_interface: Option<String>,
191191

192-
/// Monotonic timestamp used to force [`n0_watcher::Watchable`] notifications.
193-
pub last_updated: n0_future::time::Instant,
192+
/// Monotonic timestamp, when an unsuspend was detected.
193+
pub last_unsuspend: Option<n0_future::time::Instant>,
194194
}
195195

196196
impl fmt::Display for State {
@@ -260,7 +260,7 @@ impl State {
260260
have_v6,
261261
is_expensive: false,
262262
default_route_interface,
263-
last_updated: n0_future::time::Instant::now(),
263+
last_unsuspend: None,
264264
}
265265
}
266266

@@ -277,20 +277,10 @@ impl State {
277277
have_v4: true,
278278
is_expensive: false,
279279
default_route_interface: Some(ifname),
280-
last_updated: n0_future::time::Instant::now(),
280+
last_unsuspend: None,
281281
}
282282
}
283283

284-
/// Compares network state ignoring `last_updated`.
285-
pub fn eq_ignoring_timestamp(&self, other: &State) -> bool {
286-
self.interfaces == other.interfaces
287-
&& self.local_addresses == other.local_addresses
288-
&& self.have_v6 == other.have_v6
289-
&& self.have_v4 == other.have_v4
290-
&& self.is_expensive == other.is_expensive
291-
&& self.default_route_interface == other.default_route_interface
292-
}
293-
294284
/// Is this a major change compared to the `old` one?.
295285
pub fn is_major_change(&self, old: &State) -> bool {
296286
if self.have_v6 != old.have_v6

netwatch/src/interfaces/wasm_browser.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub struct State {
7979
/// The URL to the Proxy Autoconfig URL, if applicable.
8080
pub(crate) pac: Option<String>,
8181

82-
/// Monotonic timestamp used to force [`n0_watcher::Watchable`] notifications.
83-
pub last_updated: Instant,
82+
/// Monotonic timestamp, when an unsuspend was detected.
83+
pub last_unsuspend: Option<n0_future::time::Instant>,
8484
}
8585

8686
impl fmt::Display for State {
@@ -121,21 +121,10 @@ impl State {
121121
default_route_interface: Some(BROWSER_INTERFACE.to_string()),
122122
http_proxy: None,
123123
pac: None,
124-
last_updated: Instant::now(),
124+
last_unsuspend: None,
125125
}
126126
}
127127

128-
/// Compares network state ignoring `last_updated`.
129-
pub fn eq_ignoring_timestamp(&self, other: &State) -> bool {
130-
self.interfaces == other.interfaces
131-
&& self.have_v6 == other.have_v6
132-
&& self.have_v4 == other.have_v4
133-
&& self.is_expensive == other.is_expensive
134-
&& self.default_route_interface == other.default_route_interface
135-
&& self.http_proxy == other.http_proxy
136-
&& self.pac == other.pac
137-
}
138-
139128
/// Is this a major change compared to the `old` one?.
140129
pub fn is_major_change(&self, old: &State) -> bool {
141130
// All changes are major.

netwatch/src/netmon/actor.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ impl Actor {
143143
async fn handle_potential_change(&mut self, time_jumped: bool) {
144144
trace!("potential change");
145145

146-
let new_state = State::new().await;
146+
let mut new_state = State::new().await;
147147
let old_state = &self.interface_state.get();
148148

149-
// No major changes, continue on
150-
if !time_jumped && old_state.eq_ignoring_timestamp(&new_state) {
149+
if time_jumped {
150+
new_state.last_unsuspend.replace(Instant::now());
151+
} else if old_state == &new_state {
152+
// No major changes, continue on
151153
debug!("no changes detected");
152154
return;
153155
}

0 commit comments

Comments
 (0)