TheBitTorrentProtocol
EVERYTHING ABOUT BITTORRENT PROTOCOL
WhatisBitTorrent?
Efficientcontentdistributionsystemusing
fileswarming.Usuallydoesnotperform
allthefunctionsofatypicalp2psystem,
likesearching.
BitTorrenttraffic
CacheLogic estimated that BitTorrent traffic
accounts for roughly 35% of all traffic on the
Internet.
Filesharing
Toshareafileorgroupoffiles,apeerfirst
createsa.torrentfile,asmallfilethatcontains
(1)metadataaboutthefilestobeshared,and
(2)Informationaboutthetracker,thecomputer
!thatcoordinatesthefiledistribution.
Peersfirstobtaina.torrentfile,andthenconnect
tothespecifiedtracker,whichtellsthemfrom
whichotherpeerstodownloadthepiecesofthefile.
BT Components
On a public domain site, obtain .torrent
file.forexample:
http://bt.LOR.net
http://bt.HarryPotter.com/
The Lord of Ring.torrent
Web
Serve
r
Harry Potter.torrent
Transformer.torrent
Filesharing
Large files are broken into pieces of size
between
64 KB and 1 MB
BT: publishing a file
Bob
Web Server
BT: publishing a file
Bob
Web Server
BT: publishing a file
Bob
Web Server
BT: publishing a file
Harry Potter.torrent
Bob
Web Server
BT: publishing a file
Harry Potter.torrent
Bob
Tracker
BT: publishing a file
Harry Potter.torrent
Bob
Tracker
BT: publishing a file
Harry Potter.torrent
Bob
Tracker
BT: publishing a file
Harry Potter.torrent
Bob
Tracker
BT: publishing a file
Harry Potter.torrent
Bob
Tracker
BT: publishing a file
Harry Potter.torrent
Bob
Tracker
Downloader:
Seeder:
Downloader:
BT: publishing a file
Harry Potter.torrent
Bob
Tracker
Downloader:
Seeder:
Downloader:
The.torrentfile
TheURLofthetracker
Pieces<hash1,hash2,.hashn>
Piecelength
Name
Lengthofthefile
TheTracker
IPaddress,port,peerid
Stateinformation(CompletedorDownloading)
Returnsarandomlistofpeers
BitTorrentLingo
Seeder=apeerthatprovidesthecompletefile.
Initialseeder=apeerthatprovidestheinitialcopy.
Leecher
Initial
seeder
Onewhoisdownloading
(notaderogatoryterm)
Leecher
Seeder
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{}
Downloader B
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{}
Downloader B
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{1,2,3}
Downloader B
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{}
{1,2,3}
Downloader C
Downloader B
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{}
{1,2,3}
Downloader C
Downloader B
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{1,2,3}
{1,2,3,4}
Downloader C
Downloader B
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{1,2,3}
{1,2,3,4}
Downloader C
Downloader B
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{1,2,3,5}
{1,2,3,4}
Downloader C
Downloader B
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{1,2,3,5}
{1,2,3,4}
Downloader C
Downloader B
Simple example
{1,2,3,4,5,6,7,8,9,10}
Seeder:
{1,2,3,5}
{1,2,3,4,5}
Downloader C
Downloader B
BasicIdea
Initialseederchopsfileintomanypieces.
Leecherfirstlocatesthe.torrentfilethatdirectsittoa
tracker,whichtellswhichotherpeersaredownloading
thatfile.Asaleecherdownloadspiecesofthefile,
replicasofthepiecesarecreated.Moredownloadsmean
morereplicasavailable
Assoonasaleecherhasacompletepiece,itcan
potentiallyshareitwithotherdownloaders.Eventually
eachleecherbecomesaseederbyobtainingallthe
pieces,andassemblesthefile.Verifiesthechecksum.
Operation
PiecesandSubPieces
Apieceisbrokenintosubpieces...
typically16KBinsize
Untilapieceisassembled,onlydownload
thesubpiecesofthatpieceonly
Thispolicyletspiecesassemblequickly
Pipelining
WhentransferringdataoverTCP,alwayshaveseveral
requestspendingatonce,toavoidadelaybetween
piecesbeingsent.Atanypointintime,somenumber,
typically5,arerequestedsimultaneously.
Everytimeapieceorasubpiecearrives,anew
requestissentout.
PieceSelection
The order in which pieces are selected by
differentpeersiscriticalforgoodperformance
Ifaninefficientpolicyisused,thenpeersmay
endupinasituationwhereeachhasallidentical
setofeasilyavailablepieces,andnoneofthe
missingones.
Iftheoriginalseedisprematurelytakendown,
then the file cannot be completely
downloaded!Whataregoodpolicies?
BT: internal Chunk Selection
mechanisms
StrictPriority
FirstPriority
RarestFirst
Generalrule
RandomFirstPiece
Specialcase,atthebeginning
EndgameMode
Specialcase
RandomFirstPiece
Initially,apeerhasnothingtotrade
ImportanttogetacompletepieceASAP
Select a random piece of the file
anddownloadit
RarestPieceFirst
Determinethepiecesthataremostrare
amongyourpeers,anddownloadthosefirst.
This ensures that the most
commonly available pieces are left
tilltheendtodownload.
EndgameMode
Neartheend,missingpiecesarerequested
fromeverypeercontainingthem.Whenthe
piecearrives,thependingrequestsforthat
piecearecancelled.
Thisensuresthatadownloadisnotprevented
fromcompletionduetoasinglepeerwitha
slowtransferrate.
Somebandwidthiswasted,butinpractice,thisis
nottoomuch.
BT: internal mechanism
Built-in incentive mechanism (where all the
magic happens):
Choking Algorithm
Optimistic Unchoking
Choking
Chokingisatemporaryrefusaltoupload.Itis
oneofBitTorrentsmostpowerfulideatodeal
withfreeriders(thosewhoonlydownloadbut
neverupload).
Titfortat strategy is based on game
theoreticconcepts.
Choking
Reasonsforchoking:
Avoidfreeriders
Networkcongestion
Agoodchokingalgorithm
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Choking
Reasonsforchoking:
Avoidfreeriders
Networkcongestion
Agoodchokingalgorithm
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Choking
Networkcongestion
A
v
oi
d
fr
ee
ri
de
rs
Alice
Agoodchokingalgorithm
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Choking
Networkcongestion
A
v
oi
d
fr
ee
ri
de
rs
Alice
Agoodchokingalgorithm
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Choking
Reasonsforchoking:
Alice
Avoidfreeriders
Networkcongestion
Agoodchokingalgorithm
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Bob
Choking
Reasonsforchoking:
Alice
Avoidfreeriders
Networkcongestion
Agoodchokingalgorithm
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Bob
Choking
Reasonsforchoking:
Alice
Avoidfreeriders
Networkcongestion
Agoodchokingalgorithm
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Bob
Choking
Reasonsforchoking:
Alice
Avoidfreeriders
Networkcongestion
Agoodchokingalgorithm
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Bob
Choking
Reasonsforchoking:
Alice
Avoidfreeriders
Networkcongestion
Agoodchokingalgorithm
Choked
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Bob
Choking
Reasonsforchoking:
Alice
Avoidfreeriders
Networkcongestion
Agoodchokingalgorithm
Choked
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Bob
Choking
Networkcongestion
A
v
oi
d
fr
ee
ri
de
rs
Alice
Agoodchokingalgorithm
Choked
Choked
capsthenumberofsimultaneous
uploadsforgoodTCPperformance.
Avoidschokingandunchoking
tooquickly,(knownasfibrillation)..
Bob
MoreonChoking
!Peerstryoutunusedconnectionsonceina
whiletofindoutiftheymightbebetterthan
thecurrentones(optimisticunchoking).
Optimistic unchoking
Optimistic unchoking
ABitTorrentpeerhasasingleoptimistic
unchoketowhichituploadsregardlessofthe
currentdownloadratefromit.Thispeer
rotatesevery30s
Optimistic unchoking
ABitTorrentpeerhasasingleoptimistic
unchoketowhichituploadsregardlessofthe
currentdownloadratefromit.Thispeer
rotatesevery30s
Optimistic unchoking
ABitTorrentpeerhasasingleoptimistic
unchoketowhichituploadsregardlessofthe
currentdownloadratefromit.Thispeer
rotatesevery30s
Reasons:
Optimistic unchoking
ABitTorrentpeerhasasingleoptimistic
unchoketowhichituploadsregardlessofthe
currentdownloadratefromit.Thispeer
rotatesevery30s
Reasons:
Todiscovercurrentlyunusedconnectionsarebetter
thantheonesbeingused
Optimistic unchoking
ABitTorrentpeerhasasingleoptimistic
unchoketowhichituploadsregardlessofthe
currentdownloadratefromit.Thispeer
rotatesevery30s
Reasons:
Todiscovercurrentlyunusedconnectionsarebetter
thantheonesbeingused
Toprovideminimalservicetonewpeers
UploadOnlymode
Once download is complete, a peer has
nodownloadratestouseforcomparison
nor has any need to use them. The
questionis,whichnodestouploadto?
Policy:Uploadtothosewiththebestupload
rate.Thisensuresthatpiecesgetreplicated
faster,andnewseedersarecreatedfast
QuestionsaboutBT
QuestionsaboutBT
WhichfeaturescontributetotheefficiencyofBitTorrent?
QuestionsaboutBT
WhichfeaturescontributetotheefficiencyofBitTorrent?
Whatistheeffectofbandwidthconstraints?
QuestionsaboutBT
WhichfeaturescontributetotheefficiencyofBitTorrent?
Whatistheeffectofbandwidthconstraints?
IstheRarestFirstpolicyreallynecessary?
QuestionsaboutBT
WhichfeaturescontributetotheefficiencyofBitTorrent?
Whatistheeffectofbandwidthconstraints?
IstheRarestFirstpolicyreallynecessary?
Mustnodesperformseedingafterdownloadingiscomplete?
QuestionsaboutBT
WhichfeaturescontributetotheefficiencyofBitTorrent?
Whatistheeffectofbandwidthconstraints?
IstheRarestFirstpolicyreallynecessary?
Mustnodesperformseedingafterdownloadingiscomplete?
HowseriousistheLastPieceProblem?
QuestionsaboutBT
WhichfeaturescontributetotheefficiencyofBitTorrent?
Whatistheeffectofbandwidthconstraints?
IstheRarestFirstpolicyreallynecessary?
Mustnodesperformseedingafterdownloadingiscomplete?
HowseriousistheLastPieceProblem?
Doestheincentivemechanismaffecttheperformancemuch?
Onemoreexample
peer C
peer A
peer D
peer B
peer E
Onemoreexample
HELLO
peer A HELLO
peer
C
HELLO
peer B
HELLO
peer
D
peer
Onemoreexample
peer C
peer A
Bitmap
Bitmap
Bitmap
peer D
peer B
Bitmap
peer E
Onemoreexample
peer C
peer A
Request
C5
Request C1
peer D
peer B
peer E
Onemoreexample
Without upload constraint
peer C
peer A
peer D
peer B
peer E
Onemoreexample
Without upload constraint
peer C
peer A
C5
C1
peer D
peer B
peer E
Onemoreexample
Without upload constraint With upload
constraint
peer C
peer A
C5
C1
peer D
peer B
peer E
Trackerlesstorrents
BitTorrentalsosupports"trackerless"torrents,
featuringaDHTimplementationthatallowsthe
clienttodownloadtorrentsthathavebeencreated
withoutusingaBitTorrenttracker.