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

cyclon.p2p

v1.0.0

Published

A Javascript implementation of the Cyclon peer sampling protocol

Downloads

353

Readme

cyclon.p2p

Build Status Dependencies

A Javascript implementation of the Cyclon peer sampling protocol

The details and an analysis of the implementation can be found in;

N. Tindall and A. Harwood, "Peer-to-peer between browsers: cyclon protocol over WebRTC," Peer-to-Peer Computing (P2P), 2015 IEEE International Conference on, Boston, MA, 2015, pp. 1-5. doi: 10.1109/P2P.2015.7328517

The Cyclon protocol is described in;

Voulgaris, S.; Gavidia, D. & van Steen, M. (2005), 'CYCLON: Inexpensive Membership Management for Unstructured P2P Overlays', J. Network Syst. Manage. 13 (2).

Overview

The cyclon.p2p implementation has two dependencies, a Bootstrap and a Comms instance. Their functions and interfaces are described below.

Bootstrap

The purpose of the Bootstrap is to retrieve some peers to initially populate a node's neighbour cache. Its interface is quite simple.

getInitialPeerSet(localNode, maxPeers)

Get an initial set of peers. Returns a Promise that will resolve to a set of peers no greater than the specified limit.

Parameters
  • localNode The CyclonNode that is requesting the peers.
  • limit The maximum number of peers to return.

Comms

The Comms is the layer that takes care of a node's communication with other nodes. It is responsible for executing shuffles for the local node. Its interface is again quite simple.

initialize(localNode, metadataProviders)

Initialize the Comms instance. This must be called before any attempt is made to do anything else.

Parameters
  • localNode A reference to the local CyclonNode.
  • metadataProviders A JavaScript Object whose keys will be used as node pointer metadata keys and values will be executed to get the corresponding values.

sendShuffleRequest(destinationNodePointer, shuffleSet)

Send a shuffle request to another node in the network. Returns a cancellable Bluebird promise that will resolve when a shuffle has been successfully executed. If a cancellation or error occurs it will reject with the error.

Parameters
  • destinationNodePointer The node pointer of the destination node.
  • shuffleSet The set of node pointers to include in the shuffle request message.

createNewPointer()

Create a new pointer to the local node, containing the current metadata and signalling details.

getLocalId()

Return the string which the Comms layer is using to identify the local node.

Usage

On its own this package is not particularly useful unless you intend to create your own Comms and Bootstrap implementations. The cyclon-p2p-rtc-comms package provides a configurable implementation of the interfaces that will work in modern Chrome and Firefox (and maybe Opera?) browsers.

A demonstration of the WebRTC implementation of cyclon.p2p can be found here. Open a few tabs and watch the protocol work.

The Local Simulation

This package contains "local" Comms and Bootstrap implementations that can be used to run a local multi-node simulation of the protocol by executing

node localSimulation.js

In the working directory. The local simulation is configured to bootstrap each peer in the network with only the node pointer of its neighbour to the right (on a number scale, wrapping at the node with the maximum ID). It will then start all the nodes and output some network metrics.

An example of the output:

Starting Cyclon.p2p simulation of 50 nodes
Ideal entropy is 5.614709844115208
1: entropy (min=Infinity, mean=NaN, max=-Infinity), in-degree (mean=0, std.dev=0), orphans=50
2: entropy (min=0, mean=0, max=0), in-degree (mean=1, std.dev=0), orphans=0
3: entropy (min=0.9182958340544896, mean=1.0008546455628127, max=2), in-degree (mean=1.56, std.dev=0.6374950980203691), orphans=0
4: entropy (min=2.2516291673878226, mean=2.3793927048285384, max=3.1219280948873624), in-degree (mean=4.48, std.dev=2.475802900071005), orphans=0
5: entropy (min=2.5216406363433186, mean=2.972442624013195, max=3.75), in-degree (mean=6.66, std.dev=3.2410492128321655), orphans=0

The information output includes

  • entropy A measurement of the Shannon Entropy of the stream of peers that the protocol has produced over the network. The entropy of the stream is measured at each node and the statistics aggregated. The Shannon entropy is an indication of how evenly the probabilities of each node in the network being selected are distributed. The "ideal" entropy, where each peer is equally likely to appear in the sample, is output at the beginning of the simulation.
  • in-degree The in-degree in a directed graph is the number of edges arriving at a particular vertex. In the context of the Cyclon network it indicates the number of peers whose neighbour caches have a pointer to a particular node.
  • orphans This is just a count of the number of nodes in the network with an in-degree of zero. This should stay at zero.