Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("error: batch closed")
ErrClosed is returned when operating on a batch that has already been closed.
var ErrNotCommited = errors.New("error: batch not commited")
ErrNotCommited is returned when closing a batch that hasn't been successfully committed.
var ErrNotFound = fmt.Errorf("merkledag: not found")
var ParallelBatchCommits = runtime.NumCPU() * 2
ParallelBatchCommits is the number of batch commits that can be in-flight before blocking. TODO(ipfs/go-ipfs#4299): Experiment with multiple datastores, storage devices, and CPUs to find the right value/formula.
Functions ¶
func Register ¶ added in v0.5.0
func Register(codec uint64, decoder DecodeBlockFunc)
Register registers block decoders with the default BlockDecoder.
Types ¶
type Batch ¶ added in v0.5.3
Batch is a buffer for batching adds to a dag.
func NewBatch ¶ added in v0.5.3
func NewBatch(ctx context.Context, ds DAGService) *Batch
NewBatch returns a node buffer (Batch) that buffers nodes internally and commits them to the underlying DAGService in batches. Use this if you intend to add or remove a lot of nodes all at once.
If the passed context is canceled, any in-progress commits are aborted.
type BlockDecoder ¶ added in v0.4.8
type BlockDecoder interface {
Register(codec uint64, decoder DecodeBlockFunc)
Decode(blocks.Block) (Node, error)
}
var DefaultBlockDecoder BlockDecoder = &safeBlockDecoder{decoders: make(map[uint64]DecodeBlockFunc)}
type DAGService ¶ added in v0.5.3
type DAGService interface {
NodeGetter
// Add adds a node to this DAG.
Add(context.Context, Node) error
// Remove removes a node from this DAG.
//
// Remove returns no error if the requested node is not present in this DAG.
Remove(context.Context, *cid.Cid) error
// AddMany adds many nodes to this DAG.
//
// Consider using NewBatch instead of calling this directly if you need
// to add an unbounded number of nodes to avoid buffering too much.
AddMany(context.Context, []Node) error
// RemoveMany removes many nodes from this DAG.
//
// It returns success even if the nodes were not present in the DAG.
RemoveMany(context.Context, []*cid.Cid) error
}
DAGService is an IPFS Merkle DAG service.
type DecodeBlockFunc ¶ added in v0.4.8
DecodeBlockFunc functions decode blocks into nodes.
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
Cid *cid.Cid
}
Link represents an IPFS Merkle DAG Link between Nodes.
type LinkGetter ¶ added in v0.5.3
type LinkGetter interface {
NodeGetter
// GetLinks returns the children of the node refered to by the given
// CID.
GetLinks(ctx context.Context, nd *cid.Cid) ([]*Link, error)
}
NodeGetters can optionally implement this interface to make finding linked objects faster.
type Node ¶
type Node interface {
blocks.Block
Resolver
// ResolveLink is a helper function that calls resolve and asserts the
// output is a link
ResolveLink(path []string) (*Link, []string, error)
// Copy returns a deep copy of this node
Copy() Node
// Links is a helper function that returns all links within this object
Links() []*Link
// TODO: not sure if stat deserves to stay
Stat() (*NodeStat, error)
// Size returns the size in bytes of the serialized object
Size() (uint64, error)
}
Node is the base interface all IPLD nodes must implement.
Nodes are **Immutable** and all methods defined on the interface are **Thread Safe**.
type NodeGetter ¶
type NodeGetter interface {
// Get retrieves nodes by CID. Depending on the NodeGetter
// implementation, this may involve fetching the Node from a remote
// machine; consider setting a deadline in the context.
Get(context.Context, *cid.Cid) (Node, error)
// GetMany returns a channel of NodeOptions given a set of CIDs.
GetMany(context.Context, []*cid.Cid) <-chan *NodeOption
}
The basic Node resolution service.
type NodeOption ¶ added in v0.5.3
Either a node or an error.
type NodePromise ¶ added in v0.5.3
type NodePromise struct {
// contains filtered or unexported fields
}
func GetDAG ¶ added in v0.5.3
func GetDAG(ctx context.Context, ds NodeGetter, root Node) []*NodePromise
GetDAG will fill out all of the links of the given Node. It returns an array of NodePromise with the linked nodes all in the proper order.
func GetNodes ¶ added in v0.5.3
func GetNodes(ctx context.Context, ds NodeGetter, keys []*cid.Cid) []*NodePromise
GetNodes returns an array of 'FutureNode' promises, with each corresponding to the key with the same index as the passed in keys
func NewNodePromise ¶ added in v0.5.3
func NewNodePromise(ctx context.Context) *NodePromise
NodePromise 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.
Thread Safety: This is multiple-consumer/single-producer safe.
func (*NodePromise) Fail ¶ added in v0.5.3
func (np *NodePromise) Fail(err error)
Call this function to fail a promise.
Once a promise has been failed or fulfilled, further attempts to fail it will be silently dropped.
func (*NodePromise) Get ¶ added in v0.5.3
func (np *NodePromise) Get(ctx context.Context) (Node, error)
Get the value of this promise.
This function is safe to call concurrently from any number of goroutines.
func (*NodePromise) Send ¶ added in v0.5.3
func (np *NodePromise) Send(nd Node)
Fulfill this promise.
Once a promise has been fulfilled or failed, calling this function will panic.
type NodeStat ¶
type NodeStat struct {
Hash string
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.
type Resolver ¶ added in v0.4.6
type Resolver interface {
// Resolve resolves a path through this node, stopping at any link boundary
// and returning the object found as well as the remaining path to traverse
Resolve(path []string) (interface{}, []string, error)
// Tree lists all paths within the object under 'path', and up to the given depth.
// To list the entire object (similar to `find .`) pass "" and -1
Tree(path string, depth int) []string
}