pub struct WebhookRateLimiter { /* private fields */ }Expand description
Per-source-IP token bucket. capacity tokens refill at
refill_per_sec tokens/second; each admitted request consumes
one. When the bucket empties the next call to
WebhookRateLimiter::admit returns false so the handler can
refuse with 429.
The map is bounded at max_ips: when an unknown IP would push
the map past the cap, the entry with the oldest last_refill
timestamp is evicted. That keeps memory bounded under a flood of
unique source addresses while letting a steady stream of senders
keep their state warm.
Implementations§
Source§impl WebhookRateLimiter
impl WebhookRateLimiter
Sourcepub fn new(capacity: u32, refill_per_sec: f64, max_ips: usize) -> Self
pub fn new(capacity: u32, refill_per_sec: f64, max_ips: usize) -> Self
Build a limiter that admits capacity requests up front and
then refills at refill_per_sec tokens per second. max_ips
caps the tracked set; entries past the cap are evicted oldest
first.
Sourcepub fn per_minute(rate_per_minute: u32, max_ips: usize) -> Self
pub fn per_minute(rate_per_minute: u32, max_ips: usize) -> Self
Build a limiter from the operator-facing
webhook_rate_limit_per_minute knob. The burst depth is
the same value (so a fresh sender can fire that many requests
back-to-back before throttling kicks in).
Auto Trait Implementations§
impl !Freeze for WebhookRateLimiter
impl RefUnwindSafe for WebhookRateLimiter
impl Send for WebhookRateLimiter
impl Sync for WebhookRateLimiter
impl Unpin for WebhookRateLimiter
impl UnsafeUnpin for WebhookRateLimiter
impl UnwindSafe for WebhookRateLimiter
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more