Documentation
¶
Overview ¶
package merkledag implements the ipfs Merkle DAG datastructures.
Index ¶
- Variables
- func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
- func FindLinks(links []u.Key, k u.Key, start int) []int
- type DAGService
- type Link
- type LinkSlice
- type Node
- func (n *Node) AddNodeLink(name string, that *Node) error
- func (n *Node) AddNodeLinkClean(name string, that *Node) error
- func (n *Node) Copy() *Node
- func (n *Node) Encoded(force bool) ([]byte, error)
- func (n *Node) Key() (u.Key, error)
- func (n *Node) Marshal() ([]byte, error)
- func (n *Node) MarshalTo(encoded []byte) error
- func (n *Node) Multihash() (mh.Multihash, error)
- func (n *Node) RemoveNodeLink(name string) error
- func (n *Node) Size() (uint64, error)
- func (n *Node) Stat() (*NodeStat, error)
- func (n *Node) Unmarshal(encoded []byte) error
- func (n *Node) UpdateNodeLink(name string, that *Node) (*Node, error)
- type NodeGetter
- type NodeMap
- type NodeStat
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = fmt.Errorf("merkledag: not found")
Functions ¶
func FetchGraph ¶
func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
FetchGraph asynchronously fetches all nodes that are children of the given node, and returns a channel that may be waited upon for the fetch to complete
Types ¶
type DAGService ¶
type DAGService interface {
Add(*Node) (u.Key, error)
AddRecursive(*Node) error
Get(u.Key) (*Node, error)
Remove(*Node) error
// GetDAG returns, in order, all the single leve child
// nodes of the passed in node.
GetDAG(context.Context, *Node) []NodeGetter
GetNodes(context.Context, []u.Key) []NodeGetter
}
DAGService is an IPFS Merkle DAG service.
func NewDAGService ¶
func NewDAGService(bs *bserv.BlockService) DAGService
type Link ¶
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
// a ptr to the actual node for graph manipulation
Node *Node
}
Link represents an IPFS Merkle DAG Link between Nodes.
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 Decoded ¶
func Decoded(encoded []byte) (*Node, error)
Decoded decodes raw data and returns a new Node instance.
func (*Node) AddNodeLink ¶
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
AddNodeLink adds a link to another node. without keeping a reference to the child 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) Encoded ¶
func (n *Node) Encoded(force bool) ([]byte, error)
Encoded 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) Key ¶
func (n *Node) Key() (u.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) MarshalTo ¶
func (n *Node) MarshalTo(encoded []byte) error
MarshalTo encodes a *Node instance into a given 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 (*Node) RemoveNodeLink ¶
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) Unmarshal ¶
func (n *Node) Unmarshal(encoded []byte) error
Unmarshal decodes raw data into a *Node instance. The conversion uses an intermediate PBNode.
func (*Node) UpdateNodeLink ¶
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() (*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.
type NodeMap ¶
type NodeMap map[u.Key]*Node
NodeMap maps u.Keys to Nodes. We cannot use []byte/Multihash for keys :( so have to convert Multihash bytes to string (u.Key)
type NodeStat ¶
type NodeStat struct {
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.