chord.js
is a peer-to-peer distributed hash table, built for modern browsers.
chord.js
provides two operations:
chord.put('key', value)
and:
chord.get('key').then(function(value) {
// do whatever
})
And the beauty of it? All browsers can get
the values that any browser put
, all without a centralized database. Indeed, all key-value pairs are spread across browsers. And make no mistake: all data are transferred directly between browsers.
What you can do with chord.js
is limited only by your imagination. PeerCDN could be implemented on top of it. Browser games could be implemented using it, without needing any databases. And so forth.
chord.js
uses two of the latest web technologies: WebRTC (using PeerJS) and localStorage. The underlying algorithm is Chord, therefore the name.
It's working already, but there are still a lot to be done. See the TODO list for details.
You will need Firefox 22+ or Chrome 26+. IE 11+ will most likely work, although it hasn't been tested against. Not sure about Safari and Opera.
To run it on a single machine:
- Clone this repo and
cd
into it npm install
cd server/
andnpm install
- From the base directory:
node server.js
node server/bin/peerjs --port=9000
- Open a private browser window and point it to
localhost:8000/index-for-original.html
- Open any number of private browser windows and point them to
localhost:8000
- Wait for about 10 seconds for the nodes to initialize
- Use the UI to put/get values.
To run it on multiple machines is basically the same. You can figure this out.
- Why do I need to run the PeerJS server?
The PeerJS server is used for handshake only. Once a connection is established between two browsers, they will send data to each other directly. Checkout PeerJS for details.
This also technically implies that only browsers using the same PeerJS server for handshakes can talk to each other.
- How many peers (browsers) does chord.js support?
chord.js
is an implementation of the Chord algorithm, which has a provable O(log n)
runtime performance.
- Clean up the code.
- Add a replication mechanism.
- Write tests.
- Work out the best way to manage connections.
- Benchmark.
- Optimize the startup process.
- Hash K-V pairs, for security reasons.
- Figure out the right rate to fix finger tables.
MIT.