Commit da9cdfdc authored by Mildred Ki'Lya's avatar Mildred Ki'Lya

merkledag: make Link.Node (the node cache) a private field

License: MIT
Signed-off-by: default avatarMildred Ki'Lya <mildred-pub.git@mildred.fr>
parent ec4cec0c
......@@ -77,8 +77,8 @@ func (n *dagService) AddRecursive(nd *Node) error {
}
for _, link := range nd.Links {
if link.Node != nil {
err := n.AddRecursive(link.Node)
if link.node != nil {
err := n.AddRecursive(link.node)
if err != nil {
return err
}
......@@ -110,8 +110,8 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
// Remove deletes the given node and all of its children from the BlockService
func (n *dagService) RemoveRecursive(nd *Node) error {
for _, l := range nd.Links {
if l.Node != nil {
n.RemoveRecursive(l.Node)
if l.node != nil {
n.RemoveRecursive(l.node)
}
}
k, err := nd.Key()
......
......@@ -5,8 +5,8 @@ import (
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
key "github.com/ipfs/go-ipfs/blocks/key"
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
)
var ErrLinkNotFound = fmt.Errorf("no link by that name")
......@@ -50,7 +50,7 @@ type Link struct {
Hash mh.Multihash
// a ptr to the actual node for graph manipulation
Node *Node
node *Node
}
type LinkSlice []*Link
......@@ -78,13 +78,13 @@ func MakeLink(n *Node) (*Link, error) {
// GetCachedNode returns the MDAG Node that was cached, or nil
func (l *Link) GetCachedNode() *Node {
return l.Node
return l.node
}
// GetNode returns the MDAG Node that this link points to
func (l *Link) GetNode(ctx context.Context, serv DAGService) (*Node, error) {
if l.Node != nil {
return l.Node, nil
if l.node != nil {
return l.node, nil
}
return serv.Get(ctx, key.Key(l.Hash))
......@@ -94,15 +94,15 @@ func (l *Link) GetNode(ctx context.Context, serv DAGService) (*Node, error) {
// pointer to that node along with the link to speed up further retrivals. A
// timeout is to be specified to avoid taking too much time.
func (l *Link) GetNodeAndCache(ctx context.Context, serv DAGService) (*Node, error) {
if l.Node == nil {
if l.node == nil {
nd, err := serv.Get(ctx, key.Key(l.Hash))
if err != nil {
return nil, err
}
l.Node = nd
l.node = nd
}
return l.Node, nil
return l.node, nil
}
// AddNodeLink adds a link to another node.
......@@ -112,7 +112,7 @@ func (n *Node) AddNodeLink(name string, that *Node) error {
lnk, err := MakeLink(that)
lnk.Name = name
lnk.Node = that
lnk.node = that
if err != nil {
return err
}
......@@ -142,7 +142,7 @@ func (n *Node) AddRawLink(name string, l *Link) error {
Name: name,
Size: l.Size,
Hash: l.Hash,
Node: l.Node,
node: l.node,
})
return nil
......@@ -178,7 +178,7 @@ func (n *Node) GetNodeLink(name string) (*Link, error) {
Name: l.Name,
Size: l.Size,
Hash: l.Hash,
Node: l.Node,
node: l.node,
}, nil
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment