Giter VIP home page Giter VIP logo

chord.js's Introduction

chord.js

chord.js is a peer-to-peer distributed hash table, built for modern browsers.

Introduction

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.

Status

It's working already, but there are still a lot to be done. See the TODO list for details.

Run the sample app

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:

  1. Clone this repo and cd into it
  2. npm install
  3. cd server/ and npm install
  4. From the base directory: node server.js
  5. node server/bin/peerjs --port=9000
  6. Open a private browser window and point it to localhost:8000/index-for-original.html
  7. Open any number of private browser windows and point them to localhost:8000
  8. Wait for about 10 seconds for the nodes to initialize
  9. Use the UI to put/get values.

To run it on multiple machines is basically the same. You can figure this out.

FAQ

  • 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.

TODO

  • 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.

License

MIT.

chord.js's People

Contributors

derekchiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

chord.js's Issues

Doesn't work anymore

On the first node I'm getting this in a loop:

Both PeerJS server and the node server appear to be running fine.

connecting to: the original id chord.js:35
Object {id: "the original id", hash: 794953216813279} chord.js:35
null chord.js:35
[Object]

And when I try to get a key, I get this in a loop:

TypeError {stack: (...), message: "Cannot read property 'on' of undefined"}message: "Cannot read property 'on' of undefined"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }__proto__: Error chord.js:527
connecting to: the original id chord.js:35

Any ideas?

This is latest Chrome Canary.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.