blockio

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Overview

Package blockio constains logic for a retrieval provider or client to traverse, read and verify that blocks received are in a dag in the expected traversal order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockReader

type BlockReader interface {
	// ReadBlock reads data from a single block. Data is nil
	// for intermediate nodes
	ReadBlock(context.Context) (retrievalmarket.Block, bool, error)
}

BlockReader is any data struct that can be read block by block

func NewSelectorBlockReader

func NewSelectorBlockReader(root ipld.Link, sel ipld.Node, loader ipld.Loader) BlockReader

NewSelectorBlockReader returns a new Block reader starting at the given root and using the given loader

type BlockVerifier

type BlockVerifier interface {
	Verify(context.Context, blocks.Block) (done bool, err error)
}

BlockVerifier verifies blocks received are part of a dag, in the order the dag is expected to be traversed

func NewSelectorVerifier

func NewSelectorVerifier(root ipld.Link, selector ipld.Node) BlockVerifier

NewSelectorVerifier returns a new selector based block verifier

type SelectorBlockReader

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

SelectorBlockReader reads an ipld data structure in individual blocks allowing the next block to be read and then advancing no further

func (*SelectorBlockReader) ReadBlock

ReadBlock reads the next block in the IPLD traversal

type SelectorVerifier

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

SelectorVerifier verifies a traversal of an IPLD data structure by feeding blocks in in the order they are traversed in a dag walk

func (*SelectorVerifier) Verify

func (sv *SelectorVerifier) Verify(ctx context.Context, blk blocks.Block) (done bool, err error)

Verify verifies that the given block is the next one needed for the current traversal and returns true if the traversal is done

type Traverser

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

Traverser is a class to perform a selector traversal that stops every time a new block is loaded and waits for manual input (in the form of advance or error)

func NewTraverser

func NewTraverser(root ipld.Link, selector ipld.Node) *Traverser

NewTraverser creates a new traverser

func (*Traverser) Advance

func (t *Traverser) Advance(ctx context.Context, reader io.Reader) error

Advance advances the traversal with an io.Reader for the next requested block

func (*Traverser) CurrentRequest

func (t *Traverser) CurrentRequest(ctx context.Context) (ipld.Link, ipld.LinkContext)

CurrentRequest returns the current block load waiting to be fulfilled in order to advance further

func (*Traverser) Error

func (t *Traverser) Error(ctx context.Context, err error)

Error aborts the traversal with an error

func (*Traverser) IsComplete

func (t *Traverser) IsComplete(ctx context.Context) bool

IsComplete returns true if a traversal is complete

func (*Traverser) Start

func (t *Traverser) Start(ctx context.Context)

Start initiates the traversal (run in a go routine because the regular selector traversal expects a call back)

Jump to

Keyboard shortcuts

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