Documentation ¶
Overview ¶
Package merkledag implements the IPFS Merkle DAG data structures.
Index ¶
- Variables
- func DecodeProtobufBlock(b blocks.Block) (ipld.Node, error)
- func DecodeRawBlock(block blocks.Block) (ipld.Node, error)
- func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, ...) error
- func EnumerateChildrenAsync(ctx context.Context, getLinks GetLinks, c *cid.Cid, visit func(*cid.Cid) bool) error
- func FetchGraph(ctx context.Context, root *cid.Cid, serv ipld.DAGService) error
- func FindLinks(links []*cid.Cid, c *cid.Cid, start int) []int
- func NewDAGService(bs bserv.BlockService) *dagService
- func NewReadOnlyDagService(ng ipld.NodeGetter) ipld.DAGService
- func NewSession(ctx context.Context, g ipld.NodeGetter) ipld.NodeGetter
- func PrefixForCidVersion(version int) (cid.Prefix, error)
- func V0CidPrefix() cid.Prefix
- func V1CidPrefix() cid.Prefix
- type ComboService
- func (cs *ComboService) Add(ctx context.Context, nd ipld.Node) error
- func (cs *ComboService) AddMany(ctx context.Context, nds []ipld.Node) error
- func (cs *ComboService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error)
- func (cs *ComboService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption
- func (cs *ComboService) Remove(ctx context.Context, c *cid.Cid) error
- func (cs *ComboService) RemoveMany(ctx context.Context, cids []*cid.Cid) error
- type ErrorService
- func (cs *ErrorService) Add(ctx context.Context, nd ipld.Node) error
- func (cs *ErrorService) AddMany(ctx context.Context, nds []ipld.Node) error
- func (cs *ErrorService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error)
- func (cs *ErrorService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption
- func (cs *ErrorService) Remove(ctx context.Context, c *cid.Cid) error
- func (cs *ErrorService) RemoveMany(ctx context.Context, cids []*cid.Cid) error
- type GetLinks
- type LinkSlice
- type ProgressTracker
- type ProtoNode
- func (n *ProtoNode) AddNodeLink(name string, that ipld.Node) error
- func (n *ProtoNode) AddNodeLinkClean(name string, that ipld.Node) error
- func (n *ProtoNode) AddRawLink(name string, l *ipld.Link) error
- func (n *ProtoNode) Cid() *cid.Cid
- func (n *ProtoNode) Copy() ipld.Node
- func (n *ProtoNode) Data() []byte
- func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error)
- func (n *ProtoNode) GetLinkedNode(ctx context.Context, ds ipld.DAGService, name string) (ipld.Node, error)
- func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds ipld.DAGService, name string) (*ProtoNode, error)
- func (n *ProtoNode) GetNodeLink(name string) (*ipld.Link, error)
- func (n *ProtoNode) Links() []*ipld.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) (*ipld.Link, []string, error)
- func (n *ProtoNode) SetData(d []byte)
- func (n *ProtoNode) SetLinks(links []*ipld.Link)
- func (n *ProtoNode) SetPrefix(prefix *cid.Prefix)
- func (n *ProtoNode) Size() (uint64, error)
- func (n *ProtoNode) Stat() (*ipld.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() ipld.Node
- func (rn *RawNode) Links() []*ipld.Link
- func (rn *RawNode) Resolve(path []string) (interface{}, []string, error)
- func (rn *RawNode) ResolveLink(path []string) (*ipld.Link, []string, error)
- func (rn *RawNode) Size() (uint64, error)
- func (rn *RawNode) Stat() (*ipld.NodeStat, error)
- func (rn *RawNode) Tree(p string, depth int) []string
- type SessionMaker
Constants ¶
This section is empty.
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.
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
DecodeProtobufBlock is a block decoder for protobuf IPLD nodes conforming to node.DecodeBlockFunc
func DecodeRawBlock ¶ added in v0.4.11
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
EnumerateChildrenAsync is equivalent to EnumerateChildren *except* that it fetches children in parallel.
NOTE: It *does not* make multiple concurrent calls to the passed `visit` function.
func FetchGraph ¶
FetchGraph fetches all nodes that are children of the given node
func FindLinks ¶
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
NewDAGService constructs a new DAGService (using the default implementation). Note that the default implementation is also an ipld.LinkGetter.
func NewReadOnlyDagService ¶ added in v0.4.14
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 ¶ added in v0.4.14
func NewSession(ctx context.Context, g ipld.NodeGetter) ipld.NodeGetter
NewSession returns a session backed NodeGetter if the given NodeGetter implements SessionMaker.
func PrefixForCidVersion ¶ added in v0.4.9
PrefixForCidVersion returns the Protobuf prefix for a given CID version
func V0CidPrefix ¶ added in v0.4.12
V0CidPrefix returns a prefix for CIDv0
func V1CidPrefix ¶ added in v0.4.12
V1CidPrefix returns a prefix for CIDv1 with the default settings
Types ¶
type ComboService ¶ added in v0.4.14
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) GetMany ¶ added in v0.4.14
func (cs *ComboService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption
GetMany fetches nodes using the Read DAGService.
func (*ComboService) RemoveMany ¶ added in v0.4.14
RemoveMany deletes nodes using the Write DAGService.
type ErrorService ¶ added in v0.4.14
type ErrorService struct {
Err error
}
ErrorService implements ipld.DAGService, returning 'Err' for every call.
func (*ErrorService) GetMany ¶ added in v0.4.14
func (cs *ErrorService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption
GetMany many returns the cs.Err.
func (*ErrorService) RemoveMany ¶ added in v0.4.14
RemoveMany returns the cs.Err.
type GetLinks ¶ added in v0.4.7
GetLinks is the type of function passed to the EnumerateChildren function(s) for getting the children of an IPLD node.
func GetLinksDirect ¶ added in v0.4.7
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 ¶ added in v0.4.14
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 ProgressTracker ¶ added in v0.4.7
type ProgressTracker struct { Total int // contains filtered or unexported fields }
ProgressTracker is used to show progress when fetching nodes.
func (*ProgressTracker) DeriveContext ¶ added in v0.4.7
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 ¶ added in v0.4.7
func (p *ProgressTracker) Increment()
Increment adds one to the total progress.
func (*ProgressTracker) Value ¶ added in v0.4.7
func (p *ProgressTracker) Value() int
Value returns the current progress.
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 }
ProtoNode 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
DecodeProtobuf decodes raw data and returns a new Node instance.
func NodeWithData ¶ added in v0.4.3
NodeWithData builds a new Protonode with the given data.
func (*ProtoNode) AddNodeLink ¶ added in v0.4.5
AddNodeLink adds a link to another node.
func (*ProtoNode) AddNodeLinkClean ¶ added in v0.4.5
AddNodeLinkClean adds a link to another node. without keeping a reference to the child node
func (*ProtoNode) AddRawLink ¶ added in v0.4.5
AddRawLink adds a copy of a link to this node
func (*ProtoNode) Cid ¶ added in v0.4.5
Cid returns the node's Cid, calculated according to its prefix and raw data contents.
func (*ProtoNode) Copy ¶ added in v0.4.5
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
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 ipld.DAGService, name string) (ipld.Node, error)
GetLinkedNode returns a copy of the IPLD Node with the given name.
func (*ProtoNode) GetLinkedProtoNode ¶ added in v0.4.5
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 (*ProtoNode) GetNodeLink ¶ added in v0.4.5
GetNodeLink returns a copy of the link with the given name.
func (*ProtoNode) Loggable ¶ added in v0.4.5
Loggable implements the ipfs/go-log.Loggable interface.
func (*ProtoNode) Marshal ¶ added in v0.4.5
Marshal encodes a *Node instance into a new byte slice. The conversion uses an intermediate PBNode.
func (*ProtoNode) MarshalJSON ¶ added in v0.4.5
MarshalJSON returns a JSON representation of the node.
func (*ProtoNode) RawData ¶ added in v0.4.5
RawData returns the protobuf-encoded version of the node.
func (*ProtoNode) RemoveNodeLink ¶ added in v0.4.5
RemoveNodeLink removes a link on this node by the given name.
func (*ProtoNode) ResolveLink ¶ added in v0.4.5
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) SetPrefix ¶ added in v0.4.9
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
Size returns the total size of the data addressed by node, including the total sizes of references.
func (*ProtoNode) Tree ¶ added in v0.4.5
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 ¶ added in v0.4.5
UnmarshalJSON reads the node fields from a JSON-encoded byte slice.
type RawNode ¶ added in v0.4.5
type RawNode struct {
blocks.Block
}
RawNode represents a node which only contains data.
func NewRawNode ¶ added in v0.4.5
NewRawNode creates a RawNode using the default sha2-256 hash funcition.
func NewRawNodeWPrefix ¶ added in v0.4.10
NewRawNodeWPrefix creates a RawNode with the hash function specified in prefix.
func (*RawNode) Copy ¶ added in v0.4.5
Copy performs a deep copy of this node and returns it as an ipld.Node
func (*RawNode) ResolveLink ¶ added in v0.4.5
ResolveLink returns an error.
type SessionMaker ¶ added in v0.4.14
type SessionMaker interface {
Session(context.Context) ipld.NodeGetter
}
SessionMaker is an object that can generate a new fetching session.