diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-09-08 12:36:35 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-09-08 12:36:35 +0200 |
commit | a40ba9f72f59e08c1a4d08117cfd4e40074bf64f (patch) | |
tree | 48f201ac9102b7d048cd871d6dc21a4dcfac477f | |
parent | 9b11a986f0e85eeec594da346f0b5e364c6b33ec (diff) |
make taler-merchant-depositcheck use keys via taler-merchant-exchangekeysupdate
-rw-r--r-- | src/backend/taler-merchant-depositcheck.c | 147 |
1 files changed, 96 insertions, 51 deletions
diff --git a/src/backend/taler-merchant-depositcheck.c b/src/backend/taler-merchant-depositcheck.c index 3b725596..ca9c635d 100644 --- a/src/backend/taler-merchant-depositcheck.c +++ b/src/backend/taler-merchant-depositcheck.c @@ -177,11 +177,6 @@ static struct Child *c_tail; static struct TALER_EXCHANGE_Keys *keys; /** - * Handle for active /keys request. - */ -static struct TALER_EXCHANGE_GetKeysHandle *gkh; - -/** * Head of list of active exchange interactions. */ static struct ExchangeInteraction *w_head; @@ -202,6 +197,11 @@ static uint64_t w_count; static struct GNUNET_DB_EventHandler *eh; /** + * Notification handler from database on new keys. + */ +static struct GNUNET_DB_EventHandler *keys_eh; + +/** * The merchant's configuration. */ static const struct GNUNET_CONFIGURATION_Handle *cfg; @@ -272,16 +272,16 @@ shutdown_task (void *cls) db_plugin->event_listen_cancel (eh); eh = NULL; } + if (NULL != keys_eh) + { + db_plugin->event_listen_cancel (keys_eh); + keys_eh = NULL; + } if (NULL != task) { GNUNET_SCHEDULER_cancel (task); task = NULL; } - if (NULL != gkh) - { - TALER_EXCHANGE_get_keys_cancel (gkh); - gkh = NULL; - } while (NULL != (w = w_head)) { GNUNET_CONTAINER_DLL_remove (w_head, @@ -756,42 +756,6 @@ select_work (void *cls) /** - * Function called with information about who is auditing - * a particular exchange and what keys the exchange is using. - * The ownership over the @a keys object is passed to - * the callee, thus it is given explicitly and not - * (only) via @a kr. - * - * @param cls closure, NULL - * @param kr response from /keys - * @param[in] in_keys keys object passed to callback with - * reference counter of 1. Must be freed by callee - * using TALER_EXCHANGE_keys_decref(). NULL on failure. - */ -static void -keys_cb ( - void *cls, - const struct TALER_EXCHANGE_KeysResponse *kr, - struct TALER_EXCHANGE_Keys *in_keys) -{ - gkh = NULL; - if (NULL == in_keys) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to download %skeys\n", - exchange_url); - GNUNET_SCHEDULER_shutdown (); - return; - } - keys = TALER_EXCHANGE_keys_incref (in_keys); - if (NULL != task) - GNUNET_SCHEDULER_cancel (task); - task = GNUNET_SCHEDULER_add_now (&select_work, - NULL); -} - - -/** * Start a copy of this process with the exchange URL * set to the given @a base_url * @@ -940,6 +904,76 @@ cfg_iter_cb (void *cls, /** + * Trigger (re)loading of keys from DB. + * + * @param cls NULL + * @param extra base URL of the exchange that changed + * @param extra_len number of bytes in @a extra + */ +static void +update_exchange_keys (void *cls, + const void *extra, + size_t extra_len) +{ + const char *url = extra; + + if ( (NULL == extra) || + (0 == extra_len) ) + { + GNUNET_break (0); + return; + } + if ('\0' != url[extra_len - 1]) + { + GNUNET_break (0); + return; + } + if (0 != strcmp (url, + exchange_url)) + return; /* not relevant for us */ + + { + enum GNUNET_DB_QueryStatus qs; + + if (NULL != keys) + { + TALER_EXCHANGE_keys_decref (keys); + keys = NULL; + } + qs = db_plugin->select_exchange_keys (db_plugin->cls, + exchange_url, + &keys); + if (qs < 0) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "No keys yet for `%s'\n", + exchange_url); + } + } + if (NULL == keys) + { + if (NULL != task) + { + GNUNET_SCHEDULER_cancel (task); + task = NULL; + } + } + else + { + if (NULL == task) + task = GNUNET_SCHEDULER_add_now (&select_work, + NULL); + } +} + + +/** * First task. * * @param cls closure, NULL @@ -1018,11 +1052,22 @@ run (void *cls, &db_notify, NULL); } - gkh = TALER_EXCHANGE_get_keys (ctx, - exchange_url, - NULL, - &keys_cb, - NULL); + { + struct GNUNET_DB_EventHeaderP es = { + .size = ntohs (sizeof (es)), + .type = ntohs (TALER_DBEVENT_MERCHANT_EXCHANGE_KEYS) + }; + + keys_eh = db_plugin->event_listen (db_plugin->cls, + &es, + GNUNET_TIME_UNIT_FOREVER_REL, + &update_exchange_keys, + NULL); + } + + update_exchange_keys (NULL, + exchange_url, + strlen (exchange_url) + 1); } |