pub struct ThrottleLimiter { /* private fields */ }Expand description
Throttle limiter manages bandwidth limits
Implementations§
Source§impl ThrottleLimiter
impl ThrottleLimiter
Sourcepub fn new(config: ThrottleConfig) -> Self
pub fn new(config: ThrottleConfig) -> Self
Create a new throttle limiter
Sourcepub fn config(&self) -> &ThrottleConfig
pub fn config(&self) -> &ThrottleConfig
Get configuration
Sourcepub async fn check(&self, ip: &str, bytes: u64) -> ThrottleResult
pub async fn check(&self, ip: &str, bytes: u64) -> ThrottleResult
Check if a request should be throttled
Sourcepub async fn consume(&self, ip: &str, bytes: u64) -> u64
pub async fn consume(&self, ip: &str, bytes: u64) -> u64
Consume bandwidth tokens Returns the number of bytes actually consumed
Sourcepub async fn clear_ip_buckets(&self)
pub async fn clear_ip_buckets(&self)
Clear per-IP buckets
Sourcepub async fn tracked_ip_count(&self) -> usize
pub async fn tracked_ip_count(&self) -> usize
Get number of tracked IPs
Sourcepub fn update_config(&mut self, config: ThrottleConfig)
pub fn update_config(&mut self, config: ThrottleConfig)
Update configuration (creates new buckets)
Sourcepub async fn global_tokens(&self) -> u64
pub async fn global_tokens(&self) -> u64
Get global bucket tokens
Trait Implementations§
Source§impl Clone for ThrottleLimiter
impl Clone for ThrottleLimiter
Auto Trait Implementations§
impl Freeze for ThrottleLimiter
impl !RefUnwindSafe for ThrottleLimiter
impl Send for ThrottleLimiter
impl Sync for ThrottleLimiter
impl Unpin for ThrottleLimiter
impl UnsafeUnpin for ThrottleLimiter
impl !UnwindSafe for ThrottleLimiter
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