mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-17 17:48:40 +00:00
Populate Seed (more TBD) and checks
This commit is contained in:
parent
83c76ec192
commit
d09290c5d4
8 changed files with 139 additions and 58 deletions
|
@ -1,6 +1,7 @@
|
|||
package encoding
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
|
||||
|
@ -178,3 +179,64 @@ func (r *LengthPacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||
}
|
||||
return mb, nil
|
||||
}
|
||||
|
||||
func PopulateSeed(seed string, addons *Addons) {
|
||||
if len(seed) > 0 {
|
||||
addons.Seed = []byte {1} // only turn on, more TBD
|
||||
addons.Mode = SeedMode_PaddingPlusDelay
|
||||
addons.Duration = "0-8"
|
||||
addons.Padding = &PaddingConfig{
|
||||
RegularMin: 0,
|
||||
RegularMax: 256,
|
||||
LongMin: 900,
|
||||
LongMax: 1400,
|
||||
}
|
||||
addons.Delay = &DelayConfig{
|
||||
IsRandom: true,
|
||||
MinMillis: 100,
|
||||
MaxMillis: 500,
|
||||
}
|
||||
addons.Scheduler = &SchedulerConfig{
|
||||
TimeoutMillis: 600,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func CheckSeed(requestAddons *Addons, responseAddons *Addons) error {
|
||||
if !bytes.Equal(requestAddons.Seed, responseAddons.Seed) {
|
||||
return errors.New("Seed bytes not match", requestAddons.Seed, responseAddons.Seed)
|
||||
}
|
||||
if requestAddons.Mode != responseAddons.Mode {
|
||||
return errors.New("Mode not match", requestAddons.Mode, responseAddons.Mode)
|
||||
}
|
||||
if requestAddons.Duration != responseAddons.Duration {
|
||||
return errors.New("Duration not match", requestAddons.Duration, responseAddons.Duration)
|
||||
}
|
||||
if requestAddons.Padding != nil && responseAddons.Padding != nil {
|
||||
if requestAddons.Padding.RegularMin != responseAddons.Padding.RegularMin ||
|
||||
requestAddons.Padding.RegularMax != responseAddons.Padding.RegularMax ||
|
||||
requestAddons.Padding.LongMin != responseAddons.Padding.LongMin ||
|
||||
requestAddons.Padding.LongMax != responseAddons.Padding.LongMax {
|
||||
return errors.New("Padding not match")
|
||||
}
|
||||
} else if requestAddons.Padding != nil || responseAddons.Padding != nil {
|
||||
return errors.New("Padding of one is nil but the other is not nil")
|
||||
}
|
||||
if requestAddons.Delay != nil && responseAddons.Delay != nil {
|
||||
if requestAddons.Delay.IsRandom != responseAddons.Delay.IsRandom ||
|
||||
requestAddons.Delay.MinMillis != responseAddons.Delay.MinMillis ||
|
||||
requestAddons.Delay.MaxMillis != responseAddons.Delay.MaxMillis {
|
||||
return errors.New("Delay not match")
|
||||
}
|
||||
} else if requestAddons.Delay != nil || responseAddons.Delay != nil {
|
||||
return errors.New("Delay of one is nil but the other is not nil")
|
||||
}
|
||||
if requestAddons.Scheduler != nil && responseAddons.Scheduler != nil {
|
||||
if requestAddons.Scheduler.TimeoutMillis != responseAddons.Scheduler.TimeoutMillis {
|
||||
return errors.New("Scheduler not match")
|
||||
}
|
||||
} else if requestAddons.Scheduler != nil || responseAddons.Scheduler != nil {
|
||||
return errors.New("Scheduler of one is nil but the other is not nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue