BitTorrent is a application layer network protocol for distributed, decentralised peer-to-peer file sharing. Files are divided into 256 kB chunks. There are two main types of nodes:
- A torrent is a group of peers exchanging chunks of a file.
- A tracker tracks the peers that participate in the torrent.
A peer joining the torrent will begin with no chunks, but will accumulate them over time from other peers. It first communicates with the tracker to obtain a list of peers, and then connects to a subset of peers (neighbours). While downloading, the peer uploads chunks to other peers. It may change peers with whom it exchanges chunks. Once a peer has its entire file, it may selfishly leave, or altruistically remain in the torrent (continue to seed).
At any given time, different peers have different subsets of file chunks. Periodically, a requesting peer will ask each peer for a list of chunks that they have, then will request missing chunks from peers, rarest first.
Sending chunks:
- Done to 4 peers sending the original peer chunks at the highest rate.
- Other peers are choked (don’t receive chunks) by the peer.
- The top 4 is re-evaluated every 10 seconds.
- Every 30 seconds, the peer will randomly select another peer (optimistically unchoke) and start sending chunks. This newly chosen peer may join the top 4.
- TL;DR: find a better trading partner, get file faster. If one peer optimistically unchokes another peer , and becomes one of ‘s top-4 providers, then will reciprocate and become one of ‘s top-4 providers.