summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac28
-rw-r--r--src/include/taler_twister_service.h6
-rw-r--r--src/test/test_twister.conf24
-rw-r--r--src/twister/Makefile.am22
-rw-r--r--src/twister/taler-twister-service.c112
-rw-r--r--src/twister/taler-twister.c23
-rw-r--r--src/twister/testing_api_helpers.c53
-rw-r--r--src/twister/twister_api.c14
8 files changed, 219 insertions, 63 deletions
diff --git a/configure.ac b/configure.ac
index afdb266..7820aec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,7 +88,6 @@ AS_IF([test $libgnunetutil != 1],
*** https://gnunet.org
*** ]])])
-
# Check for GNUnet's libgnunetjson.
libgnunetjson=0
AC_MSG_CHECKING([for libgnunetjson])
@@ -265,6 +264,33 @@ CFLAGS=$CFLAGS_SAVE
LDFLAGS=$LDFLAGS_SAVE
LIBS=$LIBS_SAVE
+# Check for Taler's libtalertesting
+libtalertesting=0
+AC_MSG_CHECKING([for libtalertesting])
+AC_ARG_WITH(exchange,
+ [AS_HELP_STRING([--with-exchange=PFX],
+ [base of Taler EXCHANGE installation, provides testing dependency.])],
+ [AC_MSG_RESULT([given as $with_exchange])],
+ [AC_MSG_RESULT(not given)
+ with_exchange=yes])
+AS_CASE([$with_exchange],
+ [yes], [],
+ [no], [],
+ [LDFLAGS="-L$with_exchange/lib $LDFLAGS"
+ CPPFLAGS="-I$with_exchange/include $CPPFLAGS"])
+
+CPPFLAGS="$CPPFLAGS"
+LDFLAGS="$LDFLAGS -L/usr/local/lib"
+
+
+
+AC_CHECK_HEADERS([gnunet/platform.h taler/taler_testing_lib.h],
+ [AC_CHECK_LIB([talertesting], [TALER_TESTING_setup], libtalertesting=1,,[-ltalerexchange -ltalerbank])],
+ [], [#ifdef HAVE_GNUNET_PLATFORM_H
+ #include <gnunet/platform.h>
+ #endif])
+
+AM_CONDITIONAL(HAVE_TALERTESTING, test x$libtalertesting = x1)
# should developer logic be compiled (not-for-production code)?
AC_MSG_CHECKING(whether to compile developer logic)
diff --git a/src/include/taler_twister_service.h b/src/include/taler_twister_service.h
index b279025..c9b5fb8 100644
--- a/src/include/taler_twister_service.h
+++ b/src/include/taler_twister_service.h
@@ -53,8 +53,7 @@ struct TALER_TWISTER_Handle;
* Connect to the twister service.
*
* @param cfg the configuration to use
- * @return handle to use in #TALER_TWISTER_disconnect
- * to disconnect
+ * @return handle to use in #TALER_TWISTER_disconnect to disconnect
*/
struct TALER_TWISTER_Handle *
TALER_TWISTER_connect
@@ -129,13 +128,10 @@ TALER_TESTING_prepare_twister (const char *config_filename);
* Run the twister service.
*
* @param config_filename configuration file name.
- * @param base_url twister base URL, used by wget to check
- * if the twister is up and running.
*
* @return twister process handle, NULL upon errors.
*/
struct GNUNET_OS_Process *
TALER_TESTING_run_twister (const char *config_filename);
-
#endif /* TALER_NSE_SERVICE_H_ */
diff --git a/src/test/test_twister.conf b/src/test/test_twister.conf
new file mode 100644
index 0000000..fbe48e2
--- /dev/null
+++ b/src/test/test_twister.conf
@@ -0,0 +1,24 @@
+[twister]
+# HTTP listen port for twister
+HTTP_PORT = 8888
+
+# HTTP Destination for twister. The test-Webserver needs
+# to listen on the port used here.
+# Note: no trailing '/'!
+DESTINATION_BASE_URL = http://localhost:8080
+
+# Control port for TCP
+# PORT = 8889
+HOSTNAME = localhost
+ACCEPT_FROM = 127.0.0.1;
+ACCEPT_FROM6 = ::1;
+
+# Control port for UNIX
+UNIXPATH = /tmp/taler-service-twister.sock
+UNIX_MATCH_UID = NO
+UNIX_MATCH_GID = YES
+
+# Launching of twister by ARM
+# BINARY = taler-service-twister
+# AUTOSTART = NO
+# FORCESTART = NO
diff --git a/src/twister/Makefile.am b/src/twister/Makefile.am
index 1721280..abd67f9 100644
--- a/src/twister/Makefile.am
+++ b/src/twister/Makefile.am
@@ -26,13 +26,27 @@ taler_twister_LDADD = \
$(XLIB) $(GN_LIBINTL)
-lib_LTLIBRARIES = libtalertwister.la
+lib_LTLIBRARIES = \
+ libtalertwister.la
+
+if HAVE_TALERTESTING
+lib_LTLIBRARIES += libtalertwistertesting.la
+libtalertwistertesting_la_SOURCES = \
+ testing_api_helpers.c \
+ testing_api_cmd_exec_client.c
+libtalertwistertesting_la_LIBADD = \
+ -lgnunetutil \
+ -ltalertesting \
+ $(XLIB)
+libtalertwistertesting_la_LDFLAGS = \
+ $(GN_LIB_LDFLAGS) $(WINFLAGS) \
+ -version-info 0:0:0
+endif
libtalertwister_la_SOURCES = \
- twister_api.c twister.h \
- testing_api_helpers.c
+ twister_api.c twister.h
libtalertwister_la_LIBADD = \
- -lgnunetutil \
+ -lgnunetutil
$(XLIB)
libtalertwister_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) $(WINFLAGS) \
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c
index eff9d84..eaf77a4 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -3,10 +3,10 @@
Copyright (C) 2012-2014 GNUnet e.V.
Copyright (C) 2018 Taler Systems SA
- GNUnet 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.
+ GNUnet 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.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -44,10 +44,11 @@
* @param fun name of curl_easy-function that gave the error
* @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))
+#define LOG_CURL_EASY(level,fun,rc) \
+ GNUNET_log(level, _("%s failed at %s:%d: `%s'\n"), fun, __FILE__, __LINE__, curl_easy_strerror (rc))
-/* *********************** Datastructures for HTTP handling ****************** */
+/* ******** Datastructures for HTTP handling ********** */
/**
@@ -122,7 +123,8 @@ struct HttpRequest
struct GNUNET_SCHEDULER_Task * wtask;
/**
- * Buffer we use for moving data between MHD and curl (in both directions).
+ * Buffer we use for moving data between MHD and
+ * curl (in both directions).
*/
char *io_buf;
@@ -624,25 +626,28 @@ curl_download_prepare ()
GNUNET_NETWORK_fdset_copy_native (gws,
&ws,
max + 1);
- curl_download_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- rtime,
- grs, gws,
- &curl_task_download,
- curl_multi);
+ curl_download_task = GNUNET_SCHEDULER_add_select
+ (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ rtime,
+ grs, gws,
+ &curl_task_download,
+ curl_multi);
GNUNET_NETWORK_fdset_destroy (gws);
GNUNET_NETWORK_fdset_destroy (grs);
}
else
{
- curl_download_task = GNUNET_SCHEDULER_add_delayed (rtime,
- &curl_task_download,
- curl_multi);
+ curl_download_task = GNUNET_SCHEDULER_add_delayed
+ (rtime,
+ &curl_task_download,
+ curl_multi);
}
}
/**
- * Task that is run when we are ready to receive more data from curl.
+ * Task that is run when we are ready to receive
+ * more data from curl.
*
* @param cls closure, NULL
*/
@@ -667,11 +672,13 @@ curl_task_download (void *cls)
while (NULL != (msg = curl_multi_info_read (curl_multi,
&msgnum)))
{
- GNUNET_break (CURLE_OK ==
- curl_easy_getinfo (msg->easy_handle,
- CURLINFO_PRIVATE,
- (char **) &hr ));
- if (NULL == hr)
+ GNUNET_break
+ (CURLE_OK == curl_easy_getinfo
+ (msg->easy_handle,
+ CURLINFO_PRIVATE,
+ (char **) &hr ));
+
+ if (NULL == hr)
{
GNUNET_break (0);
continue;
@@ -698,14 +705,16 @@ curl_task_download (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Download curl failed: %s\n",
curl_easy_strerror (msg->data.result));
- /* FIXME: indicate error somehow? close MHD connection badly as well? */
+ /* FIXME: indicate error somehow?
+ * close MHD connection badly as well? */
hr->state = REQUEST_STATE_DOWNLOAD_DONE;
break;
}
if (NULL == hr->response)
hr->response = curl_failure_response;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Curl request for `%s' finished, response generated\n",
+ "Curl request for `%s' finished,"
+ " response generated\n",
hr->url);
run_mhd_now ();
break;
@@ -730,14 +739,15 @@ curl_task_download (void *cls)
if (0 == running)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Suspending cURL multi loop, no more events pending\n");
+ "Suspending cURL multi loop,"
+ " no more events pending\n");
return; /* nothing more in progress */
}
curl_download_prepare ();
}
-/* ********************************* MHD response generation ******************* */
+/* *************** MHD response generation ******************* */
/**
@@ -798,7 +808,8 @@ con_val_iter (void *cls,
* @param upload_data_size set initially to the size of the
* @a upload_data provided; the method must update this
* value to the number of bytes NOT processed;
- * @param con_cls pointer to location where we store the 'struct Request'
+ * @param con_cls pointer to location where we store the
+ * 'struct Request'
* @return MHD_YES if the connection was handled successfully,
* MHD_NO if the socket must be closed due to a serious
* error while handling the request
@@ -844,8 +855,9 @@ create_response (void *cls,
GNUNET_assert (*upload_data_size + hr->io_len > hr->io_len);
GNUNET_array_grow (hr->io_buf,
hr->io_size,
- GNUNET_MAX (hr->io_size * 2 + 1024,
- *upload_data_size + hr->io_len));
+ GNUNET_MAX
+ (hr->io_size * 2 + 1024,
+ *upload_data_size + hr->io_len));
}
GNUNET_memcpy (&hr->io_buf[hr->io_len],
upload_data,
@@ -1058,12 +1070,14 @@ create_response (void *cls,
/**
- * Function called when MHD decides that we are done with a request.
+ * Function called when MHD decides that we
+ * are done with a request.
*
* @param cls NULL
* @param connection connection handle
* @param con_cls value as set by the last call to
- * the MHD_AccessHandlerCallback, should be our `struct HttpRequest *`
+ * the MHD_AccessHandlerCallback, should be
+ * our `struct HttpRequest *` (set by `create_response()`)
* @param toe reason for request termination (ignored)
*/
static void
@@ -1097,8 +1111,12 @@ mhd_completed_cb (void *cls,
}
if ( (NULL != hr->response) &&
(curl_failure_response != hr->response) )
+ /* Destroy non-error responses... (?) */
MHD_destroy_response (hr->response);
- for (header = hr->header_head; header != NULL; header = hr->header_head)
+
+ for (header = hr->header_head;
+ header != NULL;
+ header = hr->header_head)
{
GNUNET_CONTAINER_DLL_remove (hr->header_head,
hr->header_tail,
@@ -1313,7 +1331,10 @@ do_shutdown (void *cls)
/**
- * Main function that will be run
+ * Main function that will be run. Main tasks are (1) init. the
+ * curl infrastructure (curl_global_init() / curl_multi_init()),
+ * then fetch the HTTP port where its Web service should listen at,
+ * and finally start MHD on that port.
*
* @param cls closure
* @param c configuration
@@ -1343,10 +1364,11 @@ run (void *cls,
return;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (c,
- "twister",
- "DESTINATION_BASE_URL",
- &target_server_base_url))
+ GNUNET_CONFIGURATION_get_value_string
+ (c,
+ "twister",
+ "DESTINATION_BASE_URL",
+ &target_server_base_url))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"twister",
@@ -1371,14 +1393,16 @@ run (void *cls,
port);
/* start MHD daemon for HTTP */
- mhd_daemon = MHD_start_daemon (MHD_USE_DEBUG,
- (uint16_t) port,
- NULL, NULL,
- &create_response, NULL,
- MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
- MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL,
- MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL,
- MHD_OPTION_END);
+ mhd_daemon = MHD_start_daemon
+ (MHD_USE_DEBUG,
+ (uint16_t) port,
+ NULL, NULL,
+ &create_response, NULL,
+ MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
+ MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, NULL,
+ MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL,
+ MHD_OPTION_END);
+
if (NULL == mhd_daemon)
{
GNUNET_break (0);
diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c
index 6eec9a8..7abef7b 100644
--- a/src/twister/taler-twister.c
+++ b/src/twister/taler-twister.c
@@ -45,6 +45,13 @@ static int status;
static unsigned int hack_response_code;
/**
+ * This option is used to check whether the twister can accept
+ * connections over the unix domain socket interface. Used when
+ * launching it to see if everything (?) is okay.
+ */
+static int check_alive;
+
+/**
* Number of operations we launched.
*/
static unsigned int num_ops;
@@ -108,6 +115,14 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
+
+
+ if (0 != check_alive)
+ {
+ fprintf (stderr, "Could connect to twister via IPC socket.\n");
+ status = 0;
+ }
+
if ( (0 != hack_response_code) &&
(NULL != TALER_TWISTER_change_response_code
(tth,
@@ -120,8 +135,7 @@ run (void *cls,
if (0 == num_ops)
{
- fprintf (stderr,
- "No valid hacks specified!\n");
+ fprintf (stderr, "No valid hacks specified!\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -138,6 +152,11 @@ main (int argc,
char *const *argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_flag
+ ('a',
+ "checkalive",
+ gettext_noop ("Check if twister accepts IPC connections\n"),
+ &check_alive),
GNUNET_GETOPT_option_uint
('r',
"responsecode",
diff --git a/src/twister/testing_api_helpers.c b/src/twister/testing_api_helpers.c
index dc29fe9..5b70ec3 100644
--- a/src/twister/testing_api_helpers.c
+++ b/src/twister/testing_api_helpers.c
@@ -31,8 +31,57 @@
/**
* @param config_filename configuration filename.
*
- * @return the process, or NULL if the process could not
- * be started.
+ * @return twister base URL, NULL upon errors.
+ */
+char *
+TALER_TESTING_prepare_twister (const char *config_filename)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ unsigned long long port;
+ char *base_url;
+
+ cfg = GNUNET_CONFIGURATION_create ();
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_load
+ (cfg, config_filename))
+ TWISTER_FAIL ();
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number
+ (cfg, "twister",
+ "HTTP_PORT", &port))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "twister",
+ "HTTP_PORT");
+ GNUNET_CONFIGURATION_destroy (cfg);
+ TWISTER_FAIL ();
+ }
+
+ GNUNET_CONFIGURATION_destroy (cfg);
+
+ if (GNUNET_OK != GNUNET_NETWORK_test_port_free
+ (IPPROTO_TCP, (uint16_t) port))
+ {
+ fprintf (stderr,
+ "Required port %llu not available, skipping.\n",
+ port);
+ TWISTER_FAIL ();
+ }
+
+ GNUNET_assert (0 < GNUNET_asprintf
+ (&base_url,
+ "http://localhost:%llu",
+ port));
+
+ return base_url;
+}
+
+/**
+ * Run the twister service.
+ *
+ * @param config_filename configuration file name.
+ *
+ * @return twister process handle, NULL upon errors.
*/
struct GNUNET_OS_Process *
TALER_TESTING_run_twister (const char *config_filename)
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index 78f0427..07583f8 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -126,7 +126,8 @@ handle_acknowledgement (void *cls,
* @return handle to use
*/
struct TALER_TWISTER_Handle *
-TALER_TWISTER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
+TALER_TWISTER_connect
+ (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct TALER_TWISTER_Handle *h;
@@ -134,10 +135,11 @@ TALER_TWISTER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
h->cfg = cfg;
{
struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (acknowledgement,
- TWISTER_MESSAGE_TYPE_ACKNOWLEDGEMENT,
- struct GNUNET_MessageHeader,
- h),
+ GNUNET_MQ_hd_fixed_size
+ (acknowledgement,
+ TWISTER_MESSAGE_TYPE_ACKNOWLEDGEMENT,
+ struct GNUNET_MessageHeader,
+ h),
GNUNET_MQ_handler_end ()
};
@@ -151,6 +153,8 @@ TALER_TWISTER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
}
if (NULL == h->mq)
{
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Could not connect to twister service\n");
GNUNET_free (h);
return NULL;
}