Documentation ¶
Index ¶
- Constants
- Variables
- type BlockData
- type ExtensionData
- type ExtensionName
- type GraphExchange
- type IncomingBlockHookActions
- type IncomingRequestHookActions
- type IncomingResponseHookActions
- type LinkAction
- type LinkMetadata
- type LinkMetadataIterator
- type OnBlockSentListener
- type OnIncomingBlockHook
- type OnIncomingRequestHook
- type OnIncomingResponseHook
- type OnNetworkErrorListener
- type OnOutgoingBlockHook
- type OnOutgoingRequestHook
- type OnReceiverNetworkErrorListener
- type OnRequestProcessingListener
- type OnRequestUpdatedHook
- type OnRequestorCancelledListener
- type OnResponseCompletedListener
- type OutgoingBlockHookActions
- type OutgoingRequestHookActions
- type Priority
- type RemoteIncorrectResponseError
- type RemoteMissingBlockErr
- type RequestCancelledErr
- type RequestClientCancelledErr
- type RequestData
- type RequestFailedBusyErr
- type RequestFailedContentNotFoundErr
- type RequestFailedLegalErr
- type RequestFailedUnknownErr
- type RequestID
- type RequestIDContextKey
- type RequestNotFoundErr
- type RequestState
- type RequestStates
- type RequestStats
- type RequestType
- type RequestUpdatedHookActions
- type ResponseData
- type ResponseProgress
- type ResponseStats
- type ResponseStatusCode
- type Stats
- type UnregisterHookFunc
Constants ¶
const ( // ExtensionDoNotSendCIDs tells the responding peer not to send certain blocks if they // are encountered in a traversal and is documented at // https://github.com/ipld/specs/blob/master/block-layer/graphsync/known_extensions.md ExtensionDoNotSendCIDs = ExtensionName("graphsync/do-not-send-cids") // ExtensionsDoNotSendFirstBlocks tells the responding peer not to wait till the given // number of blocks have been traversed before it begins to send blocks over the wire ExtensionsDoNotSendFirstBlocks = ExtensionName("graphsync/do-not-send-first-blocks") // ExtensionDeDupByKey tells the responding peer to only deduplicate block sending // for requests that have the same key. The data for the extension is a string key ExtensionDeDupByKey = ExtensionName("graphsync/dedup-by-key") )
const ( // RequestTypeNew means a new request RequestTypeNew = RequestType("New") // RequestTypeCancel means cancel the request referenced by request ID RequestTypeCancel = RequestType("Cancel") // RequestTypeUpdate means the extensions contain an update about this request RequestTypeUpdate = RequestType("Update") )
const ( // LinkActionPresent means the linked block was present on this machine, and // is included a this message LinkActionPresent = LinkAction("Present") // LinkActionDuplicateNotSent means the linked block was present on this machine, // but I am not sending it (most likely duplicate) LinkActionDuplicateNotSent = LinkAction("DuplicateNotSent") // LinkActionMissing means I did not have the linked block, so I skipped over // this part of the traversal LinkActionMissing = LinkAction("Missing") // LinkActionDuplicateDAGSkipped means the DAG with this link points toward has already // been traversed entirely in the course of this request so I am skipping over it LinkActionDuplicateDAGSkipped = LinkAction("DuplicateDAGSkipped") )
const ( // RequestAcknowledged means the request was received and is being worked on. RequestAcknowledged = ResponseStatusCode(10) // AdditionalPeers means additional peers were found that may be able // to satisfy the request and contained in the extra block of the response. AdditionalPeers = ResponseStatusCode(11) // NotEnoughGas means fulfilling this request requires payment. NotEnoughGas = ResponseStatusCode(12) // OtherProtocol means a different type of response than GraphSync is // contained in extra. OtherProtocol = ResponseStatusCode(13) // PartialResponse may include blocks and metadata about the in progress response // in extra. PartialResponse = ResponseStatusCode(14) // RequestPaused indicates a request is paused and will not send any more data // until unpaused RequestPaused = ResponseStatusCode(15) // RequestCompletedFull means the entire fulfillment of the GraphSync request // was sent back. RequestCompletedFull = ResponseStatusCode(20) // RequestCompletedPartial means the response is completed, and part of the // GraphSync request was sent back, but not the complete request. RequestCompletedPartial = ResponseStatusCode(21) // RequestRejected means the node did not accept the incoming request. RequestRejected = ResponseStatusCode(30) // RequestFailedBusy means the node is too busy, try again later. Backoff may // be contained in extra. RequestFailedBusy = ResponseStatusCode(31) // RequestFailedUnknown means the request failed for an unspecified reason. May // contain data about why in extra. RequestFailedUnknown = ResponseStatusCode(32) // RequestFailedLegal means the request failed for legal reasons. RequestFailedLegal = ResponseStatusCode(33) // RequestFailedContentNotFound means the respondent does not have the content. RequestFailedContentNotFound = ResponseStatusCode(34) // RequestCancelled means the responder was processing the request but decided to top, for whatever reason RequestCancelled = ResponseStatusCode(35) )
GraphSync Response Status Codes
Variables ¶
var ( // ErrExtensionAlreadyRegistered means a user extension can be registered only once ErrExtensionAlreadyRegistered = errors.New("extension already registered") )
var ResponseCodeToName = map[ResponseStatusCode]string{ RequestAcknowledged: "RequestAcknowledged", AdditionalPeers: "AdditionalPeers", NotEnoughGas: "NotEnoughGas", OtherProtocol: "OtherProtocol", PartialResponse: "PartialResponse", RequestPaused: "RequestPaused", RequestCompletedFull: "RequestCompletedFull", RequestCompletedPartial: "RequestCompletedPartial", RequestRejected: "RequestRejected", RequestFailedBusy: "RequestFailedBusy", RequestFailedUnknown: "RequestFailedUnknown", RequestFailedLegal: "RequestFailedLegal", RequestFailedContentNotFound: "RequestFailedContentNotFound", RequestCancelled: "RequestCancelled", }
Functions ¶
This section is empty.
Types ¶
type BlockData ¶
type BlockData interface { // Link is the link/cid for the block Link() ipld.Link // BlockSize specifies the size of the block BlockSize() uint64 // BlockSize specifies the amount of data actually transmitted over the network BlockSizeOnWire() uint64 // The index of this block in the selector traversal Index() int64 }
BlockData gives information about a block included in a graphsync response
type ExtensionData ¶
type ExtensionData struct { Name ExtensionName Data datamodel.Node }
ExtensionData is a name/data pair for a graphsync extension
type GraphExchange ¶
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) // RegisterPersistenceOption registers an alternate loader/storer combo that can be substituted for the default RegisterPersistenceOption(name string, lsys ipld.LinkSystem) error // UnregisterPersistenceOption unregisters an alternate loader/storer combo UnregisterPersistenceOption(name string) error // RegisterIncomingRequestHook adds a hook that runs when a request is received RegisterIncomingRequestHook(hook OnIncomingRequestHook) UnregisterHookFunc // RegisterIncomingResponseHook adds a hook that runs when a response is received RegisterIncomingResponseHook(OnIncomingResponseHook) UnregisterHookFunc // RegisterIncomingBlockHook adds a hook that runs when a block is received and validated (put in block store) RegisterIncomingBlockHook(OnIncomingBlockHook) UnregisterHookFunc // RegisterOutgoingRequestHook adds a hook that runs immediately prior to sending a new request RegisterOutgoingRequestHook(hook OnOutgoingRequestHook) UnregisterHookFunc // RegisterOutgoingBlockHook adds a hook that runs every time a block is sent from a responder RegisterOutgoingBlockHook(hook OnOutgoingBlockHook) UnregisterHookFunc // RegisterRequestUpdatedHook adds a hook that runs every time an update to a request is received RegisterRequestUpdatedHook(hook OnRequestUpdatedHook) UnregisterHookFunc // RegisterOutgoingRequestProcessingListener adds a listener that gets called when an outgoing request actually begins processing (reaches // the top of the outgoing request queue) RegisterOutgoingRequestProcessingListener(listener OnRequestProcessingListener) UnregisterHookFunc // RegisterOutgoingRequestProcessingListener adds a listener that gets called when an incoming request actually begins processing (reaches // the top of the outgoing request queue) RegisterIncomingRequestProcessingListener(listener OnRequestProcessingListener) UnregisterHookFunc // RegisterCompletedResponseListener adds a listener on the responder for completed responses RegisterCompletedResponseListener(listener OnResponseCompletedListener) UnregisterHookFunc // RegisterRequestorCancelledListener adds a listener on the responder for // responses cancelled by the requestor RegisterRequestorCancelledListener(listener OnRequestorCancelledListener) UnregisterHookFunc // RegisterBlockSentListener adds a listener for when blocks are actually sent over the wire RegisterBlockSentListener(listener OnBlockSentListener) UnregisterHookFunc // RegisterNetworkErrorListener adds a listener for when errors occur sending data over the wire RegisterNetworkErrorListener(listener OnNetworkErrorListener) UnregisterHookFunc // RegisterReceiverNetworkErrorListener adds a listener for when errors occur receiving data over the wire RegisterReceiverNetworkErrorListener(listener OnReceiverNetworkErrorListener) UnregisterHookFunc // Pause pauses an in progress request or response (may take 1 or more blocks to process) Pause(context.Context, RequestID) error // Unpause unpauses a request or response that was paused // Can also send extensions with unpause Unpause(context.Context, RequestID, ...ExtensionData) error // Cancel cancels an in progress request or response Cancel(context.Context, RequestID) error // SendUpdate sends an update for an in progress request or response SendUpdate(context.Context, RequestID, ...ExtensionData) error // Stats produces insight on the current state of a graphsync exchange Stats() Stats }
GraphExchange is a protocol that can exchange IPLD graphs based on a selector
type IncomingBlockHookActions ¶
type IncomingBlockHookActions interface { TerminateWithError(error) UpdateRequestWithExtensions(...ExtensionData) PauseRequest() }
IncomingBlockHookActions are actions that incoming block hook can take to change the execution of a request
type IncomingRequestHookActions ¶
type IncomingRequestHookActions interface { AugmentContext(func(reqCtx context.Context) context.Context) SendExtensionData(ExtensionData) UsePersistenceOption(name string) UseLinkTargetNodePrototypeChooser(traversal.LinkTargetNodePrototypeChooser) TerminateWithError(error) ValidateRequest() PauseResponse() MaxLinks(uint64) }
IncomingRequestHookActions are actions that a request hook can take to change behavior for the response
type IncomingResponseHookActions ¶
type IncomingResponseHookActions interface { TerminateWithError(error) UpdateRequestWithExtensions(...ExtensionData) }
IncomingResponseHookActions are actions that incoming response hook can take to change the execution of a request
type LinkAction ¶
type LinkAction string
LinkAction is a code that is used by message metadata to communicate the state and reason for blocks being included or not in a transfer
func (LinkAction) DidFollowLink ¶
func (l LinkAction) DidFollowLink() bool
DidFollowLink indicates whether the remote actually loaded the block and followed it in its selector traversal
type LinkMetadata ¶
type LinkMetadata interface { // Length returns the number of metadata entries Length() int64 // Iterate steps over individual metadata one by one using the provided // callback Iterate(LinkMetadataIterator) }
LinkMetadata is used to access link metadata through an Iterator
type LinkMetadataIterator ¶
type LinkMetadataIterator func(cid.Cid, LinkAction)
LinkMetadataIterator is used to access individual link metadata through a LinkMetadata object
type OnBlockSentListener ¶
type OnBlockSentListener func(p peer.ID, request RequestData, block BlockData)
OnBlockSentListener runs when a block is sent over the wire
type OnIncomingBlockHook ¶
type OnIncomingBlockHook func(p peer.ID, responseData ResponseData, blockData BlockData, hookActions IncomingBlockHookActions)
OnIncomingBlockHook is a hook that runs each time a new block is validated as part of the response, regardless of whether it came locally or over the network It receives that sent the response, the most recent response, a link for the block received, and the size of the block received The difference between BlockSize & BlockSizeOnWire can be used to determine where the block came from (Local vs remote) It receives an interface for customizing how we handle the ongoing execution of the request
type OnIncomingRequestHook ¶
type OnIncomingRequestHook func(p peer.ID, request RequestData, hookActions IncomingRequestHookActions)
OnIncomingRequestHook is a hook that runs each time a new request is received. It receives the peer that sent the request and all data about the request. It receives an interface for customizing the response to this request
type OnIncomingResponseHook ¶
type OnIncomingResponseHook func(p peer.ID, responseData ResponseData, hookActions IncomingResponseHookActions)
OnIncomingResponseHook is a hook that runs each time a new response is received. It receives the peer that sent the response and all data about the response. It receives an interface for customizing how we handle the ongoing execution of the request
type OnNetworkErrorListener ¶
type OnNetworkErrorListener func(p peer.ID, request RequestData, err error)
OnNetworkErrorListener runs when queued data is not able to be sent
type OnOutgoingBlockHook ¶
type OnOutgoingBlockHook func(p peer.ID, request RequestData, block BlockData, hookActions OutgoingBlockHookActions)
OnOutgoingBlockHook is a hook that runs immediately after a requestor sends a new block on a response It receives the peer we're sending a request to, all the data aobut the request, a link for the block sent, and the size of the block sent It receives an interface for taking further action on the response
type OnOutgoingRequestHook ¶
type OnOutgoingRequestHook func(p peer.ID, request RequestData, hookActions OutgoingRequestHookActions)
OnOutgoingRequestHook is a hook that runs immediately prior to sending a request It receives the peer we're sending a request to and all the data aobut the request It receives an interface for customizing how we handle executing this request
type OnReceiverNetworkErrorListener ¶
OnReceiverNetworkErrorListener runs when errors occur receiving data over the wire
type OnRequestProcessingListener ¶
type OnRequestProcessingListener func(p peer.ID, request RequestData, inProgressRequestCount int)
OnRequestProcessingListener is called when a request actually begins processing (reaches the top of the request queue)
type OnRequestUpdatedHook ¶
type OnRequestUpdatedHook func(p peer.ID, request RequestData, updateRequest RequestData, hookActions RequestUpdatedHookActions)
OnRequestUpdatedHook is a hook that runs when an update to a request is received It receives the peer we're sending to, the original request, the request update It receives an interface to taking further action on the response
type OnRequestorCancelledListener ¶
type OnRequestorCancelledListener func(p peer.ID, request RequestData)
OnRequestorCancelledListener provides a way to listen for responses the requestor canncels
type OnResponseCompletedListener ¶
type OnResponseCompletedListener func(p peer.ID, request RequestData, status ResponseStatusCode)
OnResponseCompletedListener provides a way to listen for when responder has finished serving a response
type OutgoingBlockHookActions ¶
type OutgoingBlockHookActions interface { SendExtensionData(ExtensionData) TerminateWithError(error) PauseResponse() }
OutgoingBlockHookActions are actions that an outgoing block hook can take to change the execution of a request
type OutgoingRequestHookActions ¶
type OutgoingRequestHookActions interface { UsePersistenceOption(name string) UseLinkTargetNodePrototypeChooser(traversal.LinkTargetNodePrototypeChooser) MaxLinks(uint64) }
OutgoingRequestHookActions are actions that an outgoing request hook can take to change the execution of a request
type RemoteIncorrectResponseError ¶
type RemoteIncorrectResponseError struct { LocalLink ipld.Link RemoteLink ipld.Link Path ipld.Path }
RemoteIncorrectResponseError indicates that the remote peer sent a response to a traversal that did not correspond with the expected next link in the selector traversal based on verification of data up to this point
func (RemoteIncorrectResponseError) Error ¶
func (e RemoteIncorrectResponseError) Error() string
type RemoteMissingBlockErr ¶
type RemoteMissingBlockErr struct { Link ipld.Link Path ipld.Path }
RemoteMissingBlockErr indicates that the remote peer was missing a block in the selector requested, and we also don't have it locally. It is a -terminal error in the error stream for a request and does NOT cause a request to fail completely
func (RemoteMissingBlockErr) Error ¶
func (e RemoteMissingBlockErr) Error() string
type RequestCancelledErr ¶
type RequestCancelledErr struct{}
RequestCancelledErr is an error message received on the error channel that indicates the responder cancelled a request
func (RequestCancelledErr) Error ¶
func (e RequestCancelledErr) Error() string
type RequestClientCancelledErr ¶
type RequestClientCancelledErr struct{}
RequestClientCancelledErr is an error message received on the error channel when the request is cancelled on by the client code, either by closing the passed request context or calling CancelRequest
func (RequestClientCancelledErr) Error ¶
func (e RequestClientCancelledErr) Error() string
type RequestData ¶
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() ipld.Node // 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) (datamodel.Node, bool) // IsCancel returns true if this particular request is being cancelled Type() RequestType }
RequestData describes a received graphsync request.
type RequestFailedBusyErr ¶
type RequestFailedBusyErr struct{}
RequestFailedBusyErr is an error message received on the error channel when the peer is busy
func (RequestFailedBusyErr) Error ¶
func (e RequestFailedBusyErr) Error() string
type RequestFailedContentNotFoundErr ¶
type RequestFailedContentNotFoundErr struct{}
RequestFailedContentNotFoundErr is an error message received on the error channel when the content is not found
func (RequestFailedContentNotFoundErr) Error ¶
func (e RequestFailedContentNotFoundErr) Error() string
type RequestFailedLegalErr ¶
type RequestFailedLegalErr struct{}
RequestFailedLegalErr is an error message received on the error channel when the request fails for legal reasons
func (RequestFailedLegalErr) Error ¶
func (e RequestFailedLegalErr) Error() string
type RequestFailedUnknownErr ¶
type RequestFailedUnknownErr struct{}
RequestFailedUnknownErr is an error message received on the error channel when the request fails for unknown reasons
func (RequestFailedUnknownErr) Error ¶
func (e RequestFailedUnknownErr) Error() string
type RequestID ¶
type RequestID struct {
// contains filtered or unexported fields
}
RequestID is a unique identifier for a GraphSync request.
func NewRequestID ¶
func NewRequestID() RequestID
Create a new, random RequestID (should be a UUIDv4)
func ParseRequestID ¶
Create a RequestID from a byte slice
type RequestIDContextKey ¶
type RequestIDContextKey struct{}
RequestIDContextKey is used to the desired request id in context when initializing a request
type RequestNotFoundErr ¶
type RequestNotFoundErr struct{}
RequestNotFoundErr indicates that a request with a particular request ID was not found
func (RequestNotFoundErr) Error ¶
func (e RequestNotFoundErr) Error() string
type RequestState ¶
type RequestState uint64
RequestState describes the current general state of a request
const ( // Queued means a request has been received and is queued for processing Queued RequestState = iota // Running means a request is actively sending or receiving data Running // Paused means a request is paused Paused // CompletingSend means we have processed a query and are waiting for data to // go over the network CompletingSend )
func (RequestState) String ¶
func (rs RequestState) String() string
type RequestStates ¶
type RequestStates map[RequestID]RequestState
RequestStates describe a set of request IDs and their current state
type RequestStats ¶
type RequestStats struct { // TotalPeers is the number of peers that have active or pending requests TotalPeers uint64 // Active is the total number of active requests being processing Active uint64 // Pending is the total number of requests that are waiting to be processed Pending uint64 }
RequestStats offer statistics about request processing
type RequestType ¶
type RequestType string
type RequestUpdatedHookActions ¶
type RequestUpdatedHookActions interface { TerminateWithError(error) SendExtensionData(ExtensionData) UnpauseResponse() }
RequestUpdatedHookActions are actions that can be taken in a request updated hook to change execution of the response
type ResponseData ¶
type ResponseData interface { // RequestID returns the request ID for this response RequestID() RequestID // Status returns the status for a response Status() ResponseStatusCode // Extension returns the content for an extension on a response, or errors // if extension is not present Extension(name ExtensionName) (datamodel.Node, bool) // Metadata returns a copy of the link metadata contained in this response Metadata() LinkMetadata }
ResponseData describes a received Graphsync response
type ResponseProgress ¶
type ResponseProgress struct { Node ipld.Node // a node which matched the graphsync query Path ipld.Path // the path of that node relative to the traversal start LastBlock struct { Path ipld.Path Link ipld.Link } }
ResponseProgress is the fundamental unit of responses making progress in Graphsync.
type ResponseStats ¶
type ResponseStats struct { // MaxAllowedAllocatedTotal is the preconfigured limit on allocations // for all peers MaxAllowedAllocatedTotal uint64 // MaxAllowedAllocatedPerPeer is the preconfigured limit on allocations // for an individual peer MaxAllowedAllocatedPerPeer uint64 // TotalAllocatedAllPeers indicates the amount of memory allocated for blocks // across all peers TotalAllocatedAllPeers uint64 // TotalPendingAllocations indicates the amount awaiting freeing up of memory TotalPendingAllocations uint64 // NumPeersWithPendingAllocations indicates the number of peers that // have either maxed out their individual memory allocations or have // pending allocations cause the total limit has been reached. NumPeersWithPendingAllocations uint64 }
ResponseStats offer statistics about memory allocations for responses
type ResponseStatusCode ¶
type ResponseStatusCode int32
ResponseStatusCode is a status returned for a GraphSync Request.
func (ResponseStatusCode) AsError ¶
func (c ResponseStatusCode) AsError() error
AsError generates an error from the status code for a failing status
func (ResponseStatusCode) IsFailure ¶
func (c ResponseStatusCode) IsFailure() bool
IsFailure returns true if the response code indicates the request terminated in failure.
func (ResponseStatusCode) IsSuccess ¶
func (c ResponseStatusCode) IsSuccess() bool
IsSuccess returns true if the response code indicates the request terminated successfully.
func (ResponseStatusCode) IsTerminal ¶
func (c ResponseStatusCode) IsTerminal() bool
IsTerminal returns true if the response code signals the end of the request
func (ResponseStatusCode) String ¶
func (c ResponseStatusCode) String() string
type Stats ¶
type Stats struct { // Stats for the graphsync requestor OutgoingRequests RequestStats IncomingResponses ResponseStats // Stats for the graphsync responder IncomingRequests RequestStats OutgoingResponses ResponseStats }
Stats describes statistics about the Graphsync implementations current state
type UnregisterHookFunc ¶
type UnregisterHookFunc func()
UnregisterHookFunc is a function call to unregister a hook that was previously registered
Directories ¶
Path | Synopsis |
---|---|
reconciledloader
Package reconciledloader implements a block loader that can load from two different sources: - a local store - a series of remote responses for a given graphsync selector query
|
Package reconciledloader implements a block loader that can load from two different sources: - a local store - a series of remote responses for a given graphsync selector query |
responseassembler
Package responseassembler assembles responses that are queued for sending in outgoing messages
|
Package responseassembler assembles responses that are queued for sending in outgoing messages |