[build test]
This commit is contained in:
parent
40381afa05
commit
7a3a4413c9
6 changed files with 19 additions and 14 deletions
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -16,7 +16,6 @@ const (
|
|||
Script
|
||||
RuleSet
|
||||
Network
|
||||
Combination
|
||||
MATCH
|
||||
AND
|
||||
OR
|
||||
|
|
|
@ -5,4 +5,5 @@ var (
|
|||
Version = "1.9.1"
|
||||
BuildTime = "unknown time"
|
||||
ClashName = "Clash.Meta"
|
||||
GeodataMode bool
|
||||
)
|
||||
|
|
2
main.go
2
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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue