[tor-commits] [snowflake/main] Use a config struct for snowflake client options

cohosh at torproject.org cohosh at torproject.org
Mon Aug 23 17:24:43 UTC 2021


commit 4acc08cc60d46ba1ffce9b4492b974eff385e46b
Author: Cecylia Bocovich <cohosh at torproject.org>
Date:   Fri Aug 13 10:23:46 2021 -0400

    Use a config struct for snowflake client options
---
 client/lib/snowflake.go | 20 ++++++++++++++------
 client/snowflake.go     | 11 +++++++++--
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/client/lib/snowflake.go b/client/lib/snowflake.go
index 1987cbc..8b01d88 100644
--- a/client/lib/snowflake.go
+++ b/client/lib/snowflake.go
@@ -37,17 +37,25 @@ type Transport struct {
 	dialer *WebRTCDialer
 }
 
+type ClientConfig struct {
+	BrokerURL          string
+	AmpCacheURL        string
+	FrontDomain        string
+	ICEAddresses       []string
+	KeepLocalAddresses bool
+	Max                int
+}
+
 // Create a new Snowflake transport client that can spawn multiple Snowflake connections.
 // brokerURL and frontDomain are the urls for the broker host and domain fronting host
 // iceAddresses are the STUN/TURN urls needed for WebRTC negotiation
 // keepLocalAddresses is a flag to enable sending local network addresses (for testing purposes)
 // max is the maximum number of snowflakes the client should gather for each SOCKS connection
-func NewSnowflakeClient(brokerURL, ampCacheURL, frontDomain string,
-	iceAddresses []string, keepLocalAddresses bool, max int) (*Transport, error) {
+func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
 
 	log.Println("\n\n\n --- Starting Snowflake Client ---")
 
-	iceServers := parseIceServers(iceAddresses)
+	iceServers := parseIceServers(config.ICEAddresses)
 	// chooses a random subset of servers from inputs
 	rand.Seed(time.Now().UnixNano())
 	rand.Shuffle(len(iceServers), func(i, j int) {
@@ -63,14 +71,14 @@ func NewSnowflakeClient(brokerURL, ampCacheURL, frontDomain string,
 
 	// Rendezvous with broker using the given parameters.
 	broker, err := NewBrokerChannel(
-		brokerURL, ampCacheURL, frontDomain, CreateBrokerTransport(),
-		keepLocalAddresses)
+		config.BrokerURL, config.AmpCacheURL, config.FrontDomain, CreateBrokerTransport(),
+		config.KeepLocalAddresses)
 	if err != nil {
 		return nil, err
 	}
 	go updateNATType(iceServers, broker)
 
-	transport := &Transport{dialer: NewWebRTCDialer(broker, iceServers, max)}
+	transport := &Transport{dialer: NewWebRTCDialer(broker, iceServers, config.Max)}
 
 	return transport, nil
 }
diff --git a/client/snowflake.go b/client/snowflake.go
index ef06a2d..04ebf48 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -141,8 +141,15 @@ func main() {
 
 	iceAddresses := strings.Split(strings.TrimSpace(*iceServersCommas), ",")
 
-	transport, err := sf.NewSnowflakeClient(*brokerURL, *ampCacheURL, *frontDomain, iceAddresses,
-		*keepLocalAddresses || *oldKeepLocalAddresses, *max)
+	config := sf.ClientConfig{
+		BrokerURL:          *brokerURL,
+		AmpCacheURL:        *ampCacheURL,
+		FrontDomain:        *frontDomain,
+		ICEAddresses:       iceAddresses,
+		KeepLocalAddresses: *keepLocalAddresses || *oldKeepLocalAddresses,
+		Max:                *max,
+	}
+	transport, err := sf.NewSnowflakeClient(config)
 	if err != nil {
 		log.Fatal("Failed to start snowflake transport: ", err)
 	}





More information about the tor-commits mailing list