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
d4193eda
Commit
d4193eda
authored
Nov 08, 2019
by
hannahhoward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(graphsync): define extensions interface
define types and mock implementation for supporting extensions
parent
5084f006
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
graphsync.go
graphsync.go
+36
-0
impl/graphsync.go
impl/graphsync.go
+8
-0
No files found.
graphsync.go
View file @
d4193eda
...
...
@@ -3,6 +3,7 @@ package graphsync
import
(
"context"
"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime"
peer
"github.com/libp2p/go-libp2p-peer"
)
...
...
@@ -92,8 +93,43 @@ type ResponseProgress struct {
}
}
// RequestData describes a received graphsync request.
type
RequestData
interface
{
// ID Returns the request ID for this Request
ID
()
RequestID
// Root returns the CID to the root block of this request
Root
()
cid
.
Cid
// Selector returns the byte representation of the selector for this request
Selector
()
[]
byte
// Priority returns the priority of this request
Priority
()
Priority
// Extension returns the content for an extension on a response, or errors
// if extension is not present
Extension
(
name
ExtensionName
)
([]
byte
,
bool
)
// IsCancel returns true if this particular request is being cancelled
IsCancel
()
bool
}
// OnRequestReceivedHook is a hook that runs each time a request is received.
// It receives the peer that sent the request and all data about the request.
// It should return:
// extensionData - any extension data to add to the outgoing response
// err - error - if not nil, halt request and return RequestRejected with the responseData
type
OnRequestReceivedHook
func
(
p
peer
.
ID
,
request
RequestData
)
(
extensionData
[]
ExtensionData
,
err
error
)
// GraphExchange is a protocol that can exchange IPLD graphs based on a selector
type
GraphExchange
interface
{
// Request initiates a new GraphSync request to the given peer using the given selector spec.
Request
(
ctx
context
.
Context
,
p
peer
.
ID
,
root
ipld
.
Link
,
selector
ipld
.
Node
,
extensions
...
ExtensionData
)
(
<-
chan
ResponseProgress
,
<-
chan
error
)
// RegisterRequestReceivedHook adds a hook that runs when a request is received
// If overrideDefaultValidation is set to true, then if the hook does not error,
// it is considered to have "validated" the request -- and that validation supersedes
// the normal validation of requests Graphsync does (i.e. all selectors can be accepted)
RegisterRequestReceivedHook
(
overrideDefaultValidation
bool
,
hook
OnRequestReceivedHook
)
error
}
impl/graphsync.go
View file @
d4193eda
...
...
@@ -86,6 +86,14 @@ func (gs *GraphSync) Request(ctx context.Context, p peer.ID, root ipld.Link, sel
return
gs
.
requestManager
.
SendRequest
(
ctx
,
p
,
root
,
selector
,
extensions
...
)
}
// RegisterRequestReceivedHook adds a hook that runs when a request is received
// If overrideDefaultValidation is set to true, then if the hook does not error,
// it is considered to have "validated" the request -- and that validation supersedes
// the normal validation of requests Graphsync does (i.e. all selectors can be accepted)
func
(
gs
*
GraphSync
)
RegisterRequestReceivedHook
(
overrideDefaultValidation
bool
,
hook
graphsync
.
OnRequestReceivedHook
)
error
{
return
nil
}
type
graphSyncReceiver
GraphSync
func
(
gsr
*
graphSyncReceiver
)
graphSync
()
*
GraphSync
{
...
...
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