mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
chore: temporary update general in ParseRawConfig and rollback before its retur
Some checks are pending
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
Some checks are pending
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
This commit is contained in:
parent
9937ae1002
commit
8e6eb70e71
|
@ -58,7 +58,7 @@ func (u *UIUpdater) AutoDownloadUI() {
|
||||||
log.Infoln("External UI downloading ...")
|
log.Infoln("External UI downloading ...")
|
||||||
err := u.downloadUI()
|
err := u.downloadUI()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("Error downloading UI:", err)
|
log.Errorln("Error downloading UI: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
_ "unsafe"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/adapter"
|
"github.com/metacubex/mihomo/adapter"
|
||||||
"github.com/metacubex/mihomo/adapter/outbound"
|
"github.com/metacubex/mihomo/adapter/outbound"
|
||||||
|
@ -19,12 +20,9 @@ import (
|
||||||
"github.com/metacubex/mihomo/component/cidr"
|
"github.com/metacubex/mihomo/component/cidr"
|
||||||
"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"
|
|
||||||
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/sniffer"
|
"github.com/metacubex/mihomo/component/sniffer"
|
||||||
tlsC "github.com/metacubex/mihomo/component/tls"
|
|
||||||
"github.com/metacubex/mihomo/component/trie"
|
"github.com/metacubex/mihomo/component/trie"
|
||||||
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"
|
||||||
|
@ -588,10 +586,11 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
||||||
}
|
}
|
||||||
config.General = general
|
config.General = general
|
||||||
|
|
||||||
if len(config.General.GlobalClientFingerprint) != 0 {
|
// We need to temporarily apply some configuration in general and roll back after parsing the complete configuration.
|
||||||
log.Debugln("GlobalClientFingerprint: %s", config.General.GlobalClientFingerprint)
|
// The loading and downloading of geodata in the parseRules and parseRuleProviders rely on these.
|
||||||
tlsC.SetGlobalUtlsClient(config.General.GlobalClientFingerprint)
|
// This implementation is very disgusting, but there is currently no better solution
|
||||||
}
|
rollback := temporaryUpdateGeneral(config.General)
|
||||||
|
defer rollback()
|
||||||
|
|
||||||
controller, err := parseController(rawCfg)
|
controller, err := parseController(rawCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -707,17 +706,10 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseGeneral(cfg *RawConfig) (*General, error) {
|
//go:linkname temporaryUpdateGeneral
|
||||||
geodata.SetGeodataMode(cfg.GeodataMode)
|
func temporaryUpdateGeneral(general *General) func()
|
||||||
geodata.SetLoader(cfg.GeodataLoader)
|
|
||||||
geodata.SetSiteMatcher(cfg.GeositeMatcher)
|
|
||||||
geodata.SetGeoIpUrl(cfg.GeoXUrl.GeoIp)
|
|
||||||
geodata.SetGeoSiteUrl(cfg.GeoXUrl.GeoSite)
|
|
||||||
geodata.SetMmdbUrl(cfg.GeoXUrl.Mmdb)
|
|
||||||
geodata.SetASNUrl(cfg.GeoXUrl.ASN)
|
|
||||||
mihomoHttp.SetUA(cfg.GlobalUA)
|
|
||||||
resource.SetETag(cfg.ETagSupport)
|
|
||||||
|
|
||||||
|
func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||||
return &General{
|
return &General{
|
||||||
Inbound: Inbound{
|
Inbound: Inbound{
|
||||||
Port: cfg.Port,
|
Port: cfg.Port,
|
||||||
|
@ -751,6 +743,7 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||||
GeoUpdateInterval: cfg.GeoUpdateInterval,
|
GeoUpdateInterval: cfg.GeoUpdateInterval,
|
||||||
GeodataMode: cfg.GeodataMode,
|
GeodataMode: cfg.GeodataMode,
|
||||||
GeodataLoader: cfg.GeodataLoader,
|
GeodataLoader: cfg.GeodataLoader,
|
||||||
|
GeositeMatcher: cfg.GeositeMatcher,
|
||||||
TCPConcurrent: cfg.TCPConcurrent,
|
TCPConcurrent: cfg.TCPConcurrent,
|
||||||
FindProcessMode: cfg.FindProcessMode,
|
FindProcessMode: cfg.FindProcessMode,
|
||||||
GlobalClientFingerprint: cfg.GlobalClientFingerprint,
|
GlobalClientFingerprint: cfg.GlobalClientFingerprint,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
_ "unsafe"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/adapter"
|
"github.com/metacubex/mihomo/adapter"
|
||||||
"github.com/metacubex/mihomo/adapter/inbound"
|
"github.com/metacubex/mihomo/adapter/inbound"
|
||||||
|
@ -16,7 +17,7 @@ import (
|
||||||
"github.com/metacubex/mihomo/component/auth"
|
"github.com/metacubex/mihomo/component/auth"
|
||||||
"github.com/metacubex/mihomo/component/ca"
|
"github.com/metacubex/mihomo/component/ca"
|
||||||
"github.com/metacubex/mihomo/component/dialer"
|
"github.com/metacubex/mihomo/component/dialer"
|
||||||
G "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/iface"
|
"github.com/metacubex/mihomo/component/iface"
|
||||||
"github.com/metacubex/mihomo/component/keepalive"
|
"github.com/metacubex/mihomo/component/keepalive"
|
||||||
|
@ -101,7 +102,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||||
updateRules(cfg.Rules, cfg.SubRules, cfg.RuleProviders)
|
updateRules(cfg.Rules, cfg.SubRules, cfg.RuleProviders)
|
||||||
updateSniffer(cfg.Sniffer)
|
updateSniffer(cfg.Sniffer)
|
||||||
updateHosts(cfg.Hosts)
|
updateHosts(cfg.Hosts)
|
||||||
updateGeneral(cfg.General)
|
updateGeneral(cfg.General, true)
|
||||||
updateNTP(cfg.NTP)
|
updateNTP(cfg.NTP)
|
||||||
updateDNS(cfg.DNS, cfg.General.IPv6)
|
updateDNS(cfg.DNS, cfg.General.IPv6)
|
||||||
updateListeners(cfg.General, cfg.Listeners, force)
|
updateListeners(cfg.General, cfg.Listeners, force)
|
||||||
|
@ -161,16 +162,16 @@ func GetGeneral() *config.General {
|
||||||
Interface: dialer.DefaultInterface.Load(),
|
Interface: dialer.DefaultInterface.Load(),
|
||||||
RoutingMark: int(dialer.DefaultRoutingMark.Load()),
|
RoutingMark: int(dialer.DefaultRoutingMark.Load()),
|
||||||
GeoXUrl: config.GeoXUrl{
|
GeoXUrl: config.GeoXUrl{
|
||||||
GeoIp: G.GeoIpUrl(),
|
GeoIp: geodata.GeoIpUrl(),
|
||||||
Mmdb: G.MmdbUrl(),
|
Mmdb: geodata.MmdbUrl(),
|
||||||
ASN: G.ASNUrl(),
|
ASN: geodata.ASNUrl(),
|
||||||
GeoSite: G.GeoSiteUrl(),
|
GeoSite: geodata.GeoSiteUrl(),
|
||||||
},
|
},
|
||||||
GeoAutoUpdate: updater.GeoAutoUpdate(),
|
GeoAutoUpdate: updater.GeoAutoUpdate(),
|
||||||
GeoUpdateInterval: updater.GeoUpdateInterval(),
|
GeoUpdateInterval: updater.GeoUpdateInterval(),
|
||||||
GeodataMode: G.GeodataMode(),
|
GeodataMode: geodata.GeodataMode(),
|
||||||
GeodataLoader: G.LoaderName(),
|
GeodataLoader: geodata.LoaderName(),
|
||||||
GeositeMatcher: G.SiteMatcherName(),
|
GeositeMatcher: geodata.SiteMatcherName(),
|
||||||
TCPConcurrent: dialer.GetTcpConcurrent(),
|
TCPConcurrent: dialer.GetTcpConcurrent(),
|
||||||
FindProcessMode: tunnel.FindProcessMode(),
|
FindProcessMode: tunnel.FindProcessMode(),
|
||||||
Sniffing: tunnel.IsSniffing(),
|
Sniffing: tunnel.IsSniffing(),
|
||||||
|
@ -408,13 +409,22 @@ func updateUpdater(cfg *config.Config) {
|
||||||
updater.DefaultUiUpdater.AutoDownloadUI()
|
updater.DefaultUiUpdater.AutoDownloadUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateGeneral(general *config.General) {
|
//go:linkname temporaryUpdateGeneral github.com/metacubex/mihomo/config.temporaryUpdateGeneral
|
||||||
|
func temporaryUpdateGeneral(general *config.General) func() {
|
||||||
|
oldGeneral := GetGeneral()
|
||||||
|
updateGeneral(general, false)
|
||||||
|
return func() {
|
||||||
|
updateGeneral(oldGeneral, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateGeneral(general *config.General, logging bool) {
|
||||||
tunnel.SetMode(general.Mode)
|
tunnel.SetMode(general.Mode)
|
||||||
tunnel.SetFindProcessMode(general.FindProcessMode)
|
tunnel.SetFindProcessMode(general.FindProcessMode)
|
||||||
resolver.DisableIPv6 = !general.IPv6
|
resolver.DisableIPv6 = !general.IPv6
|
||||||
|
|
||||||
if general.TCPConcurrent {
|
dialer.SetTcpConcurrent(general.TCPConcurrent)
|
||||||
dialer.SetTcpConcurrent(general.TCPConcurrent)
|
if logging && general.TCPConcurrent {
|
||||||
log.Infoln("Use tcp concurrent")
|
log.Infoln("Use tcp concurrent")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,13 +439,23 @@ func updateGeneral(general *config.General) {
|
||||||
|
|
||||||
dialer.DefaultInterface.Store(general.Interface)
|
dialer.DefaultInterface.Store(general.Interface)
|
||||||
dialer.DefaultRoutingMark.Store(int32(general.RoutingMark))
|
dialer.DefaultRoutingMark.Store(int32(general.RoutingMark))
|
||||||
if general.RoutingMark > 0 {
|
if logging && general.RoutingMark > 0 {
|
||||||
log.Infoln("Use routing mark: %#x", general.RoutingMark)
|
log.Infoln("Use routing mark: %#x", general.RoutingMark)
|
||||||
}
|
}
|
||||||
|
|
||||||
iface.FlushCache()
|
iface.FlushCache()
|
||||||
G.SetLoader(general.GeodataLoader)
|
|
||||||
G.SetSiteMatcher(general.GeositeMatcher)
|
geodata.SetGeodataMode(general.GeodataMode)
|
||||||
|
geodata.SetLoader(general.GeodataLoader)
|
||||||
|
geodata.SetSiteMatcher(general.GeositeMatcher)
|
||||||
|
geodata.SetGeoIpUrl(general.GeoXUrl.GeoIp)
|
||||||
|
geodata.SetGeoSiteUrl(general.GeoXUrl.GeoSite)
|
||||||
|
geodata.SetMmdbUrl(general.GeoXUrl.Mmdb)
|
||||||
|
geodata.SetASNUrl(general.GeoXUrl.ASN)
|
||||||
|
mihomoHttp.SetUA(general.GlobalUA)
|
||||||
|
resource.SetETag(general.ETagSupport)
|
||||||
|
|
||||||
|
tlsC.SetGlobalUtlsClient(general.GlobalClientFingerprint)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUsers(users []auth.AuthUser) {
|
func updateUsers(users []auth.AuthUser) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user