[tor-commits] [snowflake/master] Choose a random subset from given STUN servers

cohosh at torproject.org cohosh at torproject.org
Fri Jul 24 18:22:51 UTC 2020


commit 92520f681d77127fb7dd6e578080f1351ae885a8
Author: Cecylia Bocovich <cohosh at torproject.org>
Date:   Thu Jul 23 09:28:21 2020 -0400

    Choose a random subset from given STUN servers
    
    Only chooses a subset as long as we have over 2 STUN servers to choose
    from.
---
 client/client_test.go | 4 ++--
 client/snowflake.go   | 9 +++++++++
 client/torrc          | 2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/client/client_test.go b/client/client_test.go
index aeaf979..84e9cc1 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -49,8 +49,8 @@ func TestICEServerParser(t *testing.T) {
 
 			So(len(servers), ShouldEqual, test.length)
 
-			for i, server := range servers {
-				So(server.URLs, ShouldResemble, test.urls[i])
+			for _, server := range servers {
+				So(test.urls, ShouldContain, server.URLs)
 			}
 
 		}
diff --git a/client/snowflake.go b/client/snowflake.go
index 02bbf1e..c05431b 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -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
 }
 
diff --git a/client/torrc b/client/torrc
index 9e3946e..813d22d 100644
--- a/client/torrc
+++ b/client/torrc
@@ -4,7 +4,7 @@ DataDirectory datadir
 ClientTransportPlugin snowflake exec ./client \
 -url https://snowflake-broker.azureedge.net/ \
 -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
 
 Bridge snowflake 192.0.2.3:1





More information about the tor-commits mailing list