From d7444be89c8b67c1d8c21a657406c48288a8cffd Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 22 Apr 2022 18:50:45 +0100 Subject: [PATCH] fix: update interfaces to latest version (#148) --- package.json | 6 +++--- src/index.ts | 12 ++++++++---- test/floodsub.spec.ts | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 93bc616..93e113a 100644 --- a/package.json +++ b/package.json @@ -142,14 +142,14 @@ "release": "aegir release" }, "dependencies": { - "@libp2p/interfaces": "^1.3.22", + "@libp2p/interfaces": "^1.3.24", "@libp2p/logger": "^1.1.4", - "@libp2p/pubsub": "^1.2.18", + "@libp2p/pubsub": "^1.2.20", "protons-runtime": "^1.0.3", "uint8arrays": "^3.0.0" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^1.1.23", + "@libp2p/interface-compliance-tests": "^1.1.25", "@libp2p/peer-collections": "^1.0.2", "@libp2p/peer-id": "^1.1.10", "@libp2p/peer-id-factory": "^1.0.9", diff --git a/src/index.ts b/src/index.ts index becdffc..0b76caf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import { toString } from 'uint8arrays/to-string' import { PubSubBaseProtocol } from '@libp2p/pubsub' import { multicodec } from './config.js' import { SimpleTimeCache } from './cache.js' -import type { PubSub, PubSubInit, Message, PubSubRPC, PubSubRPCMessage } from '@libp2p/interfaces/pubsub' +import type { PubSubInit, Message, PubSubRPC, PubSubRPCMessage, PublishResult } from '@libp2p/interfaces/pubsub' import type { PeerId } from '@libp2p/interfaces/peer-id' import { logger } from '@libp2p/logger' import { RPC } from './message/rpc.js' @@ -20,7 +20,7 @@ export interface FloodSubInit extends PubSubInit { * delivering an API for Publish/Subscribe, but with no CastTree Forming * (it just floods the network). */ -export class FloodSub extends PubSubBaseProtocol implements PubSub { +export class FloodSub extends PubSubBaseProtocol { public seenCache: SimpleTimeCache constructor (init?: FloodSubInit) { @@ -83,12 +83,13 @@ export class FloodSub extends PubSubBaseProtocol implements PubSub { /** * Publish message created. Forward it to the peers. */ - async publishMessage (from: PeerId, message: Message) { + async publishMessage (from: PeerId, message: Message): Promise { const peers = this.getSubscribers(message.topic) + const recipients: PeerId[] = [] if (peers == null || peers.length === 0) { log('no peers are subscribed to topic %s', message.topic) - return + return { recipients } } peers.forEach(id => { @@ -104,7 +105,10 @@ export class FloodSub extends PubSubBaseProtocol implements PubSub { log('publish msgs on topics %s %p', message.topic, id) + recipients.push(id) this.send(id, { messages: [message] }) }) + + return { recipients } } } diff --git a/test/floodsub.spec.ts b/test/floodsub.spec.ts index da34123..ef16087 100644 --- a/test/floodsub.spec.ts +++ b/test/floodsub.spec.ts @@ -100,7 +100,7 @@ describe('floodsub', () => { } expect(floodsub.send).to.have.property('callCount', 0) - floodsub.publish(topic, message) + await floodsub.publish(topic, message) await pWaitFor(async () => spy.callCount === 1)