ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
Packet Types

πŸ“¨ Network protocol packet type definitions and structures More...

Data Structures

struct  packet_header_t
 Network packet header structure. More...
 
struct  size_packet_t
 Terminal size update packet. More...
 
struct  client_info_packet_t
 Client information packet structure. More...
 
struct  stream_header_t
 Stream header packet structure. More...
 
struct  client_list_packet_t
 Client list packet structure. More...
 
struct  server_state_packet_t
 Server state packet structure. More...
 
struct  auth_failure_packet_t
 Authentication failure packet structure. More...
 
struct  protocol_version_packet_t
 Protocol version negotiation packet structure (Packet Type 1) More...
 
struct  ascii_frame_packet_t
 ASCII frame packet structure (Packet Type 2) More...
 
struct  image_frame_packet_t
 Image frame packet structure (Packet Type 3) More...
 
struct  audio_batch_packet_t
 Audio batch packet structure (Packet Type 28) More...
 
struct  crypto_capabilities_packet_t
 Crypto capabilities packet structure (Packet Type 14) More...
 
struct  crypto_parameters_packet_t
 Crypto parameters packet structure (Packet Type 15) More...
 
struct  terminal_capabilities_packet_t
 Terminal capabilities packet structure (Packet Type 5) More...
 

Enumerations

enum  packet_type_t {
  PACKET_TYPE_PROTOCOL_VERSION = 1 , PACKET_TYPE_ASCII_FRAME = 2 , PACKET_TYPE_IMAGE_FRAME = 3 , PACKET_TYPE_AUDIO = 4 ,
  PACKET_TYPE_CLIENT_CAPABILITIES = 5 , PACKET_TYPE_PING = 6 , PACKET_TYPE_PONG = 7 , PACKET_TYPE_CLIENT_JOIN = 8 ,
  PACKET_TYPE_CLIENT_LEAVE = 9 , PACKET_TYPE_STREAM_START = 10 , PACKET_TYPE_STREAM_STOP = 11 , PACKET_TYPE_CLEAR_CONSOLE = 12 ,
  PACKET_TYPE_SERVER_STATE = 13 , PACKET_TYPE_CRYPTO_CAPABILITIES = 14 , PACKET_TYPE_CRYPTO_PARAMETERS = 15 , PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT = 16 ,
  PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP = 17 , PACKET_TYPE_CRYPTO_AUTH_CHALLENGE = 18 , PACKET_TYPE_CRYPTO_AUTH_RESPONSE = 19 , PACKET_TYPE_CRYPTO_AUTH_FAILED = 20 ,
  PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP = 21 , PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE = 22 , PACKET_TYPE_CRYPTO_NO_ENCRYPTION = 23 , PACKET_TYPE_ENCRYPTED = 24 ,
  PACKET_TYPE_CRYPTO_REKEY_REQUEST = 25 , PACKET_TYPE_CRYPTO_REKEY_RESPONSE = 26 , PACKET_TYPE_CRYPTO_REKEY_COMPLETE = 27 , PACKET_TYPE_AUDIO_BATCH = 28 ,
  PACKET_TYPE_SIZE_MESSAGE = 29 , PACKET_TYPE_AUDIO_MESSAGE = 30 , PACKET_TYPE_TEXT_MESSAGE = 31 , PACKET_TYPE_ERROR_MESSAGE = 32 ,
  PACKET_TYPE_REMOTE_LOG = 33 , PACKET_TYPE_AUDIO_OPUS = 34 , PACKET_TYPE_AUDIO_OPUS_BATCH = 35 , PACKET_TYPE_ACIP_SESSION_CREATE = 100 ,
  PACKET_TYPE_ACIP_SESSION_CREATED = 101 , PACKET_TYPE_ACIP_SESSION_LOOKUP = 102 , PACKET_TYPE_ACIP_SESSION_INFO = 103 , PACKET_TYPE_ACIP_SESSION_JOIN = 104 ,
  PACKET_TYPE_ACIP_SESSION_JOINED = 105 , PACKET_TYPE_ACIP_SESSION_LEAVE = 106 , PACKET_TYPE_ACIP_SESSION_END = 107 , PACKET_TYPE_ACIP_SESSION_RECONNECT = 108 ,
  PACKET_TYPE_ACIP_WEBRTC_SDP = 110 , PACKET_TYPE_ACIP_WEBRTC_ICE = 111 , PACKET_TYPE_ACIP_STRING_RESERVE = 120 , PACKET_TYPE_ACIP_STRING_RESERVED = 121 ,
  PACKET_TYPE_ACIP_STRING_RENEW = 122 , PACKET_TYPE_ACIP_STRING_RELEASE = 123 , PACKET_TYPE_ACIP_DISCOVERY_PING = 150 , PACKET_TYPE_ACIP_ERROR = 199
}
 Network protocol packet type enumeration. More...
 
enum  auth_failure_reason_t {
  AUTH_FAIL_PASSWORD_REQUIRED = 0x01 , AUTH_FAIL_PASSWORD_INCORRECT = 0x02 , AUTH_FAIL_CLIENT_KEY_REQUIRED = 0x04 , AUTH_FAIL_CLIENT_KEY_REJECTED = 0x08 ,
  AUTH_FAIL_SIGNATURE_INVALID = 0x10
}
 Authentication failure reason flags. More...
 

Network Protocol Constants

#define LARGE_PACKET_THRESHOLD   (100 * 1024)
 Large packet size threshold (100KB)
 
#define MAX_PACKET_SIZE   ((size_t)5 * 1024 * 1024)
 Maximum packet size (5MB)
 
#define MAX_ERROR_MESSAGE_LENGTH   512
 Maximum error message length (512 bytes)
 
#define MAX_REMOTE_LOG_MESSAGE_LENGTH   512
 Maximum remote log message length (512 bytes)
 

Timeout Configuration Constants

Timeout constants for handling packets of different sizes. Large packets require extended timeouts for successful transmission.

#define BASE_SEND_TIMEOUT   5
 Base send timeout in seconds (5 seconds)
 
#define LARGE_PACKET_EXTRA_TIMEOUT_PER_MB   0.8
 Extra timeout per MB for large packets (0.8 seconds per MB)
 
#define MIN_CLIENT_TIMEOUT   10
 Minimum client timeout in seconds (10 seconds)
 
#define MAX_CLIENT_TIMEOUT   60
 Maximum client timeout in seconds (60 seconds)
 

Audio Batching Constants

Audio batching configuration for efficient audio transmission. Batched audio reduces packet overhead and improves bandwidth usage.

#define AUDIO_BATCH_COUNT   32
 Number of audio chunks per batch (4 chunks)
 
#define AUDIO_BATCH_SAMPLES   (AUDIO_SAMPLES_PER_PACKET * AUDIO_BATCH_COUNT)
 Total samples in audio batch (8192 samples)
 
#define AUDIO_BATCH_MS   186
 Audio batch duration in milliseconds (~186ms)
 
#define AUDIO_SAMPLES_PER_PACKET   256
 Samples per audio packet (256 samples)
 

Protocol Constants

#define PACKET_MAGIC   0xDEADBEEF
 Packet magic number (0xDEADBEEF)
 

Multi-User Protocol Constants

#define ASCIICHAT_DEFAULT_DISPLAY_NAME   "AsciiChatter"
 Default display name for clients without a custom name.
 

Detailed Description

πŸ“¨ Network protocol packet type definitions and structures

Packet Types README

Overview

The packet types system defines all network protocol messages used in ascii-chat. This includes protocol negotiation, media streaming (video/audio), control messages, cryptographic handshake, and multi-user protocol extensions.

Implementation: lib/network/packet_types.h

Key Features:

  • Comprehensive packet type enumeration (33 packet types)
    • Packed structures for wire format compatibility
    • Protocol versioning and capability negotiation
    • Handshake packet detection for crypto routing
    • Network byte order for cross-platform compatibility
    • Magic number validation for packet detection

Packet Categories

Packet types are organized into logical categories:

Protocol Negotiation (Type 1):

  • PACKET_TYPE_PROTOCOL_VERSION: Initial handshake for version and capabilities

Media Packets (Types 2-4, 28):

  • PACKET_TYPE_ASCII_FRAME (2): Complete ASCII art frame with metadata
  • PACKET_TYPE_IMAGE_FRAME (3): Raw RGB image from webcam
  • PACKET_TYPE_AUDIO (4): Single audio packet (legacy)
  • PACKET_TYPE_AUDIO_BATCH (28): Batched audio packets (efficient)

Control Packets (Types 5-7, 12-13):

  • PACKET_TYPE_CLIENT_CAPABILITIES (5): Terminal capabilities report
  • PACKET_TYPE_PING (6): Keepalive ping
  • PACKET_TYPE_PONG (7): Keepalive pong response
  • PACKET_TYPE_CLEAR_CONSOLE (12): Server requests console clear
  • PACKET_TYPE_SERVER_STATE (13): Server broadcasts current state

Multi-User Protocol (Types 8-11):

  • PACKET_TYPE_CLIENT_JOIN (8): Client announces capability to send media
  • PACKET_TYPE_CLIENT_LEAVE (9): Clean disconnect notification
  • PACKET_TYPE_STREAM_START (10): Client requests to start streaming
  • PACKET_TYPE_STREAM_STOP (11): Client stops sending media

Crypto Handshake (Types 14-23):

  • UNENCRYPTED - These packets must NEVER be encrypted
  • PACKET_TYPE_CRYPTO_CAPABILITIES (14): Client β†’ Server: Supported algorithms
  • PACKET_TYPE_CRYPTO_PARAMETERS (15): Server β†’ Client: Chosen algorithms + sizes
  • PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT (16): Server β†’ Client: Server public key
  • PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP (17): Client β†’ Server: Client public key
  • PACKET_TYPE_CRYPTO_AUTH_CHALLENGE (18): Server β†’ Client: Authentication nonce
  • PACKET_TYPE_CRYPTO_AUTH_RESPONSE (19): Client β†’ Server: HMAC response
  • PACKET_TYPE_CRYPTO_AUTH_FAILED (20): Server β†’ Client: Authentication rejected
  • PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP (21): Server β†’ Client: Server proves knowledge
  • PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE (22): Server β†’ Client: Encryption ready
  • PACKET_TYPE_CRYPTO_NO_ENCRYPTION (23): Client β†’ Server: Proceed without encryption
  • PACKET_TYPE_ENCRYPTED (24): Encrypted session packets (after handshake)

Crypto Rekeying (Types 25-27):

  • UNENCRYPTED during rekey - Must bypass encryption during rekey handshake
  • PACKET_TYPE_CRYPTO_REKEY_REQUEST (25): Initiator β†’ Responder: New ephemeral key
  • PACKET_TYPE_CRYPTO_REKEY_RESPONSE (26): Responder β†’ Initiator: New ephemeral key
  • PACKET_TYPE_CRYPTO_REKEY_COMPLETE (27): Encrypted with NEW key (but still handshake)

Message Packets (Types 29-33):

  • PACKET_TYPE_SIZE_MESSAGE (29): Terminal size notification
  • PACKET_TYPE_AUDIO_MESSAGE (30): Audio metadata message
  • PACKET_TYPE_TEXT_MESSAGE (31): Text chat message (future)
  • PACKET_TYPE_ERROR_MESSAGE (32): Protocol/handshake error reporting
  • PACKET_TYPE_REMOTE_LOG (33): Bidirectional remote logging payload

Remote Log Packet (Type 33)

Remote logging packets allow the server and client to forward diagnostic log entries to each other over the established connection. They carry the log level, direction hint, optional flags, and a UTF-8 text payload limited to 512 bytes.

typedef struct {
uint8_t log_level; // Matches log_level_t (LOG_DEV .. LOG_FATAL)
uint8_t direction; // REMOTE_LOG_DIRECTION_* value
uint16_t flags; // REMOTE_LOG_FLAG_* bitmask
uint32_t message_length; // Payload size (0-512)
unsigned short uint16_t
Definition common.h:57
unsigned int uint32_t
Definition common.h:58
unsigned char uint8_t
Definition common.h:56
#define PACKED_ATTR
Packed structure attribute (POSIX: attribute((packed)))
Remote log packet structure carrying log level and message text.
Definition packet.h:633

Direction values**:

  • REMOTE_LOG_DIRECTION_SERVER_TO_CLIENT (1) – Sent by the server to a client
  • REMOTE_LOG_DIRECTION_CLIENT_TO_SERVER (2) – Sent by the client to the server

    Flags**:

  • REMOTE_LOG_FLAG_TRUNCATED – Sender truncated the payload to fit the limit

Messages are encrypted automatically once the crypto handshake completes, but fall back to plaintext during handshake so early errors can still be reported. Receivers must always prefix their local log output with a β€œremote” annotation to make the source of the message obvious.

Packet Structure

Packet Header

All packets begin with a standard header:

typedef struct {
uint32_t magic; // PACKET_MAGIC (0xDEADBEEF) for validation
uint16_t type; // packet_type_t enumeration
uint32_t length; // Payload length in bytes (0 for header-only)
uint32_t crc32; // CRC32 checksum of payload (0 if length == 0)
uint32_t client_id; // Client ID (0 = server, >0 = client identifier)
Network packet header structure.
Definition packet.h:490

Header fields:

  • magic: Must be PACKET_MAGIC (0xDEADBEEF) or packet is invalid
  • type: Packet type enumeration value (packet_type_t, 1-33)
  • length: Payload data length in bytes (0 for header-only packets)
  • crc32: CRC32 checksum of payload data (not including header)
  • client_id: Identifies source (0 for server, 1-9 for clients)

Wire format:

  • Structure is packed (no padding between fields)
  • Total header size: 18 bytes (4+2+4+4+4)
  • Network byte order (big-endian) for multi-byte fields
  • Magic number validation catches corrupted packets

Example packet construction:

packet_header_t header = {
.length = (uint32_t)ascii_frame_size,
.crc32 = crc32_compute(ascii_frame_data, ascii_frame_size),
.client_id = 3 // Frame from client 3
};
uint32_t magic
Magic number (PACKET_MAGIC) for packet validation.
Definition packet.h:492
#define PACKET_MAGIC
Packet magic number (0xDEADBEEF)
Definition packet.h:251
@ PACKET_TYPE_ASCII_FRAME
Complete ASCII frame with all metadata.
Definition packet.h:286

Handshake Packet Detection

Critical function for routing crypto handshake packets:

bool packet_is_handshake_type(packet_type_t type);
packet_type_t
Network protocol packet type enumeration.
Definition packet.h:281

Returns true for:

  • Initial crypto handshake packets (types 14-23)
  • Rekey packets (types 25-27)

Returns false for:

  • All other packet types (including PACKET_TYPE_ENCRYPTED = 24)
  • PACKET_TYPE_ERROR_MESSAGE (32) – sent plaintext only before encryption is active
  • PACKET_TYPE_REMOTE_LOG (33) – encrypted when session keys are ready, plaintext otherwise

    Usage:

    // Before encrypting packet
    if (!packet_is_handshake_type(header.type)) {
    // Encrypt payload
    crypto_encrypt(&ctx, payload, payload_len, ciphertext, &ciphertext_len);
    header.type = PACKET_TYPE_ENCRYPTED; // Override type for encrypted
    header.length = (uint32_t)ciphertext_len;
    } else {
    // Send handshake packet in plaintext
    // header.type remains unchanged
    }
    crypto_result_t crypto_encrypt(crypto_context_t *ctx, const uint8_t *plaintext, size_t plaintext_len, uint8_t *ciphertext_out, size_t ciphertext_out_size, size_t *ciphertext_len_out)
    Encrypt data using XSalsa20-Poly1305.
    uint32_t length
    Payload data length in bytes (0 for header-only packets)
    Definition packet.h:496
    uint16_t type
    Packet type (packet_type_t enumeration)
    Definition packet.h:494
    @ PACKET_TYPE_ENCRYPTED
    Encrypted packet (after handshake completion)
    Definition packet.h:333

    Warning: Encrypting handshake packets will break the crypto handshake. Always check with packet_is_handshake_type() before encryption. Error packets may be sent plaintext prior to handshake completion (or when encryption is disabled), but must be encrypted once a session key is established.

Protocol Negotiation

Protocol Version Packet

First packet exchanged between client and server:

typedef struct {
uint16_t protocol_version; // Major version (e.g., 1)
uint16_t protocol_revision; // Minor revision (e.g., 0)
uint8_t supports_encryption; // 1=yes, 0=no (plaintext mode)
uint8_t compression_algorithms; // Bitmap: COMPRESS_ALGO_ZSTD, etc.
uint8_t compression_threshold; // 0-100 percentage (80 = 80%)
uint16_t feature_flags; // FEATURE_RLE_ENCODING, etc.
uint8_t reserved[7]; // Padding to 16 bytes
Protocol version negotiation packet structure (Packet Type 1)
Definition packet.h:710

Version negotiation flow:

// Client sends version packet
protocol_version_packet_t client_version = {
.protocol_revision = 0,
.supports_encryption = 1,
.compression_algorithms = COMPRESS_ALGO_ZSTD,
.compression_threshold = 80,
.feature_flags = FEATURE_RLE_ENCODING
};
send_packet(socket, PACKET_TYPE_PROTOCOL_VERSION, &client_version, sizeof(client_version));
// Server responds with its version (must match major version)
protocol_version_packet_t server_version = {
.protocol_version = 1, // Must match client
.protocol_revision = 1, // Server supports newer revision
.supports_encryption = 1,
.compression_algorithms = COMPRESS_ALGO_ZSTD,
.compression_threshold = 80,
.feature_flags = FEATURE_RLE_ENCODING
};
send_packet(socket, PACKET_TYPE_PROTOCOL_VERSION, &server_version, sizeof(server_version));
uint16_t protocol_version
Major protocol version (must match for compatibility)
Definition packet.h:712
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:754
@ PACKET_TYPE_PROTOCOL_VERSION
Protocol version and capabilities negotiation.
Definition packet.h:283
#define FEATURE_RLE_ENCODING
Run-length encoding support flag.
#define COMPRESS_ALGO_ZSTD
zstd algorithm

Version compatibility:

  • Major version mismatch: Connection rejected
  • Minor revision mismatch: OK (server uses newer features, client ignores unknown)
  • Compression negotiation: Both parties choose lowest common denominator

Frame Packets

ASCII Frame Packet

Complete ASCII art frame with compression support:

typedef struct {
uint32_t width; // Terminal width in characters
uint32_t height; // Terminal height in characters
uint32_t original_size; // Size of original ASCII data
uint32_t compressed_size; // Size of compressed data (0 = not compressed)
uint32_t checksum; // CRC32 of original ASCII data
uint32_t flags; // Bit flags: HAS_COLOR, IS_COMPRESSED, etc.
ASCII frame packet structure (Packet Type 2)
Definition packet.h:740

Payload structure:

  • Header: ascii_frame_packet_t (24 bytes)
  • Data: char data[original_size] or char compressed_data[compressed_size]

Compression handling:

// Server: Send ASCII frame
.width = 160,
.height = 45,
.original_size = 7200, // 160 * 45
.compressed_size = 0,
.checksum = crc32_compute(ascii_data, 7200),
.flags = FLAG_HAS_COLOR
};
// Compress if beneficial
if (header.original_size > COMPRESS_THRESHOLD) {
compress_data(ascii_data, header.original_size,
compressed_buf, &header.compressed_size);
if (header.compressed_size < header.original_size * 0.8) {
header.flags |= FLAG_IS_COMPRESSED;
// Send compressed data
} else {
header.compressed_size = 0;
// Send uncompressed data
}
}
asciichat_error_t compress_data(const void *input, size_t input_size, void **output, size_t *output_size, int compression_level)
Compress data using zstd with configurable compression level.
Definition compression.c:14
uint32_t original_size
Size of original uncompressed ASCII data in bytes.
Definition packet.h:746
uint32_t compressed_size
Size of compressed data (0 = not compressed)
Definition packet.h:748
uint32_t flags
Frame flags bitmask (HAS_COLOR, IS_COMPRESSED, etc.)
Definition packet.h:752

Image Frame Packet

Raw RGB image from webcam:

typedef struct {
uint32_t width; // Image width in pixels
uint32_t height; // Image height in pixels
uint32_t pixel_format; // 0=RGB24, 1=RGBA32, 2=BGR24, etc.
uint32_t compressed_size; // If >0, image is compressed
uint32_t checksum; // CRC32 of pixel data
uint32_t timestamp; // When frame was captured
Image frame packet structure (Packet Type 3)
Definition packet.h:768

Payload structure:

  • Header: image_frame_packet_t (24 bytes)
  • Data: rgb_pixel_t pixels[width * height] or compressed data

Usage (client β†’ server):

// Capture frame from webcam
uint8_t *rgb_frame = capture_webcam_frame(&width, &height);
// Create image frame packet
.width = width,
.height = height,
.pixel_format = PIXEL_FORMAT_RGB24,
.compressed_size = 0,
.checksum = crc32_compute(rgb_frame, width * height * 3),
.timestamp = get_timestamp()
};
// Send to server
send_packet(socket, PACKET_TYPE_IMAGE_FRAME, &header, sizeof(header));
send_packet_data(socket, rgb_frame, width * height * 3);
uint32_t width
Terminal width in characters.
Definition packet.h:742
@ PACKET_TYPE_IMAGE_FRAME
Complete RGB image with dimensions.
Definition packet.h:288

Audio Packets

Single Audio Packet (Legacy)

PACKET_TYPE_AUDIO (type 4) is the legacy single-packet format:

  • Fixed size: 256 samples per packet
  • Format: float samples[256]
  • Sample rate: Negotiated in protocol version packet
  • Channels: Usually mono (1 channel)

Disadvantages:

  • High packet overhead (1 packet per 256 samples)
  • At 44.1 kHz: 188 packets/second
  • Each packet: 18-byte header + 1024-byte payload = 1042 bytes
  • Total overhead: 188 Γ— 18 = 3.4 KB/sec (0.34% of bandwidth)

Batched Audio Packet (Efficient)

PACKET_TYPE_AUDIO_BATCH (type 28) batches multiple audio chunks:

typedef struct {
uint32_t batch_count; // Number of chunks (usually 4)
uint32_t total_samples; // Total samples across all chunks (1024)
uint32_t sample_rate; // 44100, 48000, etc.
uint32_t channels; // 1=mono, 2=stereo
Audio batch packet structure (Packet Type 28)
Definition packet.h:796

Payload structure:

  • Header: audio_batch_packet_t (16 bytes)
  • Data: float samples[total_samples] (interleaved if stereo)

Benefits:

  • Reduced packet overhead: 4 chunks per packet = 75% fewer packets
  • At 44.1 kHz: 47 packets/second (was 188)
  • Packet overhead: 47 Γ— 18 = 846 bytes/sec (0.08% of bandwidth)
  • 80% reduction in packet overhead

Example:

// Capture 4 audio chunks (256 samples each = 1024 total)
float samples[1024];
capture_audio_chunks(samples, 4);
// Create batch packet
.batch_count = 4,
.total_samples = 1024,
.sample_rate = 44100,
.channels = 1
};
// Send to server
send_packet(socket, PACKET_TYPE_AUDIO_BATCH, &header, sizeof(header));
send_packet_data(socket, samples, sizeof(samples));
@ PACKET_TYPE_AUDIO_BATCH
Batched audio packets for efficiency.
Definition packet.h:343

Control Packets

Client Capabilities

Client reports terminal capabilities to server:

typedef struct {
uint32_t capabilities; // Bitmask: TERM_CAP_* flags
uint32_t color_level; // terminal_color_mode_t enum
uint32_t color_count; // Actual color count (16, 256, 16777216)
uint32_t render_mode; // render_mode_t enum (foreground/background/half-block)
uint16_t width, height; // Terminal dimensions
char term_type[32]; // $TERM value
char colorterm[32]; // $COLORTERM value
uint8_t detection_reliable; // True if detection was reliable
uint32_t utf8_support; // 0=no, 1=yes
uint32_t palette_type; // palette_type_t enum
char palette_custom[64]; // Custom palette chars
uint8_t desired_fps; // Client's desired FPS (1-144)
uint8_t reserved[2];
Terminal capabilities packet structure (Packet Type 5)
Definition packet.h:909

Usage:

.capabilities = TERM_CAP_VIDEO | TERM_CAP_AUDIO | TERM_CAP_COLOR,
.color_level = TERM_COLOR_24BIT,
.color_count = 16777216,
.render_mode = RENDER_MODE_HALF_BLOCK,
.width = 160,
.height = 45,
.detection_reliable = 1,
.utf8_support = 1,
.palette_type = PALETTE_STANDARD,
.desired_fps = 30
};
strncpy(caps.term_type, getenv("TERM"), sizeof(caps.term_type) - 1);
strncpy(caps.colorterm, getenv("COLORTERM"), sizeof(caps.colorterm) - 1);
send_packet(socket, PACKET_TYPE_CLIENT_CAPABILITIES, &caps, sizeof(caps));
uint32_t capabilities
Terminal capabilities bitmask (TERM_CAP_* flags)
Definition packet.h:911
char colorterm[32]
$COLORTERM environment variable value (for debugging)
Definition packet.h:925
char term_type[32]
$TERM environment variable value (for debugging)
Definition packet.h:923
@ PACKET_TYPE_CLIENT_CAPABILITIES
Client reports terminal capabilities.
Definition packet.h:293
@ PALETTE_STANDARD
Standard ASCII palette: " ...',;:clodxkO0KXNWM".
Definition palette.h:86
@ RENDER_MODE_HALF_BLOCK
Unicode half-block characters (mixed foreground/background)
Definition terminal.h:473

Ping/Pong Keepalive

Maintains connection alive and detects dead connections:

// Server: Send ping every 30 seconds
void keepalive_thread(void *arg) {
while (running) {
sleep(30);
packet_header_t ping = {
.length = 0, // No payload
.crc32 = 0,
.client_id = 0 // From server
};
send_packet(socket, PACKET_TYPE_PING, NULL, 0);
}
}
// Client: Respond to ping
void handle_packet(packet_header_t *header, void *payload) {
if (header->type == PACKET_TYPE_PING) {
packet_header_t pong = {
.length = 0,
.crc32 = 0,
.client_id = my_client_id
};
send_packet(socket, PACKET_TYPE_PONG, NULL, 0);
}
}
@ PACKET_TYPE_PONG
Keepalive pong response.
Definition packet.h:297
@ PACKET_TYPE_PING
Keepalive ping packet.
Definition packet.h:295

Crypto Handshake Packets

All crypto handshake packets (types 14-23, 25-27) must be sent UNENCRYPTED. Use packet_is_handshake_type() to check before encryption.

Handshake Flow

Phase 1: Capability Exchange

// Client β†’ Server: Supported algorithms
.supported_auth_algorithms = AUTH_ALGO_ED25519,
.supported_cipher_algorithms = CIPHER_ALGO_XSALSA20_POLY1305,
.requires_verification = 1,
.preferred_kex = KEX_ALGO_X25519,
.preferred_auth = AUTH_ALGO_ED25519,
.preferred_cipher = CIPHER_ALGO_XSALSA20_POLY1305
};
send_packet(socket, PACKET_TYPE_CRYPTO_CAPABILITIES, &client_caps, sizeof(client_caps));
// Server β†’ Client: Chosen algorithms + data sizes
crypto_parameters_packet_t server_params = {
.selected_auth = AUTH_ALGO_ED25519,
.selected_cipher = CIPHER_ALGO_XSALSA20_POLY1305,
.verification_enabled = 1,
.kex_public_key_size = 32, // X25519
.auth_public_key_size = 32, // Ed25519
.signature_size = 64, // Ed25519
.shared_secret_size = 32, // X25519
.nonce_size = 24, // XSalsa20 nonce
.mac_size = 16, // Poly1305 MAC
.hmac_size = 32 // HMAC-SHA256
};
send_packet(socket, PACKET_TYPE_CRYPTO_PARAMETERS, &server_params, sizeof(server_params));
uint8_t selected_kex
Selected key exchange algorithm (KEX_ALGO_*)
Definition packet.h:875
uint16_t supported_kex_algorithms
Supported key exchange algorithms bitmask (KEX_ALGO_*)
Definition packet.h:846
#define AUTH_ALGO_ED25519
Ed25519 authentication (Edwards-curve signatures)
Definition packet.h:950
#define KEX_ALGO_X25519
X25519 key exchange (Curve25519)
Definition packet.h:949
#define CIPHER_ALGO_XSALSA20_POLY1305
XSalsa20-Poly1305 authenticated encryption.
Definition packet.h:952
@ PACKET_TYPE_CRYPTO_PARAMETERS
Server -> Client: Chosen algorithms + data sizes (UNENCRYPTED)
Definition packet.h:315
@ PACKET_TYPE_CRYPTO_CAPABILITIES
Client -> Server: Supported crypto algorithms (UNENCRYPTED)
Definition packet.h:313
Crypto capabilities packet structure (Packet Type 14)
Definition packet.h:844
Crypto parameters packet structure (Packet Type 15)
Definition packet.h:873

Phase 2: Key Exchange

// Server β†’ Client: Server's ephemeral public key
uint8_t server_pubkey[32];
crypto_generate_keypair(server_pubkey, server_secret);
server_pubkey, 32);
// Client β†’ Server: Client's ephemeral public key
uint8_t client_pubkey[32];
crypto_generate_keypair(client_pubkey, client_secret);
client_pubkey, 32);
crypto_result_t crypto_generate_keypair(crypto_context_t *ctx)
Generate new X25519 key pair for key exchange.
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT
Server -> Client: {server_pubkey[32]} (UNENCRYPTED)
Definition packet.h:317
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP
Client -> Server: {client_pubkey[32]} (UNENCRYPTED)
Definition packet.h:319

Phase 3: Authentication

// Server β†’ Client: Authentication challenge nonce
uint8_t challenge[32];
randombytes_buf(challenge, 32);
// Client β†’ Server: HMAC response
uint8_t client_hmac[32];
compute_hmac(client_identity_key, challenge, 32, client_hmac);
// Server verifies HMAC...
// If verification fails:
};
send_packet(socket, PACKET_TYPE_CRYPTO_AUTH_FAILED, &failure, sizeof(failure));
// If verification succeeds:
// Server β†’ Client: Server proves knowledge
uint8_t server_hmac[32];
compute_hmac(server_identity_key, client_hmac, 32, server_hmac);
uint8_t reason_flags
Bitmask of auth_failure_reason_t values indicating failure causes.
Definition packet.h:676
@ AUTH_FAIL_SIGNATURE_INVALID
Client signature verification failed (invalid signature)
Definition packet.h:663
@ PACKET_TYPE_CRYPTO_AUTH_RESPONSE
Client -> Server: {HMAC[32]} (UNENCRYPTED)
Definition packet.h:323
@ PACKET_TYPE_CRYPTO_AUTH_FAILED
Server -> Client: "authentication failed" (UNENCRYPTED)
Definition packet.h:325
@ PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP
Server -> Client: {HMAC[32]} server proves knowledge (UNENCRYPTED)
Definition packet.h:327
@ PACKET_TYPE_CRYPTO_AUTH_CHALLENGE
Server -> Client: {nonce[32]} (UNENCRYPTED)
Definition packet.h:321
Authentication failure packet structure.
Definition packet.h:674

Phase 4: Handshake Complete

// Server β†’ Client: Encryption ready
// Now all subsequent packets use PACKET_TYPE_ENCRYPTED (type 24)
// with encrypted payloads
@ PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE
Server -> Client: "encryption ready" (UNENCRYPTED)
Definition packet.h:329

Multi-User Protocol

Client Join

Client announces capability to send video/audio:

typedef struct {
uint32_t client_id; // Unique client ID
char display_name[MAX_DISPLAY_NAME_LEN]; // User display name
uint32_t capabilities; // Bitmask: CLIENT_CAP_VIDEO | CLIENT_CAP_AUDIO
.client_id = 3,
};
strncpy(join.display_name, "Alice", MAX_DISPLAY_NAME_LEN - 1);
send_packet(socket, PACKET_TYPE_CLIENT_JOIN, &join, sizeof(join));
#define MAX_DISPLAY_NAME_LEN
Maximum display name length in characters.
Definition limits.h:20
char display_name[MAX_DISPLAY_NAME_LEN]
User display name (null-terminated, max MAX_DISPLAY_NAME_LEN bytes)
Definition packet.h:549
uint32_t client_id
Unique client identifier (1-9, 0 = server)
Definition packet.h:547
#define CLIENT_CAP_AUDIO
Client can send/receive audio.
Definition packet.h:816
#define CLIENT_CAP_VIDEO
Client can send/receive video.
Definition packet.h:815
@ PACKET_TYPE_CLIENT_JOIN
Client announces capability to send media.
Definition packet.h:300
Client information packet structure.
Definition packet.h:545

Server State Broadcast

Server broadcasts current state to all clients:

typedef struct {
uint32_t connected_client_count; // Number of connected clients
uint32_t active_client_count; // Number actively sending video
uint32_t reserved[6];
.active_client_count = 3
};
// Broadcast to all clients
for (int i = 0; i < connected_clients; i++) {
&state, sizeof(state));
}
uint32_t connected_client_count
Total number of currently connected clients.
Definition packet.h:600
@ PACKET_TYPE_SERVER_STATE
Server sends current state to clients.
Definition packet.h:310
Server state packet structure.
Definition packet.h:598

Protocol Versioning

ascii-chat uses semantic versioning for protocol compatibility:

Version Format:

  • Major version: Incompatible protocol changes (client/server must match)
  • Minor revision: Backward-compatible additions (server can be newer)

Compatibility Rules:

  • Major version mismatch: Connection rejected
  • Minor revision mismatch: OK (server uses newer features, client ignores unknown)
  • Client sends: protocol_version=1, revision=0
  • Server responds: protocol_version=1, revision=X (X can be >= 0)

Future Protocol Changes:

  • Major version bump: Complete protocol redesign
  • Minor revision bump: New packet types, new flags, extended structures
  • Reserved fields: Structures include reserved fields for future expansion

Wire Format

Byte Order

All multi-byte fields use network byte order (big-endian):

// Host to network (before sending)
header.magic = htonl(PACKET_MAGIC);
header.type = htons(PACKET_TYPE_ASCII_FRAME);
header.length = htonl(payload_length);
header.crc32 = htonl(crc32_value);
header.client_id = htonl(client_id);
// Network to host (after receiving)
header.magic = ntohl(header.magic);
header.type = ntohs(header.type);
header.length = ntohl(header.length);
header.crc32 = ntohl(header.crc32);
header.client_id = ntohl(header.client_id);
uint32_t client_id
Client ID (0 = server, >0 = client identifier)
Definition packet.h:500
uint32_t crc32
CRC32 checksum of payload data (0 if length == 0)
Definition packet.h:498

Platform-specific functions:

  • POSIX: htonl(), htons(), ntohl(), ntohs()
  • Windows: htonl(), htons(), ntohl(), ntohs() (winsock.h)

Structure Packing

Structures are packed (no padding) for wire format compatibility:

#ifdef _WIN32
#pragma pack(push, 1)
#endif
typedef struct {
uint32_t field1; // Offset 0
uint16_t field2; // Offset 4 (not 8, due to packing)
uint32_t field3; // Offset 6 (not 12)
} PACKED_ATTR my_packet_t;
#ifdef _WIN32
#pragma pack(pop)
#endif

Warning: Packed structures may not be naturally aligned. Accessing fields may cause unaligned memory access (slower on some CPUs). ascii-chat structures are designed to avoid this issue.

Best Practices

  1. Always validate magic number:
    if (header.magic != PACKET_MAGIC) {
    log_error("Invalid packet magic: 0x%08X", header.magic);
    }
    @ ERROR_NETWORK_PROTOCOL
    Definition error_codes.h:73
    #define log_error(...)
    Log an ERROR message.
  2. Check handshake types before encryption:
    if (!packet_is_handshake_type(header.type)) {
    // Encrypt payload
    encrypt_packet(&header, payload, payload_len);
    }
  3. Validate payload length:
    if (header.length > MAX_PACKET_SIZE) {
    log_error("Packet too large: %u bytes", header.length);
    }
    #define MAX_PACKET_SIZE
    Maximum packet size (5MB)
    Definition packet.h:113
  4. Verify CRC32 checksums:
    uint32_t computed_crc = crc32_compute(payload, header.length);
    if (computed_crc != header.crc32) {
    log_error("CRC32 mismatch: expected 0x%08X, got 0x%08X",
    header.crc32, computed_crc);
    }
  5. Use network byte order:
    // Before sending
    header.magic = htonl(PACKET_MAGIC);
    header.length = htonl(payload_length);
    // After receiving
    header.magic = ntohl(header.magic);
    header.length = ntohl(header.length);
  6. Handle unknown packet types gracefully:
    switch (header.type) {
    handle_ascii_frame(payload, header.length);
    break;
    // ... known types ...
    default:
    log_warn("Unknown packet type: %u", header.type);
    // Ignore unknown types (forward compatibility)
    break;
    }
    #define log_warn(...)
    Log a WARN message.

Protocol Constants

Packet Size Limits:

#define LARGE_PACKET_THRESHOLD (100 * 1024) // 100 KB - triggers extended timeout
#define MAX_PACKET_SIZE ((size_t)5 * 1024 * 1024) // 5 MB - absolute maximum

Timeout Configuration:

#define BASE_SEND_TIMEOUT 5 // Base timeout in seconds
#define LARGE_PACKET_EXTRA_TIMEOUT_PER_MB 0.8 // Extra timeout per MB
#define MIN_CLIENT_TIMEOUT 10 // Minimum client timeout
#define MAX_CLIENT_TIMEOUT 60 // Maximum client timeout

Audio Configuration:

#define AUDIO_SAMPLES_PER_PACKET 256 // Samples per single audio packet
#define AUDIO_BATCH_COUNT 4 // Chunks per batch packet
#define AUDIO_BATCH_SAMPLES 1024 // Total samples in batch (256 * 4)
#define AUDIO_BATCH_MS 23 // Duration at 44.1 kHz (~23ms)

Magic Numbers:

#define PACKET_MAGIC 0xDEADBEEF // Packet header magic number
#define FRAME_MAGIC 0xDEADBEEF // Frame buffer magic (different context)
#define FRAME_FREED 0xFEEDFACE // Freed frame marker
See also
network/packet_types.h
network/packet.h
network/av.h

Macro Definition Documentation

◆ ASCIICHAT_DEFAULT_DISPLAY_NAME

#define ASCIICHAT_DEFAULT_DISPLAY_NAME   "AsciiChatter"

#include <packet.h>

Default display name for clients without a custom name.

Used when a client connects without specifying a display name.

Definition at line 517 of file packet.h.

◆ AUDIO_BATCH_COUNT

#define AUDIO_BATCH_COUNT   32

#include <packet.h>

Number of audio chunks per batch (4 chunks)

Number of audio chunks aggregated into a single batch packet for efficiency.

Definition at line 204 of file packet.h.

◆ AUDIO_BATCH_MS

#define AUDIO_BATCH_MS   186

#include <packet.h>

Audio batch duration in milliseconds (~186ms)

Approximate duration of audio batch at 44.1kHz sample rate.

Definition at line 223 of file packet.h.

◆ AUDIO_BATCH_SAMPLES

#define AUDIO_BATCH_SAMPLES   (AUDIO_SAMPLES_PER_PACKET * AUDIO_BATCH_COUNT)

#include <packet.h>

Total samples in audio batch (8192 samples)

Total audio samples across all chunks in a batch. At 44.1kHz, this equals ~185.8ms of audio.

Definition at line 214 of file packet.h.

◆ AUDIO_SAMPLES_PER_PACKET

#define AUDIO_SAMPLES_PER_PACKET   256

#include <packet.h>

Samples per audio packet (256 samples)

Number of audio samples in a single audio packet. Smaller packets provide lower latency at the cost of increased packet overhead.

Definition at line 233 of file packet.h.

◆ BASE_SEND_TIMEOUT

#define BASE_SEND_TIMEOUT   5

#include <packet.h>

Base send timeout in seconds (5 seconds)

Default timeout for sending packets. Used as base value for calculating timeouts for large packets.

Definition at line 153 of file packet.h.

◆ LARGE_PACKET_EXTRA_TIMEOUT_PER_MB

#define LARGE_PACKET_EXTRA_TIMEOUT_PER_MB   0.8

#include <packet.h>

Extra timeout per MB for large packets (0.8 seconds per MB)

Additional timeout added per MB for large packets to prevent premature timeout failures.

Definition at line 163 of file packet.h.

◆ LARGE_PACKET_THRESHOLD

#define LARGE_PACKET_THRESHOLD   (100 * 1024)

#include <packet.h>

Large packet size threshold (100KB)

Packets larger than this threshold are considered "large" and may receive extended timeouts or compression treatment.

Definition at line 103 of file packet.h.

◆ MAX_CLIENT_TIMEOUT

#define MAX_CLIENT_TIMEOUT   60

#include <packet.h>

Maximum client timeout in seconds (60 seconds)

Maximum timeout value for client operations. Prevents excessively long waits for dead connections.

Definition at line 183 of file packet.h.

◆ MAX_ERROR_MESSAGE_LENGTH

#define MAX_ERROR_MESSAGE_LENGTH   512

#include <packet.h>

Maximum error message length (512 bytes)

Error packets include a message payload. This defines the maximum number of bytes allowed in the message portion to prevent excessive allocations and potential abuse.

Definition at line 122 of file packet.h.

◆ MAX_PACKET_SIZE

#define MAX_PACKET_SIZE   ((size_t)5 * 1024 * 1024)

#include <packet.h>

Maximum packet size (5MB)

Absolute maximum size for any packet. Packets larger than this are rejected to prevent memory exhaustion attacks.

Definition at line 113 of file packet.h.

◆ MAX_REMOTE_LOG_MESSAGE_LENGTH

#define MAX_REMOTE_LOG_MESSAGE_LENGTH   512

#include <packet.h>

Maximum remote log message length (512 bytes)

Remote logging packets mirror the error packet structure but are intended for diagnostic log forwarding between client and server. Limiting the payload size keeps allocations predictable and prevents log flooding over the network.

Definition at line 132 of file packet.h.

◆ MIN_CLIENT_TIMEOUT

#define MIN_CLIENT_TIMEOUT   10

#include <packet.h>

Minimum client timeout in seconds (10 seconds)

Minimum timeout value for client operations. Set to server timeout plus buffer for reliable operation.

Definition at line 173 of file packet.h.

◆ PACKET_MAGIC

#define PACKET_MAGIC   0xDEADBEEF

#include <packet.h>

Packet magic number (0xDEADBEEF)

Magic number used in packet headers for packet validation. Invalid magic numbers indicate corrupted or invalid packets.

Definition at line 251 of file packet.h.

Enumeration Type Documentation

◆ auth_failure_reason_t

#include <packet.h>

Authentication failure reason flags.

Bitmask enumeration for authentication failure reasons. Multiple flags can be combined to indicate multiple failure causes.

Enumerator
AUTH_FAIL_PASSWORD_REQUIRED 

Server requires password but client didn't provide one.

AUTH_FAIL_PASSWORD_INCORRECT 

Password verification failed (incorrect password)

AUTH_FAIL_CLIENT_KEY_REQUIRED 

Server requires client key but client didn't provide one.

AUTH_FAIL_CLIENT_KEY_REJECTED 

Client key not in whitelist (access denied)

AUTH_FAIL_SIGNATURE_INVALID 

Client signature verification failed (invalid signature)

Definition at line 653 of file packet.h.

653 {
auth_failure_reason_t
Authentication failure reason flags.
Definition packet.h:653
@ AUTH_FAIL_PASSWORD_INCORRECT
Password verification failed (incorrect password)
Definition packet.h:657
@ AUTH_FAIL_PASSWORD_REQUIRED
Server requires password but client didn't provide one.
Definition packet.h:655
@ AUTH_FAIL_CLIENT_KEY_REQUIRED
Server requires client key but client didn't provide one.
Definition packet.h:659
@ AUTH_FAIL_CLIENT_KEY_REJECTED
Client key not in whitelist (access denied)
Definition packet.h:661

◆ packet_type_t

#include <packet.h>

Network protocol packet type enumeration.

Defines all packet types used in the ascii-chat network protocol. Packet types are organized by category: protocol negotiation, frames, audio, control, crypto handshake, multi-user extensions, messages.

PACKET CATEGORIES:

  • 1: Protocol negotiation
  • 2-3: Frame packets (ASCII, image)
  • 4: Audio packets (legacy single)
  • 5-7: Control packets (capabilities, ping/pong)
  • 8-13: Multi-user protocol extensions
  • 14-24: Crypto handshake packets (ALWAYS UNENCRYPTED)
  • 25-27: Crypto rekeying packets (ALWAYS UNENCRYPTED during rekey)
  • 28: Audio batching (efficient)
  • 29-31: Message packets (size, audio, text)
Note
Crypto handshake packets (14-23) and rekey packets (25-27) are ALWAYS sent unencrypted. Use packet_is_handshake_type() to check.
PACKET_TYPE_ENCRYPTED (24) is used for encrypted session packets after handshake completion.
Enumerator
PACKET_TYPE_PROTOCOL_VERSION 

Protocol version and capabilities negotiation.

PACKET_TYPE_ASCII_FRAME 

Complete ASCII frame with all metadata.

PACKET_TYPE_IMAGE_FRAME 

Complete RGB image with dimensions.

PACKET_TYPE_AUDIO 

Single audio packet (legacy)

PACKET_TYPE_CLIENT_CAPABILITIES 

Client reports terminal capabilities.

PACKET_TYPE_PING 

Keepalive ping packet.

PACKET_TYPE_PONG 

Keepalive pong response.

PACKET_TYPE_CLIENT_JOIN 

Client announces capability to send media.

PACKET_TYPE_CLIENT_LEAVE 

Clean disconnect notification.

PACKET_TYPE_STREAM_START 

Client requests to start sending video/audio.

PACKET_TYPE_STREAM_STOP 

Client stops sending media.

PACKET_TYPE_CLEAR_CONSOLE 

Server tells client to clear console.

PACKET_TYPE_SERVER_STATE 

Server sends current state to clients.

PACKET_TYPE_CRYPTO_CAPABILITIES 

Client -> Server: Supported crypto algorithms (UNENCRYPTED)

PACKET_TYPE_CRYPTO_PARAMETERS 

Server -> Client: Chosen algorithms + data sizes (UNENCRYPTED)

PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT 

Server -> Client: {server_pubkey[32]} (UNENCRYPTED)

PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP 

Client -> Server: {client_pubkey[32]} (UNENCRYPTED)

PACKET_TYPE_CRYPTO_AUTH_CHALLENGE 

Server -> Client: {nonce[32]} (UNENCRYPTED)

PACKET_TYPE_CRYPTO_AUTH_RESPONSE 

Client -> Server: {HMAC[32]} (UNENCRYPTED)

PACKET_TYPE_CRYPTO_AUTH_FAILED 

Server -> Client: "authentication failed" (UNENCRYPTED)

PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP 

Server -> Client: {HMAC[32]} server proves knowledge (UNENCRYPTED)

PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE 

Server -> Client: "encryption ready" (UNENCRYPTED)

PACKET_TYPE_CRYPTO_NO_ENCRYPTION 

Client -> Server: "I want to proceed without encryption" (UNENCRYPTED)

PACKET_TYPE_ENCRYPTED 

Encrypted packet (after handshake completion)

PACKET_TYPE_CRYPTO_REKEY_REQUEST 

Initiator -> Responder: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey)

PACKET_TYPE_CRYPTO_REKEY_RESPONSE 

Responder -> Initiator: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey)

PACKET_TYPE_CRYPTO_REKEY_COMPLETE 

Initiator -> Responder: Empty (encrypted with NEW key, but still handshake)

PACKET_TYPE_AUDIO_BATCH 

Batched audio packets for efficiency.

PACKET_TYPE_SIZE_MESSAGE 

Terminal size message.

PACKET_TYPE_AUDIO_MESSAGE 

Audio message.

PACKET_TYPE_TEXT_MESSAGE 

Text message.

PACKET_TYPE_ERROR_MESSAGE 

Error packet with asciichat_error_t code and human-readable message.

PACKET_TYPE_REMOTE_LOG 

Bidirectional remote logging packet.

PACKET_TYPE_AUDIO_OPUS 

Opus-encoded single audio frame.

PACKET_TYPE_AUDIO_OPUS_BATCH 

Batched Opus-encoded audio frames.

PACKET_TYPE_ACIP_SESSION_CREATE 

Create new session (Client -> Discovery Server)

PACKET_TYPE_ACIP_SESSION_CREATED 

Session created response (Discovery Server -> Client)

PACKET_TYPE_ACIP_SESSION_LOOKUP 

Lookup session by string (Client -> Discovery Server)

PACKET_TYPE_ACIP_SESSION_INFO 

Session info response (Discovery Server -> Client)

PACKET_TYPE_ACIP_SESSION_JOIN 

Join existing session (Client -> Discovery Server)

PACKET_TYPE_ACIP_SESSION_JOINED 

Session joined response (Discovery Server -> Client)

PACKET_TYPE_ACIP_SESSION_LEAVE 

Leave session (Client -> Discovery Server)

PACKET_TYPE_ACIP_SESSION_END 

End session (Host -> Discovery Server)

PACKET_TYPE_ACIP_SESSION_RECONNECT 

Reconnect to session (Client -> Discovery Server)

PACKET_TYPE_ACIP_WEBRTC_SDP 

WebRTC SDP offer/answer (bidirectional)

PACKET_TYPE_ACIP_WEBRTC_ICE 

WebRTC ICE candidate (bidirectional)

PACKET_TYPE_ACIP_STRING_RESERVE 

Reserve session string (Client -> Discovery Server)

PACKET_TYPE_ACIP_STRING_RESERVED 

String reserved response (Discovery Server -> Client)

PACKET_TYPE_ACIP_STRING_RENEW 

Renew string reservation (Client -> Discovery Server)

PACKET_TYPE_ACIP_STRING_RELEASE 

Release string reservation (Client -> Discovery Server)

PACKET_TYPE_ACIP_DISCOVERY_PING 

Discovery server ping (keepalive)

PACKET_TYPE_ACIP_ERROR 

Generic error response (Discovery Server -> Client)

Definition at line 281 of file packet.h.

281 {
284
289
298
311
334
341
344
355
360
361 // ============================================================================
362 // Discovery Service Protocol (ACDS)
363 // ============================================================================
364 // ACIP packets use range 100-199 to avoid conflicts with ascii-chat protocol (1-35)
365 // See network/acip/protocol.h for protocol overview and utility functions
366 // See network/acip/acds.h for ACDS message structures and detailed documentation
367
386
391
400
@ PACKET_TYPE_ACIP_WEBRTC_ICE
WebRTC ICE candidate (bidirectional)
Definition packet.h:390
@ PACKET_TYPE_AUDIO_OPUS_BATCH
Batched Opus-encoded audio frames.
Definition packet.h:359
@ PACKET_TYPE_AUDIO_OPUS
Opus-encoded single audio frame.
Definition packet.h:357
@ PACKET_TYPE_CLIENT_LEAVE
Clean disconnect notification.
Definition packet.h:302
@ PACKET_TYPE_ACIP_SESSION_INFO
Session info response (Discovery Server -> Client)
Definition packet.h:375
@ PACKET_TYPE_TEXT_MESSAGE
Text message.
Definition packet.h:350
@ PACKET_TYPE_AUDIO_MESSAGE
Audio message.
Definition packet.h:348
@ PACKET_TYPE_ACIP_SESSION_RECONNECT
Reconnect to session (Client -> Discovery Server)
Definition packet.h:385
@ PACKET_TYPE_STREAM_START
Client requests to start sending video/audio.
Definition packet.h:304
@ PACKET_TYPE_ACIP_ERROR
Generic error response (Discovery Server -> Client)
Definition packet.h:404
@ PACKET_TYPE_AUDIO
Single audio packet (legacy)
Definition packet.h:291
@ PACKET_TYPE_CRYPTO_REKEY_COMPLETE
Initiator -> Responder: Empty (encrypted with NEW key, but still handshake)
Definition packet.h:340
@ PACKET_TYPE_ACIP_STRING_RESERVE
Reserve session string (Client -> Discovery Server)
Definition packet.h:393
@ PACKET_TYPE_CRYPTO_REKEY_REQUEST
Initiator -> Responder: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey)
Definition packet.h:336
@ 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_CLEAR_CONSOLE
Server tells client to clear console.
Definition packet.h:308
@ PACKET_TYPE_CRYPTO_NO_ENCRYPTION
Client -> Server: "I want to proceed without encryption" (UNENCRYPTED)
Definition packet.h:331
@ PACKET_TYPE_ACIP_SESSION_CREATE
Create new session (Client -> Discovery Server)
Definition packet.h:369
@ PACKET_TYPE_ACIP_STRING_RESERVED
String reserved response (Discovery Server -> Client)
Definition packet.h:395
@ PACKET_TYPE_ACIP_DISCOVERY_PING
Discovery server ping (keepalive)
Definition packet.h:402
@ PACKET_TYPE_ACIP_SESSION_LOOKUP
Lookup session by string (Client -> Discovery Server)
Definition packet.h:373
@ PACKET_TYPE_ACIP_SESSION_LEAVE
Leave session (Client -> Discovery Server)
Definition packet.h:381
@ PACKET_TYPE_ACIP_WEBRTC_SDP
WebRTC SDP offer/answer (bidirectional)
Definition packet.h:388
@ PACKET_TYPE_ACIP_SESSION_JOIN
Join existing session (Client -> Discovery Server)
Definition packet.h:377
@ PACKET_TYPE_ACIP_SESSION_CREATED
Session created response (Discovery Server -> Client)
Definition packet.h:371
@ PACKET_TYPE_ACIP_STRING_RELEASE
Release string reservation (Client -> Discovery Server)
Definition packet.h:399
@ PACKET_TYPE_ACIP_STRING_RENEW
Renew string reservation (Client -> Discovery Server)
Definition packet.h:397
@ PACKET_TYPE_ERROR_MESSAGE
Error packet with asciichat_error_t code and human-readable message.
Definition packet.h:352
@ PACKET_TYPE_CRYPTO_REKEY_RESPONSE
Responder -> Initiator: {new_ephemeral_pk[32]} (UNENCRYPTED during rekey)
Definition packet.h:338
@ PACKET_TYPE_ACIP_SESSION_JOINED
Session joined response (Discovery Server -> Client)
Definition packet.h:379
@ PACKET_TYPE_STREAM_STOP
Client stops sending media.
Definition packet.h:306
@ PACKET_TYPE_ACIP_SESSION_END
End session (Host -> Discovery Server)
Definition packet.h:383