Improves flow handling and adds runtime stats APIs
Refactors TCP and UDP flow managers to enhance analyzer selection and flow binding accuracy, including O(1) UDP stream rebinding by 5-tuple. Introduces runtime stats tracking for engine and ruleset operations, exposing new APIs for granular performance and error metrics. Optimizes GeoMatcher with result caching and supports efficient geosite set matching, reducing redundant computation in ruleset expressions.
This commit is contained in:
@@ -2,9 +2,14 @@ package ruleset
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.difuse.io/Difuse/Mellaris/analyzer"
|
||||
"git.difuse.io/Difuse/Mellaris/ruleset/builtins/geo"
|
||||
|
||||
"github.com/expr-lang/expr/ast"
|
||||
"github.com/expr-lang/expr/parser"
|
||||
)
|
||||
|
||||
func TestExtractGeoSiteConditions(t *testing.T) {
|
||||
@@ -63,3 +68,23 @@ func TestMatchGeoSiteConditions(t *testing.T) {
|
||||
t.Fatalf("matchGeoSiteConditions() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIDPatcher_PatchesGeoSiteORChainToGeoSiteSet(t *testing.T) {
|
||||
tree, err := parser.Parse(`geosite(tls.req.sni, "google") || geosite(tls.req.sni, "youtube") || geosite(tls.req.sni, "openai")`)
|
||||
if err != nil {
|
||||
t.Fatalf("parse expression: %v", err)
|
||||
}
|
||||
root := tree.Node
|
||||
patcher := &idPatcher{GeoMatcher: geo.NewGeoMatcher("", "")}
|
||||
ast.Walk(&root, patcher)
|
||||
if patcher.Err != nil {
|
||||
t.Fatalf("patch error: %v", patcher.Err)
|
||||
}
|
||||
got := root.String()
|
||||
if !strings.Contains(got, "geosite_set(") {
|
||||
t.Fatalf("expected geosite_set rewrite, got %q", got)
|
||||
}
|
||||
if strings.Contains(got, "||") || strings.Contains(got, " or ") {
|
||||
t.Fatalf("expected OR chain to be collapsed, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user