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.