Skip to main content

RateLimitApi

Trait RateLimitApi 

Source
pub trait RateLimitApi: Send + Sync {
Show 13 methods // Required methods fn get_status( &self, addr: &IpAddr, category: &str, ) -> ClResult<Vec<(AddressKey, RateLimitStatus)>>; fn penalize( &self, addr: &IpAddr, reason: PenaltyReason, amount: u32, ) -> ClResult<()>; fn grant(&self, addr: &IpAddr, amount: u32) -> ClResult<()>; fn reset(&self, addr: &IpAddr) -> ClResult<()>; fn ban( &self, addr: &IpAddr, duration: Duration, reason: PenaltyReason, ) -> ClResult<()>; fn unban(&self, addr: &IpAddr) -> ClResult<()>; fn is_banned(&self, addr: &IpAddr) -> bool; fn list_bans(&self) -> Vec<BanEntry>; fn stats(&self) -> RateLimiterStats; fn get_pow_requirement(&self, addr: &IpAddr) -> u32; fn increment_pow_counter( &self, addr: &IpAddr, reason: PowPenaltyReason, ) -> ClResult<()>; fn decrement_pow_counter(&self, addr: &IpAddr, amount: u32) -> ClResult<()>; fn verify_pow(&self, addr: &IpAddr, token: &str) -> Result<(), PowError>;
}
Expand description

Internal API for programmatic rate limit management

Required Methods§

Source

fn get_status( &self, addr: &IpAddr, category: &str, ) -> ClResult<Vec<(AddressKey, RateLimitStatus)>>

Query current limit status for an address at all hierarchical levels

Source

fn penalize( &self, addr: &IpAddr, reason: PenaltyReason, amount: u32, ) -> ClResult<()>

Manually consume quota (increase usage) - e.g., after auth failure

Source

fn grant(&self, addr: &IpAddr, amount: u32) -> ClResult<()>

Decrease penalty count (grant extra quota) - e.g., after successful CAPTCHA

Source

fn reset(&self, addr: &IpAddr) -> ClResult<()>

Reset limits for an address at all levels

Source

fn ban( &self, addr: &IpAddr, duration: Duration, reason: PenaltyReason, ) -> ClResult<()>

Temporarily ban an address (all hierarchical levels)

Source

fn unban(&self, addr: &IpAddr) -> ClResult<()>

Unban an address

Source

fn is_banned(&self, addr: &IpAddr) -> bool

Check if an address is banned

Source

fn list_bans(&self) -> Vec<BanEntry>

List all currently banned addresses

Source

fn stats(&self) -> RateLimiterStats

Get statistics about rate limiter state

Source

fn get_pow_requirement(&self, addr: &IpAddr) -> u32

Get current PoW requirement for address (max of individual + network level)

Source

fn increment_pow_counter( &self, addr: &IpAddr, reason: PowPenaltyReason, ) -> ClResult<()>

Increment PoW counter for address

Source

fn decrement_pow_counter(&self, addr: &IpAddr, amount: u32) -> ClResult<()>

Decrement PoW counter (after successful CONN, with decay over time)

Source

fn verify_pow(&self, addr: &IpAddr, token: &str) -> Result<(), PowError>

Verify proof-of-work on action token

Implementors§