|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
UPnP/NAT-PMP port mapping implementation. More...
Go to the source code of this file.
Functions | |
| asciichat_error_t | nat_upnp_open (uint16_t internal_port, const char *description, nat_upnp_context_t **ctx) |
| Discover and open port via UPnP. | |
| void | nat_upnp_close (nat_upnp_context_t **ctx) |
| Close port mapping and clean up. | |
| bool | nat_upnp_is_active (const nat_upnp_context_t *ctx) |
| Check if port mapping is still active. | |
| asciichat_error_t | nat_upnp_refresh (nat_upnp_context_t *ctx) |
| Refresh port mapping (e.g., for long-running servers) | |
| 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. | |
UPnP/NAT-PMP port mapping implementation.
Strategy for enabling direct TCP without WebRTC:
This pragmatic approach provides direct connectivity for most home users while maintaining compatibility with stricter NATs via WebRTC fallback.
Definition in file upnp.c.
| void nat_upnp_close | ( | nat_upnp_context_t ** | ctx | ) |
Close port mapping and clean up.
Removes the port mapping from the gateway and frees resources. Safe to call with NULL.
| ctx | Context handle (will be set to NULL on return) |
Definition at line 289 of file upnp.c.
References log_debug, and SAFE_FREE.
Referenced by main().
| 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.
Useful for ACDS registration where we need to advertise the public endpoint for P2P connections.
| ctx | Context handle | |
| [out] | addr | Buffer to write "IP:port" format (must be at least 22 bytes) |
| addr_len | Size of addr buffer |
Definition at line 323 of file upnp.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_NETWORK, nat_upnp_context::external_ip, nat_upnp_context::is_mapped, nat_upnp_context::mapped_port, and SET_ERRNO.
Referenced by main(), and server_main().
| bool nat_upnp_is_active | ( | const nat_upnp_context_t * | ctx | ) |
Check if port mapping is still active.
Useful for long-running servers to verify the mapping hasn't expired.
| ctx | Context handle |
Definition at line 304 of file upnp.c.
References nat_upnp_context::external_ip, and nat_upnp_context::is_mapped.
| asciichat_error_t nat_upnp_open | ( | uint16_t | internal_port, |
| const char * | description, | ||
| nat_upnp_context_t ** | ctx | ||
| ) |
Discover and open port via UPnP.
Attempts to find an UPnP-enabled gateway and request port mapping. On success, fills in external_ip and mapped_port.
| internal_port | Local TCP port to map (e.g., 27224 for ACDS) | |
| description | Description for port mapping (e.g., "ASCII-Chat Server") | |
| [out] | ctx | Context handle (must be freed with nat_upnp_close()) |
Example:
Definition at line 249 of file upnp.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_MEMORY, ERROR_NETWORK, log_info, log_warn, SAFE_FREE, SAFE_MALLOC, and SET_ERRNO.
Referenced by main(), and server_main().
| asciichat_error_t nat_upnp_refresh | ( | nat_upnp_context_t * | ctx | ) |
Refresh port mapping (e.g., for long-running servers)
Some gateways may expire mappings. Call periodically (e.g., every hour) to ensure the mapping stays active.
| ctx | Context handle |
Definition at line 311 of file upnp.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, nat_upnp_context::is_mapped, log_debug, and SET_ERRNO.