2019-12-10 15:04:22 +08:00
|
|
|
package outboundgroup
|
|
|
|
|
|
|
|
import (
|
2022-01-18 21:09:36 +08:00
|
|
|
"github.com/Dreamacro/clash/tunnel"
|
2022-02-16 22:18:05 +08:00
|
|
|
"github.com/dlclark/regexp2"
|
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-18 21:09:36 +08:00
|
|
|
|
2022-02-16 22:18:05 +08:00
|
|
|
var filterReg *regexp2.Regexp = nil
|
|
|
|
var matchedProxies []C.Proxy
|
2022-01-05 12:19:49 +08:00
|
|
|
if len(filter) > 0 {
|
2022-02-16 22:18:05 +08:00
|
|
|
//filterReg = regexp.MustCompile(filter)
|
|
|
|
filterReg = regexp2.MustCompile(filter, 0)
|
2022-01-05 12:19:49 +08:00
|
|
|
for _, p := range proxies {
|
2022-04-22 17:27:55 +08:00
|
|
|
if p.IsProxyGroup() {
|
2022-02-23 16:17:29 +08:00
|
|
|
matchedProxies = append(matchedProxies, p)
|
2022-04-22 17:27:55 +08:00
|
|
|
continue
|
2022-02-23 16:17:29 +08:00
|
|
|
}
|
|
|
|
|
2022-02-16 22:18:05 +08:00
|
|
|
//if filterReg.MatchString(p.Name()) {
|
|
|
|
if mat, _ := filterReg.FindStringMatch(p.Name()); mat != nil {
|
2022-01-05 12:19:49 +08:00
|
|
|
matchedProxies = append(matchedProxies, p)
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 22:38:28 +08:00
|
|
|
|
2022-01-05 12:19:49 +08:00
|
|
|
if len(matchedProxies) > 0 {
|
2022-01-18 21:09:36 +08:00
|
|
|
return matchedProxies
|
|
|
|
} else {
|
|
|
|
return append([]C.Proxy{}, tunnel.Proxies()["COMPATIBLE"])
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if len(proxies) == 0 {
|
|
|
|
return append(proxies, tunnel.Proxies()["COMPATIBLE"])
|
|
|
|
} else {
|
|
|
|
return proxies
|
2022-01-05 12:19:49 +08:00
|
|
|
}
|
|
|
|
}
|
2022-01-18 21:09:36 +08:00
|
|
|
|
2019-12-10 15:04:22 +08:00
|
|
|
}
|