Xray-core/common/protocol/time.go

23 lines
403 B
Go
Raw Permalink Normal View History

2020-11-25 11:01:53 +00:00
package protocol
import (
"time"
2020-12-04 01:36:16 +00:00
"github.com/xtls/xray-core/common/dice"
2020-11-25 11:01:53 +00:00
)
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)
}
}