ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
packet.h
Go to the documentation of this file.
1
72
73#pragma once
74
75/* Storage capacities in elements; text buffers include the terminating NUL. */
76#define NETWORK_PACKET_TERM_TYPE_BUFFER_SIZE 32
77#define NETWORK_PACKET_COLORTERM_BUFFER_SIZE 32
78#define NETWORK_PACKET_PALETTE_CUSTOM_BUFFER_SIZE 64
79
80/* Existing buffer budgets in bytes, including NUL for text storage. */
81#define ACIP_OPUS_BATCH_HEADER_SIZE 16
82
83#include <libplatform/socket.h>
84#include <libplatform/compiler.h>
85#include "../../crypto/crypto.h"
86#include "../../log/log.h"
87#include "../../util/magic.h"
88#include "../../media/codecs.h"
89#include <stdint.h>
90
91#ifdef __cplusplus
92extern "C" {
93#endif
94#include <stddef.h>
95#include <stdbool.h>
96#include <errno.h>
97
98// Pack network protocol structures tightly for wire format
99#ifdef _WIN32
100#pragma pack(push, 1)
101#endif
102
125
134#define LARGE_PACKET_THRESHOLD (100 * 1024)
135
144#define MAX_PACKET_SIZE ((size_t)5 * 1024 * 1024)
145
153#define MAX_ERROR_MESSAGE_LENGTH 4096
154
163#define MAX_REMOTE_LOG_MESSAGE_LENGTH 512
164
166
175
184#define BASE_SEND_TIMEOUT (5LL * NS_PER_SEC_INT)
185
194#define LARGE_PACKET_EXTRA_TIMEOUT_PER_MB (800LL * NS_PER_MS_INT)
195
204#define MIN_CLIENT_TIMEOUT (10LL * NS_PER_SEC_INT)
205
214#define MAX_CLIENT_TIMEOUT (60LL * NS_PER_SEC_INT)
215
217
226
235#define AUDIO_BATCH_COUNT 32
236
245#define AUDIO_BATCH_SAMPLES (AUDIO_SAMPLES_PER_PACKET * AUDIO_BATCH_COUNT)
246
254#define AUDIO_BATCH_MS 186
255
264#define AUDIO_SAMPLES_PER_PACKET 256
265
267
273
284#define PACKET_MAGIC MAGIC_PACKET_VALID
285
287
315typedef enum {
318
319 // ============================================================================
320 // Cryptographic Operations (Types 1000-1999)
321 // ============================================================================
322
323 // ============================================================================
324 // Cryptographic Client Hello (Types 1000-1099)
325 // ============================================================================
326
329
330 // ============================================================================
331 // Cryptographic Handshake (Types 1100-1199)
332 // ============================================================================
333 // ALWAYS UNENCRYPTED (except ENCRYPTED which wraps encrypted data)
334
362
363 // ============================================================================
364 // Cryptographic Rekeying (Types 1200-1299)
365 // ============================================================================
366 // ALWAYS UNENCRYPTED during rekey phase
367
376
377 // ============================================================================
378 // Message Packets (Types 2000-2999)
379 // ============================================================================
380
391
392 // ============================================================================
393 // Media Frames (Types 3000-3999)
394 // ============================================================================
395
404
405 // ============================================================================
406 // Audio Packets (Types 4000-4999)
407 // ============================================================================
408
413
414 // ============================================================================
415 // Control/State Packets (Types 5000-5999)
416 // ============================================================================
417
436
437 // ============================================================================
438 // Discovery Service Protocol (ACDS) (Types 6000+)
439 // ============================================================================
440 // ACIP packets use range 6000+ for discovery mode operations
441 // See network/acip/protocol.h for protocol overview and utility functions
442 // See network/acip/acds.h for ACDS message structures and detailed documentation
443
462
467
476
477 // ============================================================================
478 // Ring Consensus Protocol (6050-6051)
479 // ============================================================================
480 // Used for proactive future host election every 5 minutes
481
486
487 // ============================================================================
488 // Host Negotiation & Migration Protocol (6060-6069)
489 // ============================================================================
490 // Used by discovery mode for dynamic host selection and failover
491
510
511 // ============================================================================
512 // Bandwidth Testing (6070-6071)
513 // ============================================================================
514 // Used for measuring network bandwidth during NAT quality detection
515
520
523
524 // ============================================================================
525 // Ring Consensus Protocol (6100-6104)
526 // ============================================================================
527 // Used for collecting statistics and coordinating ring-based consensus
528
539
540 // ============================================================================
541 // Discovery Service Keepalive (6190-6199)
542 // ============================================================================
543
549
576static inline bool packet_is_handshake_type(packet_type_t type) {
577 // Client hello for multi-key selection (type 1000)
579 return true;
580 }
581 // Crypto handshake packets (1100-1109)
583 return true;
584 }
585 // Crypto rekey packets (1201-1203)
587 return true;
588 }
589 return false;
590}
591
593static inline bool packet_is_initial_handshake_type(packet_type_t type) {
594 return packet_is_handshake_type(type) && !(type >= PACKET_TYPE_CRYPTO_REKEY_REQUEST && type <= PACKET_TYPE_CRYPTO_REKEY_COMPLETE);
595}
596
615static inline bool packet_is_precompressed(packet_type_t type) {
616 // Opus audio packets are already compressed by Opus codec
617 return (type == PACKET_TYPE_AUDIO_OPUS_BATCH);
618}
619
653PACKED_ATTR packet_header_t;
654
656asciichat_error_t packet_header_build(packet_header_t *header, packet_type_t type, const socket_buffer_t *payload, size_t count, uint32_t client_id);
657asciichat_error_t packet_encode(packet_type_t type, const void *payload, size_t length, uint32_t client_id, void *output, size_t capacity, size_t *written);
660asciichat_error_t packet_validate(const void *packet, size_t length, size_t limit, packet_header_t *header);
661
667
675#define ASCIICHAT_DEFAULT_DISPLAY_NAME "AsciiChatter"
676
678
687typedef struct {
692}
693PACKED_ATTR size_packet_t;
694
712PACKED_ATTR client_info_packet_t;
713
730PACKED_ATTR stream_header_t;
731
747PACKED_ATTR client_list_packet_t;
748
765PACKED_ATTR server_state_packet_t;
766
784PACKED_ATTR error_packet_t;
785
787#define REMOTE_LOG_FLAG_TRUNCATED 0x0001U
788
802PACKED_ATTR remote_log_packet_t;
803
824
833typedef struct {
838}
839PACKED_ATTR auth_failure_packet_t;
840
846
853#define FEATURE_RLE_ENCODING 0x01
854#define FEATURE_DELTA_FRAMES 0x02
855#define PROTOCOL_FEATURE_RECOVERABLE_ERRORS 0x04
856#define PROTOCOL_FEATURE_IDENTITY_SET 0x08
857
859
889PACKED_ATTR protocol_version_packet_t;
890
891#ifdef __cplusplus
892static_assert(sizeof(protocol_version_packet_t) == 16, "protocol version packet wire size must remain 16 bytes");
893#else
894_Static_assert(sizeof(protocol_version_packet_t) == 16, "protocol version packet wire size must remain 16 bytes");
895#endif
896
902void protocol_version_packet_init(protocol_version_packet_t *version, uint8_t supports_encryption);
903
934PACKED_ATTR ascii_frame_packet_t;
935
966PACKED_ATTR image_frame_packet_t;
967
993PACKED_ATTR audio_batch_packet_t;
994
1002#define CLIENT_CAP_VIDEO 0x01
1003#define CLIENT_CAP_AUDIO 0x02
1004#define CLIENT_CAP_COLOR 0x04
1005#define CLIENT_CAP_STRETCH 0x08
1006
1008
1016#define STREAM_TYPE_VIDEO 0x01
1017#define STREAM_TYPE_AUDIO 0x02
1018
1020
1048
1086PACKED_ATTR crypto_parameters_packet_t;
1087
1134
1143#define KEX_ALGO_X25519 0x01
1144#define AUTH_ALGO_ED25519 0x01
1145#define AUTH_ALGO_NONE 0x00
1146#define CIPHER_ALGO_XSALSA20_POLY1305 0x01
1147#define CIPHER_ALGO_NONE 0x00
1148
1161#define ACIP_CRYPTO_NONE 0x00
1162#define ACIP_CRYPTO_ENCRYPT 0x01
1163#define ACIP_CRYPTO_AUTH 0x02
1164#define ACIP_CRYPTO_FULL 0x03
1165
1171#define ACIP_CRYPTO_HAS_ENCRYPT(mode) (((mode) & ACIP_CRYPTO_ENCRYPT) != 0)
1172
1178#define ACIP_CRYPTO_HAS_AUTH(mode) (((mode) & ACIP_CRYPTO_AUTH) != 0)
1179
1181
1183
1184#ifdef _WIN32
1185#pragma pack(pop)
1186#endif
1187
1223
1245
1251
1270asciichat_error_t packet_send(socket_t sockfd, packet_type_t type, const void *data, size_t len);
1271
1291asciichat_error_t packet_receive(socket_t sockfd, packet_type_t *type, void **data, size_t *len);
1292
1294
1300
1324asciichat_error_t send_packet_secure(socket_t sockfd, packet_type_t type, const void *data, size_t len, crypto_context_t *crypto_ctx);
1325
1350packet_recv_result_t receive_packet_secure(socket_t sockfd, void *crypto_ctx, bool enforce_encryption, packet_envelope_t *envelope);
1351packet_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);
1352
1371
1379asciichat_error_t packet_parse_envelope(const void *wire, size_t length, void *crypto_ctx, packet_envelope_t *out);
1380
1383
1385
1394
1410int send_packet(socket_t sockfd, packet_type_t type, const void *data, size_t len);
1411
1429int receive_packet(socket_t sockfd, packet_type_t *type, void **data, size_t *len);
1430
1432
1442
1455int send_ping_packet(socket_t sockfd);
1456
1469int send_pong_packet(socket_t sockfd);
1470
1483asciichat_error_t packet_send_error(socket_t sockfd, const crypto_context_t *crypto_ctx, asciichat_error_t error_code, const char *message);
1484
1491size_t packet_format_error_stack(char *buffer, size_t size);
1492
1503asciichat_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);
1504
1515asciichat_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);
1516
1529asciichat_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,
1530 size_t message_buffer_size, size_t *out_message_length);
1531
1546
1561
1576
1597asciichat_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,
1598 crypto_context_t *crypto_ctx);
1599
1617asciichat_error_t send_image_frame_packet(socket_t sockfd, const void *image_data, uint16_t width, uint16_t height, uint8_t format);
1618
1620
1622uint64_t packet_send_timeout_ns(size_t packet_size);
1623
1624#ifdef __cplusplus
1625}
1626#endif
Video and audio codec definitions and capability bitmasks.
Dedicated worker for all pending errno stacks and handled history. Signal handlers may only request a...
unsigned int height
Definition fft.c:24
unsigned int width
Definition fft.c:24
unsigned short uint16_t
unsigned int uint32_t
unsigned long long uint64_t
unsigned char uint8_t
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
#define MAX_CLIENTS
Maximum possible clients (static array size) - actual runtime limit set by –max-clients (1-128).
#define MAX_DISPLAY_NAME_LEN
Maximum display name length in characters.
enum remote_log_direction remote_log_direction_t
Remote log packet direction enumeration.
log_level_t
Logging levels enumeration.
Definition log/types.h:33
auth_failure_reason_t
Authentication failure reason flags.
Definition packet.h:812
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:471
#define NETWORK_PACKET_COLORTERM_BUFFER_SIZE
Definition packet.h:77
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:885
asciichat_error_t packet_validate(const void *packet, size_t length, size_t limit, packet_header_t *header)
Definition packet.c:81
asciichat_error_t packet_encode(packet_type_t type, const void *payload, size_t length, uint32_t client_id, void *output, size_t capacity, size_t *written)
Definition packet.c:63
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:746
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:830
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:1049
asciichat_error_t packet_parse_envelope(const void *wire, size_t length, void *crypto_ctx, packet_envelope_t *out)
Parse one complete wire packet using the shared client receive path.
Definition packet.c:686
void protocol_version_packet_init(protocol_version_packet_t *version, uint8_t supports_encryption)
Initialize a protocol version packet with the current wire version.
Definition packet.c:37
int send_protocol_version_packet(socket_t sockfd, const protocol_version_packet_t *version)
Send protocol version negotiation packet.
Definition packet.c:942
int send_pong_packet(socket_t sockfd)
Send a pong packet (keepalive response).
Definition packet.c:619
size_t packet_format_error_stack(char *buffer, size_t size)
Format the current thread's error stack for transport to a peer.
Definition packet.c:722
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:388
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:793
#define NETWORK_PACKET_TERM_TYPE_BUFFER_SIZE
Definition packet.h:76
int receive_packet(socket_t sockfd, packet_type_t *type, void **data, size_t *len)
Receive a basic packet without encryption.
Definition packet.c:594
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:639
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:997
packet_type_t
Network protocol packet type enumeration.
Definition packet.h:315
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:581
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:348
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:563
int send_crypto_capabilities_packet(socket_t sockfd, const crypto_capabilities_packet_t *caps)
Send crypto capabilities packet.
Definition packet.c:956
void packet_envelope_release(packet_envelope_t *envelope)
Definition packet.c:711
int send_ping_packet(socket_t sockfd)
Send a ping packet (keepalive).
Definition packet.c:610
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:1106
asciichat_error_t packet_header_build(packet_header_t *header, packet_type_t type, const socket_buffer_t *payload, size_t count, uint32_t client_id)
Definition packet.c:47
int send_crypto_parameters_packet(socket_t sockfd, const crypto_parameters_packet_t *params)
Send crypto parameters packet.
Definition packet.c:970
packet_recv_result_t
packet envelope is intentionally a small, concrete record. Fields such as type, data,...
Definition packet.h:1235
#define NETWORK_PACKET_PALETTE_CUSTOM_BUFFER_SIZE
Definition packet.h:78
@ AUTH_FAIL_PASSWORD_INCORRECT
Password verification failed (incorrect password).
Definition packet.h:816
@ AUTH_FAIL_PASSWORD_REQUIRED
Server requires password but client didn't provide one.
Definition packet.h:814
@ AUTH_FAIL_CLIENT_KEY_REQUIRED
Server requires client key but client didn't provide one.
Definition packet.h:818
@ AUTH_FAIL_CLIENT_KEY_REJECTED
Client key not in whitelist (access denied).
Definition packet.h:820
@ AUTH_FAIL_SIGNATURE_INVALID
Client signature verification failed (invalid signature).
Definition packet.h:822
@ PACKET_TYPE_CRYPTO_CLIENT_HELLO
Client -> Server: Expected server key fingerprint for multi-key selection (UNENCRYPTED).
Definition packet.h:328
@ PACKET_TYPE_ACIP_WEBRTC_ICE
WebRTC ICE candidate (bidirectional).
Definition packet.h:466
@ PACKET_TYPE_QUIC_READY
Internal authenticated readiness barrier for ACIP over QUIC.
Definition packet.h:356
@ PACKET_TYPE_AUDIO_OPUS_BATCH
Batched Opus-encoded audio frames.
Definition packet.h:412
@ PACKET_TYPE_ACIP_PARTICIPANT_JOINED
Participant joined notification (ACDS -> Existing Participants).
Definition packet.h:507
@ PACKET_TYPE_CLIENT_LEAVE
Clean disconnect notification.
Definition packet.h:427
@ PACKET_TYPE_ACIP_SESSION_INFO
Session info response (Discovery Server -> Client).
Definition packet.h:451
@ PACKET_TYPE_IMAGE_FRAME
Complete RGB image with dimensions.
Definition packet.h:399
@ PACKET_TYPE_CRYPTO_AUTH_RESPONSE
Client -> Server: {HMAC[32]} (UNENCRYPTED).
Definition packet.h:346
@ PACKET_TYPE_TEXT_MESSAGE
Text message.
Definition packet.h:386
@ PACKET_TYPE_AUDIO_MESSAGE
Audio message.
Definition packet.h:384
@ PACKET_TYPE_PONG
Keepalive pong response.
Definition packet.h:423
@ PACKET_TYPE_ACIP_SESSION_RECONNECT
Reconnect to session (Client -> Discovery Server).
Definition packet.h:461
@ PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE
Server -> Client: "encryption ready" (UNENCRYPTED).
Definition packet.h:352
@ PACKET_TYPE_ACIP_PARTICIPANT_LIST
Participant list with ring order (ACDS -> Participants).
Definition packet.h:483
@ PACKET_TYPE_STREAM_START
Client requests to start sending video/audio.
Definition packet.h:429
@ PACKET_TYPE_ACIP_SETTINGS_SYNC
Settings sync (Initiator -> Host -> All Participants).
Definition packet.h:499
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT
Server -> Client: {server_pubkey[32]} (UNENCRYPTED).
Definition packet.h:340
@ PACKET_TYPE_ACIP_ERROR
Generic error response (Discovery Server -> Client).
Definition packet.h:547
@ PACKET_TYPE_CRYPTO_EPOCH_MARKER
Definition packet.h:359
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP
Client -> Server: {client_pubkey[32]} (UNENCRYPTED).
Definition packet.h:342
@ PACKET_TYPE_CRYPTO_REKEY_COMPLETE
Initiator -> Responder: Empty (encrypted with NEW key, but still handshake).
Definition packet.h:375
@ PACKET_TYPE_ACIP_NETWORK_QUALITY
NETWORK_QUALITY exchange (unified packet for all quality metrics).
Definition packet.h:493
@ PACKET_TYPE_SERVER_STATE
Server sends current state to clients.
Definition packet.h:435
@ PACKET_TYPE_ACIP_HOST_LOST
Host lost notification - lightweight (Participant -> ACDS).
Definition packet.h:503
@ PACKET_TYPE_ACIP_BROADCAST_ACK
Broadcast acknowledgment for reliable delivery.
Definition packet.h:522
@ PACKET_TYPE_ACIP_HOST_DESIGNATED
Host designated (ACDS -> All Participants).
Definition packet.h:497
@ PACKET_TYPE_ACIP_STRING_RESERVE
Reserve session string (Client -> Discovery Server).
Definition packet.h:469
@ PACKET_TYPE_CRYPTO_AUTH_FAILED
Server -> Client: "authentication failed" (UNENCRYPTED).
Definition packet.h:348
@ PACKET_TYPE_ENCRYPTED
Encrypted packet (after handshake completion).
Definition packet.h:369
@ PACKET_TYPE_CRYPTO_REKEY_REQUEST
Initiator -> Responder: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey).
Definition packet.h:371
@ PACKET_TYPE_SIZE_MESSAGE
Terminal size message.
Definition packet.h:382
@ PACKET_TYPE_REMOTE_LOG
Bidirectional remote logging packet.
Definition packet.h:390
@ PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP
Server -> Client: {HMAC[32]} server proves knowledge (UNENCRYPTED).
Definition packet.h:350
@ PACKET_TYPE_ACIP_HOST_ANNOUNCEMENT
Host announcement (Participant -> ACDS, "I won negotiation").
Definition packet.h:495
@ PACKET_TYPE_PROTOCOL_VERSION
Protocol version and capabilities negotiation.
Definition packet.h:317
@ PACKET_TYPE_ACIP_SETTINGS_ACK
Settings acknowledgment (Participant -> Initiator).
Definition packet.h:501
@ PACKET_TYPE_ACIP_BANDWIDTH_TEST
Bandwidth test request (Client -> ACDS).
Definition packet.h:517
@ PACKET_TYPE_CLEAR_CONSOLE
Server tells client to clear console.
Definition packet.h:433
@ PACKET_TYPE_CRYPTO_EPOCH_ACK
Definition packet.h:361
@ PACKET_TYPE_CRYPTO_NO_ENCRYPTION
Client -> Server: "I want to proceed without encryption" (UNENCRYPTED).
Definition packet.h:354
@ PACKET_TYPE_ACIP_SESSION_CREATE
Create new session (Client -> Discovery Server).
Definition packet.h:445
@ PACKET_TYPE_STATS_UPDATE
Statistics update during collection phase (Participant -> Next Participant).
Definition packet.h:534
@ PACKET_TYPE_ACIP_STRING_RESERVED
String reserved response (Discovery Server -> Client).
Definition packet.h:471
@ PACKET_TYPE_IMAGE_FRAME_H265
H.265-encoded frame from client (HEVC/H.265 codec).
Definition packet.h:401
@ PACKET_TYPE_ACIP_DISCOVERY_PING
Discovery server ping (keepalive).
Definition packet.h:545
@ PACKET_TYPE_CRYPTO_AUTH_CHALLENGE
Server -> Client: {nonce[32]} (UNENCRYPTED).
Definition packet.h:344
@ PACKET_TYPE_ASCII_FRAME
Complete ASCII frame with all metadata.
Definition packet.h:397
@ PACKET_TYPE_CRYPTO_PARAMETERS
Server -> Client: Chosen algorithms + data sizes (UNENCRYPTED).
Definition packet.h:338
@ PACKET_TYPE_ACIP_SESSION_LOOKUP
Lookup session by string (Client -> Discovery Server).
Definition packet.h:449
@ PACKET_TYPE_CRYPTO_CAPABILITIES
Client -> Server: Supported crypto algorithms (UNENCRYPTED).
Definition packet.h:336
@ PACKET_TYPE_RING_ELECTION_RESULT
Final election result (Quorum Leader -> All Participants).
Definition packet.h:536
@ PACKET_TYPE_ACIP_SESSION_LEAVE
Leave session (Client -> Discovery Server).
Definition packet.h:457
@ PACKET_TYPE_ACIP_PARTICIPANT_LEFT
Participant left notification (ACDS -> Remaining Participants).
Definition packet.h:509
@ PACKET_TYPE_ACIP_WEBRTC_SDP
WebRTC SDP offer/answer (bidirectional).
Definition packet.h:464
@ PACKET_TYPE_ACIP_SESSION_JOIN
Join existing session (Client -> Discovery Server).
Definition packet.h:453
@ PACKET_TYPE_ACIP_SESSION_CREATED
Session created response (Discovery Server -> Client).
Definition packet.h:447
@ PACKET_TYPE_CRYPTO_REKEY_NEEDED
Definition packet.h:360
@ PACKET_TYPE_STATS_ACK
Acknowledgment of statistics update (Participant -> Sender).
Definition packet.h:538
@ PACKET_TYPE_ACIP_STRING_RELEASE
Release string reservation (Client -> Discovery Server).
Definition packet.h:475
@ PACKET_TYPE_CLIENT_JOIN
Client announces capability to send media.
Definition packet.h:425
@ PACKET_TYPE_CLIENT_CAPABILITIES
Client reports terminal capabilities.
Definition packet.h:419
@ PACKET_TYPE_ACIP_FUTURE_HOST_ELECTED
Future host elected announcement (Quorum Leader -> ACDS -> All Participants).
Definition packet.h:505
@ PACKET_TYPE_IMAGE_FRAME_H264
Definition packet.h:403
@ PACKET_TYPE_ACIP_BANDWIDTH_RESULT
Bandwidth test results (ACDS -> Client).
Definition packet.h:519
@ PACKET_TYPE_ACIP_STRING_RENEW
Renew string reservation (Client -> Discovery Server).
Definition packet.h:473
@ PACKET_TYPE_ERROR_MESSAGE
Error packet with asciichat_error_t code and human-readable message.
Definition packet.h:388
@ PACKET_TYPE_RING_MEMBERS
Ring member list announcement (ACDS -> All Participants).
Definition packet.h:530
@ PACKET_TYPE_PING
Keepalive ping packet.
Definition packet.h:421
@ PACKET_TYPE_QUIC_KEYFRAME_REQUEST
Internal authenticated request for a QUIC encoded-video keyframe.
Definition packet.h:358
@ PACKET_TYPE_AUDIO_BATCH
Batched audio packets for efficiency.
Definition packet.h:410
@ PACKET_TYPE_CRYPTO_REKEY_RESPONSE
Responder -> Initiator: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey).
Definition packet.h:373
@ PACKET_TYPE_ACIP_SESSION_JOINED
Session joined response (Discovery Server -> Client).
Definition packet.h:455
@ PACKET_TYPE_STATS_COLLECTION_START
Start statistics collection phase (Coordinator -> All Participants).
Definition packet.h:532
@ PACKET_TYPE_STREAM_STOP
Client stops sending media.
Definition packet.h:431
@ PACKET_TYPE_ACIP_RING_COLLECT
Ring collect request (Participant -> Next Participant).
Definition packet.h:485
@ PACKET_TYPE_ACIP_SESSION_END
End session (Host -> Discovery Server).
Definition packet.h:459
@ PACKET_RECV_ERROR
Network error occurred.
Definition packet.h:1241
@ PACKET_RECV_EOF
Connection closed (EOF).
Definition packet.h:1239
@ PACKET_RECV_SECURITY_VIOLATION
Encryption policy violation (e.g., unencrypted packet when encryption required).
Definition packet.h:1243
@ PACKET_RECV_SUCCESS
Packet received successfully.
Definition packet.h:1237
int socket_t
📝 Logging API with multiple log levels and terminal output control
Magic number validation constants and macros.
uint64_t packet_send_timeout_ns(size_t packet_size)
Definition packet.c:111
static bool size_t gotel_query_t * out
Definition queries.h:10
The wire metadata for one rendered ASCII frame. width and height describe the terminal grid,...
Definition packet.h:920
uint32_t width
Terminal width in characters.
Definition packet.h:922
uint32_t checksum
CRC32 checksum of original ASCII data.
Definition packet.h:930
uint32_t original_size
Size of original uncompressed ASCII data in bytes.
Definition packet.h:926
uint32_t height
Terminal height in characters.
Definition packet.h:924
uint32_t compressed_size
Size of compressed data (0 = not compressed).
Definition packet.h:928
uint32_t flags
Frame flags bitmask (HAS_COLOR, IS_COMPRESSED, etc.).
Definition packet.h:932
The metadata prefix for a batch of encoded audio samples. batch_count, total_samples,...
Definition packet.h:983
uint32_t channels
Number of audio channels (1=mono, 2=stereo).
Definition packet.h:991
uint32_t batch_count
Number of audio chunks in this batch (usually AUDIO_BATCH_COUNT = 32).
Definition packet.h:985
uint32_t sample_rate
Sample rate in Hz (e.g., 44100, 48000).
Definition packet.h:989
uint32_t total_samples
Total audio samples across all chunks (typically 8192).
Definition packet.h:987
Authentication failure packet structure.
Definition packet.h:833
uint8_t reserved[7]
Reserved bytes for future use (must be zero).
Definition packet.h:837
uint8_t reason_flags
Bitmask of auth_failure_reason_t values indicating failure causes.
Definition packet.h:835
Client information packet structure.
Definition packet.h:703
char display_name[32]
User display name (null-terminated, max MAX_DISPLAY_NAME_LEN bytes).
Definition packet.h:707
uint32_t client_id
Unique client identifier (1-9, 0 = server).
Definition packet.h:705
uint32_t capabilities
Client capabilities bitmask (CLIENT_CAP_VIDEO | CLIENT_CAP_AUDIO | CLIENT_CAP_COLOR | CLIENT_CAP_STRE...
Definition packet.h:710
Snapshot of the clients currently known to the server.
Definition packet.h:741
uint32_t client_count
Number of clients in the list (0 to MAX_CLIENTS).
Definition packet.h:743
client_info_packet_t clients[128]
Array of client information structures.
Definition packet.h:745
Crypto capabilities packet structure (Packet Type 14).
Definition packet.h:1031
uint8_t preferred_auth
Preferred authentication algorithm (AUTH_ALGO_*).
Definition packet.h:1043
uint16_t supported_auth_algorithms
Supported authentication algorithms bitmask (AUTH_ALGO_*).
Definition packet.h:1035
uint16_t supported_kex_algorithms
Supported key exchange algorithms bitmask (KEX_ALGO_*).
Definition packet.h:1033
uint8_t preferred_cipher
Preferred cipher algorithm (CIPHER_ALGO_*).
Definition packet.h:1045
uint16_t supported_cipher_algorithms
Supported cipher algorithms bitmask (CIPHER_ALGO_*).
Definition packet.h:1037
uint8_t preferred_kex
Preferred key exchange algorithm (KEX_ALGO_*).
Definition packet.h:1041
uint8_t requires_verification
Server verification requirement flag (1=required, 0=optional).
Definition packet.h:1039
Endpoint cryptographic state for handshake, packet protection, authentication, and rekeying.
Crypto parameters packet structure (Packet Type 15).
Definition packet.h:1060
uint8_t hmac_size
HMAC size in bytes (e.g., 32 for HMAC-SHA256).
Definition packet.h:1082
uint8_t selected_kex
Selected key exchange algorithm (KEX_ALGO_*).
Definition packet.h:1062
uint8_t reserved[3]
Reserved bytes for future use (must be zero).
Definition packet.h:1084
uint8_t selected_cipher
Selected cipher algorithm (CIPHER_ALGO_*).
Definition packet.h:1066
uint16_t auth_public_key_size
Authentication public key size in bytes (e.g., 32 for Ed25519, 1952 for Dilithium3).
Definition packet.h:1072
uint8_t selected_auth
Selected authentication algorithm (AUTH_ALGO_*).
Definition packet.h:1064
uint8_t verification_enabled
Server verification enabled flag (1=enabled, 0=disabled).
Definition packet.h:1068
uint16_t signature_size
Signature size in bytes (e.g., 64 for Ed25519, 3309 for Dilithium3).
Definition packet.h:1074
uint8_t nonce_size
Nonce size in bytes (e.g., 24 for XSalsa20).
Definition packet.h:1078
uint8_t mac_size
MAC size in bytes (e.g., 16 for Poly1305).
Definition packet.h:1080
uint16_t shared_secret_size
Shared secret size in bytes (e.g., 32 for X25519).
Definition packet.h:1076
uint16_t kex_public_key_size
Key exchange public key size in bytes (e.g., 32 for X25519, 1568 for Kyber1024).
Definition packet.h:1070
Error packet structure carrying error code and textual description.
Definition packet.h:778
uint32_t message_length
Length of message payload in bytes (0-512).
Definition packet.h:782
uint32_t error_code
Error code from asciichat_error_t enumeration.
Definition packet.h:780
Describes one compressed image sent through ACIP. width, height, and pixel_format tell the decoder ho...
Definition packet.h:952
uint32_t pixel_format
Pixel format enum (1=RGB24, 2=RGBA32, 3=BGR24, 4=BGRA32).
Definition packet.h:958
uint32_t timestamp
Timestamp when frame was captured (milliseconds since epoch).
Definition packet.h:964
uint32_t compressed_size
Compressed data size (0 = not compressed, >0 = compressed).
Definition packet.h:960
uint32_t checksum
CRC32 checksum of pixel data.
Definition packet.h:962
uint32_t height
Image height in pixels.
Definition packet.h:956
uint32_t width
Image width in pixels.
Definition packet.h:954
Packet envelope containing received packet data.
Definition packet.h:1208
void * allocated_buffer
Buffer that needs to be freed by caller (may be NULL if not allocated).
Definition packet.h:1219
bool consumed
Shared security control; never dispatch to the application.
Definition packet.h:1217
size_t allocated_size
Size of allocated buffer in bytes.
Definition packet.h:1221
size_t len
Length of payload data in bytes.
Definition packet.h:1214
void * data
Packet payload data (decrypted and decompressed if applicable).
Definition packet.h:1212
packet_type_t type
Packet type (from packet_types.h).
Definition packet.h:1210
bool was_encrypted
True if packet was encrypted (decrypted before envelope creation).
Definition packet.h:1216
Fixed prefix shared by every ACIP packet on the wire.
Definition packet.h:641
uint32_t client_id
Client ID (0 = server, >0 = client identifier).
Definition packet.h:651
uint32_t length
Payload data length in bytes (0 for header-only packets).
Definition packet.h:647
uint64_t magic
Magic number (PACKET_MAGIC = 0xA5C11C4A1 "ASCIICHAT" in hex) for packet validation.
Definition packet.h:643
uint16_t type
Packet type (packet_type_t enumeration).
Definition packet.h:645
uint32_t crc32
CRC32 checksum of payload data (0 if length == 0).
Definition packet.h:649
Protocol version negotiation packet structure (Packet Type 1).
Definition packet.h:871
uint8_t compression_threshold
Compression threshold percentage (0-100, e.g., 80 = compress if >80% size reduction).
Definition packet.h:883
uint16_t protocol_patch
Patch protocol revision.
Definition packet.h:877
uint16_t protocol_revision
Minor protocol revision (server can be newer).
Definition packet.h:875
uint16_t protocol_version
Major protocol version (must match for compatibility).
Definition packet.h:873
uint8_t reserved[5]
Reserved bytes for future expansion (must be zero).
Definition packet.h:887
uint16_t feature_flags
Feature flags bitmask (FEATURE_RLE_ENCODING, etc.).
Definition packet.h:885
uint8_t compression_algorithms
Supported compression algorithms bitmask (COMPRESS_ALGO_*).
Definition packet.h:881
uint8_t supports_encryption
Encryption & authentication mode bitmask (ACIP_CRYPTO_* constants: NONE, ENCRYPT, AUTH,...
Definition packet.h:879
Remote log packet structure carrying log level and message text.
Definition packet.h:792
uint16_t flags
Additional flags (REMOTE_LOG_FLAG_*).
Definition packet.h:798
uint32_t message_length
Message payload length in bytes (0-512).
Definition packet.h:800
uint8_t log_level
Log level associated with the message (log_level_t cast to uint8_t).
Definition packet.h:794
uint8_t direction
Direction hint so receivers can annotate origin.
Definition packet.h:796
Server state packet structure.
Definition packet.h:757
uint32_t reserved[6]
Reserved fields for future use (must be zero).
Definition packet.h:763
uint32_t active_client_count
Number of clients actively sending video/audio streams.
Definition packet.h:761
uint32_t connected_client_count
Total number of currently connected clients.
Definition packet.h:759
Terminal size update packet.
Definition packet.h:687
uint32_t height
Terminal height in characters.
Definition packet.h:691
uint32_t width
Terminal width in characters.
Definition packet.h:689
Stream header packet structure.
Definition packet.h:722
uint32_t timestamp
Timestamp when frame/audio was captured (milliseconds since epoch).
Definition packet.h:728
uint32_t stream_type
Stream type bitmask (STREAM_TYPE_VIDEO | STREAM_TYPE_AUDIO).
Definition packet.h:726
uint32_t client_id
Client ID that this stream originates from (1-9).
Definition packet.h:724
Terminal capabilities packet structure (Packet Type 5).
Definition packet.h:1097
uint32_t codec_capabilities_video
Video codec capabilities bitmask (VIDEO_CODEC_CAP_*).
Definition packet.h:1129
uint32_t capabilities
Terminal capabilities bitmask (TERM_CAP_* flags).
Definition packet.h:1099
uint32_t color_level
Color level enum value (terminal_color_mode_t).
Definition packet.h:1101
uint32_t color_count
Actual color count (16, 256, or 16777216).
Definition packet.h:1103
uint16_t height
Terminal height in characters.
Definition packet.h:1109
uint8_t wants_padding
Whether client wants frame padding (1=padding enabled, 0=no padding for snapshot/piped modes).
Definition packet.h:1127
uint32_t render_mode
Render mode enum value (foreground/background/half-block).
Definition packet.h:1105
uint16_t width
Terminal width in characters.
Definition packet.h:1107
uint8_t desired_fps
Client's desired frame rate (1-144 FPS).
Definition packet.h:1123
uint8_t detection_reliable
Detection reliability flag (1=reliable detection, 0=best guess).
Definition packet.h:1115
uint32_t codec_capabilities_audio
Audio codec capabilities bitmask (AUDIO_CODEC_CAP_*).
Definition packet.h:1131
char palette_custom[64]
Custom palette characters (if palette_type == PALETTE_CUSTOM).
Definition packet.h:1121
char colorterm[32]
$COLORTERM environment variable value (for debugging)
Definition packet.h:1113
uint32_t palette_type
Palette type enum value (palette_type_t).
Definition packet.h:1119
uint8_t color_filter
Monochromatic color filter enum value (color_filter_t).
Definition packet.h:1125
uint32_t utf8_support
UTF-8 support flag (0=no UTF-8, 1=UTF-8 supported).
Definition packet.h:1117
char term_type[32]
$TERM environment variable value (for debugging)
Definition packet.h:1111