Skip to content

Seeding and Downloading

Outcome: one real transfer, watched from both ends — a file hashed on the machine that made it, seeded by one instance, downloaded by a second, and hashed again on arrival to prove the bytes are the same bytes. Evidence: transcripts t04, t05, t06.

The seeder: have the file, offer the file

Instance A already holds field-notes.txt in its save path — the original, hash 3346c8d4…fde5d4. Chapter 6 added the map. With data and map together, the client checks before it boasts: it re-reads the file and verifies every piece hash in the map. Three seconds after the add, t04 shows the verdict:

{"name": "field-notes.txt",
 "state": "stalledUP", "progress": 1,
 "size": 2097152, "amount_left": 0,
 "num_seeds": 0, "num_leechs": 0}

progress: 1, nothing left to fetch, state stalledUP: complete, offering, and — the honest part — connected to nobody. A seeder with no peers is just a file with good intentions. If the file had not matched the map, the check would have said so in pieces: progress would report only the share of pieces that verified, and the client would quietly treat the rest as still to download (chapter 8 makes a recheck happen on purpose).

The downloader: a map, and silence

Instance B — its own profile, WebUI on 18089, torrenting port 48189, its save path empty — takes the same map. Its first report (t05) is the mirror image:

{"state": "stalledDL", "progress": 0,
 "num_seeds": 0, "num_leechs": 0, "dlspeed": 0}

stalledDL is a precise diagnosis: the job is started, the map is good, and there is nobody to ask. The torrent names no tracker; B's DHT, PeX and LSD are off (chapter 5); A is ten ports away on the same machine and B has no way to know. Most real-world "stuck at 0%" is this state wearing different clothes — the remedy is always about finding peers, never about restarting the client.

The introduction: addPeers

BitTorrent lets a client be told where a peer lives. The API call is torrents/addPeers, and it is the only introduction these two instances ever get (t06):

curl -s -b cookies-b.txt --data \
  'hashes=53b631ea…&peers=127.0.0.1:48188' \
  http://127.0.0.1:18089/api/v2/torrents/addPeers
{"53b631ea…": {"added": 1, "failed": 0}}

Note the port: 48188 is A's torrenting port — peers are introduced to the engine, not to the WebUI.

The transfer, watched

B was throttled to 128 KiB/s in chapter 5, so the 2 MiB takes its time and the states can be seen changing. Six seconds after the introduction:

{"state": "downloading", "progress": 0.0859375,
 "num_seeds": 1, "dlspeed": 26074, "eta": 367}

One seed (A), 8.6% of the bytes held, and a speed well under the ceiling while the connection finds its stride. Twelve seconds later it is 86% done, and shortly after:

{"state": "stalledUP", "progress": 1,
 "downloaded": 2097152, "amount_left": 0}

The roles have flipped: B, which had nothing, now holds the whole file and offers it onward, while A's record shows the other side of the same event — uploaded: 2097152, one full copy served. That symmetry is BitTorrent's whole idea in miniature: every downloader is a future uploader, and the swarm's capacity grows with its crowd.

The check that ends the argument

Progress bars are the client's opinion. The proof is a hash, run by an independent tool on the arrived file:

$ sha256sum downloads-b/field-notes.txt fixtures/field-notes.txt
3346c8d4f3934e2603f47229711e107ed82f6a268a0ab2f353b5d6e3abfde5d4  downloads-b/field-notes.txt
3346c8d4f3934e2603f47229711e107ed82f6a268a0ab2f353b5d6e3abfde5d4  fixtures/field-notes.txt

Identical. Two programs, two folders, one protocol, zero trust required — every piece was hash-checked on arrival (chapter 2), and the whole-file check here closes the loop for the reader. This is the habit the guide most wants to leave you with: when a transfer matters, hash it at both ends.