From 658c3cf583b0c09e55c41a78a9ec8dbe28cb515e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 23 Jul 2016 22:32:35 +0000 Subject: more refactoring of tests for new send API --- src/transport/Makefile.am | 16 +- src/transport/test_transport_address_switch.c | 2 +- src/transport/test_transport_api_restart_1peer.c | 293 -------------------- src/transport/test_transport_api_restart_2peers.c | 298 --------------------- .../test_transport_api_restart_reconnect.c | 215 +++++++++++++++ src/transport/transport-testing-main.c | 7 +- src/transport/transport-testing-send.c | 5 +- src/transport/transport-testing.c | 61 ++++- src/transport/transport-testing.h | 5 - 9 files changed, 289 insertions(+), 613 deletions(-) delete mode 100644 src/transport/test_transport_api_restart_1peer.c delete mode 100644 src/transport/test_transport_api_restart_2peers.c create mode 100644 src/transport/test_transport_api_restart_reconnect.c (limited to 'src') diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index d6c4e3ccf..b201ab24a 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -431,7 +431,6 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \ if HAVE_TESTING check_PROGRAMS = \ - test_transport_api_restart_2peers \ test_transport_address_switch_tcp \ test_transport_address_switch_udp \ test_transport_testing_startstop \ @@ -450,6 +449,7 @@ check_PROGRAMS = \ test_transport_api_disconnect_tcp \ test_transport_api_tcp \ test_transport_api_restart_1peer \ + test_transport_api_restart_2peers \ test_transport_api_timeout_tcp \ test_transport_api_limited_sockets_tcp \ test_transport_api_tcp_nat \ @@ -508,6 +508,10 @@ endif if ENABLE_TEST_RUN AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; TESTS = \ + test_transport_address_switch_tcp \ + test_transport_address_switch_udp \ + $(HTTP_SWITCH) \ + $(HTTPS_SWITCH) \ test_transport_testing_startstop \ test_transport_testing_restart \ test_plugin_tcp \ @@ -563,11 +567,7 @@ TESTS = \ $(HTTP_API_TIMEOUT_TEST) \ $(HTTPS_API_TIMEOUT_TEST) \ $(WLAN_TIMEOUT_TEST) \ - $(BT_TIMEOUT_TEST) \ - test_transport_address_switch_tcp \ - test_transport_address_switch_udp \ - $(HTTP_SWITCH) \ - $(HTTPS_SWITCH) + $(BT_TIMEOUT_TEST) if HAVE_GETOPT_BINARY TESTS += \ test_transport_api_slow_ats @@ -762,7 +762,7 @@ test_transport_api_tcp_LDADD = \ libgnunettransporttesting.la test_transport_api_restart_1peer_SOURCES = \ - test_transport_api_restart_1peer.c + test_transport_api_restart_reconnect.c test_transport_api_restart_1peer_LDADD = \ libgnunettransport.la \ $(top_builddir)/src/hello/libgnunethello.la \ @@ -772,7 +772,7 @@ test_transport_api_restart_1peer_LDADD = \ libgnunettransporttesting.la test_transport_api_restart_2peers_SOURCES = \ - test_transport_api_restart_2peers.c + test_transport_api_restart_reconnect.c test_transport_api_restart_2peers_LDADD = \ libgnunettransport.la \ $(top_builddir)/src/hello/libgnunethello.la \ diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index 23325d392..3998854da 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c @@ -414,7 +414,7 @@ main (int argc, { struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { .connect_continuation = &connected_cb, - .config_file = "test_transport_api.conf", + .config_file = "test_transport_api_data.conf", .rec = ¬ify_receive, .nc = &GNUNET_TRANSPORT_TESTING_log_connect, .shutdown_task = &custom_shutdown, diff --git a/src/transport/test_transport_api_restart_1peer.c b/src/transport/test_transport_api_restart_1peer.c deleted file mode 100644 index 7a63ed16b..000000000 --- a/src/transport/test_transport_api_restart_1peer.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. - - 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., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -/** - * @file transport/test_transport_api_restart_1peer.c - * @brief base test case for transport implementations - * - * This test case starts 2 peers, connects and exchanges a message - * 1 peer is restarted and tested if peers reconnect - * C code apparently. - */ -#include "platform.h" -#include "gnunet_transport_service.h" -#include "transport-testing.h" - -/** - * How long until we give up on transmitting the message? - */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) - -/** - * How long until we give up on transmitting the message? - */ -#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) - -#define MTYPE 12345 - - -static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; - -static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; - -static int p1_connected; - -static int p2_connected; - -static struct GNUNET_TRANSPORT_TransmitHandle *th; - -static struct GNUNET_SCHEDULER_Task *send_task; - -static int restarted; - - -static void -custom_shutdown (void *cls) -{ - if (NULL != ats_sh) - { - GNUNET_ATS_connectivity_suggest_cancel (ats_sh); - ats_sh = NULL; - } - if (NULL != th) - { - GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - } - if (NULL != send_task) - { - GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - } -} - - -static void -restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, - void *cls) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarted peer %u (`%s'), issuing reconnect\n", - p->no, - GNUNET_i2s (&p->id)); - ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, - &ccc->p[1]->id, - 1); -} - - -static void -restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarting peer %u (`%s')\n", - p->no, - GNUNET_i2s (&p->id)); - GNUNET_assert (GNUNET_OK == - GNUNET_TRANSPORT_TESTING_restart_peer (p, - &restart_cb, - p)); -} - - -static void -notify_receive (void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *message) -{ - { - char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", - receiver->no, - ps, - ntohs (message->type), - ntohs (message->size), - GNUNET_i2s (sender)); - GNUNET_free (ps); - } - if ((MTYPE == ntohs (message->type)) && - (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) - { - if (GNUNET_NO == restarted) - { - restarted = GNUNET_YES; - restart (ccc->p[0]); - return; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarted peers connected and message was sent, stopping test...\n"); - ccc->global_ret = GNUNET_OK; - GNUNET_SCHEDULER_shutdown (); - } - } - else - { - GNUNET_break (0); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown (); - } -} - - -static size_t -notify_ready (void *cls, - size_t size, - void *buf) -{ - struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; - struct GNUNET_MessageHeader *hdr; - - th = NULL; - if (NULL == buf) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout occurred while waiting for transmit_ready\n"); - GNUNET_SCHEDULER_shutdown (); - ccc->global_ret = 42; - return 0; - } - - GNUNET_assert (size >= 256); - hdr = buf; - hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); - hdr->type = htons (MTYPE); - - { - char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); - - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", - ccc->p[1]->no, - ps, - ntohs (hdr->type), - ntohs (hdr->size), - p->no, - GNUNET_i2s (&p->id)); - GNUNET_free (ps); - } - return sizeof (struct GNUNET_MessageHeader); -} - - -static void -sendtask (void *cls) -{ - send_task = NULL; - { - char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", - ccc->p[1]->no, - GNUNET_i2s (&ccc->p[1]->id), - ccc->p[0]->no, - receiver_s); - GNUNET_free (receiver_s); - } - th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, - &ccc->p[0]->id, - 256, - TIMEOUT_TRANSMIT, - ¬ify_ready, - ccc->p[0]); -} - - -static void -notify_connect (void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) -{ - GNUNET_TRANSPORT_TESTING_log_connect (cls, - me, - other); - if (0 == memcmp (other, - &ccc->p[0]->id, - sizeof (struct GNUNET_PeerIdentity))) - p1_connected = GNUNET_YES; - if (0 == memcmp (other, - &ccc->p[1]->id, - sizeof (struct GNUNET_PeerIdentity))) - p2_connected = GNUNET_YES; - - if ( (GNUNET_YES == restarted) && - (GNUNET_YES == p1_connected) && - (GNUNET_YES == p2_connected) ) - { - /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ - send_task = GNUNET_SCHEDULER_add_now (&sendtask, - NULL); - } -} - - -static void -notify_disconnect (void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) -{ - GNUNET_TRANSPORT_TESTING_log_disconnect (cls, - me, - other); - if (me == ccc->p[0]) - p1_connected = GNUNET_NO; - if (me == ccc->p[1]) - p2_connected = GNUNET_NO; - if (NULL != th) - { - GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - } - if (NULL != send_task) - { - GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - } -} - - -int -main (int argc, char *argv[]) -{ - struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { - .connect_continuation = &sendtask, - .config_file = "test_transport_api_data.conf", - .rec = ¬ify_receive, - .nc = ¬ify_connect, - .nd = ¬ify_disconnect, - .shutdown_task = &custom_shutdown, - .timeout = TIMEOUT - }; - - ccc = &my_ccc; - if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main (2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) - return 1; - return 0; -} - -/* end of test_transport_api_restart_1peer.c */ diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c deleted file mode 100644 index 40f287623..000000000 --- a/src/transport/test_transport_api_restart_2peers.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. - - 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., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -/** - * @file transport/test_transport_api_restart_1peer.c - * @brief base test case for transport implementations - * - * This test case starts 2 peers, connects and exchanges a message - * 1 peer is restarted and tested if peers reconnect - * C code apparently. - */ -#include "platform.h" -#include "gnunet_transport_service.h" -#include "transport-testing.h" - -/** - * How long until we give up on transmitting the message? - */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) - -/** - * How long until we give up on transmitting the message? - */ -#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) - -#define MTYPE 12345 - - -static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; - -static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; - -static int p1_connected; - -static int p2_connected; - -static struct GNUNET_TRANSPORT_TransmitHandle *th; - -static struct GNUNET_SCHEDULER_Task *send_task; - -static int restarted; - - -static void -custom_shutdown (void *cls) -{ - if (NULL != ats_sh) - { - GNUNET_ATS_connectivity_suggest_cancel (ats_sh); - ats_sh = NULL; - } - if (NULL != th) - { - GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - } - if (NULL != send_task) - { - GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - } -} - - -static void -restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, - void *cls) -{ - static unsigned int c; - - c++; - if (c != 2) - return; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarted peer %u (`%s'), issuing reconnect\n", - p->no, - GNUNET_i2s (&p->id)); - ats_sh = GNUNET_ATS_connectivity_suggest (ccc->p[0]->ats, - &ccc->p[1]->id, - 1); -} - - -static void -restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarting peer %u (`%s')\n", - p->no, - GNUNET_i2s (&p->id)); - GNUNET_assert (GNUNET_OK == - GNUNET_TRANSPORT_TESTING_restart_peer (p, - &restart_cb, - p)); -} - - -static void -notify_receive (void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *message) -{ - { - char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", - receiver->no, - ps, - ntohs (message->type), - ntohs (message->size), - GNUNET_i2s (sender)); - GNUNET_free (ps); - } - if ((MTYPE == ntohs (message->type)) && - (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) - { - if (GNUNET_NO == restarted) - { - restarted = GNUNET_YES; - restart (ccc->p[0]); - restart (ccc->p[1]); - return; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Restarted peers connected and message was sent, stopping test...\n"); - ccc->global_ret = GNUNET_OK; - GNUNET_SCHEDULER_shutdown (); - } - } - else - { - GNUNET_break (0); - ccc->global_ret = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown (); - } -} - - -static size_t -notify_ready (void *cls, - size_t size, - void *buf) -{ - struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; - struct GNUNET_MessageHeader *hdr; - - th = NULL; - if (NULL == buf) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout occurred while waiting for transmit_ready\n"); - GNUNET_SCHEDULER_shutdown (); - ccc->global_ret = 42; - return 0; - } - - GNUNET_assert (size >= 256); - hdr = buf; - hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); - hdr->type = htons (MTYPE); - - { - char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", - ccc->p[1]->no, - ps, - ntohs (hdr->type), - ntohs (hdr->size), - p->no, - GNUNET_i2s (&p->id)); - GNUNET_free (ps); - } - return sizeof (struct GNUNET_MessageHeader); -} - - -static void -sendtask (void *cls) -{ - send_task = NULL; - { - char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", - ccc->p[1]->no, - GNUNET_i2s (&ccc->p[1]->id), - ccc->p[0]->no, - receiver_s); - GNUNET_free (receiver_s); - } - th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, - &ccc->p[0]->id, - 256, - TIMEOUT_TRANSMIT, - ¬ify_ready, - ccc->p[0]); -} - - -static void -notify_connect (void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) -{ - GNUNET_TRANSPORT_TESTING_log_connect (cls, - me, - other); - if (0 == memcmp (other, - &ccc->p[0]->id, - sizeof (struct GNUNET_PeerIdentity))) - p1_connected = GNUNET_YES; - if (0 == memcmp (other, - &ccc->p[1]->id, - sizeof (struct GNUNET_PeerIdentity))) - p2_connected = GNUNET_YES; - - if ( (GNUNET_YES == restarted) && - (GNUNET_YES == p1_connected) && - (GNUNET_YES == p2_connected) ) - { - /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ - send_task = GNUNET_SCHEDULER_add_now (&sendtask, - NULL); - } -} - - -static void -notify_disconnect (void *cls, - struct GNUNET_TRANSPORT_TESTING_PeerContext *me, - const struct GNUNET_PeerIdentity *other) -{ - GNUNET_TRANSPORT_TESTING_log_disconnect (cls, - me, - other); - if (me == ccc->p[0]) - p1_connected = GNUNET_NO; - if (me == ccc->p[1]) - p2_connected = GNUNET_NO; - if (NULL != th) - { - GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); - th = NULL; - } - if (NULL != send_task) - { - GNUNET_SCHEDULER_cancel (send_task); - send_task = NULL; - } -} - - -int -main (int argc, char *argv[]) -{ - struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { - .connect_continuation = &sendtask, - .config_file = "test_transport_api_data.conf", - .rec = ¬ify_receive, - .nc = ¬ify_connect, - .nd = ¬ify_disconnect, - .shutdown_task = &custom_shutdown, - .timeout = TIMEOUT - }; - - ccc = &my_ccc; - if (GNUNET_OK != - GNUNET_TRANSPORT_TESTING_main (2, - &GNUNET_TRANSPORT_TESTING_connect_check, - ccc)) - return 1; - return 0; -} - -/* end of test_transport_api_restart_1peer.c */ diff --git a/src/transport/test_transport_api_restart_reconnect.c b/src/transport/test_transport_api_restart_reconnect.c new file mode 100644 index 000000000..6fd969918 --- /dev/null +++ b/src/transport/test_transport_api_restart_reconnect.c @@ -0,0 +1,215 @@ +/* + This file is part of GNUnet. + Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +/** + * @file transport/test_transport_api_restart_reconnect.c + * @brief base test case for transport implementations + * + * This test case starts 2 peers, connects and exchanges a message. + * Then, 1 or 2 peers are restarted and it is tested if peers reconnect. + * How many peers are restarted is determined by the name of the binary. + */ +#include "platform.h" +#include "gnunet_transport_service.h" +#include "transport-testing.h" + +/** + * How long until we give up on transmitting the message? + */ +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) + + +static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; + +static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; + +static int p1_connected; + +static int p2_connected; + +static int restarted; + + +static void +custom_shutdown (void *cls) +{ + if (NULL != ats_sh) + { + GNUNET_ATS_connectivity_suggest_cancel (ats_sh); + ats_sh = NULL; + } +} + + +static void +restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, + void *cls) +{ + static unsigned int c; + + c++; + if ( (2 != c) && + (NULL != strstr (ccc->test_name, + "2peers")) ) + return; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Restarted peer %u (`%s'), issuing reconnect\n", + p->no, + GNUNET_i2s (&p->id)); + ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, + &ccc->p[1]->id, + 1); +} + + +static void +restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Restarting peer %u (`%s')\n", + p->no, + GNUNET_i2s (&p->id)); + GNUNET_assert (GNUNET_OK == + GNUNET_TRANSPORT_TESTING_restart_peer (p, + &restart_cb, + p)); +} + + +static void +notify_receive (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *message) +{ + { + char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", + receiver->no, + ps, + ntohs (message->type), + ntohs (message->size), + GNUNET_i2s (sender)); + GNUNET_free (ps); + } + if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) && + (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->size)) ) + { + if (GNUNET_NO == restarted) + { + restarted = GNUNET_YES; + fprintf (stderr, "TN: %s\n", ccc->test_name); + restart (ccc->p[0]); + if (NULL != strstr (ccc->test_name, + "2peers")) + restart (ccc->p[1]); + return; + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Restarted peers connected and message was sent, stopping test...\n"); + ccc->global_ret = GNUNET_OK; + GNUNET_SCHEDULER_shutdown (); + } + } + else + { + GNUNET_break (0); + ccc->global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + } +} + + +static void +notify_connect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) +{ + static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { + .num_messages = 1 + }; + + sc.ccc = ccc; + GNUNET_TRANSPORT_TESTING_log_connect (cls, + me, + other); + if (me == ccc->p[0]) + p1_connected = GNUNET_YES; + if (me == ccc->p[1]) + p2_connected = GNUNET_YES; + + if ( (GNUNET_YES == restarted) && + (GNUNET_YES == p1_connected) && + (GNUNET_YES == p2_connected) ) + { + /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ + GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send, + &sc); + } +} + + +static void +notify_disconnect (void *cls, + struct GNUNET_TRANSPORT_TESTING_PeerContext *me, + const struct GNUNET_PeerIdentity *other) +{ + GNUNET_TRANSPORT_TESTING_log_disconnect (cls, + me, + other); + if (me == ccc->p[0]) + p1_connected = GNUNET_NO; + if (me == ccc->p[1]) + p2_connected = GNUNET_NO; +} + + +int +main (int argc, + char *argv[]) +{ + struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { + .num_messages = 1 + }; + struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { + .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send, + .connect_continuation_cls = &sc, + .config_file = "test_transport_api_data.conf", + .rec = ¬ify_receive, + .nc = ¬ify_connect, + .nd = ¬ify_disconnect, + .shutdown_task = &custom_shutdown, + .timeout = TIMEOUT + }; + + ccc = &my_ccc; + sc.ccc = ccc; + if (GNUNET_OK != + GNUNET_TRANSPORT_TESTING_main (2, + &GNUNET_TRANSPORT_TESTING_connect_check, + ccc)) + return 1; + return 0; +} + +/* end of test_transport_api_restart_1peer.c */ diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c index f196d586b..79f6a0152 100644 --- a/src/transport/transport-testing-main.c +++ b/src/transport/transport-testing-main.c @@ -145,9 +145,8 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext /** - * Function called when we connected two peers. - * Once we have gotten to the clique, launch - * test-specific logic. + * Function called when we connected two peers. Once we have gotten + * to the clique, launch test-specific logic. * * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *` */ @@ -511,7 +510,7 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, for (unsigned int i=0;iconnected) + return; *cr = cx; } @@ -144,8 +146,7 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send sender, &find_cr, &cr); - if ( (NULL == cr) || - (GNUNET_YES != cr->connected) ) + if (NULL == cr) { GNUNET_break (0); return GNUNET_NO; diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 50c297389..899ef7851 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -77,6 +77,10 @@ static void set_p1c (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { + int *found = cls; + + if (NULL != found) + *found = GNUNET_YES; cx->p1_c = GNUNET_YES; } @@ -85,6 +89,10 @@ static void set_p2c (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { + int *found = cls; + + if (NULL != found) + *found = GNUNET_YES; cx->p2_c = GNUNET_YES; } @@ -93,6 +101,10 @@ static void clear_p1c (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { + int *found = cls; + + if (NULL != found) + *found = GNUNET_YES; cx->p1_c = GNUNET_NO; } @@ -101,6 +113,10 @@ static void clear_p2c (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) { + int *found = cls; + + if (NULL != found) + *found = GNUNET_YES; cx->p2_c = GNUNET_NO; } @@ -115,6 +131,7 @@ notify_connect (void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; + int found; p2 = find_peer_context (p->tth, peer); @@ -138,14 +155,36 @@ notify_connect (void *cls, GNUNET_i2s (&p->id)); GNUNET_free (p2_s); /* update flags in connecting contexts */ + found = GNUNET_NO; GNUNET_TRANSPORT_TESTING_find_connecting_context (p, p2, &set_p1c, - NULL); + &found); + if (GNUNET_NO == found) + { + cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); + cc->p1 = p; + cc->p2 = p2; + cc->p1_c = GNUNET_YES; + GNUNET_CONTAINER_DLL_insert (tth->cc_head, + tth->cc_tail, + cc); + } + found = GNUNET_NO; GNUNET_TRANSPORT_TESTING_find_connecting_context (p2, p, &set_p2c, - NULL); + &found); + if (GNUNET_NO == found) + { + cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); + cc->p1 = p2; + cc->p2 = p; + cc->p1_c = GNUNET_YES; + GNUNET_CONTAINER_DLL_insert (tth->cc_head, + tth->cc_tail, + cc); + } /* update set connected flag for all requests */ for (cc = tth->cc_head; NULL != cc; cc = cc->next) { @@ -703,7 +742,19 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont { struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; + ccn = NULL; + for (cc = tth->cc_head; NULL != cc; cc = cc->next) + { + if ( (cc->p1 == p1) && + (cc->p2 == p2) ) + { + ccn = cc; + break; + } + } + cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); cc->p1 = p1; cc->p2 = p2; @@ -712,6 +763,12 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont cc->cb_cls = cls; else cc->cb_cls = cc; + if (NULL != ccn) + { + cc->p1_c = ccn->p1_c; + cc->p2_c = ccn->p2_c; + cc->connected = ccn->connected; + } GNUNET_CONTAINER_DLL_insert (tth->cc_head, tth->cc_tail, cc); diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index bfed64b70..806b8c5f9 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h @@ -769,11 +769,6 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, /* ***************** Convenience functions for sending ********* */ -// TODO: -// - need to have continuation after send is done! -// - need easy way to specify continuation in case -// of the scheduler tasks - /** * Send a test message of type @a mtype and size @a msize from * peer @a sender to peer @a receiver. The peers should be -- cgit v1.2.3