From 6fb788ca2ec44837ea10a36be7fd0030fb08955b Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Thu, 28 Oct 2021 16:13:47 +0200 Subject: - fixed coverity issues --- src/include/gnunet_testing_ng_lib.h | 9 ++ src/testing/testing.c | 140 ++++++++++++++++----- .../testing_api_cmd_netjail_start_testsystem.c | 109 +++++++++++----- .../testing_api_cmd_netjail_stop_testsystem.c | 24 ++-- src/transport/gnunet-communicator-tcp.c | 29 +++-- .../test_transport_plugin_cmd_simple_send.c | 62 +++++++-- .../test_transport_plugin_cmd_udp_backchannel.c | 17 ++- src/transport/test_transport_simple_send.sh | 7 +- src/transport/test_transport_simple_send_topo.conf | 4 +- src/transport/test_transport_udp_backchannel.sh | 5 + src/transport/transport-testing-cmds.h | 17 ++- src/transport/transport_api_cmd_connecting_peers.c | 23 ++-- src/transport/transport_api_cmd_send_simple.c | 119 +++++++++++------- src/transport/transport_api_cmd_start_peer.c | 14 ++- 14 files changed, 397 insertions(+), 182 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 45e58299e..7ce73baef 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h @@ -680,6 +680,15 @@ GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, char *prefix); +/** + * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. + * + * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated. + */ +void +GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology); + + /** * Calculate the unique id identifying a node from a given connction. * diff --git a/src/testing/testing.c b/src/testing/testing.c index 4d9b7c0cb..02cedc744 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -1798,7 +1798,7 @@ get_first_value (char *line) memcpy (copy, line, slen); token = strtok_r (copy, ":", &rest); token = strtok_r (NULL, ":", &rest); - sscanf (token, "%u", &ret); + GNUNET_assert (1 == sscanf (token, "%u", &ret)); GNUNET_free (copy); return ret; } @@ -1864,7 +1864,7 @@ get_second_value (char *line) token = strtok_r (copy, ":", &rest); token = strtok_r (NULL, ":", &rest); token = strtok_r (NULL, ":", &rest); - sscanf (token, "%u", &ret); + GNUNET_assert (1 == sscanf (token, "%u", &ret)); GNUNET_free (copy); return ret; } @@ -1923,7 +1923,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node) { node_connection->node_type = GNUNET_TESTING_GLOBAL_NODE; token = strtok_r (NULL, ":", &rest); - sscanf (token, "%u", &node_n); + GNUNET_assert (1 == sscanf (token, "%u", &node_n)); LOG (GNUNET_ERROR_TYPE_ERROR, "node_n %u\n", node_n); @@ -1934,15 +1934,17 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node) { node_connection->node_type = GNUNET_TESTING_SUBNET_NODE; token = strtok_r (NULL, ":", &rest); - sscanf (token, "%u", &node_n); - node_connection->node_n = node_n; - token = strtok_r (NULL, ":", &rest); sscanf (token, "%u", &namespace_n); node_connection->namespace_n = namespace_n; + token = strtok_r (NULL, ":", &rest); + sscanf (token, "%u", &node_n); + node_connection->node_n = node_n; LOG (GNUNET_ERROR_TYPE_ERROR, - "node_n %u namespace_n %u\n", + "node_n %u namespace_n %u node->node_n %u node->namespace_n %u\n", node_n, - namespace_n); + namespace_n, + node->node_n, + node->namespace_n); } while (NULL != (token = strtok_r (NULL, ":", &rest))) { @@ -1994,13 +1996,16 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node) if (NULL != temp) { slen = strlen (temp) + 1; - copy = malloc (slen); + copy = GNUNET_malloc (slen); memcpy (copy, temp, slen); strtok_r (copy, ":", &rest); value = strtok_r (rest, "|", &rest2); while (NULL != value) { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "node_connections value %s\n", + value); node_connection = get_connect_value (value, node); GNUNET_CONTAINER_DLL_insert (node->node_connections_head, node->node_connections_tail, @@ -2011,6 +2016,7 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node) value = strtok_r (NULL, "|", &rest2); } + GNUNET_free (copy); } } @@ -2056,13 +2062,7 @@ static int log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value) { struct GNUNET_TESTING_NetjailNamespace *namespace = value; - struct GNUNET_TESTING_NetjailRouter *router = namespace->router; - LOG (GNUNET_ERROR_TYPE_ERROR, - "router_tcp: %u router_udp: %u spaces: %u\n", - router->tcp_port, - router->udp_port, - namespace->namespace_n); GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL); return GNUNET_YES; } @@ -2103,9 +2103,15 @@ GNUNET_TESTING_get_connections (unsigned int num, struct struct GNUNET_TESTING_NetjailNamespace *namespace; unsigned int namespace_n, node_m; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "gaga 1\n"); log_topo (topology); - + LOG (GNUNET_ERROR_TYPE_DEBUG, + "gaga 2\n"); hkey = GNUNET_new (struct GNUNET_ShortHashCode); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "num: %u \n", + num); if (topology->nodes_x >= num) { @@ -2118,10 +2124,10 @@ GNUNET_TESTING_get_connections (unsigned int num, struct } else { - namespace_n = (unsigned int) floor ((num - topology->nodes_x) - / topology->nodes_m); + namespace_n = (unsigned int) ceil ((double) (num - topology->nodes_x) + / topology->nodes_m); LOG (GNUNET_ERROR_TYPE_ERROR, - "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n", + "ceil num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n", num, topology->nodes_x, topology->nodes_m, @@ -2143,7 +2149,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct hkey); } - + GNUNET_free (hkey); return node->node_connections_head; } @@ -2172,10 +2178,74 @@ GNUNET_TESTING_get_pub_key (unsigned int num, struct GNUNET_CRYPTO_eddsa_key_get_public (priv_key, pub_key); peer->public_key = *pub_key; + GNUNET_free (priv_key); + GNUNET_free (pub_key); return peer; } +int +free_nodes_cb (void *cls, + const struct GNUNET_ShortHashCode *key, + void *value) +{ + (void) cls; + struct GNUNET_TESTING_NetjailNode *node = value; + struct GNUNET_TESTING_NodeConnection *pos_connection; + struct GNUNET_TESTING_NodeConnection *tmp_connection; + struct GNUNET_TESTING_AddressPrefix *pos_prefix; + struct GNUNET_TESTING_AddressPrefix *tmp_prefix; + + pos_connection = node->node_connections_head; + + while (NULL != pos_connection->next) + { + pos_prefix = pos_connection->address_prefixes_head; + while (NULL != pos_prefix->next) + { + tmp_prefix = pos_prefix->next; + GNUNET_free (pos_prefix); + pos_prefix = tmp_prefix; + } + tmp_connection = pos_connection->next; + GNUNET_free (pos_connection); + pos_connection = tmp_connection; + } + return GNUNET_OK; +} + + +int +free_namespaces_cb (void *cls, + const struct GNUNET_ShortHashCode *key, + void *value) +{ + (void) cls; + struct GNUNET_TESTING_NetjailNamespace *namespace = value; + + GNUNET_free (namespace->router); + GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, free_nodes_cb, + NULL); + return GNUNET_OK; + +} + + +/** + * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. + * + * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated. + */ +void +GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology) +{ + GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces, + free_namespaces_cb, NULL); + GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, free_nodes_cb, + NULL); + GNUNET_free (topology); +} + /** * Calculate the unique id identifying a node from a given connction. * @@ -2252,7 +2322,7 @@ GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, } else { - GNUNET_break (0); + GNUNET_assert (0); } return addr; @@ -2296,24 +2366,19 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) uint64_t fs; char *data; char *token; - char *key; + char *key = NULL; unsigned int out; char *rest = NULL; char *value; + char *value2; int ret; - struct GNUNET_TESTING_NetjailTopology *topo = GNUNET_new (struct - GNUNET_TESTING_NetjailTopology); + struct GNUNET_TESTING_NetjailTopology *topo; struct GNUNET_TESTING_NetjailNode *node; struct GNUNET_TESTING_NetjailRouter *router; struct GNUNET_TESTING_NetjailNamespace *namespace; struct GNUNET_ShortHashCode *hkey; struct GNUNET_HashCode hc; - topo->map_namespaces = - GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); - topo->map_globals = - GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); - if (GNUNET_YES != GNUNET_DISK_file_test (filename)) { LOG (GNUNET_ERROR_TYPE_ERROR, @@ -2339,14 +2404,22 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) return NULL; } - LOG (GNUNET_ERROR_TYPE_ERROR, + LOG (GNUNET_ERROR_TYPE_DEBUG, "data: %s\n", data); + data[fs] = '\0'; token = strtok_r (data, "\n", &rest); + topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology); + topo->map_namespaces = + GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); + topo->map_globals = + GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); while (NULL != token) { + if (NULL != key) + free (key); key = get_key (token); LOG (GNUNET_ERROR_TYPE_ERROR, "In the loop with token: %s beginning with %s\n", @@ -2457,12 +2530,12 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) LOG (GNUNET_ERROR_TYPE_ERROR, "Get value for key udp_port on R.\n"); - value = get_value ("udp_port", token); - ret = sscanf (value, "%u", &(router->udp_port)); + value2 = get_value ("udp_port", token); + ret = sscanf (value2, "%u", &(router->udp_port)); GNUNET_break (0 != ret && 1 >= router->udp_port); LOG (GNUNET_ERROR_TYPE_ERROR, "udp_port: %s\n", - value); + value2); if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( topo->map_namespaces, @@ -2554,6 +2627,7 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) } token = strtok_r (NULL, "\n", &rest); } + GNUNET_free (data); return topo; } diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index 9b567a01f..c3598d174 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c @@ -66,6 +66,12 @@ struct HelperMessage */ struct NetJailState { + /** + * Global state of the interpreter, used by a command + * to access information about other commands. + */ + struct GNUNET_TESTING_Interpreter *is; + /** * Context for our asynchronous completion. */ @@ -76,12 +82,6 @@ struct NetJailState */ struct GNUNET_TESTING_NetjailTopology *topology; - /** - * Pointer to the return value of the test. - * - */ - unsigned int *rv; - /** * Head of the DLL which stores messages received by the helper. * @@ -254,6 +254,7 @@ netjail_exec_cleanup (void *cls) tbc_pos); GNUNET_free (tbc_pos); } + GNUNET_TESTING_free_topology (ns->topology); GNUNET_free (ns); } @@ -429,18 +430,63 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) struct NetJailState *ns = cls;// tbc->ns; struct HelperMessage *hp_msg; unsigned int total_number = ns->local_m * ns->global_n + ns->known; + // uint16_t message_type = ntohs (message->type); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "total %u sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n", - total_number, - ns->number_of_testsystems_started, - ns->number_of_peers_started, - ns->number_of_local_tests_prepared, - ns->number_of_local_tests_finished, - ns->local_m, - ns->global_n, - ns->known); + /*switch (message_type) + { + case GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY: + ns->number_of_testsystems_started++; + break; + case GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED: + ns->number_of_peers_started++; + if (ns->number_of_peers_started == total_number) + { + for (int i = 1; i <= ns->known; i++) + { + send_all_peers_started (0,i, ns); + } + for (int i = 1; i <= ns->global_n; i++) + { + for (int j = 1; j <= ns->local_m; j++) + { + send_all_peers_started (i,j, ns); + } + } + ns->number_of_peers_started = 0; + } + break; + case GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED: + ns->number_of_local_tests_prepared++; + if (ns->number_of_local_tests_prepared == total_number) + { + for (int i = 1; i <= ns->known; i++) + { + send_all_local_tests_prepared (0,i, ns); + } + for (int i = 1; i <= ns->global_n; i++) + { + for (int j = 1; j <= ns->local_m; j++) + { + send_all_local_tests_prepared (i,j, ns); + } + } + } + break; + case GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED: + ns->number_of_local_tests_finished++; + if (ns->number_of_local_tests_finished == total_number) + { + GNUNET_TESTING_async_finish (&ns->ac); + } + break; + default: + hp_msg = GNUNET_new (struct HelperMessage); + hp_msg->bytes_msg = message->size; + memcpy (&hp_msg[1], message, message->size); + GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail, + hp_msg); + }*/ if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) { ns->number_of_testsystems_started++; @@ -505,7 +551,16 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) } - + LOG (GNUNET_ERROR_TYPE_DEBUG, + "total %u sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n", + total_number, + ns->number_of_testsystems_started, + ns->number_of_peers_started, + ns->number_of_local_tests_prepared, + ns->number_of_local_tests_finished, + ns->local_m, + ns->global_n, + ns->known); @@ -524,7 +579,7 @@ exp_cb (void *cls) struct TestingSystemCount *tbc = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); - GNUNET_TESTING_interpreter_fail (tbc->ns->ac.is); + GNUNET_TESTING_async_fail (&(tbc->ns->ac)); } @@ -560,8 +615,7 @@ create_helper_init_msg_ (const char *plugin_name) * */ static void -start_helper (struct NetJailState *ns, struct - GNUNET_CONFIGURATION_Handle *config, +start_helper (struct NetJailState *ns, unsigned int m, unsigned int n) { @@ -582,7 +636,6 @@ start_helper (struct NetJailState *ns, struct struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; struct GNUNET_TESTING_NetjailNode *node; struct GNUNET_TESTING_NetjailNamespace *namespace; - unsigned int *rv = ns->rv; if (0 == n) @@ -633,14 +686,14 @@ start_helper (struct NetJailState *ns, struct GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No SUID for %s!\n", NETJAIL_EXEC_SCRIPT); - *rv = 1; + GNUNET_TESTING_interpreter_fail (ns->is); } else if (GNUNET_NO == helper_check) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s not found!\n", NETJAIL_EXEC_SCRIPT); - *rv = 1; + GNUNET_TESTING_interpreter_fail (ns->is); } LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -729,8 +782,9 @@ start_helper (struct NetJailState *ns, struct GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Send handle is NULL!\n"); GNUNET_free (msg); - *rv = 1; + GNUNET_TESTING_interpreter_fail (ns->is); } + GNUNET_free (hkey); } @@ -746,12 +800,11 @@ netjail_exec_run (void *cls, struct GNUNET_TESTING_Interpreter *is) { struct NetJailState *ns = cls; - struct GNUNET_CONFIGURATION_Handle *config = - GNUNET_CONFIGURATION_create (); + ns->is = is; for (int i = 1; i <= ns->known; i++) { - start_helper (ns, config, + start_helper (ns, i, 0); } @@ -760,7 +813,7 @@ netjail_exec_run (void *cls, { for (int j = 1; j <= ns->local_m; j++) { - start_helper (ns, config, + start_helper (ns, j, i); } diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c index 33792f1b0..e37e955be 100644 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c @@ -35,6 +35,11 @@ struct StopHelperState { + /** + * The complete topology information. + */ + struct GNUNET_TESTING_NetjailTopology *topology; + const char *helper_start_label; /** @@ -63,21 +68,10 @@ struct StopHelperState static void stop_testing_system_cleanup (void *cls) { + struct StopHelperState *shs = cls; -} - - -/** - * Trait function of this cmd does nothing. - * - */ -static int -stop_testing_system_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_OK; + GNUNET_TESTING_free_topology (shs->topology); + GNUNET_free (shs); } @@ -148,13 +142,13 @@ GNUNET_TESTING_cmd_stop_testing_system (const char *label, shs->local_m = topology->nodes_m; shs->global_n = topology->namespaces_n; shs->known = topology->nodes_x; + shs->topology = topology; struct GNUNET_TESTING_Command cmd = { .cls = shs, .label = label, .run = &stop_testing_system_run, .cleanup = &stop_testing_system_cleanup, - .traits = &stop_testing_system_traits }; return cmd; diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 025326de7..0bf919787 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c @@ -2119,10 +2119,9 @@ tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port) * @param bindto String we extract the address part from. * @return The extracted address string. */ -static char * -extract_address (const char *bindto) +static void +extract_address (const char *bindto, char **addr) { - char *start; char *token; char *cp; @@ -2147,6 +2146,7 @@ extract_address (const char *bindto) { start++; /* skip over '['*/ cp[strlen (cp) - 1] = '\0'; /* eat ']'*/ + *addr = GNUNET_strdup (start); } else { @@ -2154,23 +2154,20 @@ extract_address (const char *bindto) if (strlen (bindto) == strlen (token)) { token = strtok_r (cp, ":", &rest); + *addr = strdup (token); } else { token++; res = GNUNET_strdup (token); - GNUNET_free (cp); - return res; + *addr = GNUNET_strdup (res); } } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "extract address 3\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "extract address with start %s\n", - start); - - return GNUNET_strdup (start); + "tcp address: %s\n", + *addr); + GNUNET_free (cp); } @@ -2241,6 +2238,7 @@ extract_port (const char *addr_and_port) GNUNET_free (cp); return 0; } + GNUNET_free (cp); } else { @@ -2250,7 +2248,6 @@ extract_port (const char *addr_and_port) port = 0; } - return port; } @@ -2269,10 +2266,11 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) unsigned int port; struct sockaddr_in v4; struct sockaddr_in6 v6; - char *start; + char *start = GNUNET_malloc (sizeof(bindto)); // cp = GNUNET_strdup (bindto); - start = extract_address (bindto); + start = GNUNET_malloc (sizeof(bindto)); + extract_address (bindto, &start); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start %s\n", @@ -3604,7 +3602,8 @@ run (void *cls, return; } - start = extract_address (bindto); + start = GNUNET_malloc (sizeof(bindto)); + extract_address (bindto, &start); if (1 == inet_pton (AF_INET, start, &v4.sin_addr)) { diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c index f0b47084b..c374fc2d0 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send.c +++ b/src/transport/test_transport_plugin_cmd_simple_send.c @@ -58,6 +58,11 @@ struct TestState * */ char *cfgname; + + /** + * The complete topology information. + */ + struct GNUNET_TESTING_NetjailTopology *topology; }; static struct GNUNET_TESTING_Command block_send; @@ -66,6 +71,8 @@ static struct GNUNET_TESTING_Command block_receive; static struct GNUNET_TESTING_Command connect_peers; +static struct GNUNET_TESTING_Command local_prepared; + /** * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being @@ -93,7 +100,8 @@ handle_test (void *cls, GNUNET_TESTING_get_trait_async_context (&block_receive, &ac); - if ((NULL == ac) || (NULL == ac->cont)) + GNUNET_assert (NULL != ac); + if (NULL == ac->cont) GNUNET_TESTING_async_fail (ac); else GNUNET_TESTING_async_finish (ac); @@ -111,7 +119,8 @@ all_peers_started () GNUNET_TESTING_get_trait_async_context (&block_send, &ac); - if ((NULL == ac) || (NULL == ac->cont)) + GNUNET_assert (NULL != ac); + if (NULL == ac->cont) GNUNET_TESTING_async_fail (ac); else GNUNET_TESTING_async_finish (ac); @@ -136,10 +145,15 @@ handle_result (void *cls, rv); reply = GNUNET_TESTING_send_local_test_finished_msg (rv); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "message prepared\n"); ts->write_message (reply, ntohs (reply->size)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "message send\n"); GNUNET_free (ts->testdir); GNUNET_free (ts->cfgname); + GNUNET_TESTING_free_topology (ts->topology); GNUNET_free (ts); } @@ -166,6 +180,24 @@ notify_connect (void *cls, } +/** + * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api. + */ +static void +all_local_tests_prepared () +{ + struct LocalPreparedState *lfs; + + GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared, + &lfs); + GNUNET_assert (NULL != &lfs->ac); + if (NULL == lfs->ac.cont) + GNUNET_TESTING_async_fail (&lfs->ac); + else + GNUNET_TESTING_async_finish (&lfs->ac); +} + + /** * Function to start a local test case. * @@ -192,8 +224,14 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, struct GNUNET_TESTING_NetjailTopology *topology = GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); - if (0 == m_int) - num = n_int; + ts->topology = topology; + + sscanf (m, "%u", &m_int); + sscanf (n, "%u", &n_int); + sscanf (local_m, "%u", &local_m_int); + + if (0 == n_int) + num = m_int; else num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; @@ -205,13 +243,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, "system-create", num, topology); + local_prepared = GNUNET_TESTING_cmd_local_test_prepared ( + "local-test-prepared", + write_message); - - sscanf (m, "%u", &m_int); - sscanf (n, "%u", &n_int); - sscanf (local_m, "%u", &local_m_int); - GNUNET_asprintf (&ts->cfgname, "test_transport_api2_tcp_node1.conf"); @@ -253,8 +289,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, connect_peers, GNUNET_TRANSPORT_cmd_send_simple ("send-simple", "start-peer", - num), + "system-create", + num, + topology), block_receive, + local_prepared, GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", "start-peer"), GNUNET_TESTING_cmd_system_destroy ("system-destroy", @@ -262,6 +301,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, GNUNET_TESTING_cmd_end () }; + ts->write_message = write_message; + GNUNET_TESTING_run (commands, GNUNET_TIME_UNIT_FOREVER_REL, &handle_result, @@ -288,6 +329,7 @@ libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls) api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); api->start_testcase = &start_testcase; api->all_peers_started = &all_peers_started; + api->all_local_tests_prepared = all_local_tests_prepared; return api; } diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c index ee6dc0274..f3afbec48 100644 --- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c +++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c @@ -58,11 +58,17 @@ struct TestState * */ char *cfgname; + + /** + * The complete topology information. + */ + struct GNUNET_TESTING_NetjailTopology *topology; }; static struct GNUNET_TESTING_Command block_send; static struct GNUNET_TESTING_Command connect_peers; + static struct GNUNET_TESTING_Command local_prepared; @@ -110,7 +116,8 @@ all_peers_started () GNUNET_TESTING_get_trait_async_context (&block_send, &ac); - if ((NULL == ac) || (NULL == ac->cont)) + GNUNET_assert (NULL != ac); + if ((NULL == ac->cont)) GNUNET_TESTING_async_fail (ac); else GNUNET_TESTING_async_finish (ac); @@ -142,6 +149,7 @@ handle_result (void *cls, GNUNET_free (ts->testdir); GNUNET_free (ts->cfgname); + GNUNET_TESTING_free_topology (ts->topology); GNUNET_free (ts); } @@ -174,10 +182,11 @@ static void all_local_tests_prepared () { struct LocalPreparedState *lfs; + GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared, &lfs); - - if ((NULL == &lfs->ac) || (NULL == lfs->ac.cont)) + GNUNET_assert (NULL != &lfs->ac); + if (NULL == lfs->ac.cont) GNUNET_TESTING_async_fail (&lfs->ac); else GNUNET_TESTING_async_finish (&lfs->ac); @@ -210,6 +219,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, struct GNUNET_TESTING_NetjailTopology *topology = GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); + ts->topology = topology; + sscanf (m, "%u", &m_int); sscanf (n, "%u", &n_int); sscanf (local_m, "%u", &local_m_int); diff --git a/src/transport/test_transport_simple_send.sh b/src/transport/test_transport_simple_send.sh index 2dd269fcc..7e3ee032f 100755 --- a/src/transport/test_transport_simple_send.sh +++ b/src/transport/test_transport_simple_send.sh @@ -1,2 +1,7 @@ #!/bin/bash -exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_topo.conf" +if [ "$(sysctl -n kernel.unprivileged_userns_clone)" == 1 ]; then + exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_topo.conf" +else + echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n" + exit 78 +fi diff --git a/src/transport/test_transport_simple_send_topo.conf b/src/transport/test_transport_simple_send_topo.conf index f878f9719..2c16201f5 100644 --- a/src/transport/test_transport_simple_send_topo.conf +++ b/src/transport/test_transport_simple_send_topo.conf @@ -1,4 +1,6 @@ M:2 N:1 X:0 -T:libgnunet_test_transport_plugin_cmd_simple_send \ No newline at end of file +T:libgnunet_test_transport_plugin_cmd_simple_send +P:1:1|{connect:{P:1:2:tcp}} +P:1:2|{connect:{P:1:1:tcp}} \ No newline at end of file diff --git a/src/transport/test_transport_udp_backchannel.sh b/src/transport/test_transport_udp_backchannel.sh index 0c37be469..9c0b11fad 100755 --- a/src/transport/test_transport_udp_backchannel.sh +++ b/src/transport/test_transport_udp_backchannel.sh @@ -1,4 +1,9 @@ #!/bin/bash +if [ "$(sysctl -n kernel.unprivileged_userns_clone)" == 1 ]; then #exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes --trace-children=yes --trace-children-skip=/usr/bin/awk,/usr/bin/cut,/usr/bin/seq,/sbin/ip ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf" exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf" # exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf" +else + echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n" + exit 78 +fi diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h index d6bb46f7d..10729990d 100644 --- a/src/transport/transport-testing-cmds.h +++ b/src/transport/transport-testing-cmds.h @@ -62,12 +62,6 @@ struct ConnectPeersState */ const char *start_peer_label; - /** - * The peer identity of this peer. - * - */ - struct GNUNET_PeerIdentity *id; - /** * The topology of the test setup. */ @@ -222,16 +216,19 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label, * Create command. * * @param label name for command. - * @param m The number of the local node of the actual network namespace. - * @param n The number of the actual namespace. - * @param num Number globally identifying the node. * @param start_peer_label Label of the cmd to start a peer. + * @param start_peer_label Label of the cmd which started the test system. + * @param num Number globally identifying the node. + * @param The topology for the test setup. * @return command. */ struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple (const char *label, const char *start_peer_label, - uint32_t num); + const char *create_label, + uint32_t num, + struct GNUNET_TESTING_NetjailTopology * + topology); /** diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c index 017d1bca3..2eb1b0914 100644 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ b/src/transport/transport_api_cmd_connecting_peers.c @@ -72,6 +72,10 @@ connect_peers_run (void *cls, cps->tl_system = tl_system; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "cps->num: %u \n", + cps->num); + cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num, cps->topology); @@ -84,28 +88,15 @@ connect_peers_run (void *cls, pos_prefix = pos_prefix->next) { - - LOG (GNUNET_ERROR_TYPE_ERROR, - "prefix: %s\n", - pos_prefix->address_prefix); - addr = GNUNET_TESTING_get_address (pos_connection, pos_prefix->address_prefix); - peer = GNUNET_TESTING_get_pub_key (num, tl_system); - - LOG (GNUNET_ERROR_TYPE_ERROR, - "num: %u pub_key %s addr: %s\n", - num, - GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)), - addr); - - cps->id = peer; - GNUNET_TRANSPORT_application_validate (ah, peer, nt, addr); + GNUNET_free (peer); + GNUNET_free (addr); } } cps->con_num = con_num; @@ -136,6 +127,7 @@ notify_connect (void *cls, if (0 == GNUNET_memcmp (peer, peer_connection)) con_num++; + GNUNET_free (peer_connection); } @@ -156,7 +148,6 @@ connect_peers_cleanup (void *cls) { struct ConnectPeersState *cps = cls; - GNUNET_free (cps->id); GNUNET_free (cps); } diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c index 0631f7051..9c34c50d7 100644 --- a/src/transport/transport_api_cmd_send_simple.c +++ b/src/transport/transport_api_cmd_send_simple.c @@ -46,21 +46,18 @@ struct SendSimpleState * */ const char *start_peer_label; -}; + /** + * Label of the cmd which started the test system. + * + */ + const char *create_label; -/** - * Trait function of this cmd does nothing. - * - */ -static int -send_simple_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - return GNUNET_OK; -} + /** + * The topology we get the connected nodes from. + */ + struct GNUNET_TESTING_NetjailTopology *topology; +}; /** @@ -77,7 +74,7 @@ send_simple_cleanup (void *cls) /** - * The run method of this cmd will send a simple message to the connected peer. + * The run method of this cmd will send a simple message to the connected peers. * */ static void @@ -92,31 +89,54 @@ send_simple_run (void *cls, const struct GNUNET_TESTING_Command *peer1_cmd; struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); struct GNUNET_HashCode hc; - int node_number; + struct GNUNET_TESTING_NodeConnection *node_connections_head; + struct GNUNET_PeerIdentity *peer; + struct GNUNET_CRYPTO_EddsaPublicKey public_key; + uint32_t num; + struct GNUNET_TESTING_NodeConnection *pos_connection; + const struct GNUNET_TESTING_Command *system_cmd; + struct GNUNET_TESTING_System *tl_system; peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, sss->start_peer_label); GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, &connected_peers_map); - node_number = 1; - GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); - memcpy (key, - &hc, - sizeof (*key)); - - mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map, - key); - - env = GNUNET_MQ_msg_extra (test, - 2600 - sizeof(*test), - GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE); - test->num = htonl (sss->num); - memset (&test[1], - sss->num, - 2600 - sizeof(*test)); - GNUNET_MQ_send (mq, - env); + system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, + sss->create_label); + GNUNET_TESTING_get_trait_test_system (system_cmd, + &tl_system); + + node_connections_head = GNUNET_TESTING_get_connections (sss->num, + sss->topology); + + for (int i = 0; i < 1; i++) + { + for (pos_connection = node_connections_head; NULL != pos_connection; + pos_connection = pos_connection->next) + { + num = GNUNET_TESTING_calculate_num (pos_connection, sss->topology); + peer = GNUNET_TESTING_get_pub_key (num, tl_system); + public_key = peer->public_key; + GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc); + + memcpy (key, + &hc, + sizeof (*key)); + mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map, + key); + env = GNUNET_MQ_msg_extra (test, + 1000 - sizeof(*test), + GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE); + test->num = htonl (sss->num); + memset (&test[1], + sss->num, + 1000 - sizeof(*test)); + GNUNET_MQ_send (mq, + env); + } + } + GNUNET_free (key); } @@ -126,31 +146,34 @@ send_simple_run (void *cls, * Create command. * * @param label name for command. - * @param m The number of the local node of the actual network namespace. - * @param n The number of the actual namespace. - * @param num Number globally identifying the node. * @param start_peer_label Label of the cmd to start a peer. + * @param start_peer_label Label of the cmd which started the test system. + * @param num Number globally identifying the node. + * @param The topology for the test setup. * @return command. */ struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple (const char *label, const char *start_peer_label, - uint32_t num) + const char *create_label, + uint32_t num, + struct GNUNET_TESTING_NetjailTopology * + topology) { struct SendSimpleState *sss; sss = GNUNET_new (struct SendSimpleState); sss->num = num; sss->start_peer_label = start_peer_label; - { - struct GNUNET_TESTING_Command cmd = { - .cls = sss, - .label = label, - .run = &send_simple_run, - .cleanup = &send_simple_cleanup, - .traits = &send_simple_traits - }; - - return cmd; - } + sss->create_label = create_label; + sss->topology = topology; + + struct GNUNET_TESTING_Command cmd = { + .cls = sss, + .label = label, + .run = &send_simple_run, + .cleanup = &send_simple_cleanup + }; + + return cmd; } diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c index dc19f10eb..a026d48cc 100644 --- a/src/transport/transport_api_cmd_start_peer.c +++ b/src/transport/transport_api_cmd_start_peer.c @@ -235,6 +235,10 @@ start_peer_run (void *cls, sps->tl_system = tl_system; + LOG (GNUNET_ERROR_TYPE_ERROR, + "Creating testing library with key number %u\n", + sps->no); + if (GNUNET_SYSERR == GNUNET_TESTING_configuration_create (tl_system, sps->cfg)) @@ -255,9 +259,10 @@ start_peer_run (void *cls, if (NULL == sps->peer) { LOG (GNUNET_ERROR_TYPE_ERROR, - "Testing library failed to create unique configuration based on `%s': `%s'\n", + "Testing library failed to create unique configuration based on `%s': `%s' with key number %u\n", sps->cfgname, - emsg); + emsg, + sps->no); GNUNET_free (emsg); GNUNET_TESTING_interpreter_fail (is); return; @@ -337,6 +342,11 @@ start_peer_run (void *cls, return; } sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); + GNUNET_free (home); + GNUNET_free (transport_unix_path); + GNUNET_free (tcp_communicator_unix_path); + GNUNET_free (udp_communicator_unix_path); + GNUNET_free (bindto); } -- cgit v1.2.3