dae/component/control/domain_match.go

49 lines
1.1 KiB
Go
Raw Normal View History

2023-01-23 18:54:21 +07:00
/*
* SPDX-License-Identifier: AGPL-3.0-only
2023-01-28 12:56:06 +07:00
* Copyright (c) since 2023, v2rayA Organization <team@v2raya.org>
2023-01-23 18:54:21 +07:00
*/
package control
import (
2023-01-23 19:01:24 +07:00
"github.com/v2rayA/dae/common/consts"
2023-01-24 14:28:39 +07:00
"regexp"
2023-01-23 18:54:21 +07:00
"strings"
)
func (c *ControlPlane) MatchDomainBitmap(domain string) (bitmap [consts.MaxRoutingLen / 32]uint32) {
2023-01-27 01:10:27 +07:00
// TODO: high performance implementation.
2023-01-23 18:54:21 +07:00
for _, s := range c.SimulatedDomainSet {
for _, d := range s.Domains {
var hit bool
switch s.Key {
case consts.RoutingDomain_Suffix:
if domain == d || strings.HasSuffix(domain, "."+d) {
2023-01-23 18:54:21 +07:00
hit = true
}
case consts.RoutingDomain_Full:
if strings.EqualFold(domain, d) {
hit = true
}
case consts.RoutingDomain_Keyword:
if strings.Contains(strings.ToLower(domain), strings.ToLower(d)) {
hit = true
}
case consts.RoutingDomain_Regex:
2023-01-24 14:28:39 +07:00
// FIXME: too slow
for _, d := range s.Domains {
if regexp.MustCompile(d).MatchString(strings.ToLower(domain)) {
hit = true
break
2023-01-24 14:28:39 +07:00
}
}
2023-01-23 18:54:21 +07:00
}
if hit {
bitmap[s.RuleIndex/32] |= 1 << (s.RuleIndex % 32)
break
}
}
}
return bitmap
}