Elamur Groupants⌕
☰

mova-modules-torrent

The groupant beside tools/modules/src/torrent.rs in the Mova repository: what the code computes, what it never does, how to go back from its outputs, its invariants, cost and checks.

Facts

Implementation material. A Mova code model describes this code at one source revision: partial models, finite checks and their stated scope. It is not a reviewed general exposition, and its labels are shown as written, never raised.

Components

componentlabelwhere
approximantpartial source modelforward
astpartialsyntax.json
compositionpartial source modelcomposition
costpartial source modelcost
descriptantpartial source modelepoch-memory
invariantpartial source modelinvariant
testspartial source modelchecks

Obernants

The typed relations around the forward model: the behaviour complement (what the code never does), the reverse reconstruction (every input compatible with an output) and specialised views.

idtypelabelwhere
mova-modules-torrent-behavior-complementbehavior_complementpartial source modelbehavior-complement
mova-modules-torrent-reverse-reconstructionreverse_reconstructionpartial source modelreverse-reconstruction
mova-modules-torrent-canonical-bencodeconstraint_relationpartial source modelinvariant

Model text

forward

Value is a bencode tree whose dictionaries are BTreeMap<Vec<u8>, _> (byte-ordered keys); encode writes BEP 3 bencode. decode parses one value, refusing non-canonical integers, unordered keys and truncation. make(dir, trackers, web_seeds) parses and verifies the module folder, checks URLs (web seeds https:// folders ending in /), orders module.json and the listed files by path, concatenates their bytes into pieces of piece_length(total) (power of two, 256 KiB..16 MiB, at most about 2 000 pieces), SHA-1s each piece, builds info {files [{length, path}], name <name>-<version>, piece length, pieces}, hashes the bencoded info (the info hash), adds a comment with licence and attribution, optional announce/announce-list and url-list, and a magnet link with dn, tr, ws.

invariant

cost

B bytes: one SHA-1 pass O(B) plus the module's SHA-256 verification O(B); memory holds all files (modules are read whole), pieces 20 bytes each.

composition

Called by main_args (make-torrent); reads through crate::Manifest::parse, verify_dir, read_verified.

behavior-complement

Does not: transfer data, contact trackers or DHT, make BitTorrent v2 or hybrid torrents, stream files larger than memory, set a private flag, verify that a web seed actually serves the files.

reverse-reconstruction

From the info dictionary, file names, lengths and order are recoverable exactly; file contents only up to SHA-1 piece collisions (search); the module's licence and attribution only from the outer comment, which is not covered by the info hash.

checks

cargo test --release -p mova-modules torrent (bencode_round_trip_and_canonical_form, a_module_torrent_is_deterministic_and_hashes_its_pieces, piece_length_grows_with_size). Negative controls: unordered keys, a leading zero, a truncated string, an HTTP or non-folder web seed, a changed file.

epoch-memory

2026-11-04, first epoch. No external client was available to load the produced torrent; correctness rests on the recomputed info hash and pieces in the tests. A multi-file web seed is fetched as <seed><name>-<version>/<path> (BEP 19), so a server must expose a <name>-<version>/ folder.

This page in Markdown → https://md.groupants.elamur.ai/free/en/mova/tools/modules/src/torrent.rs.groupant/