Michal Iskierko 6d31343205 feat: Waku v2 bridge
Issue #12610
2024-02-22 17:07:59 +01:00

21 lines
630 B
Go

package protocol
import "time"
const clockBumpInMs = uint64(time.Minute / time.Millisecond)
// CalcMessageClock calculates a new clock value for Message.
// It is used to properly sort messages and accommodate the fact
// that time might be different on each device.
func CalcMessageClock(lastObservedValue uint64, timeInMs uint64) uint64 {
clock := lastObservedValue
if clock < timeInMs {
// Added time should be larger than time skew tollerance for a message.
// Here, we use 1 minute which is larger than accepted message time skew by Whisper.
clock = timeInMs + clockBumpInMs
} else {
clock++
}
return clock
}