fix(routing): Fix MergeAndSortRulesOptimizer (#682)

This commit is contained in:
./gray 2024-10-24 20:08:49 +08:00 committed by GitHub
parent 438c05cbd6
commit 334cbd3962
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,15 +7,16 @@ package routing
import ( import (
"fmt" "fmt"
"net/netip"
"sort"
"strings"
"github.com/daeuniverse/dae/common/assets" "github.com/daeuniverse/dae/common/assets"
"github.com/daeuniverse/dae/common/consts" "github.com/daeuniverse/dae/common/consts"
"github.com/daeuniverse/dae/pkg/config_parser" "github.com/daeuniverse/dae/pkg/config_parser"
"github.com/daeuniverse/dae/pkg/geodata" "github.com/daeuniverse/dae/pkg/geodata"
"github.com/mohae/deepcopy" "github.com/mohae/deepcopy"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"net/netip"
"sort"
"strings"
) )
type RulesOptimizer interface { type RulesOptimizer interface {
@ -87,6 +88,7 @@ func (o *MergeAndSortRulesOptimizer) Optimize(rules []*config_parser.RoutingRule
if len(mergingRule.AndFunctions) == 1 && if len(mergingRule.AndFunctions) == 1 &&
len(rules[i].AndFunctions) == 1 && len(rules[i].AndFunctions) == 1 &&
mergingRule.AndFunctions[0].Name == rules[i].AndFunctions[0].Name && mergingRule.AndFunctions[0].Name == rules[i].AndFunctions[0].Name &&
mergingRule.AndFunctions[0].Not == rules[i].AndFunctions[0].Not &&
rules[i].Outbound.String(true, false, true) == mergingRule.Outbound.String(true, false, true) { rules[i].Outbound.String(true, false, true) == mergingRule.Outbound.String(true, false, true) {
mergingRule.AndFunctions[0].Params = append(mergingRule.AndFunctions[0].Params, rules[i].AndFunctions[0].Params...) mergingRule.AndFunctions[0].Params = append(mergingRule.AndFunctions[0].Params, rules[i].AndFunctions[0].Params...)
} else { } else {