|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
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 |
| ICE gathering configuration. More... | |
Typedefs | |
| typedef asciichat_error_t(* | ice_send_candidate_callback_t) (const ice_candidate_t *candidate, const char *mid, void *user_data) |
| Callback for sending ICE candidate to peer. | |
Enumerations | |
| enum | ice_candidate_type_t { ICE_CANDIDATE_HOST = 0 , ICE_CANDIDATE_SRFLX = 1 , ICE_CANDIDATE_PRFLX = 2 , ICE_CANDIDATE_RELAY = 3 } |
| ICE candidate type enumeration (RFC 5245) 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. | |
| asciichat_error_t | ice_add_remote_candidate (const ice_candidate_t *candidate, const char *mid) |
| Add remote candidate to peer connection. | |
| bool | ice_is_connected (void) |
| Check ICE connection state. | |
| asciichat_error_t | ice_get_selected_pair (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. | |
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.
Host candidates: Local IP addresses
Server-reflexive (srflx) candidates: NAT-discovered addresses
Peer-reflexive (prflx) candidates: Discovered during connectivity checks
Relay candidates: TURN relay server addresses
ICE candidates are sent via ACDS signaling relay:
Definition in file ice.h.
| typedef asciichat_error_t(* ice_send_candidate_callback_t) (const ice_candidate_t *candidate, const char *mid, void *user_data) |
Callback for sending ICE candidate to peer.
Called by ICE agent when a new candidate is discovered. Implementation should send via ACDS relay.
| candidate | Discovered candidate |
| mid | Media stream ID (e.g., "0" for audio, "1" for video) |
| user_data | User context pointer |
| enum ice_candidate_type_t |
ICE candidate type enumeration (RFC 5245)
Definition at line 74 of file ice.h.
| enum ice_protocol_t |
ICE candidate transport protocol.
| Enumerator | |
|---|---|
| ICE_PROTOCOL_UDP | |
| ICE_PROTOCOL_TCP | |
| enum 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 92 of file ice.h.
| asciichat_error_t ice_add_remote_candidate | ( | 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.
| candidate | Remote candidate from peer |
| mid | Media stream ID |
Definition at line 320 of file ice.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ice_candidate_t::foundation, ice_candidate_type_name(), ice_candidate_t::ip_address, log_debug, ice_candidate_t::port, SET_ERRNO, and ice_candidate_t::type.
| 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)
| type | Candidate type (determines typePreference) |
| local_preference | Local preference (0-65535, higher = preferred) |
| component_id | Component ID (1 or 2) |
Definition at line 51 of file ice.c.
References ICE_CANDIDATE_HOST, ICE_CANDIDATE_PRFLX, ICE_CANDIDATE_RELAY, and ICE_CANDIDATE_SRFLX.
| const char * ice_candidate_type_name | ( | ice_candidate_type_t | type | ) |
Get human-readable candidate type name.
| type | Candidate type |
Definition at line 21 of file ice.c.
References ICE_CANDIDATE_HOST, ICE_CANDIDATE_PRFLX, ICE_CANDIDATE_RELAY, and ICE_CANDIDATE_SRFLX.
Referenced by ice_add_remote_candidate(), and 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.
| candidate | Candidate to format |
| line | Output buffer for SDP line (without "a=candidate:" prefix) |
| line_size | Size of output buffer |
Definition at line 220 of file ice.c.
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, SET_ERRNO, ice_candidate_t::tcp_type, and ice_candidate_t::type.
| asciichat_error_t ice_gather_candidates | ( | const ice_config_t * | config | ) |
Start ICE candidate gathering.
Initiates gathering of candidates from all sources:
Candidates are reported via callback as they're discovered.
| config | ICE gathering configuration |
Definition at line 286 of file ice.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, log_debug, ice_config_t::pwd, ice_config_t::send_callback, SET_ERRNO, and ice_config_t::ufrag.
| asciichat_error_t ice_get_selected_pair | ( | 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.
| local_candidate | Selected local candidate (output, may be NULL) |
| remote_candidate | Selected remote candidate (output, may be NULL) |
Definition at line 362 of file ice.c.
References ERROR_INVALID_STATE, and SET_ERRNO.
| bool ice_is_connected | ( | void | ) |
Check ICE connection state.
Definition at line 352 of file ice.c.
| 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]
| line | SDP candidate line (without "a=candidate:" prefix) |
| candidate | Parsed candidate (output) |
Definition at line 89 of file ice.c.
References ASCIICHAT_OK, ice_candidate_t::component_id, ERROR_INVALID_PARAM, ice_candidate_t::foundation, ICE_CANDIDATE_HOST, ICE_CANDIDATE_PRFLX, ICE_CANDIDATE_RELAY, ICE_CANDIDATE_SRFLX, ICE_PROTOCOL_TCP, ICE_PROTOCOL_UDP, ICE_TCP_TYPE_ACTIVE, ICE_TCP_TYPE_PASSIVE, 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_STRNCPY, SET_ERRNO, ice_candidate_t::tcp_type, and ice_candidate_t::type.
| const char * ice_protocol_name | ( | ice_protocol_t | protocol | ) |
Get human-readable protocol name.
| protocol | Protocol type |
Definition at line 36 of file ice.c.
References ICE_PROTOCOL_TCP, and ICE_PROTOCOL_UDP.
Referenced by ice_format_candidate().