1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-04 21:15:24 +00:00
v2fly/common/protocol/time.go

28 lines
504 B
Go
Raw Normal View History

2016-02-23 21:51:08 +00:00
package protocol
import (
2016-02-25 16:14:49 +00:00
"math/rand"
2016-02-25 20:50:10 +00:00
"time"
2016-02-25 16:14:49 +00:00
2016-02-23 21:51:08 +00:00
"github.com/v2ray/v2ray-core/common/serial"
)
type Timestamp int64
func (this Timestamp) Bytes() []byte {
return serial.Int64Literal(this).Bytes()
}
2016-02-25 16:14:49 +00:00
type TimestampGenerator func() Timestamp
2016-02-25 20:50:10 +00:00
func NowTime() Timestamp {
return Timestamp(time.Now().Unix())
}
2016-02-25 16:14:49 +00:00
func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
return func() Timestamp {
rangeInDelta := rand.Intn(delta*2) - delta
return base + Timestamp(rangeInDelta)
}
}