fix: problem that cannot use unsorted ip set in dns response routing

This commit is contained in:
mzz2017
2023-03-31 23:36:24 +08:00
parent 6657fb329c
commit d9133b2517
3 changed files with 5 additions and 4 deletions

View File

@ -12,7 +12,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/v2rayA/ahocorasick-domain"
"regexp"
"sort"
"strings"
)
@ -185,7 +184,6 @@ func (n *AhocorasickSlimtrie) Build() (err error) {
continue
}
toBuild = ToSuffixTrieStrings(toBuild)
sort.Strings(toBuild)
n.trie[i], err = trie.NewTrie(toBuild, ValidDomainChars)
if err != nil {
return err

View File

@ -143,7 +143,7 @@ func ParamParser(to reflect.Value, section *config_parser.Section, ignoreType []
// Assign. "to" should have field "Rules".
structField, ok := to.Type().FieldByName("Rules")
if !ok || structField.Type != reflect.TypeOf([]*config_parser.RoutingRule{}) {
return fmt.Errorf("unexpected type: \"routing rule\": %v", itemVal.String(true, false, false))
return fmt.Errorf("cannot use routing rule in this context: %v", itemVal.String(true, false, false))
}
if structField.Tag.Get("mapstructure") != "_" {
return fmt.Errorf("a []*RoutingRule field \"Rules\" with mapstructure:\"_\" is required in struct %v to parse section", to.Type().String())

View File

@ -5,8 +5,10 @@ package trie
import (
"fmt"
"github.com/daeuniverse/dae/common"
"github.com/daeuniverse/dae/common/bitlist"
"math/bits"
"sort"
)
type ValidChars struct {
@ -86,8 +88,9 @@ type Trie struct {
// NewTrie creates a new *Trie struct, from a slice of sorted strings.
func NewTrie(keys []string, chars *ValidChars) (*Trie, error) {
// Check chars.
keys = common.Deduplicate(keys)
sort.Strings(keys)
for _, key := range keys {
for _, c := range []byte(key) {
if !chars.IsValidChar(c) {