From cfe7354c07e8c837691b03fb183127f431e5d218 Mon Sep 17 00:00:00 2001 From: Kr328 Date: Tue, 18 Jan 2022 13:32:47 +0800 Subject: [PATCH 1/2] Improve: change provider file modify time when updated (#1918) --- adapter/provider/fetcher.go | 1 + 1 file changed, 1 insertion(+) diff --git a/adapter/provider/fetcher.go b/adapter/provider/fetcher.go index 6c1e96b4..81f9ec96 100644 --- a/adapter/provider/fetcher.go +++ b/adapter/provider/fetcher.go @@ -102,6 +102,7 @@ func (f *fetcher) Update() (interface{}, bool, error) { hash := md5.Sum(buf) if bytes.Equal(f.hash[:], hash[:]) { f.updatedAt = &now + os.Chtimes(f.vehicle.Path(), now, now) return nil, true, nil } From b1a639feae485ea953f9cc5ddd9f06884fdc7091 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Wed, 26 Jan 2022 22:28:13 +0800 Subject: [PATCH 2/2] Fix: domain trie search --- component/trie/domain.go | 4 ++-- component/trie/domain_test.go | 8 ++++++++ component/trie/node.go | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/component/trie/domain.go b/component/trie/domain.go index ffd0b754..fcc9e3ba 100644 --- a/component/trie/domain.go +++ b/component/trie/domain.go @@ -109,13 +109,13 @@ func (t *DomainTrie) search(node *Node, parts []string) *Node { } if c := node.getChild(parts[len(parts)-1]); c != nil { - if n := t.search(c, parts[:len(parts)-1]); n != nil { + if n := t.search(c, parts[:len(parts)-1]); n != nil && n.Data != nil { return n } } if c := node.getChild(wildcard); c != nil { - if n := t.search(c, parts[:len(parts)-1]); n != nil { + if n := t.search(c, parts[:len(parts)-1]); n != nil && n.Data != nil { return n } } diff --git a/component/trie/domain_test.go b/component/trie/domain_test.go index 61340cde..4322699a 100644 --- a/component/trie/domain_test.go +++ b/component/trie/domain_test.go @@ -97,3 +97,11 @@ func TestTrie_Boundary(t *testing.T) { assert.NotNil(t, tree.Insert("..dev", localIP)) assert.Nil(t, tree.Search("dev")) } + +func TestTrie_WildcardBoundary(t *testing.T) { + tree := New() + tree.Insert("+.*", localIP) + tree.Insert("stun.*.*.*", localIP) + + assert.NotNil(t, tree.Search("example.com")) +} diff --git a/component/trie/node.go b/component/trie/node.go index be8ba91f..42672f0b 100644 --- a/component/trie/node.go +++ b/component/trie/node.go @@ -2,8 +2,8 @@ package trie // Node is the trie's node type Node struct { - Data interface{} children map[string]*Node + Data interface{} } func (n *Node) getChild(s string) *Node {