commit 75053ed8d9646b68ddc1704ae6c6683fe1d7734f
parent d9c2e2dbfc1b645380b0afcb24dc1aa04702012e
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 10 Nov 2024 17:34:48 +0100
implement #9203, and fix FTBFS issues from recent payto changes
Diffstat:
13 files changed, 54 insertions(+), 61 deletions(-)
diff --git a/src/authorization/anastasis-helper-authorization-iban.c b/src/authorization/anastasis-helper-authorization-iban.c
@@ -382,21 +382,12 @@ run (void *cls,
(void) cfgfile;
cfg = c;
if (NULL ==
- (db_plugin = ANASTASIS_DB_plugin_load (cfg)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to initialize DB subsystem\n");
- global_ret = EXIT_NOTCONFIGURED;
- return;
- }
- if (GNUNET_OK !=
- db_plugin->connect (db_plugin->cls))
+ (db_plugin = ANASTASIS_DB_plugin_load (cfg,
+ false)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Database not set up. Did you run anastasis-dbinit?\n");
global_ret = EXIT_NOTCONFIGURED;
- ANASTASIS_DB_plugin_unload (db_plugin);
- db_plugin = NULL;
return;
}
if (GNUNET_OK !=
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
@@ -894,7 +894,8 @@ run (void *cls,
}
if (NULL ==
- (db = ANASTASIS_DB_plugin_load (config)))
+ (db = ANASTASIS_DB_plugin_load (config,
+ false)))
{
GNUNET_SCHEDULER_shutdown ();
return;
diff --git a/src/include/anastasis_database_lib.h b/src/include/anastasis_database_lib.h
@@ -29,10 +29,14 @@
* Initialize the plugin.
*
* @param cfg configuration to use
+ * @param skip_preflight true if we should skip the usual
+ * preflight check which assures us that the DB is actually
+ * operational; only anastasis-dbinit should use true here.
* @return NULL on failure
*/
struct ANASTASIS_DatabasePlugin *
-ANASTASIS_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg);
+ANASTASIS_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ bool skip_preflight);
/**
diff --git a/src/stasis/anastasis-dbinit.c b/src/stasis/anastasis-dbinit.c
@@ -55,7 +55,8 @@ run (void *cls,
struct ANASTASIS_DatabasePlugin *plugin;
if (NULL ==
- (plugin = ANASTASIS_DB_plugin_load (cfg)))
+ (plugin = ANASTASIS_DB_plugin_load (cfg,
+ true)))
{
fprintf (stderr,
"Failed to initialize database plugin.\n");
diff --git a/src/stasis/anastasis_db_plugin.c b/src/stasis/anastasis_db_plugin.c
@@ -24,14 +24,9 @@
#include <ltdl.h>
-/**
- * Initialize the plugin.
- *
- * @param cfg configuration to use
- * @return #GNUNET_OK on success
- */
struct ANASTASIS_DatabasePlugin *
-ANASTASIS_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
+ANASTASIS_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ bool skip_preflight)
{
char *plugin_name;
char *lib_name;
@@ -58,15 +53,19 @@ ANASTASIS_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
plugin->library_name = lib_name;
else
lib_name = NULL;
+ if ( (! skip_preflight) &&
+ (GNUNET_OK !=
+ plugin->preflight (plugin->cls)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database not ready. Try running anastasis-dbinit!\n");
+ ANASTASIS_DB_plugin_unload (plugin);
+ return NULL;
+ }
return plugin;
}
-/**
- * Shutdown the plugin.
- *
- * @param plugin the plugin to unload
- */
void
ANASTASIS_DB_plugin_unload (struct ANASTASIS_DatabasePlugin *plugin)
{
diff --git a/src/stasis/plugin_anastasis_postgres.c b/src/stasis/plugin_anastasis_postgres.c
@@ -494,12 +494,10 @@ check_connection (void *cls)
* Connect to the database if the connection does not exist yet.
*
* @param pg the plugin-specific state
- * @param skip_prepare true if we should skip prepared statement setup
* @return #GNUNET_OK on success
*/
static enum GNUNET_GenericReturnValue
-internal_setup (struct PostgresClosure *pg,
- bool skip_prepare)
+internal_setup (struct PostgresClosure *pg)
{
if (NULL == pg->conn)
{
@@ -528,11 +526,12 @@ internal_setup (struct PostgresClosure *pg,
#endif
struct GNUNET_PQ_Context *db_conn;
- db_conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "stasis-postgres",
- NULL,
- es,
- NULL);
+ db_conn = GNUNET_PQ_connect_with_cfg2 (pg->cfg,
+ "stasis-postgres",
+ "statis-",
+ es,
+ NULL,
+ GNUNET_PQ_FLAG_CHECK_CURRENT);
if (NULL == db_conn)
return GNUNET_SYSERR;
pg->conn = db_conn;
@@ -541,8 +540,6 @@ internal_setup (struct PostgresClosure *pg,
GNUNET_PQ_reconnect_if_down (pg->conn);
if (pg->init)
return GNUNET_OK;
- if (skip_prepare)
- return GNUNET_OK;
return prepare_statements (pg);
}
@@ -569,8 +566,7 @@ postgres_preflight (void *cls)
if (! pg->init)
{
if (GNUNET_OK !=
- internal_setup (pg,
- false))
+ internal_setup (pg))
return GNUNET_SYSERR;
}
if (NULL == pg->transaction_name)
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
@@ -88,7 +88,8 @@ run (void *cls)
.purpose.size = htonl (sizeof (usp))
};
- if (NULL == (plugin = ANASTASIS_DB_plugin_load (cfg)))
+ if (NULL == (plugin = ANASTASIS_DB_plugin_load (cfg,
+ true)))
{
result = 77;
return;
diff --git a/src/testing/test_anastasis.c b/src/testing/test_anastasis.c
@@ -59,17 +59,17 @@ static struct TALER_TESTING_Credentials cred;
/**
* Payto URI of the customer (payer).
*/
-static const char *payer_payto;
+static struct TALER_FullPayto payer_payto;
/**
* Payto URI of the exchange (escrow account).
*/
-static const char *exchange_payto;
+static struct TALER_FullPayto exchange_payto;
/**
* Payto URI of the merchant (receiver).
*/
-static const char *merchant_payto;
+static struct TALER_FullPayto merchant_payto;
/**
* Merchant base URL.
@@ -373,14 +373,14 @@ main (int argc,
dir);
}
id_data = ANASTASIS_TESTING_make_id_data_example ("MaxMuster123456789");
- payer_payto =
- "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME
+ payer_payto.full_payto =
+ (char *) "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME
"?receiver-name=62";
- exchange_payto =
- "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME
+ exchange_payto.full_payto =
+ (char *) "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME
"?receiver-name=exchange";
- merchant_payto =
- "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME
+ merchant_payto.full_payto =
+ (char *) "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME
"?receiver-name=merchant";
merchant_url = "http://localhost:8080/";
diff --git a/src/testing/test_anastasis_api.c b/src/testing/test_anastasis_api.c
@@ -59,17 +59,17 @@ static struct TALER_TESTING_Credentials cred;
/**
* Payto URI of the customer (payer).
*/
-static const char *payer_payto;
+static struct TALER_FullPayto payer_payto;
/**
* Payto URI of the exchange (escrow account).
*/
-static const char *exchange_payto;
+static struct TALER_FullPayto exchange_payto;
/**
* Payto URI of the merchant (receiver).
*/
-static const char *merchant_payto;
+static struct TALER_FullPayto merchant_payto;
/**
* Merchant base URL.
@@ -326,14 +326,14 @@ main (int argc,
"%s/.secret",
dir);
}
- payer_payto =
- "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME
+ payer_payto.full_payto =
+ (char *) "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME
"?receiver-name=62";
- exchange_payto =
- "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME
+ exchange_payto.full_payto =
+ (char *) "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME
"?receiver-name=exchange";
- merchant_payto =
- "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME
+ merchant_payto.full_payto =
+ (char *) "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME
"?receiver-name=merchant";
merchant_url = "http://localhost:8080/";
diff --git a/src/testing/testing_api_cmd_truth_challenge.c b/src/testing/testing_api_cmd_truth_challenge.c
@@ -322,7 +322,7 @@ truth_challenge_traits (void *cls,
struct TALER_TESTING_Trait traits[] = {
ANASTASIS_TESTING_make_trait_payment_secret (
&ksls->payment_secret_response),
- TALER_TESTING_make_trait_payto_uri (ksls->pay_uri),
+ TALER_TESTING_make_trait_taler_uri (ksls->pay_uri),
TALER_TESTING_make_trait_order_id (ksls->order_id),
ANASTASIS_TESTING_make_trait_code (ksls->code),
TALER_TESTING_trait_end ()
diff --git a/src/testing/testing_api_cmd_truth_solve.c b/src/testing/testing_api_cmd_truth_solve.c
@@ -353,7 +353,7 @@ truth_solve_traits (void *cls,
struct TALER_TESTING_Trait traits[] = {
ANASTASIS_TESTING_make_trait_payment_secret (
&ksls->payment_secret_response),
- TALER_TESTING_make_trait_payto_uri (ksls->pay_uri),
+ TALER_TESTING_make_trait_taler_uri (ksls->pay_uri),
TALER_TESTING_make_trait_order_id (ksls->order_id),
ANASTASIS_TESTING_make_trait_code (ksls->code),
TALER_TESTING_trait_end ()
diff --git a/src/testing/testing_api_cmd_truth_store.c b/src/testing/testing_api_cmd_truth_store.c
@@ -340,7 +340,7 @@ truth_store_traits (void *cls,
ANASTASIS_TESTING_make_trait_truth_key (&tss->key),
ANASTASIS_TESTING_make_trait_eks (&tss->encrypted_keyshare),
ANASTASIS_TESTING_make_trait_payment_secret (&tss->payment_secret_response),
- TALER_TESTING_make_trait_payto_uri (tss->pay_uri),
+ TALER_TESTING_make_trait_taler_uri (tss->pay_uri),
ANASTASIS_TESTING_make_trait_filename (tss->filename),
TALER_TESTING_trait_end ()
};
diff --git a/src/testing/testing_cmd_challenge_answer.c b/src/testing/testing_cmd_challenge_answer.c
@@ -551,7 +551,7 @@ challenge_create_traits (void *cls,
ANASTASIS_TESTING_make_trait_code (cs->code),
ANASTASIS_TESTING_make_trait_payment_secret (
&cs->payment_order_req),
- TALER_TESTING_make_trait_payto_uri (cs->payment_uri),
+ TALER_TESTING_make_trait_taler_uri (cs->payment_uri),
TALER_TESTING_make_trait_order_id (cs->order_id),
TALER_TESTING_trait_end ()
};