Xray-core/common/protocol/time.go

23 lines
406 B
Go
Raw Normal View History

2020-11-25 13:01:53 +02:00
package protocol
import (
"time"
"github.com/xtls/xray-core/v1/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)
}
}