Documentation
¶
Overview ¶
package blockservice implements a BlockService interface that provides a single GetBlock/AddBlock interface that seamlessly retrieves data either locally or from a remote peer through the exchange.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("blockservice: key not found")
Functions ¶
This section is empty.
Types ¶
type BlockGetter ¶
type BlockGetter interface {
// GetBlock gets the requested block.
GetBlock(ctx context.Context, w auth.Want) (auth.AuthBlock, error)
// GetBlocks does a batch request for the given cids, returning blocks as
// they are found, in no particular order.
//
// It may not be able to find all requested blocks (or the context may
// be canceled). In that case, it will close the channel early. It is up
// to the consumer to detect this situation and keep track which blocks
// it has received and which it hasn't.
GetBlocks(ctx context.Context, ws []auth.Want) <-chan auth.AuthBlock
}
BlockGetter is the common interface shared between blockservice sessions and the blockservice.
type BlockService ¶
type BlockService interface {
io.Closer
BlockGetter
// Blockstore returns a reference to the underlying blockstore
Blockstore() auth.AuthBlockstore
// Exchange returns a reference to the underlying exchange (usually bitswap)
Exchange() exchange.Interface
// AddBlock puts a given block to the underlying datastore
AddBlock(o auth.AuthBlock) error
// AddBlocks adds a slice of blocks at the same time using batching
// capabilities of the underlying datastore whenever possible.
AddBlocks(bs []auth.AuthBlock) error
// DeleteBlock deletes the given block from the blockservice.
DeleteBlock(o cid.Cid) error
}
BlockService is a hybrid block datastore. It stores data in a local datastore and may retrieve data from a remote Exchange. It uses an internal `datastore.Datastore` instance to store values.
func New ¶
func New(bs auth.AuthBlockstore, rem exchange.Interface, host peer.ID) BlockService
NewBlockService creates a BlockService with given datastore instance.
func NewWriteThrough ¶
func NewWriteThrough(bs auth.AuthBlockstore, rem exchange.Interface) BlockService
NewWriteThrough ceates a BlockService that guarantees writes will go through to the blockstore and are not skipped by cache checks.