commit fd8e8a5f730cdd8b13a14d28a3d8341e989986f6
parent 041a0aef99a9d88fcc041cb3dcf628a947c4305c
Author: Bohdan Potuzhnyi <potub1@bfh.ch>
Date: Sun, 13 Oct 2024 09:39:30 +0000
update of the donaukeyupdate service
Diffstat:
2 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/src/backend/taler-merchant-donaukeyupdate.c b/src/backend/taler-merchant-donaukeyupdate.c
@@ -223,6 +223,7 @@ end_inquiry (void)
static enum GNUNET_DB_QueryStatus
insert_donau_keys_data(const struct DONAU_Keys *keys)
{
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Inserting Donau keys into the database %s\n", keys->donau_url);
return db_plugin->upsert_donau_keys(db_plugin->cls, keys);
}
@@ -253,6 +254,7 @@ store_donau_keys(struct DONAU_Keys *keys)
if (qs < 0)
{
db_plugin->rollback(db_plugin->cls);
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error while inserting Donau keys into the database: status %d", qs);
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
continue;
GNUNET_break (0);
@@ -263,6 +265,7 @@ store_donau_keys(struct DONAU_Keys *keys)
if (qs < 0)
{
db_plugin->rollback (db_plugin->cls);
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to commit Donau keys to the database: status %d", qs);
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
continue;
GNUNET_break (0);
@@ -293,6 +296,9 @@ donau_cert_cb(
struct Donau *d = cls;
struct GNUNET_TIME_Absolute n;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting donau cert with object \n");
+
d->conn = NULL;
switch (kr->hr.http_status)
{
@@ -407,6 +413,9 @@ lookup_donau(const char *donau_url)
GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
"Got notification about unknown Donau `%s'\n",
donau_url);
+
+
+
return NULL;
}
@@ -437,14 +446,30 @@ force_donau_keys(void *cls,
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received keys change notification: reload `%s'\n",
+ "Received keys update notification: reload `%s'\n",
url);
d = lookup_donau(url);
if (NULL == d)
{
- GNUNET_break (0);
- return;
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Donau instance `%s' not found. Creating new instance.\n", url);
+
+ // Create a new Donau instance dynamically
+ d = GNUNET_new(struct Donau);
+ d->donau_url = GNUNET_strdup(url);
+ d->keys = NULL;
+ d->conn = NULL;
+ d->retry_task = NULL;
+ d->retry_delay = DONAU_MAXFREQ;
+ d->first_retry = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_ZERO);
+ d->limited = false;
+
+ // Insert the new instance into the linked list
+ GNUNET_CONTAINER_DLL_insert(d_head, d_tail, d);
+
+ // Schedule a keys download for the newly created instance
+ download_keys(d);
}
if (NULL != d->conn)
{
diff --git a/src/backenddb/pg_upsert_donau_keys.c b/src/backenddb/pg_upsert_donau_keys.c
@@ -35,6 +35,10 @@ TMH_PG_upsert_donau_keys (
enum GNUNET_DB_QueryStatus qs;
struct PostgresClosure *pg = cls;
json_t *jkeys = DONAU_keys_to_json(keys);
+
+ if(NULL == jkeys)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+
struct GNUNET_PQ_QueryParam params[] = {
TALER_PQ_query_param_json(jkeys),
GNUNET_PQ_query_param_string(keys->donau_url),
@@ -43,7 +47,7 @@ TMH_PG_upsert_donau_keys (
check_connection(pg);
PREPARE(pg,
- "upsert_donau_keys",
+ "insert_donau_keys",
"INSERT INTO merchant_donau_keys"
"(keys_json"
",donau_url"
@@ -56,11 +60,11 @@ TMH_PG_upsert_donau_keys (
" donau_url=$2;");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "update_exchange_keys",
+ "update_donau_keys",
params);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "upsert_exchange_keys",
+ "insert_donau_keys",
params);
json_decref (jkeys);
return qs;