ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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#include <stddef.h>
91#include <stdbool.h>
92#include <errno.h>
93
94// Pack network protocol structures tightly for wire format
95#ifdef _WIN32
96#pragma pack(push, 1)
97#endif
98
111
120#define LARGE_PACKET_THRESHOLD (100 * 1024)
121
130#define MAX_PACKET_SIZE ((size_t)5 * 1024 * 1024)
131
139#define MAX_ERROR_MESSAGE_LENGTH 4096
140
149#define MAX_REMOTE_LOG_MESSAGE_LENGTH 512
150
152
161
170#define BASE_SEND_TIMEOUT (5LL * NS_PER_SEC_INT)
171
180#define LARGE_PACKET_EXTRA_TIMEOUT_PER_MB (800LL * NS_PER_MS_INT)
181
190#define MIN_CLIENT_TIMEOUT (10LL * NS_PER_SEC_INT)
191
200#define MAX_CLIENT_TIMEOUT (60LL * NS_PER_SEC_INT)
201
203
212
221#define AUDIO_BATCH_COUNT 32
222
231#define AUDIO_BATCH_SAMPLES (AUDIO_SAMPLES_PER_PACKET * AUDIO_BATCH_COUNT)
232
240#define AUDIO_BATCH_MS 186
241
250#define AUDIO_SAMPLES_PER_PACKET 256
251
253
259
270#define PACKET_MAGIC MAGIC_PACKET_VALID
271
273
301typedef enum {
304
305 // ============================================================================
306 // Cryptographic Operations (Types 1000-1999)
307 // ============================================================================
308
309 // ============================================================================
310 // Cryptographic Client Hello (Types 1000-1099)
311 // ============================================================================
312
315
316 // ============================================================================
317 // Cryptographic Handshake (Types 1100-1199)
318 // ============================================================================
319 // ALWAYS UNENCRYPTED (except ENCRYPTED which wraps encrypted data)
320
348
349 // ============================================================================
350 // Cryptographic Rekeying (Types 1200-1299)
351 // ============================================================================
352 // ALWAYS UNENCRYPTED during rekey phase
353
362
363 // ============================================================================
364 // Message Packets (Types 2000-2999)
365 // ============================================================================
366
377
378 // ============================================================================
379 // Media Frames (Types 3000-3999)
380 // ============================================================================
381
390
391 // ============================================================================
392 // Audio Packets (Types 4000-4999)
393 // ============================================================================
394
399
400 // ============================================================================
401 // Control/State Packets (Types 5000-5999)
402 // ============================================================================
403
422
423 // ============================================================================
424 // Discovery Service Protocol (ACDS) (Types 6000+)
425 // ============================================================================
426 // ACIP packets use range 6000+ for discovery mode operations
427 // See network/acip/protocol.h for protocol overview and utility functions
428 // See network/acip/acds.h for ACDS message structures and detailed documentation
429
448
453
462
463 // ============================================================================
464 // Ring Consensus Protocol (6050-6051)
465 // ============================================================================
466 // Used for proactive future host election every 5 minutes
467
472
473 // ============================================================================
474 // Host Negotiation & Migration Protocol (6060-6069)
475 // ============================================================================
476 // Used by discovery mode for dynamic host selection and failover
477
496
497 // ============================================================================
498 // Bandwidth Testing (6070-6071)
499 // ============================================================================
500 // Used for measuring network bandwidth during NAT quality detection
501
506
509
510 // ============================================================================
511 // Ring Consensus Protocol (6100-6104)
512 // ============================================================================
513 // Used for collecting statistics and coordinating ring-based consensus
514
525
526 // ============================================================================
527 // Discovery Service Keepalive (6190-6199)
528 // ============================================================================
529
535
562static inline bool packet_is_handshake_type(packet_type_t type) {
563 // Client hello for multi-key selection (type 1000)
565 return true;
566 }
567 // Crypto handshake packets (1100-1109)
569 return true;
570 }
571 // Crypto rekey packets (1201-1203)
573 return true;
574 }
575 return false;
576}
577
579static inline bool packet_is_initial_handshake_type(packet_type_t type) {
580 return packet_is_handshake_type(type) &&
582}
583
602static inline bool packet_is_precompressed(packet_type_t type) {
603 // Opus audio packets are already compressed by Opus codec
604 return (type == PACKET_TYPE_AUDIO_OPUS_BATCH);
605}
606
640PACKED_ATTR packet_header_t;
641
643asciichat_error_t packet_header_build(packet_header_t *header, packet_type_t type, const socket_buffer_t *payload,
644 size_t count, uint32_t client_id);
645asciichat_error_t packet_encode(packet_type_t type, const void *payload, size_t length, uint32_t client_id,
646 void *output, size_t capacity, size_t *written);
649asciichat_error_t packet_validate(const void *packet, size_t length, size_t limit, packet_header_t *header);
650
656
664#define ASCIICHAT_DEFAULT_DISPLAY_NAME "AsciiChatter"
665
667
676typedef struct {
681}
682PACKED_ATTR size_packet_t;
683
701PACKED_ATTR client_info_packet_t;
702
719PACKED_ATTR stream_header_t;
720
736PACKED_ATTR client_list_packet_t;
737
754PACKED_ATTR server_state_packet_t;
755
773PACKED_ATTR error_packet_t;
774
776#define REMOTE_LOG_FLAG_TRUNCATED 0x0001U
777
791PACKED_ATTR remote_log_packet_t;
792
813
822typedef struct {
827}
828PACKED_ATTR auth_failure_packet_t;
829
835
842#define FEATURE_RLE_ENCODING 0x01
843#define FEATURE_DELTA_FRAMES 0x02
844#define PROTOCOL_FEATURE_RECOVERABLE_ERRORS 0x04
845#define PROTOCOL_FEATURE_IDENTITY_SET 0x08
846
848
878PACKED_ATTR protocol_version_packet_t;
879
880_Static_assert(sizeof(protocol_version_packet_t) == 16, "protocol version packet wire size must remain 16 bytes");
881
887void protocol_version_packet_init(protocol_version_packet_t *version, uint8_t supports_encryption);
888
916PACKED_ATTR ascii_frame_packet_t;
917
945PACKED_ATTR image_frame_packet_t;
946
970PACKED_ATTR audio_batch_packet_t;
971
979#define CLIENT_CAP_VIDEO 0x01
980#define CLIENT_CAP_AUDIO 0x02
981#define CLIENT_CAP_COLOR 0x04
982#define CLIENT_CAP_STRETCH 0x08
983
985
993#define STREAM_TYPE_VIDEO 0x01
994#define STREAM_TYPE_AUDIO 0x02
995
997
1025
1063PACKED_ATTR crypto_parameters_packet_t;
1064
1111
1120#define KEX_ALGO_X25519 0x01
1121#define AUTH_ALGO_ED25519 0x01
1122#define AUTH_ALGO_NONE 0x00
1123#define CIPHER_ALGO_XSALSA20_POLY1305 0x01
1124#define CIPHER_ALGO_NONE 0x00
1125
1138#define ACIP_CRYPTO_NONE 0x00
1139#define ACIP_CRYPTO_ENCRYPT 0x01
1140#define ACIP_CRYPTO_AUTH 0x02
1141#define ACIP_CRYPTO_FULL 0x03
1142
1148#define ACIP_CRYPTO_HAS_ENCRYPT(mode) (((mode) & ACIP_CRYPTO_ENCRYPT) != 0)
1149
1155#define ACIP_CRYPTO_HAS_AUTH(mode) (((mode) & ACIP_CRYPTO_AUTH) != 0)
1156
1158
1160
1161#ifdef _WIN32
1162#pragma pack(pop)
1163#endif
1164
1200
1220
1226
1245asciichat_error_t packet_send(socket_t sockfd, packet_type_t type, const void *data, size_t len);
1246
1266asciichat_error_t packet_receive(socket_t sockfd, packet_type_t *type, void **data, size_t *len);
1267
1269
1275
1299asciichat_error_t send_packet_secure(socket_t sockfd, packet_type_t type, const void *data, size_t len,
1300 crypto_context_t *crypto_ctx);
1301
1326packet_recv_result_t receive_packet_secure(socket_t sockfd, void *crypto_ctx, bool enforce_encryption,
1327 packet_envelope_t *envelope);
1328packet_recv_result_t receive_packet_secure_with_timeout(socket_t sockfd, void *crypto_ctx, bool enforce_encryption,
1329 packet_envelope_t *envelope, uint64_t timeout_ns);
1330
1349
1351
1360
1376int send_packet(socket_t sockfd, packet_type_t type, const void *data, size_t len);
1377
1395int receive_packet(socket_t sockfd, packet_type_t *type, void **data, size_t *len);
1396
1398
1408
1421int send_ping_packet(socket_t sockfd);
1422
1435int send_pong_packet(socket_t sockfd);
1436
1450 const char *message);
1451
1458size_t packet_format_error_stack(char *buffer, size_t size);
1459
1470asciichat_error_t packet_parse_error_message(const void *data, size_t len, asciichat_error_t *out_error_code,
1471 char *message_buffer, size_t message_buffer_size,
1472 size_t *out_message_length);
1473
1485 remote_log_direction_t direction, uint16_t flags, const char *message);
1486
1499asciichat_error_t packet_parse_remote_log(const void *data, size_t len, log_level_t *out_level,
1500 remote_log_direction_t *out_direction, uint16_t *out_flags,
1501 char *message_buffer, size_t message_buffer_size, size_t *out_message_length);
1502
1517
1532
1547
1568asciichat_error_t av_send_audio_opus_batch(socket_t sockfd, const uint8_t *opus_data, size_t opus_size,
1569 const uint16_t *frame_sizes, int sample_rate, int frame_duration,
1570 int frame_count, crypto_context_t *crypto_ctx);
1571
1590 uint8_t format);
1591
1593
1595uint64_t packet_send_timeout_ns(size_t packet_size);
Video and audio codec definitions and capability bitmasks.
unsigned int height
Definition fft.c:23
unsigned int width
Definition fft.c:23
unsigned short uint16_t
Definition common.h:61
unsigned int uint32_t
Definition common.h:62
unsigned long long uint64_t
Definition common.h:63
unsigned char uint8_t
Definition common.h:60
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
#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 types.h:29
auth_failure_reason_t
Authentication failure reason flags.
Definition packet.h:801
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:492
#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:881
asciichat_error_t packet_validate(const void *packet, size_t length, size_t limit, packet_header_t *header)
Definition packet.c:86
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:67
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:733
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:824
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:1055
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:944
int send_pong_packet(socket_t sockfd)
Send a pong packet (keepalive response).
Definition packet.c:645
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:707
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:407
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:782
#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:620
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:665
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:1000
packet_type_t
Network protocol packet type enumeration.
Definition packet.h:301
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:607
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:366
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:587
int send_crypto_capabilities_packet(socket_t sockfd, const crypto_capabilities_packet_t *caps)
Send crypto capabilities packet.
Definition packet.c:958
int send_ping_packet(socket_t sockfd)
Send a ping packet (keepalive).
Definition packet.c:636
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:1114
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:972
packet_recv_result_t
packet envelope is intentionally a small, concrete record. Fields such as type, data,...
Definition packet.h:1210
#define NETWORK_PACKET_PALETTE_CUSTOM_BUFFER_SIZE
Definition packet.h:78
@ AUTH_FAIL_PASSWORD_INCORRECT
Password verification failed (incorrect password).
Definition packet.h:805
@ AUTH_FAIL_PASSWORD_REQUIRED
Server requires password but client didn't provide one.
Definition packet.h:803
@ AUTH_FAIL_CLIENT_KEY_REQUIRED
Server requires client key but client didn't provide one.
Definition packet.h:807
@ AUTH_FAIL_CLIENT_KEY_REJECTED
Client key not in whitelist (access denied).
Definition packet.h:809
@ AUTH_FAIL_SIGNATURE_INVALID
Client signature verification failed (invalid signature).
Definition packet.h:811
@ PACKET_TYPE_CRYPTO_CLIENT_HELLO
Client -> Server: Expected server key fingerprint for multi-key selection (UNENCRYPTED).
Definition packet.h:314
@ PACKET_TYPE_ACIP_WEBRTC_ICE
WebRTC ICE candidate (bidirectional).
Definition packet.h:452
@ PACKET_TYPE_QUIC_READY
Internal authenticated readiness barrier for ACIP over QUIC.
Definition packet.h:342
@ PACKET_TYPE_AUDIO_OPUS_BATCH
Batched Opus-encoded audio frames.
Definition packet.h:398
@ PACKET_TYPE_ACIP_PARTICIPANT_JOINED
Participant joined notification (ACDS -> Existing Participants).
Definition packet.h:493
@ PACKET_TYPE_CLIENT_LEAVE
Clean disconnect notification.
Definition packet.h:413
@ PACKET_TYPE_ACIP_SESSION_INFO
Session info response (Discovery Server -> Client).
Definition packet.h:437
@ PACKET_TYPE_IMAGE_FRAME
Complete RGB image with dimensions.
Definition packet.h:385
@ PACKET_TYPE_CRYPTO_AUTH_RESPONSE
Client -> Server: {HMAC[32]} (UNENCRYPTED).
Definition packet.h:332
@ PACKET_TYPE_TEXT_MESSAGE
Text message.
Definition packet.h:372
@ PACKET_TYPE_AUDIO_MESSAGE
Audio message.
Definition packet.h:370
@ PACKET_TYPE_PONG
Keepalive pong response.
Definition packet.h:409
@ PACKET_TYPE_ACIP_SESSION_RECONNECT
Reconnect to session (Client -> Discovery Server).
Definition packet.h:447
@ PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE
Server -> Client: "encryption ready" (UNENCRYPTED).
Definition packet.h:338
@ PACKET_TYPE_ACIP_PARTICIPANT_LIST
Participant list with ring order (ACDS -> Participants).
Definition packet.h:469
@ PACKET_TYPE_STREAM_START
Client requests to start sending video/audio.
Definition packet.h:415
@ PACKET_TYPE_ACIP_SETTINGS_SYNC
Settings sync (Initiator -> Host -> All Participants).
Definition packet.h:485
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT
Server -> Client: {server_pubkey[32]} (UNENCRYPTED).
Definition packet.h:326
@ PACKET_TYPE_ACIP_ERROR
Generic error response (Discovery Server -> Client).
Definition packet.h:533
@ PACKET_TYPE_CRYPTO_EPOCH_MARKER
Definition packet.h:345
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP
Client -> Server: {client_pubkey[32]} (UNENCRYPTED).
Definition packet.h:328
@ PACKET_TYPE_CRYPTO_REKEY_COMPLETE
Initiator -> Responder: Empty (encrypted with NEW key, but still handshake).
Definition packet.h:361
@ PACKET_TYPE_ACIP_NETWORK_QUALITY
NETWORK_QUALITY exchange (unified packet for all quality metrics).
Definition packet.h:479
@ PACKET_TYPE_SERVER_STATE
Server sends current state to clients.
Definition packet.h:421
@ PACKET_TYPE_ACIP_HOST_LOST
Host lost notification - lightweight (Participant -> ACDS).
Definition packet.h:489
@ PACKET_TYPE_ACIP_BROADCAST_ACK
Broadcast acknowledgment for reliable delivery.
Definition packet.h:508
@ PACKET_TYPE_ACIP_HOST_DESIGNATED
Host designated (ACDS -> All Participants).
Definition packet.h:483
@ PACKET_TYPE_ACIP_STRING_RESERVE
Reserve session string (Client -> Discovery Server).
Definition packet.h:455
@ PACKET_TYPE_CRYPTO_AUTH_FAILED
Server -> Client: "authentication failed" (UNENCRYPTED).
Definition packet.h:334
@ PACKET_TYPE_ENCRYPTED
Encrypted packet (after handshake completion).
Definition packet.h:355
@ PACKET_TYPE_CRYPTO_REKEY_REQUEST
Initiator -> Responder: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey).
Definition packet.h:357
@ PACKET_TYPE_SIZE_MESSAGE
Terminal size message.
Definition packet.h:368
@ PACKET_TYPE_REMOTE_LOG
Bidirectional remote logging packet.
Definition packet.h:376
@ PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP
Server -> Client: {HMAC[32]} server proves knowledge (UNENCRYPTED).
Definition packet.h:336
@ PACKET_TYPE_ACIP_HOST_ANNOUNCEMENT
Host announcement (Participant -> ACDS, "I won negotiation").
Definition packet.h:481
@ PACKET_TYPE_PROTOCOL_VERSION
Protocol version and capabilities negotiation.
Definition packet.h:303
@ PACKET_TYPE_ACIP_SETTINGS_ACK
Settings acknowledgment (Participant -> Initiator).
Definition packet.h:487
@ PACKET_TYPE_ACIP_BANDWIDTH_TEST
Bandwidth test request (Client -> ACDS).
Definition packet.h:503
@ PACKET_TYPE_CLEAR_CONSOLE
Server tells client to clear console.
Definition packet.h:419
@ PACKET_TYPE_CRYPTO_EPOCH_ACK
Definition packet.h:347
@ PACKET_TYPE_CRYPTO_NO_ENCRYPTION
Client -> Server: "I want to proceed without encryption" (UNENCRYPTED).
Definition packet.h:340
@ PACKET_TYPE_ACIP_SESSION_CREATE
Create new session (Client -> Discovery Server).
Definition packet.h:431
@ PACKET_TYPE_STATS_UPDATE
Statistics update during collection phase (Participant -> Next Participant).
Definition packet.h:520
@ PACKET_TYPE_ACIP_STRING_RESERVED
String reserved response (Discovery Server -> Client).
Definition packet.h:457
@ PACKET_TYPE_IMAGE_FRAME_H265
H.265-encoded frame from client (HEVC/H.265 codec).
Definition packet.h:387
@ PACKET_TYPE_ACIP_DISCOVERY_PING
Discovery server ping (keepalive).
Definition packet.h:531
@ PACKET_TYPE_CRYPTO_AUTH_CHALLENGE
Server -> Client: {nonce[32]} (UNENCRYPTED).
Definition packet.h:330
@ PACKET_TYPE_ASCII_FRAME
Complete ASCII frame with all metadata.
Definition packet.h:383
@ PACKET_TYPE_CRYPTO_PARAMETERS
Server -> Client: Chosen algorithms + data sizes (UNENCRYPTED).
Definition packet.h:324
@ PACKET_TYPE_ACIP_SESSION_LOOKUP
Lookup session by string (Client -> Discovery Server).
Definition packet.h:435
@ PACKET_TYPE_CRYPTO_CAPABILITIES
Client -> Server: Supported crypto algorithms (UNENCRYPTED).
Definition packet.h:322
@ PACKET_TYPE_RING_ELECTION_RESULT
Final election result (Quorum Leader -> All Participants).
Definition packet.h:522
@ PACKET_TYPE_ACIP_SESSION_LEAVE
Leave session (Client -> Discovery Server).
Definition packet.h:443
@ PACKET_TYPE_ACIP_PARTICIPANT_LEFT
Participant left notification (ACDS -> Remaining Participants).
Definition packet.h:495
@ PACKET_TYPE_ACIP_WEBRTC_SDP
WebRTC SDP offer/answer (bidirectional).
Definition packet.h:450
@ PACKET_TYPE_ACIP_SESSION_JOIN
Join existing session (Client -> Discovery Server).
Definition packet.h:439
@ PACKET_TYPE_ACIP_SESSION_CREATED
Session created response (Discovery Server -> Client).
Definition packet.h:433
@ PACKET_TYPE_CRYPTO_REKEY_NEEDED
Definition packet.h:346
@ PACKET_TYPE_STATS_ACK
Acknowledgment of statistics update (Participant -> Sender).
Definition packet.h:524
@ PACKET_TYPE_ACIP_STRING_RELEASE
Release string reservation (Client -> Discovery Server).
Definition packet.h:461
@ PACKET_TYPE_CLIENT_JOIN
Client announces capability to send media.
Definition packet.h:411
@ PACKET_TYPE_CLIENT_CAPABILITIES
Client reports terminal capabilities.
Definition packet.h:405
@ PACKET_TYPE_ACIP_FUTURE_HOST_ELECTED
Future host elected announcement (Quorum Leader -> ACDS -> All Participants).
Definition packet.h:491
@ PACKET_TYPE_IMAGE_FRAME_H264
Definition packet.h:389
@ PACKET_TYPE_ACIP_BANDWIDTH_RESULT
Bandwidth test results (ACDS -> Client).
Definition packet.h:505
@ PACKET_TYPE_ACIP_STRING_RENEW
Renew string reservation (Client -> Discovery Server).
Definition packet.h:459
@ PACKET_TYPE_ERROR_MESSAGE
Error packet with asciichat_error_t code and human-readable message.
Definition packet.h:374
@ PACKET_TYPE_RING_MEMBERS
Ring member list announcement (ACDS -> All Participants).
Definition packet.h:516
@ PACKET_TYPE_PING
Keepalive ping packet.
Definition packet.h:407
@ PACKET_TYPE_QUIC_KEYFRAME_REQUEST
Internal authenticated request for a QUIC encoded-video keyframe.
Definition packet.h:344
@ PACKET_TYPE_AUDIO_BATCH
Batched audio packets for efficiency.
Definition packet.h:396
@ PACKET_TYPE_CRYPTO_REKEY_RESPONSE
Responder -> Initiator: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey).
Definition packet.h:359
@ PACKET_TYPE_ACIP_SESSION_JOINED
Session joined response (Discovery Server -> Client).
Definition packet.h:441
@ PACKET_TYPE_STATS_COLLECTION_START
Start statistics collection phase (Coordinator -> All Participants).
Definition packet.h:518
@ PACKET_TYPE_STREAM_STOP
Client stops sending media.
Definition packet.h:417
@ PACKET_TYPE_ACIP_RING_COLLECT
Ring collect request (Participant -> Next Participant).
Definition packet.h:471
@ PACKET_TYPE_ACIP_SESSION_END
End session (Host -> Discovery Server).
Definition packet.h:445
@ PACKET_RECV_ERROR
Network error occurred.
Definition packet.h:1216
@ PACKET_RECV_EOF
Connection closed (EOF).
Definition packet.h:1214
@ PACKET_RECV_SECURITY_VIOLATION
Encryption policy violation (e.g., unencrypted packet when encryption required).
Definition packet.h:1218
@ PACKET_RECV_SUCCESS
Packet received successfully.
Definition packet.h:1212
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:117
The wire metadata for one rendered ASCII frame. width and height describe the terminal grid,...
Definition packet.h:902
uint32_t width
Terminal width in characters.
Definition packet.h:904
uint32_t checksum
CRC32 checksum of original ASCII data.
Definition packet.h:912
uint32_t original_size
Size of original uncompressed ASCII data in bytes.
Definition packet.h:908
uint32_t height
Terminal height in characters.
Definition packet.h:906
uint32_t compressed_size
Size of compressed data (0 = not compressed).
Definition packet.h:910
uint32_t flags
Frame flags bitmask (HAS_COLOR, IS_COMPRESSED, etc.).
Definition packet.h:914
The metadata prefix for a batch of encoded audio samples. batch_count, total_samples,...
Definition packet.h:960
uint32_t channels
Number of audio channels (1=mono, 2=stereo).
Definition packet.h:968
uint32_t batch_count
Number of audio chunks in this batch (usually AUDIO_BATCH_COUNT = 32).
Definition packet.h:962
uint32_t sample_rate
Sample rate in Hz (e.g., 44100, 48000).
Definition packet.h:966
uint32_t total_samples
Total audio samples across all chunks (typically 8192).
Definition packet.h:964
Authentication failure packet structure.
Definition packet.h:822
uint8_t reserved[7]
Reserved bytes for future use (must be zero).
Definition packet.h:826
uint8_t reason_flags
Bitmask of auth_failure_reason_t values indicating failure causes.
Definition packet.h:824
Client information packet structure.
Definition packet.h:692
char display_name[32]
User display name (null-terminated, max MAX_DISPLAY_NAME_LEN bytes).
Definition packet.h:696
uint32_t client_id
Unique client identifier (1-9, 0 = server).
Definition packet.h:694
uint32_t capabilities
Client capabilities bitmask (CLIENT_CAP_VIDEO | CLIENT_CAP_AUDIO | CLIENT_CAP_COLOR | CLIENT_CAP_STRE...
Definition packet.h:699
Snapshot of the clients currently known to the server.
Definition packet.h:730
uint32_t client_count
Number of clients in the list (0 to MAX_CLIENTS).
Definition packet.h:732
client_info_packet_t clients[128]
Array of client information structures.
Definition packet.h:734
Crypto capabilities packet structure (Packet Type 14).
Definition packet.h:1008
uint8_t preferred_auth
Preferred authentication algorithm (AUTH_ALGO_*).
Definition packet.h:1020
uint16_t supported_auth_algorithms
Supported authentication algorithms bitmask (AUTH_ALGO_*).
Definition packet.h:1012
uint16_t supported_kex_algorithms
Supported key exchange algorithms bitmask (KEX_ALGO_*).
Definition packet.h:1010
uint8_t preferred_cipher
Preferred cipher algorithm (CIPHER_ALGO_*).
Definition packet.h:1022
uint16_t supported_cipher_algorithms
Supported cipher algorithms bitmask (CIPHER_ALGO_*).
Definition packet.h:1014
uint8_t preferred_kex
Preferred key exchange algorithm (KEX_ALGO_*).
Definition packet.h:1018
uint8_t requires_verification
Server verification requirement flag (1=required, 0=optional).
Definition packet.h:1016
Endpoint cryptographic state for handshake, packet protection, authentication, and rekeying.
Crypto parameters packet structure (Packet Type 15).
Definition packet.h:1037
uint8_t hmac_size
HMAC size in bytes (e.g., 32 for HMAC-SHA256).
Definition packet.h:1059
uint8_t selected_kex
Selected key exchange algorithm (KEX_ALGO_*).
Definition packet.h:1039
uint8_t reserved[3]
Reserved bytes for future use (must be zero).
Definition packet.h:1061
uint8_t selected_cipher
Selected cipher algorithm (CIPHER_ALGO_*).
Definition packet.h:1043
uint16_t auth_public_key_size
Authentication public key size in bytes (e.g., 32 for Ed25519, 1952 for Dilithium3).
Definition packet.h:1049
uint8_t selected_auth
Selected authentication algorithm (AUTH_ALGO_*).
Definition packet.h:1041
uint8_t verification_enabled
Server verification enabled flag (1=enabled, 0=disabled).
Definition packet.h:1045
uint16_t signature_size
Signature size in bytes (e.g., 64 for Ed25519, 3309 for Dilithium3).
Definition packet.h:1051
uint8_t nonce_size
Nonce size in bytes (e.g., 24 for XSalsa20).
Definition packet.h:1055
uint8_t mac_size
MAC size in bytes (e.g., 16 for Poly1305).
Definition packet.h:1057
uint16_t shared_secret_size
Shared secret size in bytes (e.g., 32 for X25519).
Definition packet.h:1053
uint16_t kex_public_key_size
Key exchange public key size in bytes (e.g., 32 for X25519, 1568 for Kyber1024).
Definition packet.h:1047
Error packet structure carrying error code and textual description.
Definition packet.h:767
uint32_t message_length
Length of message payload in bytes (0-512).
Definition packet.h:771
uint32_t error_code
Error code from asciichat_error_t enumeration.
Definition packet.h:769
Describes one compressed image sent through ACIP. width, height, and pixel_format tell the decoder ho...
Definition packet.h:931
uint32_t pixel_format
Pixel format enum (1=RGB24, 2=RGBA32, 3=BGR24, 4=BGRA32).
Definition packet.h:937
uint32_t timestamp
Timestamp when frame was captured (milliseconds since epoch).
Definition packet.h:943
uint32_t compressed_size
Compressed data size (0 = not compressed, >0 = compressed).
Definition packet.h:939
uint32_t checksum
CRC32 checksum of pixel data.
Definition packet.h:941
uint32_t height
Image height in pixels.
Definition packet.h:935
uint32_t width
Image width in pixels.
Definition packet.h:933
Packet envelope containing received packet data.
Definition packet.h:1185
void * allocated_buffer
Buffer that needs to be freed by caller (may be NULL if not allocated).
Definition packet.h:1196
bool consumed
Shared security control; never dispatch to the application.
Definition packet.h:1194
size_t allocated_size
Size of allocated buffer in bytes.
Definition packet.h:1198
size_t len
Length of payload data in bytes.
Definition packet.h:1191
void * data
Packet payload data (decrypted and decompressed if applicable).
Definition packet.h:1189
packet_type_t type
Packet type (from packet_types.h).
Definition packet.h:1187
bool was_encrypted
True if packet was encrypted (decrypted before envelope creation).
Definition packet.h:1193
Fixed prefix shared by every ACIP packet on the wire.
Definition packet.h:628
uint32_t client_id
Client ID (0 = server, >0 = client identifier).
Definition packet.h:638
uint32_t length
Payload data length in bytes (0 for header-only packets).
Definition packet.h:634
uint64_t magic
Magic number (PACKET_MAGIC = 0xA5C11C4A1 "ASCIICHAT" in hex) for packet validation.
Definition packet.h:630
uint16_t type
Packet type (packet_type_t enumeration).
Definition packet.h:632
uint32_t crc32
CRC32 checksum of payload data (0 if length == 0).
Definition packet.h:636
Protocol version negotiation packet structure (Packet Type 1).
Definition packet.h:860
uint8_t compression_threshold
Compression threshold percentage (0-100, e.g., 80 = compress if >80% size reduction).
Definition packet.h:872
uint16_t protocol_patch
Patch protocol revision.
Definition packet.h:866
uint16_t protocol_revision
Minor protocol revision (server can be newer).
Definition packet.h:864
uint16_t protocol_version
Major protocol version (must match for compatibility).
Definition packet.h:862
uint8_t reserved[5]
Reserved bytes for future expansion (must be zero).
Definition packet.h:876
uint16_t feature_flags
Feature flags bitmask (FEATURE_RLE_ENCODING, etc.).
Definition packet.h:874
uint8_t compression_algorithms
Supported compression algorithms bitmask (COMPRESS_ALGO_*).
Definition packet.h:870
uint8_t supports_encryption
Encryption & authentication mode bitmask (ACIP_CRYPTO_* constants: NONE, ENCRYPT, AUTH,...
Definition packet.h:868
Remote log packet structure carrying log level and message text.
Definition packet.h:781
uint16_t flags
Additional flags (REMOTE_LOG_FLAG_*).
Definition packet.h:787
uint32_t message_length
Message payload length in bytes (0-512).
Definition packet.h:789
uint8_t log_level
Log level associated with the message (log_level_t cast to uint8_t).
Definition packet.h:783
uint8_t direction
Direction hint so receivers can annotate origin.
Definition packet.h:785
Server state packet structure.
Definition packet.h:746
uint32_t reserved[6]
Reserved fields for future use (must be zero).
Definition packet.h:752
uint32_t active_client_count
Number of clients actively sending video/audio streams.
Definition packet.h:750
uint32_t connected_client_count
Total number of currently connected clients.
Definition packet.h:748
Terminal size update packet.
Definition packet.h:676
uint32_t height
Terminal height in characters.
Definition packet.h:680
uint32_t width
Terminal width in characters.
Definition packet.h:678
Stream header packet structure.
Definition packet.h:711
uint32_t timestamp
Timestamp when frame/audio was captured (milliseconds since epoch).
Definition packet.h:717
uint32_t stream_type
Stream type bitmask (STREAM_TYPE_VIDEO | STREAM_TYPE_AUDIO).
Definition packet.h:715
uint32_t client_id
Client ID that this stream originates from (1-9).
Definition packet.h:713
Terminal capabilities packet structure (Packet Type 5).
Definition packet.h:1074
uint32_t codec_capabilities_video
Video codec capabilities bitmask (VIDEO_CODEC_CAP_*).
Definition packet.h:1106
uint32_t capabilities
Terminal capabilities bitmask (TERM_CAP_* flags).
Definition packet.h:1076
uint32_t color_level
Color level enum value (terminal_color_mode_t).
Definition packet.h:1078
uint32_t color_count
Actual color count (16, 256, or 16777216).
Definition packet.h:1080
uint16_t height
Terminal height in characters.
Definition packet.h:1086
uint8_t wants_padding
Whether client wants frame padding (1=padding enabled, 0=no padding for snapshot/piped modes).
Definition packet.h:1104
uint32_t render_mode
Render mode enum value (foreground/background/half-block).
Definition packet.h:1082
uint16_t width
Terminal width in characters.
Definition packet.h:1084
uint8_t desired_fps
Client's desired frame rate (1-144 FPS).
Definition packet.h:1100
uint8_t detection_reliable
Detection reliability flag (1=reliable detection, 0=best guess).
Definition packet.h:1092
uint32_t codec_capabilities_audio
Audio codec capabilities bitmask (AUDIO_CODEC_CAP_*).
Definition packet.h:1108
char palette_custom[64]
Custom palette characters (if palette_type == PALETTE_CUSTOM).
Definition packet.h:1098
char colorterm[32]
$COLORTERM environment variable value (for debugging)
Definition packet.h:1090
uint32_t palette_type
Palette type enum value (palette_type_t).
Definition packet.h:1096
uint8_t color_filter
Monochromatic color filter enum value (color_filter_t).
Definition packet.h:1102
uint32_t utf8_support
UTF-8 support flag (0=no UTF-8, 1=UTF-8 supported).
Definition packet.h:1094
char term_type[32]
$TERM environment variable value (for debugging)
Definition packet.h:1088