mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-14 21:31:16 +08:00
chore: Vision padding upgrade
This commit is contained in:
parent
bccc6aa8d1
commit
8771fa5c17
@ -241,7 +241,7 @@ func (vc *Conn) WriteBuffer(buffer *buf.Buffer) error {
|
||||
command = commandPaddingEnd
|
||||
|
||||
// disable XTLS
|
||||
vc.readProcess = false
|
||||
//vc.readProcess = false
|
||||
vc.writeFilterApplicationData = false
|
||||
vc.packetsToFilter = 0
|
||||
} else if buffer.Len() > 6 && bytes.Equal(buffer.To(3), tlsApplicationDataStart) || vc.packetsToFilter <= 0 {
|
||||
@ -252,7 +252,7 @@ func (vc *Conn) WriteBuffer(buffer *buf.Buffer) error {
|
||||
}
|
||||
vc.writeFilterApplicationData = false
|
||||
}
|
||||
ApplyPadding(buffer, command, nil)
|
||||
ApplyPadding(buffer, command, nil, vc.isTLS)
|
||||
err := vc.ExtendedWriter.WriteBuffer(buffer)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -276,7 +276,7 @@ func (vc *Conn) WriteBuffer(buffer *buf.Buffer) error {
|
||||
}
|
||||
vc.writeFilterApplicationData = false
|
||||
}
|
||||
ApplyPadding(buffer2, command, nil)
|
||||
ApplyPadding(buffer2, command, nil, vc.isTLS)
|
||||
err = vc.ExtendedWriter.WriteBuffer(buffer2)
|
||||
if vc.writeDirect {
|
||||
vc.ExtendedWriter = N.NewExtendedWriter(vc.Conn)
|
||||
@ -352,19 +352,19 @@ func (vc *Conn) sendRequest(p []byte) bool {
|
||||
|
||||
if isVision && !vc.dst.UDP && !vc.dst.Mux {
|
||||
if len(p) == 0 {
|
||||
WriteWithPadding(buffer, nil, commandPaddingContinue, vc.id)
|
||||
WriteWithPadding(buffer, nil, commandPaddingContinue, vc.id, vc.isTLS)
|
||||
} else {
|
||||
vc.FilterTLS(p)
|
||||
if vc.isTLS {
|
||||
WriteWithPadding(buffer, p, commandPaddingContinue, vc.id)
|
||||
} else {
|
||||
buf.Must(buf.Error(buffer.Write(p)))
|
||||
|
||||
// disable XTLS
|
||||
vc.readProcess = false
|
||||
vc.writeFilterApplicationData = false
|
||||
vc.packetsToFilter = 0
|
||||
}
|
||||
//if vc.isTLS {
|
||||
WriteWithPadding(buffer, p, commandPaddingContinue, vc.id, vc.isTLS)
|
||||
//} else {
|
||||
// buf.Must(buf.Error(buffer.Write(p)))
|
||||
//
|
||||
// // disable XTLS
|
||||
// vc.readProcess = false
|
||||
// vc.writeFilterApplicationData = false
|
||||
// vc.packetsToFilter = 0
|
||||
//}
|
||||
}
|
||||
} else {
|
||||
buf.Must(buf.Error(buffer.Write(p)))
|
||||
|
@ -19,16 +19,22 @@ const (
|
||||
commandPaddingDirect byte = 0x02
|
||||
)
|
||||
|
||||
func WriteWithPadding(buffer *buf.Buffer, p []byte, command byte, userUUID *uuid.UUID) {
|
||||
func WriteWithPadding(buffer *buf.Buffer, p []byte, command byte, userUUID *uuid.UUID, paddingTLS bool) {
|
||||
contentLen := int32(len(p))
|
||||
var paddingLen int32
|
||||
if contentLen < 900 {
|
||||
if contentLen < 900 && paddingTLS {
|
||||
log.Debugln("long padding")
|
||||
paddingLen = rand.Int31n(500) + 900 - contentLen
|
||||
} else {
|
||||
paddingLen = rand.Int31n(256)
|
||||
}
|
||||
if paddingLen > buf.BufferSize-21-contentLen {
|
||||
paddingLen = buf.BufferSize - 21 - contentLen
|
||||
}
|
||||
|
||||
if userUUID != nil { // unnecessary, but keep the same with Xray
|
||||
buffer.Write(userUUID.Bytes())
|
||||
}
|
||||
|
||||
buffer.WriteByte(command)
|
||||
binary.BigEndian.PutUint16(buffer.Extend(2), uint16(contentLen))
|
||||
binary.BigEndian.PutUint16(buffer.Extend(2), uint16(paddingLen))
|
||||
@ -37,13 +43,18 @@ func WriteWithPadding(buffer *buf.Buffer, p []byte, command byte, userUUID *uuid
|
||||
log.Debugln("XTLS Vision write padding1: command=%v, payloadLen=%v, paddingLen=%v", command, contentLen, paddingLen)
|
||||
}
|
||||
|
||||
func ApplyPadding(buffer *buf.Buffer, command byte, userUUID *uuid.UUID) {
|
||||
func ApplyPadding(buffer *buf.Buffer, command byte, userUUID *uuid.UUID, paddingTLS bool) {
|
||||
contentLen := int32(buffer.Len())
|
||||
var paddingLen int32
|
||||
if contentLen < 900 {
|
||||
if contentLen < 900 && paddingTLS {
|
||||
log.Debugln("long padding")
|
||||
paddingLen = rand.Int31n(500) + 900 - contentLen
|
||||
} else {
|
||||
paddingLen = rand.Int31n(256)
|
||||
}
|
||||
if paddingLen > buf.BufferSize-21-contentLen {
|
||||
paddingLen = buf.BufferSize - 21 - contentLen
|
||||
}
|
||||
|
||||
binary.BigEndian.PutUint16(buffer.ExtendHeader(2), uint16(paddingLen))
|
||||
binary.BigEndian.PutUint16(buffer.ExtendHeader(2), uint16(contentLen))
|
||||
buffer.ExtendHeader(1)[0] = command
|
||||
|
Loading…
Reference in New Issue
Block a user