Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Get Rich Quick with P2P Crypto Currency $$$$$$$$$

Get Rich Quick with P2P Crypto Currency $$$$$$$$$

Presented at Nordic.js 2017. http://nordicjs.com

Let's build something together. Expect P2P, real-time video, and audience participation! More info coming soon.

Feross Aboukhadijeh
Feross is a programmer, designer, teacher, and mad scientist based in Mountain View, CA. He's currently building WebTorrent, a streaming BitTorrent client for the browser, powered by WebRTC. Before that, he built PeerCDN, a peer-to-peer content delivery network to makes sites faster and cheaper. He's a graduate of Stanford University and he has worked at Quora, Facebook, and Intel. In the past, he did research in the Stanford human-computer interaction and computer security labs. On his free time, he works on StudyNotes, a website to help students study better.

Feross Aboukhadijeh

September 07, 2017
Tweet

More Decks by Feross Aboukhadijeh

Other Decks in Technology

Transcript

  1. P2P

  2. P2P for cost reduction » Communication Skype, Hangouts » Music

    Spotify » OS Windows Update » Game Updates Blizzard, EVE Online » Content Delivery Network PeerCDN, Peer5
  3. P2P for resilience » File sharing BitTorrent, WebTorrent » Currency

    Bitcoin » Computation Ethereum » Web Tor, I2P, Freenet » Storage IPFS, Tahoe
  4. Download files with WebTorrent const WebTorrent = require('webtorrent') const client

    = new WebTorrent() client.add('magnet:...', function (torrent) { const file = torrent.files[0] // Display the file. Supports video, audio, images, etc. file.appendTo('body') })
  5. Share files with WebTorrent const WebTorrent = require('webtorrent') const dragDrop

    = require('drag-drop') const client = new WebTorrent() dragDrop('body', function (files) { client.seed(files, function (torrent) { console.log(torrent.magnetURI) }) })
  6. Signal Hub const signalhub = require('signalhub') const hub = signalhub('demo',

    ['http://localhost:8080']) // Broadcast to a channel hub.broadcast(channel, data) // Subscribe to a channel hub.subscribe(channel).on('data', function (message) { console.log(message) })
  7. const client = new WebTorrent() dragDrop('body', function (files) { client.seed(files[0],

    function (torrent) { hub.broadcast('torrent', torrent.magnetURI) torrent.files[0].appendTo('body') }) }) hub.subscribe('torrent').on('data', function (torrentId) { client.add(torrentId, function (torrent) { torrent.files[0].appendTo('body') }) })
  8. WebRTC handshake "i want to connect" "use this webrtc offer

    to contact me" ⏱ wait for a webrtc answer... "thanks for the webrtc answer!" ✅ connected!
  9. Simple Peer const Peer = require('simple-peer') const peer = new

    Peer() peer.on('signal', function (data) { sendToRemotePeer(data) // Send via any transport }) // Call this whern remote peer sends data function receiveFromRemotePeer (data) { peer.signal(data) }
  10. Simple Peer, Pt. 2 // Once the connection is established,

    say hello! peer.on('connect', function () { peer.send('Hello!') }) // Listen for data from remote peer peer.on('data', function (data) { console.log(data) })
  11. const randombytes = require('randombytes') const localPeerId = randombytes(8).toString('hex') hub.broadcast('hello', localPeerId)

    hub.subscribe('hello').on('data', function (peerId) { const peer = new Peer() peer.on('signal', function (signal) { hub.broadcast(peerId, signal) }) }) hub.subscribe(localPeerId, function (signal) { const peer = new Peer() peer.signal(signal) })
  12. const store = { messages: [], peers: [] } peer.on('data',

    function (message) { store.messages.push(message) update() }) function sendAll (text) { const message = { from: localPeerId, text: text } store.peers.map(function (peer) { if (peer.connected) peer.send(message) }) store.messages.push(message) update() }
  13. window.addEventListener('keydown', function (event) { if (event.key === 'ArrowUp') store.keys.up =

    true else if (event.key === 'ArrowDown') store.keys.down = true else if (event.key === 'ArrowLeft') store.keys.left = true else if (event.key === 'ArrowRight') store.keys.right = true else return event.preventDefault() }) window.addEventListener('keyup', function (event) { if (event.key === 'ArrowUp') store.keys.up = false else if (event.key === 'ArrowDown') store.keys.down = false else if (event.key === 'ArrowLeft') store.keys.left = false else if (event.key === 'ArrowRight') store.keys.right = false else return event.preventDefault() })
  14. peer.on('data', function (data) { if (data.x) peer.x = data.x if

    (data.y) peer.y = data.y if (data.vx) peer.vx = data.vx if (data.vy) peer.vy = data.vy }) setInterval(function () { sendAll(store.playerPosition) // { x: 0, y: 0, vx: 0, vy: 0 } }, 100) function sendAll (position) { store.peers.map(function (peer) { if (peer.connected) peer.send(position) }) }
  15. function tick () { if (store.keys.up) store.player.vy -= K_ACCEL if

    (store.keys.down) store.player.vy += K_ACCEL if (store.keys.left) store.player.vx -= K_ACCEL if (store.keys.right) store.player.vx += K_ACCEL store.player.x += store.player.vx store.player.y += store.player.vy store.peers.forEach(function (peer) { peer.x += peer.vx peer.y += peer.vy }) update() }
  16. P2P Challenges » Topologies are complex » Trust is harder

    » Architecture is more complicated » Fewer frameworks & less starter code
  17. P2P Advantages » Cool ✨ » Reduce costs for hosting

    » Offline support automatically (often) Also: » Privacy by design (often) » User controls their data » Safe against user-hostile changes