shuffle peers when limiting px set
This commit is contained in:
parent
e4667b6073
commit
efb09f2984
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue