Skip to content

Commit 0658c95

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

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

infra/conf/freedom.go

+3-17
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) {
161161
}
162162
NConfig.LengthMin = uint64(min)
163163
NConfig.LengthMax = uint64(max)
164-
if NConfig.LengthMin > NConfig.LengthMax {
165-
NConfig.LengthMin, NConfig.LengthMax = NConfig.LengthMax, NConfig.LengthMin
166-
}
167164
if NConfig.LengthMin == 0 {
168165
return nil, errors.New("rand lengthMin or lengthMax cannot be 0")
169166
}
@@ -180,23 +177,12 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) {
180177
}
181178

182179
default:
183-
return nil, errors.New("Invalid packet,only rand,str,base64 are supported")
180+
return nil, errors.New("Invalid packet, only rand/str/base64 are supported")
184181
}
185182

186183
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")
195-
}
196-
197-
} else {
198-
NConfig.DelayMin = 0
199-
NConfig.DelayMax = 0
184+
NConfig.DelayMin = uint64(noise.Delay.From)
185+
NConfig.DelayMax = uint64(noise.Delay.To)
200186
}
201187
return NConfig, nil
202188
}

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)