@cryptotaxi247 / kubo / commits / 4cc178070

fix issues in merkledag

Jeromy committed Nov 24, 2014 at 08:28 UTC 4cc1780705c3c627a2feee8be12731ebf1b287df
3 files changed +24 -15
core/core.go
+1
@@ -115,6 +115,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
115 Config: cfg,
116 }
117 n.ContextCloser = ctxc.NewContextCloser(ctx, n.teardown)
118 + ctx = n.Context()
119
120 // setup datastore.
121 if n.Datastore, err = makeDatastore(cfg.Datastore); err != nil {
exchange/bitswap/network/ipfs_impl.go
-3
@@ -1,8 +1,6 @@
1 package network
2
3 import (
4 - "errors"
5 -
4 context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
5
6 bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
@@ -54,7 +52,6 @@ func (bsnet *impl) HandleMessage(
52
53 // TODO(brian): put this in a helper function
54 if bsmsg == nil || p == nil {
57 - bsnet.receiver.ReceiveError(errors.New("ReceiveMessage returned nil peer or message"))
55 return nil
56 }
57
merkledag/merkledag.go
+23 -12
@@ -163,17 +163,6 @@ func (n *Node) Multihash() (mh.Multihash, error) {
163 return n.cached, nil
164 }
165
166 -// Searches this nodes links for one to the given key,
167 -// returns the index of said link
168 -func (n *Node) FindLink(k u.Key) (int, error) {
169 - for i, lnk := range n.Links {
170 - if u.Key(lnk.Hash) == k {
171 - return i, nil
172 - }
173 - }
174 - return -1, u.ErrNotFound
175 -}
176 -
166 // Key returns the Multihash as a key, for maps.
167 func (n *Node) Key() (u.Key, error) {
168 h, err := n.Multihash()
@@ -298,6 +287,17 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
287 return done
288 }
289
290 +// Searches this nodes links for one to the given key,
291 +// returns the index of said link
292 +func FindLink(n *Node, k u.Key, found []*Node) (int, error) {
293 + for i, lnk := range n.Links {
294 + if u.Key(lnk.Hash) == k && found[i] == nil {
295 + return i, nil
296 + }
297 + }
298 + return -1, u.ErrNotFound
299 +}
300 +
301 // BatchFetch will fill out all of the links of the given Node.
302 // It returns a channel of nodes, which the caller can receive
303 // 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 {
324 count := 0
325 for blk := range blkchan {
326 count++
327 - i, err := root.FindLink(blk.Key())
327 + i, err := FindLink(root, blk.Key(), nodes)
328 if err != nil {
329 panic("Received block that wasnt in this nodes links!")
330 }
@@ -356,3 +356,14 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
356
357 return sig
358 }
359 +
360 +func checkForDupes(ks []u.Key) bool {
361 + seen := make(map[u.Key]struct{})
362 + for _, k := range ks {
363 + if _, ok := seen[k]; ok {
364 + return true
365 + }
366 + seen[k] = struct{}{}
367 + }
368 + return false
369 +}