mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
29 lines
597 B
Go
29 lines
597 B
Go
package protocol
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"github.com/v2ray/v2ray-core/common/protocol"
|
|
)
|
|
|
|
type RandomTimestampGenerator interface {
|
|
Next() protocol.Timestamp
|
|
}
|
|
|
|
type RealRandomTimestampGenerator struct {
|
|
base protocol.Timestamp
|
|
delta int
|
|
}
|
|
|
|
func NewRandomTimestampGenerator(base protocol.Timestamp, delta int) RandomTimestampGenerator {
|
|
return &RealRandomTimestampGenerator{
|
|
base: base,
|
|
delta: delta,
|
|
}
|
|
}
|
|
|
|
func (this *RealRandomTimestampGenerator) Next() protocol.Timestamp {
|
|
rangeInDelta := rand.Intn(this.delta*2) - this.delta
|
|
return this.base + protocol.Timestamp(rangeInDelta)
|
|
}
|