merkledag

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2017 License: MIT Imports: 15 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 DecodeProtobufBlock added in v0.4.11

func DecodeProtobufBlock(b blocks.Block) (node.Node, error)

DecodeProtobufBlock is a block decoder for protobuf IPLD nodes conforming to node.DecodeBlockFunc

func DecodeRawBlock added in v0.4.11

func DecodeRawBlock(block blocks.Block) (node.Node, error)

DecodeRawBlock is a block decoder for raw IPLD nodes conforming to `node.DecodeBlockFunc`.

func EnumerateChildren added in v0.4.0

func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, visit func(*cid.Cid) 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, getLinks GetLinks, c *cid.Cid, visit func(*cid.Cid) bool) error

func FetchGraph

func FetchGraph(ctx context.Context, root *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

func PrefixForCidVersion added in v0.4.9

func PrefixForCidVersion(version int) (cid.Prefix, error)

PrefixForCidVersion returns the Protobuf prefix for a given CID version

Types

type Batch added in v0.3.6

type Batch struct {
	MaxSize   int
	MaxBlocks 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

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

	Batch() *Batch

	LinkService
}

DAGService is an IPFS Merkle DAG service.

type GetLinks func(context.Context, *cid.Cid) ([]*node.Link, error)

func GetLinksDirect added in v0.4.7

func GetLinksDirect(serv node.NodeGetter) GetLinks

GetLinksDirect creates a function to get the links for a node, from the node, bypassing the LinkService. If the node does not exist locally (and can not be retrieved) an error will be returned.

type LinkService added in v0.4.5

type LinkService interface {
	// GetLinks return all links for a node.  The complete node does not
	// necessarily have to exist locally, or at all.  For example, raw
	// leaves cannot possibly have links so there is no need to look
	// at the node.
	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 ProgressTracker added in v0.4.7

type ProgressTracker struct {
	Total int
	// contains filtered or unexported fields
}

func (*ProgressTracker) DeriveContext added in v0.4.7

func (p *ProgressTracker) DeriveContext(ctx context.Context) context.Context

func (*ProgressTracker) Increment added in v0.4.7

func (p *ProgressTracker) Increment()

func (*ProgressTracker) Value added in v0.4.7

func (p *ProgressTracker) Value() int

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) SetPrefix added in v0.4.9

func (n *ProtoNode) SetPrefix(prefix *cid.Prefix)

SetPrefix sets the CID prefix if it is non nil, if prefix is nil then it resets it the default value

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

NewRawNode creates a RawNode using the default sha2-256 hash funcition.

func NewRawNodeWPrefix added in v0.4.10

func NewRawNodeWPrefix(data []byte, prefix cid.Prefix) (*RawNode, error)

NewRawNodeWPrefix creates a RawNode with the hash function specified in prefix.

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