⚠️‼️ Error and/or exit() when things go bad.
asciichat_error_t
Error and exit codes - unified status values (0-255)
rate_event_type_t
Rate limit event types.
@ RATE_EVENT_SESSION_LOOKUP
Session lookup.
@ RATE_EVENT_CONTROL
Control packets (CAPABILITIES, STREAM_START/STOP, LEAVE)
@ RATE_EVENT_SESSION_JOIN
Session join.
@ RATE_EVENT_CONNECTION
New connection.
@ RATE_EVENT_PING
Ping/pong keepalive (PACKET_TYPE_PING, PACKET_TYPE_PONG)
@ RATE_EVENT_SESSION_CREATE
Session creation.
@ RATE_EVENT_AUDIO
Audio packet (PACKET_TYPE_AUDIO, PACKET_TYPE_AUDIO_BATCH)
@ RATE_EVENT_MAX
Sentinel value.
@ RATE_EVENT_IMAGE_FRAME
Image frame from client (PACKET_TYPE_IMAGE_FRAME)
@ RATE_EVENT_CLIENT_JOIN
Client join request (PACKET_TYPE_CLIENT_JOIN)
asciichat_error_t rate_limiter_cleanup(rate_limiter_t *limiter, uint32_t max_age_secs)
Clean up old rate limit events.
asciichat_error_t rate_limiter_record(rate_limiter_t *limiter, const char *ip_address, rate_event_type_t event_type)
Record a rate limit event.
void rate_limiter_destroy(rate_limiter_t *limiter)
Destroy rate limiter and free resources.
void rate_limiter_set_sqlite_db(rate_limiter_t *limiter, void *db)
Set SQLite database handle for rate limiter.
rate_limiter_t * rate_limiter_create_memory(void)
Create in-memory rate limiter.
rate_limiter_t * rate_limiter_create_sqlite(const char *db_path)
Create SQLite-backed rate limiter.
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)
Check if an event from an IP address should be rate limited.
const rate_limit_config_t DEFAULT_RATE_LIMITS[RATE_EVENT_MAX]
Default rate limits for each event type.
Rate limit configuration.
uint32_t max_events
Maximum events allowed.
uint32_t window_secs
Time window in seconds.
Backend operations vtable.
void * backend_data
Backend-specific data.