Bit Torrent Angelo Sapello University of Delaware sapelloudel
Bit. Torrent Angelo Sapello University of Delaware sapello@udel. edu
Server vs. P 2 P Standard client/server model – all clients connect to a single server Peer to peer (P 2 P) – clients get the data they need from one or more other clients P 2 P may still require a server, but with a greatly reduced load
Bit. Torrent 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
Bit. Torrent 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
Bit. Torrent Transport Layer Bit. Torrent 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
Sally: 135. 116. 234. 110: 53182 Bobbi (Leecher): 128. 175. 65: 52516 Allen: 123. 35. 92. 56: 53182 Angelo: 128. 122. 35. 116: 55103 Tracker: /mytorrent: Linda: 128. 175. 13: 57812 Bobbi: 128. 175. 65: 52516 Mandriva: 142. 178. 26. 3: 62189 Sally: 135. 116. 234. 110: 53182 Allen: 123. 35. 92. 56: 49552 Linda (Seeder): 128. 175. 13: 57812 Initial Seeder/Web Server: 142. 178. 26. 3: 62189
Sally: 135. 116. 234. 110: 53182 Uninterested Choked Bobbi (Leecher): 128. 175. 65: 52516 Uninterested Choked Allen: 123. 35. 92. 56: 53182 Uninterested Choked Angelo: 128. 122. 35. 116: 55103 Uninterested Choked Tracker: /mytorrent: Linda: 128. 175. 13: 57812 Bobbi: 128. 175. 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 Linda (Seeder): 128. 175. 13: 57812 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. 65: 52516 Uninterested Choked Allen: 123. 35. 92. 56: 53182 Uninterested Unchoked Angelo: 128. 122. 35. 116: 55103 Interested Choked Tracker: /mytorrent: Linda: 128. 175. 13: 57812 Bobbi: 128. 175. 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 Linda (Seeder): 128. 175. 13: 57812 Uninterested Unchoked Initial Seeder/Web Server: 142. 178. 26. 3: 62189 Uninterested Choked
Sally: 135. 116. 234. 110: 53182 Interested Unchoked Bobbi (Leecher): 128. 175. 65: 52516 Uninterested Choked Allen: 123. 35. 92. 56: 53182 Uninterested Unchoked Angelo: 128. 122. 35. 116: 55103 Interested Unchoked Tracker: /mytorrent: Linda: 128. 175. 13: 57812 Bobbi: 128. 175. 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 Linda (Seeder): 128. 175. 13: 57812 Uninterested Unchoked Initial Seeder/Web Server: 142. 178. 26. 3: 62189 Uninterested Choked
Sally: 135. 116. 234. 110: 53182 Interested Unchoked Bobbi (Leecher): 128. 175. 65: 52516 Uninterested Choked Allen: 123. 35. 92. 56: 53182 Uninterested Unchoked Angelo: 128. 122. 35. 116: 55103 Interested Unchoked Tracker: /mytorrent: Linda: 128. 175. 13: 57812 Bobbi: 128. 175. 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 Linda (Seeder): 128. 175. 13: 57812 Uninterested Unchoked Initial Seeder/Web Server: 142. 178. 26. 3: 62189 Uninterested Choked
Sally: 135. 116. 234. 110: 53182 Interested Unchoked Bobbi (Leecher): 128. 175. 65: 52516 Uninterested Choked Allen: 123. 35. 92. 56: 53182 Uninterested Unchoked Angelo: 128. 122. 35. 116: 55103 Uninterested Unchoked Tracker: /mytorrent: Linda: 128. 175. 13: 57812 Bobbi: 128. 175. 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 Linda (Seeder): 128. 175. 13: 57812 Uninterested Unchoked Initial Seeder/Web Server: 142. 178. 26. 3: 62189 Uninterested Choked
Sally: 135. 116. 234. 110: 53182 Bobbi (Leecher): 128. 175. 65: 52516 Allen: 123. 35. 92. 56: 53182 Angelo: 128. 122. 35. 116: 55103 Tracker: /mytorrent: Linda: 128. 175. 13: 57812 Bobbi: 128. 175. 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 Linda (Seeder): 128. 175. 13: 57812 Initial Seeder/Web Server: 142. 178. 26. 3: 62189
Sally: 135. 116. 234. 110: 53182 Bobbi (Leecher): 128. 175. 65: 52516 Allen: 123. 35. 92. 56: 53182 Angelo: 128. 122. 35. 116: 55103 Tracker: /mytorrent: Linda: 128. 175. 13: 57812 Bobbi: 128. 175. 65: 52516 Mandriva: 142. 178. 26. 3: 62189 Sally: 135. 116. 234. 110: 53182 Allen: 123. 35. 92. 56: 49552 Linda (Seeder): 128. 175. 13: 57812 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: d 8: announce 96: http: //torrent. mandriva. com: 6969/announce/Mandrivalinux/282 cb 77 c 390627 c 4 4133 c 0 cb 8 a 59 ca 4 bb 2 d 203 be 13: creation datei 1257201206 e 4: infod 5: filesld 6: lengthi 341985 e 4: pathl 35: mandriva-linux-free 2010. 0 -i 586. idxeed 6: lengthi 4575985664 e 4: pathl 35: mandriva-linux-free-2010. 0 i 586. isoeed 6: lengthi 70 e 4: pathl 39: mandriva-linux-free-2010. 0 i 586. iso. md 5 eed 6: lengthi 78 e 4: pathl 40: mandriva-linux-free-2010. 0 i 586. iso. sha 1 eee 4: name 31: mandriva-linux-free-2010. 0 -i 58612: piece lengthi 262144 e 6: pieces 349160: To {“announce”: ”http: //torrent. mandriva. com: 6969/announce/Mandrivalinux/282 cb 77 c 390627 c 44 133 c 0 cb 8 a 59 ca 4 bb 2 d 203 be”, ”creation date”: 1257201206, “info”: {“files”: [{“length”: 341985, ”path”: [“mandriva-linux-free-2010. 0 -i 586. idx”]}, {“length”: 4575985664, ”path”: [“mandriva-linux-free-2010. 0 -i 586. iso”]}, {“length”: 70, ”path”: [“mandriva-linux-free-2010. 0 -i 586. iso. md 5”]}, {“length”: 78, ”path”: [“mandriva-linux-free-2010. 0 -i 586. iso. sha 1”]}], “name”: ”mandriva-linux-free-2010. 0 -i 586”, ”piece length”: 262144, ”pieces”: Binary array of 20 byte SHA-1 hash codes of each 256 KB 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/282 cb 77 c 390627 c 44133 c 0 cb 8 a 59 ca 4 bb 2 d 203 be? info_hash=%06 g%e 0 g%98%a f%be. N%f 2%f 6%40 E%ad%0 a%23 U%dd%5 d%d 4%ba&peer_id=M 6 -4 -0 -%af. F%3 b. E%b 8%c 9%2 b%94%f 1%ac%bf%93&port=57917&uploaded=0&downloaded=0&left=4576327797&corr upt=0&key=66 D 4 D 19 D&event=started&numwant=200&compact=1&no_peer_id=1&ipv 6=2002%3 a 80 af%3 ae e 1 e%3 a%3 a 80 af%3 aee 1 e HTTP/1. 1 Host: torrent. mandriva. com: 6969 User-Agent: Bit. Torrent/6400(18095) Accept-Encoding: gzip HTTP/1. 0 200 OK Content-Length: 1230 Content-Type: text/plain Pragma: no-cache d 8: intervali 1800 e 5: peers 1200: 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
Bit. Torrent protocol Bit. Torrent Handshake Protocol Name Length (1 -byte = 19) Protocol Name (“Bit. Torrent protocol”) 64 -bit reserved word Info dictionary hash (SHA 1 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)
Bit. Torrent 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 Bit. Torrent Specification: http: //www. bittorrent. org/beps/bep_0003. html Bit. Torrent Unofficial Explanation: http: //wiki. theory. org/Bit. Torrent. Specification
- Slides: 22