uni
BitTorrent is a Peer to Peer network application (1.1.2 Peer-to-Peer paradigm) used for distributing files.

3.3 BitTorrent

The file that needs to be transferred gets divide into 256KB chunks, and the peers in the torrent send and receive these chunks.

Torrent: group of peers participating in the distribution of a particular file.
tracker: node that tracks peers participating in the torrent.
Torrent Server: server that knows the IPs of the trackers.

Peers may discover other peers by trackers, DHT (distributed hash table), or PEX (peer exchange).

Chunks don’t even get transferred sequentially, every chunk has an ID so the entire file gets rebuilt by the asking peer once every chunk has arrived.

While a peer is downloading chunks it also uploads already downloaded chunks, then, when it has every chunk, it may leave or remain in the torrent to aid other peers.

3.3.1 Entering a Torrent

  1. Alice contacts the torrent Server and gets the IP of the tracker.
  2. Alice contacts the tracker and asks to be included in the torrent.
  3. The tracker adds Alice to the list of peers participating to the torrent and then sends the list to Alice.
  4. Alice tries to open concurrent TCP connections with every peer in the list.
  5. Alice manages to open TCP connections with only a subset of the torrent list, the peers she manages to connect with are called neighboring peers. Peers are divided in leeches (ones who don’t have a complete copy of the file), seeders (ones who have every chunk) and free-riders (who only want to download the file, not seed the file).
  6. Alice asks now her neighbors what chunks they have.
  7. Alice asks first for the rarer chunks, the ones that are scarse in the “neighborhood”. This approach is called rarest first.
  8. Now that Alice has some chunks, other neighbors ask her for chunks, she now has to choose which neighbors to send the chunks to. She now adopts the tit for tat approach, she starts with sending the data to the 4 neighbors sending her chunks at the highest rate (these peers get unchoked). Alice re-evaluates the top 4 peers every 10 seconds. Note that choked peers (every not-unchoked peer) do not get any chunks from Alice.
  9. Every 30 seconds Alice randomly selects another peer for sending to: she “optimistically unchokes” this peer, who may also join the top 4.

This method of distribution has the effect of pairing peers with similar bandwidth capability and limiting freeriders.

Link to original