Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run response hooks on completed requests #77

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions requestmanager/requestmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ func (crm *cancelRequestMessage) handle(rm *RequestManager) {
}

func (prm *processResponseMessage) handle(rm *RequestManager) {
filteredResponses := rm.filterResponsesForPeer(prm.responses, prm.p)
filteredResponses = rm.processExtensions(filteredResponses, prm.p)
filteredResponses := rm.processExtensions(prm.responses, prm.p)
filteredResponses = rm.filterResponsesForPeer(filteredResponses, prm.p)
rm.updateLastResponses(filteredResponses)
responseMetadata := metadataForResponses(filteredResponses)
rm.asyncLoader.ProcessResponse(responseMetadata, prm.blks)
Expand Down Expand Up @@ -426,7 +426,10 @@ func (rm *RequestManager) processExtensionsForResponse(p peer.ID, response gsmsg
rm.peerHandler.SendRequest(p, updateRequest)
}
if result.Err != nil {
requestStatus := rm.inProgressRequestStatuses[response.RequestID()]
requestStatus, ok := rm.inProgressRequestStatuses[response.RequestID()]
if !ok {
return false
}
responseError := rm.generateResponseErrorFromStatus(graphsync.RequestFailedUnknown)
select {
case requestStatus.networkError <- responseError:
Expand Down
5 changes: 5 additions & 0 deletions requestmanager/requestmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ func TestLocallyFulfilledFirstRequestSucceedsLater(t *testing.T) {
defer cancel()
peers := testutil.GeneratePeers(1)

called := make(chan struct{})
td.responseHooks.Register(func(p peer.ID, response graphsync.ResponseData, hookActions graphsync.IncomingResponseHookActions) {
close(called)
})
returnedResponseChan, returnedErrorChan := td.requestManager.SendRequest(requestCtx, peers[0], td.blockChain.TipLink, td.blockChain.Selector())

rr := readNNetworkRequests(requestCtx, t, td.requestRecordChan, 1)[0]
Expand All @@ -310,6 +314,7 @@ func TestLocallyFulfilledFirstRequestSucceedsLater(t *testing.T) {

td.fal.VerifyNoRemainingData(t, rr.gsr.ID())
testutil.VerifyEmptyErrors(ctx, t, returnedErrorChan)
testutil.AssertDoesReceive(requestCtx, t, called, "response hooks called for response")
}

func TestRequestReturnsMissingBlocks(t *testing.T) {
Expand Down