Skip to content

Commit

Permalink
chore: restful api displays more information
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Nov 21, 2024
1 parent 4623435 commit eb985b0
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 1 deletion.
4 changes: 4 additions & 0 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 12 additions & 0 deletions adapter/outbound/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/hysteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/hysteria2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/shadowsocksr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion adapter/outbound/snell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
})
}
Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/tuic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions adapter/outbound/vless.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions adapter/outbound/vmess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions adapter/outbound/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions constant/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit eb985b0

Please sign in to comment.