Skip to content

Commit

Permalink
fix: group filter touch provider
Browse files Browse the repository at this point in the history
  • Loading branch information
adlyq authored and Skyxim committed Jun 9, 2022
1 parent e995003 commit 0a4570b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
22 changes: 8 additions & 14 deletions adapter/outboundgroup/groupbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
var proxies []C.Proxy
for _, pd := range gb.providers {
if touch {
proxies = append(proxies, pd.ProxiesWithTouch()...)
} else {
proxies = append(proxies, pd.Proxies()...)
pd.Touch()
}
proxies = append(proxies, pd.Proxies()...)
}
if len(proxies) == 0 {
return append(proxies, tunnel.Proxies()["COMPATIBLE"])
Expand All @@ -63,13 +62,12 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
}

for _, pd := range gb.providers {
if pd.VehicleType() == types.Compatible {
if touch {
gb.proxies.Store(pd.Name(), pd.ProxiesWithTouch())
} else {
gb.proxies.Store(pd.Name(), pd.Proxies())
}
if touch {
pd.Touch()
}

if pd.VehicleType() == types.Compatible {
gb.proxies.Store(pd.Name(), pd.Proxies())
gb.versions.Store(pd.Name(), pd.Version())
continue
}
Expand All @@ -80,11 +78,7 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
newProxies []C.Proxy
)

if touch {
proxies = pd.ProxiesWithTouch()
} else {
proxies = pd.Proxies()
}
proxies = pd.Proxies()

for _, p := range proxies {
if mat, _ := gb.filter.FindStringMatch(p.Name()); mat != nil {
Expand Down
6 changes: 4 additions & 2 deletions adapter/outboundgroup/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
providers = append(providers, pd)
providersMap[groupName] = pd
} else {
if groupOption.URL == "" || groupOption.Interval == 0 {
//return nil, errMissHealthCheck
if groupOption.URL == "" {
groupOption.URL = "http://www.gstatic.com/generate_204"
}

if groupOption.Interval == 0 {
groupOption.Interval = 300
}

Expand Down
4 changes: 1 addition & 3 deletions adapter/provider/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func (hc *HealthCheck) process() {
ticker := time.NewTicker(time.Duration(hc.interval) * time.Second)

go func() {
t := time.NewTicker(30 * time.Second)
<-t.C
t.Stop()
time.Sleep(30 * time.Second)
hc.check()
}()

Expand Down
6 changes: 2 additions & 4 deletions adapter/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ func (pp *proxySetProvider) Proxies() []C.Proxy {
return pp.proxies
}

func (pp *proxySetProvider) ProxiesWithTouch() []C.Proxy {
func (pp *proxySetProvider) Touch() {
pp.healthCheck.touch()
return pp.Proxies()
}

func (pp *proxySetProvider) setProxies(proxies []C.Proxy) {
Expand Down Expand Up @@ -178,9 +177,8 @@ func (cp *compatibleProvider) Proxies() []C.Proxy {
return cp.proxies
}