Bittorrent Protocol Lecture20

Embed Size (px)

Citation preview

  • 8/10/2019 Bittorrent Protocol Lecture20

    1/76

    The BitTorrent Protocol

    Taken from

    http://www.cs.uiowa.edu/~ghosh/bittorrent.ppt

    http://www.cs.uiowa.edu/~ghosh/bittorrent.ppthttp://www.cs.uiowa.edu/~ghosh/bittorrent.ppt
  • 8/10/2019 Bittorrent Protocol Lecture20

    2/76

    What is BitTorrent?

    Efficient content distribution system using

    file swarming. Usually does not performall the functionsof a typical p2p system,

    like searching.

  • 8/10/2019 Bittorrent Protocol Lecture20

    3/76

    BitTorrent traffic

    CacheLogic estimated that BitTorrent traffic

    accounts for roughly 35% of all traffic on the

    Internet.

  • 8/10/2019 Bittorrent Protocol Lecture20

    4/76

    File sharing

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

    creates a .torrentfile, a small file that contains

    (1)metadataabout the files to be shared, and(2) Information about the tracker, the computer

    that coordinates the file distribution.

    Peers first obtain a .torrentfile, and then connectto the specified tracker,which tells them from which

    other peers to download the piecesof the file.

  • 8/10/2019 Bittorrent Protocol Lecture20

    5/76

    BT Components

    On a public domain site, obtain .torrent file.

    for example:

    http://bt.LOR.net

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

    Harry Potter.torrentTransformer.torrent

    The Lord of Ring.torrent

    http://bt.lor.net/http://bt.lor.net/
  • 8/10/2019 Bittorrent Protocol Lecture20

    6/76

    File sharing

    Large files are broken into pieces of size between

    64 KB and 1 MB

    1 2 3 4 5 6 7 8

  • 8/10/2019 Bittorrent Protocol Lecture20

    7/76

    BT: publishing a file

    Web Server

    Bob

  • 8/10/2019 Bittorrent Protocol Lecture20

    8/76

    BT: publishing a file

    Web Server

    Bob

  • 8/10/2019 Bittorrent Protocol Lecture20

    9/76

    BT: publishing a file

    Web Server

    Bob

  • 8/10/2019 Bittorrent Protocol Lecture20

    10/76

    BT: publishing a file

    Web Server

    BobHarry Potter.torrent

  • 8/10/2019 Bittorrent Protocol Lecture20

    11/76

    BT: publishing a file

    Bob

    Tracker

    Harry Potter.torrent

  • 8/10/2019 Bittorrent Protocol Lecture20

    12/76

    BT: publishing a file

    Bob

    Tracker

    Harry Potter.torrent

  • 8/10/2019 Bittorrent Protocol Lecture20

    13/76

    BT: publishing a file

    Bob

    Tracker

    Harry Potter.torrent

  • 8/10/2019 Bittorrent Protocol Lecture20

    14/76

    BT: publishing a file

    Bob

    Tracker

    Harry Potter.torrent

  • 8/10/2019 Bittorrent Protocol Lecture20

    15/76

    BT: publishing a file

    Bob

    Tracker

    Harry Potter.torrent

  • 8/10/2019 Bittorrent Protocol Lecture20

    16/76

    BT: publishing a file

    Bob

    Tracker

    Downloader:

    ASeeder:

    BDownloader:

    C

    Harry Potter.torrent

  • 8/10/2019 Bittorrent Protocol Lecture20

    17/76

    BT: publishing a file

    Bob

    Tracker

    Downloader:

    ASeeder:

    BDownloader:

    C

    Harry Potter.torrent

  • 8/10/2019 Bittorrent Protocol Lecture20

    18/76

    The .torrent file

    The URL of the tracker

    Pieces

    Piece length

    Name

    Length of the file

  • 8/10/2019 Bittorrent Protocol Lecture20

    19/76

    The Tracker

    IP address, port, peer id

    State information (Completed or Downloading)

    Returns a random list of peers

  • 8/10/2019 Bittorrent Protocol Lecture20

    20/76

    BitTorrent Lingo

    Seeder= a peer that provides the complete file.

    Initial seeder= a peer that provides the initial copy.

    Initial seeder

    Seeder

    Leecher

    One who is downloading

    (not a derogatory term)

    Leecher

  • 8/10/2019 Bittorrent Protocol Lecture20

    21/76

    Simple example

    Seeder:A

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

  • 8/10/2019 Bittorrent Protocol Lecture20

    22/76

    Simple example

    Seeder:A

    Downloader B

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

    {}

  • 8/10/2019 Bittorrent Protocol Lecture20

    23/76

    Simple example

    Seeder:A

    Downloader B

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

    {}

  • 8/10/2019 Bittorrent Protocol Lecture20

    24/76

    Simple example

    Seeder:A

    Downloader B

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

    {1,2,3}

  • 8/10/2019 Bittorrent Protocol Lecture20

    25/76

    Simple example

    Seeder:A

    Downloader B

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

    {1,2,3}

    Downloader C

    {}

  • 8/10/2019 Bittorrent Protocol Lecture20

    26/76

    Simple example

    Seeder:A

    Downloader B

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

    {1,2,3}

    Downloader C

    {}

  • 8/10/2019 Bittorrent Protocol Lecture20

    27/76

    Simple example

    Seeder:A

    Downloader B

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

    Downloader C

    {1,2,3}

    {1,2,3,4}

  • 8/10/2019 Bittorrent Protocol Lecture20

    28/76

    Simple example

    Seeder:A

    Downloader B

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

    Downloader C

    {1,2,3}

    {1,2,3,4}

  • 8/10/2019 Bittorrent Protocol Lecture20

    29/76

    Simple example

    Seeder:A

    Downloader B

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

    Downloader C

    {1,2,3,4}

    {1,2,3,5}

  • 8/10/2019 Bittorrent Protocol Lecture20

    30/76

    Simple example

    Seeder:A

    Downloader B

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

    Downloader C

    {1,2,3,4}

    {1,2,3,5}

  • 8/10/2019 Bittorrent Protocol Lecture20

    31/76

    Simple example

    Seeder:A

    Downloader B

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

    Downloader C

    {1,2,3,5}

    {1,2,3,4,5}

  • 8/10/2019 Bittorrent Protocol Lecture20

    32/76

    Basic Idea

    Initial seeder chops file into many pieces.

    Leecher first locates the .torrentfile 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

    each leecher becomes a seeder by obtaining all the pieces,

    and assembles the file. Verifies the checksum.

  • 8/10/2019 Bittorrent Protocol Lecture20

    33/76

    Operation

  • 8/10/2019 Bittorrent Protocol Lecture20

    34/76

    Pieces and Sub-Pieces

    A piece is broken into sub-pieces ...

    typically 16KB in size

    Until a piece is assembled, only downloadthe sub-pieces of that piece only

    This policy lets pieces assemble quickly

  • 8/10/2019 Bittorrent Protocol Lecture20

    35/76

    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

    request is sent out.

  • 8/10/2019 Bittorrent Protocol Lecture20

    36/76

    Piece Selection

    The order in which pieces are selected by differentpeers 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 ofeasily available pieces, and none of the missing

    ones.

    If the original seed is prematurely taken down,

    then the file cannot be completely downloaded!What are good policies?

    BT i t l Ch k S l ti

  • 8/10/2019 Bittorrent Protocol Lecture20

    37/76

    BT: internal Chunk Selection

    mechanisms

    Strict Priority

    First Priority

    Rarest First General rule

    Random First Piece

    Special case, at the beginning Endgame Mode

    Special case

  • 8/10/2019 Bittorrent Protocol Lecture20

    38/76

    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

  • 8/10/2019 Bittorrent Protocol Lecture20

    39/76

    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 till the end to

    download.

  • 8/10/2019 Bittorrent Protocol Lecture20

    40/76

    Endgame Mode

    Near the end, missing pieces are requested fromevery peer containing them. When the piecearrives, 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 slowtransfer rate.

    Some bandwidth is wasted, but in practice, this isnot too much.

  • 8/10/2019 Bittorrent Protocol Lecture20

    41/76

    BT: internal mechanism

    Built-in incentivemechanism (where all the

    magic happens):

    Choking Algorithm

    Optimistic Unchoking

  • 8/10/2019 Bittorrent Protocol Lecture20

    42/76

    Choking

    Chokingis a temporary refusalto upload. It is

    one of BitTorrents most powerful idea to deal

    with free riders (those who only download but

    never upload).

    Tit-for-tat strategyis based on game-theoretic

    concepts.

  • 8/10/2019 Bittorrent Protocol Lecture20

    43/76

    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)..

  • 8/10/2019 Bittorrent Protocol Lecture20

    44/76

    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)..

  • 8/10/2019 Bittorrent Protocol Lecture20

    45/76

    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

  • 8/10/2019 Bittorrent Protocol Lecture20

    46/76

    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

    C i

  • 8/10/2019 Bittorrent Protocol Lecture20

    47/76

    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

    Ch ki

  • 8/10/2019 Bittorrent Protocol Lecture20

    48/76

    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

    Ch ki

  • 8/10/2019 Bittorrent Protocol Lecture20

    49/76

    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

    Ch ki

  • 8/10/2019 Bittorrent Protocol Lecture20

    50/76

    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

    Ch ki

  • 8/10/2019 Bittorrent Protocol Lecture20

    51/76

    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

    Choked

    Ch ki

  • 8/10/2019 Bittorrent Protocol Lecture20

    52/76

    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

    Choked

    Ch ki

  • 8/10/2019 Bittorrent Protocol Lecture20

    53/76

    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

    ChokedChoked

  • 8/10/2019 Bittorrent Protocol Lecture20

    54/76

    More on Choking

    Peers try out unused connectionsonce in a

    while to find out if they might be better than

    the current ones (optimistic unchoking).

    O ti i ti h ki

  • 8/10/2019 Bittorrent Protocol Lecture20

    55/76

    Optimistic unchoking

  • 8/10/2019 Bittorrent Protocol Lecture20

    56/76

    Optimistic nchoking

  • 8/10/2019 Bittorrent Protocol Lecture20

    57/76

    Optimistic unchoking

    A BitTorrent peer has a single optimisticunchoke to which it uploads regardless of thecurrent download rate from it. This peer rotatesevery 30s

    Optimistic unchoking

  • 8/10/2019 Bittorrent Protocol Lecture20

    58/76

    Optimistic unchoking

    A BitTorrent peer has a single optimisticunchoke to which it uploads regardless of thecurrent download rate from it. This peer rotatesevery 30s

    Reasons:

    Optimistic unchoking

  • 8/10/2019 Bittorrent Protocol Lecture20

    59/76

    Optimistic unchoking

    A BitTorrent peer has a single optimisticunchoke to which it uploads regardless of thecurrent download rate from it. This peer rotatesevery 30s

    Reasons:

    To discover currently unused connections are better

    than the ones being used

    Optimistic unchoking

  • 8/10/2019 Bittorrent Protocol Lecture20

    60/76

    Optimistic unchoking

    A BitTorrent peer has a single optimisticunchoke to which it uploads regardless of thecurrent download rate from it. This peer rotatesevery 30s

    Reasons:

    To discover currently unused connections are better

    than the ones being used To provide minimal service to new peers

  • 8/10/2019 Bittorrent Protocol Lecture20

    61/76

    Upload-Only mode

    Once download is complete, a peer has nodownload rates to use for comparison norhas any need to use them. The question is,

    which nodes to upload to?

    Policy: Upload to those with the best uploadrate. This ensures that pieces get replicatedfaster, and new seeders are created fast

  • 8/10/2019 Bittorrent Protocol Lecture20

    62/76

  • 8/10/2019 Bittorrent Protocol Lecture20

    63/76

    Questions about BT

    Which features contribute to the efficiency of BitTorrent?

  • 8/10/2019 Bittorrent Protocol Lecture20

    64/76

    Questions about BT

    Which features contribute to the efficiency of BitTorrent?

    What is the effect of bandwidth constraints?

  • 8/10/2019 Bittorrent Protocol Lecture20

    65/76

    Questions about BT

    Which features contribute to the efficiency of BitTorrent?

    What is the effect of bandwidth constraints?

    Is the Rarest Firstpolicy really necessary?

  • 8/10/2019 Bittorrent Protocol Lecture20

    66/76

    Questions about BT

    Which features contribute to the efficiency of BitTorrent?

    What is the effect of bandwidth constraints?

    Is the Rarest Firstpolicy really necessary?

    Must nodes perform seedingafter downloading is complete?

  • 8/10/2019 Bittorrent Protocol Lecture20

    67/76

    Questions about BT

    Which features contribute to the efficiency of BitTorrent?

    What is the effect of bandwidth constraints?

    Is the Rarest Firstpolicy really necessary?

    Must nodes perform seedingafter downloading is complete?

    How serious is the Last Piece Problem?

  • 8/10/2019 Bittorrent Protocol Lecture20

    68/76

    Questions about BT

    Which features contribute to the efficiency of BitTorrent?

    What is the effect of bandwidth constraints?

    Is the Rarest Firstpolicy really necessary?

    Must nodes perform seedingafter downloading is complete?

    How serious is the Last Piece Problem?

    Does the incentive mechanismaffect the performance much?

    O

  • 8/10/2019 Bittorrent Protocol Lecture20

    69/76

    One more example

    peer A

    peer B

    peer C

    peer D

    peer E

    O l

  • 8/10/2019 Bittorrent Protocol Lecture20

    70/76

    One more example

    peer A

    peer B

    peer C

    peer D

    peer E

    HELLO

    HELLO

    HELLO

    HELLO

    O l

  • 8/10/2019 Bittorrent Protocol Lecture20

    71/76

    One more example

    peer A

    peer B

    peer C

    peer D

    peer E

    Bitmap

    Bitmap

    Bitmap

    Bitmap

    O l

  • 8/10/2019 Bittorrent Protocol Lecture20

    72/76

    One more example

    peer A

    peer B

    peer C

    peer D

    peer E

    RequestC

    1

    RequestC5

    O l

  • 8/10/2019 Bittorrent Protocol Lecture20

    73/76

    One more example

    peer A

    peer B

    peer C

    peer D

    peer E

    RequestC

    1

    RequestC5

    Without uploadconstraint

    O l

  • 8/10/2019 Bittorrent Protocol Lecture20

    74/76

    One more example

    peer A

    peer B

    peer C

    peer D

    peer E

    C1

    C5

    Without uploadconstraint

    O l

  • 8/10/2019 Bittorrent Protocol Lecture20

    75/76

    One more example

    peer A

    peer B

    peer C

    peer D

    peer E

    C1

    C5

    Without uploadconstraint

    With uploadconstraint

  • 8/10/2019 Bittorrent Protocol Lecture20

    76/76

    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.