npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webrtc-chord

v1.0.0

Published

Chord DHT Algorithm implementation for the browser using WebRTC and WebSockets

Downloads

11

Readme

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

  • use tracing for this

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
    example:
{
  id: 1,
  description: 'node connected to signaling server'
}
  • id: 2 description: there are no other nodes present in the ring example:
  • id: 3 description: received a request to rail new peer into the ring example:
  • id: 4 description: connected to railing peer example:
  • id: 5 description: connected to sucessor example:
  • id: 6 description: connected to entrace :number: of finger table example:

tag: finger-table

  • id: 1 description: update
    example:

tag: message

  • id: 1 description: receive
    example:
  • id: 2 description: sent
    example:
  • id: 3 description: forward
    example:

TODO:

  • [ ] Support node leaves (for example, when a browser closes a tab);
  • [ ] If the socket.io server goes down and we are already connected, don't do the bootstrap process all over again due to .on('connect') event
  • [ ] Make the state of the ring on webrtc-chord-signalling-server persistent
  • [ ] Improve vastly the quality of log messages
  • [ ] Implement the process for a Node to fill his finger table