Skip to content

Commit 826ce1b

Browse files
committed
add comments
1 parent 4f49ac8 commit 826ce1b

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

libp2p/protocols/pubsub/gossipsub.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, control: ControlMessage) =
306306
g.send(
307307
peer,
308308
RPCMsg(control: some(respControl)), true)
309+
# iwant replies have lower priority
309310
g.send(
310311
peer,
311312
RPCMsg(messages: messages), false)

libp2p/protocols/pubsub/pubsubpeer.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ type
5353
OnEvent* = proc(peer: PubSubPeer, event: PubSubPeerEvent) {.gcsafe, raises: [].}
5454

5555
RpcMessageQueue* = ref object
56+
# Tracks async tasks for sending high-priority peer-published messages.
5657
sendPriorityQueue: Deque[Future[void]]
58+
# Queue for lower-priority messages, like "IWANT" replies and relay messages.
5759
nonPriorityQueue: AsyncQueue[seq[byte]]
60+
# Task for processing non-priority message queue.
5861
sendNonPriorityTask: Future[void]
5962

6063
PubSubPeer* = ref object of RootObj
@@ -372,6 +375,7 @@ proc sendNonPriorityTask(p: PubSubPeer) {.async.} =
372375
while p.rpcmessagequeue.sendPriorityQueue.len > 0:
373376
await p.rpcmessagequeue.sendPriorityQueue[0]
374377
p.clearSendPriorityQueue()
378+
# we send non-priority messages only if there are no pending priority messages
375379
let msg = await p.rpcmessagequeue.nonPriorityQueue.popFirst()
376380
when defined(libp2p_expensive_metrics):
377381
libp2p_gossipsub_non_priority_queue_size.dec(labelValues = [$p.peerId])

0 commit comments

Comments
 (0)