Skip to content

Commit

Permalink
fix: flip conditional in piggyback control - typo from #347 (#353)
Browse files Browse the repository at this point in the history
Fix typo from  #347
  • Loading branch information
dapplion committed Oct 3, 2022
1 parent 6b5ff4d commit cad96c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements Initiali
if (!outRpc.control) outRpc.control = {}
if (!outRpc.control.prune) outRpc.control.prune = []
for (const prune of ctrl.prune) {
if (prune.topicID && this.mesh.get(prune.topicID)?.has(id)) {
if (prune.topicID && !this.mesh.get(prune.topicID)?.has(id)) {
outRpc.control.prune.push(prune)
}
}
Expand Down
40 changes: 22 additions & 18 deletions test/e2e/go-gossipsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MessageAcceptance } from '../../src/types.js'
import { GossipsubD } from '../../src/constants.js'
import { fastMsgIdFn } from '../utils/index.js'
import type { Message } from '@libp2p/interface-pubsub'
import type { IRPC } from '../../src/message/rpc.js'
import type { IRPC, RPC } from '../../src/message/rpc.js'
import type { ConnectionManagerEvents } from '@libp2p/interface-connection-manager'
import pWaitFor from 'p-wait-for'
import { Components } from '@libp2p/components'
Expand Down Expand Up @@ -1179,33 +1179,37 @@ describe('go-libp2p-pubsub gossipsub tests', function () {
const otherId = psubs[1].getPeerId().toString()
const psub = psubs[0].getPubSub() as GossipSub

const test1 = 'test1'
const test2 = 'test2'
const test3 = 'test3'
psub.mesh.set(test1, new Set([otherId]))
psub.mesh.set(test2, new Set())
const topic1 = 'topic_1'
const topic2 = 'topic_2'
const topic3 = 'topic_3'
psub.mesh.set(topic1, new Set([otherId]))
psub.mesh.set(topic2, new Set())

const rpc: IRPC = {
subscriptions: [],
messages: []
}

const toGraft = (topicID: string): RPC.IControlGraft => ({ topicID })
const toPrune = (topicID: string): RPC.IControlPrune => ({ topicID, peers: [] })

psub.piggybackControl(otherId, rpc, {
graft: [{ topicID: test1 }, { topicID: test2 }, { topicID: test3 }],
prune: [
{ topicID: test1, peers: [] },
{ topicID: test2, peers: [] },
{ topicID: test3, peers: [] }
],
graft: [toGraft(topic1), toGraft(topic2), toGraft(topic3)],
prune: [toPrune(topic1), toPrune(topic2), toPrune(topic3)],
ihave: [],
iwant: []
})

expect(rpc.control).to.be.ok()
expect(rpc).to.have.nested.property('control.graft.length', 1)
expect(rpc).to.have.nested.property('control.graft[0].topicID', test1)
expect(rpc).to.have.nested.property('control.prune.length', 2)
expect(rpc).to.have.nested.property('control.prune[0].topicID', test2)
expect(rpc).to.have.nested.property('control.prune[1].topicID', test3)
const expectedRpc: IRPC = {
subscriptions: [],
messages: [],
control: {
graft: [toGraft(topic1)],
prune: [toPrune(topic2), toPrune(topic3)]
}
}

expect(rpc).deep.equals(expectedRpc)

await psub.stop()
})
Expand Down

0 comments on commit cad96c2

Please sign in to comment.