|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🌐 Core network I/O operations with timeout support More...
Files | |
| file | protocol.h |
| ASCII-Chat IP Protocol (ACIP) packet type definitions. | |
| file | http_client.c |
| 🌐 HTTPS client with BearSSL for fetching public keys from GitHub/GitLab with CA validation | |
| file | http_client.h |
| Simple HTTPS client for fetching public keys from GitHub/GitLab. | |
| file | network.c |
| 🌐 Cross-platform socket I/O with timeout management and connection handling | |
| file | network.h |
| 🌐 Core network I/O operations with timeout support | |
| file | packet.c |
| 📦 Packet protocol handler with CRC validation, encryption, and compression | |
| file | packet.h |
| Packet protocol implementation with encryption and compression support. | |
| file | protocol.h |
| Server packet processing and protocol implementation. | |
Data Structures | |
| struct | packet_header_t |
| Network packet header structure. More... | |
| struct | size_packet_t |
| Terminal size update packet. More... | |
| struct | client_info_packet_t |
| Client information packet structure. More... | |
| struct | stream_header_t |
| Stream header packet structure. More... | |
| struct | client_list_packet_t |
| Client list packet structure. More... | |
| struct | server_state_packet_t |
| Server state packet structure. More... | |
| struct | error_packet_t |
| Error packet structure carrying error code and textual description. More... | |
| struct | remote_log_packet_t |
| Remote log packet structure carrying log level and message text. More... | |
| struct | auth_failure_packet_t |
| Authentication failure packet structure. More... | |
| struct | protocol_version_packet_t |
| Protocol version negotiation packet structure (Packet Type 1) More... | |
| struct | ascii_frame_packet_t |
| ASCII frame packet structure (Packet Type 2) More... | |
| struct | image_frame_packet_t |
| Image frame packet structure (Packet Type 3) More... | |
| struct | audio_batch_packet_t |
| Audio batch packet structure (Packet Type 28) More... | |
| struct | crypto_capabilities_packet_t |
| Crypto capabilities packet structure (Packet Type 14) More... | |
| struct | crypto_parameters_packet_t |
| Crypto parameters packet structure (Packet Type 15) More... | |
| struct | terminal_capabilities_packet_t |
| Terminal capabilities packet structure (Packet Type 5) More... | |
| struct | packet_envelope_t |
| Packet envelope containing received packet data. More... | |
Macros | |
| #define | REMOTE_LOG_FLAG_TRUNCATED 0x0001U |
| Remote log packet flag definitions. | |
Enumerations | |
| enum | packet_recv_result_t { PACKET_RECV_SUCCESS = 0 , PACKET_RECV_EOF = -1 , PACKET_RECV_ERROR = -2 , PACKET_RECV_SECURITY_VIOLATION = -3 } |
| Packet reception result codes. More... | |
Variables | |
| uint32_t | packet_header_t::magic |
| Magic number (PACKET_MAGIC) for packet validation. | |
| uint16_t | packet_header_t::type |
| Packet type (packet_type_t enumeration) | |
| uint32_t | packet_header_t::length |
| Payload data length in bytes (0 for header-only packets) | |
| uint32_t | packet_header_t::crc32 |
| CRC32 checksum of payload data (0 if length == 0) | |
| uint32_t | packet_header_t::client_id |
| Client ID (0 = server, >0 = client identifier) | |
| uint32_t | size_packet_t::width |
| Terminal width in characters. | |
| uint32_t | size_packet_t::height |
| Terminal height in characters. | |
| uint32_t | client_info_packet_t::client_id |
| Unique client identifier (1-9, 0 = server) | |
| char | client_info_packet_t::display_name [MAX_DISPLAY_NAME_LEN] |
| User display name (null-terminated, max MAX_DISPLAY_NAME_LEN bytes) | |
| uint32_t | client_info_packet_t::capabilities |
| Client capabilities bitmask (CLIENT_CAP_VIDEO | CLIENT_CAP_AUDIO | CLIENT_CAP_COLOR | CLIENT_CAP_STRETCH) | |
| uint32_t | stream_header_t::client_id |
| Client ID that this stream originates from (1-9) | |
| uint32_t | stream_header_t::stream_type |
| Stream type bitmask (STREAM_TYPE_VIDEO | STREAM_TYPE_AUDIO) | |
| uint32_t | stream_header_t::timestamp |
| Timestamp when frame/audio was captured (milliseconds since epoch) | |
| uint32_t | client_list_packet_t::client_count |
| Number of clients in the list (0 to MAX_CLIENTS) | |
| client_info_packet_t | client_list_packet_t::clients [MAX_CLIENTS] |
| Array of client information structures. | |
| uint32_t | server_state_packet_t::connected_client_count |
| Total number of currently connected clients. | |
| uint32_t | server_state_packet_t::active_client_count |
| Number of clients actively sending video/audio streams. | |
| uint32_t | server_state_packet_t::reserved [6] |
| Reserved fields for future use (must be zero) | |
| uint32_t | error_packet_t::error_code |
| Error code from asciichat_error_t enumeration. | |
| uint32_t | error_packet_t::message_length |
| Length of message payload in bytes (0-512) | |
| uint8_t | remote_log_packet_t::log_level |
| Log level associated with the message (log_level_t cast to uint8_t) | |
| uint8_t | remote_log_packet_t::direction |
| Direction hint so receivers can annotate origin. | |
| uint16_t | remote_log_packet_t::flags |
| Additional flags (REMOTE_LOG_FLAG_*) | |
| uint32_t | remote_log_packet_t::message_length |
| Message payload length in bytes (0-512) | |
| uint8_t | auth_failure_packet_t::reason_flags |
| Bitmask of auth_failure_reason_t values indicating failure causes. | |
| uint8_t | auth_failure_packet_t::reserved [7] |
| Reserved bytes for future use (must be zero) | |
| uint16_t | protocol_version_packet_t::protocol_version |
| Major protocol version (must match for compatibility) | |
| uint16_t | protocol_version_packet_t::protocol_revision |
| Minor protocol revision (server can be newer) | |
| uint8_t | protocol_version_packet_t::supports_encryption |
| Encryption support flag (1=support encryption, 0=plaintext only) | |
| uint8_t | protocol_version_packet_t::compression_algorithms |
| Supported compression algorithms bitmask (COMPRESS_ALGO_*) | |
| uint8_t | protocol_version_packet_t::compression_threshold |
| Compression threshold percentage (0-100, e.g., 80 = compress if >80% size reduction) | |
| uint16_t | protocol_version_packet_t::feature_flags |
| Feature flags bitmask (FEATURE_RLE_ENCODING, etc.) | |
| uint8_t | protocol_version_packet_t::reserved [7] |
| Reserved bytes for future expansion (must be zero) | |
| uint32_t | ascii_frame_packet_t::width |
| Terminal width in characters. | |
| uint32_t | ascii_frame_packet_t::height |
| Terminal height in characters. | |
| uint32_t | ascii_frame_packet_t::original_size |
| Size of original uncompressed ASCII data in bytes. | |
| uint32_t | ascii_frame_packet_t::compressed_size |
| Size of compressed data (0 = not compressed) | |
| uint32_t | ascii_frame_packet_t::checksum |
| CRC32 checksum of original ASCII data. | |
| uint32_t | ascii_frame_packet_t::flags |
| Frame flags bitmask (HAS_COLOR, IS_COMPRESSED, etc.) | |
| uint32_t | image_frame_packet_t::width |
| Image width in pixels. | |
| uint32_t | image_frame_packet_t::height |
| Image height in pixels. | |
| uint32_t | image_frame_packet_t::pixel_format |
| Pixel format enum (0=RGB24, 1=RGBA32, 2=BGR24, etc.) | |
| uint32_t | image_frame_packet_t::compressed_size |
| Compressed data size (0 = not compressed, >0 = compressed) | |
| uint32_t | image_frame_packet_t::checksum |
| CRC32 checksum of pixel data. | |
| uint32_t | image_frame_packet_t::timestamp |
| Timestamp when frame was captured (milliseconds since epoch) | |
| uint32_t | audio_batch_packet_t::batch_count |
| Number of audio chunks in this batch (usually AUDIO_BATCH_COUNT = 32) | |
| uint32_t | audio_batch_packet_t::total_samples |
| Total audio samples across all chunks (typically 8192) | |
| uint32_t | audio_batch_packet_t::sample_rate |
| Sample rate in Hz (e.g., 44100, 48000) | |
| uint32_t | audio_batch_packet_t::channels |
| Number of audio channels (1=mono, 2=stereo) | |
| uint16_t | crypto_capabilities_packet_t::supported_kex_algorithms |
| Supported key exchange algorithms bitmask (KEX_ALGO_*) | |
| uint16_t | crypto_capabilities_packet_t::supported_auth_algorithms |
| Supported authentication algorithms bitmask (AUTH_ALGO_*) | |
| uint16_t | crypto_capabilities_packet_t::supported_cipher_algorithms |
| Supported cipher algorithms bitmask (CIPHER_ALGO_*) | |
| uint8_t | crypto_capabilities_packet_t::requires_verification |
| Server verification requirement flag (1=required, 0=optional) | |
| uint8_t | crypto_capabilities_packet_t::preferred_kex |
| Preferred key exchange algorithm (KEX_ALGO_*) | |
| uint8_t | crypto_capabilities_packet_t::preferred_auth |
| Preferred authentication algorithm (AUTH_ALGO_*) | |
| uint8_t | crypto_capabilities_packet_t::preferred_cipher |
| Preferred cipher algorithm (CIPHER_ALGO_*) | |
| uint8_t | crypto_parameters_packet_t::selected_kex |
| Selected key exchange algorithm (KEX_ALGO_*) | |
| uint8_t | crypto_parameters_packet_t::selected_auth |
| Selected authentication algorithm (AUTH_ALGO_*) | |
| uint8_t | crypto_parameters_packet_t::selected_cipher |
| Selected cipher algorithm (CIPHER_ALGO_*) | |
| uint8_t | crypto_parameters_packet_t::verification_enabled |
| Server verification enabled flag (1=enabled, 0=disabled) | |
| uint16_t | crypto_parameters_packet_t::kex_public_key_size |
| Key exchange public key size in bytes (e.g., 32 for X25519, 1568 for Kyber1024) | |
| uint16_t | crypto_parameters_packet_t::auth_public_key_size |
| Authentication public key size in bytes (e.g., 32 for Ed25519, 1952 for Dilithium3) | |
| uint16_t | crypto_parameters_packet_t::signature_size |
| Signature size in bytes (e.g., 64 for Ed25519, 3309 for Dilithium3) | |
| uint16_t | crypto_parameters_packet_t::shared_secret_size |
| Shared secret size in bytes (e.g., 32 for X25519) | |
| uint8_t | crypto_parameters_packet_t::nonce_size |
| Nonce size in bytes (e.g., 24 for XSalsa20) | |
| uint8_t | crypto_parameters_packet_t::mac_size |
| MAC size in bytes (e.g., 16 for Poly1305) | |
| uint8_t | crypto_parameters_packet_t::hmac_size |
| HMAC size in bytes (e.g., 32 for HMAC-SHA256) | |
| uint8_t | crypto_parameters_packet_t::reserved [3] |
| Reserved bytes for future use (must be zero) | |
| uint32_t | terminal_capabilities_packet_t::capabilities |
| Terminal capabilities bitmask (TERM_CAP_* flags) | |
| uint32_t | terminal_capabilities_packet_t::color_level |
| Color level enum value (terminal_color_mode_t) | |
| uint32_t | terminal_capabilities_packet_t::color_count |
| Actual color count (16, 256, or 16777216) | |
| uint32_t | terminal_capabilities_packet_t::render_mode |
| Render mode enum value (foreground/background/half-block) | |
| uint16_t | terminal_capabilities_packet_t::width |
| Terminal width in characters. | |
| uint16_t | terminal_capabilities_packet_t::height |
| Terminal height in characters. | |
| char | terminal_capabilities_packet_t::term_type [32] |
| $TERM environment variable value (for debugging) | |
| char | terminal_capabilities_packet_t::colorterm [32] |
| $COLORTERM environment variable value (for debugging) | |
| uint8_t | terminal_capabilities_packet_t::detection_reliable |
| Detection reliability flag (1=reliable detection, 0=best guess) | |
| uint32_t | terminal_capabilities_packet_t::utf8_support |
| UTF-8 support flag (0=no UTF-8, 1=UTF-8 supported) | |
| uint32_t | terminal_capabilities_packet_t::palette_type |
| Palette type enum value (palette_type_t) | |
| char | terminal_capabilities_packet_t::palette_custom [64] |
| Custom palette characters (if palette_type == PALETTE_CUSTOM) | |
| uint8_t | terminal_capabilities_packet_t::desired_fps |
| Client's desired frame rate (1-144 FPS) | |
| uint8_t | terminal_capabilities_packet_t::reserved [2] |
| Reserved bytes for alignment (must be zero) | |
| packet_type_t | packet_envelope_t::type |
| Packet type (from packet_types.h) | |
| void * | packet_envelope_t::data |
| Packet payload data (decrypted and decompressed if applicable) | |
| size_t | packet_envelope_t::len |
| Length of payload data in bytes. | |
| bool | packet_envelope_t::was_encrypted |
| True if packet was encrypted (decrypted before envelope creation) | |
| void * | packet_envelope_t::allocated_buffer |
| Buffer that needs to be freed by caller (may be NULL if not allocated) | |
| size_t | packet_envelope_t::allocated_size |
| Size of allocated buffer in bytes. | |
HTTPS Client | |
| char * | https_get (const char *hostname, const char *path) |
| Perform HTTPS GET request. | |
Socket I/O Operations | |
| ssize_t | send_with_timeout (socket_t sockfd, const void *data, size_t len, int timeout_seconds) |
| Send data with timeout using chunked transmission. | |
| ssize_t | recv_with_timeout (socket_t sockfd, void *buf, size_t len, int timeout_seconds) |
| Receive data with timeout. | |
| int | accept_with_timeout (socket_t listenfd, struct sockaddr *addr, socklen_t *addrlen, int timeout_seconds) |
| Accept connection with timeout. | |
| bool | connect_with_timeout (socket_t sockfd, const struct sockaddr *addr, socklen_t addrlen, int timeout_seconds) |
| Connect to server with timeout. | |
Socket Configuration Functions | |
| asciichat_error_t | set_socket_timeout (socket_t sockfd, int timeout_seconds) |
| Set socket timeout for send/receive operations. | |
| asciichat_error_t | set_socket_keepalive (socket_t sockfd) |
| Enable TCP keepalive on socket. | |
| asciichat_error_t | set_socket_nonblocking (socket_t sockfd) |
| Set socket to non-blocking mode. | |
| asciichat_error_t | socket_configure_buffers (socket_t sockfd) |
| Configure socket buffers and TCP_NODELAY for optimal performance. | |
Error Reporting Functions | |
| const char * | network_error_string () |
| Get human-readable error string for network errors. | |
Packet Validation Functions | |
| asciichat_error_t | packet_validate_header (const packet_header_t *header, uint16_t *pkt_type, uint32_t *pkt_len, uint32_t *expected_crc) |
| Validate packet header and extract information. | |
| asciichat_error_t | packet_validate_crc32 (const void *data, size_t len, uint32_t expected_crc) |
| Validate packet CRC32 checksum. | |
Basic Packet I/O Functions | |
| asciichat_error_t | packet_send (socket_t sockfd, packet_type_t type, const void *data, size_t len) |
| Send a packet with header and CRC32 checksum. | |
| asciichat_error_t | packet_receive (socket_t sockfd, packet_type_t *type, void **data, size_t *len) |
| Receive a packet with header validation and CRC32 checking. | |
Secure Packet I/O Functions | |
| asciichat_error_t | send_packet_secure (socket_t sockfd, packet_type_t type, const void *data, size_t len, crypto_context_t *crypto_ctx) |
| Send a packet with encryption and compression support. | |
| packet_recv_result_t | receive_packet_secure (socket_t sockfd, void *crypto_ctx, bool enforce_encryption, packet_envelope_t *envelope) |
| Receive a packet with decryption and decompression support. | |
Legacy Packet I/O Functions | |
These functions provide basic packet I/O without encryption support. Use send_packet_secure() and receive_packet_secure() for encryption support. | |
| int | send_packet (socket_t sockfd, packet_type_t type, const void *data, size_t len) |
| Send a basic packet without encryption. | |
| int | receive_packet (socket_t sockfd, packet_type_t *type, void **data, size_t *len) |
| Receive a basic packet without encryption. | |
Protocol Packet Functions | |
Convenience functions for sending specific protocol packets. These functions construct the appropriate packet structure and send it over the socket. | |
| int | send_ping_packet (socket_t sockfd) |
| Send a ping packet (keepalive) | |
| int | send_pong_packet (socket_t sockfd) |
| Send a pong packet (keepalive response) | |
| int | send_clear_console_packet (socket_t sockfd) |
| Send a clear console packet. | |
| asciichat_error_t | packet_send_error (socket_t sockfd, const crypto_context_t *crypto_ctx, asciichat_error_t error_code, const char *message) |
| Send an error packet with optional encryption context. | |
| asciichat_error_t | packet_parse_error_message (const void *data, size_t len, asciichat_error_t *out_error_code, char *message_buffer, size_t message_buffer_size, size_t *out_message_length) |
| Parse an error packet payload into components. | |
| asciichat_error_t | packet_send_remote_log (socket_t sockfd, const crypto_context_t *crypto_ctx, log_level_t level, remote_log_direction_t direction, uint16_t flags, const char *message) |
| Send a remote log packet with optional encryption context. | |
| asciichat_error_t | packet_parse_remote_log (const void *data, size_t len, log_level_t *out_level, remote_log_direction_t *out_direction, uint16_t *out_flags, char *message_buffer, size_t message_buffer_size, size_t *out_message_length) |
| Parse a remote log packet payload into components. | |
| int | send_protocol_version_packet (socket_t sockfd, const protocol_version_packet_t *version) |
| Send protocol version negotiation packet. | |
| int | send_crypto_capabilities_packet (socket_t sockfd, const crypto_capabilities_packet_t *caps) |
| Send crypto capabilities packet. | |
| int | send_crypto_parameters_packet (socket_t sockfd, const crypto_parameters_packet_t *params) |
| Send crypto parameters packet. | |
| asciichat_error_t | send_audio_batch_packet (socket_t sockfd, const float *samples, int num_samples, int batch_count, crypto_context_t *crypto_ctx) |
| Send a batched audio packet with encryption support. | |
| asciichat_error_t | av_send_audio_opus_batch (socket_t sockfd, const uint8_t *opus_data, size_t opus_size, const uint16_t *frame_sizes, int sample_rate, int frame_duration, int frame_count, crypto_context_t *crypto_ctx) |
| Send Opus-encoded audio batch packet with encryption support. | |
| asciichat_error_t | send_ascii_frame_packet (socket_t sockfd, const char *frame_data, size_t frame_size) |
| Send ASCII frame packet. | |
| asciichat_error_t | send_image_frame_packet (socket_t sockfd, const void *image_data, uint16_t width, uint16_t height, uint8_t format) |
| Send image frame packet. | |
Network Timeout Constants | |
Timeout values tuned for real-time video streaming. All timeouts are specified in seconds. | |
| #define | CONNECT_TIMEOUT 3 |
| Connection timeout in seconds (3 seconds) | |
| #define | SEND_TIMEOUT 5 |
| Send timeout in seconds (5 seconds) | |
| #define | RECV_TIMEOUT 15 |
| Receive timeout in seconds (15 seconds) | |
| #define | ACCEPT_TIMEOUT 3 |
| Accept timeout in seconds (3 seconds) | |
Test Environment Detection | |
| #define | network_is_test_environment() ((int)is_test_environment()) |
| Check if we're in a test environment. | |
Socket Keepalive Settings | |
Keepalive settings to detect dead connections. TCP keepalive probes are sent when connection is idle to detect broken connections. | |
| #define | KEEPALIVE_IDLE 60 |
| Keepalive idle time in seconds (60 seconds) | |
| #define | KEEPALIVE_INTERVAL 10 |
| Keepalive interval in seconds (10 seconds) | |
| #define | KEEPALIVE_COUNT 8 |
| Keepalive probe count (8 probes) | |
Network Protocol Constants | |
| #define | MAX_ERROR_MESSAGE_LENGTH 512 |
| Maximum error message length (512 bytes) | |
| #define | MAX_REMOTE_LOG_MESSAGE_LENGTH 512 |
| Maximum remote log message length (512 bytes) | |
Protocol Negotiation Constants | |
| #define | FEATURE_RLE_ENCODING 0x01 |
| Feature flags for protocol_version_packet_t. | |
| #define | FEATURE_DELTA_FRAMES 0x02 |
| Delta frame encoding (future) | |
Client Capability Flags | |
Bitmask flags for client capabilities in multi-user protocol. | |
| #define | CLIENT_CAP_VIDEO 0x01 |
| Client can send/receive video. | |
| #define | CLIENT_CAP_AUDIO 0x02 |
| Client can send/receive audio. | |
| #define | CLIENT_CAP_COLOR 0x04 |
| Client supports color rendering. | |
| #define | CLIENT_CAP_STRETCH 0x08 |
| Client can stretch frames to fill terminal. | |
Stream Type Flags | |
Bitmask flags for stream types in multi-user protocol. | |
| #define | STREAM_TYPE_VIDEO 0x01 |
| Video stream. | |
| #define | STREAM_TYPE_AUDIO 0x02 |
| Audio stream. | |
Crypto Algorithm Constants | |
Algorithm identifiers for key exchange, authentication, and encryption. Used in crypto handshake packet negotiation. | |
| #define | KEX_ALGO_X25519 0x01 |
| X25519 key exchange (Curve25519) | |
| #define | AUTH_ALGO_ED25519 0x01 |
| Ed25519 authentication (Edwards-curve signatures) | |
| #define | AUTH_ALGO_NONE 0x00 |
| No authentication (plaintext mode) | |
| #define | CIPHER_ALGO_XSALSA20_POLY1305 0x01 |
| XSalsa20-Poly1305 authenticated encryption. | |
🌐 Core network I/O operations with timeout support
This module provides basic HTTPS GET functionality using BearSSL for TLS. It's designed specifically for fetching SSH/GPG public keys from GitHub and GitLab.
https://github.com/username.keyshttps://github.com/username.gpghttps://gitlab.com/username.keyshttps://gitlab.com/username.gpgThis module provides fundamental network I/O operations including socket management, timeout handling, and basic send/receive operations. All operations support configurable timeouts to prevent indefinite blocking, critical for real-time video streaming applications.
TIMEOUT SYSTEM:
SOCKET CONFIGURATION:
ERROR HANDLING:
This module provides comprehensive packet protocol implementation including packet verification, CRC validation, protocol compliance checking, encryption support, and compression integration. It serves as the core network protocol layer for ascii-chat's communication system.
PACKET STRUCTURE:
ENCRYPTION INTEGRATION:
COMPRESSION INTEGRATION:
PROTOCOL VALIDATION:
Welcome to the Network I/O module! This is where all the network communication happens—everything from basic socket operations to packet transmission. The network module is designed for real-time video streaming, which means it's optimized for low latency, reliability, and handling large data transfers smoothly.
The Network I/O module provides fundamental network operations that everything else builds on. Think of it as the foundation for all network communication. Here's what it handles:
All operations support configurable timeouts, which is critical for real-time video streaming—we can't afford to wait forever when something goes wrong. The timeout system ensures that operations fail fast rather than hanging indefinitely.
Implementation: lib/network/network.h, lib/network/packet.h
The network module is built around a few key concepts: timeouts to prevent hanging, socket configuration to keep connections healthy, and a packet protocol that handles the complexity of reliable data transmission. Let's walk through how everything fits together.
All I/O operations support configurable timeouts—this is probably the most important feature for real-time video streaming. Without timeouts, operations can hang forever when the network is flaky, which would freeze your video stream.
CONNECT_TIMEOUT)—when you're trying to connect to a server, we'll give up after 3 seconds rather than waiting foreverSEND_TIMEOUT)—when sending data, we'll give up after 5 seconds if it's not going throughRECV_TIMEOUT)—when receiving data, we'll wait up to 15 seconds (this is longer because network delays are more common on receive)ACCEPT_TIMEOUT)—when waiting for incoming connections, we'll check every 3 seconds rather than blocking foreverThese timeouts are tuned specifically for real-time video streaming. They're short enough that you notice problems quickly, but long enough that normal network hiccups don't cause false positives. Chunked transmission prevents large data from blocking indefinitely—even if a single chunk times out, we can still make progress on the rest.
Socket configuration is about keeping your connections healthy and efficient. We configure sockets with several important settings:
KEEPALIVE_IDLE, KEEPALIVE_INTERVAL, and KEEPALIVE_COUNT to tune this.SO_SNDTIMEO and SO_RCVTIMEO at the socket level, so even if the application doesn't explicitly check timeouts, the socket itself will time outThe packet protocol sits on top of the basic socket I/O and adds structure, validation, encryption, and compression. It's how we reliably transmit data even when the network is unreliable.
The packet protocol provides:
Packet Structure:
This structure makes it easy to detect problems early—if the magic number is wrong or the CRC32 doesn't match, we know the packet is corrupted before we waste time trying to decrypt it.
Send/Receive Operations:
Connection Operations:
Basic Packet I/O:
Secure Packet I/O:
Socket Setup:
The Network I/O module integrates with:
Chunked Transmission:
Timeout Handling:
Keepalive Settings:
Error Reporting:
Error Codes:
Timeout configuration is all about balance—too short and you get false positives on slow networks, too long and you delay error detection unnecessarily. We've tuned these values specifically for real-time video streaming.
Timeout values that are too short may cause false positives on slow networks—you might think the connection is dead when it's just slow. Values that are too long may delay error detection unnecessarily—you might wait too long before realizing something is wrong.
If you're running on a very slow network (like satellite internet), you might want to increase these timeouts. If you're running on a very fast network (like a local LAN), you could decrease them for faster error detection.
Large data transfers are automatically chunked—this is how we send big video frames without blocking the connection. Instead of sending everything at once (which could cause timeouts or block other operations), we break large data into smaller chunks.
send() doesn't send everything you ask it to—chunking handles this gracefully by retrying until the chunk is sentThis is used automatically for large data—you don't need to do anything special. The system detects when data is large enough to benefit from chunking and handles it automatically.
The packet protocol supports:
Handshake Packets:
packet_is_handshake_type() to check before encryption| #define ACCEPT_TIMEOUT 3 |
| #define AUTH_ALGO_ED25519 0x01 |
| #define AUTH_ALGO_NONE 0x00 |
| #define CIPHER_ALGO_XSALSA20_POLY1305 0x01 |
| #define CLIENT_CAP_AUDIO 0x02 |
| #define CLIENT_CAP_COLOR 0x04 |
| #define CLIENT_CAP_STRETCH 0x08 |
| #define CLIENT_CAP_VIDEO 0x01 |
| #define CONNECT_TIMEOUT 3 |
| #define FEATURE_DELTA_FRAMES 0x02 |
| #define FEATURE_RLE_ENCODING 0x01 |
#include <packet.h>
Feature flags for protocol_version_packet_t.
Bitmask values for optional protocol features. Used in protocol negotiation to enable advanced capabilities.
Run-length encoding support
| #define KEEPALIVE_COUNT 8 |
| #define KEEPALIVE_IDLE 60 |
| #define KEEPALIVE_INTERVAL 10 |
| #define KEX_ALGO_X25519 0x01 |
| #define MAX_ERROR_MESSAGE_LENGTH 512 |
| #define MAX_REMOTE_LOG_MESSAGE_LENGTH 512 |
#include <packet.h>
Maximum remote log message length (512 bytes)
Remote logging packets mirror the error packet structure but are intended for diagnostic log forwarding between client and server. Limiting the payload size keeps allocations predictable and prevents log flooding over the network.
| #define network_is_test_environment | ( | ) | ((int)is_test_environment()) |
#include <network.h>
Check if we're in a test environment.
Compatibility macro that calls is_test_environment() from tests/test_env.h. Used to adjust timeouts for faster test execution.
| #define RECV_TIMEOUT 15 |
| #define REMOTE_LOG_FLAG_TRUNCATED 0x0001U |
| #define SEND_TIMEOUT 5 |
| #define STREAM_TYPE_AUDIO 0x02 |
| #define STREAM_TYPE_VIDEO 0x01 |
| enum packet_recv_result_t |
#include <packet.h>
Packet reception result codes.
Result codes for packet reception operations. Negative values indicate errors, zero indicates success.
Definition at line 1003 of file packet.h.
| int accept_with_timeout | ( | socket_t | listenfd, |
| struct sockaddr * | addr, | ||
| socklen_t * | addrlen, | ||
| int | timeout_seconds | ||
| ) |
#include <network.h>
Accept connection with timeout.
| listenfd | Listening socket file descriptor |
| addr | Output: Client address structure (can be NULL) |
| addrlen | Input/output: Length of address structure |
| timeout_seconds | Timeout in seconds |
Accepts incoming connection with timeout support. Waits up to timeout_seconds for incoming connection.
| listenfd | Listening socket |
| addr | Client address structure |
| addrlen | Length of address structure |
| timeout_seconds | Timeout in seconds |
Definition at line 346 of file network.c.
References asciichat_errno, asciichat_errno_context, asciichat_set_errno_with_wsa_error(), asciichat_error_context_t::code, EBADF, ENOTSOCK, errno, error_code, ERROR_NETWORK, ERROR_NETWORK_BIND, ERROR_NETWORK_TIMEOUT, ETIMEDOUT, asciichat_error_context_t::has_system_error, INVALID_SOCKET_VALUE, SET_ERRNO, SET_ERRNO_SYS, socket_accept(), socket_fd_isset(), socket_fd_set(), socket_fd_zero(), socket_select(), and asciichat_error_context_t::system_errno.
| asciichat_error_t av_send_audio_opus_batch | ( | socket_t | sockfd, |
| const uint8_t * | opus_data, | ||
| size_t | opus_size, | ||
| const uint16_t * | frame_sizes, | ||
| int | sample_rate, | ||
| int | frame_duration, | ||
| int | frame_count, | ||
| crypto_context_t * | crypto_ctx | ||
| ) |
#include <packet.h>
Send Opus-encoded audio batch packet with encryption support.
| sockfd | Socket file descriptor |
| opus_data | Opus-encoded audio data buffer |
| opus_size | Size of Opus-encoded data in bytes |
| frame_sizes | Array of frame sizes (one per Opus frame) |
| sample_rate | Sample rate in Hz (e.g., 48000) |
| frame_duration | Frame duration in milliseconds (e.g., 20) |
| frame_count | Number of Opus frames in batch |
| crypto_ctx | Cryptographic context for encryption (NULL for plaintext) |
Sends PACKET_TYPE_AUDIO_OPUS_BATCH with multiple Opus-encoded frames. Opus provides better compression than raw audio (30-100 bytes per 20ms frame).
Definition at line 1136 of file packet.c.
References buffer_pool_alloc(), buffer_pool_free(), ERROR_INVALID_PARAM, ERROR_MEMORY, HOST_TO_NET_U16, HOST_TO_NET_U32, PACKET_TYPE_AUDIO_OPUS_BATCH, send_packet_secure(), and SET_ERRNO.
Referenced by client_send_thread_func(), and tcp_client_send_audio_opus_batch().
| bool connect_with_timeout | ( | socket_t | sockfd, |
| const struct sockaddr * | addr, | ||
| socklen_t | addrlen, | ||
| int | timeout_seconds | ||
| ) |
#include <network.h>
Connect to server with timeout.
| sockfd | Socket file descriptor |
| addr | Server address structure |
| addrlen | Address structure length |
| timeout_seconds | Timeout in seconds |
Establishes connection to server with timeout support. Waits up to timeout_seconds for connection to complete.
Connect to server with timeout.
| sockfd | Socket file descriptor |
| addr | Address to connect to |
| addrlen | Address length |
| timeout_seconds | Timeout in seconds |
Definition at line 547 of file network.c.
References ASCIICHAT_OK, EBADF, errno, error_code, EWOULDBLOCK, INVALID_SOCKET_VALUE, log_warn, set_socket_nonblocking(), socket_fd_isset(), socket_fd_set(), socket_fd_zero(), socket_getsockopt(), socket_select(), and socket_set_blocking().
Referenced by server_connection_establish(), and tcp_client_connect().
| char * https_get | ( | const char * | hostname, |
| const char * | path | ||
| ) |
#include <http_client.h>
Perform HTTPS GET request.
| hostname | Server hostname (e.g., "github.com", must not be NULL) |
| path | Resource path (e.g., "/username.keys", must not be NULL) |
Makes a secure HTTPS connection to the specified hostname and fetches the resource at the given path. Uses system CA certificates for validation.
Definition at line 109 of file http_client.c.
References ANCHOR_LIST_INIT, ASCIICHAT_OK, anchor_list::buf, BUFFER_SIZE_LARGE, free_ta_contents(), INVALID_SOCKET_VALUE, log_error, log_info, platform_load_system_ca_certs(), anchor_list::ptr, read_trust_anchors_from_memory(), SAFE_FREE, SAFE_MALLOC, SAFE_REALLOC, safe_snprintf(), and socket_close().
| const char * network_error_string | ( | ) |
#include <network.h>
Get human-readable error string for network errors.
Returns a human-readable description of the last network error. Useful for error logging and user-facing error messages.
| error_code | Error code |
Definition at line 535 of file network.c.
References socket_get_error_string().
Referenced by server_connection_establish(), socket_configure_buffers(), and tcp_client_connect().
| asciichat_error_t packet_parse_error_message | ( | const void * | data, |
| size_t | len, | ||
| asciichat_error_t * | out_error_code, | ||
| char * | message_buffer, | ||
| size_t | message_buffer_size, | ||
| size_t * | out_message_length | ||
| ) |
#include <packet.h>
Parse an error packet payload into components.
| data | Packet payload buffer |
| len | Payload length in bytes |
| out_error_code | Output pointer for asciichat_error_t value (must not be NULL) |
| message_buffer | Destination buffer for message string (must not be NULL) |
| message_buffer_size | Size of destination buffer in bytes (must be > 0) |
| out_message_length | Optional output for message length reported by sender |
Definition at line 854 of file packet.c.
References ASCIICHAT_OK, error_packet_t::error_code, ERROR_INVALID_PARAM, ERROR_NETWORK_PROTOCOL, MAX_ERROR_MESSAGE_LENGTH, error_packet_t::message_length, NET_TO_HOST_U32, and SET_ERRNO.
| asciichat_error_t packet_parse_remote_log | ( | const void * | data, |
| size_t | len, | ||
| log_level_t * | out_level, | ||
| remote_log_direction_t * | out_direction, | ||
| uint16_t * | out_flags, | ||
| char * | message_buffer, | ||
| size_t | message_buffer_size, | ||
| size_t * | out_message_length | ||
| ) |
#include <packet.h>
Parse a remote log packet payload into components.
| data | Packet payload buffer |
| len | Payload length in bytes |
| out_level | Output pointer for log level (must not be NULL) |
| out_direction | Output pointer for direction (must not be NULL) |
| out_flags | Output pointer for flags (must not be NULL) |
| message_buffer | Destination buffer for message string (must not be NULL) |
| message_buffer_size | Size of destination buffer in bytes (must be > 0) |
| out_message_length | Optional output for message length reported by sender |
Definition at line 953 of file packet.c.
References ASCIICHAT_OK, remote_log_packet_t::direction, ERROR_INVALID_PARAM, ERROR_NETWORK_PROTOCOL, remote_log_packet_t::flags, LOG_FATAL, remote_log_packet_t::log_level, MAX_REMOTE_LOG_MESSAGE_LENGTH, remote_log_packet_t::message_length, NET_TO_HOST_U16, NET_TO_HOST_U32, REMOTE_LOG_DIRECTION_CLIENT_TO_SERVER, REMOTE_LOG_DIRECTION_UNKNOWN, and SET_ERRNO.
Referenced by handle_remote_log_packet_from_client().
| asciichat_error_t packet_receive | ( | socket_t | sockfd, |
| packet_type_t * | type, | ||
| void ** | data, | ||
| size_t * | len | ||
| ) |
#include <packet.h>
Receive a packet with header validation and CRC32 checking.
| sockfd | Socket file descriptor |
| type | Output: Packet type |
| data | Output: Packet payload data (allocated by function, freed by caller) |
| len | Output: Payload data length in bytes |
Receives a complete packet, validates header, and verifies CRC32 checksum. Allocates buffer for payload data which must be freed by caller.
Receive a packet with header validation and CRC32 checking.
| sockfd | Socket file descriptor |
| type | Output: packet type |
| data | Output: packet data (allocated by caller, freed by caller) |
| len | Output: data length |
Definition at line 351 of file packet.c.
References ASCIICHAT_OK, buffer_pool_alloc(), buffer_pool_free(), ERROR_INVALID_PARAM, ERROR_NETWORK, ERROR_NETWORK_PROTOCOL, INVALID_SOCKET_VALUE, log_warn, network_is_test_environment, packet_validate_crc32(), packet_validate_header(), RECV_TIMEOUT, recv_with_timeout(), SET_ERRNO, and SET_ERRNO_SYS.
Referenced by receive_packet().
| asciichat_error_t packet_send | ( | socket_t | sockfd, |
| packet_type_t | type, | ||
| const void * | data, | ||
| size_t | len | ||
| ) |
#include <packet.h>
Send a packet with header and CRC32 checksum.
| sockfd | Socket file descriptor |
| type | Packet type (from packet_types.h) |
| data | Packet payload data (can be NULL for header-only packets) |
| len | Payload data length in bytes |
Sends a complete packet with header (magic, type, length, CRC32) and optional payload. CRC32 is computed automatically and included in header.
Send a packet with header and CRC32 checksum.
| sockfd | Socket file descriptor |
| type | Packet type |
| data | Packet data |
| len | Data length |
Definition at line 291 of file packet.c.
References asciichat_crc32, errno, ERROR_INVALID_PARAM, ERROR_NETWORK, ERROR_NETWORK_SIZE, HOST_TO_NET_U16, HOST_TO_NET_U32, INVALID_SOCKET_VALUE, log_debug, packet_header_t::magic, MAX_PACKET_SIZE, PACKET_MAGIC, SAFE_STRERROR, send_with_timeout(), SET_ERRNO, and socket_is_valid().
Referenced by packet_send_error(), packet_send_remote_log(), send_ascii_frame_packet(), send_image_frame_packet(), send_packet(), send_packet_secure(), and tcp_client_send_audio_opus().
| asciichat_error_t packet_send_error | ( | socket_t | sockfd, |
| const crypto_context_t * | crypto_ctx, | ||
| asciichat_error_t | error_code, | ||
| const char * | message | ||
| ) |
#include <packet.h>
Send an error packet with optional encryption context.
| sockfd | Socket file descriptor |
| crypto_ctx | Crypto context for encryption (NULL or not ready sends plaintext) |
| error_code | Error code from asciichat_error_t enumeration |
| message | Human-readable message to accompany the error (can be NULL) |
When the crypto context is ready, the packet is encrypted automatically. During the handshake (or when encryption is disabled), the packet is sent in plaintext so protocol errors can be delivered before encryption is active.
Definition at line 807 of file packet.c.
References ASCIICHAT_OK, crypto_is_ready(), error_code, error_packet_t::error_code, ERROR_INVALID_PARAM, ERROR_MEMORY, ERROR_NETWORK, HOST_TO_NET_U32, INVALID_SOCKET_VALUE, log_warn, MAX_ERROR_MESSAGE_LENGTH, error_packet_t::message_length, packet_send(), PACKET_TYPE_ERROR_MESSAGE, SAFE_FREE, SAFE_MALLOC, send_packet_secure(), and SET_ERRNO.
Referenced by disconnect_client_for_bad_data().
| asciichat_error_t packet_send_remote_log | ( | socket_t | sockfd, |
| const crypto_context_t * | crypto_ctx, | ||
| log_level_t | level, | ||
| remote_log_direction_t | direction, | ||
| uint16_t | flags, | ||
| const char * | message | ||
| ) |
#include <packet.h>
Send a remote log packet with optional encryption context.
| sockfd | Socket file descriptor |
| crypto_ctx | Crypto context for encryption (NULL or not ready sends plaintext) |
| level | Log level to transmit |
| direction | Direction flag (REMOTE_LOG_DIRECTION_*) |
| flags | Additional flags (REMOTE_LOG_FLAG_*) |
| message | Log message text |
<Message payload was truncated to fit the maximum length
Definition at line 896 of file packet.c.
References ASCIICHAT_OK, crypto_is_ready(), remote_log_packet_t::direction, ERROR_INVALID_PARAM, ERROR_MEMORY, ERROR_NETWORK, remote_log_packet_t::flags, HOST_TO_NET_U16, HOST_TO_NET_U32, INVALID_SOCKET_VALUE, LOG_FATAL, remote_log_packet_t::log_level, MAX_REMOTE_LOG_MESSAGE_LENGTH, remote_log_packet_t::message_length, packet_send(), PACKET_TYPE_REMOTE_LOG, REMOTE_LOG_FLAG_TRUNCATED, SAFE_FREE, SAFE_MALLOC, send_packet_secure(), and SET_ERRNO.
| asciichat_error_t packet_validate_crc32 | ( | const void * | data, |
| size_t | len, | ||
| uint32_t | expected_crc | ||
| ) |
#include <packet.h>
Validate packet CRC32 checksum.
| data | Packet payload data |
| len | Data length in bytes |
| expected_crc | Expected CRC32 checksum value |
Validates packet integrity by computing CRC32 checksum of payload and comparing with expected value. Uses hardware acceleration when available for optimal performance.
Validate packet CRC32 checksum.
| data | Packet data |
| len | Data length |
| expected_crc | Expected CRC32 value |
Definition at line 261 of file packet.c.
References asciichat_crc32, ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_NETWORK_PROTOCOL, and SET_ERRNO.
Referenced by packet_receive().
| asciichat_error_t packet_validate_header | ( | const packet_header_t * | header, |
| uint16_t * | pkt_type, | ||
| uint32_t * | pkt_len, | ||
| uint32_t * | expected_crc | ||
| ) |
#include <packet.h>
Validate packet header and extract information.
| header | Packet header to validate |
| pkt_type | Output: Packet type |
| pkt_len | Output: Packet payload length |
| expected_crc | Output: Expected CRC32 checksum |
Validates packet header structure including magic number, type, and length fields. Extracts packet information for further processing.
Validate packet header and extract information.
| header | Packet header to validate |
| pkt_type | Output: packet type |
| pkt_len | Output: packet length |
| expected_crc | Output: expected CRC32 |
Definition at line 75 of file packet.c.
References ASCIICHAT_OK, AUDIO_SAMPLES_PER_PACKET, packet_header_t::crc32, ERROR_INVALID_PARAM, ERROR_NETWORK_PROTOCOL, ERROR_NETWORK_SIZE, packet_header_t::length, packet_header_t::magic, MAX_ERROR_MESSAGE_LENGTH, MAX_PACKET_SIZE, PACKET_MAGIC, PACKET_TYPE_ACIP_DISCOVERY_PING, PACKET_TYPE_ACIP_ERROR, PACKET_TYPE_ACIP_SESSION_CREATE, PACKET_TYPE_ACIP_SESSION_CREATED, PACKET_TYPE_ACIP_SESSION_END, PACKET_TYPE_ACIP_SESSION_INFO, PACKET_TYPE_ACIP_SESSION_JOIN, PACKET_TYPE_ACIP_SESSION_JOINED, PACKET_TYPE_ACIP_SESSION_LEAVE, PACKET_TYPE_ACIP_SESSION_LOOKUP, PACKET_TYPE_ACIP_SESSION_RECONNECT, PACKET_TYPE_ACIP_STRING_RELEASE, PACKET_TYPE_ACIP_STRING_RENEW, PACKET_TYPE_ACIP_STRING_RESERVE, PACKET_TYPE_ACIP_STRING_RESERVED, PACKET_TYPE_ACIP_WEBRTC_ICE, PACKET_TYPE_ACIP_WEBRTC_SDP, PACKET_TYPE_ASCII_FRAME, PACKET_TYPE_AUDIO, PACKET_TYPE_AUDIO_BATCH, PACKET_TYPE_AUDIO_MESSAGE, PACKET_TYPE_CLIENT_CAPABILITIES, PACKET_TYPE_CLIENT_JOIN, PACKET_TYPE_CLIENT_LEAVE, PACKET_TYPE_CRYPTO_AUTH_CHALLENGE, PACKET_TYPE_CRYPTO_AUTH_FAILED, PACKET_TYPE_CRYPTO_AUTH_RESPONSE, PACKET_TYPE_CRYPTO_CAPABILITIES, PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE, PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT, PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP, PACKET_TYPE_CRYPTO_NO_ENCRYPTION, PACKET_TYPE_CRYPTO_PARAMETERS, PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP, PACKET_TYPE_ENCRYPTED, PACKET_TYPE_ERROR_MESSAGE, PACKET_TYPE_IMAGE_FRAME, PACKET_TYPE_PING, PACKET_TYPE_PONG, PACKET_TYPE_PROTOCOL_VERSION, PACKET_TYPE_SIZE_MESSAGE, PACKET_TYPE_STREAM_START, PACKET_TYPE_STREAM_STOP, PACKET_TYPE_TEXT_MESSAGE, SET_ERRNO, and packet_header_t::type.
Referenced by packet_receive().
| int receive_packet | ( | socket_t | sockfd, |
| packet_type_t * | type, | ||
| void ** | data, | ||
| size_t * | len | ||
| ) |
#include <packet.h>
Receive a basic packet without encryption.
| sockfd | Socket file descriptor |
| type | Output: Packet type |
| data | Output: Packet payload data (allocated by function) |
| len | Output: Payload data length in bytes |
Receives a plaintext packet without decryption. Allocates buffer for payload data which must be freed by caller.
| sockfd | Socket file descriptor |
| type | Output: packet type |
| data | Output: packet data |
| len | Output: data length |
Definition at line 767 of file packet.c.
References ASCIICHAT_OK, and packet_receive().
Referenced by acds_client_handler(), acds_session_create(), acds_session_join(), acds_session_lookup(), client_crypto_handshake(), crypto_handshake_client_auth_response(), crypto_handshake_client_complete(), crypto_handshake_client_key_exchange(), crypto_handshake_server_auth_challenge(), crypto_handshake_server_complete(), and server_crypto_handshake().
| packet_recv_result_t receive_packet_secure | ( | socket_t | sockfd, |
| void * | crypto_ctx, | ||
| bool | enforce_encryption, | ||
| packet_envelope_t * | envelope | ||
| ) |
#include <packet.h>
Receive a packet with decryption and decompression support.
| sockfd | Socket file descriptor |
| crypto_ctx | Cryptographic context for decryption (NULL for plaintext) |
| enforce_encryption | If true, reject unencrypted packets (except handshake) |
| envelope | Output: Received packet envelope with all metadata |
Receives a packet with automatic decryption (if encrypted) and decompression (if compressed). Validates encryption policy and packet integrity.
| sockfd | Socket file descriptor |
| crypto_ctx | Crypto context for decryption |
| enforce_encryption | Whether to require encryption |
| envelope | Output: received packet envelope |
Definition at line 568 of file packet.c.
References packet_envelope_t::allocated_buffer, packet_envelope_t::allocated_size, asciichat_crc32, buffer_pool_alloc(), buffer_pool_free(), packet_header_t::crc32, crypto_decrypt(), CRYPTO_OK, crypto_result_to_string(), packet_envelope_t::data, ERROR_CRYPTO, ERROR_INVALID_PARAM, ERROR_MEMORY, ERROR_NETWORK, ERROR_NETWORK_PROTOCOL, ERROR_NETWORK_SIZE, packet_envelope_t::len, packet_header_t::length, packet_header_t::magic, MAX_PACKET_SIZE, NET_TO_HOST_U16, NET_TO_HOST_U32, network_is_test_environment, PACKET_MAGIC, PACKET_RECV_EOF, PACKET_RECV_ERROR, PACKET_RECV_SUCCESS, PACKET_TYPE_ENCRYPTED, RECV_TIMEOUT, recv_with_timeout(), SET_ERRNO, packet_header_t::type, and packet_envelope_t::type.
Referenced by acip_client_receive_and_dispatch(), and acip_server_receive_and_dispatch().
| ssize_t recv_with_timeout | ( | socket_t | sockfd, |
| void * | buf, | ||
| size_t | len, | ||
| int | timeout_seconds | ||
| ) |
#include <network.h>
Receive data with timeout.
| sockfd | Socket file descriptor |
| buf | Buffer to receive data |
| len | Length of buffer in bytes |
| timeout_seconds | Timeout in seconds |
Receives data from socket with timeout support. Waits up to timeout_seconds for data to arrive.
| sockfd | Socket file descriptor |
| buf | Buffer to receive data |
| len | Length of buffer |
| timeout_seconds | Timeout in seconds |
Definition at line 272 of file network.c.
References EBADF, errno, ERROR_NETWORK_TIMEOUT, INVALID_SOCKET_VALUE, log_debug, log_error, network_is_test_environment, SET_ERRNO_SYS, socket_fd_isset(), socket_fd_set(), socket_fd_zero(), and socket_select().
Referenced by packet_receive(), and receive_packet_secure().
| asciichat_error_t send_ascii_frame_packet | ( | socket_t | sockfd, |
| const char * | frame_data, | ||
| size_t | frame_size | ||
| ) |
#include <packet.h>
Send ASCII frame packet.
| sockfd | Socket file descriptor |
| frame_data | ASCII frame data buffer |
| frame_size | Size of frame data in bytes |
Sends PACKET_TYPE_ASCII_FRAME with ASCII text data. Used for transmitting terminal output or text-based frames.
Definition at line 1191 of file packet.c.
References ASCIICHAT_OK, buffer_pool_alloc(), buffer_pool_free(), ascii_frame_packet_t::checksum, ascii_frame_packet_t::compressed_size, ERROR_INVALID_PARAM, ERROR_MEMORY, ascii_frame_packet_t::flags, ascii_frame_packet_t::height, ascii_frame_packet_t::original_size, packet_send(), PACKET_TYPE_ASCII_FRAME, SET_ERRNO, and ascii_frame_packet_t::width.
| asciichat_error_t send_audio_batch_packet | ( | socket_t | sockfd, |
| const float * | samples, | ||
| int | num_samples, | ||
| int | batch_count, | ||
| crypto_context_t * | crypto_ctx | ||
| ) |
#include <packet.h>
Send a batched audio packet with encryption support.
| sockfd | Socket file descriptor |
| samples | Float audio samples buffer |
| num_samples | Total number of audio samples |
| batch_count | Number of chunks in batch |
| crypto_ctx | Cryptographic context for encryption (NULL for plaintext) |
Sends PACKET_TYPE_AUDIO_BATCH with multiple audio chunks batched together. Reduces packet overhead by sending 32 chunks (~186ms) per packet. Uses system-defined AUDIO_SAMPLE_RATE and mono audio.
Definition at line 1072 of file packet.c.
References AUDIO_SAMPLE_RATE, audio_batch_packet_t::batch_count, buffer_pool_alloc(), buffer_pool_free(), audio_batch_packet_t::channels, ERROR_INVALID_PARAM, ERROR_MEMORY, HOST_TO_NET_U32, log_info, PACKET_TYPE_AUDIO_BATCH, audio_batch_packet_t::sample_rate, send_packet_secure(), SET_ERRNO, and audio_batch_packet_t::total_samples.
Referenced by client_send_thread_func(), tcp_client_send_audio_batch(), and threaded_send_audio_batch_packet().
| int send_clear_console_packet | ( | socket_t | sockfd | ) |
#include <packet.h>
Send a clear console packet.
| sockfd | Socket file descriptor |
Sends a PACKET_TYPE_CLEAR_CONSOLE packet to request client to clear terminal display.
| sockfd | Socket file descriptor |
Definition at line 803 of file packet.c.
References PACKET_TYPE_CLEAR_CONSOLE, and send_packet().
| int send_crypto_capabilities_packet | ( | socket_t | sockfd, |
| const crypto_capabilities_packet_t * | caps | ||
| ) |
#include <packet.h>
Send crypto capabilities packet.
| sockfd | Socket file descriptor |
| caps | Crypto capabilities packet structure |
Sends a PACKET_TYPE_CRYPTO_CAPABILITIES packet to advertise supported cryptographic algorithms (key exchange, authentication, cipher).
| sockfd | Socket file descriptor |
| caps | Crypto capabilities packet |
Definition at line 1030 of file packet.c.
References ERROR_INVALID_PARAM, PACKET_TYPE_CRYPTO_CAPABILITIES, send_packet(), and SET_ERRNO.
Referenced by client_crypto_handshake().
| int send_crypto_parameters_packet | ( | socket_t | sockfd, |
| const crypto_parameters_packet_t * | params | ||
| ) |
#include <packet.h>
Send crypto parameters packet.
| sockfd | Socket file descriptor |
| params | Crypto parameters packet structure |
Sends a PACKET_TYPE_CRYPTO_PARAMETERS packet containing chosen cryptographic algorithms and data sizes for handshake continuation.
| sockfd | Socket file descriptor |
| params | Crypto parameters packet |
Definition at line 1044 of file packet.c.
References crypto_parameters_packet_t::auth_public_key_size, ERROR_INVALID_PARAM, HOST_TO_NET_U16, crypto_parameters_packet_t::kex_public_key_size, log_debug, PACKET_TYPE_CRYPTO_PARAMETERS, send_packet(), SET_ERRNO, crypto_parameters_packet_t::shared_secret_size, and crypto_parameters_packet_t::signature_size.
Referenced by server_crypto_handshake().
| asciichat_error_t send_image_frame_packet | ( | socket_t | sockfd, |
| const void * | image_data, | ||
| uint16_t | width, | ||
| uint16_t | height, | ||
| uint8_t | format | ||
| ) |
#include <packet.h>
Send image frame packet.
| sockfd | Socket file descriptor |
| image_data | Image pixel data buffer |
| width | Image width in pixels |
| height | Image height in pixels |
| format | Pixel format (0=RGB24) |
Sends PACKET_TYPE_IMAGE_FRAME with RGB image data. Used for transmitting camera frames or video input.
Definition at line 1230 of file packet.c.
References ASCIICHAT_OK, buffer_pool_alloc(), buffer_pool_free(), image_frame_packet_t::checksum, image_frame_packet_t::compressed_size, ERROR_BUFFER_OVERFLOW, ERROR_INVALID_PARAM, ERROR_MEMORY, image_frame_packet_t::height, packet_send(), PACKET_TYPE_IMAGE_FRAME, image_frame_packet_t::pixel_format, SET_ERRNO, image_frame_packet_t::timestamp, and image_frame_packet_t::width.
| int send_packet | ( | socket_t | sockfd, |
| packet_type_t | type, | ||
| const void * | data, | ||
| size_t | len | ||
| ) |
#include <packet.h>
Send a basic packet without encryption.
| sockfd | Socket file descriptor |
| type | Packet type (from packet_types.h) |
| data | Packet payload data |
| len | Payload data length in bytes |
Sends a plaintext packet without encryption. Equivalent to packet_send() but returns int instead of asciichat_error_t for compatibility.
| sockfd | Socket file descriptor |
| type | Packet type |
| data | Packet data |
| len | Data length |
Definition at line 754 of file packet.c.
References ASCIICHAT_OK, and packet_send().
Referenced by acds_session_create(), acds_session_join(), acds_session_lookup(), acip_server_send_error(), crypto_handshake_client_key_exchange(), crypto_handshake_rekey_complete(), crypto_handshake_rekey_request(), crypto_handshake_rekey_response(), crypto_handshake_server_auth_challenge(), crypto_handshake_server_complete(), crypto_handshake_server_start(), send_clear_console_packet(), send_crypto_capabilities_packet(), send_crypto_parameters_packet(), send_error_packet_message(), send_ping_packet(), send_pong_packet(), send_protocol_version_packet(), signaling_relay_ice(), and signaling_relay_sdp().
| asciichat_error_t send_packet_secure | ( | socket_t | sockfd, |
| packet_type_t | type, | ||
| const void * | data, | ||
| size_t | len, | ||
| crypto_context_t * | crypto_ctx | ||
| ) |
#include <packet.h>
Send a packet with encryption and compression support.
| sockfd | Socket file descriptor |
| type | Packet type (from packet_types.h) |
| data | Packet payload data |
| len | Payload data length in bytes |
| crypto_ctx | Cryptographic context for encryption (NULL for plaintext) |
Sends a packet with automatic encryption (if crypto context provided) and compression (if packet is large enough). Handshake packets are never encrypted.
| sockfd | Socket file descriptor |
| type | Packet type |
| data | Packet data |
| len | Data length |
| crypto_ctx | Crypto context for encryption |
Definition at line 433 of file packet.c.
References asciichat_crc32, ASCIICHAT_OK, buffer_pool_alloc(), buffer_pool_free(), compress_data(), COMPRESSION_MIN_SIZE, COMPRESSION_RATIO_THRESHOLD, crypto_encrypt(), crypto_is_ready(), CRYPTO_MAC_SIZE, CRYPTO_NONCE_SIZE, CRYPTO_OK, crypto_result_to_string(), ERROR_CRYPTO, ERROR_MEMORY, ERROR_NETWORK, ERROR_NETWORK_SIZE, GET_OPTION, HOST_TO_NET_U16, HOST_TO_NET_U32, log_debug, log_debug_every, LOG_RATE_FAST, LOG_RATE_SLOW, log_warn_every, packet_header_t::magic, MAX_PACKET_SIZE, PACKET_MAGIC, packet_send(), PACKET_TYPE_ENCRYPTED, SAFE_FREE, SET_ERRNO, and should_compress().
Referenced by av_send_audio_opus_batch(), packet_send_error(), packet_send_remote_log(), send_audio_batch_packet(), tcp_client_send_audio_opus(), and tcp_client_send_packet().
| int send_ping_packet | ( | socket_t | sockfd | ) |
#include <packet.h>
Send a ping packet (keepalive)
| sockfd | Socket file descriptor |
Sends a PACKET_TYPE_PING packet to keep connection alive. Server/client responds with PACKET_TYPE_PONG.
Send a ping packet (keepalive)
| sockfd | Socket file descriptor |
Definition at line 783 of file packet.c.
References ASCIICHAT_OK, PACKET_TYPE_PING, and send_packet().
| int send_pong_packet | ( | socket_t | sockfd | ) |
#include <packet.h>
Send a pong packet (keepalive response)
| sockfd | Socket file descriptor |
Sends a PACKET_TYPE_PONG packet in response to PACKET_TYPE_PING. Indicates that connection is alive and responsive.
Send a pong packet (keepalive response)
| sockfd | Socket file descriptor |
Definition at line 793 of file packet.c.
References ASCIICHAT_OK, PACKET_TYPE_PONG, and send_packet().
| int send_protocol_version_packet | ( | socket_t | sockfd, |
| const protocol_version_packet_t * | version | ||
| ) |
#include <packet.h>
Send protocol version negotiation packet.
| sockfd | Socket file descriptor |
| version | Protocol version packet structure |
Sends a PACKET_TYPE_PROTOCOL_VERSION packet for protocol capability negotiation. Both client and server send this during handshake.
Send protocol version negotiation packet.
| sockfd | Socket file descriptor |
| version | Protocol version packet |
Definition at line 1016 of file packet.c.
References ERROR_INVALID_PARAM, PACKET_TYPE_PROTOCOL_VERSION, send_packet(), and SET_ERRNO.
Referenced by client_crypto_handshake(), and server_crypto_handshake().
| ssize_t send_with_timeout | ( | socket_t | sockfd, |
| const void * | data, | ||
| size_t | len, | ||
| int | timeout_seconds | ||
| ) |
#include <network.h>
Send data with timeout using chunked transmission.
| sockfd | Socket file descriptor |
| data | Data to send |
| len | Length of data in bytes |
| timeout_seconds | Timeout in seconds |
Sends data to socket with timeout support. Uses chunked transmission for large data to prevent blocking and enable progress tracking.
| sockfd | Socket file descriptor |
| data | Data to send |
| len | Length of data |
| timeout_seconds | Timeout in seconds |
Definition at line 200 of file network.c.
References EBADF, errno, ERROR_NETWORK_TIMEOUT, INVALID_SOCKET_VALUE, network_is_test_environment, SET_ERRNO_SYS, socket_fd_isset(), socket_fd_set(), socket_fd_zero(), and socket_select().
Referenced by packet_send().
| asciichat_error_t set_socket_keepalive | ( | socket_t | sockfd | ) |
#include <network.h>
Enable TCP keepalive on socket.
| sockfd | Socket file descriptor |
Enables TCP keepalive probes on socket using KEEPALIVE_IDLE, KEEPALIVE_INTERVAL, and KEEPALIVE_COUNT settings.
Enable TCP keepalive on socket.
| sockfd | Socket file descriptor |
Definition at line 461 of file network.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_NETWORK, INVALID_SOCKET_VALUE, KEEPALIVE_COUNT, KEEPALIVE_IDLE, KEEPALIVE_INTERVAL, SET_ERRNO, SET_ERRNO_SYS, and socket_set_keepalive_params().
| asciichat_error_t set_socket_nonblocking | ( | socket_t | sockfd | ) |
#include <network.h>
Set socket to non-blocking mode.
| sockfd | Socket file descriptor |
Sets socket to non-blocking mode. I/O operations return immediately with error if data is not available.
Set socket to non-blocking mode.
| sockfd | Socket file descriptor |
Definition at line 477 of file network.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_NETWORK, INVALID_SOCKET_VALUE, SET_ERRNO, SET_ERRNO_SYS, and socket_set_nonblocking().
Referenced by connect_with_timeout().
| asciichat_error_t set_socket_timeout | ( | socket_t | sockfd, |
| int | timeout_seconds | ||
| ) |
#include <network.h>
Set socket timeout for send/receive operations.
| sockfd | Socket file descriptor |
| timeout_seconds | Timeout in seconds |
Configures socket-level timeout for send and receive operations. This sets SO_SNDTIMEO and SO_RCVTIMEO socket options.
Set socket timeout for send/receive operations.
| sockfd | Socket file descriptor |
| timeout_seconds | Timeout in seconds |
Definition at line 436 of file network.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_NETWORK, INVALID_SOCKET_VALUE, SET_ERRNO, SET_ERRNO_SYS, and socket_setsockopt().
| asciichat_error_t socket_configure_buffers | ( | socket_t | sockfd | ) |
#include <network.h>
Configure socket buffers and TCP_NODELAY for optimal performance.
| sockfd | Socket file descriptor |
Configures socket with large send/receive buffers (1MB each) and enables TCP_NODELAY for low-latency real-time video streaming.
CONFIGURATION:
BEHAVIOR: Attempts to set all three socket options independently. Individual failures are logged as warnings but do not prevent attempting other options. This ensures TCP_NODELAY is always set even if buffer size configuration fails (common on systems with strict limits). Only returns error if ALL options fail.
| sockfd | Socket file descriptor |
Definition at line 493 of file network.c.
References ASCIICHAT_OK, ERROR_NETWORK, INVALID_SOCKET_VALUE, log_warn, network_error_string(), SET_ERRNO_SYS, and socket_setsockopt().
Referenced by server_connection_establish(), and tcp_client_connect().
| uint32_t server_state_packet_t::active_client_count |
Number of clients actively sending video/audio streams.
Definition at line 602 of file packet.h.
Referenced by broadcast_server_state_to_all_clients(), and send_server_state_to_client().
| void* packet_envelope_t::allocated_buffer |
Buffer that needs to be freed by caller (may be NULL if not allocated)
Definition at line 990 of file packet.h.
Referenced by acip_client_receive_and_dispatch(), acip_server_receive_and_dispatch(), and receive_packet_secure().
| size_t packet_envelope_t::allocated_size |
Size of allocated buffer in bytes.
Definition at line 992 of file packet.h.
Referenced by acip_client_receive_and_dispatch(), acip_server_receive_and_dispatch(), and receive_packet_secure().
| uint16_t crypto_parameters_packet_t::auth_public_key_size |
Authentication public key size in bytes (e.g., 32 for Ed25519, 1952 for Dilithium3)
Definition at line 885 of file packet.h.
Referenced by client_crypto_handshake(), crypto_handshake_set_parameters(), send_crypto_parameters_packet(), and server_crypto_handshake().
| uint32_t audio_batch_packet_t::batch_count |
Number of audio chunks in this batch (usually AUDIO_BATCH_COUNT = 32)
Definition at line 798 of file packet.h.
Referenced by acip_send_audio_batch(), audio_parse_batch_header(), and send_audio_batch_packet().
| uint32_t client_info_packet_t::capabilities |
Client capabilities bitmask (CLIENT_CAP_VIDEO | CLIENT_CAP_AUDIO | CLIENT_CAP_COLOR | CLIENT_CAP_STRETCH)
Definition at line 552 of file packet.h.
Referenced by handle_client_join_packet(), tcp_client_send_join(), and threaded_send_client_join_packet().
| uint32_t terminal_capabilities_packet_t::capabilities |
Terminal capabilities bitmask (TERM_CAP_* flags)
Definition at line 911 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint32_t audio_batch_packet_t::channels |
Number of audio channels (1=mono, 2=stereo)
Definition at line 804 of file packet.h.
Referenced by acip_send_audio_batch(), audio_parse_batch_header(), and send_audio_batch_packet().
| uint32_t ascii_frame_packet_t::checksum |
CRC32 checksum of original ASCII data.
Definition at line 750 of file packet.h.
Referenced by acip_send_ascii_frame(), and send_ascii_frame_packet().
| uint32_t image_frame_packet_t::checksum |
CRC32 checksum of pixel data.
Definition at line 778 of file packet.h.
Referenced by acip_send_image_frame(), and send_image_frame_packet().
| uint32_t client_list_packet_t::client_count |
| uint32_t packet_header_t::client_id |
Client ID (0 = server, >0 = client identifier)
Definition at line 500 of file packet.h.
Referenced by packet_queue_enqueue(), packet_send_via_transport(), and process_encrypted_packet().
| uint32_t client_info_packet_t::client_id |
Unique client identifier (1-9, 0 = server)
Definition at line 547 of file packet.h.
Referenced by tcp_client_send_join(), and threaded_send_client_join_packet().
| uint32_t stream_header_t::client_id |
| client_info_packet_t client_list_packet_t::clients[MAX_CLIENTS] |
| uint32_t terminal_capabilities_packet_t::color_count |
Actual color count (16, 256, or 16777216)
Definition at line 915 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint32_t terminal_capabilities_packet_t::color_level |
Color level enum value (terminal_color_mode_t)
Definition at line 913 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| char terminal_capabilities_packet_t::colorterm[32] |
$COLORTERM environment variable value (for debugging)
Definition at line 925 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint32_t ascii_frame_packet_t::compressed_size |
Size of compressed data (0 = not compressed)
Definition at line 748 of file packet.h.
Referenced by acip_send_ascii_frame(), and send_ascii_frame_packet().
| uint32_t image_frame_packet_t::compressed_size |
Compressed data size (0 = not compressed, >0 = compressed)
Definition at line 776 of file packet.h.
Referenced by acip_send_image_frame(), and send_image_frame_packet().
| uint8_t protocol_version_packet_t::compression_algorithms |
Supported compression algorithms bitmask (COMPRESS_ALGO_*)
Definition at line 718 of file packet.h.
Referenced by client_crypto_handshake(), handle_protocol_version_packet(), and server_crypto_handshake().
| uint8_t protocol_version_packet_t::compression_threshold |
Compression threshold percentage (0-100, e.g., 80 = compress if >80% size reduction)
Definition at line 720 of file packet.h.
Referenced by client_crypto_handshake(), and server_crypto_handshake().
| uint32_t server_state_packet_t::connected_client_count |
Total number of currently connected clients.
Definition at line 600 of file packet.h.
Referenced by broadcast_server_state_to_all_clients(), and send_server_state_to_client().
| uint32_t packet_header_t::crc32 |
CRC32 checksum of payload data (0 if length == 0)
Definition at line 498 of file packet.h.
Referenced by packet_queue_enqueue(), packet_queue_try_dequeue(), packet_queue_validate_packet(), packet_send_via_transport(), packet_validate_header(), and receive_packet_secure().
| void* packet_envelope_t::data |
Packet payload data (decrypted and decompressed if applicable)
Definition at line 984 of file packet.h.
Referenced by acip_client_receive_and_dispatch(), acip_server_receive_and_dispatch(), and receive_packet_secure().
| uint8_t terminal_capabilities_packet_t::desired_fps |
Client's desired frame rate (1-144 FPS)
Definition at line 935 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint8_t terminal_capabilities_packet_t::detection_reliable |
Detection reliability flag (1=reliable detection, 0=best guess)
Definition at line 927 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint8_t remote_log_packet_t::direction |
Direction hint so receivers can annotate origin.
Definition at line 637 of file packet.h.
Referenced by acip_send_remote_log(), packet_parse_remote_log(), and packet_send_remote_log().
| char client_info_packet_t::display_name[MAX_DISPLAY_NAME_LEN] |
User display name (null-terminated, max MAX_DISPLAY_NAME_LEN bytes)
Definition at line 549 of file packet.h.
Referenced by handle_client_join_packet(), tcp_client_send_join(), and threaded_send_client_join_packet().
| uint32_t error_packet_t::error_code |
Error code from asciichat_error_t enumeration.
Definition at line 621 of file packet.h.
Referenced by acip_send_error(), packet_parse_error_message(), and packet_send_error().
| uint16_t protocol_version_packet_t::feature_flags |
Feature flags bitmask (FEATURE_RLE_ENCODING, etc.)
Definition at line 722 of file packet.h.
Referenced by client_crypto_handshake(), handle_protocol_version_packet(), and server_crypto_handshake().
| uint16_t remote_log_packet_t::flags |
Additional flags (REMOTE_LOG_FLAG_*)
Definition at line 639 of file packet.h.
Referenced by acip_send_remote_log(), packet_parse_remote_log(), and packet_send_remote_log().
| uint32_t ascii_frame_packet_t::flags |
Frame flags bitmask (HAS_COLOR, IS_COMPRESSED, etc.)
Definition at line 752 of file packet.h.
Referenced by acip_send_ascii_frame(), and send_ascii_frame_packet().
| uint32_t size_packet_t::height |
Terminal height in characters.
Definition at line 533 of file packet.h.
Referenced by handle_size_packet().
| uint32_t ascii_frame_packet_t::height |
Terminal height in characters.
Definition at line 744 of file packet.h.
Referenced by acip_send_ascii_frame(), and send_ascii_frame_packet().
| uint32_t image_frame_packet_t::height |
Image height in pixels.
Definition at line 772 of file packet.h.
Referenced by acip_send_image_frame(), and send_image_frame_packet().
| uint16_t terminal_capabilities_packet_t::height |
Terminal height in characters.
Definition at line 921 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint8_t crypto_parameters_packet_t::hmac_size |
HMAC size in bytes (e.g., 32 for HMAC-SHA256)
Definition at line 895 of file packet.h.
Referenced by crypto_handshake_set_parameters(), and server_crypto_handshake().
| uint16_t crypto_parameters_packet_t::kex_public_key_size |
Key exchange public key size in bytes (e.g., 32 for X25519, 1568 for Kyber1024)
Definition at line 883 of file packet.h.
Referenced by client_crypto_handshake(), crypto_handshake_set_parameters(), send_crypto_parameters_packet(), and server_crypto_handshake().
| size_t packet_envelope_t::len |
Length of payload data in bytes.
Definition at line 986 of file packet.h.
Referenced by acip_client_receive_and_dispatch(), acip_server_receive_and_dispatch(), and receive_packet_secure().
| uint32_t packet_header_t::length |
Payload data length in bytes (0 for header-only packets)
Definition at line 496 of file packet.h.
Referenced by packet_queue_enqueue(), packet_queue_validate_packet(), packet_send_via_transport(), packet_validate_header(), and receive_packet_secure().
| uint8_t remote_log_packet_t::log_level |
Log level associated with the message (log_level_t cast to uint8_t)
Definition at line 635 of file packet.h.
Referenced by acip_send_remote_log(), packet_parse_remote_log(), and packet_send_remote_log().
| uint8_t crypto_parameters_packet_t::mac_size |
MAC size in bytes (e.g., 16 for Poly1305)
Definition at line 893 of file packet.h.
Referenced by crypto_handshake_set_parameters(), and server_crypto_handshake().
| uint32_t packet_header_t::magic |
Magic number (PACKET_MAGIC) for packet validation.
Definition at line 492 of file packet.h.
Referenced by packet_queue_enqueue(), packet_queue_free_packet(), packet_queue_try_dequeue(), packet_queue_validate_packet(), packet_send(), packet_send_via_transport(), packet_validate_header(), receive_packet_secure(), and send_packet_secure().
| uint32_t error_packet_t::message_length |
Length of message payload in bytes (0-512)
Definition at line 623 of file packet.h.
Referenced by acip_send_error(), packet_parse_error_message(), and packet_send_error().
| uint32_t remote_log_packet_t::message_length |
Message payload length in bytes (0-512)
Definition at line 641 of file packet.h.
Referenced by acip_send_remote_log(), packet_parse_remote_log(), and packet_send_remote_log().
| uint8_t crypto_parameters_packet_t::nonce_size |
Nonce size in bytes (e.g., 24 for XSalsa20)
Definition at line 891 of file packet.h.
Referenced by crypto_handshake_set_parameters(), and server_crypto_handshake().
| uint32_t ascii_frame_packet_t::original_size |
Size of original uncompressed ASCII data in bytes.
Definition at line 746 of file packet.h.
Referenced by acip_send_ascii_frame(), and send_ascii_frame_packet().
| char terminal_capabilities_packet_t::palette_custom[64] |
Custom palette characters (if palette_type == PALETTE_CUSTOM)
Definition at line 933 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint32_t terminal_capabilities_packet_t::palette_type |
Palette type enum value (palette_type_t)
Definition at line 931 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint32_t image_frame_packet_t::pixel_format |
Pixel format enum (0=RGB24, 1=RGBA32, 2=BGR24, etc.)
Definition at line 774 of file packet.h.
Referenced by acip_send_image_frame(), and send_image_frame_packet().
| uint8_t crypto_capabilities_packet_t::preferred_auth |
Preferred authentication algorithm (AUTH_ALGO_*)
Definition at line 856 of file packet.h.
Referenced by client_crypto_handshake().
| uint8_t crypto_capabilities_packet_t::preferred_cipher |
Preferred cipher algorithm (CIPHER_ALGO_*)
Definition at line 858 of file packet.h.
Referenced by client_crypto_handshake().
| uint8_t crypto_capabilities_packet_t::preferred_kex |
Preferred key exchange algorithm (KEX_ALGO_*)
Definition at line 854 of file packet.h.
Referenced by client_crypto_handshake().
| uint16_t protocol_version_packet_t::protocol_revision |
Minor protocol revision (server can be newer)
Definition at line 714 of file packet.h.
Referenced by client_crypto_handshake(), handle_protocol_version_packet(), and server_crypto_handshake().
| uint16_t protocol_version_packet_t::protocol_version |
Major protocol version (must match for compatibility)
Definition at line 712 of file packet.h.
Referenced by client_crypto_handshake(), handle_protocol_version_packet(), and server_crypto_handshake().
| uint8_t auth_failure_packet_t::reason_flags |
Bitmask of auth_failure_reason_t values indicating failure causes.
Definition at line 676 of file packet.h.
Referenced by crypto_handshake_client_complete(), crypto_handshake_server_auth_challenge(), and crypto_handshake_server_complete().
| uint32_t terminal_capabilities_packet_t::render_mode |
Render mode enum value (foreground/background/half-block)
Definition at line 917 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint8_t crypto_capabilities_packet_t::requires_verification |
Server verification requirement flag (1=required, 0=optional)
Definition at line 852 of file packet.h.
Referenced by client_crypto_handshake().
| uint8_t terminal_capabilities_packet_t::reserved[2] |
Reserved bytes for alignment (must be zero)
Definition at line 937 of file packet.h.
Referenced by tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint8_t crypto_parameters_packet_t::reserved[3] |
| uint32_t server_state_packet_t::reserved[6] |
Reserved fields for future use (must be zero)
Definition at line 604 of file packet.h.
Referenced by broadcast_server_state_to_all_clients(), and send_server_state_to_client().
| uint8_t auth_failure_packet_t::reserved[7] |
| uint8_t protocol_version_packet_t::reserved[7] |
Reserved bytes for future expansion (must be zero)
Definition at line 724 of file packet.h.
Referenced by handle_protocol_version_packet().
| uint32_t audio_batch_packet_t::sample_rate |
Sample rate in Hz (e.g., 44100, 48000)
Definition at line 802 of file packet.h.
Referenced by acip_send_audio_batch(), audio_parse_batch_header(), and send_audio_batch_packet().
| uint8_t crypto_parameters_packet_t::selected_auth |
Selected authentication algorithm (AUTH_ALGO_*)
Definition at line 877 of file packet.h.
Referenced by client_crypto_handshake(), and server_crypto_handshake().
| uint8_t crypto_parameters_packet_t::selected_cipher |
Selected cipher algorithm (CIPHER_ALGO_*)
Definition at line 879 of file packet.h.
Referenced by client_crypto_handshake(), and server_crypto_handshake().
| uint8_t crypto_parameters_packet_t::selected_kex |
Selected key exchange algorithm (KEX_ALGO_*)
Definition at line 875 of file packet.h.
Referenced by client_crypto_handshake(), and server_crypto_handshake().
| uint16_t crypto_parameters_packet_t::shared_secret_size |
Shared secret size in bytes (e.g., 32 for X25519)
Definition at line 889 of file packet.h.
Referenced by client_crypto_handshake(), crypto_handshake_set_parameters(), send_crypto_parameters_packet(), and server_crypto_handshake().
| uint16_t crypto_parameters_packet_t::signature_size |
Signature size in bytes (e.g., 64 for Ed25519, 3309 for Dilithium3)
Definition at line 887 of file packet.h.
Referenced by client_crypto_handshake(), crypto_handshake_set_parameters(), send_crypto_parameters_packet(), and server_crypto_handshake().
| uint32_t stream_header_t::stream_type |
| uint16_t crypto_capabilities_packet_t::supported_auth_algorithms |
Supported authentication algorithms bitmask (AUTH_ALGO_*)
Definition at line 848 of file packet.h.
Referenced by client_crypto_handshake(), and server_crypto_handshake().
| uint16_t crypto_capabilities_packet_t::supported_cipher_algorithms |
Supported cipher algorithms bitmask (CIPHER_ALGO_*)
Definition at line 850 of file packet.h.
Referenced by client_crypto_handshake(), and server_crypto_handshake().
| uint16_t crypto_capabilities_packet_t::supported_kex_algorithms |
Supported key exchange algorithms bitmask (KEX_ALGO_*)
Definition at line 846 of file packet.h.
Referenced by client_crypto_handshake(), and server_crypto_handshake().
| uint8_t protocol_version_packet_t::supports_encryption |
Encryption support flag (1=support encryption, 0=plaintext only)
Definition at line 716 of file packet.h.
Referenced by client_crypto_handshake(), handle_protocol_version_packet(), and server_crypto_handshake().
| char terminal_capabilities_packet_t::term_type[32] |
$TERM environment variable value (for debugging)
Definition at line 923 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint32_t stream_header_t::timestamp |
| uint32_t image_frame_packet_t::timestamp |
Timestamp when frame was captured (milliseconds since epoch)
Definition at line 780 of file packet.h.
Referenced by acip_send_image_frame(), and send_image_frame_packet().
| uint32_t audio_batch_packet_t::total_samples |
Total audio samples across all chunks (typically 8192)
Definition at line 800 of file packet.h.
Referenced by acip_send_audio_batch(), audio_parse_batch_header(), and send_audio_batch_packet().
| uint16_t packet_header_t::type |
Packet type (packet_type_t enumeration)
Definition at line 494 of file packet.h.
Referenced by packet_queue_enqueue(), packet_queue_try_dequeue(), packet_queue_validate_packet(), packet_send_via_transport(), packet_validate_header(), process_encrypted_packet(), and receive_packet_secure().
| packet_type_t packet_envelope_t::type |
Packet type (from packet_types.h)
Definition at line 982 of file packet.h.
Referenced by acip_client_receive_and_dispatch(), acip_server_receive_and_dispatch(), and receive_packet_secure().
| uint32_t terminal_capabilities_packet_t::utf8_support |
UTF-8 support flag (0=no UTF-8, 1=UTF-8 supported)
Definition at line 929 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| uint8_t crypto_parameters_packet_t::verification_enabled |
Server verification enabled flag (1=enabled, 0=disabled)
Definition at line 881 of file packet.h.
Referenced by client_crypto_handshake(), and server_crypto_handshake().
| bool packet_envelope_t::was_encrypted |
| uint32_t size_packet_t::width |
Terminal width in characters.
Definition at line 531 of file packet.h.
Referenced by handle_size_packet().
| uint32_t ascii_frame_packet_t::width |
Terminal width in characters.
Definition at line 742 of file packet.h.
Referenced by acip_send_ascii_frame(), and send_ascii_frame_packet().
| uint32_t image_frame_packet_t::width |
Image width in pixels.
Definition at line 770 of file packet.h.
Referenced by acip_send_image_frame(), and send_image_frame_packet().
| uint16_t terminal_capabilities_packet_t::width |
Terminal width in characters.
Definition at line 919 of file packet.h.
Referenced by handle_client_capabilities_packet(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().