pub struct ReplayCache { /* private fields */ }Expand description
TTL-based replay cache with automatic expiration and O(1) eviction
Uses VecDeque to track insertion order for constant-time removal of oldest entries when the cache reaches capacity, avoiding O(n log n) sorting overhead.
Implementations§
Source§impl ReplayCache
impl ReplayCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new replay cache with default settings
Default TTL: 5 minutes (longer than handshake timeout) Default max entries: 10,000
Sourcepub fn with_settings(ttl: Duration, max_entries: usize) -> Self
pub fn with_settings(ttl: Duration, max_entries: usize) -> Self
Create a replay cache with custom settings
Sourcepub fn is_replay(
&mut self,
peer_id: &str,
nonce: &[u8; 16],
timestamp: u64,
) -> bool
pub fn is_replay( &mut self, peer_id: &str, nonce: &[u8; 16], timestamp: u64, ) -> bool
Check if a nonce/timestamp combination has been seen recently
Returns true if the combination is a replay (already seen), false if new. Automatically cleans up expired entries during the check.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get current cache statistics
Trait Implementations§
Source§impl Debug for ReplayCache
impl Debug for ReplayCache
Auto Trait Implementations§
impl Freeze for ReplayCache
impl RefUnwindSafe for ReplayCache
impl Send for ReplayCache
impl Sync for ReplayCache
impl Unpin for ReplayCache
impl UnwindSafe for ReplayCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more