pub struct DistributedLimiter { /* private fields */ }Expand description
Shared-store rate limiter: the distributed counterpart of the three governor limiters. Holds
the GCRA params for the global per-IP limit, the per-route overrides, and the per-key limit,
plus the backing [Store] and the fail-open policy.
Implementations§
Source§impl DistributedLimiter
impl DistributedLimiter
Sourcepub fn build(rl: &RateLimitCfg, mode: StoreMode) -> Result<DistributedLimiter>
pub fn build(rl: &RateLimitCfg, mode: StoreMode) -> Result<DistributedLimiter>
Build from config for a distributed StoreMode (memory/redis). Compiles the GCRA
params for every limit up front, so a bad rate/burst fails at startup/reload — exactly
like the local limiter.
Sourcepub async fn check_ip_route(&self, ip: IpAddr, path: &str) -> Admit
pub async fn check_ip_route(&self, ip: IpAddr, path: &str) -> Admit
Pre-auth check: the per-route override matching path (longest prefix), else the global
per-IP limit. Keyed per client IP, like the local limiter.
Sourcepub async fn check_key(&self, principal: &str) -> Admit
pub async fn check_key(&self, principal: &str) -> Admit
Post-auth check: the per-principal limit (keyed by API-key id / JWT subject). Returns
Admit::Allowed when per-key limiting is disabled.
Auto Trait Implementations§
impl !Freeze for DistributedLimiter
impl !RefUnwindSafe for DistributedLimiter
impl !UnwindSafe for DistributedLimiter
impl Send for DistributedLimiter
impl Sync for DistributedLimiter
impl Unpin for DistributedLimiter
impl UnsafeUnpin for DistributedLimiter
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