From 5317d6e3e6b772de79fea187a4490b1bff880690 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sun, 26 Dec 2021 21:20:41 +0800 Subject: [PATCH] =?UTF-8?q?[Feature]=20=E6=B7=BB=E5=8A=A0unified-delay=20b?= =?UTF-8?q?oolean=20=E6=8E=A7=E5=88=B6=E5=BB=B6=E8=BF=9F=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=8C=E9=BB=98=E8=AE=A4=E4=B8=BAfalse=EF=BC=8C=E5=BD=93?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEtrue=E6=97=B6=E5=BF=BD=E7=95=A5=E6=8F=A1?= =?UTF-8?q?=E6=89=8B=E5=BB=B6=E8=BF=9F=EF=BC=8C=E5=B0=86=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E7=BB=93=E6=9E=9C=EF=BC=8C=E4=BB=8E=E8=80=8C?= =?UTF-8?q?=E5=88=A9=E4=BA=8E=E4=B8=8D=E5=90=8C=E5=8D=8F=E8=AE=AE=E7=9A=84?= =?UTF-8?q?url-test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter/adapter.go | 14 +++++++++++++- config/config.go | 20 ++++++++++++-------- hub/executor/executor.go | 1 + 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/adapter/adapter.go b/adapter/adapter.go index 76bbe2e3..0b10fae7 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -16,6 +16,8 @@ import ( "go.uber.org/atomic" ) +var UnifiedDelay = atomic.NewBool(false) + type Proxy struct { C.ProxyAdapter history *queue.Queue @@ -114,6 +116,8 @@ func (p *Proxy) URLTest(ctx context.Context, url string) (t uint16, err error) { } }() + unifiedDelay := UnifiedDelay.Load() + addr, err := urlToMetadata(url) if err != nil { return @@ -150,11 +154,19 @@ func (p *Proxy) URLTest(ctx context.Context, url string) (t uint16, err error) { }, } defer client.CloseIdleConnections() - resp, err := client.Do(req) if err != nil { return } + + if unifiedDelay { + start = time.Now() + resp, err = client.Do(req) + if err != nil { + return + } + } + resp.Body.Close() t = uint16(time.Since(start) / time.Millisecond) return diff --git a/config/config.go b/config/config.go index 3218bdb5..d9dcf9fe 100644 --- a/config/config.go +++ b/config/config.go @@ -34,10 +34,11 @@ import ( type General struct { Inbound Controller - Mode T.TunnelMode `json:"mode"` - LogLevel log.LogLevel `json:"log-level"` - IPv6 bool `json:"ipv6"` - Interface string `json:"-"` + Mode T.TunnelMode `json:"mode"` + UnifiedDelay bool + LogLevel log.LogLevel `json:"log-level"` + IPv6 bool `json:"ipv6"` + Interface string `json:"-"` } // Inbound @@ -161,6 +162,7 @@ type RawConfig struct { AllowLan bool `yaml:"allow-lan"` BindAddress string `yaml:"bind-address"` Mode T.TunnelMode `yaml:"mode"` + UnifiedDelay bool `yaml:"unified-delay"` LogLevel log.LogLevel `yaml:"log-level"` IPv6 bool `yaml:"ipv6"` ExternalController string `yaml:"external-controller"` @@ -197,6 +199,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) { AllowLan: false, BindAddress: "*", Mode: T.Rule, + UnifiedDelay: false, Authentication: []string{}, LogLevel: log.INFO, Hosts: map[string]string{}, @@ -318,10 +321,11 @@ func parseGeneral(cfg *RawConfig) (*General, error) { ExternalUI: cfg.ExternalUI, Secret: cfg.Secret, }, - Mode: cfg.Mode, - LogLevel: cfg.LogLevel, - IPv6: cfg.IPv6, - Interface: cfg.Interface, + UnifiedDelay: cfg.UnifiedDelay, + Mode: cfg.Mode, + LogLevel: cfg.LogLevel, + IPv6: cfg.IPv6, + Interface: cfg.Interface, }, nil } diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 877214d5..1820decc 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -185,6 +185,7 @@ func updateRules(rules []C.Rule, ruleProviders map[string]*provider.RuleProvider func updateGeneral(general *config.General, force bool) { tunnel.SetMode(general.Mode) resolver.DisableIPv6 = !general.IPv6 + adapter.UnifiedDelay.Store(general.UnifiedDelay) if (general.Tun.Enable || general.TProxyPort != 0) && general.Interface == "" { autoDetectInterfaceName, err := dev.GetAutoDetectInterface()