Skip to main content

IdentityCache

Struct IdentityCache 

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

IdentityCache is an LRU cache that maps NodeId to a verified identity record.

IdentityCache avoids repeated Merkle proof verification for frequently-seen peers. Callers must propagate key rotation and revocation events via on_rotation and on_revocation to keep cached entries consistent with the log.

Implementations§

Source§

impl IdentityCache

Source

pub fn new(settings: Option<&IdentityCacheSettings>) -> Result<Self, Error>

new creates an identity cache with the given settings.

Pass None to use the default settings (CACHE_DEFAULT_CAPACITY, CACHE_DEFAULT_TTL).

§Errors

Returns Err if the underlying C allocation fails.

Source

pub fn lookup( &mut self, node_id: &NodeId, now: Tstamp, ) -> Result<CachedIdentity, Error>

lookup retrieves the cached identity for a node if it exists and has not expired.

§Errors

Returns Err if no valid (non-expired) entry is found for node_id.

Source

pub fn store( &mut self, node_id: &NodeId, pubkey: &[u8; 32], log_index: u64, now: Tstamp, ) -> Result<(), Error>

store adds or updates a verified identity entry in the cache.

now is used to set the verified_at and expires_at fields of the stored entry.

§Errors

Returns Err if the C call fails.

Source

pub fn invalidate(&mut self, node_id: &NodeId) -> Result<(), Error>

invalidate removes the cached entry for a node, forcing re-verification on next lookup.

§Errors

Returns Err if the C call fails (e.g. node not in cache).

Source

pub fn clear(&mut self)

clear removes all entries from the cache.

Source

pub fn size(&self) -> usize

size returns the current number of entries in the cache.

Source

pub fn capacity(&self) -> usize

capacity returns the maximum number of entries the cache can hold before eviction.

Source

pub fn on_rotation( &mut self, node_id: &NodeId, new_pubkey: &[u8; 32], new_log_index: u64, now: Tstamp, ) -> Result<(), Error>

on_rotation updates a cached entry after a node rotates its key.

Updates the stored pubkey and log_index so subsequent lookups return the new key without requiring a fresh Merkle proof verification.

§Errors

Returns Err if the C call fails (e.g. node not in cache).

Source

pub fn on_revocation(&mut self, node_id: &NodeId) -> Result<(), Error>

on_revocation marks a node as revoked in the cache.

After this call, lookup will return an entry with a revoked flag, so callers can reject the peer without a full Merkle verification.

§Errors

Returns Err if the C call fails.

Source

pub fn stats(&self) -> CacheStats

stats returns a snapshot of the cache performance counters.

Source

pub fn reset_stats(&mut self)

reset_stats zeroes all performance counters.

Trait Implementations§

Source§

impl Drop for IdentityCache

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for IdentityCache

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, 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.