2019-12-10 15:04:22 +08:00
|
|
|
package outboundgroup
|
|
|
|
|
|
|
|
import (
|
2022-01-05 12:19:49 +08:00
|
|
|
"regexp"
|
2019-12-10 15:04:22 +08:00
|
|
|
"time"
|
|
|
|
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
2021-07-04 20:32:59 +08:00
|
|
|
"github.com/Dreamacro/clash/constant/provider"
|
2019-12-10 15:04:22 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultGetProxiesDuration = time.Second * 5
|
|
|
|
)
|
|
|
|
|
2022-01-05 12:19:49 +08:00
|
|
|
func getProvidersProxies(providers []provider.ProxyProvider, touch bool, filter string) []C.Proxy {
|
2019-12-10 15:04:22 +08:00
|
|
|
proxies := []C.Proxy{}
|
|
|
|
for _, provider := range providers {
|
2020-11-19 00:53:22 +08:00
|
|
|
if touch {
|
|
|
|
proxies = append(proxies, provider.ProxiesWithTouch()...)
|
|
|
|
} else {
|
|
|
|
proxies = append(proxies, provider.Proxies()...)
|
|
|
|
}
|
2019-12-10 15:04:22 +08:00
|
|
|
}
|
2022-01-05 12:19:49 +08:00
|
|
|
var filterReg *regexp.Regexp = nil
|
|
|
|
matchedProxies := []C.Proxy{}
|
|
|
|
if len(filter) > 0 {
|
|
|
|
filterReg = regexp.MustCompile(filter)
|
|
|
|
for _, p := range proxies {
|
|
|
|
if filterReg.MatchString(p.Name()) {
|
|
|
|
matchedProxies = append(matchedProxies, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//if no proxy matched, means bad filter, return all proxies
|
|
|
|
if len(matchedProxies) > 0 {
|
|
|
|
proxies = matchedProxies
|
|
|
|
}
|
|
|
|
}
|
2019-12-10 15:04:22 +08:00
|
|
|
return proxies
|
|
|
|
}
|