@@ -170,7 +170,7 @@ func (vc *Conn) WriteBuffer(buffer *buf.Buffer) (err error) {
170
170
if vc .needHandshake {
171
171
vc .needHandshake = false
172
172
if buffer .IsEmpty () {
173
- ApplyPadding (buffer , commandPaddingContinue , vc .userUUID , false )
173
+ ApplyPadding (buffer , commandPaddingContinue , vc .userUUID , true ) // we do a long padding to hide vless header
174
174
} else {
175
175
vc .FilterTLS (buffer .Bytes ())
176
176
ApplyPadding (buffer , commandPaddingContinue , vc .userUUID , vc .isTLS )
@@ -190,55 +190,37 @@ func (vc *Conn) WriteBuffer(buffer *buf.Buffer) (err error) {
190
190
}
191
191
192
192
if vc .writeFilterApplicationData {
193
- buffer2 := ReshapeBuffer (buffer )
194
- defer buffer2 .Release ()
195
193
vc .FilterTLS (buffer .Bytes ())
196
- command := commandPaddingContinue
197
- if ! vc .isTLS {
198
- command = commandPaddingEnd
199
-
200
- // disable XTLS
201
- //vc.readProcess = false
202
- vc .writeFilterApplicationData = false
203
- vc .packetsToFilter = 0
204
- } else if buffer .Len () > 6 && bytes .Equal (buffer .To (3 ), tlsApplicationDataStart ) || vc .packetsToFilter <= 0 {
205
- command = commandPaddingEnd
206
- if vc .enableXTLS {
207
- command = commandPaddingDirect
208
- vc .writeDirect = true
209
- }
210
- vc .writeFilterApplicationData = false
211
- }
212
- ApplyPadding (buffer , command , nil , vc .isTLS )
213
- err = vc .ExtendedWriter .WriteBuffer (buffer )
214
- if err != nil {
215
- return err
216
- }
217
- if vc .writeDirect {
218
- vc .ExtendedWriter = N .NewExtendedWriter (vc .netConn )
219
- log .Debugln ("XTLS Vision direct write start" )
220
- //time.Sleep(5 * time.Millisecond)
221
- }
222
- if buffer2 != nil {
223
- if vc .writeDirect || ! vc .isTLS {
224
- return vc .ExtendedWriter .WriteBuffer (buffer2 )
225
- }
226
- vc .FilterTLS (buffer2 .Bytes ())
227
- command = commandPaddingContinue
228
- if buffer2 .Len () > 6 && bytes .Equal (buffer2 .To (3 ), tlsApplicationDataStart ) || vc .packetsToFilter <= 0 {
229
- command = commandPaddingEnd
230
- if vc .enableXTLS {
231
- command = commandPaddingDirect
232
- vc .writeDirect = true
194
+ buffers := vc .ReshapeBuffer (buffer )
195
+ applyPadding := true
196
+ for i , buffer := range buffers {
197
+ command := commandPaddingContinue
198
+ if applyPadding {
199
+ if vc .isTLS && buffer .Len () > 6 && bytes .Equal (buffer .To (3 ), tlsApplicationDataStart ) {
200
+ command = commandPaddingEnd
201
+ if vc .enableXTLS {
202
+ command = commandPaddingDirect
203
+ vc .writeDirect = true
204
+ }
205
+ vc .writeFilterApplicationData = false
206
+ applyPadding = false
207
+ } else if ! vc .isTLS12orAbove && vc .packetsToFilter <= 1 {
208
+ command = commandPaddingEnd
209
+ vc .writeFilterApplicationData = false
210
+ applyPadding = false
233
211
}
234
- vc .writeFilterApplicationData = false
212
+ ApplyPadding (buffer , command , nil , vc .isTLS )
213
+ }
214
+
215
+ err = vc .ExtendedWriter .WriteBuffer (buffer )
216
+ if err != nil {
217
+ buf .ReleaseMulti (buffers [i :]) // release unwritten buffers
218
+ return
235
219
}
236
- ApplyPadding (buffer2 , command , nil , vc .isTLS )
237
- err = vc .ExtendedWriter .WriteBuffer (buffer2 )
238
- if vc .writeDirect {
220
+ if command == commandPaddingDirect {
239
221
vc .ExtendedWriter = N .NewExtendedWriter (vc .netConn )
240
222
log .Debugln ("XTLS Vision direct write start" )
241
- //time.Sleep(10 * time.Millisecond)
223
+ //time.Sleep(5 * time.Millisecond)
242
224
}
243
225
}
244
226
return err
0 commit comments