diff options
author | Nic Eigel <nic@eigel.ch> | 2024-01-16 22:37:07 +0100 |
---|---|---|
committer | Nic Eigel <nic@eigel.ch> | 2024-01-16 22:37:07 +0100 |
commit | 45b110edb2b4fd39c56f433c5c0a7f93cd29d4da (patch) | |
tree | 3ce6145e8ea7f67daaa1af55b3651002021167fd /src/auditor | |
parent | 510d4fc5234e8e17d73e8d95a0dc66ad37c03fef (diff) |
progress on auditor helpers
Diffstat (limited to 'src/auditor')
-rw-r--r-- | src/auditor/Makefile.am | 1 | ||||
-rw-r--r-- | src/auditor/generate-auditor-basedb.conf | 28 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd.c | 3 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd_deposit-confirmation-get.c | 206 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd_deposit-confirmation-get.h | 70 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd_deposit-confirmation.c | 98 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd_deposit-confirmation.h | 29 | ||||
-rw-r--r-- | src/auditor/taler-helper-auditor-deposits.c | 132 |
8 files changed, 393 insertions, 174 deletions
diff --git a/src/auditor/Makefile.am b/src/auditor/Makefile.am index c3deedba1..36b540c03 100644 --- a/src/auditor/Makefile.am +++ b/src/auditor/Makefile.am @@ -163,6 +163,7 @@ taler_helper_auditor_wire_LDADD = \ taler_auditor_httpd_SOURCES = \ taler-auditor-httpd.c taler-auditor-httpd.h \ taler-auditor-httpd_deposit-confirmation.c taler-auditor-httpd_deposit-confirmation.h \ + taler-auditor-httpd_deposit-confirmation-get.c taler-auditor-httpd_deposit-confirmation-get.h \ taler-auditor-httpd_mhd.c taler-auditor-httpd_mhd.h taler_auditor_httpd_LDADD = \ $(LIBGCRYPT_LIBS) \ diff --git a/src/auditor/generate-auditor-basedb.conf b/src/auditor/generate-auditor-basedb.conf index 8aae9a924..8efb81a3e 100644 --- a/src/auditor/generate-auditor-basedb.conf +++ b/src/auditor/generate-auditor-basedb.conf @@ -13,9 +13,22 @@ SIGNKEY_DURATION = 4 weeks LOOKAHEAD_SIGN = 32 weeks 1 day SIGNKEY_LEGAL_DURATION = 4 weeks AML_THRESHOLD = TESTKUDOS:1000000 +db = postgres +BASE_URL = http://localhost:8081/ +IDLE_RESERVE_EXPIRATION_TIME = 4 weeks +LEGAL_RESERVE_EXPIRATION_TIME = 4 weeks + +[exchangedb] +IDLE_RESERVE_EXPIRATION_TIME = 4 weeks +LEGAL_RESERVE_EXPIRATION_TIME = 4 weeks +AGGREGATOR_SHIFT = 1 s +DEFAULT_PURSE_LIMIT = 1 [exchangedb-postgres] CONFIG = postgres:///auditor-basedb +SQL_DIR = $DATADIR/sql/exchange/ +IDLE_RESERVE_EXPIRATION_TIME = 4 weeks +LEGAL_RESERVE_EXPIRATION_TIME = 4 weeks [exchange-account-1] PAYTO_URI = payto://iban/SANDBOXX/DE989651?receiver-name=Exchange+Company @@ -49,9 +62,12 @@ WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/" [merchant] FORCE_AUDIT = YES +SERVE = TCP +PORT = 8888 [merchantdb-postgres] CONFIG = postgres:///auditor-basedb +SQL_DIR = $DATADIR/sql/merchant/ [merchant-exchange-default] MASTER_KEY = M4FGP18EQFXFGGFQ1AWXHACN2JX0SMVK9CNF6459Z1WG18JSN0BG @@ -67,13 +83,25 @@ DB_CONNECTION="postgresql:///auditor-basedb" [libeufin-sandbox] DB_CONNECTION="postgresql:///auditor-basedb" +[libeufin-bank] +CURRENCY = EUR +DEFAULT_CUSTOMER_DEBT_LIMIT = EUR:200 # dead +DEFAULT_ADMIN_DEBT_LIMIT = EUR:2000 +REGISTRATION_BONUS_ENABLED = yes +REGISTRATION_BONUS = EUR:100 +SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8081/ +SERVE = tcp +PORT = 8082 + [auditor] BASE_URL = http://localhost:8083/ TINY_AMOUNT = TESTKUDOS:0.01 PUBLIC_KEY = 0EHPW5WEKHXPPN4MPJNGA7Z6D29JP21GKVNV8ARFB1YW7WWJX20G +db = postgres [auditordb-postgres] CONFIG = postgres:///auditor-basedb +SQL_DIR = $DATADIR/sql/auditor/ [coin_kudos_ct_1] value = TESTKUDOS:0.01 diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c index 0bb9c77d9..94adb5471 100644 --- a/src/auditor/taler-auditor-httpd.c +++ b/src/auditor/taler-auditor-httpd.c @@ -31,6 +31,7 @@ #include "taler_auditordb_lib.h" #include "taler_exchangedb_lib.h" #include "taler-auditor-httpd_deposit-confirmation.h" +#include "taler-auditor-httpd_deposit-confirmation-get.h" #include "taler-auditor-httpd_mhd.h" #include "taler-auditor-httpd.h" @@ -207,7 +208,7 @@ handle_mhd_request (void *cls, &TAH_DEPOSIT_CONFIRMATION_handler, MHD_HTTP_OK }, { "/deposit-confirmation", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, - &TAH_DEPOSIT_CONFIRMATION_get, MHD_HTTP_OK }, + &TAH_DEPOSIT_CONFIRMATION_handler_get, MHD_HTTP_OK }, // { "/deposit-confirmation", MHD_HTTP_METHOD_DELETE, "application/json", // NULL, 0, // &TAH_DEPOSIT_CONFIRMATION_delete, MHD_HTTP_OK }, diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation-get.c b/src/auditor/taler-auditor-httpd_deposit-confirmation-get.c new file mode 100644 index 000000000..5caff7aba --- /dev/null +++ b/src/auditor/taler-auditor-httpd_deposit-confirmation-get.c @@ -0,0 +1,206 @@ +/*
+ This file is part of TALER
+ Copyright (C) 2014-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file taler-auditor-httpd_deposit-confirmation-get.c
+ * @brief Handle /deposit-confirmation requests; return list of deposit confirmations from merchant
+ * that were not received from the exchange, by auditor.
+ * @author Nic Eigel
+ */
+
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler-auditor-httpd.h"
+#include "taler-auditor-httpd_deposit-confirmation-get.h"
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * @brief Information about a signing key of the exchange. Signing keys are used
+ * to sign exchange messages other than coins, i.e. to confirm that a
+ * deposit was successful or that a refresh was accepted.
+ */
+struct ExchangeSigningKeyDataP
+{
+
+ /**
+ * When does this signing key begin to be valid?
+ */
+ struct GNUNET_TIME_TimestampNBO start;
+
+ /**
+ * When does this signing key expire? Note: This is currently when
+ * the Exchange will definitively stop using it. Signatures made with
+ * the key remain valid until @e end. When checking validity periods,
+ * clients should allow for some overlap between keys and tolerate
+ * the use of either key during the overlap time (due to the
+ * possibility of clock skew).
+ */
+ struct GNUNET_TIME_TimestampNBO expire;
+
+ /**
+ * When do signatures with this signing key become invalid? After
+ * this point, these signatures cannot be used in (legal) disputes
+ * anymore, as the Exchange is then allowed to destroy its side of the
+ * evidence. @e end is expected to be significantly larger than @e
+ * expire (by a year or more).
+ */
+ struct GNUNET_TIME_TimestampNBO end;
+
+ /**
+ * The public online signing key that the exchange will use
+ * between @e start and @e expire.
+ */
+ struct TALER_ExchangePublicKeyP signkey_pub;
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+/**
+ * Cache of already verified exchange signing keys. Maps the hash of the
+ * `struct TALER_ExchangeSigningKeyValidityPS` to the (static) string
+ * "verified" or "revoked". Access to this map is guarded by the #lock.
+ */
+static struct GNUNET_CONTAINER_MultiHashMap *cache;
+
+/**
+ * Lock for operations on #cache.
+ */
+static pthread_mutex_t lock;
+
+
+/**
+ * Add deposit confirmation to the list.
+ *
+ * @param[in,out] cls a `json_t *` array to extend
+ * @param serial_id location of the @a dc in the database
+ * @param dc struct of deposit confirmation
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+static enum GNUNET_GenericReturnValue
+add_deposit_confirmation (void *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_DepositConfirmation *dc)
+{
+ json_t *list = cls;
+ json_t *obj;
+
+ obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("dc",
+ dc));
+ GNUNET_break (0 ==
+ json_array_append_new (list,
+ obj));
+ return GNUNET_OK;
+}
+
+
+/**
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] connection_cls the connection's closure (can be updated)
+ * @param upload_data upload data
+ * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @return MHD result code
+ */
+MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_handler_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+ json_t *ja;
+ enum GNUNET_DB_QueryStatus qs;
+
+ (void) rh;
+ (void) connection_cls;
+ (void) upload_data;
+ (void) upload_data_size;
+ if (GNUNET_SYSERR ==
+ TAH_plugin->preflight (TAH_plugin->cls))
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_SETUP_FAILED,
+ NULL);
+ }
+ ja = json_array ();
+ GNUNET_break (NULL != ja);
+ // TODO correct below
+ struct TALER_AUDITORDB_ProgressPointDepositConfirmation ppdc = { 0 }; // FIXME: initialize...
+
+ qs = TAH_plugin->get_deposit_confirmations (
+ TAH_plugin->cls,
+ ppdc.last_deposit_confirmation_serial_id,
+ &add_deposit_confirmation,
+ ja);
+
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
+ json_decref (ja);
+ TALER_LOG_WARNING (
+ "Failed to handle GET /deposit-confirmation in database\n");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "deposit-confirmation");
+ }
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("deposit-confirmation",
+ ja));
+}
+
+
+void
+TEAH_DEPOSIT_CONFIRMATION_GET_init (void)
+{
+ cache = GNUNET_CONTAINER_multihashmap_create (32,
+ GNUNET_NO);
+ GNUNET_assert (0 == pthread_mutex_init (&lock, NULL));
+}
+
+
+void
+TEAH_DEPOSIT_CONFIRMATION_GET_done (void)
+{
+ if (NULL != cache)
+ {
+ GNUNET_CONTAINER_multihashmap_destroy (cache);
+ cache = NULL;
+ GNUNET_assert (0 == pthread_mutex_destroy (&lock));
+ }
+}
+
+
+/*MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_delete(struct TEH_RequestContext *rc,
+ const char *const args[1]) {
+}*/
+
+
+/* end of taler-auditor-httpd_deposit-confirmation.c */
diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation-get.h b/src/auditor/taler-auditor-httpd_deposit-confirmation-get.h new file mode 100644 index 000000000..f1f522787 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_deposit-confirmation-get.h @@ -0,0 +1,70 @@ +/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-auditor-httpd_deposit-confirmation-get.h
+ * @brief Handle GET /deposit-confirmation requests
+ * @author Nic Eigel
+ */
+#ifndef TALER_AUDITOR_HTTPD_DEPOSIT_CONFIRMATION_GET_H
+#define TALER_AUDITOR_HTTPD_DEPOSIT_CONFIRMATION_GET_H
+
+#include <gnunet/gnunet_util_lib.h>
+#include <microhttpd.h>
+#include "taler-auditor-httpd.h"
+
+/**
+ * Initialize subsystem.
+ */
+void
+TEAH_DEPOSIT_CONFIRMATION_GET_init (void);
+
+/**
+ * Shut down subsystem.
+ */
+void
+TEAH_DEPOSIT_CONFIRMATION_GET_done (void);
+
+/**
+ * Handle a "/deposit-confirmation" request.
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] connection_cls the connection's closure (can be updated)
+ * @param upload_data upload data
+ * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @return MHD result code
+ */
+MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_handler_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size);
+
+/**
+ * Handle a DELETE "/deposit-confirmation/$dc" request.
+ *
+ * @param rc request details about the request to handle
+ * @param args argument with the dc primary key
+ * @return MHD result code
+ */
+/*MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_delete (
+ struct TEH_RequestContext *rc,
+ const char *const args[1]);*/
+
+
+#endif
diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation.c b/src/auditor/taler-auditor-httpd_deposit-confirmation.c index 2631c6f58..10243eafc 100644 --- a/src/auditor/taler-auditor-httpd_deposit-confirmation.c +++ b/src/auditor/taler-auditor-httpd_deposit-confirmation.c @@ -453,101 +453,3 @@ TEAH_DEPOSIT_CONFIRMATION_done (void) GNUNET_assert (0 == pthread_mutex_destroy (&lock)); } } - - -/** - * Add deposit confirmation to the list. - * - * @param[in,out] cls a `json_t *` array to extend - * @param serial_id location of the @a dc in the database - * @param dc struct of deposit confirmation - * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating - */ -static enum GNUNET_GenericReturnValue -add_deposit_confirmation (void *cls, - uint64_t serial_id, - const struct TALER_AUDITORDB_DepositConfirmation *dc) -{ - json_t *list = cls; - json_t *obj; - - obj = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_data_auto ("dc", - dc)); - GNUNET_break (0 == - json_array_append_new (list, - obj)); - return GNUNET_OK; -} - - -/** - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @return MHD result code - */ -MHD_RESULT -TAH_DEPOSIT_CONFIRMATION_get (struct TAH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size) -{ - json_t *ja; - enum GNUNET_DB_QueryStatus qs; - - (void) rh; - (void) connection_cls; - (void) upload_data; - (void) upload_data_size; - if (GNUNET_SYSERR == - TAH_plugin->preflight (TAH_plugin->cls)) - { - GNUNET_break (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_SETUP_FAILED, - NULL); - } - ja = json_array (); - GNUNET_break (NULL != ja); - // TODO correct below - struct TALER_AUDITORDB_ProgressPointDepositConfirmation ppdc = { 0 }; // FIXME: initialize... - - qs = TAH_plugin->get_deposit_confirmations ( - TAH_plugin->cls, - NULL, /* FIXME: master-public key to be removed! */ - ppdc.last_deposit_confirmation_serial_id, - &add_deposit_confirmation, - ja); - - if (0 > qs) - { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); - json_decref (ja); - TALER_LOG_WARNING ( - "Failed to handle GET /deposit-confirmation in database\n"); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_FETCH_FAILED, - "deposit-confirmation"); - } - return TALER_MHD_REPLY_JSON_PACK ( - connection, - MHD_HTTP_OK, - GNUNET_JSON_pack_array_steal ("deposit-confirmation", - ja)); -} - - -/*MHD_RESULT -TAH_DEPOSIT_CONFIRMATION_delete(struct TEH_RequestContext *rc, - const char *const args[1]) { -}*/ - - -/* end of taler-auditor-httpd_deposit-confirmation.c */ diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation.h b/src/auditor/taler-auditor-httpd_deposit-confirmation.h index ff42e4aa3..1226dda69 100644 --- a/src/auditor/taler-auditor-httpd_deposit-confirmation.h +++ b/src/auditor/taler-auditor-httpd_deposit-confirmation.h @@ -56,34 +56,5 @@ TAH_DEPOSIT_CONFIRMATION_handler (struct TAH_RequestHandler *rh, const char *upload_data, size_t *upload_data_size); -/** - * Handle a "/deposit-confirmation" request. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @return MHD result code - */ -MHD_RESULT -TAH_DEPOSIT_CONFIRMATION_get (struct TAH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size); - -/** - * Handle a DELETE "/deposit-confirmation/$dc" request. - * - * @param rc request details about the request to handle - * @param args argument with the dc primary key - * @return MHD result code - */ -/*MHD_RESULT -TAH_DEPOSIT_CONFIRMATION_delete ( - struct TEH_RequestContext *rc, - const char *const args[1]);*/ - #endif diff --git a/src/auditor/taler-helper-auditor-deposits.c b/src/auditor/taler-helper-auditor-deposits.c index 520fc2f47..fea23131b 100644 --- a/src/auditor/taler-helper-auditor-deposits.c +++ b/src/auditor/taler-helper-auditor-deposits.c @@ -17,6 +17,7 @@ * @file auditor/taler-helper-auditor-deposits.c * @brief audits an exchange database for deposit confirmation consistency * @author Christian Grothoff + * @author Nic Eigel * * We simply check that all of the deposit confirmations reported to us * by merchants were also reported to us by the exchange. @@ -35,14 +36,14 @@ /* -- -- SELECT serial_id,h_contract_terms,h_wire,merchant_pub ... --- FROM auditor.depoist_confirmations +-- FROM auditor.auditor_deposit_confirmations -- WHERE NOT ancient -- ORDER BY exchange_timestamp ASC; -- SELECT 1 - FROM exchange.deposits dep WHERE ($RESULT.contract_terms = dep.h_contract_terms) AND ($RESULT.h_wire = dep.h_wire) AND ...); -- IF FOUND --- DELETE FROM auditor.depoist_confirmations +-- DELETE FROM auditor.auditor_deposit_confirmations -- WHERE serial_id = $RESULT.serial_id; -- SELECT exchange_timestamp AS latest -- FROM exchange.deposits ORDER BY exchange_timestamp DESC; @@ -54,11 +55,6 @@ */ /** - * Next task to run, if any. - */ -static struct GNUNET_SCHEDULER_Task *task; - -/** * Return value from main(). */ static int global_ret; @@ -91,6 +87,11 @@ static struct GNUNET_DB_EventHandler *eh; static struct TALER_AUDITORDB_Plugin *db_plugin; /** + * The auditors's configuration. + */ +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +/** * Closure for #test_dc. */ struct DepositConfirmationContext @@ -126,7 +127,6 @@ struct DepositConfirmationContext }; - /** * Given a deposit confirmation from #TALER_ARL_adb, check that it is also * in #TALER_ARL_edb. Update the deposit confirmation context accordingly. @@ -145,7 +145,7 @@ test_dc (void *cls, bool missing = false; dcc->last_seen_coin_serial = serial_id; - for (unsigned int i = 0; i<dc->num_coins; i++) + for (unsigned int i = 0; i < dc->num_coins; i++) { enum GNUNET_DB_QueryStatus qs; struct GNUNET_TIME_Timestamp exchange_timestamp; @@ -215,15 +215,14 @@ analyze_deposit_confirmations (void *cls) enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qsx; enum GNUNET_DB_QueryStatus qsp; - (void) cls; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Analyzing deposit confirmations\n"); + ppdc.last_deposit_confirmation_serial_id = 0; qsp = TALER_ARL_adb->get_auditor_progress_deposit_confirmation ( TALER_ARL_adb->cls, &TALER_ARL_master_pub, &ppdc); + if (0 > qsp) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp); @@ -248,9 +247,10 @@ analyze_deposit_confirmations (void *cls) dcc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; dcc.missed_count = 0LLU; dcc.first_missed_coin_serial = UINT64_MAX; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "lastdepconfserialid %lu\n", + ppdc.last_deposit_confirmation_serial_id); qsx = TALER_ARL_adb->get_deposit_confirmations ( TALER_ARL_adb->cls, - &TALER_ARL_master_pub, ppdc.last_deposit_confirmation_serial_id, &test_dc, &dcc); @@ -268,11 +268,16 @@ analyze_deposit_confirmations (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == dcc.qs); return dcc.qs; } - if (UINT64_MAX == dcc.first_missed_coin_serial) - ppdc.last_deposit_confirmation_serial_id = dcc.last_seen_coin_serial; - else - ppdc.last_deposit_confirmation_serial_id = dcc.first_missed_coin_serial - 1; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "getting in here when i shouldnt\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "lastseencoinserialid %lu\n", + dcc.last_seen_coin_serial); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "dcc.qs %u\n", dcc.qs); + /* if (UINT64_MAX == dcc.first_missed_coin_serial) + ppdc.last_deposit_confirmation_serial_id = dcc.last_seen_coin_serial; + else + ppdc.last_deposit_confirmation_serial_id = dcc.first_missed_coin_serial - 1; + */ /* sync 'cc' back to disk */ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp) qs = TALER_ARL_adb->update_auditor_progress_deposit_confirmation ( @@ -291,6 +296,7 @@ analyze_deposit_confirmations (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + number_missed_deposit_confirmations = (json_int_t) dcc.missed_count; total_missed_deposit_confirmations = dcc.missed_amount; @@ -313,14 +319,52 @@ db_notify (void *cls, const void *extra, size_t extra_size) { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Received notification for new deposit_confirmation\n"); + (void) cls; (void) extra; (void) extra_size; - GNUNET_assert (NULL != task); - GNUNET_SCHEDULER_cancel (task); - task = GNUNET_SCHEDULER_add_now (&analyze_deposit_confirmations, - NULL); + if (GNUNET_OK != + TALER_ARL_init (cfg)) + { + 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; + } + GNUNET_assert (NULL != + (report_deposit_confirmation_inconsistencies = json_array ())); + + if (GNUNET_OK != + TALER_ARL_setup_sessions_and_run (&analyze_deposit_confirmations, + NULL)) + { + global_ret = EXIT_FAILURE; + return; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deposit audit complete\n"); + TALER_ARL_done ( + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_array_steal ("deposit_confirmation_inconsistencies", + report_deposit_confirmation_inconsistencies), + GNUNET_JSON_pack_uint64 ("missing_deposit_confirmation_count", + number_missed_deposit_confirmations), + TALER_JSON_pack_amount ("missing_deposit_confirmation_total", + &total_missed_deposit_confirmations), + TALER_JSON_pack_time_abs_human ("auditor_start_time", + start_time), + TALER_JSON_pack_time_abs_human ("auditor_end_time", + GNUNET_TIME_absolute_get ()))); } @@ -341,6 +385,7 @@ run (void *cls, (void) cls; (void) args; (void) cfgfile; + cfg = c; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching deposit auditor\n"); if (GNUNET_OK != @@ -350,37 +395,32 @@ run (void *cls, return; } - /*if (NULL == + 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; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to initialize DB subsystem\n"); + GNUNET_SCHEDULER_shutdown (); + return; } if (GNUNET_OK != - db_plugin->connect (db_plugin->cls)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to database\n"); - GNUNET_SCHEDULER_shutdown (); - return; - } + db_plugin->preflight (db_plugin->cls)) { - struct GNUNET_DB_EventHeaderP es = { - .size = htons (sizeof (es)), - .type = htons (TALER_DBEVENT_AUDITOR_NEW_DEPOSIT_CONFIRMATIONS) - }; - - eh = db_plugin->event_listen (db_plugin->cls, - &es, - GNUNET_TIME_UNIT_FOREVER_REL, - &db_notify, - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to database\n"); + GNUNET_SCHEDULER_shutdown (); + return; } - GNUNET_assert (NULL == task); - task = GNUNET_SCHEDULER_add_now (&select_work, - NULL);*/ + + struct GNUNET_DB_EventHeaderP es = { + .size = htons (sizeof (es)), + .type = htons (TALER_DBEVENT_EXCHANGE_AUDITOR_NEW_DEPOSIT_CONFIRMATION) + }; + eh = db_plugin->event_listen (db_plugin->cls, + &es, + GNUNET_TIME_UNIT_FOREVER_REL, + &db_notify, + NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting deposit audit\n"); |