BitTorrent Protocol
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/
Web
Serve
r
Harry Potter.torrent
Transformer.torrent
Filesharing
Large files are broken into pieces of size
between
64 KB and 1 MB
Web Server
Web Server
Web Server
Tracker
Tracker
Tracker
Tracker
Tracker
Tracker
Downloader:
Seeder:
Downloader:
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
Ifaninefficientpolicyisused,thenpeersmay
endupinasituationwhereeachhasallidentical
setofeasilyavailablepieces,andnoneofthe
missingones.
Iftheoriginalseedisprematurelytakendown,
RarestFirst
Generalrule
RandomFirstPiece
Specialcase,atthebeginning
EndgameMode
Specialcase
RandomFirstPiece
Initially,apeerhasnothingtotrade
ImportanttogetacompletepieceASAP
RarestPieceFirst
Determinethepiecesthataremostrare
amongyourpeers,anddownloadthosefirst.
tilltheendtodownload.
EndgameMode
Neartheend,missingpiecesarerequested
fromeverypeercontainingthem.Whenthe
piecearrives,thependingrequestsforthat
piecearecancelled.
Thisensuresthatadownloadisnotprevented
fromcompletionduetoasinglepeerwitha
slowtransferrate.
Somebandwidthiswasted,butinpractice,thisis
nottoomuch.
Choking
Chokingisatemporaryrefusaltoupload.Itis
oneofBitTorrentsmostpowerfulideatodeal
withfreeriders(thosewhoonlydownloadbut
neverupload).
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.