From 9f301964ed74316de7796c0cbd9728190ac2fdda Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Date: Wed, 28 Apr 2021 10:03:03 +0900 Subject: [PATCH] fix control messages (#566) * remove unused control graft check in handleControl * avoid sending empty Iwant messages --- libp2p/protocols/pubsub/gossipsub.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 54e07f052..b44c1842d 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -247,12 +247,13 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, rpcMsg: RPCMsg) = g.handlePrune(peer, control.prune) var respControl: ControlMessage - respControl.iwant.add(g.handleIHave(peer, control.ihave)) + let iwant = g.handleIHave(peer, control.ihave) + if iwant.messageIDs.len > 0: + respControl.iwant.add(iwant) respControl.prune.add(g.handleGraft(peer, control.graft)) let messages = g.handleIWant(peer, control.iwant) if - respControl.graft.len > 0 or respControl.prune.len > 0 or respControl.iwant.len > 0 or messages.len > 0: @@ -264,12 +265,15 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, rpcMsg: RPCMsg) = libp2p_pubsub_broadcast_messages.inc(labelValues = [topic]) else: libp2p_pubsub_broadcast_messages.inc(labelValues = ["generic"]) + libp2p_pubsub_broadcast_iwant.inc(respControl.iwant.len.int64) + for prune in respControl.prune: if g.knownTopics.contains(prune.topicID): libp2p_pubsub_broadcast_prune.inc(labelValues = [prune.topicID]) else: libp2p_pubsub_broadcast_prune.inc(labelValues = ["generic"]) + trace "sending control message", msg = shortLog(respControl), peer g.send( peer,