BitTorrent Protocol

93
The BitTorrent Protocol EVERYTHING ABOUT BITTORRENT PROTOCOL

description

everything about bittorrent protocol

Transcript of BitTorrent Protocol

Page 1: BitTorrent Protocol

The BitTorrent Protocol

EVERYTHING ABOUT BITTORRENT PROTOCOL

Page 2: BitTorrent Protocol

What is BitTorrent?

Efficient content distribution system using

file swarming. Usually does not perform

all the functions of a typical p2p system,

like searching.

Page 3: BitTorrent Protocol

BitTorrent traffic

CacheLogic estimated that BitTorrent traffic

accounts for roughly 35% of all traffic on the

Internet.

Page 4: BitTorrent Protocol

File sharing

To share a file or group of files, a peer first 

creates a .torrent file, a small file that contains

(1)metadata about the files to be shared, and 

(2)Information about the tracker, the computer

!that coordinates the file distribution.

Peers first obtain a .torrent file, and then connect

Page 5: BitTorrent Protocol

to the specified tracker, which tells them from 

which other peers to download the pieces of the file.

Page 6: BitTorrent Protocol

BT Components

On   a   public   domain   site,   obtain   .torrent

file. for example:

– http://bt.LOR.net

– http://bt.HarryPotter.com/ Web Server

The Lord of Ring.torrent

Page 7: BitTorrent Protocol

Harry Potter.torrentTransformer.torrent

Page 8: BitTorrent Protocol

File sharing

Large files are broken into pieces of size between

64 KB and 1 MB

Page 9: BitTorrent Protocol

1 2 3 4 5 6 7 8

Page 10: BitTorrent Protocol

BT: publishing a file

Bob

Web Server

Page 11: BitTorrent Protocol

BT: publishing a file

Bob

Web Server

Page 12: BitTorrent Protocol

BT: publishing a file

Bob

Web Server

Page 13: BitTorrent Protocol

BT: publishing a file

Harry Potter.torrentBob

Web Server

Page 14: BitTorrent Protocol

BT: publishing a file

Harry Potter.torrentBob

Tracker

Page 15: BitTorrent Protocol

BT: publishing a file

Harry Potter.torrentBob

Tracker

Page 16: BitTorrent Protocol

BT: publishing a file

Harry Potter.torrentBob

Tracker

Page 17: BitTorrent Protocol

BT: publishing a file

Harry Potter.torrentBob

Tracker

Page 18: BitTorrent Protocol

BT: publishing a file

Harry Potter.torrentBob

Tracker

Page 19: BitTorrent Protocol

BT: publishing a file

Harry Potter.torrentBob

Tracker

Downloader: Seeder: Downloader:

A B C

Page 20: BitTorrent Protocol

BT: publishing a file

Harry Potter.torrentBob

Tracker

Downloader: Seeder: Downloader:

A B C

Page 21: BitTorrent Protocol

The .torrent file

The URL of the tracker

Pieces <hash1,hash 2,….hash n>

Piece length

Name

Length of the file

Page 22: BitTorrent Protocol

The Tracker

IP address, port, peer id

State information (Completed or Downloading)

Returns a random list of peers

Page 23: BitTorrent Protocol

BitTorrent Lingo

Seeder = a peer that provides the complete file. 

Initial seeder = a peer that provides the initial copy.

Initial seeder

Leecher

One who is downloading 

(not a derogatory term)

 Leecher

Page 24: BitTorrent Protocol

Seeder

Page 25: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

Page 26: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{}

Downloader B

Page 27: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{}

Downloader B

Page 28: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{1,2,3}

Downloader B

Page 29: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{}

{1,2,3}

Downloader CDownloader B

Page 30: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{}

{1,2,3}

Downloader CDownloader B

Page 31: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{1,2,3}

{1,2,3,4}

Downloader CDownloader B

Page 32: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{1,2,3}

{1,2,3,4}

Downloader CDownloader B

Page 33: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{1,2,3,5}

{1,2,3,4}

Downloader CDownloader B

Page 34: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{1,2,3,5}

{1,2,3,4}

Downloader CDownloader B

Page 35: BitTorrent Protocol

Simple example

{1,2,3,4,5,6,7,8,9,10}

Seeder: A

{1,2,3,5}

{1,2,3,4,5}

Downloader CDownloader B

Page 36: BitTorrent Protocol

Basic Idea

Initial seeder chops file into many pieces.

Leecher first locates the .torrent file that directs it to a 

tracker, which tells which other peers are downloading that file. As a leecher downloads pieces of the file, 

replicas of the pieces are created. More downloads mean 

more replicas available

As soon as a leecher has a complete piece, it can 

potentially share it with other downloaders. Eventually 

Page 37: BitTorrent Protocol

each leecher becomes a seeder by obtaining all the 

pieces, and assembles the file. Verifies the checksum.

Page 38: BitTorrent Protocol

Operation

Page 39: BitTorrent Protocol

Pieces and Sub­Pieces

A piece is broken into sub­pieces ...

typically 16KB in size Until a piece is assembled, only download

the sub­pieces of that piece only

This policy lets pieces assemble quickly

Page 40: BitTorrent Protocol

Pipelining

When transferring data over TCP, always have several

requests pending at once, to avoid a delay between 

pieces being sent. At any point in time, some number, 

typically 5, are requested simultaneously.

Every time a piece or a sub­piece arrives, a new

Page 41: BitTorrent Protocol

request is sent out.

Page 42: BitTorrent Protocol

Piece Selection

The  order  in   which   pieces   are   selected   by

different peers is critical for good performance

If an inefficient policy is used, then peers may 

end up in a situation where each has all identical 

set of easily available pieces, and none of the 

missing ones.

If the original seed is prematurely taken down,

Page 43: BitTorrent Protocol

then   the   file   cannot   be   completely

downloaded! What are “good policies?”

Page 44: BitTorrent Protocol

BT: internal Chunk Selectionmechanisms

Strict Priority

– First Priority

Rarest First

– General rule

Random First Piece

– Special case, at the beginning

Page 45: BitTorrent Protocol

Endgame Mode

– Special case

Page 46: BitTorrent Protocol

Random First Piece

Initially, a peer has nothing to trade

Important to get a complete piece ASAP

Select   a   random   piece   of   the   file

and download it

Page 47: BitTorrent Protocol

Rarest Piece First

Determine the pieces that are most rare 

among your peers, and download those first.

This   ensures   that   the   most

commonly   available   pieces   are   left

Page 48: BitTorrent Protocol

till the end to download.

Page 49: BitTorrent Protocol

Endgame Mode

Near the end, missing pieces are requested from every peer containing them. When the piece arrives, the pending requests for that piece are cancelled.

This ensures that a download is not prevented from completion due to a single peer with a slow transfer rate.

Page 50: BitTorrent Protocol

Some bandwidth is wasted, but in practice, this is

not too much.

Page 51: BitTorrent Protocol

BT: internal mechanism

Built-in incentive mechanism (where all the

magic happens):

– Choking Algorithm

– Optimistic Unchoking

Page 52: BitTorrent Protocol

Choking

Choking is a temporary refusal to upload. It is 

one of BitTorrent’s most powerful idea to deal 

with free riders (those who only download but

never upload).

Tit­for­tat   strategy  is   based   on   game­

Page 53: BitTorrent Protocol

theoretic concepts.

Page 54: BitTorrent Protocol

Choking

Reasons for choking:

–Avoid free riders

–Network congestion

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Page 55: BitTorrent Protocol

Choking

Reasons for choking:

–Avoid free riders

–Network congestion

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Page 56: BitTorrent Protocol

Choking

R–Avoidfreeriders

Network congestion

Page 57: BitTorrent Protocol

Alice

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Page 58: BitTorrent Protocol

Choking

R–Avoidfreeriders

Network congestion

Page 59: BitTorrent Protocol

Alice

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Page 60: BitTorrent Protocol

Choking

Reasons for choking:

–Avoid free riders

–Network congestion

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Alice

Bob

Page 61: BitTorrent Protocol

Choking

Reasons for choking:

–Avoid free riders

–Network congestion

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Alice

Bob

Page 62: BitTorrent Protocol

Choking

Reasons for choking:

–Avoid free riders

–Network congestion

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Alice

Bob

Page 63: BitTorrent Protocol

Choking

Reasons for choking:

–Avoid free riders

–Network congestion

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Alice

Bob

Page 64: BitTorrent Protocol

Choking

Reasons for choking:

–Avoid free riders

–Network congestion

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Alice

Choked

Bob

Page 65: BitTorrent Protocol

Choking

Reasons for choking:

–Avoid free riders

–Network congestion

A good choking algorithm

caps the number of simultaneous 

uploads for good TCP performance. 

Avoids choking and unchoking

too quickly, (known as fibrillation)..

Alice

Choked

Bob

Page 66: BitTorrent Protocol

Choking

R–Avoidfreeriders

Network congestion

Page 67: BitTorrent Protocol

Alice

A good choking algorithm Choked Choked

caps the number of simultaneous

uploads for good TCP performance.

Avoids choking and unchoking

too quickly, (known as fibrillation).. Bob

Page 68: BitTorrent Protocol

More on Choking

!Peers try out unused connections once in a 

while to find out if they might be better than

the current ones (optimistic unchoking) .

Page 69: BitTorrent Protocol

Optimistic unchoking

Page 70: BitTorrent Protocol

Optimistic unchoking

A BitTorrent peer has a single “optimistic 

unchoke” to which it uploads regardless of the 

current download rate from it. This peer 

rotates every 30s

Page 71: BitTorrent Protocol

Optimistic unchoking

A BitTorrent peer has a single “optimistic 

unchoke” to which it uploads regardless of the 

current download rate from it. This peer 

rotates every 30s

Page 72: BitTorrent Protocol

Optimistic unchoking

A BitTorrent peer has a single “optimistic 

unchoke” to which it uploads regardless of the 

current download rate from it. This peer 

rotates every 30s

Reasons:

Page 73: BitTorrent Protocol

Optimistic unchoking

A BitTorrent peer has a single “optimistic 

unchoke” to which it uploads regardless of the 

current download rate from it. This peer 

rotates every 30s

Reasons:

– To discover currently unused connections are better

than the ones being used

Page 74: BitTorrent Protocol

Optimistic unchoking

A BitTorrent peer has a single “optimistic 

unchoke” to which it uploads regardless of the 

current download rate from it. This peer 

rotates every 30s

Reasons:

– To discover currently unused connections are betterthan the ones being used

Page 75: BitTorrent Protocol

– To provide minimal service to new peers

Page 76: BitTorrent Protocol

Upload­Only mode

Once download  is  complete,  a  peer  has

no download rates to use for comparison

nor   has   any   need   to   use   them.   The

question is, which nodes to upload to?

Policy: Upload to those with the best upload 

rate. This ensures that pieces get replicated 

Page 77: BitTorrent Protocol

faster, and new seeders are created fast

Page 78: BitTorrent Protocol

Questions about BT

Page 79: BitTorrent Protocol

Questions about BT

• Which features contribute to the efficiency of BitTorrent?

Page 80: BitTorrent Protocol

Questions about BT

Which features contribute to the efficiency of BitTorrent?

What is the effect of bandwidth constraints?

Page 81: BitTorrent Protocol

Questions about BT

Which features contribute to the efficiency of BitTorrent?

What is the effect of bandwidth constraints?

Is the Rarest First policy really necessary?

Page 82: BitTorrent Protocol

Questions about BT

Which features contribute to the efficiency of BitTorrent?

What is the effect of bandwidth constraints?

Is the Rarest First policy really necessary?

Must nodes perform seeding after downloading is complete?

Page 83: BitTorrent Protocol

Questions about BT

Which features contribute to the efficiency of BitTorrent?

What is the effect of bandwidth constraints?

Is the Rarest First policy really necessary?

Must nodes perform seeding after downloading is complete?

How serious is the Last Piece Problem?

Page 84: BitTorrent Protocol

Questions about BT

Which features contribute to the efficiency of BitTorrent?

What is the effect of bandwidth constraints?

Is the Rarest First policy really necessary?

Must nodes perform seeding after downloading is complete?

How serious is the Last Piece Problem?

Does the incentive mechanism affect the performance much?

Page 85: BitTorrent Protocol

One more example

peer C

peer A

peer D

peer B

peer E

Page 86: BitTorrent Protocol

One more example

HELLO

peer A HELLO

HELLO

peer B HELLO

peerC

peerD

peer

Page 87: BitTorrent Protocol

E

Page 88: BitTorrent Protocol

peer A

peer B

One more example

peer C

Bitmap

Bitmap

peer DBitmap

Bitmap peer E

Page 89: BitTorrent Protocol

One more example

peer ARequest

C5

Request C1

peer B

peer C

peer D

peer E

Page 90: BitTorrent Protocol

One more example

peer A

peer B

Without upload constraint

peer C

peer D

peer E

Page 91: BitTorrent Protocol

One more example

peer A

C5

C1

peer B

Without upload constraint

peer C

peer D

peer E

Page 92: BitTorrent Protocol

One more example

peer A

C5

C1

peer B

Without upload constraint With upload

constraint

peer C

peer D

peer E

Page 93: BitTorrent Protocol

Trackerless torrents

BitTorrent also supports "trackerless" torrents, 

featuring a DHT implementation that allows the 

client to download torrents that have been created

without using a BitTorrent tracker.