From d9d8507c8fdf8607e1a31f19e1c216242be933c4 Mon Sep 17 00:00:00 2001 From: admin <2833154405@qq.com> Date: Mon, 21 Mar 2022 12:23:21 +0800 Subject: [PATCH 1/4] [Fix] skip when country code not found in GeoIP.dat --- rule/provider/parse.go | 3 +++ rule/provider/provider.go | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/rule/provider/parse.go b/rule/provider/parse.go index 8d07f469..230bc888 100644 --- a/rule/provider/parse.go +++ b/rule/provider/parse.go @@ -85,6 +85,9 @@ func parseRule(tp, payload, target string, params []string) (C.Rule, error) { default: parseErr = fmt.Errorf("unsupported rule type %s", tp) } + if parseErr != nil { + return nil, parseErr + } ruleExtra := &C.RuleExtra{ Network: RC.FindNetwork(params), SourceIPs: RC.FindSourceIPs(params), diff --git a/rule/provider/provider.go b/rule/provider/provider.go index 2befc694..a587ecaf 100644 --- a/rule/provider/provider.go +++ b/rule/provider/provider.go @@ -6,10 +6,12 @@ import ( "github.com/Dreamacro/clash/component/trie" C "github.com/Dreamacro/clash/constant" P "github.com/Dreamacro/clash/constant/provider" + "github.com/Dreamacro/clash/log" "gopkg.in/yaml.v2" "runtime" "strings" "time" + "unsafe" ) var ( @@ -129,7 +131,12 @@ func NewRuleSetProvider(name string, behavior P.RuleType, interval time.Duration return err } - rp.count = len(rulesRaw) + if rp.behavior == P.Classical { + rp.count = len(*(*[]C.Rule)(unsafe.Pointer(&rules))) + } else { + rp.count = len(rulesRaw) + } + rp.setRules(rules) return nil } @@ -201,13 +208,12 @@ func handleClassicalRules(rules []string) (interface{}, error) { var classicalRules []C.Rule for _, rawRule := range rules { ruleType, rule, params := ruleParse(rawRule) - if ruleType == "RULE-SET" { - return nil, errors.New("error rule type") - } r, err := parseRule(ruleType, rule, "", params) if err != nil { - return nil, err + //return nil, err + log.Warnln("%s", err) + continue } classicalRules = append(classicalRules, r) From 6a4d2b336819e89e9bf10b0dfb767c7460675fc5 Mon Sep 17 00:00:00 2001 From: admin <2833154405@qq.com> Date: Mon, 21 Mar 2022 12:34:32 +0800 Subject: [PATCH 2/4] Change type conversion method --- rule/provider/provider.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rule/provider/provider.go b/rule/provider/provider.go index a587ecaf..9ffc788f 100644 --- a/rule/provider/provider.go +++ b/rule/provider/provider.go @@ -11,7 +11,6 @@ import ( "runtime" "strings" "time" - "unsafe" ) var ( @@ -132,7 +131,7 @@ func NewRuleSetProvider(name string, behavior P.RuleType, interval time.Duration } if rp.behavior == P.Classical { - rp.count = len(*(*[]C.Rule)(unsafe.Pointer(&rules))) + rp.count = len(rules.([]C.Rule)) } else { rp.count = len(rulesRaw) } From 5386c3903df5c88886bb56e84a3f3b75aacc7a52 Mon Sep 17 00:00:00 2001 From: admin <2833154405@qq.com> Date: Mon, 21 Mar 2022 18:09:36 +0800 Subject: [PATCH 3/4] delete useless code --- config/config.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/config/config.go b/config/config.go index 43d10b94..702d93a1 100644 --- a/config/config.go +++ b/config/config.go @@ -440,13 +440,6 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[ providersMap[name] = pd } - for _, proxyProvider := range providersMap { - log.Infoln("Start initial provider %s", proxyProvider.Name()) - if err := proxyProvider.Initial(); err != nil { - return nil, nil, fmt.Errorf("initial proxy provider %s error: %w", proxyProvider.Name(), err) - } - } - // parse proxy group for idx, mapping := range groupsConfig { group, err := outboundgroup.ParseProxyGroup(mapping, proxies, providersMap) From 668d29d91ff792cedcac39630e1ba9a6a21a027d Mon Sep 17 00:00:00 2001 From: admin <2833154405@qq.com> Date: Mon, 21 Mar 2022 19:47:21 +0800 Subject: [PATCH 4/4] init sequence adjustment --- hub/executor/executor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hub/executor/executor.go b/hub/executor/executor.go index e261ef9e..aff16826 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -75,14 +75,14 @@ func ApplyConfig(cfg *config.Config, force bool) { defer mux.Unlock() updateUsers(cfg.Users) - updateHosts(cfg.Hosts) updateProxies(cfg.Proxies, cfg.Providers) updateRules(cfg.Rules, cfg.RuleProviders) - updateGeneral(cfg.General, force) updateDNS(cfg.DNS, cfg.Tun) + updateGeneral(cfg.General, force) updateTun(cfg.Tun) updateIPTables(cfg.DNS, cfg.General, cfg.Tun) updateExperimental(cfg) + updateHosts(cfg.Hosts) loadProvider(cfg.RuleProviders, cfg.Providers) updateProfile(cfg)