-
Notifications
You must be signed in to change notification settings - Fork 12
/
snowflake.patch
124 lines (114 loc) · 4.47 KB
/
snowflake.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
diff --git a/client/snowflake.go b/client/snowflake.go
index 4ebbaf5..749955b 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -1,9 +1,7 @@
// Client transport plugin for the Snowflake pluggable transport.
-package main
+package snowflakeclient
import (
- "flag"
- "fmt"
"io"
"log"
"net"
@@ -39,6 +37,8 @@ func (p ptEventLogger) OnNewSnowflakeEvent(e event.SnowflakeEvent) {
pt.Log(pt.LogSeverityNotice, e.String())
}
+var sigChan = make(chan os.Signal, 1)
+
// Exchanges bytes between two ReadWriters.
// (In this case, between a SOCKS connection and a snowflake transport conn)
func copyLoop(socks, sfconn io.ReadWriter) {
@@ -159,33 +159,14 @@ func socksAcceptLoop(ln *pt.SocksListener, config sf.ClientConfig, shutdown chan
}
}
-func main() {
- iceServersCommas := flag.String("ice", "", "comma-separated list of ICE servers")
- brokerURL := flag.String("url", "", "URL of signaling broker")
- frontDomain := flag.String("front", "", "front domain")
- frontDomainsCommas := flag.String("fronts", "", "comma-separated list of front domains")
- ampCacheURL := flag.String("ampcache", "", "URL of AMP cache to use as a proxy for signaling")
- sqsQueueURL := flag.String("sqsqueue", "", "URL of SQS Queue to use as a proxy for signaling")
- sqsCredsStr := flag.String("sqscreds", "", "credentials to access SQS Queue")
- logFilename := flag.String("log", "", "name of log file")
- logToStateDir := flag.Bool("log-to-state-dir", false, "resolve the log file relative to tor's pt state dir")
- keepLocalAddresses := flag.Bool("keep-local-addresses", false, "keep local LAN address ICE candidates")
- unsafeLogging := flag.Bool("unsafe-logging", false, "prevent logs from being scrubbed")
- max := flag.Int("max", DefaultSnowflakeCapacity,
- "capacity for number of multiplexed WebRTC peers")
- versionFlag := flag.Bool("version", false, "display version info to stderr and quit")
-
- // Deprecated
- oldLogToStateDir := flag.Bool("logToStateDir", false, "use -log-to-state-dir instead")
- oldKeepLocalAddresses := flag.Bool("keepLocalAddresses", false, "use -keep-local-addresses instead")
-
- flag.Parse()
-
- if *versionFlag {
- fmt.Fprintf(os.Stderr, "snowflake-client %s", version.ConstructResult())
- os.Exit(0)
+func Start(port *int, iceServersCommas, brokerURL, frontDomainsCommas, ampCacheURL, sqsQueueURL, sqsCredsStr, logFilename *string, logToStateDir, keepLocalAddresses, unsafeLogging *bool, max *int) {
+ if *max < DefaultSnowflakeCapacity {
+ *max = DefaultSnowflakeCapacity
}
+ oldLogToStateDir := logToStateDir
+ oldKeepLocalAddresses := keepLocalAddresses
+
log.SetFlags(log.LstdFlags | log.LUTC)
// Don't write to stderr; versions of tor earlier than about 0.3.5.6 do
@@ -226,11 +207,6 @@ func main() {
frontDomains = strings.Split(strings.TrimSpace(*frontDomainsCommas), ",")
}
- // Maintain backwards compatability with legacy commandline option
- if (len(frontDomains) == 0) && (*frontDomain != "") {
- frontDomains = []string{*frontDomain}
- }
-
config := sf.ClientConfig{
BrokerURL: *brokerURL,
AmpCacheURL: *ampCacheURL,
@@ -270,7 +246,7 @@ func main() {
switch methodName {
case "snowflake":
// TODO: Be able to recover when SOCKS dies.
- ln, err := pt.ListenSocks("tcp", "127.0.0.1:0")
+ ln, err := pt.ListenSocks("tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(*port)))
if err != nil {
pt.CmethodError(methodName, err.Error())
break
@@ -285,7 +261,6 @@ func main() {
}
pt.CmethodsDone()
- sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM)
if os.Getenv("TOR_PT_EXIT_ON_STDIN_CLOSE") == "1" {
@@ -312,3 +287,8 @@ func main() {
wg.Wait()
log.Println("snowflake is done.")
}
+
+func Stop() {
+ log.Println("synthesizing SIGTERM because of explicit Stop call")
+ sigChan <- syscall.SIGTERM
+}
diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go
index 39c4c2f..af9773f 100644
--- a/proxy/lib/snowflake.go
+++ b/proxy/lib/snowflake.go
@@ -145,6 +145,8 @@ type SnowflakeProxy struct {
periodicProxyStats *periodicProxyStats
bytesLogger bytesLogger
+
+ ClientConnectedCallback func()
}
// Checks whether an IP address is a remote address for the client
@@ -626,6 +628,8 @@ func (sf *SnowflakeProxy) runSession(sid string) {
select {
case <-dataChan:
log.Println("Connection successful")
+ go sf.ClientConnectedCallback()
+
case <-time.After(dataChannelTimeout):
log.Println("Timed out waiting for client to open data channel.")
if err := pc.Close(); err != nil {