SeenMessageCache

Struct SeenMessageCache 

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

Cache of seen message IDs for deduplication

Tracks message IDs with TTL expiration to prevent infinite relay loops while allowing legitimate re-transmissions.

Implementations§

Source§

impl SeenMessageCache

Source

pub fn new() -> Self

Create a new cache with default TTL

Source

pub fn with_ttl(ttl_ms: u64) -> Self

Create with custom TTL

Source

pub fn has_seen(&self, message_id: &MessageId) -> bool

Check if a message has been seen before

Returns true if the message was already seen (should not process/relay). Returns false if this is a new message (should process).

Source

pub fn mark_seen( &mut self, message_id: MessageId, origin: NodeId, now_ms: u64, ) -> bool

Mark a message as seen

Returns true if this is a new message (first time seen). Returns false if we’ve seen this message before.

Source

pub fn check_and_mark( &mut self, message_id: MessageId, origin: NodeId, now_ms: u64, ) -> bool

Check and mark in one operation

Returns true if this is a new message that should be processed. Returns false if the message was already seen (duplicate).

Source

pub fn cleanup(&mut self, now_ms: u64)

Remove expired entries

Source

pub fn len(&self) -> usize

Get the number of entries in the cache

Source

pub fn is_empty(&self) -> bool

Check if the cache is empty

Source

pub fn clear(&mut self)

Clear all entries

Source

pub fn get_stats(&self, message_id: &MessageId) -> Option<(u64, u32, NodeId)>

Get statistics about a message

Trait Implementations§

Source§

impl Debug for SeenMessageCache

Source§

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

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

impl Default for SeenMessageCache

Available on crate feature std only.
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, 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.