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

Commit

Permalink
fix: update interfaces to latest version (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Apr 22, 2022
1 parent e484896 commit d7444be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<boolean>

constructor (init?: FloodSubInit) {
Expand Down Expand Up @@ -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<PublishResult> {
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 => {
Expand All @@ -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 }
}
}
2 changes: 1 addition & 1 deletion test/floodsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d7444be

Please sign in to comment.