forked from tladesignz/IPtProxy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
obfs4.patch
180 lines (162 loc) · 5.04 KB
/
obfs4.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
diff --git a/obfs4proxy/obfs4proxy.go b/obfs4proxy/obfs4proxy.go
index 628f56b..be2cc55 100644
--- a/obfs4proxy/obfs4proxy.go
+++ b/obfs4proxy/obfs4proxy.go
@@ -27,10 +27,9 @@
// Go language Tor Pluggable Transport suite. Works only as a managed
// client/server.
-package main
+package obfs4proxy
import (
- "flag"
"fmt"
"io"
golog "log"
@@ -38,6 +37,7 @@ import (
"net/url"
"os"
"path"
+ "strconv"
"sync"
"syscall"
@@ -58,7 +58,7 @@ const (
var stateDir string
var termMon *termMonitor
-func clientSetup() (launched bool, listeners []net.Listener) {
+func clientSetup(meekPort, obfs2Port, obfs3Port, obfs4Port, scramblesuitPort *int) (launched bool, listeners []net.Listener) {
ptClientInfo, err := pt.ClientSetup(transports.Transports())
if err != nil {
golog.Fatal(err)
@@ -85,7 +85,20 @@ func clientSetup() (launched bool, listeners []net.Listener) {
continue
}
- ln, err := net.Listen("tcp", socksAddr)
+ realSocksAddr := socksAddr
+ if name == "obfs4" {
+ realSocksAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(*obfs4Port))
+ } else if name == "meek_lite" {
+ realSocksAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(*meekPort))
+ } else if name == "obfs2" {
+ realSocksAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(*obfs2Port))
+ } else if name == "obfs3" {
+ realSocksAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(*obfs3Port))
+ } else if name == "scramblesuit" {
+ realSocksAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(*scramblesuitPort))
+ }
+
+ ln, err := net.Listen("tcp", realSocksAddr)
if err != nil {
_ = pt.CmethodError(name, err.Error())
continue
@@ -304,22 +317,16 @@ func getVersion() string {
return fmt.Sprintf("obfs4proxy-%s", obfs4proxyVersion)
}
-func main() {
+func Start(meekPort, obfs2Port, obfs3Port, obfs4Port, scramblesuitPort *int, logLevelStr *string, enableLogging *bool, unsafeLogging *bool) {
// Initialize the termination state monitor as soon as possible.
termMon = newTermMonitor()
- // Handle the command line arguments.
- _, execName := path.Split(os.Args[0])
- showVer := flag.Bool("version", false, "Print version and exit")
- logLevelStr := flag.String("logLevel", "ERROR", "Log level (ERROR/WARN/INFO/DEBUG)")
- enableLogging := flag.Bool("enableLogging", false, "Log to TOR_PT_STATE_LOCATION/"+obfs4proxyLogFile)
- unsafeLogging := flag.Bool("unsafeLogging", false, "Disable the address scrubber")
- flag.Parse()
-
- if *showVer {
- fmt.Printf("%s\n", getVersion())
- os.Exit(0)
+ if *logLevelStr == "" {
+ *logLevelStr = "ERROR"
}
+
+ execName := "obfs4"
+
if err := log.SetLogLevel(*logLevelStr); err != nil {
golog.Fatalf("[ERROR]: %s - failed to set log level: %s", execName, err)
}
@@ -338,8 +345,7 @@ func main() {
golog.Fatalf("[ERROR]: %s - failed to initialize logging", execName)
}
if err = transports.Init(); err != nil {
- log.Errorf("%s - failed to initialize transports: %s", execName, err)
- os.Exit(-1)
+ log.Noticef("%s - failed to initialize transports: %s", execName, err)
}
log.Noticef("%s - launched", getVersion())
@@ -347,7 +353,7 @@ func main() {
// Do the managed pluggable transport protocol configuration.
if isClient {
log.Infof("%s - initializing client transport listeners", execName)
- launched, ptListeners = clientSetup()
+ launched, ptListeners = clientSetup(meekPort, obfs2Port, obfs3Port, obfs4Port, scramblesuitPort)
} else {
log.Infof("%s - initializing server transport listeners", execName)
launched, ptListeners = serverSetup()
@@ -379,3 +385,11 @@ func main() {
}
termMon.wait(true)
}
+
+func Stop() {
+ log.Noticef("obfs4 Stop: synthesizing SIGINT and SIGTERM")
+
+ termMon.sigChan <- syscall.SIGINT
+
+ termMon.sigChan <- syscall.SIGTERM
+}
diff --git a/obfs4proxy/proxy_http.go b/obfs4proxy/proxy_http.go
index 1adadf8..7ff608d 100644
--- a/obfs4proxy/proxy_http.go
+++ b/obfs4proxy/proxy_http.go
@@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-package main
+package obfs4proxy
import (
"bufio"
diff --git a/obfs4proxy/proxy_socks4.go b/obfs4proxy/proxy_socks4.go
index ac8be9e..8922e15 100644
--- a/obfs4proxy/proxy_socks4.go
+++ b/obfs4proxy/proxy_socks4.go
@@ -31,7 +31,7 @@
* license that can be found in the LICENSE file.
*/
-package main
+package obfs4proxy
import (
"errors"
diff --git a/obfs4proxy/pt_extras.go b/obfs4proxy/pt_extras.go
index 18bc2df..766811e 100644
--- a/obfs4proxy/pt_extras.go
+++ b/obfs4proxy/pt_extras.go
@@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-package main
+package obfs4proxy
import (
"errors"
diff --git a/obfs4proxy/termmon.go b/obfs4proxy/termmon.go
index 59304c9..53ba1e2 100644
--- a/obfs4proxy/termmon.go
+++ b/obfs4proxy/termmon.go
@@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-package main
+package obfs4proxy
import (
"io"
diff --git a/obfs4proxy/termmon_linux.go b/obfs4proxy/termmon_linux.go
index 926e630..abbadde 100644
--- a/obfs4proxy/termmon_linux.go
+++ b/obfs4proxy/termmon_linux.go
@@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-package main
+package obfs4proxy
import (
"fmt"