Skip to content

Commit

Permalink
deps!: update to latest libp2p@0.45.x deps (#111)
Browse files Browse the repository at this point in the history
Update to the consolidated libp2p interface deps.

Adds a note to the readme about configuring a pubsub service.

Closes #98
  • Loading branch information
achingbrain authored Sep 18, 2023
1 parent e7fd8b0 commit d54009b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ It is worth noting that this module does not include any message signing for bro

This module *MUST* be used on a libp2p node that is running [Pubsub](https://github.com/libp2p/js-libp2p-pubsub). If Pubsub does not exist, or is not running, this module will not work.

To run a PubSub service, include a `pubsub` implementation in your services map such as `@chainsafe/libp2p-gossipsub`.

For more information see the [docs on customizing libp2p](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#customizing-libp2p).

### Usage in js-libp2p

See the [js-libp2p configuration docs](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#customizing-peer-discovery) for how to include this module as a peer discovery module in js-libp2p.
Expand All @@ -64,10 +68,11 @@ If you are only interested in listening to the global pubsub topic the minimal c
```js
import { createLibp2p } from 'libp2p'
import { websockets } from '@libp2p/websockets'
import { mplex } from '@libp2p/mplex'
import { yamux } from '@chainsafe/libp2p-yamux'
import { noise } from '@chainsafe/libp2p-noise'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'
import { identify } from 'libp2p/identify'

const node = await createLibp2p({
transports: [
Expand All @@ -77,12 +82,15 @@ const node = await createLibp2p({
mplex()
],
connectionEncryption: [
noise()
yamux()
],
pubsub: new GossipSub(), // Can also be `libp2p-floodsub` if desired
peerDiscovery: [
pubsubPeerDiscovery()
]
],
services: {
pubsub: gossipsub(),
identify: identify()
}
})
```

Expand Down
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,16 @@
"docs": "aegir docs"
},
"dependencies": {
"@libp2p/interface-peer-discovery": "^2.0.0",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interface-peer-info": "^1.0.2",
"@libp2p/interface-pubsub": "^4.0.0",
"@libp2p/interfaces": "^3.0.3",
"@libp2p/interface": "^0.1.2",
"@libp2p/interface-internal": "^0.1.5",
"@libp2p/logger": "^3.0.2",
"@libp2p/peer-id": "^3.0.2",
"@multiformats/multiaddr": "^12.0.0",
"protons-runtime": "^5.0.0",
"uint8arraylist": "^2.4.3"
},
"devDependencies": {
"@libp2p/interface-address-manager": "^3.0.0",
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.0",
"@libp2p/interface-compliance-tests": "^4.0.6",
"@libp2p/peer-id-factory": "^3.0.4",
"aegir": "^40.0.0",
"p-defer": "^4.0.0",
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { peerDiscovery } from '@libp2p/interface-peer-discovery'
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
import { CustomEvent, EventEmitter } from '@libp2p/interface/events'
import { peerDiscovery } from '@libp2p/interface/peer-discovery'
import { logger } from '@libp2p/logger'
import { peerIdFromKeys } from '@libp2p/peer-id'
import { multiaddr } from '@multiformats/multiaddr'
import { Peer as PBPeer } from './peer.js'
import type { AddressManager } from '@libp2p/interface-address-manager'
import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerInfo } from '@libp2p/interface-peer-info'
import type { Message, PubSub } from '@libp2p/interface-pubsub'
import type { Startable } from '@libp2p/interfaces/startable'
import type { PeerDiscovery, PeerDiscoveryEvents } from '@libp2p/interface/peer-discovery'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { PeerInfo } from '@libp2p/interface/peer-info'
import type { Message, PubSub } from '@libp2p/interface/pubsub'
import type { Startable } from '@libp2p/interface/startable'
import type { AddressManager } from '@libp2p/interface-internal/address-manager'

const log = logger('libp2p:discovery:pubsub')
export const TOPIC = '_peer-discovery._p2p._pubsub'
Expand Down
8 changes: 4 additions & 4 deletions test/compliance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-env mocha */

import tests from '@libp2p/interface-peer-discovery-compliance-tests'
import { CustomEvent } from '@libp2p/interfaces/events'
import { CustomEvent } from '@libp2p/interface/events'
import tests from '@libp2p/interface-compliance-tests/peer-discovery'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { multiaddr } from '@multiformats/multiaddr'
import { stubInterface } from 'ts-sinon'
import { pubsubPeerDiscovery, TOPIC } from '../src/index.js'
import { Peer as PBPeer } from '../src/peer.js'
import type { AddressManager } from '@libp2p/interface-address-manager'
import type { PubSub } from '@libp2p/interface-pubsub'
import type { PubSub } from '@libp2p/interface/pubsub'
import type { AddressManager } from '@libp2p/interface-internal/address-manager'

describe('compliance tests', () => {
let intervalId: ReturnType<typeof setInterval>
Expand Down
12 changes: 6 additions & 6 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */

import { CustomEvent } from '@libp2p/interfaces/events'
import { start, stop } from '@libp2p/interfaces/startable'
import { CustomEvent } from '@libp2p/interface/events'
import { start, stop } from '@libp2p/interface/startable'
import { peerIdFromKeys } from '@libp2p/peer-id'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { multiaddr } from '@multiformats/multiaddr'
Expand All @@ -12,10 +12,10 @@ import sinon from 'sinon'
import { type StubbedInstance, stubInterface } from 'ts-sinon'
import { pubsubPeerDiscovery, type PubSubPeerDiscoveryComponents, TOPIC } from '../src/index.js'
import * as PB from '../src/peer.js'
import type { AddressManager } from '@libp2p/interface-address-manager'
import type { PeerDiscovery } from '@libp2p/interface-peer-discovery'
import type { PeerInfo } from '@libp2p/interface-peer-info'
import type { PubSub } from '@libp2p/interface-pubsub'
import type { PeerDiscovery } from '@libp2p/interface/peer-discovery'
import type { PeerInfo } from '@libp2p/interface/peer-info'
import type { PubSub } from '@libp2p/interface/pubsub'
import type { AddressManager } from '@libp2p/interface-internal/address-manager'

const listeningMultiaddr = multiaddr('/ip4/127.0.0.1/tcp/9000/ws')

Expand Down

0 comments on commit d54009b

Please sign in to comment.