Skip to content

v0.14.0 — torrent

Choose a tag to compare

@ralyodio ralyodio released this 29 Aug 16:58
1d375e8

torrent — make a torrent out of a directory, and get it seeded

torrent create ./album              # writes album.torrent, prints the magnet
torrent seed ./album                # …and hands the magnet to torlnk
torrent magnet album.torrent        # for one you already have
torrent info album.torrent

create-torrent writes a .torrent and never prints a hash; torlnk takes a magnet rather than a file. The two do not meet without something in between, and this is it.

The info hash is computed here, not by adding a dependency — a SHA-1 over the bencoded info dictionary, read verbatim. Decode and re-encode and the hash changes the moment a client wrote a key in an order we did not reproduce, which yields a well-formed magnet for a torrent that does not exist. A test pins our hash against the one a real client computed for a torrent it made itself.

Trackers were checked, not copied. A browser can only ever be a WebRTC peer, so a torrent with no wss:// tracker is invisible to every web player — on the DHT, found by desktop clients, and showing the browser a torrent with no peers, which reads as dead rather than as a missing tracker. Of the announce list the WebTorrent tooling ships by default:

tracker state
tracker.leechers-paradise.org no DNS at all
tracker.coppersurfer.tk UDP connect times out
tracker.empire-js.us UDP connect times out
tracker.btorrent.xyz self-signed cert; a browser refuses it

What ships is two WSS trackers that complete a WebSocket handshake and four UDP trackers that return a connection id.

Other notes

  • --webseed embeds HTTP URLs already serving the same bytes (BEP 19), so the torrent is downloadable before any peer has it. The URL must serve the exact bytes, or it fails its hash check in a way that looks like corruption.
  • --private is opt-in and named: a private torrent is excluded from the DHT by every client honouring the flag — the opposite of the reason to make one here.
  • Seed duration is deliberately not a flag; torlnk's --seed-time is a daemon setting, not per-torrent.

Requirements

npm i -g create-torrent for create. torrent seed also needs torlnk running — and note torlnk installs with pnpm only (pnpm add -g torlnk); npm cannot install it at all.

Upgrading

cli-tools update — the install is symlinks into a working tree, so this pulls and relinks.