Home

Awesome

webrtc-chord

DISCLAIMER: Implementing a full Chord algorithm proved to be an unviable option (due to the high number of data-channels that had to be open inside a browser), in order to overcome this, I've come up with webrtc-explorer, and adaptable Chord like implementation. I'll no longer support this module

It enables you to communicate between several browsers in a p2p/decentralized fashion.

How to create a node

webrtc-chord uses browserify

var chord = require('webrtc-chord');

var nodeConfig = {
  signalingURL: 'http://url-to-webrtc-chord-signaling-server.com'
};
var node = chord.createNode(nodeConfig);

node.e.on('ready', function (){
  // this node is ready
});

How to communicate with other nodes

Send a message to a Node responsible for the ID 1af17e73721dbe0c40011b82ed4bb1a7dbe3ce29

var nodeToSend = '1af17e73721dbe0c40011b82ed4bb1a7dbe3ce29'; 
// 160 bit ID represented in hex(`git_sha1` module is a good way to generate these)

node.send(destID: '1af17e73721dbe0c40011b82ed4bb1a7dbe3ce29', 
          data: 'hey, how are you doing');

Send a message to this node sucessor (next node in Chord)

node.sendSucessor(data: 'hey, how are you doing');

Receive a message

node.e.on('message', function(message) {
  console.log(message);
});

Other options

finger table updates

logging

add the logging flag to your nodeConfig

var nodeConfig = {
  //...
  logging: true
  //...
};

tracing

In order to understand the events which happen on the webrtc-chord network and their order, webrtc-chord using a tracing module (canela).

To activate it, simply add tracing to your config:

var nodeConfig = {
  //...
  tracing: true
  //...
};

Then, the returned EventEmitter from .createChord() will also emit the events described on the tracing DSL. Each trace has a specific id per tag, so it is easy to identify them automatically.

tracing DSL

tag: signaling

{
  id: 1,
  description: 'node connected to signaling server'
}

tag: finger-table

tag: message

TODO: