mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
feat: add include-all
to proxy-groups
This commit is contained in:
parent
3d643cb95a
commit
1d3e9f4889
|
@ -34,10 +34,12 @@ type GroupCommonOption struct {
|
|||
ExcludeFilter string `group:"exclude-filter,omitempty"`
|
||||
ExcludeType string `group:"exclude-type,omitempty"`
|
||||
ExpectedStatus string `group:"expected-status,omitempty"`
|
||||
IncludeAll bool `group:"include-all,omitempty"`
|
||||
IncludeAllProxies bool `group:"include-all-proxies,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) {
|
||||
func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, providersMap map[string]types.ProxyProvider, AllProxies []string, AllProviders []string) (C.ProxyAdapter, error) {
|
||||
decoder := structure.NewDecoder(structure.Option{TagName: "group", WeaklyTypedInput: true})
|
||||
|
||||
groupOption := &GroupCommonOption{
|
||||
|
@ -55,18 +57,24 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
|
|||
|
||||
providers := []types.ProxyProvider{}
|
||||
|
||||
if groupOption.IncludeAll {
|
||||
groupOption.IncludeAllProviders = true
|
||||
groupOption.IncludeAllProxies = true
|
||||
}
|
||||
var GroupUse []string
|
||||
visited := make(map[string]bool)
|
||||
var GroupProxies []string
|
||||
if groupOption.IncludeAllProviders {
|
||||
for name := range provider.ProxyProviderName {
|
||||
GroupUse = append(GroupUse, name)
|
||||
visited[name] = true
|
||||
}
|
||||
GroupUse = append(GroupUse, AllProviders...)
|
||||
} else {
|
||||
GroupUse = groupOption.Use
|
||||
}
|
||||
if groupOption.IncludeAllProxies {
|
||||
GroupProxies = append(groupOption.Proxies, AllProxies...)
|
||||
} else {
|
||||
GroupProxies = groupOption.Proxies
|
||||
}
|
||||
|
||||
if len(groupOption.Proxies) == 0 && len(GroupUse) == 0 {
|
||||
if len(GroupProxies) == 0 && len(GroupUse) == 0 {
|
||||
return nil, fmt.Errorf("%s: %w", groupName, errMissProxy)
|
||||
}
|
||||
|
||||
|
@ -87,8 +95,8 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
|
|||
testUrl = groupOption.URL
|
||||
}
|
||||
|
||||
if len(groupOption.Proxies) != 0 {
|
||||
ps, err := getProxies(proxyMap, groupOption.Proxies)
|
||||
if len(GroupProxies) != 0 {
|
||||
ps, err := getProxies(proxyMap, GroupProxies)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", groupName, err)
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@ import (
|
|||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var ProxyProviderName = make(map[string]struct{})
|
||||
|
||||
const (
|
||||
ReservedName = "default"
|
||||
)
|
||||
|
@ -201,7 +199,6 @@ 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, override), proxiesOnUpdate(pd))
|
||||
pd.Fetcher = fetcher
|
||||
ProxyProviderName[name] = struct{}{}
|
||||
wrapper := &ProxySetProvider{pd}
|
||||
runtime.SetFinalizer(wrapper, stopProxyProvider)
|
||||
return wrapper, nil
|
||||
|
|
|
@ -695,6 +695,7 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
|||
providersConfig := cfg.ProxyProvider
|
||||
|
||||
var proxyList []string
|
||||
var AllProxies []string
|
||||
proxiesList := list.New()
|
||||
groupsList := list.New()
|
||||
|
||||
|
@ -717,6 +718,7 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
|||
}
|
||||
proxies[proxy.Name()] = proxy
|
||||
proxyList = append(proxyList, proxy.Name())
|
||||
AllProxies = append(AllProxies, proxy.Name())
|
||||
proxiesList.PushBack(mapping)
|
||||
}
|
||||
|
||||
|
@ -735,6 +737,7 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
var AllProviders []string
|
||||
// parse and initial providers
|
||||
for name, mapping := range providersConfig {
|
||||
if name == provider.ReservedName {
|
||||
|
@ -747,11 +750,12 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
|||
}
|
||||
|
||||
providersMap[name] = pd
|
||||
AllProviders = append(AllProviders, name)
|
||||
}
|
||||
|
||||
// parse proxy group
|
||||
for idx, mapping := range groupsConfig {
|
||||
group, err := outboundgroup.ParseProxyGroup(mapping, proxies, providersMap)
|
||||
group, err := outboundgroup.ParseProxyGroup(mapping, proxies, providersMap, AllProxies, AllProviders)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("proxy group[%d]: %w", idx, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user