core: bugfix: bootstrap random permutation
the random permutaton for bootstrap peers was not working as intended, returning the first four bootstrap peers always. this commit fixes it to be a random subset.
Juan Batiz-Benet committed
Apr 20, 2015 at 06:00 UTC
ce7914063f97354f647c947a1ba966b944e4a2aa
1 file changed
+4
-1
core/bootstrap.go
+4
-1
@@ -225,8 +225,11 @@ func toPeerInfo(bp config.BootstrapPeer) peer.PeerInfo {
225
func randomSubsetOfPeers(in []peer.PeerInfo, max int) []peer.PeerInfo {
226
n := math2.IntMin(max, len(in))
227
var out []peer.PeerInfo
228
- for _, val := range rand.Perm(n) {
228
+ for _, val := range rand.Perm(len(in)) {
229
out = append(out, in[val])
230
+ if len(out) >= n {
231
+ break
232
+ }
233
}
234
return out
235
}