blockstream

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: MIT Imports: 21 Imported by: 0

README

Build Go Report Card License codecov

go-blockstream

Blockstream is an experimental protocol for transporting IPFS blocks from multiple known peers without discovery. Implements Exchange interface.

Documentation

Index

Constants

View Source
const Protocol protocol.ID = "/blockstream/1.0.0"

Variables

View Source
var ErrNoProviders = errors.New("blockstream: no providers")

Functions

func Explore added in v1.2.0

func Explore(ctx context.Context, id cid.Cid, bs Streamer, h Explorer) error

Explore gets first blocks from stream, passes it to handler that may explore new key in block and handles them over until no more left. Once any Result error appears, it returns immediately.

Types

type BlockStream

type BlockStream struct {
	Host    host.Host
	Granter access.Granter
	Blocks  blockstore.Blockstore
	// contains filtered or unexported fields
}

func NewBlockStream

func NewBlockStream(ctx context.Context, host host.Host, bstore blockstore.Blockstore, granter access.Granter, opts ...Option) *BlockStream

func (*BlockStream) Close

func (bs *BlockStream) Close() error

func (*BlockStream) Session

func (bs *BlockStream) Session(ctx context.Context, peers []peer.ID, opts ...SessionOption) (*Session, error)

Session starts new BlockStream session between current node and providing 'peers'.

type Explorer added in v1.2.0

type Explorer func(blocks.Block) ([]cid.Cid, error)

Explorer gets keys from block in a user defined way.

type Option

type Option func(plain *BlockStream)

func Collectors

func Collectors(c int) Option

type Session

type Session struct {
	// contains filtered or unexported fields
}

TODO Refactor this, my ayes hurt watching this

func (*Session) Blocks

func (ses *Session) Blocks(ctx context.Context, ids []cid.Cid) (<-chan block.Result, <-chan error)

Blocks fetches Blocks by their CIDs evenly from the remote providers in the session. Block order is guaranteed to be the same as requested.

func (*Session) Stream

func (ses *Session) Stream(ctx context.Context, in <-chan []cid.Cid) (<-chan block.Result, <-chan error)

Stream starts direct Block fetching from remote providers. It fetches the Blocks requested with 'in' chan by their ids. Stream is automatically stopped when both: the requested blocks are all fetched and 'in' chan is closed. It might be also terminated with the provided context. Block order is guaranteed to be the same as requested through the `in` chan.

type SessionOption added in v1.2.0

type SessionOption func(*sessionOpts)

func Blockstore added in v1.2.0

func Blockstore(bs blockstore.Blockstore) SessionOption

func Offline added in v1.2.0

func Offline(off bool) SessionOption

func Save added in v1.2.0

func Save(s bool) SessionOption

type Streamer added in v1.2.0

type Streamer interface {

	// Stream initiates ordered stream of Blocks from implementation defined source.
	Stream(context.Context, <-chan []cid.Cid) (<-chan block.Result, <-chan error)
}

TODO Interface is not final TODO Implementation distributing requests between multiple streamers by some abstract characteristic.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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