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 ¶
This section is empty.
Functions ¶
func ContextWithSession ¶ added in v0.18.0
func ContextWithSession(ctx context.Context, bs BlockService) context.Context
ContextWithSession is a helper which creates a context with an embded session, future calls to [BlockGetter.GetBlock], [BlockGetter.GetBlocks] and NewSession with the same BlockService will be redirected to this same session instead. Sessions are lazily setup, this is cheap. It wont make a new session if one exists already in the context.
func EmbedSessionInContext ¶ added in v0.18.0
EmbedSessionInContext is like ContextWithSession but it allows to embed an existing session.
Types ¶
type BlockGetter ¶
type BlockGetter interface {
// GetBlock gets the requested block.
GetBlock(ctx context.Context, c cid.Cid) (blocks.Block, 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, ks []cid.Cid) <-chan blocks.Block
}
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() blockstore.Blockstore
// Exchange returns a reference to the underlying exchange (usually bitswap)
Exchange() exchange.Interface
// AddBlock puts a given block to the underlying datastore
AddBlock(ctx context.Context, o blocks.Block) error
// AddBlocks adds a slice of blocks at the same time using batching
// capabilities of the underlying datastore whenever possible.
AddBlocks(ctx context.Context, bs []blocks.Block) error
// DeleteBlock deletes the given block from the blockservice.
DeleteBlock(ctx context.Context, 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 blockstore.Blockstore, exchange exchange.Interface, opts ...Option) BlockService
New creates a BlockService with given datastore instance.
type BoundedBlockService ¶ added in v0.12.0
type BoundedBlockService interface {
BlockService
Allowlist() verifcid.Allowlist
}
BoundedBlockService is a Blockservice bounded via strict multihash Allowlist.
type Option ¶ added in v0.12.0
type Option func(*blockService)
func WithAllowlist ¶ added in v0.12.0
WithAllowlist sets a custom verifcid.Allowlist which will be used
func WriteThrough ¶ added in v0.12.0
WriteThrough disable cache checks for writes and make them go straight to the blockstore, when enabled.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a helper type to provide higher level access to bitswap sessions
func NewSession ¶
func NewSession(ctx context.Context, bs BlockService) *Session
NewSession creates a new session that allows for controlled exchange of wantlists to decrease the bandwidth overhead. If the current exchange is a SessionExchange, a new exchange session will be created. Otherwise, the current exchange will be used directly. Sessions are lazily setup, this is cheap.