@rsksmart/rif-communications-pubsub-bootnode
TypeScript icon, indicating that this package has built-in type declarations

0.1.0-dev.0 • Public • Published

RIF Communications PubSub bootnode

CircleCI Dependency Status standard-readme compliant js-standard-style Managed by tAsEgir

Simple boot node for RIF Communications PubSub

The aim to provide a libp2p node which serves as bootstrap node for projects which use rif-commmunications-pubsub.

This can be also used for local development where you can define the list of Rooms that will be listened on and messages printed out to STDOUT.

Table of Contents

Usage

Example of usage:

npm start

Spawns a new libp2p node with new PeerId listening to TCP connections on port 6030.

NODE_ENV=develop npm start

Spawns a new libp2p node with PeerId QmbQJ4FyVBAar7rLwc1jjeJ6Nba6w2ddqczamJL6vTDrwm listening to websocket connections on port 6030 and joins rooms 0xtestroom and 0xtestroom2. Any peers joining and leaving the room will be logged as well as any messages in th following format:

<roomName>: peer <peerId> joined
<roomName>: peer <peerId> left
<roomName>: message {from: <peerId>, data: <content of the message>}
<roomName>: message {from: <peerId>, data: <content of the message>, to: <peerId>} // Only for direct messages

Config

In ./config. You can switch between configurations by setting NODE_ENV variable. Local configuration is good to put to local.json5 file. For configuration mechanism please visit the node-config page.

// Libp2p config
libp2p: {},

// Peer ID in a JSON format
peerId: {},

// Rooms to subscribe to, strings
rooms: []

Supported env. variables

  • RIFC_ROOMS (json/array): same as rooms option
  • RIFC_LISTEN_ADDR (json/array): same as libp2p.address.listen
  • RIFC_PEER_ID (json): Peer ID JSON like specified in `js-peer-id

Deployment

This project can be deployed with Dockerfile bundled with this repo. Ports 6666 and 6667 have to be published. Also if this is deployed on production level stable PeerId should be used. If PeerId is not defined than over restarts it will change, which should not happen for production boot nodes.

You can generate one using npm run generate-peerid and then set that either with config file or RIFC_PEER_ID env. variable (set the variable as the whole generated JSON).

$ PEER_ID=$(npm run generate-peerid) // This should be stored in some file somewhere
$ docker build -t rif-comunication-bootnode .  
$ docker run -e RIFC_PEER_ID="$PEER_ID" -p 6666 -p 6667 -it rif-comunication-bootnode  

License

MIT

Package Sidebar

Install

npm i @rsksmart/rif-communications-pubsub-bootnode

Weekly Downloads

0

Version

0.1.0-dev.0

License

MIT

Unpacked Size

15.4 kB

Total Files

14

Last publish

Collaborators