The BitTorrent File Sharing Network - How does it work?

The key components of the BitTorrent network are the tracker, the web server hosting the torrent file, seeds and peers. This page describes the working of the BitTorrent client. Let us assume Peer A wishes to download a file.

The official documentation for the protocol can be found here.

1.Download the torrent file

The torrent file is the metafile containing information about the location of the tracker and verification hashes for the pieces of the file. It is usually hosted on some popular website. The first step is to download the torrent file. If the .torrent association has already been made on our web browser, a click on the url of the webpage is sufficient to download it.

2.Contact the Tracker

The next step is to send a HTTP-GET request to the tracker. The tracker is a server which accpets requests for information about other peers on the network. The GET Request advertises Peer A's Peer id, IP address and Port number to the tracker, so that other peers in the network can get in touch with Peer A.

3.Tracker Response

The tracker responds with a list of peers, (ip address and port number), who are currently downloading or uploading the file. Say, Peer A sees Peers B and C in the response list from the tracker. Also, as indicated, let Peer C be a seed. A seed is a peer that has a complete copy of the file.

4.Peer Connection

Peer A then initiates TCP connections with the peers in the peer list it obtained from the tracker. Since B and C were on that list, Peer A connects to both and initiates a 3 way Bittorrent handshake.

5.Peer A downloads a piece from the network.

Once the connection has been establisthed and remote peer has been authenticated, the peers B and C advertise what pieces they already have with a BITFIELD message. Peer A expresses INTEREST since it does not have any pieces yet. Peer A then sends a REQUEST message requesting for a particular chunk of a piece. When the remote peers UNCHOKE Peer A, it starts downloading from them. Initially Peer A only downloads untill it gets hold of a complete piece.

6.Piece exchange starts.

After Peer A has succesfully downloaded a complete piece and verified it against the hash in the .torrent file, it broadcasts a HAVE message indicating that it just got a piece. If other peers are interested then they can obtain it from Peer A. Now Peer A has boot strapped into the file swarming network adn starts exchanging portions of the file with other leeches. Note, that Peer C is a seed and since it has a complete copy of the file, it only uploads to other leeches in the network.

7.Peers periodically contact tracker.

The peers periodically contact the tracker to discover more peers. These Announce messages also act in advertising to the tracker of the peer's progress. The announce message consists of fields to indicate how much the peer has downloaded and how much is left.

Finally, once Peer A completes downloading the fie, it disconnects from other seeds and becomes a seed, offering the file to other leeches in the network.

Karthik Tamilmani