Documentation
¶
Overview ¶
package merkledag implements the IPFS Merkle DAG datastructures.
Index ¶
- Variables
- func EnumerateChildren(ctx context.Context, ds LinkService, root *cid.Cid, visit func(*cid.Cid) bool, ...) error
- func EnumerateChildrenAsync(ctx context.Context, ds DAGService, c *cid.Cid, visit func(*cid.Cid) bool) error
- func FetchGraph(ctx context.Context, c *cid.Cid, serv DAGService) error
- func FindLinks(links []*cid.Cid, c *cid.Cid, start int) []int
- func NewDAGService(bs bserv.BlockService) *dagService
- type Batch
- type DAGService
- type LinkService
- type LinkSlice
- type NodeGetter
- type NodeOption
- type ProtoNode
- func (n *ProtoNode) AddNodeLink(name string, that node.Node) error
- func (n *ProtoNode) AddNodeLinkClean(name string, that node.Node) error
- func (n *ProtoNode) AddRawLink(name string, l *node.Link) error
- func (n *ProtoNode) Cid() *cid.Cid
- func (n *ProtoNode) Copy() node.Node
- func (n *ProtoNode) Data() []byte
- func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error)
- func (n *ProtoNode) GetLinkedNode(ctx context.Context, ds DAGService, name string) (node.Node, error)
- func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds DAGService, name string) (*ProtoNode, error)
- func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error)
- func (n *ProtoNode) Links() []*node.Link
- func (n *ProtoNode) Loggable() map[string]interface{}
- func (n *ProtoNode) Marshal() ([]byte, error)
- func (n *ProtoNode) MarshalJSON() ([]byte, error)
- func (n *ProtoNode) Multihash() mh.Multihash
- func (n *ProtoNode) RawData() []byte
- func (n *ProtoNode) RemoveNodeLink(name string) error
- func (n *ProtoNode) Resolve(path []string) (interface{}, []string, error)
- func (n *ProtoNode) ResolveLink(path []string) (*node.Link, []string, error)
- func (n *ProtoNode) SetData(d []byte)
- func (n *ProtoNode) SetLinks(links []*node.Link)
- func (n *ProtoNode) Size() (uint64, error)
- func (n *ProtoNode) Stat() (*node.NodeStat, error)
- func (n *ProtoNode) String() string
- func (n *ProtoNode) Tree(p string, depth int) []string
- func (n *ProtoNode) UnmarshalJSON(b []byte) error
- func (n *ProtoNode) UpdateNodeLink(name string, that *ProtoNode) (*ProtoNode, error)
- type RawNode
- func (rn *RawNode) Copy() node.Node
- func (rn *RawNode) Links() []*node.Link
- func (rn *RawNode) Resolve(path []string) (interface{}, []string, error)
- func (rn *RawNode) ResolveLink(path []string) (*node.Link, []string, error)
- func (rn *RawNode) Size() (uint64, error)
- func (rn *RawNode) Stat() (*node.NodeStat, error)
- func (rn *RawNode) Tree(p string, depth int) []string
Constants ¶
This section is empty.
Variables ¶
var ErrLinkNotFound = fmt.Errorf("no link by that name")
var ErrNotFound = fmt.Errorf("merkledag: not found")
var ErrNotProtobuf = fmt.Errorf("expected protobuf dag node")
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 ¶
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
}
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 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.
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 (*ProtoNode) AddNodeLink ¶ added in v0.4.5
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 (*ProtoNode) AddRawLink ¶ added in v0.4.5
func (n *ProtoNode) AddRawLink(name string, l *node.Link) error
AddRawLink adds a copy of a link to this node
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) 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 (*ProtoNode) GetNodeLink ¶ added in v0.4.5
func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error)
Return a copy of the link with given name
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) RemoveNodeLink ¶ added in v0.4.5
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 (*ProtoNode) ResolveLink ¶ added in v0.4.5
func (n *ProtoNode) ResolveLink(path []string) (*node.Link, []string, error)
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) UnmarshalJSON ¶ added in v0.4.5
func (n *ProtoNode) UnmarshalJSON(b []byte) error
func (*ProtoNode) UpdateNodeLink ¶ added in v0.4.5
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) Resolve ¶ added in v0.4.5
func (rn *RawNode) Resolve(path []string) (interface{}, []string, error)
func (*RawNode) ResolveLink ¶ added in v0.4.5
func (rn *RawNode) ResolveLink(path []string) (*node.Link, []string, error)