forked from n8fr8/IPtProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snowflake.patch
110 lines (101 loc) · 3.96 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
diff --git a/client/snowflake.go b/client/snowflake.go
index d76efbf..dd28681 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -1,8 +1,7 @@
// Client transport plugin for the Snowflake pluggable transport.
-package main
+package snowflakeclient
import (
- "flag"
"io"
"io/ioutil"
"log"
@@ -24,6 +23,8 @@ const (
DefaultSnowflakeCapacity = 1
)
+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) {
@@ -119,23 +120,13 @@ 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")
- ampCacheURL := flag.String("ampcache", "", "URL of AMP cache to use as a proxy for signaling")
- 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")
-
- // Deprecated
- oldLogToStateDir := flag.Bool("logToStateDir", false, "use -log-to-state-dir instead")
- oldKeepLocalAddresses := flag.Bool("keepLocalAddresses", false, "use -keep-local-addresses instead")
+func Start(port *int, iceServersCommas, brokerURL, frontDomain, ampCacheURL, logFilename *string, logToStateDir, keepLocalAddresses, unsafeLogging *bool, max *int) {
+ if *max < DefaultSnowflakeCapacity {
+ *max = DefaultSnowflakeCapacity
+ }
- flag.Parse()
+ oldLogToStateDir := logToStateDir
+ oldKeepLocalAddresses := keepLocalAddresses
log.SetFlags(log.LstdFlags | log.LUTC)
@@ -195,7 +186,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
@@ -210,7 +201,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" {
@@ -237,3 +227,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 e39fcfb..d8b72fa 100644
--- a/proxy/lib/snowflake.go
+++ b/proxy/lib/snowflake.go
@@ -102,6 +102,8 @@ type SnowflakeProxy struct {
// NATProbeURL is the URL of the probe service we use for NAT checks
NATProbeURL string
shutdown chan struct{}
+
+ ClientConnectedCallback func()
}
// Checks whether an IP address is a remote address for the client
@@ -183,7 +185,7 @@ func (s *SignalingServer) pollOffer(sid string, shutdown chan struct{}) *webrtc.
return nil
default:
numClients := int((tokens.count() / 8) * 8) // Round down to 8
- body, err := messages.EncodePollRequest(sid, "standalone", currentNATType, numClients)
+ body, err := messages.EncodePollRequest(sid, "iptproxy", currentNATType, numClients)
if err != nil {
log.Printf("Error encoding poll message: %s", err.Error())
return nil
@@ -474,6 +476,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 {