From 0f8acfa78bf101ed1c2ae993684b22de89d94bf7 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 15 Oct 2018 10:54:03 +0200 Subject: adapt (badly) to unsynced clocks --- shard/lib/app/chat.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'shard/lib') diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex index be3b848..2e5e076 100644 --- a/shard/lib/app/chat.ex +++ b/shard/lib/app/chat.ex @@ -163,7 +163,13 @@ defmodule SApp.Chat do with all connected peers. """ def handle_cast({:chat_send, pk, msg}, state) do - msgbin = SData.term_bin {(System.os_time :seconds), msg} + next_ts = case MST.last(state.mst, nil, 1) do + [] -> System.os_time :seconds + [{{_, msgbin, _}, true}] -> + {ts, _msg} = SData.term_unbin msgbin + max(ts + 1, System.os_time :seconds) + end + msgbin = SData.term_bin {next_ts, msg} {:ok, sign} = Shard.Keys.sign_detached(pk, msgbin) msgitem = {pk, msgbin, sign} -- cgit v1.2.3