shuffle IWANT list

This commit is contained in:
vyzo 2020-03-22 20:52:19 +02:00
parent 588f7b85c0
commit d0979258f7
1 changed files with 10 additions and 0 deletions

View File

@ -318,6 +318,9 @@ func (gs *GossipSubRouter) handleIHave(p peer.ID, ctl *pb.ControlMessage) []*pb.
iwantlst = append(iwantlst, mid) iwantlst = append(iwantlst, mid)
} }
// ask in random order
shuffleStrings(iwantlst)
return []*pb.ControlIWant{&pb.ControlIWant{MessageIDs: iwantlst}} return []*pb.ControlIWant{&pb.ControlIWant{MessageIDs: iwantlst}}
} }
@ -1151,3 +1154,10 @@ func shufflePeerInfo(peers []*pb.PeerInfo) {
peers[i], peers[j] = peers[j], peers[i] peers[i], peers[j] = peers[j], peers[i]
} }
} }
func shuffleStrings(lst []string) {
for i := range lst {
j := rand.Intn(i + 1)
lst[i], lst[j] = lst[j], lst[i]
}
}