mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -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
|
@ -49,8 +49,8 @@ func TestICEServerParser(t *testing.T) {
|
||||||
|
|
||||||
So(len(servers), ShouldEqual, test.length)
|
So(len(servers), ShouldEqual, test.length)
|
||||||
|
|
||||||
for i, server := range servers {
|
for _, server := range servers {
|
||||||
So(server.URLs, ShouldResemble, test.urls[i])
|
So(test.urls, ShouldContain, server.URLs)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -77,6 +78,7 @@ func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// s is a comma-separated list of ICE server URLs.
|
// s is a comma-separated list of ICE server URLs.
|
||||||
|
// chooses a random subset of servers from inputs
|
||||||
func parseIceServers(s string) []webrtc.ICEServer {
|
func parseIceServers(s string) []webrtc.ICEServer {
|
||||||
var servers []webrtc.ICEServer
|
var servers []webrtc.ICEServer
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
|
@ -90,6 +92,13 @@ func parseIceServers(s string) []webrtc.ICEServer {
|
||||||
URLs: []string{url},
|
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
|
return servers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ DataDirectory datadir
|
||||||
ClientTransportPlugin snowflake exec ./client \
|
ClientTransportPlugin snowflake exec ./client \
|
||||||
-url https://snowflake-broker.azureedge.net/ \
|
-url https://snowflake-broker.azureedge.net/ \
|
||||||
-front ajax.aspnetcdn.com \
|
-front ajax.aspnetcdn.com \
|
||||||
-ice stun:stun.l.google.com:19302 \
|
-ice stun:stun.voip.blackberry.com:3478,stun:stun.altar.com.pl:3478,stun:stun.antisip.com:3478,stun:stun.bluesip.net:3478,stun:stun.dus.net:3478,stun:stun.epygi.com:3478,stun:stun.sonetel.com:3478,stun:stun.sonetel.net:3478,stun:stun.stunprotocol.org:3478,stun:stun.uls.co.za:3478,stun:stun.voipgate.com:3478,stun:stun.voys.nl:3478 \
|
||||||
-max 3
|
-max 3
|
||||||
|
|
||||||
Bridge snowflake 192.0.2.3:1
|
Bridge snowflake 192.0.2.3:1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue