From e7a8b23efae95c91438b2ff9b288ad731ffe0d29 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Tue, 7 Mar 2023 16:34:57 +0800 Subject: [PATCH] chore: do not apply padding for nonTLS packet with contentLen over 900 --- transport/vless/vision.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/transport/vless/vision.go b/transport/vless/vision.go index b80fbb71..857d9150 100644 --- a/transport/vless/vision.go +++ b/transport/vless/vision.go @@ -24,13 +24,15 @@ var mutex sync.RWMutex func WriteWithPadding(buffer *buf.Buffer, p []byte, command byte, userUUID *uuid.UUID, paddingTLS bool) { contentLen := int32(len(p)) - mutex.Lock() var paddingLen int32 - if contentLen < 900 && paddingTLS { - //log.Debugln("long padding") - paddingLen = fastrand.Int31n(500) + 900 - contentLen - } else { - paddingLen = fastrand.Int31n(256) + mutex.Lock() + if contentLen < 900 { + if paddingTLS { + //log.Debugln("long padding") + paddingLen = fastrand.Int31n(500) + 900 - contentLen + } else { + paddingLen = fastrand.Int31n(256) + } } mutex.Unlock() if userUUID != nil { // unnecessary, but keep the same with Xray @@ -48,13 +50,15 @@ func WriteWithPadding(buffer *buf.Buffer, p []byte, command byte, userUUID *uuid func ApplyPadding(buffer *buf.Buffer, command byte, userUUID *uuid.UUID, paddingTLS bool) { contentLen := int32(buffer.Len()) - mutex.Lock() var paddingLen int32 - if contentLen < 900 && paddingTLS { - //log.Debugln("long padding") - paddingLen = fastrand.Int31n(500) + 900 - contentLen - } else { - paddingLen = fastrand.Int31n(256) + mutex.Lock() + if contentLen < 900 { + if paddingTLS { + //log.Debugln("long padding") + paddingLen = fastrand.Int31n(500) + 900 - contentLen + } else { + paddingLen = fastrand.Int31n(256) + } } mutex.Unlock()