mirror of
https://github.com/p4gefau1t/trojan-go.git
synced 2024-04-21 12:21:34 +00:00
Support regexp rule type
Compatible with V2Ray rules
This commit is contained in:
@@ -69,7 +69,7 @@ Trojan-Go内建的路由模块可以帮助你实现国内直连,即客户端
|
||||
|
||||
- "full:",完全域名匹配
|
||||
|
||||
- "regex:",正则表达式匹配
|
||||
- "regexp:",正则表达式匹配
|
||||
|
||||
- "cidr:",CIDR匹配
|
||||
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user