-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow custom configuration of transports (#57)
* feat(graphsync): setup alternate stores add a method to allow swapping of an alternate store for a given request * refactor(datatransfer): move all interfaces to top move interfaces to the top level package to avoid circular imports * feat(impl): support transport configurer Support a per voucher type transport configurer to allow custom configuration of a transport * fix(lint): fix lint/mod-tidy * fix(impl): fix integration test
- Loading branch information
1 parent
34b009b
commit 5bb7276
Showing
34 changed files
with
981 additions
and
683 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package datatransfer | ||
|
||
type errorType string | ||
|
||
func (e errorType) Error() string { | ||
return string(e) | ||
} | ||
|
||
// ErrHandlerAlreadySet means an event handler was already set for this instance of | ||
// hooks | ||
const ErrHandlerAlreadySet = errorType("already set event handler") | ||
|
||
// ErrHandlerNotSet means you cannot issue commands to this interface because the | ||
// handler has not been set | ||
const ErrHandlerNotSet = errorType("event handler has not been set") | ||
|
||
// ErrChannelNotFound means the channel this command was issued for does not exist | ||
const ErrChannelNotFound = errorType("channel not found") | ||
|
||
// ErrPause is a special error that the DataReceived / DataSent hooks can | ||
// use to pause the channel | ||
const ErrPause = errorType("pause channel") | ||
|
||
// ErrResume is a special error that the RequestReceived / ResponseReceived hooks can | ||
// use to resume the channel | ||
const ErrResume = errorType("resume channel") |
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,94 @@ | ||
package datatransfer | ||
|
||
import "time" | ||
|
||
// EventCode is a name for an event that occurs on a data transfer channel | ||
type EventCode int | ||
|
||
const ( | ||
// Open is an event occurs when a channel is first opened | ||
Open EventCode = iota | ||
|
||
// Accept is an event that emits when the data transfer is first accepted | ||
Accept | ||
|
||
// Progress is an event that gets emitted every time more data is transferred | ||
Progress | ||
|
||
// Cancel indicates one side has cancelled the transfer | ||
Cancel | ||
|
||
// Error is an event that emits when an error occurs in a data transfer | ||
Error | ||
|
||
// CleanupComplete emits when a request is cleaned up | ||
CleanupComplete | ||
|
||
// NewVoucher means we have a new voucher on this channel | ||
NewVoucher | ||
|
||
// NewVoucherResult means we have a new voucher result on this channel | ||
NewVoucherResult | ||
|
||
// PauseInitiator emits when the data sender pauses transfer | ||
PauseInitiator | ||
|
||
// ResumeInitiator emits when the data sender resumes transfer | ||
ResumeInitiator | ||
|
||
// PauseResponder emits when the data receiver pauses transfer | ||
PauseResponder | ||
|
||
// ResumeResponder emits when the data receiver resumes transfer | ||
ResumeResponder | ||
|
||
// FinishTransfer emits when the initiator has completed sending/receiving data | ||
FinishTransfer | ||
|
||
// ResponderCompletes emits when the initiator receives a message that the responder is finished | ||
ResponderCompletes | ||
|
||
// ResponderBeginsFinalization emits when the initiator receives a message that the responder is finilizing | ||
ResponderBeginsFinalization | ||
|
||
// BeginFinalizing emits when the responder completes its operations but awaits a response from the | ||
// initiator | ||
BeginFinalizing | ||
|
||
// Complete is emitted when a data transfer is complete | ||
Complete | ||
) | ||
|
||
// Events are human readable names for data transfer events | ||
var Events = map[EventCode]string{ | ||
Open: "Open", | ||
Accept: "Accept", | ||
Progress: "Progress", | ||
Cancel: "Cancel", | ||
Error: "Error", | ||
CleanupComplete: "CleanupComplete", | ||
NewVoucher: "NewVoucher", | ||
NewVoucherResult: "NewVoucherResult", | ||
PauseInitiator: "PauseInitiator", | ||
ResumeInitiator: "ResumeInitiator", | ||
PauseResponder: "PauseResponder", | ||
ResumeResponder: "ResumeResponder", | ||
FinishTransfer: "FinishTransfer", | ||
ResponderBeginsFinalization: "ResponderBeginsFinalization", | ||
ResponderCompletes: "ResponderCompletes", | ||
BeginFinalizing: "BeginFinalizing", | ||
Complete: "Complete", | ||
} | ||
|
||
// Event is a struct containing information about a data transfer event | ||
type Event struct { | ||
Code EventCode // What type of event it is | ||
Message string // Any clarifying information about the event | ||
Timestamp time.Time // when the event happened | ||
} | ||
|
||
// Subscriber is a callback that is called when events are emitted | ||
type Subscriber func(event Event, channelState ChannelState) | ||
|
||
// Unsubscribe is a function that gets called to unsubscribe from data transfer events | ||
type Unsubscribe func() |
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
Oops, something went wrong.