[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake/main] Comment package and minor changes exports
commit 84e8a183e59d0e4cea3dd572e87a221379d968f9
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date: Tue Oct 26 15:10:59 2021 -0400
Comment package and minor changes exports
---
proxy/lib/proxy-go_test.go | 2 +-
proxy/lib/snowflake.go | 36 +++++++++++++++++++++++++++++-------
proxy/lib/tokens.go | 2 +-
proxy/lib/tokens_test.go | 2 +-
proxy/lib/util.go | 2 +-
proxy/lib/webrtcconn.go | 2 +-
proxy/main.go | 26 ++++++++++++++------------
7 files changed, 48 insertions(+), 24 deletions(-)
diff --git a/proxy/lib/proxy-go_test.go b/proxy/lib/proxy-go_test.go
index af71648..3a81a1b 100644
--- a/proxy/lib/proxy-go_test.go
+++ b/proxy/lib/proxy-go_test.go
@@ -1,4 +1,4 @@
-package snowflake
+package snowflake_proxy
import (
"bytes"
diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go
index 793fa2b..85f86b2 100644
--- a/proxy/lib/snowflake.go
+++ b/proxy/lib/snowflake.go
@@ -1,4 +1,27 @@
-package snowflake
+/*
+Package snowflake_proxy provides functionality for creating, starting, and stopping a snowflake
+proxy.
+
+To run a proxy, you must first create a proxy configuration
+
+ proxy := snowflake_proxy.SnowflakeProxy{
+ BrokerURL: "https://snowflake-broker.example.com",
+ STUNURL: "stun:stun.stunprotocol.org:3478",
+ // ...
+ }
+
+You may then start and stop the proxy. Stopping the proxy will close existing connections and
+the proxy will not poll for more clients.
+
+ go func() {
+ proxy.Start()
+ }
+
+ // ...
+
+ proxy.Stop()
+*/
+package snowflake_proxy
import (
"bytes"
@@ -76,11 +99,10 @@ var (
// Snowflake in another Go application.
type SnowflakeProxy struct {
Capacity uint
- StunURL string
- RawBrokerURL string
+ STUNURL string
+ BrokerURL string
KeepLocalAddresses bool
RelayURL string
- LogOutput io.Writer
shutdown chan struct{}
}
@@ -475,12 +497,12 @@ func (sf *SnowflakeProxy) Start() {
log.Println("starting")
var err error
- broker, err = newSignalingServer(sf.RawBrokerURL, sf.KeepLocalAddresses)
+ broker, err = newSignalingServer(sf.BrokerURL, sf.KeepLocalAddresses)
if err != nil {
log.Fatal(err)
}
- _, err = url.Parse(sf.StunURL)
+ _, err = url.Parse(sf.STUNURL)
if err != nil {
log.Fatalf("invalid stun url: %s", err)
}
@@ -492,7 +514,7 @@ func (sf *SnowflakeProxy) Start() {
config = webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
- URLs: []string{sf.StunURL},
+ URLs: []string{sf.STUNURL},
},
},
}
diff --git a/proxy/lib/tokens.go b/proxy/lib/tokens.go
index 1331778..d312ecf 100644
--- a/proxy/lib/tokens.go
+++ b/proxy/lib/tokens.go
@@ -1,4 +1,4 @@
-package snowflake
+package snowflake_proxy
import (
"sync/atomic"
diff --git a/proxy/lib/tokens_test.go b/proxy/lib/tokens_test.go
index 702a887..4393a21 100644
--- a/proxy/lib/tokens_test.go
+++ b/proxy/lib/tokens_test.go
@@ -1,4 +1,4 @@
-package snowflake
+package snowflake_proxy
import (
"testing"
diff --git a/proxy/lib/util.go b/proxy/lib/util.go
index 2df23eb..5055187 100644
--- a/proxy/lib/util.go
+++ b/proxy/lib/util.go
@@ -1,4 +1,4 @@
-package snowflake
+package snowflake_proxy
import (
"fmt"
diff --git a/proxy/lib/webrtcconn.go b/proxy/lib/webrtcconn.go
index 20b1172..6e16bec 100644
--- a/proxy/lib/webrtcconn.go
+++ b/proxy/lib/webrtcconn.go
@@ -1,4 +1,4 @@
-package snowflake
+package snowflake_proxy
import (
"fmt"
diff --git a/proxy/main.go b/proxy/main.go
index 12b3752..aabac51 100644
--- a/proxy/main.go
+++ b/proxy/main.go
@@ -7,42 +7,44 @@ import (
"os"
"git.torproject.org/pluggable-transports/snowflake.git/common/safelog"
- "git.torproject.org/pluggable-transports/snowflake.git/proxy/lib"
+ sf "git.torproject.org/pluggable-transports/snowflake.git/proxy/lib"
)
func main() {
capacity := flag.Int("capacity", 10, "maximum concurrent clients")
- stunURL := flag.String("stun", snowflake.DefaultSTUNURL, "broker URL")
+ stunURL := flag.String("stun", sf.DefaultSTUNURL, "broker URL")
logFilename := flag.String("log", "", "log filename")
- rawBrokerURL := flag.String("broker", snowflake.DefaultBrokerURL, "broker URL")
+ rawBrokerURL := flag.String("broker", sf.DefaultBrokerURL, "broker URL")
unsafeLogging := flag.Bool("unsafe-logging", false, "prevent logs from being scrubbed")
keepLocalAddresses := flag.Bool("keep-local-addresses", false, "keep local LAN address ICE candidates")
- relayURL := flag.String("relay", snowflake.DefaultRelayURL, "websocket relay URL")
+ relayURL := flag.String("relay", sf.DefaultRelayURL, "websocket relay URL")
flag.Parse()
- sf := snowflake.SnowflakeProxy{
+ proxy := sf.SnowflakeProxy{
Capacity: uint(*capacity),
- StunURL: *stunURL,
- RawBrokerURL: *rawBrokerURL,
+ STUNURL: *stunURL,
+ BrokerURL: *rawBrokerURL,
KeepLocalAddresses: *keepLocalAddresses,
RelayURL: *relayURL,
- LogOutput: os.Stderr,
}
+ var logOutput io.Writer = os.Stderr
+ 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 {
log.Fatal(err)
}
defer f.Close()
- sf.LogOutput = io.MultiWriter(os.Stderr, f)
+ logOutput = io.MultiWriter(os.Stderr, f)
}
if *unsafeLogging {
- log.SetOutput(sf.LogOutput)
+ log.SetOutput(logOutput)
} else {
- log.SetOutput(&safelog.LogScrubber{Output: sf.LogOutput})
+ log.SetOutput(&safelog.LogScrubber{Output: logOutput})
}
- sf.Start()
+ proxy.Start()
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits