feat: add include-all-providers to proxy-groups

This commit is contained in:
gVisor bot 2023-11-11 22:15:57 +08:00
parent 4077fb59be
commit b737c0451e
2 changed files with 30 additions and 15 deletions

View File

@ -34,6 +34,7 @@ type GroupCommonOption struct {
ExcludeFilter string `group:"exclude-filter,omitempty"`
ExcludeType string `group:"exclude-type,omitempty"`
ExpectedStatus string `group:"expected-status,omitempty"`
IncludeAllProviders bool `group:"include-all-providers,omitempty"`
}
func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, providersMap map[string]types.ProxyProvider) (C.ProxyAdapter, error) {
@ -54,7 +55,18 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
providers := []types.ProxyProvider{}
if len(groupOption.Proxies) == 0 && len(groupOption.Use) == 0 {
var GroupUse []string
visited := make(map[string]bool)
if groupOption.IncludeAllProviders {
for name := range provider.ProxyProviderName {
GroupUse = append(GroupUse, name)
visited[name] = true
}
} else {
GroupUse = groupOption.Use
}
if len(groupOption.Proxies) == 0 && len(GroupUse) == 0 {
return nil, fmt.Errorf("%s: %w", groupName, errMissProxy)
}
@ -107,8 +119,8 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
providersMap[groupName] = pd
}
if len(groupOption.Use) != 0 {
list, err := getProviders(providersMap, groupOption.Use)
if len(GroupUse) != 0 {
list, err := getProviders(providersMap, GroupUse)
if err != nil {
return nil, fmt.Errorf("%s: %w", groupName, err)
}

View File

@ -24,6 +24,8 @@ import (
"gopkg.in/yaml.v3"
)
var ProxyProviderName = make(map[string]struct{})
const (
ReservedName = "default"
)
@ -193,6 +195,7 @@ func NewProxySetProvider(name string, interval time.Duration, filter string, exc
fetcher := resource.NewFetcher[[]C.Proxy](name, interval, vehicle, proxiesParseAndFilter(filter, excludeFilter, excludeTypeArray, filterRegs, excludeFilterReg, dialerProxy), proxiesOnUpdate(pd))
pd.Fetcher = fetcher
ProxyProviderName[name] = struct{}{}
wrapper := &ProxySetProvider{pd}
runtime.SetFinalizer(wrapper, stopProxyProvider)
return wrapper, nil