mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-27 01:07:10 +00:00
feat: fake-ip-filter support rule-set: and geosite:
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user