pub struct MonotonicCounterSystem { /* private fields */ }Expand description
Monotonic counter system for preventing replay attacks
Implementations§
Source§impl MonotonicCounterSystem
impl MonotonicCounterSystem
Sourcepub async fn new_with_sync_interval(
storage_path: PathBuf,
sync_interval: Duration,
) -> Result<Self>
pub async fn new_with_sync_interval( storage_path: PathBuf, sync_interval: Duration, ) -> Result<Self>
Create a new monotonic counter system with custom sync interval
Sourcepub async fn start_sync_task(&mut self) -> Result<()>
pub async fn start_sync_task(&mut self) -> Result<()>
Start the background sync task
Sourcepub async fn stop_sync_task(&mut self)
pub async fn stop_sync_task(&mut self)
Stop the background sync task
Sourcepub async fn validate_sequence(
&self,
user_id: &UserId,
sequence: u64,
message_hash: [u8; 32],
) -> Result<SequenceValidationResult>
pub async fn validate_sequence( &self, user_id: &UserId, sequence: u64, message_hash: [u8; 32], ) -> Result<SequenceValidationResult>
Validate and update sequence number for a peer
Sourcepub async fn batch_update(
&self,
requests: Vec<BatchUpdateRequest>,
) -> Result<Vec<BatchUpdateResult>>
pub async fn batch_update( &self, requests: Vec<BatchUpdateRequest>, ) -> Result<Vec<BatchUpdateResult>>
Process batch updates for multiple peers
Sourcepub async fn get_stats(&self) -> CounterStats
pub async fn get_stats(&self) -> CounterStats
Get current statistics
Sourcepub async fn get_peer_counter(&self, user_id: &UserId) -> Option<PeerCounter>
pub async fn get_peer_counter(&self, user_id: &UserId) -> Option<PeerCounter>
Get counter state for a specific peer
Sourcepub async fn reset_peer_counter(&self, user_id: &UserId) -> Result<()>
pub async fn reset_peer_counter(&self, user_id: &UserId) -> Result<()>
Reset counter for a peer (use with caution)
Sourcepub async fn cleanup_old_sequences(&self) -> Result<()>
pub async fn cleanup_old_sequences(&self) -> Result<()>
Cleanup old sequence entries
Auto Trait Implementations§
impl Freeze for MonotonicCounterSystem
impl !RefUnwindSafe for MonotonicCounterSystem
impl Send for MonotonicCounterSystem
impl Sync for MonotonicCounterSystem
impl Unpin for MonotonicCounterSystem
impl UnsafeUnpin for MonotonicCounterSystem
impl !UnwindSafe for MonotonicCounterSystem
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
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.