Share
Embed
Transcript
136 slides
-
GET /file.txt HTTP/1.1 HTTP request HTTP response HTTP/1.1 200 OK
URL: http://example.com/file.txt -
client client client client client client client client client client
client HTTP server -
client client client client client client client client client client
client client HTTP server -
client client client client client client client client client client
client client client HTTP server -
REQUEST 0 0 16384 BitTorrent request BitTorrent response PIECE 0
0 <data> method piece index byte offset length method piece index byte offset piece data -
No central point of failure Fast downloads Efficient protocol Every
downloader also uploads Decentralized -
Peer 1 Peer 2 Peer 3 0 1 2 3
4 0 1 2 3 4 0 1 2 3 4 You 0 1 2 3 4 -
Peer 1 Peer 2 Peer 3 0 1 2 3
4 0 1 2 3 4 0 1 2 3 4 You 0 1 2 3 4 -
Peer 1 Peer 2 Peer 3 0 1 2 3
4 0 1 2 3 4 0 1 2 3 4 You 0 1 2 3 4 0 1 3 -
Peer 1 Peer 2 Peer 3 0 1 2 3
4 0 1 2 3 4 0 1 2 3 4 You 0 1 2 3 4 0 1 3 2 4 -
Peer 1 Peer 2 Peer 3 0 1 2 3
4 0 1 2 3 4 0 1 2 3 4 You 0 1 2 3 4 0 2 3 4 0 1 2 -
Request same piece from multiple peers Tit-for-tat Help peers that
help us Preempt slow peers Download rarest piece first Preserve torrent health Incentivize peers to trade with us -
Torrent file { name: 'My awesome file', pieces:[ '1f9c3f59beec079715ec53324bde8569e4a0b4eb', 'ec42307d4ce5557b5d3964c5ef55d354cf4a6ecc',
'7bf1bcaf79d11fa5e0be06593c8faafc0c2ba2cf', '76d71c5b01526b23007f9e9929beafc5151e6511' ], announce: 'http://tracker.example.com' } -
Torrent file { name: 'My awesome file', pieces:[ '1f9c3f59beec079715ec53324bde8569e4a0b4eb', 'ec42307d4ce5557b5d3964c5ef55d354cf4a6ecc',
'7bf1bcaf79d11fa5e0be06593c8faafc0c2ba2cf', '76d71c5b01526b23007f9e9929beafc5151e6511' ], announce: 'http://tracker.example.com' } Info Hash: d2474e86c95b19b8bcfdb92bc12c9d44667cfa36 -
Cryptographic hashes • “One-way function” • Same input always produces
same output • Given output, very very hard to find input -
Tracker server { 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36': [ '12.34.56.78:3000', '34.56.78.12:4000', '56.78.12.34:5000' ], '52164f03629fd1322636babb2c014b7dae582da4':
[ '12.34.56.78:3000', '34.56.78.12:4000', '56.78.12.34:5000' ] } -
Decentralization HTTP Torrent files Magnet links Find URIs Search engines,
friends Search engines, friends Search engines, friend Find peers DNS (Domain Name System) Tracker server DHT (Distributed Hash Tabl File transfer Single HTTP server Many BitTorrent peers Many BitTorrent peers -
Decentralization HTTP Torrent files Magnet links Find URIs Search engines,
friends Search engines, friends Search engines, friend Find peers DNS (Domain Name System) Tracker server DHT (Distributed Hash Tabl File transfer Single HTTP server Many BitTorrent peers Many BitTorrent peers -
Decentralization HTTP Torrent files Magnet links Find URIs Search engines,
friends Search engines, friends Search engines, friend Find peers DNS (Domain Name System) Tracker server DHT (Distributed Hash Tabl File transfer Single HTTP server Many BitTorrent peers Many BitTorrent peers -
Distributed Hash Table • Distributed key-value lookup • Efficient (Kademlia)
• Every peer is a tracker server -
• if new peer would make bucket K+1 • if
our ID is in the bucket • split the bucket, & add the new peer • else • ping all peers in bucket • if some peer is dead • replace dead peer with new peer • else • throw away new peer Bucket size cannot surpass K -
Distributed Hash Table 0 2160 a node's table is densest
around it's own id -
put(key, value) • if key is “near” our node ID
• store the { key, value } • else • throw it away -
put(key, value) • if key is “near” our node ID
• store the { key, value } • else • throw it away put( 'e88e8338c572a06e3c801b29f519df532b3e76f6', '12.34.56.78:3000' ) -
DHT storage { 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36': [ '12.34.56.78:3000', '34.56.78.12:4000', '56.78.12.34:5000' ], 'd2474e86629fd1322636babb2c014b7dae582da4':
[ '12.34.56.78:3000', '34.56.78.12:4000', '56.78.12.34:5000' ] } -
lookup(key) • pick K closest nodes, send them lookup(key) message
• if they return new DHT nodes (that are closer) • send them lookup(key) message & recurse • else if they return peers (they are a tracker!) • we're done – connect to the peers! -
Distributed Hash Table 0 2160 a node's table is densest
around it's own id -
Distributed Hash Table • Fast O(log n) lookup, where n
is number of nodes • Over time, table fills with stable, long-running nodes -
Decentralization HTTP Torrent files Magnet links Find URIs Search engines,
friends Search engines, friends Search engines, friends Find peers DNS (Domain Name System) Tracker server DHT (Distributed Hash Table) File transfer Single HTTP server Many BitTorrent peers Many BitTorrent peers -
“A project to bring realtime communication (RTC) to the open
web platform” - Justin Uberti @ Google I/O 2012 -
bittorrent bittorrent bittorrent bittorrent hybrid hybrid webtorrent webtorrent webtorrent (webrtc)
bittorrent webtorrent IMPORTANT! -
bittorrent bittorrent bittorrent bittorrent hybrid hybrid webtorrent webtorrent webtorrent (webrtc)
bittorrent webtorrent IMPORTANT! -
Usage: webtorrent <options> <torrent> Download the torrent, given as: *
magnet uri * http/https url to .torrent file * filesystem path to .torrent file * info hash (as hex string) Options: --airplay stream to Apple TV (AirPlay) --chromecast stream to Chromecast --vlc stream in VLC --mplayer stream in MPlayer --mpv stream in MPV --omx [jack] stream in omx (jack=local|hdmi) -p, --port [number] change the http port [default: 9000] -b, --blocklist [path] use the specified blocklist -t, --subtitles [file] load subtitles file -l, --list list available files in torrent -n, --no-quit do not quit webtorrent on vlc exit -r, --remove remove downloaded files on exit -q, --quiet silence stdout -
webtorrent bittorrent-dht bittorrent-protocol bittorrent-tracker bittorrent-swarm ut_metadata magnet-uri parse-torrent extension torrent-discovery
create-torrent ut_pex parse-torrent-file magnet-uri -
webtorrent bittorrent-dht bittorrent-protocol bittorrent-tracker bittorrent-swarm ut_metadata magnet-uri parse-torrent extension torrent-discovery
create-torrent ut_pex parse-torrent-file magnet-uri -
new RTCPeerConnection(constraints, config) <offer> pc Server createOffer() getUserMedia() addStream() <stream>
“negotiationneeded” setLocalDescription() -
new RTCPeerConnection(constraints, config) <offer> <offer> pc Server createOffer() getUserMedia() addStream()
<stream> “negotiationneeded” setLocalDescription() -
new RTCPeerConnection(constraints, config) <offer> <offer> pc Server new RTCPeerConnection(…) createOffer()
getUserMedia() addStream() <stream> “negotiationneeded” setLocalDescription() -
new RTCPeerConnection(constraints, config) <offer> <offer> pc Server pc new RTCPeerConnection(…)
createOffer() getUserMedia() addStream() <stream> “negotiationneeded” setLocalDescription() -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> pc Server pc new
RTCPeerConnection(…) createOffer() getUserMedia() addStream() <stream> “negotiationneeded” setLocalDescription() -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> pc Server pc new
RTCPeerConnection(…) createOffer() getUserMedia() addStream() <stream> getUserMedia() “negotiationneeded” setLocalDescription() -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> pc Server pc new
RTCPeerConnection(…) createOffer() getUserMedia() addStream() <stream> getUserMedia() <stream> “negotiationneeded” setLocalDescription() -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() pc Server pc
new RTCPeerConnection(…) createOffer() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() pc Server pc
new RTCPeerConnection(…) createOffer() createAnswer() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() pc Server pc
new RTCPeerConnection(…) createOffer() createAnswer() <answer> getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() pc Server pc
new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() pc Server pc
new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() pc Server pc
new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() pc Server pc
new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> pc
Server pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> pc
Server ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> pc
Server <candidate> ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> pc
Server <candidate> addIceCandidate() ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> <candidate>
“icecandidate” pc Server <candidate> addIceCandidate() ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> <candidate>
“icecandidate” pc Server <candidate> addIceCandidate() ⋮ ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> <candidate>
“icecandidate” pc Server <candidate> addIceCandidate() <candidate> ⋮ ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> <candidate>
“icecandidate” pc Server <candidate> addIceCandidate() <candidate> ⋮ ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() addIceCandidate() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> <candidate>
“icecandidate” pc Server <candidate> addIceCandidate() <candidate> ⋮ ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() addIceCandidate() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” “addstream” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> <candidate>
“icecandidate” pc Server <candidate> addIceCandidate() <candidate> ⋮ ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() addIceCandidate() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” “addstream” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> <candidate>
“icecandidate” pc Server <candidate> addIceCandidate() <candidate> ⋮ ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() addIceCandidate() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” “addstream” “addstream” -
setRemoteDescription() new RTCPeerConnection(constraints, config) <offer> <offer> setLocalDescription() “icecandidate” <candidate> <candidate>
“icecandidate” pc Server <candidate> addIceCandidate() <candidate> ⋮ ⋮ pc new RTCPeerConnection(…) createOffer() setLocalDescription() createAnswer() <answer> <answer> setRemoteDescription() addIceCandidate() getUserMedia() addStream() <stream> getUserMedia() addStream() <stream> “negotiationneeded” “addstream” “addstream” -
TUTORIALS, HELP, MORE… FALLBACK TO HTTP DOCUMENTATION BUILD WEBTORRENT APPS
CALLING MAD SCIENTISTS! WEB SEEDS -
THIS IS STILL UNIMPLEMENTED JS EVERYWHERE WEBRTC DHT NATIVE APP
NODE-WEBKIT CHROME/FIREFOX APPS