Mathias Buus @mafintosh
javascript and bittorrent
... and MAD SCIENCE!
how does bittorrent work?
when people think of bittorent they usually think:
盗版!

bittorent is way more than this
normal way of fetching content online
server client
nice and simple
what happens when 1,000,000 clients arrive
client client client client client client server
client client client client client client server
client client client client client client server
what if clients just share data between each other instead?
peer peer peer peer peer
THIS IS P2P
But can we trust incoming data?
peer
split the file into pieces ~(512kb - 10mb) and hash each of them
[
  hash(piece_1),
  hash(piece_2),
  ...
  hash(piece_N)
]
If we get piece #1 we verify it using hash #1
we could store the list of hashes (torrent file) on a trusted server
server + torrent file
server + torrent file
RECURSION TO THE RESCUE!
magnet_link = hash([
  hash(piece_1),
  hash(piece_2),
  ...
  hash(piece_N)
])
peer hash(piece) peer
use magnet link to verify the hashes
... but how do we find peers that share our file?
DISTRIBUTED
HASH
TABLE
every peer joins the dht
{
  magnet_link_1: 'my-ip:my-port',
  magnet_link_2: 'my-ip:my-port',
  ...
}
  
~10,000,000 nodes at any time (source)
this is basically how bittorrent downloads data
PRETTY SIMPLE
bittorrent can distribute A LOT of content
we want to access ALL this content instantly
how can we make bittorrent stream?
streaming bittorrent means fetching pieces based on demand
me piece₅ peer
me piece₅ peer
me piece₅ peer piece₅ peer
me piece₅ peer piece₅ peer
me piece₅ peer piece₅ peer
me piece₅ peer piece₅ peer
concurrent fetch of most critical pieces
I IMPLEMENTED THIS
torrent-stream is a node module that does this
    var engine = torrentStream(torrentFile)
    var file = engine.files[0]
    var stream = file.createReadStream({
      start: 0,
      end: 1000
    })
  
streaming content is a
billion dollar industry
netflix uses ~1/3 of internet traffic during peak hours (source)
1/3!
what if we could stream video content using P2P?
peerflix streams video to vlc
Mathias, show demo of peerflix
where normal streaming decreases quality under load we could increase it
the more people who watch the video the better it runs
this is not a gimmick
MAD SCIENCE TIME
stream any content
all of wikipedia is on bittorrent
peerwiki browses wikipedia using bittorrent
Mathias, show demo of peerwiki
linux is on bittorrent
what if virtual box understood streams?
what if virtual box understood streams?
what if virtual box did not change a thing?
funny gifs
torrent-mount mounts a torrent as a file system
Mathias, show demo of torrent-mount
谢谢!
mathiasbuus@gmail.com
github.com/mafintosh
webtorrent
ipfs
scuttlebutt
dat
peermaps