summaryrefslogtreecommitdiff
path: root/src/exchange
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-23 00:00:32 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-23 00:00:32 +0200
commitc559b1c935a93c4cdec442beeac59264d483c824 (patch)
tree625cf48e047e6534606b5b6b9cd0c15f4c3672dc /src/exchange
parent37f049b3bc98c72f68687e67f102ee5b06f9263d (diff)
downloadexchange-c559b1c935a93c4cdec442beeac59264d483c824.tar.gz
exchange-c559b1c935a93c4cdec442beeac59264d483c824.tar.bz2
exchange-c559b1c935a93c4cdec442beeac59264d483c824.zip
complete implementation of long-polling for reserve status; remove support for multi-threaded exchange httpd
Diffstat (limited to 'src/exchange')
-rw-r--r--src/exchange/Makefile.am5
-rw-r--r--src/exchange/taler-exchange-aggregator.c63
-rw-r--r--src/exchange/taler-exchange-closer.c55
-rw-r--r--src/exchange/taler-exchange-httpd.c554
-rw-r--r--src/exchange/taler-exchange-httpd.h2
-rw-r--r--src/exchange/taler-exchange-httpd_auditors.c5
-rw-r--r--src/exchange/taler-exchange-httpd_db.c17
-rw-r--r--src/exchange/taler-exchange-httpd_db.h4
-rw-r--r--src/exchange/taler-exchange-httpd_deposit.c9
-rw-r--r--src/exchange/taler-exchange-httpd_deposits_get.c3
-rw-r--r--src/exchange/taler-exchange-httpd_keys.c99
-rw-r--r--src/exchange/taler-exchange-httpd_link.c3
-rw-r--r--src/exchange/taler-exchange-httpd_loop.c209
-rw-r--r--src/exchange/taler-exchange-httpd_loop.h60
-rw-r--r--src/exchange/taler-exchange-httpd_management_auditors.c5
-rw-r--r--src/exchange/taler-exchange-httpd_management_auditors_AP_disable.c4
-rw-r--r--src/exchange/taler-exchange-httpd_management_denominations_HDP_revoke.c1
-rw-r--r--src/exchange/taler-exchange-httpd_management_post_keys.c6
-rw-r--r--src/exchange/taler-exchange-httpd_management_signkey_EP_revoke.c1
-rw-r--r--src/exchange/taler-exchange-httpd_management_wire_disable.c4
-rw-r--r--src/exchange/taler-exchange-httpd_management_wire_enable.c5
-rw-r--r--src/exchange/taler-exchange-httpd_management_wire_fees.c4
-rw-r--r--src/exchange/taler-exchange-httpd_melt.c10
-rw-r--r--src/exchange/taler-exchange-httpd_recoup.c11
-rw-r--r--src/exchange/taler-exchange-httpd_refreshes_reveal.c10
-rw-r--r--src/exchange/taler-exchange-httpd_refund.c5
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_get.c24
-rw-r--r--src/exchange/taler-exchange-httpd_transfers_get.c4
-rw-r--r--src/exchange/taler-exchange-httpd_withdraw.c6
-rw-r--r--src/exchange/taler-exchange-transfer.c46
-rw-r--r--src/exchange/taler-exchange-wirewatch.c35
-rwxr-xr-xsrc/exchange/test_taler_exchange_httpd_restart.sh107
32 files changed, 255 insertions, 1121 deletions
diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am
index 4c1f26dfc..1f53b0123 100644
--- a/src/exchange/Makefile.am
+++ b/src/exchange/Makefile.am
@@ -84,7 +84,6 @@ taler_exchange_httpd_SOURCES = \
taler-exchange-httpd_deposits_get.c taler-exchange-httpd_deposits_get.h \
taler-exchange-httpd_keys.c taler-exchange-httpd_keys.h \
taler-exchange-httpd_link.c taler-exchange-httpd_link.h \
- taler-exchange-httpd_loop.c taler-exchange-httpd_loop.h \
taler-exchange-httpd_management.h \
taler-exchange-httpd_management_auditors.c \
taler-exchange-httpd_management_auditors_AP_disable.c \
@@ -122,7 +121,6 @@ taler_exchange_httpd_LDADD = \
-lgnunetjson \
-ljansson \
-lz \
- -lpthread \
$(XLIB)
# Testcases
@@ -130,8 +128,7 @@ taler_exchange_httpd_LDADD = \
AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
check_SCRIPTS = \
- test_taler_exchange_httpd.sh \
- test_taler_exchange_httpd_restart.sh
+ test_taler_exchange_httpd.sh
if HAVE_EXPENSIVE_TESTS
check_SCRIPTS += \
test_taler_exchange_httpd_afl.sh
diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c
index 5da0a8094..c82b66669 100644
--- a/src/exchange/taler-exchange-aggregator.c
+++ b/src/exchange/taler-exchange-aggregator.c
@@ -90,11 +90,6 @@ struct AggregationUnit
const struct TALER_EXCHANGEDB_AccountInfo *wa;
/**
- * Database session for all of our transactions.
- */
- struct TALER_EXCHANGEDB_Session *session;
-
- /**
* Array of row_ids from the aggregation.
*/
uint64_t additional_rows[TALER_EXCHANGEDB_MATCHING_DEPOSITS_LIMIT];
@@ -355,7 +350,6 @@ deposit_cb (void *cls,
au->total_amount = *amount_with_fee;
au->have_refund = GNUNET_NO;
qs = db_plugin->select_refunds_by_coin (db_plugin->cls,
- au->session,
coin_pub,
&au->merchant_pub,
h_contract_terms,
@@ -444,7 +438,6 @@ deposit_cb (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = db_plugin->get_wire_fee (db_plugin->cls,
- au->session,
au->wa->method,
au->execution_time,
&start_date,
@@ -468,7 +461,6 @@ deposit_cb (void *cls,
TALER_B2S (&au->wtid),
TALER_amount2s (&au->wire_fee));
qs = db_plugin->insert_aggregation_tracking (db_plugin->cls,
- au->session,
&au->wtid,
row_id);
if (qs <= 0)
@@ -480,7 +472,6 @@ deposit_cb (void *cls,
"Aggregator marks deposit %llu as done\n",
(unsigned long long) row_id);
qs = db_plugin->mark_deposit_done (db_plugin->cls,
- au->session,
row_id);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
@@ -535,7 +526,6 @@ aggregate_cb (void *cls,
/* compute contribution of this coin (after fees) */
au->have_refund = GNUNET_NO;
qs = db_plugin->select_refunds_by_coin (db_plugin->cls,
- au->session,
coin_pub,
&au->merchant_pub,
h_contract_terms,
@@ -596,7 +586,6 @@ aggregate_cb (void *cls,
au->additional_rows[au->rows_offset++] = row_id;
/* insert into aggregation tracking table */
qs = db_plugin->insert_aggregation_tracking (db_plugin->cls,
- au->session,
&au->wtid,
row_id);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
@@ -605,7 +594,6 @@ aggregate_cb (void *cls,
return qs;
}
qs = db_plugin->mark_deposit_done (db_plugin->cls,
- au->session,
row_id);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
@@ -622,16 +610,14 @@ aggregate_cb (void *cls,
/**
* Perform a database commit. If it fails, print a warning.
*
- * @param session session to perform the commit for.
* @return status of commit
*/
static enum GNUNET_DB_QueryStatus
-commit_or_warn (struct TALER_EXCHANGEDB_Session *session)
+commit_or_warn (void)
{
enum GNUNET_DB_QueryStatus qs;
- qs = db_plugin->commit (db_plugin->cls,
- session);
+ qs = db_plugin->commit (db_plugin->cls);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
return qs;
GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -652,24 +638,23 @@ static void
run_aggregation (void *cls)
{
struct AggregationUnit au_active;
- struct TALER_EXCHANGEDB_Session *session;
enum GNUNET_DB_QueryStatus qs;
(void) cls;
task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking for ready deposits to aggregate\n");
- if (NULL == (session = db_plugin->get_session (db_plugin->cls)))
+ if (GNUNET_SYSERR ==
+ db_plugin->preflight (db_plugin->cls))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to obtain database session!\n");
+ "Failed to obtain database connection!\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_OK !=
- db_plugin->start_deferred_wire_out (db_plugin->cls,
- session))
+ db_plugin->start_deferred_wire_out (db_plugin->cls))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to start database transaction!\n");
@@ -680,16 +665,13 @@ run_aggregation (void *cls)
memset (&au_active,
0,
sizeof (au_active));
- au_active.session = session;
qs = db_plugin->get_ready_deposit (db_plugin->cls,
- session,
&deposit_cb,
&au_active);
if (0 >= qs)
{
cleanup_au (&au_active);
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -729,7 +711,6 @@ run_aggregation (void *cls)
"Found ready deposit for %s, aggregating\n",
TALER_B2S (&au_active.merchant_pub));
qs = db_plugin->iterate_matching_deposits (db_plugin->cls,
- session,
&au_active.h_wire,
&au_active.merchant_pub,
&aggregate_cb,
@@ -741,8 +722,7 @@ run_aggregation (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to execute deposit iteration!\n");
cleanup_au (&au_active);
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
@@ -752,8 +732,7 @@ run_aggregation (void *cls)
/* serializiability issue, try again */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Serialization issue, trying again later!\n");
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
cleanup_au (&au_active);
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_aggregation,
@@ -780,14 +759,12 @@ run_aggregation (void *cls)
TALER_amount2s (&au_active.final_amount));
/* Rollback ongoing transaction, as we will not use the respective
WTID and thus need to remove the tracking data */
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
/* There were results, just the value was too low. Start another
transaction to mark all* of the selected deposits as minor! */
if (GNUNET_OK !=
db_plugin->start (db_plugin->cls,
- session,
"aggregator mark tiny transactions"))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -799,14 +776,12 @@ run_aggregation (void *cls)
}
/* Mark transactions by row_id as minor */
qs = db_plugin->mark_deposit_tiny (db_plugin->cls,
- session,
au_active.row_id);
if (0 <= qs)
{
for (unsigned int i = 0; i<au_active.rows_offset; i++)
{
qs = db_plugin->mark_deposit_tiny (db_plugin->cls,
- session,
au_active.additional_rows[i]);
if (0 > qs)
break;
@@ -816,8 +791,7 @@ run_aggregation (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Serialization issue, trying again later!\n");
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
cleanup_au (&au_active);
/* start again */
GNUNET_assert (NULL == task);
@@ -827,15 +801,14 @@ run_aggregation (void *cls)
}
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
cleanup_au (&au_active);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
}
/* commit */
- (void) commit_or_warn (session);
+ (void) commit_or_warn ();
cleanup_au (&au_active);
/* start again */
@@ -877,7 +850,6 @@ run_aggregation (void *cls)
(unsigned int) buf_size);
/* Commit our intention to execute the wire transfer! */
qs = db_plugin->wire_prepare_data_insert (db_plugin->cls,
- session,
au_active.wa->method,
buf,
buf_size);
@@ -887,7 +859,6 @@ run_aggregation (void *cls)
table constraints */
if (qs >= 0)
qs = db_plugin->store_wire_transfer_out (db_plugin->cls,
- session,
au_active.execution_time,
&au_active.wtid,
au_active.wire,
@@ -899,8 +870,7 @@ run_aggregation (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Serialization issue for prepared wire data; trying again later!\n");
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
/* start again */
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_aggregation,
@@ -910,8 +880,7 @@ run_aggregation (void *cls)
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
/* die hard */
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
@@ -923,7 +892,7 @@ run_aggregation (void *cls)
/* Now we can finally commit the overall transaction, as we are
again consistent if all of this passes. */
- switch (commit_or_warn (session))
+ switch (commit_or_warn ())
{
case GNUNET_DB_STATUS_SOFT_ERROR:
/* try again */
diff --git a/src/exchange/taler-exchange-closer.c b/src/exchange/taler-exchange-closer.c
index 89e439998..926c93554 100644
--- a/src/exchange/taler-exchange-closer.c
+++ b/src/exchange/taler-exchange-closer.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016-2020 Taler Systems SA
+ Copyright (C) 2016-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -174,16 +174,14 @@ parse_wirewatch_config (void)
/**
* Perform a database commit. If it fails, print a warning.
*
- * @param session session to perform the commit for.
* @return status of commit
*/
static enum GNUNET_DB_QueryStatus
-commit_or_warn (struct TALER_EXCHANGEDB_Session *session)
+commit_or_warn (void)
{
enum GNUNET_DB_QueryStatus qs;
- qs = db_plugin->commit (db_plugin->cls,
- session);
+ qs = db_plugin->commit (db_plugin->cls);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
return qs;
GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -195,26 +193,12 @@ commit_or_warn (struct TALER_EXCHANGEDB_Session *session)
/**
- * Closure for #expired_reserve_cb().
- */
-struct ExpiredReserveContext
-{
-
- /**
- * Database session we are using.
- */
- struct TALER_EXCHANGEDB_Session *session;
-
-};
-
-
-/**
* Function called with details about expired reserves.
* We trigger the reserve closure by inserting the respective
* closing record and prewire instructions into the respective
* tables.
*
- * @param cls a `struct ExpiredReserveContext *`
+ * @param cls NULL
* @param reserve_pub public key of the reserve
* @param left amount left in the reserve
* @param account_payto_uri information about the bank account that initially
@@ -229,8 +213,6 @@ expired_reserve_cb (void *cls,
const char *account_payto_uri,
struct GNUNET_TIME_Absolute expiration_date)
{
- struct ExpiredReserveContext *erc = cls;
- struct TALER_EXCHANGEDB_Session *session = erc->session;
struct GNUNET_TIME_Absolute now;
struct TALER_WireTransferIdentifierRawP wtid;
struct TALER_Amount amount_without_fee;
@@ -239,6 +221,7 @@ expired_reserve_cb (void *cls,
enum GNUNET_DB_QueryStatus qs;
const struct TALER_EXCHANGEDB_AccountInfo *wa;
+ (void) cls;
/* NOTE: potential optimization: use custom SQL API to not
fetch this: */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -269,7 +252,6 @@ expired_reserve_cb (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = db_plugin->get_wire_fee (db_plugin->cls,
- session,
wa->method,
expiration_date,
&start_date,
@@ -326,7 +308,6 @@ expired_reserve_cb (void *cls,
sizeof (*reserve_pub)));
if (GNUNET_SYSERR != ret)
qs = db_plugin->insert_reserve_closed (db_plugin->cls,
- session,
reserve_pub,
now,
account_payto_uri,
@@ -356,7 +337,7 @@ expired_reserve_cb (void *cls,
/* Reserve balance was almost zero OR soft error */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Reserve was virtually empty, moving on\n");
- (void) commit_or_warn (session);
+ (void) commit_or_warn ();
return qs;
}
@@ -373,7 +354,6 @@ expired_reserve_cb (void *cls,
&buf_size);
/* Commit our intention to execute the wire transfer! */
qs = db_plugin->wire_prepare_data_insert (db_plugin->cls,
- session,
wa->method,
buf,
buf_size);
@@ -404,17 +384,16 @@ expired_reserve_cb (void *cls,
static void
run_reserve_closures (void *cls)
{
- struct TALER_EXCHANGEDB_Session *session;
enum GNUNET_DB_QueryStatus qs;
- struct ExpiredReserveContext erc;
struct GNUNET_TIME_Absolute now;
(void) cls;
task = NULL;
- if (NULL == (session = db_plugin->get_session (db_plugin->cls)))
+ if (GNUNET_SYSERR ==
+ db_plugin->preflight (db_plugin->cls))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to obtain database session!\n");
+ "Failed to obtain database connection!\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
@@ -422,7 +401,6 @@ run_reserve_closures (void *cls)
if (GNUNET_OK !=
db_plugin->start (db_plugin->cls,
- session,
"aggregator reserve closures"))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -431,30 +409,26 @@ run_reserve_closures (void *cls)
GNUNET_SCHEDULER_shutdown ();
return;
}
- erc.session = session;
now = GNUNET_TIME_absolute_get ();
(void) GNUNET_TIME_round_abs (&now);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking for reserves to close by date %s\n",
GNUNET_STRINGS_absolute_time_to_string (now));
qs = db_plugin->get_expired_reserves (db_plugin->cls,
- session,
now,
&expired_reserve_cb,
- &erc);
+ NULL);
GNUNET_assert (1 >= qs);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
case GNUNET_DB_STATUS_SOFT_ERROR:
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_reserve_closures,
NULL);
@@ -462,8 +436,7 @@ run_reserve_closures (void *cls)
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"No more idle reserves to close, going to sleep.\n");
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
GNUNET_assert (NULL == task);
if (GNUNET_YES == test_mode)
{
@@ -477,7 +450,7 @@ run_reserve_closures (void *cls)
}
return;
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- (void) commit_or_warn (session);
+ (void) commit_or_warn ();
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_reserve_closures,
NULL);
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index c06695e4d..627ac00f9 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -34,7 +34,6 @@
#include "taler-exchange-httpd_deposits_get.h"
#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_link.h"
-#include "taler-exchange-httpd_loop.h"
#include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_melt.h"
#include "taler-exchange-httpd_mhd.h"
@@ -53,7 +52,7 @@
/**
* Backlog for listen operation on unix domain sockets.
*/
-#define UNIX_BACKLOG 500
+#define UNIX_BACKLOG 50
/**
@@ -67,7 +66,7 @@ int TEH_allow_keys_timetravel;
/**
* The exchange's configuration (global)
*/
-struct GNUNET_CONFIGURATION_Handle *TEH_cfg;
+const struct GNUNET_CONFIGURATION_Handle *TEH_cfg;
/**
* How long is caching /keys allowed at most? (global)
@@ -101,16 +100,14 @@ char *TEH_currency;
static unsigned int connection_timeout = 30;
/**
- * How many threads to use.
- * The default value (0) sets the actual number of threads
- * based on the number of available cores.
+ * -C command-line flag given?
*/
-static unsigned int num_threads = 0;
+static int connection_close;
/**
- * The HTTP Daemon.
+ * Value to return from main()
*/
-static struct MHD_Daemon *mhd;
+static int global_ret;
/**
* Port to run the daemon on.
@@ -118,17 +115,6 @@ static struct MHD_Daemon *mhd;
static uint16_t serve_port;
/**
- * Path for the unix domain-socket
- * to run the daemon on.
- */
-static char *serve_unixpath;
-
-/**
- * File mode for unix-domain socket.
- */
-static mode_t unixpath_mode;
-
-/**
* Counter for the number of requests this HTTP has processed so far.
*/
static unsigned long long req_count;
@@ -302,11 +288,8 @@ handle_mhd_completion_callback (void *cls,
TALER_MHD_parse_post_cleanup_callback (rc->opaque_post_parsing_context);
/* Sanity-check that we didn't leave any transactions hanging */
- /* NOTE: In high-performance production, we could consider
- removing this as it should not be needed and might be costly
- (to be benchmarked). */
- TEH_plugin->preflight (TEH_plugin->cls,
- TEH_plugin->get_session (TEH_plugin->cls));
+ GNUNET_break (GNUNET_OK ==
+ TEH_plugin->preflight (TEH_plugin->cls));
GNUNET_free (rc);
*con_cls = NULL;
GNUNET_async_scope_restore (&old_scope);
@@ -1179,18 +1162,6 @@ exchange_serve_process_config (void)
"Failed to initialize DB subsystem\n");
return GNUNET_SYSERR;
}
-
- if (GNUNET_OK !=
- TALER_MHD_parse_config (TEH_cfg,
- "exchange",
- &serve_port,
- &serve_unixpath,
- &unixpath_mode))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to setup HTTPd subsystem\n");
- return GNUNET_SYSERR;
- }
return GNUNET_OK;
}
@@ -1248,16 +1219,11 @@ write_stats (void)
/* Developer logic for supporting the `-f' option. */
#if HAVE_DEVELOPER
-
/**
* Option `-f' (specifies an input file to give to the HTTP server).
*/
static char *input_filename;
-/**
- * We finished handling the request and should now terminate.
- */
-static int do_terminate;
/**
* Run 'nc' or 'ncat' as a fake HTTP client using #input_filename
@@ -1277,7 +1243,8 @@ run_fake_client (void)
"-"))
fd = STDIN_FILENO;
else
- fd = open (input_filename, O_RDONLY);
+ fd = open (input_filename,
+ O_RDONLY);
if (-1 == fd)
{
fprintf (stderr,
@@ -1325,6 +1292,50 @@ run_fake_client (void)
/**
+ * Run the exchange to serve a single request only, without threads.
+ *
+ * @return #GNUNET_OK on success
+ */
+static void
+run_single_request (void)
+{
+ pid_t xfork;
+
+ xfork = fork ();
+ if (-1 == xfork)
+ {
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (0 == xfork)
+ {
+ pid_t cld;
+
+ cld = run_fake_client ();
+ if (-1 == cld)
+ _exit (EXIT_FAILURE);
+ _exit (EXIT_SUCCESS);
+ }
+
+ {
+ int status;
+
+ if (xfork != waitpid (xfork,
+ &status,
+ 0))
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Waiting for `nc' child failed: %s\n",
+ strerror (errno));
+ }
+}
+
+
+/* end of HAVE_DEVELOPER */
+#endif
+
+
+/**
* Signature of the callback used by MHD to notify the application
* about completed connections. If we are running in test-mode with
* an #input_filename, this function is used to terminate the HTTPD
@@ -1344,240 +1355,138 @@ connection_done (void *cls,
(void) cls;
(void) connection;
(void) socket_context;
+
+#if HAVE_DEVELOPER
/* We only act if the connection is closed. */
if (MHD_CONNECTION_NOTIFY_CLOSED != toe)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Connection done!\n");
- do_terminate = GNUNET_YES;
+ if (NULL != input_filename)
+ GNUNET_SCHEDULER_shutdown ();
+#endif
}
/**
- * Run the exchange to serve a single request only, without threads.
+ * Function run on shutdown.
*
- * @return #GNUNET_OK on success
+ * @param cls NULL
*/
-static int
-run_single_request (void)
+static void
+do_shutdown (void *cls)
{
- pid_t cld;
- int status;
-
- /* run only the testfile input, then terminate */
- mhd
- = MHD_start_daemon (MHD_USE_PIPE_FOR_SHUTDOWN
- | MHD_USE_DEBUG | MHD_USE_DUAL_STACK
- | MHD_USE_TCP_FASTOPEN,
- 0, /* pick free port */
- NULL, NULL,
- &handle_mhd_request, NULL,
- MHD_OPTION_LISTEN_BACKLOG_SIZE, (unsigned int) 10,
- MHD_OPTION_EXTERNAL_LOGGER, &TALER_MHD_handle_logs,
- NULL,
- MHD_OPTION_NOTIFY_COMPLETED,
- &handle_mhd_completion_callback, NULL,
- MHD_OPTION_CONNECTION_TIMEOUT, connection_timeout,
- MHD_OPTION_NOTIFY_CONNECTION, &connection_done, NULL,
- MHD_OPTION_END);
- if (NULL == mhd)
- {
- fprintf (stderr,
- "Failed to start HTTP server.\n");
- return GNUNET_SYSERR;
- }
- serve_port = MHD_get_daemon_info (mhd,
- MHD_DAEMON_INFO_BIND_PORT)->port;
- cld = run_fake_client ();
- if (-1 == cld)
- return GNUNET_SYSERR;
- /* run the event loop until #connection_done() was called */
- while (GNUNET_NO == do_terminate)
- {
- fd_set rs;
- fd_set ws;
- fd_set es;
- struct timeval tv;
- MHD_UNSIGNED_LONG_LONG timeout;
- int maxsock = -1;
- int have_tv;
-
- FD_ZERO (&rs);
- FD_ZERO (&ws);
- FD_ZERO (&es);
- if (MHD_YES !=
- MHD_get_fdset (mhd,
- &rs,
- &ws,
- &es,
- &maxsock))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- have_tv = MHD_get_timeout (mhd,
- &timeout);
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = 1000 * (timeout % 1000);
- if (-1 == select (maxsock + 1,
- &rs,
- &ws,
- &es,
- have_tv ? &tv : NULL))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- MHD_run (mhd);
- }
- {
- MHD_socket sock = MHD_quiesce_daemon (mhd);
+ struct MHD_Daemon *mhd;
+ (void) cls;
- TEH_resume_keys_requests (true);
- TEH_reserves_get_cleanup ();
+ mhd = TALER_MHD_daemon_stop ();
+ TEH_resume_keys_requests (true);
+ TEH_reserves_get_cleanup ();
+ if (NULL != mhd)
MHD_stop_daemon (mhd);
- GNUNET_break (0 == close (sock));
- }
- mhd = NULL;
- if (cld != waitpid (cld,
- &status,
- 0))
- fprintf (stderr,
- "Waiting for `nc' child failed: %s\n",
- strerror (errno));
- return GNUNET_OK;
+ TALER_EXCHANGEDB_plugin_unload (TEH_plugin);
+ TEH_WIRE_done ();
}
-/* end of HAVE_DEVELOPER */
-#endif
-
-
/**
- * Run the ordinary multi-threaded main loop and the logic to
- * wait for CTRL-C.
+ * Main function that will be run by the scheduler.
*
- * @param fh listen socket
- * @param argv command line arguments
- * @return #GNUNET_OK on success
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be
+ * NULL!)
+ * @param config configuration
*/
-static int
-run_main_loop (int fh,
- char *const *argv)
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *config)
{
- int ret;
-
- GNUNET_assert (0 < num_threads);
-
- mhd
- = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_PIPE_FOR_SHUTDOWN
- | MHD_USE_DEBUG | MHD_USE_DUAL_STACK
- | MHD_USE_INTERNAL_POLLING_THREAD
- | MHD_ALLOW_SUSPEND_RESUME
- | MHD_USE_TCP_FASTOPEN,
- (-1 == fh) ? serve_port : 0,
- NULL, NULL,
- &handle_mhd_request, NULL,
- MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) num_threads,
- MHD_OPTION_LISTEN_BACKLOG_SIZE, (unsigned int) 1024,
- MHD_OPTION_LISTEN_SOCKET, fh,
- MHD_OPTION_EXTERNAL_LOGGER, &TALER_MHD_handle_logs,
- NULL,
- MHD_OPTION_NOTIFY_COMPLETED,
- &handle_mhd_completion_callback, NULL,
- MHD_OPTION_CONNECTION_TIMEOUT, connection_timeout,
- MHD_OPTION_END);
- if (NULL == mhd)
+ enum TALER_MHD_GlobalOptions go;
+ int fh;
+
+ go = TALER_MHD_GO_NONE;
+ if (connection_close)
+ go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE;
+ TALER_MHD_setup (go);
+ TEH_cfg = config;
+
+ if (GNUNET_OK !=
+ exchange_serve_process_config ())
{
- fprintf (stderr,
- "Failed to start HTTP server.\n");
- return GNUNET_SYSERR;
+ global_ret = EXIT_NOTCONFIGURED;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
}
-
- atexit (&write_stats);
- ret = TEH_loop_run ();
- switch (ret)
+ if (GNUNET_OK !=
+ TEH_WIRE_init ())
{
- case GNUNET_OK:
- case GNUNET_SYSERR:
- {
- MHD_socket sock = MHD_quiesce_daemon (mhd);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (GNUNET_OK !=
+ TEH_keys_init ())
+ {
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
- TEH_resume_keys_requests (true);
- TEH_reserves_get_cleanup ();
- MHD_stop_daemon (mhd);
- GNUNET_break (0 == close (sock));
- }
- mhd = NULL;
- break;
- case GNUNET_NO:
+ TEH_load_terms (TEH_cfg);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
+ fh = TALER_MHD_bind (TEH_cfg,
+ "exchange",
+ &serve_port);
+ if ( (0 == serve_port) &&
+ (-1 == fh) )
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ {
+ struct MHD_Daemon *mhd;
+
+ mhd = MHD_start_daemon (MHD_USE_SUSPEND_RESUME
+ | MHD_USE_PIPE_FOR_SHUTDOWN
+ | MHD_USE_DEBUG | MHD_USE_DUAL_STACK
+ | MHD_USE_TCP_FASTOPEN,
+ (-1 == fh) ? serve_port : 0,
+ NULL, NULL,
+ &handle_mhd_request, NULL,
+ MHD_OPTION_LISTEN_BACKLOG_SIZE,
+ (unsigned int) 1024,
+ MHD_OPTION_LISTEN_SOCKET,
+ fh,
+ MHD_OPTION_EXTERNAL_LOGGER,
+ &TALER_MHD_handle_logs,
+ NULL,
+ MHD_OPTION_NOTIFY_COMPLETED,
+ &handle_mhd_completion_callback,
+ NULL,
+ MHD_OPTION_NOTIFY_CONNECTION,
+ &connection_done,
+ NULL,
+ MHD_OPTION_CONNECTION_TIMEOUT,
+ connection_timeout,
+ MHD_OPTION_END);
+ if (NULL == mhd)
{
- MHD_socket sock = MHD_quiesce_daemon (mhd);
- pid_t chld;
- int flags;
-
- /* Set flags to make 'sock' inherited by child */
- flags = fcntl (sock, F_GETFD);
- GNUNET_assert (-1 != flags);
- flags &= ~FD_CLOEXEC;
- GNUNET_assert (-1 != fcntl (sock,
- F_SETFD,
- flags));
- chld = fork ();
- if (-1 == chld)
- {
- /* fork() failed, continue clean up, unhappily */
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "fork");
- }
- if (0 == chld)
- {
- char pids[12];
-
- /* exec another taler-exchange-httpd, passing on the listen socket;
- as in systemd it is expected to be on FD #3 */
- if (3 != dup2 (sock, 3))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "dup2");
- _exit (1);
- }
- /* Tell the child that it is the desired recipient for FD #3 */
- GNUNET_snprintf (pids,
- sizeof (pids),
- "%u",
- getpid ());
- setenv ("LISTEN_PID", pids, 1);
- setenv ("LISTEN_FDS", "1", 1);
- /* Finally, exec the (presumably) more recent exchange binary */
- execvp ("taler-exchange-httpd",
- argv);
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "execvp");
- _exit (1);
- }
- /* we're the original process, handle remaining contextions
- before exiting; as the listen socket is no longer used,
- close it here */
- GNUNET_break (0 == close (sock));
- while (0 != MHD_get_daemon_info (mhd,
- MHD_DAEMON_INFO_CURRENT_CONNECTIONS)->
- num_connections)
- sleep (1);
- /* Now we're really done, practice clean shutdown */
- TEH_resume_keys_requests (true);
- TEH_reserves_get_cleanup ();
- MHD_stop_daemon (mhd);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to launch HTTP service. Is the port in use?\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
}
- break;
- default:
- GNUNET_break (0);
- TEH_resume_keys_requests (true);
- MHD_stop_daemon (mhd);
- break;
+ global_ret = EXIT_SUCCESS;
+ TALER_MHD_daemon_start (mhd);
}
+ atexit (&write_stats);
- return ret;
+#if HAVE_DEVELOPER
+ if (NULL != input_filename)
+ run_single_request ();
+#endif
}
@@ -1592,10 +1501,6 @@ int
main (int argc,
char *const *argv)
{
- char *cfgfile = NULL;
- char *loglev = NULL;
- char *logfile = NULL;
- int connection_close = GNUNET_NO;
const struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_option_flag ('a',
"allow-timetravel",
@@ -1605,7 +1510,6 @@ main (int argc,
"connection-close",
"force HTTP connections to be closed after each request",
&connection_close),
- GNUNET_GETOPT_option_cfgfile (&cfgfile),
GNUNET_GETOPT_option_uint ('t',
"timeout",
"SECONDS",
@@ -1613,11 +1517,6 @@ main (int argc,
&connection_timeout),
GNUNET_GETOPT_option_timetravel ('T',
"timetravel"),
- GNUNET_GETOPT_option_uint ('n',
- "num-threads",
- "NUM_THREADS",
- "size of the thread pool",
- &num_threads),
#if HAVE_DEVELOPER
GNUNET_GETOPT_option_filename ('f',
"file-input",
@@ -1627,141 +1526,22 @@ main (int argc,
#endif
GNUNET_GETOPT_option_help (
"HTTP server providing a RESTful API to access a Taler exchange"),
- GNUNET_GETOPT_option_loglevel (&loglev),
- GNUNET_GETOPT_option_logfile (&logfile),
GNUNET_GETOPT_option_version (VERSION "-" VCS_VERSION),
GNUNET_GETOPT_OPTION_END
};
- int ret;
- const char *listen_pid;
- const char *listen_fds;
- int fh = -1;
- enum TALER_MHD_GlobalOptions go;
+ enum GNUNET_GenericReturnValue ret;
TALER_OS_init ();
- ret = GNUNET_GETOPT_run ("taler-exchange-httpd",
- options,
- argc, argv);
+ ret = GNUNET_PROGRAM_run (argc, argv,
+ "taler-exchange-httpd",
+ "Taler exchange HTTP service",
+ options,
+ &run, NULL);
if (GNUNET_SYSERR == ret)
return EXIT_INVALIDARGUMENT;
if (GNUNET_NO == ret)
return EXIT_SUCCESS;
- if (0 == num_threads)
- {
- cpu_set_t mask;
- GNUNET_assert (0 ==
- sched_getaffinity (0,
- sizeof (cpu_set_t),
- &mask));
- num_threads = CPU_COUNT (&mask);
- }
- go = TALER_MHD_GO_NONE;
- if (connection_close)
- go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE;
- TALER_MHD_setup (go);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_log_setup ("taler-exchange-httpd",
- (NULL == loglev) ? "INFO" : loglev,
- logfile));
- GNUNET_free (loglev);
- GNUNET_free (logfile);
- if (NULL == cfgfile)
- cfgfile = GNUNET_CONFIGURATION_default_filename ();
- if (NULL == cfgfile)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Can't find default configuration file.\n");
- return EXIT_NOTCONFIGURED;
- }
-
- TEH_cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (TEH_cfg,
- cfgfile))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed configuration file `%s', exit ...\n",
- cfgfile);
- GNUNET_free (cfgfile);
- return EXIT_NOTCONFIGURED;
- }
- GNUNET_free (cfgfile);
- if (GNUNET_OK !=
- exchange_serve_process_config ())
- return EXIT_NOTCONFIGURED;
- TEH_load_terms (TEH_cfg);
-
- /* check for systemd-style FD passing */
- listen_pid = getenv ("LISTEN_PID");
- listen_fds = getenv ("LISTEN_FDS");
- if ( (NULL != listen_pid) &&
- (NULL != listen_fds) &&
- (getpid () == strtol (listen_pid,
- NULL,
- 10)) &&
- (1 == strtoul (listen_fds,
- NULL,
- 10)) )
- {
- int flags;
-
- fh = 3;
- flags = fcntl (fh,
- F_GETFD);
- if ( (-1 == flags) &&
- (EBADF == errno) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Bad listen socket passed, ignored\n");
- fh = -1;
- }
- flags |= FD_CLOEXEC;
- if ( (-1 != fh) &&
- (0 != fcntl (fh,
- F_SETFD,
- flags)) )
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "fcntl");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Successfully obtained listen socket from hypervisor\n");
- }
-
- /* initialize #internal_key_state with an RC of 1 */
- if (GNUNET_OK !=
- TEH_WIRE_init ())
- return EXIT_FAILURE;
- if (GNUNET_OK !=
- TEH_keys_init ())
- return EXIT_FAILURE;
- ret = TEH_loop_init ();
- if (GNUNET_OK == ret)
- {
-#if HAVE_DEVELOPER
- if (NULL != input_filename)
- {
- ret = run_single_request ();
- }
- else
-#endif
- {
- /* consider unix path */
- if ( (-1 == fh) &&
- (NULL != serve_unixpath) )
- {
- fh = TALER_MHD_open_unix_path (serve_unixpath,
- unixpath_mode);
- if (-1 == fh)
- return EXIT_NOPERMISSION; /* at least most likely */
- }
- ret = run_main_loop (fh,
- argv);
- }
- /* release signal handlers */
- TEH_loop_done ();
- }
- TALER_EXCHANGEDB_plugin_unload (TEH_plugin);
- TEH_WIRE_done ();
- return (GNUNET_SYSERR == ret) ? EXIT_FAILURE : EXIT_SUCCESS;
+ return global_ret;
}
diff --git a/src/exchange/taler-exchange-httpd.h b/src/exchange/taler-exchange-httpd.h
index eaecc9720..e43426488 100644
--- a/src/exchange/taler-exchange-httpd.h
+++ b/src/exchange/taler-exchange-httpd.h
@@ -42,7 +42,7 @@ extern struct GNUNET_TIME_Relative TEH_reserve_closing_delay;
/**
* The exchange's configuration.
*/
-extern struct GNUNET_CONFIGURATION_Handle *TEH_cfg;
+extern const struct GNUNET_CONFIGURATION_Handle *TEH_cfg;
/**
* Main directory with exchange data.
diff --git a/src/exchange/taler-exchange-httpd_auditors.c b/src/exchange/taler-exchange-httpd_auditors.c
index f3c061e39..34e640ad7 100644
--- a/src/exchange/taler-exchange-httpd_auditors.c
+++ b/src/exchange/taler-exchange-httpd_auditors.c
@@ -65,7 +65,6 @@ struct AddAuditorDenomContext
*
* @param cls closure with a `struct AddAuditorDenomContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -73,7 +72,6 @@ struct AddAuditorDenomContext
static enum GNUNET_DB_QueryStatus
add_auditor_denom_sig (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct AddAuditorDenomContext *awc = cls;
@@ -84,7 +82,6 @@ add_auditor_denom_sig (void *cls,
qs = TEH_plugin->lookup_denomination_key (
TEH_plugin->cls,
- session,
awc->h_denom_pub,
&meta);
if (qs < 0)
@@ -110,7 +107,6 @@ add_auditor_denom_sig (void *cls,
qs = TEH_plugin->lookup_auditor_status (
TEH_plugin->cls,
- session,
awc->auditor_pub,
&auditor_url,
&enabled);
@@ -174,7 +170,6 @@ add_auditor_denom_sig (void *cls,
GNUNET_free (auditor_url);
qs = TEH_plugin->insert_auditor_denom_sig (TEH_plugin->cls,
- session,
awc->h_denom_pub,
awc->auditor_pub,
&awc->auditor_sig);
diff --git a/src/exchange/taler-exchange-httpd_db.c b/src/exchange/taler-exchange-httpd_db.c
index 8574224af..3c6936497 100644
--- a/src/exchange/taler-exchange-httpd_db.c
+++ b/src/exchange/taler-exchange-httpd_db.c
@@ -45,21 +45,18 @@
*
* @param coin the coin to make known
* @param connection MHD request context
- * @param session database session and transaction to use
* @param[out] mhd_ret set to MHD status on error
* @return transaction status, negative on error (@a mhd_ret will be set in this case)
*/
enum GNUNET_DB_QueryStatus
TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
enum TALER_EXCHANGEDB_CoinKnownStatus cks;
/* make sure coin is 'known' in database */
cks = TEH_plugin->ensure_coin_known (TEH_plugin->cls,
- session,
coin);
switch (cks)
{
@@ -85,7 +82,6 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
- session,
&coin->coin_pub,
GNUNET_NO,
&tl);
@@ -135,11 +131,10 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
TEH_DB_TransactionCallback cb,
void *cb_cls)
{
- struct TALER_EXCHANGEDB_Session *session;
-
if (NULL != mhd_ret)
*mhd_ret = -1; /* set to invalid value, to help detect bugs */
- if (NULL == (session = TEH_plugin->get_session (TEH_plugin->cls)))
+ if (GNUNET_OK !=
+ TEH_plugin->preflight (TEH_plugin->cls))
{
GNUNET_break (0);
if (NULL != mhd_ret)
@@ -157,7 +152,6 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
if (GNUNET_OK !=
TEH_plugin->start (TEH_plugin->cls,
- session,
name))
{
GNUNET_break (0);
@@ -170,16 +164,13 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
}
qs = cb (cb_cls,
connection,
- session,
mhd_ret);
if (0 > qs)
- TEH_plugin->rollback (TEH_plugin->cls,
- session);
+ TEH_plugin->rollback (TEH_plugin->cls);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
return GNUNET_SYSERR;
if (0 <= qs)
- qs = TEH_plugin->commit (TEH_plugin->cls,
- session);
+ qs = TEH_plugin->commit (TEH_plugin->cls);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
if (NULL != mhd_ret)
diff --git a/src/exchange/taler-exchange-httpd_db.h b/src/exchange/taler-exchange-httpd_db.h
index 7e73340b7..c115981d3 100644
--- a/src/exchange/taler-exchange-httpd_db.h
+++ b/src/exchange/taler-exchange-httpd_db.h
@@ -31,14 +31,12 @@
*
* @param coin the coin to make known
* @param connection MHD request context
- * @param session database session and transaction to use
* @param[out] mhd_ret set to MHD status on error
* @return transaction status, negative on error (@a mhd_ret will be set in this case)
*/
enum GNUNET_DB_QueryStatus
TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret);
@@ -52,7 +50,6 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
*
* @param cls closure
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -60,7 +57,6 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
typedef enum GNUNET_DB_QueryStatus
(*TEH_DB_TransactionCallback)(void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret);
diff --git a/src/exchange/taler-exchange-httpd_deposit.c b/src/exchange/taler-exchange-httpd_deposit.c
index 5ea48c20c..9c4cfdc7e 100644
--- a/src/exchange/taler-exchange-httpd_deposit.c
+++ b/src/exchange/taler-exchange-httpd_deposit.c
@@ -133,14 +133,12 @@ struct DepositContext
*
* @param cls a `struct DepositContext`
* @param connection MHD request context
- * @param session database session and transaction to use
* @param[out] mhd_ret set to MHD status on error
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
deposit_precheck (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct DepositContext *dc = cls;
@@ -149,7 +147,6 @@ deposit_precheck (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->have_deposit (TEH_plugin->cls,
- session,
deposit,
GNUNET_YES /* check refund deadline */,
&deposit_fee,
@@ -202,14 +199,12 @@ deposit_precheck (void *cls,
*
* @param cls a `struct DepositContext`
* @param connection MHD request context
- * @param session database session and transaction to use
* @param[out] mhd_ret set to MHD status on error
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
deposit_transaction (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct DepositContext *dc = cls;
@@ -220,7 +215,6 @@ deposit_transaction (void *cls,
/* make sure coin is 'known' in database */
qs = TEH_make_coin_known (&deposit->coin,
connection,
- session,
mhd_ret);
if (qs < 0)
return qs;
@@ -230,7 +224,6 @@ deposit_transaction (void *cls,
that we are in the transaction scope. */
qs = deposit_precheck (cls,
connection,
- session,
mhd_ret);
if (qs < 0)
return qs;
@@ -244,7 +237,6 @@ deposit_transaction (void *cls,
struct TALER_EXCHANGEDB_TransactionList *tl;
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
- session,
&deposit->coin.coin_pub,
GNUNET_NO,
&tl);
@@ -292,7 +284,6 @@ deposit_transaction (void *cls,
tl);
}
qs = TEH_plugin->insert_deposit (TEH_plugin->cls,
- session,
dc->exchange_timestamp,
deposit);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
diff --git a/src/exchange/taler-exchange-httpd_deposits_get.c b/src/exchange/taler-exchange-httpd_deposits_get.c
index f32b88b6d..04e2acb02 100644
--- a/src/exchange/taler-exchange-httpd_deposits_get.c
+++ b/src/exchange/taler-exchange-httpd_deposits_get.c
@@ -203,7 +203,6 @@ handle_wtid_data (void *cls,
*
* @param cls closure of type `struct DepositWtidContext *`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -211,14 +210,12 @@ handle_wtid_data (void *cls,
static enum GNUNET_DB_QueryStatus
deposits_get_transaction (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct DepositWtidContext *ctx = cls;
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_transfer_by_deposit (TEH_plugin->cls,
- session,
&ctx->tps->h_contract_terms,
&ctx->tps->h_wire,
&ctx->tps->coin_pub,
diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c
index 216afd7c5..f37aafbd1 100644
--- a/src/exchange/taler-exchange-httpd_keys.c
+++ b/src/exchange/taler-exchange-httpd_keys.c
@@ -19,7 +19,6 @@
* @author Christian Grothoff
*/
#include "platform.h"
-#include <pthread.h>
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd.h"
@@ -339,10 +338,9 @@ struct SuspendedKeysRequests
/**
- * Thread-local. Contains a pointer to `struct TEH_KeyStateHandle` or NULL.
- * Stores the per-thread latest generation of our key state.
+ * Stores the latest generation of our key state.
*/
-static pthread_key_t key_state;
+static struct TEH_KeyStateHandle *key_state;
/**
* Counter incremented whenever we have a reason to re-build the keys because
@@ -351,7 +349,7 @@ static pthread_key_t key_state;
* changes, the variable MUST be volatile. See #TEH_keys_get_state() and
* #TEH_keys_update_states() for uses of this variable.
*/
-static volatile uint64_t key_generation;
+static uint64_t key_generation;
/**
* Head of DLL of suspended /keys requests.
@@ -392,29 +390,11 @@ static struct TALER_SecurityModulePublicKeyP denom_sm_pub;
static struct TALER_SecurityModulePublicKeyP esign_sm_pub;
/**
- * Mutex protecting access to #denom_sm_pub and #esign_sm_pub.
- * (Could be split into two locks if ever needed.)
- */
-static pthread_mutex_t sm_pub_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-/**
- * Mutex protecting access to #skr_head and #skr_tail.
- * (Could be split into two locks if ever needed.)
- */
-static pthread_mutex_t skr_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-/**
* Are we shutting down?
*/
static bool terminating;
/**
- * Did we ever initialize #key_state?
- */
-static bool key_state_available;
-
-
-/**
* Suspend /keys request while we (hopefully) are waiting to be
* provisioned with key material.
*
@@ -427,10 +407,8 @@ suspend_request (struct MHD_Connection *connection)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Suspending /keys request until key material changes\n");
- GNUNET_assert (0 == pthread_mutex_lock (&skr_mutex));
if (terminating)
{
- GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
@@ -452,9 +430,9 @@ suspend_request (struct MHD_Connection *connection)
skr_size--;
skr_connection = skr->connection;
MHD_resume_connection (skr->connection);
+ TALER_MHD_daemon_trigger ();
GNUNET_free (skr);
}
- GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
return MHD_YES;
}
@@ -464,7 +442,6 @@ TEH_resume_keys_requests (bool do_shutdown)
{
struct SuspendedKeysRequests *skr;
- GNUNET_assert (0 == pthread_mutex_lock (&skr_mutex));
if (do_shutdown)
terminating = true;
while (NULL != (skr = skr_head))
@@ -474,9 +451,9 @@ TEH_resume_keys_requests (bool do_shutdown)
skr);
skr_size--;
MHD_resume_connection (skr->connection);
+ TALER_MHD_daemon_trigger ();
GNUNET_free (skr);
}
- GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
}
@@ -510,7 +487,6 @@ clear_response_cache (struct TEH_KeyStateHandle *ksh)
static void
check_denom_sm_pub (const struct TALER_SecurityModulePublicKeyP *sm_pub)
{
- GNUNET_assert (0 == pthread_mutex_lock (&sm_pub_mutex));
if (0 !=
GNUNET_memcmp (sm_pub,
&denom_sm_pub))
@@ -523,7 +499,6 @@ check_denom_sm_pub (const struct TALER_SecurityModulePublicKeyP *sm_pub)
}
denom_sm_pub = *sm_pub; /* TOFU ;-) */
}
- GNUNET_assert (0 == pthread_mutex_unlock (&sm_pub_mutex));
}
@@ -536,7 +511,6 @@ check_denom_sm_pub (const struct TALER_SecurityModulePublicKeyP *sm_pub)
static void
check_esign_sm_pub (const struct TALER_SecurityModulePublicKeyP *sm_pub)
{
- GNUNET_assert (0 == pthread_mutex_lock (&sm_pub_mutex));
if (0 !=
GNUNET_memcmp (sm_pub,
&esign_sm_pub))
@@ -549,7 +523,6 @@ check_esign_sm_pub (const struct TALER_SecurityModulePublicKeyP *sm_pub)
}
esign_sm_pub = *sm_pub; /* TOFU ;-) */
}
- GNUNET_assert (0 == pthread_mutex_unlock (&sm_pub_mutex));
}
@@ -896,38 +869,9 @@ destroy_key_state (struct TEH_KeyStateHandle *ksh,
}
-/**
- * Free all resources associated with @a cls. Called when
- * the respective pthread is destroyed.
- *
- * @param[in] cls a `struct TEH_KeyStateHandle`.
- */
-static void
-destroy_key_state_cb (void *cls)
-{
- struct TEH_KeyStateHandle *ksh = cls;
-
- destroy_key_state (ksh,
- true);
-}
-
-
-/**
- * Initialize keys submodule.
- *
- * @return #GNUNET_OK on success
- */
int
TEH_keys_init ()
{
- if (0 !=
- pthread_key_create (&key_state,
- &destroy_key_state_cb))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- key_state_available = true;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (TEH_cfg,
"exchange",
@@ -949,11 +893,9 @@ TEH_keys_init ()
void __attribute__ ((destructor))
TEH_keys_finished ()
{
- if (key_state_available)
- {
- GNUNET_assert (0 ==
- pthread_key_delete (key_state));
- }
+ if (NULL != key_state)
+ destroy_key_state (key_state,
+ true);
}
@@ -1799,22 +1741,14 @@ get_key_state (bool management_only)
struct TEH_KeyStateHandle *old_ksh;
struct TEH_KeyStateHandle *ksh;
- GNUNET_assert (key_state_available);
- old_ksh = pthread_getspecific (key_state);
+ old_ksh = key_state;
if (NULL == old_ksh)
{
ksh = build_key_state (NULL,
management_only);
if (NULL == ksh)
return NULL;
- if (0 != pthread_setspecific (key_state,
- ksh))
- {
- GNUNET_break (0);
- destroy_key_state (ksh,
- true);
- return NULL;
- }
+ key_state = ksh;
return ksh;
}
if ( (old_ksh->key_generation < key_generation) ||
@@ -1826,15 +1760,7 @@ get_key_state (bool management_only)
(unsigned long long) key_generation);
ksh = build_key_state (old_ksh->helpers,
management_only);
- if (0 != pthread_setspecific (key_state,
- ksh))
- {
- GNUNET_break (0);
- if (NULL != ksh)
- destroy_key_state (ksh,
- false);
- return NULL;
- }
+ key_state = ksh;
old_ksh->helpers = NULL;
destroy_key_state (old_ksh,
false);
@@ -2099,17 +2025,14 @@ TEH_keys_get_handler (struct TEH_RequestContext *rc,
ksh = TEH_keys_get_state ();
if (NULL == ksh)
{
- GNUNET_assert (0 == pthread_mutex_lock (&skr_mutex));
if ( (SKR_LIMIT == skr_size) &&
(rc->connection == skr_connection) )
{
- GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
"too many connections suspended on /keys");
}
- GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
return suspend_request (rc->connection);
}
krd = bsearch (&last_issue_date,
diff --git a/src/exchange/taler-exchange-httpd_link.c b/src/exchange/taler-exchange-httpd_link.c
index bbb027522..75d32e562 100644
--- a/src/exchange/taler-exchange-httpd_link.c
+++ b/src/exchange/taler-exchange-httpd_link.c
@@ -130,7 +130,6 @@ fail:
*
* @param cls closure
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -138,14 +137,12 @@ fail:
static enum GNUNET_DB_QueryStatus
link_transaction (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct HTD_Context *ctx = cls;
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->get_link_data (TEH_plugin->cls,
- session,
&ctx->coin_pub,
&handle_link_data,
ctx);
diff --git a/src/exchange/taler-exchange-httpd_loop.c b/src/exchange/taler-exchange-httpd_loop.c
deleted file mode 100644
index 086fbc874..000000000
--- a/src/exchange/taler-exchange-httpd_loop.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014--2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-exchange-httpd_loop.c
- * @brief management of our main loop
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <pthread.h>
-#include "taler-exchange-httpd_loop.h"
-
-
-/* ************************* Signal logic ************************** */
-
-/**
- * Pipe used for signaling reloading of our key state.
- */
-static int reload_pipe[2] = { -1, -1 };
-
-
-/**
- * Handle a signal, writing relevant signal numbers to the pipe.
- *
- * @param signal_number the signal number
- */
-static void
-handle_signal (int signal_number)
-{
- char c = (char) signal_number; /* never seen a signal_number > 127 on any platform */
-
- (void) ! write (reload_pipe[1],
- &c,
- 1);
- /* While one might like to "handle errors" here, even logging via fprintf()
- isn't safe inside of a signal handler. So there is nothing we safely CAN
- do. OTOH, also very little that can go wrong in practice. Calling _exit()
- on errors might be a possibility, but that might do more harm than good. *///
-}
-
-
-/**
- * Call #handle_signal() to pass the received signal via
- * the control pipe.
- */
-static void
-handle_sigint (void)
-{
- handle_signal (SIGINT);
-}
-
-
-/**
- * Call #handle_signal() to pass the received signal via
- * the control pipe.
- */
-static void
-handle_sigterm (void)
-{
- handle_signal (SIGTERM);
-}
-
-
-/**
- * Call #handle_signal() to pass the received signal via
- * the control pipe.
- */
-static void
-handle_sighup (void)
-{
- handle_signal (SIGHUP);
-}
-
-
-/**
- * Call #handle_signal() to pass the received signal via
- * the control pipe.
- */
-static void
-handle_sigchld (void)
-{
- handle_signal (SIGCHLD);
-}
-
-
-int
-TEH_loop_run (void)
-{
- int ret;
-
- ret = 2;
- while (2 == ret)
- {
- char c;
- ssize_t res;
-
- errno = 0;
- res = read (reload_pipe[0],
- &c,
- 1);
- if ((res < 0) && (EINTR != errno))
- {
- GNUNET_break (0);
- ret = GNUNET_SYSERR;
- break;
- }
- if (EINTR == errno)
- continue;
- switch (c)
- {
- case SIGTERM:
- case SIGINT:
- /* terminate */
- ret = GNUNET_OK;
- break;
- case SIGHUP:
- /* restart updated binary */
- ret = GNUNET_NO;
- break;
-#if HAVE_DEVELOPER
- case SIGCHLD:
- /* running in test-mode, test finished, terminate */
- ret = GNUNET_OK;
- break;
-#endif
- default:
- /* unexpected character */
- GNUNET_break (0);
- break;
- }
- }
- return ret;
-}
-
-
-static struct GNUNET_SIGNAL_Context *sigterm;
-static struct GNUNET_SIGNAL_Context *sigint;
-static struct GNUNET_SIGNAL_Context *sighup;
-static struct GNUNET_SIGNAL_Context *sigchld;
-
-
-int
-TEH_loop_init (void)
-{
- if (0 != pipe (reload_pipe))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
- return GNUNET_SYSERR;
- }
- sigterm = GNUNET_SIGNAL_handler_install (SIGTERM,
- &handle_sigterm);
- sigint = GNUNET_SIGNAL_handler_install (SIGINT,
- &handle_sigint);
- sighup = GNUNET_SIGNAL_handler_install (SIGHUP,
- &handle_sighup);
- sigchld = GNUNET_SIGNAL_handler_install (SIGCHLD,
- &handle_sigchld);
- return GNUNET_OK;
-}
-
-
-void
-TEH_loop_done (void)
-{
- if (NULL != sigterm)
- {
- GNUNET_SIGNAL_handler_uninstall (sigterm);
- sigterm = NULL;
- }
- if (NULL != sigint)
- {
- GNUNET_SIGNAL_handler_uninstall (sigint);
- sigint = NULL;
- }
- if (NULL != sighup)
- {
- GNUNET_SIGNAL_handler_uninstall (sighup);
- sighup = NULL;
- }
- if (NULL != sigchld)
- {
- GNUNET_SIGNAL_handler_uninstall (sigchld);
- sigchld = NULL;
- }
- if (-1 != reload_pipe[0])
- {
- GNUNET_break (0 == close (reload_pipe[0]));
- GNUNET_break (0 == close (reload_pipe[1]));
- reload_pipe[0] = reload_pipe[1] = -1;
- }
-}
-
-
-/* end of taler-exchange-httpd_loop.c */
diff --git a/src/exchange/taler-exchange-httpd_loop.h b/src/exchange/taler-exchange-httpd_loop.h
deleted file mode 100644
index 700f56776..000000000
--- a/src/exchange/taler-exchange-httpd_loop.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file exchange/taler-exchange-httpd_loop.h
- * @brief management of our main loop
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#ifndef TALER_EXCHANGE_HTTPD_LOOP_H
-#define TALER_EXCHANGE_HTTPD_LOOP_H
-
-#include <gnunet/gnunet_util_lib.h>
-#include <microhttpd.h>
-#include "taler-exchange-httpd.h"
-
-
-/**
- * Setup our signal handlers.
- *
- * @return #GNUNET_OK on success
- */
-int
-TEH_loop_init (void);
-
-
-/**
- * Finally, tear down our signal handlers.
- */
-void
-TEH_loop_done (void);
-
-
-/**
- * Read signals from a pipe in a loop, and reload keys from disk if
- * SIGUSR1 is received, terminate if SIGTERM/SIGINT is received, and
- * restart if SIGHUP is received.
- *
- * @return #GNUNET_SYSERR on errors,
- * #GNUNET_OK to terminate normally
- * #GNUNET_NO to restart an update version of the binary
- */
-int
-TEH_loop_run (void);
-
-
-#endif
diff --git a/src/exchange/taler-exchange-httpd_management_auditors.c b/src/exchange/taler-exchange-httpd_management_auditors.c
index 77e7d8657..d782618f1 100644
--- a/src/exchange/taler-exchange-httpd_management_auditors.c
+++ b/src/exchange/taler-exchange-httpd_management_auditors.c
@@ -74,7 +74,6 @@ struct AddAuditorContext
*
* @param cls closure with a `struct AddAuditorContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -82,7 +81,6 @@ struct AddAuditorContext
static enum GNUNET_DB_QueryStatus
add_auditor (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct AddAuditorContext *aac = cls;
@@ -90,7 +88,6 @@ add_auditor (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls,
- session,
&aac->auditor_pub,
&last_date);
if (qs < 0)
@@ -116,14 +113,12 @@ add_auditor (void *cls,
}
if (0 == qs)
qs = TEH_plugin->insert_auditor (TEH_plugin->cls,
- session,
&aac->auditor_pub,
aac->auditor_url,
aac->auditor_name,
aac->validity_start);
else
qs = TEH_plugin->update_auditor (TEH_plugin->cls,
- session,
&aac->auditor_pub,
aac->auditor_url,
aac->auditor_name,
diff --git a/src/exchange/taler-exchange-httpd_management_auditors_AP_disable.c b/src/exchange/taler-exchange-httpd_management_auditors_AP_disable.c
index 382b0f6b4..7bf191f47 100644
--- a/src/exchange/taler-exchange-httpd_management_auditors_AP_disable.c
+++ b/src/exchange/taler-exchange-httpd_management_auditors_AP_disable.c
@@ -65,7 +65,6 @@ struct DelAuditorContext
*
* @param cls closure with a `struct DelAuditorContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -73,7 +72,6 @@ struct DelAuditorContext
static enum GNUNET_DB_QueryStatus
del_auditor (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct DelAuditorContext *dac = cls;
@@ -81,7 +79,6 @@ del_auditor (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls,
- session,
&dac->auditor_pub,
&last_date);
if (qs < 0)
@@ -114,7 +111,6 @@ del_auditor (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR;
}
qs = TEH_plugin->update_auditor (TEH_plugin->cls,
- session,
&dac->auditor_pub,
"", /* auditor URL */
"", /* auditor name */
diff --git a/src/exchange/taler-exchange-httpd_management_denominations_HDP_revoke.c b/src/exchange/taler-exchange-httpd_management_denominations_HDP_revoke.c
index 1a89652e8..6519404df 100644
--- a/src/exchange/taler-exchange-httpd_management_denominations_HDP_revoke.c
+++ b/src/exchange/taler-exchange-httpd_management_denominations_HDP_revoke.c
@@ -70,7 +70,6 @@ TEH_handler_management_denominations_HDP_revoke (
NULL);
}
qs = TEH_plugin->insert_denomination_revocation (TEH_plugin->cls,
- NULL,
h_denom_pub,
&master_sig);
if (qs < 0)
diff --git a/src/exchange/taler-exchange-httpd_management_post_keys.c b/src/exchange/taler-exchange-httpd_management_post_keys.c
index 0e4eb9894..311fff781 100644
--- a/src/exchange/taler-exchange-httpd_management_post_keys.c
+++ b/src/exchange/taler-exchange-httpd_management_post_keys.c
@@ -107,7 +107,6 @@ struct AddKeysContext
*
* @param cls closure with a `struct AddKeysContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -115,7 +114,6 @@ struct AddKeysContext
static enum GNUNET_DB_QueryStatus
add_keys (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct AddKeysContext *akc = cls;
@@ -131,7 +129,6 @@ add_keys (void *cls,
/* For idempotency, check if the key is already active */
qs = TEH_plugin->lookup_denomination_key (
TEH_plugin->cls,
- session,
&akc->d_sigs[i].h_denom_pub,
&meta);
if (qs < 0)
@@ -207,7 +204,6 @@ add_keys (void *cls,
continue; /* skip, already known */
qs = TEH_plugin->add_denomination_key (
TEH_plugin->cls,
- session,
&akc->d_sigs[i].h_denom_pub,
&denom_pub,
&meta,
@@ -239,7 +235,6 @@ add_keys (void *cls,
qs = TEH_plugin->lookup_signing_key (
TEH_plugin->cls,
- session,
&akc->s_sigs[i].exchange_pub,
&meta);
if (qs < 0)
@@ -297,7 +292,6 @@ add_keys (void *cls,
continue; /* skip, already known */
qs = TEH_plugin->activate_signing_key (
TEH_plugin->cls,
- session,
&akc->s_sigs[i].exchange_pub,
&meta,
&akc->s_sigs[i].master_sig);
diff --git a/src/exchange/taler-exchange-httpd_management_signkey_EP_revoke.c b/src/exchange/taler-exchange-httpd_management_signkey_EP_revoke.c
index 273c05d58..0d6317b47 100644
--- a/src/exchange/taler-exchange-httpd_management_signkey_EP_revoke.c
+++ b/src/exchange/taler-exchange-httpd_management_signkey_EP_revoke.c
@@ -69,7 +69,6 @@ TEH_handler_management_signkeys_EP_revoke (
NULL);
}
qs = TEH_plugin->insert_signkey_revocation (TEH_plugin->cls,
- NULL,
exchange_pub,
&master_sig);
if (qs < 0)
diff --git a/src/exchange/taler-exchange-httpd_management_wire_disable.c b/src/exchange/taler-exchange-httpd_management_wire_disable.c
index 3b760ea9f..17bd7273f 100644
--- a/src/exchange/taler-exchange-httpd_management_wire_disable.c
+++ b/src/exchange/taler-exchange-httpd_management_wire_disable.c
@@ -65,7 +65,6 @@ struct DelWireContext
*
* @param cls closure with a `struct DelWireContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -73,7 +72,6 @@ struct DelWireContext
static enum GNUNET_DB_QueryStatus
del_wire (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct DelWireContext *awc = cls;
@@ -81,7 +79,6 @@ del_wire (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_wire_timestamp (TEH_plugin->cls,
- session,
awc->payto_uri,
&last_date);
if (qs < 0)
@@ -114,7 +111,6 @@ del_wire (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR;
}
qs = TEH_plugin->update_wire (TEH_plugin->cls,
- session,
awc->payto_uri,
awc->validity_end,
false);
diff --git a/src/exchange/taler-exchange-httpd_management_wire_enable.c b/src/exchange/taler-exchange-httpd_management_wire_enable.c
index 00c95b05c..4bad41b40 100644
--- a/src/exchange/taler-exchange-httpd_management_wire_enable.c
+++ b/src/exchange/taler-exchange-httpd_management_wire_enable.c
@@ -72,7 +72,6 @@ struct AddWireContext
*
* @param cls closure with a `struct AddWireContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -80,7 +79,6 @@ struct AddWireContext
static enum GNUNET_DB_QueryStatus
add_wire (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct AddWireContext *awc = cls;
@@ -88,7 +86,6 @@ add_wire (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_wire_timestamp (TEH_plugin->cls,
- session,
awc->payto_uri,
&last_date);
if (qs < 0)
@@ -114,13 +111,11 @@ add_wire (void *cls,
}
if (0 == qs)
qs = TEH_plugin->insert_wire (TEH_plugin->cls,
- session,
awc->payto_uri,
awc->validity_start,
&awc->master_sig_wire);
else
qs = TEH_plugin->update_wire (TEH_plugin->cls,
- session,
awc->payto_uri,
awc->validity_start,
true);
diff --git a/src/exchange/taler-exchange-httpd_management_wire_fees.c b/src/exchange/taler-exchange-httpd_management_wire_fees.c
index 5486ff336..4272a2d06 100644
--- a/src/exchange/taler-exchange-httpd_management_wire_fees.c
+++ b/src/exchange/taler-exchange-httpd_management_wire_fees.c
@@ -80,7 +80,6 @@ struct AddFeeContext
*
* @param cls closure with a `struct AddFeeContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -88,7 +87,6 @@ struct AddFeeContext
static enum GNUNET_DB_QueryStatus
add_fee (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct AddFeeContext *afc = cls;
@@ -98,7 +96,6 @@ add_fee (void *cls,
qs = TEH_plugin->lookup_wire_fee_by_time (
TEH_plugin->cls,
- session,
afc->wire_method,
afc->start_time,
afc->end_time,
@@ -142,7 +139,6 @@ add_fee (void *cls,
qs = TEH_plugin->insert_wire_fee (
TEH_plugin->cls,
- session,
afc->wire_method,
afc->start_time,
afc->end_time,
diff --git a/src/exchange/taler-exchange-httpd_melt.c b/src/exchange/taler-exchange-httpd_melt.c
index 071a9c380..af0a0a636 100644
--- a/src/exchange/taler-exchange-httpd_melt.c
+++ b/src/exchange/taler-exchange-httpd_melt.c
@@ -170,14 +170,12 @@ struct MeltContext
* melt operation.
*
* @param connection the connection to send errors to
- * @param session the database connection
* @param[in,out] rmc melt context
* @param[out] mhd_ret status code to return to MHD on hard error
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
refresh_check_melt (struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
struct MeltContext *rmc,
MHD_RESULT *mhd_ret)
{
@@ -191,7 +189,6 @@ refresh_check_melt (struct MHD_Connection *connection,
/* get historic transaction costs of this coin, including recoups as
we might be a zombie coin */
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
- session,
&rmc->refresh_session.coin.coin_pub,
GNUNET_YES,
&tl);
@@ -301,7 +298,6 @@ refresh_check_melt (struct MHD_Connection *connection,
*
* @param cls our `struct MeltContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -309,7 +305,6 @@ refresh_check_melt (struct MHD_Connection *connection,
static enum GNUNET_DB_QueryStatus
melt_transaction (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct MeltContext *rmc = cls;
@@ -321,7 +316,6 @@ melt_transaction (void *cls,
{
qs = TEH_make_coin_known (&rmc->refresh_session.coin,
connection,
- session,
mhd_ret);
if (qs < 0)
return qs;
@@ -329,7 +323,6 @@ melt_transaction (void *cls,
/* Check if we already created a matching refresh_session */
qs = TEH_plugin->get_melt_index (TEH_plugin->cls,
- session,
&rmc->refresh_session.rc,
&noreveal_index);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
@@ -355,7 +348,6 @@ melt_transaction (void *cls,
/* check coin has enough funds remaining on it to cover melt cost */
qs = refresh_check_melt (connection,
- session,
rmc,
mhd_ret);
if (0 > qs)
@@ -367,7 +359,6 @@ melt_transaction (void *cls,
TALER_CNC_KAPPA);
if (0 >=
(qs = TEH_plugin->insert_melt (TEH_plugin->cls,
- session,
&rmc->refresh_session)))
{
if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
@@ -511,7 +502,6 @@ check_for_denomination_key (struct MHD_Connection *connection,
revoked (those must be recouped) */
qs = TEH_plugin->get_coin_denomination (
TEH_plugin->cls,
- NULL,
&rmc->refresh_session.coin.coin_pub,
&denom_hash);
if (0 > qs)
diff --git a/src/exchange/taler-exchange-httpd_recoup.c b/src/exchange/taler-exchange-httpd_recoup.c
index 521b75627..137034a42 100644
--- a/src/exchange/taler-exchange-httpd_recoup.c
+++ b/src/exchange/taler-exchange-httpd_recoup.c
@@ -114,7 +114,6 @@ struct RecoupContext
*
* @param cls the `struct RecoupContext *`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status code
@@ -122,7 +121,6 @@ struct RecoupContext
static enum GNUNET_DB_QueryStatus
recoup_transaction (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct RecoupContext *pc = cls;
@@ -135,7 +133,6 @@ recoup_transaction (void *cls,
/* make sure coin is 'known' in database */
qs = TEH_make_coin_known (pc->coin,
connection,
- session,
mhd_ret);
if (qs < 0)
return qs;
@@ -145,7 +142,6 @@ recoup_transaction (void *cls,
if (pc->refreshed)
{
qs = TEH_plugin->get_old_coin_by_h_blind (TEH_plugin->cls,
- session,
&pc->h_blind,
&pc->target.old_coin_pub);
if (0 > qs)
@@ -164,7 +160,6 @@ recoup_transaction (void *cls,
else
{
qs = TEH_plugin->get_reserve_by_h_blind (TEH_plugin->cls,
- session,
&pc->h_blind,
&pc->target.reserve_pub);
if (0 > qs)
@@ -194,7 +189,6 @@ recoup_transaction (void *cls,
/* Calculate remaining balance, including recoups already applied. */
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
- session,
&pc->coin->coin_pub,
GNUNET_YES,
&tl);
@@ -270,8 +264,7 @@ recoup_transaction (void *cls,
/* Recoup has no effect: coin fully spent! */
enum GNUNET_DB_QueryStatus ret;
- TEH_plugin->rollback (TEH_plugin->cls,
- session);
+ TEH_plugin->rollback (TEH_plugin->cls);
if (GNUNET_NO == existing_recoup_found)
{
/* Refuse: insufficient funds for recoup */
@@ -300,7 +293,6 @@ recoup_transaction (void *cls,
if (pc->refreshed)
{
qs = TEH_plugin->insert_recoup_refresh_request (TEH_plugin->cls,
- session,
pc->coin,
pc->coin_sig,
pc->coin_bks,
@@ -311,7 +303,6 @@ recoup_transaction (void *cls,
else
{
qs = TEH_plugin->insert_recoup_request (TEH_plugin->cls,
- session,
&pc->target.reserve_pub,
pc->coin,
pc->coin_sig,
diff --git a/src/exchange/taler-exchange-httpd_refreshes_reveal.c b/src/exchange/taler-exchange-httpd_refreshes_reveal.c
index dc4bdf0e6..4ca6bd15b 100644
--- a/src/exchange/taler-exchange-httpd_refreshes_reveal.c
+++ b/src/exchange/taler-exchange-httpd_refreshes_reveal.c
@@ -201,7 +201,6 @@ check_exists_cb (void *cls,
*
* @param cls closure of type `struct RevealContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -209,7 +208,6 @@ check_exists_cb (void *cls,
static enum GNUNET_DB_QueryStatus
refreshes_reveal_preflight (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct RevealContext *rctx = cls;
@@ -217,7 +215,6 @@ refreshes_reveal_preflight (void *cls,
/* Try to see if we already have given an answer before. */
qs = TEH_plugin->get_refresh_reveal (TEH_plugin->cls,
- session,
&rctx->rc,
&check_exists_cb,
rctx);
@@ -258,7 +255,6 @@ refreshes_reveal_preflight (void *cls,
*
* @param cls closure of type `struct RevealContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -266,7 +262,6 @@ refreshes_reveal_preflight (void *cls,
static enum GNUNET_DB_QueryStatus
refreshes_reveal_transaction (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct RevealContext *rctx = cls;
@@ -276,7 +271,6 @@ refreshes_reveal_transaction (void *cls,
/* Obtain basic information about the refresh operation and what
gamma we committed to. */
qs = TEH_plugin->get_melt (TEH_plugin->cls,
- session,
&rctx->rc,
&melt);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@@ -441,7 +435,6 @@ refreshes_reveal_transaction (void *cls,
*
* @param cls closure of type `struct RevealContext`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -449,7 +442,6 @@ refreshes_reveal_transaction (void *cls,
static enum GNUNET_DB_QueryStatus
refreshes_reveal_persist (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct RevealContext *rctx = cls;
@@ -470,7 +462,6 @@ refreshes_reveal_persist (void *cls,
rrc->coin_sig = rctx->ev_sigs[i];
}
qs = TEH_plugin->insert_refresh_reveal (TEH_plugin->cls,
- session,
&rctx->rc,
rctx->num_fresh_coins,
rrcs,
@@ -621,7 +612,6 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection,
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
(qs = TEH_plugin->get_melt (TEH_plugin->cls,
- NULL,
&rctx->rc,
&melt)))
{
diff --git a/src/exchange/taler-exchange-httpd_refund.c b/src/exchange/taler-exchange-httpd_refund.c
index 2ea19b7e8..73b4b251b 100644
--- a/src/exchange/taler-exchange-httpd_refund.c
+++ b/src/exchange/taler-exchange-httpd_refund.c
@@ -94,7 +94,6 @@ reply_refund_success (struct MHD_Connection *connection,
*
* @param cls closure with a `const struct TALER_EXCHANGEDB_Refund *`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -102,7 +101,6 @@ reply_refund_success (struct MHD_Connection *connection,
static enum GNUNET_DB_QueryStatus
refund_transaction (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
const struct TALER_EXCHANGEDB_Refund *refund = cls;
@@ -118,7 +116,6 @@ refund_transaction (void *cls,
tl = NULL;
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
- session,
&refund->coin.coin_pub,
GNUNET_NO,
&tl);
@@ -344,7 +341,6 @@ refund_transaction (void *cls,
/* Finally, store new refund data */
qs = TEH_plugin->insert_refund (TEH_plugin->cls,
- session,
refund);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
@@ -407,7 +403,6 @@ verify_and_execute_refund (struct MHD_Connection *connection,
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->get_coin_denomination (TEH_plugin->cls,
- NULL,
&refund->coin.coin_pub,
&denom_hash);
if (0 > qs)
diff --git a/src/exchange/taler-exchange-httpd_reserves_get.c b/src/exchange/taler-exchange-httpd_reserves_get.c
index 04085a0c3..57ab71378 100644
--- a/src/exchange/taler-exchange-httpd_reserves_get.c
+++ b/src/exchange/taler-exchange-httpd_reserves_get.c
@@ -54,7 +54,7 @@ struct ReservePoller
* Subscription for the database event we are
* waiting for.
*/
- struct TALER_EXCHANGEDB_EventHandler *eh;
+ struct GNUNET_DB_EventHandler *eh;
/**
* When will this request time out?
@@ -110,8 +110,11 @@ rp_cleanup (struct TEH_RequestContext *rc)
{
struct ReservePoller *rp = rc->rh_ctx;
+ GNUNET_assert (! rp->suspended);
if (NULL != rp->eh)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Cancelling DB event listening\n");
TEH_plugin->event_listen_cancel (TEH_plugin->cls,
rp->eh);
rp->eh = NULL;
@@ -153,6 +156,7 @@ db_event_cb (void *cls,
rp_tail,
rp);
MHD_resume_connection (rp->connection);
+ TALER_MHD_daemon_trigger ();
GNUNET_async_scope_restore (&old_scope);
}
@@ -218,7 +222,6 @@ struct ReserveHistoryContext
*
* @param cls a `struct ReserveHistoryContext *`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!); unused
* @return transaction status
@@ -226,7 +229,6 @@ struct ReserveHistoryContext
static enum GNUNET_DB_QueryStatus
reserve_history_transaction (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct ReserveHistoryContext *rsc = cls;
@@ -234,7 +236,6 @@ reserve_history_transaction (void *cls,
(void) connection;
(void) mhd_ret;
return TEH_plugin->get_reserve_history (TEH_plugin->cls,
- session,
&rsc->reserve_pub,
&rsc->rh);
}
@@ -247,7 +248,7 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
struct ReserveHistoryContext rsc;
MHD_RESULT mhd_ret;
struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO;
- struct TALER_EXCHANGEDB_EventHandler *eh = NULL;
+ struct GNUNET_DB_EventHandler *eh = NULL;
if (GNUNET_OK !=
GNUNET_STRINGS_string_to_data (args[0],
@@ -288,7 +289,8 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
timeout_ms);
}
}
- if (! GNUNET_TIME_relative_is_zero (timeout))
+ if ( (! GNUNET_TIME_relative_is_zero (timeout)) &&
+ (NULL == rc->rh_ctx) )
{
struct TALER_ReserveEventP rep = {
.header.size = htons (sizeof (rep)),
@@ -296,6 +298,8 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
.reserve_pub = rsc.reserve_pub
};
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting DB event listening\n");
eh = TEH_plugin->event_listen (TEH_plugin->cls,
timeout,
&rep.header,
@@ -309,7 +313,12 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
&mhd_ret,
&reserve_history_transaction,
&rsc))
+ {
+ if (NULL != eh)
+ TEH_plugin->event_listen_cancel (TEH_plugin->cls,
+ eh);
return mhd_ret;
+ }
/* generate proper response */
if (NULL == rsc.rh)
{
@@ -340,6 +349,9 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
MHD_suspend_connection (rc->connection);
return MHD_YES;
}
+ if (NULL != eh)
+ TEH_plugin->event_listen_cancel (TEH_plugin->cls,
+ eh);
mhd_ret = reply_reserve_history_success (rc->connection,
rsc.rh);
TEH_plugin->free_reserve_history (TEH_plugin->cls,
diff --git a/src/exchange/taler-exchange-httpd_transfers_get.c b/src/exchange/taler-exchange-httpd_transfers_get.c
index 9fd343a53..abf0fdbc8 100644
--- a/src/exchange/taler-exchange-httpd_transfers_get.c
+++ b/src/exchange/taler-exchange-httpd_transfers_get.c
@@ -406,7 +406,6 @@ free_ctx (struct WtidTransactionContext *ctx)
*
* @param cls closure
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -414,7 +413,6 @@ free_ctx (struct WtidTransactionContext *ctx)
static enum GNUNET_DB_QueryStatus
get_transfer_deposits (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct WtidTransactionContext *ctx = cls;
@@ -428,7 +426,6 @@ get_transfer_deposits (void *cls,
serialization failure */
free_ctx (ctx);
qs = TEH_plugin->lookup_wire_transfer (TEH_plugin->cls,
- session,
&ctx->wtid,
&handle_deposit_data,
ctx);
@@ -462,7 +459,6 @@ get_transfer_deposits (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR;
}
qs = TEH_plugin->get_wire_fee (TEH_plugin->cls,
- session,
ctx->wire_method,
ctx->exec_time,
&wire_fee_start_date,
diff --git a/src/exchange/taler-exchange-httpd_withdraw.c b/src/exchange/taler-exchange-httpd_withdraw.c
index 7d10bb8e7..d9cba045c 100644
--- a/src/exchange/taler-exchange-httpd_withdraw.c
+++ b/src/exchange/taler-exchange-httpd_withdraw.c
@@ -152,7 +152,6 @@ struct WithdrawContext
*
* @param cls a `struct WithdrawContext *`
* @param connection MHD request which triggered the transaction
- * @param session database session to use
* @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!)
* @return transaction status
@@ -160,7 +159,6 @@ struct WithdrawContext
static enum GNUNET_DB_QueryStatus
withdraw_transaction (void *cls,
struct MHD_Connection *connection,
- struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret)
{
struct WithdrawContext *wc = cls;
@@ -175,7 +173,6 @@ withdraw_transaction (void *cls,
wc->collectable.sig.rsa_signature = NULL;
#endif
qs = TEH_plugin->get_withdraw_info (TEH_plugin->cls,
- session,
&wc->wsrd.h_coin_envelope,
&wc->collectable);
if (0 > qs)
@@ -212,7 +209,6 @@ withdraw_transaction (void *cls,
"Trying to withdraw from reserve: %s\n",
TALER_B2S (&r.pub));
qs = TEH_plugin->reserves_get (TEH_plugin->cls,
- session,
&r);
if (0 > qs)
{
@@ -253,7 +249,6 @@ withdraw_transaction (void *cls,
}
#endif
qs = TEH_plugin->get_reserve_history (TEH_plugin->cls,
- session,
&wc->wsrd.reserve_pub,
&rh);
if (NULL == rh)
@@ -300,7 +295,6 @@ withdraw_transaction (void *cls,
wc->collectable.h_coin_envelope = wc->wsrd.h_coin_envelope;
wc->collectable.reserve_sig = wc->signature;
qs = TEH_plugin->insert_withdraw_info (TEH_plugin->cls,
- session,
&wc->collectable);
if (0 > qs)
{
diff --git a/src/exchange/taler-exchange-transfer.c b/src/exchange/taler-exchange-transfer.c
index 567943437..d6d44eb05 100644
--- a/src/exchange/taler-exchange-transfer.c
+++ b/src/exchange/taler-exchange-transfer.c
@@ -38,11 +38,6 @@ struct WirePrepareData
{
/**
- * Database session for all of our transactions.
- */
- struct TALER_EXCHANGEDB_Session *session;
-
- /**
* Wire execution handle.
*/
struct TALER_BANK_TransferHandle *eh;
@@ -140,8 +135,7 @@ shutdown_task (void *cls)
TALER_BANK_transfer_cancel (wpd->eh);
wpd->eh = NULL;
}
- db_plugin->rollback (db_plugin->cls,
- wpd->session);
+ db_plugin->rollback (db_plugin->cls);
GNUNET_free (wpd);
wpd = NULL;
}
@@ -196,16 +190,14 @@ parse_wirewatch_config (void)
/**
* Perform a database commit. If it fails, print a warning.
*
- * @param session session to perform the commit for.
* @return status of commit
*/
static enum GNUNET_DB_QueryStatus
-commit_or_warn (struct TALER_EXCHANGEDB_Session *session)
+commit_or_warn (void)
{
enum GNUNET_DB_QueryStatus qs;
- qs = db_plugin->commit (db_plugin->cls,
- session);
+ qs = db_plugin->commit (db_plugin->cls);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
return qs;
GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -245,7 +237,6 @@ wire_confirm_cb (void *cls,
uint64_t row_id,
struct GNUNET_TIME_Absolute wire_timestamp)
{
- struct TALER_EXCHANGEDB_Session *session = wpd->session;
enum GNUNET_DB_QueryStatus qs;
(void) cls;
@@ -256,7 +247,6 @@ wire_confirm_cb (void *cls,
{
case MHD_HTTP_OK:
qs = db_plugin->wire_prepare_data_mark_finished (db_plugin->cls,
- session,
wpd->row_id);
/* continued below */
break;
@@ -267,7 +257,6 @@ wire_confirm_cb (void *cls,
http_status_code,
ec);
qs = db_plugin->wire_prepare_data_mark_failed (db_plugin->cls,
- session,
wpd->row_id);
/* continued below */
break;
@@ -276,8 +265,7 @@ wire_confirm_cb (void *cls,
"Wire transaction failed: %u/%d\n",
http_status_code,
ec);
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
GNUNET_free (wpd);
@@ -287,8 +275,7 @@ wire_confirm_cb (void *cls,
if (0 >= qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
{
/* try again */
@@ -307,7 +294,7 @@ wire_confirm_cb (void *cls,
}
GNUNET_free (wpd);
wpd = NULL;
- switch (commit_or_warn (session))
+ switch (commit_or_warn ())
{
case GNUNET_DB_STATUS_SOFT_ERROR:
/* try again */
@@ -362,8 +349,7 @@ wire_prepare_cb (void *cls,
(NULL == buf) )
{
GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls,
- wpd->session);
+ db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_FAILURE;
goto cleanup;
}
@@ -377,8 +363,7 @@ wire_prepare_cb (void *cls,
/* Should really never happen here, as when we get
here the wire account should be in the cache. */
GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls,
- wpd->session);
+ db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_NOTCONFIGURED;
goto cleanup;
}
@@ -392,8 +377,7 @@ wire_prepare_cb (void *cls,
if (NULL == wpd->eh)
{
GNUNET_break (0); /* Irrecoverable */
- db_plugin->rollback (db_plugin->cls,
- wpd->session);
+ db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_FAILURE;
goto cleanup;
}
@@ -415,23 +399,22 @@ static void
run_transfers (void *cls)
{
enum GNUNET_DB_QueryStatus qs;
- struct TALER_EXCHANGEDB_Session *session;
(void) cls;
task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking for pending wire transfers\n");
- if (NULL == (session = db_plugin->get_session (db_plugin->cls)))
+ if (GNUNET_SYSERR ==
+ db_plugin->preflight (db_plugin->cls))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to obtain database session!\n");
+ "Failed to obtain database connection!\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_OK !=
db_plugin->start (db_plugin->cls,
- session,
"aggregator run transfer"))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -441,15 +424,12 @@ run_transfers (void *cls)
return;
}
wpd = GNUNET_new (struct WirePrepareData);
- wpd->session = session;
qs = db_plugin->wire_prepare_data_get (db_plugin->cls,
- session,
&wire_prepare_cb,
NULL);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
return; /* continued via continuation set in #wire_prepare_cb() */
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
GNUNET_free (wpd);
wpd = NULL;
switch (qs)
diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c
index 2993999a8..fb1fde31d 100644
--- a/src/exchange/taler-exchange-wirewatch.c
+++ b/src/exchange/taler-exchange-wirewatch.c
@@ -63,11 +63,6 @@ struct WireAccount
const struct TALER_EXCHANGEDB_AccountInfo *ai;
/**
- * Database session we are using for the current transaction.
- */
- struct TALER_EXCHANGEDB_Session *session;
-
- /**
* Active request for history.
*/
struct TALER_BANK_CreditHistoryHandle *hh;
@@ -355,8 +350,7 @@ find_transfers (void *cls);
static void
handle_soft_error (struct WireAccount *wa)
{
- db_plugin->rollback (db_plugin->cls,
- wa->session);
+ db_plugin->rollback (db_plugin->cls);
if (1 < wa->batch_size)
{
wa->batch_thresh = wa->batch_size;
@@ -386,7 +380,6 @@ do_commit (struct WireAccount *wa)
{
/* shard is complete, mark this as well */
qs = db_plugin->complete_shard (db_plugin->cls,
- wa->session,
wa->job_name,
wa->shard_start,
wa->shard_end);
@@ -394,8 +387,7 @@ do_commit (struct WireAccount *wa)
{
case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls,
- wa->session);
+ db_plugin->rollback (db_plugin->cls);
GNUNET_SCHEDULER_shutdown ();
return;
case GNUNET_DB_STATUS_SOFT_ERROR:
@@ -413,8 +405,7 @@ do_commit (struct WireAccount *wa)
break;
}
}
- qs = db_plugin->commit (db_plugin->cls,
- wa->session);
+ qs = db_plugin->commit (db_plugin->cls);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -432,7 +423,6 @@ do_commit (struct WireAccount *wa)
}
/* transaction success, update #last_row_off */
wa->batch_start = wa->latest_row_off;
- wa->session = NULL; /* should not be needed */
if (wa->batch_size < MAXIMUM_BATCH_SIZE)
{
int delta;
@@ -492,7 +482,6 @@ history_cb (void *cls,
const json_t *json)
{
struct WireAccount *wa = cls;
- struct TALER_EXCHANGEDB_Session *session = wa->session;
enum GNUNET_DB_QueryStatus qs;
(void) json;
@@ -518,8 +507,7 @@ history_cb (void *cls,
"Serial ID %llu not monotonic (got %llu before). Failing!\n",
(unsigned long long) serial_id,
(unsigned long long) wa->latest_row_off);
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
GNUNET_SCHEDULER_shutdown ();
wa->hh = NULL;
return GNUNET_SYSERR;
@@ -547,7 +535,6 @@ history_cb (void *cls,
(Note: this may require changing both the
plugin API as well as modifying how this function is called.) */
qs = db_plugin->reserves_in_insert (db_plugin->cls,
- session,
&details->reserve_pub,
&details->amount,
details->execution_date,
@@ -558,8 +545,7 @@ history_cb (void *cls,
{
case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
GNUNET_SCHEDULER_shutdown ();
wa->hh = NULL;
return GNUNET_SYSERR;
@@ -590,23 +576,22 @@ history_cb (void *cls,
static void
find_transfers (void *cls)
{
- struct TALER_EXCHANGEDB_Session *session;
enum GNUNET_DB_QueryStatus qs;
unsigned int limit;
(void) cls;
task = NULL;
- if (NULL == (session = db_plugin->get_session (db_plugin->cls)))
+ if (GNUNET_SYSERR ==
+ db_plugin->preflight (db_plugin->cls))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to obtain database session!\n");
+ "Failed to obtain database connection!\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
}
wa_pos->delay = true;
wa_pos->current_batch_size = 0; /* reset counter */
- wa_pos->session = session;
if (wa_pos->shard_end <= wa_pos->batch_start)
{
uint64_t start;
@@ -662,7 +647,6 @@ find_transfers (void *cls)
}
if (GNUNET_OK !=
db_plugin->start_read_committed (db_plugin->cls,
- session,
"wirewatch check for incoming wire transfers"))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -689,8 +673,7 @@ find_transfers (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to start request for account history!\n");
- db_plugin->rollback (db_plugin->cls,
- session);
+ db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
diff --git a/src/exchange/test_taler_exchange_httpd_restart.sh b/src/exchange/test_taler_exchange_httpd_restart.sh
deleted file mode 100755
index 26a315bf8..000000000
--- a/src/exchange/test_taler_exchange_httpd_restart.sh
+++ /dev/null
@@ -1,107 +0,0 @@
-#!/bin/bash
-#
-# This file is part of TALER
-# Copyright (C) 2020 Taler Systems SA
-#
-# TALER is free software; you can redistribute it and/or modify it under the
-# terms of the GNU Affero General Public License as published by the Free Software
-# Foundation; either version 3, or (at your option) any later version.
-#
-# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License along with
-# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-#
-#
-# This script launches an exchange (binding to a UNIX domain socket) and then
-# restarts it in various ways (SIGHUP to re-read configuration, and SIGUSR1 to
-# re-spawn a new binary). Basically, the goal is to make sure that the HTTP
-# server survives these less common operations.
-#
-#
-set -eu
-
-# Exit, with status code "skip" (no 'real' failure)
-function exit_skip() {
- echo $1
- exit 77
-}
-
-# Exit, with error message (hard failure)
-function exit_fail() {
- echo $1
- kill `jobs -p` >/dev/null 2>/dev/null || true
- wait
- exit 1
-}
-
-echo -n "Testing for curl"
-curl --version >/dev/null </dev/null || exit_skip " MISSING"
-echo " FOUND"
-
-
-# Clear environment from variables that override config.
-unset XDG_DATA_HOME
-unset XDG_CONFIG_HOME
-#
-echo -n "Launching exchange ..."
-PREFIX=
-# Uncomment this line to run with valgrind...
-# PREFIX="valgrind --trace-children=yes --leak-check=yes --track-fds=yes --error-exitcode=1 --log-file=valgrind.%p"
-
-CONFIG=test_taler_exchange_unix.conf
-
-# Setup database
-taler-exchange-dbinit -c $CONFIG &> /dev/null
-# Run Exchange HTTPD (in background)
-$PREFIX taler-exchange-httpd -c $CONFIG 2> test-exchange.log &
-
-# Where should we be bound to?
-UNIXPATH=`taler-config -c $CONFIG -s exchange -f -o UNIXPATH`
-
-# Give HTTP time to start
-
-for n in `seq 1 100`
-do
- echo -n "."
- sleep 0.1
- OK=1
- curl --unix-socket "${UNIXPATH}" "http://ignored/" >/dev/null 2> /dev/null && break
- OK=0
-done
-if [ 1 != $OK ]
-then
- exit_fail "Failed to launch exchange"
-fi
-echo " DONE"
-
-# Finally run test...
-echo -n "Restarting program ..."
-kill -SIGHUP $!
-sleep 1
-curl --unix-socket "${UNIXPATH}" "http://ignored/" >/dev/null 2> /dev/null || exit_fail "SIGHUP killed HTTP service"
-echo " DONE"
-
-echo -n "Waiting for parent to die ..."
-wait $!
-echo " DONE"
-
-echo -n "Testing child still alive ..."
-curl --unix-socket "${UNIXPATH}" "http://ignored/" >/dev/null 2> /dev/null || exit_fail "SIGHUP killed HTTP service"
-echo " DONE"
-
-
-echo -n "Killing grandchild ..."
-CPID=`ps x | grep taler-exchange-httpd | grep -v grep | awk '{print $1}'`
-kill -TERM $CPID
-while true
-do
- ps x | grep -v grep | grep taler-exchange-httpd > /dev/null || break
- sleep 0.1
-done
-echo " DONE"
-
-# Return status code from exchange for this script
-exit 0