This commit is contained in:
cui 2026-06-18 19:43:54 +00:00 committed by GitHub
commit adbfe9bbb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -91,15 +91,9 @@ func (s *stun) ExternalIP() (net.IP, error) {
func (s *stun) randomServers(n int) []string { func (s *stun) randomServers(n int) []string {
n = min(n, len(s.serverList)) n = min(n, len(s.serverList))
m := make(map[int]struct{}, n)
list := make([]string, 0, n) list := make([]string, 0, n)
for i := 0; i < len(s.serverList)*2 && len(list) < n; i++ { for _, index := range rand.Perm(len(s.serverList))[:n] {
index := rand.Intn(len(s.serverList))
if _, alreadyHit := m[index]; alreadyHit {
continue
}
list = append(list, s.serverList[index]) list = append(list, s.serverList[index])
m[index] = struct{}{}
} }
return list return list
} }