add comments

This commit is contained in:
Diego 2024-02-06 15:02:40 +01:00
parent 0317d589ce
commit 07cab432ba
No known key found for this signature in database
GPG Key ID: C9DAC9BF68D1F806
2 changed files with 5 additions and 0 deletions

View File

@ -306,6 +306,7 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, control: ControlMessage) =
g.send(
peer,
RPCMsg(control: some(respControl)), true)
# iwant replies have lower priority
g.send(
peer,
RPCMsg(messages: messages), false)

View File

@ -53,8 +53,11 @@ type
OnEvent* = proc(peer: PubSubPeer, event: PubSubPeerEvent) {.gcsafe, raises: [].}
RpcMessageQueue* = ref object
# Tracks async tasks for sending high-priority peer-published messages.
sendPriorityQueue: Deque[Future[void]]
# Queue for lower-priority messages, like "IWANT" replies and relay messages.
nonPriorityQueue: AsyncQueue[seq[byte]]
# Task for processing non-priority message queue.
sendNonPriorityTask: Future[void]
PubSubPeer* = ref object of RootObj
@ -372,6 +375,7 @@ proc sendNonPriorityTask(p: PubSubPeer) {.async.} =
while p.rpcmessagequeue.sendPriorityQueue.len > 0:
await p.rpcmessagequeue.sendPriorityQueue[0]
p.clearSendPriorityQueue()
# we send non-priority messages only if there are no pending priority messages
let msg = await p.rpcmessagequeue.nonPriorityQueue.popFirst()
when defined(libp2p_expensive_metrics):
libp2p_gossipsub_non_priority_queue_size.dec(labelValues = [$p.peerId])