Skip to content

Commit 8f5a864

Browse files
committed
chore: cleanup unneeded setting in parseGeneral, move to executor
1 parent 9286e21 commit 8f5a864

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

config/config.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ import (
2020
"github.com/metacubex/mihomo/component/fakeip"
2121
"github.com/metacubex/mihomo/component/geodata"
2222
mihomoHttp "github.com/metacubex/mihomo/component/http"
23-
"github.com/metacubex/mihomo/component/keepalive"
2423
P "github.com/metacubex/mihomo/component/process"
2524
"github.com/metacubex/mihomo/component/resolver"
2625
"github.com/metacubex/mihomo/component/resource"
2726
"github.com/metacubex/mihomo/component/sniffer"
2827
tlsC "github.com/metacubex/mihomo/component/tls"
2928
"github.com/metacubex/mihomo/component/trie"
30-
"github.com/metacubex/mihomo/component/updater"
3129
C "github.com/metacubex/mihomo/constant"
3230
providerTypes "github.com/metacubex/mihomo/constant/provider"
3331
snifferTypes "github.com/metacubex/mihomo/constant/sniffer"
@@ -66,6 +64,9 @@ type General struct {
6664
GlobalClientFingerprint string `json:"global-client-fingerprint"`
6765
GlobalUA string `json:"global-ua"`
6866
ETagSupport bool `json:"etag-support"`
67+
KeepAliveIdle int `json:"keep-alive-idle"`
68+
KeepAliveInterval int `json:"keep-alive-interval"`
69+
DisableKeepAlive bool `json:"disable-keep-alive"`
6970
}
7071

7172
// Inbound config
@@ -707,8 +708,6 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
707708
}
708709

709710
func parseGeneral(cfg *RawConfig) (*General, error) {
710-
updater.SetGeoAutoUpdate(cfg.GeoAutoUpdate)
711-
updater.SetGeoUpdateInterval(cfg.GeoUpdateInterval)
712711
geodata.SetGeodataMode(cfg.GeodataMode)
713712
geodata.SetLoader(cfg.GeodataLoader)
714713
geodata.SetSiteMatcher(cfg.GeositeMatcher)
@@ -719,10 +718,6 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
719718
mihomoHttp.SetUA(cfg.GlobalUA)
720719
resource.SetETag(cfg.ETagSupport)
721720

722-
keepalive.SetKeepAliveIdle(time.Duration(cfg.KeepAliveIdle) * time.Second)
723-
keepalive.SetKeepAliveInterval(time.Duration(cfg.KeepAliveInterval) * time.Second)
724-
keepalive.SetDisableKeepAlive(cfg.DisableKeepAlive)
725-
726721
return &General{
727722
Inbound: Inbound{
728723
Port: cfg.Port,
@@ -761,6 +756,9 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
761756
GlobalClientFingerprint: cfg.GlobalClientFingerprint,
762757
GlobalUA: cfg.GlobalUA,
763758
ETagSupport: cfg.ETagSupport,
759+
KeepAliveIdle: cfg.KeepAliveIdle,
760+
KeepAliveInterval: cfg.KeepAliveInterval,
761+
DisableKeepAlive: cfg.DisableKeepAlive,
764762
}, nil
765763
}
766764

hub/executor/executor.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
G "github.com/metacubex/mihomo/component/geodata"
2020
mihomoHttp "github.com/metacubex/mihomo/component/http"
2121
"github.com/metacubex/mihomo/component/iface"
22+
"github.com/metacubex/mihomo/component/keepalive"
2223
"github.com/metacubex/mihomo/component/profile"
2324
"github.com/metacubex/mihomo/component/profile/cachefile"
2425
"github.com/metacubex/mihomo/component/resolver"
@@ -117,7 +118,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
117118
runtime.GC()
118119
tunnel.OnRunning()
119120
hcCompatibleProvider(cfg.Providers)
120-
initExternalUI(cfg.Controller)
121+
updateUpdater(cfg)
121122

122123
resolver.ResetConnection()
123124
}
@@ -176,6 +177,9 @@ func GetGeneral() *config.General {
176177
GlobalClientFingerprint: tlsC.GetGlobalFingerprint(),
177178
GlobalUA: mihomoHttp.UA(),
178179
ETagSupport: resource.ETag(),
180+
KeepAliveInterval: int(keepalive.KeepAliveInterval() / time.Second),
181+
KeepAliveIdle: int(keepalive.KeepAliveIdle() / time.Second),
182+
DisableKeepAlive: keepalive.DisableKeepAlive(),
179183
}
180184

181185
return general
@@ -394,7 +398,12 @@ func updateTunnels(tunnels []LC.Tunnel) {
394398
listener.PatchTunnel(tunnels, tunnel.Tunnel)
395399
}
396400

397-
func initExternalUI(controller *config.Controller) {
401+
func updateUpdater(cfg *config.Config) {
402+
general := cfg.General
403+
updater.SetGeoAutoUpdate(general.GeoAutoUpdate)
404+
updater.SetGeoUpdateInterval(general.GeoUpdateInterval)
405+
406+
controller := cfg.Controller
398407
updater.DefaultUiUpdater = updater.NewUiUpdater(controller.ExternalUI, controller.ExternalUIURL, controller.ExternalUIName)
399408
updater.DefaultUiUpdater.AutoDownloadUI()
400409
}
@@ -412,6 +421,10 @@ func updateGeneral(general *config.General) {
412421
inbound.SetTfo(general.InboundTfo)
413422
inbound.SetMPTCP(general.InboundMPTCP)
414423

424+
keepalive.SetKeepAliveIdle(time.Duration(general.KeepAliveIdle) * time.Second)
425+
keepalive.SetKeepAliveInterval(time.Duration(general.KeepAliveInterval) * time.Second)
426+
keepalive.SetDisableKeepAlive(general.DisableKeepAlive)
427+
415428
adapter.UnifiedDelay.Store(general.UnifiedDelay)
416429

417430
dialer.DefaultInterface.Store(general.Interface)

0 commit comments

Comments
 (0)