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
impl IdentityCache
Sourcepub fn new(settings: Option<&IdentityCacheSettings>) -> Result<Self, Error>
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.
Sourcepub fn lookup(
&mut self,
node_id: &NodeId,
now: Tstamp,
) -> Result<CachedIdentity, Error>
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.
Sourcepub fn store(
&mut self,
node_id: &NodeId,
pubkey: &[u8; 32],
log_index: u64,
now: Tstamp,
) -> Result<(), Error>
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.
Sourcepub fn invalidate(&mut self, node_id: &NodeId) -> Result<(), Error>
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).
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
capacity returns the maximum number of entries the cache can hold before eviction.
Sourcepub fn on_rotation(
&mut self,
node_id: &NodeId,
new_pubkey: &[u8; 32],
new_log_index: u64,
now: Tstamp,
) -> Result<(), Error>
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).
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
stats returns a snapshot of the cache performance counters.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
reset_stats zeroes all performance counters.