From 807c421aa8b1a3b1910add50fb0ffa47f6d6140f Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Wed, 2 Nov 2016 12:09:47 +0100 Subject: Added verify-entries to frontend. sendsth is now publish-sth --- src/frontend.erl | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/frontend.erl b/src/frontend.erl index f3c72ed..a3ea885 100644 --- a/src/frontend.erl +++ b/src/frontend.erl @@ -40,10 +40,39 @@ request(post, ?APPURL_PLOP_FRONTEND, "sendlog", Input) -> write_or_verify_index(Start, Hashes) end; -request(post, ?APPURL_PLOP_FRONTEND, "sendsth", Input) -> +request(post, ?APPURL_PLOP_FRONTEND, "verify-entries", Input) -> case (catch mochijson2:decode(Input)) of {error, E} -> - html("sendentry: bad input:", E); + html("verify-entries: bad input:", E); + {struct, PropList} -> + VerifiedSize = db:sendsth_verified() + 1, + NewSize = proplists:get_value(<<"verify_to">>, PropList), + Indexsize = db:indexsize(), + + if + NewSize < VerifiedSize -> + success({[{result, <<"ok">>}, {verified, VerifiedSize}]}); + NewSize > Indexsize -> + html("Has too few entries", Indexsize); + true -> + lager:debug("old size: ~p new size: ~p", + [VerifiedSize, NewSize]), + + Errors = check_entries(NewSize), + + case Errors of + [] -> + success({[{result, <<"ok">>}, {verified, NewSize}]}); + _ -> + html("Database not complete", Errors) + end + end + end; + +request(post, ?APPURL_PLOP_FRONTEND, "publish-sth", Input) -> + case (catch mochijson2:decode(Input)) of + {error, E} -> + html("publish-sth: bad input:", E); {struct, PropList} -> OldSize = db:size(), Treesize = proplists:get_value(<<"tree_size">>, PropList), -- cgit v1.1