From 74416570d4913952e2b878296cf8e78e2701ff23 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Tue, 31 Jan 2023 18:02:12 +0000 Subject: [PATCH] Format VLESS inbound.go and outbound.go --- proxy/vless/inbound/inbound.go | 8 ++++---- proxy/vless/outbound/outbound.go | 15 ++++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/proxy/vless/inbound/inbound.go b/proxy/vless/inbound/inbound.go index d4ea246d..5b0833ca 100644 --- a/proxy/vless/inbound/inbound.go +++ b/proxy/vless/inbound/inbound.go @@ -485,16 +485,13 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s var p uintptr if tlsConn, ok := iConn.(*tls.Conn); ok { if tlsConn.ConnectionState().Version != gotls.VersionTLS13 { - return newError(`failed to use ` + requestAddons.Flow + `, found outer tls version `, tlsConn.ConnectionState().Version).AtWarning() + return newError(`failed to use `+requestAddons.Flow+`, found outer tls version `, tlsConn.ConnectionState().Version).AtWarning() } netConn = tlsConn.NetConn() if pc, ok := netConn.(*proxyproto.Conn); ok { netConn = pc.Raw() // 8192 > 4096, there is no need to process pc's bufReader } - if sc, ok := netConn.(syscall.Conn); ok { - rawConn, _ = sc.SyscallConn() - } t = reflect.TypeOf(tlsConn.Conn).Elem() p = uintptr(unsafe.Pointer(tlsConn.Conn)) } else if _, ok := iConn.(*tls.UConn); ok { @@ -504,6 +501,9 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s } else { return newError("XTLS only supports TCP, mKCP and DomainSocket for now.").AtWarning() } + if sc, ok := netConn.(syscall.Conn); ok { + rawConn, _ = sc.SyscallConn() + } i, _ := t.FieldByName("input") r, _ := t.FieldByName("rawInput") input = (*bytes.Reader)(unsafe.Pointer(p + i.Offset)) diff --git a/proxy/vless/outbound/outbound.go b/proxy/vless/outbound/outbound.go index a4c70a2b..82505911 100644 --- a/proxy/vless/outbound/outbound.go +++ b/proxy/vless/outbound/outbound.go @@ -158,16 +158,10 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte var p uintptr if tlsConn, ok := iConn.(*tls.Conn); ok { netConn = tlsConn.NetConn() - if sc, ok := netConn.(syscall.Conn); ok { - rawConn, _ = sc.SyscallConn() - } t = reflect.TypeOf(tlsConn.Conn).Elem() p = uintptr(unsafe.Pointer(tlsConn.Conn)) } else if utlsConn, ok := iConn.(*tls.UConn); ok { - netConn = utlsConn.Conn.NetConn() - if sc, ok := netConn.(syscall.Conn); ok { - rawConn, _ = sc.SyscallConn() - } + netConn = utlsConn.NetConn() t = reflect.TypeOf(utlsConn.Conn).Elem() p = uintptr(unsafe.Pointer(utlsConn.Conn)) } else if _, ok := iConn.(*xtls.Conn); ok { @@ -175,6 +169,9 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte } else { return newError("XTLS only supports TCP, mKCP and DomainSocket for now.").AtWarning() } + if sc, ok := netConn.(syscall.Conn); ok { + rawConn, _ = sc.SyscallConn() + } i, _ := t.FieldByName("input") r, _ := t.FieldByName("rawInput") input = (*bytes.Reader)(unsafe.Pointer(p + i.Offset)) @@ -265,11 +262,11 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte if rawConn != nil && requestAddons.Flow == vless.XRV { if tlsConn, ok := iConn.(*tls.Conn); ok { if tlsConn.ConnectionState().Version != gotls.VersionTLS13 { - return newError(`failed to use ` + requestAddons.Flow + `, found outer tls version `, tlsConn.ConnectionState().Version).AtWarning() + return newError(`failed to use `+requestAddons.Flow+`, found outer tls version `, tlsConn.ConnectionState().Version).AtWarning() } } else if utlsConn, ok := iConn.(*tls.UConn); ok { if utlsConn.ConnectionState().Version != utls.VersionTLS13 { - return newError(`failed to use ` + requestAddons.Flow + `, found outer tls version `, utlsConn.ConnectionState().Version).AtWarning() + return newError(`failed to use `+requestAddons.Flow+`, found outer tls version `, utlsConn.ConnectionState().Version).AtWarning() } } var counter stats.Counter