chore: Cleanup code
This commit is contained in:
parent
fef5ad780d
commit
1479b449df
32 changed files with 77 additions and 56 deletions
|
@ -1,4 +1,4 @@
|
||||||
// +build android,cmfa
|
//go:build android && cmfa
|
||||||
|
|
||||||
package outboundgroup
|
package outboundgroup
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ func ParseProxyProvider(name string, mapping map[string]any) (types.ProxyProvide
|
||||||
case "http":
|
case "http":
|
||||||
if schema.Path != "" {
|
if schema.Path != "" {
|
||||||
path := C.Path.Resolve(schema.Path)
|
path := C.Path.Resolve(schema.Path)
|
||||||
if !features.Contains("cmfa") && !C.Path.IsSafePath(path) {
|
if !features.CMFA && !C.Path.IsSafePath(path) {
|
||||||
return nil, fmt.Errorf("%w: %s", errSubPath, path)
|
return nil, fmt.Errorf("%w: %s", errSubPath, path)
|
||||||
}
|
}
|
||||||
vehicle = resource.NewHTTPVehicle(schema.URL, path)
|
vehicle = resource.NewHTTPVehicle(schema.URL, path)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build android,cmfa
|
//go:build android && cmfa
|
||||||
|
|
||||||
package provider
|
package provider
|
||||||
|
|
||||||
|
|
|
@ -71,10 +71,10 @@ func DialContext(ctx context.Context, network, address string, options ...Option
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListenPacket(ctx context.Context, network, address string, options ...Option) (net.PacketConn, error) {
|
func ListenPacket(ctx context.Context, network, address string, options ...Option) (net.PacketConn, error) {
|
||||||
if features.Contains("cmfa") && DefaultSocketHook != nil{
|
if features.CMFA && DefaultSocketHook != nil {
|
||||||
return listenPacketHooked(ctx, network, address)
|
return listenPacketHooked(ctx, network, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := applyOptions(options...)
|
cfg := applyOptions(options...)
|
||||||
|
|
||||||
lc := &net.ListenConfig{}
|
lc := &net.ListenConfig{}
|
||||||
|
@ -119,10 +119,10 @@ func GetTcpConcurrent() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dialContext(ctx context.Context, network string, destination netip.Addr, port string, opt *option) (net.Conn, error) {
|
func dialContext(ctx context.Context, network string, destination netip.Addr, port string, opt *option) (net.Conn, error) {
|
||||||
if features.Contains("cmfa") && DefaultSocketHook != nil{
|
if features.CMFA && DefaultSocketHook != nil {
|
||||||
return dialContextHooked(ctx, network, destination, port)
|
return dialContextHooked(ctx, network, destination, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
address := net.JoinHostPort(destination.String(), port)
|
address := net.JoinHostPort(destination.String(), port)
|
||||||
|
|
||||||
netDialer := opt.netDialer
|
netDialer := opt.netDialer
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build android,cmfa
|
//go:build android && cmfa
|
||||||
|
|
||||||
package dialer
|
package dialer
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build !cmfa
|
//go:build !(android && cmfa)
|
||||||
|
|
||||||
package dialer
|
package dialer
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build android,cmfa
|
//go:build android && cmfa
|
||||||
|
|
||||||
package mmdb
|
package mmdb
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package process
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"github.com/metacubex/mihomo/constant"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -20,7 +19,3 @@ const (
|
||||||
func FindProcessName(network string, srcIP netip.Addr, srcPort int) (uint32, string, error) {
|
func FindProcessName(network string, srcIP netip.Addr, srcPort int) (uint32, string, error) {
|
||||||
return findProcessName(network, srcIP, srcPort)
|
return findProcessName(network, srcIP, srcPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindPackageName(metadata *constant.Metadata) (string, error) {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build android,cmfa
|
//go:build android && cmfa
|
||||||
|
|
||||||
package process
|
package process
|
||||||
|
|
9
component/process/process_common.go
Normal file
9
component/process/process_common.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
//go:build !(android && cmfa)
|
||||||
|
|
||||||
|
package process
|
||||||
|
|
||||||
|
import "github.com/metacubex/mihomo/constant"
|
||||||
|
|
||||||
|
func FindPackageName(metadata *constant.Metadata) (string, error) {
|
||||||
|
return "", nil
|
||||||
|
}
|
|
@ -324,7 +324,7 @@ type RawConfig struct {
|
||||||
RawTLS TLS `yaml:"tls"`
|
RawTLS TLS `yaml:"tls"`
|
||||||
Listeners []map[string]any `yaml:"listeners"`
|
Listeners []map[string]any `yaml:"listeners"`
|
||||||
|
|
||||||
ClashForAndroid RawClashForAndroid `yaml:"clash-for-android" json:"clash-for-android"`
|
ClashForAndroid RawClashForAndroid `yaml:"clash-for-android" json:"clash-for-android"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GeoXUrl struct {
|
type GeoXUrl struct {
|
||||||
|
@ -554,7 +554,7 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
||||||
config.DNS = dnsCfg
|
config.DNS = dnsCfg
|
||||||
|
|
||||||
err = parseTun(rawCfg.Tun, config.General)
|
err = parseTun(rawCfg.Tun, config.General)
|
||||||
if !features.Contains("cmfa") && err != nil {
|
if !features.CMFA && err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,4 @@
|
||||||
|
|
||||||
package features
|
package features
|
||||||
|
|
||||||
func init() {
|
const CMFA = true
|
||||||
TAGS = append(TAGS, "cmfa")
|
|
||||||
}
|
|
||||||
|
|
5
constant/features/cmfa_stub.go
Normal file
5
constant/features/cmfa_stub.go
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
//go:build !cmfa
|
||||||
|
|
||||||
|
package features
|
||||||
|
|
||||||
|
const CMFA = false
|
|
@ -2,6 +2,4 @@
|
||||||
|
|
||||||
package features
|
package features
|
||||||
|
|
||||||
func init() {
|
const WithLowMemory = true
|
||||||
TAGS = append(TAGS, "with_low_memory")
|
|
||||||
}
|
|
||||||
|
|
5
constant/features/low_memory_stub.go
Normal file
5
constant/features/low_memory_stub.go
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
//go:build !with_low_memory
|
||||||
|
|
||||||
|
package features
|
||||||
|
|
||||||
|
const WithLowMemory = false
|
|
@ -2,6 +2,4 @@
|
||||||
|
|
||||||
package features
|
package features
|
||||||
|
|
||||||
func init() {
|
const NoFakeTCP = true
|
||||||
TAGS = append(TAGS, "no_fake_tcp")
|
|
||||||
}
|
|
||||||
|
|
5
constant/features/no_fake_tcp_stub.go
Normal file
5
constant/features/no_fake_tcp_stub.go
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
//go:build !no_fake_tcp
|
||||||
|
|
||||||
|
package features
|
||||||
|
|
||||||
|
const NoFakeTCP = false
|
|
@ -1,11 +1,17 @@
|
||||||
package features
|
package features
|
||||||
|
|
||||||
import(
|
func Tags() (tags []string) {
|
||||||
"golang.org/x/exp/slices"
|
if CMFA {
|
||||||
)
|
tags = append(tags, "cmfa")
|
||||||
|
}
|
||||||
var TAGS = make([]string, 0, 0)
|
if WithLowMemory {
|
||||||
|
tags = append(tags, "with_low_memory")
|
||||||
func Contains(feat string) (bool) {
|
}
|
||||||
return slices.Contains(TAGS, feat)
|
if NoFakeTCP {
|
||||||
}
|
tags = append(tags, "no_fake_tcp")
|
||||||
|
}
|
||||||
|
if WithGVisor {
|
||||||
|
tags = append(tags, "with_gvisor")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,4 @@
|
||||||
|
|
||||||
package features
|
package features
|
||||||
|
|
||||||
func init() {
|
const WithGVisor = true
|
||||||
TAGS = append(TAGS, "with_gvisor")
|
|
||||||
}
|
|
||||||
|
|
5
constant/features/with_gvisor_stub.go
Normal file
5
constant/features/with_gvisor_stub.go
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
//go:build !with_gvisor
|
||||||
|
|
||||||
|
package features
|
||||||
|
|
||||||
|
const WithGVisor = false
|
|
@ -1,4 +1,4 @@
|
||||||
// +build !cmfa
|
//go:build !(android && cmfa)
|
||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build android,cmfa
|
//go:build android && cmfa
|
||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// +build !cmfa
|
//go:build !(android && cmfa)
|
||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
func UpdateIsolateHandler(resolver *Resolver, mapper *ResolverEnhancer) {
|
func UpdateIsolateHandler(resolver *Resolver, mapper *ResolverEnhancer) {
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -50,10 +50,10 @@ func (s *Server) SetHandler(handler handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReCreateServer(addr string, resolver *Resolver, mapper *ResolverEnhancer) {
|
func ReCreateServer(addr string, resolver *Resolver, mapper *ResolverEnhancer) {
|
||||||
if features.Contains("cmfa") {
|
if features.CMFA {
|
||||||
UpdateIsolateHandler(resolver, mapper)
|
UpdateIsolateHandler(resolver, mapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
if addr == address && resolver != nil {
|
if addr == address && resolver != nil {
|
||||||
handler := NewHandler(resolver, mapper)
|
handler := NewHandler(resolver, mapper)
|
||||||
server.SetHandler(handler)
|
server.SetHandler(handler)
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/metacubex/mihomo/component/trie"
|
"github.com/metacubex/mihomo/component/trie"
|
||||||
"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/features"
|
||||||
"github.com/metacubex/mihomo/constant/provider"
|
"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"
|
||||||
|
@ -35,7 +36,6 @@ import (
|
||||||
"github.com/metacubex/mihomo/log"
|
"github.com/metacubex/mihomo/log"
|
||||||
"github.com/metacubex/mihomo/ntp"
|
"github.com/metacubex/mihomo/ntp"
|
||||||
"github.com/metacubex/mihomo/tunnel"
|
"github.com/metacubex/mihomo/tunnel"
|
||||||
"github.com/metacubex/mihomo/constant/features"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var mux sync.Mutex
|
var mux sync.Mutex
|
||||||
|
@ -171,7 +171,7 @@ func updateListeners(general *config.General, listeners map[string]C.InboundList
|
||||||
listener.ReCreateHTTP(general.Port, tunnel.Tunnel)
|
listener.ReCreateHTTP(general.Port, tunnel.Tunnel)
|
||||||
listener.ReCreateSocks(general.SocksPort, tunnel.Tunnel)
|
listener.ReCreateSocks(general.SocksPort, tunnel.Tunnel)
|
||||||
listener.ReCreateRedir(general.RedirPort, tunnel.Tunnel)
|
listener.ReCreateRedir(general.RedirPort, tunnel.Tunnel)
|
||||||
if !features.Contains("cmfa") {
|
if !features.CMFA {
|
||||||
listener.ReCreateAutoRedir(general.EBpf.AutoRedir, tunnel.Tunnel)
|
listener.ReCreateAutoRedir(general.EBpf.AutoRedir, tunnel.Tunnel)
|
||||||
}
|
}
|
||||||
listener.ReCreateTProxy(general.TProxyPort, tunnel.Tunnel)
|
listener.ReCreateTProxy(general.TProxyPort, tunnel.Tunnel)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build android,cmfa
|
//go:build android && cmfa
|
||||||
|
|
||||||
package http
|
package http
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ func NewWithAuthenticate(addr string, tunnel C.Tunnel, authenticate bool, additi
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if features.Contains("cmfa") {
|
if features.CMFA {
|
||||||
if t, ok := conn.(*net.TCPConn); ok {
|
if t, ok := conn.(*net.TCPConn); ok {
|
||||||
t.SetKeepAlive(false)
|
t.SetKeepAlive(false)
|
||||||
}
|
}
|
||||||
|
|
4
main.go
4
main.go
|
@ -48,8 +48,8 @@ func main() {
|
||||||
if version {
|
if version {
|
||||||
fmt.Printf("Mihomo Meta %s %s %s with %s %s\n",
|
fmt.Printf("Mihomo Meta %s %s %s with %s %s\n",
|
||||||
C.Version, runtime.GOOS, runtime.GOARCH, runtime.Version(), C.BuildTime)
|
C.Version, runtime.GOOS, runtime.GOARCH, runtime.Version(), C.BuildTime)
|
||||||
if len(features.TAGS) != 0 {
|
if tags := features.Tags(); len(tags) != 0 {
|
||||||
fmt.Printf("Use tags: %s\n", strings.Join(features.TAGS, ", "))
|
fmt.Printf("Use tags: %s\n", strings.Join(tags, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -63,7 +63,7 @@ func ParseRuleProvider(name string, mapping map[string]interface{}, parse func(t
|
||||||
case "http":
|
case "http":
|
||||||
if schema.Path != "" {
|
if schema.Path != "" {
|
||||||
path := C.Path.Resolve(schema.Path)
|
path := C.Path.Resolve(schema.Path)
|
||||||
if !features.Contains("cmfa") && !C.Path.IsSafePath(path) {
|
if !features.CMFA && !C.Path.IsSafePath(path) {
|
||||||
return nil, fmt.Errorf("%w: %s", errSubPath, path)
|
return nil, fmt.Errorf("%w: %s", errSubPath, path)
|
||||||
}
|
}
|
||||||
vehicle = resource.NewHTTPVehicle(schema.URL, path)
|
vehicle = resource.NewHTTPVehicle(schema.URL, path)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build android,cmfa
|
//go:build android && cmfa
|
||||||
|
|
||||||
package provider
|
package provider
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build android,cmfa
|
//go:build android && cmfa
|
||||||
|
|
||||||
package statistic
|
package statistic
|
||||||
|
|
||||||
|
|
|
@ -621,7 +621,7 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) {
|
||||||
|
|
||||||
if attemptProcessLookup && !findProcessMode.Off() && (findProcessMode.Always() || rule.ShouldFindProcess()) {
|
if attemptProcessLookup && !findProcessMode.Off() && (findProcessMode.Always() || rule.ShouldFindProcess()) {
|
||||||
attemptProcessLookup = false
|
attemptProcessLookup = false
|
||||||
if !features.Contains("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 := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(metadata.SrcPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue