Académique Documents
Professionnel Documents
Culture Documents
(Figure 2)
Handshaking
Each peer listens to a TCP port for incoming requests from other peers and reports this port number to
the tracker, as already mentioned. After obtaining the list of peers and their port numbers from the
tracker, the local peer may connect to the remote peers on specified ports. Similarly the remote peers
may open a TCP connection with the local peer at the port reported by it to the tracker. A pair of peers
with an active TCP link between them are known as neighbors. After the connections have been
established, the PWP requires that a two- way “handshaking” operation be performed over each
connection before it is used to exchange any data. A handshake message (a 68 byte string) is sent and
validated at each end of the connection. In case the authentication fails at either end, the connection is
dropped. Thus, handshaking serves as a security measure. As per the current specifications, the
handshake message includes information like the 20 byte Peer ID (a Peer ID uniquely identifies a peer in
a swarm) and the info-hash (SHA - 1 hash of the info key in the meta information file. It uniquely identifies
the torrent).
Each peer can verify the Peer ID of its neighbor by cross cheking against the list obtained from the
tracker and the info-hash against its own copy of the meta information file.
There is provision for incorporating stronger security checks in the handshake message in future.
Piece Selection
‘Rarest Piece First’ which dictates that a peer first download the pieces that the fewest of its neighbors
have proves to be a good approach in most cases not only for the local peer but for the swarm on the
whole. It helps to increase the availability of rare pieces and ensures that new pieces are quickly
requested incase there is a lone seeder in the swarm (e.g. the publisher). It thus helps in quickly
distributing a concentrated torrent across the swarm. However, at the start of download, a peer may opt
for a ‘Random Piece First’ strategy as the first priority at that point is to start uploading to others. During
the final stages of its download, a peer may send requests to all its neighbors for all the remaining
blocks. It then sends out ‘cancels’ for the blocks that arrive. This helps it to quickly complete its
download.
A Buzzing Swarm …
A swarm of BT peers, hooked onto a torrent bustles with activity.
There are peers joining and leaving the swarm, friendships (read TCP connections) being forged and
broken, neighbors choking each other – it doesn’t quite look like a nice place to be in! And yet, in the end
all are happy!
Lets look at the swarm from a peer’s point of view. After registering itself with and obtaining information
about the swarm from the tracker, the peer, say ‘P’, starts sending out connection requests to the peers
in swarm that it finds attractive. (This depends on the particular Peer Selection Strategy that P
implements). P successfully establishes connections with several peers and starts downloading different
pieces of the torrent from them. As it finishes downloading some of the pieces, P starts receiving
requests from other peers – its now P’s turn to share! If P now tries to act smart by not uploading what it
has, it may soon be penalised by the other peers in the swarm who might choke it. Similarly, P can also
choke some of its neighbors. (Depending on it’s choking algorithm) There might also be mutual
expression of ‘interest’ between P and it’s peers.
And while all this is going on, P must not forget to keep forging new alliances (sending requests to other
peers). It must also keep itself abreast about the current affairs of the swarm! (by periodically obtaining
statistical information from the tracker).
Finally, after P has completed its download, social etiquettes demand that it should continue to offer
some community service by becoming a seeder for some time.
A Parting Note
Some times sheer common sense and imagination can produce magnificent masterpieces!
Bit Torrent is a clear case in point. Kudos to Bram Cohen for his wonderful gift to the internet community!