pub struct DdosConnectionGuard { /* private fields */ }Expand description
RAII guard for a single IP’s connection slot.
Created by DdosConnectionGuard::try_new; dropped when the connection ends.
While alive it holds a slot in the per-IP connection counter.
Exposes allow_request and report_bad_request so callers never need to
pass a raw Arc<dyn DdosProtection> through request handling code.
Implementations§
Source§impl DdosConnectionGuard
impl DdosConnectionGuard
Sourcepub fn try_new(
ddos: Arc<dyn DdosProtection>,
ip: impl Into<String>,
) -> Option<Self>
pub fn try_new( ddos: Arc<dyn DdosProtection>, ip: impl Into<String>, ) -> Option<Self>
Try to acquire a connection slot for ip.
Returns None if the IP is over the per-IP connection cap or is already
rate-limited. Returns Some(guard) on success; the slot is released
automatically when the guard is dropped.
pub fn ip(&self) -> &str
Sourcepub fn allow_request(&self) -> bool
pub fn allow_request(&self) -> bool
Returns true if the next request from this connection should be processed.
Sourcepub fn report_bad_request(&self)
pub fn report_bad_request(&self)
Report that a request from this connection was malformed or malicious.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DdosConnectionGuard
impl !RefUnwindSafe for DdosConnectionGuard
impl Send for DdosConnectionGuard
impl Sync for DdosConnectionGuard
impl Unpin for DdosConnectionGuard
impl UnsafeUnpin for DdosConnectionGuard
impl !UnwindSafe for DdosConnectionGuard
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
§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>
Converts
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>
Converts
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