ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
ice.h File Reference

ICE (Interactive Connectivity Establishment) for WebRTC. More...

Go to the source code of this file.

Data Structures

struct  ice_candidate_t
 Single ICE candidate for connectivity. More...
struct  ice_config_t
 Credentials and callback used while gathering ICE candidates. More...

Macros

#define NETWORK_WEBRTC_ICE_FOUNDATION_BUFFER_SIZE   32
#define NETWORK_WEBRTC_ICE_RADDR_BUFFER_SIZE   64
#define NETWORK_WEBRTC_ICE_EXTENSIONS_BUFFER_SIZE   256

Typedefs

typedef asciichat_error_t(* ice_send_candidate_callback_t) (const ice_candidate_t *candidate, const char *mid, void *user_data)
 Single ICE candidate for connectivity.

Enumerations

enum  ice_candidate_type_t { ICE_CANDIDATE_HOST = 0 , ICE_CANDIDATE_SRFLX = 1 , ICE_CANDIDATE_PRFLX = 2 , ICE_CANDIDATE_RELAY = 3 }
 Credentials and callback used while gathering ICE candidates. More...
enum  ice_protocol_t { ICE_PROTOCOL_UDP = 0 , ICE_PROTOCOL_TCP = 1 }
 ICE candidate transport protocol. More...
enum  ice_tcp_type_t { ICE_TCP_TYPE_ACTIVE = 0 , ICE_TCP_TYPE_PASSIVE = 1 , ICE_TCP_TYPE_SO = 2 }
 ICE candidate TCP type (if applicable). More...

Functions

asciichat_error_t ice_gather_candidates (const ice_config_t *config)
 Start ICE candidate gathering.
asciichat_error_t ice_parse_candidate (const char *line, ice_candidate_t *candidate)
 Parse ICE candidate from attribute string.
asciichat_error_t ice_format_candidate (const ice_candidate_t *candidate, char *line, size_t line_size)
 Format ICE candidate to attribute string.
uint32_t ice_calculate_priority (ice_candidate_type_t type, uint16_t local_preference, uint8_t component_id)
 Calculate candidate priority.
uint32_t ice_calculate_priority_for_candidate (const ice_candidate_t *candidate)
 Calculate candidate priority with IP-aware local preference.
asciichat_error_t ice_add_remote_candidate (struct webrtc_peer_connection *pc, const ice_candidate_t *candidate, const char *mid)
 Add remote candidate to peer connection.
bool ice_is_connected (struct webrtc_peer_connection *pc)
 Check ICE connection state.
int webrtc_get_rtc_id (struct webrtc_peer_connection *pc)
 Get the internal libdatachannel peer connection ID.
asciichat_error_t ice_get_selected_pair (struct webrtc_peer_connection *pc, ice_candidate_t *local_candidate, ice_candidate_t *remote_candidate)
 Get selected candidate pair.
const char * ice_candidate_type_name (ice_candidate_type_t type)
 Get human-readable candidate type name.
const char * ice_protocol_name (ice_protocol_t protocol)
 Get human-readable protocol name.

Detailed Description

ICE (Interactive Connectivity Establishment) for WebRTC.

Handles ICE candidate gathering, exchange, and connectivity checking. ICE is the mechanism that allows WebRTC peers to discover and connect across NATs and firewalls using STUN and TURN servers.

ICE Candidate Types

Host candidates: Local IP addresses

  • Direct connection if both peers on same network

Server-reflexive (srflx) candidates: NAT-discovered addresses

  • Obtained from STUN server
  • Allows hole punching across NATs

Peer-reflexive (prflx) candidates: Discovered during connectivity checks

  • May emerge when direct STUN-based connection works

Relay candidates: TURN relay server addresses

  • Guaranteed to work through any firewall
  • Last resort for restrictive networks

ICE Candidate Exchange

  1. Gathering phase: Collect candidates from all sources
    • Host candidates (network interfaces)
    • STUN server response
    • TURN relay addresses
  2. Signaling phase: Send candidates to peer via ACDS relay
    • Each candidate sent as ACIP_WEBRTC_ICE packet
    • Order: host first, then srflx, then relay
  3. Connectivity checking: Verify which candidates work
    • WebRTC agent tests each candidate pair
    • Selects best pair (lowest latency, highest bandwidth)
  4. Connection: Data flows through selected candidate pair
    • May change during session (ICE restart)

Integration with ACDS

ICE candidates are sent via ACDS signaling relay:

  • PACKET_TYPE_ACIP_WEBRTC_ICE for each candidate
  • Peer decodes and adds to peer connection
  • Peer agent tests connectivity with received candidates
Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
January 2026

Definition in file ice.h.

Macro Definition Documentation

◆ NETWORK_WEBRTC_ICE_EXTENSIONS_BUFFER_SIZE

#define NETWORK_WEBRTC_ICE_EXTENSIONS_BUFFER_SIZE   256

Definition at line 60 of file ice.h.

◆ NETWORK_WEBRTC_ICE_FOUNDATION_BUFFER_SIZE

#define NETWORK_WEBRTC_ICE_FOUNDATION_BUFFER_SIZE   32

Definition at line 58 of file ice.h.

◆ NETWORK_WEBRTC_ICE_RADDR_BUFFER_SIZE

#define NETWORK_WEBRTC_ICE_RADDR_BUFFER_SIZE   64

Definition at line 59 of file ice.h.

Typedef Documentation

◆ ice_send_candidate_callback_t

typedef asciichat_error_t(* ice_send_candidate_callback_t) (const ice_candidate_t *candidate, const char *mid, void *user_data)

Single ICE candidate for connectivity.

Callback for sending ICE candidate to peer

Called by ICE agent when a new candidate is discovered. Implementation should send via ACDS relay.

Parameters
candidateDiscovered candidate
midMedia stream ID (e.g., "0" for audio, "1" for video)
user_dataUser context pointer
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 161 of file ice.h.

Enumeration Type Documentation

◆ ice_candidate_type_t

Credentials and callback used while gathering ICE candidates.

ICE candidate type enumeration (RFC 5245)

Enumerator
ICE_CANDIDATE_HOST 

Host candidate (local IP address).

ICE_CANDIDATE_SRFLX 

Server-reflexive (NAT-discovered via STUN).

ICE_CANDIDATE_PRFLX 

Peer-reflexive (discovered during checks).

ICE_CANDIDATE_RELAY 

Relay candidate (TURN server).

Definition at line 81 of file ice.h.

81 {
ice_candidate_type_t
Credentials and callback used while gathering ICE candidates.
Definition ice.h:81
@ ICE_CANDIDATE_SRFLX
Server-reflexive (NAT-discovered via STUN).
Definition ice.h:83
@ ICE_CANDIDATE_HOST
Host candidate (local IP address).
Definition ice.h:82
@ ICE_CANDIDATE_RELAY
Relay candidate (TURN server).
Definition ice.h:85
@ ICE_CANDIDATE_PRFLX
Peer-reflexive (discovered during checks).
Definition ice.h:84

◆ ice_protocol_t

ICE candidate transport protocol.

Enumerator
ICE_PROTOCOL_UDP 
ICE_PROTOCOL_TCP 

Definition at line 91 of file ice.h.

91 {
ice_protocol_t
ICE candidate transport protocol.
Definition ice.h:91
@ ICE_PROTOCOL_UDP
Definition ice.h:92
@ ICE_PROTOCOL_TCP
Definition ice.h:93

◆ ice_tcp_type_t

ICE candidate TCP type (if applicable).

Enumerator
ICE_TCP_TYPE_ACTIVE 

Actively opens connection.

ICE_TCP_TYPE_PASSIVE 

Passively waits for connection.

ICE_TCP_TYPE_SO 

Simultaneous open.

Definition at line 99 of file ice.h.

99 {
102 ICE_TCP_TYPE_SO = 2,
ice_tcp_type_t
ICE candidate TCP type (if applicable).
Definition ice.h:99
@ ICE_TCP_TYPE_SO
Simultaneous open.
Definition ice.h:102
@ ICE_TCP_TYPE_ACTIVE
Actively opens connection.
Definition ice.h:100
@ ICE_TCP_TYPE_PASSIVE
Passively waits for connection.
Definition ice.h:101

Function Documentation

◆ ice_add_remote_candidate()

asciichat_error_t ice_add_remote_candidate ( struct webrtc_peer_connection * pc,
const ice_candidate_t * candidate,
const char * mid )

Add remote candidate to peer connection.

Called when receiving candidate from peer. The WebRTC agent will test connectivity with this candidate.

Parameters
pcPeer connection to add candidate to
candidateRemote candidate from peer
midMedia stream ID
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 423 of file ice.c.

424 {
425 if (!pc || !candidate || !mid) {
426 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid remote candidate parameters");
427 }
428
429 // Validate candidate has required fields
430 if (candidate->ip_address[0] == '\0' || candidate->port == 0) {
431 return SET_ERRNO(ERROR_INVALID_PARAM, "Candidate missing IP address or port");
432 }
433
434 log_debug("ICE: Adding remote candidate %s:%u (type=%s, foundation=%s) on mid=%s", candidate->ip_address,
435 candidate->port, ice_candidate_type_name(candidate->type), candidate->foundation, mid);
436
437 // Format candidate to SDP attribute line for libdatachannel
439 asciichat_error_t err = ice_format_candidate(candidate, candidate_line, sizeof(candidate_line));
440 if (err != ASCIICHAT_OK) {
441 return err;
442 }
443
444 // Delegate to WebRTC layer
445 return webrtc_add_remote_candidate(pc, candidate_line, mid);
446}
#define SET_ERRNO(code,...)
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_INVALID_PARAM
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:595
asciichat_error_t webrtc_add_remote_candidate(webrtc_peer_connection_t *pc, const char *candidate, const char *mid)
Add remote ICE candidate.
#define NETWORK_WEBRTC_ICE_CANDIDATE_LINE_BUFFER_SIZE
Definition ice.c:12
asciichat_error_t ice_format_candidate(const ice_candidate_t *candidate, char *line, size_t line_size)
Format ICE candidate to attribute string.
Definition ice.c:323
const char * ice_candidate_type_name(ice_candidate_type_t type)
Get human-readable candidate type name.
Definition ice.c:29
char ip_address[64]
IP address (IPv4 or IPv6).
Definition ice.h:126
char foundation[32]
Unique identifier for candidate (for pairing).
Definition ice.h:120
uint16_t port
Port number.
Definition ice.h:127
ice_candidate_type_t type
host, srflx, prflx, or relay
Definition ice.h:130

References ASCIICHAT_OK, ERROR_INVALID_PARAM, ice_candidate_t::foundation, ice_candidate_type_name(), ice_format_candidate(), ice_candidate_t::ip_address, log_debug, NETWORK_WEBRTC_ICE_CANDIDATE_LINE_BUFFER_SIZE, ice_candidate_t::port, SET_ERRNO, ice_candidate_t::type, and webrtc_add_remote_candidate().

◆ ice_calculate_priority()

uint32_t ice_calculate_priority ( ice_candidate_type_t type,
uint16_t local_preference,
uint8_t component_id )

Calculate candidate priority.

Implements RFC 5245 priority formula: priority = (2^24 * typePreference) + (2^8 * localPreference) + (256 - componentID)

Parameters
typeCandidate type (determines typePreference)
local_preferenceLocal preference (0-65535, higher = preferred)
component_idComponent ID (1 or 2)
Returns
Calculated priority

Definition at line 104 of file ice.c.

104 {
105 // RFC 5245: priority = (2^24 * typePreference) + (2^8 * localPreference) + (256 - componentID)
106
107 // Type preference (higher is better):
108 // - Host: 126 (most preferred, lowest latency)
109 // - SRFLX: 100 (STUN-discovered address)
110 // - PRFLX: 110 (discovered during connectivity checks)
111 // - Relay: 0 (least preferred, uses bandwidth)
112
113 uint8_t type_preference = 0;
114 switch (type) {
116 type_preference = 126;
117 break;
119 type_preference = 100;
120 break;
122 type_preference = 110;
123 break;
125 default:
126 type_preference = 0;
127 break;
128 }
129
130 uint32_t priority =
131 (((uint32_t)type_preference) << 24) | (((uint32_t)local_preference) << 8) | (256 - (uint32_t)component_id);
132
133 return priority;
134}
unsigned int uint32_t
Definition common.h:62
unsigned char uint8_t
Definition common.h:60

References ICE_CANDIDATE_HOST, ICE_CANDIDATE_PRFLX, ICE_CANDIDATE_RELAY, and ICE_CANDIDATE_SRFLX.

Referenced by ice_calculate_priority_for_candidate().

◆ ice_calculate_priority_for_candidate()

uint32_t ice_calculate_priority_for_candidate ( const ice_candidate_t * candidate)

Calculate candidate priority with IP-aware local preference.

Automatically determines local_preference based on IP address classification:

  • LAN addresses (192.168.x.x, 10.x.x.x, etc.): Highest priority (65535)
  • Localhost (127.x.x.x, ::1): High priority (65000)
  • Internet (public IPs): Medium priority (32768)
  • Unknown/invalid: Lowest priority (0)

This prioritization improves connection establishment by preferring:

  1. Local network peers (lowest latency, no NAT)
  2. Public IPs (direct connectivity)
  3. Unknown addresses (fallback)
Parameters
candidateICE candidate with IP address to classify
Returns
Calculated priority using RFC 5245 formula with IP-based local preference
Example
ice_candidate_t candidate = {
.ip_address = "192.168.1.100",
.component_id = 1
};
// Returns high priority due to LAN address
uint32_t ice_calculate_priority_for_candidate(const ice_candidate_t *candidate)
Calculate candidate priority with IP-aware local preference.
Definition ice.c:136
Single ICE candidate for connectivity.
Definition ice.h:118

Definition at line 136 of file ice.c.

136 {
137 if (!candidate) {
138 return 0;
139 }
140
141 // Calculate local preference based on IP classification
142 uint16_t local_pref = ice_calculate_local_preference_by_ip(candidate->ip_address);
143
144 // Use standard RFC 5245 priority formula with IP-aware local preference
145 return ice_calculate_priority(candidate->type, local_pref, (uint8_t)candidate->component_id);
146}
unsigned short uint16_t
Definition common.h:61
uint32_t ice_calculate_priority(ice_candidate_type_t type, uint16_t local_preference, uint8_t component_id)
Calculate candidate priority.
Definition ice.c:104
uint32_t component_id
Component (1=RTP, 2=RTCP; usually 1).
Definition ice.h:121

References ice_candidate_t::component_id, ice_calculate_priority(), ice_candidate_t::ip_address, and ice_candidate_t::type.

◆ ice_candidate_type_name()

const char * ice_candidate_type_name ( ice_candidate_type_t type)

Get human-readable candidate type name.

Parameters
typeCandidate type
Returns
Static string (e.g., "host", "srflx", "relay")

Definition at line 29 of file ice.c.

29 {
30 switch (type) {
32 return "host";
34 return "srflx";
36 return "prflx";
38 return "relay";
39 default:
40 return "unknown";
41 }
42}

References ICE_CANDIDATE_HOST, ICE_CANDIDATE_PRFLX, ICE_CANDIDATE_RELAY, and ICE_CANDIDATE_SRFLX.

Referenced by ice_add_remote_candidate(), and ice_format_candidate().

◆ ice_format_candidate()

asciichat_error_t ice_format_candidate ( const ice_candidate_t * candidate,
char * line,
size_t line_size )

Format ICE candidate to attribute string.

Converts ice_candidate_t structure to SDP attribute line.

Parameters
candidateCandidate to format
lineOutput buffer for SDP line (without "a=candidate:" prefix)
line_sizeSize of output buffer
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 323 of file ice.c.

323 {
324 if (!candidate || !line || line_size == 0) {
325 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid candidate format parameters");
326 }
327
328 // Format: foundation component protocol priority ip port typ type [raddr rport] [tcptype type]
329 // Example: 1 1 udp 2130706431 192.168.1.1 54321 typ host
330 // Example with raddr: 1 1 udp 2130706431 203.0.113.45 54321 typ srflx raddr 192.168.1.1 rport 12345
331
332 int written = safe_snprintf(line, line_size, "%s %u %s %u %s %u typ %s", candidate->foundation,
333 candidate->component_id, ice_protocol_name(candidate->protocol), candidate->priority,
334 candidate->ip_address, candidate->port, ice_candidate_type_name(candidate->type));
335
336 if (written < 0 || (size_t)written >= line_size) {
337 return SET_ERRNO(ERROR_BUFFER_FULL, "Candidate line too large for buffer");
338 }
339
340 size_t remaining = line_size - (size_t)written;
341 char *pos = line + written;
342
343 // 2. If srflx/prflx/relay: append raddr and rport
344 if (candidate->type == ICE_CANDIDATE_SRFLX || candidate->type == ICE_CANDIDATE_PRFLX ||
345 candidate->type == ICE_CANDIDATE_RELAY) {
346 if (candidate->raddr[0] != '\0') {
347 int appended = safe_snprintf(pos, remaining, " raddr %s rport %u", candidate->raddr, candidate->rport);
348 if (appended < 0 || (size_t)appended >= remaining) {
349 return SET_ERRNO(ERROR_BUFFER_FULL, "Cannot append raddr/rport to candidate line");
350 }
351 pos += appended;
352 remaining -= (size_t)appended;
353 }
354 }
355
356 // 3. If TCP: append tcptype
357 if (candidate->protocol == ICE_PROTOCOL_TCP) {
358 const char *tcptype_str = "passive"; // default
359 if (candidate->tcp_type == ICE_TCP_TYPE_ACTIVE) {
360 tcptype_str = "active";
361 } else if (candidate->tcp_type == ICE_TCP_TYPE_SO) {
362 tcptype_str = "so";
363 }
364
365 int appended = safe_snprintf(pos, remaining, " tcptype %s", tcptype_str);
366 if (appended < 0 || (size_t)appended >= remaining) {
367 return SET_ERRNO(ERROR_BUFFER_FULL, "Cannot append tcptype to candidate line");
368 }
369 pos += appended;
370 remaining -= (size_t)appended;
371 }
372
373 // 4. Append any extensions
374 if (candidate->extensions[0] != '\0') {
375 int appended = safe_snprintf(pos, remaining, " %s", candidate->extensions);
376 if (appended < 0 || (size_t)appended >= remaining) {
377 return SET_ERRNO(ERROR_BUFFER_FULL, "Cannot append extensions to candidate line");
378 }
379 }
380
381 // 5. Ensure line is null-terminated (snprintf already does this)
382 return ASCIICHAT_OK;
383}
@ ERROR_BUFFER_FULL
int safe_snprintf(char *buffer, size_t buffer_size, const char *format,...)
Platform-safe snprintf wrapper.
const char * ice_protocol_name(ice_protocol_t protocol)
Get human-readable protocol name.
Definition ice.c:44
uint32_t priority
Candidate priority (used for preference).
Definition ice.h:123
uint16_t rport
Related port.
Definition ice.h:134
ice_protocol_t protocol
UDP or TCP.
Definition ice.h:122
char extensions[256]
Additional extensions (e.g., "tcptype passive").
Definition ice.h:140
ice_tcp_type_t tcp_type
active, passive, so
Definition ice.h:137
char raddr[64]
Related address (for srflx/prflx).
Definition ice.h:133

References ASCIICHAT_OK, ice_candidate_t::component_id, ERROR_BUFFER_FULL, ERROR_INVALID_PARAM, ice_candidate_t::extensions, ice_candidate_t::foundation, ICE_CANDIDATE_PRFLX, ICE_CANDIDATE_RELAY, ICE_CANDIDATE_SRFLX, ice_candidate_type_name(), ice_protocol_name(), ICE_PROTOCOL_TCP, ICE_TCP_TYPE_ACTIVE, ICE_TCP_TYPE_SO, ice_candidate_t::ip_address, ice_candidate_t::port, ice_candidate_t::priority, ice_candidate_t::protocol, ice_candidate_t::raddr, ice_candidate_t::rport, safe_snprintf(), SET_ERRNO, ice_candidate_t::tcp_type, and ice_candidate_t::type.

Referenced by ice_add_remote_candidate().

◆ ice_gather_candidates()

asciichat_error_t ice_gather_candidates ( const ice_config_t * config)

Start ICE candidate gathering.

Initiates gathering of candidates from all sources:

  • Host candidates (network interfaces)
  • STUN server (server-reflexive)
  • TURN relay

Candidates are reported via callback as they're discovered.

Parameters
configICE gathering configuration
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 389 of file ice.c.

389 {
390 if (!config) {
391 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid ICE config");
392 }
393
394 if (!config->send_callback) {
395 return SET_ERRNO(ERROR_INVALID_PARAM, "ICE config missing send_callback");
396 }
397
398 log_debug("ICE: Starting candidate gathering (ufrag=%s, pwd=%s)", config->ufrag, config->pwd);
399
400 // NOTE: libdatachannel (juice) handles ICE candidate gathering internally.
401 // This function is a placeholder for the callback-based API.
402 // The actual gathering happens in the peer_manager when you:
403 // 1. Create peer connection with rtcCreatePeerConnection()
404 // 2. Set ice candidate callback with rtcSetIceCandidateCallback()
405 // 3. libdatachannel automatically gathers candidates from:
406 // - Local interfaces (host candidates)
407 // - STUN servers (server-reflexive candidates)
408 // - TURN servers (relay candidates)
409 // 4. When a candidate is found, rtcSetIceCandidateCallback() is called
410 // 5. Application (webrtc.c) formats and sends via ACDS signaling
411 //
412 // This ice_gather_candidates() function may not be called directly -
413 // the gathering happens automatically when peer connection is created.
414 // Keeping this for API compatibility.
415
416 return ASCIICHAT_OK;
417}
const char * ufrag
Username fragment for ICE (from offer).
Definition ice.h:172
ice_send_candidate_callback_t send_callback
Called for each gathered candidate.
Definition ice.h:174
const char * pwd
Password for ICE (from offer).
Definition ice.h:173

References ASCIICHAT_OK, ERROR_INVALID_PARAM, log_debug, ice_config_t::pwd, ice_config_t::send_callback, SET_ERRNO, and ice_config_t::ufrag.

◆ ice_get_selected_pair()

asciichat_error_t ice_get_selected_pair ( struct webrtc_peer_connection * pc,
ice_candidate_t * local_candidate,
ice_candidate_t * remote_candidate )

Get selected candidate pair.

Returns the local and remote candidates that were selected for data flow. Uses libdatachannel's rtcGetSelectedCandidatePair() API via C++ bindings.

Parameters
pcPeer connection to query
local_candidateSelected local candidate (output, may be NULL)
remote_candidateSelected remote candidate (output, may be NULL)
Returns
ASCIICHAT_OK if pair selected, ERROR_INVALID_STATE if no pair selected yet

Definition at line 462 of file ice.c.

463 {
464 // Delegate to C++ implementation which uses libdatachannel's C++ API
465 return ice_get_selected_pair_impl(pc, local_candidate, remote_candidate);
466}
asciichat_error_t ice_get_selected_pair_impl(webrtc_peer_connection_t *pc, ice_candidate_t *local_candidate, ice_candidate_t *remote_candidate)
Get selected ICE candidate pair (C++ implementation).

References ice_get_selected_pair_impl().

◆ ice_is_connected()

bool ice_is_connected ( struct webrtc_peer_connection * pc)

Check ICE connection state.

Parameters
pcPeer connection to check
Returns
true if connected, false otherwise

Definition at line 448 of file ice.c.

448 {
449 if (!pc) {
450 return false;
451 }
452
453 // Check peer connection state
455 return (state == WEBRTC_STATE_CONNECTED);
456}
webrtc_state_t webrtc_get_state(webrtc_peer_connection_t *pc)
Get current connection state.
webrtc_state_t
ICE, signaling, DataChannel, and callback settings for a WebRTC peer.
@ WEBRTC_STATE_CONNECTED
DataChannel established and ready.

References webrtc_get_state(), and WEBRTC_STATE_CONNECTED.

◆ ice_parse_candidate()

asciichat_error_t ice_parse_candidate ( const char * line,
ice_candidate_t * candidate )

Parse ICE candidate from attribute string.

Converts SDP candidate attribute line to ice_candidate_t structure.

Format: a=candidate:foundation component protocol priority ip port typ type [raddr rport] [extensions]

Parameters
lineSDP candidate line (without "a=candidate:" prefix)
candidateParsed candidate (output)
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 319 of file ice.c.

319 {
320 return ice_parse_candidate_pcre2(line, candidate);
321}

◆ ice_protocol_name()

const char * ice_protocol_name ( ice_protocol_t protocol)

Get human-readable protocol name.

Parameters
protocolProtocol type
Returns
Static string (e.g., "udp", "tcp")

Definition at line 44 of file ice.c.

44 {
45 switch (protocol) {
47 return "udp";
49 return "tcp";
50 default:
51 return "unknown";
52 }
53}

References ICE_PROTOCOL_TCP, and ICE_PROTOCOL_UDP.

Referenced by ice_format_candidate().

◆ webrtc_get_rtc_id()

int webrtc_get_rtc_id ( webrtc_peer_connection_t * pc)

Get the internal libdatachannel peer connection ID.

Helper function for C++ code that needs access to internal rtc_id without exposing the full structure definition.

Parameters
pcPeer connection to query
Returns
libdatachannel peer connection ID, or -1 if pc is NULL

Helper function for C++ code that needs access to internal rtc_id without exposing the full structure definition.

Parameters
pcPeer connection
Returns
libdatachannel peer connection ID, or -1 if pc is NULL

Definition at line 1062 of file lib/network/webrtc/webrtc.c.

1062 {
1063 if (!pc) {
1064 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid null peer connectiont");
1065 return -1;
1066 }
1067 return pc->rtc_id;
1068}
int rtc_id
libdatachannel peer connection ID