fix: group filter touch provider

This commit is contained in:
adlyq 2022-06-07 17:19:25 +08:00
parent 2a4f2f3942
commit ed17a1bf23
6 changed files with 37 additions and 47 deletions

View file

@ -81,7 +81,7 @@ type HysteriaOption struct {
Obfs string `proxy:"obfs,omitempty"` Obfs string `proxy:"obfs,omitempty"`
SNI string `proxy:"sni,omitempty"` SNI string `proxy:"sni,omitempty"`
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"` SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
ALPN []string `proxy:"alpn,omitempty"` ALPN string `proxy:"alpn,omitempty"`
CustomCA string `proxy:"ca,omitempty"` CustomCA string `proxy:"ca,omitempty"`
CustomCAString string `proxy:"ca_str,omitempty"` CustomCAString string `proxy:"ca_str,omitempty"`
ReceiveWindowConn uint64 `proxy:"recv_window_conn,omitempty"` ReceiveWindowConn uint64 `proxy:"recv_window_conn,omitempty"`
@ -126,7 +126,7 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
MinVersion: tls.VersionTLS13, MinVersion: tls.VersionTLS13,
} }
if len(option.ALPN) > 0 { if len(option.ALPN) > 0 {
tlsConfig.NextProtos = option.ALPN tlsConfig.NextProtos = []string{option.ALPN}
} else { } else {
tlsConfig.NextProtos = []string{DefaultALPN} tlsConfig.NextProtos = []string{DefaultALPN}
} }

View file

@ -51,10 +51,9 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
var proxies []C.Proxy var proxies []C.Proxy
for _, pd := range gb.providers { for _, pd := range gb.providers {
if touch { if touch {
proxies = append(proxies, pd.ProxiesWithTouch()...) pd.Touch()
} else {
proxies = append(proxies, pd.Proxies()...)
} }
proxies = append(proxies, pd.Proxies()...)
} }
if len(proxies) == 0 { if len(proxies) == 0 {
return append(proxies, tunnel.Proxies()["COMPATIBLE"]) return append(proxies, tunnel.Proxies()["COMPATIBLE"])
@ -63,13 +62,12 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
} }
for _, pd := range gb.providers { for _, pd := range gb.providers {
if pd.VehicleType() == types.Compatible {
if touch { if touch {
gb.proxies.Store(pd.Name(), pd.ProxiesWithTouch()) pd.Touch()
} else {
gb.proxies.Store(pd.Name(), pd.Proxies())
} }
if pd.VehicleType() == types.Compatible {
gb.proxies.Store(pd.Name(), pd.Proxies())
gb.versions.Store(pd.Name(), pd.Version()) gb.versions.Store(pd.Name(), pd.Version())
continue continue
} }
@ -80,11 +78,7 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
newProxies []C.Proxy newProxies []C.Proxy
) )
if touch {
proxies = pd.ProxiesWithTouch()
} else {
proxies = pd.Proxies() proxies = pd.Proxies()
}
for _, p := range proxies { for _, p := range proxies {
if mat, _ := gb.filter.FindStringMatch(p.Name()); mat != nil { if mat, _ := gb.filter.FindStringMatch(p.Name()); mat != nil {

View file

@ -75,9 +75,11 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
providers = append(providers, pd) providers = append(providers, pd)
providersMap[groupName] = pd providersMap[groupName] = pd
} else { } else {
if groupOption.URL == "" || groupOption.Interval == 0 { if groupOption.URL == "" {
//return nil, errMissHealthCheck
groupOption.URL = "http://www.gstatic.com/generate_204" groupOption.URL = "http://www.gstatic.com/generate_204"
}
if groupOption.Interval == 0 {
groupOption.Interval = 300 groupOption.Interval = 300
} }

View file

@ -32,9 +32,7 @@ func (hc *HealthCheck) process() {
ticker := time.NewTicker(time.Duration(hc.interval) * time.Second) ticker := time.NewTicker(time.Duration(hc.interval) * time.Second)
go func() { go func() {
t := time.NewTicker(30 * time.Second) time.Sleep(30 * time.Second)
<-t.C
t.Stop()
hc.check() hc.check()
}() }()

View file

@ -84,9 +84,8 @@ func (pp *proxySetProvider) Proxies() []C.Proxy {
return pp.proxies return pp.proxies
} }
func (pp *proxySetProvider) ProxiesWithTouch() []C.Proxy { func (pp *proxySetProvider) Touch() {
pp.healthCheck.touch() pp.healthCheck.touch()
return pp.Proxies()
} }
func (pp *proxySetProvider) setProxies(proxies []C.Proxy) { func (pp *proxySetProvider) setProxies(proxies []C.Proxy) {
@ -178,9 +177,8 @@ func (cp *compatibleProvider) Proxies() []C.Proxy {
return cp.proxies return cp.proxies
} }
func (cp *compatibleProvider) ProxiesWithTouch() []C.Proxy { func (cp *compatibleProvider) Touch() {
cp.healthCheck.touch() cp.healthCheck.touch()
return cp.Proxies()
} }
func stopCompatibleProvider(pd *CompatibleProvider) { func stopCompatibleProvider(pd *CompatibleProvider) {

View file

@ -66,9 +66,7 @@ type Provider interface {
type ProxyProvider interface { type ProxyProvider interface {
Provider Provider
Proxies() []C.Proxy Proxies() []C.Proxy
// ProxiesWithTouch is used to inform the provider that the proxy is actually being used while getting the list of proxies. Touch()
// Commonly used in DialContext and DialPacketConn
ProxiesWithTouch() []C.Proxy
HealthCheck() HealthCheck()
Version() uint Version() uint
} }