@@ -220,6 +220,8 @@ method unsubscribePeer*(g: GossipSub, peer: PeerId) =
220
220
for topic, info in stats[].topicInfos.mpairs:
221
221
info.firstMessageDeliveries = 0
222
222
223
+ pubSubPeer.stopSendNonPriorityTask ()
224
+
223
225
procCall FloodSub (g).unsubscribePeer (peer)
224
226
225
227
proc handleSubscribe * (g: GossipSub ,
@@ -279,31 +281,40 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, control: ControlMessage) =
279
281
respControl.prune.add (g.handleGraft (peer, control.graft))
280
282
let messages = g.handleIWant (peer, control.iwant)
281
283
282
- if
283
- respControl.prune.len > 0 or
284
- respControl.iwant.len > 0 or
285
- messages.len > 0 :
286
- # iwant and prunes from here, also messages
284
+ let
285
+ isPruneNotEmpty = respControl.prune.len > 0
286
+ isIWantNotEmpty = respControl.iwant.len > 0
287
+
288
+ if isPruneNotEmpty or isIWantNotEmpty:
289
+
290
+ if isIWantNotEmpty:
291
+ libp2p_pubsub_broadcast_iwant.inc (respControl.iwant.len.int64 )
292
+
293
+ if isPruneNotEmpty:
294
+ for prune in respControl.prune:
295
+ if g.knownTopics.contains (prune.topicId):
296
+ libp2p_pubsub_broadcast_prune.inc (labelValues = [prune.topicId])
297
+ else :
298
+ libp2p_pubsub_broadcast_prune.inc (labelValues = [" generic" ])
299
+
300
+ trace " sending control message" , msg = shortLog (respControl), peer
301
+ g.send (
302
+ peer,
303
+ RPCMsg (control: some (respControl)), isHighPriority = true )
287
304
305
+ if messages.len > 0 :
288
306
for smsg in messages:
289
307
for topic in smsg.topicIds:
290
308
if g.knownTopics.contains (topic):
291
309
libp2p_pubsub_broadcast_messages.inc (labelValues = [topic])
292
310
else :
293
311
libp2p_pubsub_broadcast_messages.inc (labelValues = [" generic" ])
294
312
295
- libp2p_pubsub_broadcast_iwant.inc (respControl.iwant.len.int64 )
296
-
297
- for prune in respControl.prune:
298
- if g.knownTopics.contains (prune.topicId):
299
- libp2p_pubsub_broadcast_prune.inc (labelValues = [prune.topicId])
300
- else :
301
- libp2p_pubsub_broadcast_prune.inc (labelValues = [" generic" ])
302
-
303
- trace " sending control message" , msg = shortLog (respControl), peer
313
+ # iwant replies have lower priority
314
+ trace " sending iwant reply messages" , peer
304
315
g.send (
305
316
peer,
306
- RPCMsg (control: some (respControl ), messages: messages) )
317
+ RPCMsg (messages: messages ), isHighPriority = false )
307
318
308
319
proc validateAndRelay (g: GossipSub ,
309
320
msg: Message ,
@@ -356,7 +367,7 @@ proc validateAndRelay(g: GossipSub,
356
367
if msg.data.len > msgId.len * 10 :
357
368
g.broadcast (toSendPeers, RPCMsg (control: some (ControlMessage (
358
369
idontwant: @ [ControlIWant (messageIds: @ [msgId])]
359
- ))))
370
+ ))), isHighPriority = true )
360
371
361
372
for peer in toSendPeers:
362
373
for heDontWant in peer.heDontWants:
@@ -370,7 +381,7 @@ proc validateAndRelay(g: GossipSub,
370
381
371
382
# In theory, if topics are the same in all messages, we could batch - we'd
372
383
# also have to be careful to only include validated messages
373
- g.broadcast (toSendPeers, RPCMsg (messages: @ [msg]))
384
+ g.broadcast (toSendPeers, RPCMsg (messages: @ [msg]), isHighPriority = false )
374
385
trace " forwarded message to peers" , peers = toSendPeers.len, msgId, peer
375
386
for topic in msg.topicIds:
376
387
if topic notin g.topics: continue
@@ -441,7 +452,7 @@ method rpcHandler*(g: GossipSub,
441
452
peer.recvObservers (rpcMsg)
442
453
443
454
if rpcMsg.ping.len in 1 ..< 64 and peer.pingBudget > 0 :
444
- g.send (peer, RPCMsg (pong: rpcMsg.ping))
455
+ g.send (peer, RPCMsg (pong: rpcMsg.ping), isHighPriority = true )
445
456
peer.pingBudget.dec
446
457
for i in 0 ..< min (g.topicsHigh, rpcMsg.subscriptions.len):
447
458
template sub : untyped = rpcMsg.subscriptions[i]
@@ -551,7 +562,7 @@ method onTopicSubscription*(g: GossipSub, topic: string, subscribed: bool) =
551
562
topicID: topic,
552
563
peers: g.peerExchangeList (topic),
553
564
backoff: g.parameters.unsubscribeBackoff.seconds.uint64 )])))
554
- g.broadcast (mpeers, msg)
565
+ g.broadcast (mpeers, msg, isHighPriority = true )
555
566
556
567
for peer in mpeers:
557
568
g.pruned (peer, topic, backoff = some (g.parameters.unsubscribeBackoff))
@@ -655,7 +666,7 @@ method publish*(g: GossipSub,
655
666
656
667
g.mcache.put (msgId, msg)
657
668
658
- g.broadcast (peers, RPCMsg (messages: @ [msg]))
669
+ g.broadcast (peers, RPCMsg (messages: @ [msg]), isHighPriority = true )
659
670
660
671
if g.knownTopics.contains (topic):
661
672
libp2p_pubsub_messages_published.inc (peers.len.int64 , labelValues = [topic])
0 commit comments