go-merkledag: github.com/ipfs/go-merkledag Index | Files | Directories

package merkledag

import "github.com/ipfs/go-merkledag"

Package merkledag implements the IPFS Merkle DAG data structures.

Index

Package Files

coding.go errservice.go merkledag.go node.go raw.go readonly.go rwservice.go session.go

Variables

var (
    ErrNotProtobuf  = fmt.Errorf("expected protobuf dag node")
    ErrLinkNotFound = fmt.Errorf("no link by that name")
)

Common errors

var ErrReadOnly = fmt.Errorf("cannot write to readonly DAGService")

ErrReadOnly is used when a read-only datastructure is written to.

func DecodeProtobufBlock Uses

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

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

func DecodeRawBlock Uses

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

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

func FetchGraph Uses

func FetchGraph(ctx context.Context, root cid.Cid, serv ipld.DAGService) error

FetchGraph fetches all nodes that are children of the given node

func FetchGraphWithDepthLimit Uses

func FetchGraphWithDepthLimit(ctx context.Context, root cid.Cid, depthLim int, serv ipld.DAGService) error

FetchGraphWithDepthLimit fetches all nodes that are children to the given node down to the given depth. maxDepth=0 means "only fetch root", maxDepth=1 means "fetch root and its direct children" and so on... maxDepth=-1 means unlimited.

func NewDAGService Uses

func NewDAGService(bs bserv.BlockService) *dagService

NewDAGService constructs a new DAGService (using the default implementation). Note that the default implementation is also an ipld.LinkGetter.

func NewReadOnlyDagService Uses

func NewReadOnlyDagService(ng ipld.NodeGetter) ipld.DAGService

NewReadOnlyDagService takes a NodeGetter, and returns a full DAGService implementation that returns ErrReadOnly when its 'write' methods are invoked.

func NewSession Uses

func NewSession(ctx context.Context, g ipld.NodeGetter) ipld.NodeGetter

NewSession returns a session backed NodeGetter if the given NodeGetter implements SessionMaker.

func PrefixForCidVersion Uses

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

PrefixForCidVersion returns the Protobuf prefix for a given CID version

func V0CidPrefix Uses

func V0CidPrefix() cid.Prefix

V0CidPrefix returns a prefix for CIDv0

func V1CidPrefix Uses

func V1CidPrefix() cid.Prefix

V1CidPrefix returns a prefix for CIDv1 with the default settings

func Walk Uses

func Walk(ctx context.Context, getLinks GetLinks, c cid.Cid, visit func(cid.Cid) bool, options ...WalkOption) error

WalkGraph will walk the dag in order (depth first) starting at the given root.

func WalkDepth Uses

func WalkDepth(ctx context.Context, getLinks GetLinks, c cid.Cid, visit func(cid.Cid, int) bool, options ...WalkOption) error

WalkDepth walks the dag starting at the given root and passes the current depth to a given visit function. The visit function can be used to limit DAG exploration.

type ComboService Uses

type ComboService struct {
    Read  ipld.NodeGetter
    Write ipld.DAGService
}

ComboService implements ipld.DAGService, using 'Read' for all fetch methods, and 'Write' for all methods that add new objects.

func (*ComboService) Add Uses

func (cs *ComboService) Add(ctx context.Context, nd ipld.Node) error

Add writes a new node using the Write DAGService.

func (*ComboService) AddMany Uses

func (cs *ComboService) AddMany(ctx context.Context, nds []ipld.Node) error

AddMany adds nodes using the Write DAGService.

func (*ComboService) Get Uses

func (cs *ComboService) Get(ctx context.Context, c cid.Cid) (ipld.Node, error)

Get fetches a node using the Read DAGService.

func (*ComboService) GetMany Uses

func (cs *ComboService) GetMany(ctx context.Context, cids []cid.Cid) <-chan *ipld.NodeOption

GetMany fetches nodes using the Read DAGService.

func (*ComboService) Remove Uses

func (cs *ComboService) Remove(ctx context.Context, c cid.Cid) error

Remove deletes a node using the Write DAGService.

func (*ComboService) RemoveMany Uses

func (cs *ComboService) RemoveMany(ctx context.Context, cids []cid.Cid) error

RemoveMany deletes nodes using the Write DAGService.

type ErrorService Uses

type ErrorService struct {
    Err error
}

ErrorService implements ipld.DAGService, returning 'Err' for every call.

func (*ErrorService) Add Uses

func (cs *ErrorService) Add(ctx context.Context, nd ipld.Node) error

Add returns the cs.Err.

func (*ErrorService) AddMany Uses

func (cs *ErrorService) AddMany(ctx context.Context, nds []ipld.Node) error

AddMany returns the cs.Err.

func (*ErrorService) Get Uses

func (cs *ErrorService) Get(ctx context.Context, c cid.Cid) (ipld.Node, error)

Get returns the cs.Err.

func (*ErrorService) GetMany Uses

func (cs *ErrorService) GetMany(ctx context.Context, cids []cid.Cid) <-chan *ipld.NodeOption

GetMany many returns the cs.Err.

func (*ErrorService) Remove Uses

func (cs *ErrorService) Remove(ctx context.Context, c cid.Cid) error

Remove returns the cs.Err.

func (*ErrorService) RemoveMany Uses

func (cs *ErrorService) RemoveMany(ctx context.Context, cids []cid.Cid) error

RemoveMany returns the cs.Err.

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

GetLinks is the type of function passed to the EnumerateChildren function(s) for getting the children of an IPLD node.

func GetLinksDirect Uses

func GetLinksDirect(serv ipld.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.

func GetLinksWithDAG Uses

func GetLinksWithDAG(ng ipld.NodeGetter) GetLinks

GetLinksWithDAG returns a GetLinks function that tries to use the given NodeGetter as a LinkGetter to get the children of a given IPLD node. This may allow us to traverse the DAG without actually loading and parsing the node in question (if we already have the links cached).

type LinkSlice Uses

type LinkSlice []*ipld.Link

LinkSlice is a slice of ipld.Links

func (LinkSlice) Len Uses

func (ls LinkSlice) Len() int

func (LinkSlice) Less Uses

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

func (LinkSlice) Swap Uses

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

type ProgressTracker Uses

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

ProgressTracker is used to show progress when fetching nodes.

func (*ProgressTracker) DeriveContext Uses

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

DeriveContext returns a new context with value "progress" derived from the given one.

func (*ProgressTracker) Increment Uses

func (p *ProgressTracker) Increment()

Increment adds one to the total progress.

func (*ProgressTracker) Value Uses

func (p *ProgressTracker) Value() int

Value returns the current progress.

type ProtoNode Uses

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

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

func DecodeProtobuf Uses

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

DecodeProtobuf decodes raw data and returns a new Node instance.

func NodeWithData Uses

func NodeWithData(d []byte) *ProtoNode

NodeWithData builds a new Protonode with the given data.

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

AddNodeLink adds a link to another node.

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

AddRawLink adds a copy of a link to this node

func (*ProtoNode) Cid Uses

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

Cid returns the node's Cid, calculated according to its prefix and raw data contents.

func (*ProtoNode) CidBuilder Uses

func (n *ProtoNode) CidBuilder() cid.Builder

CidBuilder returns the CID Builder for this ProtoNode, it is never nil

func (*ProtoNode) Copy Uses

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

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

func (*ProtoNode) Data Uses

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

Data returns the data stored by this node.

func (*ProtoNode) EncodeProtobuf Uses

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 Uses

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

GetLinkedNode returns a copy of the IPLD Node with the given name.

func (*ProtoNode) GetLinkedProtoNode Uses

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

GetLinkedProtoNode returns a copy of the ProtoNode with the given name.

func (n *ProtoNode) GetNodeLink(name string) (*ipld.Link, error)

GetNodeLink returns a copy of the link with the given name.

func (*ProtoNode) GetPBNode Uses

func (n *ProtoNode) GetPBNode() *pb.PBNode

GetPBNode converts *ProtoNode into it's protocol buffer variant. If you plan on mutating the data of the original node, it is recommended that you call ProtoNode.Copy() before calling ProtoNode.GetPBNode()

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

Links returns the node links.

func (*ProtoNode) Loggable Uses

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

Loggable implements the ipfs/go-log.Loggable interface.

func (*ProtoNode) Marshal Uses

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 Uses

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

MarshalJSON returns a JSON representation of the node.

func (*ProtoNode) Multihash Uses

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

Multihash hashes the encoded data of this node.

func (*ProtoNode) RawData Uses

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

RawData returns the protobuf-encoded version of the node.

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

RemoveNodeLink removes a link on this node by the given name.

func (*ProtoNode) Resolve Uses

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

Resolve is an alias for ResolveLink.

func (n *ProtoNode) ResolveLink(path []string) (*ipld.Link, []string, error)

ResolveLink consumes the first element of the path and obtains the link corresponding to it from the node. It returns the link and the path without the consumed element.

func (*ProtoNode) SetCidBuilder Uses

func (n *ProtoNode) SetCidBuilder(builder cid.Builder)

SetCidBuilder sets the CID builder if it is non nil, if nil then it is reset to the default value

func (*ProtoNode) SetData Uses

func (n *ProtoNode) SetData(d []byte)

SetData stores data in this nodes.

func (n *ProtoNode) SetLinks(links []*ipld.Link)

SetLinks replaces the node links with the given ones.

func (*ProtoNode) Size Uses

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 Uses

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

Stat returns statistics on the node.

func (*ProtoNode) String Uses

func (n *ProtoNode) String() string

String prints the node's Cid.

func (*ProtoNode) Tree Uses

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

Tree returns the link names of the ProtoNode. ProtoNodes are only ever one path deep, so anything different than an empty string for p results in nothing. The depth parameter is ignored.

func (*ProtoNode) UnmarshalJSON Uses

func (n *ProtoNode) UnmarshalJSON(b []byte) error

UnmarshalJSON reads the node fields from a JSON-encoded byte slice.

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 Uses

type RawNode struct {
    blocks.Block
}

RawNode represents a node which only contains data.

func NewRawNode Uses

func NewRawNode(data []byte) *RawNode

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

func NewRawNodeWPrefix Uses

func NewRawNodeWPrefix(data []byte, builder cid.Builder) (*RawNode, error)

NewRawNodeWPrefix creates a RawNode using the provided cid builder

func (*RawNode) Copy Uses

func (rn *RawNode) Copy() ipld.Node

Copy performs a deep copy of this node and returns it as an ipld.Node

func (rn *RawNode) Links() []*ipld.Link

Links returns nil.

func (*RawNode) MarshalJSON Uses

func (rn *RawNode) MarshalJSON() ([]byte, error)

MarshalJSON is required for our "ipfs dag" commands.

func (*RawNode) Resolve Uses

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

Resolve returns an error.

func (rn *RawNode) ResolveLink(path []string) (*ipld.Link, []string, error)

ResolveLink returns an error.

func (*RawNode) Size Uses

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

Size returns the size of this node

func (*RawNode) Stat Uses

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

Stat returns some Stats about this node.

func (*RawNode) Tree Uses

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

Tree returns nil.

type SessionMaker Uses

type SessionMaker interface {
    Session(context.Context) ipld.NodeGetter
}

SessionMaker is an object that can generate a new fetching session.

type WalkOption Uses

type WalkOption func(*walkOptions)

WalkOption is a setter for walkOptions

func Concurrency Uses

func Concurrency(worker int) WalkOption

Concurrency is a WalkOption indicating that node fetching should be done in parallel, with a specific concurrency factor. NOTE: When using that option, the walk order is *not* guarantee. NOTE: It *does not* make multiple concurrent calls to the passed `visit` function.

func Concurrent Uses

func Concurrent() WalkOption

Concurrent is a WalkOption indicating that node fetching should be done in parallel, with the default concurrency factor. NOTE: When using that option, the walk order is *not* guarantee. NOTE: It *does not* make multiple concurrent calls to the passed `visit` function.

func IgnoreErrors Uses

func IgnoreErrors() WalkOption

IgnoreErrors is a WalkOption indicating that the walk should attempt to continue even when an error occur.

func IgnoreMissing Uses

func IgnoreMissing() WalkOption

IgnoreMissing is a WalkOption indicating that the walk should continue when a node is missing.

func OnError Uses

func OnError(handler func(c cid.Cid, err error) error) WalkOption

OnError is a WalkOption adding a custom error handler. If this handler return a nil error, the walk will continue.

func OnMissing Uses

func OnMissing(callback func(c cid.Cid)) WalkOption

OnMissing is a WalkOption adding a callback that will be triggered on a missing node.

func SkipRoot Uses

func SkipRoot() WalkOption

SkipRoot is a WalkOption indicating that the root node should skipped

Directories

PathSynopsis
dagutils
pb
test
traversePackage traverse provides merkledag traversal functions

Package merkledag imports 14 packages (graph) and is imported by 149 packages. Updated 2020-05-07. Refresh now. Tools for package owners.