pub struct AuthLimiter { /* private fields */ }Expand description
Shared throttle state, built once at startup.
Implementations§
Source§impl AuthLimiter
impl AuthLimiter
pub fn new(trusted: TrustedProxies) -> Self
Sourcepub fn check(
&self,
peer: Option<SocketAddr>,
forwarded_for: Option<&str>,
) -> Decision
pub fn check( &self, peer: Option<SocketAddr>, forwarded_for: Option<&str>, ) -> Decision
Records an attempt from peer, honouring forwarded_for only if the
peer is a trusted proxy.
The per-client ceiling is charged first, and the global one only if the client had budget left.
That order is load-bearing. Charging global first spends it on requests that are about to be refused anyway, so one address sitting on its own exhausted bucket could drain the site-wide budget and deny login to everyone — a cheaper attack than the identity rotation the global ceiling exists to stop.
A poisoned lock denies: the limiter failing open would silently restore the unmetered oracle this exists to close.
Sourcepub fn check_verification(
&self,
peer: Option<SocketAddr>,
forwarded_for: Option<&str>,
) -> Decision
pub fn check_verification( &self, peer: Option<SocketAddr>, forwarded_for: Option<&str>, ) -> Decision
Records a token verification from peer.
Separate from the login budget: these are ordinary authenticated requests, so the ceiling is far higher and exhausting it must not lock a client out of logging in.
Auto Trait Implementations§
impl !Freeze for AuthLimiter
impl RefUnwindSafe for AuthLimiter
impl Send for AuthLimiter
impl Sync for AuthLimiter
impl Unpin for AuthLimiter
impl UnsafeUnpin for AuthLimiter
impl UnwindSafe for AuthLimiter
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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