-
Notifications
You must be signed in to change notification settings - Fork 42
/
merkledag.go
63 lines (49 loc) · 1.75 KB
/
merkledag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package format
import (
"context"
"fmt"
cid "github.com/ipfs/fs-repo-migrations/ipfs-6-to-7/gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
)
var ErrNotFound = fmt.Errorf("merkledag: not found")
// Either a node or an error.
type NodeOption struct {
Node Node
Err error
}
// The basic Node resolution service.
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
}
// NodeGetters can optionally implement this interface to make finding linked
// objects faster.
type LinkGetter interface {
NodeGetter
// TODO(ipfs/go-ipld-format#9): This should return []*cid.Cid
// GetLinks returns the children of the node refered to by the given
// CID.
GetLinks(ctx context.Context, nd *cid.Cid) ([]*Link, error)
}
// DAGService is an IPFS Merkle DAG service.
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
}