mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 18:13:54 +08:00
merkledag: make Link.Node (the node cache) a private field
License: MIT Signed-off-by: Mildred Ki'Lya <mildred-pub.git@mildred.fr>
This commit is contained in:
@ -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) {
|
|||||||
// 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 (
|
|||||||
|
|
||||||
"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 {
|
|||||||
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) {
|
|||||||
|
|
||||||
// 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) {
|
|||||||
// 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 {
|
|||||||
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 {
|
|||||||
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) {
|
|||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,10 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
|
||||||
"github.com/ipfs/go-ipfs/blocks/key"
|
"github.com/ipfs/go-ipfs/blocks/key"
|
||||||
"github.com/ipfs/go-ipfs/merkledag"
|
"github.com/ipfs/go-ipfs/merkledag"
|
||||||
"github.com/ipfs/go-ipfs/pin/internal/pb"
|
"github.com/ipfs/go-ipfs/pin/internal/pb"
|
||||||
|
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
||||||
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
|
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -172,7 +172,6 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
|
|||||||
Name: "",
|
Name: "",
|
||||||
Hash: childKey.ToMultihash(),
|
Hash: childKey.ToMultihash(),
|
||||||
Size: size,
|
Size: size,
|
||||||
Node: child,
|
|
||||||
}
|
}
|
||||||
n.Links[int(h%defaultFanout)] = l
|
n.Links[int(h%defaultFanout)] = l
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user