fix: config code merge

This commit is contained in:
wwqgtxx 2022-12-06 10:13:05 +08:00
parent b5b06ea49c
commit cd99b2e795
4 changed files with 56 additions and 58 deletions

View file

@ -30,7 +30,6 @@ import (
"github.com/Dreamacro/clash/dns" "github.com/Dreamacro/clash/dns"
L "github.com/Dreamacro/clash/listener" L "github.com/Dreamacro/clash/listener"
LC "github.com/Dreamacro/clash/listener/config" LC "github.com/Dreamacro/clash/listener/config"
"github.com/Dreamacro/clash/listener/tunnel"
"github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/log"
R "github.com/Dreamacro/clash/rules" R "github.com/Dreamacro/clash/rules"
RP "github.com/Dreamacro/clash/rules/provider" RP "github.com/Dreamacro/clash/rules/provider"
@ -45,33 +44,33 @@ type General struct {
Controller Controller
Mode T.TunnelMode `json:"mode"` Mode T.TunnelMode `json:"mode"`
UnifiedDelay bool UnifiedDelay bool
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:"-"` RoutingMark int `json:"-"`
GeodataMode bool `json:"geodata-mode"` GeodataMode bool `json:"geodata-mode"`
GeodataLoader string `json:"geodata-loader"` GeodataLoader string `json:"geodata-loader"`
TCPConcurrent bool `json:"tcp-concurrent"` TCPConcurrent bool `json:"tcp-concurrent"`
EnableProcess bool `json:"enable-process"` EnableProcess bool `json:"enable-process"`
Tun LC.Tun `json:"tun"` Sniffing bool `json:"sniffing"`
TuicServer LC.TuicServer `json:"tuic-server"` EBpf EBpf `json:"-"`
Sniffing bool `json:"sniffing"`
EBpf EBpf `json:"-"`
} }
// Inbound config // Inbound config
type Inbound struct { type Inbound struct {
Port int `json:"port"` Port int `json:"port"`
SocksPort int `json:"socks-port"` SocksPort int `json:"socks-port"`
RedirPort int `json:"redir-port"` RedirPort int `json:"redir-port"`
TProxyPort int `json:"tproxy-port"` TProxyPort int `json:"tproxy-port"`
MixedPort int `json:"mixed-port"` MixedPort int `json:"mixed-port"`
ShadowSocksConfig string `json:"ss-config"` Tun LC.Tun `json:"tun"`
VmessConfig string `json:"vmess-config"` TuicServer LC.TuicServer `json:"tuic-server"`
Authentication []string `json:"authentication"` ShadowSocksConfig string `json:"ss-config"`
AllowLan bool `json:"allow-lan"` VmessConfig string `json:"vmess-config"`
BindAddress string `json:"bind-address"` Authentication []string `json:"authentication"`
InboundTfo bool `json:"inbound-tfo"` AllowLan bool `json:"allow-lan"`
BindAddress string `json:"bind-address"`
InboundTfo bool `json:"inbound-tfo"`
} }
// Controller config // Controller config
@ -157,7 +156,7 @@ type Config struct {
Listeners map[string]C.InboundListener Listeners map[string]C.InboundListener
Providers map[string]providerTypes.ProxyProvider Providers map[string]providerTypes.ProxyProvider
RuleProviders map[string]providerTypes.RuleProvider RuleProviders map[string]providerTypes.RuleProvider
Tunnels []tunnel.Tunnel Tunnels []LC.Tunnel
Sniffer *Sniffer Sniffer *Sniffer
TLS *TLS TLS *TLS
} }
@ -227,32 +226,32 @@ type RawTuicServer struct {
} }
type RawConfig struct { type RawConfig struct {
Port int `yaml:"port"` Port int `yaml:"port"`
SocksPort int `yaml:"socks-port"` SocksPort int `yaml:"socks-port"`
RedirPort int `yaml:"redir-port"` RedirPort int `yaml:"redir-port"`
TProxyPort int `yaml:"tproxy-port"` TProxyPort int `yaml:"tproxy-port"`
MixedPort int `yaml:"mixed-port"` MixedPort int `yaml:"mixed-port"`
ShadowSocksConfig string `yaml:"ss-config"` ShadowSocksConfig string `yaml:"ss-config"`
VmessConfig string `yaml:"vmess-config"` VmessConfig string `yaml:"vmess-config"`
InboundTfo bool `yaml:"inbound-tfo"` InboundTfo bool `yaml:"inbound-tfo"`
Authentication []string `yaml:"authentication"` Authentication []string `yaml:"authentication"`
AllowLan bool `yaml:"allow-lan"` AllowLan bool `yaml:"allow-lan"`
BindAddress string `yaml:"bind-address"` BindAddress string `yaml:"bind-address"`
Mode T.TunnelMode `yaml:"mode"` Mode T.TunnelMode `yaml:"mode"`
UnifiedDelay bool `yaml:"unified-delay"` UnifiedDelay bool `yaml:"unified-delay"`
LogLevel log.LogLevel `yaml:"log-level"` LogLevel log.LogLevel `yaml:"log-level"`
IPv6 bool `yaml:"ipv6"` IPv6 bool `yaml:"ipv6"`
ExternalController string `yaml:"external-controller"` ExternalController string `yaml:"external-controller"`
ExternalControllerTLS string `yaml:"external-controller-tls"` ExternalControllerTLS string `yaml:"external-controller-tls"`
ExternalUI string `yaml:"external-ui"` ExternalUI string `yaml:"external-ui"`
Secret string `yaml:"secret"` Secret string `yaml:"secret"`
Interface string `yaml:"interface-name"` Interface string `yaml:"interface-name"`
RoutingMark int `yaml:"routing-mark"` RoutingMark int `yaml:"routing-mark"`
Tunnels []tunnel.Tunnel `yaml:"tunnels"` Tunnels []LC.Tunnel `yaml:"tunnels"`
GeodataMode bool `yaml:"geodata-mode"` GeodataMode bool `yaml:"geodata-mode"`
GeodataLoader string `yaml:"geodata-loader"` GeodataLoader string `yaml:"geodata-loader"`
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"` TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
EnableProcess bool `yaml:"enable-process" json:"enable-process"` EnableProcess bool `yaml:"enable-process" json:"enable-process"`
Sniffer RawSniffer `yaml:"sniffer"` Sniffer RawSniffer `yaml:"sniffer"`
ProxyProvider map[string]map[string]any `yaml:"proxy-providers"` ProxyProvider map[string]map[string]any `yaml:"proxy-providers"`

View file

@ -29,7 +29,6 @@ import (
LC "github.com/Dreamacro/clash/listener/config" LC "github.com/Dreamacro/clash/listener/config"
"github.com/Dreamacro/clash/listener/inner" "github.com/Dreamacro/clash/listener/inner"
"github.com/Dreamacro/clash/listener/tproxy" "github.com/Dreamacro/clash/listener/tproxy"
T "github.com/Dreamacro/clash/listener/tunnel"
"github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/log"
"github.com/Dreamacro/clash/tunnel" "github.com/Dreamacro/clash/tunnel"
) )
@ -115,6 +114,8 @@ func GetGeneral() *config.General {
RedirPort: ports.RedirPort, RedirPort: ports.RedirPort,
TProxyPort: ports.TProxyPort, TProxyPort: ports.TProxyPort,
MixedPort: ports.MixedPort, MixedPort: ports.MixedPort,
Tun: listener.GetTunConf(),
TuicServer: listener.GetTuicConf(),
ShadowSocksConfig: ports.ShadowSocksConfig, ShadowSocksConfig: ports.ShadowSocksConfig,
VmessConfig: ports.VmessConfig, VmessConfig: ports.VmessConfig,
Authentication: authenticator, Authentication: authenticator,
@ -125,8 +126,6 @@ func GetGeneral() *config.General {
LogLevel: log.Level(), LogLevel: log.Level(),
IPv6: !resolver.DisableIPv6, IPv6: !resolver.DisableIPv6,
GeodataLoader: G.LoaderName(), GeodataLoader: G.LoaderName(),
Tun: listener.GetTunConf(),
TuicServer: listener.GetTuicConf(),
Interface: dialer.DefaultInterface.Load(), Interface: dialer.DefaultInterface.Load(),
Sniffing: tunnel.IsSniffing(), Sniffing: tunnel.IsSniffing(),
TCPConcurrent: dialer.GetDial(), TCPConcurrent: dialer.GetDial(),
@ -304,7 +303,7 @@ func updateSniffer(sniffer *config.Sniffer) {
} }
} }
func updateTunnels(tunnels []T.Tunnel) { func updateTunnels(tunnels []LC.Tunnel) {
listener.PatchTunnel(tunnels, tunnel.TCPIn(), tunnel.UDPIn()) listener.PatchTunnel(tunnels, tunnel.TCPIn(), tunnel.UDPIn())
} }

View file

@ -1,4 +1,4 @@
package tunnel package config
import ( import (
"fmt" "fmt"

View file

@ -625,7 +625,7 @@ func ReCreateAutoRedir(ifaceNames []string, tcpIn chan<- C.ConnContext, _ chan<-
log.Infoln("Auto redirect proxy listening at: %s, attached tc ebpf program to interfaces %v", autoRedirListener.Address(), autoRedirProgram.RawNICs()) log.Infoln("Auto redirect proxy listening at: %s, attached tc ebpf program to interfaces %v", autoRedirListener.Address(), autoRedirProgram.RawNICs())
} }
func PatchTunnel(tunnels []tunnel.Tunnel, tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) { func PatchTunnel(tunnels []LC.Tunnel, tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter) {
tunnelMux.Lock() tunnelMux.Lock()
defer tunnelMux.Unlock() defer tunnelMux.Unlock()
@ -664,7 +664,7 @@ func PatchTunnel(tunnels []tunnel.Tunnel, tcpIn chan<- C.ConnContext, udpIn chan
newElm := lo.FlatMap( newElm := lo.FlatMap(
tunnels, tunnels,
func(tunnel tunnel.Tunnel, _ int) []addrProxy { func(tunnel LC.Tunnel, _ int) []addrProxy {
return lo.Map( return lo.Map(
tunnel.Network, tunnel.Network,
func(network string, _ int) addrProxy { func(network string, _ int) addrProxy {