Skip to content

Commit

Permalink
shuffle peers when limiting px set
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Dec 5, 2019
1 parent a09bca2 commit 2f558ba
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,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]
}

Expand Down Expand Up @@ -896,3 +897,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]
}
}

0 comments on commit 2f558ba

Please sign in to comment.