0.0.5 • Published 6 years ago

hyperserver v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

HyperServer

THIS IS A WORK IN PROGRESS PROJECT

HyperServer is a light-weight library for building both large and small scale peer-to-peer (P2P) networks. It does not implement P2P data replication for you. It is simply a plain, flexible peer-to-peer networking solution, onto which you can easily build your own replication model or use some kind of event passing mechanism.

Installation

npm install hyperserver

System overview

When attempting to join a P2P network, specific discovery or membership protocols (or other configuration information) may be required, and, if a newly joining node is unaware of these protocols, the newly established joining node will not be able to communicate with other nodes and ultimately join the network.

This is why we need bootstrapping nodes; to provide the initial required information to a newly joined node so that it knows how to proceed connecting to other nodes. There are two types of nodes/peers you can create with this library: bootstrapping nodes and default nodes.

Usage

const hyperserver = require('hyperserver');

const node = hyperserver.createNode({
    ip: '192.168.0.1/255.255.255.0',
    port: 3000,
    bootstrap: true, // Assign the node to be a bootstrapping node.
    seeds: [ // List of endpoints to which the node should initially connect.
        { "address": "192.168.0.17", "port": 3000 }
    ]
});

Events

node.on('available', () => {
    // Fires when there are peers available.
});

node.on('unavailable', () => {
    // Fires when there are no peers available anymore.
});

node.on('connect', (peer) => {
    // Fires when a peer connects to this node.
});

node.on('disconnect', (peer) => {
    // Fires when a peer disconnects from this node.
});

node.on('data', (data, peer) => {
    // Fires when a message is received from a certain peer.
});