|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
Network error handling utilities. More...
Go to the source code of this file.
Functions | |
| asciichat_error_t | send_error_packet (socket_t sockfd, asciichat_error_t error_code) |
| Send an ACIP error packet using asciichat_error_t. | |
| asciichat_error_t | send_error_packet_message (socket_t sockfd, asciichat_error_t error_code, const char *message) |
| Send an ACIP error packet with custom message. | |
| bool | check_and_record_rate_limit (rate_limiter_t *rate_limiter, const char *client_ip, rate_event_type_t event_type, socket_t client_socket, const char *operation_name) |
| Check rate limit and send error if exceeded. | |
| bool | check_and_record_packet_rate_limit (rate_limiter_t *rate_limiter, const char *client_ip, socket_t client_socket, packet_type_t packet_type) |
| Map packet type to rate event type and check rate limit. | |
Network error handling utilities.
Provides helper functions for sending error responses and handling common error patterns in network protocols.
Definition in file errors.h.
| bool check_and_record_packet_rate_limit | ( | rate_limiter_t * | rate_limiter, |
| const char * | client_ip, | ||
| socket_t | client_socket, | ||
| packet_type_t | packet_type | ||
| ) |
Map packet type to rate event type and check rate limit.
Maps packet_type_t to the corresponding rate_event_type_t and performs rate limiting check. Sends ERROR_RATE_LIMITED response if exceeded.
Packet type to rate event mapping:
| rate_limiter | Rate limiter instance |
| client_ip | Client IP address |
| client_socket | Client socket for sending error response |
| packet_type | Packet type being processed |
Definition at line 54 of file errors.c.
References check_and_record_rate_limit(), PACKET_TYPE_AUDIO, PACKET_TYPE_AUDIO_BATCH, PACKET_TYPE_AUDIO_OPUS, PACKET_TYPE_AUDIO_OPUS_BATCH, PACKET_TYPE_CLIENT_CAPABILITIES, PACKET_TYPE_CLIENT_JOIN, PACKET_TYPE_CLIENT_LEAVE, PACKET_TYPE_IMAGE_FRAME, PACKET_TYPE_PING, PACKET_TYPE_PONG, PACKET_TYPE_STREAM_START, PACKET_TYPE_STREAM_STOP, RATE_EVENT_AUDIO, RATE_EVENT_CLIENT_JOIN, RATE_EVENT_CONTROL, RATE_EVENT_IMAGE_FRAME, and RATE_EVENT_PING.
Referenced by process_decrypted_packet().
| bool check_and_record_rate_limit | ( | rate_limiter_t * | rate_limiter, |
| const char * | client_ip, | ||
| rate_event_type_t | event_type, | ||
| socket_t | client_socket, | ||
| const char * | operation_name | ||
| ) |
Check rate limit and send error if exceeded.
Helper function that checks rate limit, sends error response if exceeded, and records the event if allowed. Encapsulates the common pattern:
| rate_limiter | Rate limiter instance |
| client_ip | Client IP address for logging |
| event_type | Type of event being rate limited |
| client_socket | Socket to send error packet on |
| operation_name | Name of operation for logging (e.g., "SESSION_CREATE") |
Definition at line 38 of file errors.c.
References ASCIICHAT_OK, ERROR_RATE_LIMITED, log_warn, rate_limiter_check(), rate_limiter_record(), and send_error_packet_message().
Referenced by check_and_record_packet_rate_limit().
| asciichat_error_t send_error_packet | ( | socket_t | sockfd, |
| asciichat_error_t | error_code | ||
| ) |
Send an ACIP error packet using asciichat_error_t.
Converts an asciichat_error_t code to an ACIP error packet and sends it. Uses asciichat_error_string() for the error message.
| sockfd | Socket to send error on |
| error_code | Error code from asciichat_error_t enum |
Definition at line 11 of file errors.c.
References error_code, and send_error_packet_message().
| asciichat_error_t send_error_packet_message | ( | socket_t | sockfd, |
| asciichat_error_t | error_code, | ||
| const char * | message | ||
| ) |
Send an ACIP error packet with custom message.
Converts an asciichat_error_t code to an ACIP error packet with a custom error message.
| sockfd | Socket to send error on |
| error_code | Error code from asciichat_error_t enum |
| message | Custom error message (max 255 chars) |
Definition at line 15 of file errors.c.
References acip_error_t, ASCIICHAT_OK, error_code, ERROR_INVALID_PARAM, ERROR_NETWORK, INVALID_SOCKET_VALUE, PACKET_TYPE_ACIP_ERROR, SAFE_STRNCPY, send_packet(), and SET_ERRNO.
Referenced by check_and_record_rate_limit(), and send_error_packet().