|
1 | 1 | package encoding |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "context" |
5 | 6 | "io" |
6 | 7 |
|
@@ -177,3 +178,64 @@ func (r *LengthPacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) { |
177 | 178 | } |
178 | 179 | return mb, nil |
179 | 180 | } |
| 181 | + |
| 182 | +func PopulateSeed(seed string, addons *Addons) { |
| 183 | + if len(seed) > 0 { |
| 184 | + addons.Seed = []byte {1} // only turn on, more TBD |
| 185 | + addons.Mode = SeedMode_PaddingPlusDelay |
| 186 | + addons.Duration = "0-8" |
| 187 | + addons.Padding = &PaddingConfig{ |
| 188 | + RegularMin: 0, |
| 189 | + RegularMax: 256, |
| 190 | + LongMin: 900, |
| 191 | + LongMax: 1400, |
| 192 | + } |
| 193 | + addons.Delay = &DelayConfig{ |
| 194 | + IsRandom: true, |
| 195 | + MinMillis: 100, |
| 196 | + MaxMillis: 500, |
| 197 | + } |
| 198 | + addons.Scheduler = &SchedulerConfig{ |
| 199 | + TimeoutMillis: 600, |
| 200 | + } |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +func CheckSeed(requestAddons *Addons, responseAddons *Addons) error { |
| 205 | + if !bytes.Equal(requestAddons.Seed, responseAddons.Seed) { |
| 206 | + return newError("Seed bytes not match", requestAddons.Seed, responseAddons.Seed) |
| 207 | + } |
| 208 | + if requestAddons.Mode != responseAddons.Mode { |
| 209 | + return newError("Mode not match", requestAddons.Mode, responseAddons.Mode) |
| 210 | + } |
| 211 | + if requestAddons.Duration != responseAddons.Duration { |
| 212 | + return newError("Duration not match", requestAddons.Duration, responseAddons.Duration) |
| 213 | + } |
| 214 | + if requestAddons.Padding != nil && responseAddons.Padding != nil { |
| 215 | + if requestAddons.Padding.RegularMin != responseAddons.Padding.RegularMin || |
| 216 | + requestAddons.Padding.RegularMax != responseAddons.Padding.RegularMax || |
| 217 | + requestAddons.Padding.LongMin != responseAddons.Padding.LongMin || |
| 218 | + requestAddons.Padding.LongMax != responseAddons.Padding.LongMax { |
| 219 | + return newError("Padding not match") |
| 220 | + } |
| 221 | + } else if requestAddons.Padding != nil || responseAddons.Padding != nil { |
| 222 | + return newError("Padding of one is nil but the other is not nil") |
| 223 | + } |
| 224 | + if requestAddons.Delay != nil && responseAddons.Delay != nil { |
| 225 | + if requestAddons.Delay.IsRandom != responseAddons.Delay.IsRandom || |
| 226 | + requestAddons.Delay.MinMillis != responseAddons.Delay.MinMillis || |
| 227 | + requestAddons.Delay.MaxMillis != responseAddons.Delay.MaxMillis { |
| 228 | + return newError("Delay not match") |
| 229 | + } |
| 230 | + } else if requestAddons.Delay != nil || responseAddons.Delay != nil { |
| 231 | + return newError("Delay of one is nil but the other is not nil") |
| 232 | + } |
| 233 | + if requestAddons.Scheduler != nil && responseAddons.Scheduler != nil { |
| 234 | + if requestAddons.Scheduler.TimeoutMillis != responseAddons.Scheduler.TimeoutMillis { |
| 235 | + return newError("Scheduler not match") |
| 236 | + } |
| 237 | + } else if requestAddons.Scheduler != nil || responseAddons.Scheduler != nil { |
| 238 | + return newError("Scheduler of one is nil but the other is not nil") |
| 239 | + } |
| 240 | + return nil |
| 241 | +} |
0 commit comments