Compare commits

...

1 Commits

Author SHA1 Message Date
ufarooqstatus
54a4054308 Skip sending IWant if we have received multiple IDontWants for the same msgId 2024-06-03 19:13:26 +05:00

View File

@@ -29,6 +29,7 @@ declareGauge(libp2p_gossipsub_low_peers_topics, "number of topics in mesh with a
declareGauge(libp2p_gossipsub_healthy_peers_topics, "number of topics in mesh with at least dlow peers (but below dhigh)")
declareCounter(libp2p_gossipsub_above_dhigh_condition, "number of above dhigh pruning branches ran", labels = ["topic"])
declareGauge(libp2p_gossipsub_received_iwants, "received iwants", labels = ["kind"])
declareCounter(libp2p_gossipsub_IWANT_Saves, "number of saved IWANTs based on received IDontWants")
proc grafted*(g: GossipSub, p: PubSubPeer, topic: string) =
g.withPeerStats(p.peerId) do (stats: var PeerStats):
@@ -249,14 +250,29 @@ proc handleIHave*(g: GossipSub,
trace "peer sent ihave",
peer, topicID = ihave.topicID, msgs = ihave.messageIDs
if ihave.topicID in g.topics:
#look here for receieved idontwants for the same message
var meshPeers: HashSet[PubSubPeer]
g.mesh.withValue(ihave.topicID, peers): meshPeers.incl(peers[])
for msgId in ihave.messageIDs:
if not g.hasSeen(g.salt(msgId)):
if peer.iHaveBudget <= 0:
break
elif msgId notin res.messageIDs:
res.messageIDs.add(msgId)
dec peer.iHaveBudget
trace "requested message via ihave", messageID=msgId
#dont send IWANT if we have received (N number of) IDontWant(s) for a msgID
let saltedID = g.salt(msgId)
var numFinds: int = 0
for meshPeer in meshPeers:
for heDontWant in meshPeer.heDontWants:
if saltedID in heDontWant:
numFinds = numFinds + 1
#break;
if numFinds > 0: #Or wait for N number of IDontWants
libp2p_gossipsub_IWANT_Saves.inc
else:
res.messageIDs.add(msgId)
dec peer.iHaveBudget
trace "requested message via ihave", messageID=msgId
# shuffling res.messageIDs before sending it out to increase the likelihood
# of getting an answer if the peer truncates the list due to internal size restrictions.
g.rng.shuffle(res.messageIDs)