ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
server_like.c
Go to the documentation of this file.
1
2/* Storage capacities in elements; text buffers include the terminating NUL. */
3#define SESSION_SERVER_LIKE_PUBLIC_ADDR_BUFFER_SIZE 22
4
14
17#include "server_like.h"
18#include "quic_listeners.h"
20#include <ascii-chat/common.h>
23#include <ascii-chat/log/log.h>
25#include <ascii-chat/buffer.h>
29#include <options/options.h>
30#include <libflags/explicit.h>
31#include <libplatform/compiler.h>
32#include <libplatform/system.h>
33#include <libplatform/terminal.h>
34#include <libplatform/systemd.h>
35#include <libplatform/keyboard.h>
36#include <libplatform/system.h>
37#include <libplatform/terminal.h>
38#include <ascii-chat/util/ip.h>
40#include <signal.h>
41#include <string.h>
42
43/* ============================================================================
44 * Static State
45 * ============================================================================ */
46
47static network_server_t *g_network_server;
48static quic_endpoint_t *g_quic_endpoint;
49static quic_endpoint_t *g_webtransport_endpoint;
50
51static asciichat_mdns_t *g_mdns_ctx = NULL;
52static nat_upnp_context_t *g_upnp_ctx = NULL;
53static nat_upnp_context_t *g_ws_upnp_ctx = NULL;
54static platform_thread_t g_upnp_thread;
55static bool g_upnp_thread_started = false;
56static atomic_t g_upnp_stop = {0};
57static atomic_t g_upnp_ready = {0};
58
59// The worker is the sole mapping writer after mode initialization. Shutdown
60// joins it before freeing the context or issuing the delete request.
61static void *upnp_renewal_thread(void *unused) {
62 (void)unused;
63 while (!atomic_load_bool(&g_upnp_stop)) {
64 if (atomic_load_bool(&g_upnp_ready)) {
65 nat_upnp_context_t *mappings[] = {g_upnp_ctx, g_ws_upnp_ctx};
66 for (size_t i = 0; i < sizeof(mappings) / sizeof(mappings[0]); i++) {
67 if (mappings[i] && time_get_ns() >= mappings[i]->refresh_at_ns) {
69 if (nat_upnp_refresh(mappings[i]) != ASCIICHAT_OK) {
70 LOG_ERRNO_IF_SET("Router mapping renewal failed");
71 }
73 }
74 }
75 }
77 }
78 return NULL;
79}
80
81static platform_thread_t g_status_screen_thread;
82static bool g_status_screen_thread_started = false;
83
85static session_server_like_status_fn g_status_fn = NULL;
86static void *g_status_user_data = NULL;
87
88/* ============================================================================
89 * Signal Handler
90 * ============================================================================ */
91
93static atomic_t g_shutdown_requested = {0};
94
95static session_server_like_interrupt_fn g_interrupt_fn = NULL;
96
97static void server_like_signal_handler(int sig) {
98 atomic_store_u64(&g_shutdown_requested, 1);
99 if (g_interrupt_fn) {
100 g_interrupt_fn(sig);
101 }
102}
103
104/* ============================================================================
105 * Keyboard Queue (lock-free SPSC ring buffer)
106 * ============================================================================ */
107
108/* ============================================================================
109 * Status Screen Thread
110 * ============================================================================ */
111
113static atomic_t g_status_should_exit = {0};
114
115static void *status_screen_thread_func(void *arg) {
116 (void)arg;
117
118 uint32_t fps = GET_OPTION(fps);
119 if (fps == 0) {
120 fps = 60;
121 }
122 uint64_t frame_interval_us = US_PER_SEC_INT / fps;
123
124 log_debug("Status screen thread started (target %u FPS)", fps);
125
126 int output_fd = platform_isatty(STDOUT_FILENO) ? STDOUT_FILENO : STDERR_FILENO;
127
128 // Stderr is the status output when stdout is redirected; retain it in that
129 // case. The presentation controller suppresses competing terminal log writes.
130 platform_stderr_redirect_handle_t stderr_redirect = {.original_fd = -1, .devnull_fd = -1};
131 if (output_fd != STDERR_FILENO) {
132 stderr_redirect = platform_stderr_redirect_to_null();
133 }
134
135 while (!atomic_load_bool(&g_status_should_exit)) {
136 uint64_t frame_start = platform_get_monotonic_time_us();
139
140 // Call mode's status callback to populate status data
141 // Callbacks outlive the borrowed run configuration until the thread stops.
142 if (g_status_fn) {
143 ui_status_t status;
144 memset(&status, 0, sizeof(status));
145 g_status_fn(g_status_user_data, &status);
147 }
148
149 // Maintain frame rate
150 uint64_t frame_end = platform_get_monotonic_time_us();
151 uint64_t frame_time = frame_end - frame_start;
152 if (frame_time < frame_interval_us) {
153 platform_sleep_us((unsigned int)(frame_interval_us - frame_time));
154 }
155 }
156
158
159 platform_stderr_restore(stderr_redirect);
160
161 log_debug("Status screen thread exiting");
162 return NULL;
163}
164
165/* ============================================================================
166 * WebSocket Server Thread
167 * ============================================================================ */
168
170 return g_network_server;
171}
172
174 return g_mdns_ctx;
175}
176
178 return g_upnp_ctx;
179}
180
181/* ============================================================================
182 * Helpers
183 * ============================================================================ */
184
185asciichat_error_t session_server_like_mdns_advertise(const char *name, const char *type, uint16_t port, const char **txt, size_t txt_count) {
186 if (!g_mdns_ctx) {
187 return SET_ERRNO(ERROR_INVALID_STATE, "mDNS context not initialized");
188 }
189
190 char hostname[HOSTNAME_BUFFER_SIZE] = {0};
191 gethostname(hostname, sizeof(hostname) - 1);
192
193 asciichat_mdns_service_t service = {
194 .name = name,
195 .type = type,
196 .host = hostname,
197 .port = port,
198 .txt_records = txt,
199 .txt_count = txt_count,
200 };
201
202 asciichat_error_t result = asciichat_mdns_advertise(g_mdns_ctx, &service);
203 if (result != ASCIICHAT_OK) {
204 LOG_ERRNO_IF_SET("Failed to advertise mDNS service");
205 log_warn("mDNS advertising failed - LAN discovery disabled");
206 } else {
207 log_info("mDNS: Service advertised as '%s' type '%s' (port=%d)", name, type, port);
208 }
209
210 return result;
211}
212
213/* ============================================================================
214 * Accessors (shutdown state and network resources)
215 * ============================================================================ */
216
218 server_like_signal_handler(SIGINT);
219}
220
222 return (bool)atomic_load_u64(&g_shutdown_requested);
223}
224
225/* ============================================================================
226 * Shared Handshake
227 * ============================================================================ */
228
230 if (!config) {
231 return SET_ERRNO(ERROR_INVALID_PARAM, "config is NULL");
232 }
233 if (!config->init_fn) {
234 return SET_ERRNO(ERROR_INVALID_PARAM, "init_fn is NULL");
235 }
236 if (!config->interrupt_fn) {
237 return SET_ERRNO(ERROR_INVALID_PARAM, "interrupt_fn is NULL");
238 }
239 if (!config->connections.packet) {
240 return SET_ERRNO(ERROR_INVALID_PARAM, "connection packet callback is NULL");
241 }
242
244
245 /* === 1. Keepawake === */
246
247 bool keepawake_enabled = GET_OPTION(enable_keepawake);
248 bool keepawake_disabled = GET_OPTION(disable_keepawake);
249 if (keepawake_enabled && keepawake_disabled) {
250 return SET_ERRNO(ERROR_INVALID_PARAM, "Cannot specify both --keepawake and --no-keepawake");
251 }
252 if (keepawake_enabled) {
254 bool suppressed = errno_notifications_suppress(true);
255 asciichat_error_t keepawake_result = platform_enable_keepawake();
257 if (keepawake_result != ASCIICHAT_OK) {
258 log_warn("Unable to inhibit system sleep: %s", asciichat_error_string(keepawake_result));
259 }
261 }
262
263 /* === 2. File descriptor limit === */
264
265 if (config->raise_fd_limit) {
266 platform_raise_fd_limit(config->fd_limit_target);
267 }
268
269 /* === 3. Signal handlers === */
270
271 atomic_store_u64(&g_shutdown_requested, 0);
272 g_interrupt_fn = config->interrupt_fn;
273 platform_signal(SIGINT, server_like_signal_handler);
274 platform_signal(SIGTERM, server_like_signal_handler);
275#ifndef _WIN32
276 platform_signal(SIGPIPE, SIG_IGN);
277#endif
278
279 /* === 4. TCP server init === */
280
281 int port = GET_OPTION(port);
282 const char *address = GET_OPTION(address);
283 const char *address6 = GET_OPTION(address6);
284
285 const char *effective_address = (address && strlen(address) > 0) ? address : "127.0.0.1";
286 const char *effective_address6 = (address6 && strlen(address6) > 0) ? address6 : "::1";
287 bool ipv4_has_value = true;
288
289 result = session_quic_listeners_open(port, &g_quic_endpoint, &g_webtransport_endpoint);
290 if (result != ASCIICHAT_OK)
291 goto cleanup;
292
293 network_server_config_t tcp_config = {
294 .port = port,
295 .ipv4_address = effective_address,
296 .ipv6_address = effective_address6,
297 .bind_ipv4 = true,
298 .bind_ipv6 = true,
299 .callbacks = config->connections,
300 .max_payload = config->max_payload,
301 .partial_timeout_ms = config->partial_timeout_ms,
302 .idle_timeout_ms = config->idle_timeout_ms,
303 .websocket_enabled = config->websocket_enabled,
304 .websocket_port = GET_OPTION(websocket_port),
305 .tls_cert_path = GET_OPTION(tls_cert),
306 .tls_key_path = GET_OPTION(tls_key),
307 .tick = config->tick_fn,
308 .tick_context = config->tick_user_data,
309 .user_data = config->connection_user_data,
310 .quic_endpoint = g_quic_endpoint,
311 .webtransport_endpoint = g_webtransport_endpoint,
312 };
313
314 result = network_server_create(&tcp_config, &g_network_server);
315 if (result != ASCIICHAT_OK) {
316 log_error("Failed to initialize TCP server on port %d", port);
317 goto cleanup;
318 }
319 log_info("TCP server initialized on port %d", port);
320
321 /* === 5. UPnP port mapping === */
322
323 bool upnp_requested = config->upnp.enabled && GET_OPTION(enable_upnp);
324 bool ipv4_loopback = ipv4_has_value && is_localhost_ipv4(address);
325 bool ipv4_listener = tcp_config.bind_ipv4 && !ipv4_loopback;
326 if (upnp_requested && ipv4_listener) {
327 log_info("UPnP status: discovering (TCP port %d)", port);
329 asciichat_error_t upnp_result = nat_upnp_open((uint16_t)port, config->upnp.description, &g_upnp_ctx);
330 if (upnp_result == ASCIICHAT_OK && !nat_upnp_matches_bind_address(g_upnp_ctx, tcp_config.ipv4_address)) {
331 log_warn("NAT: gateway mapping does not target the bound IPv4 listener; removing it");
332 nat_upnp_close(&g_upnp_ctx);
333 upnp_result = ERROR_NETWORK;
334 }
335 if (upnp_result == ASCIICHAT_OK && nat_upnp_is_active(g_upnp_ctx)) {
337 if (nat_upnp_get_address(g_upnp_ctx, public_addr, sizeof(public_addr)) == ASCIICHAT_OK) {
338 log_info("UPnP status: mapped at %s (external reachability unverified)", public_addr);
339 }
340 } else {
341 log_warn("UPnP status: unavailable. Listener remains enabled; for Internet access, "
342 "check router support or manually forward TCP port %d. External reachability is unverified.",
343 port);
344 }
346 } else if (upnp_requested) {
347 log_info("UPnP status: disabled (requires a non-loopback IPv4 listener)");
348 } else {
349 log_info("UPnP status: disabled");
350 if (ipv4_listener && (!ipv4_has_value || strcmp(address, "0.0.0.0") == 0 || is_lan_ipv4(address))) {
351 log_info("For connections from outside your LAN, try --port-forwarding or forward TCP port %d on your router.", port);
352 }
353 }
354
355 /* === 6. mDNS === */
356
357 if (config->mdns.enabled) {
358 g_mdns_ctx = asciichat_mdns_init();
359 if (!g_mdns_ctx) {
360 LOG_ERRNO_IF_SET("Failed to initialize mDNS (non-fatal, LAN discovery disabled)");
361 log_warn("mDNS disabled - LAN discovery will not be available");
362 } else if (config->mdns.service_name) {
363 // Immediate advertisement if service_name is provided
365 }
366 }
367
368 /* === 8. Mode-specific init === */
369
370 result = config->init_fn(config->init_user_data);
371 if (result != ASCIICHAT_OK) {
372 log_error("Mode initialization failed");
373 goto cleanup;
374 }
375
376 /* === 8b. WebSocket event loop thread start (after mode init succeeds) === */
377
378 if (!atomic_load_u64(&g_shutdown_requested)) {
379 result = network_server_start(g_network_server);
380 if (result != ASCIICHAT_OK)
381 goto cleanup;
382 platform_systemd_notify_status("Listener started");
383 platform_systemd_notify_ready();
384 if (config->ready_fn)
385 config->ready_fn();
386 } else {
387 goto cleanup;
388 }
389
390 if (upnp_requested && network_server_websocket_enabled(g_network_server)) {
391 // WebSocket binds independently of the raw TCP listener's address.
392 asciichat_errno_scope_t ws_mapping_scope = errno_scope_begin();
393 if (nat_upnp_open((uint16_t)GET_OPTION(websocket_port), "ascii-chat WebSocket", &g_ws_upnp_ctx) != ASCIICHAT_OK) {
394 log_warn("WebSocket mapping unavailable; manually forward TCP port %d if needed", GET_OPTION(websocket_port));
395 }
396 errno_scope_end(ws_mapping_scope, ASCIICHAT_ERRNO_HANDLED);
397 }
398
399 if (g_upnp_ctx || g_ws_upnp_ctx) {
400 atomic_store_bool(&g_upnp_stop, false);
401 atomic_store_bool(&g_upnp_ready, false);
402 if (platform_thread_create(&g_upnp_thread, "upnp_renewal", upnp_renewal_thread, NULL) == 0) {
403 g_upnp_thread_started = true;
404 } else {
405 log_warn("NAT: could not start lease renewal; removing the temporary mapping");
406 nat_upnp_close(&g_upnp_ctx);
407 nat_upnp_close(&g_ws_upnp_ctx);
408 }
409 }
410
411 // Keep bounded log capture available even when only the stats overlay is used.
413 /* === 9. Status screen === */
414
415 if (config->status_fn) {
416 bool status_opt = GET_OPTION(status_screen);
417 bool status_explicit = flags_explicit_state_was_set("status-screen");
418 if ((status_opt && terminal_is_interactive()) || (status_explicit && status_opt)) {
419 atomic_store_bool(&g_status_should_exit, false);
420
421 // Store callback and user data for the lifetime of the status thread.
422 g_status_fn = config->status_fn;
423 g_status_user_data = config->status_user_data;
424
425 if (platform_thread_create(&g_status_screen_thread, "status_screen", status_screen_thread_func, NULL) == 0) {
426 g_status_screen_thread_started = true;
427 log_info("Status screen thread started");
428 } else {
429 log_error("Failed to start status screen thread");
431 g_status_fn = NULL;
432 g_status_user_data = NULL;
433 }
434 }
435 }
436
437 atomic_store_bool(&g_upnp_ready, true);
438
439 /* === 10. TCP accept loop (blocks) === */
440
441 log_info("Server accepting connections on port %d", port);
443 result = network_server_run(g_network_server);
444 if (result != ASCIICHAT_OK) {
445 log_error("TCP server exited with error");
446 }
447
448 /* === CLEANUP === */
449
450cleanup:
451 if (g_upnp_thread_started) {
452 atomic_store_bool(&g_upnp_stop, true);
453 thread_join(&g_upnp_thread, NULL);
454 g_upnp_thread_started = false;
455 }
456
457 // Remove the mapping before mode teardown, which can wait on other services.
458 if (g_upnp_ctx) {
459 nat_upnp_close(&g_upnp_ctx);
460 log_debug("UPnP port mapping closed");
461 }
462
463 nat_upnp_close(&g_ws_upnp_ctx);
464
465 /* 11. Stop status screen */
466 if (g_status_screen_thread_started) {
467 atomic_store_bool(&g_status_should_exit, true);
468 int join_result = thread_join_timeout(&g_status_screen_thread, NULL, 2000 * NS_PER_MS_INT);
469 if (join_result != 0) {
470 log_warn("Status screen thread did not exit within 2s");
471 }
472 g_status_screen_thread_started = false;
473 g_status_fn = NULL;
474 g_status_user_data = NULL;
475 }
477
478 asciichat_error_t stopped = network_server_stop(g_network_server);
479 if (stopped != ASCIICHAT_OK)
480 return stopped;
481
482 /* 13. Mode-specific cleanup (only call if config provided) */
483 if (config && config->cleanup_fn) {
484 config->cleanup_fn(config->cleanup_user_data);
485 }
486
487 network_server_destroy(&g_network_server);
488 stopped = session_quic_listeners_close(&g_quic_endpoint, &g_webtransport_endpoint);
489 if (stopped != ASCIICHAT_OK)
490 return stopped;
491
492 /* 17. mDNS cleanup */
493 if (g_mdns_ctx) {
494 asciichat_mdns_destroy(g_mdns_ctx);
495 g_mdns_ctx = NULL;
496 log_debug("mDNS context destroyed");
497 }
498
499 /* 18. Keepawake */
500 if (keepawake_enabled) {
502 }
503
504 return result;
505}
void errno_scope_end(asciichat_errno_scope_t scope, asciichat_errno_outcome_t outcome)
bool errno_notifications_suppress(bool suppress)
asciichat_errno_scope_t errno_scope_begin(void)
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
#define SET_ERRNO(code,...)
@ ASCIICHAT_ERRNO_HANDLED
#define LOG_ERRNO_IF_SET(message)
void atomic_store_bool(atomic_t *a, bool value)
Atomically store a boolean value.
bool atomic_load_bool(atomic_t *a)
Atomic pointer wrapper.
void atomic_store_u64(atomic_t *a, uint64_t value)
Atomically store a uint64_t value.
uint64_t atomic_load_u64(const atomic_t *a)
Atomically load a uint64_t value.
Named object registry for debugging — log identifiable resource names.
unsigned short uint16_t
unsigned int uint32_t
unsigned long long uint64_t
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_INVALID_STATE
@ ERROR_NETWORK
Definition error_codes.h:77
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
#define HOSTNAME_BUFFER_SIZE
#define log_warn(...)
Log a WARN message.
Definition log/log.h:591
#define log_error(...)
Log an ERROR message.
Definition log/log.h:604
#define log_info(...)
Log an INFO message.
Definition log/log.h:578
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:565
#define NS_PER_MS_INT
Definition time.h:172
void time_sleep_ns(uint64_t ns)
Configuration for adaptive sleep behavior.
Definition time.c:116
#define US_PER_SEC_INT
Definition time.h:177
#define GET_OPTION(field)
Definition options.h:1339
int is_lan_ipv4(const char *ip)
Check if IPv4 address is a private/LAN address.
Definition ip.c:1145
int is_localhost_ipv4(const char *ip)
Check if IPv4 address is localhost.
Definition ip.c:1259
⚙️ Common definitions, error codes, macros, and types shared throughout the application
Server-side handshake functions.
struct quic_endpoint quic_endpoint_t
struct network_server network_server_t
🌍 IP Address Parsing and Formatting Utilities
asciichat_error_t network_server_create(const network_server_config_t *config, network_server_t **out)
asciichat_error_t network_server_start(network_server_t *s)
void network_server_destroy(network_server_t **owner)
asciichat_error_t network_server_stop(network_server_t *s)
asciichat_error_t network_server_run(network_server_t *s)
bool network_server_websocket_enabled(network_server_t *s)
📝 Logging API with multiple log levels and terminal output control
void asciichat_mdns_destroy(asciichat_mdns_t *mdns)
Shutdown mDNS context and cleanup.
asciichat_mdns_t * asciichat_mdns_init(void)
Initialize mDNS context.
asciichat_error_t asciichat_mdns_advertise(asciichat_mdns_t *mdns, const asciichat_mdns_service_t *service)
Advertise a service on the local network.
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
asciichat_error_t session_quic_listeners_close(quic_endpoint_t **native, quic_endpoint_t **webtransport)
asciichat_error_t session_quic_listeners_open(int port, quic_endpoint_t **native, quic_endpoint_t **webtransport)
bool log_search_check_signal_cancel(void)
Check and clear the signal-cancel flag.
Definition search.c:418
void log_search_exit_mode(bool accept)
Exit search mode.
Definition search.c:312
Interactive search filtering for terminal screens.
ACIP shared/bidirectional packet sending functions.
void session_server_like_request_shutdown(void)
#define SESSION_SERVER_LIKE_PUBLIC_ADDR_BUFFER_SIZE
Definition server_like.c:3
bool session_server_like_shutdown_requested(void)
asciichat_mdns_t * session_server_like_get_mdns_ctx(void)
asciichat_error_t session_server_like_mdns_advertise(const char *name, const char *type, uint16_t port, const char **txt, size_t txt_count)
asciichat_error_t session_server_like_run(const session_server_like_config_t *config)
network_server_t * session_server_like_get_network_server(void)
nat_upnp_context_t * session_server_like_get_upnp_ctx(void)
struct session_server_like_config session_server_like_config_t
The useful part of session server like config is in [struct].mdns, [struct].upnp, init_fn,...
void(* session_server_like_status_fn)(void *user_data, ui_status_t *out_status)
Definition server_like.h:29
void(* session_server_like_interrupt_fn)(int sig)
Definition server_like.h:25
bool terminal_is_interactive(void)
void ui_status_log_destroy(void)
Cleanup status screen log capture system.
Definition status.c:59
void ui_status_log_init(void)
Initialize status screen log capture system.
Definition status.c:51
bool ui_status_display_interactive(const ui_status_t *status)
Display status screen with keyboard input support Returns true if status screen should continue,...
Definition status.c:170
🔤 String Manipulation and Shell Escaping Utilities
When code needs to work with asciichat errno snapshot, it keeps total, copied here instead of scatter...
Service information for advertisement.
Owns one mDNS browse or advertisement session, including its socket, event-loop registration,...
Atomic value wrapper for integral/boolean types.
Definition atomic.h:80
asciichat_error_t(* packet)(network_connection_t *, packet_type_t, const void *, size_t, void *)
void(* tick_fn)(void *user_data)
Definition server_like.h:44
struct session_server_like_config::@331157361304265235031377013321160306024244316160 mdns
session_server_like_interrupt_fn interrupt_fn
Definition server_like.h:42
struct session_server_like_config::@022167030105260237161361274212172160377140006150 upnp
network_connection_callbacks_t connections
Definition server_like.h:53
session_server_like_init_fn init_fn
Definition server_like.h:38
session_server_like_cleanup_fn cleanup_fn
Definition server_like.h:47
session_server_like_status_fn status_fn
Definition server_like.h:50
Status information for server/discovery service modes.
Definition status.h:43
signal_handler_t platform_signal(int, signal_handler_t)
void platform_disable_keepawake(void)
Definition stubs/system.c:8
int platform_enable_keepawake(void)
Definition stubs/system.c:4
⏱️ High-precision timing utilities using sokol_time.h and uthash
void ui_controller_remove(ui_screen_t screen)
void ui_controller_title_ready(void)
@ UI_SCREEN_STATUS
asciichat_error_t nat_upnp_refresh(nat_upnp_context_t *ctx)
Refresh port mapping (e.g., for long-running servers).
Definition upnp.c:303
bool nat_upnp_matches_bind_address(const nat_upnp_context_t *ctx, const char *bind_address)
Whether the mapping targets a specific IPv4 bind address, or any wildcard listener.
Definition upnp.c:284
bool nat_upnp_is_active(const nat_upnp_context_t *ctx)
Check if port mapping is still active.
Definition upnp.c:280
void nat_upnp_close(nat_upnp_context_t **ctx)
Close port mapping and clean up.
Definition upnp.c:240
asciichat_error_t nat_upnp_open(uint16_t internal_port, const char *description, nat_upnp_context_t **ctx)
Discover and open port via UPnP.
Definition upnp.c:194
asciichat_error_t nat_upnp_get_address(const nat_upnp_context_t *ctx, char *addr, size_t addr_len)
Get the public address (IP:port) for advertising to clients.
Definition upnp.c:329
struct nat_upnp_context nat_upnp_context_t
Handle to UPnP context.
int platform_isatty(int fd)
Definition util.c:70