ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
webrtc.c File Reference

WebRTC P2P signaling for discovery mode failover. More...

Go to the source code of this file.

Functions

webrtc_signaling_callbacks_t discovery_webrtc_get_direct_signaling_callbacks (acip_transport_t *tcp_transport, const uint8_t session_id[16], const uint8_t participant_id[16])
 Create signaling callbacks for direct peer-to-peer connection during failover.
 
void discovery_webrtc_set_tcp_transport (acip_transport_t *transport)
 Set the TCP transport for direct peer-to-peer signaling.
 
void discovery_webrtc_set_session_context (const uint8_t session_id[16], const uint8_t participant_id[16])
 Set session and participant IDs for direct signaling.
 
void discovery_webrtc_cleanup_transport (void)
 Cleanup and release the direct peer-to-peer transport.
 

Detailed Description

WebRTC P2P signaling for discovery mode failover.

Implements direct peer-to-peer SDP/ICE exchange for discovery mode migration. Unlike client mode (which uses ACDS relay), failover uses direct TCP connections to send WebRTC signaling messages.

Definition in file src/discovery/webrtc.c.

Function Documentation

◆ discovery_webrtc_cleanup_transport()

void discovery_webrtc_cleanup_transport ( void  )

Cleanup and release the direct peer-to-peer transport.

Clears the TCP transport used for direct signaling. Called on migration completion or when the P2P connection is torn down.

Note
Actual transport cleanup (closing connections, freeing resources) should be done by caller before calling this.
Thread-safe.

Definition at line 286 of file src/discovery/webrtc.c.

286 {
287 ensure_mutex_initialized();
288 mutex_lock(&g_webrtc_mutex);
289
290 g_tcp_transport = NULL;
291 g_session_context.is_set = false;
292
293 mutex_unlock(&g_webrtc_mutex);
294}
#define mutex_lock(mutex)
Lock a mutex (with debug tracking in debug builds)
#define mutex_unlock(mutex)
Unlock a mutex (with debug tracking in debug builds)

References mutex_lock, and mutex_unlock.

◆ discovery_webrtc_get_direct_signaling_callbacks()

webrtc_signaling_callbacks_t discovery_webrtc_get_direct_signaling_callbacks ( acip_transport_t *  tcp_transport,
const uint8_t  session_id[16],
const uint8_t  participant_id[16] 
)

Create signaling callbacks for direct peer-to-peer connection during failover.

Returns callbacks that send SDP/ICE directly over TCP to the peer (not through ACDS). Used when participants reconnect to a new host after migration.

Parameters
tcp_transportTCP transport connected to the new host
session_idSession UUID (16 bytes, copied)
participant_idLocal participant UUID (16 bytes, copied)
Returns
Signaling callbacks for use with peer manager
Note
The returned structure points to static callbacks and is valid for program lifetime.
TCP transport must be connected and valid when callbacks are invoked.
Set tcp_transport to NULL to disable the callbacks.

Definition at line 239 of file src/discovery/webrtc.c.

241 {
242 ensure_mutex_initialized();
243 mutex_lock(&g_webrtc_mutex);
244
245 g_tcp_transport = tcp_transport;
246
247 if (session_id && participant_id) {
248 memcpy(g_session_context.session_id, session_id, 16);
249 memcpy(g_session_context.participant_id, participant_id, 16);
250 g_session_context.is_set = true;
251 }
252
253 mutex_unlock(&g_webrtc_mutex);
254
255 webrtc_signaling_callbacks_t callbacks = {
256 .send_sdp = discovery_send_sdp,
257 .send_ice = discovery_send_ice,
258 .user_data = NULL, // Unused - we use global state
259 };
260
261 return callbacks;
262}
uint8_t session_id[16]
uint8_t participant_id[16]
Signaling callbacks for sending SDP/ICE.
webrtc_send_sdp_callback_t send_sdp
Send SDP via ACDS.

References mutex_lock, mutex_unlock, participant_id, webrtc_signaling_callbacks_t::send_sdp, and session_id.

◆ discovery_webrtc_set_session_context()

void discovery_webrtc_set_session_context ( const uint8_t  session_id[16],
const uint8_t  participant_id[16] 
)

Set session and participant IDs for direct signaling.

Configures the session context used when sending SDP/ICE messages directly. Must be called before peer manager generates any local descriptions.

Parameters
session_idSession UUID (16 bytes, copied)
participant_idLocal participant UUID (16 bytes, copied)
Note
Callbacks will fail with ERROR_INVALID_STATE if IDs are not set.

Definition at line 271 of file src/discovery/webrtc.c.

271 {
272 ensure_mutex_initialized();
273 mutex_lock(&g_webrtc_mutex);
274
275 if (session_id && participant_id) {
276 memcpy(g_session_context.session_id, session_id, 16);
277 memcpy(g_session_context.participant_id, participant_id, 16);
278 g_session_context.is_set = true;
279 } else {
280 g_session_context.is_set = false;
281 }
282
283 mutex_unlock(&g_webrtc_mutex);
284}

References mutex_lock, mutex_unlock, participant_id, and session_id.

◆ discovery_webrtc_set_tcp_transport()

void discovery_webrtc_set_tcp_transport ( acip_transport_t *  transport)

Set the TCP transport for direct peer-to-peer signaling.

Configures the transport that will be used to send SDP/ICE messages directly to the peer (bypassing ACDS). Must be called before peer manager generates any local descriptions.

Parameters
transportTCP transport to new host (NULL to disable)
Note
This is separate from the ACDS transport used in client mode.
Callbacks will fail with ERROR_INVALID_STATE if transport is NULL.

Definition at line 264 of file src/discovery/webrtc.c.

264 {
265 ensure_mutex_initialized();
266 mutex_lock(&g_webrtc_mutex);
267 g_tcp_transport = transport;
268 mutex_unlock(&g_webrtc_mutex);
269}

References mutex_lock, and mutex_unlock.

Variable Documentation

◆ is_set

bool is_set

Definition at line 50 of file src/discovery/webrtc.c.

◆ participant_id

◆ session_id