mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-25 06:36:05 +03:00
Freedom: Combine fragmented tlshello if interval is 0 (#3663)
Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> Co-authored-by: Ahmadreza Dorkhah <djahmadfire@gmail.com>
This commit is contained in:
parent
96e8b8b279
commit
9e93c19161
@ -402,6 +402,7 @@ func (f *FragmentWriter) Write(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
data := b[5:recordLen]
|
data := b[5:recordLen]
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
|
var hello []byte
|
||||||
for from := 0; ; {
|
for from := 0; ; {
|
||||||
to := from + int(randBetween(int64(f.fragment.LengthMin), int64(f.fragment.LengthMax)))
|
to := from + int(randBetween(int64(f.fragment.LengthMin), int64(f.fragment.LengthMax)))
|
||||||
if to > len(data) {
|
if to > len(data) {
|
||||||
@ -413,12 +414,22 @@ func (f *FragmentWriter) Write(b []byte) (int, error) {
|
|||||||
from = to
|
from = to
|
||||||
buf[3] = byte(l >> 8)
|
buf[3] = byte(l >> 8)
|
||||||
buf[4] = byte(l)
|
buf[4] = byte(l)
|
||||||
|
if f.fragment.IntervalMax == 0 { // combine fragmented tlshello if interval is 0
|
||||||
|
hello = append(hello, buf[:5+l]...)
|
||||||
|
} else {
|
||||||
_, err := f.writer.Write(buf[:5+l])
|
_, err := f.writer.Write(buf[:5+l])
|
||||||
time.Sleep(time.Duration(randBetween(int64(f.fragment.IntervalMin), int64(f.fragment.IntervalMax))) * time.Millisecond)
|
time.Sleep(time.Duration(randBetween(int64(f.fragment.IntervalMin), int64(f.fragment.IntervalMax))) * time.Millisecond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if from == len(data) {
|
if from == len(data) {
|
||||||
|
if len(hello) > 0 {
|
||||||
|
_, err := f.writer.Write(hello)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(b) > recordLen {
|
if len(b) > recordLen {
|
||||||
n, err := f.writer.Write(b[recordLen:])
|
n, err := f.writer.Write(b[recordLen:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user