To know more about torrent download, I used wireshark to capture the packets transferred during the download. I was able to find that a file is split into multiple pieces that comes from different peers. Also, a single piece was transmitted as many different chunks of equal size. The piece id and length is the information available to identify the chunks.

I was able to get piece ids of different pieces transferred. But now how can I rearrange these pieces in the correct order? Does the piece id has any significance in this respect?

Also, How do torrent clients reassemble and store pieces? tells about hash values. From where can I get these values from the packets captured using wireshark?

  • BitTorrent is a well-defined protocol. While I’m all for exploring stuff, canonical documentation is the way to go if available. – Daniel B Nov 29 '14 at 10:27
  • @DanielB: I went through the documentation and it helped me to analyze these things. But I didn't get solution for my doubt.. – Jackzz Nov 29 '14 at 10:29

Ok, let's simplfy things.

Let's say you had a 100Mb torrent. You could break that down into 100 1mb pieces (numbered 0 to 99), but it doesn't have to be 1mb, it could be as small as 64kb, or as large as 16mb, and is usually (but not always) a two-power. Each of those pieces is made up of chunks. Each chunk is 16kb. A chunk is the smallest amount of data a torrent client deals with (with a 1mb piece there's 64 chunks).

A client can request any chunk, from any piece, from any peer that's announced it has that piece.

Once the client has all the chunks for a piece, it'll then check that combined piece against the SHA1 hash for that piece that's in the torrent file (to answer the last bit). If it passes, it's saved and marked as a 'have' for other people to request, else it's discarded.

So yes, without knowing the piece id, how will you know what piece it's from, so how to group it with the rest of that piece, and then run it against the hash, and then save it?


The piece id do have significance in rearrangement of pieces. To make it sure, I created my own torrent of a small file and divided it into 10 pieces. Then I downloaded the same torrent from another system and noted the order in which pieces were downloaded. At the same time I captured the packets using wireshark. After the download was complete, I checked the have messages broadcasted by the client and the piece ids in the messages was in the same order as it was downloaded. Since I am not concerned about the hash values right now,this solves my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.