Support regexp rule type

Compatible with V2Ray rules
This commit is contained in:
loyalsoldier
2021-01-22 17:48:59 +08:00
parent 8d5d06bd63
commit 669bd3317a
3 changed files with 16 additions and 3 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ Trojan-Go内建的路由模块可以帮助你实现国内直连,即客户端
- "full:",完全域名匹配
- "regex:",正则表达式匹配
- "regexp:",正则表达式匹配
- "cidr:"CIDR匹配
+13
View File
@@ -418,6 +418,19 @@ func NewClient(ctx context.Context, underlay tunnel.Client) (*Client, error) {
})
}
// Just for compatibility with V2Ray rule type `regexp`
regexpInfo := loadCode(cfg, "regexp:")
for _, info := range regexpInfo {
if _, err := regexp.Compile(info.code); err != nil {
return nil, common.NewError("invalid regular expression: " + info.code).Base(err)
}
client.domains[info.strategy] = append(client.domains[info.strategy], &v2router.Domain{
Type: v2router.Domain_Regex,
Value: info.code,
Attribute: nil,
})
}
fullInfo := loadCode(cfg, "full:")
for _, info := range fullInfo {
client.domains[info.strategy] = append(client.domains[info.strategy], &v2router.Domain{
+2 -2
View File
@@ -77,11 +77,11 @@ router:
- "full:localhost"
- "domain:bypass.com"
block:
- "regex:blockreg(.*)"
- "regexp:blockreg(.*)"
- "full:blockfull"
- "domain:block.com"
proxy:
- "regex:proxyreg(.*)"
- "regexp:proxyreg(.*)"
- "full:proxyfull"
- "domain:proxy.com"
- "cidr:192.168.1.1/16"