Question

I'm trying to understand the process inside BitTorrent and implement something similar. However, I still don't know the process of piece selection and transfer. How can each peer know that which peer has which file piece? Does each peer need to ask each other whether it has the requested piece or not all the time?

I have also heard about "rarest piece first" approach, which tries to get rarer piece before. How to get these information without wasting network traffic?

Thank you.

Was it helpful?

Solution

This is done with two messages: bitfield and have.

  • After two peers perform a handshake, they can optionally send bitfields as their first messages, which compactly represent all of their completed blocks.

  • Once a peer successfully downloads and verifies a block, they broadcast a have message to all of their connected peers, letting them know which block they just completed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top