merkledag

package
v0.4.5-pre2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

package merkledag implements the IPFS Merkle DAG datastructures.

Index

Constants

This section is empty.

Variables

View Source
var ErrLinkNotFound = fmt.Errorf("no link by that name")
View Source
var ErrNotFound = fmt.Errorf("merkledag: not found")
View Source
var ErrNotProtobuf = fmt.Errorf("expected protobuf dag node")
View Source
var FetchGraphConcurrency = 8

FetchGraphConcurrency is total number of concurrent fetches that 'fetchNodes' will start at a time

Functions

func EnumerateChildren added in v0.4.0

func EnumerateChildren(ctx context.Context, ds LinkService, root *cid.Cid, visit func(*cid.Cid) bool, bestEffort bool) error

EnumerateChildren will walk the dag below the given root node and add all unseen children to the passed in set. TODO: parallelize to avoid disk latency perf hits?

func EnumerateChildrenAsync added in v0.4.0

func EnumerateChildrenAsync(ctx context.Context, ds DAGService, c *cid.Cid, visit func(*cid.Cid) bool) error

func FetchGraph

func FetchGraph(ctx context.Context, c *cid.Cid, serv DAGService) error

FetchGraph fetches all nodes that are children of the given node

func FindLinks(links []*cid.Cid, c *cid.Cid, start int) []int

FindLinks searches this nodes links for the given key, returns the indexes of any links pointing to it

func NewDAGService

func NewDAGService(bs bserv.BlockService) *dagService

Types

type Batch added in v0.3.6

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

func (*Batch) Add added in v0.3.6

func (t *Batch) Add(nd node.Node) (*cid.Cid, error)

func (*Batch) Commit added in v0.3.6

func (t *Batch) Commit() error

type DAGService

type DAGService interface {
	Add(node.Node) (*cid.Cid, error)
	Get(context.Context, *cid.Cid) (node.Node, error)
	Remove(node.Node) error

	// GetDAG returns, in order, all the single leve child
	// nodes of the passed in node.
	GetMany(context.Context, []*cid.Cid) <-chan *NodeOption

	Batch() *Batch

	LinkService
}

DAGService is an IPFS Merkle DAG service.

type LinkService added in v0.4.5

type LinkService interface {
	// Return all links for a node, may be more effect than
	// calling Get in DAGService
	GetLinks(context.Context, *cid.Cid) ([]*node.Link, error)

	GetOfflineLinkService() LinkService
}

type LinkSlice

type LinkSlice []*node.Link

func (LinkSlice) Len

func (ls LinkSlice) Len() int

func (LinkSlice) Less

func (ls LinkSlice) Less(a, b int) bool

func (LinkSlice) Swap

func (ls LinkSlice) Swap(a, b int)

type NodeGetter

type NodeGetter interface {
	Get(context.Context) (node.Node, error)
	Fail(err error)
	Send(node.Node)
}

NodeGetter 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.

func GetDAG added in v0.4.0

func GetDAG(ctx context.Context, ds DAGService, root node.Node) []NodeGetter

GetDAG will fill out all of the links of the given Node. It returns a channel of nodes, which the caller can receive all the child nodes of 'root' on, in proper order.

func GetNodes added in v0.4.0

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

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

type NodeOption added in v0.4.0

type NodeOption struct {
	Node node.Node
	Err  error
}

type ProtoNode added in v0.4.5

type ProtoNode struct {

	// Prefix specifies cid version and hashing function
	Prefix cid.Prefix
	// contains filtered or unexported fields
}

Node represents a node in the IPFS Merkle DAG. nodes have opaque data and a set of navigable links.

func DecodeProtobuf added in v0.4.0

func DecodeProtobuf(encoded []byte) (*ProtoNode, error)

Decoded decodes raw data and returns a new Node instance.

func NodeWithData added in v0.4.3

func NodeWithData(d []byte) *ProtoNode
func (n *ProtoNode) AddNodeLink(name string, that node.Node) error

AddNodeLink adds a link to another node.

func (*ProtoNode) AddNodeLinkClean added in v0.4.5

func (n *ProtoNode) AddNodeLinkClean(name string, that node.Node) error

AddNodeLinkClean adds a link to another node. without keeping a reference to the child node

func (n *ProtoNode) AddRawLink(name string, l *node.Link) error

AddRawLink adds a copy of a link to this node

func (*ProtoNode) Cid added in v0.4.5

func (n *ProtoNode) Cid() *cid.Cid

func (*ProtoNode) Copy added in v0.4.5

func (n *ProtoNode) Copy() node.Node

Copy returns a copy of the node. NOTE: Does not make copies of Node objects in the links.

func (*ProtoNode) Data added in v0.4.5

func (n *ProtoNode) Data() []byte

func (*ProtoNode) EncodeProtobuf added in v0.4.5

func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error)

EncodeProtobuf returns the encoded raw data version of a Node instance. It may use a cached encoded version, unless the force flag is given.

func (*ProtoNode) GetLinkedNode added in v0.4.5

func (n *ProtoNode) GetLinkedNode(ctx context.Context, ds DAGService, name string) (node.Node, error)

func (*ProtoNode) GetLinkedProtoNode added in v0.4.5

func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds DAGService, name string) (*ProtoNode, error)
func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error)

Return a copy of the link with given name

func (n *ProtoNode) Links() []*node.Link

func (*ProtoNode) Loggable added in v0.4.5

func (n *ProtoNode) Loggable() map[string]interface{}

func (*ProtoNode) Marshal added in v0.4.5

func (n *ProtoNode) Marshal() ([]byte, error)

Marshal encodes a *Node instance into a new byte slice. The conversion uses an intermediate PBNode.

func (*ProtoNode) MarshalJSON added in v0.4.5

func (n *ProtoNode) MarshalJSON() ([]byte, error)

func (*ProtoNode) Multihash added in v0.4.5

func (n *ProtoNode) Multihash() mh.Multihash

Multihash hashes the encoded data of this node.

func (*ProtoNode) RawData added in v0.4.5

func (n *ProtoNode) RawData() []byte
func (n *ProtoNode) RemoveNodeLink(name string) error

Remove a link on this node by the given name

func (*ProtoNode) Resolve added in v0.4.5

func (n *ProtoNode) Resolve(path []string) (interface{}, []string, error)
func (n *ProtoNode) ResolveLink(path []string) (*node.Link, []string, error)

func (*ProtoNode) SetData added in v0.4.5

func (n *ProtoNode) SetData(d []byte)
func (n *ProtoNode) SetLinks(links []*node.Link)

func (*ProtoNode) Size added in v0.4.5

func (n *ProtoNode) Size() (uint64, error)

Size returns the total size of the data addressed by node, including the total sizes of references.

func (*ProtoNode) Stat added in v0.4.5

func (n *ProtoNode) Stat() (*node.NodeStat, error)

Stat returns statistics on the node.

func (*ProtoNode) String added in v0.4.5

func (n *ProtoNode) String() string

func (*ProtoNode) Tree added in v0.4.5

func (n *ProtoNode) Tree(p string, depth int) []string

func (*ProtoNode) UnmarshalJSON added in v0.4.5

func (n *ProtoNode) UnmarshalJSON(b []byte) error
func (n *ProtoNode) UpdateNodeLink(name string, that *ProtoNode) (*ProtoNode, error)

UpdateNodeLink return a copy of the node with the link name set to point to that. If a link of the same name existed, it is removed.

type RawNode added in v0.4.5

type RawNode struct {
	blocks.Block
}

func NewRawNode added in v0.4.5

func NewRawNode(data []byte) *RawNode

func (*RawNode) Copy added in v0.4.5

func (rn *RawNode) Copy() node.Node
func (rn *RawNode) Links() []*node.Link

func (*RawNode) Resolve added in v0.4.5

func (rn *RawNode) Resolve(path []string) (interface{}, []string, error)
func (rn *RawNode) ResolveLink(path []string) (*node.Link, []string, error)

func (*RawNode) Size added in v0.4.5

func (rn *RawNode) Size() (uint64, error)

func (*RawNode) Stat added in v0.4.5

func (rn *RawNode) Stat() (*node.NodeStat, error)

func (*RawNode) Tree added in v0.4.5

func (rn *RawNode) Tree(p string, depth int) []string

Directories

Path Synopsis
Package merkledag_pb is a generated protocol buffer package.
Package merkledag_pb is a generated protocol buffer package.
Package traverse provides merkledag traversal functions
Package traverse provides merkledag traversal functions

Jump to

Keyboard shortcuts

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