Skip to main content

Module files

Module files 

Source
Expand description

File transfer: chunking, reassembly, hash verification, cache, save.

Cache layout: <data_dir>/files/cache/<file_id> // verified, complete <data_dir>/files/cache/<file_id>.part // in-progress reassembly

File-IDs are the SHA-256 hash of the wire bytes (plaintext for non-encrypted offers, ciphertext for encrypted offers — the encryption layer is a separate concern). Receivers verify each completed transfer’s bytes match the announced file_id before exposing the file to the caller.

Modules§

encryption
File encryption for room attachments.

Structs§

CompletedFile
What accept_chunk returns on the chunk that completes the transfer.
FileManager
OutgoingPlan
What prepare_outgoing hands back: enough to drive a sequence of FileOffer + N FileChunk gossipsub messages.

Constants§

CHUNK_SIZE
Bytes per chunk on the wire. A FileChunk is base64-encoded inside a JSON envelope, so the raw chunk must leave room for ~34% base64 expansion plus the envelope and still fit under gossipsub’s transmit limit. 40 KiB raw → ~55 KiB on the wire, comfortably under even the 64 KiB gossipsub default (and well under the 256 KiB ceiling huddle sets explicitly — see network::start_network_with).
MAX_FILE_SIZE
Hard cap on a single offer for Phase 2. Larger files defer to a dedicated libp2p stream protocol (see plan.md Phase 3 notes).

Functions§

guess_mime
Best-effort MIME guess from a filename. Returns None for unknown extensions — receivers should not depend on this being present.