├── .gitignore ├── LICENSE ├── README.md ├── index.html ├── index.js ├── package.json └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | node_modules 3 | *.ignore 4 | npm-debug.log* 5 | bundle.js 6 | *.swo 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Web-DHT 2 | 3 | Web-DHT is a demo showing one possible way for running a DHT within the web browser. It does this by utilizing [bittorrent-dht](https://github.com/feross/bittorrent-dht) as the DHT protococol and [peer-relay](https://github.com/xuset/peer-relay) as the underlying transport. 4 | 5 | ## How it works 6 | 7 | peer-relay is a p2p message relay that allows for peers to send messages to another without being directly connected to one another. This is possible because peer-relay forms it's own network of peers that it can relay messages through. A dgram-like socket interface is also provided which allows peer-relay to be used by packages that exepct a dgram socket like bittorrent-dht. Check out [peer-relay](https://github.com/xuset/peer-relay) for more info on how it works. 8 | 9 | A short snippet on how things are setup under the hood: 10 | ``` 11 | var PeerRelay = require('peer-relay') 12 | var DHT = require('bittorrent-dht') 13 | 14 | var socket = new PeerRelay.Socket(opts) 15 | 16 | var dht = new DHT({ 17 | socket: socket // All communication will go through the PeerRelay socket 18 | }) 19 | ``` 20 | 21 | ## Setup 22 | 23 | ```bash 24 | git clone https://github.com/xuset/web-dht/ 25 | cd web-dht 26 | npm install 27 | ``` 28 | 29 | To start the bootstrap/first peer run: 30 | ```bash 31 | npm start 8000 32 | ``` 33 | 34 | This will start a NodeJS peer that accepts connections over WebSocket on port 8000. NodeJS peers support incoming WebSockets connections and optionally incoming WebRTC connections while web browser peers only support incoming WebRTC connections. Both support outgoing WebSocket connections. 35 | 36 | To start a web browser peer open the `index.html` file with your browser either by double clicking or starting your own web server. It will attempt to bootstrap itself by first connecting to `ws://localhost:8000`. The `index.html` also provides a basic interface for the DHT by providing the ability to get and put static values in the DHT and also displaying some basic stats for that peer like who the peer is connected to. 37 | 38 | Multiple web browser peers can be started by opening `index.html` in multiple tabs/windows/browsers and they will start to connect to each other. 39 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
96 |