twister

HTTP fault injector for testing
Log | Files | Refs | README | LICENSE

commit 46e7f60c0758a6348134da8cb7b6abd5874278be
parent d3a666d18290181103ba4039b45c1dd507b76595
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu, 14 Nov 2024 15:55:08 +0100

update twister for latest GNUnet APIs

Diffstat:
Mconfigure.ac | 94++++++++++++++++++++++---------------------------------------------------------
Mm4/libcurl.m4 | 2+-
Msrc/include/taler_twister_service.h | 8++++++++
Msrc/twister/Makefile.am | 4+++-
Msrc/twister/taler-twister-service.c | 168+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/twister/taler-twister.c | 1+
Asrc/twister/twister_pd.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 178 insertions(+), 155 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -107,6 +107,31 @@ AS_IF([test $libgnunetjson != 1], *** ]])]) +# Save before checking libcurl +CFLAGS_SAVE=$CFLAGS +LDFLAGS_SAVE=$LDFLAGS +LIBS_SAVE=$LIBS + +# check for libcurl +LIBCURL_CHECK_CONFIG(,7.34.0,[curl=1],[curl=0]) + +# cURL must support CURLINFO_TLS_SESSION, version >= 7.34 +AS_IF([test "x$curl" = x1],[ + AC_CHECK_HEADER([curl/curl.h], + [AC_CHECK_DECLS(CURLINFO_TLS_SESSION,[curl=1],[curl=0],[[#include <curl/curl.h>]])], + [curl=0]) +]) + +# libcurl should be mutually exclusive +AS_IF([test "$curl" = 1], + AM_CONDITIONAL(HAVE_LIBCURL, true) + AC_DEFINE([HAVE_LIBCURL],[1],[Have libcurl]) + [LIBCURL_LIBS="-lcurl"], + [AC_MSG_ERROR([FATAL: No libcurl])]) + +AC_SUBST([LIBCURL_LIBS]) + + # Check for GNUnet's libgnunetcurl. libgnunetcurl=0 AC_MSG_CHECKING([for libgnunetcurl]) @@ -126,12 +151,11 @@ AS_IF([test $libgnunetcurl != 1], [AC_MSG_ERROR([[ *** *** You need libgnunetcurl to build this program. -*** Make sure you have libcurl or libgnurl installed while +*** Make sure you have libcurl installed while *** building GNUnet. *** ]])]) - # check for libmicrohttpd microhttpd=0 AC_MSG_CHECKING([for microhttpd]) @@ -188,71 +212,6 @@ LDFLAGS_SAVE=$LDFLAGS LIBS_SAVE="$LIBS" -# check for libgnurl -# libgnurl -LIBGNURL_CHECK_CONFIG(,7.34.0,gnurl=1,gnurl=0) -if test "$gnurl" = 1 -then - LDFLAGS="-L$with_libgnurl/lib $LDFLAGS" - CPPFLAGS="-I$with_libgnurl/include $CPPFLAGS" - AM_CONDITIONAL(HAVE_LIBGNURL, [true]) - AC_DEFINE([HAVE_LIBGNURL],[1],[Have libgnurl]) -else - AM_CONDITIONAL(HAVE_LIBGNURL, [false]) -fi - -# libcurl-gnutls -LIBCURL_CHECK_CONFIG(,7.34.0,[curl=true],[curl=false]) -if test "x$curl" = xtrue -then - LDFLAGS="-L$with_libcurl/lib $LDFLAGS" - CPPFLAGS="-I$with_libcurl/include $CPPFLAGS" - AC_CHECK_HEADERS([curl/curl.h], - AC_CHECK_DECLS(CURLINFO_TLS_SESSION,[curl=true],[curl=false],[[#include <curl/curl.h>]]), - [curl=false]) - # need libcurl-gnutls.so, everything else is not acceptable - AC_CHECK_LIB([curl-gnutls],[curl_easy_getinfo],,[curl=false]) - # cURL must support CURLINFO_TLS_SESSION, version >= 7.34 - -fi -if test x$curl = xfalse -then - AM_CONDITIONAL(HAVE_LIBCURL, false) -if test "$gnurl" = 0 -then - AC_MSG_WARN([GNUnet requires libcurl-gnutls >= 7.34]) -fi -else - AM_CONDITIONAL(HAVE_LIBCURL, true) - AC_DEFINE([HAVE_LIBCURL],[1],[Have CURL]) -fi - - -# Check for curl/curl.h and gnurl/curl.h so we can use #ifdef -# HAVE_CURL_CURL_H later (the above LIBCURL_CHECK_CONFIG accepted -# *either* header set). -AC_CHECK_HEADERS([curl/curl.h],, - curl=false - AC_CHECK_HEADERS([gnurl/curl.h],, - gnurl=false)) - - -# libgnurl -if test "x$gnurl" = "x0" -then - if test "x$curl" = "x0" - then - AC_MSG_NOTICE([NOTICE: libgnurl not found. http client support will not be compiled.]) - AC_MSG_WARN([ERROR: libgnurl not found. hostlist daemon will not be compiled, and you probably WANT the hostlist daemon]) - else - AC_MSG_NOTICE([WARNING: libgnurl not found, trying to use libcurl-gnutls instead.]) - fi -fi - -CFLAGS=$CFLAGS_SAVE -LDFLAGS=$LDFLAGS_SAVE -LIBS=$LIBS_SAVE - # test for zlib SAVE_LDFLAGS=$LDFLAGS SAVE_CPPFLAGS=$CPPFLAGS @@ -390,7 +349,6 @@ else # logic if doc_only is set, make sure conditionals are still defined AM_CONDITIONAL([HAVE_LIBCURL], [false]) -AM_CONDITIONAL([HAVE_LIBGNURL], [false]) AM_CONDITIONAL([HAVE_DEVELOPER], [false]) AM_CONDITIONAL([USE_COVERAGE], [false]) AM_CONDITIONAL([ENABLE_DOC], [true]) diff --git a/m4/libcurl.m4 b/m4/libcurl.m4 @@ -61,7 +61,7 @@ AC_DEFUN([LIBCURL_CHECK_CONFIG], AH_TEMPLATE([LIBCURL_PROTOCOL_SMTP],[Defined if libcurl supports SMTP]) AC_ARG_WITH(libcurl, - AC_HELP_STRING([--with-libcurl=PREFIX],[look for the curl library in PREFIX/lib and headers in PREFIX/include]), + AS_HELP_STRING([--with-libcurl=PREFIX],[look for the curl library in PREFIX/lib and headers in PREFIX/include]), [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])]) if test "$_libcurl_with" != "no" ; then diff --git a/src/include/taler_twister_service.h b/src/include/taler_twister_service.h @@ -48,6 +48,14 @@ extern "C" */ struct TALER_TWISTER_Handle; + +/** + * Return twister project data. + */ +const struct GNUNET_OS_ProjectData * +TWISTER_project_data (void); + + /** * Connect to the twister service. * diff --git a/src/twister/Makefile.am b/src/twister/Makefile.am @@ -14,6 +14,7 @@ taler_twister_service_SOURCES = \ taler-twister-service.c taler_twister_service_LDADD = \ $(LIBGCRYPT_LIBS) \ + libtalertwister.la \ -lmicrohttpd \ -lcurl \ -ljansson \ @@ -32,7 +33,8 @@ lib_LTLIBRARIES = \ libtalertwister.la libtalertwister_la_SOURCES = \ - twister_api.c twister.h + twister_api.c twister.h \ + twister_pd.c libtalertwister_la_LIBADD = \ -lgnunetutil \ $(XLIB) diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c @@ -29,28 +29,25 @@ */ #include "platform.h" #include <microhttpd.h> -#if HAVE_CURL_CURL_H #include <curl/curl.h> -#elif HAVE_GNURL_CURL_H -#include <gnurl/curl.h> -#endif #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> #include <gnunet/gnunet_mhd_compat.h> #include "twister.h" +#include "taler_twister_service.h" #include <jansson.h> #include <microhttpd.h> #include <zlib.h> #define TWISTER_LOG_INFO(...) \ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__) #define TWISTER_LOG_DEBUG(...) \ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) #define TWISTER_LOG_WARNING(...) \ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, __VA_ARGS__) + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, __VA_ARGS__) #define TWISTER_LOG_ERROR(...) \ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__) #define REQUEST_BUFFER_MAX (1024 * 1024) #define UNIX_BACKLOG 500 @@ -63,8 +60,9 @@ * @param rc return code from curl */ #define LOG_CURL_EASY(level,fun,rc) \ - GNUNET_log (level, _ ("%s failed at %s:%d: `%s'\n"), fun, __FILE__, __LINE__, \ - curl_easy_strerror (rc)) + GNUNET_log (level, _ ("%s failed at %s:%d: `%s'\n"), fun, __FILE__, \ + __LINE__, \ + curl_easy_strerror (rc)) /* ******** Datastructures for HTTP handling ********** */ @@ -1272,6 +1270,7 @@ delete_object (struct MHD_Connection *con, { char *target; json_t *parent; + int ret_deletion = -1; if (NULL == hr->json) return GNUNET_NO; @@ -1286,8 +1285,6 @@ delete_object (struct MHD_Connection *con, } /* here, element is the parent of the element to be deleted. */ - int ret_deletion = -1; - if (json_is_object (parent)) ret_deletion = json_object_del (parent, target); @@ -1415,7 +1412,7 @@ static void create_response_with_chaos_rate (struct HttpRequest *hr) { uint64_t random; - void *resp_buf; + const void *resp_buf; size_t resp_len; random = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, @@ -1437,9 +1434,8 @@ create_response_with_chaos_rate (struct HttpRequest *hr) resp_buf = hr->io_buf; } hr->response - = MHD_create_response_from_buffer (resp_len, - resp_buf, - MHD_RESPMEM_MUST_COPY); + = MHD_create_response_from_buffer_copy (resp_len, + resp_buf); } @@ -2335,14 +2331,14 @@ open_unix_path (const char *path, * Crawl the configuration file and extracts the serving * method, TCP vs IPC, and the respective details (port/path/mode) * - * @param cfg configuration handle. + * @param ccfg configuration handle. * @param port[out] port number to use * @param path[out] unix path for IPC. * @param mode[out] mode string for @a path. * @return #GNUNET_SYSERR if the parsing didn't succeed. */ static int -parse_serving_mean (const struct GNUNET_CONFIGURATION_Handle *cfg, +parse_serving_mean (const struct GNUNET_CONFIGURATION_Handle *ccfg, uint16_t *port, char **path, mode_t *mode) @@ -2355,7 +2351,7 @@ parse_serving_mean (const struct GNUNET_CONFIGURATION_Handle *cfg, if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_choice (cfg, + GNUNET_CONFIGURATION_get_value_choice (ccfg, "twister", "SERVE", choices, @@ -2371,11 +2367,11 @@ parse_serving_mean (const struct GNUNET_CONFIGURATION_Handle *cfg, { *path = NULL; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number - (cfg, - "twister", - "HTTP_PORT", - &port_ull)) + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (ccfg, + "twister", + "HTTP_PORT", + &port_ull)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "twister", @@ -2388,11 +2384,11 @@ parse_serving_mean (const struct GNUNET_CONFIGURATION_Handle *cfg, /* serving via unix */ - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename - (cfg, - "twister", - "SERVE_UNIXPATH", - path)) + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_filename (ccfg, + "twister", + "SERVE_UNIXPATH", + path)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "twister", @@ -2400,11 +2396,11 @@ parse_serving_mean (const struct GNUNET_CONFIGURATION_Handle *cfg, return GNUNET_SYSERR; } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string - (cfg, - "twister", - "SERVE_UNIXMODE", - &modestring)) + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (ccfg, + "twister", + "SERVE_UNIXMODE", + &modestring)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "twister", @@ -2945,61 +2941,63 @@ handle_set_response_code /** - * Define "main" method using service macro. + * Main function. */ -GNUNET_SERVICE_MAIN - ("twister", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_fixed_size (set_response_code, - TWISTER_MESSAGE_TYPE_SET_RESPONSE_CODE, - struct TWISTER_SetResponseCode, +int +main (int argc, + char *const *argv) +{ + struct GNUNET_MQ_MessageHandler mh[] = { + GNUNET_MQ_hd_fixed_size (set_response_code, + TWISTER_MESSAGE_TYPE_SET_RESPONSE_CODE, + struct TWISTER_SetResponseCode, + NULL), + GNUNET_MQ_hd_var_size (modify_path_ul, + TWISTER_MESSAGE_TYPE_MODIFY_PATH_UL, + struct TWISTER_ModifyPath, NULL), - - GNUNET_MQ_hd_var_size (modify_path_ul, - TWISTER_MESSAGE_TYPE_MODIFY_PATH_UL, - struct TWISTER_ModifyPath, - NULL), - - GNUNET_MQ_hd_var_size (modify_path_dl, - TWISTER_MESSAGE_TYPE_MODIFY_PATH_DL, - struct TWISTER_ModifyPath, - NULL), - - GNUNET_MQ_hd_var_size (modify_header_dl, - TWISTER_MESSAGE_TYPE_MODIFY_HEADER_DL, - struct TWISTER_ModifyPath, - NULL), - - GNUNET_MQ_hd_fixed_size (malform_upload, - TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD, - struct TWISTER_Malform, + GNUNET_MQ_hd_var_size (modify_path_dl, + TWISTER_MESSAGE_TYPE_MODIFY_PATH_DL, + struct TWISTER_ModifyPath, NULL), - - GNUNET_MQ_hd_fixed_size (malform, - TWISTER_MESSAGE_TYPE_MALFORM, - struct TWISTER_Malform, + GNUNET_MQ_hd_var_size (modify_header_dl, + TWISTER_MESSAGE_TYPE_MODIFY_HEADER_DL, + struct TWISTER_ModifyPath, NULL), - - GNUNET_MQ_hd_var_size (delete_path, - TWISTER_MESSAGE_TYPE_DELETE_PATH, - struct TWISTER_DeletePath, - NULL), - - GNUNET_MQ_hd_var_size (flip_path_ul, - TWISTER_MESSAGE_TYPE_FLIP_PATH_UL, - struct TWISTER_FlipPath, - NULL), - - GNUNET_MQ_hd_var_size (flip_path_dl, - TWISTER_MESSAGE_TYPE_FLIP_PATH_DL, - struct TWISTER_FlipPath, - NULL), - - GNUNET_MQ_handler_end ()); + GNUNET_MQ_hd_fixed_size (malform_upload, + TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD, + struct TWISTER_Malform, + NULL), + GNUNET_MQ_hd_fixed_size (malform, + TWISTER_MESSAGE_TYPE_MALFORM, + struct TWISTER_Malform, + NULL), + GNUNET_MQ_hd_var_size (delete_path, + TWISTER_MESSAGE_TYPE_DELETE_PATH, + struct TWISTER_DeletePath, + NULL), + GNUNET_MQ_hd_var_size (flip_path_ul, + TWISTER_MESSAGE_TYPE_FLIP_PATH_UL, + struct TWISTER_FlipPath, + NULL), + GNUNET_MQ_hd_var_size (flip_path_dl, + TWISTER_MESSAGE_TYPE_FLIP_PATH_DL, + struct TWISTER_FlipPath, + NULL), + GNUNET_MQ_handler_end () + }; + + return GNUNET_SERVICE_run_ (TWISTER_project_data (), + argc, + argv, + "twister", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + mh); +} /* end of taler-twister-service.c */ diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c @@ -393,6 +393,7 @@ main (int argc, status = 1; ret = GNUNET_PROGRAM_run ( + TWISTER_project_data (), argc, argv, "taler-twister", diff --git a/src/twister/twister_pd.c b/src/twister/twister_pd.c @@ -0,0 +1,56 @@ +/* + This file is part of Taler. + Copyright (C) 2024 Taler Systems SA + + 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 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 General Public License for more details. + + You should have received a copy of the GNU General Public + License along with Taler; see the file COPYING. If not, + write to the Free Software Foundation, Inc., 51 Franklin + Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/** + * @file twister_pd.c + * @brief Twister project data + * @author Christian Grothoff + */ +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include "taler_twister_service.h" + + +/** + * Default project data used for installation path detection + * for Twister. + */ +static const struct GNUNET_OS_ProjectData twister_project_data = { + .libname = "libtalertwister", + .project_dirname = "twister", + .binary_name = "taler-twister", + .version = PACKAGE_VERSION " " VCS_VERSION, + .env_varname = "TWISTER_PREFIX", + .base_config_varname = "TWISTER_BASE_CONFIG", + .bug_email = "taler@gnu.org", + .homepage = "http://www.gnu.org/s/taler/", + .config_file = "twister.conf", + .user_config_file = "~/.config/twister.conf", + .is_gnu = 1, + .gettext_domain = "twister", + .gettext_path = NULL, + .agpl_url = GNUNET_AGPL_URL, +}; + + +const struct GNUNET_OS_ProjectData * +TWISTER_project_data () +{ + return &twister_project_data; +}