chore: do not apply padding for nonTLS packet with contentLen over 900

This commit is contained in:
gVisor bot 2023-03-07 16:34:57 +08:00
parent a0760ece28
commit e7a8b23efa

View file

@ -24,14 +24,16 @@ 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 {
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
buffer.Write(userUUID.Bytes())
@ -48,14 +50,16 @@ 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 {
mutex.Lock()
if contentLen < 900 {
if paddingTLS {
//log.Debugln("long padding")
paddingLen = fastrand.Int31n(500) + 900 - contentLen
} else {
paddingLen = fastrand.Int31n(256)
}
}
mutex.Unlock()
binary.BigEndian.PutUint16(buffer.ExtendHeader(2), uint16(paddingLen))