Skip to content

Commit

Permalink
Add more fuzz match support @Release
Browse files Browse the repository at this point in the history
  • Loading branch information
wweir committed Jan 29, 2019
1 parent 8194083 commit 9bc5a32
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 34 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
*.out

.DS_Store
**/.DS_Store
._*
*.swp
*.swo
.vscode
.idea
sower
cert.pem
**/cert.pem
privkey.pem
**/privkey.pem
/sower.toml
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
SERVER:=127.0.0.1:5533

default: build
default: test build

generate:
go generate ./...

test:
go test -race ./...
build:
GO111MODULE=on go build -v -ldflags \
"-X main.version=$(shell git describe --tags) \
Expand Down
32 changes: 17 additions & 15 deletions conf/sower.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ dns_server="223.5.5.5" # Alibaba public dns
client_ip="127.0.0.1" # listen the IP, dns target is the IP
# clear_dns_cache="killall -HUP mDNSResponder"
blocklist=[
"*.google.com", # google
"*.goo.gl",
"*.googleusercontent.com",
"*.googleapis.com",
"*.youtube.com", # youtube
"*.ytimg.com",
"*.ggpht.com",
"*.googlevideo.com",
"*.facebook.com", # facebook
"*.xx.fbcdn.net",
"*.twitter.com", # twitter
"*.twimg.com",
"*.blogspot.com", # blogspot
"*.wikipedia.org", # wikipeida
"**.google.com", # google
"**.goo.gl",
"**.googleusercontent.com",
"**.googleapis.com",
"**.youtube.com", # youtube
"**.ytimg.com",
"**.ggpht.com",
"**.googlevideo.com",
"**.facebook.com", # facebook
"**.xx.fbcdn.net",
"**.twitter.com", # twitter
"**.twimg.com",
"**.blogspot.com", # blogspot
"**.wikipedia.org", # wikipeida
]
whitelist=[
"iamp.*.*.*",
"iamp.*.*",
"imap-mail.*.*",
"imap-mail.outlook.com",
"**.qq.com",
"**.baidu.com"
]
verbose=0
15 changes: 13 additions & 2 deletions util/suffix_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ func (n *node) add(secs []string) {
case 1:
n.node[secs[length-1]] = &node{node: map[string]*node{"": &node{}}}
default:
subNode, ok := n.node[secs[length-1]]
sec := secs[length-1]
if sec == "**" {
sec = "*"
}

subNode, ok := n.node[sec]
if !ok {
subNode = &node{node: map[string]*node{}}
n.node[secs[length-1]] = subNode
n.node[sec] = subNode
}
subNode.add(secs[:length-1])
}
Expand All @@ -73,6 +78,9 @@ func (n *node) matchSecs(secs []string, fuzzNode bool) bool {
if _, ok := n.node[""]; ok {
return true
}
if _, ok := n.node["**"]; ok {
return true
}
if _, ok := n.node["*"]; ok {
return !fuzzNode
}
Expand All @@ -85,6 +93,9 @@ func (n *node) matchSecs(secs []string, fuzzNode bool) bool {
if n, ok := n.node["*"]; ok {
return n.matchSecs(secs[:length-1], true)
}
if _, ok := n.node["**"]; ok {
return true
}

return false
}
24 changes: 14 additions & 10 deletions util/suffix_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,40 @@ func TestNode_Match(t *testing.T) {
},
}, {
"fuzz1",
NewNodeFromRules(".", "wweir.cc", "*.wweir.cc"),
[]test{
{"wweir.cc", true},
{"a.wweir.cc", true},
},
}, {
"fuzz2",
NewNodeFromRules(".", "a.wweir.cc", "*.wweir.cc"),
NewNodeFromRules(".", "wweir.cc", "a.wweir.cc", "*.wweir.cc"),
[]test{
{"wweir.cc", true},
{"a.wweir.cc", true},
{"b.wweir.cc", true},
{"a.b.wweir.cc", false},
},
}, {
"fuzz3",
"fuzz2",
NewNodeFromRules(".", "a.*.cc"),
[]test{
{"wweir.cc", false},
{"a.wweir.cc", true},
{"b.wweir.cc", false},
},
}, {
"fuzz4",
"fuzz3",
NewNodeFromRules(".", "*.*.cc", "iamp.*.*"),
[]test{
{"wweir.cc", false},
{"a.wweir.cc", true},
{"b.wweir.cc", true},
{"iamp.wweir.cc", true},
},
}, {
"fuzz4",
NewNodeFromRules(".", "**.cc", "a.**.com"),
[]test{
{"wweir.cc", true},
{"a.wweir.cc", true},
{"a.b.wweir.cc", true},
{"a.wweir.com", true},
{"b.wweir.com", false},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 9bc5a32

Please sign in to comment.