mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-04 12:57:31 +00:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
644c04fdc9 | ||
|
|
926aaec717 | ||
|
|
a4b76809ac | ||
|
|
ff76576cbe | ||
|
|
1d5890abc1 | ||
|
|
a3c023ae3e | ||
|
|
8b32c4371e | ||
|
|
5a285acd32 | ||
|
|
c2209d68f7 | ||
|
|
fd39c2a7fc | ||
|
|
421dc79aea | ||
|
|
27b47f976c | ||
|
|
c25a38898f | ||
|
|
f3edbc2b45 | ||
|
|
6fb1f796a5 | ||
|
|
99e68e9983 | ||
|
|
6bffbdd9d3 | ||
|
|
cfdaebe952 | ||
|
|
c8af92a01f | ||
|
|
ff62386f6b | ||
|
|
85c56e7446 | ||
|
|
9ed9c3d1c3 | ||
|
|
dcfe664a7d | ||
|
|
fb1ae21fb7 | ||
|
|
90f47a6d0c | ||
|
|
f2bf4a077e | ||
|
|
8701639347 | ||
|
|
5bc0ac7281 |
@@ -4,9 +4,9 @@ RUN echo "I'm building for $TARGETPLATFORM"
|
|||||||
|
|
||||||
RUN apk add --no-cache gzip && \
|
RUN apk add --no-cache gzip && \
|
||||||
mkdir /mihomo-config && \
|
mkdir /mihomo-config && \
|
||||||
wget -O /mihomo-config/geoip.metadb https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.metadb && \
|
wget -O /mihomo-config/geoip.metadb https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb && \
|
||||||
wget -O /mihomo-config/geosite.dat https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite.dat && \
|
wget -O /mihomo-config/geosite.dat https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat && \
|
||||||
wget -O /mihomo-config/geoip.dat https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.dat
|
wget -O /mihomo-config/geoip.dat https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat
|
||||||
|
|
||||||
COPY docker/file-name.sh /mihomo/file-name.sh
|
COPY docker/file-name.sh /mihomo/file-name.sh
|
||||||
WORKDIR /mihomo
|
WORKDIR /mihomo
|
||||||
|
|||||||
@@ -51,26 +51,12 @@ func (p *Proxy) AliveForTestUrl(url string) bool {
|
|||||||
return p.alive.Load()
|
return p.alive.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dial implements C.Proxy
|
|
||||||
func (p *Proxy) Dial(metadata *C.Metadata) (C.Conn, error) {
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTCPTimeout)
|
|
||||||
defer cancel()
|
|
||||||
return p.DialContext(ctx, metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DialContext implements C.ProxyAdapter
|
// DialContext implements C.ProxyAdapter
|
||||||
func (p *Proxy) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
|
func (p *Proxy) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
|
||||||
conn, err := p.ProxyAdapter.DialContext(ctx, metadata)
|
conn, err := p.ProxyAdapter.DialContext(ctx, metadata)
|
||||||
return conn, err
|
return conn, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialUDP implements C.ProxyAdapter
|
|
||||||
func (p *Proxy) DialUDP(metadata *C.Metadata) (C.PacketConn, error) {
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultUDPTimeout)
|
|
||||||
defer cancel()
|
|
||||||
return p.ListenPacketContext(ctx, metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListenPacketContext implements C.ProxyAdapter
|
// ListenPacketContext implements C.ProxyAdapter
|
||||||
func (p *Proxy) ListenPacketContext(ctx context.Context, metadata *C.Metadata) (C.PacketConn, error) {
|
func (p *Proxy) ListenPacketContext(ctx context.Context, metadata *C.Metadata) (C.PacketConn, error) {
|
||||||
pc, err := p.ProxyAdapter.ListenPacketContext(ctx, metadata)
|
pc, err := p.ProxyAdapter.ListenPacketContext(ctx, metadata)
|
||||||
|
|||||||
@@ -263,7 +263,9 @@ func NewConn(c net.Conn, a C.ProxyAdapter) C.Conn {
|
|||||||
if _, ok := c.(syscall.Conn); !ok { // exclusion system conn like *net.TCPConn
|
if _, ok := c.(syscall.Conn); !ok { // exclusion system conn like *net.TCPConn
|
||||||
c = N.NewDeadlineConn(c) // most conn from outbound can't handle readDeadline correctly
|
c = N.NewDeadlineConn(c) // most conn from outbound can't handle readDeadline correctly
|
||||||
}
|
}
|
||||||
return &conn{N.NewExtendedConn(c), []string{a.Name()}, a.Addr()}
|
cc := &conn{N.NewExtendedConn(c), nil, a.Addr()}
|
||||||
|
cc.AppendToChains(a)
|
||||||
|
return cc
|
||||||
}
|
}
|
||||||
|
|
||||||
type packetConn struct {
|
type packetConn struct {
|
||||||
@@ -320,7 +322,9 @@ func newPacketConn(pc net.PacketConn, a ProxyAdapter) C.PacketConn {
|
|||||||
if _, ok := pc.(syscall.Conn); !ok { // exclusion system conn like *net.UDPConn
|
if _, ok := pc.(syscall.Conn); !ok { // exclusion system conn like *net.UDPConn
|
||||||
epc = N.NewDeadlineEnhancePacketConn(epc) // most conn from outbound can't handle readDeadline correctly
|
epc = N.NewDeadlineEnhancePacketConn(epc) // most conn from outbound can't handle readDeadline correctly
|
||||||
}
|
}
|
||||||
return &packetConn{epc, []string{a.Name()}, a.Name(), utils.NewUUIDV4().String(), a.Addr(), a.ResolveUDP}
|
cpc := &packetConn{epc, nil, a.Name(), utils.NewUUIDV4().String(), a.Addr(), a.ResolveUDP}
|
||||||
|
cpc.AppendToChains(a)
|
||||||
|
return cpc
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddRef interface {
|
type AddRef interface {
|
||||||
|
|||||||
@@ -252,13 +252,14 @@ func (spc *ssrPacketConn) WaitReadFrom() (data []byte, put func(), addr net.Addr
|
|||||||
return nil, nil, nil, errors.New("parse addr error")
|
return nil, nil, nil, errors.New("parse addr error")
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = _addr.UDPAddr()
|
udpAddr := _addr.UDPAddr()
|
||||||
if addr == nil {
|
if udpAddr == nil {
|
||||||
if put != nil {
|
if put != nil {
|
||||||
put()
|
put()
|
||||||
}
|
}
|
||||||
return nil, nil, nil, errors.New("parse addr error")
|
return nil, nil, nil, errors.New("parse addr error")
|
||||||
}
|
}
|
||||||
|
addr = udpAddr
|
||||||
|
|
||||||
data = data[len(_addr):]
|
data = data[len(_addr):]
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
)
|
)
|
||||||
@@ -194,7 +194,7 @@ func strategyStickySessions(url string) strategyFn {
|
|||||||
key := utils.MapHash(getKeyWithSrcAndDst(metadata))
|
key := utils.MapHash(getKeyWithSrcAndDst(metadata))
|
||||||
length := len(proxies)
|
length := len(proxies)
|
||||||
idx, has := lruCache.Get(key)
|
idx, has := lruCache.Get(key)
|
||||||
if !has {
|
if !has || idx >= length {
|
||||||
idx = int(jumpHash(key+uint64(time.Now().UnixNano()), int32(length)))
|
idx = int(jumpHash(key+uint64(time.Now().UnixNano()), int32(length)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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":
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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{
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -49,13 +49,7 @@ func ParseProxy(mapping map[string]any) (C.Proxy, error) {
|
|||||||
}
|
}
|
||||||
proxy, err = outbound.NewHttp(*httpOption)
|
proxy, err = outbound.NewHttp(*httpOption)
|
||||||
case "vmess":
|
case "vmess":
|
||||||
vmessOption := &outbound.VmessOption{
|
vmessOption := &outbound.VmessOption{}
|
||||||
HTTPOpts: outbound.HTTPOptions{
|
|
||||||
Method: "GET",
|
|
||||||
Path: []string{"/"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
err = decoder.Decode(mapping, vmessOption)
|
err = decoder.Decode(mapping, vmessOption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -138,3 +138,5 @@ func escape[T any](x T) T {
|
|||||||
// ptrSize is the size of a pointer in bytes - unsafe.Sizeof(uintptr(0)) but as an ideal constant.
|
// ptrSize is the size of a pointer in bytes - unsafe.Sizeof(uintptr(0)) but as an ideal constant.
|
||||||
// It is also the size of the machine's native word size (that is, 4 on 32-bit systems, 8 on 64-bit).
|
// It is also the size of the machine's native word size (that is, 4 on 32-bit systems, 8 on 64-bit).
|
||||||
const ptrSize = 4 << (^uintptr(0) >> 63)
|
const ptrSize = 4 << (^uintptr(0) >> 63)
|
||||||
|
|
||||||
|
const testComparableAllocations = false
|
||||||
|
|||||||
@@ -11,3 +11,5 @@ func Comparable[T comparable](seed Seed, v T) uint64 {
|
|||||||
func WriteComparable[T comparable](h *Hash, x T) {
|
func WriteComparable[T comparable](h *Hash, x T) {
|
||||||
maphash.WriteComparable(h, x)
|
maphash.WriteComparable(h, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const testComparableAllocations = true
|
||||||
|
|||||||
@@ -423,7 +423,9 @@ func TestWriteComparableNoncommute(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestComparableAllocations(t *testing.T) {
|
func TestComparableAllocations(t *testing.T) {
|
||||||
t.Skip("test broken in old golang version")
|
if !testComparableAllocations {
|
||||||
|
t.Skip("test broken in old golang version")
|
||||||
|
}
|
||||||
seed := MakeSeed()
|
seed := MakeSeed()
|
||||||
x := heapStr(t)
|
x := heapStr(t)
|
||||||
allocs := testing.AllocsPerRun(10, func() {
|
allocs := testing.AllocsPerRun(10, func() {
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ var WriteBuffer = bufio.WriteBuffer
|
|||||||
type ReadWaitOptions = network.ReadWaitOptions
|
type ReadWaitOptions = network.ReadWaitOptions
|
||||||
|
|
||||||
var NewReadWaitOptions = network.NewReadWaitOptions
|
var NewReadWaitOptions = network.NewReadWaitOptions
|
||||||
|
var CalculateFrontHeadroom = network.CalculateFrontHeadroom
|
||||||
|
var CalculateRearHeadroom = network.CalculateRearHeadroom
|
||||||
|
|
||||||
type ReaderWithUpstream = network.ReaderWithUpstream
|
type ReaderWithUpstream = network.ReaderWithUpstream
|
||||||
type WithUpstreamReader = network.WithUpstreamReader
|
type WithUpstreamReader = network.WithUpstreamReader
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ func (d *Decoder) Decode(src map[string]any, dst any) error {
|
|||||||
key, omitKey, found := strings.Cut(tag, ",")
|
key, omitKey, found := strings.Cut(tag, ",")
|
||||||
omitempty := found && omitKey == "omitempty"
|
omitempty := found && omitKey == "omitempty"
|
||||||
|
|
||||||
|
// As a special case, if the field tag is "-", the field is always omitted.
|
||||||
|
// Note that a field with name "-" can still be generated using the tag "-,".
|
||||||
|
if key == "-" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
value, ok := src[key]
|
value, ok := src[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
if d.option.KeyReplacer != nil {
|
if d.option.KeyReplacer != nil {
|
||||||
|
|||||||
@@ -288,3 +288,23 @@ func TestStructure_Null(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, s.Opt.Bar, "")
|
assert.Equal(t, s.Opt.Bar, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStructure_Ignore(t *testing.T) {
|
||||||
|
rawMap := map[string]any{
|
||||||
|
"-": "newData",
|
||||||
|
}
|
||||||
|
|
||||||
|
s := struct {
|
||||||
|
MustIgnore string `test:"-"`
|
||||||
|
}{MustIgnore: "oldData"}
|
||||||
|
|
||||||
|
err := decoder.Decode(rawMap, &s)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, s.MustIgnore, "oldData")
|
||||||
|
|
||||||
|
// test omitempty
|
||||||
|
delete(rawMap, "-")
|
||||||
|
err = decoder.Decode(rawMap, &s)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, s.MustIgnore, "oldData")
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ func (c *cachefileStore) FlushFakeIP() error {
|
|||||||
return c.cache.FlushFakeIP()
|
return c.cache.FlushFakeIP()
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCachefileStore(cache *cachefile.CacheFile) *cachefileStore {
|
func newCachefileStore(cache *cachefile.CacheFile, prefix netip.Prefix) *cachefileStore {
|
||||||
return &cachefileStore{cache.FakeIpStore()}
|
if prefix.Addr().Is6() {
|
||||||
|
return &cachefileStore{cache.FakeIpStore6()}
|
||||||
|
} else {
|
||||||
|
return &cachefileStore{cache.FakeIpStore()}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/component/profile/cachefile"
|
"github.com/metacubex/mihomo/component/profile/cachefile"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
|
||||||
|
|
||||||
"go4.org/netipx"
|
"go4.org/netipx"
|
||||||
)
|
)
|
||||||
@@ -36,8 +35,6 @@ type Pool struct {
|
|||||||
offset netip.Addr
|
offset netip.Addr
|
||||||
cycle bool
|
cycle bool
|
||||||
mux sync.Mutex
|
mux sync.Mutex
|
||||||
host []C.DomainMatcher
|
|
||||||
mode C.FilterMode
|
|
||||||
ipnet netip.Prefix
|
ipnet netip.Prefix
|
||||||
store store
|
store store
|
||||||
}
|
}
|
||||||
@@ -66,24 +63,6 @@ func (p *Pool) LookBack(ip netip.Addr) (string, bool) {
|
|||||||
return p.store.GetByIP(ip)
|
return p.store.GetByIP(ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShouldSkipped return if domain should be skipped
|
|
||||||
func (p *Pool) ShouldSkipped(domain string) bool {
|
|
||||||
should := p.shouldSkipped(domain)
|
|
||||||
if p.mode == C.FilterWhiteList {
|
|
||||||
return !should
|
|
||||||
}
|
|
||||||
return should
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pool) shouldSkipped(domain string) bool {
|
|
||||||
for _, matcher := range p.host {
|
|
||||||
if matcher.MatchDomain(domain) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exist returns if given ip exists in fake-ip pool
|
// Exist returns if given ip exists in fake-ip pool
|
||||||
func (p *Pool) Exist(ip netip.Addr) bool {
|
func (p *Pool) Exist(ip netip.Addr) bool {
|
||||||
p.mux.Lock()
|
p.mux.Lock()
|
||||||
@@ -166,8 +145,6 @@ func (p *Pool) restoreState() {
|
|||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
IPNet netip.Prefix
|
IPNet netip.Prefix
|
||||||
Host []C.DomainMatcher
|
|
||||||
Mode C.FilterMode
|
|
||||||
|
|
||||||
// Size sets the maximum number of entries in memory
|
// Size sets the maximum number of entries in memory
|
||||||
// and does not work if Persistence is true
|
// and does not work if Persistence is true
|
||||||
@@ -197,12 +174,10 @@ func New(options Options) (*Pool, error) {
|
|||||||
last: last,
|
last: last,
|
||||||
offset: first.Prev(),
|
offset: first.Prev(),
|
||||||
cycle: false,
|
cycle: false,
|
||||||
host: options.Host,
|
|
||||||
mode: options.Mode,
|
|
||||||
ipnet: options.IPNet,
|
ipnet: options.IPNet,
|
||||||
}
|
}
|
||||||
if options.Persistence {
|
if options.Persistence {
|
||||||
pool.store = newCachefileStore(cachefile.Cache())
|
pool.store = newCachefileStore(cachefile.Cache(), options.IPNet)
|
||||||
} else {
|
} else {
|
||||||
pool.store = newMemoryStore(options.Size)
|
pool.store = newMemoryStore(options.Size)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/component/profile/cachefile"
|
"github.com/metacubex/mihomo/component/profile/cachefile"
|
||||||
"github.com/metacubex/mihomo/component/trie"
|
|
||||||
C "github.com/metacubex/mihomo/constant"
|
|
||||||
|
|
||||||
"github.com/metacubex/bbolt"
|
"github.com/metacubex/bbolt"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -43,7 +41,7 @@ func createCachefileStore(options Options) (*Pool, string, error) {
|
|||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
pool.store = newCachefileStore(&cachefile.CacheFile{DB: db})
|
pool.store = newCachefileStore(&cachefile.CacheFile{DB: db}, options.IPNet)
|
||||||
return pool, f.Name(), nil
|
return pool, f.Name(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,47 +144,6 @@ func TestPool_CycleUsed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPool_Skip(t *testing.T) {
|
|
||||||
ipnet := netip.MustParsePrefix("192.168.0.1/29")
|
|
||||||
tree := trie.New[struct{}]()
|
|
||||||
assert.NoError(t, tree.Insert("example.com", struct{}{}))
|
|
||||||
assert.False(t, tree.IsEmpty())
|
|
||||||
pools, tempfile, err := createPools(Options{
|
|
||||||
IPNet: ipnet,
|
|
||||||
Size: 10,
|
|
||||||
Host: []C.DomainMatcher{tree.NewDomainSet()},
|
|
||||||
})
|
|
||||||
assert.Nil(t, err)
|
|
||||||
defer os.Remove(tempfile)
|
|
||||||
|
|
||||||
for _, pool := range pools {
|
|
||||||
assert.True(t, pool.ShouldSkipped("example.com"))
|
|
||||||
assert.False(t, pool.ShouldSkipped("foo.com"))
|
|
||||||
assert.False(t, pool.shouldSkipped("baz.com"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPool_SkipWhiteList(t *testing.T) {
|
|
||||||
ipnet := netip.MustParsePrefix("192.168.0.1/29")
|
|
||||||
tree := trie.New[struct{}]()
|
|
||||||
assert.NoError(t, tree.Insert("example.com", struct{}{}))
|
|
||||||
assert.False(t, tree.IsEmpty())
|
|
||||||
pools, tempfile, err := createPools(Options{
|
|
||||||
IPNet: ipnet,
|
|
||||||
Size: 10,
|
|
||||||
Host: []C.DomainMatcher{tree.NewDomainSet()},
|
|
||||||
Mode: C.FilterWhiteList,
|
|
||||||
})
|
|
||||||
assert.Nil(t, err)
|
|
||||||
defer os.Remove(tempfile)
|
|
||||||
|
|
||||||
for _, pool := range pools {
|
|
||||||
assert.False(t, pool.ShouldSkipped("example.com"))
|
|
||||||
assert.True(t, pool.ShouldSkipped("foo.com"))
|
|
||||||
assert.True(t, pool.ShouldSkipped("baz.com"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPool_MaxCacheSize(t *testing.T) {
|
func TestPool_MaxCacheSize(t *testing.T) {
|
||||||
ipnet := netip.MustParsePrefix("192.168.0.1/24")
|
ipnet := netip.MustParsePrefix("192.168.0.1/24")
|
||||||
pool, _ := New(Options{
|
pool, _ := New(Options{
|
||||||
|
|||||||
28
component/fakeip/skipper.go
Normal file
28
component/fakeip/skipper.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package fakeip
|
||||||
|
|
||||||
|
import (
|
||||||
|
C "github.com/metacubex/mihomo/constant"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Skipper struct {
|
||||||
|
Host []C.DomainMatcher
|
||||||
|
Mode C.FilterMode
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShouldSkipped return if domain should be skipped
|
||||||
|
func (p *Skipper) ShouldSkipped(domain string) bool {
|
||||||
|
should := p.shouldSkipped(domain)
|
||||||
|
if p.Mode == C.FilterWhiteList {
|
||||||
|
return !should
|
||||||
|
}
|
||||||
|
return should
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Skipper) shouldSkipped(domain string) bool {
|
||||||
|
for _, matcher := range p.Host {
|
||||||
|
if matcher.MatchDomain(domain) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
35
component/fakeip/skipper_test.go
Normal file
35
component/fakeip/skipper_test.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package fakeip
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/metacubex/mihomo/component/trie"
|
||||||
|
C "github.com/metacubex/mihomo/constant"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSkipper_BlackList(t *testing.T) {
|
||||||
|
tree := trie.New[struct{}]()
|
||||||
|
assert.NoError(t, tree.Insert("example.com", struct{}{}))
|
||||||
|
assert.False(t, tree.IsEmpty())
|
||||||
|
skipper := &Skipper{
|
||||||
|
Host: []C.DomainMatcher{tree.NewDomainSet()},
|
||||||
|
}
|
||||||
|
assert.True(t, skipper.ShouldSkipped("example.com"))
|
||||||
|
assert.False(t, skipper.ShouldSkipped("foo.com"))
|
||||||
|
assert.False(t, skipper.shouldSkipped("baz.com"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSkipper_WhiteList(t *testing.T) {
|
||||||
|
tree := trie.New[struct{}]()
|
||||||
|
assert.NoError(t, tree.Insert("example.com", struct{}{}))
|
||||||
|
assert.False(t, tree.IsEmpty())
|
||||||
|
skipper := &Skipper{
|
||||||
|
Host: []C.DomainMatcher{tree.NewDomainSet()},
|
||||||
|
Mode: C.FilterWhiteList,
|
||||||
|
}
|
||||||
|
assert.False(t, skipper.ShouldSkipped("example.com"))
|
||||||
|
assert.True(t, skipper.ShouldSkipped("foo.com"))
|
||||||
|
assert.True(t, skipper.ShouldSkipped("baz.com"))
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ var (
|
|||||||
|
|
||||||
bucketSelected = []byte("selected")
|
bucketSelected = []byte("selected")
|
||||||
bucketFakeip = []byte("fakeip")
|
bucketFakeip = []byte("fakeip")
|
||||||
|
bucketFakeip6 = []byte("fakeip6")
|
||||||
bucketETag = []byte("etag")
|
bucketETag = []byte("etag")
|
||||||
bucketSubscriptionInfo = []byte("subscriptioninfo")
|
bucketSubscriptionInfo = []byte("subscriptioninfo")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,10 +10,15 @@ import (
|
|||||||
|
|
||||||
type FakeIpStore struct {
|
type FakeIpStore struct {
|
||||||
*CacheFile
|
*CacheFile
|
||||||
|
bucketName []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CacheFile) FakeIpStore() *FakeIpStore {
|
func (c *CacheFile) FakeIpStore() *FakeIpStore {
|
||||||
return &FakeIpStore{c}
|
return &FakeIpStore{c, bucketFakeip}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CacheFile) FakeIpStore6() *FakeIpStore {
|
||||||
|
return &FakeIpStore{c, bucketFakeip6}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeIpStore) GetByHost(host string) (ip netip.Addr, exist bool) {
|
func (c *FakeIpStore) GetByHost(host string) (ip netip.Addr, exist bool) {
|
||||||
@@ -21,7 +26,7 @@ func (c *FakeIpStore) GetByHost(host string) (ip netip.Addr, exist bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.DB.View(func(t *bbolt.Tx) error {
|
c.DB.View(func(t *bbolt.Tx) error {
|
||||||
if bucket := t.Bucket(bucketFakeip); bucket != nil {
|
if bucket := t.Bucket(c.bucketName); bucket != nil {
|
||||||
if v := bucket.Get([]byte(host)); v != nil {
|
if v := bucket.Get([]byte(host)); v != nil {
|
||||||
ip, exist = netip.AddrFromSlice(v)
|
ip, exist = netip.AddrFromSlice(v)
|
||||||
}
|
}
|
||||||
@@ -36,7 +41,7 @@ func (c *FakeIpStore) PutByHost(host string, ip netip.Addr) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := c.DB.Batch(func(t *bbolt.Tx) error {
|
err := c.DB.Batch(func(t *bbolt.Tx) error {
|
||||||
bucket, err := t.CreateBucketIfNotExists(bucketFakeip)
|
bucket, err := t.CreateBucketIfNotExists(c.bucketName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -52,7 +57,7 @@ func (c *FakeIpStore) GetByIP(ip netip.Addr) (host string, exist bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.DB.View(func(t *bbolt.Tx) error {
|
c.DB.View(func(t *bbolt.Tx) error {
|
||||||
if bucket := t.Bucket(bucketFakeip); bucket != nil {
|
if bucket := t.Bucket(c.bucketName); bucket != nil {
|
||||||
if v := bucket.Get(ip.AsSlice()); v != nil {
|
if v := bucket.Get(ip.AsSlice()); v != nil {
|
||||||
host, exist = string(v), true
|
host, exist = string(v), true
|
||||||
}
|
}
|
||||||
@@ -67,7 +72,7 @@ func (c *FakeIpStore) PutByIP(ip netip.Addr, host string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := c.DB.Batch(func(t *bbolt.Tx) error {
|
err := c.DB.Batch(func(t *bbolt.Tx) error {
|
||||||
bucket, err := t.CreateBucketIfNotExists(bucketFakeip)
|
bucket, err := t.CreateBucketIfNotExists(c.bucketName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -85,7 +90,7 @@ func (c *FakeIpStore) DelByIP(ip netip.Addr) {
|
|||||||
|
|
||||||
addr := ip.AsSlice()
|
addr := ip.AsSlice()
|
||||||
err := c.DB.Batch(func(t *bbolt.Tx) error {
|
err := c.DB.Batch(func(t *bbolt.Tx) error {
|
||||||
bucket, err := t.CreateBucketIfNotExists(bucketFakeip)
|
bucket, err := t.CreateBucketIfNotExists(c.bucketName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -105,11 +110,11 @@ func (c *FakeIpStore) DelByIP(ip netip.Addr) {
|
|||||||
|
|
||||||
func (c *FakeIpStore) FlushFakeIP() error {
|
func (c *FakeIpStore) FlushFakeIP() error {
|
||||||
err := c.DB.Batch(func(t *bbolt.Tx) error {
|
err := c.DB.Batch(func(t *bbolt.Tx) error {
|
||||||
bucket := t.Bucket(bucketFakeip)
|
bucket := t.Bucket(c.bucketName)
|
||||||
if bucket == nil {
|
if bucket == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return t.DeleteBucket(bucketFakeip)
|
return t.DeleteBucket(c.bucketName)
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
280
config/config.go
280
config/config.go
@@ -20,15 +20,15 @@ import (
|
|||||||
"github.com/metacubex/mihomo/component/cidr"
|
"github.com/metacubex/mihomo/component/cidr"
|
||||||
"github.com/metacubex/mihomo/component/fakeip"
|
"github.com/metacubex/mihomo/component/fakeip"
|
||||||
"github.com/metacubex/mihomo/component/geodata"
|
"github.com/metacubex/mihomo/component/geodata"
|
||||||
P "github.com/metacubex/mihomo/component/process"
|
"github.com/metacubex/mihomo/component/process"
|
||||||
"github.com/metacubex/mihomo/component/resolver"
|
"github.com/metacubex/mihomo/component/resolver"
|
||||||
"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"
|
"github.com/metacubex/mihomo/listener"
|
||||||
LC "github.com/metacubex/mihomo/listener/config"
|
LC "github.com/metacubex/mihomo/listener/config"
|
||||||
"github.com/metacubex/mihomo/log"
|
"github.com/metacubex/mihomo/log"
|
||||||
R "github.com/metacubex/mihomo/rules"
|
R "github.com/metacubex/mihomo/rules"
|
||||||
@@ -44,27 +44,27 @@ import (
|
|||||||
// General config
|
// General config
|
||||||
type General struct {
|
type General struct {
|
||||||
Inbound
|
Inbound
|
||||||
Mode T.TunnelMode `json:"mode"`
|
Mode T.TunnelMode `json:"mode"`
|
||||||
UnifiedDelay bool `json:"unified-delay"`
|
UnifiedDelay bool `json:"unified-delay"`
|
||||||
LogLevel log.LogLevel `json:"log-level"`
|
LogLevel log.LogLevel `json:"log-level"`
|
||||||
IPv6 bool `json:"ipv6"`
|
IPv6 bool `json:"ipv6"`
|
||||||
Interface string `json:"interface-name"`
|
Interface string `json:"interface-name"`
|
||||||
RoutingMark int `json:"routing-mark"`
|
RoutingMark int `json:"routing-mark"`
|
||||||
GeoXUrl GeoXUrl `json:"geox-url"`
|
GeoXUrl GeoXUrl `json:"geox-url"`
|
||||||
GeoAutoUpdate bool `json:"geo-auto-update"`
|
GeoAutoUpdate bool `json:"geo-auto-update"`
|
||||||
GeoUpdateInterval int `json:"geo-update-interval"`
|
GeoUpdateInterval int `json:"geo-update-interval"`
|
||||||
GeodataMode bool `json:"geodata-mode"`
|
GeodataMode bool `json:"geodata-mode"`
|
||||||
GeodataLoader string `json:"geodata-loader"`
|
GeodataLoader string `json:"geodata-loader"`
|
||||||
GeositeMatcher string `json:"geosite-matcher"`
|
GeositeMatcher string `json:"geosite-matcher"`
|
||||||
TCPConcurrent bool `json:"tcp-concurrent"`
|
TCPConcurrent bool `json:"tcp-concurrent"`
|
||||||
FindProcessMode P.FindProcessMode `json:"find-process-mode"`
|
FindProcessMode process.FindProcessMode `json:"find-process-mode"`
|
||||||
Sniffing bool `json:"sniffing"`
|
Sniffing bool `json:"sniffing"`
|
||||||
GlobalClientFingerprint string `json:"global-client-fingerprint"`
|
GlobalClientFingerprint string `json:"global-client-fingerprint"`
|
||||||
GlobalUA string `json:"global-ua"`
|
GlobalUA string `json:"global-ua"`
|
||||||
ETagSupport bool `json:"etag-support"`
|
ETagSupport bool `json:"etag-support"`
|
||||||
KeepAliveIdle int `json:"keep-alive-idle"`
|
KeepAliveIdle int `json:"keep-alive-idle"`
|
||||||
KeepAliveInterval int `json:"keep-alive-interval"`
|
KeepAliveInterval int `json:"keep-alive-interval"`
|
||||||
DisableKeepAlive bool `json:"disable-keep-alive"`
|
DisableKeepAlive bool `json:"disable-keep-alive"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inbound config
|
// Inbound config
|
||||||
@@ -157,7 +157,11 @@ type DNS struct {
|
|||||||
DefaultNameserver []dns.NameServer
|
DefaultNameserver []dns.NameServer
|
||||||
CacheAlgorithm string
|
CacheAlgorithm string
|
||||||
CacheMaxSize int
|
CacheMaxSize int
|
||||||
FakeIPRange *fakeip.Pool
|
FakeIPRange netip.Prefix
|
||||||
|
FakeIPPool *fakeip.Pool
|
||||||
|
FakeIPRange6 netip.Prefix
|
||||||
|
FakeIPPool6 *fakeip.Pool
|
||||||
|
FakeIPSkipper *fakeip.Skipper
|
||||||
NameServerPolicy []dns.Policy
|
NameServerPolicy []dns.Policy
|
||||||
ProxyServerNameserver []dns.NameServer
|
ProxyServerNameserver []dns.NameServer
|
||||||
DirectNameServer []dns.NameServer
|
DirectNameServer []dns.NameServer
|
||||||
@@ -195,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
|
||||||
@@ -221,6 +225,7 @@ type RawDNS struct {
|
|||||||
Listen string `yaml:"listen" json:"listen"`
|
Listen string `yaml:"listen" json:"listen"`
|
||||||
EnhancedMode C.DNSMode `yaml:"enhanced-mode" json:"enhanced-mode"`
|
EnhancedMode C.DNSMode `yaml:"enhanced-mode" json:"enhanced-mode"`
|
||||||
FakeIPRange string `yaml:"fake-ip-range" json:"fake-ip-range"`
|
FakeIPRange string `yaml:"fake-ip-range" json:"fake-ip-range"`
|
||||||
|
FakeIPRange6 string `yaml:"fake-ip-range6" json:"fake-ip-range6"`
|
||||||
FakeIPFilter []string `yaml:"fake-ip-filter" json:"fake-ip-filter"`
|
FakeIPFilter []string `yaml:"fake-ip-filter" json:"fake-ip-filter"`
|
||||||
FakeIPFilterMode C.FilterMode `yaml:"fake-ip-filter-mode" json:"fake-ip-filter-mode"`
|
FakeIPFilterMode C.FilterMode `yaml:"fake-ip-filter-mode" json:"fake-ip-filter-mode"`
|
||||||
DefaultNameserver []string `yaml:"default-nameserver" json:"default-nameserver"`
|
DefaultNameserver []string `yaml:"default-nameserver" json:"default-nameserver"`
|
||||||
@@ -377,51 +382,51 @@ type RawTLS struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RawConfig struct {
|
type RawConfig struct {
|
||||||
Port int `yaml:"port" json:"port"`
|
Port int `yaml:"port" json:"port"`
|
||||||
SocksPort int `yaml:"socks-port" json:"socks-port"`
|
SocksPort int `yaml:"socks-port" json:"socks-port"`
|
||||||
RedirPort int `yaml:"redir-port" json:"redir-port"`
|
RedirPort int `yaml:"redir-port" json:"redir-port"`
|
||||||
TProxyPort int `yaml:"tproxy-port" json:"tproxy-port"`
|
TProxyPort int `yaml:"tproxy-port" json:"tproxy-port"`
|
||||||
MixedPort int `yaml:"mixed-port" json:"mixed-port"`
|
MixedPort int `yaml:"mixed-port" json:"mixed-port"`
|
||||||
ShadowSocksConfig string `yaml:"ss-config" json:"ss-config"`
|
ShadowSocksConfig string `yaml:"ss-config" json:"ss-config"`
|
||||||
VmessConfig string `yaml:"vmess-config" json:"vmess-config"`
|
VmessConfig string `yaml:"vmess-config" json:"vmess-config"`
|
||||||
InboundTfo bool `yaml:"inbound-tfo" json:"inbound-tfo"`
|
InboundTfo bool `yaml:"inbound-tfo" json:"inbound-tfo"`
|
||||||
InboundMPTCP bool `yaml:"inbound-mptcp" json:"inbound-mptcp"`
|
InboundMPTCP bool `yaml:"inbound-mptcp" json:"inbound-mptcp"`
|
||||||
Authentication []string `yaml:"authentication" json:"authentication"`
|
Authentication []string `yaml:"authentication" json:"authentication"`
|
||||||
SkipAuthPrefixes []netip.Prefix `yaml:"skip-auth-prefixes" json:"skip-auth-prefixes"`
|
SkipAuthPrefixes []netip.Prefix `yaml:"skip-auth-prefixes" json:"skip-auth-prefixes"`
|
||||||
LanAllowedIPs []netip.Prefix `yaml:"lan-allowed-ips" json:"lan-allowed-ips"`
|
LanAllowedIPs []netip.Prefix `yaml:"lan-allowed-ips" json:"lan-allowed-ips"`
|
||||||
LanDisAllowedIPs []netip.Prefix `yaml:"lan-disallowed-ips" json:"lan-disallowed-ips"`
|
LanDisAllowedIPs []netip.Prefix `yaml:"lan-disallowed-ips" json:"lan-disallowed-ips"`
|
||||||
AllowLan bool `yaml:"allow-lan" json:"allow-lan"`
|
AllowLan bool `yaml:"allow-lan" json:"allow-lan"`
|
||||||
BindAddress string `yaml:"bind-address" json:"bind-address"`
|
BindAddress string `yaml:"bind-address" json:"bind-address"`
|
||||||
Mode T.TunnelMode `yaml:"mode" json:"mode"`
|
Mode T.TunnelMode `yaml:"mode" json:"mode"`
|
||||||
UnifiedDelay bool `yaml:"unified-delay" json:"unified-delay"`
|
UnifiedDelay bool `yaml:"unified-delay" json:"unified-delay"`
|
||||||
LogLevel log.LogLevel `yaml:"log-level" json:"log-level"`
|
LogLevel log.LogLevel `yaml:"log-level" json:"log-level"`
|
||||||
IPv6 bool `yaml:"ipv6" json:"ipv6"`
|
IPv6 bool `yaml:"ipv6" json:"ipv6"`
|
||||||
ExternalController string `yaml:"external-controller" json:"external-controller"`
|
ExternalController string `yaml:"external-controller" json:"external-controller"`
|
||||||
ExternalControllerPipe string `yaml:"external-controller-pipe" json:"external-controller-pipe"`
|
ExternalControllerPipe string `yaml:"external-controller-pipe" json:"external-controller-pipe"`
|
||||||
ExternalControllerUnix string `yaml:"external-controller-unix" json:"external-controller-unix"`
|
ExternalControllerUnix string `yaml:"external-controller-unix" json:"external-controller-unix"`
|
||||||
ExternalControllerTLS string `yaml:"external-controller-tls" json:"external-controller-tls"`
|
ExternalControllerTLS string `yaml:"external-controller-tls" json:"external-controller-tls"`
|
||||||
ExternalControllerCors RawCors `yaml:"external-controller-cors" json:"external-controller-cors"`
|
ExternalControllerCors RawCors `yaml:"external-controller-cors" json:"external-controller-cors"`
|
||||||
ExternalUI string `yaml:"external-ui" json:"external-ui"`
|
ExternalUI string `yaml:"external-ui" json:"external-ui"`
|
||||||
ExternalUIURL string `yaml:"external-ui-url" json:"external-ui-url"`
|
ExternalUIURL string `yaml:"external-ui-url" json:"external-ui-url"`
|
||||||
ExternalUIName string `yaml:"external-ui-name" json:"external-ui-name"`
|
ExternalUIName string `yaml:"external-ui-name" json:"external-ui-name"`
|
||||||
ExternalDohServer string `yaml:"external-doh-server" json:"external-doh-server"`
|
ExternalDohServer string `yaml:"external-doh-server" json:"external-doh-server"`
|
||||||
Secret string `yaml:"secret" json:"secret"`
|
Secret string `yaml:"secret" json:"secret"`
|
||||||
Interface string `yaml:"interface-name" json:"interface-name"`
|
Interface string `yaml:"interface-name" json:"interface-name"`
|
||||||
RoutingMark int `yaml:"routing-mark" json:"routing-mark"`
|
RoutingMark int `yaml:"routing-mark" json:"routing-mark"`
|
||||||
Tunnels []LC.Tunnel `yaml:"tunnels" json:"tunnels"`
|
Tunnels []LC.Tunnel `yaml:"tunnels" json:"tunnels"`
|
||||||
GeoAutoUpdate bool `yaml:"geo-auto-update" json:"geo-auto-update"`
|
GeoAutoUpdate bool `yaml:"geo-auto-update" json:"geo-auto-update"`
|
||||||
GeoUpdateInterval int `yaml:"geo-update-interval" json:"geo-update-interval"`
|
GeoUpdateInterval int `yaml:"geo-update-interval" json:"geo-update-interval"`
|
||||||
GeodataMode bool `yaml:"geodata-mode" json:"geodata-mode"`
|
GeodataMode bool `yaml:"geodata-mode" json:"geodata-mode"`
|
||||||
GeodataLoader string `yaml:"geodata-loader" json:"geodata-loader"`
|
GeodataLoader string `yaml:"geodata-loader" json:"geodata-loader"`
|
||||||
GeositeMatcher string `yaml:"geosite-matcher" json:"geosite-matcher"`
|
GeositeMatcher string `yaml:"geosite-matcher" json:"geosite-matcher"`
|
||||||
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
|
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
|
||||||
FindProcessMode P.FindProcessMode `yaml:"find-process-mode" json:"find-process-mode"`
|
FindProcessMode process.FindProcessMode `yaml:"find-process-mode" json:"find-process-mode"`
|
||||||
GlobalClientFingerprint string `yaml:"global-client-fingerprint" json:"global-client-fingerprint"`
|
GlobalClientFingerprint string `yaml:"global-client-fingerprint" json:"global-client-fingerprint"`
|
||||||
GlobalUA string `yaml:"global-ua" json:"global-ua"`
|
GlobalUA string `yaml:"global-ua" json:"global-ua"`
|
||||||
ETagSupport bool `yaml:"etag-support" json:"etag-support"`
|
ETagSupport bool `yaml:"etag-support" json:"etag-support"`
|
||||||
KeepAliveIdle int `yaml:"keep-alive-idle" json:"keep-alive-idle"`
|
KeepAliveIdle int `yaml:"keep-alive-idle" json:"keep-alive-idle"`
|
||||||
KeepAliveInterval int `yaml:"keep-alive-interval" json:"keep-alive-interval"`
|
KeepAliveInterval int `yaml:"keep-alive-interval" json:"keep-alive-interval"`
|
||||||
DisableKeepAlive bool `yaml:"disable-keep-alive" json:"disable-keep-alive"`
|
DisableKeepAlive bool `yaml:"disable-keep-alive" json:"disable-keep-alive"`
|
||||||
|
|
||||||
ProxyProvider map[string]map[string]any `yaml:"proxy-providers" json:"proxy-providers"`
|
ProxyProvider map[string]map[string]any `yaml:"proxy-providers" json:"proxy-providers"`
|
||||||
RuleProvider map[string]map[string]any `yaml:"rule-providers" json:"rule-providers"`
|
RuleProvider map[string]map[string]any `yaml:"rule-providers" json:"rule-providers"`
|
||||||
@@ -474,7 +479,7 @@ func DefaultRawConfig() *RawConfig {
|
|||||||
Proxy: []map[string]any{},
|
Proxy: []map[string]any{},
|
||||||
ProxyGroup: []map[string]any{},
|
ProxyGroup: []map[string]any{},
|
||||||
TCPConcurrent: false,
|
TCPConcurrent: false,
|
||||||
FindProcessMode: P.FindProcessStrict,
|
FindProcessMode: process.FindProcessStrict,
|
||||||
GlobalUA: "clash.meta/" + C.Version,
|
GlobalUA: "clash.meta/" + C.Version,
|
||||||
ETagSupport: true,
|
ETagSupport: true,
|
||||||
DNS: RawDNS{
|
DNS: RawDNS{
|
||||||
@@ -648,11 +653,11 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
|||||||
config.Proxies = proxies
|
config.Proxies = proxies
|
||||||
config.Providers = providers
|
config.Providers = providers
|
||||||
|
|
||||||
listener, err := parseListeners(rawCfg)
|
listeners, err := parseListeners(rawCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.Listeners = listener
|
config.Listeners = listeners
|
||||||
|
|
||||||
log.Infoln("Geodata Loader mode: %s", geodata.LoaderName())
|
log.Infoln("Geodata Loader mode: %s", geodata.LoaderName())
|
||||||
log.Infoln("Geosite Matcher implementation: %s", geodata.SiteMatcherName())
|
log.Infoln("Geosite Matcher implementation: %s", geodata.SiteMatcherName())
|
||||||
@@ -680,13 +685,15 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
|||||||
}
|
}
|
||||||
config.Hosts = hosts
|
config.Hosts = hosts
|
||||||
|
|
||||||
|
parseIPV6(rawCfg) // must before DNS and Tun
|
||||||
|
|
||||||
dnsCfg, err := parseDNS(rawCfg, ruleProviders)
|
dnsCfg, err := parseDNS(rawCfg, ruleProviders)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.DNS = dnsCfg
|
config.DNS = dnsCfg
|
||||||
|
|
||||||
err = parseTun(rawCfg.Tun, config.General)
|
err = parseTun(rawCfg.Tun, dnsCfg, config.General)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -838,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
|
||||||
@@ -940,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)
|
||||||
}
|
}
|
||||||
@@ -950,24 +957,25 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
|
|||||||
func parseListeners(cfg *RawConfig) (listeners map[string]C.InboundListener, err error) {
|
func parseListeners(cfg *RawConfig) (listeners map[string]C.InboundListener, err error) {
|
||||||
listeners = make(map[string]C.InboundListener)
|
listeners = make(map[string]C.InboundListener)
|
||||||
for index, mapping := range cfg.Listeners {
|
for index, mapping := range cfg.Listeners {
|
||||||
listener, err := L.ParseListener(mapping)
|
inboundListener, err := listener.ParseListener(mapping)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("proxy %d: %w", index, err)
|
return nil, fmt.Errorf("proxy %d: %w", index, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, exist := mapping[listener.Name()]; exist {
|
name := inboundListener.Name()
|
||||||
return nil, fmt.Errorf("listener %s is the duplicate name", listener.Name())
|
if _, exist := mapping[name]; exist {
|
||||||
|
return nil, fmt.Errorf("listener %s is the duplicate name", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
listeners[listener.Name()] = listener
|
listeners[name] = inboundListener
|
||||||
|
|
||||||
}
|
}
|
||||||
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)
|
||||||
@@ -980,7 +988,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)
|
||||||
@@ -1043,7 +1051,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
|
||||||
@@ -1266,7 +1274,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() {
|
||||||
@@ -1341,7 +1349,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")
|
||||||
@@ -1407,13 +1415,27 @@ func parseDNS(rawCfg *RawConfig, ruleProviders map[string]providerTypes.RuleProv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeIPRange, err := netip.ParsePrefix(cfg.FakeIPRange)
|
if cfg.FakeIPRange != "" {
|
||||||
T.SetFakeIPRange(fakeIPRange)
|
dnsCfg.FakeIPRange, err = netip.ParsePrefix(cfg.FakeIPRange)
|
||||||
if cfg.EnhancedMode == C.DNSFakeIP {
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if !dnsCfg.FakeIPRange.Addr().Is4() {
|
||||||
|
return nil, errors.New("dns.fake-ip-range must be a IPv4 prefix")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.FakeIPRange6 != "" {
|
||||||
|
dnsCfg.FakeIPRange6, err = netip.ParsePrefix(cfg.FakeIPRange6)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !dnsCfg.FakeIPRange6.Addr().Is6() {
|
||||||
|
return nil, errors.New("dns.fake-ip-range6 must be a IPv6 prefix")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.EnhancedMode == C.DNSFakeIP {
|
||||||
var fakeIPTrie *trie.DomainTrie[struct{}]
|
var fakeIPTrie *trie.DomainTrie[struct{}]
|
||||||
if len(dnsCfg.Fallback) != 0 {
|
if len(dnsCfg.Fallback) != 0 {
|
||||||
fakeIPTrie = trie.New[struct{}]()
|
fakeIPTrie = trie.New[struct{}]()
|
||||||
@@ -1431,18 +1453,39 @@ func parseDNS(rawCfg *RawConfig, ruleProviders map[string]providerTypes.RuleProv
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pool, err := fakeip.New(fakeip.Options{
|
skipper := &fakeip.Skipper{
|
||||||
IPNet: fakeIPRange,
|
Host: host,
|
||||||
Size: 1000,
|
Mode: cfg.FakeIPFilterMode,
|
||||||
Host: host,
|
}
|
||||||
Mode: cfg.FakeIPFilterMode,
|
dnsCfg.FakeIPSkipper = skipper
|
||||||
Persistence: rawCfg.Profile.StoreFakeIP,
|
|
||||||
})
|
if dnsCfg.FakeIPRange.IsValid() {
|
||||||
if err != nil {
|
pool, err := fakeip.New(fakeip.Options{
|
||||||
return nil, err
|
IPNet: dnsCfg.FakeIPRange,
|
||||||
|
Size: 1000,
|
||||||
|
Persistence: rawCfg.Profile.StoreFakeIP,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dnsCfg.FakeIPPool = pool
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsCfg.FakeIPRange = pool
|
if dnsCfg.FakeIPRange6.IsValid() {
|
||||||
|
pool6, err := fakeip.New(fakeip.Options{
|
||||||
|
IPNet: dnsCfg.FakeIPRange6,
|
||||||
|
Size: 1000,
|
||||||
|
Persistence: rawCfg.Profile.StoreFakeIP,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dnsCfg.FakeIPPool6 = pool6
|
||||||
|
}
|
||||||
|
|
||||||
|
if dnsCfg.FakeIPPool == nil && dnsCfg.FakeIPPool6 == nil {
|
||||||
|
return nil, errors.New("disallow `fake-ip-range` and `fake-ip-range6` both empty with fake-ip mode")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cfg.Fallback) != 0 {
|
if len(cfg.Fallback) != 0 {
|
||||||
@@ -1504,17 +1547,20 @@ func parseAuthentication(rawRecords []string) []auth.AuthUser {
|
|||||||
return users
|
return users
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTun(rawTun RawTun, general *General) error {
|
func parseIPV6(rawCfg *RawConfig) {
|
||||||
tunAddressPrefix := T.FakeIPRange()
|
if !rawCfg.IPv6 || !verifyIP6() {
|
||||||
|
rawCfg.DNS.FakeIPRange6 = ""
|
||||||
|
rawCfg.Tun.Inet6Address = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseTun(rawTun RawTun, dns *DNS, general *General) error {
|
||||||
|
tunAddressPrefix := dns.FakeIPRange
|
||||||
if !tunAddressPrefix.IsValid() {
|
if !tunAddressPrefix.IsValid() {
|
||||||
tunAddressPrefix = netip.MustParsePrefix("198.18.0.1/16")
|
tunAddressPrefix = netip.MustParsePrefix("198.18.0.1/16")
|
||||||
}
|
}
|
||||||
tunAddressPrefix = netip.PrefixFrom(tunAddressPrefix.Addr(), 30)
|
tunAddressPrefix = netip.PrefixFrom(tunAddressPrefix.Addr(), 30)
|
||||||
|
|
||||||
if !general.IPv6 || !verifyIP6() {
|
|
||||||
rawTun.Inet6Address = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
general.Tun = LC.Tun{
|
general.Tun = LC.Tun{
|
||||||
Enable: rawTun.Enable,
|
Enable: rawTun.Enable,
|
||||||
Device: rawTun.Device,
|
Device: rawTun.Device,
|
||||||
@@ -1587,7 +1633,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,
|
||||||
@@ -1677,7 +1723,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)
|
||||||
@@ -1724,7 +1770,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)
|
||||||
@@ -1767,14 +1813,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:
|
||||||
}
|
}
|
||||||
@@ -1782,14 +1828,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:
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,6 +155,10 @@ func verifyIP6() bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// eg: Calling net.InterfaceAddrs() fails on Android SDK 30
|
||||||
|
// https://github.com/golang/go/issues/40569
|
||||||
|
return true // just ignore
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,8 +139,11 @@ type ProxyAdapter interface {
|
|||||||
// SupportUOT return UDP over TCP support
|
// SupportUOT return UDP over TCP support
|
||||||
SupportUOT() bool
|
SupportUOT() bool
|
||||||
|
|
||||||
|
// SupportWithDialer only for deprecated relay group, the new protocol does not need to be implemented.
|
||||||
SupportWithDialer() NetWork
|
SupportWithDialer() NetWork
|
||||||
|
// DialContextWithDialer only for deprecated relay group, the new protocol does not need to be implemented.
|
||||||
DialContextWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (Conn, error)
|
DialContextWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (Conn, error)
|
||||||
|
// ListenPacketWithDialer only for deprecated relay group, the new protocol does not need to be implemented.
|
||||||
ListenPacketWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (PacketConn, error)
|
ListenPacketWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (PacketConn, error)
|
||||||
|
|
||||||
// IsL3Protocol return ProxyAdapter working in L3 (tell dns module not pass the domain to avoid loopback)
|
// IsL3Protocol return ProxyAdapter working in L3 (tell dns module not pass the domain to avoid loopback)
|
||||||
@@ -178,12 +181,6 @@ type Proxy interface {
|
|||||||
ExtraDelayHistories() map[string]ProxyState
|
ExtraDelayHistories() map[string]ProxyState
|
||||||
LastDelayForTestUrl(url string) uint16
|
LastDelayForTestUrl(url string) uint16
|
||||||
URLTest(ctx context.Context, url string, expectedStatus utils.IntRanges[uint16]) (uint16, error)
|
URLTest(ctx context.Context, url string, expectedStatus utils.IntRanges[uint16]) (uint16, error)
|
||||||
|
|
||||||
// Deprecated: use DialContext instead.
|
|
||||||
Dial(metadata *Metadata) (Conn, error)
|
|
||||||
|
|
||||||
// Deprecated: use DialPacketConn instead.
|
|
||||||
DialUDP(metadata *Metadata) (PacketConn, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdapterType is enum of adapter type
|
// AdapterType is enum of adapter type
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ const (
|
|||||||
TUIC
|
TUIC
|
||||||
HYSTERIA2
|
HYSTERIA2
|
||||||
ANYTLS
|
ANYTLS
|
||||||
|
MIERU
|
||||||
INNER
|
INNER
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -109,6 +110,8 @@ func (t Type) String() string {
|
|||||||
return "Hysteria2"
|
return "Hysteria2"
|
||||||
case ANYTLS:
|
case ANYTLS:
|
||||||
return "AnyTLS"
|
return "AnyTLS"
|
||||||
|
case MIERU:
|
||||||
|
return "Mieru"
|
||||||
case INNER:
|
case INNER:
|
||||||
return "Inner"
|
return "Inner"
|
||||||
default:
|
default:
|
||||||
@@ -149,6 +152,8 @@ func ParseType(t string) (*Type, error) {
|
|||||||
res = HYSTERIA2
|
res = HYSTERIA2
|
||||||
case "ANYTLS":
|
case "ANYTLS":
|
||||||
res = ANYTLS
|
res = ANYTLS
|
||||||
|
case "MIERU":
|
||||||
|
res = MIERU
|
||||||
case "INNER":
|
case "INNER":
|
||||||
res = INNER
|
res = INNER
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ResolverEnhancer struct {
|
type ResolverEnhancer struct {
|
||||||
mode C.DNSMode
|
mode C.DNSMode
|
||||||
fakePool *fakeip.Pool
|
fakeIPPool *fakeip.Pool
|
||||||
mapping *lru.LruCache[netip.Addr, string]
|
fakeIPPool6 *fakeip.Pool
|
||||||
useHosts bool
|
fakeIPSkipper *fakeip.Skipper
|
||||||
|
mapping *lru.LruCache[netip.Addr, string]
|
||||||
|
useHosts bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ResolverEnhancer) FakeIPEnabled() bool {
|
func (h *ResolverEnhancer) FakeIPEnabled() bool {
|
||||||
@@ -28,10 +30,14 @@ func (h *ResolverEnhancer) IsExistFakeIP(ip netip.Addr) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if pool := h.fakePool; pool != nil {
|
if pool := h.fakeIPPool; pool != nil {
|
||||||
return pool.Exist(ip)
|
return pool.Exist(ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pool6 := h.fakeIPPool6; pool6 != nil {
|
||||||
|
return pool6.Exist(ip)
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,10 +46,14 @@ func (h *ResolverEnhancer) IsFakeIP(ip netip.Addr) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if pool := h.fakePool; pool != nil {
|
if pool := h.fakeIPPool; pool != nil {
|
||||||
return pool.IPNet().Contains(ip) && ip != pool.Gateway() && ip != pool.Broadcast()
|
return pool.IPNet().Contains(ip) && ip != pool.Gateway() && ip != pool.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pool6 := h.fakeIPPool6; pool6 != nil {
|
||||||
|
return pool6.IPNet().Contains(ip) && ip != pool6.Gateway() && ip != pool6.Broadcast()
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,20 +62,30 @@ func (h *ResolverEnhancer) IsFakeBroadcastIP(ip netip.Addr) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if pool := h.fakePool; pool != nil {
|
if pool := h.fakeIPPool; pool != nil {
|
||||||
return pool.Broadcast() == ip
|
return pool.Broadcast() == ip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pool6 := h.fakeIPPool6; pool6 != nil {
|
||||||
|
return pool6.Broadcast() == ip
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ResolverEnhancer) FindHostByIP(ip netip.Addr) (string, bool) {
|
func (h *ResolverEnhancer) FindHostByIP(ip netip.Addr) (string, bool) {
|
||||||
if pool := h.fakePool; pool != nil {
|
if pool := h.fakeIPPool; pool != nil {
|
||||||
if host, existed := pool.LookBack(ip); existed {
|
if host, existed := pool.LookBack(ip); existed {
|
||||||
return host, true
|
return host, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pool6 := h.fakeIPPool6; pool6 != nil {
|
||||||
|
if host, existed := pool6.LookBack(ip); existed {
|
||||||
|
return host, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if mapping := h.mapping; mapping != nil {
|
if mapping := h.mapping; mapping != nil {
|
||||||
if host, existed := h.mapping.Get(ip); existed {
|
if host, existed := h.mapping.Get(ip); existed {
|
||||||
return host, true
|
return host, true
|
||||||
@@ -82,9 +102,12 @@ func (h *ResolverEnhancer) InsertHostByIP(ip netip.Addr, host string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *ResolverEnhancer) FlushFakeIP() error {
|
func (h *ResolverEnhancer) FlushFakeIP() error {
|
||||||
if pool := h.fakePool; pool != nil {
|
if pool := h.fakeIPPool; pool != nil {
|
||||||
return pool.FlushFakeIP()
|
return pool.FlushFakeIP()
|
||||||
}
|
}
|
||||||
|
if pool6 := h.fakeIPPool6; pool6 != nil {
|
||||||
|
return pool6.FlushFakeIP()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,36 +116,48 @@ func (h *ResolverEnhancer) PatchFrom(o *ResolverEnhancer) {
|
|||||||
o.mapping.CloneTo(h.mapping)
|
o.mapping.CloneTo(h.mapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.fakePool != nil && o.fakePool != nil {
|
if h.fakeIPPool != nil && o.fakeIPPool != nil {
|
||||||
h.fakePool.CloneFrom(o.fakePool)
|
h.fakeIPPool.CloneFrom(o.fakeIPPool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if h.fakeIPPool6 != nil && o.fakeIPPool6 != nil {
|
||||||
|
h.fakeIPPool6.CloneFrom(o.fakeIPPool6)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ResolverEnhancer) StoreFakePoolState() {
|
func (h *ResolverEnhancer) StoreFakePoolState() {
|
||||||
if h.fakePool != nil {
|
if h.fakeIPPool != nil {
|
||||||
h.fakePool.StoreState()
|
h.fakeIPPool.StoreState()
|
||||||
|
}
|
||||||
|
|
||||||
|
if h.fakeIPPool6 != nil {
|
||||||
|
h.fakeIPPool6.StoreState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type EnhancerConfig struct {
|
type EnhancerConfig struct {
|
||||||
EnhancedMode C.DNSMode
|
IPv6 bool
|
||||||
Pool *fakeip.Pool
|
EnhancedMode C.DNSMode
|
||||||
UseHosts bool
|
FakeIPPool *fakeip.Pool
|
||||||
|
FakeIPPool6 *fakeip.Pool
|
||||||
|
FakeIPSkipper *fakeip.Skipper
|
||||||
|
UseHosts bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnhancer(cfg EnhancerConfig) *ResolverEnhancer {
|
func NewEnhancer(cfg EnhancerConfig) *ResolverEnhancer {
|
||||||
var fakePool *fakeip.Pool
|
e := &ResolverEnhancer{
|
||||||
var mapping *lru.LruCache[netip.Addr, string]
|
|
||||||
|
|
||||||
if cfg.EnhancedMode != C.DNSNormal {
|
|
||||||
fakePool = cfg.Pool
|
|
||||||
mapping = lru.New(lru.WithSize[netip.Addr, string](4096))
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ResolverEnhancer{
|
|
||||||
mode: cfg.EnhancedMode,
|
mode: cfg.EnhancedMode,
|
||||||
fakePool: fakePool,
|
|
||||||
mapping: mapping,
|
|
||||||
useHosts: cfg.UseHosts,
|
useHosts: cfg.UseHosts,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.EnhancedMode != C.DNSNormal {
|
||||||
|
e.fakeIPPool = cfg.FakeIPPool
|
||||||
|
if cfg.IPv6 {
|
||||||
|
e.fakeIPPool6 = cfg.FakeIPPool6
|
||||||
|
}
|
||||||
|
e.fakeIPSkipper = cfg.FakeIPSkipper
|
||||||
|
e.mapping = lru.New(lru.WithSize[netip.Addr, string](4096))
|
||||||
|
}
|
||||||
|
|
||||||
|
return e
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ func withHosts(mapping *lru.LruCache[netip.Addr, string]) middleware {
|
|||||||
} else if q.Qtype == D.TypeAAAA {
|
} else if q.Qtype == D.TypeAAAA {
|
||||||
rr := &D.AAAA{}
|
rr := &D.AAAA{}
|
||||||
rr.Hdr = D.RR_Header{Name: q.Name, Rrtype: D.TypeAAAA, Class: D.ClassINET, Ttl: 10}
|
rr.Hdr = D.RR_Header{Name: q.Name, Rrtype: D.TypeAAAA, Class: D.ClassINET, Ttl: 10}
|
||||||
ip := ipAddr.As16()
|
rr.AAAA = ipAddr.AsSlice()
|
||||||
rr.AAAA = ip[:]
|
|
||||||
msg.Answer = append(msg.Answer, rr)
|
msg.Answer = append(msg.Answer, rr)
|
||||||
if mapping != nil {
|
if mapping != nil {
|
||||||
mapping.SetWithExpire(ipAddr, host, time.Now().Add(time.Second*10))
|
mapping.SetWithExpire(ipAddr, host, time.Now().Add(time.Second*10))
|
||||||
@@ -147,29 +146,42 @@ func withMapping(mapping *lru.LruCache[netip.Addr, string]) middleware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withFakeIP(fakePool *fakeip.Pool) middleware {
|
func withFakeIP(skipper *fakeip.Skipper, fakePool *fakeip.Pool, fakePool6 *fakeip.Pool) middleware {
|
||||||
return func(next handler) handler {
|
return func(next handler) handler {
|
||||||
return func(ctx *icontext.DNSContext, r *D.Msg) (*D.Msg, error) {
|
return func(ctx *icontext.DNSContext, r *D.Msg) (*D.Msg, error) {
|
||||||
q := r.Question[0]
|
q := r.Question[0]
|
||||||
|
|
||||||
host := strings.TrimRight(q.Name, ".")
|
host := strings.TrimRight(q.Name, ".")
|
||||||
if fakePool.ShouldSkipped(host) {
|
if skipper.ShouldSkipped(host) {
|
||||||
return next(ctx, r)
|
return next(ctx, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rr D.RR
|
||||||
switch q.Qtype {
|
switch q.Qtype {
|
||||||
case D.TypeAAAA, D.TypeSVCB, D.TypeHTTPS:
|
case D.TypeA:
|
||||||
|
if fakePool == nil {
|
||||||
|
return handleMsgWithEmptyAnswer(r), nil
|
||||||
|
}
|
||||||
|
ip := fakePool.Lookup(host)
|
||||||
|
rr = &D.A{
|
||||||
|
Hdr: D.RR_Header{Name: q.Name, Rrtype: D.TypeA, Class: D.ClassINET, Ttl: dnsDefaultTTL},
|
||||||
|
A: ip.AsSlice(),
|
||||||
|
}
|
||||||
|
case D.TypeAAAA:
|
||||||
|
if fakePool6 == nil {
|
||||||
|
return handleMsgWithEmptyAnswer(r), nil
|
||||||
|
}
|
||||||
|
ip := fakePool6.Lookup(host)
|
||||||
|
rr = &D.AAAA{
|
||||||
|
Hdr: D.RR_Header{Name: q.Name, Rrtype: D.TypeAAAA, Class: D.ClassINET, Ttl: dnsDefaultTTL},
|
||||||
|
AAAA: ip.AsSlice(),
|
||||||
|
}
|
||||||
|
case D.TypeSVCB, D.TypeHTTPS:
|
||||||
return handleMsgWithEmptyAnswer(r), nil
|
return handleMsgWithEmptyAnswer(r), nil
|
||||||
}
|
default:
|
||||||
|
|
||||||
if q.Qtype != D.TypeA {
|
|
||||||
return next(ctx, r)
|
return next(ctx, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
rr := &D.A{}
|
|
||||||
rr.Hdr = D.RR_Header{Name: q.Name, Rrtype: D.TypeA, Class: D.ClassINET, Ttl: dnsDefaultTTL}
|
|
||||||
ip := fakePool.Lookup(host)
|
|
||||||
rr.A = ip.AsSlice()
|
|
||||||
msg := r.Copy()
|
msg := r.Copy()
|
||||||
msg.Answer = []D.RR{rr}
|
msg.Answer = []D.RR{rr}
|
||||||
|
|
||||||
@@ -226,7 +238,7 @@ func newHandler(resolver *Resolver, mapper *ResolverEnhancer) handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mapper.mode == C.DNSFakeIP {
|
if mapper.mode == C.DNSFakeIP {
|
||||||
middlewares = append(middlewares, withFakeIP(mapper.fakePool))
|
middlewares = append(middlewares, withFakeIP(mapper.fakeIPSkipper, mapper.fakeIPPool, mapper.fakeIPPool6))
|
||||||
}
|
}
|
||||||
|
|
||||||
if mapper.mode != C.DNSNormal {
|
if mapper.mode != C.DNSNormal {
|
||||||
|
|||||||
@@ -261,6 +261,7 @@ dns:
|
|||||||
enhanced-mode: fake-ip # or redir-host
|
enhanced-mode: fake-ip # or redir-host
|
||||||
|
|
||||||
fake-ip-range: 198.18.0.1/16 # fake-ip 池设置
|
fake-ip-range: 198.18.0.1/16 # fake-ip 池设置
|
||||||
|
# fake-ip-range6: fdfe:dcba:9876::1/64 # fake-ip6 池设置
|
||||||
|
|
||||||
# 配置不使用 fake-ip 的域名
|
# 配置不使用 fake-ip 的域名
|
||||||
fake-ip-filter:
|
fake-ip-filter:
|
||||||
@@ -1555,6 +1556,15 @@ listeners:
|
|||||||
# -----END ECH KEYS-----
|
# -----END ECH KEYS-----
|
||||||
# padding-scheme: "" # https://github.com/anytls/anytls-go/blob/main/docs/protocol.md#cmdupdatepaddingscheme
|
# padding-scheme: "" # https://github.com/anytls/anytls-go/blob/main/docs/protocol.md#cmdupdatepaddingscheme
|
||||||
|
|
||||||
|
- name: mieru-in-1
|
||||||
|
type: mieru
|
||||||
|
port: 10818 # 支持使用ports格式,例如200,302 or 200,204,401-429,501-503
|
||||||
|
listen: 0.0.0.0
|
||||||
|
transport: TCP # 支持 TCP 或者 UDP
|
||||||
|
users:
|
||||||
|
username1: password1
|
||||||
|
username2: password2
|
||||||
|
|
||||||
- name: trojan-in-1
|
- name: trojan-in-1
|
||||||
type: trojan
|
type: trojan
|
||||||
port: 10819 # 支持使用ports格式,例如200,302 or 200,204,401-429,501-503
|
port: 10819 # 支持使用ports格式,例如200,302 or 200,204,401-429,501-503
|
||||||
|
|||||||
22
go.mod
22
go.mod
@@ -6,25 +6,25 @@ require (
|
|||||||
github.com/bahlo/generic-list-go v0.2.0
|
github.com/bahlo/generic-list-go v0.2.0
|
||||||
github.com/coreos/go-iptables v0.8.0
|
github.com/coreos/go-iptables v0.8.0
|
||||||
github.com/dlclark/regexp2 v1.11.5
|
github.com/dlclark/regexp2 v1.11.5
|
||||||
github.com/ebitengine/purego v0.9.0
|
github.com/ebitengine/purego v0.9.1
|
||||||
github.com/enfein/mieru/v3 v3.20.0
|
github.com/enfein/mieru/v3 v3.22.1
|
||||||
github.com/go-chi/chi/v5 v5.2.3
|
github.com/go-chi/chi/v5 v5.2.3
|
||||||
github.com/go-chi/render v1.0.3
|
github.com/go-chi/render v1.0.3
|
||||||
github.com/gobwas/ws v1.4.0
|
github.com/gobwas/ws v1.4.0
|
||||||
github.com/gofrs/uuid/v5 v5.3.2
|
github.com/gofrs/uuid/v5 v5.4.0
|
||||||
github.com/golang/snappy v1.0.0
|
github.com/golang/snappy v1.0.0
|
||||||
github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905
|
github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905
|
||||||
github.com/klauspost/compress v1.17.9 // lastest version compatible with golang1.20
|
github.com/klauspost/compress v1.17.9 // lastest version compatible with golang1.20
|
||||||
github.com/mdlayher/netlink v1.7.2
|
github.com/mdlayher/netlink v1.7.2
|
||||||
github.com/metacubex/amneziawg-go v0.0.0-20250902133113-a7f637c14281
|
github.com/metacubex/amneziawg-go v0.0.0-20251104174305-5a0e9f7e361d
|
||||||
github.com/metacubex/bart v0.24.0
|
github.com/metacubex/bart v0.26.0
|
||||||
github.com/metacubex/bbolt v0.0.0-20250725135710-010dbbbb7a5b
|
github.com/metacubex/bbolt v0.0.0-20250725135710-010dbbbb7a5b
|
||||||
github.com/metacubex/blake3 v0.1.0
|
github.com/metacubex/blake3 v0.1.0
|
||||||
github.com/metacubex/chacha v0.1.5
|
github.com/metacubex/chacha v0.1.5
|
||||||
github.com/metacubex/fswatch v0.1.1
|
github.com/metacubex/fswatch v0.1.1
|
||||||
github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759
|
github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759
|
||||||
github.com/metacubex/kcp-go v0.0.0-20251007183319-0df1aec1639a
|
github.com/metacubex/kcp-go v0.0.0-20251105084629-8c93f4bf37be
|
||||||
github.com/metacubex/quic-go v0.55.1-0.20251004050223-450bd9e32033
|
github.com/metacubex/quic-go v0.55.1-0.20251024060151-bd465f127128
|
||||||
github.com/metacubex/randv2 v0.2.0
|
github.com/metacubex/randv2 v0.2.0
|
||||||
github.com/metacubex/restls-client-go v0.1.7
|
github.com/metacubex/restls-client-go v0.1.7
|
||||||
github.com/metacubex/sing v0.5.6
|
github.com/metacubex/sing v0.5.6
|
||||||
@@ -33,12 +33,12 @@ require (
|
|||||||
github.com/metacubex/sing-shadowsocks v0.2.12
|
github.com/metacubex/sing-shadowsocks v0.2.12
|
||||||
github.com/metacubex/sing-shadowsocks2 v0.2.7
|
github.com/metacubex/sing-shadowsocks2 v0.2.7
|
||||||
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2
|
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2
|
||||||
github.com/metacubex/sing-tun v0.4.8
|
github.com/metacubex/sing-tun v0.4.9
|
||||||
github.com/metacubex/sing-vmess v0.2.4
|
github.com/metacubex/sing-vmess v0.2.4
|
||||||
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f
|
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f
|
||||||
github.com/metacubex/smux v0.0.0-20250922175018-15c9a6a78719
|
github.com/metacubex/smux v0.0.0-20250922175018-15c9a6a78719
|
||||||
github.com/metacubex/tfo-go v0.0.0-20250921095601-b102db4216c0
|
github.com/metacubex/tfo-go v0.0.0-20251024101424-368b42b59148
|
||||||
github.com/metacubex/utls v1.8.2
|
github.com/metacubex/utls v1.8.3
|
||||||
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f
|
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f
|
||||||
github.com/miekg/dns v1.1.63 // lastest version compatible with golang1.20
|
github.com/miekg/dns v1.1.63 // lastest version compatible with golang1.20
|
||||||
github.com/mroth/weightedrand/v2 v2.1.0
|
github.com/mroth/weightedrand/v2 v2.1.0
|
||||||
@@ -46,7 +46,7 @@ require (
|
|||||||
github.com/oschwald/maxminddb-golang v1.12.0 // lastest version compatible with golang1.20
|
github.com/oschwald/maxminddb-golang v1.12.0 // lastest version compatible with golang1.20
|
||||||
github.com/sagernet/cors v1.2.1
|
github.com/sagernet/cors v1.2.1
|
||||||
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a
|
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a
|
||||||
github.com/samber/lo v1.51.0
|
github.com/samber/lo v1.52.0
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/stretchr/testify v1.11.1
|
github.com/stretchr/testify v1.11.1
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1
|
github.com/vmihailenco/msgpack/v5 v5.4.1
|
||||||
|
|||||||
44
go.sum
44
go.sum
@@ -23,10 +23,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
|
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
|
||||||
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||||
github.com/ebitengine/purego v0.9.0 h1:mh0zpKBIXDceC63hpvPuGLiJ8ZAa3DfrFTudmfi8A4k=
|
github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s0A=
|
||||||
github.com/ebitengine/purego v0.9.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
||||||
github.com/enfein/mieru/v3 v3.20.0 h1:1ob7pCIVSH5FYFAfYvim8isLW1vBOS4cFOUF9exJS38=
|
github.com/enfein/mieru/v3 v3.22.1 h1:/XGYYXpEhEJlxosmtbpEJkhtRLHB8IToG7LB8kU2ZDY=
|
||||||
github.com/enfein/mieru/v3 v3.20.0/go.mod h1:zJBUCsi5rxyvHM8fjFf+GLaEl4OEjjBXr1s5F6Qd3hM=
|
github.com/enfein/mieru/v3 v3.22.1/go.mod h1:zJBUCsi5rxyvHM8fjFf+GLaEl4OEjjBXr1s5F6Qd3hM=
|
||||||
github.com/ericlagergren/aegis v0.0.0-20250325060835-cd0defd64358 h1:kXYqH/sL8dS/FdoFjr12ePjnLPorPo2FsnrHNuXSDyo=
|
github.com/ericlagergren/aegis v0.0.0-20250325060835-cd0defd64358 h1:kXYqH/sL8dS/FdoFjr12ePjnLPorPo2FsnrHNuXSDyo=
|
||||||
github.com/ericlagergren/aegis v0.0.0-20250325060835-cd0defd64358/go.mod h1:hkIFzoiIPZYxdFOOLyDho59b7SrDfo+w3h+yWdlg45I=
|
github.com/ericlagergren/aegis v0.0.0-20250325060835-cd0defd64358/go.mod h1:hkIFzoiIPZYxdFOOLyDho59b7SrDfo+w3h+yWdlg45I=
|
||||||
github.com/ericlagergren/polyval v0.0.0-20220411101811-e25bc10ba391 h1:8j2RH289RJplhA6WfdaPqzg1MjH2K8wX5e0uhAxrw2g=
|
github.com/ericlagergren/polyval v0.0.0-20220411101811-e25bc10ba391 h1:8j2RH289RJplhA6WfdaPqzg1MjH2K8wX5e0uhAxrw2g=
|
||||||
@@ -55,8 +55,8 @@ github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
|
|||||||
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||||
github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
|
github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
|
||||||
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
|
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
|
||||||
github.com/gofrs/uuid/v5 v5.3.2 h1:2jfO8j3XgSwlz/wHqemAEugfnTlikAYHhnqQ8Xh4fE0=
|
github.com/gofrs/uuid/v5 v5.4.0 h1:EfbpCTjqMuGyq5ZJwxqzn3Cbr2d0rUZU7v5ycAk/e/0=
|
||||||
github.com/gofrs/uuid/v5 v5.3.2/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
|
github.com/gofrs/uuid/v5 v5.4.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
|
||||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||||
@@ -90,12 +90,12 @@ github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/
|
|||||||
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
|
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
|
||||||
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
|
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
|
||||||
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
|
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
|
||||||
github.com/metacubex/amneziawg-go v0.0.0-20250902133113-a7f637c14281 h1:09EM0sOLb2kfL0KETGhHujsBLB5iy5U/2yHRHsxf/pI=
|
github.com/metacubex/amneziawg-go v0.0.0-20251104174305-5a0e9f7e361d h1:vAJ0ZT4aO803F1uw2roIA9yH7Sxzox34tVVyye1bz6c=
|
||||||
github.com/metacubex/amneziawg-go v0.0.0-20250902133113-a7f637c14281/go.mod h1:MsM/5czONyXMJ3PRr5DbQ4O/BxzAnJWOIcJdLzW6qHY=
|
github.com/metacubex/amneziawg-go v0.0.0-20251104174305-5a0e9f7e361d/go.mod h1:MsM/5czONyXMJ3PRr5DbQ4O/BxzAnJWOIcJdLzW6qHY=
|
||||||
github.com/metacubex/ascon v0.1.0 h1:6ZWxmXYszT1XXtwkf6nxfFhc/OTtQ9R3Vyj1jN32lGM=
|
github.com/metacubex/ascon v0.1.0 h1:6ZWxmXYszT1XXtwkf6nxfFhc/OTtQ9R3Vyj1jN32lGM=
|
||||||
github.com/metacubex/ascon v0.1.0/go.mod h1:eV5oim4cVPPdEL8/EYaTZ0iIKARH9pnhAK/fcT5Kacc=
|
github.com/metacubex/ascon v0.1.0/go.mod h1:eV5oim4cVPPdEL8/EYaTZ0iIKARH9pnhAK/fcT5Kacc=
|
||||||
github.com/metacubex/bart v0.24.0 h1:EyNiPeVOlg0joSHTzi5oentI0j5M89utUq/5dd76pWM=
|
github.com/metacubex/bart v0.26.0 h1:d/bBTvVatfVWGfQbiDpYKI1bXUJgjaabB2KpK1Tnk6w=
|
||||||
github.com/metacubex/bart v0.24.0/go.mod h1:DCcyfP4MC+Zy7sLK7XeGuMw+P5K9mIRsYOBgiE8icsI=
|
github.com/metacubex/bart v0.26.0/go.mod h1:DCcyfP4MC+Zy7sLK7XeGuMw+P5K9mIRsYOBgiE8icsI=
|
||||||
github.com/metacubex/bbolt v0.0.0-20250725135710-010dbbbb7a5b h1:j7dadXD8I2KTmMt8jg1JcaP1ANL3JEObJPdANKcSYPY=
|
github.com/metacubex/bbolt v0.0.0-20250725135710-010dbbbb7a5b h1:j7dadXD8I2KTmMt8jg1JcaP1ANL3JEObJPdANKcSYPY=
|
||||||
github.com/metacubex/bbolt v0.0.0-20250725135710-010dbbbb7a5b/go.mod h1:+WmP0VJZDkDszvpa83HzfUp6QzARl/IKkMorH4+nODw=
|
github.com/metacubex/bbolt v0.0.0-20250725135710-010dbbbb7a5b/go.mod h1:+WmP0VJZDkDszvpa83HzfUp6QzARl/IKkMorH4+nODw=
|
||||||
github.com/metacubex/blake3 v0.1.0 h1:KGnjh/56REO7U+cgZA8dnBhxdP7jByrG7hTP+bu6cqY=
|
github.com/metacubex/blake3 v0.1.0 h1:KGnjh/56REO7U+cgZA8dnBhxdP7jByrG7hTP+bu6cqY=
|
||||||
@@ -108,12 +108,12 @@ github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759 h1:cjd4biTvO
|
|||||||
github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759/go.mod h1:UHOv2xu+RIgLwpXca7TLrXleEd4oR3sPatW6IF8wU88=
|
github.com/metacubex/gopacket v1.1.20-0.20230608035415-7e2f98a3e759/go.mod h1:UHOv2xu+RIgLwpXca7TLrXleEd4oR3sPatW6IF8wU88=
|
||||||
github.com/metacubex/gvisor v0.0.0-20250919004547-6122b699a301 h1:N5GExQJqYAH3gOCshpp2u/J3CtNYzMctmlb0xK9wtbQ=
|
github.com/metacubex/gvisor v0.0.0-20250919004547-6122b699a301 h1:N5GExQJqYAH3gOCshpp2u/J3CtNYzMctmlb0xK9wtbQ=
|
||||||
github.com/metacubex/gvisor v0.0.0-20250919004547-6122b699a301/go.mod h1:8LpS0IJW1VmWzUm3ylb0e2SK5QDm5lO/2qwWLZgRpBU=
|
github.com/metacubex/gvisor v0.0.0-20250919004547-6122b699a301/go.mod h1:8LpS0IJW1VmWzUm3ylb0e2SK5QDm5lO/2qwWLZgRpBU=
|
||||||
github.com/metacubex/kcp-go v0.0.0-20251007183319-0df1aec1639a h1:5vdk2pI71itLBT2mpyNExM1UKZ+2mG7MVC+ZARpRXmg=
|
github.com/metacubex/kcp-go v0.0.0-20251105084629-8c93f4bf37be h1:Y7SigZIqfv/+RIA/D7R6EbB9p+brPRoGOM6zobSmRIM=
|
||||||
github.com/metacubex/kcp-go v0.0.0-20251007183319-0df1aec1639a/go.mod h1:HIJZW4QMhbBqXuqC1ly6Hn0TEYT2SzRw58ns1yGhXTs=
|
github.com/metacubex/kcp-go v0.0.0-20251105084629-8c93f4bf37be/go.mod h1:HIJZW4QMhbBqXuqC1ly6Hn0TEYT2SzRw58ns1yGhXTs=
|
||||||
github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793 h1:1Qpuy+sU3DmyX9HwI+CrBT/oLNJngvBorR2RbajJcqo=
|
github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793 h1:1Qpuy+sU3DmyX9HwI+CrBT/oLNJngvBorR2RbajJcqo=
|
||||||
github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793/go.mod h1:RjRNb4G52yAgfR+Oe/kp9G4PJJ97Fnj89eY1BFO3YyA=
|
github.com/metacubex/nftables v0.0.0-20250503052935-30a69ab87793/go.mod h1:RjRNb4G52yAgfR+Oe/kp9G4PJJ97Fnj89eY1BFO3YyA=
|
||||||
github.com/metacubex/quic-go v0.55.1-0.20251004050223-450bd9e32033 h1:LEzvR5AmHEatqE6IWgMBUJHnaiz9VJfZeDGOiHFuWZU=
|
github.com/metacubex/quic-go v0.55.1-0.20251024060151-bd465f127128 h1:I1uvJl206/HbkzEAZpLgGkZgUveOZb+P+6oTUj7dN+o=
|
||||||
github.com/metacubex/quic-go v0.55.1-0.20251004050223-450bd9e32033/go.mod h1:1lktQFtCD17FZliVypbrDHwbsFSsmz2xz2TRXydvB5c=
|
github.com/metacubex/quic-go v0.55.1-0.20251024060151-bd465f127128/go.mod h1:1lktQFtCD17FZliVypbrDHwbsFSsmz2xz2TRXydvB5c=
|
||||||
github.com/metacubex/randv2 v0.2.0 h1:uP38uBvV2SxYfLj53kuvAjbND4RUDfFJjwr4UigMiLs=
|
github.com/metacubex/randv2 v0.2.0 h1:uP38uBvV2SxYfLj53kuvAjbND4RUDfFJjwr4UigMiLs=
|
||||||
github.com/metacubex/randv2 v0.2.0/go.mod h1:kFi2SzrQ5WuneuoLLCMkABtiBu6VRrMrWFqSPyj2cxY=
|
github.com/metacubex/randv2 v0.2.0/go.mod h1:kFi2SzrQ5WuneuoLLCMkABtiBu6VRrMrWFqSPyj2cxY=
|
||||||
github.com/metacubex/restls-client-go v0.1.7 h1:eCwiXCTQb5WJu9IlgYvDBA1OgrINv58dEe7hcN5H15k=
|
github.com/metacubex/restls-client-go v0.1.7 h1:eCwiXCTQb5WJu9IlgYvDBA1OgrINv58dEe7hcN5H15k=
|
||||||
@@ -131,18 +131,18 @@ github.com/metacubex/sing-shadowsocks2 v0.2.7 h1:hSuuc0YpsfiqYqt1o+fP4m34BQz4e6w
|
|||||||
github.com/metacubex/sing-shadowsocks2 v0.2.7/go.mod h1:vOEbfKC60txi0ca+yUlqEwOGc3Obl6cnSgx9Gf45KjE=
|
github.com/metacubex/sing-shadowsocks2 v0.2.7/go.mod h1:vOEbfKC60txi0ca+yUlqEwOGc3Obl6cnSgx9Gf45KjE=
|
||||||
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2 h1:gXU+MYPm7Wme3/OAY2FFzVq9d9GxPHOqu5AQfg/ddhI=
|
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2 h1:gXU+MYPm7Wme3/OAY2FFzVq9d9GxPHOqu5AQfg/ddhI=
|
||||||
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2/go.mod h1:mbfboaXauKJNIHJYxQRa+NJs4JU9NZfkA+I33dS2+9E=
|
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2/go.mod h1:mbfboaXauKJNIHJYxQRa+NJs4JU9NZfkA+I33dS2+9E=
|
||||||
github.com/metacubex/sing-tun v0.4.8 h1:3PyiUKWXYi37yHptXskzL1723O3OUdyt0Aej4XHVikM=
|
github.com/metacubex/sing-tun v0.4.9 h1:jY0Yyt8nnN3yQRN/jTxgqNCmGi1dsFdxdIi7pQUlVVU=
|
||||||
github.com/metacubex/sing-tun v0.4.8/go.mod h1:L/TjQY5JEGy8nvsuYmy/XgMFMCPiF0+AWSFCYfS6r9w=
|
github.com/metacubex/sing-tun v0.4.9/go.mod h1:L/TjQY5JEGy8nvsuYmy/XgMFMCPiF0+AWSFCYfS6r9w=
|
||||||
github.com/metacubex/sing-vmess v0.2.4 h1:Tx6AGgCiEf400E/xyDuYyafsel6sGbR8oF7RkAaus6I=
|
github.com/metacubex/sing-vmess v0.2.4 h1:Tx6AGgCiEf400E/xyDuYyafsel6sGbR8oF7RkAaus6I=
|
||||||
github.com/metacubex/sing-vmess v0.2.4/go.mod h1:21R5R1u90uUvBQF0owoooEu96/SAYYD56nDrwm6nFaM=
|
github.com/metacubex/sing-vmess v0.2.4/go.mod h1:21R5R1u90uUvBQF0owoooEu96/SAYYD56nDrwm6nFaM=
|
||||||
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f h1:Sr/DYKYofKHKc4GF3qkRGNuj6XA6c0eqPgEDN+VAsYU=
|
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f h1:Sr/DYKYofKHKc4GF3qkRGNuj6XA6c0eqPgEDN+VAsYU=
|
||||||
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f/go.mod h1:jpAkVLPnCpGSfNyVmj6Cq4YbuZsFepm/Dc+9BAOcR80=
|
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f/go.mod h1:jpAkVLPnCpGSfNyVmj6Cq4YbuZsFepm/Dc+9BAOcR80=
|
||||||
github.com/metacubex/smux v0.0.0-20250922175018-15c9a6a78719 h1:T6qCCfolRDAVJKeaPW/mXwNLjnlo65AYN7WS2jrBNaM=
|
github.com/metacubex/smux v0.0.0-20250922175018-15c9a6a78719 h1:T6qCCfolRDAVJKeaPW/mXwNLjnlo65AYN7WS2jrBNaM=
|
||||||
github.com/metacubex/smux v0.0.0-20250922175018-15c9a6a78719/go.mod h1:4bPD8HWx9jPJ9aE4uadgyN7D1/Wz3KmPy+vale8sKLE=
|
github.com/metacubex/smux v0.0.0-20250922175018-15c9a6a78719/go.mod h1:4bPD8HWx9jPJ9aE4uadgyN7D1/Wz3KmPy+vale8sKLE=
|
||||||
github.com/metacubex/tfo-go v0.0.0-20250921095601-b102db4216c0 h1:Ui+/2s5Qz0lSnDUBmEL12M5Oi/PzvFxGTNohm8ZcsmE=
|
github.com/metacubex/tfo-go v0.0.0-20251024101424-368b42b59148 h1:Zd0QqciLIhv9MKbGKTPEgN8WUFsgQGA1WJBy6spEnVU=
|
||||||
github.com/metacubex/tfo-go v0.0.0-20250921095601-b102db4216c0/go.mod h1:l9oLnLoEXyGZ5RVLsh7QCC5XsouTUyKk4F2nLm2DHLw=
|
github.com/metacubex/tfo-go v0.0.0-20251024101424-368b42b59148/go.mod h1:l9oLnLoEXyGZ5RVLsh7QCC5XsouTUyKk4F2nLm2DHLw=
|
||||||
github.com/metacubex/utls v1.8.2 h1:d7KalMZ5hnOJ6lThMz8Ykd+5dvmXH3Eoeyfv2jUuG3w=
|
github.com/metacubex/utls v1.8.3 h1:0m/yCxm3SK6kWve2lKiFb1pue1wHitJ8sQQD4Ikqde4=
|
||||||
github.com/metacubex/utls v1.8.2/go.mod h1:kncGGVhFaoGn5M3pFe3SXhZCzsbCJayNOH4UEqTKTko=
|
github.com/metacubex/utls v1.8.3/go.mod h1:kncGGVhFaoGn5M3pFe3SXhZCzsbCJayNOH4UEqTKTko=
|
||||||
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f h1:FGBPRb1zUabhPhDrlKEjQ9lgIwQ6cHL4x8M9lrERhbk=
|
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f h1:FGBPRb1zUabhPhDrlKEjQ9lgIwQ6cHL4x8M9lrERhbk=
|
||||||
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f/go.mod h1:oPGcV994OGJedmmxrcK9+ni7jUEMGhR+uVQAdaduIP4=
|
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f/go.mod h1:oPGcV994OGJedmmxrcK9+ni7jUEMGhR+uVQAdaduIP4=
|
||||||
github.com/metacubex/yamux v0.0.0-20250918083631-dd5f17c0be49 h1:lhlqpYHopuTLx9xQt22kSA9HtnyTDmk5XjjQVCGHe2E=
|
github.com/metacubex/yamux v0.0.0-20250918083631-dd5f17c0be49 h1:lhlqpYHopuTLx9xQt22kSA9HtnyTDmk5XjjQVCGHe2E=
|
||||||
@@ -175,8 +175,8 @@ github.com/sagernet/cors v1.2.1 h1:Cv5Z8y9YSD6Gm+qSpNrL3LO4lD3eQVvbFYJSG7JCMHQ=
|
|||||||
github.com/sagernet/cors v1.2.1/go.mod h1:O64VyOjjhrkLmQIjF4KGRrJO/5dVXFdpEmCW/eISRAI=
|
github.com/sagernet/cors v1.2.1/go.mod h1:O64VyOjjhrkLmQIjF4KGRrJO/5dVXFdpEmCW/eISRAI=
|
||||||
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a h1:ObwtHN2VpqE0ZNjr6sGeT00J8uU7JF4cNUdb44/Duis=
|
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a h1:ObwtHN2VpqE0ZNjr6sGeT00J8uU7JF4cNUdb44/Duis=
|
||||||
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM=
|
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM=
|
||||||
github.com/samber/lo v1.51.0 h1:kysRYLbHy/MB7kQZf5DSN50JHmMsNEdeY24VzJFu7wI=
|
github.com/samber/lo v1.52.0 h1:Rvi+3BFHES3A8meP33VPAxiBZX/Aws5RxrschYGjomw=
|
||||||
github.com/samber/lo v1.51.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
|
github.com/samber/lo v1.52.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
|
||||||
github.com/sina-ghaderi/poly1305 v0.0.0-20220724002748-c5926b03988b h1:rXHg9GrUEtWZhEkrykicdND3VPjlVbYiLdX9J7gimS8=
|
github.com/sina-ghaderi/poly1305 v0.0.0-20220724002748-c5926b03988b h1:rXHg9GrUEtWZhEkrykicdND3VPjlVbYiLdX9J7gimS8=
|
||||||
github.com/sina-ghaderi/poly1305 v0.0.0-20220724002748-c5926b03988b/go.mod h1:X7qrxNQViEaAN9LNZOPl9PfvQtp3V3c7LTo0dvGi0fM=
|
github.com/sina-ghaderi/poly1305 v0.0.0-20220724002748-c5926b03988b/go.mod h1:X7qrxNQViEaAN9LNZOPl9PfvQtp3V3c7LTo0dvGi0fM=
|
||||||
github.com/sina-ghaderi/rabaead v0.0.0-20220730151906-ab6e06b96e8c h1:DjKMC30y6yjG3IxDaeAj3PCoRr+IsO+bzyT+Se2m2Hk=
|
github.com/sina-ghaderi/rabaead v0.0.0-20220730151906-ab6e06b96e8c h1:DjKMC30y6yjG3IxDaeAj3PCoRr+IsO+bzyT+Se2m2Hk=
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -39,7 +39,7 @@ import (
|
|||||||
"github.com/metacubex/mihomo/listener/inner"
|
"github.com/metacubex/mihomo/listener/inner"
|
||||||
"github.com/metacubex/mihomo/listener/tproxy"
|
"github.com/metacubex/mihomo/listener/tproxy"
|
||||||
"github.com/metacubex/mihomo/log"
|
"github.com/metacubex/mihomo/log"
|
||||||
"github.com/metacubex/mihomo/ntp"
|
"github.com/metacubex/mihomo/ntp/ntp"
|
||||||
"github.com/metacubex/mihomo/tunnel"
|
"github.com/metacubex/mihomo/tunnel"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -247,10 +247,11 @@ func updateDNS(c *config.DNS, generalIPv6 bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipv6 := c.IPv6 && generalIPv6
|
||||||
r := dns.NewResolver(dns.Config{
|
r := dns.NewResolver(dns.Config{
|
||||||
Main: c.NameServer,
|
Main: c.NameServer,
|
||||||
Fallback: c.Fallback,
|
Fallback: c.Fallback,
|
||||||
IPv6: c.IPv6 && generalIPv6,
|
IPv6: ipv6,
|
||||||
IPv6Timeout: c.IPv6Timeout,
|
IPv6Timeout: c.IPv6Timeout,
|
||||||
FallbackIPFilter: c.FallbackIPFilter,
|
FallbackIPFilter: c.FallbackIPFilter,
|
||||||
FallbackDomainFilter: c.FallbackDomainFilter,
|
FallbackDomainFilter: c.FallbackDomainFilter,
|
||||||
@@ -263,9 +264,12 @@ func updateDNS(c *config.DNS, generalIPv6 bool) {
|
|||||||
CacheMaxSize: c.CacheMaxSize,
|
CacheMaxSize: c.CacheMaxSize,
|
||||||
})
|
})
|
||||||
m := dns.NewEnhancer(dns.EnhancerConfig{
|
m := dns.NewEnhancer(dns.EnhancerConfig{
|
||||||
EnhancedMode: c.EnhancedMode,
|
IPv6: ipv6,
|
||||||
Pool: c.FakeIPRange,
|
EnhancedMode: c.EnhancedMode,
|
||||||
UseHosts: c.UseHosts,
|
FakeIPPool: c.FakeIPPool,
|
||||||
|
FakeIPPool6: c.FakeIPPool6,
|
||||||
|
FakeIPSkipper: c.FakeIPSkipper,
|
||||||
|
UseHosts: c.UseHosts,
|
||||||
})
|
})
|
||||||
|
|
||||||
// reuse cache of old host mapper
|
// reuse cache of old host mapper
|
||||||
@@ -299,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)
|
||||||
@@ -318,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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"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/hub/executor"
|
"github.com/metacubex/mihomo/hub/executor"
|
||||||
P "github.com/metacubex/mihomo/listener"
|
"github.com/metacubex/mihomo/listener"
|
||||||
LC "github.com/metacubex/mihomo/listener/config"
|
LC "github.com/metacubex/mihomo/listener/config"
|
||||||
"github.com/metacubex/mihomo/log"
|
"github.com/metacubex/mihomo/log"
|
||||||
"github.com/metacubex/mihomo/tunnel"
|
"github.com/metacubex/mihomo/tunnel"
|
||||||
@@ -306,7 +306,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if general.AllowLan != nil {
|
if general.AllowLan != nil {
|
||||||
P.SetAllowLan(*general.AllowLan)
|
listener.SetAllowLan(*general.AllowLan)
|
||||||
}
|
}
|
||||||
|
|
||||||
if general.SkipAuthPrefixes != nil {
|
if general.SkipAuthPrefixes != nil {
|
||||||
@@ -322,7 +322,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if general.BindAddress != nil {
|
if general.BindAddress != nil {
|
||||||
P.SetBindAddress(*general.BindAddress)
|
listener.SetBindAddress(*general.BindAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
if general.Sniffing != nil {
|
if general.Sniffing != nil {
|
||||||
@@ -337,17 +337,17 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
|||||||
dialer.DefaultInterface.Store(*general.InterfaceName)
|
dialer.DefaultInterface.Store(*general.InterfaceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
ports := P.GetPorts()
|
ports := listener.GetPorts()
|
||||||
|
|
||||||
P.ReCreateHTTP(pointerOrDefault(general.Port, ports.Port), tunnel.Tunnel)
|
listener.ReCreateHTTP(pointerOrDefault(general.Port, ports.Port), tunnel.Tunnel)
|
||||||
P.ReCreateSocks(pointerOrDefault(general.SocksPort, ports.SocksPort), tunnel.Tunnel)
|
listener.ReCreateSocks(pointerOrDefault(general.SocksPort, ports.SocksPort), tunnel.Tunnel)
|
||||||
P.ReCreateRedir(pointerOrDefault(general.RedirPort, ports.RedirPort), tunnel.Tunnel)
|
listener.ReCreateRedir(pointerOrDefault(general.RedirPort, ports.RedirPort), tunnel.Tunnel)
|
||||||
P.ReCreateTProxy(pointerOrDefault(general.TProxyPort, ports.TProxyPort), tunnel.Tunnel)
|
listener.ReCreateTProxy(pointerOrDefault(general.TProxyPort, ports.TProxyPort), tunnel.Tunnel)
|
||||||
P.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tunnel.Tunnel)
|
listener.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tunnel.Tunnel)
|
||||||
P.ReCreateTun(pointerOrDefaultTun(general.Tun, P.LastTunConf), tunnel.Tunnel)
|
listener.ReCreateTun(pointerOrDefaultTun(general.Tun, listener.LastTunConf), tunnel.Tunnel)
|
||||||
P.ReCreateShadowSocks(pointerOrDefault(general.ShadowSocksConfig, ports.ShadowSocksConfig), tunnel.Tunnel)
|
listener.ReCreateShadowSocks(pointerOrDefault(general.ShadowSocksConfig, ports.ShadowSocksConfig), tunnel.Tunnel)
|
||||||
P.ReCreateVmess(pointerOrDefault(general.VmessConfig, ports.VmessConfig), tunnel.Tunnel)
|
listener.ReCreateVmess(pointerOrDefault(general.VmessConfig, ports.VmessConfig), tunnel.Tunnel)
|
||||||
P.ReCreateTuic(pointerOrDefaultTuicServer(general.TuicServer, P.LastTuicConf), tunnel.Tunnel)
|
listener.ReCreateTuic(pointerOrDefaultTuicServer(general.TuicServer, listener.LastTuicConf), tunnel.Tunnel)
|
||||||
|
|
||||||
if general.Mode != nil {
|
if general.Mode != nil {
|
||||||
tunnel.SetMode(*general.Mode)
|
tunnel.SetMode(*general.Mode)
|
||||||
|
|||||||
@@ -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()))
|
||||||
|
|||||||
181
listener/inbound/mieru.go
Normal file
181
listener/inbound/mieru.go
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
package inbound
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/metacubex/mihomo/adapter/inbound"
|
||||||
|
"github.com/metacubex/mihomo/common/utils"
|
||||||
|
C "github.com/metacubex/mihomo/constant"
|
||||||
|
"github.com/metacubex/mihomo/listener/mieru"
|
||||||
|
"github.com/metacubex/mihomo/log"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
|
mieruserver "github.com/enfein/mieru/v3/apis/server"
|
||||||
|
mierupb "github.com/enfein/mieru/v3/pkg/appctl/appctlpb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Mieru struct {
|
||||||
|
*Base
|
||||||
|
option *MieruOption
|
||||||
|
server mieruserver.Server
|
||||||
|
mu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
type MieruOption struct {
|
||||||
|
BaseOption
|
||||||
|
Transport string `inbound:"transport"`
|
||||||
|
Users map[string]string `inbound:"users"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type mieruListenerFactory struct{}
|
||||||
|
|
||||||
|
func (mieruListenerFactory) Listen(ctx context.Context, network, address string) (net.Listener, error) {
|
||||||
|
return inbound.ListenContext(ctx, network, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mieruListenerFactory) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error) {
|
||||||
|
return inbound.ListenPacketContext(ctx, network, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMieru(option *MieruOption) (*Mieru, error) {
|
||||||
|
base, err := NewBase(&option.BaseOption)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
config, err := buildMieruServerConfig(option, base.ports)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to build mieru server config: %w", err)
|
||||||
|
}
|
||||||
|
s := mieruserver.NewServer()
|
||||||
|
if err := s.Store(config); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to store mieru server config: %w", err)
|
||||||
|
}
|
||||||
|
// Server is started lazily when Listen() is called for the first time.
|
||||||
|
return &Mieru{
|
||||||
|
Base: base,
|
||||||
|
option: option,
|
||||||
|
server: s,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mieru) Config() C.InboundConfig {
|
||||||
|
return m.option
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mieru) Listen(tunnel C.Tunnel) error {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if !m.server.IsRunning() {
|
||||||
|
if err := m.server.Start(); err != nil {
|
||||||
|
return fmt.Errorf("failed to start mieru server: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
additions := m.config.Additions()
|
||||||
|
if len(additions) == 0 {
|
||||||
|
additions = []inbound.Addition{
|
||||||
|
inbound.WithInName("DEFAULT-MIERU"),
|
||||||
|
inbound.WithSpecialRules(""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
c, req, err := m.server.Accept()
|
||||||
|
if err != nil {
|
||||||
|
if !m.server.IsRunning() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
go mieru.Handle(c, tunnel, req, additions...)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
log.Infoln("Mieru[%s] proxy listening at: %s", m.Name(), m.Address())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mieru) Close() error {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if m.server.IsRunning() {
|
||||||
|
return m.server.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ C.InboundListener = (*Mieru)(nil)
|
||||||
|
|
||||||
|
func (o MieruOption) Equal(config C.InboundConfig) bool {
|
||||||
|
return optionToString(o) == optionToString(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildMieruServerConfig(option *MieruOption, ports utils.IntRanges[uint16]) (*mieruserver.ServerConfig, error) {
|
||||||
|
if err := validateMieruOption(option); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to validate mieru option: %w", err)
|
||||||
|
}
|
||||||
|
if len(ports) == 0 {
|
||||||
|
return nil, fmt.Errorf("port is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
var transportProtocol *mierupb.TransportProtocol
|
||||||
|
switch option.Transport {
|
||||||
|
case "TCP":
|
||||||
|
transportProtocol = mierupb.TransportProtocol_TCP.Enum()
|
||||||
|
case "UDP":
|
||||||
|
transportProtocol = mierupb.TransportProtocol_UDP.Enum()
|
||||||
|
}
|
||||||
|
var portBindings []*mierupb.PortBinding
|
||||||
|
for _, portRange := range ports {
|
||||||
|
if portRange.Start() == portRange.End() {
|
||||||
|
portBindings = append(portBindings, &mierupb.PortBinding{
|
||||||
|
Port: proto.Int32(int32(portRange.Start())),
|
||||||
|
Protocol: transportProtocol,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
portBindings = append(portBindings, &mierupb.PortBinding{
|
||||||
|
PortRange: proto.String(fmt.Sprintf("%d-%d", portRange.Start(), portRange.End())),
|
||||||
|
Protocol: transportProtocol,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var users []*mierupb.User
|
||||||
|
for username, password := range option.Users {
|
||||||
|
users = append(users, &mierupb.User{
|
||||||
|
Name: proto.String(username),
|
||||||
|
Password: proto.String(password),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &mieruserver.ServerConfig{
|
||||||
|
Config: &mierupb.ServerConfig{
|
||||||
|
PortBindings: portBindings,
|
||||||
|
Users: users,
|
||||||
|
},
|
||||||
|
StreamListenerFactory: mieruListenerFactory{},
|
||||||
|
PacketListenerFactory: mieruListenerFactory{},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateMieruOption(option *MieruOption) error {
|
||||||
|
if option.Transport != "TCP" && option.Transport != "UDP" {
|
||||||
|
return fmt.Errorf("transport must be TCP or UDP")
|
||||||
|
}
|
||||||
|
if len(option.Users) == 0 {
|
||||||
|
return fmt.Errorf("users is empty")
|
||||||
|
}
|
||||||
|
for username, password := range option.Users {
|
||||||
|
if username == "" {
|
||||||
|
return fmt.Errorf("username is empty")
|
||||||
|
}
|
||||||
|
if password == "" {
|
||||||
|
return fmt.Errorf("password is empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
212
listener/inbound/mieru_test.go
Normal file
212
listener/inbound/mieru_test.go
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
package inbound_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"net/netip"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/metacubex/mihomo/adapter/outbound"
|
||||||
|
"github.com/metacubex/mihomo/listener/inbound"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewMieru(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
option *inbound.MieruOption
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "valid with port",
|
||||||
|
args: args{
|
||||||
|
option: &inbound.MieruOption{
|
||||||
|
BaseOption: inbound.BaseOption{
|
||||||
|
Port: "8080",
|
||||||
|
},
|
||||||
|
Transport: "TCP",
|
||||||
|
Users: map[string]string{"user": "pass"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "valid with port range",
|
||||||
|
args: args{
|
||||||
|
option: &inbound.MieruOption{
|
||||||
|
BaseOption: inbound.BaseOption{
|
||||||
|
Port: "8090-8099",
|
||||||
|
},
|
||||||
|
Transport: "UDP",
|
||||||
|
Users: map[string]string{"user": "pass"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "valid mix of port and port-range",
|
||||||
|
args: args{
|
||||||
|
option: &inbound.MieruOption{
|
||||||
|
BaseOption: inbound.BaseOption{
|
||||||
|
Port: "8080,8090-8099",
|
||||||
|
},
|
||||||
|
Transport: "TCP",
|
||||||
|
Users: map[string]string{"user": "pass"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid - no port",
|
||||||
|
args: args{
|
||||||
|
option: &inbound.MieruOption{
|
||||||
|
Transport: "TCP",
|
||||||
|
Users: map[string]string{"user": "pass"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid - transport",
|
||||||
|
args: args{
|
||||||
|
option: &inbound.MieruOption{
|
||||||
|
BaseOption: inbound.BaseOption{
|
||||||
|
Port: "8080",
|
||||||
|
},
|
||||||
|
Transport: "INVALID",
|
||||||
|
Users: map[string]string{"user": "pass"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid - no transport",
|
||||||
|
args: args{
|
||||||
|
option: &inbound.MieruOption{
|
||||||
|
BaseOption: inbound.BaseOption{
|
||||||
|
Port: "8080",
|
||||||
|
},
|
||||||
|
Users: map[string]string{"user": "pass"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid - no users",
|
||||||
|
args: args{
|
||||||
|
option: &inbound.MieruOption{
|
||||||
|
BaseOption: inbound.BaseOption{
|
||||||
|
Port: "8080",
|
||||||
|
},
|
||||||
|
Transport: "TCP",
|
||||||
|
Users: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid - empty username",
|
||||||
|
args: args{
|
||||||
|
option: &inbound.MieruOption{
|
||||||
|
BaseOption: inbound.BaseOption{
|
||||||
|
Port: "8080",
|
||||||
|
},
|
||||||
|
Transport: "TCP",
|
||||||
|
Users: map[string]string{"": "pass"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid - empty password",
|
||||||
|
args: args{
|
||||||
|
option: &inbound.MieruOption{
|
||||||
|
BaseOption: inbound.BaseOption{
|
||||||
|
Port: "8080",
|
||||||
|
},
|
||||||
|
Transport: "TCP",
|
||||||
|
Users: map[string]string{"user": ""},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := inbound.NewMieru(tt.args.option)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("NewMieru() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
got.Close()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInboundMieru(t *testing.T) {
|
||||||
|
t.Run("HANDSHAKE_STANDARD", func(t *testing.T) {
|
||||||
|
testInboundMieruTCP(t, "HANDSHAKE_STANDARD")
|
||||||
|
})
|
||||||
|
t.Run("HANDSHAKE_NO_WAIT", func(t *testing.T) {
|
||||||
|
testInboundMieruTCP(t, "HANDSHAKE_NO_WAIT")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInboundMieruTCP(t *testing.T, handshakeMode string) {
|
||||||
|
t.Parallel()
|
||||||
|
l, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
port := l.Addr().(*net.TCPAddr).Port
|
||||||
|
l.Close()
|
||||||
|
|
||||||
|
inboundOptions := inbound.MieruOption{
|
||||||
|
BaseOption: inbound.BaseOption{
|
||||||
|
NameStr: "mieru_inbound",
|
||||||
|
Listen: "127.0.0.1",
|
||||||
|
Port: strconv.Itoa(port),
|
||||||
|
},
|
||||||
|
Transport: "TCP",
|
||||||
|
Users: map[string]string{"test": "password"},
|
||||||
|
}
|
||||||
|
in, err := inbound.NewMieru(&inboundOptions)
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tunnel := NewHttpTestTunnel()
|
||||||
|
defer tunnel.Close()
|
||||||
|
|
||||||
|
err = in.Listen(tunnel)
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer in.Close()
|
||||||
|
|
||||||
|
addrPort, err := netip.ParseAddrPort(in.Address())
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
outboundOptions := outbound.MieruOption{
|
||||||
|
Name: "mieru_outbound",
|
||||||
|
Server: addrPort.Addr().String(),
|
||||||
|
Port: int(addrPort.Port()),
|
||||||
|
Transport: "TCP",
|
||||||
|
UserName: "test",
|
||||||
|
Password: "password",
|
||||||
|
HandshakeMode: handshakeMode,
|
||||||
|
}
|
||||||
|
out, err := outbound.NewMieru(outboundOptions)
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
tunnel.DoTest(t, out)
|
||||||
|
}
|
||||||
124
listener/mieru/server.go
Normal file
124
listener/mieru/server.go
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
package mieru
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/netip"
|
||||||
|
|
||||||
|
"github.com/metacubex/mihomo/adapter/inbound"
|
||||||
|
N "github.com/metacubex/mihomo/common/net"
|
||||||
|
C "github.com/metacubex/mihomo/constant"
|
||||||
|
"github.com/metacubex/mihomo/transport/socks5"
|
||||||
|
|
||||||
|
mierucommon "github.com/enfein/mieru/v3/apis/common"
|
||||||
|
mieruconstant "github.com/enfein/mieru/v3/apis/constant"
|
||||||
|
mierumodel "github.com/enfein/mieru/v3/apis/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Handle(conn net.Conn, tunnel C.Tunnel, request *mierumodel.Request, additions ...inbound.Addition) {
|
||||||
|
// Return a fake response to the client.
|
||||||
|
resp := &mierumodel.Response{
|
||||||
|
Reply: mieruconstant.Socks5ReplySuccess,
|
||||||
|
BindAddr: mierumodel.AddrSpec{
|
||||||
|
IP: net.IPv4zero,
|
||||||
|
Port: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := resp.WriteToSocks5(conn); err != nil {
|
||||||
|
conn.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the connection with tunnel.
|
||||||
|
metadata := mieruRequestToMetadata(request)
|
||||||
|
inbound.ApplyAdditions(&metadata, additions...)
|
||||||
|
switch metadata.NetWork {
|
||||||
|
case C.TCP:
|
||||||
|
tunnel.HandleTCPConn(conn, &metadata)
|
||||||
|
case C.UDP:
|
||||||
|
pc := mierucommon.NewPacketOverStreamTunnel(conn)
|
||||||
|
ep := N.NewEnhancePacketConn(pc)
|
||||||
|
for {
|
||||||
|
data, put, addr, err := ep.WaitReadFrom()
|
||||||
|
if err != nil {
|
||||||
|
if put != nil {
|
||||||
|
// Unresolved UDP packet, return buffer to the pool.
|
||||||
|
put()
|
||||||
|
}
|
||||||
|
// mieru returns EOF or ErrUnexpectedEOF when a session is closed.
|
||||||
|
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.ErrClosedPipe) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
target, payload, err := socks5.DecodeUDPPacket(data)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
packet := &packet{
|
||||||
|
pc: ep,
|
||||||
|
addr: addr,
|
||||||
|
payload: payload,
|
||||||
|
put: put,
|
||||||
|
}
|
||||||
|
tunnel.HandleUDPPacket(inbound.NewPacket(target, packet, C.MIERU, additions...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mieruRequestToMetadata(request *mierumodel.Request) C.Metadata {
|
||||||
|
m := C.Metadata{
|
||||||
|
DstPort: uint16(request.DstAddr.Port),
|
||||||
|
}
|
||||||
|
switch request.Command {
|
||||||
|
case mieruconstant.Socks5ConnectCmd:
|
||||||
|
m.NetWork = C.TCP
|
||||||
|
case mieruconstant.Socks5UDPAssociateCmd:
|
||||||
|
m.NetWork = C.UDP
|
||||||
|
}
|
||||||
|
if request.DstAddr.FQDN != "" {
|
||||||
|
m.Host = request.DstAddr.FQDN
|
||||||
|
} else if request.DstAddr.IP != nil {
|
||||||
|
m.DstIP, _ = netip.AddrFromSlice(request.DstAddr.IP)
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
type packet struct {
|
||||||
|
pc net.PacketConn
|
||||||
|
addr net.Addr // source (i.e. remote) IP & Port of the packet
|
||||||
|
payload []byte
|
||||||
|
put func()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ C.UDPPacket = (*packet)(nil)
|
||||||
|
var _ C.UDPPacketInAddr = (*packet)(nil)
|
||||||
|
|
||||||
|
func (c *packet) Data() []byte {
|
||||||
|
return c.payload
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *packet) WriteBack(b []byte, addr net.Addr) (n int, err error) {
|
||||||
|
packet, err := socks5.EncodeUDPPacket(socks5.ParseAddrToSocksAddr(addr), b)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return c.pc.WriteTo(packet, c.addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *packet) Drop() {
|
||||||
|
if c.put != nil {
|
||||||
|
c.put()
|
||||||
|
c.put = nil
|
||||||
|
}
|
||||||
|
c.payload = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *packet) LocalAddr() net.Addr {
|
||||||
|
return c.addr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *packet) InAddr() net.Addr {
|
||||||
|
return c.pc.LocalAddr()
|
||||||
|
}
|
||||||
@@ -127,6 +127,13 @@ func ParseListener(mapping map[string]any) (C.InboundListener, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
listener, err = IN.NewAnyTLS(anytlsOption)
|
listener, err = IN.NewAnyTLS(anytlsOption)
|
||||||
|
case "mieru":
|
||||||
|
mieruOption := &IN.MieruOption{}
|
||||||
|
err = decoder.Decode(mapping, mieruOption)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
listener, err = IN.NewMieru(mieruOption)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupport proxy type: %s", proxyType)
|
return nil, fmt.Errorf("unsupport proxy type: %s", proxyType)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ package ntp
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/component/dialer"
|
"github.com/metacubex/mihomo/component/dialer"
|
||||||
"github.com/metacubex/mihomo/component/proxydialer"
|
"github.com/metacubex/mihomo/component/proxydialer"
|
||||||
"github.com/metacubex/mihomo/log"
|
"github.com/metacubex/mihomo/log"
|
||||||
|
mihomoNtp "github.com/metacubex/mihomo/ntp"
|
||||||
|
|
||||||
M "github.com/metacubex/sing/common/metadata"
|
M "github.com/metacubex/sing/common/metadata"
|
||||||
"github.com/metacubex/sing/common/ntp"
|
"github.com/metacubex/sing/common/ntp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var globalSrv atomic.Pointer[Service]
|
var globalSrv *Service
|
||||||
var globalMu sync.Mutex
|
var globalMu sync.Mutex
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
@@ -23,21 +23,20 @@ type Service struct {
|
|||||||
ticker *time.Ticker
|
ticker *time.Ticker
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
offset atomic.Int64 // [time.Duration]
|
|
||||||
syncSystemTime bool
|
syncSystemTime bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReCreateNTPService(server string, interval time.Duration, dialerProxy string, syncSystemTime bool) {
|
func ReCreateNTPService(server string, interval time.Duration, dialerProxy string, syncSystemTime bool) {
|
||||||
globalMu.Lock()
|
globalMu.Lock()
|
||||||
defer globalMu.Unlock()
|
defer globalMu.Unlock()
|
||||||
if service := globalSrv.Swap(nil); service != nil {
|
if globalSrv != nil {
|
||||||
service.Stop()
|
globalSrv.Stop()
|
||||||
}
|
}
|
||||||
if server == "" || interval <= 0 {
|
if server == "" || interval <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
service := &Service{
|
globalSrv = &Service{
|
||||||
server: M.ParseSocksaddr(server),
|
server: M.ParseSocksaddr(server),
|
||||||
dialer: proxydialer.NewByNameSingDialer(dialerProxy, dialer.NewDialer()),
|
dialer: proxydialer.NewByNameSingDialer(dialerProxy, dialer.NewDialer()),
|
||||||
ticker: time.NewTicker(interval * time.Minute),
|
ticker: time.NewTicker(interval * time.Minute),
|
||||||
@@ -45,8 +44,7 @@ func ReCreateNTPService(server string, interval time.Duration, dialerProxy strin
|
|||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
syncSystemTime: syncSystemTime,
|
syncSystemTime: syncSystemTime,
|
||||||
}
|
}
|
||||||
service.Start()
|
globalSrv.Start()
|
||||||
globalSrv.Store(service)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Service) Start() {
|
func (srv *Service) Start() {
|
||||||
@@ -59,10 +57,6 @@ func (srv *Service) Stop() {
|
|||||||
srv.cancel()
|
srv.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Service) Offset() time.Duration {
|
|
||||||
return time.Duration(srv.offset.Load())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (srv *Service) update() error {
|
func (srv *Service) update() error {
|
||||||
var response *ntp.Response
|
var response *ntp.Response
|
||||||
var err error
|
var err error
|
||||||
@@ -80,7 +74,7 @@ func (srv *Service) update() error {
|
|||||||
} else if offset < time.Duration(0) {
|
} else if offset < time.Duration(0) {
|
||||||
log.Infoln("System clock is behind NTP time by %s", -offset)
|
log.Infoln("System clock is behind NTP time by %s", -offset)
|
||||||
}
|
}
|
||||||
srv.offset.Store(int64(offset))
|
mihomoNtp.SetOffset(offset)
|
||||||
if srv.syncSystemTime {
|
if srv.syncSystemTime {
|
||||||
timeNow := response.Time
|
timeNow := response.Time
|
||||||
syncErr := setSystemTime(timeNow)
|
syncErr := setSystemTime(timeNow)
|
||||||
@@ -97,7 +91,7 @@ func (srv *Service) update() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Service) loopUpdate() {
|
func (srv *Service) loopUpdate() {
|
||||||
defer srv.offset.Store(0)
|
defer mihomoNtp.SetOffset(0)
|
||||||
defer srv.ticker.Stop()
|
defer srv.ticker.Stop()
|
||||||
for {
|
for {
|
||||||
err := srv.update()
|
err := srv.update()
|
||||||
@@ -111,13 +105,3 @@ func (srv *Service) loopUpdate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Now() time.Time {
|
|
||||||
now := time.Now()
|
|
||||||
if service := globalSrv.Load(); service != nil {
|
|
||||||
if offset := service.Offset(); offset.Abs() > 0 {
|
|
||||||
now = now.Add(offset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return now
|
|
||||||
}
|
|
||||||
28
ntp/time.go
Normal file
28
ntp/time.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// Package ntp provide time.Now
|
||||||
|
//
|
||||||
|
// DON'T import other package in mihomo to keep minimal internal dependencies
|
||||||
|
package ntp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"sync/atomic"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _offset atomic.Int64 // [time.Duration]
|
||||||
|
|
||||||
|
func SetOffset(offset time.Duration) {
|
||||||
|
_offset.Store(int64(offset))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetOffset() time.Duration {
|
||||||
|
return time.Duration(_offset.Load())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Now() time.Time {
|
||||||
|
now := time.Now()
|
||||||
|
if offset := GetOffset(); offset != 0 {
|
||||||
|
now = now.Add(offset)
|
||||||
|
}
|
||||||
|
return now
|
||||||
|
}
|
||||||
@@ -34,7 +34,7 @@ func ConvertToMrs(buf []byte, behavior P.RuleBehavior, format P.RuleFormat, w io
|
|||||||
}
|
}
|
||||||
|
|
||||||
var encoder *zstd.Encoder
|
var encoder *zstd.Encoder
|
||||||
encoder, err = zstd.NewWriter(w, zstd.WithEncoderLevel(zstd.SpeedBestCompression))
|
encoder, err = zstd.NewWriter(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,7 +183,11 @@ func (pc *PacketConn) WaitReadFrom() (data []byte, put func(), addr net.Addr, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
addr = destination.UDPAddr()
|
udpAddr := destination.UDPAddr()
|
||||||
|
if udpAddr == nil {
|
||||||
|
return nil, nil, nil, errors.New("parse addr error")
|
||||||
|
}
|
||||||
|
addr = udpAddr
|
||||||
|
|
||||||
data = pool.Get(pool.UDPBufferSize)
|
data = pool.Get(pool.UDPBufferSize)
|
||||||
put = func() {
|
put = func() {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ func SetCongestionController(quicConn *quic.Conn, cc string, cwnd int) {
|
|||||||
case "cubic":
|
case "cubic":
|
||||||
quicConn.SetCongestionControl(
|
quicConn.SetCongestionControl(
|
||||||
congestion.NewCubicSender(
|
congestion.NewCubicSender(
|
||||||
congestion.DefaultClock{},
|
|
||||||
congestion.GetInitialPacketSize(quicConn),
|
congestion.GetInitialPacketSize(quicConn),
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
@@ -29,7 +28,6 @@ func SetCongestionController(quicConn *quic.Conn, cc string, cwnd int) {
|
|||||||
case "new_reno":
|
case "new_reno":
|
||||||
quicConn.SetCongestionControl(
|
quicConn.SetCongestionControl(
|
||||||
congestion.NewCubicSender(
|
congestion.NewCubicSender(
|
||||||
congestion.DefaultClock{},
|
|
||||||
congestion.GetInitialPacketSize(quicConn),
|
congestion.GetInitialPacketSize(quicConn),
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
@@ -37,7 +35,6 @@ func SetCongestionController(quicConn *quic.Conn, cc string, cwnd int) {
|
|||||||
case "bbr_meta_v1":
|
case "bbr_meta_v1":
|
||||||
quicConn.SetCongestionControl(
|
quicConn.SetCongestionControl(
|
||||||
congestion.NewBBRSender(
|
congestion.NewBBRSender(
|
||||||
congestion.DefaultClock{},
|
|
||||||
congestion.GetInitialPacketSize(quicConn),
|
congestion.GetInitialPacketSize(quicConn),
|
||||||
c.ByteCount(cwnd)*congestion.InitialMaxDatagramSize,
|
c.ByteCount(cwnd)*congestion.InitialMaxDatagramSize,
|
||||||
congestion.DefaultBBRMaxCongestionWindow*congestion.InitialMaxDatagramSize,
|
congestion.DefaultBBRMaxCongestionWindow*congestion.InitialMaxDatagramSize,
|
||||||
@@ -48,7 +45,6 @@ func SetCongestionController(quicConn *quic.Conn, cc string, cwnd int) {
|
|||||||
case "bbr":
|
case "bbr":
|
||||||
quicConn.SetCongestionControl(
|
quicConn.SetCongestionControl(
|
||||||
congestionv2.NewBbrSender(
|
congestionv2.NewBbrSender(
|
||||||
congestionv2.DefaultClock{},
|
|
||||||
congestionv2.GetInitialPacketSize(quicConn),
|
congestionv2.GetInitialPacketSize(quicConn),
|
||||||
c.ByteCount(cwnd),
|
c.ByteCount(cwnd),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ const (
|
|||||||
|
|
||||||
type bbrSender struct {
|
type bbrSender struct {
|
||||||
mode bbrMode
|
mode bbrMode
|
||||||
clock Clock
|
|
||||||
rttStats congestion.RTTStatsProvider
|
rttStats congestion.RTTStatsProvider
|
||||||
bytesInFlight congestion.ByteCount
|
bytesInFlight congestion.ByteCount
|
||||||
// return total bytes of unacked packets.
|
// return total bytes of unacked packets.
|
||||||
@@ -232,14 +231,12 @@ type bbrSender struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewBBRSender(
|
func NewBBRSender(
|
||||||
clock Clock,
|
|
||||||
initialMaxDatagramSize,
|
initialMaxDatagramSize,
|
||||||
initialCongestionWindow,
|
initialCongestionWindow,
|
||||||
initialMaxCongestionWindow congestion.ByteCount,
|
initialMaxCongestionWindow congestion.ByteCount,
|
||||||
) *bbrSender {
|
) *bbrSender {
|
||||||
b := &bbrSender{
|
b := &bbrSender{
|
||||||
mode: STARTUP,
|
mode: STARTUP,
|
||||||
clock: clock,
|
|
||||||
sampler: NewBandwidthSampler(),
|
sampler: NewBandwidthSampler(),
|
||||||
maxBandwidth: NewWindowedFilter(int64(BandwidthWindowSize), MaxFilter),
|
maxBandwidth: NewWindowedFilter(int64(BandwidthWindowSize), MaxFilter),
|
||||||
maxAckHeight: NewWindowedFilter(int64(BandwidthWindowSize), MaxFilter),
|
maxAckHeight: NewWindowedFilter(int64(BandwidthWindowSize), MaxFilter),
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package congestion
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
// A Clock returns the current time
|
|
||||||
type Clock interface {
|
|
||||||
Now() time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultClock implements the Clock interface using the Go stdlib clock.
|
|
||||||
type DefaultClock struct{}
|
|
||||||
|
|
||||||
var _ Clock = DefaultClock{}
|
|
||||||
|
|
||||||
// Now gets the current time
|
|
||||||
func (DefaultClock) Now() time.Time {
|
|
||||||
return time.Now()
|
|
||||||
}
|
|
||||||
@@ -37,8 +37,6 @@ const betaLastMax float32 = 0.85
|
|||||||
|
|
||||||
// Cubic implements the cubic algorithm from TCP
|
// Cubic implements the cubic algorithm from TCP
|
||||||
type Cubic struct {
|
type Cubic struct {
|
||||||
clock Clock
|
|
||||||
|
|
||||||
// Number of connections to simulate.
|
// Number of connections to simulate.
|
||||||
numConnections int
|
numConnections int
|
||||||
|
|
||||||
@@ -67,9 +65,8 @@ type Cubic struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCubic returns a new Cubic instance
|
// NewCubic returns a new Cubic instance
|
||||||
func NewCubic(clock Clock) *Cubic {
|
func NewCubic() *Cubic {
|
||||||
c := &Cubic{
|
c := &Cubic{
|
||||||
clock: clock,
|
|
||||||
numConnections: defaultNumConnections,
|
numConnections: defaultNumConnections,
|
||||||
}
|
}
|
||||||
c.Reset()
|
c.Reset()
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ type cubicSender struct {
|
|||||||
rttStats congestion.RTTStatsProvider
|
rttStats congestion.RTTStatsProvider
|
||||||
cubic *Cubic
|
cubic *Cubic
|
||||||
pacer *pacer
|
pacer *pacer
|
||||||
clock Clock
|
|
||||||
|
|
||||||
reno bool
|
reno bool
|
||||||
|
|
||||||
@@ -61,12 +60,10 @@ var (
|
|||||||
|
|
||||||
// NewCubicSender makes a new cubic sender
|
// NewCubicSender makes a new cubic sender
|
||||||
func NewCubicSender(
|
func NewCubicSender(
|
||||||
clock Clock,
|
|
||||||
initialMaxDatagramSize congestion.ByteCount,
|
initialMaxDatagramSize congestion.ByteCount,
|
||||||
reno bool,
|
reno bool,
|
||||||
) *cubicSender {
|
) *cubicSender {
|
||||||
return newCubicSender(
|
return newCubicSender(
|
||||||
clock,
|
|
||||||
reno,
|
reno,
|
||||||
initialMaxDatagramSize,
|
initialMaxDatagramSize,
|
||||||
initialCongestionWindow*initialMaxDatagramSize,
|
initialCongestionWindow*initialMaxDatagramSize,
|
||||||
@@ -75,7 +72,6 @@ func NewCubicSender(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newCubicSender(
|
func newCubicSender(
|
||||||
clock Clock,
|
|
||||||
reno bool,
|
reno bool,
|
||||||
initialMaxDatagramSize,
|
initialMaxDatagramSize,
|
||||||
initialCongestionWindow,
|
initialCongestionWindow,
|
||||||
@@ -89,8 +85,7 @@ func newCubicSender(
|
|||||||
initialMaxCongestionWindow: initialMaxCongestionWindow,
|
initialMaxCongestionWindow: initialMaxCongestionWindow,
|
||||||
congestionWindow: initialCongestionWindow,
|
congestionWindow: initialCongestionWindow,
|
||||||
slowStartThreshold: MaxByteCount,
|
slowStartThreshold: MaxByteCount,
|
||||||
cubic: NewCubic(clock),
|
cubic: NewCubic(),
|
||||||
clock: clock,
|
|
||||||
reno: reno,
|
reno: reno,
|
||||||
maxDatagramSize: initialMaxDatagramSize,
|
maxDatagramSize: initialMaxDatagramSize,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ const (
|
|||||||
|
|
||||||
type bbrSender struct {
|
type bbrSender struct {
|
||||||
rttStats congestion.RTTStatsProvider
|
rttStats congestion.RTTStatsProvider
|
||||||
clock Clock
|
|
||||||
pacer *Pacer
|
pacer *Pacer
|
||||||
|
|
||||||
mode bbrMode
|
mode bbrMode
|
||||||
@@ -244,12 +243,10 @@ type bbrSender struct {
|
|||||||
var _ congestion.CongestionControl = &bbrSender{}
|
var _ congestion.CongestionControl = &bbrSender{}
|
||||||
|
|
||||||
func NewBbrSender(
|
func NewBbrSender(
|
||||||
clock Clock,
|
|
||||||
initialMaxDatagramSize congestion.ByteCount,
|
initialMaxDatagramSize congestion.ByteCount,
|
||||||
initialCongestionWindowPackets congestion.ByteCount,
|
initialCongestionWindowPackets congestion.ByteCount,
|
||||||
) *bbrSender {
|
) *bbrSender {
|
||||||
return newBbrSender(
|
return newBbrSender(
|
||||||
clock,
|
|
||||||
initialMaxDatagramSize,
|
initialMaxDatagramSize,
|
||||||
initialCongestionWindowPackets*initialMaxDatagramSize,
|
initialCongestionWindowPackets*initialMaxDatagramSize,
|
||||||
congestion.MaxCongestionWindowPackets*initialMaxDatagramSize,
|
congestion.MaxCongestionWindowPackets*initialMaxDatagramSize,
|
||||||
@@ -257,13 +254,11 @@ func NewBbrSender(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newBbrSender(
|
func newBbrSender(
|
||||||
clock Clock,
|
|
||||||
initialMaxDatagramSize,
|
initialMaxDatagramSize,
|
||||||
initialCongestionWindow,
|
initialCongestionWindow,
|
||||||
initialMaxCongestionWindow congestion.ByteCount,
|
initialMaxCongestionWindow congestion.ByteCount,
|
||||||
) *bbrSender {
|
) *bbrSender {
|
||||||
b := &bbrSender{
|
b := &bbrSender{
|
||||||
clock: clock,
|
|
||||||
mode: bbrModeStartup,
|
mode: bbrModeStartup,
|
||||||
sampler: newBandwidthSampler(roundTripCount(bandwidthWindowSize)),
|
sampler: newBandwidthSampler(roundTripCount(bandwidthWindowSize)),
|
||||||
lastSentPacket: invalidPacketNumber,
|
lastSentPacket: invalidPacketNumber,
|
||||||
@@ -297,7 +292,7 @@ func newBbrSender(
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
b.enterStartupMode(b.clock.Now())
|
b.enterStartupMode()
|
||||||
b.setHighCwndGain(derivedHighCWNDGain)
|
b.setHighCwndGain(derivedHighCWNDGain)
|
||||||
|
|
||||||
return b
|
return b
|
||||||
@@ -605,7 +600,7 @@ func (b *bbrSender) maybeUpdateMinRtt(now monotime.Time, sampleMinRtt time.Durat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Enters the STARTUP mode.
|
// Enters the STARTUP mode.
|
||||||
func (b *bbrSender) enterStartupMode(now monotime.Time) {
|
func (b *bbrSender) enterStartupMode() {
|
||||||
b.mode = bbrModeStartup
|
b.mode = bbrModeStartup
|
||||||
// b.maybeTraceStateChange(logging.CongestionStateStartup)
|
// b.maybeTraceStateChange(logging.CongestionStateStartup)
|
||||||
b.pacingGain = b.highGain
|
b.pacingGain = b.highGain
|
||||||
@@ -757,7 +752,7 @@ func (b *bbrSender) maybeEnterOrExitProbeRtt(now monotime.Time, isRoundStart, mi
|
|||||||
if now.Sub(b.exitProbeRttAt) >= 0 && b.probeRttRoundPassed {
|
if now.Sub(b.exitProbeRttAt) >= 0 && b.probeRttRoundPassed {
|
||||||
b.minRttTimestamp = now
|
b.minRttTimestamp = now
|
||||||
if !b.isAtFullBandwidth {
|
if !b.isAtFullBandwidth {
|
||||||
b.enterStartupMode(now)
|
b.enterStartupMode()
|
||||||
} else {
|
} else {
|
||||||
b.enterProbeBandwidthMode(now)
|
b.enterProbeBandwidthMode(now)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package congestion
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/metacubex/quic-go/monotime"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Clock returns the current time
|
|
||||||
type Clock interface {
|
|
||||||
Now() monotime.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultClock implements the Clock interface using the Go stdlib clock.
|
|
||||||
type DefaultClock struct{}
|
|
||||||
|
|
||||||
var _ Clock = DefaultClock{}
|
|
||||||
|
|
||||||
// Now gets the current time
|
|
||||||
func (DefaultClock) Now() monotime.Time {
|
|
||||||
return monotime.Now()
|
|
||||||
}
|
|
||||||
@@ -242,14 +242,26 @@ func (vc *Conn) WriteBuffer(buffer *buf.Buffer) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (vc *Conn) FrontHeadroom() int {
|
func (vc *Conn) FrontHeadroom() int {
|
||||||
|
fontHeadroom := PaddingHeaderLen - uuid.Size
|
||||||
if vc.readFilterUUID || vc.writeOnceUserUUID != nil {
|
if vc.readFilterUUID || vc.writeOnceUserUUID != nil {
|
||||||
return PaddingHeaderLen
|
fontHeadroom = PaddingHeaderLen
|
||||||
}
|
}
|
||||||
return PaddingHeaderLen - uuid.Size
|
if vc.writeFilterApplicationData { // The writer may be replaced, add the required value for vc.netConn
|
||||||
|
if abs := N.CalculateFrontHeadroom(vc.netConn) - N.CalculateFrontHeadroom(vc.Conn); abs > 0 {
|
||||||
|
fontHeadroom += abs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fontHeadroom
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vc *Conn) RearHeadroom() int {
|
func (vc *Conn) RearHeadroom() int {
|
||||||
return 500 + 900
|
rearHeadroom := 500 + 900
|
||||||
|
if vc.writeFilterApplicationData { // The writer may be replaced, add the required value for vc.netConn
|
||||||
|
if abs := N.CalculateRearHeadroom(vc.netConn) - N.CalculateRearHeadroom(vc.Conn); abs > 0 {
|
||||||
|
rearHeadroom += abs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rearHeadroom
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vc *Conn) NeedHandshake() bool {
|
func (vc *Conn) NeedHandshake() bool {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package vmess
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -55,11 +54,11 @@ func (hc *httpConn) Write(b []byte) (int, error) {
|
|||||||
return hc.Conn.Write(b)
|
return hc.Conn.Write(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(hc.cfg.Path) == 0 {
|
path := "/"
|
||||||
return -1, errors.New("path is empty")
|
if len(hc.cfg.Path) > 0 {
|
||||||
|
path = hc.cfg.Path[randv2.IntN(len(hc.cfg.Path))]
|
||||||
}
|
}
|
||||||
|
|
||||||
path := hc.cfg.Path[randv2.IntN(len(hc.cfg.Path))]
|
|
||||||
host := hc.cfg.Host
|
host := hc.cfg.Host
|
||||||
if header := hc.cfg.Headers["Host"]; len(header) != 0 {
|
if header := hc.cfg.Headers["Host"]; len(header) != 0 {
|
||||||
host = header[randv2.IntN(len(header))]
|
host = header[randv2.IntN(len(header))]
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ import (
|
|||||||
"github.com/metacubex/mihomo/common/utils"
|
"github.com/metacubex/mihomo/common/utils"
|
||||||
"github.com/metacubex/mihomo/component/loopback"
|
"github.com/metacubex/mihomo/component/loopback"
|
||||||
"github.com/metacubex/mihomo/component/nat"
|
"github.com/metacubex/mihomo/component/nat"
|
||||||
P "github.com/metacubex/mihomo/component/process"
|
"github.com/metacubex/mihomo/component/process"
|
||||||
"github.com/metacubex/mihomo/component/resolver"
|
"github.com/metacubex/mihomo/component/resolver"
|
||||||
"github.com/metacubex/mihomo/component/slowdown"
|
"github.com/metacubex/mihomo/component/slowdown"
|
||||||
"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
|
||||||
@@ -59,21 +59,19 @@ var (
|
|||||||
// default timeout for UDP session
|
// default timeout for UDP session
|
||||||
udpTimeout = 60 * time.Second
|
udpTimeout = 60 * time.Second
|
||||||
|
|
||||||
findProcessMode = atomic.NewInt32Enum(P.FindProcessStrict)
|
findProcessMode = atomic.NewInt32Enum(process.FindProcessStrict)
|
||||||
|
|
||||||
fakeIPRange netip.Prefix
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -114,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,14 +140,6 @@ func Status() TunnelStatus {
|
|||||||
return status.Load()
|
return status.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetFakeIPRange(p netip.Prefix) {
|
|
||||||
fakeIPRange = p
|
|
||||||
}
|
|
||||||
|
|
||||||
func FakeIPRange() netip.Prefix {
|
|
||||||
return fakeIPRange
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetSniffing(b bool) {
|
func SetSniffing(b bool) {
|
||||||
if snifferDispatcher.Enable() {
|
if snifferDispatcher.Enable() {
|
||||||
configMux.Lock()
|
configMux.Lock()
|
||||||
@@ -205,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
|
||||||
@@ -233,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
|
||||||
@@ -273,13 +263,13 @@ func SetMode(m TunnelMode) {
|
|||||||
mode = m
|
mode = m
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindProcessMode() P.FindProcessMode {
|
func FindProcessMode() process.FindProcessMode {
|
||||||
return findProcessMode.Load()
|
return findProcessMode.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFindProcessMode replace SetAlwaysFindProcess
|
// SetFindProcessMode replace SetAlwaysFindProcess
|
||||||
// always find process info if legacyAlways = true or mode.Always() = true, may be increase many memory
|
// always find process info if legacyAlways = true or mode.Always() = true, may be increase many memory
|
||||||
func SetFindProcessMode(mode P.FindProcessMode) {
|
func SetFindProcessMode(mode process.FindProcessMode) {
|
||||||
findProcessMode.Store(mode)
|
findProcessMode.Store(mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,7 +358,7 @@ func resolveMetadata(metadata *C.Metadata) (proxy C.Proxy, rule C.Rule, err erro
|
|||||||
attemptProcessLookup = false
|
attemptProcessLookup = false
|
||||||
if !features.CMFA {
|
if !features.CMFA {
|
||||||
// normal check for process
|
// normal check for process
|
||||||
uid, path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(metadata.SrcPort))
|
uid, path, err := process.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(metadata.SrcPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugln("[Process] find process error for %s: %v", metadata.String(), err)
|
log.Debugln("[Process] find process error for %s: %v", metadata.String(), err)
|
||||||
} else {
|
} else {
|
||||||
@@ -376,13 +366,13 @@ func resolveMetadata(metadata *C.Metadata) (proxy C.Proxy, rule C.Rule, err erro
|
|||||||
metadata.ProcessPath = path
|
metadata.ProcessPath = path
|
||||||
metadata.Uid = uid
|
metadata.Uid = uid
|
||||||
|
|
||||||
if pkg, err := P.FindPackageName(metadata); err == nil { // for android (not CMFA) package names
|
if pkg, err := process.FindPackageName(metadata); err == nil { // for android (not CMFA) package names
|
||||||
metadata.Process = pkg
|
metadata.Process = pkg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// check package names
|
// check package names
|
||||||
pkg, err := P.FindPackageName(metadata)
|
pkg, err := process.FindPackageName(metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugln("[Process] find process error for %s: %v", metadata.String(), err)
|
log.Debugln("[Process] find process error for %s: %v", metadata.String(), err)
|
||||||
} else {
|
} else {
|
||||||
@@ -394,10 +384,10 @@ func resolveMetadata(metadata *C.Metadata) (proxy C.Proxy, rule C.Rule, err erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch FindProcessMode() {
|
switch FindProcessMode() {
|
||||||
case P.FindProcessAlways:
|
case process.FindProcessAlways:
|
||||||
helper.FindProcess()
|
helper.FindProcess()
|
||||||
helper.FindProcess = nil
|
helper.FindProcess = nil
|
||||||
case P.FindProcessOff:
|
case process.FindProcessOff:
|
||||||
helper.FindProcess = nil
|
helper.FindProcess = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,7 +553,7 @@ func handleTCPConn(connCtx C.ConnContext) {
|
|||||||
dialMetadata := metadata
|
dialMetadata := metadata
|
||||||
if len(metadata.Host) > 0 {
|
if len(metadata.Host) > 0 {
|
||||||
if node, ok := resolver.DefaultHosts.Search(metadata.Host, false); ok {
|
if node, ok := resolver.DefaultHosts.Search(metadata.Host, false); ok {
|
||||||
if dstIp, _ := node.RandIP(); !FakeIPRange().Contains(dstIp) {
|
if dstIp, _ := node.RandIP(); !resolver.IsFakeIP(dstIp) {
|
||||||
dialMetadata.DstIP = dstIp
|
dialMetadata.DstIP = dstIp
|
||||||
dialMetadata.DNSMode = C.DNSHosts
|
dialMetadata.DNSMode = C.DNSHosts
|
||||||
dialMetadata = dialMetadata.Pure()
|
dialMetadata = dialMetadata.Pure()
|
||||||
|
|||||||
Reference in New Issue
Block a user