pub struct LoginLimiter { /* private fields */ }Expand description
Limits credential attempts per client address (IPv4 address, IPv6 /64) and per wider block (IPv4 /24, IPv6 /48), plus a ceiling on rejections across all clients.
Implementations§
Source§impl LoginLimiter
impl LoginLimiter
Sourcepub fn new(max: usize, window: Duration, ceiling: Ceiling) -> Self
pub fn new(max: usize, window: Duration, ceiling: Ceiling) -> Self
At most max attempts per address and BLOCK_MAX_ATTEMPTS per block within window,
and ceiling once rejections across all addresses reach GLOBAL_MAX_FAILURES.
Sourcepub fn is_blocked(&self, ip: IpAddr) -> bool
pub fn is_blocked(&self, ip: IpAddr) -> bool
Whether a new attempt from ip would be refused.
Sourcepub fn refusal(&self, ip: IpAddr) -> Option<Refusal>
pub fn refusal(&self, ip: IpAddr) -> Option<Refusal>
Why a new attempt from ip would be refused, if it would.
Sourcepub fn record_failure(&self, ip: IpAddr)
pub fn record_failure(&self, ip: IpAddr)
Records a rejected attempt from ip that was not reserved first.
Sourcepub fn try_reserve(&self, ip: IpAddr) -> Result<Reservation, Refusal>
pub fn try_reserve(&self, ip: IpAddr) -> Result<Reservation, Refusal>
Counts an attempt before it is checked, so concurrent attempts share the per-client and
per-block limits. Settle it with Self::fail if the credential is rejected, otherwise
with Self::refund. Until then it does not count toward the global ceiling.
Sourcepub fn refund(&self, reservation: Reservation)
pub fn refund(&self, reservation: Reservation)
Gives a reserved attempt back: it was accepted, or could not be checked.
Sourcepub fn fail(&self, reservation: Reservation)
pub fn fail(&self, reservation: Reservation)
Keeps a reserved attempt as a rejection, counted toward the global ceiling too.
Auto Trait Implementations§
impl !Freeze for LoginLimiter
impl Forget for LoginLimiter
impl RefUnwindSafe for LoginLimiter
impl Send for LoginLimiter
impl Sync for LoginLimiter
impl Unpin for LoginLimiter
impl UnsafeUnpin for LoginLimiter
impl UnwindSafe for LoginLimiter
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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