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

View file

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

View file

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