floodsub-stream
Version:
libp2p-floodsub variant that delivers unique messages - the same message content will not be delivered twice
85 lines (61 loc) • 3.15 kB
Markdown
js-libp2p-floodsub
==================
[](http://ipn.io)
[](http://libp2p.io/)
[](http://webchat.freenode.net/?channels=%23ipfs)
[](https://coveralls.io/github/libp2p/js-libp2p-floodsub?branch=master)
[](https://travis-ci.org/libp2p/js-libp2p-floodsub)
[](https://circleci.com/gh/libp2p/js-libp2p-floodsub)
[](https://david-dm.org/libp2p/js-libp2p-floodsub) [](https://github.com/feross/standard)
[](https://github.com/RichardLitt/standard-readme)
[](https://waffle.io/libp2p/js-libp2p-floodsub)
> libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).
## Lead Maintainer
[Vasco Santos](https://github.com/vasco-santos).
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Contribute](#contribute)
- [License](#license)
## Install
```sh
> npm install libp2p-floodsub
```
## Examples
```JavaScript
const FloodSub = require('libp2p-floodsub')
const fsub = new FloodSub(node)
fsub.start((err) => {
if (err) {
console.log('Upsy', err)
}
fsub.on('fruit', (data) => {
console.log(data)
})
fsub.subscribe('fruit')
fsub.publish('fruit', new Buffer('banana'))
})
```
## Events
Floodsub emits two kinds of events:
1. `<topic>` when a message is received for a particular topic
```Javascript
fsub.on('fruit', (data) => { ... })
```
- `data`: a Buffer containing the data that was published to the topic
2. `floodsub:subscription-change` when the local peer receives an update to the subscriptions of a remote peer.
```Javascript
fsub.on('floodsub:subscription-change', (peerInfo, topics, changes) => { ... })
```
- `peerInfo`: a [PeerInfo](https://github.com/libp2p/js-peer-info) object
- `topics`: the topics that the peer is now subscribed to
- `changes`: an array of `{ topicCID: <topic>, subscribe: <boolean> }`
eg `[ { topicCID: 'fruit', subscribe: true }, { topicCID: 'vegetables': false } ]`
## API
See https://libp2p.github.io/js-libp2p-floodsub
## Contribute
PRs are welcome!
Small note: If editing the Readme, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
MIT © David Dias