-
Notifications
You must be signed in to change notification settings - Fork 12
/
lyrebird.patch
191 lines (171 loc) · 5.39 KB
/
lyrebird.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
181
182
183
184
185
186
187
188
189
190
191
diff --git a/cmd/lyrebird/lyrebird.go b/cmd/lyrebird/lyrebird.go
index 29c51a3..c74095d 100644
--- a/cmd/lyrebird/lyrebird.go
+++ b/cmd/lyrebird/lyrebird.go
@@ -27,17 +27,16 @@
// Go language Tor Pluggable Transport suite. Works only as a managed
// client/server.
-package main
+package lyrebird
import (
- "flag"
- "fmt"
"io"
golog "log"
"net"
"net/url"
"os"
"path"
+ "strconv"
"sync"
"syscall"
@@ -52,13 +51,14 @@ import (
const (
lyrebirdLogFile = "lyrebird.log"
socksAddr = "127.0.0.1:0"
+ LyrebirdVersion = "lyrebird-0.2.0"
+ LyrebirdLogFile = lyrebirdLogFile
)
-var lyrebirdVersion = "devel"
var stateDir string
var termMon *termMonitor
-func clientSetup() (launched bool, listeners []net.Listener) {
+func clientSetup(meekPort, obfs2Port, obfs3Port, obfs4Port, scramblesuitPort, webtunnelPort *int) (launched bool, listeners []net.Listener) {
ptClientInfo, err := pt.ClientSetup(transports.Transports())
if err != nil {
golog.Fatal(err)
@@ -85,7 +85,22 @@ 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))
+ } else if name == "webtunnel" {
+ realSocksAddr = net.JoinHostPort("127.0.0.1", strconv.Itoa(*webtunnelPort))
+ }
+
+ ln, err := net.Listen("tcp", realSocksAddr)
if err != nil {
_ = pt.CmethodError(name, err.Error())
continue
@@ -300,22 +315,16 @@ func copyLoop(a net.Conn, b net.Conn) error {
return nil
}
-func main() {
+func Start(meekPort, obfs2Port, obfs3Port, obfs4Port, scramblesuitPort, webtunnelPort *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/"+lyrebirdLogFile)
- unsafeLogging := flag.Bool("unsafeLogging", false, "Disable the address scrubber")
- flag.Parse()
-
- if *showVer {
- fmt.Printf("%s\n", lyrebirdVersion)
- os.Exit(0)
+ if *logLevelStr == "" {
+ *logLevelStr = "ERROR"
}
+
+ execName := "lyrebird"
+
if err := log.SetLogLevel(*logLevelStr); err != nil {
golog.Fatalf("[ERROR]: %s - failed to set log level: %s", execName, err)
}
@@ -334,16 +343,15 @@ 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", lyrebirdVersion)
+ log.Noticef("%s - launched", LyrebirdVersion)
// 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, webtunnelPort)
} else {
log.Infof("%s - initializing server transport listeners", execName)
launched, ptListeners = serverSetup()
@@ -375,3 +383,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/cmd/lyrebird/proxy_http.go b/cmd/lyrebird/proxy_http.go
index f1eae42..529ed12 100644
--- a/cmd/lyrebird/proxy_http.go
+++ b/cmd/lyrebird/proxy_http.go
@@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-package main
+package lyrebird
import (
"bufio"
diff --git a/cmd/lyrebird/proxy_socks4.go b/cmd/lyrebird/proxy_socks4.go
index d416f27..c5e1a05 100644
--- a/cmd/lyrebird/proxy_socks4.go
+++ b/cmd/lyrebird/proxy_socks4.go
@@ -31,7 +31,7 @@
* license that can be found in the LICENSE file.
*/
-package main
+package lyrebird
import (
"errors"
diff --git a/cmd/lyrebird/pt_extras.go b/cmd/lyrebird/pt_extras.go
index 6c2cca5..e3c5c90 100644
--- a/cmd/lyrebird/pt_extras.go
+++ b/cmd/lyrebird/pt_extras.go
@@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-package main
+package lyrebird
import (
"errors"
diff --git a/cmd/lyrebird/termmon.go b/cmd/lyrebird/termmon.go
index 42c2f84..93794bb 100644
--- a/cmd/lyrebird/termmon.go
+++ b/cmd/lyrebird/termmon.go
@@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-package main
+package lyrebird
import (
"io"
diff --git a/cmd/lyrebird/termmon_linux.go b/cmd/lyrebird/termmon_linux.go
index 926e630..0c872cb 100644
--- a/cmd/lyrebird/termmon_linux.go
+++ b/cmd/lyrebird/termmon_linux.go
@@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-package main
+package lyrebird
import (
"fmt"