diff --git a/examples/package.json b/examples/package.json index 35637751..c94da14d 100644 --- a/examples/package.json +++ b/examples/package.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@libp2p/pubsub-peer-discovery": "^5.0.1", - "@libp2p/floodsub": "^1.0.5", + "@libp2p/floodsub": "^1.0.6", "execa": "^2.1.0", "fs-extra": "^8.1.0", "libp2p": "../", diff --git a/examples/pubsub/1.js b/examples/pubsub/1.js index 15417112..bb89977e 100644 --- a/examples/pubsub/1.js +++ b/examples/pubsub/1.js @@ -48,6 +48,8 @@ const createNode = async () => { // node2 publishes "news" every second setInterval(() => { - node2.pubsub.publish(topic, uint8ArrayFromString('Bird bird bird, bird is the word!')) + node2.pubsub.publish(topic, uint8ArrayFromString('Bird bird bird, bird is the word!')).catch(err => { + console.error(err) + }) }, 1000) })() diff --git a/examples/pubsub/README.md b/examples/pubsub/README.md index 9dec1f97..0913e1fd 100644 --- a/examples/pubsub/README.md +++ b/examples/pubsub/README.md @@ -69,7 +69,9 @@ await node2.pubsub.subscribe(topic) // node2 publishes "news" every second setInterval(() => { - node2.pubsub.publish(topic, fromString('Bird bird bird, bird is the word!')) + node2.pubsub.publish(topic, fromString('Bird bird bird, bird is the word!')).catch(err => { + console.error(err) + }) }, 1000) ``` diff --git a/examples/pubsub/message-filtering/1.js b/examples/pubsub/message-filtering/1.js index efe1d835..f83ecc98 100644 --- a/examples/pubsub/message-filtering/1.js +++ b/examples/pubsub/message-filtering/1.js @@ -74,7 +74,9 @@ const createNode = async () => { // car is not a fruit ! setInterval(() => { console.log('############## fruit ' + myFruits[count] + ' ##############') - node1.pubsub.publish(topic, uint8ArrayFromString(myFruits[count])) + node1.pubsub.publish(topic, uint8ArrayFromString(myFruits[count])).catch(err => { + console.info(err) + }) count++ if (count == myFruits.length) { count = 0 diff --git a/examples/pubsub/message-filtering/README.md b/examples/pubsub/message-filtering/README.md index 9eecb873..99cec8aa 100644 --- a/examples/pubsub/message-filtering/README.md +++ b/examples/pubsub/message-filtering/README.md @@ -88,7 +88,9 @@ const myFruits = ['banana', 'apple', 'car', 'orange']; setInterval(() => { console.log('############## fruit ' + myFruits[count] + ' ##############') - node1.pubsub.publish(topic, new TextEncoder().encode(myFruits[count])) + node1.pubsub.publish(topic, new TextEncoder().encode(myFruits[count])).catch(err => { + console.error(err) + }) count++ if (count == myFruits.length) { count = 0 diff --git a/package.json b/package.json index 73cd9168..78820120 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "@achingbrain/nat-port-mapper": "^1.0.0", "@libp2p/connection": "^1.1.5", "@libp2p/crypto": "^0.22.11", - "@libp2p/interfaces": "^1.3.22", + "@libp2p/interfaces": "^1.3.24", "@libp2p/logger": "^1.1.4", "@libp2p/multistream-select": "^1.0.4", "@libp2p/peer-id": "^1.1.10", @@ -162,8 +162,8 @@ "@libp2p/daemon-server": "^1.0.2", "@libp2p/delegated-content-routing": "^1.0.2", "@libp2p/delegated-peer-routing": "^1.0.2", - "@libp2p/floodsub": "^1.0.5", - "@libp2p/interface-compliance-tests": "^1.1.23", + "@libp2p/floodsub": "^1.0.6", + "@libp2p/interface-compliance-tests": "^1.1.25", "@libp2p/interop": "^1.0.3", "@libp2p/kad-dht": "^1.0.7", "@libp2p/mdns": "^1.0.4", diff --git a/src/pubsub/dummy-pubsub.ts b/src/pubsub/dummy-pubsub.ts index 82014760..15fe0536 100644 --- a/src/pubsub/dummy-pubsub.ts +++ b/src/pubsub/dummy-pubsub.ts @@ -1,6 +1,6 @@ import { EventEmitter } from '@libp2p/interfaces' import type { PeerId } from '@libp2p/interfaces/peer-id' -import type { PubSub, PubSubEvents, StrictNoSign, StrictSign } from '@libp2p/interfaces/pubsub' +import type { PublishResult, PubSub, PubSubEvents, StrictNoSign, StrictSign } from '@libp2p/interfaces/pubsub' import errCode from 'err-code' import { messages, codes } from '../errors.js' @@ -45,7 +45,7 @@ export class DummyPubSub extends EventEmitter implements PubSub { throw errCode(new Error(messages.PUBSUB_DISABLED), codes.ERR_PUBSUB_DISABLED) } - publish (): void { + async publish (): Promise { throw errCode(new Error(messages.PUBSUB_DISABLED), codes.ERR_PUBSUB_DISABLED) } } diff --git a/test/configuration/pubsub.spec.ts b/test/configuration/pubsub.spec.ts index 6d0c6e68..080503b3 100644 --- a/test/configuration/pubsub.spec.ts +++ b/test/configuration/pubsub.spec.ts @@ -90,12 +90,12 @@ describe('Pubsub subscription handlers adapter', () => { pubsub.subscribe(topic) pubsub.addEventListener('message', handler) - pubsub.publish(topic, uint8ArrayFromString('useless-data')) + await pubsub.publish(topic, uint8ArrayFromString('useless-data')) await defer.promise pubsub.unsubscribe(topic) pubsub.removeEventListener('message', handler) - pubsub.publish(topic, uint8ArrayFromString('useless-data')) + await pubsub.publish(topic, uint8ArrayFromString('useless-data')) // wait to guarantee that the handler is not called twice await delay(100) diff --git a/test/configuration/utils.ts b/test/configuration/utils.ts index 3965d6b0..b7cbacf8 100644 --- a/test/configuration/utils.ts +++ b/test/configuration/utils.ts @@ -5,7 +5,7 @@ import { WebSockets } from '@libp2p/websockets' import * as filters from '@libp2p/websockets/filters' import { MULTIADDRS_WEBSOCKETS } from '../fixtures/browser.js' import mergeOptions from 'merge-options' -import type { Message, PubSubInit, PubSubRPC, PubSubRPCMessage } from '@libp2p/interfaces/pubsub' +import type { Message, PublishResult, PubSubInit, PubSubRPC, PubSubRPCMessage } from '@libp2p/interfaces/pubsub' import type { Libp2pInit, Libp2pOptions } from '../../src/index.js' import type { PeerId } from '@libp2p/interfaces/peer-id' import * as cborg from 'cborg' @@ -44,11 +44,12 @@ class MockPubSub extends PubSubBaseProtocol { return cborg.encode(rpc) } - async publishMessage (from: PeerId, message: Message): Promise { + async publishMessage (from: PeerId, message: Message): Promise { const peers = this.getSubscribers(message.topic) + const recipients: PeerId[] = [] if (peers == null || peers.length === 0) { - return + return { recipients } } peers.forEach(id => { @@ -60,8 +61,11 @@ class MockPubSub extends PubSubBaseProtocol { return } + recipients.push(id) this.send(id, { messages: [message] }) }) + + return { recipients } } } diff --git a/test/identify/index.spec.ts b/test/identify/index.spec.ts index bbe81306..c1ae112a 100644 --- a/test/identify/index.spec.ts +++ b/test/identify/index.spec.ts @@ -114,13 +114,7 @@ describe('Identify', () => { await localIdentify.start() await remoteIdentify.start() - const [localToRemote] = connectionPair({ - peerId: localComponents.getPeerId(), - registrar: localComponents.getRegistrar() - }, { - peerId: remoteComponents.getPeerId(), - registrar: remoteComponents.getRegistrar() - }) + const [localToRemote] = connectionPair(localComponents, remoteComponents) const localAddressBookConsumePeerRecordSpy = sinon.spy(localComponents.getPeerStore().addressBook, 'consumePeerRecord') const localProtoBookSetSpy = sinon.spy(localComponents.getPeerStore().protoBook, 'set') @@ -161,13 +155,7 @@ describe('Identify', () => { }) await remoteIdentify.start() - const [localToRemote] = connectionPair({ - peerId: localComponents.getPeerId(), - registrar: localComponents.getRegistrar() - }, { - peerId: remoteComponents.getPeerId(), - registrar: remoteComponents.getRegistrar() - }) + const [localToRemote] = connectionPair(localComponents, remoteComponents) sinon.stub(localComponents.getPeerStore().addressBook, 'consumePeerRecord').throws() @@ -194,13 +182,7 @@ describe('Identify', () => { await localIdentify.start() await remoteIdentify.start() - const [localToRemote] = connectionPair({ - peerId: localComponents.getPeerId(), - registrar: localComponents.getRegistrar() - }, { - peerId: remoteComponents.getPeerId(), - registrar: remoteComponents.getRegistrar() - }) + const [localToRemote] = connectionPair(localComponents, remoteComponents) // send an invalid message await remoteComponents.getRegistrar().unhandle(MULTICODEC_IDENTIFY) @@ -267,13 +249,7 @@ describe('Identify', () => { await localIdentify.start() await remoteIdentify.start() - const [localToRemote, remoteToLocal] = connectionPair({ - peerId: localComponents.getPeerId(), - registrar: localComponents.getRegistrar() - }, { - peerId: remoteComponents.getPeerId(), - registrar: remoteComponents.getRegistrar() - }) + const [localToRemote, remoteToLocal] = connectionPair(localComponents, remoteComponents) // ensure connections are registered by connection manager localComponents.getUpgrader().dispatchEvent(new CustomEvent('connection', { @@ -353,13 +329,7 @@ describe('Identify', () => { await localIdentify.start() await remoteIdentify.start() - const [localToRemote, remoteToLocal] = connectionPair({ - peerId: localComponents.getPeerId(), - registrar: localComponents.getRegistrar() - }, { - peerId: remoteComponents.getPeerId(), - registrar: remoteComponents.getRegistrar() - }) + const [localToRemote, remoteToLocal] = connectionPair(localComponents, remoteComponents) // ensure connections are registered by connection manager localComponents.getUpgrader().dispatchEvent(new CustomEvent('connection', {