Angelo Sapello University of Delaware sapello@udel.edu BitTorrent Angelo Sapello University of Delaware sapello@udel.edu
Server vs. P2P Standard client/server model – all clients connect to a single server Peer to peer (P2P) – clients get the data they need from one or more other clients P2P may still require a server, but with a greatly reduced load
BitTorrent Terminology Torrent file – the meta-data file indicating what tracker to connect to and what the file should look like Tracker – an HTTP server that keeps track of the swarm Swarm – the group of peers downloading/uploading the file Seeder – A peer that has all the pieces of the file Leecher – A peer that only downloads
BitTorrent model User downloads a meta-data “torrent” file Peer connects to tracker server to get peer information Peer connects to other peers in the swarm Peer downloads pieces in a rarest first fashion Peer simultaneously uploads pieces to other peers Model defined by Bram Cohen
BitTorrent Transport Layer BitTorrent is a three part application layer protocol TCP provides all transport layer services Reliable: No need for ACKs by client Connection oriented: Minimal client handshakes Down-side: Multiple connections cause “fairness” issues Multiple port usage causes NAT/firewall clogging
Initial Seeder/Web Server: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Bobbi (Leecher): 128.175.75.65:52516 Allen: 123.35.92.56:53182 Angelo: 128.122.35.116:55103 Linda (Seeder): 128.175.75.13:57812 Tracker: /mytorrent: Linda:128.175.75.13:57812 Bobbi: 128.175.75.65:52516 Mandriva: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Allen: 123.35.92.56:49552 Initial Seeder/Web Server: 142.178.26.3:62189
Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked Sally: 135.116.234.110:53182 Uninterested Choked Bobbi (Leecher): 128.175.75.65:52516 Uninterested Choked Allen: 123.35.92.56:53182 Uninterested Choked Angelo: 128.122.35.116:55103 Uninterested Choked Linda (Seeder): 128.175.75.13:57812 Uninterested Choked Tracker: /mytorrent: Linda:128.175.75.13:57812 Bobbi: 128.175.75.65:52516 Mandriva: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Allen: 123.35.92.56:49552 Angelo: 128.122.35.116:55103 Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked
Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked Sally: 135.116.234.110:53182 Uninterested Unchoked Bobbi (Leecher): 128.175.75.65:52516 Uninterested Choked Allen: 123.35.92.56:53182 Uninterested Unchoked Angelo: 128.122.35.116:55103 Interested Choked Linda (Seeder): 128.175.75.13:57812 Uninterested Unchoked Tracker: /mytorrent: Linda:128.175.75.13:57812 Bobbi: 128.175.75.65:52516 Mandriva: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Allen: 123.35.92.56:49552 Angelo: 128.122.35.116:55103 Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked
Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked Sally: 135.116.234.110:53182 Interested Unchoked Bobbi (Leecher): 128.175.75.65:52516 Uninterested Choked Allen: 123.35.92.56:53182 Uninterested Unchoked Angelo: 128.122.35.116:55103 Interested Unchoked Linda (Seeder): 128.175.75.13:57812 Uninterested Unchoked Tracker: /mytorrent: Linda:128.175.75.13:57812 Bobbi: 128.175.75.65:52516 Mandriva: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Allen: 123.35.92.56:49552 Angelo: 128.122.35.116:55103 Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked
Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked Sally: 135.116.234.110:53182 Interested Unchoked Bobbi (Leecher): 128.175.75.65:52516 Uninterested Choked Allen: 123.35.92.56:53182 Uninterested Unchoked Angelo: 128.122.35.116:55103 Interested Unchoked Linda (Seeder): 128.175.75.13:57812 Uninterested Unchoked Tracker: /mytorrent: Linda:128.175.75.13:57812 Bobbi: 128.175.75.65:52516 Mandriva: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Allen: 123.35.92.56:49552 Angelo: 128.122.35.116:55103 Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked
Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked Sally: 135.116.234.110:53182 Interested Unchoked Bobbi (Leecher): 128.175.75.65:52516 Uninterested Choked Allen: 123.35.92.56:53182 Uninterested Unchoked Angelo: 128.122.35.116:55103 Uninterested Unchoked Linda (Seeder): 128.175.75.13:57812 Uninterested Unchoked Tracker: /mytorrent: Linda:128.175.75.13:57812 Bobbi: 128.175.75.65:52516 Mandriva: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Allen: 123.35.92.56:49552 Angelo: 128.122.35.116:55103 Initial Seeder/Web Server: 142.178.26.3:62189 Uninterested Choked
Initial Seeder/Web Server: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Bobbi (Leecher): 128.175.75.65:52516 Allen: 123.35.92.56:53182 Angelo: 128.122.35.116:55103 Linda (Seeder): 128.175.75.13:57812 Tracker: /mytorrent: Linda:128.175.75.13:57812 Bobbi: 128.175.75.65:52516 Mandriva: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Allen: 123.35.92.56:49552 Angelo: 128.122.35.116:55103 Initial Seeder/Web Server: 142.178.26.3:62189
Initial Seeder/Web Server: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Bobbi (Leecher): 128.175.75.65:52516 Allen: 123.35.92.56:53182 Angelo: 128.122.35.116:55103 Linda (Seeder): 128.175.75.13:57812 Tracker: /mytorrent: Linda:128.175.75.13:57812 Bobbi: 128.175.75.65:52516 Mandriva: 142.178.26.3:62189 Sally: 135.116.234.110:53182 Allen: 123.35.92.56:49552 Initial Seeder/Web Server: 142.178.26.3:62189
Meta-data format Information bencoded String “#:” ; any array of characters Integer “i” - “e” ; a signed integer Dictionary “d” - “e” ; key-value pairs List “l” - “e” ; an array of the above types Announce section – tracker information Info section – file and pieces information Pieces – a list of SHA-1 hash values of data chunks in the files
Meta-data file (cont'd) Multiple files are ordered and concatenated to download like a single file Example: d8:announce96:http://torrent.mandriva.com:6969/announce/Mandrivalinux/282cb77c390627c4 4133c0cb8a59ca4bb2d203be13:creation datei1257201206e4:infod5:filesld6:lengthi341985e4:pathl35:mandriva-linux-free- 2010.0-i586.idxeed6:lengthi4575985664e4:pathl35:mandriva-linux-free-2010.0- i586.isoeed6:lengthi70e4:pathl39:mandriva-linux-free-2010.0- i586.iso.md5eed6:lengthi78e4:pathl40:mandriva-linux-free-2010.0- i586.iso.sha1eee4:name31:mandriva-linux-free-2010.0-i58612:piece lengthi262144e6:pieces349160: To {“announce”:”http://torrent.mandriva.com:6969/announce/Mandrivalinux/282cb77c390627c44 133c0cb8a59ca4bb2d203be”,”creation date”:1257201206, “info”:{“files”:[{“length”:341985,”path”:[“mandriva-linux-free-2010.0-i586.idx”]}, {“length”:4575985664,”path”:[“mandriva-linux-free-2010.0-i586.iso”]}, {“length”:70,”path”:[“mandriva-linux-free-2010.0-i586.iso.md5”]}, {“length”:78,”path”:[“mandriva-linux-free-2010.0-i586.iso.sha1”]}], “name”:”mandriva-linux-free-2010.0-i586”,”piece length”:262144,”pieces”: Binary array of 20 byte SHA-1 hash codes of each 256KB data chunk }}
Peace of mind How do you ensure that a peer has not tainted the piece? SHA-1 hash algorithm proposed by NSA requires 2^80 hash operations to find a match pair by brute force. Mathematically broken in 2^63 operations. Poisoned pieces are rejected and peer is no longer recognized as part of the swarm
Tracker protocol Standard HTTP GET request/response Example: GET /announce/Mandrivalinux/282cb77c390627c44133c0cb8a59ca4bb2d203be?info_hash=%06g%e0g%98%a f%beN%f2%f6%40E%ad%0a%23U%dd%5d%d4%ba&peer_id=M6-4-0-- %afF%3bE%b8%c9%2b%94%f1%ac%bf%93&port=57917&uploaded=0&downloaded=0&left=4576327797&corr upt=0&key=66D4D19D&event=started&numwant=200&compact=1&no_peer_id=1&ipv6=2002%3a80af%3ae e1e%3a%3a80af%3aee1e HTTP/1.1 Host: torrent.mandriva.com:6969 User-Agent: BitTorrent/6400(18095) Accept-Encoding: gzip HTTP/1.0 200 OK Content-Length: 1230 Content-Type: text/plain Pragma: no-cache d8:intervali1800e5:peers1200: Binary encoded IP address, port number pairs for the entire (or subset of the) swarm or beconded dictionary or Peer ID, IP address, port triplets
BitTorrent protocol BitTorrent Handshake All other messages Protocol Name Length (1-byte = 19) Protocol Name (“BitTorrent protocol”) 64-bit reserved word Info dictionary hash (SHA1 20-bytes) Peer ID (20 bytes) All other messages Message length (32-bits/4-bytes) Message ID (8-bits/1-byte) Payload (Message length – 1 bytes)
BitTorrent Message IDs None (len = 0): Keep Alive 0: Choke = Not willing to send data 1: Unchoke = Willing to send data 2: Interested = Would like data 3: Not interested = Would not like data 4: Have = I have just downloaded this piece 5: Bitfield = I have these pieces 6: Request = I would like this block – index (piece), begin(offset) and length 7: Piece = Here is a block – index (piece), begin(offset) and block (actual data) 8: Cancel = I no longer want this block – index, begin, length
Wireshark Example
Other issues Leeching Firewall/NAT crashing Connection throttling (Comcast) Copyright protection
Questions? Additional resources BitTorrent Specification: http://www.bittorrent.org/beps/bep_0003.html BitTorrent Unofficial Explanation: http://wiki.theory.org/BitTorrentSpecification