retrieve

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoGetters           = errors.New("no Getters configured")
	ErrPartialContents     = errors.New("target is not empty")
	ErrNothingToResume     = errors.New("nothing to resume; target already the correct size, or is empty")
	ErrCantResume          = errors.New("request can't be resumed")
	ErrShortWrite          = errors.New("Getter returned too few bytes")
	ErrLongWrite           = errors.New("Getter returned too many bytes")
	ErrSizeMismatch        = errors.New("the ExpectedSize and the size returned from the verifier differ")
	ErrUndefinedCID        = errors.New("missing/undefined CID")
	ErrInvalidExpectedSize = errors.New("invalid ExpectedSize")
)
View Source
var (
	ErrNoBlockGetters = errors.New("no BlockGetters configured")
	ErrBadBlock       = errors.New("invalid block")
)

Functions

This section is empty.

Types

type BlockGetter

type BlockGetter interface {
	GetBlock(context.Context, cid.Cid) (blocks.Block, error)
}

type Getter

type Getter interface {
	Get(context.Context, cid.Cid, int64) (io.ReadCloser, error)
}

TODO: Document how Get should behave if the target size indicates the payload has been completely received. A nil error is insufficient because this could cause a Get to be wrongly regarded as verified. Perhaps a sentinel error?

type IsTrusteder

type IsTrusteder interface {
	IsTrusted() bool
}

TODO: IsVerifier / IsVerified

type R

type R struct {
	Getters      []Getter
	BlockGetters []BlockGetter
}

func (*R) GetBlock

func (r *R) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block, error)

GetBlock returns the block with CID c it receives from one of the configured [BlockGetter]s. It confirms that the block's reported CID is equal to c, but assumes the BlockGetter has hashed the block.

func (*R) Raw

func (r *R) Raw(c cid.Cid) *Raw

TODO: Require ExpectedSize argument?

type Raw

type Raw struct {
	Getters      []Getter
	CID          cid.Cid
	ExpectedSize int64
	VerifyFn     VerifyFn
	Target       io.WriteSeeker
}

Raw represents a request to fetch, verify, and store a given CID.

func (*Raw) Download

func (raw *Raw) Download(ctx context.Context) (err error)

Download fetches the payload of raw.CID with one or more of raw.Getters. If this payload verifies correctly, and can be written to raw.Target, the method returns nil.

type VerifyFn

type VerifyFn func() (expectedSize int64, err error)

VerifyFn verifies that raw.Target matches raw.CID, and returns the total size raw.Target is expected to be. If verification fails, a non-nil error is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL