Home

Awesome

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)

Iterates through intervals to calculate the sum.

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

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

new GossipmongerPeer(id, [options])

Creates a new instance of GossipmongerPeer.

gossipmongerPeer.deltasAfterVersion(version)

Calculates deltas for this peer since version.

gossipmongerPeer.markContact(time)

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])

See The ϕ Accrual Failure Detector.

gossipmongerPeer.updateLocal(key, value)

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

gossipmongerPeer.updateWithDelta(key, value, version)

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