Skip to main content

RelaySeenCache

Struct RelaySeenCache 

Source
pub struct RelaySeenCache { /* private fields */ }
Expand description

Bounded, insertion-ordered record of recently handled message ids.

Implementations§

Source§

impl RelaySeenCache

Source

pub fn new() -> Self

Creates a cache with the default sizing.

Source

pub fn with_config(config: RelaySeenConfig) -> Self

Creates a cache with explicit sizing.

Source

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.

Source

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.

Source

pub fn contains(&self, message_id: &str) -> bool

Whether message_id is currently suppressed, without recording it.

Source

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.

Source

pub fn len(&self) -> usize

Number of ids currently tracked.

Source

pub fn is_empty(&self) -> bool

Whether the cache holds no ids.

Source

pub fn duplicates_suppressed(&self) -> u64

How many arrivals were suppressed as already-handled.

Source

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.

Source

pub fn clear(&mut self)

Removes every entry.

Trait Implementations§

Source§

impl Debug for RelaySeenCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RelaySeenCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more