You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ChunkNet is a chunk-based file transfer protocol that provides secure, reliable, and resumable file transfers. This document defines the wire protocol, message formats, and state machines for ChunkNet implementations.
Design Principles
Chunk-based: Files are split into fixed-size chunks for independent transmission
Secure by default: All data is encrypted after handshake
Resumable: Transfers can be resumed from the last acknowledged chunk
Verifiable: Per-chunk checksums and whole-file hash validation
Extensible: Versioned messages with reserved fields for future use
Constants
Name
Value
Description
DEFAULT_PORT
4200
Default listening port
CHUNK_SIZE
262144 (256 KB)
Default chunk size in bytes
MAX_FILENAME_LEN
4096
Maximum filename length
PROTOCOL_VERSION
1
Current protocol version
MAGIC_NUMBER
0x434E4554 ("CNET")
Protocol identifier
Message Format
All messages follow a common header structure using little-endian byte order.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Min Version | Max Version | Capabilities |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Client ID (16 bytes) |
| ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Field
Size
Description
Min Version
1 byte
Minimum supported protocol version
Max Version
1 byte
Maximum supported protocol version
Capabilities
2 bytes
Supported features bitmap
Client ID
16 bytes
Random client identifier (UUID)
Capability Flags
Bit
Name
Description
0
CAP_AES_GCM
Supports AES-256-GCM
1
CAP_CHACHA20
Supports ChaCha20-Poly1305
2
CAP_COMPRESSION
Supports chunk compression
3
CAP_RESUME
Supports transfer resume
4-15
Reserved
Must be zero
HELLO_ACK Message (Type 0x02)
Same format as HELLO. The receiver selects the highest common version and preferred cipher.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Chunk Index (4 bytes) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Status | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Field
Size
Description
Chunk Index
4 bytes
Acknowledged chunk index
Status
1 byte
0=OK, 1=Hash mismatch, 2=Out of order
Reserved
3 bytes
Must be zero
Transfer Completion
TRANSFER_COMPLETE Message (Type 0x30)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Total Chunks Sent (4 bytes) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Total Bytes Sent (8 bytes) |
| ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
TRANSFER_VERIFIED Message (Type 0x31)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Status | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+