@rsksmart/rif-communications-pubsub-bootnode
Version:
Simple bootnode for RIF Communications PubSub
86 lines (59 loc) • 3.78 kB
Markdown
[](https://circleci.com/gh/rsksmart/rif-communications-pubsub-node/)
[](https://david-dm.org/rsksmart/rif-communications-pubsub-node)
[](http://iovlabs.org)
[](https://www.rifos.org/)
[](https://github.com/RichardLitt/standard-readme)
[](https://github.com/feross/standard)
[](https://github.com/auhau/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`](https://github.com/rsksmart/rif-communications-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.
- [Usage](
- [Config](
- [License](
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
```
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](https://github.com/lorenwest/node-config/) page.
```JSON5
// Libp2p config
libp2p: {},
// Peer ID in a JSON format
peerId: {},
// Rooms to subscribe to, strings
rooms: []
```
- `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](https://github.com/libp2p/js-peer-id#createfromjsonobj)
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)