diff options
author | Nic <nic@eigel.ch> | 2024-01-09 01:26:00 +0100 |
---|---|---|
committer | Nic <nic@eigel.ch> | 2024-01-09 01:26:00 +0100 |
commit | a7b6db8c59061ab386c2b14949eb871477a7b7fb (patch) | |
tree | b52591d4ee5df2902c45943b1ca91f3172b9138e /src/auditor | |
parent | 342f119263130001803d5847fbe72a259647a4df (diff) | |
download | exchange-a7b6db8c59061ab386c2b14949eb871477a7b7fb.tar.xz |
adding auditor resp endpoints, trigger for helper deposit_confirmations
Diffstat (limited to 'src/auditor')
-rw-r--r-- | src/auditor/taler-auditor-httpd.c | 6 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd_deposit-confirmation.c | 135 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd_deposit-confirmation.h | 30 | ||||
-rw-r--r-- | src/auditor/taler-helper-auditor-deposits.c | 69 |
4 files changed, 218 insertions, 22 deletions
diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c index a59ce3de0..c1853d84a 100644 --- a/src/auditor/taler-auditor-httpd.c +++ b/src/auditor/taler-auditor-httpd.c @@ -206,6 +206,12 @@ handle_mhd_request (void *cls, { "/deposit-confirmation", MHD_HTTP_METHOD_PUT, "application/json", NULL, 0, &TAH_DEPOSIT_CONFIRMATION_handler, MHD_HTTP_OK }, + { "/deposit-confirmation", MHD_HTTP_METHOD_GET, "application/json", + NULL, 0, + &TAH_DEPOSIT_CONFIRMATION_get, MHD_HTTP_OK }, +// { "/deposit-confirmation", MHD_HTTP_METHOD_DELETE, "application/json", +// NULL, 0, +// &TAH_DEPOSIT_CONFIRMATION_delete, MHD_HTTP_OK }, { "/exchanges", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, &TAH_EXCHANGES_handler, MHD_HTTP_OK }, diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation.c b/src/auditor/taler-auditor-httpd_deposit-confirmation.c index 020d43d56..9a3e5475c 100644 --- a/src/auditor/taler-auditor-httpd_deposit-confirmation.c +++ b/src/auditor/taler-auditor-httpd_deposit-confirmation.c @@ -31,7 +31,6 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_deposit-confirmation.h" - GNUNET_NETWORK_STRUCT_BEGIN /** @@ -118,11 +117,11 @@ verify_and_execute_deposit_confirmation ( const struct TALER_CoinSpendSignatureP *coin_sigps[ GNUNET_NZL (dc->num_coins)]; - for (unsigned int i = 0; i<dc->num_coins; i++) + for (unsigned int i = 0; i < dc->num_coins; i++) coin_sigps[i] = &dc->coin_sigs[i]; if (GNUNET_TIME_absolute_is_future (es->ep_start.abs_time) || - GNUNET_TIME_absolute_is_past (es->ep_expire.abs_time) ) + GNUNET_TIME_absolute_is_past (es->ep_expire.abs_time)) { /* Signing key expired */ TALER_LOG_WARNING ("Expired exchange signing key\n"); @@ -134,7 +133,7 @@ verify_and_execute_deposit_confirmation ( /* check our cache */ GNUNET_CRYPTO_hash (&skv, - sizeof (skv), + sizeof(skv), &h); GNUNET_assert (0 == pthread_mutex_lock (&lock)); cached = GNUNET_CONTAINER_multihashmap_get (cache, @@ -341,8 +340,8 @@ TAH_DEPOSIT_CONFIRMATION_handler ( &json); if (GNUNET_SYSERR == res) return MHD_NO; - if ( (GNUNET_NO == res) || - (NULL == json) ) + if ((GNUNET_NO == res) || + (NULL == json)) return MHD_YES; res = TALER_MHD_parse_json_data (connection, json, @@ -350,12 +349,12 @@ TAH_DEPOSIT_CONFIRMATION_handler ( if (GNUNET_SYSERR == res) { json_decref (json); - return MHD_NO; /* hard failure */ + return MHD_NO; /* hard failure */ } if (GNUNET_NO == res) { json_decref (json); - return MHD_YES; /* failure */ + return MHD_YES; /* failure */ } } num_coins = json_array_size (jcoin_sigs); @@ -382,7 +381,7 @@ TAH_DEPOSIT_CONFIRMATION_handler ( struct TALER_CoinSpendSignatureP coin_sigs[num_coins]; MHD_RESULT res; - for (unsigned int i = 0; i<num_coins; i++) + for (unsigned int i = 0; i < num_coins; i++) { json_t *jpub = json_array_get (jcoin_pubs, i); @@ -391,12 +390,12 @@ TAH_DEPOSIT_CONFIRMATION_handler ( const char *ps = json_string_value (jpub); const char *ss = json_string_value (jsig); - if ( (NULL == ps) || - (GNUNET_OK != - GNUNET_STRINGS_string_to_data (ps, - strlen (ps), - &coin_pubs[i], - sizeof (coin_pubs[i]))) ) + if ((NULL == ps) || + (GNUNET_OK != + GNUNET_STRINGS_string_to_data (ps, + strlen (ps), + &coin_pubs[i], + sizeof(coin_pubs[i])))) { GNUNET_break_op (0); json_decref (json); @@ -405,12 +404,12 @@ TAH_DEPOSIT_CONFIRMATION_handler ( TALER_EC_GENERIC_PARAMETER_MALFORMED, "coin_pub[] malformed"); } - if ( (NULL == ss) || - (GNUNET_OK != - GNUNET_STRINGS_string_to_data (ss, - strlen (ss), - &coin_sigs[i], - sizeof (coin_sigs[i]))) ) + if ((NULL == ss) || + (GNUNET_OK != + GNUNET_STRINGS_string_to_data (ss, + strlen (ss), + &coin_sigs[i], + sizeof(coin_sigs[i])))) { GNUNET_break_op (0); json_decref (json); @@ -423,7 +422,7 @@ TAH_DEPOSIT_CONFIRMATION_handler ( dc.num_coins = num_coins; dc.coin_pubs = coin_pubs; dc.coin_sigs = coin_sigs; - es.exchange_pub = dc.exchange_pub; /* used twice! */ + es.exchange_pub = dc.exchange_pub; /* used twice! */ dc.master_public_key = es.master_public_key; res = verify_and_execute_deposit_confirmation (connection, &dc, @@ -456,4 +455,96 @@ TEAH_DEPOSIT_CONFIRMATION_done (void) } +/** + * Add deposit confirmation to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param dc struct of deposit confirmation + */ +static void +add_deposit_confirmation (void *cls, + 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)); + +} + + +/** + * + * @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; + + qs = TAH_plugin->get_deposit_confirmations ( + TAH_plugin->cls, + &TAH_plugin, + 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 a7c331916..ff42e4aa3 100644 --- a/src/auditor/taler-auditor-httpd_deposit-confirmation.h +++ b/src/auditor/taler-auditor-httpd_deposit-confirmation.h @@ -56,4 +56,34 @@ 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 8ec2b223e..4f2283739 100644 --- a/src/auditor/taler-helper-auditor-deposits.c +++ b/src/auditor/taler-helper-auditor-deposits.c @@ -29,6 +29,8 @@ #include "taler_bank_service.h" #include "taler_signatures.h" #include "report-lib.h" +#include <taler/taler_dbevents.h> +#include <jansson.h> /* -- @@ -51,6 +53,10 @@ -- AND NOT ancient; */ +/** + * Next task to run, if any. + */ +static struct GNUNET_SCHEDULER_Task *task; /** * Return value from main(). @@ -77,6 +83,13 @@ static struct TALER_Amount total_missed_deposit_confirmations; */ static int internal_checks; +static struct GNUNET_DB_EventHandler *eh; + +/** + * Our database plugin. + */ +static struct TALER_AUDITORDB_Plugin *db_plugin; + /** * Closure for #test_dc. */ @@ -289,6 +302,29 @@ analyze_deposit_confirmations (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) +{ + (void) cls; + (void) extra; + (void) extra_size; + + GNUNET_assert (NULL != task); + GNUNET_SCHEDULER_cancel (task); + task = GNUNET_SCHEDULER_add_now (&analyze_deposit_confirmations, + NULL); +} + + +/** * Main function that will be run. * * @param cls closure @@ -313,6 +349,39 @@ run (void *cls, 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->connect (db_plugin->cls)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to database\n"); + GNUNET_SCHEDULER_shutdown (); + return; + } + { + 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_assert (NULL == task); + task = GNUNET_SCHEDULER_add_now (&select_work, + NULL);*/ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting deposit audit\n"); GNUNET_assert (NULL != |