blockservice

package module
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: AGPL-3.0 Imports: 9 Imported by: 0

README

go-blockservice

a fork of ipfs/go-blockservice optimized for usage with TemporalX.

Modifications

  • WriteThrough and non-WriteThrough blockservice are condensed into the same one. We leverage the underlying blockstore logic to avoid excessive writes to disk, and to determine what we need to announce to the network. Only blocks we do not have previously will be announced to the network
  • Remove ipfs/go-log and use uber-go/zap instead
  • Allow insecure hash functions
    • The point of not allowing insecure hash functions is somewhat useful in public networks, but insecure hash functions are often used within enterprise environments (checksum, short lived cache keys, etc...)

License

All original code is licensed as it is upstream, modifications are licensed under AGPL-v3 and will be marked accordingly

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

View Source
var (
	// ErrNotFound is returned when the blockservice is unable to find the key
	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, 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(o blocks.Block) error

	// AddBlocks adds a slice of blocks at the same time using batching
	// capabilities of the underlying datastore whenever possible.
	AddBlocks(bs []blocks.Block) 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

New creates a BlockService with given datastore instance.

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, logger *zap.Logger) *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.

func (*Session) GetBlock

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

GetBlock gets a block in the context of a request session

func (*Session) GetBlocks

func (s *Session) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blocks.Block

GetBlocks gets blocks in the context of a request session

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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