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 exchanging chunks of a 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 download chunks it also upload already downloaded chunks then, when it has every chunk, it may leave or remain in the torrent.
3.3.1 Entering a Torrent
Link to original
- Alice contacts the torrent Server and gets the IP of the tracker.
- Alice contacts the tracker and asks to be included in the torrent.
- The tracker adds Alice to the list of peers participating to the torrent and then sends the list to Alice.
- Alice tries to open TCP connections with every peer in the list.
- Alice manages to open TCP connections with only a subset of the torrent list, the peers she manages to connect with are called neighbors. 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).
- Alice asks now her neighbors what chunks they have.
- Alice asks first for the rarer chunks, the ones that are scarse in the “neighborhood”. This approach is called rarest first.
- 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.
- Other peers are choked by Alice.
- Alice re-evaluates the top 4 peers every 10 seconds.
- Every 30 seconds Alice randomly selects another peer for sending to: she “optimistically unchokes” this peer. This new peer may also join the top 4.