[FEAT] Add geodata loader mode switch
This commit is contained in:
parent
c28f42d823
commit
28a1475f66
3 changed files with 15 additions and 13 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/adapter"
|
"github.com/Dreamacro/clash/adapter"
|
||||||
"github.com/Dreamacro/clash/adapter/outbound"
|
"github.com/Dreamacro/clash/adapter/outbound"
|
||||||
|
@ -309,7 +310,7 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
||||||
|
|
||||||
func parseGeneral(cfg *RawConfig) (*General, error) {
|
func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||||
externalUI := cfg.ExternalUI
|
externalUI := cfg.ExternalUI
|
||||||
|
geodata.SetLoader(cfg.GeodataLoader)
|
||||||
// checkout externalUI exist
|
// checkout externalUI exist
|
||||||
if externalUI != "" {
|
if externalUI != "" {
|
||||||
externalUI = C.Path.Resolve(externalUI)
|
externalUI = C.Path.Resolve(externalUI)
|
||||||
|
@ -334,11 +335,12 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||||
ExternalUI: cfg.ExternalUI,
|
ExternalUI: cfg.ExternalUI,
|
||||||
Secret: cfg.Secret,
|
Secret: cfg.Secret,
|
||||||
},
|
},
|
||||||
UnifiedDelay: cfg.UnifiedDelay,
|
UnifiedDelay: cfg.UnifiedDelay,
|
||||||
Mode: cfg.Mode,
|
Mode: cfg.Mode,
|
||||||
LogLevel: cfg.LogLevel,
|
LogLevel: cfg.LogLevel,
|
||||||
IPv6: cfg.IPv6,
|
IPv6: cfg.IPv6,
|
||||||
Interface: cfg.Interface,
|
Interface: cfg.Interface,
|
||||||
|
GeodataLoader: cfg.GeodataLoader,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,6 +488,7 @@ time = ClashTime()
|
||||||
func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[string]*providerTypes.RuleProvider, error) {
|
func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[string]*providerTypes.RuleProvider, error) {
|
||||||
ruleProviders := map[string]*providerTypes.RuleProvider{}
|
ruleProviders := map[string]*providerTypes.RuleProvider{}
|
||||||
|
|
||||||
|
startTime := time.Now()
|
||||||
// parse rule provider
|
// parse rule provider
|
||||||
for name, mapping := range cfg.RuleProvider {
|
for name, mapping := range cfg.RuleProvider {
|
||||||
rp, err := RP.ParseRuleProvider(name, mapping)
|
rp, err := RP.ParseRuleProvider(name, mapping)
|
||||||
|
@ -560,7 +563,9 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[strin
|
||||||
rules = append(rules, parsed)
|
rules = append(rules, parsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elapsedTime := time.Since(startTime) / time.Millisecond // duration in ms
|
||||||
|
log.Infoln("Initialization time consuming %dms", elapsedTime) //Segment finished in xxm
|
||||||
|
log.Infoln("Geodata Loader mode: %s", geodata.LoaderName())
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
|
|
||||||
return rules, ruleProviders, nil
|
return rules, ruleProviders, nil
|
||||||
|
|
|
@ -78,11 +78,11 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
||||||
|
|
||||||
updateUsers(cfg.Users)
|
updateUsers(cfg.Users)
|
||||||
updateHosts(cfg.Hosts)
|
updateHosts(cfg.Hosts)
|
||||||
|
updateGeneral(cfg.General, cfg.Tun, force)
|
||||||
updateProxies(cfg.Proxies, cfg.Providers)
|
updateProxies(cfg.Proxies, cfg.Providers)
|
||||||
updateRules(cfg.Rules, cfg.RuleProviders)
|
updateRules(cfg.Rules, cfg.RuleProviders)
|
||||||
updateIPTables(cfg.DNS, cfg.General, cfg.Tun)
|
updateIPTables(cfg.DNS, cfg.General, cfg.Tun)
|
||||||
updateDNS(cfg.DNS, cfg.Tun)
|
updateDNS(cfg.DNS, cfg.Tun)
|
||||||
updateGeneral(cfg.General, cfg.Tun, force)
|
|
||||||
updateTun(cfg.Tun)
|
updateTun(cfg.Tun)
|
||||||
updateExperimental(cfg)
|
updateExperimental(cfg)
|
||||||
loadProvider(cfg.RuleProviders, cfg.Providers)
|
loadProvider(cfg.RuleProviders, cfg.Providers)
|
||||||
|
@ -242,9 +242,6 @@ func updateGeneral(general *config.General, Tun *config.Tun, force bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
geodataLoader := general.GeodataLoader
|
|
||||||
G.SetLoader(geodataLoader)
|
|
||||||
|
|
||||||
allowLan := general.AllowLan
|
allowLan := general.AllowLan
|
||||||
P.SetAllowLan(allowLan)
|
P.SetAllowLan(allowLan)
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ func ParseRule(tp, payload, target string, params []string) (C.Rule, error) {
|
||||||
)
|
)
|
||||||
|
|
||||||
ruleExtra := &C.RuleExtra{
|
ruleExtra := &C.RuleExtra{
|
||||||
Network: RC.FindNetwork(params),
|
Network: RC.FindNetwork(params),
|
||||||
SourceIPs: RC.FindSourceIPs(params),
|
SourceIPs: RC.FindSourceIPs(params),
|
||||||
ProcessNames: RC.FindProcessName(params),
|
ProcessNames: RC.FindProcessName(params),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue