mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-24 13:49:19 +02:00
23 lines
403 B
Go
23 lines
403 B
Go
package protocol
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/xtls/xray-core/common/dice"
|
|
)
|
|
|
|
type Timestamp int64
|
|
|
|
type TimestampGenerator func() Timestamp
|
|
|
|
func NowTime() Timestamp {
|
|
return Timestamp(time.Now().Unix())
|
|
}
|
|
|
|
func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
|
|
return func() Timestamp {
|
|
rangeInDelta := dice.Roll(delta*2) - delta
|
|
return base + Timestamp(rangeInDelta)
|
|
}
|
|
}
|