Kurlyk
Loading...
Searching...
No Matches
kurlyk::WebSocketRateLimiter Class Reference

Manages rate limiting for WebSocket requests based on predefined limits. More...

#include <WebSocketRateLimiter.hpp>

Classes

struct  LimitData
 

Public Types

using time_point_t = std::chrono::steady_clock::time_point
 

Public Member Functions

void set_limit (const std::vector< WebSocketConfig::RateLimitData > &rate_limits)
 Sets the rate limits to control WebSocket request frequency.
 
bool allow_request (long rate_limit_id)
 Checks if a request is allowed under the specified rate limit.
 

Private Member Functions

bool check_limit (long rate_limit_id)
 Checks if a request is allowed under the specified rate limit without updating the count.
 
void update_limit (long rate_limit_id)
 Updates the request count for the specified rate limit ID.
 

Private Attributes

std::mutex m_mutex
 Mutex to protect shared data.
 
std::vector< LimitDatam_limit_data
 Vector storing rate limit configurations.
 

Detailed Description

Manages rate limiting for WebSocket requests based on predefined limits.

The limiter applies a general rate limit (id 0) to all requests by default.

Definition at line 13 of file WebSocketRateLimiter.hpp.

Member Typedef Documentation

◆ time_point_t

using kurlyk::WebSocketRateLimiter::time_point_t = std::chrono::steady_clock::time_point

Definition at line 15 of file WebSocketRateLimiter.hpp.

Member Function Documentation

◆ allow_request()

bool kurlyk::WebSocketRateLimiter::allow_request ( long rate_limit_id)
inline

Checks if a request is allowed under the specified rate limit.

Parameters
rate_limit_idThe ID of the rate limit category to apply.
Returns
true if the request is allowed, false if the request exceeds the limit.

Definition at line 41 of file WebSocketRateLimiter.hpp.

◆ check_limit()

bool kurlyk::WebSocketRateLimiter::check_limit ( long rate_limit_id)
inlineprivate

Checks if a request is allowed under the specified rate limit without updating the count.

Parameters
rate_limit_idThe ID of the rate limit to apply.
Returns
true if the request is allowed, false if the request exceeds the limit.

Definition at line 81 of file WebSocketRateLimiter.hpp.

◆ set_limit()

void kurlyk::WebSocketRateLimiter::set_limit ( const std::vector< WebSocketConfig::RateLimitData > & rate_limits)
inline

Sets the rate limits to control WebSocket request frequency.

Parameters
rate_limitsA vector of rate limit configurations for different request categories.

Definition at line 19 of file WebSocketRateLimiter.hpp.

◆ update_limit()

void kurlyk::WebSocketRateLimiter::update_limit ( long rate_limit_id)
inlineprivate

Updates the request count for the specified rate limit ID.

Parameters
rate_limit_idThe ID of the rate limit to apply.

Definition at line 101 of file WebSocketRateLimiter.hpp.

Member Data Documentation

◆ m_limit_data

std::vector<LimitData> kurlyk::WebSocketRateLimiter::m_limit_data
private

Vector storing rate limit configurations.

Definition at line 76 of file WebSocketRateLimiter.hpp.

◆ m_mutex

std::mutex kurlyk::WebSocketRateLimiter::m_mutex
private

Mutex to protect shared data.

Definition at line 75 of file WebSocketRateLimiter.hpp.


The documentation for this class was generated from the following file: