Skip to content

Commit

Permalink
Freedom config: Fix noises delay (#4233)
Browse files Browse the repository at this point in the history
Co-authored-by: RPRX <[email protected]>
  • Loading branch information
GFW-knocker and RPRX committed Jan 1, 2025
1 parent 480eac7 commit 3dec711
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions infra/conf/freedom.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,15 @@ 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")
NConfig.DelayMin = uint64(noise.Delay.From)
NConfig.DelayMax = uint64(noise.Delay.To)
if NConfig.DelayMin > NConfig.DelayMax {
NConfig.DelayMin, NConfig.DelayMax = NConfig.DelayMax, NConfig.DelayMin
}

} else {
NConfig.DelayMin = 0
NConfig.DelayMax = 0
Expand Down
2 changes: 1 addition & 1 deletion proxy/freedom/freedom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 3dec711

Please sign in to comment.