chore: cleanup import path for constant/provider

This commit is contained in:
wwqgtxx 2025-11-06 19:27:06 +08:00
parent a3c023ae3e
commit 1d5890abc1
17 changed files with 104 additions and 105 deletions

View File

@ -10,7 +10,7 @@ import (
N "github.com/metacubex/mihomo/common/net" N "github.com/metacubex/mihomo/common/net"
"github.com/metacubex/mihomo/common/utils" "github.com/metacubex/mihomo/common/utils"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
) )
type Fallback struct { type Fallback struct {
@ -150,7 +150,7 @@ func (f *Fallback) ForceSet(name string) {
f.selected = name f.selected = name
} }
func NewFallback(option *GroupCommonOption, providers []provider.ProxyProvider) *Fallback { func NewFallback(option *GroupCommonOption, providers []P.ProxyProvider) *Fallback {
return &Fallback{ return &Fallback{
GroupBase: NewGroupBase(GroupBaseOption{ GroupBase: NewGroupBase(GroupBaseOption{
Name: option.Name, Name: option.Name,

View File

@ -12,8 +12,7 @@ import (
"github.com/metacubex/mihomo/common/atomic" "github.com/metacubex/mihomo/common/atomic"
"github.com/metacubex/mihomo/common/utils" "github.com/metacubex/mihomo/common/utils"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
types "github.com/metacubex/mihomo/constant/provider"
"github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/log"
"github.com/metacubex/mihomo/tunnel" "github.com/metacubex/mihomo/tunnel"
@ -26,7 +25,7 @@ type GroupBase struct {
filterRegs []*regexp2.Regexp filterRegs []*regexp2.Regexp
excludeFilterRegs []*regexp2.Regexp excludeFilterRegs []*regexp2.Regexp
excludeTypeArray []string excludeTypeArray []string
providers []provider.ProxyProvider providers []P.ProxyProvider
failedTestMux sync.Mutex failedTestMux sync.Mutex
failedTimes int failedTimes int
failedTime time.Time failedTime time.Time
@ -48,7 +47,7 @@ type GroupBaseOption struct {
ExcludeType string ExcludeType string
TestTimeout int TestTimeout int
MaxFailedTimes int MaxFailedTimes int
Providers []provider.ProxyProvider Providers []P.ProxyProvider
} }
func NewGroupBase(opt GroupBaseOption) *GroupBase { func NewGroupBase(opt GroupBaseOption) *GroupBase {
@ -125,7 +124,7 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
} }
} else { } else {
for _, pd := range gb.providers { for _, pd := range gb.providers {
if pd.VehicleType() == types.Compatible { // compatible provider unneeded filter if pd.VehicleType() == P.Compatible { // compatible provider unneeded filter
proxies = append(proxies, pd.Proxies()...) proxies = append(proxies, pd.Proxies()...)
continue continue
} }

View File

@ -14,7 +14,7 @@ import (
N "github.com/metacubex/mihomo/common/net" N "github.com/metacubex/mihomo/common/net"
"github.com/metacubex/mihomo/common/utils" "github.com/metacubex/mihomo/common/utils"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
"golang.org/x/net/publicsuffix" "golang.org/x/net/publicsuffix"
) )
@ -239,7 +239,7 @@ func (lb *LoadBalance) MarshalJSON() ([]byte, error) {
}) })
} }
func NewLoadBalance(option *GroupCommonOption, providers []provider.ProxyProvider, strategy string) (lb *LoadBalance, err error) { func NewLoadBalance(option *GroupCommonOption, providers []P.ProxyProvider, strategy string) (lb *LoadBalance, err error) {
var strategyFn strategyFn var strategyFn strategyFn
switch strategy { switch strategy {
case "consistent-hashing": case "consistent-hashing":

View File

@ -11,7 +11,7 @@ import (
"github.com/metacubex/mihomo/common/structure" "github.com/metacubex/mihomo/common/structure"
"github.com/metacubex/mihomo/common/utils" "github.com/metacubex/mihomo/common/utils"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
types "github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
"github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/log"
) )
@ -48,7 +48,7 @@ type GroupCommonOption struct {
RoutingMark int `group:"routing-mark,omitempty"` RoutingMark int `group:"routing-mark,omitempty"`
} }
func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, providersMap map[string]types.ProxyProvider, AllProxies []string, AllProviders []string) (C.ProxyAdapter, error) { func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, providersMap map[string]P.ProxyProvider, AllProxies []string, AllProviders []string) (C.ProxyAdapter, error) {
decoder := structure.NewDecoder(structure.Option{TagName: "group", WeaklyTypedInput: true}) decoder := structure.NewDecoder(structure.Option{TagName: "group", WeaklyTypedInput: true})
groupOption := &GroupCommonOption{ groupOption := &GroupCommonOption{
@ -71,7 +71,7 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
groupName := groupOption.Name groupName := groupOption.Name
providers := []types.ProxyProvider{} providers := []P.ProxyProvider{}
if groupOption.IncludeAll { if groupOption.IncludeAll {
groupOption.IncludeAllProviders = true groupOption.IncludeAllProviders = true
@ -169,7 +169,7 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
return nil, fmt.Errorf("%s: %w", groupName, err) return nil, fmt.Errorf("%s: %w", groupName, err)
} }
providers = append([]types.ProxyProvider{pd}, providers...) providers = append([]P.ProxyProvider{pd}, providers...)
providersMap[groupName] = pd providersMap[groupName] = pd
} }
@ -206,15 +206,15 @@ func getProxies(mapping map[string]C.Proxy, list []string) ([]C.Proxy, error) {
return ps, nil return ps, nil
} }
func getProviders(mapping map[string]types.ProxyProvider, list []string) ([]types.ProxyProvider, error) { func getProviders(mapping map[string]P.ProxyProvider, list []string) ([]P.ProxyProvider, error) {
var ps []types.ProxyProvider var ps []P.ProxyProvider
for _, name := range list { for _, name := range list {
p, ok := mapping[name] p, ok := mapping[name]
if !ok { if !ok {
return nil, fmt.Errorf("'%s' not found", name) return nil, fmt.Errorf("'%s' not found", name)
} }
if p.VehicleType() == types.Compatible { if p.VehicleType() == P.Compatible {
return nil, fmt.Errorf("proxy group %s can't contains in `use`", name) return nil, fmt.Errorf("proxy group %s can't contains in `use`", name)
} }
ps = append(ps, p) ps = append(ps, p)
@ -222,7 +222,7 @@ func getProviders(mapping map[string]types.ProxyProvider, list []string) ([]type
return ps, nil return ps, nil
} }
func addTestUrlToProviders(providers []types.ProxyProvider, url string, expectedStatus utils.IntRanges[uint16], filter string, interval uint) { func addTestUrlToProviders(providers []P.ProxyProvider, url string, expectedStatus utils.IntRanges[uint16], filter string, interval uint) {
if len(providers) == 0 || len(url) == 0 { if len(providers) == 0 || len(url) == 0 {
return return
} }

View File

@ -4,22 +4,22 @@ package outboundgroup
import ( import (
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
) )
type ProxyGroup interface { type ProxyGroup interface {
C.ProxyAdapter C.ProxyAdapter
Providers() []provider.ProxyProvider Providers() []P.ProxyProvider
Proxies() []C.Proxy Proxies() []C.Proxy
Now() string Now() string
} }
func (f *Fallback) Providers() []provider.ProxyProvider { func (f *Fallback) Providers() []P.ProxyProvider {
return f.providers return f.providers
} }
func (lb *LoadBalance) Providers() []provider.ProxyProvider { func (lb *LoadBalance) Providers() []P.ProxyProvider {
return lb.providers return lb.providers
} }
@ -35,7 +35,7 @@ func (lb *LoadBalance) Now() string {
return "" return ""
} }
func (r *Relay) Providers() []provider.ProxyProvider { func (r *Relay) Providers() []P.ProxyProvider {
return r.providers return r.providers
} }
@ -47,7 +47,7 @@ func (r *Relay) Now() string {
return "" return ""
} }
func (s *Selector) Providers() []provider.ProxyProvider { func (s *Selector) Providers() []P.ProxyProvider {
return s.providers return s.providers
} }
@ -55,7 +55,7 @@ func (s *Selector) Proxies() []C.Proxy {
return s.GetProxies(false) return s.GetProxies(false)
} }
func (u *URLTest) Providers() []provider.ProxyProvider { func (u *URLTest) Providers() []P.ProxyProvider {
return u.providers return u.providers
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/metacubex/mihomo/component/dialer" "github.com/metacubex/mihomo/component/dialer"
"github.com/metacubex/mihomo/component/proxydialer" "github.com/metacubex/mihomo/component/proxydialer"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
"github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/log"
) )
@ -149,7 +149,7 @@ func (r *Relay) Addr() string {
return proxies[len(proxies)-1].Addr() return proxies[len(proxies)-1].Addr()
} }
func NewRelay(option *GroupCommonOption, providers []provider.ProxyProvider) *Relay { func NewRelay(option *GroupCommonOption, providers []P.ProxyProvider) *Relay {
log.Warnln("The group [%s] with relay type is deprecated, please using dialer-proxy instead", option.Name) log.Warnln("The group [%s] with relay type is deprecated, please using dialer-proxy instead", option.Name)
return &Relay{ return &Relay{
GroupBase: NewGroupBase(GroupBaseOption{ GroupBase: NewGroupBase(GroupBaseOption{

View File

@ -6,7 +6,7 @@ import (
"errors" "errors"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
) )
type Selector struct { type Selector struct {
@ -108,7 +108,7 @@ func (s *Selector) selectedProxy(touch bool) C.Proxy {
return proxies[0] return proxies[0]
} }
func NewSelector(option *GroupCommonOption, providers []provider.ProxyProvider) *Selector { func NewSelector(option *GroupCommonOption, providers []P.ProxyProvider) *Selector {
return &Selector{ return &Selector{
GroupBase: NewGroupBase(GroupBaseOption{ GroupBase: NewGroupBase(GroupBaseOption{
Name: option.Name, Name: option.Name,

View File

@ -11,7 +11,7 @@ import (
"github.com/metacubex/mihomo/common/singledo" "github.com/metacubex/mihomo/common/singledo"
"github.com/metacubex/mihomo/common/utils" "github.com/metacubex/mihomo/common/utils"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
) )
type urlTestOption func(*URLTest) type urlTestOption func(*URLTest)
@ -202,7 +202,7 @@ func parseURLTestOption(config map[string]any) []urlTestOption {
return opts return opts
} }
func NewURLTest(option *GroupCommonOption, providers []provider.ProxyProvider, options ...urlTestOption) *URLTest { func NewURLTest(option *GroupCommonOption, providers []P.ProxyProvider, options ...urlTestOption) *URLTest {
urlTest := &URLTest{ urlTest := &URLTest{
GroupBase: NewGroupBase(GroupBaseOption{ GroupBase: NewGroupBase(GroupBaseOption{
Name: option.Name, Name: option.Name,

View File

@ -10,7 +10,7 @@ import (
"github.com/metacubex/mihomo/common/utils" "github.com/metacubex/mihomo/common/utils"
"github.com/metacubex/mihomo/component/resource" "github.com/metacubex/mihomo/component/resource"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
types "github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
"github.com/dlclark/regexp2" "github.com/dlclark/regexp2"
) )
@ -73,7 +73,7 @@ type proxyProviderSchema struct {
Header map[string][]string `provider:"header,omitempty"` Header map[string][]string `provider:"header,omitempty"`
} }
func ParseProxyProvider(name string, mapping map[string]any) (types.ProxyProvider, error) { func ParseProxyProvider(name string, mapping map[string]any) (P.ProxyProvider, error) {
decoder := structure.NewDecoder(structure.Option{TagName: "provider", WeaklyTypedInput: true}) decoder := structure.NewDecoder(structure.Option{TagName: "provider", WeaklyTypedInput: true})
schema := &proxyProviderSchema{ schema := &proxyProviderSchema{
@ -104,7 +104,7 @@ func ParseProxyProvider(name string, mapping map[string]any) (types.ProxyProvide
return nil, err return nil, err
} }
var vehicle types.Vehicle var vehicle P.Vehicle
switch schema.Type { switch schema.Type {
case "file": case "file":
path := C.Path.Resolve(schema.Path) path := C.Path.Resolve(schema.Path)

View File

@ -16,7 +16,7 @@ import (
"github.com/metacubex/mihomo/component/profile/cachefile" "github.com/metacubex/mihomo/component/profile/cachefile"
"github.com/metacubex/mihomo/component/resource" "github.com/metacubex/mihomo/component/resource"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
types "github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
"github.com/metacubex/mihomo/tunnel/statistic" "github.com/metacubex/mihomo/tunnel/statistic"
"github.com/dlclark/regexp2" "github.com/dlclark/regexp2"
@ -68,8 +68,8 @@ func (bp *baseProvider) HealthCheck() {
bp.healthCheck.check() bp.healthCheck.check()
} }
func (bp *baseProvider) Type() types.ProviderType { func (bp *baseProvider) Type() P.ProviderType {
return types.Proxy return P.Proxy
} }
func (bp *baseProvider) Proxies() []C.Proxy { func (bp *baseProvider) Proxies() []C.Proxy {
@ -171,7 +171,7 @@ func (pp *proxySetProvider) Close() error {
return pp.Fetcher.Close() return pp.Fetcher.Close()
} }
func NewProxySetProvider(name string, interval time.Duration, payload []map[string]any, parser resource.Parser[[]C.Proxy], vehicle types.Vehicle, hc *HealthCheck) (*ProxySetProvider, error) { func NewProxySetProvider(name string, interval time.Duration, payload []map[string]any, parser resource.Parser[[]C.Proxy], vehicle P.Vehicle, hc *HealthCheck) (*ProxySetProvider, error) {
pd := &proxySetProvider{ pd := &proxySetProvider{
baseProvider: baseProvider{ baseProvider: baseProvider{
name: name, name: name,
@ -238,8 +238,8 @@ func (ip *inlineProvider) MarshalJSON() ([]byte, error) {
}) })
} }
func (ip *inlineProvider) VehicleType() types.VehicleType { func (ip *inlineProvider) VehicleType() P.VehicleType {
return types.Inline return P.Inline
} }
func (ip *inlineProvider) Update() error { func (ip *inlineProvider) Update() error {
@ -303,8 +303,8 @@ func (cp *compatibleProvider) Update() error {
return nil return nil
} }
func (cp *compatibleProvider) VehicleType() types.VehicleType { func (cp *compatibleProvider) VehicleType() P.VehicleType {
return types.Compatible return P.Compatible
} }
func NewCompatibleProvider(name string, proxies []C.Proxy, hc *HealthCheck) (*CompatibleProvider, error) { func NewCompatibleProvider(name string, proxies []C.Proxy, hc *HealthCheck) (*CompatibleProvider, error) {

View File

@ -8,7 +8,7 @@ import (
"github.com/metacubex/mihomo/common/utils" "github.com/metacubex/mihomo/common/utils"
"github.com/metacubex/mihomo/component/slowdown" "github.com/metacubex/mihomo/component/slowdown"
types "github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
"github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/log"
"github.com/metacubex/fswatch" "github.com/metacubex/fswatch"
@ -22,7 +22,7 @@ type Fetcher[V any] struct {
ctxCancel context.CancelFunc ctxCancel context.CancelFunc
resourceType string resourceType string
name string name string
vehicle types.Vehicle vehicle P.Vehicle
updatedAt time.Time updatedAt time.Time
hash utils.HashType hash utils.HashType
parser Parser[V] parser Parser[V]
@ -37,11 +37,11 @@ func (f *Fetcher[V]) Name() string {
return f.name return f.name
} }
func (f *Fetcher[V]) Vehicle() types.Vehicle { func (f *Fetcher[V]) Vehicle() P.Vehicle {
return f.vehicle return f.vehicle
} }
func (f *Fetcher[V]) VehicleType() types.VehicleType { func (f *Fetcher[V]) VehicleType() P.VehicleType {
return f.vehicle.Type() return f.vehicle.Type()
} }
@ -88,7 +88,7 @@ func (f *Fetcher[V]) Update() (V, bool, error) {
f.backoff.AddAttempt() // add a failed attempt to backoff f.backoff.AddAttempt() // add a failed attempt to backoff
return lo.Empty[V](), false, err return lo.Empty[V](), false, err
} }
return f.loadBuf(buf, hash, f.vehicle.Type() != types.File) return f.loadBuf(buf, hash, f.vehicle.Type() != P.File)
} }
func (f *Fetcher[V]) SideUpdate(buf []byte) (V, bool, error) { func (f *Fetcher[V]) SideUpdate(buf []byte) (V, bool, error) {
@ -180,7 +180,7 @@ func (f *Fetcher[V]) pullLoop(forceUpdate bool) {
func (f *Fetcher[V]) startPullLoop(forceUpdate bool) (err error) { func (f *Fetcher[V]) startPullLoop(forceUpdate bool) (err error) {
// pull contents automatically // pull contents automatically
if f.vehicle.Type() == types.File { if f.vehicle.Type() == P.File {
f.watcher, err = fswatch.NewWatcher(fswatch.Options{ f.watcher, err = fswatch.NewWatcher(fswatch.Options{
Path: []string{f.vehicle.Path()}, Path: []string{f.vehicle.Path()},
Callback: f.updateCallback, Callback: f.updateCallback,
@ -218,7 +218,7 @@ func (f *Fetcher[V]) updateWithLog() {
return return
} }
func NewFetcher[V any](name string, interval time.Duration, vehicle types.Vehicle, parser Parser[V], onUpdate func(V)) *Fetcher[V] { func NewFetcher[V any](name string, interval time.Duration, vehicle P.Vehicle, parser Parser[V], onUpdate func(V)) *Fetcher[V] {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
minBackoff := 10 * time.Second minBackoff := 10 * time.Second
if interval < minBackoff { if interval < minBackoff {

View File

@ -12,7 +12,7 @@ import (
"github.com/metacubex/mihomo/common/utils" "github.com/metacubex/mihomo/common/utils"
mihomoHttp "github.com/metacubex/mihomo/component/http" mihomoHttp "github.com/metacubex/mihomo/component/http"
"github.com/metacubex/mihomo/component/profile/cachefile" "github.com/metacubex/mihomo/component/profile/cachefile"
types "github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
) )
const ( const (
@ -50,8 +50,8 @@ type FileVehicle struct {
path string path string
} }
func (f *FileVehicle) Type() types.VehicleType { func (f *FileVehicle) Type() P.VehicleType {
return types.File return P.File
} }
func (f *FileVehicle) Path() string { func (f *FileVehicle) Path() string {
@ -91,15 +91,15 @@ type HTTPVehicle struct {
timeout time.Duration timeout time.Duration
sizeLimit int64 sizeLimit int64
inRead func(response *http.Response) inRead func(response *http.Response)
provider types.ProxyProvider provider P.ProxyProvider
} }
func (h *HTTPVehicle) Url() string { func (h *HTTPVehicle) Url() string {
return h.url return h.url
} }
func (h *HTTPVehicle) Type() types.VehicleType { func (h *HTTPVehicle) Type() P.VehicleType {
return types.HTTP return P.HTTP
} }
func (h *HTTPVehicle) Path() string { func (h *HTTPVehicle) Path() string {

View File

@ -25,7 +25,7 @@ import (
"github.com/metacubex/mihomo/component/sniffer" "github.com/metacubex/mihomo/component/sniffer"
"github.com/metacubex/mihomo/component/trie" "github.com/metacubex/mihomo/component/trie"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
providerTypes "github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
snifferTypes "github.com/metacubex/mihomo/constant/sniffer" snifferTypes "github.com/metacubex/mihomo/constant/sniffer"
"github.com/metacubex/mihomo/dns" "github.com/metacubex/mihomo/dns"
L "github.com/metacubex/mihomo/listener" L "github.com/metacubex/mihomo/listener"
@ -199,8 +199,8 @@ type Config struct {
Users []auth.AuthUser Users []auth.AuthUser
Proxies map[string]C.Proxy Proxies map[string]C.Proxy
Listeners map[string]C.InboundListener Listeners map[string]C.InboundListener
Providers map[string]providerTypes.ProxyProvider Providers map[string]P.ProxyProvider
RuleProviders map[string]providerTypes.RuleProvider RuleProviders map[string]P.RuleProvider
Tunnels []LC.Tunnel Tunnels []LC.Tunnel
Sniffer *sniffer.Config Sniffer *sniffer.Config
TLS *TLS TLS *TLS
@ -845,9 +845,9 @@ func parseTLS(cfg *RawConfig) (*TLS, error) {
}, nil }, nil
} }
func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[string]providerTypes.ProxyProvider, err error) { func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[string]P.ProxyProvider, err error) {
proxies = make(map[string]C.Proxy) proxies = make(map[string]C.Proxy)
providersMap = make(map[string]providerTypes.ProxyProvider) providersMap = make(map[string]P.ProxyProvider)
proxiesConfig := cfg.Proxy proxiesConfig := cfg.Proxy
groupsConfig := cfg.ProxyGroup groupsConfig := cfg.ProxyGroup
providersConfig := cfg.ProxyProvider providersConfig := cfg.ProxyProvider
@ -947,7 +947,7 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
&outboundgroup.GroupCommonOption{ &outboundgroup.GroupCommonOption{
Name: "GLOBAL", Name: "GLOBAL",
}, },
[]providerTypes.ProxyProvider{pd}, []P.ProxyProvider{pd},
) )
proxies["GLOBAL"] = adapter.NewProxy(global) proxies["GLOBAL"] = adapter.NewProxy(global)
} }
@ -972,9 +972,9 @@ func parseListeners(cfg *RawConfig) (listeners map[string]C.InboundListener, err
return return
} }
func parseRuleProviders(cfg *RawConfig) (ruleProviders map[string]providerTypes.RuleProvider, err error) { func parseRuleProviders(cfg *RawConfig) (ruleProviders map[string]P.RuleProvider, err error) {
RP.SetTunnel(T.Tunnel) RP.SetTunnel(T.Tunnel)
ruleProviders = map[string]providerTypes.RuleProvider{} ruleProviders = map[string]P.RuleProvider{}
// parse rule provider // parse rule provider
for name, mapping := range cfg.RuleProvider { for name, mapping := range cfg.RuleProvider {
rp, err := RP.ParseRuleProvider(name, mapping, R.ParseRule) rp, err := RP.ParseRuleProvider(name, mapping, R.ParseRule)
@ -987,7 +987,7 @@ func parseRuleProviders(cfg *RawConfig) (ruleProviders map[string]providerTypes.
return return
} }
func parseSubRules(cfg *RawConfig, proxies map[string]C.Proxy, ruleProviders map[string]providerTypes.RuleProvider) (subRules map[string][]C.Rule, err error) { func parseSubRules(cfg *RawConfig, proxies map[string]C.Proxy, ruleProviders map[string]P.RuleProvider) (subRules map[string][]C.Rule, err error) {
subRules = map[string][]C.Rule{} subRules = map[string][]C.Rule{}
for name := range cfg.SubRules { for name := range cfg.SubRules {
subRules[name] = make([]C.Rule, 0) subRules[name] = make([]C.Rule, 0)
@ -1050,7 +1050,7 @@ func verifySubRuleCircularReferences(n string, subRules map[string][]C.Rule, arr
return nil return nil
} }
func parseRules(rulesConfig []string, proxies map[string]C.Proxy, ruleProviders map[string]providerTypes.RuleProvider, subRules map[string][]C.Rule, format string) ([]C.Rule, error) { func parseRules(rulesConfig []string, proxies map[string]C.Proxy, ruleProviders map[string]P.RuleProvider, subRules map[string][]C.Rule, format string) ([]C.Rule, error) {
var rules []C.Rule var rules []C.Rule
// parse rules // parse rules
@ -1273,7 +1273,7 @@ func parsePureDNSServer(server string) string {
} }
} }
func parseNameServerPolicy(nsPolicy *orderedmap.OrderedMap[string, any], ruleProviders map[string]providerTypes.RuleProvider, respectRules bool, preferH3 bool) ([]dns.Policy, error) { func parseNameServerPolicy(nsPolicy *orderedmap.OrderedMap[string, any], ruleProviders map[string]P.RuleProvider, respectRules bool, preferH3 bool) ([]dns.Policy, error) {
var policy []dns.Policy var policy []dns.Policy
for pair := nsPolicy.Oldest(); pair != nil; pair = pair.Next() { for pair := nsPolicy.Oldest(); pair != nil; pair = pair.Next() {
@ -1348,7 +1348,7 @@ func parseNameServerPolicy(nsPolicy *orderedmap.OrderedMap[string, any], rulePro
return policy, nil return policy, nil
} }
func parseDNS(rawCfg *RawConfig, ruleProviders map[string]providerTypes.RuleProvider) (*DNS, error) { func parseDNS(rawCfg *RawConfig, ruleProviders map[string]P.RuleProvider) (*DNS, error) {
cfg := rawCfg.DNS cfg := rawCfg.DNS
if cfg.Enable && len(cfg.NameServer) == 0 { if cfg.Enable && len(cfg.NameServer) == 0 {
return nil, fmt.Errorf("if DNS configuration is turned on, NameServer cannot be empty") return nil, fmt.Errorf("if DNS configuration is turned on, NameServer cannot be empty")
@ -1632,7 +1632,7 @@ func parseTuicServer(rawTuic RawTuicServer, general *General) error {
return nil return nil
} }
func parseSniffer(snifferRaw RawSniffer, ruleProviders map[string]providerTypes.RuleProvider) (*sniffer.Config, error) { func parseSniffer(snifferRaw RawSniffer, ruleProviders map[string]P.RuleProvider) (*sniffer.Config, error) {
snifferConfig := &sniffer.Config{ snifferConfig := &sniffer.Config{
Enable: snifferRaw.Enable, Enable: snifferRaw.Enable,
ForceDnsMapping: snifferRaw.ForceDnsMapping, ForceDnsMapping: snifferRaw.ForceDnsMapping,
@ -1722,7 +1722,7 @@ func parseSniffer(snifferRaw RawSniffer, ruleProviders map[string]providerTypes.
return snifferConfig, nil return snifferConfig, nil
} }
func parseIPCIDR(addresses []string, cidrSet *cidr.IpCidrSet, adapterName string, ruleProviders map[string]providerTypes.RuleProvider) (matchers []C.IpMatcher, err error) { func parseIPCIDR(addresses []string, cidrSet *cidr.IpCidrSet, adapterName string, ruleProviders map[string]P.RuleProvider) (matchers []C.IpMatcher, err error) {
var matcher C.IpMatcher var matcher C.IpMatcher
for _, ipcidr := range addresses { for _, ipcidr := range addresses {
ipcidrLower := strings.ToLower(ipcidr) ipcidrLower := strings.ToLower(ipcidr)
@ -1769,7 +1769,7 @@ func parseIPCIDR(addresses []string, cidrSet *cidr.IpCidrSet, adapterName string
return return
} }
func parseDomain(domains []string, domainTrie *trie.DomainTrie[struct{}], adapterName string, ruleProviders map[string]providerTypes.RuleProvider) (matchers []C.DomainMatcher, err error) { func parseDomain(domains []string, domainTrie *trie.DomainTrie[struct{}], adapterName string, ruleProviders map[string]P.RuleProvider) (matchers []C.DomainMatcher, err error) {
var matcher C.DomainMatcher var matcher C.DomainMatcher
for _, domain := range domains { for _, domain := range domains {
domainLower := strings.ToLower(domain) domainLower := strings.ToLower(domain)
@ -1812,14 +1812,14 @@ func parseDomain(domains []string, domainTrie *trie.DomainTrie[struct{}], adapte
return return
} }
func parseIPRuleSet(domainSetName string, adapterName string, ruleProviders map[string]providerTypes.RuleProvider) (C.IpMatcher, error) { func parseIPRuleSet(domainSetName string, adapterName string, ruleProviders map[string]P.RuleProvider) (C.IpMatcher, error) {
if rp, ok := ruleProviders[domainSetName]; !ok { if rp, ok := ruleProviders[domainSetName]; !ok {
return nil, fmt.Errorf("not found rule-set: %s", domainSetName) return nil, fmt.Errorf("not found rule-set: %s", domainSetName)
} else { } else {
switch rp.Behavior() { switch rp.Behavior() {
case providerTypes.Domain: case P.Domain:
return nil, fmt.Errorf("rule provider type error, except ipcidr,actual %s", rp.Behavior()) return nil, fmt.Errorf("rule provider type error, except ipcidr,actual %s", rp.Behavior())
case providerTypes.Classical: case P.Classical:
log.Warnln("%s provider is %s, only matching it contain ip rule", rp.Name(), rp.Behavior()) log.Warnln("%s provider is %s, only matching it contain ip rule", rp.Name(), rp.Behavior())
default: default:
} }
@ -1827,14 +1827,14 @@ func parseIPRuleSet(domainSetName string, adapterName string, ruleProviders map[
return RP.NewRuleSet(domainSetName, adapterName, false, true) return RP.NewRuleSet(domainSetName, adapterName, false, true)
} }
func parseDomainRuleSet(domainSetName string, adapterName string, ruleProviders map[string]providerTypes.RuleProvider) (C.DomainMatcher, error) { func parseDomainRuleSet(domainSetName string, adapterName string, ruleProviders map[string]P.RuleProvider) (C.DomainMatcher, error) {
if rp, ok := ruleProviders[domainSetName]; !ok { if rp, ok := ruleProviders[domainSetName]; !ok {
return nil, fmt.Errorf("not found rule-set: %s", domainSetName) return nil, fmt.Errorf("not found rule-set: %s", domainSetName)
} else { } else {
switch rp.Behavior() { switch rp.Behavior() {
case providerTypes.IPCIDR: case P.IPCIDR:
return nil, fmt.Errorf("rule provider type error, except domain,actual %s", rp.Behavior()) return nil, fmt.Errorf("rule provider type error, except domain,actual %s", rp.Behavior())
case providerTypes.Classical: case P.Classical:
log.Warnln("%s provider is %s, only matching it contain domain rule", rp.Name(), rp.Behavior()) log.Warnln("%s provider is %s, only matching it contain domain rule", rp.Name(), rp.Behavior())
default: default:
} }

View File

@ -31,7 +31,7 @@ import (
"github.com/metacubex/mihomo/component/updater" "github.com/metacubex/mihomo/component/updater"
"github.com/metacubex/mihomo/config" "github.com/metacubex/mihomo/config"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
"github.com/metacubex/mihomo/dns" "github.com/metacubex/mihomo/dns"
"github.com/metacubex/mihomo/listener" "github.com/metacubex/mihomo/listener"
authStore "github.com/metacubex/mihomo/listener/auth" authStore "github.com/metacubex/mihomo/listener/auth"
@ -303,18 +303,18 @@ func updateHosts(tree *trie.DomainTrie[resolver.HostValue]) {
resolver.DefaultHosts = resolver.NewHosts(tree) resolver.DefaultHosts = resolver.NewHosts(tree)
} }
func updateProxies(proxies map[string]C.Proxy, providers map[string]provider.ProxyProvider) { func updateProxies(proxies map[string]C.Proxy, providers map[string]P.ProxyProvider) {
tunnel.UpdateProxies(proxies, providers) tunnel.UpdateProxies(proxies, providers)
} }
func updateRules(rules []C.Rule, subRules map[string][]C.Rule, ruleProviders map[string]provider.RuleProvider) { func updateRules(rules []C.Rule, subRules map[string][]C.Rule, ruleProviders map[string]P.RuleProvider) {
tunnel.UpdateRules(rules, subRules, ruleProviders) tunnel.UpdateRules(rules, subRules, ruleProviders)
} }
func loadProvider[P provider.Provider](providers map[string]P) { func loadProvider[T P.Provider](providers map[string]T) {
load := func(pv P) { load := func(pv T) {
name := pv.Name() name := pv.Name()
if pv.VehicleType() == provider.Compatible { if pv.VehicleType() == P.Compatible {
log.Infoln("Start initial compatible provider %s", name) log.Infoln("Start initial compatible provider %s", name)
} else { } else {
log.Infoln("Start initial provider %s", name) log.Infoln("Start initial provider %s", name)
@ -322,11 +322,11 @@ func loadProvider[P provider.Provider](providers map[string]P) {
if err := pv.Initial(); err != nil { if err := pv.Initial(); err != nil {
switch pv.Type() { switch pv.Type() {
case provider.Proxy: case P.Proxy:
{ {
log.Errorln("initial proxy provider %s error: %v", name, err) log.Errorln("initial proxy provider %s error: %v", name, err)
} }
case provider.Rule: case P.Rule:
{ {
log.Errorln("initial rule provider %s error: %v", name, err) log.Errorln("initial rule provider %s error: %v", name, err)
} }

View File

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
"github.com/metacubex/mihomo/tunnel" "github.com/metacubex/mihomo/tunnel"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
@ -45,12 +45,12 @@ func getProviders(w http.ResponseWriter, r *http.Request) {
} }
func getProvider(w http.ResponseWriter, r *http.Request) { func getProvider(w http.ResponseWriter, r *http.Request) {
provider := r.Context().Value(CtxKeyProvider).(provider.ProxyProvider) provider := r.Context().Value(CtxKeyProvider).(P.ProxyProvider)
render.JSON(w, r, provider) render.JSON(w, r, provider)
} }
func updateProvider(w http.ResponseWriter, r *http.Request) { func updateProvider(w http.ResponseWriter, r *http.Request) {
provider := r.Context().Value(CtxKeyProvider).(provider.ProxyProvider) provider := r.Context().Value(CtxKeyProvider).(P.ProxyProvider)
if err := provider.Update(); err != nil { if err := provider.Update(); err != nil {
render.Status(r, http.StatusServiceUnavailable) render.Status(r, http.StatusServiceUnavailable)
render.JSON(w, r, newError(err.Error())) render.JSON(w, r, newError(err.Error()))
@ -60,7 +60,7 @@ func updateProvider(w http.ResponseWriter, r *http.Request) {
} }
func healthCheckProvider(w http.ResponseWriter, r *http.Request) { func healthCheckProvider(w http.ResponseWriter, r *http.Request) {
provider := r.Context().Value(CtxKeyProvider).(provider.ProxyProvider) provider := r.Context().Value(CtxKeyProvider).(P.ProxyProvider)
provider.HealthCheck() provider.HealthCheck()
render.NoContent(w, r) render.NoContent(w, r)
} }
@ -93,7 +93,7 @@ func findProviderProxyByName(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var ( var (
name = r.Context().Value(CtxKeyProxyName).(string) name = r.Context().Value(CtxKeyProxyName).(string)
pd = r.Context().Value(CtxKeyProvider).(provider.ProxyProvider) pd = r.Context().Value(CtxKeyProvider).(P.ProxyProvider)
) )
proxy, exist := lo.Find(pd.Proxies(), func(proxy C.Proxy) bool { proxy, exist := lo.Find(pd.Proxies(), func(proxy C.Proxy) bool {
return proxy.Name() == name return proxy.Name() == name
@ -128,7 +128,7 @@ func getRuleProviders(w http.ResponseWriter, r *http.Request) {
} }
func updateRuleProvider(w http.ResponseWriter, r *http.Request) { func updateRuleProvider(w http.ResponseWriter, r *http.Request) {
provider := r.Context().Value(CtxKeyProvider).(provider.RuleProvider) provider := r.Context().Value(CtxKeyProvider).(P.RuleProvider)
if err := provider.Update(); err != nil { if err := provider.Update(); err != nil {
render.Status(r, http.StatusServiceUnavailable) render.Status(r, http.StatusServiceUnavailable)
render.JSON(w, r, newError(err.Error())) render.JSON(w, r, newError(err.Error()))

View File

@ -18,7 +18,7 @@ import (
"github.com/metacubex/mihomo/component/iface" "github.com/metacubex/mihomo/component/iface"
"github.com/metacubex/mihomo/component/resolver" "github.com/metacubex/mihomo/component/resolver"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
LC "github.com/metacubex/mihomo/listener/config" LC "github.com/metacubex/mihomo/listener/config"
"github.com/metacubex/mihomo/listener/sing" "github.com/metacubex/mihomo/listener/sing"
"github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/log"
@ -133,7 +133,7 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
} }
} }
ctx := context.TODO() ctx := context.TODO()
rpTunnel := tunnel.(provider.Tunnel) rpTunnel := tunnel.(P.Tunnel)
if options.GSOMaxSize == 0 { if options.GSOMaxSize == 0 {
options.GSOMaxSize = 65536 options.GSOMaxSize = 65536
} }
@ -504,7 +504,7 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
return return
} }
func (l *Listener) ruleUpdateCallback(ruleProvider provider.RuleProvider) { func (l *Listener) ruleUpdateCallback(ruleProvider P.RuleProvider) {
name := ruleProvider.Name() name := ruleProvider.Name()
if slices.Contains(l.options.RouteAddressSet, name) { if slices.Contains(l.options.RouteAddressSet, name) {
l.updateRule(ruleProvider, false, true) l.updateRule(ruleProvider, false, true)
@ -520,7 +520,7 @@ type toIpCidr interface {
ToIpCidr() *netipx.IPSet ToIpCidr() *netipx.IPSet
} }
func (l *Listener) updateRule(ruleProvider provider.RuleProvider, exclude bool, update bool) { func (l *Listener) updateRule(ruleProvider P.RuleProvider, exclude bool, update bool) {
l.ruleUpdateMutex.Lock() l.ruleUpdateMutex.Lock()
defer l.ruleUpdateMutex.Unlock() defer l.ruleUpdateMutex.Unlock()
name := ruleProvider.Name() name := ruleProvider.Name()

View File

@ -23,7 +23,7 @@ import (
"github.com/metacubex/mihomo/component/sniffer" "github.com/metacubex/mihomo/component/sniffer"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/features" "github.com/metacubex/mihomo/constant/features"
"github.com/metacubex/mihomo/constant/provider" P "github.com/metacubex/mihomo/constant/provider"
icontext "github.com/metacubex/mihomo/context" icontext "github.com/metacubex/mihomo/context"
"github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/log"
"github.com/metacubex/mihomo/tunnel/statistic" "github.com/metacubex/mihomo/tunnel/statistic"
@ -43,8 +43,8 @@ var (
listeners = make(map[string]C.InboundListener) listeners = make(map[string]C.InboundListener)
subRules map[string][]C.Rule subRules map[string][]C.Rule
proxies = make(map[string]C.Proxy) proxies = make(map[string]C.Proxy)
providers map[string]provider.ProxyProvider providers map[string]P.ProxyProvider
ruleProviders map[string]provider.RuleProvider ruleProviders map[string]P.RuleProvider
configMux sync.RWMutex configMux sync.RWMutex
// for compatibility, lazy init // for compatibility, lazy init
@ -64,14 +64,14 @@ var (
snifferDispatcher *sniffer.Dispatcher snifferDispatcher *sniffer.Dispatcher
sniffingEnable = false sniffingEnable = false
ruleUpdateCallback = utils.NewCallback[provider.RuleProvider]() ruleUpdateCallback = utils.NewCallback[P.RuleProvider]()
) )
type tunnel struct{} type tunnel struct{}
var Tunnel = tunnel{} var Tunnel = tunnel{}
var _ C.Tunnel = Tunnel var _ C.Tunnel = Tunnel
var _ provider.Tunnel = Tunnel var _ P.Tunnel = Tunnel
func (t tunnel) HandleTCPConn(conn net.Conn, metadata *C.Metadata) { func (t tunnel) HandleTCPConn(conn net.Conn, metadata *C.Metadata) {
connCtx := icontext.NewConnContext(conn, metadata) connCtx := icontext.NewConnContext(conn, metadata)
@ -112,15 +112,15 @@ func (t tunnel) NatTable() C.NatTable {
return natTable return natTable
} }
func (t tunnel) Providers() map[string]provider.ProxyProvider { func (t tunnel) Providers() map[string]P.ProxyProvider {
return providers return providers
} }
func (t tunnel) RuleProviders() map[string]provider.RuleProvider { func (t tunnel) RuleProviders() map[string]P.RuleProvider {
return ruleProviders return ruleProviders
} }
func (t tunnel) RuleUpdateCallback() *utils.Callback[provider.RuleProvider] { func (t tunnel) RuleUpdateCallback() *utils.Callback[P.RuleProvider] {
return ruleUpdateCallback return ruleUpdateCallback
} }
@ -195,7 +195,7 @@ func Listeners() map[string]C.InboundListener {
} }
// UpdateRules handle update rules // UpdateRules handle update rules
func UpdateRules(newRules []C.Rule, newSubRule map[string][]C.Rule, rp map[string]provider.RuleProvider) { func UpdateRules(newRules []C.Rule, newSubRule map[string][]C.Rule, rp map[string]P.RuleProvider) {
configMux.Lock() configMux.Lock()
rules = newRules rules = newRules
ruleProviders = rp ruleProviders = rp
@ -223,17 +223,17 @@ func ProxiesWithProviders() map[string]C.Proxy {
} }
// Providers return all compatible providers // Providers return all compatible providers
func Providers() map[string]provider.ProxyProvider { func Providers() map[string]P.ProxyProvider {
return providers return providers
} }
// RuleProviders return all loaded rule providers // RuleProviders return all loaded rule providers
func RuleProviders() map[string]provider.RuleProvider { func RuleProviders() map[string]P.RuleProvider {
return ruleProviders return ruleProviders
} }
// UpdateProxies handle update proxies // UpdateProxies handle update proxies
func UpdateProxies(newProxies map[string]C.Proxy, newProviders map[string]provider.ProxyProvider) { func UpdateProxies(newProxies map[string]C.Proxy, newProviders map[string]P.ProxyProvider) {
configMux.Lock() configMux.Lock()
proxies = newProxies proxies = newProxies
providers = newProviders providers = newProviders