[build test]

This commit is contained in:
gVisor bot 2022-03-16 17:29:09 +08:00
parent 40381afa05
commit 7a3a4413c9
6 changed files with 19 additions and 14 deletions

View File

@ -208,7 +208,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
AllowLan: false, AllowLan: false,
BindAddress: "*", BindAddress: "*",
Mode: T.Rule, Mode: T.Rule,
GeodataMode: GeodataMode, GeodataMode: C.GeodataMode,
GeodataLoader: "memconservative", GeodataLoader: "memconservative",
AutoIptables: false, AutoIptables: false,
UnifiedDelay: false, UnifiedDelay: false,

View File

@ -12,8 +12,6 @@ import (
"github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/log"
) )
var GeodataMode bool
func downloadMMDB(path string) (err error) { func downloadMMDB(path string) (err error) {
resp, err := http.Get("https://raw.githubusercontents.com/Loyalsoldier/geoip/release/Country.mmdb") resp, err := http.Get("https://raw.githubusercontents.com/Loyalsoldier/geoip/release/Country.mmdb")
if err != nil { if err != nil {
@ -87,7 +85,7 @@ func initGeoSite() error {
} }
func initGeoIP() error { func initGeoIP() error {
if GeodataMode { if C.GeodataMode {
if _, err := os.Stat(C.Path.GeoIP()); os.IsNotExist(err) { if _, err := os.Stat(C.Path.GeoIP()); os.IsNotExist(err) {
log.Infoln("Need GeoIP but can't find GeoIP.dat, start download") log.Infoln("Need GeoIP but can't find GeoIP.dat, start download")
if err := downloadGeoIP(C.Path.GeoIP()); err != nil { if err := downloadGeoIP(C.Path.GeoIP()); err != nil {

View File

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

View File

@ -1,8 +1,9 @@
package constant package constant
var ( var (
Meta = true Meta = true
Version = "1.9.1" Version = "1.9.1"
BuildTime = "unknown time" BuildTime = "unknown time"
ClashName = "Clash.Meta" ClashName = "Clash.Meta"
GeodataMode bool
) )

View File

@ -74,7 +74,7 @@ func main() {
} }
if geodataMode || executor.GetGeneral().GeodataMode { if geodataMode || executor.GetGeneral().GeodataMode {
config.GeodataMode = true C.GeodataMode = true
} }
if err := config.Init(C.Path.HomeDir()); err != nil { 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"
"github.com/Dreamacro/clash/component/geodata/router" "github.com/Dreamacro/clash/component/geodata/router"
"github.com/Dreamacro/clash/component/mmdb" "github.com/Dreamacro/clash/component/mmdb"
"github.com/Dreamacro/clash/config"
"strings" "strings"
C "github.com/Dreamacro/clash/constant" 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) { if strings.EqualFold(g.country, "LAN") || C.TunBroadcastAddr.Equal(ip) {
return ip.IsPrivate() return ip.IsPrivate()
} }
if !config.GeodataMode { if !C.GeodataMode {
record, _ := mmdb.Instance().Country(ip) record, _ := mmdb.Instance().Country(ip)
return strings.EqualFold(record.Country.IsoCode, g.country) 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) { 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) geoIPMatcher, recordsCount, err := geodata.LoadGeoIPMatcher(country)
if err != nil { if err != nil {
return nil, fmt.Errorf("[GeoIP] %s", err.Error()) return nil, fmt.Errorf("[GeoIP] %s", err.Error())
} }
log.Infoln("Start initial GeoIP rule %s => %s, records: %d", country, adapter, recordsCount) log.Infoln("Start initial GeoIP rule %s => %s, records: %d", country, adapter, recordsCount)
geoip := &GEOIP{ geoip := &GEOIP{
country: country, country: country,
adapter: adapter, adapter: adapter,
@ -83,6 +91,5 @@ func NewGEOIP(country string, adapter string, noResolveIP bool, ruleExtra *C.Rul
ruleExtra: ruleExtra, ruleExtra: ruleExtra,
geoIPMatcher: geoIPMatcher, geoIPMatcher: geoIPMatcher,
} }
return geoip, nil return geoip, nil
} }