summaryrefslogtreecommitdiff
path: root/src/auditor/taler-helper-auditor-purses.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/auditor/taler-helper-auditor-purses.c')
-rw-r--r--src/auditor/taler-helper-auditor-purses.c157
1 files changed, 156 insertions, 1 deletions
diff --git a/src/auditor/taler-helper-auditor-purses.c b/src/auditor/taler-helper-auditor-purses.c
index bc13a5fad..8ba1643df 100644
--- a/src/auditor/taler-helper-auditor-purses.c
+++ b/src/auditor/taler-helper-auditor-purses.c
@@ -26,6 +26,7 @@
#include "taler_bank_service.h"
#include "taler_signatures.h"
#include "report-lib.h"
+#include "taler_dbevents.h"
/**
@@ -118,6 +119,18 @@ static struct TALER_Amount total_bad_sig_loss;
*/
static int internal_checks;
+static struct GNUNET_DB_EventHandler *eh;
+
+/**
+ * Our database plugin.
+ */
+static struct TALER_AUDITORDB_Plugin *db_plugin;
+
+/**
+ * The auditors's configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
/* ***************************** Report logic **************************** */
@@ -1402,6 +1415,94 @@ analyze_purses (void *cls)
/**
+ * Function called on events received from Postgres.
+ *
+ * @param cls closure, NULL
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+static void
+db_notify (void *cls,
+ const void *extra,
+ size_t extra_size)
+{
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received notification to wake purses\n");
+
+ (void) cls;
+ (void) extra;
+ (void) extra_size;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &TALER_ARL_USE_AB (
+ purse_global_balance)));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_balance_insufficient_loss));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_delayed_decisions));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_arithmetic_delta_plus));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_arithmetic_delta_minus));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_balance_purse_not_closed));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_bad_sig_loss));
+
+ GNUNET_assert (NULL !=
+ (report_row_inconsistencies = json_array ()));
+ GNUNET_assert (NULL !=
+ (report_purse_balance_insufficient_inconsistencies
+ = json_array ()));
+ GNUNET_assert (NULL !=
+ (report_purse_not_closed_inconsistencies
+ = json_array ()));
+ GNUNET_assert (NULL !=
+ (report_amount_arithmetic_inconsistencies
+ = json_array ()));
+ GNUNET_assert (NULL !=
+ (report_bad_sig_losses = json_array ()));
+ if (GNUNET_OK !=
+ TALER_ARL_setup_sessions_and_run (&analyze_purses,
+ NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Audit failed\n");
+ TALER_ARL_done (NULL);
+ global_ret = EXIT_FAILURE;
+ }
+
+}
+
+
+/**
+ * Function called on shutdown.
+ */
+static void
+do_shutdown (void *cls)
+{
+ (void) cls;
+
+ if (test_mode != 1)
+ {
+ db_plugin->event_listen_cancel (eh);
+ eh = NULL;
+ TALER_AUDITORDB_plugin_unload (db_plugin);
+ db_plugin = NULL;
+ TALER_ARL_done (NULL);
+ }
+}
+
+
+/**
* Main function that will be run.
*
* @param cls closure
@@ -1418,14 +1519,61 @@ run (void *cls,
(void) cls;
(void) args;
(void) cfgfile;
+
+ cfg = c;
+
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Launching auditor\n");
+ "Launching purses auditor\n");
+
if (GNUNET_OK !=
TALER_ARL_init (c))
{
global_ret = EXIT_FAILURE;
return;
}
+
+ if (NULL ==
+ (db_plugin = TALER_AUDITORDB_plugin_load (cfg)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to initialize DB subsystem\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (GNUNET_OK !=
+ db_plugin->preflight (db_plugin->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to connect to database\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
+ if (test_mode != 1)
+ {
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running helper indefinitely\n");
+
+ struct GNUNET_DB_EventHeaderP es = {
+ .size = htons (sizeof (es)),
+ .type = htons (TALER_DBEVENT_EXCHANGE_AUDITOR_WAKE_HELPER_PURSES)
+ };
+ eh = db_plugin->event_listen (db_plugin->cls,
+ &es,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &db_notify,
+ NULL);
+ return;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running helper in test mode\n");
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting audit\n");
+
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
&TALER_ARL_USE_AB (
@@ -1466,9 +1614,16 @@ run (void *cls,
TALER_ARL_setup_sessions_and_run (&analyze_purses,
NULL))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Audit failed\n");
+ TALER_ARL_done (NULL);
global_ret = EXIT_FAILURE;
return;
}
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Audit complete\n");
+
TALER_ARL_done (
GNUNET_JSON_PACK (
/* Globals (REVIEW!) */