summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ebin/plop.app2
-rw-r--r--src/plop_sup.erl61
-rw-r--r--src/sign.erl10
3 files changed, 35 insertions, 38 deletions
diff --git a/ebin/plop.app b/ebin/plop.app
index a2a0dd4..4d07d2b 100644
--- a/ebin/plop.app
+++ b/ebin/plop.app
@@ -8,5 +8,5 @@
{modules, [plop_app, plop_sup, plop, db, ht, hex]},
{applications, [kernel, stdlib]}, % crypto, public_key
{registered, [plop, ht, db]},
- {mod, {plop_app, ["test/eckey.pem", "test/eckey-public.pem"]}}
+ {mod, {plop_app, []}}
]}.
diff --git a/src/plop_sup.erl b/src/plop_sup.erl
index eb65925..c125cc0 100644
--- a/src/plop_sup.erl
+++ b/src/plop_sup.erl
@@ -7,44 +7,39 @@
-export([start_link/1, init/1]).
-export([start_in_shell/1]).
-start_link(Args) ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
+start_link(_Args) ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
%% For testing.
start_in_shell(Args) ->
{ok, Pid} = start_link(Args),
unlink(Pid).
+
+permanent_worker(Name, {Module, Function, Args}) ->
+ permanent_worker(Name, {Module, Function, Args}, [Module]).
+
+permanent_worker(Name, StartFunc, Modules) ->
+ {Name,
+ StartFunc,
+ permanent,
+ 10000,
+ worker, Modules}.
+
%% Supervisor callback
-init(Args) ->
+init([]) ->
+ Services = application:get_env(plop, services, []),
+ Children = [permanent_worker(the_db, {db, start_link, []}, [db]),
+ permanent_worker(the_storagedb, {storagedb, start_link, []}),
+ permanent_worker(fsync, {fsyncport, start_link, []})],
+ OptionalChildren = lists:map(fun (ServiceName) ->
+ case ServiceName of
+ ht ->
+ permanent_worker(the_ht, {ht, start_link, []});
+ sign ->
+ permanent_worker(the_signing, {sign, start_link, []})
+ end
+ end, Services),
{ok, {{one_for_one, 3, 10},
- [{the_db,
- {db, start_link, []},
- permanent,
- 10000,
- worker, [db]},
- {the_storagedb,
- {storagedb, start_link, []},
- permanent,
- 10000,
- worker, [storagedb]},
- {fsync,
- {fsyncport, start_link, []},
- permanent,
- 10000,
- worker, [fsyncport]},
- {the_ht,
- {ht, start_link, []},
- permanent,
- 10000,
- worker, [ht]},
- {the_signing,
- {sign, start_link, Args}, % All arguments go to sign.
- permanent,
- 10000,
- worker, [sign]},
- {the_plop,
- {plop, start_link, []},
- permanent,
- 10000, % Shut down within 10s.
- worker, [plop]}]}}.
+ Children ++ OptionalChildren
+ }}.
diff --git a/src/sign.erl b/src/sign.erl
index eae76e7..2c4441b 100644
--- a/src/sign.erl
+++ b/src/sign.erl
@@ -7,7 +7,7 @@
-behaviour(gen_server).
%% API.
--export([start_link/2, stop/0]).
+-export([start_link/0, stop/0]).
-export([sign/1, get_pubkey/0, get_logid/0]).
-export([read_keyfile_ec/1]).
%% API for tests.
@@ -26,19 +26,21 @@
logid :: binary()
}).
-start_link(Keyfile, Passphrase) ->
- gen_server:start_link({local, ?MODULE}, ?MODULE, [Keyfile, Passphrase], []).
+start_link() ->
+ gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
stop() ->
call(?MODULE, stop).
-init([PrivKeyfile, PubKeyfile]) ->
+init([]) ->
%% Read RSA keypair.
%% {Private_key, Public_key} = read_keyfile_rsa(Keyfile, Passphrase),
%% LogID = crypto:hash(sha256,
%% public_key:der_encode('RSAPublicKey', Public_key)),
%% Read EC keypair.
+ PrivKeyfile = application:get_env(plop, log_private_key, none),
+ PubKeyfile = application:get_env(plop, log_public_key, none),
{Private_key, Public_key, LogID} = read_keyfiles_ec(PrivKeyfile, PubKeyfile),
_Tree = ht:reset_tree([db:size() - 1]),
{ok, #state{pubkey = Public_key,