mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-24 05:02:14 +08:00
chore: cleaned up some weird code
This commit is contained in:
parent
eb985b002e
commit
f805a9f4c6
@ -164,13 +164,16 @@ func (p *Proxy) MarshalJSON() ([]byte, error) {
|
|||||||
mapping["name"] = p.Name()
|
mapping["name"] = p.Name()
|
||||||
mapping["udp"] = p.SupportUDP()
|
mapping["udp"] = p.SupportUDP()
|
||||||
mapping["uot"] = p.SupportUOT()
|
mapping["uot"] = p.SupportUOT()
|
||||||
mapping["xudp"] = p.SupportXUDP()
|
|
||||||
mapping["tfo"] = p.SupportTFO()
|
proxyInfo := p.ProxyInfo()
|
||||||
mapping["mptcp"] = p.SupportMPTCP()
|
mapping["xudp"] = proxyInfo.XUDP
|
||||||
mapping["smux"] = p.SupportSMUX()
|
mapping["tfo"] = proxyInfo.TFO
|
||||||
mapping["interface"] = p.SupportInterface()
|
mapping["mptcp"] = proxyInfo.MPTCP
|
||||||
mapping["dialer-proxy"] = p.SupportDialerProxy()
|
mapping["smux"] = proxyInfo.SMUX
|
||||||
mapping["routing-mark"] = p.SupportRoutingMark()
|
mapping["interface"] = proxyInfo.Interface
|
||||||
|
mapping["dialer-proxy"] = proxyInfo.DialerProxy
|
||||||
|
mapping["routing-mark"] = proxyInfo.RoutingMark
|
||||||
|
|
||||||
return json.Marshal(mapping)
|
return json.Marshal(mapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,36 +85,15 @@ func (b *Base) SupportUDP() bool {
|
|||||||
return b.udp
|
return b.udp
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportXUDP implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (b *Base) SupportXUDP() bool {
|
func (b *Base) ProxyInfo() (info C.ProxyInfo) {
|
||||||
return b.xudp
|
info.XUDP = b.xudp
|
||||||
}
|
info.TFO = b.tfo
|
||||||
|
info.MPTCP = b.mpTcp
|
||||||
// SupportTFO implements C.ProxyAdapter
|
info.SMUX = false
|
||||||
func (b *Base) SupportTFO() bool {
|
info.Interface = b.iface
|
||||||
return b.tfo
|
info.RoutingMark = b.rmark
|
||||||
}
|
return
|
||||||
|
|
||||||
// SupportMPTCP implements C.ProxyAdapter
|
|
||||||
func (b *Base) SupportMPTCP() bool {
|
|
||||||
return b.mpTcp
|
|
||||||
}
|
|
||||||
|
|
||||||
// SupportSMUX implements C.ProxyAdapter
|
|
||||||
func (b *Base) SupportSMUX() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Base) SupportDialerProxy() string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Base) SupportInterface() string {
|
|
||||||
return b.iface
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Base) SupportRoutingMark() int {
|
|
||||||
return b.rmark
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsL3Protocol implements C.ProxyAdapter
|
// IsL3Protocol implements C.ProxyAdapter
|
||||||
|
@ -92,9 +92,11 @@ func (h *Http) SupportWithDialer() C.NetWork {
|
|||||||
return C.TCP
|
return C.TCP
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (h *Http) SupportDialerProxy() string {
|
func (h *Http) ProxyInfo() C.ProxyInfo {
|
||||||
return h.option.DialerProxy
|
info := h.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = h.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Http) shakeHand(metadata *C.Metadata, rw io.ReadWriter) error {
|
func (h *Http) shakeHand(metadata *C.Metadata, rw io.ReadWriter) error {
|
||||||
|
@ -87,9 +87,11 @@ func (h *Hysteria) genHdc(ctx context.Context, opts ...dialer.Option) utils.Pack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (h *Hysteria) SupportDialerProxy() string {
|
func (h *Hysteria) ProxyInfo() C.ProxyInfo {
|
||||||
return h.option.DialerProxy
|
info := h.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = h.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
type HysteriaOption struct {
|
type HysteriaOption struct {
|
||||||
|
@ -96,9 +96,11 @@ func closeHysteria2(h *Hysteria2) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (h *Hysteria2) SupportDialerProxy() string {
|
func (h *Hysteria2) ProxyInfo() C.ProxyInfo {
|
||||||
return h.option.DialerProxy
|
info := h.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = h.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {
|
func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {
|
||||||
|
@ -196,9 +196,11 @@ func (ss *ShadowSocks) SupportWithDialer() C.NetWork {
|
|||||||
return C.ALLNet
|
return C.ALLNet
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (ss *ShadowSocks) SupportDialerProxy() string {
|
func (ss *ShadowSocks) ProxyInfo() C.ProxyInfo {
|
||||||
return ss.option.DialerProxy
|
info := ss.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = ss.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenPacketOnStreamConn implements C.ProxyAdapter
|
// ListenPacketOnStreamConn implements C.ProxyAdapter
|
||||||
|
@ -122,9 +122,11 @@ func (ssr *ShadowSocksR) SupportWithDialer() C.NetWork {
|
|||||||
return C.ALLNet
|
return C.ALLNet
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (ssr *ShadowSocksR) SupportDialerProxy() string {
|
func (ssr *ShadowSocksR) ProxyInfo() C.ProxyInfo {
|
||||||
return ssr.option.DialerProxy
|
info := ssr.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = ssr.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewShadowSocksR(option ShadowSocksROption) (*ShadowSocksR, error) {
|
func NewShadowSocksR(option ShadowSocksROption) (*ShadowSocksR, error) {
|
||||||
|
@ -97,8 +97,10 @@ func (s *SingMux) SupportUOT() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SingMux) SupportSMUX() bool {
|
func (s *SingMux) ProxyInfo() C.ProxyInfo {
|
||||||
return true
|
info := s.ProxyAdapter.ProxyInfo()
|
||||||
|
info.SMUX = true
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func closeSingMux(s *SingMux) {
|
func closeSingMux(s *SingMux) {
|
||||||
|
@ -141,9 +141,11 @@ func (s *Snell) SupportUOT() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (s *Snell) SupportDialerProxy() string {
|
func (s *Snell) ProxyInfo() C.ProxyInfo {
|
||||||
return s.option.DialerProxy
|
info := s.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = s.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSnell(option SnellOption) (*Snell, error) {
|
func NewSnell(option SnellOption) (*Snell, error) {
|
||||||
|
@ -171,9 +171,11 @@ func (ss *Socks5) ListenPacketContext(ctx context.Context, metadata *C.Metadata,
|
|||||||
return newPacketConn(&socksPacketConn{PacketConn: pc, rAddr: bindUDPAddr, tcpConn: c}, ss), nil
|
return newPacketConn(&socksPacketConn{PacketConn: pc, rAddr: bindUDPAddr, tcpConn: c}, ss), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (ss *Socks5) SupportDialerProxy() string {
|
func (ss *Socks5) ProxyInfo() C.ProxyInfo {
|
||||||
return ss.option.DialerProxy
|
info := ss.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = ss.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSocks5(option Socks5Option) (*Socks5, error) {
|
func NewSocks5(option Socks5Option) (*Socks5, error) {
|
||||||
|
@ -121,9 +121,11 @@ func closeSsh(s *Ssh) {
|
|||||||
_ = s.client.Close()
|
_ = s.client.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportWithDialer implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (s *Ssh) SupportDialerProxy() string {
|
func (s *Ssh) ProxyInfo() C.ProxyInfo {
|
||||||
return s.option.DialerProxy
|
info := s.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = s.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSsh(option SshOption) (*Ssh, error) {
|
func NewSsh(option SshOption) (*Ssh, error) {
|
||||||
|
@ -244,9 +244,11 @@ func (t *Trojan) SupportUOT() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (t *Trojan) SupportDialerProxy() string {
|
func (t *Trojan) ProxyInfo() C.ProxyInfo {
|
||||||
return t.option.DialerProxy
|
info := t.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = t.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTrojan(option TrojanOption) (*Trojan, error) {
|
func NewTrojan(option TrojanOption) (*Trojan, error) {
|
||||||
|
@ -146,9 +146,11 @@ func (t *Tuic) dialWithDialer(ctx context.Context, dialer C.Dialer) (transport *
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (t *Tuic) SupportDialerProxy() string {
|
func (t *Tuic) ProxyInfo() C.ProxyInfo {
|
||||||
return t.option.DialerProxy
|
info := t.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = t.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTuic(option TuicOption) (*Tuic, error) {
|
func NewTuic(option TuicOption) (*Tuic, error) {
|
||||||
|
@ -379,9 +379,11 @@ func (v *Vless) SupportUOT() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportDialerProxy implements C.ProxyAdapter
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
func (v *Vless) SupportDialerProxy() string {
|
func (v *Vless) ProxyInfo() C.ProxyInfo {
|
||||||
return v.option.DialerProxy
|
info := v.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = v.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseVlessAddr(metadata *C.Metadata, xudp bool) *vless.DstAddr {
|
func parseVlessAddr(metadata *C.Metadata, xudp bool) *vless.DstAddr {
|
||||||
|
@ -388,8 +388,11 @@ func (v *Vmess) SupportWithDialer() C.NetWork {
|
|||||||
return C.ALLNet
|
return C.ALLNet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Vmess) SupportDialerProxy() string {
|
// ProxyInfo implements C.ProxyAdapter
|
||||||
return v.option.DialerProxy
|
func (v *Vmess) ProxyInfo() C.ProxyInfo {
|
||||||
|
info := v.Base.ProxyInfo()
|
||||||
|
info.DialerProxy = v.option.DialerProxy
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenPacketOnStreamConn implements C.ProxyAdapter
|
// ListenPacketOnStreamConn implements C.ProxyAdapter
|
||||||
|
@ -611,32 +611,11 @@ func (r *refProxyAdapter) SupportUDP() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *refProxyAdapter) SupportXUDP() bool {
|
func (r *refProxyAdapter) ProxyInfo() C.ProxyInfo {
|
||||||
if r.proxyAdapter != nil {
|
if r.proxyAdapter != nil {
|
||||||
return r.proxyAdapter.SupportXUDP()
|
return r.proxyAdapter.ProxyInfo()
|
||||||
}
|
}
|
||||||
return false
|
return C.ProxyInfo{}
|
||||||
}
|
|
||||||
|
|
||||||
func (r *refProxyAdapter) SupportTFO() bool {
|
|
||||||
if r.proxyAdapter != nil {
|
|
||||||
return r.proxyAdapter.SupportTFO()
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *refProxyAdapter) SupportMPTCP() bool {
|
|
||||||
if r.proxyAdapter != nil {
|
|
||||||
return r.proxyAdapter.SupportMPTCP()
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *refProxyAdapter) SupportSMUX() bool {
|
|
||||||
if r.proxyAdapter != nil {
|
|
||||||
return r.proxyAdapter.SupportSMUX()
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *refProxyAdapter) MarshalJSON() ([]byte, error) {
|
func (r *refProxyAdapter) MarshalJSON() ([]byte, error) {
|
||||||
@ -674,27 +653,6 @@ func (r *refProxyAdapter) SupportUOT() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *refProxyAdapter) SupportDialerProxy() string {
|
|
||||||
if r.proxyAdapter != nil {
|
|
||||||
return r.proxyAdapter.SupportDialerProxy()
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *refProxyAdapter) SupportInterface() string {
|
|
||||||
if r.proxyAdapter != nil {
|
|
||||||
return r.proxyAdapter.SupportInterface()
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *refProxyAdapter) SupportRoutingMark() int {
|
|
||||||
if r.proxyAdapter != nil {
|
|
||||||
return r.proxyAdapter.SupportRoutingMark()
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *refProxyAdapter) SupportWithDialer() C.NetWork {
|
func (r *refProxyAdapter) SupportWithDialer() C.NetWork {
|
||||||
if r.proxyAdapter != nil {
|
if r.proxyAdapter != nil {
|
||||||
return r.proxyAdapter.SupportWithDialer()
|
return r.proxyAdapter.SupportWithDialer()
|
||||||
|
@ -99,18 +99,24 @@ type Dialer interface {
|
|||||||
ListenPacket(ctx context.Context, network, address string, rAddrPort netip.AddrPort) (net.PacketConn, error)
|
ListenPacket(ctx context.Context, network, address string, rAddrPort netip.AddrPort) (net.PacketConn, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProxyInfo struct {
|
||||||
|
XUDP bool
|
||||||
|
TFO bool
|
||||||
|
MPTCP bool
|
||||||
|
SMUX bool
|
||||||
|
Interface string
|
||||||
|
RoutingMark int
|
||||||
|
DialerProxy string
|
||||||
|
}
|
||||||
|
|
||||||
type ProxyAdapter interface {
|
type ProxyAdapter interface {
|
||||||
Name() string
|
Name() string
|
||||||
Type() AdapterType
|
Type() AdapterType
|
||||||
Addr() string
|
Addr() string
|
||||||
SupportUDP() bool
|
SupportUDP() bool
|
||||||
SupportXUDP() bool
|
|
||||||
SupportTFO() bool
|
// ProxyInfo contains some extra information maybe useful for MarshalJSON
|
||||||
SupportMPTCP() bool
|
ProxyInfo() ProxyInfo
|
||||||
SupportSMUX() bool
|
|
||||||
SupportInterface() string
|
|
||||||
SupportRoutingMark() int
|
|
||||||
SupportDialerProxy() string
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
|
|
||||||
// Deprecated: use DialContextWithDialer and ListenPacketWithDialer instead.
|
// Deprecated: use DialContextWithDialer and ListenPacketWithDialer instead.
|
||||||
|
Loading…
Reference in New Issue
Block a user