mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2025-03-04 01:50:36 +00:00
handle empty msgs correctly
This commit is contained in:
parent
14d1787de8
commit
a1f3940c06
@ -281,12 +281,28 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, control: ControlMessage) =
|
|||||||
respControl.prune.add(g.handleGraft(peer, control.graft))
|
respControl.prune.add(g.handleGraft(peer, control.graft))
|
||||||
let messages = g.handleIWant(peer, control.iwant)
|
let messages = g.handleIWant(peer, control.iwant)
|
||||||
|
|
||||||
if
|
let
|
||||||
respControl.prune.len > 0 or
|
isPruneNotEmpty = respControl.prune.len > 0
|
||||||
respControl.iwant.len > 0 or
|
isIWantNotEmpty = respControl.iwant.len > 0
|
||||||
messages.len > 0:
|
|
||||||
# iwant and prunes from here, also messages
|
|
||||||
|
|
||||||
|
if isPruneNotEmpty or isIWantNotEmpty:
|
||||||
|
|
||||||
|
if isIWantNotEmpty:
|
||||||
|
libp2p_pubsub_broadcast_iwant.inc(respControl.iwant.len.int64)
|
||||||
|
|
||||||
|
if isPruneNotEmpty:
|
||||||
|
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,
|
||||||
|
RPCMsg(control: some(respControl)), true)
|
||||||
|
|
||||||
|
if messages.len > 0:
|
||||||
for smsg in messages:
|
for smsg in messages:
|
||||||
for topic in smsg.topicIds:
|
for topic in smsg.topicIds:
|
||||||
if g.knownTopics.contains(topic):
|
if g.knownTopics.contains(topic):
|
||||||
@ -294,19 +310,8 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, control: ControlMessage) =
|
|||||||
else:
|
else:
|
||||||
libp2p_pubsub_broadcast_messages.inc(labelValues = ["generic"])
|
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,
|
|
||||||
RPCMsg(control: some(respControl)), true)
|
|
||||||
# iwant replies have lower priority
|
# iwant replies have lower priority
|
||||||
|
trace "sending iwant reply messages", peer
|
||||||
g.send(
|
g.send(
|
||||||
peer,
|
peer,
|
||||||
RPCMsg(messages: messages), false)
|
RPCMsg(messages: messages), false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user