1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-02-20 23:47:21 -05:00

23 lines
408 B
Go
Raw Normal View History

2016-02-23 22:51:08 +01:00
package protocol
import (
2016-02-25 21:50:10 +01:00
"time"
2016-02-25 17:14:49 +01:00
"github.com/v2fly/v2ray-core/v5/common/dice"
2016-02-23 22:51:08 +01:00
)
type Timestamp int64
2016-02-25 17:14:49 +01:00
type TimestampGenerator func() Timestamp
2016-02-25 21:50:10 +01:00
func NowTime() Timestamp {
return Timestamp(time.Now().Unix())
}
2016-02-25 17:14:49 +01:00
func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
return func() Timestamp {
2016-06-29 23:53:50 +02:00
rangeInDelta := dice.Roll(delta*2) - delta
2016-02-25 17:14:49 +01:00
return base + Timestamp(rangeInDelta)
}
}