@cryptotaxi247 / kubo / commits / 88f5be3f0

test(bitswap:testnet) shuffle the providers

to avoid letting client rely on order for correctness

Brian Tiger Chow committed Sep 19, 2014 at 18:16 UTC 88f5be3f0d5e172c05992920528564398a04d6cc
1 file changed +7
exchange/bitswap/testnet/routing.go
+7
@@ -2,6 +2,7 @@ package bitswap
2
3 import (
4 "errors"
5 + "math/rand"
6 "sync"
7
8 context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
@@ -58,6 +59,12 @@ func (rs *hashTable) Providers(k u.Key) []*peer.Peer {
59 for _, peer := range peerset {
60 ret = append(ret, peer)
61 }
62 +
63 + for i := range ret {
64 + j := rand.Intn(i + 1)
65 + ret[i], ret[j] = ret[j], ret[i]
66 + }
67 +
68 return ret
69 }
70