mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-12-02 17:56:47 +00:00
chore: update proxygroup interface
This commit is contained in:
1 parent
ba42eb4aaf
commit
4500802b26
6 files changed
+38
-29
No files matched your search
@@ -19,8 +19,6 @@ type Fallback struct {
|
||||
testUrl string
|
||||
selected string
|
||||
expectedStatus string
|
||||
Hidden bool
|
||||
Icon string
|
||||
}
|
||||
|
||||
func (f *Fallback) Now() string {
|
||||
@@ -90,8 +88,8 @@ func (f *Fallback) MarshalJSON() ([]byte, error) {
|
||||
"testUrl": f.testUrl,
|
||||
"expectedStatus": f.expectedStatus,
|
||||
"fixed": f.selected,
|
||||
"hidden": f.Hidden,
|
||||
"icon": f.Icon,
|
||||
"hidden": f.Hidden(),
|
||||
"icon": f.Icon(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -163,6 +161,8 @@ func NewFallback(option *GroupCommonOption, providers []P.ProxyProvider) *Fallba
|
||||
GroupBase: NewGroupBase(GroupBaseOption{
|
||||
Name: option.Name,
|
||||
Type: C.Fallback,
|
||||
Hidden: option.Hidden,
|
||||
Icon: option.Icon,
|
||||
Filter: option.Filter,
|
||||
ExcludeFilter: option.ExcludeFilter,
|
||||
ExcludeType: option.ExcludeType,
|
||||
@@ -173,7 +173,5 @@ func NewFallback(option *GroupCommonOption, providers []P.ProxyProvider) *Fallba
|
||||
disableUDP: option.DisableUDP,
|
||||
testUrl: option.URL,
|
||||
expectedStatus: option.ExpectedStatus,
|
||||
Hidden: option.Hidden,
|
||||
Icon: option.Icon,
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import (
|
||||
|
||||
type GroupBase struct {
|
||||
*outbound.Base
|
||||
hidden bool
|
||||
icon string
|
||||
filterRegs []*regexp2.Regexp
|
||||
excludeFilterRegs []*regexp2.Regexp
|
||||
excludeTypeArray []string
|
||||
@@ -30,7 +32,7 @@ type GroupBase struct {
|
||||
failedTimes int
|
||||
failedTime time.Time
|
||||
failedTesting atomic.Bool
|
||||
TestTimeout int
|
||||
testTimeout int
|
||||
maxFailedTimes int
|
||||
|
||||
// for GetProxies
|
||||
@@ -42,6 +44,8 @@ type GroupBase struct {
|
||||
type GroupBaseOption struct {
|
||||
Name string
|
||||
Type C.AdapterType
|
||||
Hidden bool
|
||||
Icon string
|
||||
Filter string
|
||||
ExcludeFilter string
|
||||
ExcludeType string
|
||||
@@ -74,17 +78,19 @@ func NewGroupBase(opt GroupBaseOption) *GroupBase {
|
||||
|
||||
gb := &GroupBase{
|
||||
Base: outbound.NewBase(outbound.BaseOption{Name: opt.Name, Type: opt.Type}),
|
||||
hidden: opt.Hidden,
|
||||
icon: opt.Icon,
|
||||
filterRegs: filterRegs,
|
||||
excludeFilterRegs: excludeFilterRegs,
|
||||
excludeTypeArray: excludeTypeArray,
|
||||
providers: opt.Providers,
|
||||
failedTesting: atomic.NewBool(false),
|
||||
TestTimeout: opt.TestTimeout,
|
||||
testTimeout: opt.TestTimeout,
|
||||
maxFailedTimes: opt.MaxFailedTimes,
|
||||
}
|
||||
|
||||
if gb.TestTimeout == 0 {
|
||||
gb.TestTimeout = 5000
|
||||
if gb.testTimeout == 0 {
|
||||
gb.testTimeout = 5000
|
||||
}
|
||||
if gb.maxFailedTimes == 0 {
|
||||
gb.maxFailedTimes = 5
|
||||
@@ -93,6 +99,14 @@ func NewGroupBase(opt GroupBaseOption) *GroupBase {
|
||||
return gb
|
||||
}
|
||||
|
||||
func (gb *GroupBase) Hidden() bool {
|
||||
return gb.hidden
|
||||
}
|
||||
|
||||
func (gb *GroupBase) Icon() string {
|
||||
return gb.icon
|
||||
}
|
||||
|
||||
func (gb *GroupBase) Touch() {
|
||||
for _, pd := range gb.providers {
|
||||
pd.Touch()
|
||||
@@ -265,7 +279,7 @@ func (gb *GroupBase) onDialFailed(adapterType C.AdapterType, err error, fn func(
|
||||
log.Debugln("ProxyGroup: %s first failed", gb.Name())
|
||||
gb.failedTime = time.Now()
|
||||
} else {
|
||||
if time.Since(gb.failedTime) > time.Duration(gb.TestTimeout)*time.Millisecond {
|
||||
if time.Since(gb.failedTime) > time.Duration(gb.testTimeout)*time.Millisecond {
|
||||
gb.failedTimes = 0
|
||||
return
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ type LoadBalance struct {
|
||||
strategyFn strategyFn
|
||||
testUrl string
|
||||
expectedStatus string
|
||||
Hidden bool
|
||||
Icon string
|
||||
}
|
||||
|
||||
var errStrategy = errors.New("unsupported strategy")
|
||||
@@ -234,8 +232,8 @@ func (lb *LoadBalance) MarshalJSON() ([]byte, error) {
|
||||
"all": all,
|
||||
"testUrl": lb.testUrl,
|
||||
"expectedStatus": lb.expectedStatus,
|
||||
"hidden": lb.Hidden,
|
||||
"icon": lb.Icon,
|
||||
"hidden": lb.Hidden(),
|
||||
"icon": lb.Icon(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -267,6 +265,8 @@ func NewLoadBalance(option *GroupCommonOption, providers []P.ProxyProvider, stra
|
||||
GroupBase: NewGroupBase(GroupBaseOption{
|
||||
Name: option.Name,
|
||||
Type: C.LoadBalance,
|
||||
Hidden: option.Hidden,
|
||||
Icon: option.Icon,
|
||||
Filter: option.Filter,
|
||||
ExcludeFilter: option.ExcludeFilter,
|
||||
ExcludeType: option.ExcludeType,
|
||||
@@ -278,7 +278,5 @@ func NewLoadBalance(option *GroupCommonOption, providers []P.ProxyProvider, stra
|
||||
disableUDP: option.DisableUDP,
|
||||
testUrl: option.URL,
|
||||
expectedStatus: option.ExpectedStatus,
|
||||
Hidden: option.Hidden,
|
||||
Icon: option.Icon,
|
||||
}, nil
|
||||
}
|
||||
@@ -14,8 +14,6 @@ type Selector struct {
|
||||
disableUDP bool
|
||||
selected string
|
||||
testUrl string
|
||||
Hidden bool
|
||||
Icon string
|
||||
}
|
||||
|
||||
// DialContext implements C.ProxyAdapter
|
||||
@@ -68,8 +66,8 @@ func (s *Selector) MarshalJSON() ([]byte, error) {
|
||||
"now": s.Now(),
|
||||
"all": all,
|
||||
"testUrl": url,
|
||||
"hidden": s.Hidden,
|
||||
"icon": s.Icon,
|
||||
"hidden": s.Hidden(),
|
||||
"icon": s.Icon(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -121,6 +119,8 @@ func NewSelector(option *GroupCommonOption, providers []P.ProxyProvider) *Select
|
||||
GroupBase: NewGroupBase(GroupBaseOption{
|
||||
Name: option.Name,
|
||||
Type: C.Selector,
|
||||
Hidden: option.Hidden,
|
||||
Icon: option.Icon,
|
||||
Filter: option.Filter,
|
||||
ExcludeFilter: option.ExcludeFilter,
|
||||
ExcludeType: option.ExcludeType,
|
||||
@@ -131,7 +131,5 @@ func NewSelector(option *GroupCommonOption, providers []P.ProxyProvider) *Select
|
||||
selected: "COMPATIBLE",
|
||||
disableUDP: option.DisableUDP,
|
||||
testUrl: option.URL,
|
||||
Hidden: option.Hidden,
|
||||
Icon: option.Icon,
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,6 @@ type URLTest struct {
|
||||
expectedStatus string
|
||||
tolerance uint16
|
||||
disableUDP bool
|
||||
Hidden bool
|
||||
Icon string
|
||||
fastNode C.Proxy
|
||||
fastSingle *singledo.Single[C.Proxy]
|
||||
}
|
||||
@@ -180,8 +178,8 @@ func (u *URLTest) MarshalJSON() ([]byte, error) {
|
||||
"testUrl": u.testUrl,
|
||||
"expectedStatus": u.expectedStatus,
|
||||
"fixed": u.selected,
|
||||
"hidden": u.Hidden,
|
||||
"icon": u.Icon,
|
||||
"hidden": u.Hidden(),
|
||||
"icon": u.Icon(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -215,6 +213,8 @@ func NewURLTest(option *GroupCommonOption, providers []P.ProxyProvider, options
|
||||
GroupBase: NewGroupBase(GroupBaseOption{
|
||||
Name: option.Name,
|
||||
Type: C.URLTest,
|
||||
Hidden: option.Hidden,
|
||||
Icon: option.Icon,
|
||||
Filter: option.Filter,
|
||||
ExcludeFilter: option.ExcludeFilter,
|
||||
ExcludeType: option.ExcludeType,
|
||||
@@ -226,8 +226,6 @@ func NewURLTest(option *GroupCommonOption, providers []P.ProxyProvider, options
|
||||
disableUDP: option.DisableUDP,
|
||||
testUrl: option.URL,
|
||||
expectedStatus: option.ExpectedStatus,
|
||||
Hidden: option.Hidden,
|
||||
Icon: option.Icon,
|
||||
}
|
||||
|
||||
for _, option := range options {
|
||||
|
||||
@@ -16,6 +16,9 @@ type ProxyGroup interface {
|
||||
Now() string
|
||||
Touch()
|
||||
|
||||
Hidden() bool
|
||||
Icon() string
|
||||
|
||||
URLTest(ctx context.Context, url string, expectedStatus utils.IntRanges[uint16]) (mp map[string]uint16, err error)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user