Feature: add mode script

This commit is contained in:
yaling888
2021-10-15 14:11:14 +08:00
parent 862174d21b
commit c0e9d69163
28 changed files with 1918 additions and 356 deletions

View File

@ -2,16 +2,13 @@ package dns
import (
"net"
"strings"
"github.com/Dreamacro/clash/component/mmdb"
"github.com/Dreamacro/clash/component/trie"
"github.com/Dreamacro/clash/log"
"github.com/Dreamacro/clash/rule/geodata"
"github.com/Dreamacro/clash/rule/geodata/router"
_ "github.com/Dreamacro/clash/rule/geodata/standard"
//_ "github.com/Dreamacro/clash/rule/geodata/standard"
)
var multiGeoIPMatcher *router.MultiGeoIPMatcher
type fallbackIPFilter interface {
Match(net.IP) bool
}
@ -21,49 +18,8 @@ type geoipFilter struct {
}
func (gf *geoipFilter) Match(ip net.IP) bool {
if multiGeoIPMatcher == nil {
countryCode := gf.code
countryCodePrivate := "private"
geoLoader, err := geodata.GetGeoDataLoader("standard")
if err != nil {
log.Errorln("[GeoIPFilter] GetGeoDataLoader error: %s", err.Error())
return false
}
recordsCN, err := geoLoader.LoadGeoIP(countryCode)
if err != nil {
log.Errorln("[GeoIPFilter] LoadGeoIP error: %s", err.Error())
return false
}
recordsPrivate, err := geoLoader.LoadGeoIP(countryCodePrivate)
if err != nil {
log.Errorln("[GeoIPFilter] LoadGeoIP error: %s", err.Error())
return false
}
geoips := []*router.GeoIP{
{
CountryCode: countryCode,
Cidr: recordsCN,
ReverseMatch: false,
},
{
CountryCode: countryCodePrivate,
Cidr: recordsPrivate,
ReverseMatch: false,
},
}
multiGeoIPMatcher, err = router.NewMultiGeoIPMatcher(geoips)
if err != nil {
log.Errorln("[GeoIPFilter] NewMultiGeoIPMatcher error: %s", err.Error())
return false
}
}
return !multiGeoIPMatcher.ApplyIp(ip)
record, _ := mmdb.Instance().Country(ip)
return !strings.EqualFold(record.Country.IsoCode, gf.code) && !ip.IsPrivate()
}
type ipnetFilter struct {