Refactor: metadata use netip.Addr

This commit is contained in:
yaling888
2022-04-20 01:52:51 +08:00
parent 29c775331a
commit cd62daccb0
45 changed files with 369 additions and 360 deletions

View File

@@ -1,7 +1,7 @@
package dns
import (
"net"
"net/netip"
"strings"
"github.com/Dreamacro/clash/component/geodata/router"
@@ -10,23 +10,23 @@ import (
)
type fallbackIPFilter interface {
Match(net.IP) bool
Match(netip.Addr) bool
}
type geoipFilter struct {
code string
}
func (gf *geoipFilter) Match(ip net.IP) bool {
record, _ := mmdb.Instance().Country(ip)
func (gf *geoipFilter) Match(ip netip.Addr) bool {
record, _ := mmdb.Instance().Country(ip.AsSlice())
return !strings.EqualFold(record.Country.IsoCode, gf.code) && !ip.IsPrivate()
}
type ipnetFilter struct {
ipnet *net.IPNet
ipnet *netip.Prefix
}
func (inf *ipnetFilter) Match(ip net.IP) bool {
func (inf *ipnetFilter) Match(ip netip.Addr) bool {
return inf.ipnet.Contains(ip)
}
@@ -41,7 +41,7 @@ type domainFilter struct {
func NewDomainFilter(domains []string) *domainFilter {
df := domainFilter{tree: trie.New[bool]()}
for _, domain := range domains {
df.tree.Insert(domain, true)
_ = df.tree.Insert(domain, true)
}
return &df
}