Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# datastore-pubsub <!-- omit in toc -->

[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)
[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-datastore-pubsub.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-datastore-pubsub)
[![CI](https://img.shields.io/github/workflow/status/ipfs/js-datastore-pubsub/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-datastore-pubsub/actions/workflows/js-test-and-release.yml)

Expand Down Expand Up @@ -119,8 +118,12 @@ Licensed under either of

## Contribute

Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-unixfs-importer/issues)!
Contributions welcome! Please check out [the issues](https://github.com/ipfs/js-datastore-pubsub/issues).

This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.

Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

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.

[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,28 @@
},
"dependencies": {
"@libp2p/interface-dht": "^1.0.1",
"@libp2p/interface-pubsub": "^2.0.1",
"@libp2p/interface-pubsub": "^3.0.0",
"@libp2p/interfaces": "^3.0.3",
"@libp2p/logger": "^2.0.0",
"datastore-core": "^8.0.1",
"debug": "^4.2.0",
"err-code": "^3.0.1",
"interface-datastore": "^7.0.0",
"uint8arrays": "^3.0.0"
"uint8arrays": "^4.0.2"
},
"devDependencies": {
"@libp2p/components": "^2.0.0",
"@libp2p/floodsub": "^3.0.0",
"@libp2p/floodsub": "^5.0.0",
"@libp2p/interface-compliance-tests": "^3.0.2",
"@libp2p/interface-mocks": "^4.0.2",
"@libp2p/interface-mocks": "^7.0.1",
"@libp2p/interface-peer-id": "^1.0.5",
"@libp2p/interface-registrar": "^2.0.3",
"@libp2p/peer-id-factory": "^1.0.9",
"@libp2p/record": "^2.0.0",
"@types/detect-node": "^2.0.0",
"aegir": "^37.0.13",
"detect-node": "^2.0.4",
"install": "^0.13.0",
"ipfs-core-types": "^0.11.1",
"ipfs-core-types": "^0.12.1",
"it-pair": "^2.0.2",
"libp2p": "next",
"npm": "^8.10.0",
Expand Down
14 changes: 7 additions & 7 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { stop } from '@libp2p/interfaces/startable'
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId
* @typedef {import('@libp2p/interface-dht').ValidateFn} Validator
* @typedef {import('../src/types').SubscriptionKeyFn} SubscriptionKeyFn
* @typedef {import('@libp2p/components').Components} Components
* @typedef {import('./utils.js').Components} Components
*/

// Always returning the expected values
Expand Down Expand Up @@ -67,13 +67,13 @@ describe('datastore-pubsub', function () {

await connectPubsubNodes(componentsA, componentsB)

pubsubA = componentsA.getPubSub()
datastoreA = componentsA.getDatastore()
peerIdA = componentsA.getPeerId()
pubsubA = componentsA.pubsub
datastoreA = componentsA.datastore
peerIdA = componentsA.peerId

pubsubB = componentsB.getPubSub()
datastoreB = componentsB.getDatastore()
peerIdB = componentsB.getPeerId()
pubsubB = componentsB.pubsub
datastoreB = componentsB.datastore
peerIdB = componentsB.peerId
})

const value = 'value'
Expand Down
43 changes: 26 additions & 17 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
import pWaitFor from 'p-wait-for'
import { FloodSub, multicodec } from '@libp2p/floodsub'
import { floodsub, multicodec } from '@libp2p/floodsub'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { connectionPair, mockRegistrar, mockConnectionManager } from '@libp2p/interface-mocks'
import { Components } from '@libp2p/components'
import { MemoryDatastore } from 'datastore-core'
import { start } from '@libp2p/interfaces/startable'

/**
* @typedef {import('@libp2p/interface-pubsub').PubSub} PubSub
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId
* @typedef {import('@libp2p/interface-registrar').Registrar} Registrar
* @typedef {import('interface-datastore').Datastore} Datastore
*/

/**
* @typedef {object} Components
* @property {PeerId} peerId
* @property {Registrar} registrar
* @property {Datastore} datastore
* @property {PubSub} pubsub
*
* As created by libp2p
*
* @returns {Promise<Components>}
*/
export const createComponents = async () => {
const components = new Components({
/** @type {any} */
const components = {
peerId: await createEd25519PeerId(),
registrar: mockRegistrar(),
datastore: new MemoryDatastore(),
connectionManager: mockConnectionManager()
})
datastore: new MemoryDatastore()
}

const pubsub = new FloodSub({
components.connectionManager = mockConnectionManager(components)

const pubsub = floodsub({
emitSelf: true
})
pubsub.init(components)
await pubsub.start()
})(components)
await start(pubsub)

components.setPubSub(pubsub)
components.pubsub = pubsub

return components
}

/**
*
* @param {Components} componentsA
* @param {Components} componentsB
* @param {{ peerId: PeerId, registrar: Registrar }} componentsA
* @param {{ peerId: PeerId, registrar: Registrar }} componentsB
*/
export const connectPubsubNodes = async (componentsA, componentsB) => {
// Notify peers of connection
const [c0, c1] = connectionPair(componentsA, componentsB)

componentsA.getRegistrar().getTopologies(multicodec).forEach(topology => {
topology.onConnect(componentsB.getPeerId(), c0)
componentsA.registrar.getTopologies(multicodec).forEach(topology => {
topology.onConnect(componentsB.peerId, c0)
})
componentsB.getRegistrar().getTopologies(multicodec).forEach(topology => {
topology.onConnect(componentsA.getPeerId(), c1)
componentsB.registrar.getTopologies(multicodec).forEach(topology => {
topology.onConnect(componentsA.peerId, c1)
})
}

Expand Down