diff options
author | Alex Auvolat <alex@adnab.me> | 2018-09-26 15:59:22 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-09-26 15:59:22 +0200 |
commit | 1a13285971ef728109011a93e676e26248b30242 (patch) | |
tree | f03467bc07ff84961f8c3eb88497adaf36b5f009 /shard | |
parent | 7d0009d83c9b5c747d4adb535817924762429f30 (diff) | |
download | shard-1a13285971ef728109011a93e676e26248b30242.tar.gz shard-1a13285971ef728109011a93e676e26248b30242.zip |
Fixes
Diffstat (limited to 'shard')
-rw-r--r-- | shard/lib/app/chat.ex | 10 | ||||
-rw-r--r-- | shard/lib/app/pagestore.ex | 14 | ||||
-rw-r--r-- | shard/lib/keys.ex | 9 |
3 files changed, 31 insertions, 2 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex index c7df62e..52ad920 100644 --- a/shard/lib/app/chat.ex +++ b/shard/lib/app/chat.ex @@ -51,9 +51,17 @@ defmodule SApp.Chat do :ok -> Shard.Manager.dispatch_to(id, nil, self()) {:ok, page_store} = SApp.PageStore.start_link(id, :page_store) + root = Shard.Manager.load_state id + root = cond do + root == nil -> nil + GenServer.call(page_store, {:have_rec, root}) -> root + true -> + Logger.warn "Not all pages for saved root were saved, restarting from an empty state!" + nil + end mst = %MST{store: %SApp.PageStore{pid: page_store}, cmp: &msg_cmp/2, - root: Shard.Manager.load_state(id)} + root: root} GenServer.cast(self(), :init_pull) {:ok, %{channel: channel, diff --git a/shard/lib/app/pagestore.ex b/shard/lib/app/pagestore.ex index 7962084..f093ed4 100644 --- a/shard/lib/app/pagestore.ex +++ b/shard/lib/app/pagestore.ex @@ -66,6 +66,10 @@ defmodule SApp.PageStore do {:reply, hash, state} end + def handle_call({:have_rec, root}, _from, state) do + {:reply, have_rec(state, root), state} + end + defp add_request(state, key, from) do reqs_key = case state.reqs[key] do nil -> @@ -89,6 +93,16 @@ defmodule SApp.PageStore do end end + defp have_rec(state, root) do + case :dets.lookup state.store, root do + [{_, _, bin}] -> + pg = SData.term_unbin bin + pg |> SData.Page.refs |> Enum.map(&(have_rec(state, &1))) |> Enum.all? + _ -> + false + end + end + defp init_rec_pull(state, key, why, prefer_ask) do case prefer_ask do [_|_] -> diff --git a/shard/lib/keys.ex b/shard/lib/keys.ex index de054e1..b6ff461 100644 --- a/shard/lib/keys.ex +++ b/shard/lib/keys.ex @@ -72,7 +72,7 @@ defmodule Shard.Keys do List the public keys of all identities for which we have a secret key """ def list_identities() do - for [{pk, _sk}] <- :dets.match(@key_db, :"$1"), do: pk + for [pk, _sk] <- :dets.match(@key_db, {:"$1", :"$2"}), do: pk end @doc""" @@ -103,6 +103,13 @@ defmodule Shard.Keys do end end + def have_sk?(pk) do + case :dets.lookup @key_db, pk do + [{^pk, _sk}] -> true + _ -> false + end + end + @doc""" Lookup the secret key for a pk and generate a detached signature for a message. |