mirror of https://github.com/0xERR0R/blocky.git
feat: log the rule which is the cause of blocking (#1460)
Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>
This commit is contained in:
parent
58c5069803
commit
e99c98b4c2
|
@ -50,7 +50,12 @@ func (cache stringMap) contains(searchString string) bool {
|
||||||
})
|
})
|
||||||
|
|
||||||
if idx < searchBucketLen {
|
if idx < searchBucketLen {
|
||||||
return cache[searchLen][idx*searchLen:idx*searchLen+searchLen] == strings.ToLower(normalized)
|
blockRule := cache[searchLen][idx*searchLen : idx*searchLen+searchLen]
|
||||||
|
if blockRule == normalized {
|
||||||
|
log.PrefixedLog("string_map").Debugf("block rule '%s' matched with '%s'", blockRule, searchString)
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -132,7 +137,7 @@ func (cache regexCache) elementCount() int {
|
||||||
func (cache regexCache) contains(searchString string) bool {
|
func (cache regexCache) contains(searchString string) bool {
|
||||||
for _, regex := range cache {
|
for _, regex := range cache {
|
||||||
if regex.MatchString(searchString) {
|
if regex.MatchString(searchString) {
|
||||||
log.PrefixedLog("regexCache").Debugf("regex '%s' matched with '%s'", regex, searchString)
|
log.PrefixedLog("regex_cache").Debugf("regex '%s' matched with '%s'", regex, searchString)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
18
trie/trie.go
18
trie/trie.go
|
@ -1,5 +1,10 @@
|
||||||
package trie
|
package trie
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/0xERR0R/blocky/log"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// Trie stores a set of strings and can quickly check
|
// Trie stores a set of strings and can quickly check
|
||||||
// if it contains an element, or one of its parents.
|
// if it contains an element, or one of its parents.
|
||||||
//
|
//
|
||||||
|
@ -108,8 +113,12 @@ func (n *parent) insert(key string, split SplitFunc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *parent) hasParentOf(key string, split SplitFunc) bool {
|
func (n *parent) hasParentOf(key string, split SplitFunc) bool {
|
||||||
|
searchString := key
|
||||||
|
rule := ""
|
||||||
|
|
||||||
for {
|
for {
|
||||||
label, rest := split(key)
|
label, rest := split(key)
|
||||||
|
rule = strings.Join([]string{label, rule}, ".")
|
||||||
|
|
||||||
child, ok := n.children[label]
|
child, ok := n.children[label]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -132,7 +141,14 @@ func (n *parent) hasParentOf(key string, split SplitFunc) bool {
|
||||||
|
|
||||||
case terminal:
|
case terminal:
|
||||||
// Continue down the trie
|
// Continue down the trie
|
||||||
return child.hasParentOf(rest, split)
|
matched := child.hasParentOf(rest, split)
|
||||||
|
if matched {
|
||||||
|
rule = strings.Join([]string{child.String(), rule}, ".")
|
||||||
|
rule = strings.Trim(rule, ".")
|
||||||
|
log.PrefixedLog("trie").Debugf("wildcard block rule '%s' matched with '%s'", rule, searchString)
|
||||||
|
}
|
||||||
|
|
||||||
|
return matched
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue