2016-02-23 21:51:08 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2016-02-25 20:50:10 +00:00
|
|
|
"time"
|
2016-02-25 16:14:49 +00:00
|
|
|
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/common/dice"
|
|
|
|
"v2ray.com/core/common/serial"
|
2016-02-23 21:51:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Timestamp int64
|
|
|
|
|
2016-11-27 20:39:09 +00:00
|
|
|
func (v Timestamp) Bytes(b []byte) []byte {
|
|
|
|
return serial.Int64ToBytes(int64(v), b)
|
2016-02-23 21:51:08 +00:00
|
|
|
}
|
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 {
|
2016-06-29 21:53:50 +00:00
|
|
|
rangeInDelta := dice.Roll(delta*2) - delta
|
2016-02-25 16:14:49 +00:00
|
|
|
return base + Timestamp(rangeInDelta)
|
|
|
|
}
|
|
|
|
}
|