From 2b2644a76fcc75bc1a540b1f3d7d5493c3b966b2 Mon Sep 17 00:00:00 2001 From: metacubex Date: Sat, 28 Jan 2023 00:07:20 +0800 Subject: [PATCH] chore: restful api display xudp for VLESS and VMess --- adapter/adapter.go | 1 + adapter/outbound/base.go | 8 ++++++++ adapter/outbound/vless.go | 21 +++++++++++---------- adapter/outbound/vmess.go | 1 + constant/adapters.go | 1 + 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/adapter/adapter.go b/adapter/adapter.go index feef72be..ffb5ced0 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -92,6 +92,7 @@ func (p *Proxy) MarshalJSON() ([]byte, error) { mapping["history"] = p.DelayHistory() mapping["name"] = p.Name() mapping["udp"] = p.SupportUDP() + mapping["xudp"] = p.SupportXUDP() mapping["tfo"] = p.SupportTFO() return json.Marshal(mapping) } diff --git a/adapter/outbound/base.go b/adapter/outbound/base.go index dc339969..24de7d94 100644 --- a/adapter/outbound/base.go +++ b/adapter/outbound/base.go @@ -20,6 +20,7 @@ type Base struct { iface string tp C.AdapterType udp bool + xudp bool tfo bool rmark int id string @@ -89,6 +90,11 @@ 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 @@ -148,6 +154,7 @@ type BaseOption struct { Addr string Type C.AdapterType UDP bool + XUDP bool TFO bool Interface string RoutingMark int @@ -160,6 +167,7 @@ func NewBase(opt BaseOption) *Base { addr: opt.Addr, tp: opt.Type, udp: opt.UDP, + xudp: opt.XUDP, tfo: opt.TFO, iface: opt.Interface, rmark: opt.RoutingMark, diff --git a/adapter/outbound/vless.go b/adapter/outbound/vless.go index 449663f7..0bd56ff4 100644 --- a/adapter/outbound/vless.go +++ b/adapter/outbound/vless.go @@ -474,6 +474,16 @@ func NewVless(option VlessOption) (*Vless, error) { } } + switch option.PacketEncoding { + case "packetaddr", "packet": + option.PacketAddr = true + case "xudp": + option.XUDP = true + } + if option.XUDP { + option.PacketAddr = false + } + client, err := vless.NewClient(option.UUID, addons, option.FlowShow) if err != nil { return nil, err @@ -485,6 +495,7 @@ func NewVless(option VlessOption) (*Vless, error) { addr: net.JoinHostPort(option.Server, strconv.Itoa(option.Port)), tp: C.Vless, udp: option.UDP, + xudp: option.XUDP, iface: option.Interface, rmark: option.RoutingMark, prefer: C.NewDNSPrefer(option.IPVersion), @@ -493,16 +504,6 @@ func NewVless(option VlessOption) (*Vless, error) { option: &option, } - switch option.PacketEncoding { - case "packetaddr", "packet": - option.PacketAddr = true - case "xudp": - option.XUDP = true - } - if option.XUDP { - option.PacketAddr = false - } - switch option.Network { case "h2": if len(option.HTTP2Opts.Host) == 0 { diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index 999e1283..727da2ee 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -377,6 +377,7 @@ func NewVmess(option VmessOption) (*Vmess, error) { addr: net.JoinHostPort(option.Server, strconv.Itoa(option.Port)), tp: C.Vmess, udp: option.UDP, + xudp: option.XUDP, iface: option.Interface, rmark: option.RoutingMark, prefer: C.NewDNSPrefer(option.IPVersion), diff --git a/constant/adapters.go b/constant/adapters.go index c13a85c4..4480a953 100644 --- a/constant/adapters.go +++ b/constant/adapters.go @@ -92,6 +92,7 @@ type ProxyAdapter interface { Type() AdapterType Addr() string SupportUDP() bool + SupportXUDP() bool SupportTFO() bool MarshalJSON() ([]byte, error)