time.go 403 B

12345678910111213141516171819202122
  1. package protocol
  2. import (
  3. "time"
  4. "github.com/xtls/xray-core/common/dice"
  5. )
  6. type Timestamp int64
  7. type TimestampGenerator func() Timestamp
  8. func NowTime() Timestamp {
  9. return Timestamp(time.Now().Unix())
  10. }
  11. func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
  12. return func() Timestamp {
  13. rangeInDelta := dice.Roll(delta*2) - delta
  14. return base + Timestamp(rangeInDelta)
  15. }
  16. }