merkledag: make Link.Node (the node cache) a private field
License: MIT Signed-off-by: Mildred Ki'Lya <mildred-pub.git@mildred.fr>
Mildred Ki'Lya committed
Feb 24, 2016 at 08:34 UTC
28bc3ee8ee105ac988bdb4f65d10e6962e36d5eb
3 files changed
+16
-17
merkledag/merkledag.go
+4
-4
@@ -77,8 +77,8 @@ func (n *dagService) AddRecursive(nd *Node) error {
77
}
78
79
for _, link := range nd.Links {
80
- if link.Node != nil {
81
- err := n.AddRecursive(link.Node)
80
+ if link.node != nil {
81
+ err := n.AddRecursive(link.node)
82
if err != nil {
83
return err
84
}
@@ -110,8 +110,8 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
110
// Remove deletes the given node and all of its children from the BlockService
111
func (n *dagService) RemoveRecursive(nd *Node) error {
112
for _, l := range nd.Links {
113
- if l.Node != nil {
114
- n.RemoveRecursive(l.Node)
113
+ if l.node != nil {
114
+ n.RemoveRecursive(l.node)
115
}
116
}
117
k, err := nd.Key()
merkledag/node.go
+11
-11
@@ -5,8 +5,8 @@ import (
5
6
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
7
8
- mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
8
key "github.com/ipfs/go-ipfs/blocks/key"
9
+ mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
10
)
11
12
var ErrLinkNotFound = fmt.Errorf("no link by that name")
@@ -50,7 +50,7 @@ type Link struct {
50
Hash mh.Multihash
51
52
// a ptr to the actual node for graph manipulation
53
- Node *Node
53
+ node *Node
54
}
55
56
type LinkSlice []*Link
@@ -78,13 +78,13 @@ func MakeLink(n *Node) (*Link, error) {
78
79
// GetCachedNode returns the MDAG Node that was cached, or nil
80
func (l *Link) GetCachedNode() *Node {
81
- return l.Node
81
+ return l.node
82
}
83
84
// GetNode returns the MDAG Node that this link points to
85
func (l *Link) GetNode(ctx context.Context, serv DAGService) (*Node, error) {
86
- if l.Node != nil {
87
- return l.Node, nil
86
+ if l.node != nil {
87
+ return l.node, nil
88
}
89
90
return serv.Get(ctx, key.Key(l.Hash))
@@ -94,15 +94,15 @@ func (l *Link) GetNode(ctx context.Context, serv DAGService) (*Node, error) {
94
// pointer to that node along with the link to speed up further retrivals. A
95
// timeout is to be specified to avoid taking too much time.
96
func (l *Link) GetNodeAndCache(ctx context.Context, serv DAGService) (*Node, error) {
97
- if l.Node == nil {
97
+ if l.node == nil {
98
nd, err := serv.Get(ctx, key.Key(l.Hash))
99
if err != nil {
100
return nil, err
101
}
102
- l.Node = nd
102
+ l.node = nd
103
}
104
105
- return l.Node, nil
105
+ return l.node, nil
106
}
107
108
// AddNodeLink adds a link to another node.
@@ -112,7 +112,7 @@ func (n *Node) AddNodeLink(name string, that *Node) error {
112
lnk, err := MakeLink(that)
113
114
lnk.Name = name
115
- lnk.Node = that
115
+ lnk.node = that
116
if err != nil {
117
return err
118
}
@@ -142,7 +142,7 @@ func (n *Node) AddRawLink(name string, l *Link) error {
142
Name: name,
143
Size: l.Size,
144
Hash: l.Hash,
145
- Node: l.Node,
145
+ node: l.node,
146
})
147
148
return nil
@@ -178,7 +178,7 @@ func (n *Node) GetNodeLink(name string) (*Link, error) {
178
Name: l.Name,
179
Size: l.Size,
180
Hash: l.Hash,
181
- Node: l.Node,
181
+ node: l.node,
182
}, nil
183
}
184
}
pin/set.go
+1
-2
@@ -11,10 +11,10 @@ import (
11
"sort"
12
"unsafe"
13
14
- "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
14
"github.com/ipfs/go-ipfs/blocks/key"
15
"github.com/ipfs/go-ipfs/merkledag"
16
"github.com/ipfs/go-ipfs/pin/internal/pb"
17
+ "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
18
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
19
)
20
@@ -172,7 +172,6 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
172
Name: "",
173
Hash: childKey.ToMultihash(),
174
Size: size,
175
- Node: child,
175
}
176
n.Links[int(h%defaultFanout)] = l
177
}