|
ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
|
Host negotiation logic for discovery mode. More...
Go to the source code of this file.
Data Structures | |
| struct | negotiate_ctx_t |
| Host negotiation context. More... | |
Enumerations | |
| enum | negotiate_state_t { NEGOTIATE_STATE_INIT , NEGOTIATE_STATE_DETECTING_NAT , NEGOTIATE_STATE_WAITING_PEER , NEGOTIATE_STATE_COMPARING , NEGOTIATE_STATE_WE_HOST , NEGOTIATE_STATE_THEY_HOST , NEGOTIATE_STATE_FAILED , NEGOTIATE_STATE_COMPLETE } |
| Negotiation state. More... | |
Functions | |
| void | negotiate_init (negotiate_ctx_t *ctx, const uint8_t session_id[16], const uint8_t participant_id[16], bool is_initiator) |
| Initialize negotiation context. | |
| asciichat_error_t | negotiate_start_detection (negotiate_ctx_t *ctx, const char *stun_server, uint16_t local_port) |
| Start NAT detection phase. | |
| asciichat_error_t | negotiate_receive_peer_quality (negotiate_ctx_t *ctx, const acip_nat_quality_t *peer_quality) |
| Process received peer NAT quality. | |
| asciichat_error_t | negotiate_determine_result (negotiate_ctx_t *ctx) |
| Determine negotiation result. | |
| negotiate_state_t | negotiate_get_state (const negotiate_ctx_t *ctx) |
| Get current negotiation state. | |
| bool | negotiate_is_complete (const negotiate_ctx_t *ctx) |
| Check if negotiation is complete. | |
| asciichat_error_t | negotiate_get_error (const negotiate_ctx_t *ctx) |
| Get negotiation error (if failed) | |
| asciichat_error_t | negotiate_elect_future_host (const acip_nat_quality_t collected_quality[], const uint8_t participant_ids[][16], size_t num_participants, uint8_t out_future_host_id[16]) |
| Elect future host from multiple participants (NEW P2P design) | |
Host negotiation logic for discovery mode.
Implements the host negotiation protocol where participants exchange NAT quality information and determine who should become the host.
Definition in file negotiate.h.
| enum negotiate_state_t |
Negotiation state.
Definition at line 26 of file negotiate.h.
| asciichat_error_t negotiate_determine_result | ( | negotiate_ctx_t * | ctx | ) |
Determine negotiation result.
Called after both parties have exchanged NAT quality. Sets we_are_host and related fields.
| ctx | Negotiation context |
Definition at line 111 of file negotiate.c.
References negotiate_ctx_t::connection_type, nat_quality_t::detection_complete, negotiate_ctx_t::host_address, negotiate_ctx_t::host_port, negotiate_ctx_t::is_initiator, nat_compare_quality(), NEGOTIATE_STATE_COMPARING, NEGOTIATE_STATE_COMPLETE, NEGOTIATE_STATE_THEY_HOST, NEGOTIATE_STATE_WE_HOST, negotiate_ctx_t::our_quality, negotiate_ctx_t::peer_quality, negotiate_ctx_t::peer_quality_received, nat_quality_t::public_address, negotiate_ctx_t::state, nat_quality_t::upnp_available, nat_quality_t::upnp_mapped_port, and negotiate_ctx_t::we_are_host.
Referenced by discovery_session_process(), negotiate_receive_peer_quality(), and negotiate_start_detection().
| asciichat_error_t negotiate_elect_future_host | ( | const acip_nat_quality_t | collected_quality[], |
| const uint8_t | participant_ids[][16], | ||
| size_t | num_participants, | ||
| uint8_t | out_future_host_id[16] | ||
| ) |
Elect future host from multiple participants (NEW P2P design)
Called by quorum leader after collecting NAT quality from all participants. Determines who should become host if current host dies. Uses deterministic algorithm so all participants independently reach same result.
| collected_quality | Array of NAT quality from all participants |
| participant_ids | Array of participant IDs (in same order as quality array) |
| num_participants | Number of participants |
| out_future_host_id | Output: Elected future host's participant ID |
Definition at line 182 of file negotiate.c.
References MAX_PARTICIPANTS, nat_compare_quality(), and nat_quality_from_acip().
| asciichat_error_t negotiate_get_error | ( | const negotiate_ctx_t * | ctx | ) |
Get negotiation error (if failed)
| ctx | Negotiation context |
Definition at line 176 of file negotiate.c.
References negotiate_ctx_t::error.
| negotiate_state_t negotiate_get_state | ( | const negotiate_ctx_t * | ctx | ) |
Get current negotiation state.
| ctx | Negotiation context |
Definition at line 164 of file negotiate.c.
References NEGOTIATE_STATE_FAILED, and negotiate_ctx_t::state.
| void negotiate_init | ( | negotiate_ctx_t * | ctx, |
| const uint8_t | session_id[16], | ||
| const uint8_t | participant_id[16], | ||
| bool | is_initiator | ||
| ) |
Initialize negotiation context.
| ctx | Context to initialize |
| session_id | Session UUID |
| participant_id | Our participant UUID |
| is_initiator | True if we created the session |
Definition at line 17 of file negotiate.c.
References negotiate_ctx_t::is_initiator, nat_quality_init(), NEGOTIATE_STATE_INIT, negotiate_ctx_t::our_quality, participant_id, negotiate_ctx_t::participant_id, negotiate_ctx_t::peer_quality, negotiate_ctx_t::peer_quality_received, session_id, negotiate_ctx_t::session_id, negotiate_ctx_t::state, and negotiate_ctx_t::we_are_host.
Referenced by discovery_session_process().
| bool negotiate_is_complete | ( | const negotiate_ctx_t * | ctx | ) |
Check if negotiation is complete.
| ctx | Negotiation context |
Definition at line 170 of file negotiate.c.
References NEGOTIATE_STATE_COMPLETE, NEGOTIATE_STATE_FAILED, and negotiate_ctx_t::state.
| asciichat_error_t negotiate_receive_peer_quality | ( | negotiate_ctx_t * | ctx, |
| const acip_nat_quality_t * | peer_quality | ||
| ) |
Process received peer NAT quality.
| ctx | Negotiation context |
| peer_quality | Peer's NAT quality from network |
Definition at line 67 of file negotiate.c.
References nat_quality_t::detection_complete, nat_compute_tier(), nat_quality_from_acip(), negotiate_determine_result(), NEGOTIATE_STATE_COMPARING, negotiate_ctx_t::our_quality, negotiate_ctx_t::peer_quality, negotiate_ctx_t::peer_quality_received, negotiate_ctx_t::state, and nat_quality_t::upload_kbps.
| asciichat_error_t negotiate_start_detection | ( | negotiate_ctx_t * | ctx, |
| const char * | stun_server, | ||
| uint16_t | local_port | ||
| ) |
Start NAT detection phase.
| ctx | Negotiation context |
| stun_server | STUN server URL |
| local_port | Local port for detection |
Definition at line 40 of file negotiate.c.
References negotiate_ctx_t::error, nat_detect_quality(), negotiate_determine_result(), NEGOTIATE_STATE_COMPARING, NEGOTIATE_STATE_DETECTING_NAT, NEGOTIATE_STATE_FAILED, NEGOTIATE_STATE_WAITING_PEER, negotiate_ctx_t::our_quality, negotiate_ctx_t::peer_quality_received, and negotiate_ctx_t::state.