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§
Sourcefn get_status(
&self,
addr: &IpAddr,
category: &str,
) -> ClResult<Vec<(AddressKey, RateLimitStatus)>>
fn get_status( &self, addr: &IpAddr, category: &str, ) -> ClResult<Vec<(AddressKey, RateLimitStatus)>>
Query current limit status for an address at all hierarchical levels
Sourcefn penalize(
&self,
addr: &IpAddr,
reason: PenaltyReason,
amount: u32,
) -> ClResult<()>
fn penalize( &self, addr: &IpAddr, reason: PenaltyReason, amount: u32, ) -> ClResult<()>
Manually consume quota (increase usage) - e.g., after auth failure
Sourcefn grant(&self, addr: &IpAddr, amount: u32) -> ClResult<()>
fn grant(&self, addr: &IpAddr, amount: u32) -> ClResult<()>
Decrease penalty count (grant extra quota) - e.g., after successful CAPTCHA
Sourcefn ban(
&self,
addr: &IpAddr,
duration: Duration,
reason: PenaltyReason,
) -> ClResult<()>
fn ban( &self, addr: &IpAddr, duration: Duration, reason: PenaltyReason, ) -> ClResult<()>
Temporarily ban an address (all hierarchical levels)
Sourcefn stats(&self) -> RateLimiterStats
fn stats(&self) -> RateLimiterStats
Get statistics about rate limiter state
Sourcefn get_pow_requirement(&self, addr: &IpAddr) -> u32
fn get_pow_requirement(&self, addr: &IpAddr) -> u32
Get current PoW requirement for address (max of individual + network level)
Sourcefn increment_pow_counter(
&self,
addr: &IpAddr,
reason: PowPenaltyReason,
) -> ClResult<()>
fn increment_pow_counter( &self, addr: &IpAddr, reason: PowPenaltyReason, ) -> ClResult<()>
Increment PoW counter for address