1
0
Fork 0
mirror of https://github.com/XTLS/Xray-core.git synced 2025-01-13 06:03:33 +02:00
Xray-core/common/protocol/time.go
2020-12-04 09:36:16 +08:00

22 lines
403 B
Go

package protocol
import (
"time"
"github.com/xtls/xray-core/common/dice"
)
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 := dice.Roll(delta*2) - delta
return base + Timestamp(rangeInDelta)
}
}