commit ba84aba61bc56e38173af55936b81685f01c7f88
parent 26c9f368f2f8d11ac91cf47c669ca2cac248b2fd
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 15 Jun 2025 19:59:03 +0200
adjust to API changes needed for #10024
Diffstat:
2 files changed, 67 insertions(+), 145 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -122,12 +122,12 @@ AS_CASE([$with_exchange],
CPPFLAGS="-I$with_exchange/include $CPPFLAGS $POSTGRESQL_CPPFLAGS"])
AC_CHECK_HEADERS([taler/taler_mhd_lib.h],
- [AC_CHECK_LIB([talermhd], [TALER_MHD_reply_with_error], libtalermhd=1)])
+ [AC_CHECK_LIB([talermhd], [TALER_MHD_listen_bind], libtalermhd=1)])
AM_CONDITIONAL(HAVE_TALERMHD, test x$libtalermhd = x1)
AS_IF([test $libtalermhd != 1],
[AC_MSG_ERROR([[
***
-*** You need libtalermhd >= 0.14.3 (API v3) to build this program.
+*** You need libtalermhd >= 1.1.0 (API v6) to build this program.
*** This library is part of the GNU Taler exchange, available at
*** https://taler.net
*** ]])])
diff --git a/src/challenger/challenger-httpd.c b/src/challenger/challenger-httpd.c
@@ -38,12 +38,6 @@
/**
- * Backlog for listen operation on unix-domain sockets.
- */
-#define UNIX_BACKLOG 500
-
-
-/**
* Should a "Connection: close" header be added to each HTTP response?
*/
static int CH_challenger_connection_close;
@@ -59,19 +53,14 @@ struct GNUNET_CURL_Context *CH_ctx;
static struct GNUNET_CURL_RescheduleContext *rc;
/**
- * Task running the HTTP server.
- */
-static struct GNUNET_SCHEDULER_Task *mhd_task;
-
-/**
* Global return code
*/
static int global_ret;
/**
- * The MHD Daemon
+ * True if we started any HTTP daemon.
*/
-static struct MHD_Daemon *mhd;
+static bool have_daemons;
/**
* Connection handle to the our database
@@ -371,12 +360,8 @@ do_shutdown (void *cls)
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Stopping challenger-httpd\n");
+ TALER_MHD_daemons_halt ();
CH_wakeup_challenge_on_shutdown ();
- if (NULL != mhd_task)
- {
- GNUNET_SCHEDULER_cancel (mhd_task);
- mhd_task = NULL;
- }
if ( (NULL != CH_message_template) &&
(MAP_FAILED != CH_message_template) )
{
@@ -388,6 +373,7 @@ do_shutdown (void *cls)
CH_message_template = NULL;
CH_message_template_len = 0;
}
+ TALER_MHD_daemons_destroy ();
if (NULL != CH_ctx)
{
GNUNET_CURL_fini (CH_ctx);
@@ -398,11 +384,6 @@ do_shutdown (void *cls)
GNUNET_CURL_gnunet_rc_destroy (rc);
rc = NULL;
}
- if (NULL != mhd)
- {
- MHD_stop_daemon (mhd);
- mhd = NULL;
- }
if (NULL != CH_db)
{
CHALLENGER_DB_plugin_unload (CH_db);
@@ -455,57 +436,17 @@ handle_mhd_completion_callback (void *cls,
/**
- * Function that queries MHD's select sets and
- * starts the task waiting for them.
- */
-static struct GNUNET_SCHEDULER_Task *
-prepare_daemon (void);
-
-
-/**
- * Set if we should immediately #MHD_run again.
- */
-static int triggered;
-
-
-/**
- * Call MHD to process pending requests and then go back
- * and schedule the next run.
- *
- * @param cls the `struct MHD_Daemon` of the HTTP server to run
- */
-static void
-run_daemon (void *cls)
-{
- (void) cls;
- mhd_task = NULL;
- do {
- triggered = 0;
- GNUNET_assert (MHD_YES == MHD_run (mhd));
- } while (0 != triggered);
- mhd_task = prepare_daemon ();
-}
-
-
-/**
* Kick MHD to run now, to be called after MHD_resume_connection().
* Basically, we need to explicitly resume MHD's event loop whenever
* we made progress serving a request. This function re-schedules
* the task processing MHD's activities to run immediately.
+ *
+ * FIXME: replace by direct call...
*/
void
CH_trigger_daemon ()
{
- if (NULL != mhd_task)
- {
- GNUNET_SCHEDULER_cancel (mhd_task);
- mhd_task = GNUNET_SCHEDULER_add_now (&run_daemon,
- NULL);
- }
- else
- {
- triggered = 1;
- }
+ TALER_MHD_daemon_trigger ();
}
@@ -520,55 +461,42 @@ CH_trigger_curl ()
/**
- * Function that queries MHD's select sets and
- * starts the task waiting for them.
+ * Callback invoked on every listen socket to start the
+ * respective MHD HTTP daemon.
*
- * @return task that runs the next MHD interaction
+ * @param cls unused
+ * @param lsock the listen socket
*/
-static struct GNUNET_SCHEDULER_Task *
-prepare_daemon (void)
+static void
+start_daemon (void *cls,
+ int lsock)
{
- 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.rel_value_us = (uint64_t) timeout * 1000LL;
- 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;
+ struct MHD_Daemon *mhd;
+
+ (void) cls;
+ GNUNET_assert (-1 != lsock);
+ mhd = MHD_start_daemon (MHD_USE_SUSPEND_RESUME | MHD_USE_DUAL_STACK,
+ 0 /* port */,
+ NULL, NULL,
+ &url_handler, NULL,
+ MHD_OPTION_LISTEN_SOCKET, lsock,
+ MHD_OPTION_URI_LOG_CALLBACK,
+ &full_url_track_callback, NULL,
+ MHD_OPTION_NOTIFY_COMPLETED,
+ &handle_mhd_completion_callback, NULL,
+ MHD_OPTION_CONNECTION_TIMEOUT,
+ (unsigned int) 10 /* 10s */,
+ MHD_OPTION_END);
+ if (NULL == mhd)
+ {
+ global_ret = EXIT_NO_RESTART;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to launch HTTP daemon.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ have_daemons = true;
+ TALER_MHD_daemon_start (mhd);
}
@@ -587,9 +515,7 @@ run (void *cls,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
- int fh;
enum TALER_MHD_GlobalOptions go;
- uint16_t port;
(void) cls;
(void) args;
@@ -808,38 +734,34 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- fh = TALER_MHD_bind (config,
- "challenger",
- &port);
- if ( (0 == port) &&
- (-1 == fh) )
- {
- global_ret = EXIT_NOPERMISSION;
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- mhd = MHD_start_daemon (MHD_USE_SUSPEND_RESUME | MHD_USE_DUAL_STACK,
- port,
- NULL, NULL,
- &url_handler, NULL,
- MHD_OPTION_LISTEN_SOCKET, fh,
- MHD_OPTION_URI_LOG_CALLBACK,
- &full_url_track_callback, NULL,
- MHD_OPTION_NOTIFY_COMPLETED,
- &handle_mhd_completion_callback, NULL,
- MHD_OPTION_CONNECTION_TIMEOUT,
- (unsigned int) 10 /* 10s */,
- MHD_OPTION_END);
- if (NULL == mhd)
{
- global_ret = EXIT_NO_RESTART;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to launch HTTP service, exiting.\n");
- GNUNET_SCHEDULER_shutdown ();
- return;
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = TALER_MHD_listen_bind (config,
+ "challenger",
+ &start_daemon,
+ NULL);
+ switch (ret)
+ {
+ case GNUNET_SYSERR:
+ global_ret = EXIT_NOTCONFIGURED;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ case GNUNET_NO:
+ if (! have_daemons)
+ {
+ global_ret = EXIT_NOTCONFIGURED;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Could not open all configured listen sockets\n");
+ break;
+ case GNUNET_OK:
+ break;
+ }
}
global_ret = EXIT_SUCCESS;
- mhd_task = prepare_daemon ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Challenger-httpd ready\n");
}