From eb985b002e5aa61c4c2208646f33180c4fc938f9 Mon Sep 17 00:00:00 2001 From: xishang0128 Date: Thu, 21 Nov 2024 22:50:54 +0800 Subject: [PATCH] chore: restful api displays more information --- adapter/adapter.go | 4 ++++ adapter/outbound/base.go | 12 ++++++++++++ adapter/outbound/http.go | 5 +++++ adapter/outbound/hysteria.go | 5 +++++ adapter/outbound/hysteria2.go | 5 +++++ adapter/outbound/shadowsocks.go | 5 +++++ adapter/outbound/shadowsocksr.go | 5 +++++ adapter/outbound/snell.go | 7 ++++++- adapter/outbound/socks5.go | 5 +++++ adapter/outbound/ssh.go | 5 +++++ adapter/outbound/trojan.go | 5 +++++ adapter/outbound/tuic.go | 5 +++++ adapter/outbound/vless.go | 5 +++++ adapter/outbound/vmess.go | 4 ++++ adapter/outbound/wireguard.go | 21 +++++++++++++++++++++ constant/adapters.go | 3 +++ 16 files changed, 100 insertions(+), 1 deletion(-) diff --git a/adapter/adapter.go b/adapter/adapter.go index 411069fb..befe2113 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -163,10 +163,14 @@ func (p *Proxy) MarshalJSON() ([]byte, error) { mapping["alive"] = p.alive.Load() 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() return json.Marshal(mapping) } diff --git a/adapter/outbound/base.go b/adapter/outbound/base.go index 93e8d979..c15e7115 100644 --- a/adapter/outbound/base.go +++ b/adapter/outbound/base.go @@ -105,6 +105,18 @@ 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 func (b *Base) IsL3Protocol(metadata *C.Metadata) bool { return false diff --git a/adapter/outbound/http.go b/adapter/outbound/http.go index ebb1d67c..0f72f759 100644 --- a/adapter/outbound/http.go +++ b/adapter/outbound/http.go @@ -92,6 +92,11 @@ func (h *Http) SupportWithDialer() C.NetWork { return C.TCP } +// SupportDialerProxy implements C.ProxyAdapter +func (h *Http) SupportDialerProxy() string { + return h.option.DialerProxy +} + func (h *Http) shakeHand(metadata *C.Metadata, rw io.ReadWriter) error { addr := metadata.RemoteAddress() HeaderString := "CONNECT " + addr + " HTTP/1.1\r\n" diff --git a/adapter/outbound/hysteria.go b/adapter/outbound/hysteria.go index 55c66c45..964acb96 100644 --- a/adapter/outbound/hysteria.go +++ b/adapter/outbound/hysteria.go @@ -87,6 +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 +} + type HysteriaOption struct { BasicOption Name string `proxy:"name"` diff --git a/adapter/outbound/hysteria2.go b/adapter/outbound/hysteria2.go index c1a255a7..fbf0c2ec 100644 --- a/adapter/outbound/hysteria2.go +++ b/adapter/outbound/hysteria2.go @@ -96,6 +96,11 @@ func closeHysteria2(h *Hysteria2) { } } +// SupportDialerProxy implements C.ProxyAdapter +func (h *Hysteria2) SupportDialerProxy() string { + return h.option.DialerProxy +} + func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) { addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port)) var salamanderPassword string diff --git a/adapter/outbound/shadowsocks.go b/adapter/outbound/shadowsocks.go index 021fbc0a..a7c8f5bb 100644 --- a/adapter/outbound/shadowsocks.go +++ b/adapter/outbound/shadowsocks.go @@ -196,6 +196,11 @@ func (ss *ShadowSocks) SupportWithDialer() C.NetWork { return C.ALLNet } +// SupportDialerProxy implements C.ProxyAdapter +func (ss *ShadowSocks) SupportDialerProxy() string { + return ss.option.DialerProxy +} + // ListenPacketOnStreamConn implements C.ProxyAdapter func (ss *ShadowSocks) ListenPacketOnStreamConn(ctx context.Context, c net.Conn, metadata *C.Metadata) (_ C.PacketConn, err error) { if ss.option.UDPOverTCP { diff --git a/adapter/outbound/shadowsocksr.go b/adapter/outbound/shadowsocksr.go index 437695b4..d217dd16 100644 --- a/adapter/outbound/shadowsocksr.go +++ b/adapter/outbound/shadowsocksr.go @@ -122,6 +122,11 @@ func (ssr *ShadowSocksR) SupportWithDialer() C.NetWork { return C.ALLNet } +// SupportDialerProxy implements C.ProxyAdapter +func (ssr *ShadowSocksR) SupportDialerProxy() string { + return ssr.option.DialerProxy +} + func NewShadowSocksR(option ShadowSocksROption) (*ShadowSocksR, error) { // SSR protocol compatibility // https://github.com/metacubex/mihomo/pull/2056 diff --git a/adapter/outbound/snell.go b/adapter/outbound/snell.go index f6a4b4f9..7df3dd48 100644 --- a/adapter/outbound/snell.go +++ b/adapter/outbound/snell.go @@ -141,6 +141,11 @@ func (s *Snell) SupportUOT() bool { return true } +// SupportDialerProxy implements C.ProxyAdapter +func (s *Snell) SupportDialerProxy() string { + return s.option.DialerProxy +} + func NewSnell(option SnellOption) (*Snell, error) { addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port)) psk := []byte(option.Psk) @@ -204,7 +209,7 @@ func NewSnell(option SnellOption) (*Snell, error) { if err != nil { return nil, err } - + return streamConn(c, streamOption{psk, option.Version, addr, obfsOption}), nil }) } diff --git a/adapter/outbound/socks5.go b/adapter/outbound/socks5.go index 1908167a..1b3f93c5 100644 --- a/adapter/outbound/socks5.go +++ b/adapter/outbound/socks5.go @@ -171,6 +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 +} + func NewSocks5(option Socks5Option) (*Socks5, error) { var tlsConfig *tls.Config if option.TLS { diff --git a/adapter/outbound/ssh.go b/adapter/outbound/ssh.go index 9e23b463..5ea9b29c 100644 --- a/adapter/outbound/ssh.go +++ b/adapter/outbound/ssh.go @@ -121,6 +121,11 @@ func closeSsh(s *Ssh) { _ = s.client.Close() } +// SupportWithDialer implements C.ProxyAdapter +func (s *Ssh) SupportDialerProxy() string { + return s.option.DialerProxy +} + func NewSsh(option SshOption) (*Ssh, error) { addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port)) diff --git a/adapter/outbound/trojan.go b/adapter/outbound/trojan.go index b3a611af..a23a52f3 100644 --- a/adapter/outbound/trojan.go +++ b/adapter/outbound/trojan.go @@ -244,6 +244,11 @@ func (t *Trojan) SupportUOT() bool { return true } +// SupportDialerProxy implements C.ProxyAdapter +func (t *Trojan) SupportDialerProxy() string { + return t.option.DialerProxy +} + func NewTrojan(option TrojanOption) (*Trojan, error) { addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port)) diff --git a/adapter/outbound/tuic.go b/adapter/outbound/tuic.go index 666e72fa..f2c218db 100644 --- a/adapter/outbound/tuic.go +++ b/adapter/outbound/tuic.go @@ -146,6 +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 +} + func NewTuic(option TuicOption) (*Tuic, error) { addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port)) serverName := option.Server diff --git a/adapter/outbound/vless.go b/adapter/outbound/vless.go index 79058874..7fb409ae 100644 --- a/adapter/outbound/vless.go +++ b/adapter/outbound/vless.go @@ -379,6 +379,11 @@ func (v *Vless) SupportUOT() bool { return true } +// SupportDialerProxy implements C.ProxyAdapter +func (v *Vless) SupportDialerProxy() string { + return v.option.DialerProxy +} + func parseVlessAddr(metadata *C.Metadata, xudp bool) *vless.DstAddr { var addrType byte var addr []byte diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index 8797374d..a10ac2e1 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -388,6 +388,10 @@ func (v *Vmess) SupportWithDialer() C.NetWork { return C.ALLNet } +func (v *Vmess) SupportDialerProxy() string { + return v.option.DialerProxy +} + // ListenPacketOnStreamConn implements C.ProxyAdapter func (v *Vmess) ListenPacketOnStreamConn(ctx context.Context, c net.Conn, metadata *C.Metadata) (_ C.PacketConn, err error) { // vmess use stream-oriented udp with a special address, so we need a net.UDPAddr diff --git a/adapter/outbound/wireguard.go b/adapter/outbound/wireguard.go index ca732baa..470dc523 100644 --- a/adapter/outbound/wireguard.go +++ b/adapter/outbound/wireguard.go @@ -674,6 +674,27 @@ 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() diff --git a/constant/adapters.go b/constant/adapters.go index 2bbcffba..ade0100c 100644 --- a/constant/adapters.go +++ b/constant/adapters.go @@ -108,6 +108,9 @@ type ProxyAdapter interface { SupportTFO() bool SupportMPTCP() bool SupportSMUX() bool + SupportInterface() string + SupportRoutingMark() int + SupportDialerProxy() string MarshalJSON() ([]byte, error) // Deprecated: use DialContextWithDialer and ListenPacketWithDialer instead.