mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 06:12:55 +00:00
baa0767c26
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 :)
21 lines
630 B
Go
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
|
|
}
|