BitTorrent metadata files.md
1 --- 2 tags: 3 - bittorrent 4 related-to: 5 - "[[Learn BitTorrent]]" 6 - "[[Advertising BitTorrent content on Codex]]" 7 --- 8 #bittorrent 9 10 | related-to | [[Learn BitTorrent]], [[Advertising BitTorrent content on Codex]] | 11 | ---------- | ----------------------------------------------------------------- | 12 13 Called `torrent` files. 14 15 Although we are using trackerless torrents, still the information contained in torrent files is indispensable and will be provided by the peers using number of extension mechanism. We talk more about it in [[Advertising BitTorrent content on Codex]]. 16 17 ## BitTorrent v1 18 19 Files are split into fixed-size *pieces* of the same length except for maybe the last one that may be truncated. *Almost always* power of two, most commonly 2^18 = 256 KiB (older versions prior to v 3.2 used 2^20 = 1 MiB as default). For directories, the files are concatenated in the order in which they appear in the file list (see the `files` key in the `info` dictionary below). 20 21 Metainfo files, or `.torrent` files are **bencoded** dictionaries with the following keys: 22 23 - announce - the url of the tracker 24 - info - maps to a dictionaries with the following keys: 25 - name - suggested name to save a file or dictionary - purely advisory 26 - piece length - number of bytes each *piece* is split info 27 28 ### BitTorrent v2 29 30 Here the `info` dictionary, has the following keys: 31 32 - `announce` - the url of the tracker 33 - `info` 34 - `file tree` - a three structure describing each file position in the file tree 35 - `length` 36 - `pieces root` - Merkle tree toor for the given file 37 - `piece length` - as in v1, number of bytes each *piece* is split info 38 - `meta version` - set to `2` 39 - `name` - as in v1 above 40 - `piece layers` - dictionary with entries for each file larger than one piece: key being the corresponding `pieces root` and value being string being a concatenation of piece layer hashes for that file. 41 42 We have extensive examples showing how the torrent files are constructed. They can be found under the following url: [https://link.excalidraw.com/readonly/c9z3gLsV1qkTSQJUxEXk](https://link.excalidraw.com/readonly/c9z3gLsV1qkTSQJUxEXk)