Commit c52fb3be authored by Jeromy's avatar Jeromy

a little more correctness on the new bitswap impl

parent d651a376
...@@ -163,6 +163,17 @@ func (n *Node) Multihash() (mh.Multihash, error) { ...@@ -163,6 +163,17 @@ func (n *Node) Multihash() (mh.Multihash, error) {
return n.cached, nil 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. // Key returns the Multihash as a key, for maps.
func (n *Node) Key() (u.Key, error) { func (n *Node) Key() (u.Key, error) {
h, err := n.Multihash() h, err := n.Multihash()
...@@ -296,6 +307,10 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node { ...@@ -296,6 +307,10 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
var keys []u.Key var keys []u.Key
nodes := make([]*Node, len(root.Links)) nodes := make([]*Node, len(root.Links))
//temp
recvd := []int{}
//
// //
next := 0 next := 0
// //
...@@ -306,28 +321,36 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node { ...@@ -306,28 +321,36 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
blkchan := ds.Blocks.GetBlocks(ctx, keys) blkchan := ds.Blocks.GetBlocks(ctx, keys)
count := 0
for blk := range blkchan { for blk := range blkchan {
for i, lnk := range root.Links { count++
if u.Key(lnk.Hash) != blk.Key() { i, err := root.FindLink(blk.Key())
continue if err != nil {
} panic("Received block that wasnt in this nodes links!")
}
nd, err := Decoded(blk.Data) recvd = append(recvd, i)
if err != nil {
log.Error("Got back bad block!") nd, err := Decoded(blk.Data)
break if err != nil {
} log.Error("Got back bad block!")
nodes[i] = nd break
}
if next == i { nodes[i] = nd
sig <- nd
next++ if next == i {
for ; next < len(nodes) && nodes[next] != nil; next++ { sig <- nd
sig <- nodes[next] next++
} for ; next < len(nodes) && nodes[next] != nil; next++ {
sig <- nodes[next]
} }
} }
} }
if next < len(nodes) {
log.Errorf("count = %d, links = %d", count, len(nodes))
log.Error(recvd)
panic("didnt receive all requested blocks!")
}
close(sig) close(sig)
}() }()
......
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