status-go/protocol/v1/clock.go
Andrea Maria Piana baa0767c26
Handle membership update message
This commit does a few things:

1) Handle membership updates using protobuf and adds the relevant
endpoints.
2) Store in memory a map of chats + contacts for faster lookups, which
are then flushed to disk on each update
3) Validate incoming messages

Sorry for the large pr, but you know, v1 :)
2019-12-10 15:20:28 +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
}