forked from MatsuriDayo/Matsuri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsip_obfs.go
65 lines (51 loc) · 1.37 KB
/
sip_obfs.go
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
package plugin
import (
"context"
obfs "github.com/Dreamacro/clash/transport/simple-obfs"
"github.com/v2fly/v2ray-core/v5/proxy/shadowsocks"
"github.com/v2fly/v2ray-core/v5/proxy/shadowsocks/plugin/self"
"github.com/v2fly/v2ray-core/v5/transport/internet"
)
var _ shadowsocks.StreamPlugin = (*obfsLocalPlugin)(nil)
func init() {
shadowsocks.RegisterPlugin("obfs-local", func() shadowsocks.SIP003Plugin {
return new(obfsLocalPlugin)
})
}
type obfsLocalPlugin struct {
tls bool
host string
port string
}
func (p *obfsLocalPlugin) Init(_ context.Context, _ string, _ string, _ string, remotePort string, pluginOpts string, _ []string, _ *shadowsocks.MemoryAccount) error {
options, err := self.ParsePluginOptions(pluginOpts)
if err != nil {
return newError("obfs-local: failed to parse plugin options").Base(err)
}
mode := "http"
if s, ok := options.Get("obfs"); ok {
mode = s
}
if s, ok := options.Get("obfs-host"); ok {
p.host = s
}
switch mode {
case "http":
case "tls":
p.tls = true
default:
return newError("unknown obfs mode ", mode)
}
p.port = remotePort
return nil
}
func (p *obfsLocalPlugin) StreamConn(connection internet.Connection) internet.Connection {
if !p.tls {
return obfs.NewHTTPObfs(connection, p.host, p.port)
} else {
return obfs.NewTLSObfs(connection, p.host)
}
}
func (p *obfsLocalPlugin) Close() error {
return nil
}