diff options
author | Linus Nordberg <linus@nordu.net> | 2014-05-01 18:02:31 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2014-05-01 18:02:31 +0200 |
commit | 339656a35441a5d7d02282e6a5c6cdfeaf0571d6 (patch) | |
tree | 823cbe7f492c4c3f9bb8ffdc359ddefc1ffcb6e2 | |
parent | 835638e11919d2012ab74bf5e3185732e604d0ff (diff) |
Move some records out of public header file. Improve db initialisation some.
Wait for mnesia tables in init() and make the init-functions do some more.
-rw-r--r-- | include/plop.hrl | 34 | ||||
-rw-r--r-- | src/db.erl | 16 | ||||
-rw-r--r-- | src/db.hrl | 8 | ||||
l--------- | src/plop.hrl | 1 |
4 files changed, 29 insertions, 30 deletions
diff --git a/include/plop.hrl b/include/plop.hrl index 5492024..30a5385 100644 --- a/include/plop.hrl +++ b/include/plop.hrl @@ -6,14 +6,9 @@ -type entry_type() :: x509 | precert | test. % uint16 -type leaf_type() :: timestamped_entry | test. % uint8 -%% @doc What's stored in the database. --record(plop, { - index :: non_neg_integer(), % Primary key. - hash :: binary(), % SHA-256 over #FIXME.entry. Indexed in db. - spt :: binary() % serialise(#spt_on_wire{}) - }). - -%% @doc Merkle Tree Leaf -- input to hash function for leaf hashes. +%% @doc Merkle Tree Leaf -- what's sent as 'leaf_input' in response to +%% get-entries requests and also the input to the hash function for +%% leaf hashes in the tree. RFC 6962 sect 3.4. -record(mtl, { version = 1 :: pos_integer(), leaf_type = timestamped_entry :: leaf_type(), @@ -21,14 +16,6 @@ }). -type mtl() :: #mtl{}. -%% @doc Parts of what goes in an SPT. Used for FIXME. -%% -record(spt, { -%% version = 1 :: pos_integer(), -%% signature_type :: signature_type(), -%% entry :: timestamped_entry() -%% }). -%%-type spt() :: #spt{}. - -record(spt_on_wire, { version :: pos_integer(), % uint8 logid :: binary(), % SHA-256 over DER encoded public log key @@ -48,14 +35,6 @@ }). -type spt_signed() :: #spt_signed{}. -%% Internal representation of a data entry. --record(timestamped_entry, { - timestamp = now :: now | integer(), - entry_type :: entry_type(), - entry :: binary() - }). --type timestamped_entry() :: #timestamped_entry{}. - %% %% Part of interface to plop:add/1. %% -record(plop_entry, { %% type :: entry_type(), @@ -63,6 +42,13 @@ %% }). %% -type plop_entry() :: #plop_entry{}. +%% A data entry. +-record(timestamped_entry, { + timestamp = now :: now | integer(), + entry_type :: entry_type(), + entry :: binary() + }). +-type timestamped_entry() :: #timestamped_entry{}. %% @doc The parts of an STH which is to be signed. Used as the %% interface to plop:sth/1, for testing. Should probably be internal @@ -12,27 +12,30 @@ code_change/3]). -include_lib("stdlib/include/qlc.hrl"). +-include("db.hrl"). -include("plop.hrl"). %% @doc Set up a database schema on all nodes that are to be included %% in the "database cluster". Has to be run _before_ mnesia has been %% started. init_db() -> - init_db([]). + init_db([node()]). init_db(Nodes) -> - mnesia:create_schema([node()] ++ Nodes), - init_tables(Nodes). + ok = mnesia:create_schema(Nodes), + rpc:multicall(Nodes, application, start, [mnesia]), + init_tables(Nodes), + rpc:multicall(Nodes, application, stop, [mnesia]). %% @doc Run once, or rather every time you start on a new database. %% If run more than once, we'll get {aborted, {already_exists, TABLE}}. init_tables() -> - init_tables([]). + init_tables([node()]). init_tables(Nodes) -> %% We've once upon a time invoked mnesia:create_schema/1 with the %% nodes that will be part of the database. RamCopies = [], DiscCopies = [], - DiscOnlyCopies = [node()] ++ Nodes, + DiscOnlyCopies = Nodes, mnesia:start(), mnesia:create_table(plop, [{type, set}, {ram_copies, RamCopies}, @@ -48,7 +51,8 @@ dump_to_file(Filename) -> mnesia:dump_to_textfile(Filename). init(_Args) -> - {ok, []}. % TODO: return state + {mnesia:wait_for_tables([plop], 5000), + []}. start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). diff --git a/src/db.hrl b/src/db.hrl new file mode 100644 index 0000000..16b9103 --- /dev/null +++ b/src/db.hrl @@ -0,0 +1,8 @@ +%% @doc What's stored in the database. +%% 'index' is the primary key, 'hash' is also indexed. +-record(plop, { + index :: non_neg_integer(), % Primary key. + hash :: binary(), % Hash over mtl. + mtl :: mtl(), % Merkle Tree Leaf, an #mtl{}. + spt_text :: binary() % Signed Plop Timestamp, an #spt_on_wire{}. + }). diff --git a/src/plop.hrl b/src/plop.hrl new file mode 120000 index 0000000..38dfcbf --- /dev/null +++ b/src/plop.hrl @@ -0,0 +1 @@ +/home/linus/usr/src/plop/include/plop.hrl
\ No newline at end of file |