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 { ...@@ -77,8 +77,8 @@ func (n *dagService) AddRecursive(nd *Node) error {
} }
for _, link := range nd.Links { for _, link := range nd.Links {
if link.Node != nil { if link.node != nil {
err := n.AddRecursive(link.Node) err := n.AddRecursive(link.node)
if err != nil { if err != nil {
return err return err
} }
...@@ -110,8 +110,8 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) { ...@@ -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 // Remove deletes the given node and all of its children from the BlockService
func (n *dagService) RemoveRecursive(nd *Node) error { func (n *dagService) RemoveRecursive(nd *Node) error {
for _, l := range nd.Links { for _, l := range nd.Links {
if l.Node != nil { if l.node != nil {
n.RemoveRecursive(l.Node) n.RemoveRecursive(l.node)
} }
} }
k, err := nd.Key() k, err := nd.Key()
......
...@@ -5,8 +5,8 @@ import ( ...@@ -5,8 +5,8 @@ import (
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
key "github.com/ipfs/go-ipfs/blocks/key" key "github.com/ipfs/go-ipfs/blocks/key"
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
) )
var ErrLinkNotFound = fmt.Errorf("no link by that name") var ErrLinkNotFound = fmt.Errorf("no link by that name")
...@@ -50,7 +50,7 @@ type Link struct { ...@@ -50,7 +50,7 @@ type Link struct {
Hash mh.Multihash Hash mh.Multihash
// a ptr to the actual node for graph manipulation // a ptr to the actual node for graph manipulation
Node *Node node *Node
} }
type LinkSlice []*Link type LinkSlice []*Link
...@@ -78,13 +78,13 @@ func MakeLink(n *Node) (*Link, error) { ...@@ -78,13 +78,13 @@ func MakeLink(n *Node) (*Link, error) {
// GetCachedNode returns the MDAG Node that was cached, or nil // GetCachedNode returns the MDAG Node that was cached, or nil
func (l *Link) GetCachedNode() *Node { func (l *Link) GetCachedNode() *Node {
return l.Node return l.node
} }
// GetNode returns the MDAG Node that this link points to // GetNode returns the MDAG Node that this link points to
func (l *Link) GetNode(ctx context.Context, serv DAGService) (*Node, error) { func (l *Link) GetNode(ctx context.Context, serv DAGService) (*Node, error) {
if l.Node != nil { if l.node != nil {
return l.Node, nil return l.node, nil
} }
return serv.Get(ctx, key.Key(l.Hash)) return serv.Get(ctx, key.Key(l.Hash))
...@@ -94,15 +94,15 @@ func (l *Link) GetNode(ctx context.Context, serv DAGService) (*Node, error) { ...@@ -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 // 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. // timeout is to be specified to avoid taking too much time.
func (l *Link) GetNodeAndCache(ctx context.Context, serv DAGService) (*Node, error) { 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)) nd, err := serv.Get(ctx, key.Key(l.Hash))
if err != nil { if err != nil {
return nil, err return nil, err
} }
l.Node = nd l.node = nd
} }
return l.Node, nil return l.node, nil
} }
// AddNodeLink adds a link to another node. // AddNodeLink adds a link to another node.
...@@ -112,7 +112,7 @@ func (n *Node) AddNodeLink(name string, that *Node) error { ...@@ -112,7 +112,7 @@ func (n *Node) AddNodeLink(name string, that *Node) error {
lnk, err := MakeLink(that) lnk, err := MakeLink(that)
lnk.Name = name lnk.Name = name
lnk.Node = that lnk.node = that
if err != nil { if err != nil {
return err return err
} }
...@@ -142,7 +142,7 @@ func (n *Node) AddRawLink(name string, l *Link) error { ...@@ -142,7 +142,7 @@ func (n *Node) AddRawLink(name string, l *Link) error {
Name: name, Name: name,
Size: l.Size, Size: l.Size,
Hash: l.Hash, Hash: l.Hash,
Node: l.Node, node: l.node,
}) })
return nil return nil
...@@ -178,7 +178,7 @@ func (n *Node) GetNodeLink(name string) (*Link, error) { ...@@ -178,7 +178,7 @@ func (n *Node) GetNodeLink(name string) (*Link, error) {
Name: l.Name, Name: l.Name,
Size: l.Size, Size: l.Size,
Hash: l.Hash, Hash: l.Hash,
Node: l.Node, node: l.node,
}, nil }, 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