Introduction to the Bittorrent Protocol
-
Upload
tmont -
Category
Technology
-
view
6.853 -
download
4
description
Transcript of Introduction to the Bittorrent Protocol
![Page 1: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/1.jpg)
Introduction to the BitTorrent Protocol
Tommy Montgomery // March 2, 2010
![Page 2: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/2.jpg)
What is BitTorrent?
![Page 3: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/3.jpg)
What is BitTorrent? NOT illegal
![Page 4: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/4.jpg)
What is BitTorrent? NOT illegal Peer-to-peer (P2P) file transfer
![Page 5: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/5.jpg)
What is BitTorrent? NOT illegal Peer-to-peer (P2P) file transfer Awesome
![Page 6: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/6.jpg)
What is BitTorrent? NOT illegal Peer-to-peer (P2P) file transfer Awesome
![Page 7: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/7.jpg)
Poppycock! BitTorrent historically has a bad reputation,
due to its decentralized method of file transfer
This makes it difficult to “remove” a download, such as one that is illegal
BitTorrent is not inherently evil People are inherently evil I like bullet points
![Page 8: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/8.jpg)
How does it work?
![Page 9: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/9.jpg)
How does it work: Consumer Download torrent:
lots-o-cool-stuff-n-things.lulz.torrent
Open it in your favorite client:
![Page 10: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/10.jpg)
How does it work Files are downloaded piecemeal, from many
different places instead of just one Trackers are the central hub of control for
each torrent Each tracker manages your “peers”, which
are other people who are trying to download the same file
![Page 11: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/11.jpg)
Glossary
![Page 12: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/12.jpg)
Glossary Seeder
![Page 13: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/13.jpg)
Glossary Seeder
Someone who has finished downloading and is only uploading
![Page 14: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/14.jpg)
Glossary Seeder
Someone who has finished downloading and is only uploading
Leecher
![Page 15: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/15.jpg)
Glossary Seeder
Someone who has finished downloading and is only uploading
LeecherSomeone who is downloading
![Page 16: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/16.jpg)
Glossary Seeder
Someone who has finished downloading and is only uploading
LeecherSomeone who is downloading
Peer
![Page 17: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/17.jpg)
Glossary Seeder
Someone who has finished downloading and is only uploading
LeecherSomeone who is downloading
PeerThe collective term for seeders and leechers
![Page 18: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/18.jpg)
What is a torrent file? A Bencoded metadata file containing
information about one or more filesName/size/date of each file# of “pieces” of each fileSHA1 hash of each pieceTrackers for the torrent
![Page 19: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/19.jpg)
What is a “piece”? Torrents are made up of many small pieces You never download all the pieces from one
place (unless there’s only one seed) Pieces are usually less than a couple
megabytes each
![Page 20: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/20.jpg)
Bencoding Dictionaries
Prefixed with “d”, end with “e” Lists
Prefixed with “l”, end with “e” Integers
Prefixed with “i”, end with “e” Strings
Prefixed with string length + “:”
![Page 21: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/21.jpg)
Bencodingd3:foo3:bar4:lulzi8el5:hello5:worldee
![Page 22: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/22.jpg)
Bencodingd3:foo3:bar4:lulzi8el5:hello5:worldee
• Dictionary
![Page 23: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/23.jpg)
Bencodingd3:foo3:bar4:lulzi8el5:hello5:worldee
• Dictionary• String
![Page 24: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/24.jpg)
Bencodingd3:foo3:bar4:lulzi8el5:hello5:worldee
• Dictionary• String• Integer
![Page 25: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/25.jpg)
Bencodingd3:foo3:bar4:lulzi8el5:hello5:worldee
• Dictionary• String• Integer• List
![Page 26: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/26.jpg)
Trackers
![Page 27: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/27.jpg)
Trackers HTTP service that responds to GET requests Response is text/plain Bencoded dictionary Usually listens on port 6969
![Page 28: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/28.jpg)
Tracker Announce Request Usually has a billion GET params:
info_hash peer_id port uploaded downloaded left compact no_peer_id event ip numwant key trackerid
![Page 29: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/29.jpg)
Tracker Announce Request Important GET params:
info_hash○ the SHA1 hash of the piece to download
peer_id○ unique identifier of the person doing the
downloadingip/port○ the IP address and port of the peer
uploaded/downloaded/left○ used for calculating “share ratio”, i.e. how much the
tracker likes them
![Page 30: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/30.jpg)
Tracker Announce Response A Bencoded dictionary with these keys:
completeincompletetracker id (yes, that is a space)peerswarning messagefailure reason (only if an error occurred)intervalmin interval
![Page 31: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/31.jpg)
Tracker Announce Response The relevant parts:
peers○ Dictionary containing each peer’s IP address and
port○ Or, if the client wants it compact, a binary string of
each peer’s IP address and portinterval/min interval○ the interval in seconds which the client is allowed to
make a requestcomplete/incomplete○ number of seeders/leechers
![Page 32: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/32.jpg)
Tracker Implementation PHP/MySQL/Apache Why not?
![Page 33: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/33.jpg)
First, of course… We need a Bencoding library. Let’s roll our
own.
![Page 34: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/34.jpg)
![Page 35: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/35.jpg)
yay.
![Page 36: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/36.jpg)
It’s tracker time We need a way to keep track of peers, and
who’s downloaded what and stuff Let’s use MySQL
![Page 37: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/37.jpg)
![Page 38: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/38.jpg)
It’s tracker time Request is pretty boring, as it’s just a
glorified array with error handling
![Page 39: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/39.jpg)
It’s tracker time Response is a Bencoded dictionary, and is
also a glorified array
![Page 40: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/40.jpg)
![Page 41: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/41.jpg)
It’s tracker time Now we can set up an exception handler
that will send a proper response back in the event of a catastrophe
![Page 42: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/42.jpg)
It’s tracker time Now we can make the tracker announce the
peers
![Page 43: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/43.jpg)
![Page 44: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/44.jpg)
![Page 45: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/45.jpg)
Set up the torrent Now, stuff your tracker on a server
somewhere, listen on port 6969 Then add your tracker’s announce URL to a
torrent e.g. http://likeaboss.biz:6969/announce
![Page 46: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/46.jpg)
Other stuff Trackers are also facilitators and the
supreme overlords over the torrents they track
The list of peers that gets sent back to the client determines who downloads from whom
They will use download/upload statistics to determine who isn’t uploading/seeding, and punish them by giving them crappy peers
![Page 47: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/47.jpg)
Open source trackers OpenTracker (used by what’s left of The
Pirate Bay) XBT Tracker – implemented using UDP
instead of HTTP for ultimate efficiency MonoTorrent – cross-platform C#
implementation (client as well) PeerTracker – PHP 5 implementation
![Page 48: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/48.jpg)
In short… Unless you want to implement some weird
rules for who gets to download stuff, don’t write your own. I only did it for fun.
Because it’s fun.
![Page 49: Introduction to the Bittorrent Protocol](https://reader033.fdocuments.us/reader033/viewer/2022061221/54be00b44a7959b21f8b4587/html5/thumbnails/49.jpg)
Questions?