libp2p-floodsub
0.15.4

- Intro
- FloodSub
- Instance
  - cache
  - subscriptions
  - stop
  - publish
  - subscribe
  - unsubscribe
- BaseProtocol
- Instance
  - peers
  - start
  - stop
- Peer
- Instance
  - info
  - conn
  - topics
  - stream
  - isConnected
  - isWritable
  - write
  - attachConnection
  - sendSubscriptions
  - sendUnsubscriptions
  - sendMessages
  - updateSubscriptions
  - close

# Intro

Installable via `npm install --save libp2p-floodsub`, it can also be used directly in the browser.

## Download

The source is available for download from GitHub. Alternatively, you can install using npm:

    $ npm install --save libp2p-floodsub

You can then `require()` libp2p-floodsub as normal:

    const libp2PFloodsub = require('libp2p-floodsub')

## In the Browser

Libp2p-floodsub should work in any ES2015 environment out of the box.

Usage:

    <script type="text/javascript" src="index.js"></script>

The portable versions of libp2p-floodsub, including `index.js` and `index.min.js`, are included in the `/dist` folder. Libp2p-floodsub can also be found on unpkg.com under

- https://unpkg.com/libp2p-floodsub/dist/index.min.js
- https://unpkg.com/libp2p-floodsub/dist/index.js

# FloodSub

FloodSub (aka dumbsub is an implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).

Extends BaseProtocol.

#### Parameters

1. `libp2p: Object`:

## instance

### FloodSub.prototype.cache

    cache: TimeCache

Time based cache for sequence numbers.

### FloodSub.prototype.subscriptions

    subscriptions: Set<string>

List of our subscriptions

### FloodSub.prototype.stop

    stop(callback: Function): undefined

Unmounts the floodsub protocol and shuts down every connection

#### Parameters

1. `callback: Function`:

#### Returns

`undefined`

### FloodSub.prototype.publish

    publish(topics: (Array<string> | string), messages: (Array<any> | any)): undefined

Publish messages to the given topics.

#### Parameters

1. `topics: (Array<string> | string)`:
2. `messages: (Array<any> | any)`:

#### Returns

`undefined`

### FloodSub.prototype.subscribe

    subscribe(topics: (Array<string> | string)): undefined

Subscribe to the given topic(s).

#### Parameters

1. `topics: (Array<string> | string)`:

#### Returns

`undefined`

### FloodSub.prototype.unsubscribe

    unsubscribe(topics: (Array<string> | string)): undefined

Unsubscribe from the given topic(s).

#### Parameters

1. `topics: (Array<string> | string)`:

#### Returns

`undefined`

# BaseProtocol

FloodSub (aka dumbsub is an implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).

Extends EventEmitter.

#### Parameters

1. `debugName: String`:
2. `multicodec: String`:
3. `libp2p: Object`:

## instance

### BaseProtocol.prototype.peers

    peers: Map<string, Peer>

Map of peers.

### BaseProtocol.prototype.start

    start(callback: Function): undefined

Mounts the floodsub protocol onto the libp2p node and sends our subscriptions to every peer conneceted

#### Parameters

1. `callback: Function`:

#### Returns

`undefined`

### BaseProtocol.prototype.stop

    stop(callback: Function): undefined

Unmounts the floodsub protocol and shuts down every connection

#### Parameters

1. `callback: Function`:

#### Returns

`undefined`

# Peer

The known state of a connected peer.

Extends EventEmitter.

#### Parameters

1. `info: PeerInfo`:

## instance

### Peer.prototype.info

    info: PeerInfo

### Peer.prototype.conn

    conn: Connection

### Peer.prototype.topics

    topics: Set

### Peer.prototype.stream

    stream: Pushable

### Peer.prototype.isConnected

    isConnected: boolean

Is the peer connected currently?

### Peer.prototype.isWritable

    isWritable: boolean

Do we have a connection to write on?

### Peer.prototype.write

    write(msg: Buffer): undefined

Send a message to this peer. Throws if there is no `stream` to write to available.

#### Parameters

1. `msg: Buffer`:

#### Returns

`undefined`

### Peer.prototype.attachConnection

    attachConnection(conn: Connection): undefined

Attach the peer to a connection and setup a write stream

#### Parameters

1. `conn: Connection`:

#### Returns

`undefined`

### Peer.prototype.sendSubscriptions

    sendSubscriptions(topics: (Set | Array)): undefined

Send the given subscriptions to this peer.

#### Parameters

1. `topics: (Set | Array)`:

#### Returns

`undefined`

### Peer.prototype.sendUnsubscriptions

    sendUnsubscriptions(topics: (Set | Array)): undefined

Send the given unsubscriptions to this peer.

#### Parameters

1. `topics: (Set | Array)`:

#### Returns

`undefined`

### Peer.prototype.sendMessages

    sendMessages(msgs: Array<any>): undefined

Send messages to this peer.

#### Parameters

1. `msgs: Array<any>`:

#### Returns

`undefined`

### Peer.prototype.updateSubscriptions

    updateSubscriptions(changes: Array): undefined

Bulk process subscription updates.

#### Parameters

1. `changes: Array`:

#### Returns

`undefined`

### Peer.prototype.close

    close(callback: Function): undefined

Closes the open connection to peer

#### Parameters

1. `callback: Function`:

#### Returns

`undefined`