45#define WEBRTC_RECV_QUEUE_SIZE 64
79 if (!wrtc || !data || len == 0) {
80 log_error(
"Invalid DataChannel message callback parameters");
88 log_error(
"Failed to allocate receive message buffer (%zu bytes)", len);
92 memcpy(msg.
data, data, len);
103 log_warn(
"Receive queue full, dropping oldest message (%zu bytes)", dropped_msg.
len);
110 log_error(
"Failed to write to receive queue after drop");
121 log_debug_every(1000000,
"WebRTC message received (%zu bytes), queue size: %zu", len,
140 log_info(
"WebRTC DataChannel opened, transport ready");
150 log_error(
"WebRTC DataChannel error: %s", error_msg ? error_msg :
"unknown error");
171 log_info(
"WebRTC DataChannel closed");
211 void **out_allocated_buffer) {
243 *out_allocated_buffer = msg.
data;
315 if (!transport || !transport->
impl_data) {
353 log_debug(
"Destroyed WebRTC transport resources");
363 .close = webrtc_close,
364 .get_type = webrtc_get_type,
365 .get_socket = webrtc_get_socket,
366 .is_connected = webrtc_is_connected,
367 .destroy_impl = webrtc_destroy_impl,
376 if (!peer_conn || !data_channel) {
441 .on_close = webrtc_on_close,
442 .on_error = webrtc_on_error,
443 .on_message = webrtc_on_message,
444 .user_data = wrtc_data,
460 transport->
methods = &webrtc_methods;
464 log_info(
"Created WebRTC transport (crypto: %s)", crypto_ctx ?
"enabled" :
"disabled");
Cross-platform condition variable interface for ascii-chat.
#define SAFE_MALLOC(size, cast)
#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_error(...)
Log an ERROR message.
#define log_debug_every(interval_us, fmt,...)
Rate-limited DEBUG logging.
#define log_info(...)
Log an INFO message.
#define log_debug(...)
Log a DEBUG message.
ringbuffer_t * ringbuffer_create(size_t element_size, size_t capacity)
Create a new ring buffer.
size_t ringbuffer_size(const ringbuffer_t *rb)
Get current number of elements in the buffer.
void ringbuffer_destroy(ringbuffer_t *rb)
Destroy a ring buffer and free its memory.
bool ringbuffer_is_empty(const ringbuffer_t *rb)
Check if buffer is empty.
bool ringbuffer_read(ringbuffer_t *rb, void *data)
Try to read an element from the ring buffer (non-blocking)
bool ringbuffer_write(ringbuffer_t *rb, const void *data)
Try to write an element to the ring buffer (non-blocking)
asciichat_error_t webrtc_datachannel_set_callbacks(webrtc_data_channel_t *dc, const webrtc_datachannel_callbacks_t *callbacks)
Set DataChannel callbacks.
void webrtc_datachannel_destroy(webrtc_data_channel_t *dc)
Destroy a DataChannel and free resources.
void webrtc_peer_connection_close(webrtc_peer_connection_t *pc)
Close a peer connection.
void webrtc_peer_connection_destroy(webrtc_peer_connection_t *pc)
Destroy a peer connection and free resources.
asciichat_error_t webrtc_datachannel_send(webrtc_data_channel_t *dc, const uint8_t *data, size_t size)
Send data over DataChannel.
📝 Logging API with multiple log levels and terminal output control
Cross-platform mutex interface for ascii-chat.
Lock-Free Ring Buffer and Frame Buffer Management.
Transport method table (virtual function table)
asciichat_error_t(* send)(acip_transport_t *transport, const void *data, size_t len)
Send data through this transport.
Transport instance structure.
void * impl_data
Transport-specific state.
const acip_transport_methods_t * methods
Method table (virtual functions)
crypto_context_t * crypto_ctx
Optional encryption context.
Cryptographic context structure.
Lock-free ring buffer structure.
DataChannel callback structure.
void(* on_open)(webrtc_data_channel_t *dc, void *user_data)
Channel opened.
Receive queue element (variable-length message)
size_t len
Message length in bytes.
uint8_t * data
Message data (allocated, caller must free)
WebRTC transport implementation data.
webrtc_peer_connection_t * peer_conn
Peer connection (owned)
bool is_connected
Connection state.
mutex_t queue_mutex
Protect queue operations.
webrtc_data_channel_t * data_channel
Data channel (owned)
mutex_t state_mutex
Protect state changes.
cond_t queue_cond
Signal when messages arrive.
ringbuffer_t * recv_queue
Receive message queue.
Transport abstraction layer for ACIP protocol.
acip_transport_type_t
Transport type enumeration.
@ ACIP_TRANSPORT_WEBRTC
WebRTC DataChannel (P2P)
#define WEBRTC_RECV_QUEUE_SIZE
Maximum receive queue size (messages buffered before recv())
acip_transport_t * acip_webrtc_transport_create(webrtc_peer_connection_t *peer_conn, webrtc_data_channel_t *data_channel, crypto_context_t *crypto_ctx)