From bc4de6a026ce606e6026630380215ca228f242ba Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 10 Dec 2022 23:11:35 -0500 Subject: [PATCH] Fix VLESS client doesn't handle traffic if not send data first Certain ssh, mySQL and reverse proxy need server data first in a connection --- proxy/vless/encoding/encoding.go | 2 +- proxy/vless/outbound/outbound.go | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/proxy/vless/encoding/encoding.go b/proxy/vless/encoding/encoding.go index bbe3b1e7..e1987d98 100644 --- a/proxy/vless/encoding/encoding.go +++ b/proxy/vless/encoding/encoding.go @@ -442,7 +442,7 @@ func XtlsFilterTls(buffer buf.MultiBuffer, numberOfPacketToFilter *int, enableXt *numberOfPacketToFilter = 0 return } - newError("XtlsFilterTls inclusive server hello ", b.Len(), " ", *remainingServerHello).WriteToLog(session.ExportIDToError(ctx)) + newError("XtlsFilterTls inconclusive server hello ", b.Len(), " ", *remainingServerHello).WriteToLog(session.ExportIDToError(ctx)) } if *numberOfPacketToFilter <= 0 { newError("XtlsFilterTls stop filtering", buffer.Len()).WriteToLog(session.ExportIDToError(ctx)) diff --git a/proxy/vless/outbound/outbound.go b/proxy/vless/outbound/outbound.go index 7cfbbfd0..6dde2736 100644 --- a/proxy/vless/outbound/outbound.go +++ b/proxy/vless/outbound/outbound.go @@ -5,6 +5,7 @@ package outbound import ( "context" "syscall" + "time" "github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common/buf" @@ -217,20 +218,26 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte serverWriter = xudp.NewPacketWriter(serverWriter, target) } userUUID := account.ID.Bytes() - multiBuffer, err1 := clientReader.ReadMultiBuffer() - if err1 != nil { - return err1 // ... - } - if requestAddons.Flow == vless.XRV { - encoding.XtlsFilterTls(multiBuffer, &numberOfPacketToFilter, &enableXtls, &isTLS12orAbove, &isTLS, &cipher, &remainingServerHello, ctx) - if isTLS { - for i, b := range multiBuffer { - multiBuffer[i] = encoding.XtlsPadding(b, 0x00, &userUUID, ctx) + timeoutReader, ok := clientReader.(buf.TimeoutReader) + if ok { + multiBuffer, err1 := timeoutReader.ReadMultiBufferTimeout(time.Millisecond*500) + if err1 == nil { + if requestAddons.Flow == vless.XRV { + encoding.XtlsFilterTls(multiBuffer, &numberOfPacketToFilter, &enableXtls, &isTLS12orAbove, &isTLS, &cipher, &remainingServerHello, ctx) + if isTLS { + for i, b := range multiBuffer { + multiBuffer[i] = encoding.XtlsPadding(b, 0x00, &userUUID, ctx) + } + } } + if err := serverWriter.WriteMultiBuffer(multiBuffer); err != nil { + return err // ... + } + } else if err1 != buf.ErrReadTimeout { + return err1 } - } - if err := serverWriter.WriteMultiBuffer(multiBuffer); err != nil { - return err // ... + } else { + newError("Reader is not timeout reader, will send out vless header separately from first payload").AtDebug().WriteToLog(session.ExportIDToError(ctx)) } // Flush; bufferWriter.WriteMultiBufer now is bufferWriter.writer.WriteMultiBuffer if err := bufferWriter.SetBuffered(false); err != nil {