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

masterless-msgpack

v0.5.0

Published

a duplex server with mesh network edge deduplication

Downloads

10

Readme

masterless

Build Status

A fancy tcp client and server that acts as neither, and abstracts out connection deduplication between identical nodes. Uses msgpack for serialization.

Install

$ npm install masterless

Test

Run any of the following:

$ mocha
$ npm test
$ make test

Note: remember to npm install to get those yummy dev dependencies!

API

var Server = require('masterless');

var left = new Server('e4663c9c3f9a89112afc48389a951e09');
var right = new Server('b073a8ee09e1daca57e9d54a5efe5684');

left.on('listening', function(info) {
  right.connect(info);
});

right.on('connect', function(id) {
  right.send(id, {type: 'counter', total: 0});
});

left.on('message', onmessage);
right.on('message', onmessage);

function onmessage(sender, packet) {
  if (packet.type === 'counter') {
    packet.total % 100 === 0 && console.log('counter at', packet.total);
    this.send(sender, {type: 'counter', total: packet.total + 1});
  } else {
    console.log('unknown packet', packet);
  }
}

For more examples, see examples.

Server(id, [options])

Construct a new server object, with an id unique to context in which the server is used. Optionally specify a port to listen on.

var server = new Server('67d2cb3db178bc5ca7d9f7157e3119aa');
var serverWithPort = new Server('81358297b83f2d4d6cfa58ba5aff6180', {port: 23412});

server.connect(transport)

Connect to a remote node via a transport uri. Automatically sets the node as a keep node.

server.connect('tcp://192.168.1.64:2435');
server.connect(serverWithPort.info());

server.disconnect(id)

Disconnect from a remote via a node id.

server.disconnect('81358297b83f2d4d6cfa58ba5aff6180');

server.keep(id, [true|false])

Reconnects to the specified node if the connection dies.

server.keep('81358297b83f2d4d6cfa58ba5aff6180');

server.info()

Returns a formatted transport uri. The result of this function is included in the listening event. The info method returns null if the server has yet to initialize.

server.info(); // => 'tcp://192.168.1.64:35649'

server.close([callback])

Ends all connections and closes the server.

server.close(function() {
  // server has been closed
});

server.send(id, packet)

Sends a packet to one or more nodes. Returns false if unable to send for a single destination.

server.send('81358297b83f2d4d6cfa58ba5aff6180', {some: 'data'});
server.send([left.id, right.id], {some: 'other', random: 'data'});

server.send('not-a-valid-node', {not: 'sent'}); // returns false

Features

Connection Deduplication

The following example will open two connections, then close exactly one as the handshake completes.

var left = new Server(...);
var right = new Server(...);

left.connect(right.info());
right.connect(left.info());

Multiple Dispatch

Send messages to multiple nodes with low overhead (doesn't reencode the packet).

server.send([left.id, right.id], {multiple: 'dispatch'});

Limited Reconnection

Use the keep method to specify a connection is locally important, and the server will attempt to reconnect once between disconnecting.

var left = new Server(...);
var right = new Server(...);

// both nodes will unilaterally try to reconnect
right.keep(left.id);
left.connect(right.info());

left.once('connect', function() {
  // causes a reconnect
  right.disconnect(left.id);
});

Caveats

  • The wire protocol is not yet stable--it is a simple protocol, but could be far more lightweight.

License

The MIT License (MIT)