21#include <urcu/rculfhash.h>
26static bool is_broadcast_uuid(
const uint8_t uuid[16]) {
27 for (
int i = 0; i < 16; i++) {
39 return memcmp(a, b, 16) == 0;
54static void find_participant_callback(
socket_t socket,
void *client_data,
void *user_arg) {
87static void broadcast_callback(
socket_t socket,
void *client_data,
void *user_arg) {
109 log_warn(
"Failed to send packet to participant (socket=%d)", socket);
124 struct cds_lfht_iter iter_ctx;
127 cds_lfht_for_each_entry(registry->
sessions, &iter_ctx, iter, hash_node) {
128 if (uuid_equals(iter->
session_id, sdp->session_id)) {
142 if (is_broadcast_uuid(sdp->recipient_id)) {
144 log_debug(
"Broadcasting SDP to all participants in session");
150 .target_participant_id = sdp->recipient_id, .found_socket =
INVALID_SOCKET_VALUE, .found =
false};
181 struct cds_lfht_iter iter_ctx;
184 cds_lfht_for_each_entry(registry->
sessions, &iter_ctx, iter, hash_node) {
185 if (uuid_equals(iter->
session_id, ice->session_id)) {
199 if (is_broadcast_uuid(ice->recipient_id)) {
201 log_debug(
"Broadcasting ICE candidate to all participants in session");
207 .target_participant_id = ice->recipient_id, .found_socket =
INVALID_SOCKET_VALUE, .found =
false};
239 struct cds_lfht_iter iter_ctx;
242 cds_lfht_for_each_entry(registry->
sessions, &iter_ctx, iter, hash_node) {
258 .packet_type = packet_type,
260 .packet_len = packet_len,
266 log_warn(
"Broadcast sent to 0 participants (all offline or not joined yet)");
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it.
asciichat_error_t
Error and exit codes - unified status values (0-255)
#define log_warn(...)
Log a WARN message.
#define log_debug(...)
Log a DEBUG message.
int send_packet(socket_t sockfd, packet_type_t type, const void *data, size_t len)
Send a basic packet without encryption.
packet_type_t
Network protocol packet type enumeration.
@ PACKET_TYPE_ACIP_WEBRTC_ICE
WebRTC ICE candidate (bidirectional)
@ PACKET_TYPE_ACIP_WEBRTC_SDP
WebRTC SDP offer/answer (bidirectional)
void tcp_server_foreach_client(tcp_server_t *server, tcp_client_foreach_fn callback, void *user_arg)
Iterate over all clients.
📝 Logging API with multiple log levels and terminal output control
🌐 Core network I/O operations with timeout support
🎯 Session registry for discovery service (lock-free RCU implementation)
asciichat_error_t signaling_relay_sdp(session_registry_t *registry, tcp_server_t *tcp_server, const acip_webrtc_sdp_t *sdp, size_t total_packet_len)
Relay SDP offer/answer to recipient.
asciichat_error_t signaling_broadcast(session_registry_t *registry, tcp_server_t *tcp_server, const uint8_t session_id[16], packet_type_t packet_type, const void *packet, size_t packet_len)
Broadcast packet to all session participants.
asciichat_error_t signaling_relay_ice(session_registry_t *registry, tcp_server_t *tcp_server, const acip_webrtc_ice_t *ice, size_t total_packet_len)
Relay ICE candidate to recipient.
🎬 WebRTC SDP/ICE signaling relay
🌐 Discovery server TCP connection manager
Per-client connection data.
uint8_t session_id[16]
Session UUID (valid if joined_session)
uint8_t participant_id[16]
Participant UUID (valid if joined_session)
bool joined_session
Whether client has successfully joined a session.
Context for broadcasting to session participants.
packet_type_t packet_type
Packet type to send.
size_t packet_len
Packet length.
const uint8_t * target_session_id
Session to broadcast to.
const void * packet
Packet data.
size_t sent_count
Number of successful sends.
Context for finding client by participant_id.
socket_t found_socket
Socket if found.
const uint8_t * target_participant_id
Participant to find.
bool found
Whether client was found.
Session entry (RCU hash table node)
uint8_t session_id[16]
UUID.
Session registry (lock-free RCU)
struct cds_lfht * sessions
RCU lock-free hash table.