refactor: field name

This commit is contained in:
adlyq 2022-04-28 23:06:35 +08:00
parent bbbe371ea9
commit b9f270162a
3 changed files with 17 additions and 18 deletions

View File

@ -13,7 +13,7 @@ type GroupBase struct {
*outbound.Base *outbound.Base
filter *regexp2.Regexp filter *regexp2.Regexp
providers []provider.ProxyProvider providers []provider.ProxyProvider
flags map[string]uint versions map[string]uint
proxies map[string][]C.Proxy proxies map[string][]C.Proxy
} }
@ -32,7 +32,7 @@ func NewGroupBase(opt GroupBaseOption) *GroupBase {
Base: outbound.NewBase(opt.BaseOption), Base: outbound.NewBase(opt.BaseOption),
filter: filter, filter: filter,
providers: opt.providers, providers: opt.providers,
flags: map[string]uint{}, versions: map[string]uint{},
proxies: map[string][]C.Proxy{}, proxies: map[string][]C.Proxy{},
} }
} }
@ -52,21 +52,20 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
} }
return proxies return proxies
} }
//TODO("Touch Flag 没变的") //TODO("Touch Version 没变的")
for _, pd := range gb.providers { for _, pd := range gb.providers {
vt := pd.VehicleType() if pd.VehicleType() == types.Compatible {
if vt == types.Compatible {
if touch { if touch {
gb.proxies[pd.Name()] = pd.ProxiesWithTouch() gb.proxies[pd.Name()] = pd.ProxiesWithTouch()
} else { } else {
gb.proxies[pd.Name()] = pd.Proxies() gb.proxies[pd.Name()] = pd.Proxies()
} }
gb.flags[pd.Name()] = pd.Flag() gb.versions[pd.Name()] = pd.Version()
continue continue
} }
if flag, ok := gb.flags[pd.Name()]; !ok || flag != pd.Flag() { if version, ok := gb.versions[pd.Name()]; !ok || version != pd.Version() {
var ( var (
proxies []C.Proxy proxies []C.Proxy
newProxies []C.Proxy newProxies []C.Proxy
@ -85,7 +84,7 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
} }
gb.proxies[pd.Name()] = newProxies gb.proxies[pd.Name()] = newProxies
gb.flags[pd.Name()] = pd.Flag() gb.versions[pd.Name()] = pd.Version()
} }
} }
var proxies []C.Proxy var proxies []C.Proxy

View File

@ -33,11 +33,11 @@ type proxySetProvider struct {
*fetcher *fetcher
proxies []C.Proxy proxies []C.Proxy
healthCheck *HealthCheck healthCheck *HealthCheck
flag uint version uint
} }
func (pp *proxySetProvider) Flag() uint { func (pp *proxySetProvider) Version() uint {
return pp.flag return pp.version
} }
func (pp *proxySetProvider) MarshalJSON() ([]byte, error) { func (pp *proxySetProvider) MarshalJSON() ([]byte, error) {
@ -123,10 +123,10 @@ func NewProxySetProvider(name string, interval time.Duration, filter string, veh
onUpdate := func(elm any) { onUpdate := func(elm any) {
ret := elm.([]C.Proxy) ret := elm.([]C.Proxy)
pd.setProxies(ret) pd.setProxies(ret)
if pd.flag == math.MaxUint { if pd.version == math.MaxUint {
pd.flag = 0 pd.version = 0
} else { } else {
pd.flag++ pd.version++
} }
} }
@ -182,11 +182,11 @@ type compatibleProvider struct {
name string name string
healthCheck *HealthCheck healthCheck *HealthCheck
proxies []C.Proxy proxies []C.Proxy
flag uint version uint
} }
func (cp *compatibleProvider) Flag() uint { func (cp *compatibleProvider) Version() uint {
return cp.flag return cp.version
} }
func (cp *compatibleProvider) MarshalJSON() ([]byte, error) { func (cp *compatibleProvider) MarshalJSON() ([]byte, error) {

View File

@ -70,7 +70,7 @@ type ProxyProvider interface {
// Commonly used in DialContext and DialPacketConn // Commonly used in DialContext and DialPacketConn
ProxiesWithTouch() []constant.Proxy ProxiesWithTouch() []constant.Proxy
HealthCheck() HealthCheck()
Flag() uint Version() uint
} }
// Rule Type // Rule Type