proxy-groups support exclude node by node type

This commit is contained in:
ag2s20150909
2023-01-03 21:47:57 +08:00
parent f100a33d98
commit 29b72df14c
7 changed files with 31 additions and 0 deletions

View File

@ -20,6 +20,7 @@ type GroupBase struct {
*outbound.Base
filterRegs []*regexp2.Regexp
excludeFilterReg *regexp2.Regexp
excludeTypeArray []string
providers []provider.ProxyProvider
failedTestMux sync.Mutex
failedTimes int
@ -33,6 +34,7 @@ type GroupBaseOption struct {
outbound.BaseOption
filter string
excludeFilter string
excludeType string
providers []provider.ProxyProvider
}
@ -41,6 +43,10 @@ func NewGroupBase(opt GroupBaseOption) *GroupBase {
if opt.excludeFilter != "" {
excludeFilterReg = regexp2.MustCompile(opt.excludeFilter, 0)
}
var excludeTypeArray []string
if opt.excludeType!="" {
excludeTypeArray=strings.Split(opt.excludeType,"|")
}
var filterRegs []*regexp2.Regexp
if opt.filter != "" {
@ -54,6 +60,7 @@ func NewGroupBase(opt GroupBaseOption) *GroupBase {
Base: outbound.NewBase(opt.BaseOption),
filterRegs: filterRegs,
excludeFilterReg: excludeFilterReg,
excludeTypeArray: excludeTypeArray,
providers: opt.providers,
failedTesting: atomic.NewBool(false),
}
@ -148,6 +155,24 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
}
proxies = newProxies
}
if gb.excludeTypeArray !=nil{
var newProxies []C.Proxy
for _, p := range proxies {
mType := p.Type().String()
flag:=false
for i := range gb.excludeTypeArray {
if(strings.EqualFold(mType,gb.excludeTypeArray[i])){
flag=true
}
}
if(flag){
continue
}
newProxies = append(newProxies, p)
}
proxies = newProxies
}
if gb.excludeFilterReg != nil {
var newProxies []C.Proxy