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

ACIP Discovery Server (ACDS) packet handlers. More...

Go to the source code of this file.

Data Structures

struct  acip_acds_callbacks_t
 ACDS packet handler callbacks. More...
 

Functions

asciichat_error_t acip_handle_acds_packet (acip_transport_t *transport, packet_type_t type, const void *payload, size_t payload_len, const char *client_ip, const acip_acds_callbacks_t *callbacks)
 Handle incoming ACDS packet with O(1) dispatch.
 

Detailed Description

ACIP Discovery Server (ACDS) packet handlers.

Provides O(1) array-based packet dispatching for ascii-chat Discovery Server. Handles session management, WebRTC signaling, and discovery protocol packets.

Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
January 2026

Definition in file acds_handlers.h.

Function Documentation

◆ acip_handle_acds_packet()

asciichat_error_t acip_handle_acds_packet ( acip_transport_t *  transport,
packet_type_t  type,
const void *  payload,
size_t  payload_len,
const char *  client_ip,
const acip_acds_callbacks_t *  callbacks 
)

Handle incoming ACDS packet with O(1) dispatch.

Dispatches packet to appropriate callback based on type. Uses array-based lookup for constant-time handler selection.

Parameters
transportTransport instance for sending responses and accessing per-client state
typePacket type
payloadPacket payload
payload_lenPayload length
client_ipClient IP address string
callbacksApplication callbacks
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 125 of file acds_handlers.c.

127 {
128 if (!callbacks) {
129 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid callbacks");
130 }
131
133 log_info("★ ACIP_HANDLE_ACDS_PACKET: Dispatching type=%u (NETWORK_QUALITY) from %s, payload_len=%zu", type,
134 client_ip, payload_len);
135 }
136
137 // O(1) dispatch via hash table lookup
138 int idx = acds_handler_hash_lookup(g_acds_handler_hash, type);
139 if (idx < 0) {
140 return SET_ERRNO(ERROR_INVALID_PARAM, "Unhandled ACDS packet type: %d from %s", type, client_ip);
141 }
142
144 log_info("★ ACIP_HANDLE_ACDS_PACKET: Found handler at index=%d", idx);
145 }
146
147 return g_acds_handlers[idx](payload, payload_len, transport, client_ip, callbacks);
148}
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it, returning the error code.
@ ERROR_INVALID_PARAM
#define log_info(...)
Log an INFO message.
Definition log/log.h:561
@ PACKET_TYPE_ACIP_NETWORK_QUALITY
NETWORK_QUALITY exchange (unified packet for all quality metrics)
Definition packet.h:455

References ERROR_INVALID_PARAM, log_info, PACKET_TYPE_ACIP_NETWORK_QUALITY, and SET_ERRNO.

Referenced by acds_client_handler(), and acds_websocket_client_handler().