34 [RATE_EVENT_SESSION_CREATE] = {.max_events = 10, .window_secs = 60},
35 [RATE_EVENT_SESSION_LOOKUP] = {.max_events = 30, .window_secs = 60},
36 [RATE_EVENT_SESSION_JOIN] = {.max_events = 20, .window_secs = 60},
37 [RATE_EVENT_CONNECTION] = {.max_events = 50, .window_secs = 60},
38 [RATE_EVENT_IMAGE_FRAME] = {.max_events = 8640, .window_secs = 60},
39 [RATE_EVENT_AUDIO] = {.max_events = 10320, .window_secs = 60},
40 [RATE_EVENT_PING] = {.max_events = 120, .window_secs = 60},
41 [RATE_EVENT_CLIENT_JOIN] = {.max_events = 10, .window_secs = 60},
42 [RATE_EVENT_CONTROL] = {.max_events = 100, .window_secs = 60},
45 [RATE_EVENT_SESSION_CREATE] = {.max_events = 15, .window_secs = 60},
46 [RATE_EVENT_SESSION_LOOKUP] = {.max_events = 45, .window_secs = 60},
47 [RATE_EVENT_SESSION_JOIN] = {.max_events = 30, .window_secs = 60},
48 [RATE_EVENT_CONNECTION] = {.max_events = 75, .window_secs = 60},
49 [RATE_EVENT_IMAGE_FRAME] = {.max_events = 12960, .window_secs = 60},
50 [RATE_EVENT_AUDIO] = {.max_events = 15480, .window_secs = 60},
51 [RATE_EVENT_PING] = {.max_events = 180, .window_secs = 60},
52 [RATE_EVENT_CLIENT_JOIN] = {.max_events = 25, .window_secs = 60},
53 [RATE_EVENT_CONTROL] = {.max_events = 150, .window_secs = 60},
128asciichat_error_t
rate_limiter_check(rate_limiter_t *limiter,
const char *ip_address, rate_event_type_t event_type,
129 const rate_limit_config_t *config,
bool *allowed) {
130 if (!limiter || !limiter->ops || !limiter->ops->check) {
131 return SET_ERRNO(ERROR_INVALID_PARAM,
"Invalid rate limiter");
134 if (!ip_address || !allowed) {
135 return SET_ERRNO(ERROR_INVALID_PARAM,
"ip_address or allowed is NULL");
138 if (event_type >= RATE_EVENT_MAX) {
139 return SET_ERRNO(ERROR_INVALID_PARAM,
"Invalid event_type: %d", event_type);
142 return limiter->ops->check(limiter->backend_data, ip_address, event_type, config, allowed);
145asciichat_error_t
rate_limiter_record(rate_limiter_t *limiter,
const char *ip_address, rate_event_type_t event_type) {
146 if (!limiter || !limiter->ops || !limiter->ops->record) {
147 return SET_ERRNO(ERROR_INVALID_PARAM,
"Invalid rate limiter");
151 return SET_ERRNO(ERROR_INVALID_PARAM,
"ip_address is NULL");
154 if (event_type >= RATE_EVENT_MAX) {
155 return SET_ERRNO(ERROR_INVALID_PARAM,
"Invalid event_type: %d", event_type);
158 return limiter->ops->record(limiter->backend_data, ip_address, event_type);
162 if (!limiter || !limiter->ops || !limiter->ops->cleanup) {
163 return SET_ERRNO(ERROR_INVALID_PARAM,
"Invalid rate limiter");
166 return limiter->ops->cleanup(limiter->backend_data, max_age_secs);
asciichat_error_t rate_limiter_check(rate_limiter_t *limiter, const char *ip_address, rate_event_type_t event_type, const rate_limit_config_t *config, bool *allowed)