Torrent Schema v

A machine-readable model of BitTorrent in JSON-LD, in the manner of Bitcoin Schema: structures, their bencode keys and value types, derivations, and validity rules. One schema; many projections: a codec with no per-field code, this page, the diagram, the tests.

The whole schema, as layers

Seven modules from the bytes up to the index that finds a torrent, with what flows between them. The boxes are generated from the schema; each is a link to its module. Only the shaded box is data at rest: everything else is messages about it.

The seven modules as layers: nostr finds a torrent, metainfo is the .torrent file, tracker and webtorrent find peers, wire and webseed exchange pieces, bencode encodes everything; arrows carry the infohash down and pieces up

The data model: the .torrent file

Three structs, and that is all of BitTorrent's data at rest. Everything a swarm must agree on is the info dictionary, hashed once; trackers, peers and Nostr events carry that one hash and nothing else that is authoritative, which is why the forty-one other structs are messages, not data. The metainfo structures as a UML class diagram — generated from the schema, so it never drifts. Filled diamonds are composition; /name entries are derived (computed, not stored); ? marks optional fields.

UML class diagram: MetaInfo composed of Info, Info composed of FileEntry; fields and derived values from the schema

Loading schema…