From 8f5a86410c9f1539573d9518e9e497369568fc95 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Sat, 5 Oct 2024 13:58:49 +0800 Subject: [PATCH] chore: cleanup unneeded setting in parseGeneral, move to executor --- config/config.go | 14 ++++++-------- hub/executor/executor.go | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/config/config.go b/config/config.go index c1d70e81c..69957cee9 100644 --- a/config/config.go +++ b/config/config.go @@ -20,14 +20,12 @@ import ( "github.com/metacubex/mihomo/component/fakeip" "github.com/metacubex/mihomo/component/geodata" mihomoHttp "github.com/metacubex/mihomo/component/http" - "github.com/metacubex/mihomo/component/keepalive" P "github.com/metacubex/mihomo/component/process" "github.com/metacubex/mihomo/component/resolver" "github.com/metacubex/mihomo/component/resource" "github.com/metacubex/mihomo/component/sniffer" tlsC "github.com/metacubex/mihomo/component/tls" "github.com/metacubex/mihomo/component/trie" - "github.com/metacubex/mihomo/component/updater" C "github.com/metacubex/mihomo/constant" providerTypes "github.com/metacubex/mihomo/constant/provider" snifferTypes "github.com/metacubex/mihomo/constant/sniffer" @@ -66,6 +64,9 @@ type General struct { GlobalClientFingerprint string `json:"global-client-fingerprint"` GlobalUA string `json:"global-ua"` ETagSupport bool `json:"etag-support"` + KeepAliveIdle int `json:"keep-alive-idle"` + KeepAliveInterval int `json:"keep-alive-interval"` + DisableKeepAlive bool `json:"disable-keep-alive"` } // Inbound config @@ -707,8 +708,6 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) { } func parseGeneral(cfg *RawConfig) (*General, error) { - updater.SetGeoAutoUpdate(cfg.GeoAutoUpdate) - updater.SetGeoUpdateInterval(cfg.GeoUpdateInterval) geodata.SetGeodataMode(cfg.GeodataMode) geodata.SetLoader(cfg.GeodataLoader) geodata.SetSiteMatcher(cfg.GeositeMatcher) @@ -719,10 +718,6 @@ func parseGeneral(cfg *RawConfig) (*General, error) { mihomoHttp.SetUA(cfg.GlobalUA) resource.SetETag(cfg.ETagSupport) - keepalive.SetKeepAliveIdle(time.Duration(cfg.KeepAliveIdle) * time.Second) - keepalive.SetKeepAliveInterval(time.Duration(cfg.KeepAliveInterval) * time.Second) - keepalive.SetDisableKeepAlive(cfg.DisableKeepAlive) - return &General{ Inbound: Inbound{ Port: cfg.Port, @@ -761,6 +756,9 @@ func parseGeneral(cfg *RawConfig) (*General, error) { GlobalClientFingerprint: cfg.GlobalClientFingerprint, GlobalUA: cfg.GlobalUA, ETagSupport: cfg.ETagSupport, + KeepAliveIdle: cfg.KeepAliveIdle, + KeepAliveInterval: cfg.KeepAliveInterval, + DisableKeepAlive: cfg.DisableKeepAlive, }, nil } diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 0492c430f..199790635 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -19,6 +19,7 @@ import ( G "github.com/metacubex/mihomo/component/geodata" mihomoHttp "github.com/metacubex/mihomo/component/http" "github.com/metacubex/mihomo/component/iface" + "github.com/metacubex/mihomo/component/keepalive" "github.com/metacubex/mihomo/component/profile" "github.com/metacubex/mihomo/component/profile/cachefile" "github.com/metacubex/mihomo/component/resolver" @@ -117,7 +118,7 @@ func ApplyConfig(cfg *config.Config, force bool) { runtime.GC() tunnel.OnRunning() hcCompatibleProvider(cfg.Providers) - initExternalUI(cfg.Controller) + updateUpdater(cfg) resolver.ResetConnection() } @@ -176,6 +177,9 @@ func GetGeneral() *config.General { GlobalClientFingerprint: tlsC.GetGlobalFingerprint(), GlobalUA: mihomoHttp.UA(), ETagSupport: resource.ETag(), + KeepAliveInterval: int(keepalive.KeepAliveInterval() / time.Second), + KeepAliveIdle: int(keepalive.KeepAliveIdle() / time.Second), + DisableKeepAlive: keepalive.DisableKeepAlive(), } return general @@ -394,7 +398,12 @@ func updateTunnels(tunnels []LC.Tunnel) { listener.PatchTunnel(tunnels, tunnel.Tunnel) } -func initExternalUI(controller *config.Controller) { +func updateUpdater(cfg *config.Config) { + general := cfg.General + updater.SetGeoAutoUpdate(general.GeoAutoUpdate) + updater.SetGeoUpdateInterval(general.GeoUpdateInterval) + + controller := cfg.Controller updater.DefaultUiUpdater = updater.NewUiUpdater(controller.ExternalUI, controller.ExternalUIURL, controller.ExternalUIName) updater.DefaultUiUpdater.AutoDownloadUI() } @@ -412,6 +421,10 @@ func updateGeneral(general *config.General) { inbound.SetTfo(general.InboundTfo) inbound.SetMPTCP(general.InboundMPTCP) + keepalive.SetKeepAliveIdle(time.Duration(general.KeepAliveIdle) * time.Second) + keepalive.SetKeepAliveInterval(time.Duration(general.KeepAliveInterval) * time.Second) + keepalive.SetDisableKeepAlive(general.DisableKeepAlive) + adapter.UnifiedDelay.Store(general.UnifiedDelay) dialer.DefaultInterface.Store(general.Interface)