From 870da9ed169132733f2d0cba437ad538f71cf817 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 27 Sep 2011 14:03:08 +0000 Subject: - renaming test_transport_api_multiaddress to test_transport_api_timeout - adding new timeout tests for http and https --- src/transport/Makefile.am | 57 ++-- src/transport/test_transport_api_http_peer1.conf | 4 +- src/transport/test_transport_api_http_peer2.conf | 2 +- src/transport/test_transport_api_multiaddress.c | 349 --------------------- .../test_transport_api_multiaddress_tcp_peer1.conf | 33 -- .../test_transport_api_multiaddress_tcp_peer2.conf | 36 --- src/transport/test_transport_api_timeout.c | 349 +++++++++++++++++++++ .../test_transport_api_timeout_http_peer1.conf | 42 +++ .../test_transport_api_timeout_http_peer2.conf | 38 +++ .../test_transport_api_timeout_https_peer1.conf | 35 +++ .../test_transport_api_timeout_https_peer2.conf | 36 +++ .../test_transport_api_timeout_tcp_peer1.conf | 33 ++ .../test_transport_api_timeout_tcp_peer2.conf | 36 +++ src/transport/test_transport_api_unreliability.c | 2 +- 14 files changed, 602 insertions(+), 450 deletions(-) delete mode 100644 src/transport/test_transport_api_multiaddress.c delete mode 100644 src/transport/test_transport_api_multiaddress_tcp_peer1.conf delete mode 100644 src/transport/test_transport_api_multiaddress_tcp_peer2.conf create mode 100644 src/transport/test_transport_api_timeout.c create mode 100644 src/transport/test_transport_api_timeout_http_peer1.conf create mode 100644 src/transport/test_transport_api_timeout_http_peer2.conf create mode 100644 src/transport/test_transport_api_timeout_https_peer1.conf create mode 100644 src/transport/test_transport_api_timeout_https_peer2.conf create mode 100644 src/transport/test_transport_api_timeout_tcp_peer1.conf create mode 100644 src/transport/test_transport_api_timeout_tcp_peer2.conf (limited to 'src') diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index a421e089a..a76e74804 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -7,14 +7,14 @@ if HAVE_MHD if HAVE_EXPERIMENTAL GN_LIBMHD = -lmicrohttpd HTTP_PLUGIN_LA = libgnunet_plugin_transport_http.la -# HTTP_PLUGIN_TEST = test_plugin_transport_http HTTP_API_TEST = test_transport_api_http + HTTP_API_TIMEOUT_TEST = test_transport_api_timeout_http HTTP_REL_TEST = test_transport_api_reliability_http HTTP_QUOTA_TEST = test_quota_compliance_http \ test_quota_compliance_http_asymmetric_recv_constant HTTPS_PLUGIN_LA = libgnunet_plugin_transport_https.la -# HTTPS_PLUGIN_TEST = test_plugin_transport_https HTTPS_API_TEST = test_transport_api_https + HTTPS_API_TIMEOUT_TEST = test_transport_api_timeout_https HTTPS_REL_TEST = test_transport_api_reliability_https HTTPS_QUOTA_TEST = test_quota_compliance_https \ test_quota_compliance_https_asymmetric_recv_constant @@ -253,17 +253,17 @@ check_PROGRAMS = \ test_transport_testing \ test_transport_startonly \ test_transport_api_disconnect \ - test_transport_api_multiaddress_tcp \ test_transport_api_tcp \ + test_transport_api_timeout_tcp \ test_transport_api_limited_sockets_tcp \ test_transport_api_tcp_nat \ test_transport_api_udp \ $(UNIX_PLUGIN_TEST) \ test_transport_api_udp_nat \ - $(HTTP_PLUGIN_TEST) \ $(HTTP_API_TEST) \ - $(HTTPS_PLUGIN_TEST) \ + $(HTTP_API_TIMEOUT_TEST) \ $(HTTPS_API_TEST) \ + $(HTTPS_API_TIMEOUT_TEST) \ test_transport_api_multi \ test_transport_api_reliability_tcp \ test_transport_api_reliability_tcp_nat \ @@ -288,17 +288,17 @@ TESTS = \ test_transport_testing \ test_transport_startonly \ test_transport_api_disconnect \ - test_transport_api_multiaddress_tcp \ test_transport_api_tcp \ + test_transport_api_timeout_tcp \ test_transport_api_limited_sockets_tcp \ test_transport_api_tcp_nat \ test_transport_api_udp \ $(UNIX_PLUGIN_TEST) \ test_transport_api_udp_nat \ - $(HTTP_PLUGIN_TEST) \ $(HTTP_API_TEST) \ - $(HTTPS_PLUGIN_TEST) \ + $(HTTP_API_TIMEOUT_TEST) \ $(HTTPS_API_TEST) \ + $(HTTPS_API_TIMEOUT_TEST) \ test_transport_api_multi \ test_transport_api_reliability_tcp \ test_transport_api_reliability_tcp_nat \ @@ -384,14 +384,30 @@ test_transport_api_reliability_tcp_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la -test_transport_api_multiaddress_tcp_SOURCES = \ - test_transport_api_multiaddress.c -test_transport_api_multiaddress_tcp_LDADD = \ +test_transport_api_timeout_tcp_SOURCES = \ + test_transport_api_timeout.c +test_transport_api_timeout_tcp_LDADD = \ $(top_builddir)/src/transport/libgnunettransport.la \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la +test_transport_api_timeout_http_SOURCES = \ + test_transport_api_timeout.c +test_transport_api_timeout_http_LDADD = \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/transport/libgnunettransporttesting.la + +test_transport_api_timeout_https_SOURCES = \ + test_transport_api_timeout.c +test_transport_api_timeout_https_LDADD = \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/transport/libgnunettransporttesting.la + test_transport_api_reliability_tcp_nat_SOURCES = \ test_transport_api_reliability.c test_transport_api_reliability_tcp_nat_LDADD = \ @@ -464,14 +480,6 @@ test_transport_api_reliability_http_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/transport/libgnunettransporttesting.la -#test_plugin_transport_https_SOURCES = \ -# test_plugin_transport_https.c -#test_plugin_transport_https_LDADD = \ -# $(top_builddir)/src/statistics/libgnunetstatistics.la \ -# @LIBCURL@ \ -# $(top_builddir)/src/hello/libgnunethello.la \ -# $(top_builddir)/src/util/libgnunetutil.la - test_transport_api_https_SOURCES = \ test_transport_api.c test_transport_api_https_LDADD = \ @@ -597,12 +605,6 @@ test_quota_compliance_udp_asymmetric_recv_constant_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la -#test_quota_compliance_udp_asymmetric_send_constant_SOURCES = \ -# test_quota_compliance.c -#test_quota_compliance_udp_asymmetric_send_constant_LDADD = \ -# $(top_builddir)/src/transport/libgnunettransport.la \ -# $(top_builddir)/src/util/libgnunetutil.la - test_quota_compliance_unix_SOURCES = \ test_quota_compliance.c test_quota_compliance_unix_LDADD = \ @@ -617,7 +619,6 @@ test_quota_compliance_unix_asymmetric_recv_constant_LDADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la - test_transport_api_multi_SOURCES = \ test_transport_api.c test_transport_api_multi_LDADD = \ @@ -652,8 +653,8 @@ test_transport_api_https_peer1.conf\ test_transport_api_https_peer2.conf\ test_transport_api_limited_sockets_tcp_peer1.conf\ test_transport_api_limited_sockets_tcp_peer2.conf\ -test_transport_api_multiaddress_tcp_peer1.conf\ -test_transport_api_multiaddress_tcp_peer2.conf\ +test_transport_api_timeout_tcp_peer1.conf\ +test_transport_api_timeout_tcp_peer2.conf\ test_transport_api_multi_peer1.conf\ test_transport_api_multi_peer2.conf\ test_transport_api_reliability_http_peer1.conf\ diff --git a/src/transport/test_transport_api_http_peer1.conf b/src/transport/test_transport_api_http_peer1.conf index 5525bc5ab..c322c36c1 100644 --- a/src/transport/test_transport_api_http_peer1.conf +++ b/src/transport/test_transport_api_http_peer1.conf @@ -8,7 +8,7 @@ DISABLEV6 = NO [transport-http] PORT = 12080 -USE_IPv6 = NO +USE_IPv6 = YES USE_IPv4 = YES DISABLEV6 = NO #BINDTO = 127.0.0.1 @@ -32,7 +32,7 @@ PORT = 12082 UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock [transport] -DEBUG = YES +#DEBUG = YES PORT = 12081 PLUGINS = http #BINARY = .libs/gnunet-service-transport diff --git a/src/transport/test_transport_api_http_peer2.conf b/src/transport/test_transport_api_http_peer2.conf index 39c2639c2..1f5087e04 100644 --- a/src/transport/test_transport_api_http_peer2.conf +++ b/src/transport/test_transport_api_http_peer2.conf @@ -11,7 +11,7 @@ PORT = 12090 USE_IPv6 = YES USE_IPv4 = YES DISABLEV6 = NO -BINDTO = 127.0.0.1 +#BINDTO = 127.0.0.1 [arm] PORT = 12095 diff --git a/src/transport/test_transport_api_multiaddress.c b/src/transport/test_transport_api_multiaddress.c deleted file mode 100644 index 1096df840..000000000 --- a/src/transport/test_transport_api_multiaddress.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2009, 2010 Christian Grothoff (and other contributing authors) - - 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 - 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 GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file transport/test_transport_api.c - * @brief base test case for transport implementations - * - * This test case serves as a base for tcp, udp, and udp-nat - * transport test cases. Based on the executable being run - * the correct test case will be performed. Conservation of - * C code apparently. - */ - -#include "platform.h" -#include "gnunet_common.h" -#include "gnunet_hello_lib.h" -#include "gnunet_getopt_lib.h" -#include "gnunet_os_lib.h" -#include "gnunet_program_lib.h" -#include "gnunet_scheduler_lib.h" -#include "gnunet_transport_service.h" -#include "transport.h" -#include "transport-testing.h" - -#define VERBOSE GNUNET_NO - -#define VERBOSE_ARM GNUNET_NO - -#define START_ARM GNUNET_YES - -/** - * How long until we give up on transmitting the message? - */ -#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) - -#define MTYPE 12345 - -static char *test_source; - -static char *test_plugin; - -static char *test_name; - -static int ok; - -static GNUNET_SCHEDULER_TaskIdentifier die_task; - -static GNUNET_SCHEDULER_TaskIdentifier timer_task; - -struct PeerContext *p1; - -struct PeerContext *p2; - -static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; - -struct GNUNET_TRANSPORT_TransmitHandle *th; - -char *cfg_file_p1; - -char *cfg_file_p2; - -static struct GNUNET_TIME_Relative time_running; - -static int shutdown_flag; - -static int disconnects; - - -#if VERBOSE -#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) -#else -#define OKPP do { ok++; } while (0) -#endif - - -static void -end () -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); - - if (timer_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (timer_task); - timer_task = GNUNET_SCHEDULER_NO_TASK; - } - - if (die_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_NO_TASK; - } - - if (th != NULL) - GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - - - GNUNET_TRANSPORT_TESTING_stop_peer (p1); - GNUNET_TRANSPORT_TESTING_stop_peer (p2); - - if (disconnects == 0) - ok = 0; - else - { - ok = disconnects; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Fail! Had %u disconnects while waiting %llu seconds \n", - disconnects, WAIT.rel_value); - } -} - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = GNUNET_SCHEDULER_NO_TASK; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); - - if (timer_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (timer_task); - timer_task = GNUNET_SCHEDULER_NO_TASK; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "1\n"); - if (cc != NULL) - GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "2\n"); - if (th != NULL) - GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "3\n"); - if (p1 != NULL) - GNUNET_TRANSPORT_TESTING_stop_peer (p1); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "4\n"); - if (p2 != NULL) - GNUNET_TRANSPORT_TESTING_stop_peer (p2); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5\n"); - ok = GNUNET_SYSERR; -} - - -static void -notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_TRANSPORT_ATS_Information *ats, - uint32_t ats_count) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received message of type %d from peer %s!\n", - ntohs (message->type), GNUNET_i2s (peer)); -} - -static void -notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_TRANSPORT_ATS_Information *ats, - uint32_t ats_count) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", - GNUNET_i2s (peer), cls); -} - - -static void -notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) -{ - if (shutdown_flag != GNUNET_YES) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "FAIL! Peer `%4s' disconnected during waiting period!\n", - GNUNET_i2s (peer)); - disconnects++; - } -} - -static void -timer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - static int percentage; - - timer_task = GNUNET_SCHEDULER_NO_TASK; - - if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) - return; - - percentage += 10; - time_running = - GNUNET_TIME_relative_add (time_running, - GNUNET_TIME_relative_divide (WAIT, 10)); - - if (time_running.rel_value == - GNUNET_TIME_relative_max (time_running, WAIT).rel_value) - { - fprintf (stderr, "100%%\n"); - shutdown_flag = GNUNET_YES; - GNUNET_SCHEDULER_add_now (&end, NULL); - } - else - { - fprintf (stderr, "%u%%..", percentage); - timer_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (WAIT, 10), - &timer, NULL); - } -} - -static void -testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) -{ - cc = NULL; - char *p1_c = strdup (GNUNET_i2s (&p1->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c, - GNUNET_i2s (&p2->id)); - GNUNET_free (p1_c); - - shutdown_flag = GNUNET_NO; - - // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! - timer_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (WAIT, 10), - &timer, NULL); -} - -static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - - p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - NULL); - p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, ¬ify_receive, - ¬ify_connect, ¬ify_disconnect, - NULL); - - if ((p1 == NULL) || (p2 == NULL)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); - if (die_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel (die_task); - die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, - NULL); -} - -static int -check () -{ - static char *const argv[] = { "test-transport-api-multiaddress", - "-c", - "test_transport_api_data.conf", -#if VERBOSE - "-L", "DEBUG", -#endif - NULL - }; - static struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; - -#if WRITECONFIG - setTransportOptions ("test_transport_api_data.conf"); -#endif - timer_task = GNUNET_SCHEDULER_NO_TASK; - - ok = 1; - GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, - "test-transport-api-multiaddress", "nohelp", options, - &run, &ok); - - return ok; -} - -int -main (int argc, char *argv[]) -{ - int ret; - int nat_res; - - GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); - GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, - &test_plugin); - GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); - - GNUNET_log_setup (test_name, -#if VERBOSE - "DEBUG", -#else - "WARNING", -#endif - NULL); - - if ((strcmp (test_plugin, "tcp_nat") == 0) || - (strcmp (test_plugin, "udp_nat") == 0)) - { - nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server"); - if (GNUNET_NO == nat_res) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", - "gnunet-nat-server", "SUID not set"); - return 0; - } - if (GNUNET_SYSERR == nat_res) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", - "gnunet-nat-server", "file not found"); - return 0; - } - } - - GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); - GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); - - ret = check (); - - GNUNET_free (cfg_file_p1); - GNUNET_free (cfg_file_p2); - - GNUNET_free (test_source); - GNUNET_free (test_plugin); - GNUNET_free (test_name); - - - return ret; -} - -/* end of test_transport_api.c */ diff --git a/src/transport/test_transport_api_multiaddress_tcp_peer1.conf b/src/transport/test_transport_api_multiaddress_tcp_peer1.conf deleted file mode 100644 index 974481fde..000000000 --- a/src/transport/test_transport_api_multiaddress_tcp_peer1.conf +++ /dev/null @@ -1,33 +0,0 @@ -@INLINE@ test_transport_defaults.conf -[PATHS] -SERVICEHOME = /tmp/test-transport/api-tcp-p1/ -DEFAULTCONFIG = template_cfg_peer1.conf - -[transport-tcp] -PORT = 12000 -TIMEOUT = 5000 -BINDTO = 127.0.0.1 - -[arm] -PORT = 12005 -DEFAULTSERVICES = transport -UNIXPATH = /tmp/gnunet-p1-service-arm.sock - -[statistics] -PORT = 12004 -UNIXPATH = /tmp/gnunet-p1-service-statistics.sock - -[resolver] -PORT = 12003 -UNIXPATH = /tmp/gnunet-p1-service-resolver.sock - -[peerinfo] -PORT = 12002 -UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock - -[transport] -PORT = 12001 -UNIXPATH = /tmp/gnunet-p1-service-transport.sock -DEBUG = NO - - diff --git a/src/transport/test_transport_api_multiaddress_tcp_peer2.conf b/src/transport/test_transport_api_multiaddress_tcp_peer2.conf deleted file mode 100644 index 0d4869f77..000000000 --- a/src/transport/test_transport_api_multiaddress_tcp_peer2.conf +++ /dev/null @@ -1,36 +0,0 @@ -@INLINE@ test_transport_defaults.conf -[PATHS] -SERVICEHOME = /tmp/test-transport/api-tcp-p2/ -DEFAULTCONFIG = template_cfg_peer2.conf - -[nat] -ALLOW_NAT = NO - -[transport-tcp] -PORT = 0 -TIMEOUT = 5000 -BINDTO = 127.0.0.1 - -[arm] -PORT = 12014 -DEFAULTSERVICES = transport -UNIXPATH = /tmp/gnunet-p2-service-arm.sock - -[statistics] -PORT = 12013 -UNIXPATH = /tmp/gnunet-p2-service-statistics.sock - -[resolver] -PORT = 12012 -UNIXPATH = /tmp/gnunet-p2-service-resolver.sock - -[peerinfo] -PORT = 12011 -UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock - -[transport] -PORT = 12010 -UNIXPATH = /tmp/gnunet-p2-service-transport.sock -DEBUG = NO - - diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c new file mode 100644 index 000000000..cec60e989 --- /dev/null +++ b/src/transport/test_transport_api_timeout.c @@ -0,0 +1,349 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + 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 + 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 GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file transport/test_transport_api_timeout.c + * @brief test case for transport plugin implementations complying timeout + * settings + * + * + * This test case serves ensures that no peer disconnect events occurs + * while plugins are idle + */ + +#include "platform.h" +#include "gnunet_common.h" +#include "gnunet_hello_lib.h" +#include "gnunet_getopt_lib.h" +#include "gnunet_os_lib.h" +#include "gnunet_program_lib.h" +#include "gnunet_scheduler_lib.h" +#include "gnunet_transport_service.h" +#include "transport.h" +#include "transport-testing.h" + +#define VERBOSE GNUNET_NO + +#define VERBOSE_ARM GNUNET_NO + +#define START_ARM GNUNET_YES + +/** + * How long until we give up on transmitting the message? + */ +#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) + +#define MTYPE 12345 + +static char *test_source; + +static char *test_plugin; + +static char *test_name; + +static int ok; + +static GNUNET_SCHEDULER_TaskIdentifier die_task; + +static GNUNET_SCHEDULER_TaskIdentifier timer_task; + +struct PeerContext *p1; + +struct PeerContext *p2; + +static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; + +struct GNUNET_TRANSPORT_TransmitHandle *th; + +char *cfg_file_p1; + +char *cfg_file_p2; + +static struct GNUNET_TIME_Relative time_running; + +static int shutdown_flag; + +static int disconnects; + + +#if VERBOSE +#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) +#else +#define OKPP do { ok++; } while (0) +#endif + + +static void +end () +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); + + if (timer_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (timer_task); + timer_task = GNUNET_SCHEDULER_NO_TASK; + } + + if (die_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; + } + + if (th != NULL) + GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); + th = NULL; + + + GNUNET_TRANSPORT_TESTING_stop_peer (p1); + GNUNET_TRANSPORT_TESTING_stop_peer (p2); + + if (disconnects == 0) + ok = 0; + else + { + ok = disconnects; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Fail! Had %u disconnects while waiting %llu seconds \n", + disconnects, WAIT.rel_value); + } +} + +static void +end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + die_task = GNUNET_SCHEDULER_NO_TASK; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); + + if (timer_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (timer_task); + timer_task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "1\n"); + if (cc != NULL) + GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "2\n"); + if (th != NULL) + GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); + th = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "3\n"); + if (p1 != NULL) + GNUNET_TRANSPORT_TESTING_stop_peer (p1); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "4\n"); + if (p2 != NULL) + GNUNET_TRANSPORT_TESTING_stop_peer (p2); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5\n"); + ok = GNUNET_SYSERR; +} + + +static void +notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + const struct GNUNET_TRANSPORT_ATS_Information *ats, + uint32_t ats_count) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received message of type %d from peer %s!\n", + ntohs (message->type), GNUNET_i2s (peer)); +} + +static void +notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_TRANSPORT_ATS_Information *ats, + uint32_t ats_count) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", + GNUNET_i2s (peer), cls); +} + + +static void +notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) +{ + if (shutdown_flag != GNUNET_YES) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "FAIL! Peer `%4s' disconnected during waiting period!\n", + GNUNET_i2s (peer)); + disconnects++; + } +} + +static void +timer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + static int percentage; + + timer_task = GNUNET_SCHEDULER_NO_TASK; + + if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) + return; + + percentage += 10; + time_running = + GNUNET_TIME_relative_add (time_running, + GNUNET_TIME_relative_divide (WAIT, 10)); + + if (time_running.rel_value == + GNUNET_TIME_relative_max (time_running, WAIT).rel_value) + { + fprintf (stderr, "100%%\n"); + shutdown_flag = GNUNET_YES; + GNUNET_SCHEDULER_add_now (&end, NULL); + } + else + { + fprintf (stderr, "%u%%..", percentage); + timer_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (WAIT, 10), + &timer, NULL); + } +} + +static void +testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) +{ + cc = NULL; + char *p1_c = strdup (GNUNET_i2s (&p1->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c, + GNUNET_i2s (&p2->id)); + GNUNET_free (p1_c); + + shutdown_flag = GNUNET_NO; + + // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! + timer_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (WAIT, 10), + &timer, NULL); +} + +static void +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); + + p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, ¬ify_receive, + ¬ify_connect, ¬ify_disconnect, + NULL); + p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, ¬ify_receive, + ¬ify_connect, ¬ify_disconnect, + NULL); + + if ((p1 == NULL) || (p2 == NULL)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); + if (die_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); + return; + } + + cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, + NULL); +} + +static int +check () +{ + static char *const argv[] = { "test-transport-api-multiaddress", + "-c", + "test_transport_api_data.conf", +#if VERBOSE + "-L", "DEBUG", +#endif + NULL + }; + static struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + +#if WRITECONFIG + setTransportOptions ("test_transport_api_data.conf"); +#endif + timer_task = GNUNET_SCHEDULER_NO_TASK; + + ok = 1; + GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, + "test-transport-api-multiaddress", "nohelp", options, + &run, &ok); + + return ok; +} + +int +main (int argc, char *argv[]) +{ + int ret; + int nat_res; + + GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); + GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, + &test_plugin); + GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); + + GNUNET_log_setup (test_name, +#if VERBOSE + "DEBUG", +#else + "WARNING", +#endif + NULL); + + if ((strcmp (test_plugin, "tcp_nat") == 0) || + (strcmp (test_plugin, "udp_nat") == 0)) + { + nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server"); + if (GNUNET_NO == nat_res) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", + "gnunet-nat-server", "SUID not set"); + return 0; + } + if (GNUNET_SYSERR == nat_res) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", + "gnunet-nat-server", "file not found"); + return 0; + } + } + + GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); + GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); + + ret = check (); + + GNUNET_free (cfg_file_p1); + GNUNET_free (cfg_file_p2); + + GNUNET_free (test_source); + GNUNET_free (test_plugin); + GNUNET_free (test_name); + + + return ret; +} + +/* end of test_transport_api_timeout.c*/ diff --git a/src/transport/test_transport_api_timeout_http_peer1.conf b/src/transport/test_transport_api_timeout_http_peer1.conf new file mode 100644 index 000000000..c322c36c1 --- /dev/null +++ b/src/transport/test_transport_api_timeout_http_peer1.conf @@ -0,0 +1,42 @@ +@INLINE@ test_transport_defaults.conf +[PATHS] +SERVICEHOME = /tmp/test-transport/api-http-p1/ +DEFAULTCONFIG = test_transport_api_http_peer1.conf + +[nat] +DISABLEV6 = NO + +[transport-http] +PORT = 12080 +USE_IPv6 = YES +USE_IPv4 = YES +DISABLEV6 = NO +#BINDTO = 127.0.0.1 +#BINDTO6 = ::1 + +[arm] +PORT = 12085 +DEFAULTSERVICES = transport +UNIXPATH = /tmp/gnunet-p1-service-arm.sock + +[statistics] +PORT = 12084 +UNIXPATH = /tmp/gnunet-p1-service-statistics.sock + +[resolver] +PORT = 12083 +UNIXPATH = /tmp/gnunet-p1-service-resolver.sock + +[peerinfo] +PORT = 12082 +UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock + +[transport] +#DEBUG = YES +PORT = 12081 +PLUGINS = http +#BINARY = .libs/gnunet-service-transport +UNIXPATH = /tmp/gnunet-p1-service-transport.sock +#PREFIX = valgrind --leak-check=full +#PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args + diff --git a/src/transport/test_transport_api_timeout_http_peer2.conf b/src/transport/test_transport_api_timeout_http_peer2.conf new file mode 100644 index 000000000..1f5087e04 --- /dev/null +++ b/src/transport/test_transport_api_timeout_http_peer2.conf @@ -0,0 +1,38 @@ +@INLINE@ test_transport_defaults.conf +[PATHS] +SERVICEHOME = /tmp/test-transport/api-http-p2/ +DEFAULTCONFIG = test_transport_api_http_peer2.conf + +[nat] +DISABLEV6 = NO + +[transport-http] +PORT = 12090 +USE_IPv6 = YES +USE_IPv4 = YES +DISABLEV6 = NO +#BINDTO = 127.0.0.1 + +[arm] +PORT = 12095 +DEFAULTSERVICES = transport +UNIXPATH = /tmp/gnunet-p2-service-arm.sock + +[statistics] +PORT = 12094 +UNIXPATH = /tmp/gnunet-p2-service-statistics.sock + +[resolver] +PORT = 12093 +UNIXPATH = /tmp/gnunet-p2-service-resolver.sock + +[peerinfo] +PORT = 12092 +UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock + +[transport] +DEBUG = YES +PORT = 12091 +PLUGINS = http +UNIXPATH = /tmp/gnunet-p2-service-transport.sock +#PREFIX = valgrind --leak-check=full diff --git a/src/transport/test_transport_api_timeout_https_peer1.conf b/src/transport/test_transport_api_timeout_https_peer1.conf new file mode 100644 index 000000000..7a3a225f0 --- /dev/null +++ b/src/transport/test_transport_api_timeout_https_peer1.conf @@ -0,0 +1,35 @@ +@INLINE@ test_transport_defaults.conf +[PATHS] +SERVICEHOME = /tmp/test-transport/api-https-p1/ +DEFAULTCONFIG = test_transport_api_https_peer1.conf + +[transport-https] +PORT = 12100 +CRYPTO_INIT = NONE:+VERS-TLS1.0:+ARCFOUR-128:+SHA1:+RSA:+COMP-NULL +KEY_FILE = $SERVICEHOME/https_key_p1.key +CERT_FILE = $SERVICEHOME/https_cert_p1.crt +USE_IPv6 = YES +USE_IPv4 = YES + +[arm] +PORT = 12105 + +[statistics] +PORT = 12104 +UNIXPATH = /tmp/gnunet-p1-service-statistics.sock + +[resolver] +PORT = 12103 +UNIXPATH = /tmp/gnunet-p1-service-resolver.sock + +[peerinfo] +PORT = 12102 +UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock + +[transport] +PORT = 12101 +PLUGINS = https +UNIXPATH = /tmp/gnunet-p1-service-transport.sock +DEBUG = NO + + diff --git a/src/transport/test_transport_api_timeout_https_peer2.conf b/src/transport/test_transport_api_timeout_https_peer2.conf new file mode 100644 index 000000000..2c45b27f7 --- /dev/null +++ b/src/transport/test_transport_api_timeout_https_peer2.conf @@ -0,0 +1,36 @@ +@INLINE@ test_transport_defaults.conf +[PATHS] +SERVICEHOME = /tmp/test-transport/api-https-p2/ +DEFAULTCONFIG = test_transport_api_https_peer2.conf + +[transport-https] +PORT = 12110 +CRYPTO_INIT = NONE:+VERS-TLS1.0:+ARCFOUR-128:+SHA1:+RSA:+COMP-NULL +KEY_FILE = $SERVICEHOME/https_key_p2.key +CERT_FILE = $SERVICEHOME/https_cert_p2.crt +USE_IPv6 = YES +USE_IPv4 = YES + +[arm] +PORT = 12115 +UNIXPATH = /tmp/gnunet-p2-service-arm.sock + +[statistics] +PORT = 12114 +UNIXPATH = /tmp/gnunet-p2-service-statistics.sock + +[resolver] +PORT = 12113 +UNIXPATH = /tmp/gnunet-p2-service-resolver.sock + +[peerinfo] +PORT = 12112 +UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock + +[transport] +PORT = 12111 +PLUGINS = https +UNIXPATH = /tmp/gnunet-p2-service-transport.sock +DEBUG = NO + + diff --git a/src/transport/test_transport_api_timeout_tcp_peer1.conf b/src/transport/test_transport_api_timeout_tcp_peer1.conf new file mode 100644 index 000000000..974481fde --- /dev/null +++ b/src/transport/test_transport_api_timeout_tcp_peer1.conf @@ -0,0 +1,33 @@ +@INLINE@ test_transport_defaults.conf +[PATHS] +SERVICEHOME = /tmp/test-transport/api-tcp-p1/ +DEFAULTCONFIG = template_cfg_peer1.conf + +[transport-tcp] +PORT = 12000 +TIMEOUT = 5000 +BINDTO = 127.0.0.1 + +[arm] +PORT = 12005 +DEFAULTSERVICES = transport +UNIXPATH = /tmp/gnunet-p1-service-arm.sock + +[statistics] +PORT = 12004 +UNIXPATH = /tmp/gnunet-p1-service-statistics.sock + +[resolver] +PORT = 12003 +UNIXPATH = /tmp/gnunet-p1-service-resolver.sock + +[peerinfo] +PORT = 12002 +UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock + +[transport] +PORT = 12001 +UNIXPATH = /tmp/gnunet-p1-service-transport.sock +DEBUG = NO + + diff --git a/src/transport/test_transport_api_timeout_tcp_peer2.conf b/src/transport/test_transport_api_timeout_tcp_peer2.conf new file mode 100644 index 000000000..0d4869f77 --- /dev/null +++ b/src/transport/test_transport_api_timeout_tcp_peer2.conf @@ -0,0 +1,36 @@ +@INLINE@ test_transport_defaults.conf +[PATHS] +SERVICEHOME = /tmp/test-transport/api-tcp-p2/ +DEFAULTCONFIG = template_cfg_peer2.conf + +[nat] +ALLOW_NAT = NO + +[transport-tcp] +PORT = 0 +TIMEOUT = 5000 +BINDTO = 127.0.0.1 + +[arm] +PORT = 12014 +DEFAULTSERVICES = transport +UNIXPATH = /tmp/gnunet-p2-service-arm.sock + +[statistics] +PORT = 12013 +UNIXPATH = /tmp/gnunet-p2-service-statistics.sock + +[resolver] +PORT = 12012 +UNIXPATH = /tmp/gnunet-p2-service-resolver.sock + +[peerinfo] +PORT = 12011 +UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock + +[transport] +PORT = 12010 +UNIXPATH = /tmp/gnunet-p2-service-transport.sock +DEBUG = NO + + diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c index 5d4f86820..9a30f54b8 100644 --- a/src/transport/test_transport_api_unreliability.c +++ b/src/transport/test_transport_api_unreliability.c @@ -39,7 +39,7 @@ #include "transport.h" #include "transport-testing.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO #define VERBOSE_ARM GNUNET_NO -- cgit v1.2.3