From 14a6c32af2dd4fb6f56bff3fb37b465e2465bbd4 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Wed, 27 Mar 2024 16:11:17 +0700 Subject: [PATCH] feat: publish at least mesh_n peers --- src/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/index.ts b/src/index.ts index 9bc059a6..6162a13d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2036,6 +2036,18 @@ export class GossipSub extends TypedEventEmitter implements Pub tosend.add(peer) tosendCount.mesh++ }) + + 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 }