1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/common/protocol/time.go
2016-08-20 20:55:45 +02:00

28 lines
518 B
Go

package protocol
import (
"time"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/serial"
)
type Timestamp int64
func (this Timestamp) Bytes(b []byte) []byte {
return serial.Int64ToBytes(int64(this), b)
}
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)
}
}