shuffle peers when limiting px set

This commit is contained in:
vyzo 2019-12-05 21:01:37 +02:00
parent e4667b6073
commit efb09f2984
1 changed files with 8 additions and 0 deletions

View File

@ -289,6 +289,7 @@ func (gs *GossipSubRouter) addBackoff(p peer.ID, topic string) {
func (gs *GossipSubRouter) pxConnect(peers []*pb.PeerInfo) {
if len(peers) > GossipSubPrunePeers {
shufflePeerInfo(peers)
peers = peers[:GossipSubPrunePeers]
}
@ -898,3 +899,10 @@ func shufflePeers(peers []peer.ID) {
peers[i], peers[j] = peers[j], peers[i]
}
}
func shufflePeerInfo(peers []*pb.PeerInfo) {
for i := range peers {
j := rand.Intn(i + 1)
peers[i], peers[j] = peers[j], peers[i]
}
}