feat: fake-ip-filter support rule-set: and geosite:

This commit is contained in:
wwqgtxx
2024-08-14 20:02:02 +08:00
parent f20f371a61
commit 696b75ee37
3 changed files with 83 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/metacubex/mihomo/common/nnip"
"github.com/metacubex/mihomo/component/profile/cachefile"
"github.com/metacubex/mihomo/component/trie"
C "github.com/metacubex/mihomo/constant"
)
const (
@@ -36,6 +37,7 @@ type Pool struct {
cycle bool
mux sync.Mutex
host *trie.DomainTrie[struct{}]
rules []C.Rule
ipnet netip.Prefix
store store
}
@@ -66,10 +68,18 @@ func (p *Pool) LookBack(ip netip.Addr) (string, bool) {
// ShouldSkipped return if domain should be skipped
func (p *Pool) ShouldSkipped(domain string) bool {
if p.host == nil {
return false
if p.host != nil {
if p.host.Search(domain) != nil {
return true
}
}
return p.host.Search(domain) != nil
for _, rule := range p.rules {
metadata := &C.Metadata{Host: domain}
if match, _ := rule.Match(metadata); match {
return true
}
}
return false
}
// Exist returns if given ip exists in fake-ip pool
@@ -156,6 +166,8 @@ type Options struct {
IPNet netip.Prefix
Host *trie.DomainTrie[struct{}]
Rules []C.Rule
// Size sets the maximum number of entries in memory
// and does not work if Persistence is true
Size int
@@ -185,6 +197,7 @@ func New(options Options) (*Pool, error) {
offset: first.Prev(),
cycle: false,
host: options.Host,
rules: options.Rules,
ipnet: options.IPNet,
}
if options.Persistence {