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
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 != "" {

View file

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

View file

@ -1,6 +1,7 @@
package route
import (
"github.com/Dreamacro/clash/component/dialer"
"net/http"
"path/filepath"
"sync"
@ -44,6 +45,7 @@ type configSchema struct {
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()