chore: do not apply padding for nonTLS packet with contentLen over 900
This commit is contained in:
parent
a0760ece28
commit
e7a8b23efa
1 changed files with 16 additions and 12 deletions
|
@ -24,13 +24,15 @@ var mutex sync.RWMutex
|
||||||
|
|
||||||
func WriteWithPadding(buffer *buf.Buffer, p []byte, command byte, userUUID *uuid.UUID, paddingTLS bool) {
|
func WriteWithPadding(buffer *buf.Buffer, p []byte, command byte, userUUID *uuid.UUID, paddingTLS bool) {
|
||||||
contentLen := int32(len(p))
|
contentLen := int32(len(p))
|
||||||
mutex.Lock()
|
|
||||||
var paddingLen int32
|
var paddingLen int32
|
||||||
if contentLen < 900 && paddingTLS {
|
mutex.Lock()
|
||||||
//log.Debugln("long padding")
|
if contentLen < 900 {
|
||||||
paddingLen = fastrand.Int31n(500) + 900 - contentLen
|
if paddingTLS {
|
||||||
} else {
|
//log.Debugln("long padding")
|
||||||
paddingLen = fastrand.Int31n(256)
|
paddingLen = fastrand.Int31n(500) + 900 - contentLen
|
||||||
|
} else {
|
||||||
|
paddingLen = fastrand.Int31n(256)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
if userUUID != nil { // unnecessary, but keep the same with Xray
|
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) {
|
func ApplyPadding(buffer *buf.Buffer, command byte, userUUID *uuid.UUID, paddingTLS bool) {
|
||||||
contentLen := int32(buffer.Len())
|
contentLen := int32(buffer.Len())
|
||||||
mutex.Lock()
|
|
||||||
var paddingLen int32
|
var paddingLen int32
|
||||||
if contentLen < 900 && paddingTLS {
|
mutex.Lock()
|
||||||
//log.Debugln("long padding")
|
if contentLen < 900 {
|
||||||
paddingLen = fastrand.Int31n(500) + 900 - contentLen
|
if paddingTLS {
|
||||||
} else {
|
//log.Debugln("long padding")
|
||||||
paddingLen = fastrand.Int31n(256)
|
paddingLen = fastrand.Int31n(500) + 900 - contentLen
|
||||||
|
} else {
|
||||||
|
paddingLen = fastrand.Int31n(256)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue