23 lines
429 B
Go
Raw Normal View History

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