diff options
author | Magnus Ahltorp <map@kth.se> | 2015-07-31 23:33:25 +0200 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2015-07-31 23:33:25 +0200 |
commit | 329490ec8167ffe5b2bd8a390ae4d34fd8b808c0 (patch) | |
tree | ec8c95d1b4c553d8c492cbac74d3b57ac9dc4640 /src/storagedb.erl | |
parent | 99f4a7e5bb46293bebc7815c683befeda24bf977 (diff) |
Use lastverifiednewentry file when reading new entries
Diffstat (limited to 'src/storagedb.erl')
-rw-r--r-- | src/storagedb.erl | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/storagedb.erl b/src/storagedb.erl index c94a13e..d781033 100644 --- a/src/storagedb.erl +++ b/src/storagedb.erl @@ -7,7 +7,7 @@ -behaviour(gen_server). %% API -export([start_link/0, stop/0]). --export([add/1, fetchnewhashes/1]). +-export([add/1, fetchnewhashes/1, lastverifiednewentry/0]). %% gen_server callbacks. -export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2, code_change/3]). @@ -23,6 +23,10 @@ start_link() -> stop() -> call(?MODULE, stop). +lastverifiednewentry_path() -> + {ok, Value} = application:get_env(plop, lastverifiednewentry_path), + Value. + %%%%%%%%%%%%%%%%%%%% %% Public API. @@ -34,6 +38,17 @@ fetchnewhashes(Index) -> index:getrange(newentries_path(), Index, Size - 1) end. +lastverifiednewentry() -> + case atomic:readfile(lastverifiednewentry_path()) of + noentry -> + {0, none}; + Contents -> + {struct, PropList} = mochijson2:decode(Contents), + Index = proplists:get_value(<<"index">>, PropList), + Hash = proplists:get_value(<<"hash">>, PropList), + {Index, mochihex:to_bin(binary_to_list(Hash))} + end. + -spec add(binary()) -> ok. add(LeafHash) -> ok = call(?MODULE, {add_nosync, LeafHash}), |