Freedom config: Fix noises delay (#4233)

Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
GFW-knocker 2025-01-01 13:52:57 +03:30 committed by RPRX
parent 480eac7235
commit 0658c9545b
2 changed files with 4 additions and 18 deletions

View File

@ -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
}

View File

@ -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)
}
}