Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
feat!: update libp2p interfaces (#154)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: uses new single-issue libp2p interface modules
  • Loading branch information
achingbrain authored Jun 15, 2022
1 parent 0e17f26 commit 3195bfd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
63 changes: 37 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# js-libp2p-floodsub <!-- omit in toc -->
# @libp2p/floodsub <!-- omit in toc -->

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-floodsub/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-floodsub?branch=master)
[![Build Status](https://github.com/libp2p/js-libp2p-floodsub/actions/workflows/js-test-and-release.yml/badge.svg?branch=main)](https://github.com/libp2p/js-libp2p-floodsub/actions/workflows/js-test-and-release.yml)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-floodsub.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-floodsub) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![](https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square)](https://waffle.io/libp2p/js-libp2p-floodsub)
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-floodsub.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-floodsub)
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-floodsub/actions/workflows/js-test-and-release.yml)

> 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).
## Table of Contents <!-- omit in toc -->
## Table of contents <!-- omit in toc -->

- [Install](#install)
- [Usage](#usage)
Expand All @@ -20,11 +17,12 @@
- [Events](#events)
- [Contribute](#contribute)
- [License](#license)
- [Contribution](#contribution)

## Install

```sh
> npm install @libp2p/floodsub
```console
$ npm i @libp2p/floodsub
```

## Usage
Expand Down Expand Up @@ -56,26 +54,32 @@ const floodsub = new Floodsub(peerId, registrar, options)

Options is an optional object with the following key-value pairs:

* **`emitSelf`**: boolean identifying whether the node should emit to self on publish, in the event of the topic being subscribed (defaults to **false**).
- **`emitSelf`**: boolean identifying whether the node should emit to self on publish, in the event of the topic being subscribed (defaults to **false**).

For the remaining API, see https://github.com/libp2p/js-libp2p-pubsub
For the remaining API, see <https://github.com/libp2p/js-libp2p-pubsub>

## 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 Uint8Array containing the data that was published to the topic

```Javascript
fsub.on('fruit', (data) => { ... })
```

- `data`: a Uint8Array 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', (peerId, topics, changes) => { ... })
```
- `peerId`: a [PeerId](https://github.com/libp2p/js-peer-id) object
- `topics`: the topics that the peer is now subscribed to
- `changes`: an array of `{ topicID: <topic>, subscribe: <boolean> }`
eg `[ { topicID: 'fruit', subscribe: true }, { topicID: 'vegetables': false } ]`

```Javascript
fsub.on('floodsub:subscription-change', (peerId, topics, changes) => { ... })
```

- `peerId`: a [PeerId](https://github.com/libp2p/js-peer-id) object
- `topics`: the topics that the peer is now subscribed to
- `changes`: an array of `{ topicID: <topic>, subscribe: <boolean> }`
eg `[ { topicID: 'fruit', subscribe: true }, { topicID: 'vegetables': false } ]`

## Contribute

Expand All @@ -85,4 +89,11 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c

## License

[Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) © Protocol Labs
Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
],
"exports": {
".": {
"types": "./src/index.d.ts",
"import": "./dist/src/index.js"
}
},
Expand Down Expand Up @@ -142,19 +143,22 @@
"release": "aegir release"
},
"dependencies": {
"@libp2p/interfaces": "^2.0.1",
"@libp2p/interface-peer-id": "^1.0.2",
"@libp2p/interface-pubsub": "^1.0.1",
"@libp2p/logger": "^1.1.4",
"@libp2p/pubsub": "^1.2.20",
"@libp2p/pubsub": "^2.0.0",
"protons-runtime": "^1.0.3",
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"@libp2p/interface-compliance-tests": "^2.0.1",
"@libp2p/components": "^1.0.0",
"@libp2p/interface-mocks": "^1.0.1",
"@libp2p/interface-pubsub-compliance-tests": "^1.0.1",
"@libp2p/peer-collections": "^1.0.2",
"@libp2p/peer-id": "^1.1.10",
"@libp2p/peer-id-factory": "^1.0.9",
"@multiformats/multiaddr": "^10.1.8",
"aegir": "^37.0.14",
"aegir": "^37.2.0",
"multiformats": "^9.4.5",
"p-wait-for": "^4.1.0",
"protons": "^3.0.3",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { toString } from 'uint8arrays/to-string'
import { PubSubBaseProtocol } from '@libp2p/pubsub'
import { multicodec } from './config.js'
import { SimpleTimeCache } from './cache.js'
import type { PubSubInit, Message, PubSubRPC, PubSubRPCMessage, PublishResult } from '@libp2p/interfaces/pubsub'
import type { PeerId } from '@libp2p/interfaces/peer-id'
import type { PubSubInit, Message, PubSubRPC, PubSubRPCMessage, PublishResult } from '@libp2p/interface-pubsub'
import type { PeerId } from '@libp2p/interface-peer-id'
import { logger } from '@libp2p/logger'
import { RPC } from './message/rpc.js'

Expand Down
2 changes: 1 addition & 1 deletion test/compliance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */

import tests from '@libp2p/interface-compliance-tests/pubsub'
import tests from '@libp2p/interface-pubsub-compliance-tests'
import { FloodSub } from '../src/index.js'

describe('interface compliance', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/floodsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import sinon from 'sinon'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { sha256 } from 'multiformats/hashes/sha2'
import { Message, PubSubRPC, StrictNoSign } from '@libp2p/interfaces/pubsub'
import { Message, PubSubRPC, StrictNoSign } from '@libp2p/interface-pubsub'
import { PeerStreams } from '@libp2p/pubsub/peer-streams'
import { FloodSub, multicodec } from '../src/index.js'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { mockRegistrar } from '@libp2p/interface-compliance-tests/mocks'
import { mockRegistrar } from '@libp2p/interface-mocks'
import pWaitFor from 'p-wait-for'
import { Components } from '@libp2p/interfaces/components'
import { Components } from '@libp2p/components'
import { PeerSet } from '@libp2p/peer-collections'

const topic = 'my-topic'
Expand Down

0 comments on commit 3195bfd

Please sign in to comment.