From 28bc3ee8ee105ac988bdb4f65d10e6962e36d5eb Mon Sep 17 00:00:00 2001 From: Mildred Ki'Lya Date: Wed, 24 Feb 2016 08:34:32 +0100 Subject: [PATCH] merkledag: make Link.Node (the node cache) a private field License: MIT Signed-off-by: Mildred Ki'Lya --- merkledag/merkledag.go | 8 ++++---- merkledag/node.go | 22 +++++++++++----------- pin/set.go | 3 +-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/merkledag/merkledag.go b/merkledag/merkledag.go index 0152a5afc..83d363677 100644 --- a/merkledag/merkledag.go +++ b/merkledag/merkledag.go @@ -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() diff --git a/merkledag/node.go b/merkledag/node.go index ed503d312..e0e282dba 100644 --- a/merkledag/node.go +++ b/merkledag/node.go @@ -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 } } diff --git a/pin/set.go b/pin/set.go index f3d825818..669fa7a60 100644 --- a/pin/set.go +++ b/pin/set.go @@ -11,10 +11,10 @@ import ( "sort" "unsafe" - "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/merkledag" "github.com/ipfs/go-ipfs/pin/internal/pb" + "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) @@ -172,7 +172,6 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint Name: "", Hash: childKey.ToMultihash(), Size: size, - Node: child, } n.Links[int(h%defaultFanout)] = l }