|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
Parallel mDNS and ACDS session discovery. More...
Go to the source code of this file.
Data Structures | |
| struct | discovery_result_t |
| Result from session discovery. More... | |
| struct | discovery_config_t |
| Session discovery configuration. More... | |
Functions | |
| void | discovery_config_init_defaults (discovery_config_t *config) |
| Initialize discovery config with defaults. | |
| asciichat_error_t | discover_session_parallel (const char *session_string, const discovery_config_t *config, discovery_result_t *result) |
| Look up session in parallel on mDNS and ACDS. | |
| bool | is_session_string (const char *str) |
| Check if a string matches session string pattern. | |
| discovery_tui_server_t * | discovery_mdns_query (int timeout_ms, int max_servers, bool quiet, int *out_count) |
| Discover ASCII-Chat servers on local network via mDNS. | |
| void | discovery_mdns_free (discovery_tui_server_t *servers) |
| Free memory from mDNS discovery results. | |
| void | pubkey_to_hex (const uint8_t pubkey[32], char hex_out[65]) |
| Convert Ed25519 public key to hex string. | |
| asciichat_error_t | hex_to_pubkey (const char *hex_str, uint8_t pubkey_out[32]) |
| Convert hex string to Ed25519 public key. | |
Parallel mDNS and ACDS session discovery.
Implements concurrent lookup on both mDNS (local LAN) and ACDS (internet discovery) with "race to success" semantics - whichever discovery method finds the session first is used.
Three Usage Modes:
ascii-chat swift-river-mountain--server-key flag with Ed25519 public keyascii-chat --server-key $pubkey swift-river-mountain--acds-insecure flag)ascii-chat --acds-insecure swift-river-mountainThread Architecture:
Both lookups run concurrently:
Security Model:
host_pubkey=<hex>, client checks against --server-keyhost_pubkey, SESSION_LOOKUP returns it, client verifies--server-key specified, mDNS-only mode (trust first TXT record seen)Definition in file discovery.h.
| asciichat_error_t discover_session_parallel | ( | const char * | session_string, |
| const discovery_config_t * | config, | ||
| discovery_result_t * | result | ||
| ) |
Look up session in parallel on mDNS and ACDS.
Spawns two concurrent threads to search both mDNS (local LAN) and ACDS (internet). Returns immediately when either finds the session, cancelling the other search.
Verification Logic:
If config->expected_pubkey is set:
host_pubkeyhost_pubkeyIf config->expected_pubkey is NULL but config->insecure_mode is true:
If config->expected_pubkey is NULL and config->insecure_mode is false:
Thread Lifecycle:
| session_string | Session string to find (e.g., "swift-river-mountain") |
| config | Discovery configuration |
| result | Discovery result (output) |
Definition at line 655 of file discovery.c.
References discovery_thread_state_t::acds_done, discovery_config_t::acds_timeout_ms, ASCIICHAT_OK, asciichat_thread_create(), asciichat_thread_init(), asciichat_thread_is_initialized(), asciichat_thread_join(), cond_destroy(), cond_init(), cond_timedwait(), acds_thread_context_t::config, ERROR_INVALID_PARAM, ERROR_MEMORY, ERROR_NOT_FOUND, mdns_thread_context_t::expected_pubkey, discovery_config_t::expected_pubkey, discovery_thread_state_t::found, discovery_config_t::insecure_mode, is_session_string(), discovery_thread_state_t::lock, log_debug, log_info, log_warn, discovery_thread_state_t::mdns_done, mutex_destroy(), mutex_init(), mutex_lock, mutex_unlock, discovery_thread_state_t::result, SAFE_FREE, SAFE_MALLOC, mdns_thread_context_t::session_string, acds_thread_context_t::session_string, SET_ERRNO, discovery_thread_state_t::signal, discovery_result_t::source, mdns_thread_context_t::state, acds_thread_context_t::state, and discovery_result_t::success.
Referenced by client_main().
| void discovery_config_init_defaults | ( | discovery_config_t * | config | ) |
Initialize discovery config with defaults.
Sets sensible defaults:
| config | Configuration to initialize |
Definition at line 633 of file discovery.c.
References discovery_config_t::acds_port, discovery_config_t::acds_server, discovery_config_t::acds_timeout_ms, discovery_config_t::expected_pubkey, discovery_config_t::insecure_mode, and discovery_config_t::mdns_timeout_ms.
Referenced by client_main().
| void discovery_mdns_free | ( | discovery_tui_server_t * | servers | ) |
Free memory from mDNS discovery results.
Definition at line 408 of file discovery.c.
References SAFE_FREE.
Referenced by discovery_tui_free_results().
| discovery_tui_server_t * discovery_mdns_query | ( | int | timeout_ms, |
| int | max_servers, | ||
| bool | quiet, | ||
| int * | out_count | ||
| ) |
Discover ASCII-Chat servers on local network via mDNS.
Queries for mDNS _ascii-chat._tcp services and returns discovered servers. This is the core discovery function used by both:
| timeout_ms | Query timeout in milliseconds (default: 2000) |
| max_servers | Maximum servers to discover (default: 20) |
| quiet | If true, suppresses progress messages |
| out_count | Output: number of servers discovered |
Discover ASCII-Chat servers on local network via mDNS.
| timeout_ms | Query timeout in milliseconds |
| max_servers | Maximum servers to discover |
| quiet | If true, suppresses progress messages |
| out_count | Output: number of servers discovered |
Definition at line 320 of file discovery.c.
References asciichat_mdns_init(), asciichat_mdns_query(), asciichat_mdns_shutdown(), asciichat_mdns_update(), ASCIICHAT_OK, mdns_query_state_t::capacity, mdns_query_state_t::count, ERROR_INVALID_PARAM, ERROR_MEMORY, log_info, log_warn, mdns_query_state_t::query_complete, SAFE_FREE, SAFE_MALLOC, mdns_query_state_t::servers, SET_ERRNO, mdns_query_state_t::start_time_ms, and mdns_query_state_t::timeout_ms.
Referenced by discovery_tui_query().
| asciichat_error_t hex_to_pubkey | ( | const char * | hex_str, |
| uint8_t | pubkey_out[32] | ||
| ) |
Convert hex string to Ed25519 public key.
Converts 64-character hex string to 32-byte binary pubkey.
| hex_str | Hex string (64 characters) |
| pubkey_out | Output binary pubkey (32 bytes) |
Definition at line 55 of file discovery.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, and SET_ERRNO.
Referenced by client_main().
| bool is_session_string | ( | const char * | str | ) |
Check if a string matches session string pattern.
Validates that input matches three-word pattern: word-word-word Each word is 3-64 characters of alphanumerics and hyphens (RFC 952).
Examples:
swift-river-mountain - validcat-dog-bird - validswift - invalid (only one word)swift-river- - invalid (trailing hyphen)swift_river_mountain - invalid (underscores not allowed)| str | String to validate |
Definition at line 83 of file discovery.c.
Referenced by discover_session_parallel(), and parse_client_address().
| void pubkey_to_hex | ( | const uint8_t | pubkey[32], |
| char | hex_out[65] | ||
| ) |
Convert Ed25519 public key to hex string.
Converts 32-byte binary pubkey to lowercase hex (64 characters).
| pubkey | Binary public key (32 bytes) |
| hex_out | Output hex string buffer (must be at least 65 bytes) |
Definition at line 46 of file discovery.c.