From b05d9b4b7cead622dce8342daa5556b76647bc31 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 11 Mar 2017 12:58:13 +0100 Subject: [PATCH] remove old CADET testcases --- src/cadet/Makefile.am | 95 +-- src/cadet/cadet_path.c | 363 ---------- src/cadet/cadet_path.h | 226 ------- src/cadet/test_cadet.c | 1162 --------------------------------- src/cadet/test_cadet_local.c | 351 ---------- src/cadet/test_cadet_single.c | 354 ---------- 6 files changed, 1 insertion(+), 2550 deletions(-) delete mode 100644 src/cadet/cadet_path.c delete mode 100644 src/cadet/cadet_path.h delete mode 100644 src/cadet/test_cadet.c delete mode 100644 src/cadet/test_cadet_local.c delete mode 100644 src/cadet/test_cadet_single.c diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index 518646664..c33a653b0 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am @@ -116,25 +116,7 @@ check_PROGRAMS = \ test_cadet_5_speed_ack_new \ test_cadet_5_speed_reliable_new \ test_cadet_5_speed_reliable_backwards_new \ - test_cadet_5_speed_backwards_new \ - test_cadet_single \ - test_cadet_local \ - test_cadet_2_forward \ - test_cadet_2_signal \ - test_cadet_2_keepalive \ - test_cadet_2_speed \ - test_cadet_2_speed_ack \ - test_cadet_2_speed_backwards \ - test_cadet_2_speed_reliable \ - test_cadet_2_speed_reliable_backwards \ - test_cadet_5_forward \ - test_cadet_5_signal \ - test_cadet_5_keepalive \ - test_cadet_5_speed \ - test_cadet_5_speed_ack \ - test_cadet_5_speed_reliable \ - test_cadet_5_speed_reliable_backwards \ - test_cadet_5_speed_backwards + test_cadet_5_speed_backwards_new endif ld_cadet_test_lib = \ @@ -156,15 +138,6 @@ gnunet_cadet_profiler_SOURCES = \ gnunet_cadet_profiler_LDADD = $(ld_cadet_test_lib) -test_cadet_single_SOURCES = \ - test_cadet_single.c -test_cadet_single_LDADD = $(ld_cadet_test_lib) - -test_cadet_local_SOURCES = \ - test_cadet_local.c -test_cadet_local_LDADD = $(ld_cadet_test_lib) - - test_cadet_local_mq_SOURCES = \ test_cadet_local_mq.c test_cadet_local_mq_LDADD = \ @@ -172,73 +145,7 @@ test_cadet_local_mq_LDADD = \ $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la -test_cadet_2_forward_SOURCES = \ - test_cadet.c -test_cadet_2_forward_LDADD = $(ld_cadet_test_lib) - -test_cadet_2_signal_SOURCES = \ - test_cadet.c -test_cadet_2_signal_LDADD = $(ld_cadet_test_lib) - -test_cadet_2_keepalive_SOURCES = \ - test_cadet.c -test_cadet_2_keepalive_LDADD = $(ld_cadet_test_lib) - -test_cadet_2_speed_SOURCES = \ - test_cadet.c -test_cadet_2_speed_LDADD = $(ld_cadet_test_lib) - -test_cadet_2_speed_ack_SOURCES = \ - test_cadet.c -test_cadet_2_speed_ack_LDADD = $(ld_cadet_test_lib) - -test_cadet_2_speed_backwards_SOURCES = \ - test_cadet.c -test_cadet_2_speed_backwards_LDADD = $(ld_cadet_test_lib) - -test_cadet_2_speed_reliable_SOURCES = \ - test_cadet.c -test_cadet_2_speed_reliable_LDADD = $(ld_cadet_test_lib) - -test_cadet_2_speed_reliable_backwards_SOURCES = \ - test_cadet.c -test_cadet_2_speed_reliable_backwards_LDADD = $(ld_cadet_test_lib) - - -test_cadet_5_forward_SOURCES = \ - test_cadet.c -test_cadet_5_forward_LDADD = $(ld_cadet_test_lib) - -test_cadet_5_signal_SOURCES = \ - test_cadet.c -test_cadet_5_signal_LDADD = $(ld_cadet_test_lib) - -test_cadet_5_keepalive_SOURCES = \ - test_cadet.c -test_cadet_5_keepalive_LDADD = $(ld_cadet_test_lib) - -test_cadet_5_speed_SOURCES = \ - test_cadet.c -test_cadet_5_speed_LDADD = $(ld_cadet_test_lib) - -test_cadet_5_speed_ack_SOURCES = \ - test_cadet.c -test_cadet_5_speed_ack_LDADD = $(ld_cadet_test_lib) - -test_cadet_5_speed_backwards_SOURCES = \ - test_cadet.c -test_cadet_5_speed_backwards_LDADD = $(ld_cadet_test_lib) - -test_cadet_5_speed_reliable_SOURCES = \ - test_cadet.c -test_cadet_5_speed_reliable_LDADD = $(ld_cadet_test_lib) - -test_cadet_5_speed_reliable_backwards_SOURCES = \ - test_cadet.c -test_cadet_5_speed_reliable_backwards_LDADD = $(ld_cadet_test_lib) - -# NEW TESTS libgnunetcadettestnew_la_SOURCES = \ cadet_test_lib_new.c cadet_test_lib_new.h libgnunetcadettestnew_la_LIBADD = \ diff --git a/src/cadet/cadet_path.c b/src/cadet/cadet_path.c deleted file mode 100644 index 79a498805..000000000 --- a/src/cadet/cadet_path.c +++ /dev/null @@ -1,363 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2001 - 2013 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 cadet/cadet_path.c - * @brief Path handling functions - * @author Bartlomiej Polot - */ - -#include "cadet.h" -#include "cadet_path.h" -#include "gnunet-service-cadet_peer.h" - -#define LOG(level, ...) GNUNET_log_from (level,"cadet-pth",__VA_ARGS__) - - -/** - * @brief Destroy a path after some time has past. - * Removes the path from the peer (must not be used for direct paths). - * - * @param cls Closure (path to destroy). - */ -static void -path_destroy_delayed (void *cls) -{ - struct CadetPeerPath *path = cls; - struct CadetPeer *peer; - - path->path_delete = NULL; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroy delayed %p (%u)\n", - path, - path->length); - GNUNET_assert (2 < path->length); - peer = GCP_get_short (path->peers[path->length - 1], - GNUNET_NO); - GNUNET_assert (NULL != peer); - GCP_remove_path (peer, path); -} - - -/** - * Create a new path - * - * @param length How many hops will the path have. - * @return A newly allocated path with a peer array of the specified length. - */ -struct CadetPeerPath * -path_new (unsigned int length) -{ - struct CadetPeerPath *p; - - p = GNUNET_new (struct CadetPeerPath); - if (length > 0) - { - p->length = length; - p->peers = GNUNET_malloc (length * sizeof (GNUNET_PEER_Id)); - } - LOG (GNUNET_ERROR_TYPE_DEBUG, "New path %p (%u)\n", p, p->length); - return p; -} - - -/** - * Invert the path - * - * @param path the path to invert - */ -void -path_invert (struct CadetPeerPath *path) -{ - GNUNET_PEER_Id aux; - unsigned int i; - - for (i = 0; i < path->length / 2; i++) - { - aux = path->peers[i]; - path->peers[i] = path->peers[path->length - i - 1]; - path->peers[path->length - i - 1] = aux; - } -} - - -/** - * Duplicate a path, incrementing short peer's rc. - * - * @param path The path to duplicate. - */ -struct CadetPeerPath * -path_duplicate (const struct CadetPeerPath *path) -{ - struct CadetPeerPath *aux; - unsigned int i; - - aux = path_new (path->length); - GNUNET_memcpy (aux->peers, - path->peers, - path->length * sizeof (GNUNET_PEER_Id)); - for (i = 0; i < aux->length; i++) - GNUNET_PEER_change_rc (aux->peers[i], 1); - return aux; -} - - -/** - * Get the length of a path. - * - * @param path The path to measure, with the local peer at any point of it. - * - * @return Number of hops to reach destination. - * UINT_MAX in case the peer is not in the path. - */ -unsigned int -path_get_length (struct CadetPeerPath *path) -{ - if (NULL == path) - return UINT_MAX; - return path->length; -} - - - -/** - * Mark path as invalid: keep it aroud for a while to avoid trying it in a loop. - * - * Never invalidates a two-hop (direct) path, only a core handler can do that. - * - * Rationale: DHT_get sometimes returns bad cached results, for instance, - * on a locally cached result where the PUT followed a path that is no longer - * current. The path must remain "known and marked as invalid" for a while. - * - * @param p Path to invalidate. - */ -void -path_invalidate (struct CadetPeerPath *p) -{ - if (NULL != p->path_delete) - return; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Invalidating path %p (%u)\n", - p, - p->length); - p->path_delete - = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, - &path_destroy_delayed, p); -} - - -/** - * Builds a path from a PeerIdentity array. - * - * @param peers PeerIdentity array. - * @param size Size of the @c peers array. - * @param myid ID of local peer, to find @c own_pos. - * @param own_pos Output parameter: own position in the path. - * - * @return Fixed and shortened path. - */ -struct CadetPeerPath * -path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers, - unsigned int size, - GNUNET_PEER_Id myid, - unsigned int *own_pos) -{ - struct CadetPeerPath *path; - GNUNET_PEER_Id shortid; - unsigned int i; - unsigned int j; - unsigned int offset; - - /* Create path */ - LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n"); - path = path_new (size); - *own_pos = 0; - offset = 0; - for (i = 0; i < size; i++) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, " - %u: taking %s\n", - i, GNUNET_i2s (&peers[i])); - shortid = GNUNET_PEER_intern (&peers[i]); - - /* Check for loops / duplicates */ - for (j = 0; j < i - offset; j++) - { - if (path->peers[j] == shortid) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, " already exists at pos %u\n", j); - offset = i - j; - LOG (GNUNET_ERROR_TYPE_DEBUG, " offset now %u\n", offset); - GNUNET_PEER_change_rc (shortid, -1); - } - } - LOG (GNUNET_ERROR_TYPE_DEBUG, " storing at %u\n", i - offset); - path->peers[i - offset] = shortid; - if (path->peers[i - offset] == myid) - *own_pos = i - offset; - } - path->length -= offset; - - if (path->peers[*own_pos] != myid) - { - /* create path: self not found in path through self */ - GNUNET_break_op (0); - path_destroy (path); - return NULL; - } - - return path; -} - - -/** - * Test if two paths are equivalent (equal or revese of each other). - * - * @param p1 First path - * @param p2 Second path - * - * @return #GNUNET_YES if both paths are equivalent - * #GNUNET_NO otherwise - */ -int -path_equivalent (const struct CadetPeerPath *p1, - const struct CadetPeerPath *p2) -{ - unsigned int i; - unsigned int l; - unsigned int half; - - if (NULL == p1 || NULL == p2) - return GNUNET_NO; - - if (p1->length != p2->length) - return GNUNET_NO; - - l = p1->length; - if (0 == memcmp (p1->peers, p2->peers, sizeof (p1->peers[0]) * l)) - return GNUNET_YES; - - half = l / 2; - l = l - 1; - for (i = 0; i <= half; i++) - if (p1->peers[i] != p2->peers[l - i]) - return GNUNET_NO; - - return GNUNET_YES; -} - - -/** - * Test if a path is valid (or at least not known to be invalid). - * - * @param path Path to test. - * - * @return #GNUNET_YES If the path is valid or unknown, - * #GNUNET_NO If the path is known to be invalid. - */ -int -path_is_valid (const struct CadetPeerPath *path) -{ - return (NULL == path->path_delete); -} - - -/** - * Destroy the path and free any allocated resources linked to it - * - * @param p the path to destroy - * - * @return #GNUNET_OK on success - */ -int -path_destroy (struct CadetPeerPath *p) -{ - if (NULL == p) - return GNUNET_OK; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "destroying path %p (%u)\n", - p, - p->length); - GNUNET_PEER_decrement_rcs (p->peers, p->length); - GNUNET_free_non_null (p->peers); - if (NULL != p->path_delete) - GNUNET_SCHEDULER_cancel (p->path_delete); - GNUNET_free (p); - return GNUNET_OK; -} - - -/** - * Compare two paths. - * - * @param p1 First path. - * @param p2 Second path. - * - * @return > 0 if p1 is longer, or the first differing PEER_Id is higher on p1. - * < 0 if p2 is longer, or the first differing PEER_Id is higher on p2. - * 0 if they are identical. - */ -int -path_cmp (const struct CadetPeerPath *p1, - const struct CadetPeerPath *p2) -{ - if (p1->length > p2->length) - return 1; - - if (p1->length < p2->length) - return -1; - - return memcmp (p1->peers, - p2->peers, - sizeof (GNUNET_PEER_Id) * p1->length); -} - - -char * -path_2s (struct CadetPeerPath *p) -{ - char *s; - char *old; - unsigned int i; - - old = GNUNET_strdup (""); - for (i = 0; i < p->length; i++) - { - GNUNET_asprintf (&s, "%s %s", - old, GNUNET_i2s (GNUNET_PEER_resolve2 (p->peers[i]))); - GNUNET_free_non_null (old); - old = s; - } - return old; -} - - -void -path_debug (struct CadetPeerPath *p) -{ - unsigned int i; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PATH:\n"); - for (i = 0; i < p->length; i++) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n", - GNUNET_i2s (GNUNET_PEER_resolve2 (p->peers[i]))); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "END\n"); -} diff --git a/src/cadet/cadet_path.h b/src/cadet/cadet_path.h deleted file mode 100644 index bb68eec42..000000000 --- a/src/cadet/cadet_path.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2001 - 2013 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 cadet/cadet_path.h - * @brief Path handling functions - * @author Bartlomiej Polot - */ - -#ifndef CADET_PATH_H_ -#define CADET_PATH_H_ - -#ifdef __cplusplus -extern "C" -{ - #if 0 /* keep Emacsens' auto-indent happy */ -} -#endif -#endif - - -/******************************************************************************/ -/************************ DATA STRUCTURES ****************************/ -/******************************************************************************/ - -/** - * Information regarding a possible path to reach a single peer - */ -struct CadetPeerPath -{ - - /** - * Linked list - */ - struct CadetPeerPath *next; - struct CadetPeerPath *prev; - - /** - * List of all the peers that form the path from origin to target. - */ - GNUNET_PEER_Id *peers; - - /** - * Number of peers (hops) in the path - */ - unsigned int length; - - /** - * User defined data store. - */ - struct CadetConnection *c; - - /** - * Path's score, how reliable is the path. - */ -// int score; - - /** - * Task to delete the path. - * We tried it, it didn't work, don't try again in a while. - */ - struct GNUNET_SCHEDULER_Task * path_delete; - -}; - -/******************************************************************************/ -/************************* FUNCTIONS *****************************/ -/******************************************************************************/ - -/** - * Create a new path. - * - * @param length How many hops will the path have. - * - * @return A newly allocated path with a peer array of the specified length. - */ -struct CadetPeerPath * -path_new (unsigned int length); - - -/** - * Invert the path. - * - * @param path The path to invert. - */ -void -path_invert (struct CadetPeerPath *path); - - -/** - * Duplicate a path, incrementing short peer's rc. - * - * @param path The path to duplicate. - */ -struct CadetPeerPath * -path_duplicate (const struct CadetPeerPath *path); - - -/** - * Get the length of a path. - * - * @param path The path to measure, with the local peer at any point of it. - * - * @return Number of hops to reach destination. - * UINT_MAX in case the peer is not in the path. - */ -unsigned int -path_get_length (struct CadetPeerPath *path); - -/** - * Mark path as invalid: keep it aroud for a while to avoid trying it in a loop. - * - * DHT_get sometimes returns bad cached results, for instance, on a locally - * cached result where the PUT followed a path that is no longer current. - * - * @param p Path to invalidate. - */ -void -path_invalidate (struct CadetPeerPath *p); - -/** - * Test if two paths are equivalent (equal or revese of each other). - * - * @param p1 First path - * @param p2 Second path - * - * @return GNUNET_YES if both paths are equivalent - * GNUNET_NO otherwise - */ -int -path_equivalent (const struct CadetPeerPath *p1, - const struct CadetPeerPath *p2); - -/** - * Test if a path is valid (or at least not known to be invalid). - * - * @param path Path to test. - * - * @return #GNUNET_YES If the path is valid or unknown, - * #GNUNET_NO If the path is known to be invalid. - */ -int -path_is_valid (const struct CadetPeerPath *path); - -/** - * Destroy the path and free any allocated resources linked to it - * - * @param p the path to destroy - * - * @return GNUNET_OK on success - */ -int -path_destroy (struct CadetPeerPath *p); - -/** - * Compare two paths. - * - * @param p1 First path. - * @param p2 Second path. - * - * @return > 0 if p1 is longer, or the first differing PEER_Id is higher on p1. - * < 0 if p2 is longer, or the first differing PEER_Id is higher on p2. - * 0 if they are identical. - */ -int -path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2); - -/** - * Builds a path from a PeerIdentity array. - * - * @param peers PeerIdentity array. - * @param size Size of the @c peers array. - * @param myid ID of local peer, to find @c own_pos. - * @param own_pos Output parameter: own position in the path. - * - * @return Fixed and shortened path. - */ -struct CadetPeerPath * -path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers, - unsigned int size, - GNUNET_PEER_Id myid, - unsigned int *own_pos); - -/** - * Path -> allocated one line string. Caller must free. - * - * @param p Path. - */ -char * -path_2s (struct CadetPeerPath *p); - -/** - * Print info about the path for debug. - * - * @param p Path to debug. - */ -void -path_debug (struct CadetPeerPath *p); - -#if 0 /* keep Emacsens' auto-indent happy */ -{ - #endif - #ifdef __cplusplus -} -#endif - - -/* ifndef CADET_PATH_H */ -#endif diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c deleted file mode 100644 index e57c01be2..000000000 --- a/src/cadet/test_cadet.c +++ /dev/null @@ -1,1162 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2011, 2017 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 cadet/test_cadet.c - * @author Bart Polot - * @author Christian Grothoff - * @brief Test for the cadet service: retransmission of traffic. - */ -#include -#include "platform.h" -#include "cadet_test_lib.h" -#include "gnunet_cadet_service.h" -#include "gnunet_statistics_service.h" -#include - - -/** - * How many messages to send - */ -#define TOTAL_PACKETS 500 /* Cannot exceed 64k! */ - -/** - * How long until we give up on connecting the peers? - */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) - -/** - * Time to wait for stuff that should be rather fast - */ -#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) - -/** - * DIFFERENT TESTS TO RUN - */ -#define SETUP 0 -#define FORWARD 1 -#define KEEPALIVE 2 -#define SPEED 3 -#define SPEED_ACK 4 -#define SPEED_REL 8 -#define P2P_SIGNAL 10 - -/** - * Which test are we running? - */ -static int test; - -/** - * String with test name - */ -static char *test_name; - -/** - * Flag to send traffic leaf->root in speed tests to test BCK_ACK logic. - */ -static int test_backwards = GNUNET_NO; - -/** - * How many events have happened - */ -static int ok; - -/** - * Number of events expected to conclude the test successfully. - */ -static int ok_goal; - -/** - * Size of each test packet - */ -static size_t size_payload = sizeof (struct GNUNET_MessageHeader) + sizeof (uint32_t); - -/** - * Operation to get peer ids. - */ -static struct GNUNET_TESTBED_Operation *t_op[2]; - -/** - * Peer ids. - */ -static struct GNUNET_PeerIdentity *p_id[2]; - -/** - * Port ID - */ -static struct GNUNET_HashCode port; - -/** - * Peer ids counter. - */ -static unsigned int p_ids; - -/** - * Is the setup initialized? - */ -static int initialized; - -/** - * Number of payload packes sent. - */ -static int data_sent; - -/** - * Number of payload packets received. - */ -static int data_received; - -/** - * Number of payload packed acknowledgements sent. - */ -static int ack_sent; - -/** - * Number of payload packed explicitly (app level) acknowledged. - */ -static int ack_received; - -/** - * Total number of peers asked to run. - */ -static unsigned long long peers_requested; - -/** - * Number of currently running peers (should be same as @c peers_requested). - */ -static unsigned long long peers_running; - -/** - * Test context (to shut down). - */ -struct GNUNET_CADET_TEST_Context *test_ctx; - -/** - * Task called to disconnect peers. - */ -static struct GNUNET_SCHEDULER_Task *disconnect_task; - -/** - * Task To perform tests - */ -static struct GNUNET_SCHEDULER_Task *test_task; - -/** - * Task runnining #data_task(). - */ -static struct GNUNET_SCHEDULER_Task *data_job; - -/** - * Cadet handle for the root peer - */ -static struct GNUNET_CADET_Handle *h1; - -/** - * Cadet handle for the first leaf peer - */ -static struct GNUNET_CADET_Handle *h2; - -/** - * Channel handle for the root peer - */ -static struct GNUNET_CADET_Channel *ch; - -/** - * Channel handle for the dest peer - */ -static struct GNUNET_CADET_Channel *incoming_ch; - -/** - * Transmit handle for root data calls - */ -static struct GNUNET_CADET_TransmitHandle *th; - -/** - * Transmit handle for root data calls - */ -static struct GNUNET_CADET_TransmitHandle *incoming_th; - - -/** - * Time we started the data transmission (after channel has been established - * and initilized). - */ -static struct GNUNET_TIME_Absolute start_time; - -/** - * Peers handle. - */ -static struct GNUNET_TESTBED_Peer **testbed_peers; - -/** - * Statistics operation handle. - */ -static struct GNUNET_TESTBED_Operation *stats_op; - -/** - * Keepalives sent. - */ -static unsigned int ka_sent; - -/** - * Keepalives received. - */ -static unsigned int ka_received; - -/** - * How many messages were dropped by CADET because of full buffers? - */ -static unsigned int msg_dropped; - - -/** - * Get the client number considered as the "target" or "receiver", depending on - * the test type and size. - * - * @return Peer # of the target client, either 0 (for backward tests) or - * the last peer in the line (for other tests). - */ -static unsigned int -get_expected_target () -{ - if (SPEED == test && GNUNET_YES == test_backwards) - return 0; - else - return peers_requested - 1; -} - - -/** - * Show the results of the test (banwidth acheived) and log them to GAUGER - */ -static void -show_end_data (void) -{ - static struct GNUNET_TIME_Absolute end_time; - static struct GNUNET_TIME_Relative total_time; - - end_time = GNUNET_TIME_absolute_get(); - total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); - FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name); - FPRINTF (stderr, "Test time %s\n", - GNUNET_STRINGS_relative_time_to_string (total_time, - GNUNET_YES)); - FPRINTF (stderr, "Test bandwidth: %f kb/s\n", - 4 * TOTAL_PACKETS * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms - FPRINTF (stderr, "Test throughput: %f packets/s\n\n", - TOTAL_PACKETS * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms - GAUGER ("CADET", test_name, - TOTAL_PACKETS * 1000.0 / (total_time.rel_value_us / 1000), - "packets/s"); -} - - -/** - * Disconnect from cadet services af all peers, call shutdown. - * - * @param cls Closure (line number from which termination was requested). - * @param tc Task Context. - */ -static void -disconnect_cadet_peers (void *cls) -{ - long line = (long) cls; - unsigned int i; - - disconnect_task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "disconnecting cadet service of peers, called from line %ld\n", - line); - for (i = 0; i < 2; i++) - { - GNUNET_TESTBED_operation_done (t_op[i]); - } - if (NULL != ch) - { - if (NULL != th) - { - GNUNET_CADET_notify_transmit_ready_cancel (th); - th = NULL; - } - GNUNET_CADET_channel_destroy (ch); - ch = NULL; - } - if (NULL != incoming_ch) - { - if (NULL != incoming_th) - { - GNUNET_CADET_notify_transmit_ready_cancel (incoming_th); - incoming_th = NULL; - } - GNUNET_CADET_channel_destroy (incoming_ch); - incoming_ch = NULL; - } - GNUNET_CADET_TEST_cleanup (test_ctx); - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Shut down peergroup, clean up. - * - * @param cls Closure (unused). - * @param tc Task Context. - */ -static void -shutdown_task (void *cls) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); - if (NULL != data_job) - { - GNUNET_SCHEDULER_cancel (data_job); - data_job = NULL; - } - if (NULL != test_task) - { - GNUNET_SCHEDULER_cancel (test_task); - test_task = NULL; - } - if (NULL != disconnect_task) - { - GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, - (void *) __LINE__); - } -} - - -/** - * Stats callback. Finish the stats testbed operation and when all stats have - * been iterated, shutdown the test. - * - * @param cls Closure (line number from which termination was requested). - * @param op the operation that has been finished - * @param emsg error message in case the operation has failed; will be NULL if - * operation has executed successfully. - */ -static void -stats_cont (void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - " KA sent: %u, KA received: %u\n", - ka_sent, - ka_received); - if ( (KEEPALIVE == test) && - ( (ka_sent < 2) || - (ka_sent > ka_received + 1)) ) - { - GNUNET_break (0); - ok--; - } - GNUNET_TESTBED_operation_done (stats_op); - - if (NULL != disconnect_task) - GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, - cls); -} - - -/** - * Process statistic values. - * - * @param cls closure (line number, unused) - * @param peer the peer the statistic belong to - * @param subsystem name of subsystem that created the statistic - * @param name the name of the datum - * @param value the current value - * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not - * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration - */ -static int -stats_iterator (void *cls, - const struct GNUNET_TESTBED_Peer *peer, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) -{ - static const char *s_sent = "# keepalives sent"; - static const char *s_recv = "# keepalives received"; - static const char *rdrops = "# messages dropped due to full buffer"; - static const char *cdrops = "# messages dropped due to slow client"; - uint32_t i; - - i = GNUNET_TESTBED_get_index (peer); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "STATS PEER %u - %s [%s]: %llu\n", - i, - subsystem, - name, - (unsigned long long) value); - if (0 == strncmp (s_sent, name, strlen (s_sent)) && 0 == i) - ka_sent = value; - if (0 == strncmp(s_recv, name, strlen (s_recv)) && peers_requested - 1 == i) - ka_received = value; - if (0 == strncmp(rdrops, name, strlen (rdrops))) - msg_dropped += value; - if (0 == strncmp(cdrops, name, strlen (cdrops))) - msg_dropped += value; - - return GNUNET_OK; -} - - -/** - * Task to gather all statistics. - * - * @param cls Closure (NULL). - */ -static void -gather_stats_and_exit (void *cls) -{ - long l = (long) cls; - - disconnect_task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "gathering statistics from line %d\n", - (int) l); - if (NULL != ch) - { - if (NULL != th) - { - GNUNET_CADET_notify_transmit_ready_cancel (th); - th = NULL; - } - GNUNET_CADET_channel_destroy (ch); - ch = NULL; - } - stats_op = GNUNET_TESTBED_get_statistics (peers_running, testbed_peers, - "cadet", NULL, - &stats_iterator, stats_cont, cls); -} - - - -/** - * Abort test: schedule disconnect and shutdown immediately - * - * @param line Line in the code the abort is requested from (__LINE__). - */ -static void -abort_test (long line) -{ - if (NULL != disconnect_task) - { - GNUNET_SCHEDULER_cancel (disconnect_task); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Aborting test from %ld\n", line); - disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, - (void *) line); - } -} - -/** - * Transmit ready callback. - * - * @param cls Closure (message type). - * @param size Size of the tranmist buffer. - * @param buf Pointer to the beginning of the buffer. - * - * @return Number of bytes written to buf. - */ -static size_t -tmt_rdy (void *cls, size_t size, void *buf); - - -/** - * Task to request a new data transmission. - * - * @param cls Closure (peer #). - */ -static void -data_task (void *cls) -{ - struct GNUNET_CADET_Channel *channel; - static struct GNUNET_CADET_TransmitHandle **pth; - long src; - - data_job = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n"); - if (GNUNET_YES == test_backwards) - { - channel = incoming_ch; - pth = &incoming_th; - src = peers_requested - 1; - } - else - { - channel = ch; - pth = &th; - src = 0; - } - - GNUNET_assert (NULL != channel); - GNUNET_assert (NULL == *pth); - - *pth = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, - GNUNET_TIME_UNIT_FOREVER_REL, - size_payload + data_sent, - &tmt_rdy, (void *) src); - if (NULL == *pth) - { - unsigned long i = (unsigned long) cls; - - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retransmission\n"); - if (0 == i) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " in 1 ms\n"); - data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, - &data_task, (void *) 1L); - } - else - { - i++; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "in %llu ms\n", - (unsigned long long) i); - data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, - i), - &data_task, (void *) i); - } - } -} - - -/** - * Transmit ready callback - * - * @param cls Closure (peer # which is sending the data). - * @param size Size of the buffer we have. - * @param buf Buffer to copy data to. - */ -static size_t -tmt_rdy (void *cls, size_t size, void *buf) -{ - struct GNUNET_MessageHeader *msg = buf; - size_t msg_size; - uint32_t *data; - long id = (long) cls; - unsigned int counter; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "tmt_rdy on %ld, filling buffer\n", - id); - if (0 == id) - th = NULL; - else if ((peers_requested - 1) == id) - incoming_th = NULL; - else - GNUNET_assert (0); - counter = get_expected_target () == id ? ack_sent : data_sent; - msg_size = size_payload + counter; - GNUNET_assert (msg_size > sizeof (struct GNUNET_MessageHeader)); - if ( (size < msg_size) || - (NULL == buf) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "size %u, buf %p, data_sent %u, ack_received %u\n", - (unsigned int) size, - buf, - data_sent, - ack_received); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok %u, ok goal %u\n", ok, ok_goal); - GNUNET_break (ok >= ok_goal - 2); - - return 0; - } - msg->size = htons (msg_size); - msg->type = htons (GNUNET_MESSAGE_TYPE_DUMMY); - data = (uint32_t *) &msg[1]; - *data = htonl (counter); - if (GNUNET_NO == initialized) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "sending initializer\n"); - msg_size = size_payload + 1000; - msg->size = htons (msg_size); - if (SPEED_ACK == test) - data_sent++; - } - else if ( (SPEED == test) || - (SPEED_ACK == test) ) - { - if (get_expected_target() == id) - ack_sent++; - else - data_sent++; - counter++; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - " Sent message %u size %u\n", - counter, - (unsigned int) msg_size); - if ( (data_sent < TOTAL_PACKETS) && - (SPEED == test) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - " Scheduling message %d\n", - counter + 1); - data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL); - } - } - - return msg_size; -} - - -/** - * Function is called whenever a message is received. - * - * @param cls closure (set from GNUNET_CADET_connect(), peer number) - * @param channel connection to the other end - * @param channel_ctx place to store local state associated with the channel - * @param message the actual message - * @return #GNUNET_OK to keep the connection open, - * #GNUNET_SYSERR to close it (signal serious error) - */ -static int -data_callback (void *cls, - struct GNUNET_CADET_Channel *channel, - void **channel_ctx, - const struct GNUNET_MessageHeader *message) -{ - struct GNUNET_CADET_TransmitHandle **pth; - long client = (long) cls; - long expected_target_client; - uint32_t *data; - uint32_t payload; - unsigned int counter; - - ok++; - counter = get_expected_target () == client ? data_received : ack_received; - - GNUNET_CADET_receive_done (channel); - - if ((ok % 10) == 0) - { - if (NULL != disconnect_task) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - " reschedule timeout\n"); - GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, - &gather_stats_and_exit, - (void *) __LINE__); - } - } - - switch (client) - { - case 0L: - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n"); - GNUNET_assert (channel == ch); - pth = &th; - break; - case 1L: - case 4L: - GNUNET_assert (client == peers_requested - 1); - GNUNET_assert (channel == incoming_ch); - pth = &incoming_th; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Leaf client %ld got a message.\n", - client); - break; - default: - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Client %ld not valid.\n", client); - GNUNET_assert (0); - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: (%d/%d)\n", ok, ok_goal); - data = (uint32_t *) &message[1]; - payload = ntohl (*data); - if (payload == counter) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, " payload as expected: %u\n", payload); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " payload %u, expected: %u\n", - payload, counter); - } - expected_target_client = get_expected_target (); - - if (GNUNET_NO == initialized) - { - initialized = GNUNET_YES; - start_time = GNUNET_TIME_absolute_get (); - if (SPEED == test) - { - GNUNET_assert (peers_requested - 1 == client); - data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL); - return GNUNET_OK; - } - } - - counter++; - if (client == expected_target_client) /* Normally 4 */ - { - data_received++; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received); - if (SPEED != test || (ok_goal - 2) == ok) - { - /* Send ACK */ - GNUNET_assert (NULL == *pth); - *pth = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, - GNUNET_TIME_UNIT_FOREVER_REL, - size_payload + ack_sent, - &tmt_rdy, (void *) client); - return GNUNET_OK; - } - else - { - if (data_received < TOTAL_PACKETS) - return GNUNET_OK; - } - } - else /* Normally 0 */ - { - if (SPEED_ACK == test || SPEED == test) - { - ack_received++; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received); - /* send more data */ - GNUNET_assert (NULL == *pth); - *pth = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, - GNUNET_TIME_UNIT_FOREVER_REL, - size_payload + data_sent, - &tmt_rdy, (void *) client); - if (ack_received < TOTAL_PACKETS && SPEED != test) - return GNUNET_OK; - if (ok == 2 && SPEED == test) - return GNUNET_OK; - show_end_data(); - } - if (test == P2P_SIGNAL) - { - if (NULL != incoming_th) - { - GNUNET_CADET_notify_transmit_ready_cancel (incoming_th); - incoming_th = NULL; - } - GNUNET_CADET_channel_destroy (incoming_ch); - incoming_ch = NULL; - } - else - { - if (NULL != th) - { - GNUNET_CADET_notify_transmit_ready_cancel (th); - th = NULL; - } - GNUNET_CADET_channel_destroy (ch); - ch = NULL; - } - } - - return GNUNET_OK; -} - - -/** - * Data handlers for every message type of CADET's payload. - * {callback_function, message_type, size_expected} - */ -static struct GNUNET_CADET_MessageHandler handlers[] = { - {&data_callback, - GNUNET_MESSAGE_TYPE_DUMMY, - sizeof (struct GNUNET_MessageHeader)}, - {NULL, 0, 0} -}; - - -/** - * Method called whenever another peer has added us to a channel - * the other peer initiated. - * - * @param cls Closure. - * @param channel New handle to the channel. - * @param initiator Peer that started the channel. - * @param port Port this channel is connected to. - * @param options channel option flags - * @return Initial channel context for the channel - * (can be NULL -- that's not an error). - */ -static void * -incoming_channel (void *cls, - struct GNUNET_CADET_Channel *channel, - const struct GNUNET_PeerIdentity *initiator, - const struct GNUNET_HashCode *port, - enum GNUNET_CADET_ChannelOption options) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Incoming channel from %s to peer %d:%s\n", - GNUNET_i2s (initiator), - (int) (long) cls, GNUNET_h2s (port)); - ok++; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); - if ((long) cls == peers_requested - 1) - { - if (NULL != incoming_ch) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Duplicate incoming channel for client %lu\n", - (long) cls); - GNUNET_break(0); - } - incoming_ch = channel; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Incoming channel for unexpected peer #%lu\n", - (long) cls); - GNUNET_break (0); - } - if (NULL != disconnect_task) - { - GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, - &gather_stats_and_exit, - (void *) __LINE__); - } - - return NULL; -} - - -/** - * Function called whenever an inbound channel is destroyed. Should clean up - * any associated state. - * - * @param cls closure (set from GNUNET_CADET_connect, peer number) - * @param channel connection to the other end (henceforth invalid) - * @param channel_ctx place where local state associated - * with the channel is stored - */ -static void -channel_cleaner (void *cls, - const struct GNUNET_CADET_Channel *channel, - void *channel_ctx) -{ - long i = (long) cls; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Incoming channel disconnected at peer %ld\n", - i); - if (peers_running - 1 == i) - { - ok++; - GNUNET_break (channel == incoming_ch); - incoming_ch = NULL; - } - else if (0L == i) - { - if (P2P_SIGNAL == test) - { - ok++; - } - GNUNET_break (channel == ch); - ch = NULL; - } - else - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unknown peer! %d\n", - (int) i); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); - - if (NULL != disconnect_task) - { - GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_now (&gather_stats_and_exit, - (void *) __LINE__); - } -} - - -/** - * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES. - * - * Testcase continues when the root receives confirmation of connected peers, - * on callback function ch. - * - * @param cls Closure (unused). - */ -static void -do_test (void *cls) -{ - enum GNUNET_CADET_ChannelOption flags; - - test_task = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "do_test\n"); - if (NULL != disconnect_task) - { - GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = NULL; - } - - flags = GNUNET_CADET_OPTION_DEFAULT; - if (SPEED_REL == test) - { - test = SPEED; - flags |= GNUNET_CADET_OPTION_RELIABLE; - } - - ch = GNUNET_CADET_channel_create (h1, - NULL, - p_id[1], - &port, - flags); - - disconnect_task - = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, - &gather_stats_and_exit, - (void *) __LINE__); - if (KEEPALIVE == test) - return; /* Don't send any data. */ - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending data initializer...\n"); - data_received = 0; - data_sent = 0; - ack_received = 0; - ack_sent = 0; - th = GNUNET_CADET_notify_transmit_ready (ch, - GNUNET_NO, - GNUNET_TIME_UNIT_FOREVER_REL, - size_payload + 1000, - &tmt_rdy, (void *) 0L); -} - - -/** - * Callback to be called when the requested peer information is available - * - * @param cls the closure from GNUNET_TESTBED_peer_get_information() - * @param op the operation this callback corresponds to - * @param pinfo the result; will be NULL if the operation has failed - * @param emsg error message if the operation has failed; - * NULL if the operation is successfull - */ -static void -pi_cb (void *cls, - struct GNUNET_TESTBED_Operation *op, - const struct GNUNET_TESTBED_PeerInformation *pinfo, - const char *emsg) -{ - long i = (long) cls; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "id callback for %ld\n", i); - - if ( (NULL == pinfo) || - (NULL != emsg) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "pi_cb: %s\n", emsg); - abort_test (__LINE__); - return; - } - p_id[i] = pinfo->result.id; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - " id: %s\n", GNUNET_i2s (p_id[i])); - p_ids++; - if (p_ids < 2) - return; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got all IDs, starting test\n"); - test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &do_test, - NULL); -} - - -/** - * test main: start test when all peers are connected - * - * @param cls Closure. - * @param ctx Argument to give to GNUNET_CADET_TEST_cleanup on test end. - * @param num_peers Number of peers that are running. - * @param peers Array of peers. - * @param cadetes Handle to each of the CADETs of the peers. - */ -static void -tmain (void *cls, - struct GNUNET_CADET_TEST_Context *ctx, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - struct GNUNET_CADET_Handle **cadets) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n"); - ok = 0; - test_ctx = ctx; - peers_running = num_peers; - GNUNET_assert (peers_running == peers_requested); - testbed_peers = peers; - h1 = cadets[0]; - h2 = cadets[num_peers - 1]; - disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, - &disconnect_cadet_peers, - (void *) __LINE__); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); - t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0], - GNUNET_TESTBED_PIT_IDENTITY, - &pi_cb, (void *) 0L); - t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1], - GNUNET_TESTBED_PIT_IDENTITY, - &pi_cb, (void *) 1L); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n"); -} - - -/** - * Main: start test - */ -int -main (int argc, char *argv[]) -{ - initialized = GNUNET_NO; - static const struct GNUNET_HashCode *ports[2]; - const char *config_file; - char port_id[] = "test port"; - GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port); - - GNUNET_log_setup ("test", "DEBUG", NULL); - config_file = "test_cadet.conf"; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n"); - - /* Find out requested size */ - if (strstr (argv[0], "_2_") != NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DIRECT CONNECTIONs\n"); - peers_requested = 2; - } - else if (strstr (argv[0], "_5_") != NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n"); - peers_requested = 5; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n"); - peers_requested = 2; - } - - /* Find out requested test */ - if (strstr (argv[0], "_forward") != NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FORWARD\n"); - test = FORWARD; - test_name = "unicast"; - ok_goal = 4; - } - else if (strstr (argv[0], "_signal") != NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SIGNAL\n"); - test = P2P_SIGNAL; - test_name = "signal"; - ok_goal = 4; - } - else if (strstr (argv[0], "_speed_ack") != NULL) - { - /* Test is supposed to generate the following callbacks: - * 1 incoming channel (@dest) - * TOTAL_PACKETS received data packet (@dest) - * TOTAL_PACKETS received data packet (@orig) - * 1 received channel destroy (@dest) - */ - ok_goal = TOTAL_PACKETS * 2 + 2; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n"); - test = SPEED_ACK; - test_name = "speed ack"; - } - else if (strstr (argv[0], "_speed") != NULL) - { - /* Test is supposed to generate the following callbacks: - * 1 incoming channel (@dest) - * 1 initial packet (@dest) - * TOTAL_PACKETS received data packet (@dest) - * 1 received data packet (@orig) - * 1 received channel destroy (@dest) - */ - ok_goal = TOTAL_PACKETS + 4; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n"); - if (strstr (argv[0], "_reliable") != NULL) - { - test = SPEED_REL; - test_name = "speed reliable"; - config_file = "test_cadet_drop.conf"; - } - else - { - test = SPEED; - test_name = "speed"; - } - } - else if (strstr (argv[0], "_keepalive") != NULL) - { - test = KEEPALIVE; - /* Test is supposed to generate the following callbacks: - * 1 incoming channel (@dest) - * [wait] - * 1 received channel destroy (@dest) - */ - ok_goal = 2; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); - test = SETUP; - ok_goal = 0; - } - - if (strstr (argv[0], "backwards") != NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n"); - test_backwards = GNUNET_YES; - GNUNET_asprintf (&test_name, "backwards %s", test_name); - } - - p_ids = 0; - ports[0] = &port; - ports[1] = NULL; - GNUNET_CADET_TEST_run ("test_cadet_small", - config_file, - peers_requested, - &tmain, - NULL, /* tmain cls */ - &incoming_channel, - &channel_cleaner, - handlers, - ports); - if (NULL != strstr (argv[0], "_reliable")) - msg_dropped = 0; /* dropped should be retransmitted */ - - if (ok_goal > ok - msg_dropped) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "FAILED! (%d/%d)\n", ok, ok_goal); - return 1; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n"); - return 0; -} - -/* end of test_cadet.c */ diff --git a/src/cadet/test_cadet_local.c b/src/cadet/test_cadet_local.c deleted file mode 100644 index 2b915ab81..000000000 --- a/src/cadet/test_cadet_local.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2011 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 cadet/test_cadet_local.c - * @brief test cadet local: test of cadet channels with just one peer - * @author Bartlomiej Polot - */ - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_dht_service.h" -#include "gnunet_testing_lib.h" -#include "gnunet_cadet_service.h" - -struct GNUNET_TESTING_Peer *me; - -static struct GNUNET_CADET_Handle *cadet_peer_1; - -static struct GNUNET_CADET_Handle *cadet_peer_2; - -static struct GNUNET_CADET_Channel *ch; - -static int result = GNUNET_OK; - -static int got_data = GNUNET_NO; - -static struct GNUNET_SCHEDULER_Task *abort_task; - -static struct GNUNET_SCHEDULER_Task *connect_task; - -static struct GNUNET_CADET_TransmitHandle *mth; - - -/** - * Connect to other client and send data - * - * @param cls Closue (unused). - */ -static void -do_connect (void *cls); - - -/** - * Shutdown nicely - */ -static void -do_shutdown (void *cls) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "shutdown\n"); - if (NULL != abort_task) - { - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = NULL; - } - if (NULL != ch) - { - GNUNET_CADET_channel_destroy (ch); - ch = NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Disconnect client 1\n"); - if (NULL != cadet_peer_1) - { - GNUNET_CADET_disconnect (cadet_peer_1); - cadet_peer_1 = NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Disconnect client 2\n"); - if (NULL != cadet_peer_2) - { - GNUNET_CADET_disconnect (cadet_peer_2); - cadet_peer_2 = NULL; - } - if (NULL != connect_task) - { - GNUNET_SCHEDULER_cancel (connect_task); - connect_task = NULL; - } -} - - -/** - * Something went wrong and timed out. Kill everything and set error flag - */ -static void -do_abort (void *cls) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n"); - result = GNUNET_SYSERR; - abort_task = NULL; - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Function is called whenever a message is received. - * - * @param cls closure (set from GNUNET_CADET_connect) - * @param channel connection to the other end - * @param channel_ctx place to store local state associated with the channel - * @param message the actual message - * @return #GNUNET_OK to keep the connection open, - * #GNUNET_SYSERR to close it (signal serious error) - */ -static int -data_callback (void *cls, - struct GNUNET_CADET_Channel *channel, - void **channel_ctx, - const struct GNUNET_MessageHeader *message) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Data callback! Shutting down.\n"); - got_data = GNUNET_YES; - GNUNET_SCHEDULER_shutdown (); - GNUNET_CADET_receive_done (channel); - return GNUNET_OK; -} - - -/** - * Method called whenever another peer has added us to a channel - * the other peer initiated. - * - * @param cls closure - * @param channel new handle to the channel - * @param initiator peer that started the channel - * @param port port number - * @param options channel options - * @return initial channel context for the channel - * (can be NULL -- that's not an error) - */ -static void * -inbound_channel (void *cls, - struct GNUNET_CADET_Channel *channel, - const struct GNUNET_PeerIdentity *initiator, - const struct GNUNET_HashCode *port, - enum GNUNET_CADET_ChannelOption options) -{ - long id = (long) cls; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "received incoming channel on peer %d, port %s\n", - (int) id, - GNUNET_h2s (port)); - if (id != 2L) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "wrong peer\n"); - result = GNUNET_SYSERR; - } - return NULL; -} - - -/** - * Function called whenever an channel is destroyed. Should clean up - * any associated state. - * - * @param cls closure (set from GNUNET_CADET_connect) - * @param channel connection to the other end (henceforth invalid) - * @param channel_ctx place where local state associated - * with the channel is stored - */ -static void -channel_end (void *cls, - const struct GNUNET_CADET_Channel *channel, - void *channel_ctx) -{ - long id = (long) cls; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "incoming channel closed at peer %ld\n", - id); - if (NULL != mth) - { - GNUNET_CADET_notify_transmit_ready_cancel (mth); - mth = NULL; - } - if (channel == ch) - ch = NULL; - if (GNUNET_NO == got_data) - { - if (NULL == connect_task) - connect_task - = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - 2), - &do_connect, - NULL); - } -} - - -/** - * Handler array for traffic received on peer1 - */ -static struct GNUNET_CADET_MessageHandler handlers1[] = { - {&data_callback, 1, 0}, - {NULL, 0, 0} -}; - - -/** - * Handler array for traffic received on peer2 (none expected) - */ -static struct GNUNET_CADET_MessageHandler handlers2[] = { - {&data_callback, 1, 0}, - {NULL, 0, 0} -}; - - -/** - * Data send callback: fillbuffer with test packet. - * - * @param cls Closure (unused). - * @param size Buffer size. - * @param buf Buffer to fill. - * - * @return size of test packet. - */ -static size_t -do_send (void *cls, size_t size, void *buf) -{ - struct GNUNET_MessageHeader *m = buf; - - mth = NULL; - if (NULL == buf) - { - GNUNET_break (0); - result = GNUNET_SYSERR; - return 0; - } - m->size = htons (sizeof (struct GNUNET_MessageHeader)); - m->type = htons (1); - GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); - return sizeof (struct GNUNET_MessageHeader); -} - - -/** - * Connect to other client and send data - * - * @param cls Closue (unused). - */ -static void -do_connect (void *cls) -{ - struct GNUNET_PeerIdentity id; - - connect_task = NULL; - GNUNET_TESTING_peer_get_identity (me, &id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "CONNECT BY PORT\n"); - ch = GNUNET_CADET_channel_create (cadet_peer_1, - NULL, - &id, GC_u2h (1), - GNUNET_CADET_OPTION_DEFAULT); - mth = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, - GNUNET_TIME_UNIT_FOREVER_REL, - sizeof (struct GNUNET_MessageHeader), - &do_send, NULL); -} - - -/** - * Initialize framework and start test - * - * @param cls Closure (unused). - * @param cfg Configuration handle. - * @param peer Testing peer handle. - */ -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - me = peer; - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, - NULL); - abort_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 15), - &do_abort, - NULL); - cadet_peer_1 = GNUNET_CADET_connect (cfg, /* configuration */ - (void *) 1L, /* cls */ - &channel_end, /* channel end hndlr */ - handlers1); /* traffic handlers */ - cadet_peer_2 = GNUNET_CADET_connect (cfg, /* configuration */ - (void *) 2L, /* cls */ - &channel_end, /* channel end hndlr */ - handlers2); /* traffic handlers */ - - if ( (NULL == cadet_peer_1) || - (NULL == cadet_peer_2) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Couldn't connect to cadet :(\n"); - result = GNUNET_SYSERR; - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_CADET_open_port (cadet_peer_2, - GC_u2h (1), - &inbound_channel, - (void *) 2L); - if (NULL == connect_task) - connect_task - = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, - 2), - &do_connect, - NULL); -} - - -/** - * Main - */ -int -main (int argc, char *argv[]) -{ - if (0 != GNUNET_TESTING_peer_run ("test-cadet-local", - "test_cadet.conf", - &run, NULL)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "run failed\n"); - return 2; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Final result: %d\n", result); - return (result == GNUNET_OK) ? 0 : 1; -} - -/* end of test_cadet_local_1.c */ diff --git a/src/cadet/test_cadet_single.c b/src/cadet/test_cadet_single.c deleted file mode 100644 index b45b0af5d..000000000 --- a/src/cadet/test_cadet_single.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2011 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 cadet/test_cadet_single.c - * @brief test cadet single: test of cadet channels with just one client - * @author Bartlomiej Polot - */ - -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_dht_service.h" -#include "gnunet_testing_lib.h" -#include "gnunet_cadet_service.h" - -#define REPETITIONS 5 -#define DATA_SIZE 35000 - -struct GNUNET_TESTING_Peer *me; - -static struct GNUNET_CADET_Handle *cadet; - -static struct GNUNET_CADET_Channel *ch1; - -static struct GNUNET_CADET_Channel *ch2; - -static int result; - -static struct GNUNET_SCHEDULER_Task *abort_task; - -static struct GNUNET_SCHEDULER_Task *connect_task; - -static unsigned int repetition; - -static struct GNUNET_CADET_TransmitHandle *nth; - -static struct GNUNET_CADET_Port *port; - - -/* forward declaration */ -static size_t -do_send (void *cls, size_t size, void *buf); - - -/** - * Shutdown nicely - */ -static void -do_shutdown (void *cls) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "shutdown\n"); - if (NULL != port) - { - GNUNET_CADET_close_port (port); - port = NULL; - } - if (NULL != nth) - { - GNUNET_CADET_notify_transmit_ready_cancel (nth); - nth = NULL; - } - if (NULL != abort_task) - { - GNUNET_SCHEDULER_cancel (abort_task); - abort_task = NULL; - } - if (NULL != connect_task) - { - GNUNET_SCHEDULER_cancel (connect_task); - connect_task = NULL; - } - if (NULL != ch1) - { - GNUNET_CADET_channel_destroy (ch1); - ch1 = NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Disconnect clients\n"); - if (NULL != cadet) - { - GNUNET_CADET_disconnect (cadet); - cadet = NULL; - } - else - { - GNUNET_break (0); - } -} - - -/** - * Something went wrong and timed out. Kill everything and set error flag - */ -static void -do_abort (void *cls) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n"); - result = GNUNET_SYSERR; - abort_task = NULL; - GNUNET_SCHEDULER_shutdown (); -} - - -/** - * Function is called whenever a message is received. - * - * @param cls closure (set from GNUNET_CADET_connect) - * @param channel connection to the other end - * @param channel_ctx place to store local state associated with the channel - * @param message the actual message - * @return #GNUNET_OK to keep the connection open, - * #GNUNET_SYSERR to close it (signal serious error) - */ -static int -data_callback (void *cls, - struct GNUNET_CADET_Channel *channel, - void **channel_ctx, - const struct GNUNET_MessageHeader *message) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Data callback! Repetition %u/%u\n", - repetition, REPETITIONS); - repetition++; - if (repetition < REPETITIONS) - { - struct GNUNET_CADET_Channel *my_channel; - if (0 == repetition % 2) - my_channel = ch1; - else - my_channel = ch2; - nth = GNUNET_CADET_notify_transmit_ready (my_channel, - GNUNET_NO, - GNUNET_TIME_UNIT_FOREVER_REL, - sizeof (struct GNUNET_MessageHeader) - + DATA_SIZE, - &do_send, NULL); - GNUNET_CADET_receive_done (channel); - return GNUNET_OK; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "All data OK. Destroying channel.\n"); - GNUNET_assert (NULL == nth); - GNUNET_CADET_channel_destroy (ch1); - ch1 = NULL; - return GNUNET_OK; -} - - -/** - * Method called whenever another peer has added us to a channel - * the other peer initiated. - * - * @param cls closure - * @param channel new handle to the channel - * @param initiator peer that started the channel - * @param port port number - * @param options channel option flags - * @return initial channel context for the channel - * (can be NULL -- that's not an error) - */ -static void * -inbound_channel (void *cls, - struct GNUNET_CADET_Channel *channel, - const struct GNUNET_PeerIdentity *initiator, - const struct GNUNET_HashCode *port, - enum GNUNET_CADET_ChannelOption options) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "received incoming channel on port %s\n", - GNUNET_h2s (port)); - ch2 = channel; - return NULL; -} - - -/** - * Function called whenever an inbound channel is destroyed. Should clean up - * any associated state. - * - * @param cls closure (set from GNUNET_CADET_connect) - * @param channel connection to the other end (henceforth invalid) - * @param channel_ctx place where local state associated - * with the channel is stored - */ -static void -channel_end (void *cls, - const struct GNUNET_CADET_Channel *channel, - void *channel_ctx) -{ - long id = (long) cls; - - nth = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "incoming channel closed at peer %ld\n", - id); - if ( (REPETITIONS == repetition) && - (channel == ch2) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "everything fine! finishing!\n"); - result = GNUNET_OK; - GNUNET_SCHEDULER_shutdown (); - } - if (channel == ch2) - ch2 = NULL; - if (channel == ch1) - ch1 = NULL; -} - - -/** - * Handler array for traffic received on peer1 - */ -static struct GNUNET_CADET_MessageHandler handlers1[] = { - {&data_callback, 1, 0}, - {NULL, 0, 0} -}; - - -/** - * Data send callback: fillbuffer with test packet. - * - * @param cls Closure (unused). - * @param size Buffer size. - * @param buf Buffer to fill. - * @return size of test packet. - */ -static size_t -do_send (void *cls, size_t size, void *buf) -{ - struct GNUNET_MessageHeader *m = buf; - - nth = NULL; - if (NULL == buf) - { - GNUNET_break (0); - result = GNUNET_SYSERR; - return 0; - } - m->size = htons (sizeof (struct GNUNET_MessageHeader) + DATA_SIZE); - m->type = htons (1); - memset (&m[1], 0, DATA_SIZE); - GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader) + DATA_SIZE); - return sizeof (struct GNUNET_MessageHeader) + DATA_SIZE; -} - -/** - * Connect to other client and send data - * - * @param cls Closue (unused). - */ -static void -do_connect (void *cls) -{ - struct GNUNET_PeerIdentity id; - size_t size = sizeof (struct GNUNET_MessageHeader) + DATA_SIZE; - - connect_task = NULL; - GNUNET_TESTING_peer_get_identity (me, &id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); - ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, GC_u2h (1), - GNUNET_CADET_OPTION_DEFAULT); - nth = GNUNET_CADET_notify_transmit_ready (ch1, - GNUNET_NO, - GNUNET_TIME_UNIT_FOREVER_REL, - size, - &do_send, - NULL); -} - - -/** - * Initialize framework and start test - * - * @param cls Closure (unused). - * @param cfg Configuration handle. - * @param peer Testing peer handle. - */ -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - me = peer; - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); - abort_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort, - NULL); - cadet = GNUNET_CADET_connect (cfg, /* configuration */ - (void *) 1L, /* cls */ - &channel_end, /* inbound end hndlr */ - handlers1); /* traffic handlers */ - port = GNUNET_CADET_open_port (cadet, - GC_u2h (1), - &inbound_channel, - (void *) 1L); - - - if (NULL == cadet) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Couldn't connect to cadet :(\n"); - result = GNUNET_SYSERR; - return; - } - connect_task - = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &do_connect, - NULL); -} - - -/** - * Main - */ -int -main (int argc, - char *argv[]) -{ - result = GNUNET_NO; - if (0 != GNUNET_TESTING_peer_run ("test-cadet-local", - "test_cadet.conf", - &run, NULL)) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "run failed\n"); - return 2; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Final result: %d\n", - result); - return (result == GNUNET_OK) ? 0 : 1; -} - -/* end of test_cadet_single.c */ -- 2.25.1