ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
packet.h
Go to the documentation of this file.
1
73#pragma once
74
75#include "../../platform/socket.h"
76#include "../../platform/abstraction.h"
77#include "../../crypto/crypto.h"
78#include "../../log/log.h"
79#include "../../util/magic.h"
80#include "../../media/codecs.h"
81#include <stdint.h>
82#include <stddef.h>
83#include <stdbool.h>
84#include <errno.h>
85
86// Pack network protocol structures tightly for wire format
87#ifdef _WIN32
88#pragma pack(push, 1)
89#endif
90
105#define LARGE_PACKET_THRESHOLD (100 * 1024)
106
115#define MAX_PACKET_SIZE ((size_t)5 * 1024 * 1024)
116
124#define MAX_ERROR_MESSAGE_LENGTH 512
125
134#define MAX_REMOTE_LOG_MESSAGE_LENGTH 512
135
155#define BASE_SEND_TIMEOUT (5LL * NS_PER_SEC_INT)
156
165#define LARGE_PACKET_EXTRA_TIMEOUT_PER_MB (800LL * NS_PER_MS_INT)
166
175#define MIN_CLIENT_TIMEOUT (10LL * NS_PER_SEC_INT)
176
185#define MAX_CLIENT_TIMEOUT (60LL * NS_PER_SEC_INT)
186
206#define AUDIO_BATCH_COUNT 32
207
216#define AUDIO_BATCH_SAMPLES (AUDIO_SAMPLES_PER_PACKET * AUDIO_BATCH_COUNT)
217
225#define AUDIO_BATCH_MS 186
226
235#define AUDIO_SAMPLES_PER_PACKET 256
236
255#define PACKET_MAGIC MAGIC_PACKET_VALID
256
286typedef enum {
289
290 // ============================================================================
291 // Cryptographic Operations (Types 1000-1999)
292 // ============================================================================
293
294 // ============================================================================
295 // Cryptographic Client Hello (Types 1000-1099)
296 // ============================================================================
297
300
301 // ============================================================================
302 // Cryptographic Handshake (Types 1100-1199)
303 // ============================================================================
304 // ALWAYS UNENCRYPTED (except ENCRYPTED which wraps encrypted data)
305
326
327 // ============================================================================
328 // Cryptographic Rekeying (Types 1200-1299)
329 // ============================================================================
330 // ALWAYS UNENCRYPTED during rekey phase
331
340
341 // ============================================================================
342 // Message Packets (Types 2000-2999)
343 // ============================================================================
344
355
356 // ============================================================================
357 // Media Frames (Types 3000-3999)
358 // ============================================================================
359
366
367 // ============================================================================
368 // Audio Packets (Types 4000-4999)
369 // ============================================================================
370
375
376 // ============================================================================
377 // Control/State Packets (Types 5000-5999)
378 // ============================================================================
379
398
399 // ============================================================================
400 // Discovery Service Protocol (ACDS) (Types 6000+)
401 // ============================================================================
402 // ACIP packets use range 6000+ for discovery mode operations
403 // See network/acip/protocol.h for protocol overview and utility functions
404 // See network/acip/acds.h for ACDS message structures and detailed documentation
405
424
429
438
439 // ============================================================================
440 // Ring Consensus Protocol (6050-6051)
441 // ============================================================================
442 // Used for proactive future host election every 5 minutes
443
448
449 // ============================================================================
450 // Host Negotiation & Migration Protocol (6060-6069)
451 // ============================================================================
452 // Used by discovery mode for dynamic host selection and failover
453
472
473 // ============================================================================
474 // Bandwidth Testing (6070-6071)
475 // ============================================================================
476 // Used for measuring network bandwidth during NAT quality detection
477
482
485
486 // ============================================================================
487 // Ring Consensus Protocol (6100-6104)
488 // ============================================================================
489 // Used for collecting statistics and coordinating ring-based consensus
490
501
502 // ============================================================================
503 // Discovery Service Keepalive (6190-6199)
504 // ============================================================================
505
511
538static inline bool packet_is_handshake_type(packet_type_t type) {
539 // Client hello for multi-key selection (type 1000)
541 return true;
542 }
543 // Crypto handshake packets (1100-1109)
545 return true;
546 }
547 // Crypto rekey packets (1201-1203)
549 return true;
550 }
551 return false;
552}
553
572static inline bool packet_is_precompressed(packet_type_t type) {
573 // Opus audio packets are already compressed by Opus codec
574 return (type == PACKET_TYPE_AUDIO_OPUS_BATCH);
575}
576
611
625#define ASCIICHAT_DEFAULT_DISPLAY_NAME "AsciiChatter"
626
637typedef struct {
642}
644
653typedef struct {
657 char display_name[MAX_DISPLAY_NAME_LEN];
661}
663
681
697
715
734
736#define REMOTE_LOG_FLAG_TRUNCATED 0x0001U
752
773
782typedef struct {
786 uint8_t reserved[7];
787}
789
802#define FEATURE_RLE_ENCODING 0x01
803#define FEATURE_DELTA_FRAMES 0x02
835
863
891
915
923#define CLIENT_CAP_VIDEO 0x01
924#define CLIENT_CAP_AUDIO 0x02
925#define CLIENT_CAP_COLOR 0x04
926#define CLIENT_CAP_STRETCH 0x08
937#define STREAM_TYPE_VIDEO 0x01
938#define STREAM_TYPE_AUDIO 0x02
969
1008
1055
1064#define KEX_ALGO_X25519 0x01
1065#define AUTH_ALGO_ED25519 0x01
1066#define AUTH_ALGO_NONE 0x00
1067#define CIPHER_ALGO_XSALSA20_POLY1305 0x01
1068#define CIPHER_ALGO_NONE 0x00
1082#define ACIP_CRYPTO_NONE 0x00
1083#define ACIP_CRYPTO_ENCRYPT 0x01
1084#define ACIP_CRYPTO_AUTH 0x02
1085#define ACIP_CRYPTO_FULL 0x03
1092#define ACIP_CRYPTO_HAS_ENCRYPT(mode) (((mode) & ACIP_CRYPTO_ENCRYPT) != 0)
1093
1099#define ACIP_CRYPTO_HAS_AUTH(mode) (((mode) & ACIP_CRYPTO_AUTH) != 0)
1100
1105#ifdef _WIN32
1106#pragma pack(pop)
1107#endif
1108
1143
1162
1187asciichat_error_t packet_send(socket_t sockfd, packet_type_t type, const void *data, size_t len);
1188
1208asciichat_error_t packet_receive(socket_t sockfd, packet_type_t *type, void **data, size_t *len);
1209
1241asciichat_error_t send_packet_secure(socket_t sockfd, packet_type_t type, const void *data, size_t len,
1242 crypto_context_t *crypto_ctx);
1243
1268packet_recv_result_t receive_packet_secure(socket_t sockfd, void *crypto_ctx, bool enforce_encryption,
1269 packet_envelope_t *envelope);
1270packet_recv_result_t receive_packet_secure_with_timeout(socket_t sockfd, void *crypto_ctx, bool enforce_encryption,
1271 packet_envelope_t *envelope, uint64_t timeout_ns);
1272
1291
1318int send_packet(socket_t sockfd, packet_type_t type, const void *data, size_t len);
1319
1337int receive_packet(socket_t sockfd, packet_type_t *type, void **data, size_t *len);
1338
1363int send_ping_packet(socket_t sockfd);
1364
1377int send_pong_packet(socket_t sockfd);
1378
1392 const char *message);
1393
1404asciichat_error_t packet_parse_error_message(const void *data, size_t len, asciichat_error_t *out_error_code,
1405 char *message_buffer, size_t message_buffer_size,
1406 size_t *out_message_length);
1407
1419 remote_log_direction_t direction, uint16_t flags, const char *message);
1420
1433asciichat_error_t packet_parse_remote_log(const void *data, size_t len, log_level_t *out_level,
1434 remote_log_direction_t *out_direction, uint16_t *out_flags,
1435 char *message_buffer, size_t message_buffer_size, size_t *out_message_length);
1436
1451
1466
1481
1502asciichat_error_t av_send_audio_opus_batch(socket_t sockfd, const uint8_t *opus_data, size_t opus_size,
1503 const uint16_t *frame_sizes, int sample_rate, int frame_duration,
1504 int frame_count, crypto_context_t *crypto_ctx);
1505
1523asciichat_error_t send_image_frame_packet(socket_t sockfd, const void *image_data, uint16_t width, uint16_t height,
1524 uint8_t format);
1525
asciichat_error_t error_code
Cross-platform error handling utilities.
unsigned short uint16_t
Definition common.h:57
unsigned int uint32_t
Definition common.h:58
unsigned long long uint64_t
Definition common.h:59
unsigned char uint8_t
Definition common.h:56
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
#define MAX_CLIENTS
Maximum possible clients (static array size) - actual runtime limit set by –max-clients (1-32)
Definition limits.h:26
#define MAX_DISPLAY_NAME_LEN
Maximum display name length in characters.
Definition limits.h:20
enum remote_log_direction remote_log_direction_t
Remote log packet direction enumeration.
log_level_t
Logging levels enumeration.
Definition types.h:29
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.
Definition packet.c:434
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.
Definition packet.c:1056
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.
Definition packet.c:910
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.
Definition packet.c:999
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.
Definition packet.c:1230
int send_protocol_version_packet(socket_t sockfd, const protocol_version_packet_t *version)
Send protocol version negotiation packet.
Definition packet.c:1119
int send_pong_packet(socket_t sockfd)
Send a pong packet (keepalive response)
Definition packet.c:822
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.
Definition packet.c:352
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.
Definition packet.c:957
int receive_packet(socket_t sockfd, packet_type_t *type, void **data, size_t *len)
Receive a basic packet without encryption.
Definition packet.c:797
asciichat_error_t packet_decrypt_envelope(packet_envelope_t *envelope, void *crypto_ctx)
Decrypt a PACKET_TYPE_ENCRYPTED envelope and extract inner packet.
Definition packet.c:842
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.
Definition packet.c:1175
int send_packet(socket_t sockfd, packet_type_t type, const void *data, size_t len)
Send a basic packet without encryption.
Definition packet.c:784
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.
Definition packet.c:292
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.
Definition packet.c:569
int send_crypto_capabilities_packet(socket_t sockfd, const crypto_capabilities_packet_t *caps)
Send crypto capabilities packet.
Definition packet.c:1133
int send_ping_packet(socket_t sockfd)
Send a ping packet (keepalive)
Definition packet.c:813
packet_recv_result_t receive_packet_secure_with_timeout(socket_t sockfd, void *crypto_ctx, bool enforce_encryption, packet_envelope_t *envelope, uint64_t timeout_ns)
Definition packet.c:575
int send_crypto_parameters_packet(socket_t sockfd, const crypto_parameters_packet_t *params)
Send crypto parameters packet.
Definition packet.c:1147
packet_recv_result_t
Packet reception result codes.
Definition packet.h:1152
@ PACKET_RECV_ERROR
Network error occurred.
Definition packet.h:1158
@ PACKET_RECV_EOF
Connection closed (EOF)
Definition packet.h:1156
@ PACKET_RECV_SECURITY_VIOLATION
Encryption policy violation (e.g., unencrypted packet when encryption required)
Definition packet.h:1160
@ PACKET_RECV_SUCCESS
Packet received successfully.
Definition packet.h:1154
auth_failure_reason_t
Authentication failure reason flags.
Definition packet.h:761
packet_type_t
Network protocol packet type enumeration.
Definition packet.h:286
@ AUTH_FAIL_PASSWORD_INCORRECT
Password verification failed (incorrect password)
Definition packet.h:765
@ AUTH_FAIL_PASSWORD_REQUIRED
Server requires password but client didn't provide one.
Definition packet.h:763
@ AUTH_FAIL_CLIENT_KEY_REQUIRED
Server requires client key but client didn't provide one.
Definition packet.h:767
@ AUTH_FAIL_CLIENT_KEY_REJECTED
Client key not in whitelist (access denied)
Definition packet.h:769
@ AUTH_FAIL_SIGNATURE_INVALID
Client signature verification failed (invalid signature)
Definition packet.h:771
@ PACKET_TYPE_CRYPTO_CLIENT_HELLO
Client -> Server: Expected server key fingerprint for multi-key selection (UNENCRYPTED)
Definition packet.h:299
@ PACKET_TYPE_ACIP_WEBRTC_ICE
WebRTC ICE candidate (bidirectional)
Definition packet.h:428
@ PACKET_TYPE_AUDIO_OPUS_BATCH
Batched Opus-encoded audio frames.
Definition packet.h:374
@ PACKET_TYPE_ACIP_PARTICIPANT_JOINED
Participant joined notification (ACDS -> Existing Participants)
Definition packet.h:469
@ PACKET_TYPE_CLIENT_LEAVE
Clean disconnect notification.
Definition packet.h:389
@ PACKET_TYPE_ACIP_SESSION_INFO
Session info response (Discovery Server -> Client)
Definition packet.h:413
@ PACKET_TYPE_IMAGE_FRAME
Complete RGB image with dimensions.
Definition packet.h:363
@ PACKET_TYPE_CRYPTO_AUTH_RESPONSE
Client -> Server: {HMAC[32]} (UNENCRYPTED)
Definition packet.h:317
@ PACKET_TYPE_TEXT_MESSAGE
Text message.
Definition packet.h:350
@ PACKET_TYPE_AUDIO_MESSAGE
Audio message.
Definition packet.h:348
@ PACKET_TYPE_PONG
Keepalive pong response.
Definition packet.h:385
@ PACKET_TYPE_ACIP_SESSION_RECONNECT
Reconnect to session (Client -> Discovery Server)
Definition packet.h:423
@ PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE
Server -> Client: "encryption ready" (UNENCRYPTED)
Definition packet.h:323
@ PACKET_TYPE_ACIP_PARTICIPANT_LIST
Participant list with ring order (ACDS -> Participants)
Definition packet.h:445
@ PACKET_TYPE_STREAM_START
Client requests to start sending video/audio.
Definition packet.h:391
@ PACKET_TYPE_ACIP_SETTINGS_SYNC
Settings sync (Initiator -> Host -> All Participants)
Definition packet.h:461
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT
Server -> Client: {server_pubkey[32]} (UNENCRYPTED)
Definition packet.h:311
@ PACKET_TYPE_ACIP_ERROR
Generic error response (Discovery Server -> Client)
Definition packet.h:509
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP
Client -> Server: {client_pubkey[32]} (UNENCRYPTED)
Definition packet.h:313
@ PACKET_TYPE_CRYPTO_REKEY_COMPLETE
Initiator -> Responder: Empty (encrypted with NEW key, but still handshake)
Definition packet.h:339
@ PACKET_TYPE_ACIP_NETWORK_QUALITY
NETWORK_QUALITY exchange (unified packet for all quality metrics)
Definition packet.h:455
@ PACKET_TYPE_SERVER_STATE
Server sends current state to clients.
Definition packet.h:397
@ PACKET_TYPE_ACIP_HOST_LOST
Host lost notification - lightweight (Participant -> ACDS)
Definition packet.h:465
@ PACKET_TYPE_ACIP_BROADCAST_ACK
Broadcast acknowledgment for reliable delivery.
Definition packet.h:484
@ PACKET_TYPE_ACIP_HOST_DESIGNATED
Host designated (ACDS -> All Participants)
Definition packet.h:459
@ PACKET_TYPE_ACIP_STRING_RESERVE
Reserve session string (Client -> Discovery Server)
Definition packet.h:431
@ PACKET_TYPE_CRYPTO_AUTH_FAILED
Server -> Client: "authentication failed" (UNENCRYPTED)
Definition packet.h:319
@ PACKET_TYPE_ENCRYPTED
Encrypted packet (after handshake completion)
Definition packet.h:333
@ PACKET_TYPE_CRYPTO_REKEY_REQUEST
Initiator -> Responder: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey)
Definition packet.h:335
@ PACKET_TYPE_SIZE_MESSAGE
Terminal size message.
Definition packet.h:346
@ PACKET_TYPE_REMOTE_LOG
Bidirectional remote logging packet.
Definition packet.h:354
@ PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP
Server -> Client: {HMAC[32]} server proves knowledge (UNENCRYPTED)
Definition packet.h:321
@ PACKET_TYPE_ACIP_HOST_ANNOUNCEMENT
Host announcement (Participant -> ACDS, "I won negotiation")
Definition packet.h:457
@ PACKET_TYPE_PROTOCOL_VERSION
Protocol version and capabilities negotiation.
Definition packet.h:288
@ PACKET_TYPE_ACIP_SETTINGS_ACK
Settings acknowledgment (Participant -> Initiator)
Definition packet.h:463
@ PACKET_TYPE_ACIP_BANDWIDTH_TEST
Bandwidth test request (Client -> ACDS)
Definition packet.h:479
@ PACKET_TYPE_CLEAR_CONSOLE
Server tells client to clear console.
Definition packet.h:395
@ PACKET_TYPE_CRYPTO_NO_ENCRYPTION
Client -> Server: "I want to proceed without encryption" (UNENCRYPTED)
Definition packet.h:325
@ PACKET_TYPE_ACIP_SESSION_CREATE
Create new session (Client -> Discovery Server)
Definition packet.h:407
@ PACKET_TYPE_STATS_UPDATE
Statistics update during collection phase (Participant -> Next Participant)
Definition packet.h:496
@ PACKET_TYPE_ACIP_STRING_RESERVED
String reserved response (Discovery Server -> Client)
Definition packet.h:433
@ PACKET_TYPE_IMAGE_FRAME_H265
H.265-encoded frame from client (HEVC/H.265 codec)
Definition packet.h:365
@ PACKET_TYPE_ACIP_DISCOVERY_PING
Discovery server ping (keepalive)
Definition packet.h:507
@ PACKET_TYPE_CRYPTO_AUTH_CHALLENGE
Server -> Client: {nonce[32]} (UNENCRYPTED)
Definition packet.h:315
@ PACKET_TYPE_ASCII_FRAME
Complete ASCII frame with all metadata.
Definition packet.h:361
@ PACKET_TYPE_CRYPTO_PARAMETERS
Server -> Client: Chosen algorithms + data sizes (UNENCRYPTED)
Definition packet.h:309
@ PACKET_TYPE_ACIP_SESSION_LOOKUP
Lookup session by string (Client -> Discovery Server)
Definition packet.h:411
@ PACKET_TYPE_CRYPTO_CAPABILITIES
Client -> Server: Supported crypto algorithms (UNENCRYPTED)
Definition packet.h:307
@ PACKET_TYPE_RING_ELECTION_RESULT
Final election result (Quorum Leader -> All Participants)
Definition packet.h:498
@ PACKET_TYPE_ACIP_SESSION_LEAVE
Leave session (Client -> Discovery Server)
Definition packet.h:419
@ PACKET_TYPE_ACIP_PARTICIPANT_LEFT
Participant left notification (ACDS -> Remaining Participants)
Definition packet.h:471
@ PACKET_TYPE_ACIP_WEBRTC_SDP
WebRTC SDP offer/answer (bidirectional)
Definition packet.h:426
@ PACKET_TYPE_ACIP_SESSION_JOIN
Join existing session (Client -> Discovery Server)
Definition packet.h:415
@ PACKET_TYPE_ACIP_SESSION_CREATED
Session created response (Discovery Server -> Client)
Definition packet.h:409
@ PACKET_TYPE_STATS_ACK
Acknowledgment of statistics update (Participant -> Sender)
Definition packet.h:500
@ PACKET_TYPE_ACIP_STRING_RELEASE
Release string reservation (Client -> Discovery Server)
Definition packet.h:437
@ PACKET_TYPE_CLIENT_JOIN
Client announces capability to send media.
Definition packet.h:387
@ PACKET_TYPE_CLIENT_CAPABILITIES
Client reports terminal capabilities.
Definition packet.h:381
@ PACKET_TYPE_ACIP_FUTURE_HOST_ELECTED
Future host elected announcement (Quorum Leader -> ACDS -> All Participants)
Definition packet.h:467
@ PACKET_TYPE_ACIP_BANDWIDTH_RESULT
Bandwidth test results (ACDS -> Client)
Definition packet.h:481
@ PACKET_TYPE_ACIP_STRING_RENEW
Renew string reservation (Client -> Discovery Server)
Definition packet.h:435
@ PACKET_TYPE_ERROR_MESSAGE
Error packet with asciichat_error_t code and human-readable message.
Definition packet.h:352
@ PACKET_TYPE_RING_MEMBERS
Ring member list announcement (ACDS -> All Participants)
Definition packet.h:492
@ PACKET_TYPE_PING
Keepalive ping packet.
Definition packet.h:383
@ PACKET_TYPE_AUDIO_BATCH
Batched audio packets for efficiency.
Definition packet.h:372
@ PACKET_TYPE_CRYPTO_REKEY_RESPONSE
Responder -> Initiator: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey)
Definition packet.h:337
@ PACKET_TYPE_ACIP_SESSION_JOINED
Session joined response (Discovery Server -> Client)
Definition packet.h:417
@ PACKET_TYPE_STATS_COLLECTION_START
Start statistics collection phase (Coordinator -> All Participants)
Definition packet.h:494
@ PACKET_TYPE_STREAM_STOP
Client stops sending media.
Definition packet.h:393
@ PACKET_TYPE_ACIP_RING_COLLECT
Ring collect request (Participant -> Next Participant)
Definition packet.h:447
@ PACKET_TYPE_ACIP_SESSION_END
End session (Host -> Discovery Server)
Definition packet.h:421
#define PACKED_ATTR
Packed structure attribute (POSIX: attribute((packed)))
int socket_t
ClangTool/LibTooling compatibility shim for stdbool.h.
ASCII frame packet structure (Packet Type 2)
Definition packet.h:848
uint32_t width
Terminal width in characters.
Definition packet.h:850
uint32_t checksum
CRC32 checksum of original ASCII data.
Definition packet.h:858
uint32_t original_size
Size of original uncompressed ASCII data in bytes.
Definition packet.h:854
uint32_t height
Terminal height in characters.
Definition packet.h:852
uint32_t compressed_size
Size of compressed data (0 = not compressed)
Definition packet.h:856
uint32_t flags
Frame flags bitmask (HAS_COLOR, IS_COMPRESSED, etc.)
Definition packet.h:860
Audio batch packet structure (Packet Type 28)
Definition packet.h:904
uint32_t channels
Number of audio channels (1=mono, 2=stereo)
Definition packet.h:912
uint32_t batch_count
Number of audio chunks in this batch (usually AUDIO_BATCH_COUNT = 32)
Definition packet.h:906
uint32_t sample_rate
Sample rate in Hz (e.g., 44100, 48000)
Definition packet.h:910
uint32_t total_samples
Total audio samples across all chunks (typically 8192)
Definition packet.h:908
Authentication failure packet structure.
Definition packet.h:782
uint8_t reason_flags
Bitmask of auth_failure_reason_t values indicating failure causes.
Definition packet.h:784
Client information packet structure.
Definition packet.h:653
uint32_t client_id
Unique client identifier (1-9, 0 = server)
Definition packet.h:655
uint32_t capabilities
Client capabilities bitmask (CLIENT_CAP_VIDEO | CLIENT_CAP_AUDIO | CLIENT_CAP_COLOR | CLIENT_CAP_STRE...
Definition packet.h:660
Client list packet structure.
Definition packet.h:690
uint32_t client_count
Number of clients in the list (0 to MAX_CLIENTS)
Definition packet.h:692
Crypto capabilities packet structure (Packet Type 14)
Definition packet.h:952
uint8_t preferred_auth
Preferred authentication algorithm (AUTH_ALGO_*)
Definition packet.h:964
uint16_t supported_auth_algorithms
Supported authentication algorithms bitmask (AUTH_ALGO_*)
Definition packet.h:956
uint16_t supported_kex_algorithms
Supported key exchange algorithms bitmask (KEX_ALGO_*)
Definition packet.h:954
uint8_t preferred_cipher
Preferred cipher algorithm (CIPHER_ALGO_*)
Definition packet.h:966
uint16_t supported_cipher_algorithms
Supported cipher algorithms bitmask (CIPHER_ALGO_*)
Definition packet.h:958
uint8_t preferred_kex
Preferred key exchange algorithm (KEX_ALGO_*)
Definition packet.h:962
uint8_t requires_verification
Server verification requirement flag (1=required, 0=optional)
Definition packet.h:960
Cryptographic context structure.
Crypto parameters packet structure (Packet Type 15)
Definition packet.h:981
uint8_t hmac_size
HMAC size in bytes (e.g., 32 for HMAC-SHA256)
Definition packet.h:1003
uint8_t selected_kex
Selected key exchange algorithm (KEX_ALGO_*)
Definition packet.h:983
uint8_t selected_cipher
Selected cipher algorithm (CIPHER_ALGO_*)
Definition packet.h:987
uint16_t auth_public_key_size
Authentication public key size in bytes (e.g., 32 for Ed25519, 1952 for Dilithium3)
Definition packet.h:993
uint8_t selected_auth
Selected authentication algorithm (AUTH_ALGO_*)
Definition packet.h:985
uint8_t verification_enabled
Server verification enabled flag (1=enabled, 0=disabled)
Definition packet.h:989
uint16_t signature_size
Signature size in bytes (e.g., 64 for Ed25519, 3309 for Dilithium3)
Definition packet.h:995
uint8_t nonce_size
Nonce size in bytes (e.g., 24 for XSalsa20)
Definition packet.h:999
uint8_t mac_size
MAC size in bytes (e.g., 16 for Poly1305)
Definition packet.h:1001
uint16_t shared_secret_size
Shared secret size in bytes (e.g., 32 for X25519)
Definition packet.h:997
uint16_t kex_public_key_size
Key exchange public key size in bytes (e.g., 32 for X25519, 1568 for Kyber1024)
Definition packet.h:991
Error packet structure carrying error code and textual description.
Definition packet.h:727
uint32_t message_length
Length of message payload in bytes (0-512)
Definition packet.h:731
uint32_t error_code
Error code from asciichat_error_t enumeration.
Definition packet.h:729
Image frame packet structure (Packet Type 3)
Definition packet.h:876
uint32_t pixel_format
Pixel format enum (1=RGB24, 2=RGBA32, 3=BGR24, 4=BGRA32)
Definition packet.h:882
uint32_t timestamp
Timestamp when frame was captured (milliseconds since epoch)
Definition packet.h:888
uint32_t compressed_size
Compressed data size (0 = not compressed, >0 = compressed)
Definition packet.h:884
uint32_t checksum
CRC32 checksum of pixel data.
Definition packet.h:886
uint32_t height
Image height in pixels.
Definition packet.h:880
uint32_t width
Image width in pixels.
Definition packet.h:878
Packet envelope containing received packet data.
Definition packet.h:1129
void * allocated_buffer
Buffer that needs to be freed by caller (may be NULL if not allocated)
Definition packet.h:1139
size_t allocated_size
Size of allocated buffer in bytes.
Definition packet.h:1141
size_t len
Length of payload data in bytes.
Definition packet.h:1135
void * data
Packet payload data (decrypted and decompressed if applicable)
Definition packet.h:1133
packet_type_t type
Packet type (from packet_types.h)
Definition packet.h:1131
bool was_encrypted
True if packet was encrypted (decrypted before envelope creation)
Definition packet.h:1137
Network packet header structure.
Definition packet.h:598
uint32_t client_id
Client ID (0 = server, >0 = client identifier)
Definition packet.h:608
uint32_t length
Payload data length in bytes (0 for header-only packets)
Definition packet.h:604
uint64_t magic
Magic number (PACKET_MAGIC = 0xA5C11C4A1 "ASCIICHAT" in hex) for packet validation.
Definition packet.h:600
uint16_t type
Packet type (packet_type_t enumeration)
Definition packet.h:602
uint32_t crc32
CRC32 checksum of payload data (0 if length == 0)
Definition packet.h:606
Protocol version negotiation packet structure (Packet Type 1)
Definition packet.h:818
uint8_t compression_threshold
Compression threshold percentage (0-100, e.g., 80 = compress if >80% size reduction)
Definition packet.h:828
uint16_t protocol_revision
Minor protocol revision (server can be newer)
Definition packet.h:822
uint16_t protocol_version
Major protocol version (must match for compatibility)
Definition packet.h:820
uint16_t feature_flags
Feature flags bitmask (FEATURE_RLE_ENCODING, etc.)
Definition packet.h:830
uint8_t compression_algorithms
Supported compression algorithms bitmask (COMPRESS_ALGO_*)
Definition packet.h:826
uint8_t supports_encryption
Encryption & authentication mode bitmask (ACIP_CRYPTO_* constants: NONE, ENCRYPT, AUTH,...
Definition packet.h:824
Remote log packet structure carrying log level and message text.
Definition packet.h:741
uint16_t flags
Additional flags (REMOTE_LOG_FLAG_*)
Definition packet.h:747
uint32_t message_length
Message payload length in bytes (0-512)
Definition packet.h:749
uint8_t log_level
Log level associated with the message (log_level_t cast to uint8_t)
Definition packet.h:743
uint8_t direction
Direction hint so receivers can annotate origin.
Definition packet.h:745
Server state packet structure.
Definition packet.h:706
uint32_t active_client_count
Number of clients actively sending video/audio streams.
Definition packet.h:710
uint32_t connected_client_count
Total number of currently connected clients.
Definition packet.h:708
Terminal size update packet.
Definition packet.h:637
uint32_t height
Terminal height in characters.
Definition packet.h:641
uint32_t width
Terminal width in characters.
Definition packet.h:639
Stream header packet structure.
Definition packet.h:672
uint32_t timestamp
Timestamp when frame/audio was captured (milliseconds since epoch)
Definition packet.h:678
uint32_t stream_type
Stream type bitmask (STREAM_TYPE_VIDEO | STREAM_TYPE_AUDIO)
Definition packet.h:676
uint32_t client_id
Client ID that this stream originates from (1-9)
Definition packet.h:674
Terminal capabilities packet structure (Packet Type 5)
Definition packet.h:1018
uint32_t codec_capabilities_video
Video codec capabilities bitmask (VIDEO_CODEC_CAP_*)
Definition packet.h:1050
uint32_t capabilities
Terminal capabilities bitmask (TERM_CAP_* flags)
Definition packet.h:1020
uint32_t color_level
Color level enum value (terminal_color_mode_t)
Definition packet.h:1022
uint32_t color_count
Actual color count (16, 256, or 16777216)
Definition packet.h:1024
uint16_t height
Terminal height in characters.
Definition packet.h:1030
uint8_t wants_padding
Whether client wants frame padding (1=padding enabled, 0=no padding for snapshot/piped modes)
Definition packet.h:1048
uint32_t render_mode
Render mode enum value (foreground/background/half-block)
Definition packet.h:1026
uint16_t width
Terminal width in characters.
Definition packet.h:1028
uint8_t desired_fps
Client's desired frame rate (1-144 FPS)
Definition packet.h:1044
uint8_t detection_reliable
Detection reliability flag (1=reliable detection, 0=best guess)
Definition packet.h:1036
uint32_t codec_capabilities_audio
Audio codec capabilities bitmask (AUDIO_CODEC_CAP_*)
Definition packet.h:1052
uint32_t palette_type
Palette type enum value (palette_type_t)
Definition packet.h:1040
uint8_t color_filter
Monochromatic color filter enum value (color_filter_t)
Definition packet.h:1046
uint32_t utf8_support
UTF-8 support flag (0=no UTF-8, 1=UTF-8 supported)
Definition packet.h:1038