shuffle peers

This commit is contained in:
vyzo 2018-02-20 14:00:33 +02:00 committed by Steven Allen
parent 8fbc4e1c70
commit 64d35994d1
1 changed files with 6 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package floodsub
import ( import (
"context" "context"
"math/rand"
"time" "time"
pb "github.com/libp2p/go-floodsub/pb" pb "github.com/libp2p/go-floodsub/pb"
@ -350,7 +351,7 @@ func (gs *GossipSubRouter) heartbeat() {
} }
} }
// do we have too many peers // do we have too many peers?
if len(peers) > GossipSubDhi { if len(peers) > GossipSubDhi {
idontneed := len(peers) - GossipSubD idontneed := len(peers) - GossipSubD
plst := peerMapToList(peers) plst := peerMapToList(peers)
@ -526,7 +527,6 @@ func (gs *GossipSubRouter) getPeers(topic string, filter func(peer.ID) bool) []p
} }
shufflePeers(peers) shufflePeers(peers)
return peers return peers
} }
@ -547,5 +547,8 @@ func peerMapToList(peers map[peer.ID]struct{}) []peer.ID {
} }
func shufflePeers(peers []peer.ID) { func shufflePeers(peers []peer.ID) {
// TODO for i := range peers {
j := rand.Intn(i + 1)
peers[i], peers[j] = peers[j], peers[i]
}
} }