format

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 7 Imported by: 0

README

go-ipld-format

Coverage Status Travis CI

go-ipld-format is a set of interfaces that a type needs to implement in order to be a part of the ipld merkle-forest.

Table of Contents

Install

make install

Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Jeromy Johnson

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("error: batch closed")

ErrClosed is returned when operating on a batch that has already been closed.

View Source
var ErrNotCommited = errors.New("error: batch not commited")

ErrNotCommited is returned when closing a batch that hasn't been successfully committed.

View Source
var ErrNotFound = fmt.Errorf("merkledag: not found")
View Source
var ParallelBatchCommits = runtime.NumCPU() * 2

ParallelBatchCommits is the number of batch commits that can be in-flight before blocking. TODO(ipfs/go-ipfs#4299): Experiment with multiple datastores, storage devices, and CPUs to find the right value/formula.

Functions

func Copy added in v0.6.0

func Copy(ctx context.Context, from, to DAGService, root cid.Cid) error

func Register added in v0.5.0

func Register(codec uint64, decoder DecodeBlockFunc)

Register registers block decoders with the default BlockDecoder.

Types

type Batch added in v0.5.3

type Batch struct {
	MaxSize  int
	MaxNodes int
	// contains filtered or unexported fields
}

Batch is a buffer for batching adds to a dag.

func NewBatch added in v0.5.3

func NewBatch(ctx context.Context, ds DAGService) *Batch

NewBatch returns a node buffer (Batch) that buffers nodes internally and commits them to the underlying DAGService in batches. Use this if you intend to add or remove a lot of nodes all at once.

If the passed context is canceled, any in-progress commits are aborted.

func (*Batch) Add added in v0.5.3

func (t *Batch) Add(nd Node) error

Add adds a node to the batch and commits the batch if necessary.

func (*Batch) Commit added in v0.5.3

func (t *Batch) Commit() error

Commit commits batched nodes.

type BlockDecoder added in v0.4.8

type BlockDecoder interface {
	Register(codec uint64, decoder DecodeBlockFunc)
	Decode(blocks.Block) (Node, error)
}
var DefaultBlockDecoder BlockDecoder = &safeBlockDecoder{decoders: make(map[uint64]DecodeBlockFunc)}

type DAGService added in v0.5.3

type DAGService interface {
	NodeGetter

	// Add adds a node to this DAG.
	Add(context.Context, Node) error

	// Remove removes a node from this DAG.
	//
	// Remove returns no error if the requested node is not present in this DAG.
	Remove(context.Context, cid.Cid) error

	// AddMany adds many nodes to this DAG.
	//
	// Consider using NewBatch instead of calling this directly if you need
	// to add an unbounded number of nodes to avoid buffering too much.
	AddMany(context.Context, []Node) error

	// RemoveMany removes many nodes from this DAG.
	//
	// It returns success even if the nodes were not present in the DAG.
	RemoveMany(context.Context, []cid.Cid) error
}

DAGService is an IPFS Merkle DAG service.

type DecodeBlockFunc added in v0.4.8

type DecodeBlockFunc func(block blocks.Block) (Node, error)

DecodeBlockFunc functions decode blocks into nodes.

type Link struct {
	// utf string name. should be unique per object
	Name string // utf8

	// cumulative size of target object
	Size uint64

	// multihash of the target object
	Cid cid.Cid
}

Link represents an IPFS Merkle DAG Link between Nodes.

func GetLinks(ctx context.Context, ng NodeGetter, c cid.Cid) ([]*Link, error)

GetLinks returns the CIDs of the children of the given node. Prefer this method over looking up the node itself and calling `Links()` on it as this method may be able to use a link cache.

func MakeLink(n Node) (*Link, error)

MakeLink creates a link to the given node

func (*Link) GetNode

func (l *Link) GetNode(ctx context.Context, serv NodeGetter) (Node, error)

GetNode returns the MDAG Node that this link points to

type LinkGetter added in v0.5.3

type LinkGetter interface {
	NodeGetter

	// GetLinks returns the children of the node refered to by the given
	// CID.
	GetLinks(ctx context.Context, nd cid.Cid) ([]*Link, error)
}

NodeGetters can optionally implement this interface to make finding linked objects faster.

type Node

type Node interface {
	blocks.Block
	Resolver

	// ResolveLink is a helper function that calls resolve and asserts the
	// output is a link
	ResolveLink(path []string) (*Link, []string, error)

	// Copy returns a deep copy of this node
	Copy() Node

	// Links is a helper function that returns all links within this object
	Links() []*Link

	// TODO: not sure if stat deserves to stay
	Stat() (*NodeStat, error)

	// Size returns the size in bytes of the serialized object
	Size() (uint64, error)
}

Node is the base interface all IPLD nodes must implement.

Nodes are **Immutable** and all methods defined on the interface are **Thread Safe**.

func Decode added in v0.4.8

func Decode(block blocks.Block) (Node, error)

Decode decodes the given block using the default BlockDecoder.

type NodeGetter

type NodeGetter interface {
	// Get retrieves nodes by CID. Depending on the NodeGetter
	// implementation, this may involve fetching the Node from a remote
	// machine; consider setting a deadline in the context.
	Get(context.Context, cid.Cid) (Node, error)

	// GetMany returns a channel of NodeOptions given a set of CIDs.
	GetMany(context.Context, []cid.Cid) <-chan *NodeOption
}

The basic Node resolution service.

type NodeOption added in v0.5.3

type NodeOption struct {
	Node Node
	Err  error
}

Either a node or an error.

type NodePromise added in v0.5.3

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

func GetDAG added in v0.5.3

func GetDAG(ctx context.Context, ds NodeGetter, root Node) []*NodePromise

GetDAG will fill out all of the links of the given Node. It returns an array of NodePromise with the linked nodes all in the proper order.

func GetNodes added in v0.5.3

func GetNodes(ctx context.Context, ds NodeGetter, keys []cid.Cid) []*NodePromise

GetNodes returns an array of 'FutureNode' promises, with each corresponding to the key with the same index as the passed in keys

func NewNodePromise added in v0.5.3

func NewNodePromise(ctx context.Context) *NodePromise

NodePromise provides a promise like interface for a dag Node the first call to Get will block until the Node is received from its internal channels, subsequent calls will return the cached node.

Thread Safety: This is multiple-consumer/single-producer safe.

func (*NodePromise) Fail added in v0.5.3

func (np *NodePromise) Fail(err error)

Call this function to fail a promise.

Once a promise has been failed or fulfilled, further attempts to fail it will be silently dropped.

func (*NodePromise) Get added in v0.5.3

func (np *NodePromise) Get(ctx context.Context) (Node, error)

Get the value of this promise.

This function is safe to call concurrently from any number of goroutines.

func (*NodePromise) Send added in v0.5.3

func (np *NodePromise) Send(nd Node)

Fulfill this promise.

Once a promise has been fulfilled or failed, calling this function will panic.

type NodeStat

type NodeStat struct {
	Hash           string
	NumLinks       int // number of links in link table
	BlockSize      int // size of the raw, encoded data
	LinksSize      int // size of the links segment
	DataSize       int // size of the data segment
	CumulativeSize int // cumulative size of object and its references
}

NodeStat is a statistics object for a Node. Mostly sizes.

func (NodeStat) String

func (ns NodeStat) String() string

type Resolver added in v0.4.6

type Resolver interface {
	// Resolve resolves a path through this node, stopping at any link boundary
	// and returning the object found as well as the remaining path to traverse
	Resolve(path []string) (interface{}, []string, error)

	// Tree lists all paths within the object under 'path', and up to the given depth.
	// To list the entire object (similar to `find .`) pass "" and -1
	Tree(path string, depth int) []string
}

Jump to

Keyboard shortcuts

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