Add some documentation on the intended purpose of GetLinks.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Feb 21, 2017 at 12:48 UTC
e4bbd246ece1179628856095177186ba8d6ef45a
1 file changed
+9
-4
merkledag/merkledag.go
+9
-4
@@ -36,8 +36,10 @@ type DAGService interface {
36
}
37
38
type LinkService interface {
39
- // Return all links for a node, may be more effect than
40
- // calling Get in DAGService
39
+ // GetLinks return all links for a node. The complete node does not
40
+ // necessarily have to exist locally, or at all. For example, raw
41
+ // leaves cannot possibly have links so there is no need to look
42
+ // at the node.
43
GetLinks(context.Context, *cid.Cid) ([]*node.Link, error)
44
45
GetOfflineLinkService() LinkService
@@ -114,6 +116,8 @@ func decodeBlock(b blocks.Block) (node.Node, error) {
116
}
117
}
118
119
+// GetLinks return the links for the node, the node doesn't necessarily have
120
+// to exist locally.
121
func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*node.Link, error) {
122
if c.Type() == cid.Raw {
123
return nil, nil
@@ -138,8 +142,9 @@ func (n *dagService) Remove(nd node.Node) error {
142
return n.Blocks.DeleteBlock(nd)
143
}
144
141
-// get the links for a node, from the node, bypassing the
142
-// LinkService
145
+// GetLinksDirect creates a function to get the links for a node, from
146
+// the node, bypassing the LinkService. If the node does not exist
147
+// locally (and can not be retrieved) an error will be returned.
148
func GetLinksDirect(serv DAGService) GetLinks {
149
return func(ctx context.Context, c *cid.Cid) ([]*node.Link, error) {
150
node, err := serv.Get(ctx, c)