2021-07-04 20:32:59 +08:00
|
|
|
package provider
|
|
|
|
|
|
|
|
import (
|
2023-11-03 21:01:45 +08:00
|
|
|
"github.com/metacubex/mihomo/common/utils"
|
|
|
|
"github.com/metacubex/mihomo/constant"
|
2021-07-04 20:32:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Vehicle Type
|
|
|
|
const (
|
|
|
|
File VehicleType = iota
|
|
|
|
HTTP
|
|
|
|
Compatible
|
|
|
|
)
|
|
|
|
|
|
|
|
// VehicleType defined
|
|
|
|
type VehicleType int
|
|
|
|
|
|
|
|
func (v VehicleType) String() string {
|
|
|
|
switch v {
|
|
|
|
case File:
|
|
|
|
return "File"
|
|
|
|
case HTTP:
|
|
|
|
return "HTTP"
|
|
|
|
case Compatible:
|
|
|
|
return "Compatible"
|
|
|
|
default:
|
|
|
|
return "Unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Vehicle interface {
|
|
|
|
Read() ([]byte, error)
|
|
|
|
Path() string
|
|
|
|
Type() VehicleType
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provider Type
|
|
|
|
const (
|
|
|
|
Proxy ProviderType = iota
|
|
|
|
Rule
|
|
|
|
)
|
|
|
|
|
|
|
|
// ProviderType defined
|
|
|
|
type ProviderType int
|
|
|
|
|
|
|
|
func (pt ProviderType) String() string {
|
|
|
|
switch pt {
|
|
|
|
case Proxy:
|
|
|
|
return "Proxy"
|
|
|
|
case Rule:
|
|
|
|
return "Rule"
|
|
|
|
default:
|
|
|
|
return "Unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provider interface
|
|
|
|
type Provider interface {
|
|
|
|
Name() string
|
|
|
|
VehicleType() VehicleType
|
|
|
|
Type() ProviderType
|
|
|
|
Initial() error
|
|
|
|
Update() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProxyProvider interface
|
|
|
|
type ProxyProvider interface {
|
|
|
|
Provider
|
|
|
|
Proxies() []constant.Proxy
|
2022-11-04 13:11:01 +08:00
|
|
|
// Touch is used to inform the provider that the proxy is actually being used while getting the list of proxies.
|
2021-10-15 21:44:53 +08:00
|
|
|
// Commonly used in DialContext and DialPacketConn
|
2022-06-07 17:19:25 +08:00
|
|
|
Touch()
|
2021-07-04 20:32:59 +08:00
|
|
|
HealthCheck()
|
2022-07-20 08:53:54 +08:00
|
|
|
Version() uint32
|
2023-06-04 11:51:30 +08:00
|
|
|
RegisterHealthCheckTask(url string, expectedStatus utils.IntRanges[uint16], filter string, interval uint)
|
2024-02-24 14:52:42 +08:00
|
|
|
HealthCheckURL() string
|
2021-07-04 20:32:59 +08:00
|
|
|
}
|
|
|
|
|
2023-04-14 13:51:26 +08:00
|
|
|
// RuleProvider interface
|
|
|
|
type RuleProvider interface {
|
|
|
|
Provider
|
|
|
|
Behavior() RuleBehavior
|
|
|
|
Match(*constant.Metadata) bool
|
|
|
|
ShouldResolveIP() bool
|
|
|
|
ShouldFindProcess() bool
|
|
|
|
AsRule(adaptor string) constant.Rule
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rule Behavior
|
2021-07-04 20:32:59 +08:00
|
|
|
const (
|
2023-04-14 13:51:26 +08:00
|
|
|
Domain RuleBehavior = iota
|
2021-07-04 20:32:59 +08:00
|
|
|
IPCIDR
|
|
|
|
Classical
|
|
|
|
)
|
|
|
|
|
2023-04-14 13:51:26 +08:00
|
|
|
// RuleBehavior defined
|
|
|
|
type RuleBehavior int
|
2021-07-04 20:32:59 +08:00
|
|
|
|
2023-04-14 13:51:26 +08:00
|
|
|
func (rt RuleBehavior) String() string {
|
2021-07-04 20:32:59 +08:00
|
|
|
switch rt {
|
|
|
|
case Domain:
|
|
|
|
return "Domain"
|
|
|
|
case IPCIDR:
|
|
|
|
return "IPCIDR"
|
|
|
|
case Classical:
|
|
|
|
return "Classical"
|
|
|
|
default:
|
|
|
|
return "Unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-14 13:51:26 +08:00
|
|
|
const (
|
|
|
|
YamlRule RuleFormat = iota
|
|
|
|
TextRule
|
|
|
|
)
|
|
|
|
|
|
|
|
type RuleFormat int
|
|
|
|
|
|
|
|
func (rf RuleFormat) String() string {
|
|
|
|
switch rf {
|
|
|
|
case YamlRule:
|
|
|
|
return "YamlRule"
|
|
|
|
case TextRule:
|
|
|
|
return "TextRule"
|
|
|
|
default:
|
|
|
|
return "Unknown"
|
|
|
|
}
|
2021-07-04 20:32:59 +08:00
|
|
|
}
|