[Refactor]
1.allow maybe empty group 2.use COMPATIBLE(DIRECT alias) when proxy group is empty 3.http provider pass through tunnel
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package outboundgroup
|
||||
|
||||
import (
|
||||
"github.com/Dreamacro/clash/tunnel"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
@ -21,6 +22,7 @@ func getProvidersProxies(providers []provider.ProxyProvider, touch bool, filter
|
||||
proxies = append(proxies, provider.Proxies()...)
|
||||
}
|
||||
}
|
||||
|
||||
var filterReg *regexp.Regexp = nil
|
||||
matchedProxies := []C.Proxy{}
|
||||
if len(filter) > 0 {
|
||||
@ -32,8 +34,16 @@ func getProvidersProxies(providers []provider.ProxyProvider, touch bool, filter
|
||||
}
|
||||
//if no proxy matched, means bad filter, return all proxies
|
||||
if len(matchedProxies) > 0 {
|
||||
proxies = matchedProxies
|
||||
return matchedProxies
|
||||
} else {
|
||||
return append([]C.Proxy{}, tunnel.Proxies()["COMPATIBLE"])
|
||||
}
|
||||
} else {
|
||||
if len(proxies) == 0 {
|
||||
return append(proxies, tunnel.Proxies()["COMPATIBLE"])
|
||||
} else {
|
||||
return proxies
|
||||
}
|
||||
}
|
||||
return proxies
|
||||
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (f *Fallback) onDialFailed() {
|
||||
} else {
|
||||
failedCount := f.failedTimes.Inc()
|
||||
log.Warnln("%s failed count: %d", f.Name(), failedCount)
|
||||
if failedCount >= 5 && failedCount < 6 {
|
||||
if failedCount >= 5 {
|
||||
log.Warnln("because %s failed multiple times, active health check", f.Name())
|
||||
for _, proxyProvider := range f.providers {
|
||||
go proxyProvider.HealthCheck()
|
||||
@ -97,10 +97,11 @@ func (f *Fallback) SupportUDP() bool {
|
||||
|
||||
// MarshalJSON implements C.ProxyAdapter
|
||||
func (f *Fallback) MarshalJSON() ([]byte, error) {
|
||||
var all []string
|
||||
all := make([]string, 0)
|
||||
for _, proxy := range f.proxies(false) {
|
||||
all = append(all, proxy.Name())
|
||||
}
|
||||
|
||||
return json.Marshal(map[string]interface{}{
|
||||
"type": f.Type().String(),
|
||||
"now": f.Now(),
|
||||
|
@ -150,10 +150,12 @@ func (lb *LoadBalance) proxies(touch bool) []C.Proxy {
|
||||
|
||||
// MarshalJSON implements C.ProxyAdapter
|
||||
func (lb *LoadBalance) MarshalJSON() ([]byte, error) {
|
||||
var all []string
|
||||
all := make([]string, 0)
|
||||
|
||||
for _, proxy := range lb.proxies(false) {
|
||||
all = append(all, proxy.Name())
|
||||
}
|
||||
|
||||
return json.Marshal(map[string]interface{}{
|
||||
"type": lb.Type().String(),
|
||||
"all": all,
|
||||
|
@ -23,7 +23,7 @@ type Relay struct {
|
||||
func (r *Relay) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) {
|
||||
var proxies []C.Proxy
|
||||
for _, proxy := range r.proxies(metadata, true) {
|
||||
if proxy.Type() != C.Direct {
|
||||
if proxy.Type() != C.Direct && proxy.Type() != C.Compatible {
|
||||
proxies = append(proxies, proxy)
|
||||
}
|
||||
}
|
||||
@ -69,10 +69,12 @@ func (r *Relay) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d
|
||||
|
||||
// MarshalJSON implements C.ProxyAdapter
|
||||
func (r *Relay) MarshalJSON() ([]byte, error) {
|
||||
var all []string
|
||||
all := make([]string, 0)
|
||||
|
||||
for _, proxy := range r.rawProxies(false) {
|
||||
all = append(all, proxy.Name())
|
||||
}
|
||||
|
||||
return json.Marshal(map[string]interface{}{
|
||||
"type": r.Type().String(),
|
||||
"all": all,
|
||||
|
@ -50,7 +50,8 @@ func (s *Selector) SupportUDP() bool {
|
||||
|
||||
// MarshalJSON implements C.ProxyAdapter
|
||||
func (s *Selector) MarshalJSON() ([]byte, error) {
|
||||
var all []string
|
||||
all := make([]string, 0)
|
||||
|
||||
for _, proxy := range getProvidersProxies(s.providers, false, s.filter) {
|
||||
all = append(all, proxy.Name())
|
||||
}
|
||||
|
@ -125,10 +125,12 @@ func (u *URLTest) SupportUDP() bool {
|
||||
|
||||
// MarshalJSON implements C.ProxyAdapter
|
||||
func (u *URLTest) MarshalJSON() ([]byte, error) {
|
||||
var all []string
|
||||
all := make([]string, 0)
|
||||
|
||||
for _, proxy := range u.proxies(false) {
|
||||
all = append(all, proxy.Name())
|
||||
}
|
||||
|
||||
return json.Marshal(map[string]interface{}{
|
||||
"type": u.Type().String(),
|
||||
"now": u.Now(),
|
||||
@ -149,7 +151,7 @@ func (u *URLTest) onDialFailed() {
|
||||
} else {
|
||||
failedCount := u.failedTimes.Inc()
|
||||
log.Warnln("%s failed count: %d", u.Name(), failedCount)
|
||||
if failedCount >= 5 && failedCount < 6 {
|
||||
if failedCount >= 5 {
|
||||
log.Warnln("because %s failed multiple times, active health check", u.Name())
|
||||
for _, proxyProvider := range u.providers {
|
||||
go proxyProvider.HealthCheck()
|
||||
|
Reference in New Issue
Block a user