github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/common/protocol/time.go (about) 1 package protocol 2 3 import ( 4 "time" 5 6 "github.com/v2fly/v2ray-core/v5/common/dice" 7 ) 8 9 type Timestamp int64 10 11 type TimestampGenerator func() Timestamp 12 13 func NowTime() Timestamp { 14 return Timestamp(time.Now().Unix()) 15 } 16 17 func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator { 18 return func() Timestamp { 19 rangeInDelta := dice.Roll(delta*2) - delta 20 return base + Timestamp(rangeInDelta) 21 } 22 }