mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-29 05:25:21 -05:00
23 lines
429 B
Go
23 lines
429 B
Go
package protocol
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"github.com/v2ray/v2ray-core/common/serial"
|
|
)
|
|
|
|
type Timestamp int64
|
|
|
|
func (this Timestamp) Bytes() []byte {
|
|
return serial.Int64Literal(this).Bytes()
|
|
}
|
|
|
|
type TimestampGenerator func() Timestamp
|
|
|
|
func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
|
|
return func() Timestamp {
|
|
rangeInDelta := rand.Intn(delta*2) - delta
|
|
return base + Timestamp(rangeInDelta)
|
|
}
|
|
}
|