mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
chore: cleanup unneeded setting in parseGeneral, move to executor
This commit is contained in:
parent
9286e21026
commit
8f5a86410c
|
@ -20,14 +20,12 @@ import (
|
||||||
"github.com/metacubex/mihomo/component/fakeip"
|
"github.com/metacubex/mihomo/component/fakeip"
|
||||||
"github.com/metacubex/mihomo/component/geodata"
|
"github.com/metacubex/mihomo/component/geodata"
|
||||||
mihomoHttp "github.com/metacubex/mihomo/component/http"
|
mihomoHttp "github.com/metacubex/mihomo/component/http"
|
||||||
"github.com/metacubex/mihomo/component/keepalive"
|
|
||||||
P "github.com/metacubex/mihomo/component/process"
|
P "github.com/metacubex/mihomo/component/process"
|
||||||
"github.com/metacubex/mihomo/component/resolver"
|
"github.com/metacubex/mihomo/component/resolver"
|
||||||
"github.com/metacubex/mihomo/component/resource"
|
"github.com/metacubex/mihomo/component/resource"
|
||||||
"github.com/metacubex/mihomo/component/sniffer"
|
"github.com/metacubex/mihomo/component/sniffer"
|
||||||
tlsC "github.com/metacubex/mihomo/component/tls"
|
tlsC "github.com/metacubex/mihomo/component/tls"
|
||||||
"github.com/metacubex/mihomo/component/trie"
|
"github.com/metacubex/mihomo/component/trie"
|
||||||
"github.com/metacubex/mihomo/component/updater"
|
|
||||||
C "github.com/metacubex/mihomo/constant"
|
C "github.com/metacubex/mihomo/constant"
|
||||||
providerTypes "github.com/metacubex/mihomo/constant/provider"
|
providerTypes "github.com/metacubex/mihomo/constant/provider"
|
||||||
snifferTypes "github.com/metacubex/mihomo/constant/sniffer"
|
snifferTypes "github.com/metacubex/mihomo/constant/sniffer"
|
||||||
|
@ -66,6 +64,9 @@ type General struct {
|
||||||
GlobalClientFingerprint string `json:"global-client-fingerprint"`
|
GlobalClientFingerprint string `json:"global-client-fingerprint"`
|
||||||
GlobalUA string `json:"global-ua"`
|
GlobalUA string `json:"global-ua"`
|
||||||
ETagSupport bool `json:"etag-support"`
|
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
|
// Inbound config
|
||||||
|
@ -707,8 +708,6 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseGeneral(cfg *RawConfig) (*General, error) {
|
func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||||
updater.SetGeoAutoUpdate(cfg.GeoAutoUpdate)
|
|
||||||
updater.SetGeoUpdateInterval(cfg.GeoUpdateInterval)
|
|
||||||
geodata.SetGeodataMode(cfg.GeodataMode)
|
geodata.SetGeodataMode(cfg.GeodataMode)
|
||||||
geodata.SetLoader(cfg.GeodataLoader)
|
geodata.SetLoader(cfg.GeodataLoader)
|
||||||
geodata.SetSiteMatcher(cfg.GeositeMatcher)
|
geodata.SetSiteMatcher(cfg.GeositeMatcher)
|
||||||
|
@ -719,10 +718,6 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||||
mihomoHttp.SetUA(cfg.GlobalUA)
|
mihomoHttp.SetUA(cfg.GlobalUA)
|
||||||
resource.SetETag(cfg.ETagSupport)
|
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{
|
return &General{
|
||||||
Inbound: Inbound{
|
Inbound: Inbound{
|
||||||
Port: cfg.Port,
|
Port: cfg.Port,
|
||||||
|
@ -761,6 +756,9 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||||
GlobalClientFingerprint: cfg.GlobalClientFingerprint,
|
GlobalClientFingerprint: cfg.GlobalClientFingerprint,
|
||||||
GlobalUA: cfg.GlobalUA,
|
GlobalUA: cfg.GlobalUA,
|
||||||
ETagSupport: cfg.ETagSupport,
|
ETagSupport: cfg.ETagSupport,
|
||||||
|
KeepAliveIdle: cfg.KeepAliveIdle,
|
||||||
|
KeepAliveInterval: cfg.KeepAliveInterval,
|
||||||
|
DisableKeepAlive: cfg.DisableKeepAlive,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
G "github.com/metacubex/mihomo/component/geodata"
|
G "github.com/metacubex/mihomo/component/geodata"
|
||||||
mihomoHttp "github.com/metacubex/mihomo/component/http"
|
mihomoHttp "github.com/metacubex/mihomo/component/http"
|
||||||
"github.com/metacubex/mihomo/component/iface"
|
"github.com/metacubex/mihomo/component/iface"
|
||||||
|
"github.com/metacubex/mihomo/component/keepalive"
|
||||||
"github.com/metacubex/mihomo/component/profile"
|
"github.com/metacubex/mihomo/component/profile"
|
||||||
"github.com/metacubex/mihomo/component/profile/cachefile"
|
"github.com/metacubex/mihomo/component/profile/cachefile"
|
||||||
"github.com/metacubex/mihomo/component/resolver"
|
"github.com/metacubex/mihomo/component/resolver"
|
||||||
|
@ -117,7 +118,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
tunnel.OnRunning()
|
tunnel.OnRunning()
|
||||||
hcCompatibleProvider(cfg.Providers)
|
hcCompatibleProvider(cfg.Providers)
|
||||||
initExternalUI(cfg.Controller)
|
updateUpdater(cfg)
|
||||||
|
|
||||||
resolver.ResetConnection()
|
resolver.ResetConnection()
|
||||||
}
|
}
|
||||||
|
@ -176,6 +177,9 @@ func GetGeneral() *config.General {
|
||||||
GlobalClientFingerprint: tlsC.GetGlobalFingerprint(),
|
GlobalClientFingerprint: tlsC.GetGlobalFingerprint(),
|
||||||
GlobalUA: mihomoHttp.UA(),
|
GlobalUA: mihomoHttp.UA(),
|
||||||
ETagSupport: resource.ETag(),
|
ETagSupport: resource.ETag(),
|
||||||
|
KeepAliveInterval: int(keepalive.KeepAliveInterval() / time.Second),
|
||||||
|
KeepAliveIdle: int(keepalive.KeepAliveIdle() / time.Second),
|
||||||
|
DisableKeepAlive: keepalive.DisableKeepAlive(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return general
|
return general
|
||||||
|
@ -394,7 +398,12 @@ func updateTunnels(tunnels []LC.Tunnel) {
|
||||||
listener.PatchTunnel(tunnels, tunnel.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 = updater.NewUiUpdater(controller.ExternalUI, controller.ExternalUIURL, controller.ExternalUIName)
|
||||||
updater.DefaultUiUpdater.AutoDownloadUI()
|
updater.DefaultUiUpdater.AutoDownloadUI()
|
||||||
}
|
}
|
||||||
|
@ -412,6 +421,10 @@ func updateGeneral(general *config.General) {
|
||||||
inbound.SetTfo(general.InboundTfo)
|
inbound.SetTfo(general.InboundTfo)
|
||||||
inbound.SetMPTCP(general.InboundMPTCP)
|
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)
|
adapter.UnifiedDelay.Store(general.UnifiedDelay)
|
||||||
|
|
||||||
dialer.DefaultInterface.Store(general.Interface)
|
dialer.DefaultInterface.Store(general.Interface)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user