[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake/main] Modify handling of misconfigurations and defaults
commit 3caa83d84de681b3cd38f4c61cfef2e9bd091176
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date: Tue Oct 26 15:40:32 2021 -0400
Modify handling of misconfigurations and defaults
---
proxy/lib/snowflake.go | 34 ++++++++++++++++++++--------------
proxy/main.go | 8 ++++++--
2 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go
index bd50dc8..734657a 100644
--- a/proxy/lib/snowflake.go
+++ b/proxy/lib/snowflake.go
@@ -15,7 +15,8 @@ You may then start and stop the proxy. Stopping the proxy will close existing co
the proxy will not poll for more clients.
go func() {
- proxy.Start()
+ err := proxy.Start()
+ // handle error
}
// ...
@@ -46,16 +47,12 @@ import (
"github.com/pion/webrtc/v3"
)
-// DefaultBrokerURL is the snowflake broker run at https://snowflake-broker.torproject.net
const DefaultBrokerURL = "https://snowflake-broker.torproject.net/"
-// DefaultProbeURL is run at https://snowflake-broker.torproject.net:8443/probe
const DefaultProbeURL = "https://snowflake-broker.torproject.net:8443/probe"
-// DefaultRelayURL is run at wss://snowflake.torproject.net
const DefaultRelayURL = "wss://snowflake.bamsoftware.com/"
-// DefaultSTUNURL is run at stun:stun.stunprotocol.org:3478
const DefaultSTUNURL = "stun:stun.stunprotocol.org:3478"
const pollInterval = 5 * time.Second
@@ -486,27 +483,35 @@ func (sf *SnowflakeProxy) runSession(sid string) {
// Start configures and starts a Snowflake, fully formed and special. Configuration
// values that are unset will default to their corresponding default values.
-func (sf *SnowflakeProxy) Start() {
+func (sf *SnowflakeProxy) Start() error {
+ var err error
+ log.Println("starting")
sf.shutdown = make(chan struct{})
- log.SetFlags(log.LstdFlags | log.LUTC)
-
- log.Println("starting")
+ // blank configurations revert to default
+ if sf.BrokerURL == "" {
+ sf.BrokerURL = DefaultBrokerURL
+ }
+ if sf.RelayURL == "" {
+ sf.RelayURL = DefaultRelayURL
+ }
+ if sf.STUNURL == "" {
+ sf.STUNURL = DefaultSTUNURL
+ }
- var err error
broker, err = newSignalingServer(sf.BrokerURL, sf.KeepLocalAddresses)
if err != nil {
- log.Fatal(err)
+ return fmt.Errorf("error configuring broker: %s", err)
}
_, err = url.Parse(sf.STUNURL)
if err != nil {
- log.Fatalf("invalid stun url: %s", err)
+ return fmt.Errorf("invalid stun url: %s", err)
}
_, err = url.Parse(sf.RelayURL)
if err != nil {
- log.Fatalf("invalid relay url: %s", err)
+ return fmt.Errorf("invalid relay url: %s", err)
}
config = webrtc.Configuration{
@@ -528,13 +533,14 @@ func (sf *SnowflakeProxy) Start() {
for ; true; <-ticker.C {
select {
case <-sf.shutdown:
- return
+ return nil
default:
tokens.get()
sessionID := genSessionID()
sf.runSession(sessionID)
}
}
+ return nil
}
// Stop closes all existing connections and shuts down the Snowflake.
diff --git a/proxy/main.go b/proxy/main.go
index aabac51..368589c 100644
--- a/proxy/main.go
+++ b/proxy/main.go
@@ -11,7 +11,7 @@ import (
)
func main() {
- capacity := flag.Int("capacity", 10, "maximum concurrent clients")
+ capacity := flag.Uint("capacity", 0, "maximum concurrent clients")
stunURL := flag.String("stun", sf.DefaultSTUNURL, "broker URL")
logFilename := flag.String("log", "", "log filename")
rawBrokerURL := flag.String("broker", sf.DefaultBrokerURL, "broker URL")
@@ -32,6 +32,7 @@ func main() {
var logOutput io.Writer = os.Stderr
log.SetFlags(log.LstdFlags | log.LUTC)
+ log.SetFlags(log.LstdFlags | log.LUTC)
if *logFilename != "" {
f, err := os.OpenFile(*logFilename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
@@ -46,5 +47,8 @@ func main() {
log.SetOutput(&safelog.LogScrubber{Output: logOutput})
}
- proxy.Start()
+ err := proxy.Start()
+ if err != nil {
+ log.Fatal(err)
+ }
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits