merkledag

package
v0.4.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2016 License: MIT Imports: 11 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")

Functions

func EnumerateChildren added in v0.4.0

func EnumerateChildren(ctx context.Context, ds DAGService, root *Node, set key.KeySet) 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, root *Node, set key.KeySet) error

func FetchGraph

func FetchGraph(ctx context.Context, root *Node, serv DAGService) error

FetchGraph fetches all nodes that are children of the given node

func FindLinks(links []key.Key, k key.Key, start int) []int

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

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) (key.Key, error)

func (*Batch) Commit added in v0.3.6

func (t *Batch) Commit() error

type DAGService

type DAGService interface {
	Add(*Node) (key.Key, error)
	Get(context.Context, key.Key) (*Node, error)
	Remove(*Node) error

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

	Batch() *Batch
}

DAGService is an IPFS Merkle DAG service.

func NewDAGService

func NewDAGService(bs *bserv.BlockService) DAGService
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
	Hash mh.Multihash
}

Link represents an IPFS Merkle DAG Link between Nodes.

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 DAGService) (*Node, error)

GetNode returns the MDAG Node that this link points to

type LinkSlice

type LinkSlice []*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 Node

type Node struct {
	Links []*Link
	Data  []byte
	// 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) (*Node, error)

Decoded decodes raw data and returns a new Node instance.

func (n *Node) AddNodeLink(name string, that *Node) error

AddNodeLink adds a link to another node.

func (*Node) AddNodeLinkClean

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

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

func (n *Node) AddRawLink(name string, l *Link) error

AddRawLink adds a copy of a link to this node

func (*Node) Copy

func (n *Node) Copy() *Node

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

func (*Node) EncodeProtobuf added in v0.4.0

func (n *Node) 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 (*Node) GetLinkedNode added in v0.3.6

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

Return a copy of the link with given name

func (*Node) Key

func (n *Node) Key() (key.Key, error)

Key returns the Multihash as a key, for maps.

func (*Node) Marshal

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

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

func (*Node) Multihash

func (n *Node) Multihash() (mh.Multihash, error)

Multihash hashes the encoded data of this node.

func (n *Node) RemoveNodeLink(name string) error

Remove a link on this node by the given name

func (*Node) Size

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

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

func (*Node) Stat

func (n *Node) Stat() (*NodeStat, error)

Stat returns statistics on the node.

func (n *Node) UpdateNodeLink(name string, that *Node) (*Node, 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 NodeGetter

type NodeGetter interface {
	Get(context.Context) (*Node, error)
}

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) []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 []key.Key) []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
	Err  error
}

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

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