A feature rich peer discovery and management library written entirely in typescript.
A module to find nodes on a network, establish secure communication channels, execute code and much much more.
[ ] Communication channels after node discovery
[ ] Node monitoring via a local web server
npm i find-peers --save
To use find-peers in Socket.io mode install it first.
npm i socket.io-client
npm i socket.io
To automatically generate self signed SSL certificates at runtime node-forge must be installed.
npm i node-forge
const { FindPeers } = require('find-peers');
const options = { autoGenId: true };
const find = new FindPeers(options);
find.on('found-nodes', (data) => {
// new discovered nodes
});
find.on('server_up', () => {
console.log('server is up!');
});
find.on('server_err', (err) => {
console.log(err);
});
find.on('multicast_err', (err) => {
console.log(err);
});
find.on('echo', (data) => {
console.log(data.message, 'from', data.from.id);
});
Property | Description | Default value |
---|---|---|
autoGenId | Automatically generate a 32 word random id | false |
identity | Set node details: id, bind to ip etc. | undefined |
securityLevel | Security mode of the library to be used | 4 |
verifyTries | Number of times to attempt to verify a node during initial pairing | 3 |
tryTime | Timeout limit | 10000 |
hashOptions | Options passed to argon 2 as per argon2.Options from node-argon2 ( 1 ) |
|
modLength | Length of generated RSA key ( 3 ) | 2048 |
keyGenGroup | Algorithm for key generation ( 3 ) | rsa |
aesVersion | Type of aes-256 to be used ( 2 - 4 ) | aes-256-cbc |
oaepHash | Hash to use alongside pbkdf2 | sha-256 |
groupName | Mod group to use in Diffie - Hellman exchange | modp15 |
autoStartSearch | Automatically start searching for nodes as soon as object is created | true |
serverType | Server type to be used for communication after node discovery | tcp |
serverPort | Server port | 19235 |
multicastPort | Multicast port | 18235 |
broadCastInterval | Interval at which to send out multicast | 500 |
multiCastTimeout | Duration of node search | 60000 |
multiCastReSearch | Automatically re - search for nodes | 300000 |
shouldReSearch | Enable re - search | false |
searchForever | Disable multiCastTimeout and re - search | false |
shouldPing | Ping nodes to veriy if still active | false |
pingInterval | Interval to ping nodes at | 1000 |
pingCount | Number of failed ping attempts before marked as disconnect | 20 |
temporaryDisconnect | Number of failed ping attempts before marked as temporary disconnect | 10 |
pingMIA | Number of seconds between ping reponses to be marked as temporary disconnect | 25000 |
pingLimit | Number of failed ping attempts before reconnection attempts are stopped | 100 |
whiteList | Array of nodes (by ip or id) to be whitelisted from ping | undefined |
blackList | Array of nodes (by ip or id) to be blacklisted from connections | undefined |
privateServerKey | Private key for https, tls server or Socket.io https server | undefined |
certificate | Certificate / public key for https, tls server or Socket.io https server | undefined |
genKeypair | Automatically generate an SSL key pair (private key, certificate) for use with https, tls or Socket.io https server using node-forge | false |
attrs | Attributes passed for SSL key pair generation (country name, address, organization name, etc…) |
|
socketIOOptions | Options to be used with Socket.io server |
|
Function | Description | Arguments |
---|---|---|
getClients | Get entire list of verified nodes | void |
echo | Send a message to all nodes | message: string, omit ?: string[] |
messageClient | Send message to a specific node | id: string, message: string |
getIdentity | Get identity object of current node | void |