Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-graphsync
Commits
35b1c6b1
Commit
35b1c6b1
authored
Apr 18, 2019
by
hannahhoward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(responsecache): improve error message
Improve Error message on missing blocks, and also add missing comments
parent
7050142c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletion
+11
-1
requestmanager/asyncloader/responsecache/responsecache.go
requestmanager/asyncloader/responsecache/responsecache.go
+11
-1
No files found.
requestmanager/asyncloader/responsecache/responsecache.go
View file @
35b1c6b1
...
@@ -17,12 +17,16 @@ type responseCacheMessage interface {
...
@@ -17,12 +17,16 @@ type responseCacheMessage interface {
handle
(
rc
*
ResponseCache
)
handle
(
rc
*
ResponseCache
)
}
}
// UnverifiedBlockStore is an interface for storing blocks
// as they come in and removing them as they are verified
type
UnverifiedBlockStore
interface
{
type
UnverifiedBlockStore
interface
{
PruneBlocks
(
func
(
ipld
.
Link
)
bool
)
PruneBlocks
(
func
(
ipld
.
Link
)
bool
)
VerifyBlock
(
ipld
.
Link
)
([]
byte
,
error
)
VerifyBlock
(
ipld
.
Link
)
([]
byte
,
error
)
AddUnverifiedBlock
(
ipld
.
Link
,
[]
byte
)
AddUnverifiedBlock
(
ipld
.
Link
,
[]
byte
)
}
}
// ResponseCache maintains a store of unverified blocks and response
// data about links for loading, and prunes blocks as needed.
type
ResponseCache
struct
{
type
ResponseCache
struct
{
responseCacheLk
sync
.
RWMutex
responseCacheLk
sync
.
RWMutex
...
@@ -30,6 +34,7 @@ type ResponseCache struct {
...
@@ -30,6 +34,7 @@ type ResponseCache struct {
unverifiedBlockStore
UnverifiedBlockStore
unverifiedBlockStore
UnverifiedBlockStore
}
}
// New initializes a new ResponseCache using the given unverified block store.
func
New
(
unverifiedBlockStore
UnverifiedBlockStore
)
*
ResponseCache
{
func
New
(
unverifiedBlockStore
UnverifiedBlockStore
)
*
ResponseCache
{
return
&
ResponseCache
{
return
&
ResponseCache
{
linkTracker
:
linktracker
.
New
(),
linkTracker
:
linktracker
.
New
(),
...
@@ -37,6 +42,8 @@ func New(unverifiedBlockStore UnverifiedBlockStore) *ResponseCache {
...
@@ -37,6 +42,8 @@ func New(unverifiedBlockStore UnverifiedBlockStore) *ResponseCache {
}
}
}
}
// FinishRequest indicate there is no more need to track blocks tied to this
// response
func
(
rc
*
ResponseCache
)
FinishRequest
(
requestID
gsmsg
.
GraphSyncRequestID
)
{
func
(
rc
*
ResponseCache
)
FinishRequest
(
requestID
gsmsg
.
GraphSyncRequestID
)
{
rc
.
responseCacheLk
.
Lock
()
rc
.
responseCacheLk
.
Lock
()
rc
.
linkTracker
.
FinishRequest
(
requestID
)
rc
.
linkTracker
.
FinishRequest
(
requestID
)
...
@@ -47,16 +54,19 @@ func (rc *ResponseCache) FinishRequest(requestID gsmsg.GraphSyncRequestID) {
...
@@ -47,16 +54,19 @@ func (rc *ResponseCache) FinishRequest(requestID gsmsg.GraphSyncRequestID) {
rc
.
responseCacheLk
.
Unlock
()
rc
.
responseCacheLk
.
Unlock
()
}
}
// AttemptLoad attempts to laod the given block from the cache
func
(
rc
*
ResponseCache
)
AttemptLoad
(
requestID
gsmsg
.
GraphSyncRequestID
,
link
ipld
.
Link
)
([]
byte
,
error
)
{
func
(
rc
*
ResponseCache
)
AttemptLoad
(
requestID
gsmsg
.
GraphSyncRequestID
,
link
ipld
.
Link
)
([]
byte
,
error
)
{
rc
.
responseCacheLk
.
Lock
()
rc
.
responseCacheLk
.
Lock
()
defer
rc
.
responseCacheLk
.
Unlock
()
defer
rc
.
responseCacheLk
.
Unlock
()
if
rc
.
linkTracker
.
IsKnownMissingLink
(
requestID
,
link
)
{
if
rc
.
linkTracker
.
IsKnownMissingLink
(
requestID
,
link
)
{
return
nil
,
fmt
.
Errorf
(
"Remote Peer Is Missing Block
"
)
return
nil
,
fmt
.
Errorf
(
"Remote Peer Is Missing Block
: %s"
,
link
.
String
()
)
}
}
data
,
_
:=
rc
.
unverifiedBlockStore
.
VerifyBlock
(
link
)
data
,
_
:=
rc
.
unverifiedBlockStore
.
VerifyBlock
(
link
)
return
data
,
nil
return
data
,
nil
}
}
// ProcessResponse processes incoming response data, adding unverified blocks,
// and tracking link metadata from a remote peer
func
(
rc
*
ResponseCache
)
ProcessResponse
(
responses
map
[
gsmsg
.
GraphSyncRequestID
]
metadata
.
Metadata
,
func
(
rc
*
ResponseCache
)
ProcessResponse
(
responses
map
[
gsmsg
.
GraphSyncRequestID
]
metadata
.
Metadata
,
blks
[]
blocks
.
Block
)
{
blks
[]
blocks
.
Block
)
{
rc
.
responseCacheLk
.
Lock
()
rc
.
responseCacheLk
.
Lock
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment