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

solyd-swarm

v0.0.11

Published

exchange messages with other peers interested in a topic

Downloads

14

Readme

solyd-swarm

Form a p2p swarm of nodes around a topic and exchange messages.

Background

This module provides a simple pubsub interface on top of an unstructured swarm of peers interested in a common topic string. Distributed pubsub! It's meant to be used as a primitive to build server-less applications without needing to have a deeper understanding of distributed systems.

This module doesn't make guarantees about latencies, nor does it guarantee delivery. Gossip isn't as fast as flooding, but it's a very robust means of propogating data over an unstructured network. If the network is stable message should reach eveyr node, but partitions can occur in the network and bridging peers can drop out at any time.

Messages are cryptographically signed by their creator and given a unique sequence number. This means that a. each incoming message can be verified that it came from its claimed author, and that b. peers will not report duplicate messages (e.g. if two different peers deliver them).

Example

var pubsub = require('solyd-swarm')

var swarm = pubsub('foobar')

swarm.on('message', function (msg) {
  console.log('message', msg)

  setTimeout(function() { process.exit(0) }, 1000)
})

swarm.on('connected', function () {
  swarm.publish({ data: 'hello warld from ' + this.id + '!'})
})

Run two copies of this:

$ node example.js &
$ node example.js &

Running this in two terminals shows the message exchange:

found + connected to peer
message { data: 'hello warld from
WpiDF+5f+HRTrm2JOmNHTPyGlYGpAN3QNNwwsu3RtbY=.ed25519!' }
found + connected to peer
message { data: 'hello warld from
JxafbAD7qjHCpQY+G/2i1B7vMmBlNTC7HEh9GfP+5yY=.ed25519!' }

API

var pubsub = require('solyd-swarm')

var swarm = pubsub(topic)

Returns a new pubsub swarm interested in the topic topic (string). It will begin searching for other interested peers using the BitTorrent DHT and multicast DNS.

swarm.on('message', function (msg) {})

Emits when a new message has been received by a peer.

swarm.publish(msg)

Publish a message to the rest of the swarm. It will gradually propogate through the swarm using periodic gossip.

swarm.leave()

Leave the swarm.

Install

With npm installed, run

$ npm install solyd-swarm

License

ISC