[build test]

This commit is contained in:
MetaCubeX 2022-03-16 17:29:09 +08:00
parent 1034780e8e
commit 0f2123179a
6 changed files with 19 additions and 14 deletions

View file

@ -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,

View file

@ -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 {

View file

@ -16,7 +16,6 @@ const (
Script
RuleSet
Network
Combination
MATCH
AND
OR

View file

@ -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
)

View file

@ -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 {

View file

@ -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
}