feat: RESTful API support set tcp-concurrent

This commit is contained in:
adlyq 2022-05-26 19:49:12 +08:00
parent 7431001ed6
commit 2ebc0383b5
3 changed files with 25 additions and 12 deletions

View file

@ -15,6 +15,7 @@ var (
dialMux sync.Mutex dialMux sync.Mutex
actualSingleDialContext = singleDialContext actualSingleDialContext = singleDialContext
actualDualStackDialContext = dualStackDialContext actualDualStackDialContext = dualStackDialContext
tcpConcurrent = false
DisableIPv6 = false DisableIPv6 = false
) )
@ -76,6 +77,7 @@ func ListenPacket(ctx context.Context, network, address string, options ...Optio
func SetDial(concurrent bool) { func SetDial(concurrent bool) {
dialMux.Lock() dialMux.Lock()
tcpConcurrent = concurrent
if concurrent { if concurrent {
actualSingleDialContext = concurrentSingleDialContext actualSingleDialContext = concurrentSingleDialContext
actualDualStackDialContext = concurrentDualStackDialContext actualDualStackDialContext = concurrentDualStackDialContext
@ -87,6 +89,10 @@ func SetDial(concurrent bool) {
dialMux.Unlock() dialMux.Unlock()
} }
func GetDial() bool {
return tcpConcurrent
}
func dialContext(ctx context.Context, network string, destination netip.Addr, port string, opt *option) (net.Conn, error) { func dialContext(ctx context.Context, network string, destination netip.Addr, port string, opt *option) (net.Conn, error) {
dialer := &net.Dialer{} dialer := &net.Dialer{}
if opt.interfaceName != "" { if opt.interfaceName != "" {

View file

@ -121,6 +121,7 @@ func GetGeneral() *config.General {
Tun: P.GetTunConf(), Tun: P.GetTunConf(),
Interface: dialer.DefaultInterface.Load(), Interface: dialer.DefaultInterface.Load(),
Sniffing: tunnel.IsSniffing(), Sniffing: tunnel.IsSniffing(),
TCPConcurrent: dialer.GetDial(),
} }
return general return general

View file

@ -1,6 +1,7 @@
package route package route
import ( import (
"github.com/Dreamacro/clash/component/dialer"
"net/http" "net/http"
"path/filepath" "path/filepath"
"sync" "sync"
@ -44,6 +45,7 @@ type configSchema struct {
LogLevel *log.LogLevel `json:"log-level"` LogLevel *log.LogLevel `json:"log-level"`
IPv6 *bool `json:"ipv6"` IPv6 *bool `json:"ipv6"`
Sniffing *bool `json:"sniffing"` Sniffing *bool `json:"sniffing"`
TcpConcurrent *bool `json:"tcp-concurrent"`
} }
func getConfigs(w http.ResponseWriter, r *http.Request) { func getConfigs(w http.ResponseWriter, r *http.Request) {
@ -79,6 +81,10 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
tunnel.SetSniffing(*general.Sniffing) tunnel.SetSniffing(*general.Sniffing)
} }
if general.TcpConcurrent != nil {
dialer.SetDial(*general.TcpConcurrent)
}
ports := P.GetPorts() ports := P.GetPorts()
tcpIn := tunnel.TCPIn() tcpIn := tunnel.TCPIn()