diff --git a/component/dialer/dialer.go b/component/dialer/dialer.go index 4f06ca5c..79a51b5d 100644 --- a/component/dialer/dialer.go +++ b/component/dialer/dialer.go @@ -15,6 +15,7 @@ var ( dialMux sync.Mutex actualSingleDialContext = singleDialContext actualDualStackDialContext = dualStackDialContext + tcpConcurrent = false DisableIPv6 = false ) @@ -76,6 +77,7 @@ func ListenPacket(ctx context.Context, network, address string, options ...Optio func SetDial(concurrent bool) { dialMux.Lock() + tcpConcurrent = concurrent if concurrent { actualSingleDialContext = concurrentSingleDialContext actualDualStackDialContext = concurrentDualStackDialContext @@ -87,6 +89,10 @@ func SetDial(concurrent bool) { dialMux.Unlock() } +func GetDial() bool { + return tcpConcurrent +} + func dialContext(ctx context.Context, network string, destination netip.Addr, port string, opt *option) (net.Conn, error) { dialer := &net.Dialer{} if opt.interfaceName != "" { diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 7d83698b..1dd21c10 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -121,6 +121,7 @@ func GetGeneral() *config.General { Tun: P.GetTunConf(), Interface: dialer.DefaultInterface.Load(), Sniffing: tunnel.IsSniffing(), + TCPConcurrent: dialer.GetDial(), } return general diff --git a/hub/route/configs.go b/hub/route/configs.go index b60ad586..f87fa5ce 100644 --- a/hub/route/configs.go +++ b/hub/route/configs.go @@ -1,6 +1,7 @@ package route import ( + "github.com/Dreamacro/clash/component/dialer" "net/http" "path/filepath" "sync" @@ -32,18 +33,19 @@ func configRouter() http.Handler { } type configSchema struct { - Port *int `json:"port"` - SocksPort *int `json:"socks-port"` - RedirPort *int `json:"redir-port"` - TProxyPort *int `json:"tproxy-port"` - MixedPort *int `json:"mixed-port"` - Tun *config.Tun `json:"tun"` - AllowLan *bool `json:"allow-lan"` - BindAddress *string `json:"bind-address"` - Mode *tunnel.TunnelMode `json:"mode"` - LogLevel *log.LogLevel `json:"log-level"` - IPv6 *bool `json:"ipv6"` - Sniffing *bool `json:"sniffing"` + Port *int `json:"port"` + SocksPort *int `json:"socks-port"` + RedirPort *int `json:"redir-port"` + TProxyPort *int `json:"tproxy-port"` + MixedPort *int `json:"mixed-port"` + Tun *config.Tun `json:"tun"` + AllowLan *bool `json:"allow-lan"` + BindAddress *string `json:"bind-address"` + Mode *tunnel.TunnelMode `json:"mode"` + LogLevel *log.LogLevel `json:"log-level"` + IPv6 *bool `json:"ipv6"` + Sniffing *bool `json:"sniffing"` + TcpConcurrent *bool `json:"tcp-concurrent"` } func getConfigs(w http.ResponseWriter, r *http.Request) { @@ -79,6 +81,10 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) { tunnel.SetSniffing(*general.Sniffing) } + if general.TcpConcurrent != nil { + dialer.SetDial(*general.TcpConcurrent) + } + ports := P.GetPorts() tcpIn := tunnel.TCPIn()