pub struct ReplayCache { /* private fields */ }Expand description
Bounded FIFO cache of (link_id, signature, nonce) SHA-256
fingerprints. Cheap to clone (it’s behind an Arc in the daemon’s
AppState); the inner mutex serialises every insert/lookup so the
cache is safe to share across handler invocations.
Implementations§
Source§impl ReplayCache
impl ReplayCache
Sourcepub fn record_and_check(
&self,
link_id: &str,
signature: &[u8],
nonce: &str,
) -> ReplayDecision
pub fn record_and_check( &self, link_id: &str, signature: &[u8], nonce: &str, ) -> ReplayDecision
Fingerprint (link_id, signature, nonce) and check membership.
Returns true if the fingerprint has been seen before — the
caller should reject the request as a replay. Returns false
on the first seen value AND inserts it as a side effect.
The caller is responsible for producing the nonce (random UUID expected) and for choosing whether to bypass this check when the request omits the nonce field (back-compat mode).
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of currently-cached fingerprints. Useful for tests and for a future metrics exporter.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the cache is empty. Trivial helper to satisfy clippy
(len_zero) on the few call sites that care.
Sourcepub fn evictions_since_boot(&self) -> u64
pub fn evictions_since_boot(&self) -> u64
v0.7.0 #1033 — cumulative number of FIFO evictions since
process boot. Non-zero values mean the cache hit its ceiling
and dropped older fingerprints to make room. Operators should
surface this via a metrics exporter and page on sustained
growth: either legitimate verify-flow load is exceeding the
documented ceiling (escalate to a true distributed cache) OR
an attacker is flooding unique nonces to evict legitimate
fingerprints (the issue’s flush-attack vector — investigate
rate-limit at /api/v1/links/verify).
Trait Implementations§
Source§impl Debug for ReplayCache
impl Debug for ReplayCache
Source§impl Default for ReplayCache
impl Default for ReplayCache
Source§fn default() -> ReplayCache
fn default() -> 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 UnsafeUnpin 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
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