mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-05 18:07:00 +00:00
22 lines
374 B
Go
22 lines
374 B
Go
package protocol
|
|
|
|
import (
|
|
"math/rand/v2"
|
|
"time"
|
|
)
|
|
|
|
type Timestamp int64
|
|
|
|
type TimestampGenerator func() Timestamp
|
|
|
|
func NowTime() Timestamp {
|
|
return Timestamp(time.Now().Unix())
|
|
}
|
|
|
|
func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
|
|
return func() Timestamp {
|
|
rangeInDelta := rand.N(delta*2) - delta
|
|
return base + Timestamp(rangeInDelta)
|
|
}
|
|
}
|