|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
π― Connection fallback orchestrator for Phase 3 WebRTC integration More...
Go to the source code of this file.
Functions | |
| const char * | connection_state_name (connection_state_t state) |
| Get human-readable state name for logging. | |
| uint32_t | connection_get_stage (connection_state_t state) |
| Get current stage number (1, 2, or 3) from state. | |
| asciichat_error_t | connection_context_init (connection_attempt_context_t *ctx, bool prefer_webrtc, bool no_webrtc, bool webrtc_skip_stun, bool webrtc_disable_turn) |
| Initialize connection attempt context. | |
| void | connection_context_cleanup (connection_attempt_context_t *ctx) |
| Cleanup connection attempt context. | |
| asciichat_error_t | connection_state_transition (connection_attempt_context_t *ctx, connection_state_t new_state) |
| Transition to next connection state with validation. | |
| bool | connection_check_timeout (const connection_attempt_context_t *ctx) |
| Check if current stage has exceeded timeout. | |
| asciichat_error_t | connection_attempt_with_fallback (connection_attempt_context_t *ctx, const char *server_address, uint16_t server_port, const char *acds_server, uint16_t acds_port) |
| Orchestrate connection attempt with automatic fallback. | |
π― Connection fallback orchestrator for Phase 3 WebRTC integration
Implements the 3-stage connection fallback sequence:
Features:
Integration Points:
Definition in file connection_attempt.c.
| asciichat_error_t connection_attempt_with_fallback | ( | connection_attempt_context_t * | ctx, |
| const char * | server_address, | ||
| uint16_t | server_port, | ||
| const char * | acds_server, | ||
| uint16_t | acds_port | ||
| ) |
Orchestrate connection attempt with automatic fallback.
Attempt connection with 3-stage fallback sequence.
Implements 3-stage fallback sequence:
Each stage is attempted until success or timeout. On timeout, falls back to next stage. Returns ASCIICHAT_OK and sets ctx->active_transport when connection succeeds. Returns error code when all stages fail.
Called from src/client/main.c in the connection loop. Replaces direct TCP connection attempt with automatic fallback.
| ctx | Connection context (initialized by caller) |
| server_address | Server IP/hostname |
| server_port | Server port |
| acds_server | ACDS discovery server address |
| acds_port | ACDS discovery server port |
Definition at line 882 of file connection_attempt.c.
References ASCIICHAT_OK, CONN_STATE_CONNECTED, CONN_STATE_FAILED, connection_check_timeout(), connection_state_transition(), ERROR_INVALID_PARAM, ERROR_NETWORK, log_debug, log_error, log_info, log_warn, connection_attempt_context_t::no_webrtc, connection_attempt_context_t::prefer_webrtc, connection_attempt_context_t::reconnect_attempt, SET_ERRNO, connection_attempt_context_t::webrtc_disable_turn, and connection_attempt_context_t::webrtc_skip_stun.
Referenced by client_main().
| bool connection_check_timeout | ( | const connection_attempt_context_t * | ctx | ) |
Check if current stage has exceeded timeout.
Compares elapsed time since stage_start_time against current_stage_timeout_seconds.
| ctx | Connection context |
Definition at line 234 of file connection_attempt.c.
References connection_get_stage(), connection_attempt_context_t::current_stage_timeout_seconds, connection_attempt_context_t::current_state, log_warn, and connection_attempt_context_t::stage_start_time.
Referenced by connection_attempt_with_fallback().
| void connection_context_cleanup | ( | connection_attempt_context_t * | ctx | ) |
Cleanup connection attempt context.
Closes and releases any active transports, frees WebRTC peer manager. Called on connection success, failure, or shutdown.
| ctx | Connection context to cleanup |
Definition at line 156 of file connection_attempt.c.
References acip_transport_destroy(), connection_attempt_context_t::active_transport, log_debug, connection_attempt_context_t::peer_manager, tcp_client_destroy(), connection_attempt_context_t::tcp_client_instance, connection_attempt_context_t::tcp_transport, webrtc_peer_manager_destroy(), and connection_attempt_context_t::webrtc_transport.
Referenced by client_main().
| asciichat_error_t connection_context_init | ( | connection_attempt_context_t * | ctx, |
| bool | prefer_webrtc, | ||
| bool | no_webrtc, | ||
| bool | webrtc_skip_stun, | ||
| bool | webrtc_disable_turn | ||
| ) |
Initialize connection attempt context.
Sets up initial state, resets timeouts, and prepares for connection attempt.
| ctx | Connection context to initialize |
| prefer_webrtc | CLI flag: prefer WebRTC over TCP |
| no_webrtc | CLI flag: disable WebRTC, use TCP only |
| webrtc_skip_stun | CLI flag: skip STUN stage, go straight to TURN |
| webrtc_disable_turn | CLI flag: disable TURN stage (use STUN as fallback) |
Definition at line 118 of file connection_attempt.c.
References ASCIICHAT_OK, CONN_STATE_IDLE, CONN_TIMEOUT_DIRECT_TCP, connection_attempt_context_t::current_stage_timeout_seconds, connection_attempt_context_t::current_state, ERROR_INVALID_PARAM, log_debug, connection_attempt_context_t::no_webrtc, connection_attempt_context_t::prefer_webrtc, connection_attempt_context_t::previous_state, connection_attempt_context_t::reconnect_attempt, SET_ERRNO, connection_attempt_context_t::stage_failures, connection_attempt_context_t::stage_start_time, connection_attempt_context_t::total_transitions, connection_attempt_context_t::webrtc_disable_turn, and connection_attempt_context_t::webrtc_skip_stun.
Referenced by client_main().
| uint32_t connection_get_stage | ( | connection_state_t | state | ) |
Get current stage number (1, 2, or 3) from state.
Get current stage number (1, 2, or 3)
Definition at line 98 of file connection_attempt.c.
References CONN_STATE_ATTEMPTING_DIRECT_TCP, CONN_STATE_ATTEMPTING_WEBRTC_STUN, CONN_STATE_ATTEMPTING_WEBRTC_TURN, CONN_STATE_DIRECT_TCP_FAILED, CONN_STATE_WEBRTC_STUN_FAILED, and CONN_STATE_WEBRTC_TURN_FAILED.
Referenced by connection_check_timeout(), and connection_state_transition().
| const char * connection_state_name | ( | connection_state_t | state | ) |
Get human-readable state name for logging.
| state | Connection state |
Definition at line 54 of file connection_attempt.c.
References CONN_STATE_ATTEMPTING_DIRECT_TCP, CONN_STATE_ATTEMPTING_WEBRTC_STUN, CONN_STATE_ATTEMPTING_WEBRTC_TURN, CONN_STATE_CONNECTED, CONN_STATE_DIRECT_TCP_CONNECTED, CONN_STATE_DIRECT_TCP_FAILED, CONN_STATE_DISCONNECTED, CONN_STATE_FAILED, CONN_STATE_IDLE, CONN_STATE_WEBRTC_STUN_CONNECTED, CONN_STATE_WEBRTC_STUN_FAILED, CONN_STATE_WEBRTC_STUN_SIGNALING, CONN_STATE_WEBRTC_TURN_CONNECTED, CONN_STATE_WEBRTC_TURN_FAILED, and CONN_STATE_WEBRTC_TURN_SIGNALING.
Referenced by connection_state_transition().
| asciichat_error_t connection_state_transition | ( | connection_attempt_context_t * | ctx, |
| connection_state_t | new_state | ||
| ) |
Transition to next connection state with validation.
Transition to next connection state.
Definition at line 194 of file connection_attempt.c.
References ASCIICHAT_OK, CONN_TIMEOUT_DIRECT_TCP, CONN_TIMEOUT_WEBRTC_STUN, CONN_TIMEOUT_WEBRTC_TURN, connection_get_stage(), connection_state_name(), connection_attempt_context_t::current_stage_timeout_seconds, connection_attempt_context_t::current_state, ERROR_INVALID_PARAM, log_debug, connection_attempt_context_t::previous_state, SET_ERRNO, connection_attempt_context_t::stage_start_time, and connection_attempt_context_t::total_transitions.
Referenced by connection_attempt_with_fallback().