gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated: make taler-merchant-depositcheck


From: gnunet
Subject: [taler-merchant] branch master updated: make taler-merchant-depositcheck use keys via taler-merchant-exchangekeysupdate
Date: Sun, 08 Sep 2024 13:29:24 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new a40ba9f7 make taler-merchant-depositcheck use keys via 
taler-merchant-exchangekeysupdate
a40ba9f7 is described below

commit a40ba9f72f59e08c1a4d08117cfd4e40074bf64f
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Sep 8 12:36:35 2024 +0200

    make taler-merchant-depositcheck use keys via 
taler-merchant-exchangekeysupdate
---
 src/backend/taler-merchant-depositcheck.c | 147 +++++++++++++++++++-----------
 1 file 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
@@ -176,11 +176,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.
  */
@@ -201,6 +196,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.
  */
@@ -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,
@@ -755,42 +755,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
@@ -939,6 +903,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.
  *
@@ -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);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]