summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ht.erl11
-rw-r--r--src/plop.erl16
2 files changed, 11 insertions, 16 deletions
diff --git a/src/ht.erl b/src/ht.erl
index b6570a0..ec8527f 100644
--- a/src/ht.erl
+++ b/src/ht.erl
@@ -261,15 +261,14 @@ new([-1]) ->
new([]);
%% Initialise tree from db.
new([Version]) when is_integer(Version) ->
- foldl(fun(#mtl{entry = E}, Tree) ->
- D = (E#timestamped_entry.entry)#plop_entry.data,
- add(Tree, D) % Return value -> Tree in next invocation.
+ foldl(fun(MTL, Tree) ->
+ %% Return value becomes Tree in next invocation.
+ add(Tree, plop:serialise(MTL))
end, new([]), db:get_by_index_sorted(0, Version));
%% Initialise tree from List.
new([List]) when is_list(List) ->
- foldl(fun(D, Tree) ->
- add(Tree, D) % Return value -> Tree in next invocation.
- end, new([]), List).
+ foldl(fun(SerialisedMTL, Tree) -> add(Tree, SerialisedMTL) end,
+ new([]), List).
update(Tree) ->
update(Tree, Tree#tree.version).
diff --git a/src/plop.erl b/src/plop.erl
index 92ada3a..8277175 100644
--- a/src/plop.erl
+++ b/src/plop.erl
@@ -104,7 +104,8 @@ terminate(_Reason, _State) ->
ok.
%%%%%%%%%%%%%%%%%%%%
-add(Data) when is_record(Data, timestamped_entry) ->
+-spec add(timestamped_entry()) -> spt().
+add(Data) ->
gen_server:call(?MODULE, {add, Data}).
sth() ->
gen_server:call(?MODULE, {sth, []}).
@@ -171,22 +172,17 @@ handle_call({test, pubkey}, _From,
-spec do_add(timestamped_entry(),
public_key:rsa_private_key(),
binary()) -> {ok|error, binary()}.
-do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry},
- Privkey,
- LogID) ->
- DB_hash = crypto:hash(sha256, serialise(PlopEntry)),
+do_add(TimestampedEntry, Privkey, LogID) ->
+ DB_hash = crypto:hash(sha256,
+ serialise(TimestampedEntry#timestamped_entry.entry)),
Record = db:find(entryhash, DB_hash),
case Record of
#plop{index = _I, mtl = MTL, spt = SPT} ->
%% Costly database consistency checking. FIXME: Remove.
- E = MTL#mtl.entry,
Record = Record#plop{
entryhash = DB_hash,
mtlhash = ht:leaf_hash(serialise(MTL)),
- mtl = #mtl{entry =
- #timestamped_entry{
- timestamp = E#timestamped_entry.timestamp,
- entry = PlopEntry}}},
+ mtl = MTL},
{ok, SPT};
[] ->
NewSPT = spt(LogID, Privkey, TimestampedEntry),