Counts the datagrams of each address in windows of one second.
More...
#include </__w/project-rtype/project-rtype/server/include/rtype/rate_limit.hpp>
|
| using | Clock = std::chrono::steady_clock |
| | Clock of the windows.
|
| |
|
| | RateLimiter (std::uint32_t per_second) noexcept |
| | Creates a limiter with no address yet.
|
| |
| bool | allow (const aegis2d::net::Endpoint &source, Clock::time_point now) |
| | Counts a datagram and tells whether it may be handled.
|
| |
| void | prune (Clock::time_point now) |
| | Forgets the addresses whose window ended, to bound the memory a flood of forged addresses can take.
|
| |
| std::size_t | addresses () const noexcept |
| | Number of addresses being counted.
|
| |
|
| static constexpr std::chrono::seconds | window {1} |
| | Length of a window.
|
| |
Counts the datagrams of each address in windows of one second.
The first datagrams_per_second datagrams of a window pass; the next ones are refused until the window ends. Addresses silent for a whole window are forgotten by prune(). Not thread-safe: use it from the network thread.
◆ Clock
◆ RateLimiter()
| rtype::RateLimiter::RateLimiter |
( |
std::uint32_t |
per_second | ) |
|
|
explicitnoexcept |
Creates a limiter with no address yet.
- Parameters
-
| per_second | Datagrams accepted per address and window; 0 refuses everything. |
◆ addresses()
| std::size_t rtype::RateLimiter::addresses |
( |
| ) |
const |
|
noexcept |
Number of addresses being counted.
- Returns
- The count.
◆ allow()
| bool rtype::RateLimiter::allow |
( |
const aegis2d::net::Endpoint & |
source, |
|
|
Clock::time_point |
now |
|
) |
| |
Counts a datagram and tells whether it may be handled.
- Parameters
-
| source | Source of the datagram; only its address counts. |
| now | Current time. |
- Returns
false if the address already sent its datagrams of the window.
◆ prune()
| void rtype::RateLimiter::prune |
( |
Clock::time_point |
now | ) |
|
Forgets the addresses whose window ended, to bound the memory a flood of forged addresses can take.
- Parameters
-
◆ window
| constexpr std::chrono::seconds rtype::RateLimiter::window {1} |
|
staticconstexpr |
The documentation for this class was generated from the following file: