Improve: simple dns prefetch

This commit is contained in:
Dreamacro
2018-06-11 18:36:39 +08:00
parent 4f192ef575
commit 4f769debe7
8 changed files with 30 additions and 21 deletions

View File

@ -1,8 +1,6 @@
package rules
import (
"net"
C "github.com/Dreamacro/clash/constant"
"github.com/oschwald/geoip2-golang"
@ -29,14 +27,10 @@ func (g *GEOIP) RuleType() C.RuleType {
}
func (g *GEOIP) IsMatch(addr *C.Addr) bool {
if addr.AddrType == C.AtypDomainName {
if addr.IP == nil {
return false
}
dstIP := net.ParseIP(addr.Host)
if dstIP == nil {
return false
}
record, _ := mmdb.Country(dstIP)
record, _ := mmdb.Country(*addr.IP)
return record.Country.IsoCode == g.country
}

View File

@ -16,15 +16,11 @@ func (i *IPCIDR) RuleType() C.RuleType {
}
func (i *IPCIDR) IsMatch(addr *C.Addr) bool {
if addr.AddrType == C.AtypDomainName {
return false
}
ip := net.ParseIP(addr.Host)
if ip == nil {
if addr.IP == nil {
return false
}
return i.ipnet.Contains(ip)
return i.ipnet.Contains(*addr.IP)
}
func (g *IPCIDR) Adapter() string {