ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
memory.h File Reference

🧠 In-memory rate limiting backend interface More...

Go to the source code of this file.

Functions

void * memory_backend_create (void)
 Create memory backend instance.
 
uint64_t rate_limiter_get_time_ms (void)
 Helper: Get current time in milliseconds.
 
const char * rate_limiter_event_type_string (rate_event_type_t event_type)
 Helper: Get event type string for logging.
 

Variables

const rate_limiter_backend_ops_t memory_backend_ops
 Memory backend operations vtable.
 

Detailed Description

🧠 In-memory rate limiting backend interface

Definition in file network/rate_limit/memory.h.

Function Documentation

◆ memory_backend_create()

void * memory_backend_create ( void  )

Create memory backend instance.

Returns
Backend instance or NULL on failure

Definition at line 239 of file network/rate_limit/memory.c.

239 {
241 if (!backend) {
242 log_error("Failed to allocate memory backend");
243 return NULL;
244 }
245
246 memset(backend, 0, sizeof(*backend));
247
248 if (mutex_init(&backend->lock, "rate_limiter") != 0) {
249 log_error("Failed to initialize mutex");
250 SAFE_FREE(backend);
251 return NULL;
252 }
253
254 log_debug("Memory rate limiter backend initialized");
255 return backend;
256}
#define SAFE_FREE(ptr)
Definition common.h:376
#define SAFE_MALLOC(size, cast)
Definition common.h:264
#define log_error(...)
Log an ERROR message.
Definition log/log.h:587
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:548
int mutex_init(mutex_t *mutex, const char *name)
Initialize a mutex with a name.
Definition threading.c:16
Memory backend data.
mutex_t lock
Mutex for thread safety.

References memory_backend_t::lock, log_debug, log_error, mutex_init(), SAFE_FREE, and SAFE_MALLOC.

Referenced by rate_limiter_create_memory().

◆ rate_limiter_event_type_string()

const char * rate_limiter_event_type_string ( rate_event_type_t  event_type)

Helper: Get event type string for logging.

Helper: Get event type string for logging.

Definition at line 176 of file rate_limit.c.

176 {
177 if (event_type >= RATE_EVENT_MAX) {
178 return "unknown";
179 }
180 return event_type_strings[event_type];
181}
@ RATE_EVENT_MAX
Sentinel value.
Definition rate_limit.h:60

◆ rate_limiter_get_time_ms()

uint64_t rate_limiter_get_time_ms ( void  )

Helper: Get current time in milliseconds.

Variable Documentation

◆ memory_backend_ops

const rate_limiter_backend_ops_t memory_backend_ops
extern

Memory backend operations vtable.

Definition at line 258 of file network/rate_limit/memory.c.

258 {
259 .check = memory_check,
260 .record = memory_record,
261 .cleanup = memory_cleanup,
262 .destroy = memory_destroy,
263};

Referenced by rate_limiter_create_memory().