-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(graphsync): add incoming block hook types add types (not implemented) for incoming block hook * feat(asyncloader): identify local loads add a boolean value to AsyncLoadResult to determine if a request load was local * fixup! feat(graphsync): add incoming block hook types * feat(hooks): add block hooks plumbing * feat(requestmanager): process block hooks Process block hooks on each block, and connect last response to blocks * feat(peerresponsemanager): add transactions add the ability to do multple response operations with a gaurantee they will end up in a single response * refactor(lint): fix lint errors
- Loading branch information
1 parent
9d5f2c2
commit 430b4dc
Showing
20 changed files
with
1,112 additions
and
434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package hooks | ||
|
||
import ( | ||
"github.com/hannahhoward/go-pubsub" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
|
||
"github.com/ipfs/go-graphsync" | ||
) | ||
|
||
// IncomingBlockHooks is a set of incoming block hooks that can be processed | ||
type IncomingBlockHooks struct { | ||
pubSub *pubsub.PubSub | ||
} | ||
|
||
type internalBlockHookEvent struct { | ||
p peer.ID | ||
response graphsync.ResponseData | ||
block graphsync.BlockData | ||
rha *updateHookActions | ||
} | ||
|
||
func blockHookDispatcher(event pubsub.Event, subscriberFn pubsub.SubscriberFn) error { | ||
ie := event.(internalBlockHookEvent) | ||
hook := subscriberFn.(graphsync.OnIncomingBlockHook) | ||
hook(ie.p, ie.response, ie.block, ie.rha) | ||
return ie.rha.err | ||
} | ||
|
||
// NewBlockHooks returns a new list of incoming request hooks | ||
func NewBlockHooks() *IncomingBlockHooks { | ||
return &IncomingBlockHooks{pubSub: pubsub.New(blockHookDispatcher)} | ||
} | ||
|
||
// Register registers an extension to process incoming responses | ||
func (ibh *IncomingBlockHooks) Register(hook graphsync.OnIncomingBlockHook) graphsync.UnregisterHookFunc { | ||
return graphsync.UnregisterHookFunc(ibh.pubSub.Subscribe(hook)) | ||
} | ||
|
||
// ProcessBlockHooks runs response hooks against an incoming response | ||
func (ibh *IncomingBlockHooks) ProcessBlockHooks(p peer.ID, response graphsync.ResponseData, block graphsync.BlockData) UpdateResult { | ||
rha := &updateHookActions{} | ||
_ = ibh.pubSub.Publish(internalBlockHookEvent{p, response, block, rha}) | ||
return rha.result() | ||
} |
Oops, something went wrong.