feat: sniffer's force-domain and skip-domain support rule-set: and geosite:

This commit is contained in:
wwqgtxx
2024-08-14 22:38:17 +08:00
parent 696b75ee37
commit 7fd0467aef
7 changed files with 166 additions and 112 deletions

View File

@@ -8,7 +8,6 @@ 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"
)
@@ -36,8 +35,7 @@ type Pool struct {
offset netip.Addr
cycle bool
mux sync.Mutex
host *trie.DomainTrie[struct{}]
rules []C.Rule
host []C.Rule
ipnet netip.Prefix
store store
}
@@ -68,14 +66,8 @@ 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 {
if p.host.Search(domain) != nil {
return true
}
}
for _, rule := range p.rules {
metadata := &C.Metadata{Host: domain}
if match, _ := rule.Match(metadata); match {
for _, rule := range p.host {
if match, _ := rule.Match(&C.Metadata{Host: domain}); match {
return true
}
}
@@ -164,9 +156,7 @@ func (p *Pool) restoreState() {
type Options struct {
IPNet netip.Prefix
Host *trie.DomainTrie[struct{}]
Rules []C.Rule
Host []C.Rule
// Size sets the maximum number of entries in memory
// and does not work if Persistence is true
@@ -197,7 +187,6 @@ func New(options Options) (*Pool, error) {
offset: first.Prev(),
cycle: false,
host: options.Host,
rules: options.Rules,
ipnet: options.IPNet,
}
if options.Persistence {

View File

@@ -9,6 +9,8 @@ import (
"github.com/metacubex/mihomo/component/profile/cachefile"
"github.com/metacubex/mihomo/component/trie"
C "github.com/metacubex/mihomo/constant"
RP "github.com/metacubex/mihomo/rules/provider"
"github.com/sagernet/bbolt"
"github.com/stretchr/testify/assert"
@@ -154,7 +156,7 @@ func TestPool_Skip(t *testing.T) {
pools, tempfile, err := createPools(Options{
IPNet: ipnet,
Size: 10,
Host: tree,
Host: []C.Rule{RP.NewDomainSet(tree.NewDomainSet(), "")},
})
assert.Nil(t, err)
defer os.Remove(tempfile)