|
Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
|
Token-bucket rate limiter keyed by client. More...
#include <RateLimiter.hpp>

Classes | |
| struct | Bucket |
Public Member Functions | |
| RateLimiter (RateLimitOptions options) | |
| RateLimiter (size_t max_requests, std::chrono::seconds window) | |
| bool | operator() (http::HttpRequest &req, std::shared_ptr< http::ResponseWriter > writer) |
| size_t | tracked_clients () |
| Number of clients currently tracked (for tests and metrics). | |
Private Types | |
| using | Clock = std::chrono::steady_clock |
Private Member Functions | |
| void | evict_refilled (Clock::time_point now) |
Private Attributes | |
| RateLimitOptions | options_ |
| double | refill_per_second_ |
| std::unordered_map< std::string, Bucket > | buckets_ |
| Clock::time_point | last_sweep_ |
| std::mutex | mutex_ |
Token-bucket rate limiter keyed by client.
Each client gets max_requests tokens that refill continuously over window. Rejected requests receive 429 with Retry-After. Clients whose bucket has refilled are forgotten, and at most max_tracked_clients are kept, so the memory used is bounded no matter how many addresses a client rotates through.
|
private |
|
explicit |
| orbit::middleware::RateLimiter::RateLimiter | ( | size_t | max_requests, |
| std::chrono::seconds | window | ||
| ) |
|
private |
| bool orbit::middleware::RateLimiter::operator() | ( | http::HttpRequest & | req, |
| std::shared_ptr< http::ResponseWriter > | writer | ||
| ) |
| size_t orbit::middleware::RateLimiter::tracked_clients | ( | ) |
Number of clients currently tracked (for tests and metrics).
|
private |
|
private |
|
private |
|
private |
|
private |