From 0658c9545b763009ee45607d2db757b01591175d Mon Sep 17 00:00:00 2001 From: GFW-knocker <123458121+GFW-knocker@users.noreply.github.com> Date: Wed, 1 Jan 2025 13:52:57 +0330 Subject: [PATCH] Freedom config: Fix noises delay (#4233) Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> --- infra/conf/freedom.go | 20 +++----------------- proxy/freedom/freedom.go | 2 +- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/infra/conf/freedom.go b/infra/conf/freedom.go index 14c09cc2..693df1e3 100644 --- a/infra/conf/freedom.go +++ b/infra/conf/freedom.go @@ -161,9 +161,6 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) { } NConfig.LengthMin = uint64(min) NConfig.LengthMax = uint64(max) - if NConfig.LengthMin > NConfig.LengthMax { - NConfig.LengthMin, NConfig.LengthMax = NConfig.LengthMax, NConfig.LengthMin - } if NConfig.LengthMin == 0 { return nil, errors.New("rand lengthMin or lengthMax cannot be 0") } @@ -180,23 +177,12 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) { } default: - return nil, errors.New("Invalid packet,only rand,str,base64 are supported") + return nil, errors.New("Invalid packet, only rand/str/base64 are supported") } if noise.Delay != nil { - if noise.Delay.From != 0 && noise.Delay.To != 0 { - NConfig.DelayMin = uint64(noise.Delay.From) - NConfig.DelayMax = uint64(noise.Delay.To) - if NConfig.DelayMin > NConfig.LengthMax { - NConfig.DelayMin, NConfig.DelayMax = NConfig.LengthMax, NConfig.DelayMin - } - } else { - return nil, errors.New("DelayMin or DelayMax cannot be zero") - } - - } else { - NConfig.DelayMin = 0 - NConfig.DelayMax = 0 + NConfig.DelayMin = uint64(noise.Delay.From) + NConfig.DelayMax = uint64(noise.Delay.To) } return NConfig, nil } diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index f2d68eea..dcf012ae 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -419,7 +419,7 @@ func (w *NoisePacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error { } w.Writer.WriteMultiBuffer(buf.MultiBuffer{buf.FromBytes(noise)}) - if n.DelayMin != 0 { + if n.DelayMin != 0 || n.DelayMax != 0 { time.Sleep(time.Duration(randBetween(int64(n.DelayMin), int64(n.DelayMax))) * time.Millisecond) } }