diff options
Diffstat (limited to 'src/state')
| -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)) } |
