Neat Paraskavedekatriaphobia's Meaning
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



    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.


    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 
    // on receiving a delta about otherPeer 
    otherPeer.updateFromDelta('otherFoo', 'otherBar', 17);
    // test liveness criteria of otherPeer 
    if (otherPeer.phi() > MY_PHI_THRESHOLD) {
    // on changing some local peer value 
    localPeer.updateLocal('foo', 'bar');
    // the dead rise! (made contact with otherPeer) 


    npm test




    Public API


    • 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.


    • 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.


    • 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.


    Sets live property to false.


    Sets live property to true.


    • 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.





    npm i gossipmonger-peer

    Downloadsweekly downloads






    last publish


    • avatar