Documentation
¶
Index ¶
- Constants
- Variables
- func IsUnknownPeerID(p peer.ID) bool
- func MakeAsyncCandidates(buffer int) (InboundAsyncCandidates, OutboundAsyncCandidates)
- func ParseProtocolsString(v string) ([]multicodec.Code, error)
- func QueryResponseFromReader(r io.Reader) (*retrievaltypes.QueryResponse, error)
- func QueryToWriter(q *retrievaltypes.Query, w io.Writer) error
- func RegisterRetrievalIDToContext(parentCtx context.Context, id RetrievalID) context.Context
- func ToProviderString(ai []Provider) (string, error)
- type CandidateFinder
- type CandidateRetrieval
- type CandidateRetriever
- type CandidateSource
- type EventCode
- type FIL
- type FetchConfig
- type FetchOption
- type Fetcher
- type FindCandidatesResult
- type HasChecker
- type InboundAsyncCandidates
- type OutboundAsyncCandidates
- type Provider
- type ReadableWritableStorage
- type RetrievalCandidate
- type RetrievalEvent
- type RetrievalEventSubscriber
- type RetrievalID
- type RetrievalRequest
- type RetrievalResult
- type RetrievalStats
- type Retriever
Constants ¶
const FilecoinPrecision = uint64(1_000_000_000_000_000_000)
Variables ¶
var ErrIncorrectContextValue = errors.New("context key does not point to a valid retrieval id")
ErrIncorrectContextValue indicates a value for the retrieval id context key that wasn't a retrieval id
var ErrMissingContextKey = errors.New("context key for retrieval is missing")
ErrMissingContextKey indicates no retrieval context key was present for a given context
Functions ¶
func IsUnknownPeerID ¶
func MakeAsyncCandidates ¶
func MakeAsyncCandidates(buffer int) (InboundAsyncCandidates, OutboundAsyncCandidates)
func ParseProtocolsString ¶
func ParseProtocolsString(v string) ([]multicodec.Code, error)
func QueryResponseFromReader ¶
func QueryResponseFromReader(r io.Reader) (*retrievaltypes.QueryResponse, error)
QueryResponseFromReader reads a QueryResponse object in dag-cbor form from a stream
func QueryToWriter ¶
func QueryToWriter(q *retrievaltypes.Query, w io.Writer) error
QueryToWriter writes a Query object in dag-cbor form to a stream
func RegisterRetrievalIDToContext ¶
func RegisterRetrievalIDToContext(parentCtx context.Context, id RetrievalID) context.Context
func ToProviderString ¶
Types ¶
type CandidateFinder ¶
type CandidateFinder interface {
FindCandidates(ctx context.Context, request RetrievalRequest, events func(RetrievalEvent), onCandidates func([]RetrievalCandidate)) error
}
type CandidateRetrieval ¶
type CandidateRetrieval interface {
RetrieveFromAsyncCandidates(asyncCandidates InboundAsyncCandidates) (*RetrievalStats, error)
}
type CandidateRetriever ¶
type CandidateRetriever interface {
Retrieve(ctx context.Context, request RetrievalRequest, events func(RetrievalEvent)) CandidateRetrieval
}
type CandidateSource ¶
type EventCode ¶
type EventCode string
const ( CandidatesFoundCode EventCode = "candidates-found" CandidatesFilteredCode EventCode = "candidates-filtered" StartedCode EventCode = "started" StartedFetchCode EventCode = "started-fetch" StartedFindingCandidatesCode EventCode = "started-finding-candidates" StartedRetrievalCode EventCode = "started-retrieval" ConnectedToProviderCode EventCode = "connected-to-provider" QueryAskedCode EventCode = "query-asked" QueryAskedFilteredCode EventCode = "query-asked-filtered" ProposedCode EventCode = "proposed" AcceptedCode EventCode = "accepted" FirstByteCode EventCode = "first-byte-received" FailedCode EventCode = "failed" FailedRetrievalCode EventCode = "failed-retrieval" SuccessCode EventCode = "success" FinishedCode EventCode = "finished" BlockReceivedCode EventCode = "block-received" )
type FIL ¶
type FIL gostatetypesbig.Int
type FetchConfig ¶
type FetchConfig struct {
EventsCallback func(RetrievalEvent)
}
func NewFetchConfig ¶
func NewFetchConfig(opts ...FetchOption) FetchConfig
NewFetchConfig creates a new FetchConfig with the given options.
type FetchOption ¶
type FetchOption func(cfg *FetchConfig)
func WithEventsCallback ¶
func WithEventsCallback(callback func(RetrievalEvent)) FetchOption
WithEventsCallback sets the callback function for events that occur during the retrieval process. Only one callback can be set per retrieval.
type Fetcher ¶
type Fetcher interface {
Fetch(context.Context, RetrievalRequest, ...FetchOption) (*RetrievalStats, error)
}
type FindCandidatesResult ¶
type FindCandidatesResult struct {
Candidate RetrievalCandidate
Err error
}
type HasChecker ¶ added in v1.0.0
HasChecker is an optional interface for checking if a block exists in storage without reading it. Used to avoid redundant fetches in per-block mode.
type InboundAsyncCandidates ¶
type InboundAsyncCandidates <-chan []RetrievalCandidate
func (InboundAsyncCandidates) Next ¶
func (ias InboundAsyncCandidates) Next(ctx context.Context) (bool, []RetrievalCandidate, error)
type OutboundAsyncCandidates ¶
type OutboundAsyncCandidates chan<- []RetrievalCandidate
func (OutboundAsyncCandidates) SendNext ¶
func (oas OutboundAsyncCandidates) SendNext(ctx context.Context, next []RetrievalCandidate) error
type Provider ¶
func ParseProviderStrings ¶
type ReadableWritableStorage ¶
type ReadableWritableStorage interface {
ipldstorage.ReadableStorage
ipldstorage.WritableStorage
ipldstorage.StreamingReadableStorage
}
type RetrievalCandidate ¶
type RetrievalCandidate struct {
MinerPeer peer.AddrInfo
RootCid cid.Cid
Metadata metadata.Metadata
}
RetrievalCandidate describes a peer and CID combination that can be used to retrieve data from the peer. The RootCid describes the head of an IPLD graph that is being retrieved. The MinerPeer is the peer that is (apparently) storing the data.
The Metadata field contains information about the protocols supported by the peer that may be used to further refine how the retrieval is performed.
func NewRetrievalCandidate ¶
func NewRetrievalCandidate(pid peer.ID, addrs []multiaddr.Multiaddr, rootCid cid.Cid, protocols ...metadata.Protocol) RetrievalCandidate
NewRetrievalCandidate creates a new RetrievalCandidate with the given parameters.
func (RetrievalCandidate) Endpoint ¶ added in v1.0.0
func (rc RetrievalCandidate) Endpoint() string
Endpoint returns a string representation of the provider's address for logging. Prefers multiaddr format (e.g. /ip4/1.2.3.4/tcp/443/https) over peer ID.
type RetrievalEvent ¶
type RetrievalEvent interface {
fmt.Stringer
// Time returns the time that the event occurred
Time() time.Time
// RetrievalId returns the unique ID for this retrieval
RetrievalId() RetrievalID
// Code returns the type of event this is
Code() EventCode
// RootCid returns the CID being requested
RootCid() cid.Cid
}
type RetrievalEventSubscriber ¶
type RetrievalEventSubscriber func(event RetrievalEvent)
RetrievalEventSubscriber is a function that receives a stream of retrieval events from all retrievals that are in progress. Various different types implement the RetrievalEvent interface and may contain additional information about the event beyond what is available on the RetrievalEvent interface.
type RetrievalID ¶
func NewRetrievalID ¶
func NewRetrievalID() (RetrievalID, error)
func RetrievalIDFromContext ¶
func RetrievalIDFromContext(ctx context.Context) (RetrievalID, error)
func (RetrievalID) MarshalText ¶
func (id RetrievalID) MarshalText() ([]byte, error)
func (RetrievalID) String ¶
func (id RetrievalID) String() string
func (*RetrievalID) UnmarshalText ¶
func (id *RetrievalID) UnmarshalText(data []byte) error
type RetrievalRequest ¶
type RetrievalRequest struct {
trustlessutils.Request
// RetrievalID is a unique identifier for this request.
RetrievalID RetrievalID
// LinkSystem is the destination for the blocks to fetch, it may be
// pre-populated with existing blocks in the DAG, in which case they may
// be used to satisfy the request (except in the case of an HTTP retrieval,
// which will fetch the entire DAG, regardless).
LinkSystem ipld.LinkSystem
// Selector is the IPLD selector to use when fetching the DAG. If nil, the
// Path and Scope will be used to generate a selector.
Selector ipld.Node
// Protocols is an optional list of protocols to use when fetching the DAG.
// If nil, the default protocols will be used.
Protocols []multicodec.Code
// MaxBlocks optionally specifies the maximum number of blocks to fetch.
// If zero, no limit is applied.
MaxBlocks uint64
// Providers optionally specifies a list of peers to use when fetching
// blocks. If nil, the default peer discovery mechanism will be used.
Providers []Provider
}
RetrievalRequest describes the parameters of a request. It is intended to be immutable.
func NewRequestForPath ¶
func NewRequestForPath( store ipldstorage.WritableStorage, rootCid cid.Cid, path string, dagScope trustlessutils.DagScope, byteRange *trustlessutils.ByteRange, ) (RetrievalRequest, error)
NewRequestForPath creates a new RetrievalRequest for the given root CID as the head of the graph to fetch, the path within that graph to fetch, the scope that dictates the depth of fetching withint he graph and the byte range to fetch if intending to fetch part of a large UnixFS file.
The byteRange parameter should be left nil if this is not a request for a partial UnixFS file; and if it is set, the dagScope should be DagScopeEntity.
The LinkSystem is configured to use the provided store for both reading and writing and it is explicitly set to be trusted (i.e. it will not check CIDs match bytes). If the storage is not truested, request.LinkSystem.TrustedStore should be set to false after this call.
func (RetrievalRequest) GetDescriptorString ¶
func (r RetrievalRequest) GetDescriptorString() (string, error)
GetDescriptorString returns a URL and query string-style descriptor string for the request. This is different from GetUrlPath as it is not intended (nor safe) to use as an HTTP request. Instead, this should be used for logging and other descriptive purposes.
If this request uses an explicit Selector rather than a Path, an error will be returned.
func (RetrievalRequest) GetSelector ¶
func (r RetrievalRequest) GetSelector() ipld.Node
GetSelector will safely return a selector for this request. If none has been set, it will generate one for the path & scope.
func (RetrievalRequest) GetSupportedProtocols ¶
func (r RetrievalRequest) GetSupportedProtocols(allSupportedProtocols []multicodec.Code) []multicodec.Code
GetSupportedProtocols will safely return the supported protocols for a specific request. It takes a list of all supported protocols, and -- if the request has protocols, it will return all the request protocols that are in the supported list -- if the request has no protocols, it will return the entire supported protocol list
type RetrievalResult ¶
type RetrievalResult struct {
Stats *RetrievalStats
Err error
}
type RetrievalStats ¶
type Retriever ¶
type Retriever interface {
Retrieve(ctx context.Context, request RetrievalRequest, events func(RetrievalEvent)) (*RetrievalStats, error)
}