summaryrefslogtreecommitdiff
path: root/src/db.erl
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2014-10-27 01:30:15 +0100
committerMagnus Ahltorp <map@kth.se>2014-10-27 01:30:15 +0100
commit79caa8decbb21228cf3f5cbe32fbf972c40e70dc (patch)
tree5e5ae633f29ce8aaa0155ef4595ad5c4b2efaa8c /src/db.erl
parentfb3b9591cc81158824db13818cf6320d5f4a0f7b (diff)
Check that entries are actually present when receiving new STH from merge nodes
Diffstat (limited to 'src/db.erl')
-rw-r--r--src/db.erl9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/db.erl b/src/db.erl
index f7c2057..2a64935 100644
--- a/src/db.erl
+++ b/src/db.erl
@@ -7,7 +7,7 @@
%% API.
-export([start_link/0, stop/0]).
-export([add/4, add/2, add_entryhash/2, add_index/2, set_treesize/1, size/0]).
--export([get_by_index/1, get_by_indices/3, get_by_leaf_hash/1, get_by_entry_hash/1, entry_for_leafhash/1, leafhash_for_index/1]).
+-export([get_by_index/1, get_by_indices/3, get_by_leaf_hash/1, get_by_entry_hash/1, entry_for_leafhash/1, leafhash_for_index/1, leafhash_for_indices/2, indexsize/0]).
%% gen_server callbacks.
-export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2,
code_change/3]).
@@ -18,6 +18,9 @@
size() ->
binary_to_integer(atomic:readfile(treesize_path())).
+indexsize() ->
+ index:indexsize(index_path()).
+
init(_Args) ->
{ok, []}.
@@ -158,7 +161,7 @@ handle_call({add, {LeafHash, EntryHash, Data, Index}}, _From, State) ->
ok = perm:ensurefile(indexforhash_root_path(),
LeafHash, integer_to_binary(Index)),
ok = index:add(index_path(), Index, LeafHash),
- ok = atomic:replacefile(treesize_path(), integer_to_list(Index+1)),
+ ok = atomic:replacefile(treesize_path(), integer_to_binary(Index+1)),
{reply, ok, State};
handle_call({add, {LeafHash, Data}}, _From, State) ->
@@ -178,7 +181,7 @@ handle_call({add_index, {LeafHash, Index}}, _From, State) ->
{reply, ok, State};
handle_call({set_treesize, Size}, _From, State) ->
- ok = atomic:replacefile(treesize_path(), integer_to_list(Size)),
+ ok = atomic:replacefile(treesize_path(), integer_to_binary(Size)),
{reply, ok, State};
handle_call({get_by_indices, {Start, End, _Sorted}}, _From, State) ->