mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Choose a random subset from given STUN servers
Only chooses a subset as long as we have over 2 STUN servers to choose from.
This commit is contained in:
parent
eaac9f5b6b
commit
92520f681d
3 changed files with 12 additions and 3 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -77,6 +78,7 @@ func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) {
|
|||
}
|
||||
|
||||
// s is a comma-separated list of ICE server URLs.
|
||||
// chooses a random subset of servers from inputs
|
||||
func parseIceServers(s string) []webrtc.ICEServer {
|
||||
var servers []webrtc.ICEServer
|
||||
s = strings.TrimSpace(s)
|
||||
|
@ -90,6 +92,13 @@ func parseIceServers(s string) []webrtc.ICEServer {
|
|||
URLs: []string{url},
|
||||
})
|
||||
}
|
||||
rand.Seed(time.Now().Unix())
|
||||
rand.Shuffle(len(servers), func(i, j int) {
|
||||
servers[i], servers[j] = servers[j], servers[i]
|
||||
})
|
||||
if len(servers) > 2 {
|
||||
servers = servers[:len(servers)/2]
|
||||
}
|
||||
return servers
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue