From 28a1475f669f90561d79896a5877a81abe591b8e Mon Sep 17 00:00:00 2001 From: Clash-Mini Date: Sat, 5 Feb 2022 02:42:49 +0800 Subject: [PATCH] [FEAT] Add geodata loader mode switch --- config/config.go | 19 ++++++++++++------- hub/executor/executor.go | 5 +---- rule/parser.go | 4 ++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/config/config.go b/config/config.go index 292a957e..55b382b7 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,7 @@ import ( "regexp" "runtime" "strings" + "time" "github.com/Dreamacro/clash/adapter" "github.com/Dreamacro/clash/adapter/outbound" @@ -309,7 +310,7 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) { func parseGeneral(cfg *RawConfig) (*General, error) { externalUI := cfg.ExternalUI - + geodata.SetLoader(cfg.GeodataLoader) // checkout externalUI exist if externalUI != "" { externalUI = C.Path.Resolve(externalUI) @@ -334,11 +335,12 @@ func parseGeneral(cfg *RawConfig) (*General, error) { ExternalUI: cfg.ExternalUI, Secret: cfg.Secret, }, - UnifiedDelay: cfg.UnifiedDelay, - Mode: cfg.Mode, - LogLevel: cfg.LogLevel, - IPv6: cfg.IPv6, - Interface: cfg.Interface, + UnifiedDelay: cfg.UnifiedDelay, + Mode: cfg.Mode, + LogLevel: cfg.LogLevel, + IPv6: cfg.IPv6, + Interface: cfg.Interface, + GeodataLoader: cfg.GeodataLoader, }, nil } @@ -486,6 +488,7 @@ time = ClashTime() func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[string]*providerTypes.RuleProvider, error) { ruleProviders := map[string]*providerTypes.RuleProvider{} + startTime := time.Now() // parse rule provider for name, mapping := range cfg.RuleProvider { 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) } } - + 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() return rules, ruleProviders, nil diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 378f5cbf..3dc5d14c 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -78,11 +78,11 @@ func ApplyConfig(cfg *config.Config, force bool) { updateUsers(cfg.Users) updateHosts(cfg.Hosts) + updateGeneral(cfg.General, cfg.Tun, force) updateProxies(cfg.Proxies, cfg.Providers) updateRules(cfg.Rules, cfg.RuleProviders) updateIPTables(cfg.DNS, cfg.General, cfg.Tun) updateDNS(cfg.DNS, cfg.Tun) - updateGeneral(cfg.General, cfg.Tun, force) updateTun(cfg.Tun) updateExperimental(cfg) loadProvider(cfg.RuleProviders, cfg.Providers) @@ -242,9 +242,6 @@ func updateGeneral(general *config.General, Tun *config.Tun, force bool) { return } - geodataLoader := general.GeodataLoader - G.SetLoader(geodataLoader) - allowLan := general.AllowLan P.SetAllowLan(allowLan) diff --git a/rule/parser.go b/rule/parser.go index 88c8b375..a125027c 100644 --- a/rule/parser.go +++ b/rule/parser.go @@ -15,8 +15,8 @@ func ParseRule(tp, payload, target string, params []string) (C.Rule, error) { ) ruleExtra := &C.RuleExtra{ - Network: RC.FindNetwork(params), - SourceIPs: RC.FindSourceIPs(params), + Network: RC.FindNetwork(params), + SourceIPs: RC.FindSourceIPs(params), ProcessNames: RC.FindProcessName(params), }