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 0658c95
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
20 changes: 3 additions & 17 deletions infra/conf/freedom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
}
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 0658c95

Please sign in to comment.