Skip to content

Commit 3dec711

Browse files
GFW-knockerRPRX
andcommitted
Freedom config: Fix noises delay (#4233)
Co-authored-by: RPRX <[email protected]>
1 parent 480eac7 commit 3dec711

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

Diff for: infra/conf/freedom.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,15 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) {
180180
}
181181

182182
default:
183-
return nil, errors.New("Invalid packet,only rand,str,base64 are supported")
183+
return nil, errors.New("Invalid packet, only rand/str/base64 are supported")
184184
}
185185

186186
if noise.Delay != nil {
187-
if noise.Delay.From != 0 && noise.Delay.To != 0 {
188-
NConfig.DelayMin = uint64(noise.Delay.From)
189-
NConfig.DelayMax = uint64(noise.Delay.To)
190-
if NConfig.DelayMin > NConfig.LengthMax {
191-
NConfig.DelayMin, NConfig.DelayMax = NConfig.LengthMax, NConfig.DelayMin
192-
}
193-
} else {
194-
return nil, errors.New("DelayMin or DelayMax cannot be zero")
187+
NConfig.DelayMin = uint64(noise.Delay.From)
188+
NConfig.DelayMax = uint64(noise.Delay.To)
189+
if NConfig.DelayMin > NConfig.DelayMax {
190+
NConfig.DelayMin, NConfig.DelayMax = NConfig.DelayMax, NConfig.DelayMin
195191
}
196-
197192
} else {
198193
NConfig.DelayMin = 0
199194
NConfig.DelayMax = 0

Diff for: proxy/freedom/freedom.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (w *NoisePacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
419419
}
420420
w.Writer.WriteMultiBuffer(buf.MultiBuffer{buf.FromBytes(noise)})
421421

422-
if n.DelayMin != 0 {
422+
if n.DelayMin != 0 || n.DelayMax != 0 {
423423
time.Sleep(time.Duration(randBetween(int64(n.DelayMin), int64(n.DelayMax))) * time.Millisecond)
424424
}
425425
}

0 commit comments

Comments
 (0)