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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gossipmonger-peer

v0.1.0

Published

Peer datastructure for Gossipmonger

Readme

gossipmonger-peer

Stability: 1 - Experimental

NPM version

GossipmongerPeer is a peer datastructure used by Gossipmonger, an implementation of the Scuttlebutt gossip protocol endpoint for real-time peer-to-peer peer-state distribution.

Usage

var GossipmongerPeer = require('gossipmonger-peer');
// create local peer
var localPeer = new GossipmongerPeer(localId);

// on finding out about another peer
var otherPeer = new GossipmongerPeer(otherId);

// on making contact with otherPeer
otherPeer.markContact();

// on receiving a delta about otherPeer
otherPeer.updateFromDelta('otherFoo', 'otherBar', 17);

// test liveness criteria of otherPeer
if (otherPeer.phi() > MY_PHI_THRESHOLD) {
    otherPeer.markDead();
}

// on changing some local peer value
localPeer.updateLocal('foo', 'bar');

// the dead rise! (made contact with otherPeer)
otherPeer.markLive();

Tests

npm test

Overview

Documentation

GossipmongerPeer

Public API

GossipmongerPeer.calculateIntervalsSum(intervals)

  • intervals: Array Intervals to calculate the sum of.
  • Return: Integer Calculated sum.

Iterates through intervals to calculate the sum.

GossipmongerPeer.calculateIntervalsSumEfficiently(sum, newInterval, [oldInterval])

  • sum: Integer Current sum.
  • newInterval: Integer New interval being added to calculate the mean.
  • oldInterval: Integer (Default: undefined) Old interval being removed from being used in calculating the mean.
  • Return: Integer Calculated sum.

Instead of iterating through an array, simply adds newInterval to sum and substracts oldInterval if present.

new GossipmongerPeer(id, [options])

  • id: String Id of the peer.
  • options: Object
    • data: Object (Default: {}) Peer data.
    • intervals: Array (Default: [750]) An array of the last (up to MAX_INTERVALS) intervals between times when the peer has been seen.
    • intervalsMean: Integer (Default: undefined) Memoized intervals mean.
    • lastTime: Integer (Default: undefined) The last time the peer has been seen (in milliseconds since midnight Jan 1, 1970).
    • live: Boolean (Default: true) Indicator whether or not the peer is thought to be live.
    • maxVersionSeen: Integer (Default: 0) Vector clock value indicating the last version of the peer that has been observed.
    • MAX_INTERVALS: Integer (Default: 100) The maximum number of intervals to keep in intervals.
    • sum: Integer (Default: undefined) Memoized sum of intervals to make intervals mean calculation more efficient.
    • transport: Any Any data identifying this peer to the transport mechanism that is required for correct transport operation.

Creates a new instance of GossipmongerPeer.

gossipmongerPeer.deltasAfterVersion(version)

  • version: Integer Vector clock version to construct deltas for.
  • Return: Array An array of deltas (ex delta: [key, value, version]).

Calculates deltas for this peer since version.

gossipmongerPeer.markContact(time)

  • time: Integer (Default: new Date().getTime()) The time this peer has been seen (in milliseconds since midnight Jan 1, 1970).

Marks that contact with the peer occurred at time. This is used later in phi calculations.

gossipmongerPeer.markDead()

Sets live property to false.

gossipmongerPeer.markLive()

Sets live property to true.

gossipmongerPeer.phi([time])

  • time: Integer (Default: new Date().getTime()) The time to use as "now" in phi calculation (in milliseconds since midnight Jan 1, 1970).
  • Return: Number Calculated phi for this peer.

See The ϕ Accrual Failure Detector.

gossipmongerPeer.updateLocal(key, value)

  • key: String Key to update.
  • value: Any The value to update with.
  • Return: String If the key has been updated, the key is returned, otherwise a null is returned instead.

Updates peer data and increments maxVersionSeen for the peer on which this is used. Intended for only manipulating data for the local peer.

gossipmongerPeer.updateFromDelta(key, value, version)

  • key: String The key for the value to update.
  • value: Any The value to update with.
  • version: Integer The vector clock version of this key value pair.
  • Return: String If the key has been updated, the key is returned, otherwise a null is returned instead.

Updated peer data and sets maxVersionSeen to version if the version is greater than maxVersionSeen. Intended for manipulating data for remote peers cached locally.

Sources