shuffle IWANT list
This commit is contained in:
parent
588f7b85c0
commit
d0979258f7
10
gossipsub.go
10
gossipsub.go
@ -318,6 +318,9 @@ func (gs *GossipSubRouter) handleIHave(p peer.ID, ctl *pb.ControlMessage) []*pb.
|
||||
iwantlst = append(iwantlst, mid)
|
||||
}
|
||||
|
||||
// ask in random order
|
||||
shuffleStrings(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]
|
||||
}
|
||||
}
|
||||
|
||||
func shuffleStrings(lst []string) {
|
||||
for i := range lst {
|
||||
j := rand.Intn(i + 1)
|
||||
lst[i], lst[j] = lst[j], lst[i]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user