Skip to content

Commit

Permalink
feat: publish at least mesh_n peers (#493)
Browse files Browse the repository at this point in the history
* feat: publish at least mesh_n peers

* chore: add more comments
  • Loading branch information
twoeths authored Apr 19, 2024
1 parent ff620fd commit bc3906f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,20 @@ export class GossipSub extends TypedEventEmitter<GossipsubEvents> implements Pub
tosend.add(peer)
tosendCount.mesh++
})

// We want to publish to at least `D` peers.
// If there are insufficient peers in the mesh, publish to other topic peers
if (meshPeers.size < this.opts.D) {
// pick additional topic peers above the publishThreshold
const topicPeers = this.getRandomGossipPeers(topic, this.opts.D - meshPeers.size, (id) => {
return !meshPeers.has(id) && !this.direct.has(id) && !this.floodsubPeers.has(id) && this.score.score(id) >= this.opts.scoreThresholds.publishThreshold
})

topicPeers.forEach((peer) => {
tosend.add(peer)
tosendCount.mesh++
})
}
// eslint-disable-next-line @typescript-eslint/brace-style
}

Expand Down

0 comments on commit bc3906f

Please sign in to comment.