pub struct FederationNonceCache { /* private fields */ }Expand description
v0.7.0 #922 — per-peer bounded FIFO cache of (peer_id, nonce).
Implementations§
Source§impl FederationNonceCache
impl FederationNonceCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Fresh empty cache. In-memory only — the cache resets on every
daemon restart. Prefer Self::new_with_db_persistence in
production: pre-#1255 the in-memory-only cache opened a
replay window on every restart.
Sourcepub fn new_with_db_persistence(db_path: impl Into<PathBuf>) -> Result<Self>
pub fn new_with_db_persistence(db_path: impl Into<PathBuf>) -> Result<Self>
#1255 (MED, 2026-05-25) — persistence-enabled constructor.
Opens the ai-memory sqlite DB at db_path (runs migrations
to ensure the federation_nonce_cache table is present),
rehydrates the in-memory cache from the persisted rows
(oldest last_touch first so the in-process LRU ordering
matches the on-disk order), and arms the cache so every
subsequent Fresh fingerprint is persisted to disk.
Construction errors out if the DB cannot be opened or migrated — operators want loud failure here, not a silent fallback to in-memory mode that re-opens the replay window.
§Errors
Returns an error if the DB cannot be opened or the load query fails.
Sourcepub fn record_and_check(&self, peer_id: &str, nonce: &str) -> ReplayDecision
pub fn record_and_check(&self, peer_id: &str, nonce: &str) -> ReplayDecision
Check + record (peer_id, nonce).
Sourcepub fn peer_evictions_since_boot(&self) -> u64
pub fn peer_evictions_since_boot(&self) -> u64
v0.7.0 #1038 — cumulative number of peer-slot evictions
(outer LRU). Non-zero means peer churn caused the outer
HashMap to hit FEDERATION_NONCE_MAX_PEERS and drop an
older peer’s slot. Operators page on sustained growth.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Distinct peers with at least one cached fingerprint.
Sourcepub fn len_for_peer(&self, peer_id: &str) -> usize
pub fn len_for_peer(&self, peer_id: &str) -> usize
Cached fingerprints for peer_id.
Trait Implementations§
Source§impl Debug for FederationNonceCache
impl Debug for FederationNonceCache
Source§impl Default for FederationNonceCache
impl Default for FederationNonceCache
Source§fn default() -> FederationNonceCache
fn default() -> FederationNonceCache
Auto Trait Implementations§
impl !Freeze for FederationNonceCache
impl RefUnwindSafe for FederationNonceCache
impl Send for FederationNonceCache
impl Sync for FederationNonceCache
impl Unpin for FederationNonceCache
impl UnsafeUnpin for FederationNonceCache
impl UnwindSafe for FederationNonceCache
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more