Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log the rule which is the cause of blocking #1460

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cache/stringcache/string_caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
})

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("stringMap").Debugf("block rule '%s' matched with '%s'", blockRule, searchString)
ThinkChaos marked this conversation as resolved.
Show resolved Hide resolved
return true

Check failure on line 56 in cache/stringcache/string_caches.go

View workflow job for this annotation

GitHub Actions / make (lint, true, false)

return with no blank line before (nlreturn)
zc-devs marked this conversation as resolved.
Show resolved Hide resolved
}
}

return false
Expand Down
16 changes: 15 additions & 1 deletion trie/trie.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package trie

import (
"github.com/0xERR0R/blocky/log"
"strings"
)

// Trie stores a set of strings and can quickly check
// if it contains an element, or one of its parents.
//
Expand Down Expand Up @@ -108,8 +113,11 @@
}

func (n *parent) hasParentOf(key string, split SplitFunc) bool {
searchString := key
rule := ""
zc-devs marked this conversation as resolved.
Show resolved Hide resolved
for {
label, rest := split(key)

Check failure on line 119 in trie/trie.go

View workflow job for this annotation

GitHub Actions / make (lint, true, false)

for statement without condition should never be cuddled (wsl)
rule = strings.Join([]string{label, rule}, ".")

child, ok := n.children[label]
if !ok {
Expand All @@ -132,8 +140,14 @@

case terminal:
// 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)
zc-devs marked this conversation as resolved.
Show resolved Hide resolved
}
return matched
zc-devs marked this conversation as resolved.
Show resolved Hide resolved
}

Check failure on line 150 in trie/trie.go

View workflow job for this annotation

GitHub Actions / make (lint, true, false)

return with no blank line before (nlreturn)
}
}

Expand Down
Loading