mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-26 12:57:44 +08:00
fix issues in merkledag
This commit is contained in:
parent
d721c448af
commit
4cc1780705
@ -115,6 +115,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
|
||||
Config: cfg,
|
||||
}
|
||||
n.ContextCloser = ctxc.NewContextCloser(ctx, n.teardown)
|
||||
ctx = n.Context()
|
||||
|
||||
// setup datastore.
|
||||
if n.Datastore, err = makeDatastore(cfg.Datastore); err != nil {
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
|
||||
bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
|
||||
@ -54,7 +52,6 @@ func (bsnet *impl) HandleMessage(
|
||||
|
||||
// TODO(brian): put this in a helper function
|
||||
if bsmsg == nil || p == nil {
|
||||
bsnet.receiver.ReceiveError(errors.New("ReceiveMessage returned nil peer or message"))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -163,17 +163,6 @@ func (n *Node) Multihash() (mh.Multihash, error) {
|
||||
return n.cached, nil
|
||||
}
|
||||
|
||||
// Searches this nodes links for one to the given key,
|
||||
// returns the index of said link
|
||||
func (n *Node) FindLink(k u.Key) (int, error) {
|
||||
for i, lnk := range n.Links {
|
||||
if u.Key(lnk.Hash) == k {
|
||||
return i, nil
|
||||
}
|
||||
}
|
||||
return -1, u.ErrNotFound
|
||||
}
|
||||
|
||||
// Key returns the Multihash as a key, for maps.
|
||||
func (n *Node) Key() (u.Key, error) {
|
||||
h, err := n.Multihash()
|
||||
@ -298,6 +287,17 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
|
||||
return done
|
||||
}
|
||||
|
||||
// Searches this nodes links for one to the given key,
|
||||
// returns the index of said link
|
||||
func FindLink(n *Node, k u.Key, found []*Node) (int, error) {
|
||||
for i, lnk := range n.Links {
|
||||
if u.Key(lnk.Hash) == k && found[i] == nil {
|
||||
return i, nil
|
||||
}
|
||||
}
|
||||
return -1, u.ErrNotFound
|
||||
}
|
||||
|
||||
// BatchFetch will fill out all of the links of the given Node.
|
||||
// It returns a channel of nodes, which the caller can receive
|
||||
// all the child nodes of 'root' on, in proper order.
|
||||
@ -324,7 +324,7 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
|
||||
count := 0
|
||||
for blk := range blkchan {
|
||||
count++
|
||||
i, err := root.FindLink(blk.Key())
|
||||
i, err := FindLink(root, blk.Key(), nodes)
|
||||
if err != nil {
|
||||
panic("Received block that wasnt in this nodes links!")
|
||||
}
|
||||
@ -356,3 +356,14 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
|
||||
|
||||
return sig
|
||||
}
|
||||
|
||||
func checkForDupes(ks []u.Key) bool {
|
||||
seen := make(map[u.Key]struct{})
|
||||
for _, k := range ks {
|
||||
if _, ok := seen[k]; ok {
|
||||
return true
|
||||
}
|
||||
seen[k] = struct{}{}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user