2What is BitTorrent? Efficient content distribution system using file swarming.
3A BitTorrent file distribution consists of these entities: A static 'metainfo' fileA BitTorrent trackerAn 'original' downloaderThe end user downloaders
4To start serving, a host goes through the following steps: Start running a trackerStart running an ordinary web server.Generate a metainfo (.torrent) file using the complete file to be served and the URL of the tracker.Put the metainfo file on the web server.Link to the metainfo (.torrent) file from some other web page.Start a downloader which already has the complete file (the 'origin').
5To start downloading: Get a BitTorrent client Find a .torrent file. Select where to save the file locally.Wait for download to complete.Tell downloader to exit (it keeps uploading until this happens).
6Bencode All data passed in BT is bencoded (BEE –Encoded). This is a representation convention used to avoid interoperability problems.
7Data in .torrent files The URL of the tracker. Suggested name to save the file.piece length maps to the number of bytes in each piece the file is split into.pieces maps to a string whose length is a multiple of 20. It is to be subdivided into strings of length 20, each of which is the SHA1 hash of the piece at the corresponding index.
8Tracker <> Peer communication Actual packet structure
9Peer > Tracker: GET requests has following keys info_hash – hash of the .torrent.peer_id – My unique ID.My IP / Portuploaded / Downloadedleft – Can not be calculated from Downloaded, because of errors / restart.event - Why I do the GET.
10GET events Reasons for calling the GET: Started Completed Stopped Empty - done at regular intervals
11Tracker > Peer : tracker GET responses failure interval – next time to GETList of peers
12Peer <> Peer communication Actual packet structure
13Peers protocol operates over TCP Peer connections are symmetrical Refers to pieces by index from .torrentConnections contain : choked and interested
15Change connection state 'choke', 'unchoke', 'interested', and 'not interested' have no payload.Data transfer takes place:one side is interested, other side is not chokingstate must be kept up to date at all timesThis is a precondition for upload / download – REQUEST / PIECE
16BITFIELD Only ever sent as the first message. bitfield - a bit for each piece –1 – Have0 – Don’t haveMay skip if has 0 pieces.
17HAVESingle number, the index which that downloader just completed and checked the hash of.
18REQUEST Contain - index, begin, and length Length is generally a power of two unless it gets truncated by the end of the file.
19PIECEGetting the actual data from a peerCorrelates to a REQUEST.
20CANCEL same payload as request messages. generally only sent during what's called 'endgame mode'. Try to download whole piece from multiple sources.
21Choking reasons TCP congestion control is poorly with many connections choking lets each peer use a tit-for-tat-ish algorithm
22Choking Algorithm Criteria (Recommended) Cap the number of simultaneous uploads for good TCP performance.It should avoid choking and unchoking quickly, known as 'fibrillation'.Reciprocate to peers who let it download.try out unused connections once in a while known as optimistic un choking.