After metadata is received and verified, the downloader requests pieces from peers.
- Seeder sends
bitfield(orhave_all) showing which pieces it has - Downloader sends
interested(message ID 2) - Seeder sends
unchoke(message ID 1) - Downloader sends
requestmessages (message ID 6) - Seeder responds with
piecemessages (message ID 7) - After all pieces: downloader sends
not_interested(message ID 3)
[length=13][id=6][index:uint32][begin:uint32][length:uint32]
index: piece index (0-based)begin: byte offset within the piecelength: number of bytes requested (typically 16384 = 16KB)
[length=9+N][id=7][index:uint32][begin:uint32][data:N bytes]
After receiving all blocks for a piece, the client computes SHA-1 (or SHA-256) of the assembled piece and compares against the hash in the info dict.
{
"event": "have_all",
"role": "downloader",
"direction": "received"
}{
"event": "have_all",
"role": "seeder",
"direction": "received"
}{
"event": "downloader_done",
"downloaded": 49152,
"uploaded": 157,
"peers": 1,
"ratio": 0.5627240143369175
}