Skip to content

Commit

Permalink
chore: cleanup unneeded setting in parseGeneral, move to executor
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Oct 5, 2024
1 parent 9286e21 commit 8f5a864
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
14 changes: 6 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 15 additions & 2 deletions hub/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand All @@ -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)
Expand Down

0 comments on commit 8f5a864

Please sign in to comment.