chore: cleaned up some weird code

This commit is contained in:
wwqgtxx 2024-11-26 10:04:41 +08:00
parent eb985b002e
commit f805a9f4c6
17 changed files with 99 additions and 126 deletions

View File

@ -164,13 +164,16 @@ func (p *Proxy) MarshalJSON() ([]byte, error) {
mapping["name"] = p.Name()
mapping["udp"] = p.SupportUDP()
mapping["uot"] = p.SupportUOT()
mapping["xudp"] = p.SupportXUDP()
mapping["tfo"] = p.SupportTFO()
mapping["mptcp"] = p.SupportMPTCP()
mapping["smux"] = p.SupportSMUX()
mapping["interface"] = p.SupportInterface()
mapping["dialer-proxy"] = p.SupportDialerProxy()
mapping["routing-mark"] = p.SupportRoutingMark()
proxyInfo := p.ProxyInfo()
mapping["xudp"] = proxyInfo.XUDP
mapping["tfo"] = proxyInfo.TFO
mapping["mptcp"] = proxyInfo.MPTCP
mapping["smux"] = proxyInfo.SMUX
mapping["interface"] = proxyInfo.Interface
mapping["dialer-proxy"] = proxyInfo.DialerProxy
mapping["routing-mark"] = proxyInfo.RoutingMark
return json.Marshal(mapping)
}

View File

@ -85,36 +85,15 @@ func (b *Base) SupportUDP() bool {
return b.udp
}
// SupportXUDP implements C.ProxyAdapter
func (b *Base) SupportXUDP() bool {
return b.xudp
}
// SupportTFO implements C.ProxyAdapter
func (b *Base) SupportTFO() bool {
return b.tfo
}
// 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
// ProxyInfo implements C.ProxyAdapter
func (b *Base) ProxyInfo() (info C.ProxyInfo) {
info.XUDP = b.xudp
info.TFO = b.tfo
info.MPTCP = b.mpTcp
info.SMUX = false
info.Interface = b.iface
info.RoutingMark = b.rmark
return
}
// IsL3Protocol implements C.ProxyAdapter

View File

@ -92,9 +92,11 @@ func (h *Http) SupportWithDialer() C.NetWork {
return C.TCP
}
// SupportDialerProxy implements C.ProxyAdapter
func (h *Http) SupportDialerProxy() string {
return h.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (h *Http) ProxyInfo() C.ProxyInfo {
info := h.Base.ProxyInfo()
info.DialerProxy = h.option.DialerProxy
return info
}
func (h *Http) shakeHand(metadata *C.Metadata, rw io.ReadWriter) error {

View File

@ -87,9 +87,11 @@ func (h *Hysteria) genHdc(ctx context.Context, opts ...dialer.Option) utils.Pack
}
}
// SupportDialerProxy implements C.ProxyAdapter
func (h *Hysteria) SupportDialerProxy() string {
return h.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (h *Hysteria) ProxyInfo() C.ProxyInfo {
info := h.Base.ProxyInfo()
info.DialerProxy = h.option.DialerProxy
return info
}
type HysteriaOption struct {

View File

@ -96,9 +96,11 @@ func closeHysteria2(h *Hysteria2) {
}
}
// SupportDialerProxy implements C.ProxyAdapter
func (h *Hysteria2) SupportDialerProxy() string {
return h.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (h *Hysteria2) ProxyInfo() C.ProxyInfo {
info := h.Base.ProxyInfo()
info.DialerProxy = h.option.DialerProxy
return info
}
func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {

View File

@ -196,9 +196,11 @@ func (ss *ShadowSocks) SupportWithDialer() C.NetWork {
return C.ALLNet
}
// SupportDialerProxy implements C.ProxyAdapter
func (ss *ShadowSocks) SupportDialerProxy() string {
return ss.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (ss *ShadowSocks) ProxyInfo() C.ProxyInfo {
info := ss.Base.ProxyInfo()
info.DialerProxy = ss.option.DialerProxy
return info
}
// ListenPacketOnStreamConn implements C.ProxyAdapter

View File

@ -122,9 +122,11 @@ func (ssr *ShadowSocksR) SupportWithDialer() C.NetWork {
return C.ALLNet
}
// SupportDialerProxy implements C.ProxyAdapter
func (ssr *ShadowSocksR) SupportDialerProxy() string {
return ssr.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (ssr *ShadowSocksR) ProxyInfo() C.ProxyInfo {
info := ssr.Base.ProxyInfo()
info.DialerProxy = ssr.option.DialerProxy
return info
}
func NewShadowSocksR(option ShadowSocksROption) (*ShadowSocksR, error) {

View File

@ -97,8 +97,10 @@ func (s *SingMux) SupportUOT() bool {
return true
}
func (s *SingMux) SupportSMUX() bool {
return true
func (s *SingMux) ProxyInfo() C.ProxyInfo {
info := s.ProxyAdapter.ProxyInfo()
info.SMUX = true
return info
}
func closeSingMux(s *SingMux) {

View File

@ -141,9 +141,11 @@ func (s *Snell) SupportUOT() bool {
return true
}
// SupportDialerProxy implements C.ProxyAdapter
func (s *Snell) SupportDialerProxy() string {
return s.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (s *Snell) ProxyInfo() C.ProxyInfo {
info := s.Base.ProxyInfo()
info.DialerProxy = s.option.DialerProxy
return info
}
func NewSnell(option SnellOption) (*Snell, error) {

View File

@ -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
}
// SupportDialerProxy implements C.ProxyAdapter
func (ss *Socks5) SupportDialerProxy() string {
return ss.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (ss *Socks5) ProxyInfo() C.ProxyInfo {
info := ss.Base.ProxyInfo()
info.DialerProxy = ss.option.DialerProxy
return info
}
func NewSocks5(option Socks5Option) (*Socks5, error) {

View File

@ -121,9 +121,11 @@ func closeSsh(s *Ssh) {
_ = s.client.Close()
}
// SupportWithDialer implements C.ProxyAdapter
func (s *Ssh) SupportDialerProxy() string {
return s.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (s *Ssh) ProxyInfo() C.ProxyInfo {
info := s.Base.ProxyInfo()
info.DialerProxy = s.option.DialerProxy
return info
}
func NewSsh(option SshOption) (*Ssh, error) {

View File

@ -244,9 +244,11 @@ func (t *Trojan) SupportUOT() bool {
return true
}
// SupportDialerProxy implements C.ProxyAdapter
func (t *Trojan) SupportDialerProxy() string {
return t.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (t *Trojan) ProxyInfo() C.ProxyInfo {
info := t.Base.ProxyInfo()
info.DialerProxy = t.option.DialerProxy
return info
}
func NewTrojan(option TrojanOption) (*Trojan, error) {

View File

@ -146,9 +146,11 @@ func (t *Tuic) dialWithDialer(ctx context.Context, dialer C.Dialer) (transport *
return
}
// SupportDialerProxy implements C.ProxyAdapter
func (t *Tuic) SupportDialerProxy() string {
return t.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (t *Tuic) ProxyInfo() C.ProxyInfo {
info := t.Base.ProxyInfo()
info.DialerProxy = t.option.DialerProxy
return info
}
func NewTuic(option TuicOption) (*Tuic, error) {

View File

@ -379,9 +379,11 @@ func (v *Vless) SupportUOT() bool {
return true
}
// SupportDialerProxy implements C.ProxyAdapter
func (v *Vless) SupportDialerProxy() string {
return v.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (v *Vless) ProxyInfo() C.ProxyInfo {
info := v.Base.ProxyInfo()
info.DialerProxy = v.option.DialerProxy
return info
}
func parseVlessAddr(metadata *C.Metadata, xudp bool) *vless.DstAddr {

View File

@ -388,8 +388,11 @@ func (v *Vmess) SupportWithDialer() C.NetWork {
return C.ALLNet
}
func (v *Vmess) SupportDialerProxy() string {
return v.option.DialerProxy
// ProxyInfo implements C.ProxyAdapter
func (v *Vmess) ProxyInfo() C.ProxyInfo {
info := v.Base.ProxyInfo()
info.DialerProxy = v.option.DialerProxy
return info
}
// ListenPacketOnStreamConn implements C.ProxyAdapter

View File

@ -611,32 +611,11 @@ func (r *refProxyAdapter) SupportUDP() bool {
return false
}
func (r *refProxyAdapter) SupportXUDP() bool {
func (r *refProxyAdapter) ProxyInfo() C.ProxyInfo {
if r.proxyAdapter != nil {
return r.proxyAdapter.SupportXUDP()
return r.proxyAdapter.ProxyInfo()
}
return false
}
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
return C.ProxyInfo{}
}
func (r *refProxyAdapter) MarshalJSON() ([]byte, error) {
@ -674,27 +653,6 @@ func (r *refProxyAdapter) SupportUOT() bool {
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 {
if r.proxyAdapter != nil {
return r.proxyAdapter.SupportWithDialer()

View File

@ -99,18 +99,24 @@ type Dialer interface {
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 {
Name() string
Type() AdapterType
Addr() string
SupportUDP() bool
SupportXUDP() bool
SupportTFO() bool
SupportMPTCP() bool
SupportSMUX() bool
SupportInterface() string
SupportRoutingMark() int
SupportDialerProxy() string
// ProxyInfo contains some extra information maybe useful for MarshalJSON
ProxyInfo() ProxyInfo
MarshalJSON() ([]byte, error)
// Deprecated: use DialContextWithDialer and ListenPacketWithDialer instead.