1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-05 01:38:24 -05:00
v2fly/common/protocol/time.go
2018-11-02 18:20:02 +01:00

23 lines
392 B
Go

package protocol
import (
"time"
"v2ray.com/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)
}
}