1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/common/protocol/time.go
2016-02-25 21:50:10 +01:00

28 lines
504 B
Go

package protocol
import (
"math/rand"
"time"
"github.com/v2ray/v2ray-core/common/serial"
)
type Timestamp int64
func (this Timestamp) Bytes() []byte {
return serial.Int64Literal(this).Bytes()
}
type TimestampGenerator func() Timestamp
func NowTime() Timestamp {
return Timestamp(time.Now().Unix())
}
func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
return func() Timestamp {
rangeInDelta := rand.Intn(delta*2) - delta
return base + Timestamp(rangeInDelta)
}
}