Expand description
WebSocket transport protocol shared by the server and the browser client.
Both upload and download use the exact same block-transfer engine over a single WebSocket connection per file:
- The sender pipelines fixed-size blocks without waiting for a per-block
acknowledgment, so blocks may be sent out of order and
throughput is bounded by bandwidth instead of
block_size / RTT. - The receiver verifies every block in real time (CRC32 + bounds) and
marks bad blocks with a
FRAME_NAK; the sender re-adds those indices to its transfer queue. - A wave boundary (
FRAME_WAVE_DONE) triggers a reconciliation round: the receiver replies with aFRAME_REQlisting every block still not verified, which the sender re-queues and re-sends. This repeats until the receiver has verified all blocks, at which point it sendsFRAME_COMPLETE(for downloads the client is the receiver and sends it; for uploads the server is the receiver, commits the file and sends it).
All control commands (handshake, directory listing, metadata) travel over the same WebSocket; nothing uses separate HTTP requests anymore on the client transfer path.
§Frame layout
Every frame is [type: u8][payload: ...]. Control frames carry a JSON
payload; data frames carry a compact binary payload (see the individual
builders/parsers below).
Structs§
- Block
- A decoded
FRAME_BLOCKpayload. - Block
Set - A compact bitset tracking which blocks the receiver has verified good.
- Complete
Message - The
FRAME_COMPLETEpayload (receiver → sender). - Error
Message - The
FRAME_ERRORpayload. - Hello
- The
FRAME_HELLOpayload. - Ready
Reply - The
FRAME_READYpayload (server → client). - Start
Request - The
FRAME_STARTpayload (client → server).
Enums§
- Transfer
Kind - Direction of a transfer.
Constants§
- FRAME_
BLOCK - Block payload (binary):
[index:u32][crc:u32][raw_len:u32][data]. - FRAME_
COMPLETE - Receiver completed the transfer (
CompleteMessage, JSON). - FRAME_
ERROR - Protocol error (
{"code","message"}, JSON). - FRAME_
HELLO - Client → server handshake (
{"protocol","token"}). - FRAME_
HELLO_ OK - Server → client handshake acknowledgment (
{"ok":true}). - FRAME_
LIST_ REPLY - Server → client directory listing reply (
{"path","entries":[...]}). - FRAME_
LIST_ REQ - Client → server directory listing request (
{"path"}). - FRAME_
META_ REPLY - Server → client file metadata reply (
{"path","size","mtime","etag"}). - FRAME_
META_ REQ - Client → server file metadata request (
{"path"}). - FRAME_
NAK - Receiver marks a block bad → sender re-queues it (binary
[index:u32]). - FRAME_
READY - Server → client transfer ready (
ReadyReply). - FRAME_
REQ - Receiver asks the sender to re-send a set of blocks
(binary
[count:u32][index:u32 ...]). - FRAME_
START - Client → server transfer start (
StartRequest). - FRAME_
WAVE_ DONE - Sender finished a wave of blocks (empty payload).
Functions§
- block_
bounds - The absolute
[start, end)byte range of blockindex. - block_
count - The number of blocks covering
sizebytes atblock_size. - block_
frame - Build a
FRAME_BLOCKframe. - block_
offset - The absolute byte offset where block
indexof a transfer that begins at fileoffsetlands. - control_
frame - Build a control frame from a serializable JSON payload.
- crc32
- CRC32 of a byte slice, used to verify every block in real time.
- frame_
payload - Strip the type byte and return the payload slice.
- frame_
type - Read the frame type from the first byte.
- missing_
blocks - The block indices of
size-byte file atblock_sizethat are NOT covered byreceivedranges — the “transfer queue” a sender seeds on resume so it only retransmits the broken/lost parts. - nak_
frame - Build a
FRAME_NAKframe forindex. - parse_
block - Parse a
FRAME_BLOCKframe. - parse_
control - Parse a control frame’s JSON payload into
T. - parse_
nak - Parse the block index out of a
FRAME_NAKframe. - parse_
req - Parse a
FRAME_REQframe into the requested indices. - req_
frame - Build a
FRAME_REQframe for a set of indices. - wave_
done_ frame - A
FRAME_WAVE_DONEframe (empty payload).