gossipmonger-tcp-transport

0.1.6 • Public • Published

gossipmonger-tcp-transport

Stability: 1 - Experimental

NPM version

TCP Transport for Gossipmonger (an implementation of the Scuttlebutt gossip protocol endpoint for real-time peer-to-peer replication).

Contributors

@tristanls, @KenanSulayman, @yuskesh

Usage

var GossipmongerTcpTransport = require('gossipmonger-tcp-transport');
var transport = new GossipmongerTcpTransport();
 
transport.on('deltas', function (remotePeer, deltas) {
    // process deltas
});
 
transport.on('digest', function (remotePeer, digest) {
    // process digest
});
 
transport.on('error', function (error) {
    // process the error
    // if error handler is not registered if an error occurs it will be thrown
});
 
transport.on('listening', function () {
    console.log('listening...'); 
});
 
transport.listen();

Tests

npm test

Overview

TCP Transport for Gossipmonger.

Documentation

TcpTransport

Public API

TcpTransport.listen([options], [callback])

  • options: See new TcpTransport(options) options.
  • callback: See tcpTransport.listen(callback) callback.
  • Return: Object An instance of TcpTransport with server listening on host and port as specified in options or defaults.

Creates new TCP transport and starts the server.

new TcpTransport([options])

  • options: Object (Default: {})
    • host: String (Default: 'localhost')
    • port: Integer (Default: 9742) A port value of zero will assign a random port.

Creates a new TCP transport. The host and port specified in the options will be the ones advertised to other peers to connect to. They must be reachable from the "outside".

If "internal" host and port are different from the "outside" ones, specify the "internal" version in options when calling transport.listen([options], [callback])

tcpTransport.close([callback])

  • callback: Function (Default: undefined) function () {} Optional callback to call once the server is stopped.

Stops the server from listening to requests from other peers.

tcpTransport.deltas(remotePeer, localPeer, deltasToSend)

  • remotePeer: Object Peer to send rpc to.
    • transport: Object TCP transport data.
      • host: String Host to connect to.
      • port: Integer Port to connect to.
  • localPeer: Object Sender peer.
    • id: String Sender peer id.
    • transport: Object TCP transport data.
      • host: String Host to connect to.
      • port: Integer Port to connect to.
  • deltasToSend: Any Deltas to send.

Sends deltasToSend to the remotePeer.

tcpTransport.digest(remotePeer, localPeer, digestToSend)

  • remotePeer: Object Peer to send rpc to.
    • transport: Object TCP transport data.
      • host: String Host to connect to.
      • port: Integer Port to connect to.
  • localPeer: Object Sender peer.
    • id: String Sender peer id.
    • transport: Object TCP transport data.
      • host: String Host to connect to.
      • port: Integer Port to connect to.
  • digestToSend: Any Digest to send.

Sends digestToSend to the remotePeer.

tcpTransport.listen([options], [callback])

  • options: Object (Default: {})
    • host: String (Default: as specified on construction) Hostname or IP to listen on.
    • port: Integer (Default: as specified on construction) Port number to listen on.
  • callback: Function (Default: undefined) function () {} Optional callback to call once the server is up.

Starts the server to listen to requests from other peers.

tcpTransport.rpc(remotePeer, payload)

CAUTION: reserved for internal use

  • remotePeer: Object Peer to send rpc to.
    • transport: Object TCP transport data.
      • host: String Host to connect to.
      • port: Integer Port to connect to.
  • payload: String or Object Payload is send on the wire. If an Object is provided, it will be JSON.stringify()'ed.

An internal common implementation for tcpTransport.deltas(...) and tcpTransport.digest(...).

Event deltas

  • function (remotePeer, deltas) {}
    • remotePeer: Object
      • id: String Id of the peer.
      • transport: Any Any data identifying this peer to the transport mechanism that is required for correct transport operation.
    • deltas: Any Received deltas.

Emitted when TcpTransport receives deltas from a peer.

Event digest

  • function (remotePeer, digest) {}
    • remotePeer: Object
      • id: String Id of the peer.
      • transport: Any Any data identifying this peer to the transport mechanism that is required for correct transport operation.
    • digest: Any Received digest.

Emitted when TcpTransport receives digest from a peer.

Event error

  • function (error) {}
    • error: Object An error that occurred.

Emitted when TcpTransport encounters an error. If no handler is registered, an exception will be thrown.

Event listening

  • function () {}

Emitted when TcpTransport starts listening for connections from peers.

Readme

Keywords

none

Package Sidebar

Install

npm i gossipmonger-tcp-transport

Weekly Downloads

0

Version

0.1.6

License

MIT

Last publish

Collaborators

  • tristanls