complete implementation of long-polling for reserve status; remove support for multi-threaded exchange httpd

This commit is contained in:
Christian Grothoff 2021-08-23 00:00:32 +02:00
parent 37f049b3bc
commit c559b1c935
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
58 changed files with 1129 additions and 3111 deletions

View File

@ -41,11 +41,6 @@ struct TALER_Amount TALER_ARL_currency_round_unit;
*/ */
const struct GNUNET_CONFIGURATION_Handle *TALER_ARL_cfg; const struct GNUNET_CONFIGURATION_Handle *TALER_ARL_cfg;
/**
* Our session with the #TALER_ARL_edb.
*/
struct TALER_EXCHANGEDB_Session *TALER_ARL_esession;
/** /**
* Handle to access the auditor's database. * Handle to access the auditor's database.
*/ */
@ -213,7 +208,6 @@ TALER_ARL_get_denomination_info_by_hash (
denominations = GNUNET_CONTAINER_multihashmap_create (256, denominations = GNUNET_CONTAINER_multihashmap_create (256,
GNUNET_NO); GNUNET_NO);
qs = TALER_ARL_edb->iterate_denomination_info (TALER_ARL_edb->cls, qs = TALER_ARL_edb->iterate_denomination_info (TALER_ARL_edb->cls,
TALER_ARL_esession,
&add_denomination, &add_denomination,
NULL); NULL);
if (0 > qs) if (0 > qs)
@ -239,7 +233,6 @@ TALER_ARL_get_denomination_info_by_hash (
struct TALER_EXCHANGEDB_DenominationKeyInformationP issue; struct TALER_EXCHANGEDB_DenominationKeyInformationP issue;
qs = TALER_ARL_edb->get_denomination_info (TALER_ARL_edb->cls, qs = TALER_ARL_edb->get_denomination_info (TALER_ARL_edb->cls,
TALER_ARL_esession,
dh, dh,
&issue); &issue);
if (qs <= 0) if (qs <= 0)
@ -324,23 +317,24 @@ transact (TALER_ARL_Analysis analysis,
GNUNET_break (0); GNUNET_break (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
TALER_ARL_edb->preflight (TALER_ARL_edb->cls, if (GNUNET_OK !=
TALER_ARL_esession); TALER_ARL_edb->preflight (TALER_ARL_edb->cls))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
ret = TALER_ARL_edb->start (TALER_ARL_edb->cls, ret = TALER_ARL_edb->start (TALER_ARL_edb->cls,
TALER_ARL_esession,
"auditor"); "auditor");
if (GNUNET_OK != ret) if (GNUNET_OK != ret)
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_ARL_edb->rollback (TALER_ARL_edb->cls, TALER_ARL_edb->rollback (TALER_ARL_edb->cls);
TALER_ARL_esession);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
qs = analysis (analysis_cls); qs = analysis (analysis_cls);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
{ {
qs = TALER_ARL_edb->commit (TALER_ARL_edb->cls, qs = TALER_ARL_edb->commit (TALER_ARL_edb->cls);
TALER_ARL_esession);
if (0 > qs) if (0 > qs)
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@ -367,8 +361,7 @@ transact (TALER_ARL_Analysis analysis,
"Processing failed (or no changes), rolling back transaction\n"); "Processing failed (or no changes), rolling back transaction\n");
TALER_ARL_adb->rollback (TALER_ARL_adb->cls, TALER_ARL_adb->rollback (TALER_ARL_adb->cls,
TALER_ARL_asession); TALER_ARL_asession);
TALER_ARL_edb->rollback (TALER_ARL_edb->cls, TALER_ARL_edb->rollback (TALER_ARL_edb->cls);
TALER_ARL_esession);
} }
switch (qs) switch (qs)
{ {
@ -396,11 +389,11 @@ int
TALER_ARL_setup_sessions_and_run (TALER_ARL_Analysis ana, TALER_ARL_setup_sessions_and_run (TALER_ARL_Analysis ana,
void *ana_cls) void *ana_cls)
{ {
TALER_ARL_esession = TALER_ARL_edb->get_session (TALER_ARL_edb->cls); if (GNUNET_OK !=
if (NULL == TALER_ARL_esession) TALER_ARL_edb->preflight (TALER_ARL_edb->cls))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to initialize exchange session.\n"); "Failed to initialize exchange connection.\n");
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
TALER_ARL_asession = TALER_ARL_adb->get_session (TALER_ARL_adb->cls); TALER_ARL_asession = TALER_ARL_adb->get_session (TALER_ARL_adb->cls);

View File

@ -54,11 +54,6 @@ extern struct TALER_Amount TALER_ARL_currency_round_unit;
*/ */
extern const struct GNUNET_CONFIGURATION_Handle *TALER_ARL_cfg; extern const struct GNUNET_CONFIGURATION_Handle *TALER_ARL_cfg;
/**
* Our session with the #TALER_ARL_edb.
*/
extern struct TALER_EXCHANGEDB_Session *TALER_ARL_esession;
/** /**
* Handle to access the auditor's database. * Handle to access the auditor's database.
*/ */

View File

@ -61,9 +61,9 @@
static int auditor_connection_close; static int auditor_connection_close;
/** /**
* The auditor's configuration (global) * The auditor's configuration.
*/ */
static struct GNUNET_CONFIGURATION_Handle *cfg; static const struct GNUNET_CONFIGURATION_Handle *cfg;
/** /**
* Our DB plugin. * Our DB plugin.
@ -86,187 +86,20 @@ static struct TALER_AuditorPublicKeyP auditor_pub;
static unsigned int connection_timeout = 30; static unsigned int connection_timeout = 30;
/** /**
* The HTTP Daemon. * Return value from main()
*/ */
static struct MHD_Daemon *mhd; static int global_ret;
/** /**
* Port to run the daemon on. * Port to run the daemon on.
*/ */
static uint16_t serve_port; 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;
/** /**
* Our currency. * Our currency.
*/ */
char *TAH_currency; char *TAH_currency;
/**
* 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 = signal_number;
(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);
}
/**
* 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
*/
static int
signal_loop (void)
{
struct GNUNET_SIGNAL_Context *sigterm;
struct GNUNET_SIGNAL_Context *sigint;
struct GNUNET_SIGNAL_Context *sighup;
struct GNUNET_SIGNAL_Context *sigchld;
int ret;
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);
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)
{
/* ignore, do the loop again */
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;
}
}
GNUNET_SIGNAL_handler_uninstall (sigterm);
GNUNET_SIGNAL_handler_uninstall (sigint);
GNUNET_SIGNAL_handler_uninstall (sighup);
GNUNET_SIGNAL_handler_uninstall (sigchld);
GNUNET_break (0 == close (reload_pipe[0]));
GNUNET_break (0 == close (reload_pipe[1]));
return ret;
}
/** /**
* Function called whenever MHD is done with a request. If the * Function called whenever MHD is done with a request. If the
@ -435,7 +268,7 @@ handle_mhd_request (void *cls,
* *
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
static int static enum GNUNET_GenericReturnValue
auditor_serve_process_config (void) auditor_serve_process_config (void)
{ {
if (NULL == if (NULL ==
@ -452,13 +285,11 @@ auditor_serve_process_config (void)
"Failed to initialize DB subsystem to query exchange database\n"); "Failed to initialize DB subsystem to query exchange database\n");
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (GNUNET_OK != if (GNUNET_SYSERR ==
TALER_MHD_parse_config (cfg, TAH_eplugin->preflight (TAH_eplugin->cls))
"auditor",
&serve_port,
&serve_unixpath,
&unixpath_mode))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to initialize DB subsystem to query exchange database\n");
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (GNUNET_OK != if (GNUNET_OK !=
@ -533,6 +364,113 @@ auditor_serve_process_config (void)
} }
/**
* Function run on shutdown.
*
* @param cls NULL
*/
static void
do_shutdown (void *cls)
{
struct MHD_Daemon *mhd;
(void) cls;
mhd = TALER_MHD_daemon_stop ();
TEAH_DEPOSIT_CONFIRMATION_done ();
if (NULL != mhd)
MHD_stop_daemon (mhd);
if (NULL != TAH_plugin)
{
TALER_AUDITORDB_plugin_unload (TAH_plugin);
TAH_plugin = NULL;
}
if (NULL != TAH_eplugin)
{
TALER_EXCHANGEDB_plugin_unload (TAH_eplugin);
TAH_eplugin = NULL;
}
}
/**
* Main function that will be run by the scheduler.
*
* @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 void
run (void *cls,
char *const *args,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
enum TALER_MHD_GlobalOptions go;
int fh;
go = TALER_MHD_GO_NONE;
if (auditor_connection_close)
go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE;
TALER_MHD_setup (go);
cfg = config;
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
if (GNUNET_OK !=
auditor_serve_process_config ())
{
global_ret = EXIT_NOTCONFIGURED;
GNUNET_SCHEDULER_shutdown ();
return;
}
TEAH_DEPOSIT_CONFIRMATION_init ();
fh = TALER_MHD_bind (cfg,
"auditor",
&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_CONNECTION_TIMEOUT,
connection_timeout,
MHD_OPTION_END);
if (NULL == mhd)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to launch HTTP service. Is the port in use?\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
global_ret = EXIT_SUCCESS;
TALER_MHD_daemon_start (mhd);
}
}
/** /**
* The main function of the taler-auditor-httpd server ("the auditor"). * The main function of the taler-auditor-httpd server ("the auditor").
* *
@ -544,15 +482,11 @@ int
main (int argc, main (int argc,
char *const *argv) char *const *argv)
{ {
char *cfgfile = NULL;
char *loglev = NULL;
char *logfile = NULL;
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_option_flag ('C', GNUNET_GETOPT_option_flag ('C',
"connection-close", "connection-close",
"force HTTP connections to be closed after each request", "force HTTP connections to be closed after each request",
&auditor_connection_close), &auditor_connection_close),
GNUNET_GETOPT_option_cfgfile (&cfgfile),
GNUNET_GETOPT_option_uint ('t', GNUNET_GETOPT_option_uint ('t',
"timeout", "timeout",
"SECONDS", "SECONDS",
@ -560,207 +494,22 @@ main (int argc,
&connection_timeout), &connection_timeout),
GNUNET_GETOPT_option_help ( GNUNET_GETOPT_option_help (
"HTTP server providing a RESTful API to access a Taler auditor"), "HTTP server providing a RESTful API to access a Taler auditor"),
GNUNET_GETOPT_option_loglevel (&loglev),
GNUNET_GETOPT_option_logfile (&logfile),
GNUNET_GETOPT_option_version (VERSION "-" VCS_VERSION), GNUNET_GETOPT_option_version (VERSION "-" VCS_VERSION),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
}; };
int ret; int ret;
const char *listen_pid;
const char *listen_fds;
int fh = -1;
enum TALER_MHD_GlobalOptions go;
TALER_OS_init (); TALER_OS_init ();
{ ret = GNUNET_PROGRAM_run (argc, argv,
int ret; "taler-auditor-httpd",
"Taler auditor HTTP service",
ret = GNUNET_GETOPT_run ("taler-auditor-httpd", options,
options, &run, NULL);
argc, argv); if (GNUNET_SYSERR == ret)
if (GNUNET_NO == ret) return EXIT_INVALIDARGUMENT;
return EXIT_SUCCESS; if (GNUNET_NO == ret)
if (GNUNET_SYSERR == ret) return EXIT_SUCCESS;
return EXIT_FAILURE; return global_ret;
}
go = TALER_MHD_GO_NONE;
if (auditor_connection_close)
go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE;
TALER_MHD_setup (go);
GNUNET_assert (GNUNET_OK ==
GNUNET_log_setup ("taler-auditor-httpd",
(NULL == loglev) ? "INFO" : loglev,
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;
}
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_load (cfg,
cfgfile))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Malformed configuration file `%s', exiting ...\n",
cfgfile);
GNUNET_free (cfgfile);
return EXIT_NOTCONFIGURED;
}
GNUNET_free (cfgfile);
if (GNUNET_OK !=
auditor_serve_process_config ())
return EXIT_NOTCONFIGURED;
TEAH_DEPOSIT_CONFIRMATION_init ();
/* 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");
}
/* consider unix path */
if ( (-1 == fh) &&
(NULL != serve_unixpath) )
{
fh = TALER_MHD_open_unix_path (serve_unixpath,
unixpath_mode);
if (-1 == fh)
{
TEAH_DEPOSIT_CONFIRMATION_done ();
return EXIT_NOPERMISSION; /* most likely at least */
}
}
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_USE_TCP_FASTOPEN,
(-1 == fh) ? serve_port : 0,
NULL, NULL,
&handle_mhd_request, NULL,
MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) 32,
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)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to start HTTP server.\n");
TEAH_DEPOSIT_CONFIRMATION_done ();
return EXIT_FAILURE;
}
/* normal behavior */
ret = signal_loop ();
switch (ret)
{
case GNUNET_OK:
case GNUNET_SYSERR:
MHD_stop_daemon (mhd);
break;
case GNUNET_NO:
{
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-auditor-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 auditor binary */
execvp ("taler-auditor-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 */
MHD_stop_daemon (mhd);
}
break;
default:
GNUNET_break (0);
MHD_stop_daemon (mhd);
break;
}
TALER_AUDITORDB_plugin_unload (TAH_plugin);
TAH_plugin = NULL;
TALER_EXCHANGEDB_plugin_unload (TAH_eplugin);
TAH_eplugin = NULL;
TEAH_DEPOSIT_CONFIRMATION_done ();
return (GNUNET_SYSERR == ret) ? EXIT_FAILURE : EXIT_SUCCESS;
} }

View File

@ -147,7 +147,6 @@ verify_and_execute_deposit_confirmation (
/* check for revocation */ /* check for revocation */
qs = TAH_eplugin->lookup_signkey_revocation (TAH_eplugin->cls, qs = TAH_eplugin->lookup_signkey_revocation (TAH_eplugin->cls,
NULL,
&es->exchange_pub, &es->exchange_pub,
&master_sig); &master_sig);
if (0 > qs) if (0 > qs)

View File

@ -119,11 +119,6 @@ static struct Table tables[] = {
*/ */
struct InsertContext struct InsertContext
{ {
/**
* Database session to use.
*/
struct TALER_EXCHANGEDB_Session *ds;
/** /**
* Table we are replicating. * Table we are replicating.
*/ */
@ -154,7 +149,6 @@ do_insert (void *cls,
if (0 >= ctx->qs) if (0 >= ctx->qs)
return GNUNET_SYSERR; return GNUNET_SYSERR;
qs = dst->insert_records_by_table (dst->cls, qs = dst->insert_records_by_table (dst->cls,
ctx->ds,
td); td);
if (0 >= qs) if (0 >= qs)
{ {
@ -193,42 +187,34 @@ do_insert (void *cls,
* *
* @return #GNUNET_OK on success, #GNUNET_SYSERR to rollback * @return #GNUNET_OK on success, #GNUNET_SYSERR to rollback
*/ */
static int static enum GNUNET_GenericReturnValue
transact (struct TALER_EXCHANGEDB_Session *ss, transact (void)
struct TALER_EXCHANGEDB_Session *ds)
{ {
struct InsertContext ctx = { struct InsertContext ctx = {
.ds = ds,
.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
}; };
if (0 > if (0 >
src->start (src->cls, src->start (src->cls,
ss,
"lookup src serials")) "lookup src serials"))
return GNUNET_SYSERR; return GNUNET_SYSERR;
for (unsigned int i = 0; ! tables[i].end; i++) for (unsigned int i = 0; ! tables[i].end; i++)
src->lookup_serial_by_table (src->cls, src->lookup_serial_by_table (src->cls,
ss,
tables[i].rt, tables[i].rt,
&tables[i].end_serial); &tables[i].end_serial);
if (0 > if (0 >
src->commit (src->cls, src->commit (src->cls))
ss))
return GNUNET_SYSERR; return GNUNET_SYSERR;
if (GNUNET_OK != if (GNUNET_OK !=
dst->start (src->cls, dst->start (src->cls,
ds,
"lookup dst serials")) "lookup dst serials"))
return GNUNET_SYSERR; return GNUNET_SYSERR;
for (unsigned int i = 0; ! tables[i].end; i++) for (unsigned int i = 0; ! tables[i].end; i++)
dst->lookup_serial_by_table (dst->cls, dst->lookup_serial_by_table (dst->cls,
ds,
tables[i].rt, tables[i].rt,
&tables[i].start_serial); &tables[i].start_serial);
if (0 > if (0 >
dst->commit (dst->cls, dst->commit (dst->cls))
ds))
return GNUNET_SYSERR; return GNUNET_SYSERR;
for (unsigned int i = 0; ! tables[i].end; i++) for (unsigned int i = 0; ! tables[i].end; i++)
{ {
@ -248,16 +234,13 @@ transact (struct TALER_EXCHANGEDB_Session *ss,
if (GNUNET_OK != if (GNUNET_OK !=
src->start (src->cls, src->start (src->cls,
ss,
"copy table (src)")) "copy table (src)"))
return GNUNET_SYSERR; return GNUNET_SYSERR;
if (GNUNET_OK != if (GNUNET_OK !=
dst->start (dst->cls, dst->start (dst->cls,
ds,
"copy table (dst)")) "copy table (dst)"))
return GNUNET_SYSERR; return GNUNET_SYSERR;
qs = src->lookup_records_by_table (src->cls, qs = src->lookup_records_by_table (src->cls,
ss,
table->rt, table->rt,
table->start_serial, table->start_serial,
&do_insert, &do_insert,
@ -290,10 +273,8 @@ transact (struct TALER_EXCHANGEDB_Session *ss,
} }
if (0 == ctx.qs) if (0 == ctx.qs)
return GNUNET_SYSERR; /* insertion failed, maybe record existed? try again */ return GNUNET_SYSERR; /* insertion failed, maybe record existed? try again */
src->rollback (src->cls, src->rollback (src->cls);
ss); qs = dst->commit (dst->cls);
qs = dst->commit (dst->cls,
ds);
if (GNUNET_DB_STATUS_SOFT_ERROR == qs) if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@ -328,35 +309,29 @@ static void
do_sync (void *cls) do_sync (void *cls)
{ {
static struct GNUNET_TIME_Relative delay; static struct GNUNET_TIME_Relative delay;
struct TALER_EXCHANGEDB_Session *ss;
struct TALER_EXCHANGEDB_Session *ds;
sync_task = NULL; sync_task = NULL;
actual_size = 0; actual_size = 0;
ss = src->get_session (src->cls); if (GNUNET_SYSERR ==
if (NULL == ss) src->preflight (src->cls))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to begin transaction with data source. Exiting\n"); "Failed to begin transaction with data source. Exiting\n");
return; return;
} }
ds = dst->get_session (dst->cls); if (GNUNET_SYSERR ==
if (NULL == ds) dst->preflight (dst->cls))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to begin transaction with data destination. Exiting\n"); "Failed to begin transaction with data destination. Exiting\n");
return; return;
} }
if (GNUNET_OK != if (GNUNET_OK != transact ())
transact (ss,
ds))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Transaction failed, rolling back\n"); "Transaction failed, rolling back\n");
src->rollback (src->cls, src->rollback (src->cls);
ss); dst->rollback (dst->cls);
dst->rollback (dst->cls,
ds);
} }
if (0 != global_ret) if (0 != global_ret)
{ {

View File

@ -756,7 +756,6 @@ wire_transfer_information_cb (
/* Obtain coin's transaction history */ /* Obtain coin's transaction history */
qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls, qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls,
TALER_ARL_esession,
coin_pub, coin_pub,
GNUNET_YES, GNUNET_YES,
&tl); &tl);
@ -770,7 +769,6 @@ wire_transfer_information_cb (
return; return;
} }
qs = TALER_ARL_edb->get_known_coin (TALER_ARL_edb->cls, qs = TALER_ARL_edb->get_known_coin (TALER_ARL_edb->cls,
TALER_ARL_esession,
coin_pub, coin_pub,
&coin); &coin);
if (qs <= 0) if (qs <= 0)
@ -946,7 +944,6 @@ get_wire_fee (struct AggregationContext *ac,
wfi = GNUNET_new (struct WireFeeInfo); wfi = GNUNET_new (struct WireFeeInfo);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
TALER_ARL_edb->get_wire_fee (TALER_ARL_edb->cls, TALER_ARL_edb->get_wire_fee (TALER_ARL_edb->cls,
TALER_ARL_esession,
method, method,
timestamp, timestamp,
&wfi->start_date, &wfi->start_date,
@ -1083,7 +1080,6 @@ check_wire_out_cb (void *cls,
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
qs = TALER_ARL_edb->lookup_wire_transfer (TALER_ARL_edb->cls, qs = TALER_ARL_edb->lookup_wire_transfer (TALER_ARL_edb->cls,
TALER_ARL_esession,
wtid, wtid,
&wire_transfer_information_cb, &wire_transfer_information_cb,
&wcc); &wcc);
@ -1258,7 +1254,6 @@ analyze_aggregations (void *cls)
ac.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; ac.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
qs = TALER_ARL_edb->select_wire_out_above_serial_id ( qs = TALER_ARL_edb->select_wire_out_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppa.last_wire_out_serial_id, ppa.last_wire_out_serial_id,
&check_wire_out_cb, &check_wire_out_cb,
&ac); &ac);

View File

@ -476,7 +476,6 @@ check_coin_history (const struct TALER_CoinSpendPublicKeyP *coin_pub,
int have_refund; int have_refund;
qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls, qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls,
TALER_ARL_esession,
coin_pub, coin_pub,
GNUNET_YES, GNUNET_YES,
&tl); &tl);
@ -717,7 +716,6 @@ init_denomination (const struct GNUNET_HashCode *denom_hash,
TALER_amount2s (&ds->denom_balance), TALER_amount2s (&ds->denom_balance),
(unsigned long long) ds->num_issued); (unsigned long long) ds->num_issued);
qs = TALER_ARL_edb->get_denomination_revocation (TALER_ARL_edb->cls, qs = TALER_ARL_edb->get_denomination_revocation (TALER_ARL_edb->cls,
TALER_ARL_esession,
denom_hash, denom_hash,
&msig, &msig,
&rowid); &rowid);
@ -878,7 +876,6 @@ sync_denomination (void *cls,
TALER_amount2s (&ds->denom_balance), TALER_amount2s (&ds->denom_balance),
(unsigned long long) ds->num_issued); (unsigned long long) ds->num_issued);
cnt = TALER_ARL_edb->count_known_coins (TALER_ARL_edb->cls, cnt = TALER_ARL_edb->count_known_coins (TALER_ARL_edb->cls,
TALER_ARL_esession,
denom_hash); denom_hash);
if (0 > cnt) if (0 > cnt)
{ {
@ -1187,7 +1184,6 @@ check_known_coin (const char *operation,
"Checking denomination signature on %s\n", "Checking denomination signature on %s\n",
TALER_B2S (coin_pub)); TALER_B2S (coin_pub));
qs = TALER_ARL_edb->get_known_coin (TALER_ARL_edb->cls, qs = TALER_ARL_edb->get_known_coin (TALER_ARL_edb->cls,
TALER_ARL_esession,
coin_pub, coin_pub,
&ci); &ci);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
@ -1336,7 +1332,6 @@ refresh_session_cb (void *cls,
}; };
qs = TALER_ARL_edb->get_refresh_reveal (TALER_ARL_edb->cls, qs = TALER_ARL_edb->get_refresh_reveal (TALER_ARL_edb->cls,
TALER_ARL_esession,
rc, rc,
&reveal_data_cb, &reveal_data_cb,
&reveal_ctx); &reveal_ctx);
@ -2250,7 +2245,6 @@ check_denomination (
struct TALER_AuditorSignatureP auditor_sig; struct TALER_AuditorSignatureP auditor_sig;
qs = TALER_ARL_edb->select_auditor_denom_sig (TALER_ARL_edb->cls, qs = TALER_ARL_edb->select_auditor_denom_sig (TALER_ARL_edb->cls,
TALER_ARL_esession,
&issue->denom_hash, &issue->denom_hash,
&TALER_ARL_auditor_pub, &TALER_ARL_auditor_pub,
&auditor_sig); &auditor_sig);
@ -2329,7 +2323,6 @@ analyze_coins (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking denominations...\n"); "Checking denominations...\n");
qs = TALER_ARL_edb->iterate_denomination_info (TALER_ARL_edb->cls, qs = TALER_ARL_edb->iterate_denomination_info (TALER_ARL_edb->cls,
TALER_ARL_esession,
&check_denomination, &check_denomination,
NULL); NULL);
if (0 > qs) if (0 > qs)
@ -2389,7 +2382,6 @@ analyze_coins (void *cls)
if (0 > if (0 >
(qs = TALER_ARL_edb->select_withdrawals_above_serial_id ( (qs = TALER_ARL_edb->select_withdrawals_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppc.last_withdraw_serial_id, ppc.last_withdraw_serial_id,
&withdraw_cb, &withdraw_cb,
&cc)) ) &cc)) )
@ -2404,7 +2396,6 @@ analyze_coins (void *cls)
if (0 > if (0 >
(qs = TALER_ARL_edb->select_refunds_above_serial_id ( (qs = TALER_ARL_edb->select_refunds_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppc.last_refund_serial_id, ppc.last_refund_serial_id,
&refund_cb, &refund_cb,
&cc))) &cc)))
@ -2419,7 +2410,6 @@ analyze_coins (void *cls)
if (0 > if (0 >
(qs = TALER_ARL_edb->select_recoup_refresh_above_serial_id ( (qs = TALER_ARL_edb->select_recoup_refresh_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppc.last_recoup_refresh_serial_id, ppc.last_recoup_refresh_serial_id,
&recoup_refresh_cb, &recoup_refresh_cb,
&cc))) &cc)))
@ -2432,7 +2422,6 @@ analyze_coins (void *cls)
if (0 > if (0 >
(qs = TALER_ARL_edb->select_recoup_above_serial_id ( (qs = TALER_ARL_edb->select_recoup_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppc.last_recoup_serial_id, ppc.last_recoup_serial_id,
&recoup_cb, &recoup_cb,
&cc))) &cc)))
@ -2447,7 +2436,6 @@ analyze_coins (void *cls)
if (0 > if (0 >
(qs = TALER_ARL_edb->select_refreshes_above_serial_id ( (qs = TALER_ARL_edb->select_refreshes_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppc.last_melt_serial_id, ppc.last_melt_serial_id,
&refresh_session_cb, &refresh_session_cb,
&cc))) &cc)))
@ -2462,7 +2450,6 @@ analyze_coins (void *cls)
if (0 > if (0 >
(qs = TALER_ARL_edb->select_deposits_above_serial_id ( (qs = TALER_ARL_edb->select_deposits_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppc.last_deposit_serial_id, ppc.last_deposit_serial_id,
&deposit_cb, &deposit_cb,
&cc))) &cc)))

View File

@ -123,7 +123,6 @@ test_dc (void *cls,
struct TALER_Amount deposit_fee; struct TALER_Amount deposit_fee;
qs = TALER_ARL_edb->have_deposit (TALER_ARL_edb->cls, qs = TALER_ARL_edb->have_deposit (TALER_ARL_edb->cls,
TALER_ARL_esession,
&dep, &dep,
GNUNET_NO /* do not check refund deadline */, GNUNET_NO /* do not check refund deadline */,
&deposit_fee, &deposit_fee,

View File

@ -744,7 +744,6 @@ handle_recoup_by_reserve (
if (NULL == rev) if (NULL == rev)
{ {
qs = TALER_ARL_edb->get_denomination_revocation (TALER_ARL_edb->cls, qs = TALER_ARL_edb->get_denomination_revocation (TALER_ARL_edb->cls,
TALER_ARL_esession,
&coin->denom_pub_hash, &coin->denom_pub_hash,
&msig, &msig,
&rev_rowid); &rev_rowid);
@ -882,7 +881,6 @@ get_closing_fee (const char *receiver_account,
method); method);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
TALER_ARL_edb->get_wire_fee (TALER_ARL_edb->cls, TALER_ARL_edb->get_wire_fee (TALER_ARL_edb->cls,
TALER_ARL_esession,
method, method,
atime, atime,
&start_date, &start_date,
@ -1089,7 +1087,6 @@ verify_reserve_balance (void *cls,
reserve.pub = rs->reserve_pub; reserve.pub = rs->reserve_pub;
qs = TALER_ARL_edb->reserves_get (TALER_ARL_edb->cls, qs = TALER_ARL_edb->reserves_get (TALER_ARL_edb->cls,
TALER_ARL_esession,
&reserve); &reserve);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{ {
@ -1377,7 +1374,6 @@ analyze_reserves (void *cls)
qs = TALER_ARL_edb->select_reserves_in_above_serial_id ( qs = TALER_ARL_edb->select_reserves_in_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppr.last_reserve_in_serial_id, ppr.last_reserve_in_serial_id,
&handle_reserve_in, &handle_reserve_in,
&rc); &rc);
@ -1388,7 +1384,6 @@ analyze_reserves (void *cls)
} }
qs = TALER_ARL_edb->select_withdrawals_above_serial_id ( qs = TALER_ARL_edb->select_withdrawals_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppr.last_reserve_out_serial_id, ppr.last_reserve_out_serial_id,
&handle_reserve_out, &handle_reserve_out,
&rc); &rc);
@ -1399,7 +1394,6 @@ analyze_reserves (void *cls)
} }
qs = TALER_ARL_edb->select_recoup_above_serial_id ( qs = TALER_ARL_edb->select_recoup_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppr.last_reserve_recoup_serial_id, ppr.last_reserve_recoup_serial_id,
&handle_recoup_by_reserve, &handle_recoup_by_reserve,
&rc); &rc);
@ -1410,7 +1404,6 @@ analyze_reserves (void *cls)
} }
qs = TALER_ARL_edb->select_reserve_closed_above_serial_id ( qs = TALER_ARL_edb->select_reserve_closed_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppr.last_reserve_close_serial_id, ppr.last_reserve_close_serial_id,
&handle_reserve_closed, &handle_reserve_closed,
&rc); &rc);

View File

@ -665,8 +665,7 @@ commit (enum GNUNET_DB_QueryStatus qs)
"Hard error, not recording progress\n"); "Hard error, not recording progress\n");
TALER_ARL_adb->rollback (TALER_ARL_adb->cls, TALER_ARL_adb->rollback (TALER_ARL_adb->cls,
TALER_ARL_asession); TALER_ARL_asession);
TALER_ARL_edb->rollback (TALER_ARL_edb->cls, TALER_ARL_edb->rollback (TALER_ARL_edb->cls);
TALER_ARL_esession);
return qs; return qs;
} }
for (struct WireAccount *wa = wa_head; for (struct WireAccount *wa = wa_head;
@ -741,8 +740,7 @@ commit (enum GNUNET_DB_QueryStatus qs)
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
{ {
qs = TALER_ARL_edb->commit (TALER_ARL_edb->cls, qs = TALER_ARL_edb->commit (TALER_ARL_edb->cls);
TALER_ARL_esession);
if (0 > qs) if (0 > qs)
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@ -769,8 +767,7 @@ commit (enum GNUNET_DB_QueryStatus qs)
"Processing failed, rolling back transaction\n"); "Processing failed, rolling back transaction\n");
TALER_ARL_adb->rollback (TALER_ARL_adb->cls, TALER_ARL_adb->rollback (TALER_ARL_adb->cls,
TALER_ARL_asession); TALER_ARL_asession);
TALER_ARL_edb->rollback (TALER_ARL_edb->cls, TALER_ARL_edb->rollback (TALER_ARL_edb->cls);
TALER_ARL_esession);
} }
return qs; return qs;
} }
@ -870,7 +867,6 @@ check_for_required_transfers (void)
"Analyzing exchange's unfinished deposits (deadline: %s)\n", "Analyzing exchange's unfinished deposits (deadline: %s)\n",
GNUNET_STRINGS_absolute_time_to_string (next_timestamp)); GNUNET_STRINGS_absolute_time_to_string (next_timestamp));
qs = TALER_ARL_edb->select_deposits_missing_wire (TALER_ARL_edb->cls, qs = TALER_ARL_edb->select_deposits_missing_wire (TALER_ARL_edb->cls,
TALER_ARL_esession,
pp.last_timestamp, pp.last_timestamp,
next_timestamp, next_timestamp,
&wire_missing_cb, &wire_missing_cb,
@ -1267,7 +1263,6 @@ check_exchange_wire_out (struct WireAccount *wa)
wa->ai->section_name); wa->ai->section_name);
qs = TALER_ARL_edb->select_wire_out_above_serial_id_by_account ( qs = TALER_ARL_edb->select_wire_out_above_serial_id_by_account (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
wa->ai->section_name, wa->ai->section_name,
wa->pp.last_wire_out_serial_id, wa->pp.last_wire_out_serial_id,
&wire_out_cb, &wire_out_cb,
@ -1824,7 +1819,6 @@ process_credits (void *cls)
wa->ai->section_name); wa->ai->section_name);
qs = TALER_ARL_edb->select_reserves_in_above_serial_id_by_account ( qs = TALER_ARL_edb->select_reserves_in_above_serial_id_by_account (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
wa->ai->section_name, wa->ai->section_name,
wa->pp.last_reserve_in_serial_id, wa->pp.last_reserve_in_serial_id,
&reserve_in_cb, &reserve_in_cb,
@ -1953,11 +1947,11 @@ reserve_closed_cb (void *cls,
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
begin_transaction (void) begin_transaction (void)
{ {
TALER_ARL_esession = TALER_ARL_edb->get_session (TALER_ARL_edb->cls); if (GNUNET_OK !=
if (NULL == TALER_ARL_esession) TALER_ARL_edb->preflight (TALER_ARL_edb->cls))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to initialize exchange database session.\n"); "Failed to initialize exchange database connection.\n");
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
TALER_ARL_asession = TALER_ARL_adb->get_session (TALER_ARL_adb->cls); TALER_ARL_asession = TALER_ARL_adb->get_session (TALER_ARL_adb->cls);
@ -1974,11 +1968,9 @@ begin_transaction (void)
GNUNET_break (0); GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
TALER_ARL_edb->preflight (TALER_ARL_edb->cls, TALER_ARL_edb->preflight (TALER_ARL_edb->cls);
TALER_ARL_esession);
if (GNUNET_OK != if (GNUNET_OK !=
TALER_ARL_edb->start (TALER_ARL_edb->cls, TALER_ARL_edb->start (TALER_ARL_edb->cls,
TALER_ARL_esession,
"wire auditor")) "wire auditor"))
{ {
GNUNET_break (0); GNUNET_break (0);
@ -2031,7 +2023,6 @@ begin_transaction (void)
qs = TALER_ARL_edb->select_reserve_closed_above_serial_id ( qs = TALER_ARL_edb->select_reserve_closed_above_serial_id (
TALER_ARL_edb->cls, TALER_ARL_edb->cls,
TALER_ARL_esession,
pp.last_reserve_close_uuid, pp.last_reserve_close_uuid,
&reserve_closed_cb, &reserve_closed_cb,
NULL); NULL);

View File

@ -226,7 +226,6 @@ TALER_BANK_admin_add_incoming (
{ {
GNUNET_free (aai); GNUNET_free (aai);
json_decref (admin_obj); json_decref (admin_obj);
GNUNET_break (0);
return NULL; return NULL;
} }
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,

View File

@ -84,7 +84,6 @@ taler_exchange_httpd_SOURCES = \
taler-exchange-httpd_deposits_get.c taler-exchange-httpd_deposits_get.h \ 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_keys.c taler-exchange-httpd_keys.h \
taler-exchange-httpd_link.c taler-exchange-httpd_link.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.h \
taler-exchange-httpd_management_auditors.c \ taler-exchange-httpd_management_auditors.c \
taler-exchange-httpd_management_auditors_AP_disable.c \ taler-exchange-httpd_management_auditors_AP_disable.c \
@ -122,7 +121,6 @@ taler_exchange_httpd_LDADD = \
-lgnunetjson \ -lgnunetjson \
-ljansson \ -ljansson \
-lz \ -lz \
-lpthread \
$(XLIB) $(XLIB)
# Testcases # 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; AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
check_SCRIPTS = \ check_SCRIPTS = \
test_taler_exchange_httpd.sh \ test_taler_exchange_httpd.sh
test_taler_exchange_httpd_restart.sh
if HAVE_EXPENSIVE_TESTS if HAVE_EXPENSIVE_TESTS
check_SCRIPTS += \ check_SCRIPTS += \
test_taler_exchange_httpd_afl.sh test_taler_exchange_httpd_afl.sh

View File

@ -89,11 +89,6 @@ struct AggregationUnit
*/ */
const struct TALER_EXCHANGEDB_AccountInfo *wa; 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. * Array of row_ids from the aggregation.
*/ */
@ -355,7 +350,6 @@ deposit_cb (void *cls,
au->total_amount = *amount_with_fee; au->total_amount = *amount_with_fee;
au->have_refund = GNUNET_NO; au->have_refund = GNUNET_NO;
qs = db_plugin->select_refunds_by_coin (db_plugin->cls, qs = db_plugin->select_refunds_by_coin (db_plugin->cls,
au->session,
coin_pub, coin_pub,
&au->merchant_pub, &au->merchant_pub,
h_contract_terms, h_contract_terms,
@ -444,7 +438,6 @@ deposit_cb (void *cls,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = db_plugin->get_wire_fee (db_plugin->cls, qs = db_plugin->get_wire_fee (db_plugin->cls,
au->session,
au->wa->method, au->wa->method,
au->execution_time, au->execution_time,
&start_date, &start_date,
@ -468,7 +461,6 @@ deposit_cb (void *cls,
TALER_B2S (&au->wtid), TALER_B2S (&au->wtid),
TALER_amount2s (&au->wire_fee)); TALER_amount2s (&au->wire_fee));
qs = db_plugin->insert_aggregation_tracking (db_plugin->cls, qs = db_plugin->insert_aggregation_tracking (db_plugin->cls,
au->session,
&au->wtid, &au->wtid,
row_id); row_id);
if (qs <= 0) if (qs <= 0)
@ -480,7 +472,6 @@ deposit_cb (void *cls,
"Aggregator marks deposit %llu as done\n", "Aggregator marks deposit %llu as done\n",
(unsigned long long) row_id); (unsigned long long) row_id);
qs = db_plugin->mark_deposit_done (db_plugin->cls, qs = db_plugin->mark_deposit_done (db_plugin->cls,
au->session,
row_id); row_id);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{ {
@ -535,7 +526,6 @@ aggregate_cb (void *cls,
/* compute contribution of this coin (after fees) */ /* compute contribution of this coin (after fees) */
au->have_refund = GNUNET_NO; au->have_refund = GNUNET_NO;
qs = db_plugin->select_refunds_by_coin (db_plugin->cls, qs = db_plugin->select_refunds_by_coin (db_plugin->cls,
au->session,
coin_pub, coin_pub,
&au->merchant_pub, &au->merchant_pub,
h_contract_terms, h_contract_terms,
@ -596,7 +586,6 @@ aggregate_cb (void *cls,
au->additional_rows[au->rows_offset++] = row_id; au->additional_rows[au->rows_offset++] = row_id;
/* insert into aggregation tracking table */ /* insert into aggregation tracking table */
qs = db_plugin->insert_aggregation_tracking (db_plugin->cls, qs = db_plugin->insert_aggregation_tracking (db_plugin->cls,
au->session,
&au->wtid, &au->wtid,
row_id); row_id);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
@ -605,7 +594,6 @@ aggregate_cb (void *cls,
return qs; return qs;
} }
qs = db_plugin->mark_deposit_done (db_plugin->cls, qs = db_plugin->mark_deposit_done (db_plugin->cls,
au->session,
row_id); row_id);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) 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. * Perform a database commit. If it fails, print a warning.
* *
* @param session session to perform the commit for.
* @return status of commit * @return status of commit
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
commit_or_warn (struct TALER_EXCHANGEDB_Session *session) commit_or_warn (void)
{ {
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = db_plugin->commit (db_plugin->cls, qs = db_plugin->commit (db_plugin->cls);
session);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
return qs; return qs;
GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs) GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs)
@ -652,24 +638,23 @@ static void
run_aggregation (void *cls) run_aggregation (void *cls)
{ {
struct AggregationUnit au_active; struct AggregationUnit au_active;
struct TALER_EXCHANGEDB_Session *session;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
(void) cls; (void) cls;
task = NULL; task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking for ready deposits to aggregate\n"); "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, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to obtain database session!\n"); "Failed to obtain database connection!\n");
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
} }
if (GNUNET_OK != if (GNUNET_OK !=
db_plugin->start_deferred_wire_out (db_plugin->cls, db_plugin->start_deferred_wire_out (db_plugin->cls))
session))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to start database transaction!\n"); "Failed to start database transaction!\n");
@ -680,16 +665,13 @@ run_aggregation (void *cls)
memset (&au_active, memset (&au_active,
0, 0,
sizeof (au_active)); sizeof (au_active));
au_active.session = session;
qs = db_plugin->get_ready_deposit (db_plugin->cls, qs = db_plugin->get_ready_deposit (db_plugin->cls,
session,
&deposit_cb, &deposit_cb,
&au_active); &au_active);
if (0 >= qs) if (0 >= qs)
{ {
cleanup_au (&au_active); cleanup_au (&au_active);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -729,7 +711,6 @@ run_aggregation (void *cls)
"Found ready deposit for %s, aggregating\n", "Found ready deposit for %s, aggregating\n",
TALER_B2S (&au_active.merchant_pub)); TALER_B2S (&au_active.merchant_pub));
qs = db_plugin->iterate_matching_deposits (db_plugin->cls, qs = db_plugin->iterate_matching_deposits (db_plugin->cls,
session,
&au_active.h_wire, &au_active.h_wire,
&au_active.merchant_pub, &au_active.merchant_pub,
&aggregate_cb, &aggregate_cb,
@ -741,8 +722,7 @@ run_aggregation (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to execute deposit iteration!\n"); "Failed to execute deposit iteration!\n");
cleanup_au (&au_active); cleanup_au (&au_active);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
@ -752,8 +732,7 @@ run_aggregation (void *cls)
/* serializiability issue, try again */ /* serializiability issue, try again */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Serialization issue, trying again later!\n"); "Serialization issue, trying again later!\n");
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
cleanup_au (&au_active); cleanup_au (&au_active);
GNUNET_assert (NULL == task); GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_aggregation, task = GNUNET_SCHEDULER_add_now (&run_aggregation,
@ -780,14 +759,12 @@ run_aggregation (void *cls)
TALER_amount2s (&au_active.final_amount)); TALER_amount2s (&au_active.final_amount));
/* Rollback ongoing transaction, as we will not use the respective /* Rollback ongoing transaction, as we will not use the respective
WTID and thus need to remove the tracking data */ WTID and thus need to remove the tracking data */
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
/* There were results, just the value was too low. Start another /* There were results, just the value was too low. Start another
transaction to mark all* of the selected deposits as minor! */ transaction to mark all* of the selected deposits as minor! */
if (GNUNET_OK != if (GNUNET_OK !=
db_plugin->start (db_plugin->cls, db_plugin->start (db_plugin->cls,
session,
"aggregator mark tiny transactions")) "aggregator mark tiny transactions"))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -799,14 +776,12 @@ run_aggregation (void *cls)
} }
/* Mark transactions by row_id as minor */ /* Mark transactions by row_id as minor */
qs = db_plugin->mark_deposit_tiny (db_plugin->cls, qs = db_plugin->mark_deposit_tiny (db_plugin->cls,
session,
au_active.row_id); au_active.row_id);
if (0 <= qs) if (0 <= qs)
{ {
for (unsigned int i = 0; i<au_active.rows_offset; i++) for (unsigned int i = 0; i<au_active.rows_offset; i++)
{ {
qs = db_plugin->mark_deposit_tiny (db_plugin->cls, qs = db_plugin->mark_deposit_tiny (db_plugin->cls,
session,
au_active.additional_rows[i]); au_active.additional_rows[i]);
if (0 > qs) if (0 > qs)
break; break;
@ -816,8 +791,7 @@ run_aggregation (void *cls)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Serialization issue, trying again later!\n"); "Serialization issue, trying again later!\n");
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
cleanup_au (&au_active); cleanup_au (&au_active);
/* start again */ /* start again */
GNUNET_assert (NULL == task); GNUNET_assert (NULL == task);
@ -827,15 +801,14 @@ run_aggregation (void *cls)
} }
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{ {
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
cleanup_au (&au_active); cleanup_au (&au_active);
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
} }
/* commit */ /* commit */
(void) commit_or_warn (session); (void) commit_or_warn ();
cleanup_au (&au_active); cleanup_au (&au_active);
/* start again */ /* start again */
@ -877,7 +850,6 @@ run_aggregation (void *cls)
(unsigned int) buf_size); (unsigned int) buf_size);
/* Commit our intention to execute the wire transfer! */ /* Commit our intention to execute the wire transfer! */
qs = db_plugin->wire_prepare_data_insert (db_plugin->cls, qs = db_plugin->wire_prepare_data_insert (db_plugin->cls,
session,
au_active.wa->method, au_active.wa->method,
buf, buf,
buf_size); buf_size);
@ -887,7 +859,6 @@ run_aggregation (void *cls)
table constraints */ table constraints */
if (qs >= 0) if (qs >= 0)
qs = db_plugin->store_wire_transfer_out (db_plugin->cls, qs = db_plugin->store_wire_transfer_out (db_plugin->cls,
session,
au_active.execution_time, au_active.execution_time,
&au_active.wtid, &au_active.wtid,
au_active.wire, au_active.wire,
@ -899,8 +870,7 @@ run_aggregation (void *cls)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Serialization issue for prepared wire data; trying again later!\n"); "Serialization issue for prepared wire data; trying again later!\n");
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
/* start again */ /* start again */
GNUNET_assert (NULL == task); GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_aggregation, task = GNUNET_SCHEDULER_add_now (&run_aggregation,
@ -910,8 +880,7 @@ run_aggregation (void *cls)
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{ {
GNUNET_break (0); GNUNET_break (0);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
/* die hard */ /* die hard */
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
@ -923,7 +892,7 @@ run_aggregation (void *cls)
/* Now we can finally commit the overall transaction, as we are /* Now we can finally commit the overall transaction, as we are
again consistent if all of this passes. */ again consistent if all of this passes. */
switch (commit_or_warn (session)) switch (commit_or_warn ())
{ {
case GNUNET_DB_STATUS_SOFT_ERROR: case GNUNET_DB_STATUS_SOFT_ERROR:
/* try again */ /* try again */

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER 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 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 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. * Perform a database commit. If it fails, print a warning.
* *
* @param session session to perform the commit for.
* @return status of commit * @return status of commit
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
commit_or_warn (struct TALER_EXCHANGEDB_Session *session) commit_or_warn (void)
{ {
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = db_plugin->commit (db_plugin->cls, qs = db_plugin->commit (db_plugin->cls);
session);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
return qs; return qs;
GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs) GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs)
@ -194,27 +192,13 @@ 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. * Function called with details about expired reserves.
* We trigger the reserve closure by inserting the respective * We trigger the reserve closure by inserting the respective
* closing record and prewire instructions into the respective * closing record and prewire instructions into the respective
* tables. * tables.
* *
* @param cls a `struct ExpiredReserveContext *` * @param cls NULL
* @param reserve_pub public key of the reserve * @param reserve_pub public key of the reserve
* @param left amount left in the reserve * @param left amount left in the reserve
* @param account_payto_uri information about the bank account that initially * @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, const char *account_payto_uri,
struct GNUNET_TIME_Absolute expiration_date) struct GNUNET_TIME_Absolute expiration_date)
{ {
struct ExpiredReserveContext *erc = cls;
struct TALER_EXCHANGEDB_Session *session = erc->session;
struct GNUNET_TIME_Absolute now; struct GNUNET_TIME_Absolute now;
struct TALER_WireTransferIdentifierRawP wtid; struct TALER_WireTransferIdentifierRawP wtid;
struct TALER_Amount amount_without_fee; struct TALER_Amount amount_without_fee;
@ -239,6 +221,7 @@ expired_reserve_cb (void *cls,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
const struct TALER_EXCHANGEDB_AccountInfo *wa; const struct TALER_EXCHANGEDB_AccountInfo *wa;
(void) cls;
/* NOTE: potential optimization: use custom SQL API to not /* NOTE: potential optimization: use custom SQL API to not
fetch this: */ fetch this: */
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@ -269,7 +252,6 @@ expired_reserve_cb (void *cls,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = db_plugin->get_wire_fee (db_plugin->cls, qs = db_plugin->get_wire_fee (db_plugin->cls,
session,
wa->method, wa->method,
expiration_date, expiration_date,
&start_date, &start_date,
@ -326,7 +308,6 @@ expired_reserve_cb (void *cls,
sizeof (*reserve_pub))); sizeof (*reserve_pub)));
if (GNUNET_SYSERR != ret) if (GNUNET_SYSERR != ret)
qs = db_plugin->insert_reserve_closed (db_plugin->cls, qs = db_plugin->insert_reserve_closed (db_plugin->cls,
session,
reserve_pub, reserve_pub,
now, now,
account_payto_uri, account_payto_uri,
@ -356,7 +337,7 @@ expired_reserve_cb (void *cls,
/* Reserve balance was almost zero OR soft error */ /* Reserve balance was almost zero OR soft error */
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Reserve was virtually empty, moving on\n"); "Reserve was virtually empty, moving on\n");
(void) commit_or_warn (session); (void) commit_or_warn ();
return qs; return qs;
} }
@ -373,7 +354,6 @@ expired_reserve_cb (void *cls,
&buf_size); &buf_size);
/* Commit our intention to execute the wire transfer! */ /* Commit our intention to execute the wire transfer! */
qs = db_plugin->wire_prepare_data_insert (db_plugin->cls, qs = db_plugin->wire_prepare_data_insert (db_plugin->cls,
session,
wa->method, wa->method,
buf, buf,
buf_size); buf_size);
@ -404,17 +384,16 @@ expired_reserve_cb (void *cls,
static void static void
run_reserve_closures (void *cls) run_reserve_closures (void *cls)
{ {
struct TALER_EXCHANGEDB_Session *session;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
struct ExpiredReserveContext erc;
struct GNUNET_TIME_Absolute now; struct GNUNET_TIME_Absolute now;
(void) cls; (void) cls;
task = NULL; 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, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to obtain database session!\n"); "Failed to obtain database connection!\n");
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
@ -422,7 +401,6 @@ run_reserve_closures (void *cls)
if (GNUNET_OK != if (GNUNET_OK !=
db_plugin->start (db_plugin->cls, db_plugin->start (db_plugin->cls,
session,
"aggregator reserve closures")) "aggregator reserve closures"))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -431,30 +409,26 @@ run_reserve_closures (void *cls)
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
} }
erc.session = session;
now = GNUNET_TIME_absolute_get (); now = GNUNET_TIME_absolute_get ();
(void) GNUNET_TIME_round_abs (&now); (void) GNUNET_TIME_round_abs (&now);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking for reserves to close by date %s\n", "Checking for reserves to close by date %s\n",
GNUNET_STRINGS_absolute_time_to_string (now)); GNUNET_STRINGS_absolute_time_to_string (now));
qs = db_plugin->get_expired_reserves (db_plugin->cls, qs = db_plugin->get_expired_reserves (db_plugin->cls,
session,
now, now,
&expired_reserve_cb, &expired_reserve_cb,
&erc); NULL);
GNUNET_assert (1 >= qs); GNUNET_assert (1 >= qs);
switch (qs) switch (qs)
{ {
case GNUNET_DB_STATUS_HARD_ERROR: case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0); GNUNET_break (0);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
case GNUNET_DB_STATUS_SOFT_ERROR: case GNUNET_DB_STATUS_SOFT_ERROR:
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
GNUNET_assert (NULL == task); GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_reserve_closures, task = GNUNET_SCHEDULER_add_now (&run_reserve_closures,
NULL); NULL);
@ -462,8 +436,7 @@ run_reserve_closures (void *cls)
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"No more idle reserves to close, going to sleep.\n"); "No more idle reserves to close, going to sleep.\n");
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
GNUNET_assert (NULL == task); GNUNET_assert (NULL == task);
if (GNUNET_YES == test_mode) if (GNUNET_YES == test_mode)
{ {
@ -477,7 +450,7 @@ run_reserve_closures (void *cls)
} }
return; return;
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
(void) commit_or_warn (session); (void) commit_or_warn ();
GNUNET_assert (NULL == task); GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_reserve_closures, task = GNUNET_SCHEDULER_add_now (&run_reserve_closures,
NULL); NULL);

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER 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 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 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_deposits_get.h"
#include "taler-exchange-httpd_keys.h" #include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_link.h" #include "taler-exchange-httpd_link.h"
#include "taler-exchange-httpd_loop.h"
#include "taler-exchange-httpd_management.h" #include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_melt.h" #include "taler-exchange-httpd_melt.h"
#include "taler-exchange-httpd_mhd.h" #include "taler-exchange-httpd_mhd.h"
@ -53,7 +52,7 @@
/** /**
* Backlog for listen operation on unix domain sockets. * 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) * 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) * How long is caching /keys allowed at most? (global)
@ -101,33 +100,20 @@ char *TEH_currency;
static unsigned int connection_timeout = 30; static unsigned int connection_timeout = 30;
/** /**
* How many threads to use. * -C command-line flag given?
* The default value (0) sets the actual number of threads
* based on the number of available cores.
*/ */
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. * Port to run the daemon on.
*/ */
static uint16_t serve_port; 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. * Counter for the number of requests this HTTP has processed so far.
*/ */
@ -302,11 +288,8 @@ handle_mhd_completion_callback (void *cls,
TALER_MHD_parse_post_cleanup_callback (rc->opaque_post_parsing_context); TALER_MHD_parse_post_cleanup_callback (rc->opaque_post_parsing_context);
/* Sanity-check that we didn't leave any transactions hanging */ /* Sanity-check that we didn't leave any transactions hanging */
/* NOTE: In high-performance production, we could consider GNUNET_break (GNUNET_OK ==
removing this as it should not be needed and might be costly TEH_plugin->preflight (TEH_plugin->cls));
(to be benchmarked). */
TEH_plugin->preflight (TEH_plugin->cls,
TEH_plugin->get_session (TEH_plugin->cls));
GNUNET_free (rc); GNUNET_free (rc);
*con_cls = NULL; *con_cls = NULL;
GNUNET_async_scope_restore (&old_scope); GNUNET_async_scope_restore (&old_scope);
@ -1179,18 +1162,6 @@ exchange_serve_process_config (void)
"Failed to initialize DB subsystem\n"); "Failed to initialize DB subsystem\n");
return GNUNET_SYSERR; 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; return GNUNET_OK;
} }
@ -1248,16 +1219,11 @@ write_stats (void)
/* Developer logic for supporting the `-f' option. */ /* Developer logic for supporting the `-f' option. */
#if HAVE_DEVELOPER #if HAVE_DEVELOPER
/** /**
* Option `-f' (specifies an input file to give to the HTTP server). * Option `-f' (specifies an input file to give to the HTTP server).
*/ */
static char *input_filename; 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 * Run 'nc' or 'ncat' as a fake HTTP client using #input_filename
@ -1277,7 +1243,8 @@ run_fake_client (void)
"-")) "-"))
fd = STDIN_FILENO; fd = STDIN_FILENO;
else else
fd = open (input_filename, O_RDONLY); fd = open (input_filename,
O_RDONLY);
if (-1 == fd) if (-1 == fd)
{ {
fprintf (stderr, fprintf (stderr,
@ -1324,6 +1291,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 * Signature of the callback used by MHD to notify the application
* about completed connections. If we are running in test-mode with * about completed connections. If we are running in test-mode with
@ -1344,240 +1355,138 @@ connection_done (void *cls,
(void) cls; (void) cls;
(void) connection; (void) connection;
(void) socket_context; (void) socket_context;
#if HAVE_DEVELOPER
/* We only act if the connection is closed. */ /* We only act if the connection is closed. */
if (MHD_CONNECTION_NOTIFY_CLOSED != toe) if (MHD_CONNECTION_NOTIFY_CLOSED != toe)
return; return;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, if (NULL != input_filename)
"Connection done!\n"); GNUNET_SCHEDULER_shutdown ();
do_terminate = GNUNET_YES;
}
/**
* Run the exchange to serve a single request only, without threads.
*
* @return #GNUNET_OK on success
*/
static int
run_single_request (void)
{
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);
TEH_resume_keys_requests (true);
TEH_reserves_get_cleanup ();
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;
}
/* end of HAVE_DEVELOPER */
#endif #endif
}
/** /**
* Run the ordinary multi-threaded main loop and the logic to * Function run on shutdown.
* wait for CTRL-C.
* *
* @param fh listen socket * @param cls NULL
* @param argv command line arguments
* @return #GNUNET_OK on success
*/ */
static int static void
run_main_loop (int fh, do_shutdown (void *cls)
char *const *argv)
{ {
int ret; struct MHD_Daemon *mhd;
(void) cls;
GNUNET_assert (0 < num_threads); mhd = TALER_MHD_daemon_stop ();
TEH_resume_keys_requests (true);
mhd TEH_reserves_get_cleanup ();
= MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_PIPE_FOR_SHUTDOWN if (NULL != mhd)
| 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)
{
fprintf (stderr,
"Failed to start HTTP server.\n");
return GNUNET_SYSERR;
}
atexit (&write_stats);
ret = TEH_loop_run ();
switch (ret)
{
case GNUNET_OK:
case GNUNET_SYSERR:
{
MHD_socket sock = MHD_quiesce_daemon (mhd);
TEH_resume_keys_requests (true);
TEH_reserves_get_cleanup ();
MHD_stop_daemon (mhd);
GNUNET_break (0 == close (sock));
}
mhd = NULL;
break;
case GNUNET_NO:
{
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);
}
break;
default:
GNUNET_break (0);
TEH_resume_keys_requests (true);
MHD_stop_daemon (mhd); MHD_stop_daemon (mhd);
break; TALER_EXCHANGEDB_plugin_unload (TEH_plugin);
TEH_WIRE_done ();
}
/**
* Main function that will be run by the scheduler.
*
* @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 void
run (void *cls,
char *const *args,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
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 ())
{
global_ret = EXIT_NOTCONFIGURED;
GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_OK !=
TEH_WIRE_init ())
{
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_OK !=
TEH_keys_init ())
{
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
} }
return ret; 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)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to launch HTTP service. Is the port in use?\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
global_ret = EXIT_SUCCESS;
TALER_MHD_daemon_start (mhd);
}
atexit (&write_stats);
#if HAVE_DEVELOPER
if (NULL != input_filename)
run_single_request ();
#endif
} }
@ -1592,10 +1501,6 @@ int
main (int argc, main (int argc,
char *const *argv) char *const *argv)
{ {
char *cfgfile = NULL;
char *loglev = NULL;
char *logfile = NULL;
int connection_close = GNUNET_NO;
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_option_flag ('a', GNUNET_GETOPT_option_flag ('a',
"allow-timetravel", "allow-timetravel",
@ -1605,7 +1510,6 @@ main (int argc,
"connection-close", "connection-close",
"force HTTP connections to be closed after each request", "force HTTP connections to be closed after each request",
&connection_close), &connection_close),
GNUNET_GETOPT_option_cfgfile (&cfgfile),
GNUNET_GETOPT_option_uint ('t', GNUNET_GETOPT_option_uint ('t',
"timeout", "timeout",
"SECONDS", "SECONDS",
@ -1613,11 +1517,6 @@ main (int argc,
&connection_timeout), &connection_timeout),
GNUNET_GETOPT_option_timetravel ('T', GNUNET_GETOPT_option_timetravel ('T',
"timetravel"), "timetravel"),
GNUNET_GETOPT_option_uint ('n',
"num-threads",
"NUM_THREADS",
"size of the thread pool",
&num_threads),
#if HAVE_DEVELOPER #if HAVE_DEVELOPER
GNUNET_GETOPT_option_filename ('f', GNUNET_GETOPT_option_filename ('f',
"file-input", "file-input",
@ -1627,141 +1526,22 @@ main (int argc,
#endif #endif
GNUNET_GETOPT_option_help ( GNUNET_GETOPT_option_help (
"HTTP server providing a RESTful API to access a Taler exchange"), "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_version (VERSION "-" VCS_VERSION),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
}; };
int ret; enum GNUNET_GenericReturnValue ret;
const char *listen_pid;
const char *listen_fds;
int fh = -1;
enum TALER_MHD_GlobalOptions go;
TALER_OS_init (); TALER_OS_init ();
ret = GNUNET_GETOPT_run ("taler-exchange-httpd", ret = GNUNET_PROGRAM_run (argc, argv,
options, "taler-exchange-httpd",
argc, argv); "Taler exchange HTTP service",
options,
&run, NULL);
if (GNUNET_SYSERR == ret) if (GNUNET_SYSERR == ret)
return EXIT_INVALIDARGUMENT; return EXIT_INVALIDARGUMENT;
if (GNUNET_NO == ret) if (GNUNET_NO == ret)
return EXIT_SUCCESS; return EXIT_SUCCESS;
if (0 == num_threads) return global_ret;
{
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;
} }

View File

@ -42,7 +42,7 @@ extern struct GNUNET_TIME_Relative TEH_reserve_closing_delay;
/** /**
* The exchange's configuration. * The exchange's configuration.
*/ */
extern struct GNUNET_CONFIGURATION_Handle *TEH_cfg; extern const struct GNUNET_CONFIGURATION_Handle *TEH_cfg;
/** /**
* Main directory with exchange data. * Main directory with exchange data.

View File

@ -65,7 +65,6 @@ struct AddAuditorDenomContext
* *
* @param cls closure with a `struct AddAuditorDenomContext` * @param cls closure with a `struct AddAuditorDenomContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -73,7 +72,6 @@ struct AddAuditorDenomContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
add_auditor_denom_sig (void *cls, add_auditor_denom_sig (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct AddAuditorDenomContext *awc = cls; struct AddAuditorDenomContext *awc = cls;
@ -84,7 +82,6 @@ add_auditor_denom_sig (void *cls,
qs = TEH_plugin->lookup_denomination_key ( qs = TEH_plugin->lookup_denomination_key (
TEH_plugin->cls, TEH_plugin->cls,
session,
awc->h_denom_pub, awc->h_denom_pub,
&meta); &meta);
if (qs < 0) if (qs < 0)
@ -110,7 +107,6 @@ add_auditor_denom_sig (void *cls,
qs = TEH_plugin->lookup_auditor_status ( qs = TEH_plugin->lookup_auditor_status (
TEH_plugin->cls, TEH_plugin->cls,
session,
awc->auditor_pub, awc->auditor_pub,
&auditor_url, &auditor_url,
&enabled); &enabled);
@ -174,7 +170,6 @@ add_auditor_denom_sig (void *cls,
GNUNET_free (auditor_url); GNUNET_free (auditor_url);
qs = TEH_plugin->insert_auditor_denom_sig (TEH_plugin->cls, qs = TEH_plugin->insert_auditor_denom_sig (TEH_plugin->cls,
session,
awc->h_denom_pub, awc->h_denom_pub,
awc->auditor_pub, awc->auditor_pub,
&awc->auditor_sig); &awc->auditor_sig);

View File

@ -45,21 +45,18 @@
* *
* @param coin the coin to make known * @param coin the coin to make known
* @param connection MHD request context * @param connection MHD request context
* @param session database session and transaction to use
* @param[out] mhd_ret set to MHD status on error * @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) * @return transaction status, negative on error (@a mhd_ret will be set in this case)
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin, TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
enum TALER_EXCHANGEDB_CoinKnownStatus cks; enum TALER_EXCHANGEDB_CoinKnownStatus cks;
/* make sure coin is 'known' in database */ /* make sure coin is 'known' in database */
cks = TEH_plugin->ensure_coin_known (TEH_plugin->cls, cks = TEH_plugin->ensure_coin_known (TEH_plugin->cls,
session,
coin); coin);
switch (cks) switch (cks)
{ {
@ -85,7 +82,6 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls, qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
session,
&coin->coin_pub, &coin->coin_pub,
GNUNET_NO, GNUNET_NO,
&tl); &tl);
@ -135,11 +131,10 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
TEH_DB_TransactionCallback cb, TEH_DB_TransactionCallback cb,
void *cb_cls) void *cb_cls)
{ {
struct TALER_EXCHANGEDB_Session *session;
if (NULL != mhd_ret) if (NULL != mhd_ret)
*mhd_ret = -1; /* set to invalid value, to help detect bugs */ *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); GNUNET_break (0);
if (NULL != mhd_ret) if (NULL != mhd_ret)
@ -157,7 +152,6 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
if (GNUNET_OK != if (GNUNET_OK !=
TEH_plugin->start (TEH_plugin->cls, TEH_plugin->start (TEH_plugin->cls,
session,
name)) name))
{ {
GNUNET_break (0); GNUNET_break (0);
@ -170,16 +164,13 @@ TEH_DB_run_transaction (struct MHD_Connection *connection,
} }
qs = cb (cb_cls, qs = cb (cb_cls,
connection, connection,
session,
mhd_ret); mhd_ret);
if (0 > qs) if (0 > qs)
TEH_plugin->rollback (TEH_plugin->cls, TEH_plugin->rollback (TEH_plugin->cls);
session);
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
return GNUNET_SYSERR; return GNUNET_SYSERR;
if (0 <= qs) if (0 <= qs)
qs = TEH_plugin->commit (TEH_plugin->cls, qs = TEH_plugin->commit (TEH_plugin->cls);
session);
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{ {
if (NULL != mhd_ret) if (NULL != mhd_ret)

View File

@ -31,14 +31,12 @@
* *
* @param coin the coin to make known * @param coin the coin to make known
* @param connection MHD request context * @param connection MHD request context
* @param session database session and transaction to use
* @param[out] mhd_ret set to MHD status on error * @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) * @return transaction status, negative on error (@a mhd_ret will be set in this case)
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin, TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret); MHD_RESULT *mhd_ret);
@ -52,7 +50,6 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
* *
* @param cls closure * @param cls closure
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -60,7 +57,6 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
typedef enum GNUNET_DB_QueryStatus typedef enum GNUNET_DB_QueryStatus
(*TEH_DB_TransactionCallback)(void *cls, (*TEH_DB_TransactionCallback)(void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret); MHD_RESULT *mhd_ret);

View File

@ -133,14 +133,12 @@ struct DepositContext
* *
* @param cls a `struct DepositContext` * @param cls a `struct DepositContext`
* @param connection MHD request context * @param connection MHD request context
* @param session database session and transaction to use
* @param[out] mhd_ret set to MHD status on error * @param[out] mhd_ret set to MHD status on error
* @return transaction status * @return transaction status
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
deposit_precheck (void *cls, deposit_precheck (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct DepositContext *dc = cls; struct DepositContext *dc = cls;
@ -149,7 +147,6 @@ deposit_precheck (void *cls,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->have_deposit (TEH_plugin->cls, qs = TEH_plugin->have_deposit (TEH_plugin->cls,
session,
deposit, deposit,
GNUNET_YES /* check refund deadline */, GNUNET_YES /* check refund deadline */,
&deposit_fee, &deposit_fee,
@ -202,14 +199,12 @@ deposit_precheck (void *cls,
* *
* @param cls a `struct DepositContext` * @param cls a `struct DepositContext`
* @param connection MHD request context * @param connection MHD request context
* @param session database session and transaction to use
* @param[out] mhd_ret set to MHD status on error * @param[out] mhd_ret set to MHD status on error
* @return transaction status * @return transaction status
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
deposit_transaction (void *cls, deposit_transaction (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct DepositContext *dc = cls; struct DepositContext *dc = cls;
@ -220,7 +215,6 @@ deposit_transaction (void *cls,
/* make sure coin is 'known' in database */ /* make sure coin is 'known' in database */
qs = TEH_make_coin_known (&deposit->coin, qs = TEH_make_coin_known (&deposit->coin,
connection, connection,
session,
mhd_ret); mhd_ret);
if (qs < 0) if (qs < 0)
return qs; return qs;
@ -230,7 +224,6 @@ deposit_transaction (void *cls,
that we are in the transaction scope. */ that we are in the transaction scope. */
qs = deposit_precheck (cls, qs = deposit_precheck (cls,
connection, connection,
session,
mhd_ret); mhd_ret);
if (qs < 0) if (qs < 0)
return qs; return qs;
@ -244,7 +237,6 @@ deposit_transaction (void *cls,
struct TALER_EXCHANGEDB_TransactionList *tl; struct TALER_EXCHANGEDB_TransactionList *tl;
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls, qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
session,
&deposit->coin.coin_pub, &deposit->coin.coin_pub,
GNUNET_NO, GNUNET_NO,
&tl); &tl);
@ -292,7 +284,6 @@ deposit_transaction (void *cls,
tl); tl);
} }
qs = TEH_plugin->insert_deposit (TEH_plugin->cls, qs = TEH_plugin->insert_deposit (TEH_plugin->cls,
session,
dc->exchange_timestamp, dc->exchange_timestamp,
deposit); deposit);
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)

View File

@ -203,7 +203,6 @@ handle_wtid_data (void *cls,
* *
* @param cls closure of type `struct DepositWtidContext *` * @param cls closure of type `struct DepositWtidContext *`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -211,14 +210,12 @@ handle_wtid_data (void *cls,
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
deposits_get_transaction (void *cls, deposits_get_transaction (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct DepositWtidContext *ctx = cls; struct DepositWtidContext *ctx = cls;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_transfer_by_deposit (TEH_plugin->cls, qs = TEH_plugin->lookup_transfer_by_deposit (TEH_plugin->cls,
session,
&ctx->tps->h_contract_terms, &ctx->tps->h_contract_terms,
&ctx->tps->h_wire, &ctx->tps->h_wire,
&ctx->tps->coin_pub, &ctx->tps->coin_pub,

View File

@ -19,7 +19,6 @@
* @author Christian Grothoff * @author Christian Grothoff
*/ */
#include "platform.h" #include "platform.h"
#include <pthread.h>
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "taler_mhd_lib.h" #include "taler_mhd_lib.h"
#include "taler-exchange-httpd.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 latest generation of our key state.
* Stores the per-thread 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 * 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 * changes, the variable MUST be volatile. See #TEH_keys_get_state() and
* #TEH_keys_update_states() for uses of this variable. * #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. * Head of DLL of suspended /keys requests.
@ -391,29 +389,11 @@ static struct TALER_SecurityModulePublicKeyP denom_sm_pub;
*/ */
static struct TALER_SecurityModulePublicKeyP esign_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? * Are we shutting down?
*/ */
static bool terminating; static bool terminating;
/**
* Did we ever initialize #key_state?
*/
static bool key_state_available;
/** /**
* Suspend /keys request while we (hopefully) are waiting to be * Suspend /keys request while we (hopefully) are waiting to be
* provisioned with key material. * provisioned with key material.
@ -427,10 +407,8 @@ suspend_request (struct MHD_Connection *connection)
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Suspending /keys request until key material changes\n"); "Suspending /keys request until key material changes\n");
GNUNET_assert (0 == pthread_mutex_lock (&skr_mutex));
if (terminating) if (terminating)
{ {
GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
return TALER_MHD_reply_with_error (connection, return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR, MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
@ -452,9 +430,9 @@ suspend_request (struct MHD_Connection *connection)
skr_size--; skr_size--;
skr_connection = skr->connection; skr_connection = skr->connection;
MHD_resume_connection (skr->connection); MHD_resume_connection (skr->connection);
TALER_MHD_daemon_trigger ();
GNUNET_free (skr); GNUNET_free (skr);
} }
GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
return MHD_YES; return MHD_YES;
} }
@ -464,7 +442,6 @@ TEH_resume_keys_requests (bool do_shutdown)
{ {
struct SuspendedKeysRequests *skr; struct SuspendedKeysRequests *skr;
GNUNET_assert (0 == pthread_mutex_lock (&skr_mutex));
if (do_shutdown) if (do_shutdown)
terminating = true; terminating = true;
while (NULL != (skr = skr_head)) while (NULL != (skr = skr_head))
@ -474,9 +451,9 @@ TEH_resume_keys_requests (bool do_shutdown)
skr); skr);
skr_size--; skr_size--;
MHD_resume_connection (skr->connection); MHD_resume_connection (skr->connection);
TALER_MHD_daemon_trigger ();
GNUNET_free (skr); GNUNET_free (skr);
} }
GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
} }
@ -510,7 +487,6 @@ clear_response_cache (struct TEH_KeyStateHandle *ksh)
static void static void
check_denom_sm_pub (const struct TALER_SecurityModulePublicKeyP *sm_pub) check_denom_sm_pub (const struct TALER_SecurityModulePublicKeyP *sm_pub)
{ {
GNUNET_assert (0 == pthread_mutex_lock (&sm_pub_mutex));
if (0 != if (0 !=
GNUNET_memcmp (sm_pub, GNUNET_memcmp (sm_pub,
&denom_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 ;-) */ 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 static void
check_esign_sm_pub (const struct TALER_SecurityModulePublicKeyP *sm_pub) check_esign_sm_pub (const struct TALER_SecurityModulePublicKeyP *sm_pub)
{ {
GNUNET_assert (0 == pthread_mutex_lock (&sm_pub_mutex));
if (0 != if (0 !=
GNUNET_memcmp (sm_pub, GNUNET_memcmp (sm_pub,
&esign_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 ;-) */ 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 int
TEH_keys_init () 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 != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (TEH_cfg, GNUNET_CONFIGURATION_get_value_time (TEH_cfg,
"exchange", "exchange",
@ -949,11 +893,9 @@ TEH_keys_init ()
void __attribute__ ((destructor)) void __attribute__ ((destructor))
TEH_keys_finished () TEH_keys_finished ()
{ {
if (key_state_available) if (NULL != key_state)
{ destroy_key_state (key_state,
GNUNET_assert (0 == true);
pthread_key_delete (key_state));
}
} }
@ -1799,22 +1741,14 @@ get_key_state (bool management_only)
struct TEH_KeyStateHandle *old_ksh; struct TEH_KeyStateHandle *old_ksh;
struct TEH_KeyStateHandle *ksh; struct TEH_KeyStateHandle *ksh;
GNUNET_assert (key_state_available); old_ksh = key_state;
old_ksh = pthread_getspecific (key_state);
if (NULL == old_ksh) if (NULL == old_ksh)
{ {
ksh = build_key_state (NULL, ksh = build_key_state (NULL,
management_only); management_only);
if (NULL == ksh) if (NULL == ksh)
return NULL; return NULL;
if (0 != pthread_setspecific (key_state, key_state = ksh;
ksh))
{
GNUNET_break (0);
destroy_key_state (ksh,
true);
return NULL;
}
return ksh; return ksh;
} }
if ( (old_ksh->key_generation < key_generation) || if ( (old_ksh->key_generation < key_generation) ||
@ -1826,15 +1760,7 @@ get_key_state (bool management_only)
(unsigned long long) key_generation); (unsigned long long) key_generation);
ksh = build_key_state (old_ksh->helpers, ksh = build_key_state (old_ksh->helpers,
management_only); management_only);
if (0 != pthread_setspecific (key_state, key_state = ksh;
ksh))
{
GNUNET_break (0);
if (NULL != ksh)
destroy_key_state (ksh,
false);
return NULL;
}
old_ksh->helpers = NULL; old_ksh->helpers = NULL;
destroy_key_state (old_ksh, destroy_key_state (old_ksh,
false); false);
@ -2099,17 +2025,14 @@ TEH_keys_get_handler (struct TEH_RequestContext *rc,
ksh = TEH_keys_get_state (); ksh = TEH_keys_get_state ();
if (NULL == ksh) if (NULL == ksh)
{ {
GNUNET_assert (0 == pthread_mutex_lock (&skr_mutex));
if ( (SKR_LIMIT == skr_size) && if ( (SKR_LIMIT == skr_size) &&
(rc->connection == skr_connection) ) (rc->connection == skr_connection) )
{ {
GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
return TALER_MHD_reply_with_error (rc->connection, return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_INTERNAL_SERVER_ERROR, MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING, TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
"too many connections suspended on /keys"); "too many connections suspended on /keys");
} }
GNUNET_assert (0 == pthread_mutex_unlock (&skr_mutex));
return suspend_request (rc->connection); return suspend_request (rc->connection);
} }
krd = bsearch (&last_issue_date, krd = bsearch (&last_issue_date,

View File

@ -130,7 +130,6 @@ fail:
* *
* @param cls closure * @param cls closure
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -138,14 +137,12 @@ fail:
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
link_transaction (void *cls, link_transaction (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct HTD_Context *ctx = cls; struct HTD_Context *ctx = cls;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->get_link_data (TEH_plugin->cls, qs = TEH_plugin->get_link_data (TEH_plugin->cls,
session,
&ctx->coin_pub, &ctx->coin_pub,
&handle_link_data, &handle_link_data,
ctx); ctx);

View File

@ -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 */

View File

@ -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

View File

@ -74,7 +74,6 @@ struct AddAuditorContext
* *
* @param cls closure with a `struct AddAuditorContext` * @param cls closure with a `struct AddAuditorContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -82,7 +81,6 @@ struct AddAuditorContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
add_auditor (void *cls, add_auditor (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct AddAuditorContext *aac = cls; struct AddAuditorContext *aac = cls;
@ -90,7 +88,6 @@ add_auditor (void *cls,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls, qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls,
session,
&aac->auditor_pub, &aac->auditor_pub,
&last_date); &last_date);
if (qs < 0) if (qs < 0)
@ -116,14 +113,12 @@ add_auditor (void *cls,
} }
if (0 == qs) if (0 == qs)
qs = TEH_plugin->insert_auditor (TEH_plugin->cls, qs = TEH_plugin->insert_auditor (TEH_plugin->cls,
session,
&aac->auditor_pub, &aac->auditor_pub,
aac->auditor_url, aac->auditor_url,
aac->auditor_name, aac->auditor_name,
aac->validity_start); aac->validity_start);
else else
qs = TEH_plugin->update_auditor (TEH_plugin->cls, qs = TEH_plugin->update_auditor (TEH_plugin->cls,
session,
&aac->auditor_pub, &aac->auditor_pub,
aac->auditor_url, aac->auditor_url,
aac->auditor_name, aac->auditor_name,

View File

@ -65,7 +65,6 @@ struct DelAuditorContext
* *
* @param cls closure with a `struct DelAuditorContext` * @param cls closure with a `struct DelAuditorContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -73,7 +72,6 @@ struct DelAuditorContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
del_auditor (void *cls, del_auditor (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct DelAuditorContext *dac = cls; struct DelAuditorContext *dac = cls;
@ -81,7 +79,6 @@ del_auditor (void *cls,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls, qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls,
session,
&dac->auditor_pub, &dac->auditor_pub,
&last_date); &last_date);
if (qs < 0) if (qs < 0)
@ -114,7 +111,6 @@ del_auditor (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
qs = TEH_plugin->update_auditor (TEH_plugin->cls, qs = TEH_plugin->update_auditor (TEH_plugin->cls,
session,
&dac->auditor_pub, &dac->auditor_pub,
"", /* auditor URL */ "", /* auditor URL */
"", /* auditor name */ "", /* auditor name */

View File

@ -70,7 +70,6 @@ TEH_handler_management_denominations_HDP_revoke (
NULL); NULL);
} }
qs = TEH_plugin->insert_denomination_revocation (TEH_plugin->cls, qs = TEH_plugin->insert_denomination_revocation (TEH_plugin->cls,
NULL,
h_denom_pub, h_denom_pub,
&master_sig); &master_sig);
if (qs < 0) if (qs < 0)

View File

@ -107,7 +107,6 @@ struct AddKeysContext
* *
* @param cls closure with a `struct AddKeysContext` * @param cls closure with a `struct AddKeysContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -115,7 +114,6 @@ struct AddKeysContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
add_keys (void *cls, add_keys (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct AddKeysContext *akc = cls; struct AddKeysContext *akc = cls;
@ -131,7 +129,6 @@ add_keys (void *cls,
/* For idempotency, check if the key is already active */ /* For idempotency, check if the key is already active */
qs = TEH_plugin->lookup_denomination_key ( qs = TEH_plugin->lookup_denomination_key (
TEH_plugin->cls, TEH_plugin->cls,
session,
&akc->d_sigs[i].h_denom_pub, &akc->d_sigs[i].h_denom_pub,
&meta); &meta);
if (qs < 0) if (qs < 0)
@ -207,7 +204,6 @@ add_keys (void *cls,
continue; /* skip, already known */ continue; /* skip, already known */
qs = TEH_plugin->add_denomination_key ( qs = TEH_plugin->add_denomination_key (
TEH_plugin->cls, TEH_plugin->cls,
session,
&akc->d_sigs[i].h_denom_pub, &akc->d_sigs[i].h_denom_pub,
&denom_pub, &denom_pub,
&meta, &meta,
@ -239,7 +235,6 @@ add_keys (void *cls,
qs = TEH_plugin->lookup_signing_key ( qs = TEH_plugin->lookup_signing_key (
TEH_plugin->cls, TEH_plugin->cls,
session,
&akc->s_sigs[i].exchange_pub, &akc->s_sigs[i].exchange_pub,
&meta); &meta);
if (qs < 0) if (qs < 0)
@ -297,7 +292,6 @@ add_keys (void *cls,
continue; /* skip, already known */ continue; /* skip, already known */
qs = TEH_plugin->activate_signing_key ( qs = TEH_plugin->activate_signing_key (
TEH_plugin->cls, TEH_plugin->cls,
session,
&akc->s_sigs[i].exchange_pub, &akc->s_sigs[i].exchange_pub,
&meta, &meta,
&akc->s_sigs[i].master_sig); &akc->s_sigs[i].master_sig);

View File

@ -69,7 +69,6 @@ TEH_handler_management_signkeys_EP_revoke (
NULL); NULL);
} }
qs = TEH_plugin->insert_signkey_revocation (TEH_plugin->cls, qs = TEH_plugin->insert_signkey_revocation (TEH_plugin->cls,
NULL,
exchange_pub, exchange_pub,
&master_sig); &master_sig);
if (qs < 0) if (qs < 0)

View File

@ -65,7 +65,6 @@ struct DelWireContext
* *
* @param cls closure with a `struct DelWireContext` * @param cls closure with a `struct DelWireContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -73,7 +72,6 @@ struct DelWireContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
del_wire (void *cls, del_wire (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct DelWireContext *awc = cls; struct DelWireContext *awc = cls;
@ -81,7 +79,6 @@ del_wire (void *cls,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_wire_timestamp (TEH_plugin->cls, qs = TEH_plugin->lookup_wire_timestamp (TEH_plugin->cls,
session,
awc->payto_uri, awc->payto_uri,
&last_date); &last_date);
if (qs < 0) if (qs < 0)
@ -114,7 +111,6 @@ del_wire (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
qs = TEH_plugin->update_wire (TEH_plugin->cls, qs = TEH_plugin->update_wire (TEH_plugin->cls,
session,
awc->payto_uri, awc->payto_uri,
awc->validity_end, awc->validity_end,
false); false);

View File

@ -72,7 +72,6 @@ struct AddWireContext
* *
* @param cls closure with a `struct AddWireContext` * @param cls closure with a `struct AddWireContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -80,7 +79,6 @@ struct AddWireContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
add_wire (void *cls, add_wire (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct AddWireContext *awc = cls; struct AddWireContext *awc = cls;
@ -88,7 +86,6 @@ add_wire (void *cls,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->lookup_wire_timestamp (TEH_plugin->cls, qs = TEH_plugin->lookup_wire_timestamp (TEH_plugin->cls,
session,
awc->payto_uri, awc->payto_uri,
&last_date); &last_date);
if (qs < 0) if (qs < 0)
@ -114,13 +111,11 @@ add_wire (void *cls,
} }
if (0 == qs) if (0 == qs)
qs = TEH_plugin->insert_wire (TEH_plugin->cls, qs = TEH_plugin->insert_wire (TEH_plugin->cls,
session,
awc->payto_uri, awc->payto_uri,
awc->validity_start, awc->validity_start,
&awc->master_sig_wire); &awc->master_sig_wire);
else else
qs = TEH_plugin->update_wire (TEH_plugin->cls, qs = TEH_plugin->update_wire (TEH_plugin->cls,
session,
awc->payto_uri, awc->payto_uri,
awc->validity_start, awc->validity_start,
true); true);

View File

@ -80,7 +80,6 @@ struct AddFeeContext
* *
* @param cls closure with a `struct AddFeeContext` * @param cls closure with a `struct AddFeeContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -88,7 +87,6 @@ struct AddFeeContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
add_fee (void *cls, add_fee (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct AddFeeContext *afc = cls; struct AddFeeContext *afc = cls;
@ -98,7 +96,6 @@ add_fee (void *cls,
qs = TEH_plugin->lookup_wire_fee_by_time ( qs = TEH_plugin->lookup_wire_fee_by_time (
TEH_plugin->cls, TEH_plugin->cls,
session,
afc->wire_method, afc->wire_method,
afc->start_time, afc->start_time,
afc->end_time, afc->end_time,
@ -142,7 +139,6 @@ add_fee (void *cls,
qs = TEH_plugin->insert_wire_fee ( qs = TEH_plugin->insert_wire_fee (
TEH_plugin->cls, TEH_plugin->cls,
session,
afc->wire_method, afc->wire_method,
afc->start_time, afc->start_time,
afc->end_time, afc->end_time,

View File

@ -170,14 +170,12 @@ struct MeltContext
* melt operation. * melt operation.
* *
* @param connection the connection to send errors to * @param connection the connection to send errors to
* @param session the database connection
* @param[in,out] rmc melt context * @param[in,out] rmc melt context
* @param[out] mhd_ret status code to return to MHD on hard error * @param[out] mhd_ret status code to return to MHD on hard error
* @return transaction status code * @return transaction status code
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
refresh_check_melt (struct MHD_Connection *connection, refresh_check_melt (struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
struct MeltContext *rmc, struct MeltContext *rmc,
MHD_RESULT *mhd_ret) 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 /* get historic transaction costs of this coin, including recoups as
we might be a zombie coin */ we might be a zombie coin */
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls, qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
session,
&rmc->refresh_session.coin.coin_pub, &rmc->refresh_session.coin.coin_pub,
GNUNET_YES, GNUNET_YES,
&tl); &tl);
@ -301,7 +298,6 @@ refresh_check_melt (struct MHD_Connection *connection,
* *
* @param cls our `struct MeltContext` * @param cls our `struct MeltContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -309,7 +305,6 @@ refresh_check_melt (struct MHD_Connection *connection,
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
melt_transaction (void *cls, melt_transaction (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct MeltContext *rmc = cls; struct MeltContext *rmc = cls;
@ -321,7 +316,6 @@ melt_transaction (void *cls,
{ {
qs = TEH_make_coin_known (&rmc->refresh_session.coin, qs = TEH_make_coin_known (&rmc->refresh_session.coin,
connection, connection,
session,
mhd_ret); mhd_ret);
if (qs < 0) if (qs < 0)
return qs; return qs;
@ -329,7 +323,6 @@ melt_transaction (void *cls,
/* Check if we already created a matching refresh_session */ /* Check if we already created a matching refresh_session */
qs = TEH_plugin->get_melt_index (TEH_plugin->cls, qs = TEH_plugin->get_melt_index (TEH_plugin->cls,
session,
&rmc->refresh_session.rc, &rmc->refresh_session.rc,
&noreveal_index); &noreveal_index);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) 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 */ /* check coin has enough funds remaining on it to cover melt cost */
qs = refresh_check_melt (connection, qs = refresh_check_melt (connection,
session,
rmc, rmc,
mhd_ret); mhd_ret);
if (0 > qs) if (0 > qs)
@ -367,7 +359,6 @@ melt_transaction (void *cls,
TALER_CNC_KAPPA); TALER_CNC_KAPPA);
if (0 >= if (0 >=
(qs = TEH_plugin->insert_melt (TEH_plugin->cls, (qs = TEH_plugin->insert_melt (TEH_plugin->cls,
session,
&rmc->refresh_session))) &rmc->refresh_session)))
{ {
if (GNUNET_DB_STATUS_SOFT_ERROR != qs) if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
@ -511,7 +502,6 @@ check_for_denomination_key (struct MHD_Connection *connection,
revoked (those must be recouped) */ revoked (those must be recouped) */
qs = TEH_plugin->get_coin_denomination ( qs = TEH_plugin->get_coin_denomination (
TEH_plugin->cls, TEH_plugin->cls,
NULL,
&rmc->refresh_session.coin.coin_pub, &rmc->refresh_session.coin.coin_pub,
&denom_hash); &denom_hash);
if (0 > qs) if (0 > qs)

View File

@ -114,7 +114,6 @@ struct RecoupContext
* *
* @param cls the `struct RecoupContext *` * @param cls the `struct RecoupContext *`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status code * @return transaction status code
@ -122,7 +121,6 @@ struct RecoupContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
recoup_transaction (void *cls, recoup_transaction (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct RecoupContext *pc = cls; struct RecoupContext *pc = cls;
@ -135,7 +133,6 @@ recoup_transaction (void *cls,
/* make sure coin is 'known' in database */ /* make sure coin is 'known' in database */
qs = TEH_make_coin_known (pc->coin, qs = TEH_make_coin_known (pc->coin,
connection, connection,
session,
mhd_ret); mhd_ret);
if (qs < 0) if (qs < 0)
return qs; return qs;
@ -145,7 +142,6 @@ recoup_transaction (void *cls,
if (pc->refreshed) if (pc->refreshed)
{ {
qs = TEH_plugin->get_old_coin_by_h_blind (TEH_plugin->cls, qs = TEH_plugin->get_old_coin_by_h_blind (TEH_plugin->cls,
session,
&pc->h_blind, &pc->h_blind,
&pc->target.old_coin_pub); &pc->target.old_coin_pub);
if (0 > qs) if (0 > qs)
@ -164,7 +160,6 @@ recoup_transaction (void *cls,
else else
{ {
qs = TEH_plugin->get_reserve_by_h_blind (TEH_plugin->cls, qs = TEH_plugin->get_reserve_by_h_blind (TEH_plugin->cls,
session,
&pc->h_blind, &pc->h_blind,
&pc->target.reserve_pub); &pc->target.reserve_pub);
if (0 > qs) if (0 > qs)
@ -194,7 +189,6 @@ recoup_transaction (void *cls,
/* Calculate remaining balance, including recoups already applied. */ /* Calculate remaining balance, including recoups already applied. */
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls, qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
session,
&pc->coin->coin_pub, &pc->coin->coin_pub,
GNUNET_YES, GNUNET_YES,
&tl); &tl);
@ -270,8 +264,7 @@ recoup_transaction (void *cls,
/* Recoup has no effect: coin fully spent! */ /* Recoup has no effect: coin fully spent! */
enum GNUNET_DB_QueryStatus ret; enum GNUNET_DB_QueryStatus ret;
TEH_plugin->rollback (TEH_plugin->cls, TEH_plugin->rollback (TEH_plugin->cls);
session);
if (GNUNET_NO == existing_recoup_found) if (GNUNET_NO == existing_recoup_found)
{ {
/* Refuse: insufficient funds for recoup */ /* Refuse: insufficient funds for recoup */
@ -300,7 +293,6 @@ recoup_transaction (void *cls,
if (pc->refreshed) if (pc->refreshed)
{ {
qs = TEH_plugin->insert_recoup_refresh_request (TEH_plugin->cls, qs = TEH_plugin->insert_recoup_refresh_request (TEH_plugin->cls,
session,
pc->coin, pc->coin,
pc->coin_sig, pc->coin_sig,
pc->coin_bks, pc->coin_bks,
@ -311,7 +303,6 @@ recoup_transaction (void *cls,
else else
{ {
qs = TEH_plugin->insert_recoup_request (TEH_plugin->cls, qs = TEH_plugin->insert_recoup_request (TEH_plugin->cls,
session,
&pc->target.reserve_pub, &pc->target.reserve_pub,
pc->coin, pc->coin,
pc->coin_sig, pc->coin_sig,

View File

@ -201,7 +201,6 @@ check_exists_cb (void *cls,
* *
* @param cls closure of type `struct RevealContext` * @param cls closure of type `struct RevealContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -209,7 +208,6 @@ check_exists_cb (void *cls,
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
refreshes_reveal_preflight (void *cls, refreshes_reveal_preflight (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct RevealContext *rctx = cls; struct RevealContext *rctx = cls;
@ -217,7 +215,6 @@ refreshes_reveal_preflight (void *cls,
/* Try to see if we already have given an answer before. */ /* Try to see if we already have given an answer before. */
qs = TEH_plugin->get_refresh_reveal (TEH_plugin->cls, qs = TEH_plugin->get_refresh_reveal (TEH_plugin->cls,
session,
&rctx->rc, &rctx->rc,
&check_exists_cb, &check_exists_cb,
rctx); rctx);
@ -258,7 +255,6 @@ refreshes_reveal_preflight (void *cls,
* *
* @param cls closure of type `struct RevealContext` * @param cls closure of type `struct RevealContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -266,7 +262,6 @@ refreshes_reveal_preflight (void *cls,
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
refreshes_reveal_transaction (void *cls, refreshes_reveal_transaction (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct RevealContext *rctx = cls; struct RevealContext *rctx = cls;
@ -276,7 +271,6 @@ refreshes_reveal_transaction (void *cls,
/* Obtain basic information about the refresh operation and what /* Obtain basic information about the refresh operation and what
gamma we committed to. */ gamma we committed to. */
qs = TEH_plugin->get_melt (TEH_plugin->cls, qs = TEH_plugin->get_melt (TEH_plugin->cls,
session,
&rctx->rc, &rctx->rc,
&melt); &melt);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 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 cls closure of type `struct RevealContext`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -449,7 +442,6 @@ refreshes_reveal_transaction (void *cls,
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
refreshes_reveal_persist (void *cls, refreshes_reveal_persist (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct RevealContext *rctx = cls; struct RevealContext *rctx = cls;
@ -470,7 +462,6 @@ refreshes_reveal_persist (void *cls,
rrc->coin_sig = rctx->ev_sigs[i]; rrc->coin_sig = rctx->ev_sigs[i];
} }
qs = TEH_plugin->insert_refresh_reveal (TEH_plugin->cls, qs = TEH_plugin->insert_refresh_reveal (TEH_plugin->cls,
session,
&rctx->rc, &rctx->rc,
rctx->num_fresh_coins, rctx->num_fresh_coins,
rrcs, rrcs,
@ -621,7 +612,6 @@ resolve_refreshes_reveal_denominations (struct MHD_Connection *connection,
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
(qs = TEH_plugin->get_melt (TEH_plugin->cls, (qs = TEH_plugin->get_melt (TEH_plugin->cls,
NULL,
&rctx->rc, &rctx->rc,
&melt))) &melt)))
{ {

View File

@ -94,7 +94,6 @@ reply_refund_success (struct MHD_Connection *connection,
* *
* @param cls closure with a `const struct TALER_EXCHANGEDB_Refund *` * @param cls closure with a `const struct TALER_EXCHANGEDB_Refund *`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -102,7 +101,6 @@ reply_refund_success (struct MHD_Connection *connection,
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
refund_transaction (void *cls, refund_transaction (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
const struct TALER_EXCHANGEDB_Refund *refund = cls; const struct TALER_EXCHANGEDB_Refund *refund = cls;
@ -118,7 +116,6 @@ refund_transaction (void *cls,
tl = NULL; tl = NULL;
qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls, qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
session,
&refund->coin.coin_pub, &refund->coin.coin_pub,
GNUNET_NO, GNUNET_NO,
&tl); &tl);
@ -344,7 +341,6 @@ refund_transaction (void *cls,
/* Finally, store new refund data */ /* Finally, store new refund data */
qs = TEH_plugin->insert_refund (TEH_plugin->cls, qs = TEH_plugin->insert_refund (TEH_plugin->cls,
session,
refund); refund);
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{ {
@ -407,7 +403,6 @@ verify_and_execute_refund (struct MHD_Connection *connection,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->get_coin_denomination (TEH_plugin->cls, qs = TEH_plugin->get_coin_denomination (TEH_plugin->cls,
NULL,
&refund->coin.coin_pub, &refund->coin.coin_pub,
&denom_hash); &denom_hash);
if (0 > qs) if (0 > qs)

View File

@ -54,7 +54,7 @@ struct ReservePoller
* Subscription for the database event we are * Subscription for the database event we are
* waiting for. * waiting for.
*/ */
struct TALER_EXCHANGEDB_EventHandler *eh; struct GNUNET_DB_EventHandler *eh;
/** /**
* When will this request time out? * When will this request time out?
@ -110,8 +110,11 @@ rp_cleanup (struct TEH_RequestContext *rc)
{ {
struct ReservePoller *rp = rc->rh_ctx; struct ReservePoller *rp = rc->rh_ctx;
GNUNET_assert (! rp->suspended);
if (NULL != rp->eh) if (NULL != rp->eh)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Cancelling DB event listening\n");
TEH_plugin->event_listen_cancel (TEH_plugin->cls, TEH_plugin->event_listen_cancel (TEH_plugin->cls,
rp->eh); rp->eh);
rp->eh = NULL; rp->eh = NULL;
@ -153,6 +156,7 @@ db_event_cb (void *cls,
rp_tail, rp_tail,
rp); rp);
MHD_resume_connection (rp->connection); MHD_resume_connection (rp->connection);
TALER_MHD_daemon_trigger ();
GNUNET_async_scope_restore (&old_scope); GNUNET_async_scope_restore (&old_scope);
} }
@ -218,7 +222,6 @@ struct ReserveHistoryContext
* *
* @param cls a `struct ReserveHistoryContext *` * @param cls a `struct ReserveHistoryContext *`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!); unused * if transaction failed (!); unused
* @return transaction status * @return transaction status
@ -226,7 +229,6 @@ struct ReserveHistoryContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
reserve_history_transaction (void *cls, reserve_history_transaction (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct ReserveHistoryContext *rsc = cls; struct ReserveHistoryContext *rsc = cls;
@ -234,7 +236,6 @@ reserve_history_transaction (void *cls,
(void) connection; (void) connection;
(void) mhd_ret; (void) mhd_ret;
return TEH_plugin->get_reserve_history (TEH_plugin->cls, return TEH_plugin->get_reserve_history (TEH_plugin->cls,
session,
&rsc->reserve_pub, &rsc->reserve_pub,
&rsc->rh); &rsc->rh);
} }
@ -247,7 +248,7 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
struct ReserveHistoryContext rsc; struct ReserveHistoryContext rsc;
MHD_RESULT mhd_ret; MHD_RESULT mhd_ret;
struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO; struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO;
struct TALER_EXCHANGEDB_EventHandler *eh = NULL; struct GNUNET_DB_EventHandler *eh = NULL;
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_STRINGS_string_to_data (args[0], GNUNET_STRINGS_string_to_data (args[0],
@ -288,7 +289,8 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
timeout_ms); timeout_ms);
} }
} }
if (! GNUNET_TIME_relative_is_zero (timeout)) if ( (! GNUNET_TIME_relative_is_zero (timeout)) &&
(NULL == rc->rh_ctx) )
{ {
struct TALER_ReserveEventP rep = { struct TALER_ReserveEventP rep = {
.header.size = htons (sizeof (rep)), .header.size = htons (sizeof (rep)),
@ -296,6 +298,8 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
.reserve_pub = rsc.reserve_pub .reserve_pub = rsc.reserve_pub
}; };
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Starting DB event listening\n");
eh = TEH_plugin->event_listen (TEH_plugin->cls, eh = TEH_plugin->event_listen (TEH_plugin->cls,
timeout, timeout,
&rep.header, &rep.header,
@ -309,7 +313,12 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
&mhd_ret, &mhd_ret,
&reserve_history_transaction, &reserve_history_transaction,
&rsc)) &rsc))
{
if (NULL != eh)
TEH_plugin->event_listen_cancel (TEH_plugin->cls,
eh);
return mhd_ret; return mhd_ret;
}
/* generate proper response */ /* generate proper response */
if (NULL == rsc.rh) if (NULL == rsc.rh)
{ {
@ -340,6 +349,9 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc,
MHD_suspend_connection (rc->connection); MHD_suspend_connection (rc->connection);
return MHD_YES; return MHD_YES;
} }
if (NULL != eh)
TEH_plugin->event_listen_cancel (TEH_plugin->cls,
eh);
mhd_ret = reply_reserve_history_success (rc->connection, mhd_ret = reply_reserve_history_success (rc->connection,
rsc.rh); rsc.rh);
TEH_plugin->free_reserve_history (TEH_plugin->cls, TEH_plugin->free_reserve_history (TEH_plugin->cls,

View File

@ -406,7 +406,6 @@ free_ctx (struct WtidTransactionContext *ctx)
* *
* @param cls closure * @param cls closure
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -414,7 +413,6 @@ free_ctx (struct WtidTransactionContext *ctx)
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
get_transfer_deposits (void *cls, get_transfer_deposits (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct WtidTransactionContext *ctx = cls; struct WtidTransactionContext *ctx = cls;
@ -428,7 +426,6 @@ get_transfer_deposits (void *cls,
serialization failure */ serialization failure */
free_ctx (ctx); free_ctx (ctx);
qs = TEH_plugin->lookup_wire_transfer (TEH_plugin->cls, qs = TEH_plugin->lookup_wire_transfer (TEH_plugin->cls,
session,
&ctx->wtid, &ctx->wtid,
&handle_deposit_data, &handle_deposit_data,
ctx); ctx);
@ -462,7 +459,6 @@ get_transfer_deposits (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
qs = TEH_plugin->get_wire_fee (TEH_plugin->cls, qs = TEH_plugin->get_wire_fee (TEH_plugin->cls,
session,
ctx->wire_method, ctx->wire_method,
ctx->exec_time, ctx->exec_time,
&wire_fee_start_date, &wire_fee_start_date,

View File

@ -152,7 +152,6 @@ struct WithdrawContext
* *
* @param cls a `struct WithdrawContext *` * @param cls a `struct WithdrawContext *`
* @param connection MHD request which triggered the transaction * @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, * @param[out] mhd_ret set to MHD response status for @a connection,
* if transaction failed (!) * if transaction failed (!)
* @return transaction status * @return transaction status
@ -160,7 +159,6 @@ struct WithdrawContext
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
withdraw_transaction (void *cls, withdraw_transaction (void *cls,
struct MHD_Connection *connection, struct MHD_Connection *connection,
struct TALER_EXCHANGEDB_Session *session,
MHD_RESULT *mhd_ret) MHD_RESULT *mhd_ret)
{ {
struct WithdrawContext *wc = cls; struct WithdrawContext *wc = cls;
@ -175,7 +173,6 @@ withdraw_transaction (void *cls,
wc->collectable.sig.rsa_signature = NULL; wc->collectable.sig.rsa_signature = NULL;
#endif #endif
qs = TEH_plugin->get_withdraw_info (TEH_plugin->cls, qs = TEH_plugin->get_withdraw_info (TEH_plugin->cls,
session,
&wc->wsrd.h_coin_envelope, &wc->wsrd.h_coin_envelope,
&wc->collectable); &wc->collectable);
if (0 > qs) if (0 > qs)
@ -212,7 +209,6 @@ withdraw_transaction (void *cls,
"Trying to withdraw from reserve: %s\n", "Trying to withdraw from reserve: %s\n",
TALER_B2S (&r.pub)); TALER_B2S (&r.pub));
qs = TEH_plugin->reserves_get (TEH_plugin->cls, qs = TEH_plugin->reserves_get (TEH_plugin->cls,
session,
&r); &r);
if (0 > qs) if (0 > qs)
{ {
@ -253,7 +249,6 @@ withdraw_transaction (void *cls,
} }
#endif #endif
qs = TEH_plugin->get_reserve_history (TEH_plugin->cls, qs = TEH_plugin->get_reserve_history (TEH_plugin->cls,
session,
&wc->wsrd.reserve_pub, &wc->wsrd.reserve_pub,
&rh); &rh);
if (NULL == rh) if (NULL == rh)
@ -300,7 +295,6 @@ withdraw_transaction (void *cls,
wc->collectable.h_coin_envelope = wc->wsrd.h_coin_envelope; wc->collectable.h_coin_envelope = wc->wsrd.h_coin_envelope;
wc->collectable.reserve_sig = wc->signature; wc->collectable.reserve_sig = wc->signature;
qs = TEH_plugin->insert_withdraw_info (TEH_plugin->cls, qs = TEH_plugin->insert_withdraw_info (TEH_plugin->cls,
session,
&wc->collectable); &wc->collectable);
if (0 > qs) if (0 > qs)
{ {

View File

@ -37,11 +37,6 @@
struct WirePrepareData struct WirePrepareData
{ {
/**
* Database session for all of our transactions.
*/
struct TALER_EXCHANGEDB_Session *session;
/** /**
* Wire execution handle. * Wire execution handle.
*/ */
@ -140,8 +135,7 @@ shutdown_task (void *cls)
TALER_BANK_transfer_cancel (wpd->eh); TALER_BANK_transfer_cancel (wpd->eh);
wpd->eh = NULL; wpd->eh = NULL;
} }
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
wpd->session);
GNUNET_free (wpd); GNUNET_free (wpd);
wpd = NULL; wpd = NULL;
} }
@ -196,16 +190,14 @@ parse_wirewatch_config (void)
/** /**
* Perform a database commit. If it fails, print a warning. * Perform a database commit. If it fails, print a warning.
* *
* @param session session to perform the commit for.
* @return status of commit * @return status of commit
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
commit_or_warn (struct TALER_EXCHANGEDB_Session *session) commit_or_warn (void)
{ {
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = db_plugin->commit (db_plugin->cls, qs = db_plugin->commit (db_plugin->cls);
session);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
return qs; return qs;
GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs) GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs)
@ -245,7 +237,6 @@ wire_confirm_cb (void *cls,
uint64_t row_id, uint64_t row_id,
struct GNUNET_TIME_Absolute wire_timestamp) struct GNUNET_TIME_Absolute wire_timestamp)
{ {
struct TALER_EXCHANGEDB_Session *session = wpd->session;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
(void) cls; (void) cls;
@ -256,7 +247,6 @@ wire_confirm_cb (void *cls,
{ {
case MHD_HTTP_OK: case MHD_HTTP_OK:
qs = db_plugin->wire_prepare_data_mark_finished (db_plugin->cls, qs = db_plugin->wire_prepare_data_mark_finished (db_plugin->cls,
session,
wpd->row_id); wpd->row_id);
/* continued below */ /* continued below */
break; break;
@ -267,7 +257,6 @@ wire_confirm_cb (void *cls,
http_status_code, http_status_code,
ec); ec);
qs = db_plugin->wire_prepare_data_mark_failed (db_plugin->cls, qs = db_plugin->wire_prepare_data_mark_failed (db_plugin->cls,
session,
wpd->row_id); wpd->row_id);
/* continued below */ /* continued below */
break; break;
@ -276,8 +265,7 @@ wire_confirm_cb (void *cls,
"Wire transaction failed: %u/%d\n", "Wire transaction failed: %u/%d\n",
http_status_code, http_status_code,
ec); ec);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
GNUNET_free (wpd); GNUNET_free (wpd);
@ -287,8 +275,7 @@ wire_confirm_cb (void *cls,
if (0 >= qs) if (0 >= qs)
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
if (GNUNET_DB_STATUS_SOFT_ERROR == qs) if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
{ {
/* try again */ /* try again */
@ -307,7 +294,7 @@ wire_confirm_cb (void *cls,
} }
GNUNET_free (wpd); GNUNET_free (wpd);
wpd = NULL; wpd = NULL;
switch (commit_or_warn (session)) switch (commit_or_warn ())
{ {
case GNUNET_DB_STATUS_SOFT_ERROR: case GNUNET_DB_STATUS_SOFT_ERROR:
/* try again */ /* try again */
@ -362,8 +349,7 @@ wire_prepare_cb (void *cls,
(NULL == buf) ) (NULL == buf) )
{ {
GNUNET_break (0); GNUNET_break (0);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
wpd->session);
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
goto cleanup; goto cleanup;
} }
@ -377,8 +363,7 @@ wire_prepare_cb (void *cls,
/* Should really never happen here, as when we get /* Should really never happen here, as when we get
here the wire account should be in the cache. */ here the wire account should be in the cache. */
GNUNET_break (0); GNUNET_break (0);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
wpd->session);
global_ret = EXIT_NOTCONFIGURED; global_ret = EXIT_NOTCONFIGURED;
goto cleanup; goto cleanup;
} }
@ -392,8 +377,7 @@ wire_prepare_cb (void *cls,
if (NULL == wpd->eh) if (NULL == wpd->eh)
{ {
GNUNET_break (0); /* Irrecoverable */ GNUNET_break (0); /* Irrecoverable */
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
wpd->session);
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
goto cleanup; goto cleanup;
} }
@ -415,23 +399,22 @@ static void
run_transfers (void *cls) run_transfers (void *cls)
{ {
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
struct TALER_EXCHANGEDB_Session *session;
(void) cls; (void) cls;
task = NULL; task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking for pending wire transfers\n"); "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, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to obtain database session!\n"); "Failed to obtain database connection!\n");
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
} }
if (GNUNET_OK != if (GNUNET_OK !=
db_plugin->start (db_plugin->cls, db_plugin->start (db_plugin->cls,
session,
"aggregator run transfer")) "aggregator run transfer"))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -441,15 +424,12 @@ run_transfers (void *cls)
return; return;
} }
wpd = GNUNET_new (struct WirePrepareData); wpd = GNUNET_new (struct WirePrepareData);
wpd->session = session;
qs = db_plugin->wire_prepare_data_get (db_plugin->cls, qs = db_plugin->wire_prepare_data_get (db_plugin->cls,
session,
&wire_prepare_cb, &wire_prepare_cb,
NULL); NULL);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
return; /* continued via continuation set in #wire_prepare_cb() */ return; /* continued via continuation set in #wire_prepare_cb() */
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
GNUNET_free (wpd); GNUNET_free (wpd);
wpd = NULL; wpd = NULL;
switch (qs) switch (qs)

View File

@ -62,11 +62,6 @@ struct WireAccount
*/ */
const struct TALER_EXCHANGEDB_AccountInfo *ai; const struct TALER_EXCHANGEDB_AccountInfo *ai;
/**
* Database session we are using for the current transaction.
*/
struct TALER_EXCHANGEDB_Session *session;
/** /**
* Active request for history. * Active request for history.
*/ */
@ -355,8 +350,7 @@ find_transfers (void *cls);
static void static void
handle_soft_error (struct WireAccount *wa) handle_soft_error (struct WireAccount *wa)
{ {
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
wa->session);
if (1 < wa->batch_size) if (1 < wa->batch_size)
{ {
wa->batch_thresh = 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 */ /* shard is complete, mark this as well */
qs = db_plugin->complete_shard (db_plugin->cls, qs = db_plugin->complete_shard (db_plugin->cls,
wa->session,
wa->job_name, wa->job_name,
wa->shard_start, wa->shard_start,
wa->shard_end); wa->shard_end);
@ -394,8 +387,7 @@ do_commit (struct WireAccount *wa)
{ {
case GNUNET_DB_STATUS_HARD_ERROR: case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0); GNUNET_break (0);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
wa->session);
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
case GNUNET_DB_STATUS_SOFT_ERROR: case GNUNET_DB_STATUS_SOFT_ERROR:
@ -413,8 +405,7 @@ do_commit (struct WireAccount *wa)
break; break;
} }
} }
qs = db_plugin->commit (db_plugin->cls, qs = db_plugin->commit (db_plugin->cls);
wa->session);
switch (qs) switch (qs)
{ {
case GNUNET_DB_STATUS_HARD_ERROR: case GNUNET_DB_STATUS_HARD_ERROR:
@ -432,7 +423,6 @@ do_commit (struct WireAccount *wa)
} }
/* transaction success, update #last_row_off */ /* transaction success, update #last_row_off */
wa->batch_start = wa->latest_row_off; wa->batch_start = wa->latest_row_off;
wa->session = NULL; /* should not be needed */
if (wa->batch_size < MAXIMUM_BATCH_SIZE) if (wa->batch_size < MAXIMUM_BATCH_SIZE)
{ {
int delta; int delta;
@ -492,7 +482,6 @@ history_cb (void *cls,
const json_t *json) const json_t *json)
{ {
struct WireAccount *wa = cls; struct WireAccount *wa = cls;
struct TALER_EXCHANGEDB_Session *session = wa->session;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
(void) json; (void) json;
@ -518,8 +507,7 @@ history_cb (void *cls,
"Serial ID %llu not monotonic (got %llu before). Failing!\n", "Serial ID %llu not monotonic (got %llu before). Failing!\n",
(unsigned long long) serial_id, (unsigned long long) serial_id,
(unsigned long long) wa->latest_row_off); (unsigned long long) wa->latest_row_off);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
wa->hh = NULL; wa->hh = NULL;
return GNUNET_SYSERR; return GNUNET_SYSERR;
@ -547,7 +535,6 @@ history_cb (void *cls,
(Note: this may require changing both the (Note: this may require changing both the
plugin API as well as modifying how this function is called.) */ plugin API as well as modifying how this function is called.) */
qs = db_plugin->reserves_in_insert (db_plugin->cls, qs = db_plugin->reserves_in_insert (db_plugin->cls,
session,
&details->reserve_pub, &details->reserve_pub,
&details->amount, &details->amount,
details->execution_date, details->execution_date,
@ -558,8 +545,7 @@ history_cb (void *cls,
{ {
case GNUNET_DB_STATUS_HARD_ERROR: case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0); GNUNET_break (0);
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
wa->hh = NULL; wa->hh = NULL;
return GNUNET_SYSERR; return GNUNET_SYSERR;
@ -590,23 +576,22 @@ history_cb (void *cls,
static void static void
find_transfers (void *cls) find_transfers (void *cls)
{ {
struct TALER_EXCHANGEDB_Session *session;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
unsigned int limit; unsigned int limit;
(void) cls; (void) cls;
task = NULL; 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, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to obtain database session!\n"); "Failed to obtain database connection!\n");
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
} }
wa_pos->delay = true; wa_pos->delay = true;
wa_pos->current_batch_size = 0; /* reset counter */ wa_pos->current_batch_size = 0; /* reset counter */
wa_pos->session = session;
if (wa_pos->shard_end <= wa_pos->batch_start) if (wa_pos->shard_end <= wa_pos->batch_start)
{ {
uint64_t start; uint64_t start;
@ -662,7 +647,6 @@ find_transfers (void *cls)
} }
if (GNUNET_OK != if (GNUNET_OK !=
db_plugin->start_read_committed (db_plugin->cls, db_plugin->start_read_committed (db_plugin->cls,
session,
"wirewatch check for incoming wire transfers")) "wirewatch check for incoming wire transfers"))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -689,8 +673,7 @@ find_transfers (void *cls)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to start request for account history!\n"); "Failed to start request for account history!\n");
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls);
session);
global_ret = EXIT_FAILURE; global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;

View File

@ -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

View File

@ -29,12 +29,10 @@
* Function called with denominations records to insert into table. * Function called with denominations records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_denominations (struct PostgresClosure *pg, irbt_cb_table_denominations (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_HashCode denom_hash; struct GNUNET_HashCode denom_hash;
@ -65,12 +63,11 @@ irbt_cb_table_denominations (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg;
GNUNET_CRYPTO_rsa_public_key_hash ( GNUNET_CRYPTO_rsa_public_key_hash (
td->details.denominations.denom_pub.rsa_public_key, td->details.denominations.denom_pub.rsa_public_key,
&denom_hash); &denom_hash);
return GNUNET_PQ_eval_prepared_non_select (session->conn, return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_into_table_denominations", "insert_into_table_denominations",
params); params);
} }
@ -80,14 +77,12 @@ irbt_cb_table_denominations (struct PostgresClosure *pg,
* Function called with denomination_revocations records to insert into table. * Function called with denomination_revocations records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_denomination_revocations (struct PostgresClosure *pg, irbt_cb_table_denomination_revocations (
struct TALER_EXCHANGEDB_Session *session, struct PostgresClosure *pg,
const struct const struct TALER_EXCHANGEDB_TableData *td)
TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_uint64 (&td->serial),
@ -98,8 +93,7 @@ irbt_cb_table_denomination_revocations (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_denomination_revocations", "insert_into_table_denomination_revocations",
params); params);
} }
@ -109,12 +103,10 @@ irbt_cb_table_denomination_revocations (struct PostgresClosure *pg,
* Function called with reserves records to insert into table. * Function called with reserves records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_reserves (struct PostgresClosure *pg, irbt_cb_table_reserves (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -127,8 +119,7 @@ irbt_cb_table_reserves (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_reserves", "insert_into_table_reserves",
params); params);
} }
@ -138,12 +129,10 @@ irbt_cb_table_reserves (struct PostgresClosure *pg,
* Function called with reserves_in records to insert into table. * Function called with reserves_in records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_reserves_in (struct PostgresClosure *pg, irbt_cb_table_reserves_in (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -160,8 +149,7 @@ irbt_cb_table_reserves_in (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_reserves_in", "insert_into_table_reserves_in",
params); params);
} }
@ -171,12 +159,10 @@ irbt_cb_table_reserves_in (struct PostgresClosure *pg,
* Function called with reserves_close records to insert into table. * Function called with reserves_close records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_reserves_close (struct PostgresClosure *pg, irbt_cb_table_reserves_close (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -191,8 +177,7 @@ irbt_cb_table_reserves_close (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_reserves_close", "insert_into_table_reserves_close",
params); params);
} }
@ -202,12 +187,10 @@ irbt_cb_table_reserves_close (struct PostgresClosure *pg,
* Function called with reserves_out records to insert into table. * Function called with reserves_out records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_reserves_out (struct PostgresClosure *pg, irbt_cb_table_reserves_out (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -226,8 +209,7 @@ irbt_cb_table_reserves_out (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_reserves_out", "insert_into_table_reserves_out",
params); params);
} }
@ -237,12 +219,10 @@ irbt_cb_table_reserves_out (struct PostgresClosure *pg,
* Function called with auditors records to insert into table. * Function called with auditors records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_auditors (struct PostgresClosure *pg, irbt_cb_table_auditors (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
uint8_t is_active = td->details.auditors.is_active ? 1 : 0; uint8_t is_active = td->details.auditors.is_active ? 1 : 0;
@ -256,8 +236,7 @@ irbt_cb_table_auditors (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_auditors", "insert_into_table_auditors",
params); params);
} }
@ -267,12 +246,10 @@ irbt_cb_table_auditors (struct PostgresClosure *pg,
* Function called with auditor_denom_sigs records to insert into table. * Function called with auditor_denom_sigs records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_auditor_denom_sigs (struct PostgresClosure *pg, irbt_cb_table_auditor_denom_sigs (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -285,8 +262,7 @@ irbt_cb_table_auditor_denom_sigs (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_auditor_denom_sigs", "insert_into_table_auditor_denom_sigs",
params); params);
} }
@ -296,12 +272,10 @@ irbt_cb_table_auditor_denom_sigs (struct PostgresClosure *pg,
* Function called with exchange_sign_keys records to insert into table. * Function called with exchange_sign_keys records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_exchange_sign_keys (struct PostgresClosure *pg, irbt_cb_table_exchange_sign_keys (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -319,8 +293,7 @@ irbt_cb_table_exchange_sign_keys (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_exchange_sign_keys", "insert_into_table_exchange_sign_keys",
params); params);
} }
@ -330,12 +303,10 @@ irbt_cb_table_exchange_sign_keys (struct PostgresClosure *pg,
* Function called with signkey_revocations records to insert into table. * Function called with signkey_revocations records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_signkey_revocations (struct PostgresClosure *pg, irbt_cb_table_signkey_revocations (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -346,8 +317,7 @@ irbt_cb_table_signkey_revocations (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_signkey_revocations", "insert_into_table_signkey_revocations",
params); params);
} }
@ -357,12 +327,10 @@ irbt_cb_table_signkey_revocations (struct PostgresClosure *pg,
* Function called with known_coins records to insert into table. * Function called with known_coins records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_known_coins (struct PostgresClosure *pg, irbt_cb_table_known_coins (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -375,8 +343,7 @@ irbt_cb_table_known_coins (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_known_coins", "insert_into_table_known_coins",
params); params);
} }
@ -386,12 +353,10 @@ irbt_cb_table_known_coins (struct PostgresClosure *pg,
* Function called with refresh_commitments records to insert into table. * Function called with refresh_commitments records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_refresh_commitments (struct PostgresClosure *pg, irbt_cb_table_refresh_commitments (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -408,8 +373,7 @@ irbt_cb_table_refresh_commitments (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_refresh_commitments", "insert_into_table_refresh_commitments",
params); params);
} }
@ -419,14 +383,12 @@ irbt_cb_table_refresh_commitments (struct PostgresClosure *pg,
* Function called with refresh_revealed_coins records to insert into table. * Function called with refresh_revealed_coins records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_refresh_revealed_coins (struct PostgresClosure *pg, irbt_cb_table_refresh_revealed_coins (
struct TALER_EXCHANGEDB_Session *session, struct PostgresClosure *pg,
const struct const struct TALER_EXCHANGEDB_TableData *td)
TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_HashCode h_coin_ev; struct GNUNET_HashCode h_coin_ev;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -449,11 +411,10 @@ irbt_cb_table_refresh_revealed_coins (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg;
GNUNET_CRYPTO_hash (td->details.refresh_revealed_coins.coin_ev, GNUNET_CRYPTO_hash (td->details.refresh_revealed_coins.coin_ev,
td->details.refresh_revealed_coins.coin_ev_size, td->details.refresh_revealed_coins.coin_ev_size,
&h_coin_ev); &h_coin_ev);
return GNUNET_PQ_eval_prepared_non_select (session->conn, return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_into_table_refresh_revealed_coins", "insert_into_table_refresh_revealed_coins",
params); params);
} }
@ -463,13 +424,11 @@ irbt_cb_table_refresh_revealed_coins (struct PostgresClosure *pg,
* Function called with refresh_transfer_keys records to insert into table. * Function called with refresh_transfer_keys records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_refresh_transfer_keys ( irbt_cb_table_refresh_transfer_keys (
struct PostgresClosure *pg, struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -485,8 +444,7 @@ irbt_cb_table_refresh_transfer_keys (
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_refresh_transfer_keys", "insert_into_table_refresh_transfer_keys",
params); params);
} }
@ -496,12 +454,10 @@ irbt_cb_table_refresh_transfer_keys (
* Function called with deposits records to insert into table. * Function called with deposits records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_deposits (struct PostgresClosure *pg, irbt_cb_table_deposits (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
uint8_t tiny = td->details.deposits.tiny ? 1 : 0; uint8_t tiny = td->details.deposits.tiny ? 1 : 0;
@ -527,10 +483,9 @@ irbt_cb_table_deposits (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg;
TALER_JSON_merchant_wire_signature_hash (td->details.deposits.wire, TALER_JSON_merchant_wire_signature_hash (td->details.deposits.wire,
&h_wire); &h_wire);
return GNUNET_PQ_eval_prepared_non_select (session->conn, return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_into_table_deposits", "insert_into_table_deposits",
params); params);
} }
@ -540,12 +495,10 @@ irbt_cb_table_deposits (struct PostgresClosure *pg,
* Function called with refunds records to insert into table. * Function called with refunds records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_refunds (struct PostgresClosure *pg, irbt_cb_table_refunds (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -557,8 +510,7 @@ irbt_cb_table_refunds (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_refunds", "insert_into_table_refunds",
params); params);
} }
@ -568,12 +520,10 @@ irbt_cb_table_refunds (struct PostgresClosure *pg,
* Function called with wire_out records to insert into table. * Function called with wire_out records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_wire_out (struct PostgresClosure *pg, irbt_cb_table_wire_out (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -587,8 +537,7 @@ irbt_cb_table_wire_out (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_wire_out", "insert_into_table_wire_out",
params); params);
} }
@ -598,12 +547,10 @@ irbt_cb_table_wire_out (struct PostgresClosure *pg,
* Function called with aggregation_tracking records to insert into table. * Function called with aggregation_tracking records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_aggregation_tracking (struct PostgresClosure *pg, irbt_cb_table_aggregation_tracking (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -615,8 +562,7 @@ irbt_cb_table_aggregation_tracking (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_aggregation_tracking", "insert_into_table_aggregation_tracking",
params); params);
} }
@ -626,12 +572,10 @@ irbt_cb_table_aggregation_tracking (struct PostgresClosure *pg,
* Function called with wire_fee records to insert into table. * Function called with wire_fee records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_wire_fee (struct PostgresClosure *pg, irbt_cb_table_wire_fee (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -645,8 +589,7 @@ irbt_cb_table_wire_fee (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_wire_fee", "insert_into_table_wire_fee",
params); params);
} }
@ -656,12 +599,10 @@ irbt_cb_table_wire_fee (struct PostgresClosure *pg,
* Function called with recoup records to insert into table. * Function called with recoup records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_recoup (struct PostgresClosure *pg, irbt_cb_table_recoup (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -675,8 +616,7 @@ irbt_cb_table_recoup (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_recoup", "insert_into_table_recoup",
params); params);
} }
@ -686,12 +626,10 @@ irbt_cb_table_recoup (struct PostgresClosure *pg,
* Function called with recoup_refresh records to insert into table. * Function called with recoup_refresh records to insert into table.
* *
* @param pg plugin context * @param pg plugin context
* @param session database session
* @param td record to insert * @param td record to insert
*/ */
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
irbt_cb_table_recoup_refresh (struct PostgresClosure *pg, irbt_cb_table_recoup_refresh (struct PostgresClosure *pg,
struct TALER_EXCHANGEDB_Session *session,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -706,8 +644,7 @@ irbt_cb_table_recoup_refresh (struct PostgresClosure *pg,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
(void) pg; return GNUNET_PQ_eval_prepared_non_select (pg->conn,
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"insert_into_table_recoup_refresh", "insert_into_table_recoup_refresh",
params); params);
} }

File diff suppressed because it is too large Load Diff

View File

@ -95,8 +95,6 @@ mark_prepare_cb (void *cls,
const char *buf, const char *buf,
size_t buf_size) size_t buf_size)
{ {
struct TALER_EXCHANGEDB_Session *session = cls;
GNUNET_assert (11 == buf_size); GNUNET_assert (11 == buf_size);
GNUNET_assert (0 == strcasecmp (wire_method, GNUNET_assert (0 == strcasecmp (wire_method,
"testcase")); "testcase"));
@ -105,7 +103,6 @@ mark_prepare_cb (void *cls,
buf_size)); buf_size));
GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
plugin->wire_prepare_data_mark_finished (plugin->cls, plugin->wire_prepare_data_mark_finished (plugin->cls,
session,
rowid)); rowid));
} }
@ -113,31 +110,26 @@ mark_prepare_cb (void *cls,
/** /**
* Test API relating to persisting the wire plugins preparation data. * Test API relating to persisting the wire plugins preparation data.
* *
* @param session database session to use for the test
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
static int static int
test_wire_prepare (struct TALER_EXCHANGEDB_Session *session) test_wire_prepare (void)
{ {
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->wire_prepare_data_get (plugin->cls, plugin->wire_prepare_data_get (plugin->cls,
session,
&dead_prepare_cb, &dead_prepare_cb,
NULL)); NULL));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->wire_prepare_data_insert (plugin->cls, plugin->wire_prepare_data_insert (plugin->cls,
session,
"testcase", "testcase",
"hello world", "hello world",
11)); 11));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->wire_prepare_data_get (plugin->cls, plugin->wire_prepare_data_get (plugin->cls,
session,
&mark_prepare_cb, &mark_prepare_cb,
session)); NULL));
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->wire_prepare_data_get (plugin->cls, plugin->wire_prepare_data_get (plugin->cls,
session,
&dead_prepare_cb, &dead_prepare_cb,
NULL)); NULL));
return GNUNET_OK; return GNUNET_OK;
@ -149,7 +141,6 @@ drop:
/** /**
* Checks if the given reserve has the given amount of balance and expiry * Checks if the given reserve has the given amount of balance and expiry
* *
* @param session the database connection
* @param pub the public key of the reserve * @param pub the public key of the reserve
* @param value balance value * @param value balance value
* @param fraction balance fraction * @param fraction balance fraction
@ -158,8 +149,7 @@ drop:
* as the given parameters; #GNUNET_SYSERR if not * as the given parameters; #GNUNET_SYSERR if not
*/ */
static int static int
check_reserve (struct TALER_EXCHANGEDB_Session *session, check_reserve (const struct TALER_ReservePublicKeyP *pub,
const struct TALER_ReservePublicKeyP *pub,
uint64_t value, uint64_t value,
uint32_t fraction, uint32_t fraction,
const char *currency) const char *currency)
@ -169,7 +159,6 @@ check_reserve (struct TALER_EXCHANGEDB_Session *session,
reserve.pub = *pub; reserve.pub = *pub;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_get (plugin->cls, plugin->reserves_get (plugin->cls,
session,
&reserve)); &reserve));
FAILIF (value != reserve.balance.value); FAILIF (value != reserve.balance.value);
FAILIF (fraction != reserve.balance.fraction); FAILIF (fraction != reserve.balance.fraction);
@ -206,7 +195,6 @@ destroy_denom_key_pair (struct DenomKeyPair *dkp)
* Create a denominaiton key pair by registering the denomination in the DB. * Create a denominaiton key pair by registering the denomination in the DB.
* *
* @param size the size of the denomination key * @param size the size of the denomination key
* @param session the DB session
* @param now time to use for key generation, legal expiration will be 3h later. * @param now time to use for key generation, legal expiration will be 3h later.
* @param fee_withdraw withdraw fee to use * @param fee_withdraw withdraw fee to use
* @param fee_deposit deposit fee to use * @param fee_deposit deposit fee to use
@ -216,7 +204,6 @@ destroy_denom_key_pair (struct DenomKeyPair *dkp)
*/ */
static struct DenomKeyPair * static struct DenomKeyPair *
create_denom_key_pair (unsigned int size, create_denom_key_pair (unsigned int size,
struct TALER_EXCHANGEDB_Session *session,
struct GNUNET_TIME_Absolute now, struct GNUNET_TIME_Absolute now,
const struct TALER_Amount *value, const struct TALER_Amount *value,
const struct TALER_Amount *fee_withdraw, const struct TALER_Amount *fee_withdraw,
@ -269,7 +256,6 @@ create_denom_key_pair (unsigned int size,
TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY); TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_denomination_info (plugin->cls, plugin->insert_denomination_info (plugin->cls,
session,
&dki.denom_pub, &dki.denom_pub,
&dki.issue)) &dki.issue))
{ {
@ -279,7 +265,6 @@ create_denom_key_pair (unsigned int size,
} }
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_denomination_info (plugin->cls, plugin->get_denomination_info (plugin->cls,
session,
&dki.issue.properties.denom_hash, &dki.issue.properties.denom_hash,
&issue2)) &issue2))
{ {
@ -502,12 +487,10 @@ handle_link_data_cb (void *cls,
/** /**
* Function to test melting of coins as part of a refresh session * Function to test melting of coins as part of a refresh session
* *
* @param session the database session
* @param refresh_session the refresh session
* @return #GNUNET_OK if everything went well; #GNUNET_SYSERR if not * @return #GNUNET_OK if everything went well; #GNUNET_SYSERR if not
*/ */
static int static int
test_melting (struct TALER_EXCHANGEDB_Session *session) test_melting (void)
{ {
struct TALER_EXCHANGEDB_Refresh refresh_session; struct TALER_EXCHANGEDB_Refresh refresh_session;
struct TALER_EXCHANGEDB_Melt ret_refresh_session; struct TALER_EXCHANGEDB_Melt ret_refresh_session;
@ -528,7 +511,6 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
now = GNUNET_TIME_absolute_get (); now = GNUNET_TIME_absolute_get ();
GNUNET_TIME_round_abs (&now); GNUNET_TIME_round_abs (&now);
dkp = create_denom_key_pair (512, dkp = create_denom_key_pair (512,
session,
now, now,
&value, &value,
&fee_withdraw, &fee_withdraw,
@ -556,20 +538,16 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
/* test insert_melt & get_melt */ /* test insert_melt & get_melt */
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->get_melt (plugin->cls, plugin->get_melt (plugin->cls,
session,
&refresh_session.rc, &refresh_session.rc,
&ret_refresh_session)); &ret_refresh_session));
FAILIF (TALER_EXCHANGEDB_CKS_ADDED != FAILIF (TALER_EXCHANGEDB_CKS_ADDED !=
plugin->ensure_coin_known (plugin->cls, plugin->ensure_coin_known (plugin->cls,
session,
&refresh_session.coin)); &refresh_session.coin));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_melt (plugin->cls, plugin->insert_melt (plugin->cls,
session,
&refresh_session)); &refresh_session));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_melt (plugin->cls, plugin->get_melt (plugin->cls,
session,
&refresh_session.rc, &refresh_session.rc,
&ret_refresh_session)); &ret_refresh_session));
FAILIF (refresh_session.noreveal_index != FAILIF (refresh_session.noreveal_index !=
@ -597,7 +575,6 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
auditor_row_cnt = 0; auditor_row_cnt = 0;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_refreshes_above_serial_id (plugin->cls, plugin->select_refreshes_above_serial_id (plugin->cls,
session,
0, 0,
&audit_refresh_session_cb, &audit_refresh_session_cb,
NULL)); NULL));
@ -619,7 +596,6 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
now = GNUNET_TIME_absolute_get (); now = GNUNET_TIME_absolute_get ();
GNUNET_TIME_round_abs (&now); GNUNET_TIME_round_abs (&now);
new_dkp[cnt] = create_denom_key_pair (1024, new_dkp[cnt] = create_denom_key_pair (1024,
session,
now, now,
&value, &value,
&fee_withdraw, &fee_withdraw,
@ -646,13 +622,11 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
RND_BLK (&tpub); RND_BLK (&tpub);
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->get_refresh_reveal (plugin->cls, plugin->get_refresh_reveal (plugin->cls,
session,
&refresh_session.rc, &refresh_session.rc,
&never_called_cb, &never_called_cb,
NULL)); NULL));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_refresh_reveal (plugin->cls, plugin->insert_refresh_reveal (plugin->cls,
session,
&refresh_session.rc, &refresh_session.rc,
MELT_NEW_COINS, MELT_NEW_COINS,
revealed_coins, revealed_coins,
@ -661,14 +635,12 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
&tpub)); &tpub));
FAILIF (0 >= FAILIF (0 >=
plugin->get_refresh_reveal (plugin->cls, plugin->get_refresh_reveal (plugin->cls,
session,
&refresh_session.rc, &refresh_session.rc,
&check_refresh_reveal_cb, &check_refresh_reveal_cb,
NULL)); NULL));
qs = plugin->get_link_data (plugin->cls, qs = plugin->get_link_data (plugin->cls,
session,
&refresh_session.coin.coin_pub, &refresh_session.coin.coin_pub,
&handle_link_data_cb, &handle_link_data_cb,
NULL); NULL);
@ -679,7 +651,6 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = plugin->get_coin_transactions (plugin->cls, qs = plugin->get_coin_transactions (plugin->cls,
session,
&refresh_session.coin.coin_pub, &refresh_session.coin.coin_pub,
GNUNET_YES, GNUNET_YES,
&tl); &tl);
@ -1085,11 +1056,10 @@ audit_reserve_out_cb (void *cls,
/** /**
* Test garbage collection. * Test garbage collection.
* *
* @param session DB session to use
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
static int static int
test_gc (struct TALER_EXCHANGEDB_Session *session) test_gc (void)
{ {
struct DenomKeyPair *dkp; struct DenomKeyPair *dkp;
struct GNUNET_TIME_Absolute now; struct GNUNET_TIME_Absolute now;
@ -1104,7 +1074,6 @@ test_gc (struct TALER_EXCHANGEDB_Session *session)
GNUNET_TIME_UNIT_HOURS, GNUNET_TIME_UNIT_HOURS,
4)); 4));
dkp = create_denom_key_pair (1024, dkp = create_denom_key_pair (1024,
session,
past, past,
&value, &value,
&fee_withdraw, &fee_withdraw,
@ -1124,7 +1093,6 @@ test_gc (struct TALER_EXCHANGEDB_Session *session)
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->get_denomination_info (plugin->cls, plugin->get_denomination_info (plugin->cls,
session,
&denom_hash, &denom_hash,
&issue2)) &issue2))
{ {
@ -1140,11 +1108,10 @@ test_gc (struct TALER_EXCHANGEDB_Session *session)
/** /**
* Test wire fee storage. * Test wire fee storage.
* *
* @param session DB session to use
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
static int static int
test_wire_fees (struct TALER_EXCHANGEDB_Session *session) test_wire_fees (void)
{ {
struct GNUNET_TIME_Absolute start_date; struct GNUNET_TIME_Absolute start_date;
struct GNUNET_TIME_Absolute end_date; struct GNUNET_TIME_Absolute end_date;
@ -1172,7 +1139,6 @@ test_wire_fees (struct TALER_EXCHANGEDB_Session *session)
sizeof (master_sig)); sizeof (master_sig));
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_wire_fee (plugin->cls, plugin->insert_wire_fee (plugin->cls,
session,
"wire-method", "wire-method",
start_date, start_date,
end_date, end_date,
@ -1185,7 +1151,6 @@ test_wire_fees (struct TALER_EXCHANGEDB_Session *session)
} }
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->insert_wire_fee (plugin->cls, plugin->insert_wire_fee (plugin->cls,
session,
"wire-method", "wire-method",
start_date, start_date,
end_date, end_date,
@ -1200,7 +1165,6 @@ test_wire_fees (struct TALER_EXCHANGEDB_Session *session)
half-open interval [start_date,end_date) */ half-open interval [start_date,end_date) */
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->get_wire_fee (plugin->cls, plugin->get_wire_fee (plugin->cls,
session,
"wire-method", "wire-method",
end_date, end_date,
&sd, &sd,
@ -1214,7 +1178,6 @@ test_wire_fees (struct TALER_EXCHANGEDB_Session *session)
} }
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_wire_fee (plugin->cls, plugin->get_wire_fee (plugin->cls,
session,
"wire-method", "wire-method",
start_date, start_date,
&sd, &sd,
@ -1279,12 +1242,10 @@ audit_wire_cb (void *cls,
/** /**
* Test API relating to wire_out handling. * Test API relating to wire_out handling.
* *
* @param session database session to use for the test
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
static int static int
test_wire_out (struct TALER_EXCHANGEDB_Session *session, test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit)
const struct TALER_EXCHANGEDB_Deposit *deposit)
{ {
auditor_row_cnt = 0; auditor_row_cnt = 0;
memset (&wire_out_wtid, memset (&wire_out_wtid,
@ -1300,8 +1261,7 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
the aggregation table, so we need to start the special the aggregation table, so we need to start the special
transaction where this is allowed... */ transaction where this is allowed... */
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->start_deferred_wire_out (plugin->cls, plugin->start_deferred_wire_out (plugin->cls));
session));
/* setup values for wire transfer aggregation data */ /* setup values for wire transfer aggregation data */
merchant_pub_wt = deposit->merchant_pub; merchant_pub_wt = deposit->merchant_pub;
@ -1317,7 +1277,6 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
&coin_fee_wt)); &coin_fee_wt));
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->lookup_wire_transfer (plugin->cls, plugin->lookup_wire_transfer (plugin->cls,
session,
&wire_out_wtid, &wire_out_wtid,
&cb_wt_never, &cb_wt_never,
NULL)); NULL));
@ -1328,7 +1287,6 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
h_contract_terms_wt2.bits[0]++; h_contract_terms_wt2.bits[0]++;
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->lookup_transfer_by_deposit (plugin->cls, plugin->lookup_transfer_by_deposit (plugin->cls,
session,
&h_contract_terms_wt2, &h_contract_terms_wt2,
&h_wire_wt, &h_wire_wt,
&coin_pub_wt, &coin_pub_wt,
@ -1339,7 +1297,6 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
/* insert WT data */ /* insert WT data */
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_aggregation_tracking (plugin->cls, plugin->insert_aggregation_tracking (plugin->cls,
session,
&wire_out_wtid, &wire_out_wtid,
deposit_rowid)); deposit_rowid));
@ -1355,7 +1312,6 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
"this-is-my-salt")); "this-is-my-salt"));
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->store_wire_transfer_out (plugin->cls, plugin->store_wire_transfer_out (plugin->cls,
session,
wire_out_date, wire_out_date,
&wire_out_wtid, &wire_out_wtid,
wire_out_account, wire_out_account,
@ -1369,18 +1325,15 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
} }
/* And now the commit should still succeed! */ /* And now the commit should still succeed! */
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->commit (plugin->cls, plugin->commit (plugin->cls));
session));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->lookup_wire_transfer (plugin->cls, plugin->lookup_wire_transfer (plugin->cls,
session,
&wire_out_wtid, &wire_out_wtid,
&cb_wt_check, &cb_wt_check,
&cb_wt_never)); &cb_wt_never));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->lookup_transfer_by_deposit (plugin->cls, plugin->lookup_transfer_by_deposit (plugin->cls,
session,
&h_contract_terms_wt, &h_contract_terms_wt,
&h_wire_wt, &h_wire_wt,
&coin_pub_wt, &coin_pub_wt,
@ -1389,7 +1342,6 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session,
&cb_wtid_never)); &cb_wtid_never));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_wire_out_above_serial_id (plugin->cls, plugin->select_wire_out_above_serial_id (plugin->cls,
session,
0, 0,
&audit_wire_cb, &audit_wire_cb,
NULL)); NULL));
@ -1536,7 +1488,6 @@ static void
run (void *cls) run (void *cls)
{ {
struct GNUNET_CONFIGURATION_Handle *cfg = cls; struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct TALER_EXCHANGEDB_Session *session;
struct TALER_CoinSpendSignatureP coin_sig; struct TALER_CoinSpendSignatureP coin_sig;
struct GNUNET_TIME_Absolute deadline; struct GNUNET_TIME_Absolute deadline;
struct TALER_DenominationBlindingKeyP coin_blind; struct TALER_DenominationBlindingKeyP coin_blind;
@ -1566,7 +1517,6 @@ run (void *cls)
dkp = NULL; dkp = NULL;
rh = NULL; rh = NULL;
session = NULL;
deposit.coin.denom_sig.rsa_signature = NULL; deposit.coin.denom_sig.rsa_signature = NULL;
wire = GNUNET_JSON_PACK ( wire = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("payto_uri", GNUNET_JSON_pack_string ("payto_uri",
@ -1588,22 +1538,14 @@ run (void *cls)
result = 77; result = 77;
goto drop; goto drop;
} }
if (NULL == plugin->preflight (plugin->cls);
(session = plugin->get_session (plugin->cls)))
{
result = 77;
goto drop;
}
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->start (plugin->cls, plugin->start (plugin->cls,
session,
"test-1")); "test-1"));
/* test DB is empty */ /* test DB is empty */
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->select_recoup_above_serial_id (plugin->cls, plugin->select_recoup_above_serial_id (plugin->cls,
session,
0, 0,
&recoup_cb, &recoup_cb,
NULL)); NULL));
@ -1630,14 +1572,12 @@ run (void *cls)
result = 4; result = 4;
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->get_latest_reserve_in_reference (plugin->cls, plugin->get_latest_reserve_in_reference (plugin->cls,
session,
"exchange-account-1", "exchange-account-1",
&rr)); &rr));
now = GNUNET_TIME_absolute_get (); now = GNUNET_TIME_absolute_get ();
(void) GNUNET_TIME_round_abs (&now); (void) GNUNET_TIME_round_abs (&now);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_in_insert (plugin->cls, plugin->reserves_in_insert (plugin->cls,
session,
&reserve_pub, &reserve_pub,
&value, &value,
now, now,
@ -1646,13 +1586,11 @@ run (void *cls)
4)); 4));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls, plugin->get_latest_reserve_in_reference (plugin->cls,
session,
"exchange-account-1", "exchange-account-1",
&rr)); &rr));
FAILIF (4 != rr); FAILIF (4 != rr);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
check_reserve (session, check_reserve (&reserve_pub,
&reserve_pub,
value.value, value.value,
value.fraction, value.fraction,
value.currency)); value.currency));
@ -1660,7 +1598,6 @@ run (void *cls)
(void) GNUNET_TIME_round_abs (&now); (void) GNUNET_TIME_round_abs (&now);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_in_insert (plugin->cls, plugin->reserves_in_insert (plugin->cls,
session,
&reserve_pub, &reserve_pub,
&value, &value,
now, now,
@ -1669,18 +1606,15 @@ run (void *cls)
5)); 5));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls, plugin->get_latest_reserve_in_reference (plugin->cls,
session,
"exchange-account-1", "exchange-account-1",
&rr)); &rr));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls, plugin->get_latest_reserve_in_reference (plugin->cls,
session,
"exchange-account-1", "exchange-account-1",
&rr)); &rr));
FAILIF (5 != rr); FAILIF (5 != rr);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
check_reserve (session, check_reserve (&reserve_pub,
&reserve_pub,
value.value * 2, value.value * 2,
value.fraction * 2, value.fraction * 2,
value.currency)); value.currency));
@ -1688,7 +1622,6 @@ run (void *cls)
now = GNUNET_TIME_absolute_get (); now = GNUNET_TIME_absolute_get ();
(void) GNUNET_TIME_round_abs (&now); (void) GNUNET_TIME_round_abs (&now);
dkp = create_denom_key_pair (1024, dkp = create_denom_key_pair (1024,
session,
now, now,
&value, &value,
&fee_withdraw, &fee_withdraw,
@ -1710,18 +1643,15 @@ run (void *cls)
TALER_amount_set_zero (CURRENCY, &cbc.withdraw_fee)); TALER_amount_set_zero (CURRENCY, &cbc.withdraw_fee));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_withdraw_info (plugin->cls, plugin->insert_withdraw_info (plugin->cls,
session,
&cbc)); &cbc));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
check_reserve (session, check_reserve (&reserve_pub,
&reserve_pub,
value.value, value.value,
value.fraction, value.fraction,
value.currency)); value.currency));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_reserve_by_h_blind (plugin->cls, plugin->get_reserve_by_h_blind (plugin->cls,
session,
&cbc.h_coin_envelope, &cbc.h_coin_envelope,
&reserve_pub2)); &reserve_pub2));
FAILIF (0 != GNUNET_memcmp (&reserve_pub, FAILIF (0 != GNUNET_memcmp (&reserve_pub,
@ -1729,7 +1659,6 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_withdraw_info (plugin->cls, plugin->get_withdraw_info (plugin->cls,
session,
&cbc.h_coin_envelope, &cbc.h_coin_envelope,
&cbc2)); &cbc2));
FAILIF (0 != GNUNET_memcmp (&cbc2.reserve_sig, &cbc.reserve_sig)); FAILIF (0 != GNUNET_memcmp (&cbc2.reserve_sig, &cbc.reserve_sig));
@ -1751,7 +1680,6 @@ run (void *cls)
(void) GNUNET_TIME_round_abs (&deadline); (void) GNUNET_TIME_round_abs (&deadline);
FAILIF (TALER_EXCHANGEDB_CKS_ADDED != FAILIF (TALER_EXCHANGEDB_CKS_ADDED !=
plugin->ensure_coin_known (plugin->cls, plugin->ensure_coin_known (plugin->cls,
session,
&deposit.coin)); &deposit.coin));
{ {
struct TALER_EXCHANGEDB_Reserve pre_reserve; struct TALER_EXCHANGEDB_Reserve pre_reserve;
@ -1761,11 +1689,9 @@ run (void *cls)
pre_reserve.pub = reserve_pub; pre_reserve.pub = reserve_pub;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_get (plugin->cls, plugin->reserves_get (plugin->cls,
session,
&pre_reserve)); &pre_reserve));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_recoup_request (plugin->cls, plugin->insert_recoup_request (plugin->cls,
session,
&reserve_pub, &reserve_pub,
&deposit.coin, &deposit.coin,
&coin_sig, &coin_sig,
@ -1776,7 +1702,6 @@ run (void *cls)
post_reserve.pub = reserve_pub; post_reserve.pub = reserve_pub;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_get (plugin->cls, plugin->reserves_get (plugin->cls,
session,
&post_reserve)); &post_reserve));
FAILIF (0 >= FAILIF (0 >=
TALER_amount_subtract (&delta, TALER_amount_subtract (&delta,
@ -1788,7 +1713,6 @@ run (void *cls)
} }
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_recoup_above_serial_id (plugin->cls, plugin->select_recoup_above_serial_id (plugin->cls,
session,
0, 0,
&recoup_cb, &recoup_cb,
&coin_blind)); &coin_blind));
@ -1804,7 +1728,6 @@ run (void *cls)
(void) GNUNET_TIME_round_abs (&now); (void) GNUNET_TIME_round_abs (&now);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_reserve_closed (plugin->cls, plugin->insert_reserve_closed (plugin->cls,
session,
&reserve_pub, &reserve_pub,
now, now,
sndr, sndr,
@ -1812,15 +1735,13 @@ run (void *cls)
&amount_with_fee, &amount_with_fee,
&fee_closing)); &fee_closing));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
check_reserve (session, check_reserve (&reserve_pub,
&reserve_pub,
0, 0,
0, 0,
value.currency)); value.currency));
result = 7; result = 7;
qs = plugin->get_reserve_history (plugin->cls, qs = plugin->get_reserve_history (plugin->cls,
session,
&reserve_pub, &reserve_pub,
&rh); &rh);
FAILIF (0 > qs); FAILIF (0 > qs);
@ -1891,13 +1812,11 @@ run (void *cls)
auditor_row_cnt = 0; auditor_row_cnt = 0;
FAILIF (0 >= FAILIF (0 >=
plugin->select_reserves_in_above_serial_id (plugin->cls, plugin->select_reserves_in_above_serial_id (plugin->cls,
session,
0, 0,
&audit_reserve_in_cb, &audit_reserve_in_cb,
NULL)); NULL));
FAILIF (0 >= FAILIF (0 >=
plugin->select_withdrawals_above_serial_id (plugin->cls, plugin->select_withdrawals_above_serial_id (plugin->cls,
session,
0, 0,
&audit_reserve_out_cb, &audit_reserve_out_cb,
NULL)); NULL));
@ -1926,7 +1845,6 @@ run (void *cls)
result = 8; result = 8;
FAILIF (TALER_EXCHANGEDB_CKS_ADDED != FAILIF (TALER_EXCHANGEDB_CKS_ADDED !=
plugin->ensure_coin_known (plugin->cls, plugin->ensure_coin_known (plugin->cls,
session,
&deposit.coin)); &deposit.coin));
{ {
struct GNUNET_TIME_Absolute now; struct GNUNET_TIME_Absolute now;
@ -1937,12 +1855,10 @@ run (void *cls)
GNUNET_TIME_round_abs (&now); GNUNET_TIME_round_abs (&now);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_deposit (plugin->cls, plugin->insert_deposit (plugin->cls,
session,
now, now,
&deposit)); &deposit));
FAILIF (1 != FAILIF (1 !=
plugin->have_deposit (plugin->cls, plugin->have_deposit (plugin->cls,
session,
&deposit, &deposit,
GNUNET_YES, GNUNET_YES,
&deposit_fee, &deposit_fee,
@ -1959,7 +1875,6 @@ run (void *cls)
GNUNET_TIME_UNIT_SECONDS); GNUNET_TIME_UNIT_SECONDS);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_deposits_missing_wire (plugin->cls, plugin->select_deposits_missing_wire (plugin->cls,
session,
start_range, start_range,
end_range, end_range,
&wire_missing_cb, &wire_missing_cb,
@ -1969,7 +1884,6 @@ run (void *cls)
auditor_row_cnt = 0; auditor_row_cnt = 0;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_deposits_above_serial_id (plugin->cls, plugin->select_deposits_above_serial_id (plugin->cls,
session,
0, 0,
&audit_deposit_cb, &audit_deposit_cb,
NULL)); NULL));
@ -1977,7 +1891,6 @@ run (void *cls)
result = 9; result = 9;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->iterate_matching_deposits (plugin->cls, plugin->iterate_matching_deposits (plugin->cls,
session,
&deposit.h_wire, &deposit.h_wire,
&deposit.merchant_pub, &deposit.merchant_pub,
&matching_deposit_cb, &matching_deposit_cb,
@ -1986,53 +1899,41 @@ run (void *cls)
sleep (2); /* giv deposit time to be ready */ sleep (2); /* giv deposit time to be ready */
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_ready_deposit (plugin->cls, plugin->get_ready_deposit (plugin->cls,
session,
&deposit_cb, &deposit_cb,
&deposit)); &deposit));
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->commit (plugin->cls, plugin->commit (plugin->cls));
session));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->start (plugin->cls, plugin->start (plugin->cls,
session,
"test-2")); "test-2"));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->mark_deposit_tiny (plugin->cls, plugin->mark_deposit_tiny (plugin->cls,
session,
deposit_rowid)); deposit_rowid));
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->get_ready_deposit (plugin->cls, plugin->get_ready_deposit (plugin->cls,
session,
&deposit_cb, &deposit_cb,
&deposit)); &deposit));
plugin->rollback (plugin->cls, plugin->rollback (plugin->cls);
session);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_ready_deposit (plugin->cls, plugin->get_ready_deposit (plugin->cls,
session,
&deposit_cb, &deposit_cb,
&deposit)); &deposit));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->start (plugin->cls, plugin->start (plugin->cls,
session,
"test-3")); "test-3"));
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->test_deposit_done (plugin->cls, plugin->test_deposit_done (plugin->cls,
session,
&deposit.coin.coin_pub, &deposit.coin.coin_pub,
&deposit.merchant_pub, &deposit.merchant_pub,
&deposit.h_contract_terms, &deposit.h_contract_terms,
&deposit.h_wire)); &deposit.h_wire));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->mark_deposit_done (plugin->cls, plugin->mark_deposit_done (plugin->cls,
session,
deposit_rowid)); deposit_rowid));
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->commit (plugin->cls, plugin->commit (plugin->cls));
session));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->test_deposit_done (plugin->cls, plugin->test_deposit_done (plugin->cls,
session,
&deposit.coin.coin_pub, &deposit.coin.coin_pub,
&deposit.merchant_pub, &deposit.merchant_pub,
&deposit.h_contract_terms, &deposit.h_contract_terms,
@ -2042,7 +1943,6 @@ run (void *cls)
deposit2 = deposit; deposit2 = deposit;
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->start (plugin->cls, plugin->start (plugin->cls,
session,
"test-2")); "test-2"));
RND_BLK (&deposit2.merchant_pub); /* should fail if merchant is different */ RND_BLK (&deposit2.merchant_pub); /* should fail if merchant is different */
{ {
@ -2051,7 +1951,6 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->have_deposit (plugin->cls, plugin->have_deposit (plugin->cls,
session,
&deposit2, &deposit2,
GNUNET_YES, GNUNET_YES,
&deposit_fee, &deposit_fee,
@ -2060,17 +1959,15 @@ run (void *cls)
RND_BLK (&deposit2.coin.coin_pub); /* should fail if coin is different */ RND_BLK (&deposit2.coin.coin_pub); /* should fail if coin is different */
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->have_deposit (plugin->cls, plugin->have_deposit (plugin->cls,
session,
&deposit2, &deposit2,
GNUNET_YES, GNUNET_YES,
&deposit_fee, &deposit_fee,
&r)); &r));
} }
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
test_melting (session)); test_melting ());
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->commit (plugin->cls, plugin->commit (plugin->cls));
session));
/* test insert_refund! */ /* test insert_refund! */
@ -2085,11 +1982,9 @@ run (void *cls)
refund.details.refund_fee = fee_refund; refund.details.refund_fee = fee_refund;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_refund (plugin->cls, plugin->insert_refund (plugin->cls,
session,
&refund)); &refund));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_refunds_by_coin (plugin->cls, plugin->select_refunds_by_coin (plugin->cls,
session,
&refund.coin.coin_pub, &refund.coin.coin_pub,
&refund.details.merchant_pub, &refund.details.merchant_pub,
&refund.details.h_contract_terms, &refund.details.h_contract_terms,
@ -2100,30 +1995,22 @@ run (void *cls)
RND_BLK (&master_sig); RND_BLK (&master_sig);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_denomination_revocation (plugin->cls, plugin->insert_denomination_revocation (plugin->cls,
session,
&dkp_pub_hash, &dkp_pub_hash,
&master_sig)); &master_sig));
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->commit (plugin->cls, plugin->commit (plugin->cls));
session)); plugin->preflight (plugin->cls);
plugin->preflight (plugin->cls,
session);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->start (plugin->cls, plugin->start (plugin->cls,
session,
"test-4")); "test-4"));
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->insert_denomination_revocation (plugin->cls, plugin->insert_denomination_revocation (plugin->cls,
session,
&dkp_pub_hash, &dkp_pub_hash,
&master_sig)); &master_sig));
plugin->rollback (plugin->cls, plugin->rollback (plugin->cls);
session); plugin->preflight (plugin->cls);
plugin->preflight (plugin->cls,
session);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->start (plugin->cls, plugin->start (plugin->cls,
session,
"test-5")); "test-5"));
{ {
struct TALER_MasterSignatureP msig; struct TALER_MasterSignatureP msig;
@ -2131,7 +2018,6 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_denomination_revocation (plugin->cls, plugin->get_denomination_revocation (plugin->cls,
session,
&dkp_pub_hash, &dkp_pub_hash,
&msig, &msig,
&rev_rowid)); &rev_rowid));
@ -2144,7 +2030,6 @@ run (void *cls)
RND_BLK (&coin_blind); RND_BLK (&coin_blind);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_recoup_request (plugin->cls, plugin->insert_recoup_request (plugin->cls,
session,
&reserve_pub, &reserve_pub,
&deposit.coin, &deposit.coin,
&coin_sig, &coin_sig,
@ -2156,14 +2041,12 @@ run (void *cls)
auditor_row_cnt = 0; auditor_row_cnt = 0;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_refunds_above_serial_id (plugin->cls, plugin->select_refunds_above_serial_id (plugin->cls,
session,
0, 0,
&audit_refund_cb, &audit_refund_cb,
NULL)); NULL));
FAILIF (1 != auditor_row_cnt); FAILIF (1 != auditor_row_cnt);
qs = plugin->get_coin_transactions (plugin->cls, qs = plugin->get_coin_transactions (plugin->cls,
session,
&refund.coin.coin_pub, &refund.coin.coin_pub,
GNUNET_YES, GNUNET_YES,
&tl); &tl);
@ -2262,28 +2145,23 @@ run (void *cls)
plugin->free_coin_transaction_list (plugin->cls, plugin->free_coin_transaction_list (plugin->cls,
tl); tl);
plugin->rollback (plugin->cls, plugin->rollback (plugin->cls);
session);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
test_wire_prepare (session)); test_wire_prepare ());
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
test_wire_out (session, test_wire_out (&deposit));
&deposit));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
test_gc (session)); test_gc ());
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
test_wire_fees (session)); test_wire_fees ());
plugin->preflight (plugin->cls, plugin->preflight (plugin->cls);
session);
result = 0; result = 0;
drop: drop:
if ( (0 != result) && if (0 != result)
(NULL != session) ) plugin->rollback (plugin->cls);
plugin->rollback (plugin->cls,
session);
if (NULL != rh) if (NULL != rh)
plugin->free_reserve_history (plugin->cls, plugin->free_reserve_history (plugin->cls,
rh); rh);

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER 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 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 terms of the GNU Affero General Public License as published by the Free Software
@ -1164,6 +1164,8 @@ typedef void
* *
* @param exchange the exchange handle; the exchange must be ready to operate * @param exchange the exchange handle; the exchange must be ready to operate
* @param reserve_pub public key of the reserve to inspect * @param reserve_pub public key of the reserve to inspect
* @param timeout how long to wait for an affirmative reply
* (enables long polling if the reserve does not yet exist)
* @param cb the callback to call when a reply for this request is available * @param cb the callback to call when a reply for this request is available
* @param cb_cls closure for the above callback * @param cb_cls closure for the above callback
* @return a handle for this request; NULL if the inputs are invalid (i.e. * @return a handle for this request; NULL if the inputs are invalid (i.e.
@ -1173,6 +1175,7 @@ struct TALER_EXCHANGE_ReservesGetHandle *
TALER_EXCHANGE_reserves_get ( TALER_EXCHANGE_reserves_get (
struct TALER_EXCHANGE_Handle *exchange, struct TALER_EXCHANGE_Handle *exchange,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
struct GNUNET_TIME_Relative timeout,
TALER_EXCHANGE_ReservesGetCallback cb, TALER_EXCHANGE_ReservesGetCallback cb,
void *cb_cls); void *cb_cls);

File diff suppressed because it is too large Load Diff

View File

@ -467,6 +467,35 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
uint16_t *port); uint16_t *port);
/**
* Start to run an event loop for @a daemon.
* Only one daemon can be running per process
* using this API.
*
* @param daemon the MHD service to run
*/
void
TALER_MHD_daemon_start (struct MHD_Daemon *daemon);
/**
* Stop running the event loop for MHD.
*
* @return the daemon that we were previously running,
* or NULL if none was active
*/
struct MHD_Daemon *
TALER_MHD_daemon_stop (void);
/**
* Trigger MHD daemon that is running. Needed when
* a connection was resumed.
*/
void
TALER_MHD_daemon_trigger (void);
/** /**
* Prepared responses for legal documents * Prepared responses for legal documents
* (terms of service, privacy policy). * (terms of service, privacy policy).

View File

@ -105,10 +105,6 @@ struct TALER_TESTING_DatabaseConnection
*/ */
struct TALER_EXCHANGEDB_Plugin *plugin; struct TALER_EXCHANGEDB_Plugin *plugin;
/**
* Session with the database.
*/
struct TALER_EXCHANGEDB_Session *session;
}; };
struct TALER_TESTING_LibeufinServices struct TALER_TESTING_LibeufinServices

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER 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 TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software terms of the GNU General Public License as published by the Free Software
@ -234,33 +234,18 @@ handle_reserves_get_finished (void *cls,
} }
/**
* Submit a request to obtain the transaction history of a reserve
* from the exchange. Note that while we return the full response to the
* caller for further processing, we do already verify that the
* response is well-formed (i.e. that signatures included in the
* response are all valid and add up to the balance). If the exchange's
* reply is not well-formed, we return an HTTP status code of zero to
* @a cb.
*
* @param exchange the exchange handle; the exchange must be ready to operate
* @param reserve_pub public key of the reserve to inspect
* @param cb the callback to call when a reply for this request is available
* @param cb_cls closure for the above callback
* @return a handle for this request; NULL if the inputs are invalid (i.e.
* signatures fail to verify). In this case, the callback is not called.
*/
struct TALER_EXCHANGE_ReservesGetHandle * struct TALER_EXCHANGE_ReservesGetHandle *
TALER_EXCHANGE_reserves_get (struct TALER_EXCHANGE_Handle *exchange, TALER_EXCHANGE_reserves_get (
const struct struct TALER_EXCHANGE_Handle *exchange,
TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
TALER_EXCHANGE_ReservesGetCallback cb, struct GNUNET_TIME_Relative timeout,
void *cb_cls) TALER_EXCHANGE_ReservesGetCallback cb,
void *cb_cls)
{ {
struct TALER_EXCHANGE_ReservesGetHandle *rgh; struct TALER_EXCHANGE_ReservesGetHandle *rgh;
struct GNUNET_CURL_Context *ctx; struct GNUNET_CURL_Context *ctx;
CURL *eh; CURL *eh;
char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 16]; char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 16 + 32];
if (GNUNET_YES != if (GNUNET_YES !=
TEAH_handle_is_ready (exchange)) TEAH_handle_is_ready (exchange))
@ -271,17 +256,31 @@ TALER_EXCHANGE_reserves_get (struct TALER_EXCHANGE_Handle *exchange,
{ {
char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2]; char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2];
char *end; char *end;
char timeout_str[32];
end = GNUNET_STRINGS_data_to_string (reserve_pub, end = GNUNET_STRINGS_data_to_string (
sizeof (struct reserve_pub,
TALER_ReservePublicKeyP), sizeof (struct TALER_ReservePublicKeyP),
pub_str, pub_str,
sizeof (pub_str)); sizeof (pub_str));
*end = '\0'; *end = '\0';
GNUNET_snprintf (arg_str, GNUNET_snprintf (timeout_str,
sizeof (arg_str), sizeof (timeout_str),
"/reserves/%s", "%llu",
pub_str); (unsigned long long)
(timeout.rel_value_us
/ GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us));
if (GNUNET_TIME_relative_is_zero (timeout))
GNUNET_snprintf (arg_str,
sizeof (arg_str),
"/reserves/%s",
pub_str);
else
GNUNET_snprintf (arg_str,
sizeof (arg_str),
"/reserves/%s?timeout_ms=%s",
pub_str,
timeout_str);
} }
rgh = GNUNET_new (struct TALER_EXCHANGE_ReservesGetHandle); rgh = GNUNET_new (struct TALER_EXCHANGE_ReservesGetHandle);
rgh->exchange = exchange; rgh->exchange = exchange;
@ -312,15 +311,9 @@ TALER_EXCHANGE_reserves_get (struct TALER_EXCHANGE_Handle *exchange,
} }
/**
* Cancel a reserve status request. This function cannot be used
* on a request handle if a response is already served for it.
*
* @param rgh the reserve status request handle
*/
void void
TALER_EXCHANGE_reserves_get_cancel (struct TALER_EXCHANGE_reserves_get_cancel (
TALER_EXCHANGE_ReservesGetHandle *rgh) struct TALER_EXCHANGE_ReservesGetHandle *rgh)
{ {
if (NULL != rgh->job) if (NULL != rgh->job)
{ {
@ -332,4 +325,4 @@ TALER_EXCHANGE_reserves_get_cancel (struct
} }
/* end of exchange_api_reserve.c */ /* end of exchange_api_reserves_get.c */

View File

@ -13,7 +13,8 @@ libtalermhd_la_SOURCES = \
mhd_config.c \ mhd_config.c \
mhd_legal.c \ mhd_legal.c \
mhd_parsing.c \ mhd_parsing.c \
mhd_responses.c mhd_responses.c \
mhd_run.c
libtalermhd_la_LDFLAGS = \ libtalermhd_la_LDFLAGS = \
-version-info 0:0:0 \ -version-info 0:0:0 \
-no-undefined -no-undefined

View File

@ -322,6 +322,53 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
char *bind_to; char *bind_to;
struct GNUNET_NETWORK_Handle *nh; struct GNUNET_NETWORK_Handle *nh;
/* try systemd passing first */
{
const char *listen_pid;
const char *listen_fds;
/* 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 fh;
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");
if (-1 != fh)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Successfully obtained listen socket from hypervisor\n");
return fh;
}
}
}
/* now try configuration file */
*port = 0; *port = 0;
{ {
char *serve_unixpath; char *serve_unixpath;

174
src/mhd/mhd_run.c Normal file
View File

@ -0,0 +1,174 @@
/*
This file is part of TALER
Copyright (C) 2019-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
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 mhd_run.c
* @brief API for running an MHD daemon with the
* GNUnet scheduler
* @author Christian Grothoff
*/
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
#include <jansson.h>
#include <microhttpd.h>
#include "taler_util.h"
#include "taler_mhd_lib.h"
/**
* Set if we should immediately #MHD_run again.
*/
static int triggered;
/**
* Task running the HTTP server.
*/
static struct GNUNET_SCHEDULER_Task *mhd_task;
/**
* The MHD daemon we are running.
*/
static struct MHD_Daemon *mhd;
/**
* Function that queries MHD's select sets and
* starts the task waiting for them.
*/
static struct GNUNET_SCHEDULER_Task *
prepare_daemon (void);
/**
* Call MHD to process pending requests and then go back
* and schedule the next run.
*
* @param cls NULL
*/
static void
run_daemon (void *cls)
{
mhd_task = NULL;
do {
triggered = 0;
GNUNET_assert (MHD_YES ==
MHD_run (mhd));
} while (0 != triggered);
mhd_task = prepare_daemon ();
}
/**
* Function that queries MHD's select sets and starts the task waiting for
* them.
*
* @return task handle for the MHD task.
*/
static struct GNUNET_SCHEDULER_Task *
prepare_daemon (void)
{
struct GNUNET_SCHEDULER_Task *ret;
fd_set rs;
fd_set ws;
fd_set es;
struct GNUNET_NETWORK_FDSet *wrs;
struct GNUNET_NETWORK_FDSet *wws;
int max;
MHD_UNSIGNED_LONG_LONG timeout;
int haveto;
struct GNUNET_TIME_Relative tv;
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
wrs = GNUNET_NETWORK_fdset_create ();
wws = GNUNET_NETWORK_fdset_create ();
max = -1;
GNUNET_assert (MHD_YES ==
MHD_get_fdset (mhd,
&rs,
&ws,
&es,
&max));
haveto = MHD_get_timeout (mhd,
&timeout);
if (haveto == MHD_YES)
tv = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
timeout);
else
tv = GNUNET_TIME_UNIT_FOREVER_REL;
GNUNET_NETWORK_fdset_copy_native (wrs,
&rs,
max + 1);
GNUNET_NETWORK_fdset_copy_native (wws,
&ws,
max + 1);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding run_daemon select task\n");
ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
tv,
wrs,
wws,
&run_daemon,
NULL);
GNUNET_NETWORK_fdset_destroy (wrs);
GNUNET_NETWORK_fdset_destroy (wws);
return ret;
}
void
TALER_MHD_daemon_start (struct MHD_Daemon *daemon)
{
GNUNET_assert (NULL == mhd);
mhd = daemon;
mhd_task = prepare_daemon ();
}
struct MHD_Daemon *
TALER_MHD_daemon_stop (void)
{
struct MHD_Daemon *ret;
if (NULL != mhd_task)
{
GNUNET_SCHEDULER_cancel (mhd_task);
mhd_task = NULL;
}
ret = mhd;
mhd = NULL;
return ret;
}
void
TALER_MHD_daemon_trigger (void)
{
if (NULL != mhd_task)
{
GNUNET_SCHEDULER_cancel (mhd_task);
mhd_task = NULL;
run_daemon (NULL);
}
else
{
triggered = 1;
}
}
/* end of mhd_run.c */

View File

@ -41,7 +41,7 @@ static struct TALER_TESTING_ExchangeConfiguration ec;
static struct TALER_TESTING_BankConfiguration bc; static struct TALER_TESTING_BankConfiguration bc;
/** /**
* Contains plugin and session. * Contains plugin.
*/ */
static struct TALER_TESTING_DatabaseConnection dbc; static struct TALER_TESTING_DatabaseConnection dbc;
@ -499,8 +499,14 @@ prepare_database (void *cls,
TALER_TESTING_interpreter_fail (is); TALER_TESTING_interpreter_fail (is);
return; return;
} }
dbc.session = dbc.plugin->get_session (dbc.plugin->cls); if (GNUNET_OK !=
GNUNET_assert (NULL != dbc.session); dbc.plugin->preflight (dbc.plugin->cls))
{
GNUNET_break (0);
result = 77;
TALER_TESTING_interpreter_fail (is);
return;
}
GNUNET_SCHEDULER_add_shutdown (&unload_db, GNUNET_SCHEDULER_add_shutdown (&unload_db,
NULL); NULL);
run (NULL, run (NULL,

View File

@ -149,16 +149,13 @@ insert_deposit_run (void *cls,
if ( (GNUNET_OK != if ( (GNUNET_OK !=
ids->dbc->plugin->start (ids->dbc->plugin->cls, ids->dbc->plugin->start (ids->dbc->plugin->cls,
ids->dbc->session,
"talertestinglib: denomination insertion")) || "talertestinglib: denomination insertion")) ||
(GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
ids->dbc->plugin->insert_denomination_info (ids->dbc->plugin->cls, ids->dbc->plugin->insert_denomination_info (ids->dbc->plugin->cls,
ids->dbc->session,
&dpk, &dpk,
&issue)) || &issue)) ||
(GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
ids->dbc->plugin->commit (ids->dbc->plugin->cls, ids->dbc->plugin->commit (ids->dbc->plugin->cls)) )
ids->dbc->session)) )
{ {
TALER_TESTING_interpreter_fail (is); TALER_TESTING_interpreter_fail (is);
return; return;
@ -228,24 +225,19 @@ insert_deposit_run (void *cls,
/* finally, actually perform the DB operation */ /* finally, actually perform the DB operation */
if ( (GNUNET_OK != if ( (GNUNET_OK !=
ids->dbc->plugin->start (ids->dbc->plugin->cls, ids->dbc->plugin->start (ids->dbc->plugin->cls,
ids->dbc->session,
"libtalertesting: insert deposit")) || "libtalertesting: insert deposit")) ||
(0 > (0 >
ids->dbc->plugin->ensure_coin_known (ids->dbc->plugin->cls, ids->dbc->plugin->ensure_coin_known (ids->dbc->plugin->cls,
ids->dbc->session,
&deposit.coin)) || &deposit.coin)) ||
(GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
ids->dbc->plugin->insert_deposit (ids->dbc->plugin->cls, ids->dbc->plugin->insert_deposit (ids->dbc->plugin->cls,
ids->dbc->session,
ids->exchange_timestamp, ids->exchange_timestamp,
&deposit)) || &deposit)) ||
(GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
ids->dbc->plugin->commit (ids->dbc->plugin->cls, ids->dbc->plugin->commit (ids->dbc->plugin->cls)) )
ids->dbc->session)) )
{ {
GNUNET_break (0); GNUNET_break (0);
ids->dbc->plugin->rollback (ids->dbc->plugin->cls, ids->dbc->plugin->rollback (ids->dbc->plugin->cls);
ids->dbc->session);
TALER_TESTING_interpreter_fail (is); TALER_TESTING_interpreter_fail (is);
} }
@ -302,7 +294,7 @@ insert_deposit_traits (void *cls,
* Make the "insert-deposit" CMD. * Make the "insert-deposit" CMD.
* *
* @param label command label. * @param label command label.
* @param dbc collects database plugin and session handles. * @param dbc collects database plugin
* @param merchant_name Human-readable name of the merchant. * @param merchant_name Human-readable name of the merchant.
* @param merchant_account merchant's account name (NOT a payto:// URI) * @param merchant_account merchant's account name (NOT a payto:// URI)
* @param exchange_timestamp when did the exchange receive the deposit * @param exchange_timestamp when did the exchange receive the deposit

View File

@ -356,6 +356,7 @@ status_run (void *cls,
} }
ss->rsh = TALER_EXCHANGE_reserves_get (is->exchange, ss->rsh = TALER_EXCHANGE_reserves_get (is->exchange,
ss->reserve_pubp, ss->reserve_pubp,
GNUNET_TIME_UNIT_ZERO,
&reserve_status_cb, &reserve_status_cb,
ss); ss);
} }

View File

@ -559,7 +559,8 @@ TALER_TESTING_wait_auditor_ready (const char *base_url)
base_url); // make sure ends with '/' base_url); // make sure ends with '/'
/* give child time to start and bind against the socket */ /* give child time to start and bind against the socket */
fprintf (stderr, fprintf (stderr,
"Waiting for `taler-auditor-httpd' to be ready\n"); "Waiting for `taler-auditor-httpd' to be ready at %s\n",
base_url);
iter = 0; iter = 0;
do do
{ {