Feature: support domain in fallback filter (#964)

This commit is contained in:
Melvin
2020-09-28 22:17:10 +08:00
committed by GitHub
parent e09931dcf7
commit a6444bb449
4 changed files with 89 additions and 19 deletions

View File

@ -4,9 +4,10 @@ import (
"net"
"github.com/Dreamacro/clash/component/mmdb"
"github.com/Dreamacro/clash/component/trie"
)
type fallbackFilter interface {
type fallbackIPFilter interface {
Match(net.IP) bool
}
@ -24,3 +25,22 @@ type ipnetFilter struct {
func (inf *ipnetFilter) Match(ip net.IP) bool {
return inf.ipnet.Contains(ip)
}
type fallbackDomainFilter interface {
Match(domain string) bool
}
type domainFilter struct {
tree *trie.DomainTrie
}
func NewDomainFilter(domains []string) *domainFilter {
df := domainFilter{tree: trie.New()}
for _, domain := range domains {
df.tree.Insert(domain, "")
}
return &df
}
func (df *domainFilter) Match(domain string) bool {
return df.tree.Search(domain) != nil
}