Struct kvarn::limiting::Manager

source ·
pub struct Manager { /* private fields */ }
Expand description

Data used to limit requests.

One instance of this is used per Listener. It counts using a atomic::AtomicUsize and keeps the count of requests per IpAddr in a Mutex, for fast access times and cheap cloning.

Implementations

Creates a new manager.

Use LimitManager::default for sane defaults.

The number of allowed requests per reset is max_requests * check_every. After reset_seconds, all data is cleared.

As the math implies, increasing max_requests and lowering reset_seconds does nothing to the amount of accepted requests. Though, if you have large reset_seconds, it’ll take longer for the limits to clear after the user has reached max_requests.

Disables limiting of this manager.

Sets the number of calls in between checking the request.

This is here to not have to check every request.

Sets the max requests in the current cycle (which resets after Self::set_reset_seconds). If the amount of requests from a IP address exceeds max_requests in the cycle, the request is denied.

Sets the interval to clear all limits.

See Self::new for considerations when making this value large.

Registers a request from addr.

This is called twice, once when a new connection is established, and once when a new request is made.

Does not always lock the Mutex, only once per check_every. It only atomic::AtomicUsize::fetch_add else, with atomic::Ordering::Relaxed. This is less reliable, but faster. We do not require this to be to be exact.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Default is Self::new(10, 10, 10).

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more