diff options
| author | tv <tv@krebsco.de> | 2026-11-06 04:34:23 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-06 04:34:23 +0100 |
| commit | d6f6c2e020ac648b54c0e024596460ffb82ca437 (patch) | |
| tree | d2b35b071b8f2f878ab333bf39d169c14015d7d1 /src/state/peer.rs | |
| parent | b4d0f3d9671c3bac8fd3c4b6c3f5f75196a06742 (diff) | |
suspend detected
Diffstat (limited to 'src/state/peer.rs')
| -rw-r--r-- | src/state/peer.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/state/peer.rs b/src/state/peer.rs index e0cea7e..857c29d 100644 --- a/src/state/peer.rs +++ b/src/state/peer.rs @@ -370,6 +370,18 @@ impl PeerState { .map(|(bytes, _)| bytes) } + /// The machine slept for `gap` (`swarm::suspend`): heard from, added, and awaiting + /// an answer that much earlier, as the monotonic clock stood still meanwhile. + pub(crate) fn aged(&mut self, gap: Duration) { + let earlier = |at: Instant| at.checked_sub(gap).unwrap_or(at); + self.last_seen = self.last_seen.map(earlier); + self.added_at = earlier(self.added_at); + if let Some(awaiting) = &mut self.awaiting_answer { + awaiting.ask_again_at = awaiting.ask_again_at.map(earlier); + awaiting.unreached_at = earlier(awaiting.unreached_at); + } + } + fn quiet_for(&self, now: Instant) -> Duration { now.saturating_duration_since(self.last_seen.unwrap_or(self.added_at)) } |
