mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
23 lines
408 B
Go
23 lines
408 B
Go
package protocol
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/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)
|
|
}
|
|
}
|