Skip to content

Commit bc3906f

Browse files
authored
feat: publish at least mesh_n peers (#493)
* feat: publish at least mesh_n peers * chore: add more comments
1 parent ff620fd commit bc3906f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,20 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub
20362036
tosend.add(peer)
20372037
tosendCount.mesh++
20382038
})
2039+
2040+
// We want to publish to at least `D` peers.
2041+
// If there are insufficient peers in the mesh, publish to other topic peers
2042+
if (meshPeers.size < this.opts.D) {
2043+
// pick additional topic peers above the publishThreshold
2044+
const topicPeers = this.getRandomGossipPeers(topic, this.opts.D - meshPeers.size, (id) => {
2045+
return !meshPeers.has(id) && !this.direct.has(id) && !this.floodsubPeers.has(id) && this.score.score(id) >= this.opts.scoreThresholds.publishThreshold
2046+
})
2047+
2048+
topicPeers.forEach((peer) => {
2049+
tosend.add(peer)
2050+
tosendCount.mesh++
2051+
})
2052+
}
20392053
// eslint-disable-next-line @typescript-eslint/brace-style
20402054
}
20412055

0 commit comments

Comments
 (0)