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

    gossipmonger-peerpublic

    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

    Keywords

    none

    install

    npm i gossipmonger-peer

    Downloadsweekly downloads

    188

    version

    0.1.0

    license

    none

    last publish

    collaborators

    • avatar