Skip to content

Commit 8a576e1

Browse files
committed
chore: short-circuit unnecessary message processing
1 parent 6aa14b2 commit 8a576e1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

impl/graphsync.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,17 @@ func (gsr *graphSyncReceiver) ReceiveMessage(
486486
ctx context.Context,
487487
sender peer.ID,
488488
incoming gsmsg.GraphSyncMessage) {
489-
gsr.graphSync().responseManager.ProcessRequests(ctx, sender, incoming.Requests())
490-
gsr.graphSync().requestManager.ProcessResponses(sender, incoming.Responses(), incoming.Blocks())
489+
490+
requests := incoming.Requests()
491+
responses := incoming.Responses()
492+
blocks := incoming.Blocks()
493+
494+
if len(requests) > 0 {
495+
gsr.graphSync().responseManager.ProcessRequests(ctx, sender, requests)
496+
}
497+
if len(responses) > 0 || len(blocks) > 0 {
498+
gsr.graphSync().requestManager.ProcessResponses(sender, responses, blocks)
499+
}
491500
}
492501

493502
// ReceiveError is part of the network's Receiver interface and handles incoming

0 commit comments

Comments
 (0)