pub struct RelaySeenCache { /* private fields */ }Expand description
Bounded, insertion-ordered record of recently handled message ids.
Implementations§
Source§impl RelaySeenCache
impl RelaySeenCache
Sourcepub fn with_config(config: RelaySeenConfig) -> Self
pub fn with_config(config: RelaySeenConfig) -> Self
Creates a cache with explicit sizing.
Sourcepub fn observe(&mut self, message_id: &str) -> SeenOutcome
pub fn observe(&mut self, message_id: &str) -> SeenOutcome
Records message_id, reporting whether it had been seen already.
This is the single entry point: checking and recording are one step so no caller can test an id and then forget to record it, which would forward every copy.
Sourcepub fn forget(&mut self, message_id: &str)
pub fn forget(&mut self, message_id: &str)
Forgets message_id, so a later copy is treated as new again.
For a frame that was recorded as handled and then dropped without ever being transmitted — displaced from a queue, abandoned for waiting too long, refused room on the way back. The record would otherwise refuse every later copy for the rest of the retention window, including the sender’s own retransmissions, which carry the same id: a route closed for ten minutes by a few seconds of congestion, with nothing on the air to justify it.
Safe only because nothing was transmitted. An id forgotten after the frame reached a neighbor could be forwarded a second time — by every node — which is how a flood becomes a storm, so callers must be certain the frame travelled nowhere.
One exception, and only at the point of acceptance: the mesh relay governor forgets and immediately re-records an id when it accepts the sender’s own re-send of a frame it already carried. The entry is gone for no observable moment, so no echo can slip through, and a re-send the governor refuses never reaches this call.
Sourcepub fn contains(&self, message_id: &str) -> bool
pub fn contains(&self, message_id: &str) -> bool
Whether message_id is currently suppressed, without recording it.
Sourcepub fn expire(&mut self, now: Instant)
pub fn expire(&mut self, now: Instant)
Drops entries older than the retention window.
Called automatically by Self::observe; exposed so an idle node can
release memory from its process tick.
Sourcepub fn duplicates_suppressed(&self) -> u64
pub fn duplicates_suppressed(&self) -> u64
How many arrivals were suppressed as already-handled.
Sourcepub fn capacity_evictions(&self) -> u64
pub fn capacity_evictions(&self) -> u64
How many ids were dropped for capacity rather than age.
Expected to stay at zero: an id evicted while copies of it are still in flight would be forwarded again. A rising count means the cache is too small for the traffic the node is seeing.