diff --git a/config/config.go b/config/config.go index 37698bdf..36a938cc 100644 --- a/config/config.go +++ b/config/config.go @@ -208,7 +208,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) { AllowLan: false, BindAddress: "*", Mode: T.Rule, - GeodataMode: GeodataMode, + GeodataMode: C.GeodataMode, GeodataLoader: "memconservative", AutoIptables: false, UnifiedDelay: false, diff --git a/config/initial.go b/config/initial.go index 9b242afc..c312c4d0 100644 --- a/config/initial.go +++ b/config/initial.go @@ -12,8 +12,6 @@ import ( "github.com/Dreamacro/clash/log" ) -var GeodataMode bool - func downloadMMDB(path string) (err error) { resp, err := http.Get("https://raw.githubusercontents.com/Loyalsoldier/geoip/release/Country.mmdb") if err != nil { @@ -87,7 +85,7 @@ func initGeoSite() error { } func initGeoIP() error { - if GeodataMode { + if C.GeodataMode { if _, err := os.Stat(C.Path.GeoIP()); os.IsNotExist(err) { log.Infoln("Need GeoIP but can't find GeoIP.dat, start download") if err := downloadGeoIP(C.Path.GeoIP()); err != nil { diff --git a/constant/rule.go b/constant/rule.go index fdb11a72..9c79013a 100644 --- a/constant/rule.go +++ b/constant/rule.go @@ -16,7 +16,6 @@ const ( Script RuleSet Network - Combination MATCH AND OR diff --git a/constant/version.go b/constant/version.go index 9bee7777..56495b84 100644 --- a/constant/version.go +++ b/constant/version.go @@ -1,8 +1,9 @@ package constant var ( - Meta = true - Version = "1.9.1" - BuildTime = "unknown time" - ClashName = "Clash.Meta" + Meta = true + Version = "1.9.1" + BuildTime = "unknown time" + ClashName = "Clash.Meta" + GeodataMode bool ) diff --git a/main.go b/main.go index 4c465d2a..4ba72960 100644 --- a/main.go +++ b/main.go @@ -74,7 +74,7 @@ func main() { } if geodataMode || executor.GetGeneral().GeodataMode { - config.GeodataMode = true + C.GeodataMode = true } if err := config.Init(C.Path.HomeDir()); err != nil { diff --git a/rule/common/geoip.go b/rule/common/geoip.go index 29355ed9..bac36f45 100644 --- a/rule/common/geoip.go +++ b/rule/common/geoip.go @@ -5,7 +5,6 @@ import ( "github.com/Dreamacro/clash/component/geodata" "github.com/Dreamacro/clash/component/geodata/router" "github.com/Dreamacro/clash/component/mmdb" - "github.com/Dreamacro/clash/config" "strings" C "github.com/Dreamacro/clash/constant" @@ -37,7 +36,7 @@ func (g *GEOIP) Match(metadata *C.Metadata) bool { if strings.EqualFold(g.country, "LAN") || C.TunBroadcastAddr.Equal(ip) { return ip.IsPrivate() } - if !config.GeodataMode { + if !C.GeodataMode { record, _ := mmdb.Instance().Country(ip) return strings.EqualFold(record.Country.IsoCode, g.country) } @@ -69,13 +68,22 @@ func (g *GEOIP) GetIPMatcher() *router.GeoIPMatcher { } func NewGEOIP(country string, adapter string, noResolveIP bool, ruleExtra *C.RuleExtra) (*GEOIP, error) { + if !C.GeodataMode { + geoip := &GEOIP{ + country: country, + adapter: adapter, + noResolveIP: noResolveIP, + ruleExtra: ruleExtra, + } + return geoip, nil + } + geoIPMatcher, recordsCount, err := geodata.LoadGeoIPMatcher(country) if err != nil { return nil, fmt.Errorf("[GeoIP] %s", err.Error()) } log.Infoln("Start initial GeoIP rule %s => %s, records: %d", country, adapter, recordsCount) - geoip := &GEOIP{ country: country, adapter: adapter, @@ -83,6 +91,5 @@ func NewGEOIP(country string, adapter string, noResolveIP bool, ruleExtra *C.Rul ruleExtra: ruleExtra, geoIPMatcher: geoIPMatcher, } - return geoip, nil }