2016-02-23 16:51:08 -05:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2016-02-25 15:50:10 -05:00
|
|
|
"time"
|
2016-02-25 11:14:49 -05:00
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/common/dice"
|
2016-02-23 16:51:08 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Timestamp int64
|
|
|
|
|
2016-02-25 11:14:49 -05:00
|
|
|
type TimestampGenerator func() Timestamp
|
|
|
|
|
2016-02-25 15:50:10 -05:00
|
|
|
func NowTime() Timestamp {
|
|
|
|
return Timestamp(time.Now().Unix())
|
|
|
|
}
|
|
|
|
|
2016-02-25 11:14:49 -05:00
|
|
|
func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
|
|
|
|
return func() Timestamp {
|
2016-06-29 17:53:50 -04:00
|
|
|
rangeInDelta := dice.Roll(delta*2) - delta
|
2016-02-25 11:14:49 -05:00
|
|
|
return base + Timestamp(rangeInDelta)
|
|
|
|
}
|
|
|
|
}
|