[tor-commits] [snowflake/main] Parse SOCKS arguments and prefer over command line options

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


commit e762f58a31de9167933fbd75047a48d2e1cdeb36
Author: Cecylia Bocovich <cohosh at torproject.org>
Date:   Fri Aug 13 10:55:52 2021 -0400

    Parse SOCKS arguments and prefer over command line options
    
    Parsing the Snowflake client options from SOCKS allow us to specify
    snowflake client settings in the bridge lines.
---
 client/snowflake.go | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/client/snowflake.go b/client/snowflake.go
index 04ebf48..d6bad0e 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -10,6 +10,7 @@ import (
 	"os"
 	"os/signal"
 	"path/filepath"
+	"strconv"
 	"strings"
 	"sync"
 	"syscall"
@@ -44,7 +45,7 @@ func copyLoop(socks, sfconn io.ReadWriter) {
 }
 
 // Accept local SOCKS connections and connect to a Snowflake connection
-func socksAcceptLoop(ln *pt.SocksListener, transport *sf.Transport, shutdown chan struct{}, wg *sync.WaitGroup) {
+func socksAcceptLoop(ln *pt.SocksListener, config sf.ClientConfig, shutdown chan struct{}, wg *sync.WaitGroup) {
 	defer ln.Close()
 	for {
 		conn, err := ln.AcceptSocks()
@@ -67,6 +68,30 @@ func socksAcceptLoop(ln *pt.SocksListener, transport *sf.Transport, shutdown cha
 				return
 			}
 
+			// Check to see if our command line options are overriden by SOCKS options
+			if arg, ok := conn.Req.Args.Get("ampcache"); ok {
+				config.AmpCacheURL = arg
+			}
+			if arg, ok := conn.Req.Args.Get("front"); ok {
+				config.FrontDomain = arg
+			}
+			if arg, ok := conn.Req.Args.Get("ice"); ok {
+				config.ICEAddresses = strings.Split(strings.TrimSpace(arg), ",")
+			}
+			if arg, ok := conn.Req.Args.Get("max"); ok {
+				max, err := strconv.Atoi(arg)
+				if err == nil {
+					config.Max = max
+				}
+			}
+			if arg, ok := conn.Req.Args.Get("url"); ok {
+				config.BrokerURL = arg
+			}
+			transport, err := sf.NewSnowflakeClient(config)
+			if err != nil {
+				log.Fatal("Failed to start snowflake transport: ", err)
+			}
+
 			handler := make(chan struct{})
 			go func() {
 				defer close(handler)
@@ -149,10 +174,6 @@ func main() {
 		KeepLocalAddresses: *keepLocalAddresses || *oldKeepLocalAddresses,
 		Max:                *max,
 	}
-	transport, err := sf.NewSnowflakeClient(config)
-	if err != nil {
-		log.Fatal("Failed to start snowflake transport: ", err)
-	}
 
 	// Begin goptlib client process.
 	ptInfo, err := pt.ClientSetup(nil)
@@ -176,7 +197,7 @@ func main() {
 				break
 			}
 			log.Printf("Started SOCKS listener at %v.", ln.Addr())
-			go socksAcceptLoop(ln, transport, shutdown, &wg)
+			go socksAcceptLoop(ln, config, shutdown, &wg)
 			pt.Cmethod(methodName, ln.Version(), ln.Addr())
 			listeners = append(listeners, ln)
 		default:





More information about the tor-commits mailing list