mirror of https://github.com/Dreamacro/clash.git
Feature: v2ray-plugin support disable mux
This commit is contained in:
parent
e0c8aed5c7
commit
1a8a6d0b5d
|
@ -179,6 +179,7 @@ Proxy:
|
||||||
# skip-cert-verify: true
|
# skip-cert-verify: true
|
||||||
# host: bing.com
|
# host: bing.com
|
||||||
# path: "/"
|
# path: "/"
|
||||||
|
# mux: true
|
||||||
# headers:
|
# headers:
|
||||||
# custom: value
|
# custom: value
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,9 @@ type ShadowSocks struct {
|
||||||
cipher core.Cipher
|
cipher core.Cipher
|
||||||
|
|
||||||
// obfs
|
// obfs
|
||||||
obfsMode string
|
obfsMode string
|
||||||
obfsOption *simpleObfsOption
|
obfsOption *simpleObfsOption
|
||||||
wsOption *v2rayObfs.WebsocketOption
|
v2rayOption *v2rayObfs.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShadowSocksOption struct {
|
type ShadowSocksOption struct {
|
||||||
|
@ -55,6 +55,7 @@ type v2rayObfsOption struct {
|
||||||
TLS bool `obfs:"tls,omitempty"`
|
TLS bool `obfs:"tls,omitempty"`
|
||||||
Headers map[string]string `obfs:"headers,omitempty"`
|
Headers map[string]string `obfs:"headers,omitempty"`
|
||||||
SkipCertVerify bool `obfs:"skip-cert-verify,omitempty"`
|
SkipCertVerify bool `obfs:"skip-cert-verify,omitempty"`
|
||||||
|
Mux bool `obfs:"mux,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *ShadowSocks) Dial(metadata *C.Metadata) (C.Conn, error) {
|
func (ss *ShadowSocks) Dial(metadata *C.Metadata) (C.Conn, error) {
|
||||||
|
@ -71,7 +72,7 @@ func (ss *ShadowSocks) Dial(metadata *C.Metadata) (C.Conn, error) {
|
||||||
c = obfs.NewHTTPObfs(c, ss.obfsOption.Host, port)
|
c = obfs.NewHTTPObfs(c, ss.obfsOption.Host, port)
|
||||||
case "websocket":
|
case "websocket":
|
||||||
var err error
|
var err error
|
||||||
c, err = v2rayObfs.NewWebsocketObfs(c, ss.wsOption)
|
c, err = v2rayObfs.NewV2rayObfs(c, ss.v2rayOption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error())
|
return nil, fmt.Errorf("%s connect error: %s", ss.server, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -116,7 +117,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
|
||||||
return nil, fmt.Errorf("ss %s initialize error: %s", server, err.Error())
|
return nil, fmt.Errorf("ss %s initialize error: %s", server, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var wsOption *v2rayObfs.WebsocketOption
|
var v2rayOption *v2rayObfs.Option
|
||||||
var obfsOption *simpleObfsOption
|
var obfsOption *simpleObfsOption
|
||||||
obfsMode := ""
|
obfsMode := ""
|
||||||
|
|
||||||
|
@ -144,7 +145,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
|
||||||
obfsMode = opts.Mode
|
obfsMode = opts.Mode
|
||||||
obfsOption = &opts
|
obfsOption = &opts
|
||||||
} else if option.Plugin == "v2ray-plugin" {
|
} else if option.Plugin == "v2ray-plugin" {
|
||||||
opts := v2rayObfsOption{Host: "bing.com"}
|
opts := v2rayObfsOption{Host: "bing.com", Mux: true}
|
||||||
if err := decoder.Decode(option.PluginOpts, &opts); err != nil {
|
if err := decoder.Decode(option.PluginOpts, &opts); err != nil {
|
||||||
return nil, fmt.Errorf("ss %s initialize v2ray-plugin error: %s", server, err.Error())
|
return nil, fmt.Errorf("ss %s initialize v2ray-plugin error: %s", server, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -162,11 +163,12 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
|
||||||
ClientSessionCache: getClientSessionCache(),
|
ClientSessionCache: getClientSessionCache(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wsOption = &v2rayObfs.WebsocketOption{
|
v2rayOption = &v2rayObfs.Option{
|
||||||
Host: opts.Host,
|
Host: opts.Host,
|
||||||
Path: opts.Path,
|
Path: opts.Path,
|
||||||
Headers: opts.Headers,
|
Headers: opts.Headers,
|
||||||
TLSConfig: tlsConfig,
|
TLSConfig: tlsConfig,
|
||||||
|
Mux: opts.Mux,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,9 +181,9 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
|
||||||
server: server,
|
server: server,
|
||||||
cipher: ciph,
|
cipher: ciph,
|
||||||
|
|
||||||
obfsMode: obfsMode,
|
obfsMode: obfsMode,
|
||||||
wsOption: wsOption,
|
v2rayOption: v2rayOption,
|
||||||
obfsOption: obfsOption,
|
obfsOption: obfsOption,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,17 @@ import (
|
||||||
"github.com/Dreamacro/clash/component/vmess"
|
"github.com/Dreamacro/clash/component/vmess"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WebsocketOption is options of websocket obfs
|
// Option is options of websocket obfs
|
||||||
type WebsocketOption struct {
|
type Option struct {
|
||||||
Host string
|
Host string
|
||||||
Path string
|
Path string
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
|
Mux bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWebsocketObfs return a HTTPObfs
|
// NewV2rayObfs return a HTTPObfs
|
||||||
func NewWebsocketObfs(conn net.Conn, option *WebsocketOption) (net.Conn, error) {
|
func NewV2rayObfs(conn net.Conn, option *Option) (net.Conn, error) {
|
||||||
header := http.Header{}
|
header := http.Header{}
|
||||||
for k, v := range option.Headers {
|
for k, v := range option.Headers {
|
||||||
header.Add(k, v)
|
header.Add(k, v)
|
||||||
|
@ -36,10 +37,13 @@ func NewWebsocketObfs(conn net.Conn, option *WebsocketOption) (net.Conn, error)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
conn = NewMux(conn, MuxOption{
|
|
||||||
ID: [2]byte{0, 0},
|
if option.Mux {
|
||||||
Host: "127.0.0.1",
|
conn = NewMux(conn, MuxOption{
|
||||||
Port: 0,
|
ID: [2]byte{0, 0},
|
||||||
})
|
Host: "127.0.0.1",
|
||||||
|
Port: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue