aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-07 13:07:30 +0200
committert3sserakt <t3ss@posteo.de>2021-10-07 13:07:30 +0200
commitd7fa0579995790840199ec86cb4d518f9d372fcd (patch)
treeb41accedea6cd0fb78d75afee61911b94a1099fb
parent658bceab7ba3aab5121e8874d8508264d3f63ce3 (diff)
downloadgnunet-d7fa0579995790840199ec86cb4d518f9d372fcd.tar.gz
gnunet-d7fa0579995790840199ec86cb4d518f9d372fcd.zip
- add generic topology configuration by file
- cmd simple send using file configuration from file - added cmd to check the logs for backchannel encapsulation - added cmd which notifies the master loop of local loop being prepared to finish - added logging to helper.c - moved code from connecting peers cmd into global functions - added parameters given to the connecting peers cmd - added assertion when notifying the transport service about a new queue, if the communicator has no intial capacity - added optional valgrind cmd to test script - added flag für queues with unlimited length - added check for queues with higher priority - added attribute queue_capacity to struct Queue - bug fixing worker task for kce generation and transport notification about available queue in udp communicator - change value for unlimited queue length from 0 to UINT16_MAX in tcp communicator and service - added loop to stop the test system for the globally known peers in stop testsystem cmd - refactored endless growing array to handle further messages from the local loops, and added logic to handle the local test prepare msg - added utility methods in testing.c - added forwarding of all tests prepared msg in gnunet-cmds-helper.c - added cmd to end loop without shutdown - added without shutdown cmd to simple send testcase - added backchannel check, without shutdown and prepared cmd to udp backchannel testcase.
-rw-r--r--src/include/gnunet_protocols.h6
-rw-r--r--src/include/gnunet_testing_ng_lib.h97
-rw-r--r--src/include/gnunet_testing_plugin.h8
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/gnunet-cmds-helper.c10
-rw-r--r--src/testing/test_testing_topology.c44
-rw-r--r--src/testing/testing.c264
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c2
-rw-r--r--src/testing/testing_api_cmd_local_test_prepared.c168
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c181
-rw-r--r--src/testing/testing_api_cmd_netjail_start_v2.c2
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c22
-rw-r--r--src/testing/testing_api_loop.c19
-rw-r--r--src/testing/testing_cmds.h17
-rw-r--r--src/transport/Makefile.am2
-rw-r--r--src/transport/gnunet-communicator-tcp.c20
-rw-r--r--src/transport/gnunet-communicator-udp.c101
-rw-r--r--src/transport/gnunet-service-tng.c207
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c7
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_v2.c3
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c37
-rwxr-xr-xsrc/transport/test_transport_udp_backchannel.sh2
-rw-r--r--src/transport/transport-testing-cmds.h72
-rw-r--r--src/transport/transport_api2_communication.c9
-rw-r--r--src/transport/transport_api_cmd_backchannel_check.c628
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c14
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v3.c251
-rw-r--r--src/transport/transport_api_cmd_send_simple_v3.c194
-rw-r--r--src/util/helper.c4
29 files changed, 2012 insertions, 380 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 41f2876e6..9e278eb92 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -3579,7 +3579,11 @@ extern "C" {
3579 3579
3580#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED 1703 3580#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED 1703
3581 3581
3582#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1704 3582#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED 1704
3583
3584#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED 1705
3585
3586#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1706
3583 3587
3584/*********************************************************************************/ 3588/*********************************************************************************/
3585 3589
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 31665f8f7..6138f567b 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -79,17 +79,17 @@ enum GNUNET_TESTING_NODE_TYPE
79 GNUNET_TESTING_GLOBAL_NODE 79 GNUNET_TESTING_GLOBAL_NODE
80}; 80};
81 81
82struct GNUNET_TESTING_ADDRESS_PREFIX 82struct GNUNET_TESTING_AddressPrefix
83{ 83{
84 /** 84 /**
85 * Pointer to the previous prefix in the DLL. 85 * Pointer to the previous prefix in the DLL.
86 */ 86 */
87 struct GNUNET_TESTING_ADDRESS_PREFIX *prev; 87 struct GNUNET_TESTING_AddressPrefix *prev;
88 88
89 /** 89 /**
90 * Pointer to the next prefix in the DLL. 90 * Pointer to the next prefix in the DLL.
91 */ 91 */
92 struct GNUNET_TESTING_ADDRESS_PREFIX *next; 92 struct GNUNET_TESTING_AddressPrefix *next;
93 93
94 /** 94 /**
95 * The address prefix. 95 * The address prefix.
@@ -138,12 +138,12 @@ struct GNUNET_TESTING_NodeConnection
138 /** 138 /**
139 * Head of the DLL with the address prefixes for the protocolls this node is reachable. 139 * Head of the DLL with the address prefixes for the protocolls this node is reachable.
140 */ 140 */
141 struct GNUNET_TESTING_ADDRESS_PREFIX *address_prefixes_head; 141 struct GNUNET_TESTING_AddressPrefix *address_prefixes_head;
142 142
143 /** 143 /**
144 * Tail of the DLL with the address prefixes for the protocolls this node is reachable. 144 * Tail of the DLL with the address prefixes for the protocolls this node is reachable.
145 */ 145 */
146 struct GNUNET_TESTING_ADDRESS_PREFIX *address_prefixes_tail; 146 struct GNUNET_TESTING_AddressPrefix *address_prefixes_tail;
147}; 147};
148 148
149/** 149/**
@@ -379,6 +379,11 @@ struct GNUNET_TESTING_Command
379 */ 379 */
380 bool asynchronous_finish; 380 bool asynchronous_finish;
381 381
382 /**
383 * Shall the scheduler shutdown, when end cmd is reach?
384 */
385 bool shutdown_on_end;
386
382}; 387};
383 388
384 389
@@ -450,6 +455,15 @@ GNUNET_TESTING_cmd_end (void);
450 455
451 456
452/** 457/**
458 * Create command array terminator without shutdown.
459 *
460 * @return a end-command.
461 */
462struct GNUNET_TESTING_Command
463GNUNET_TESTING_cmd_end_without_shutdown (void);
464
465
466/**
453 * Turn asynchronous command into non blocking command by setting asynchronous_finish to true. 467 * Turn asynchronous command into non blocking command by setting asynchronous_finish to true.
454 * 468 *
455 * @param cmd command to make synchronous. 469 * @param cmd command to make synchronous.
@@ -661,6 +675,55 @@ GNUNET_TESTING_get_topo_from_file (const char *filename);
661 675
662 676
663/** 677/**
678 * Get the connections to other nodes for a specific node.
679 *
680 * @param num The specific node we want the connections for.
681 * @param topology The topology we get the connections from.
682 * @return The connections of the node.
683 */
684struct GNUNET_TESTING_NodeConnection *
685GNUNET_TESTING_get_connections (unsigned int num, struct
686 GNUNET_TESTING_NetjailTopology *topology);
687
688
689/**
690 * Get the address for a specific communicator from a connection.
691 *
692 * @param connection The connection we like to have the address from.
693 * @param prefix The communicator protocol prefix.
694 * @return The address of the communicator.
695 */
696char *
697GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
698 char *prefix);
699
700
701/**
702 * Calculate the unique id identifying a node from a given connction.
703 *
704 * @param node_connection The connection we calculate the id from.
705 * @param topology The topology we get all needed information from.
706 * @return The unique id of the node from the connection.
707 */
708unsigned int
709GNUNET_TESTING_calculate_num (struct
710 GNUNET_TESTING_NodeConnection *node_connection,
711 struct GNUNET_TESTING_NetjailTopology *topology);
712
713
714/**
715 * Retrieve the public key from the test system with the unique node id.
716 *
717 * @param num The unique node id.
718 * @param tl_system The test system.
719 * @return The peer identity wrapping the public key.
720 */
721struct GNUNET_PeerIdentity *
722GNUNET_TESTING_get_pub_key (unsigned int num, struct
723 GNUNET_TESTING_System *tl_system);
724
725
726/**
664 * Obtain performance data from the interpreter. 727 * Obtain performance data from the interpreter.
665 * 728 *
666 * @param timers what commands (by label) to obtain runtimes for 729 * @param timers what commands (by label) to obtain runtimes for
@@ -1183,12 +1246,36 @@ GNUNET_TESTING_cmd_block_until_external_trigger (const char *label,
1183 unsigned int * 1246 unsigned int *
1184 stop_blocking); 1247 stop_blocking);
1185 1248
1249
1186struct GNUNET_TESTING_Command 1250struct GNUNET_TESTING_Command
1187GNUNET_TESTING_cmd_send_peer_ready (const char *label, 1251GNUNET_TESTING_cmd_send_peer_ready (const char *label,
1188 TESTING_CMD_HELPER_write_cb write_message); 1252 TESTING_CMD_HELPER_write_cb write_message);
1189 1253
1254
1255/**
1256 * Create command.
1257 *
1258 * @param label name for command.
1259 * @param write_message Callback to write messages to the master loop.
1260 * @return command.
1261 */
1190struct GNUNET_TESTING_Command 1262struct GNUNET_TESTING_Command
1191GNUNET_TESTING_cmd_local_test_finished (const char *label, 1263GNUNET_TESTING_cmd_local_test_finished (const char *label,
1192 TESTING_CMD_HELPER_write_cb 1264 TESTING_CMD_HELPER_write_cb
1193 write_message); 1265 write_message);
1266
1267/**
1268 * Create command.
1269 *
1270 * @param label name for command.
1271 * @param write_message Callback to write messages to the master loop.
1272 * @param all_local_tests_prepared Flag which will be set from outside.
1273 * @return command.
1274 */
1275struct GNUNET_TESTING_Command
1276GNUNET_TESTING_cmd_local_test_prepared (const char *label,
1277 TESTING_CMD_HELPER_write_cb
1278 write_message,
1279 unsigned int *
1280 all_local_tests_prepared);
1194#endif 1281#endif
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
index 151827d4b..4a6a9368e 100644
--- a/src/include/gnunet_testing_plugin.h
+++ b/src/include/gnunet_testing_plugin.h
@@ -48,9 +48,15 @@ typedef void
48 char *m, 48 char *m,
49 char *local_m); 49 char *local_m);
50 50
51
51typedef void 52typedef void
52(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) (); 53(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) ();
53 54
55
56typedef void
57(*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) ();
58
59
54struct GNUNET_TESTING_PluginFunctions 60struct GNUNET_TESTING_PluginFunctions
55{ 61{
56 /** 62 /**
@@ -61,6 +67,8 @@ struct GNUNET_TESTING_PluginFunctions
61 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase; 67 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase;
62 68
63 GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started; 69 GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started;
70
71 GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED all_local_tests_prepared;
64}; 72};
65 73
66#if 0 /* keep Emacsens' auto-indent happy */ 74#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index efb22b279..07caeb44e 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -44,6 +44,7 @@ libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \
44 44
45libgnunettesting_la_SOURCES = \ 45libgnunettesting_la_SOURCES = \
46 testing_api_cmd_local_test_finished.c \ 46 testing_api_cmd_local_test_finished.c \
47 testing_api_cmd_local_test_prepared.c \
47 testing_api_cmd_send_peer_ready.c \ 48 testing_api_cmd_send_peer_ready.c \
48 testing_api_cmd_block_until_all_peers_started.c \ 49 testing_api_cmd_block_until_all_peers_started.c \
49 testing_api_cmd_block_until_external_trigger.c \ 50 testing_api_cmd_block_until_external_trigger.c \
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index e50db0cf6..4aeccb115 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -418,9 +418,19 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
418 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( 418 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
419 message->type)) 419 message->type))
420 { 420 {
421 LOG (GNUNET_ERROR_TYPE_DEBUG,
422 "all peers started\n");
421 plugin->api->all_peers_started (); 423 plugin->api->all_peers_started ();
422 return GNUNET_OK; 424 return GNUNET_OK;
423 } 425 }
426 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED == ntohs (
427 message->type))
428 {
429 LOG (GNUNET_ERROR_TYPE_DEBUG,
430 "all local tests prepared\n");
431 plugin->api->all_local_tests_prepared ();
432 return GNUNET_OK;
433 }
424 else 434 else
425 { 435 {
426 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); 436 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
new file mode 100644
index 000000000..cfc91e609
--- /dev/null
+++ b/src/testing/test_testing_topology.c
@@ -0,0 +1,44 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_testcmd.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
31
32int
33main (int argc,
34 char *const *argv)
35{
36 GNUNET_log_setup ("test-topology",
37 "DEBUG",
38 NULL);
39 LOG (GNUNET_ERROR_TYPE_DEBUG,
40 "Test\n");
41 GNUNET_TESTING_get_topo_from_file ("topo.conf");
42 LOG (GNUNET_ERROR_TYPE_DEBUG,
43 "Test2\n");
44}
diff --git a/src/testing/testing.c b/src/testing/testing.c
index a11d404a5..d3acd4689 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -37,6 +37,15 @@
37 37
38#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
39 39
40#define CONNECT_ADDRESS_TEMPLATE "%s-192.168.15.%u:60002"
41
42#define ROUTER_CONNECT_ADDRESS_TEMPLATE "%s-92.68.150.%u:60002"
43
44#define KNOWN_CONNECT_ADDRESS_TEMPLATE "%s-92.68.151.%u:60002"
45
46#define PREFIX_TCP "tcp"
47
48#define PREFIX_UDP "udp"
40 49
41/** 50/**
42 * Lowest port used for GNUnet testing. Should be high enough to not 51 * Lowest port used for GNUnet testing. Should be high enough to not
@@ -1900,7 +1909,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1900 unsigned int namespace_n; 1909 unsigned int namespace_n;
1901 char *rest = NULL; 1910 char *rest = NULL;
1902 char *rest2 = NULL; 1911 char *rest2 = NULL;
1903 struct GNUNET_TESTING_ADDRESS_PREFIX *prefix; 1912 struct GNUNET_TESTING_AddressPrefix *prefix;
1904 1913
1905 node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection); 1914 node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection);
1906 node_connection->node = node; 1915 node_connection->node = node;
@@ -1936,7 +1945,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1936 } 1945 }
1937 while (NULL != (token = strtok_r (NULL, ":", &rest))) 1946 while (NULL != (token = strtok_r (NULL, ":", &rest)))
1938 { 1947 {
1939 prefix = GNUNET_new (struct GNUNET_TESTING_ADDRESS_PREFIX); 1948 prefix = GNUNET_new (struct GNUNET_TESTING_AddressPrefix);
1940 token2 = strtok_r (token, "}", &rest2); 1949 token2 = strtok_r (token, "}", &rest2);
1941 if (NULL != token2) 1950 if (NULL != token2)
1942 { 1951 {
@@ -1958,13 +1967,12 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
1958 GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head, 1967 GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head,
1959 node_connection->address_prefixes_tail, 1968 node_connection->address_prefixes_tail,
1960 prefix); 1969 prefix);
1970 LOG (GNUNET_ERROR_TYPE_ERROR,
1971 "address_prefix %s\n",
1972 prefix->address_prefix);
1961 } 1973 }
1962 1974
1963 GNUNET_free (copy); 1975 GNUNET_free (copy);
1964 LOG (GNUNET_ERROR_TYPE_ERROR,
1965 "address_prefix %s\n",
1966 prefix->address_prefix);
1967
1968 return node_connection; 1976 return node_connection;
1969} 1977}
1970 1978
@@ -2006,6 +2014,250 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node)
2006} 2014}
2007 2015
2008 2016
2017static int
2018log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2019{
2020 struct GNUNET_TESTING_NetjailNode *node = value;
2021 struct GNUNET_TESTING_NodeConnection *pos_connection;
2022 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
2023
2024 LOG (GNUNET_ERROR_TYPE_ERROR,
2025 "plugin: %s space: %u node: %u global: %u\n",
2026 node->plugin,
2027 node->namespace_n,
2028 node->node_n,
2029 node->is_global);
2030
2031 for (pos_connection = node->node_connections_head; NULL != pos_connection;
2032 pos_connection = pos_connection->next)
2033 {
2034
2035 LOG (GNUNET_ERROR_TYPE_ERROR,
2036 "namespace_n: %u node_n: %u node_type: %u\n",
2037 pos_connection->namespace_n,
2038 pos_connection->node_n,
2039 pos_connection->node_type);
2040
2041 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
2042 pos_prefix =
2043 pos_prefix->next)
2044 {
2045 LOG (GNUNET_ERROR_TYPE_ERROR,
2046 "prefix: %s\n",
2047 pos_prefix->address_prefix);
2048 }
2049 }
2050 return GNUNET_YES;
2051}
2052
2053
2054static int
2055log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
2056{
2057 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
2058 struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
2059
2060 LOG (GNUNET_ERROR_TYPE_ERROR,
2061 "router_tcp: %u router_udp: %u spaces: %u\n",
2062 router->tcp_port,
2063 router->udp_port,
2064 namespace->namespace_n);
2065 GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
2066 return GNUNET_YES;
2067}
2068
2069
2070static int
2071log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
2072{
2073 LOG (GNUNET_ERROR_TYPE_ERROR,
2074 "plugin: %s spaces: %u nodes: %u known: %u\n",
2075 topology->plugin,
2076 topology->namespaces_n,
2077 topology->nodes_m,
2078 topology->nodes_x);
2079
2080 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
2081 log_namespaces, NULL);
2082 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
2083 NULL);
2084 return GNUNET_YES;
2085}
2086
2087
2088/**
2089 * Get the connections to other nodes for a specific node.
2090 *
2091 * @param num The specific node we want the connections for.
2092 * @param topology The topology we get the connections from.
2093 * @return The connections of the node.
2094 */
2095struct GNUNET_TESTING_NodeConnection *
2096GNUNET_TESTING_get_connections (unsigned int num, struct
2097 GNUNET_TESTING_NetjailTopology *topology)
2098{
2099 struct GNUNET_TESTING_NetjailNode *node;
2100 struct GNUNET_ShortHashCode *hkey;
2101 struct GNUNET_HashCode hc;
2102 struct GNUNET_TESTING_NetjailNamespace *namespace;
2103 unsigned int namespace_n, node_m;
2104
2105 log_topo (topology);
2106
2107 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2108 if (topology->nodes_x >= num)
2109 {
2110
2111 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
2112 memcpy (hkey,
2113 &hc,
2114 sizeof (*hkey));
2115 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
2116 hkey);
2117 }
2118 else
2119 {
2120 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
2121 / topology->nodes_m);
2122 LOG (GNUNET_ERROR_TYPE_ERROR,
2123 "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
2124 num,
2125 topology->nodes_x,
2126 topology->nodes_m,
2127 namespace_n);
2128 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2129 GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
2130 memcpy (hkey,
2131 &hc,
2132 sizeof (*hkey));
2133 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
2134 hkey);
2135 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
2136 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2137 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
2138 memcpy (hkey,
2139 &hc,
2140 sizeof (*hkey));
2141 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
2142 hkey);
2143 }
2144
2145
2146 return node->node_connections_head;
2147}
2148
2149
2150/**
2151 * Retrieve the public key from the test system with the unique node id.
2152 *
2153 * @param num The unique node id.
2154 * @param tl_system The test system.
2155 * @return The peer identity wrapping the public key.
2156 */
2157struct GNUNET_PeerIdentity *
2158GNUNET_TESTING_get_pub_key (unsigned int num, struct
2159 GNUNET_TESTING_System *tl_system)
2160{
2161 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
2162 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
2163 GNUNET_CRYPTO_EddsaPublicKey);
2164 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
2165 GNUNET_CRYPTO_EddsaPrivateKey);
2166
2167 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
2168 num,
2169 peer);
2170
2171 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
2172 pub_key);
2173 peer->public_key = *pub_key;
2174 return peer;
2175}
2176
2177
2178/**
2179 * Calculate the unique id identifying a node from a given connction.
2180 *
2181 * @param node_connection The connection we calculate the id from.
2182 * @param topology The topology we get all needed information from.
2183 * @return The unique id of the node from the connection.
2184 */
2185unsigned int
2186GNUNET_TESTING_calculate_num (struct
2187 GNUNET_TESTING_NodeConnection *node_connection,
2188 struct GNUNET_TESTING_NetjailTopology *topology)
2189{
2190 unsigned int n, m, num;
2191
2192 n = node_connection->namespace_n;
2193 m = node_connection->node_n;
2194
2195 if (0 == n)
2196 num = m;
2197 else
2198 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
2199
2200 return num;
2201}
2202
2203
2204/**
2205 * Get the address for a specific communicator from a connection.
2206 *
2207 * @param connection The connection we like to have the address from.
2208 * @param prefix The communicator protocol prefix.
2209 * @return The address of the communicator.
2210 */
2211char *
2212GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
2213 char *prefix)
2214{
2215 struct GNUNET_TESTING_NetjailNode *node;
2216 char *addr;
2217 char *template;
2218
2219 LOG (GNUNET_ERROR_TYPE_ERROR,
2220 "node_n: %u\n",
2221 connection->node_n);
2222
2223 node = connection->node;
2224 if (connection->namespace_n == node->namespace_n)
2225 {
2226 template = CONNECT_ADDRESS_TEMPLATE;
2227 }
2228 else if (0 == connection->namespace_n)
2229 {
2230 template = KNOWN_CONNECT_ADDRESS_TEMPLATE;
2231 }
2232 else
2233 {
2234 template = ROUTER_CONNECT_ADDRESS_TEMPLATE;
2235 }
2236
2237 if (0 == strcmp (PREFIX_TCP, prefix))
2238 {
2239
2240 GNUNET_asprintf (&addr,
2241 template,
2242 prefix,
2243 connection->node_n);
2244 }
2245 else if (0 == strcmp (PREFIX_UDP, prefix))
2246 {
2247 GNUNET_asprintf (&addr,
2248 template,
2249 prefix,
2250 connection->node_n);
2251 }
2252 else
2253 {
2254 GNUNET_break (0);
2255 }
2256
2257 return addr;
2258}
2259
2260
2009/** 2261/**
2010 * Getting the topology from file. 2262 * Getting the topology from file.
2011 * 2263 *
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index 383de4c10..b50e471e9 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -115,7 +115,7 @@ local_test_finished_finish (void *cls,
115 GNUNET_SCHEDULER_TaskCallback cont, 115 GNUNET_SCHEDULER_TaskCallback cont,
116 void *cont_cls) 116 void *cont_cls)
117{ 117{
118 LOG (GNUNET_ERROR_TYPE_DEBUG, 118 LOG (GNUNET_ERROR_TYPE_ERROR,
119 "Stopping local loop\n"); 119 "Stopping local loop\n");
120 return GNUNET_YES; 120 return GNUNET_YES;
121} 121}
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c
new file mode 100644
index 000000000..4e915c7c0
--- /dev/null
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -0,0 +1,168 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_local_test_prepared.c
23 * @brief cmd to block the interpreter loop until all peers started.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "testing_cmds.h"
30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
36
37/**
38 * Struct to hold information for callbacks.
39 *
40 */
41struct LocalPreparedState
42{
43 /**
44 * Callback to write messages to the master loop.
45 *
46 */
47 TESTING_CMD_HELPER_write_cb write_message;
48
49 /**
50 * The message send back to the master loop.
51 *
52 */
53 struct GNUNET_CMDS_LOCAL_TEST_PREPARED *reply;
54
55 /**
56 * Flag indicating if all local tests finished.
57 */
58 unsigned int *all_local_tests_prepared;
59};
60
61
62/**
63 * Trait function of this cmd does nothing.
64 *
65 */
66static int
67local_test_prepared_traits (void *cls,
68 const void **ret,
69 const char *trait,
70 unsigned int index)
71{
72 return GNUNET_OK;
73}
74
75
76/**
77 * The cleanup function of this cmd frees resources the cmd allocated.
78 *
79 */
80static void
81local_test_prepared_cleanup (void *cls,
82 const struct GNUNET_TESTING_Command *cmd)
83{
84 struct LocalPreparedState *lfs = cls;
85
86 GNUNET_free (lfs->reply);
87 GNUNET_free (lfs);
88}
89
90
91/**
92 * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TESTS_PREPARED message to the master loop.
93 *
94 */
95static void
96local_test_prepared_run (void *cls,
97 const struct GNUNET_TESTING_Command *cmd,
98 struct GNUNET_TESTING_Interpreter *is)
99{
100 struct LocalPreparedState *lfs = cls;
101
102 struct GNUNET_CMDS_LOCAL_TEST_PREPARED *reply;
103 size_t msg_length;
104
105 msg_length = sizeof(struct GNUNET_CMDS_LOCAL_TEST_PREPARED);
106 reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_TEST_PREPARED);
107 reply->header.type = htons (
108 GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED);
109 reply->header.size = htons ((uint16_t) msg_length);
110 lfs->reply = reply;
111 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
112}
113
114
115/**
116 * This finish function will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
117 *
118 */
119static int
120local_test_prepared_finish (void *cls,
121 GNUNET_SCHEDULER_TaskCallback cont,
122 void *cont_cls)
123{
124 struct LocalPreparedState *lfs = cls;
125 unsigned int *ret = lfs->all_local_tests_prepared;
126
127 if (GNUNET_YES == *ret)
128 {
129 cont (cont_cls);
130 }
131
132 return *ret;
133
134}
135
136
137/**
138 * Create command.
139 *
140 * @param label name for command.
141 * @param write_message Callback to write messages to the master loop.
142 * @param all_local_tests_prepared Flag which will be set from outside.
143 * @return command.
144 */
145struct GNUNET_TESTING_Command
146GNUNET_TESTING_cmd_local_test_prepared (const char *label,
147 TESTING_CMD_HELPER_write_cb
148 write_message,
149 unsigned int *
150 all_local_tests_prepared)
151{
152 struct LocalPreparedState *lfs;
153
154 lfs = GNUNET_new (struct LocalPreparedState);
155 lfs->write_message = write_message;
156 lfs->all_local_tests_prepared = all_local_tests_prepared;
157
158 struct GNUNET_TESTING_Command cmd = {
159 .cls = lfs,
160 .label = label,
161 .run = &local_test_prepared_run,
162 .finish = &local_test_prepared_finish,
163 .cleanup = &local_test_prepared_cleanup,
164 .traits = &local_test_prepared_traits
165 };
166
167 return cmd;
168}
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
index ccb3f5ae8..5e27a7a82 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
@@ -30,6 +30,11 @@
30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.sh" 30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.sh"
31 31
32/** 32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
36
37/**
33 * Struct to store messages send/received by the helper into a DLL 38 * Struct to store messages send/received by the helper into a DLL
34 * 39 *
35 */ 40 */
@@ -116,13 +121,13 @@ struct NetJailState
116 /** 121 /**
117 * The send handle for the helper 122 * The send handle for the helper
118 */ 123 */
119 struct GNUNET_HELPER_SendHandle **shandle; 124 // struct GNUNET_HELPER_SendHandle **shandle;
120 125
121 /** 126 /**
122 * Size of the array NetJailState#shandle. 127 * Size of the array NetJailState#shandle.
123 * 128 *
124 */ 129 */
125 unsigned int n_shandle; 130 // unsigned int n_shandle;
126 131
127 /** 132 /**
128 * The messages send to the helper. 133 * The messages send to the helper.
@@ -151,7 +156,13 @@ struct NetJailState
151 * Number of local tests finished. 156 * Number of local tests finished.
152 * 157 *
153 */ 158 */
154 unsigned int number_of_local_test_finished; 159 unsigned int number_of_local_tests_finished;
160
161 /**
162 * Number of local tests prepared to finish.
163 *
164 */
165 unsigned int number_of_local_tests_prepared;
155 166
156 /** 167 /**
157 * Name of the test case plugin the helper will load. 168 * Name of the test case plugin the helper will load.
@@ -189,6 +200,17 @@ struct TestingSystemCount
189 struct TestingSystemCount *prev; 200 struct TestingSystemCount *prev;
190 201
191 /** 202 /**
203 * The send handle for the helper
204 */
205 struct GNUNET_HELPER_SendHandle *shandle;// **shandle;
206
207 /**
208 * Size of the array NetJailState#shandle.
209 *
210 */
211 // unsigned int n_shandle;
212
213 /**
192 * The number of the test environment. 214 * The number of the test environment.
193 * 215 *
194 */ 216 */
@@ -277,10 +299,9 @@ netjail_exec_traits (void *cls,
277 * @return #GNUNET_OK on success. 299 * @return #GNUNET_OK on success.
278 */ 300 */
279int 301int
280GNUNET_TESTING_get_trait_helper_handles_v2 (const struct 302GNUNET_TESTING_get_trait_helper_handles_v2 (
281 GNUNET_TESTING_Command *cmd, 303 const struct GNUNET_TESTING_Command *cmd,
282 struct GNUNET_HELPER_Handle *** 304 struct GNUNET_HELPER_Handle ***helper)
283 helper)
284{ 305{
285 return cmd->traits (cmd->cls, 306 return cmd->traits (cmd->cls,
286 (const void **) helper, 307 (const void **) helper,
@@ -293,18 +314,19 @@ GNUNET_TESTING_get_trait_helper_handles_v2 (const struct
293 * Continuation function from GNUNET_HELPER_send() 314 * Continuation function from GNUNET_HELPER_send()
294 * 315 *
295 * @param cls closure 316 * @param cls closure
296 * @param result GNUNET_OK on success, 317 * @param result #GNUNET_OK on success,
297 * GNUNET_NO if helper process died 318 * #GNUNET_NO if helper process died
298 * GNUNET_SYSERR during GNUNET_HELPER_stop 319 * #GNUNET_SYSERR during GNUNET_HELPER_stop
299 */ 320 */
300static void 321static void
301clear_msg (void *cls, int result) 322clear_msg (void *cls,
323 int result)
302{ 324{
303 struct TestingSystemCount *tbc = cls; 325 struct TestingSystemCount *tbc = cls;
304 struct NetJailState *ns = tbc->ns; 326 struct NetJailState *ns = tbc->ns;
305 327
306 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]); 328 GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]);
307 ns->shandle[tbc->count - 1] = NULL; 329 tbc->shandle = NULL;// [tbc->count - 1] = NULL;
308 GNUNET_free (ns->msg[tbc->count - 1]); 330 GNUNET_free (ns->msg[tbc->count - 1]);
309 ns->msg[tbc->count - 1] = NULL; 331 ns->msg[tbc->count - 1] = NULL;
310} 332}
@@ -323,10 +345,11 @@ clear_msg (void *cls, int result)
323 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 345 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
324 */ 346 */
325static int 347static int
326helper_mst (void *cls, const struct GNUNET_MessageHeader *message) 348helper_mst (void *cls,
349 const struct GNUNET_MessageHeader *message)
327{ 350{
328 struct TestingSystemCount *tbc = cls; 351 // struct TestingSystemCount *tbc = cls;
329 struct NetJailState *ns = tbc->ns; 352 struct NetJailState *ns = cls;// tbc->ns;
330 struct HelperMessage *hp_msg; 353 struct HelperMessage *hp_msg;
331 354
332 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) 355 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
@@ -338,10 +361,18 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
338 { 361 {
339 ns->number_of_peers_started++; 362 ns->number_of_peers_started++;
340 } 363 }
364 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED == ntohs (
365 message->type))
366 {
367 LOG (GNUNET_ERROR_TYPE_DEBUG,
368 "received prepare msg %u\n",
369 ns->number_of_local_tests_prepared);
370 ns->number_of_local_tests_prepared++;
371 }
341 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( 372 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
342 message->type)) 373 message->type))
343 { 374 {
344 ns->number_of_local_test_finished++; 375 ns->number_of_local_tests_finished++;
345 } 376 }
346 else 377 else
347 { 378 {
@@ -364,8 +395,10 @@ static void
364exp_cb (void *cls) 395exp_cb (void *cls)
365{ 396{
366 struct NetJailState *ns = cls; 397 struct NetJailState *ns = cls;
398 unsigned int *rv = ns->rv;
399
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); 400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
368 *ns->rv = 1; 401 *rv = 1;
369} 402}
370 403
371 404
@@ -420,6 +453,7 @@ start_helper (struct NetJailState *ns, struct
420 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; 453 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
421 struct GNUNET_TESTING_NetjailNode *node; 454 struct GNUNET_TESTING_NetjailNode *node;
422 struct GNUNET_TESTING_NetjailNamespace *namespace; 455 struct GNUNET_TESTING_NetjailNamespace *namespace;
456 unsigned int *rv = ns->rv;
423 457
424 458
425 if (0 == n) 459 if (0 == n)
@@ -460,7 +494,8 @@ start_helper (struct NetJailState *ns, struct
460 else 494 else
461 tbc->count = (n - 1) * ns->local_m + m + ns->known; 495 tbc->count = (n - 1) * ns->local_m + m + ns->known;
462 496
463 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail, 497 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head,
498 ns->tbcs_tail,
464 tbc); 499 tbc);
465 500
466 501
@@ -469,14 +504,14 @@ start_helper (struct NetJailState *ns, struct
469 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 504 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
470 "No SUID for %s!\n", 505 "No SUID for %s!\n",
471 NETJAIL_EXEC_SCRIPT); 506 NETJAIL_EXEC_SCRIPT);
472 *ns->rv = 1; 507 *rv = 1;
473 } 508 }
474 else if (GNUNET_NO == helper_check) 509 else if (GNUNET_NO == helper_check)
475 { 510 {
476 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
477 "%s not found!\n", 512 "%s not found!\n",
478 NETJAIL_EXEC_SCRIPT); 513 NETJAIL_EXEC_SCRIPT);
479 *ns->rv = 1; 514 *rv = 1;
480 } 515 }
481 516
482 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( 517 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
@@ -485,7 +520,7 @@ start_helper (struct NetJailState *ns, struct
485 script_argv, 520 script_argv,
486 &helper_mst, 521 &helper_mst,
487 &exp_cb, 522 &exp_cb,
488 tbc)); 523 ns));
489 524
490 helper = ns->helper[tbc->count - 1]; 525 helper = ns->helper[tbc->count - 1];
491 526
@@ -542,19 +577,20 @@ start_helper (struct NetJailState *ns, struct
542 577
543 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); 578 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
544 579
545 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( 580 // GNUNET_array_append (tbc->shandle, tbc->n_shandle,
546 helper, 581 tbc->shandle = GNUNET_HELPER_send (
547 &msg->header, 582 helper,
548 GNUNET_NO, 583 &msg->header,
549 &clear_msg, 584 GNUNET_NO,
550 tbc)); 585 &clear_msg,
586 tbc); // );
551 587
552 if (NULL == ns->shandle[tbc->count - 1]) 588 if (NULL == tbc->shandle)// [tbc->count - 1])
553 { 589 {
554 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 590 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
555 "Send handle is NULL!\n"); 591 "Send handle is NULL!\n");
556 GNUNET_free (msg); 592 GNUNET_free (msg);
557 *ns->rv = 1; 593 *rv = 1;
558 } 594 }
559} 595}
560 596
@@ -595,39 +631,76 @@ netjail_exec_run (void *cls,
595 631
596 632
597static void 633static void
598send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) 634send_message_to_locals (
635 unsigned int i,
636 unsigned int j,
637 struct NetJailState *ns,
638 struct GNUNET_MessageHeader *header
639 )
599{ 640{
600 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 641 // unsigned int total_number = ns->local_m * ns->global_n + ns->known;
601 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
602 size_t msg_length;
603 struct GNUNET_HELPER_Handle *helper; 642 struct GNUNET_HELPER_Handle *helper;
604 struct TestingSystemCount *tbc; 643 struct TestingSystemCount *tbc;
605 644
645 LOG (GNUNET_ERROR_TYPE_DEBUG,
646 "send message to locals\n");
606 tbc = GNUNET_new (struct TestingSystemCount); 647 tbc = GNUNET_new (struct TestingSystemCount);
607 tbc->ns = ns; 648 tbc->ns = ns;
608 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone. 649 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
609 if (0 == i) 650 if (0 == i)
610 tbc->count = j + total_number; 651 tbc->count = j; // + total_number;
611 else 652 else
612 tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known; 653 tbc->count = (i - 1) * ns->local_m + j + ns->known; // + total_number ;
613 654
614 helper = ns->helper[tbc->count - 1 - total_number]; 655 helper = ns->helper[tbc->count - 1];// - total_number];
615 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
616 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
617 reply->header.type = htons (
618 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
619 reply->header.size = htons ((uint16_t) msg_length);
620 656
621 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); 657 GNUNET_array_append (ns->msg, ns->n_msg, header);
622 658
623 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( 659 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
624 helper, 660 helper,
625 &reply->header, 661 header,
626 GNUNET_NO, 662 GNUNET_NO,
627 &clear_msg, 663 &clear_msg,
628 tbc); 664 tbc);
629 665
630 GNUNET_array_append (ns->shandle, ns->n_shandle, sh); 666 tbc->shandle = sh;
667 // GNUNET_array_append (tbc->shandle, tbc->n_shandle, sh);
668}
669
670
671static void
672send_all_local_tests_prepared (unsigned int i, unsigned int j, struct
673 NetJailState *ns)
674{
675 struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED *reply;
676 size_t msg_length;
677
678
679 msg_length = sizeof(struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
680 reply = GNUNET_new (struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
681 reply->header.type = htons (
682 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED);
683 reply->header.size = htons ((uint16_t) msg_length);
684
685 send_message_to_locals (i, j, ns, &reply->header);
686}
687
688
689static void
690send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
691{
692
693 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
694 size_t msg_length;
695
696
697 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
698 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
699 reply->header.type = htons (
700 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
701 reply->header.size = htons ((uint16_t) msg_length);
702
703 send_message_to_locals (i, j, ns, &reply->header);
631} 704}
632 705
633 706
@@ -650,12 +723,28 @@ netjail_start_finish (void *cls,
650 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 723 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
651 724
652 725
653 if (ns->number_of_local_test_finished == total_number) 726 if (ns->number_of_local_tests_finished == total_number)
654 { 727 {
655 ret = GNUNET_YES; 728 ret = GNUNET_YES;
656 cont (cont_cls); 729 cont (cont_cls);
657 } 730 }
658 731
732 if (ns->number_of_local_tests_prepared == total_number)
733 {
734 for (int i = 1; i <= ns->known; i++)
735 {
736 send_all_local_tests_prepared (0,i, ns);
737 }
738
739 for (int i = 1; i <= ns->global_n; i++)
740 {
741 for (int j = 1; j <= ns->local_m; j++)
742 {
743 send_all_local_tests_prepared (i,j, ns);
744 }
745 }
746 }
747
659 if (ns->number_of_testsystems_started == total_number) 748 if (ns->number_of_testsystems_started == total_number)
660 { 749 {
661 ns->number_of_testsystems_started = 0; 750 ns->number_of_testsystems_started = 0;
diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c
index 36fbb0e10..7d802db6a 100644
--- a/src/testing/testing_api_cmd_netjail_start_v2.c
+++ b/src/testing/testing_api_cmd_netjail_start_v2.c
@@ -75,7 +75,7 @@ netjail_start_cleanup (void *cls,
75 { 75 {
76 GNUNET_assert (0 == 76 GNUNET_assert (0 ==
77 GNUNET_OS_process_kill (ns->start_proc, 77 GNUNET_OS_process_kill (ns->start_proc,
78 SIGKILL)); 78 SIGTERM));
79 GNUNET_assert (GNUNET_OK == 79 GNUNET_assert (GNUNET_OK ==
80 GNUNET_OS_process_wait (ns->start_proc)); 80 GNUNET_OS_process_wait (ns->start_proc));
81 GNUNET_OS_process_destroy (ns->start_proc); 81 GNUNET_OS_process_destroy (ns->start_proc);
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
index 8eccc5764..6ce106eaa 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
@@ -45,6 +45,12 @@ struct StopHelperState
45 unsigned int local_m; 45 unsigned int local_m;
46 46
47 unsigned int global_n; 47 unsigned int global_n;
48
49 /**
50 * Number of global known nodes.
51 *
52 */
53 unsigned int known;
48}; 54};
49 55
50 56
@@ -97,11 +103,24 @@ stop_testing_system_run (void *cls,
97 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, 103 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
98 &helper); 104 &helper);
99 105
106 for (int i = 1; i <= shs->known; i++)
107 {
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
109 "i: %u\n",
110 i);
111 GNUNET_HELPER_stop (helper[i - 1],
112 GNUNET_YES);
113 }
114
100 for (int i = 1; i <= shs->global_n; i++) 115 for (int i = 1; i <= shs->global_n; i++)
101 { 116 {
102 for (int j = 1; j <= shs->local_m; j++) 117 for (int j = 1; j <= shs->local_m; j++)
103 { 118 {
104 GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j - 1], 119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
120 "i: %u j: %u\n",
121 i,
122 j);
123 GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j + shs->known - 1],
105 GNUNET_YES); 124 GNUNET_YES);
106 } 125 }
107 } 126 }
@@ -130,6 +149,7 @@ GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
130 shs->helper_start_label = helper_start_label; 149 shs->helper_start_label = helper_start_label;
131 shs->local_m = topology->nodes_m; 150 shs->local_m = topology->nodes_m;
132 shs->global_n = topology->namespaces_n; 151 shs->global_n = topology->namespaces_n;
152 shs->known = topology->nodes_x;
133 153
134 struct GNUNET_TESTING_Command cmd = { 154 struct GNUNET_TESTING_Command cmd = {
135 .cls = shs, 155 .cls = shs,
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 0c24c0e26..ab095aafa 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -408,6 +408,22 @@ GNUNET_TESTING_cmd_end (void)
408{ 408{
409 static struct GNUNET_TESTING_Command cmd; 409 static struct GNUNET_TESTING_Command cmd;
410 cmd.label = NULL; 410 cmd.label = NULL;
411 cmd.shutdown_on_end = GNUNET_YES;
412
413 return cmd;
414}
415
416/**
417 * Create command array terminator without shutdown.
418 *
419 * @return a end-command.
420 */
421struct GNUNET_TESTING_Command
422GNUNET_TESTING_cmd_end_without_shutdown (void)
423{
424 static struct GNUNET_TESTING_Command cmd;
425 cmd.label = NULL;
426 cmd.shutdown_on_end = GNUNET_NO;
411 427
412 return cmd; 428 return cmd;
413} 429}
@@ -447,7 +463,8 @@ interpreter_run (void *cls)
447 "Running command END %p\n", 463 "Running command END %p\n",
448 is); 464 is);
449 is->result = GNUNET_OK; 465 is->result = GNUNET_OK;
450 GNUNET_SCHEDULER_shutdown (); 466 if (GNUNET_YES == cmd->shutdown_on_end)
467 GNUNET_SCHEDULER_shutdown ();
451 return; 468 return;
452 } 469 }
453 else if (NULL != cmd) 470 else if (NULL != cmd)
diff --git a/src/testing/testing_cmds.h b/src/testing/testing_cmds.h
index 7a5860aea..005402a73 100644
--- a/src/testing/testing_cmds.h
+++ b/src/testing/testing_cmds.h
@@ -85,6 +85,23 @@ struct GNUNET_CMDS_LOCAL_FINISHED
85 struct GNUNET_MessageHeader header; 85 struct GNUNET_MessageHeader header;
86}; 86};
87 87
88struct GNUNET_CMDS_LOCAL_TEST_PREPARED
89{
90 /**
91 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED
92 */
93 struct GNUNET_MessageHeader header;
94};
95
96struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED
97{
98 /**
99 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED
100 */
101 struct GNUNET_MessageHeader header;
102};
103
88GNUNET_NETWORK_STRUCT_END 104GNUNET_NETWORK_STRUCT_END
105
89#endif 106#endif
90/* end of testing_cmds.h */ 107/* end of testing_cmds.h */
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 32075ee16..73544a8d5 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -163,12 +163,14 @@ libgnunettransporttesting2_la_SOURCES = \
163 transport_api_cmd_connecting_peers.c \ 163 transport_api_cmd_connecting_peers.c \
164 transport_api_cmd_connecting_peers_v2.c \ 164 transport_api_cmd_connecting_peers_v2.c \
165 transport_api_cmd_connecting_peers_v3.c \ 165 transport_api_cmd_connecting_peers_v3.c \
166 transport_api_cmd_backchannel_check.c \
166 transport_api_cmd_start_peer.c \ 167 transport_api_cmd_start_peer.c \
167 transport_api_cmd_start_peer_v2.c \ 168 transport_api_cmd_start_peer_v2.c \
168 transport_api_cmd_start_peer_v3.c \ 169 transport_api_cmd_start_peer_v3.c \
169 transport_api_cmd_stop_peer.c \ 170 transport_api_cmd_stop_peer.c \
170 transport_api_cmd_send_simple.c \ 171 transport_api_cmd_send_simple.c \
171 transport_api_cmd_send_simple_v2.c \ 172 transport_api_cmd_send_simple_v2.c \
173 transport_api_cmd_send_simple_v3.c \
172 transport-testing2.c transport-testing2.h \ 174 transport-testing2.c transport-testing2.h \
173 transport-testing-cmds.h \ 175 transport-testing-cmds.h \
174 transport-testing-filenames2.c \ 176 transport-testing-filenames2.c \
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index d8bf7c1a8..025326de7 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -1119,6 +1119,10 @@ pass_plaintext_to_core (struct Queue *queue,
1119 const struct GNUNET_MessageHeader *hdr = plaintext; 1119 const struct GNUNET_MessageHeader *hdr = plaintext;
1120 int ret; 1120 int ret;
1121 1121
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1123 "pass message from %s to core\n",
1124 GNUNET_i2s (&queue->target));
1125
1122 if (ntohs (hdr->size) != plaintext_len) 1126 if (ntohs (hdr->size) != plaintext_len)
1123 { 1127 {
1124 /* NOTE: If we ever allow multiple CORE messages in one 1128 /* NOTE: If we ever allow multiple CORE messages in one
@@ -1132,6 +1136,8 @@ pass_plaintext_to_core (struct Queue *queue,
1132 ADDRESS_VALIDITY_PERIOD, 1136 ADDRESS_VALIDITY_PERIOD,
1133 &core_read_finished_cb, 1137 &core_read_finished_cb,
1134 queue); 1138 queue);
1139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1140 "passed to core\n");
1135 if (GNUNET_OK == ret) 1141 if (GNUNET_OK == ret)
1136 queue->backpressure++; 1142 queue->backpressure++;
1137 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */ 1143 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
@@ -1795,7 +1801,7 @@ try_handle_plaintext (struct Queue *queue)
1795 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, 1801 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch,
1796 &queue->target, 1802 &queue->target,
1797 foreign_addr, 1803 foreign_addr,
1798 UINT32_MAX, /* no MTU */ 1804 UINT16_MAX, /* no MTU */
1799 GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, 1805 GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED,
1800 0, /* Priority */ 1806 0, /* Priority */
1801 queue->nt, 1807 queue->nt,
@@ -2444,7 +2450,7 @@ boot_queue (struct Queue *queue)
2444 * Generate and transmit our ephemeral key and the signature for 2450 * Generate and transmit our ephemeral key and the signature for
2445 * the initial KX with the other peer. Must be called first, before 2451 * the initial KX with the other peer. Must be called first, before
2446 * any other bytes are ever written to the output buffer. Note that 2452 * any other bytes are ever written to the output buffer. Note that
2447 * our cipher must already be initialized when calling this function. 2453 * our cipher must already be initialized when calling thi function.
2448 * Helper function for #start_initial_kx_out(). 2454 * Helper function for #start_initial_kx_out().
2449 * 2455 *
2450 * @param queue queue to do KX for 2456 * @param queue queue to do KX for
@@ -2725,6 +2731,9 @@ proto_read_kx (void *cls)
2725 queue->listen_sock = pq->listen_sock; 2731 queue->listen_sock = pq->listen_sock;
2726 queue->sock = pq->sock; 2732 queue->sock = pq->sock;
2727 2733
2734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2735 "created queue with target %s\n",
2736 GNUNET_i2s (&queue->target));
2728 2737
2729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2730 "start kx proto\n"); 2739 "start kx proto\n");
@@ -2984,6 +2993,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2984 queue->sock = sock; 2993 queue->sock = sock;
2985 queue->cs = GNUNET_TRANSPORT_CS_OUTBOUND; 2994 queue->cs = GNUNET_TRANSPORT_CS_OUTBOUND;
2986 boot_queue (queue); 2995 boot_queue (queue);
2996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2997 "booted queue with target %s\n",
2998 GNUNET_i2s (&queue->target));
2987 // queue->mq_awaits_continue = GNUNET_YES; 2999 // queue->mq_awaits_continue = GNUNET_YES;
2988 queue->read_task = 3000 queue->read_task =
2989 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 3001 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
@@ -3646,6 +3658,10 @@ main (int argc, char *const *argv)
3646 }; 3658 };
3647 int ret; 3659 int ret;
3648 3660
3661 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
3662 "transport",
3663 "Starting tcp communicator\n");
3664
3649 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 3665 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
3650 return 2; 3666 return 2;
3651 3667
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index ef7b1d6c0..659fd7d26 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -1494,7 +1494,27 @@ add_acks (struct SharedSecret *ss, int acks_to_add)
1494 1494
1495 GNUNET_assert (NULL != ss); 1495 GNUNET_assert (NULL != ss);
1496 GNUNET_assert (NULL != receiver); 1496 GNUNET_assert (NULL != receiver);
1497 GNUNET_assert (NULL != receiver->d_qh); 1497
1498 if (NULL == receiver->d_qh)
1499 {
1500 receiver->d_qh =
1501 GNUNET_TRANSPORT_communicator_mq_add (ch,
1502 &receiver->target,
1503 receiver->foreign_addr,
1504 receiver->d_mtu,
1505 acks_to_add,
1506 1, /* Priority */
1507 receiver->nt,
1508 GNUNET_TRANSPORT_CS_OUTBOUND,
1509 receiver->d_mq);
1510 }
1511 else
1512 {
1513 GNUNET_TRANSPORT_communicator_mq_update (ch,
1514 receiver->d_qh,
1515 acks_to_add,
1516 1);
1517 }
1498 1518
1499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1500 "Tell transport we have %u more acks!\n", 1520 "Tell transport we have %u more acks!\n",
@@ -1502,10 +1522,7 @@ add_acks (struct SharedSecret *ss, int acks_to_add)
1502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1503 "%u kce for rekeying.\n", 1523 "%u kce for rekeying.\n",
1504 receiver->number_rekeying_kce); 1524 receiver->number_rekeying_kce);
1505 GNUNET_TRANSPORT_communicator_mq_update (ch, 1525
1506 receiver->d_qh,
1507 acks_to_add,
1508 1);
1509 // Until here for alternativ 1 1526 // Until here for alternativ 1
1510 1527
1511 /* move ss to head to avoid discarding it anytime soon! */ 1528 /* move ss to head to avoid discarding it anytime soon! */
@@ -1744,7 +1761,7 @@ kce_generate_cb (void *cls)
1744 if (((GNUNET_NO == ss->sender->rekeying) && (ss->sender->acks_available < 1761 if (((GNUNET_NO == ss->sender->rekeying) && (ss->sender->acks_available <
1745 KCN_TARGET) ) || 1762 KCN_TARGET) ) ||
1746 ((ss->sender->ss_rekey == ss) && (GNUNET_YES == ss->sender->rekeying) && 1763 ((ss->sender->ss_rekey == ss) && (GNUNET_YES == ss->sender->rekeying) &&
1747 (ss->sender->acks_available < 128))) 1764 (ss->sender->acks_available < KCN_TARGET)))
1748 { 1765 {
1749 1766
1750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1754,20 +1771,24 @@ kce_generate_cb (void *cls)
1754 for (int i = 0; i < GENERATE_AT_ONCE; i++) 1771 for (int i = 0; i < GENERATE_AT_ONCE; i++)
1755 kce_generate (ss, ++ss->sequence_allowed); 1772 kce_generate (ss, ++ss->sequence_allowed);
1756 1773
1757 ss->sender->kce_task = GNUNET_SCHEDULER_add_delayed ( 1774 if (KCN_TARGET > ss->sender->acks_available)
1758 WORKING_QUEUE_INTERVALL, 1775 {
1759 kce_generate_cb, 1776 ss->sender->kce_task = GNUNET_SCHEDULER_add_delayed (
1760 ss); 1777 WORKING_QUEUE_INTERVALL,
1761 } 1778 kce_generate_cb,
1762 else 1779 ss);
1763 { 1780 }
1764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1781 else
1765 "We have enough keys.\n"); 1782 {
1766 ss_finished = ss; 1783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1767 ss->sender->kce_task_finished = GNUNET_YES; 1784 "We have enough keys.\n");
1785 ss_finished = ss;
1786 ss->sender->kce_task_finished = GNUNET_YES;
1787 }
1768 } 1788 }
1769 1789
1770 1790
1791
1771} 1792}
1772 1793
1773 1794
@@ -1850,7 +1871,17 @@ consider_ss_ack (struct SharedSecret *ss, int initial)
1850 kce_generate (ss, ++ss->sequence_allowed); 1871 kce_generate (ss, ++ss->sequence_allowed);
1851 }*/ 1872 }*/
1852 1873
1853 if (((NULL != kce_task) && kce_task_finished) || (GNUNET_NO == initial)) 1874 if (NULL != kce_task)
1875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1876 "kce_task is not NULL\n");
1877 if (kce_task_finished)
1878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1879 "kce_task_finished: GNUNET_YES\n");
1880 if (initial)
1881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1882 "initial: GNUNET_YES\n");
1883
1884 if ( kce_task_finished || (GNUNET_NO == initial))
1854 { 1885 {
1855 struct UDPAck ack; 1886 struct UDPAck ack;
1856 struct SharedSecret *ss_tell; 1887 struct SharedSecret *ss_tell;
@@ -1877,8 +1908,7 @@ consider_ss_ack (struct SharedSecret *ss, int initial)
1877 if (GNUNET_NO != initial) 1908 if (GNUNET_NO != initial)
1878 { 1909 {
1879 destroy_all_secrets (ss, GNUNET_YES); 1910 destroy_all_secrets (ss, GNUNET_YES);
1880 kce_task = NULL; 1911 ss->sender->kce_task_finished = GNUNET_NO;
1881 kce_task_finished = GNUNET_NO;
1882 } 1912 }
1883 } 1913 }
1884 else if ((NULL == kce_task) && ((KCN_THRESHOLD > 1914 else if ((NULL == kce_task) && ((KCN_THRESHOLD >
@@ -2678,8 +2708,10 @@ mq_send_kx (struct GNUNET_MQ_Handle *mq,
2678 receiver->address_len)) 2708 receiver->address_len))
2679 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 2709 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
2680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2681 "Sending KX to %s\n", GNUNET_a2s (receiver->address, 2711 "Sending KX with payload size %u to %s\n",
2682 receiver->address_len)); 2712 msize,
2713 GNUNET_a2s (receiver->address,
2714 receiver->address_len));
2683 GNUNET_MQ_impl_send_continue (mq); 2715 GNUNET_MQ_impl_send_continue (mq);
2684} 2716}
2685 2717
@@ -2940,7 +2972,8 @@ mq_send_d (struct GNUNET_MQ_Handle *mq,
2940 receiver->address_len)) 2972 receiver->address_len))
2941 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 2973 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
2942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2943 "Sending UDPBox %u acks left\n", 2975 "Sending UDPBox with payload size %u, %u acks left\n",
2976 msize,
2944 receiver->acks_available); 2977 receiver->acks_available);
2945 GNUNET_MQ_impl_send_continue (mq); 2978 GNUNET_MQ_impl_send_continue (mq);
2946 receiver->acks_available--; 2979 receiver->acks_available--;
@@ -3135,17 +3168,6 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
3135 receiver->nt, 3168 receiver->nt,
3136 GNUNET_TRANSPORT_CS_OUTBOUND, 3169 GNUNET_TRANSPORT_CS_OUTBOUND,
3137 receiver->kx_mq); 3170 receiver->kx_mq);
3138 receiver->d_qh =
3139 GNUNET_TRANSPORT_communicator_mq_add (ch,
3140 &receiver->target,
3141 receiver->foreign_addr,
3142 receiver->d_mtu,
3143 0, /* Initialize with 0 acks */
3144 1, /* Priority */
3145 receiver->nt,
3146 GNUNET_TRANSPORT_CS_OUTBOUND,
3147 receiver->d_mq);
3148
3149} 3171}
3150 3172
3151 3173
@@ -3755,9 +3777,11 @@ run (void *cls,
3755 GNUNET_free (bindto); 3777 GNUNET_free (bindto);
3756 in = (struct sockaddr *) &in_sto; 3778 in = (struct sockaddr *) &in_sto;
3757 in_len = sto_len; 3779 in_len = sto_len;
3758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3780 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
3759 "Bound to `%s'\n", 3781 "transport",
3760 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); 3782 "Bound to `%s'\n",
3783 GNUNET_a2s ((const struct sockaddr *) &in_sto,
3784 sto_len));
3761 switch (in->sa_family) 3785 switch (in->sa_family)
3762 { 3786 {
3763 case AF_INET: 3787 case AF_INET:
@@ -3853,6 +3877,9 @@ main (int argc, char *const *argv)
3853 }; 3877 };
3854 int ret; 3878 int ret;
3855 3879
3880 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
3881 "transport",
3882 "Starting udp communicator\n");
3856 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 3883 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
3857 return 2; 3884 return 2;
3858 3885
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index a7e2a8c04..a90bef3b5 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -1736,6 +1736,11 @@ struct Queue
1736 const char *address; 1736 const char *address;
1737 1737
1738 /** 1738 /**
1739 * Is this queue of unlimited length.
1740 */
1741 unsigned int unlimited_length;
1742
1743 /**
1739 * Task scheduled for the time when this queue can (likely) transmit the 1744 * Task scheduled for the time when this queue can (likely) transmit the
1740 * next message. 1745 * next message.
1741 */ 1746 */
@@ -1787,6 +1792,11 @@ struct Queue
1787 unsigned int queue_length; 1792 unsigned int queue_length;
1788 1793
1789 /** 1794 /**
1795 * Capacity of the queue.
1796 */
1797 uint64_t q_capacity;
1798
1799 /**
1790 * Queue priority 1800 * Queue priority
1791 */ 1801 */
1792 uint32_t priority; 1802 uint32_t priority;
@@ -3446,6 +3456,35 @@ transmit_on_queue (void *cls);
3446 3456
3447 3457
3448/** 3458/**
3459 * Check if the communicator has another queue with higher prio ready for sending.
3460 */
3461static unsigned int
3462check_for_queue_with_higher_prio (struct Queue *queue, struct Queue *queue_head)
3463{
3464 for (struct Queue *s = queue_head; NULL != s;
3465 s = s->next_client)
3466 {
3467 if (s->tc->details.communicator.address_prefix !=
3468 queue->tc->details.communicator.address_prefix)
3469 {
3470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3471 "queue address %s qid %u compare with queue: address %s qid %u\n",
3472 queue->address,
3473 queue->qid,
3474 s->address,
3475 s->qid);
3476 if ((s->priority > queue->priority) && (0 < s->q_capacity) &&
3477 (QUEUE_LENGTH_LIMIT > s->queue_length) )
3478 return GNUNET_YES;
3479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3480 "Lower prio\n");
3481 }
3482 }
3483 return GNUNET_NO;
3484}
3485
3486
3487/**
3449 * Called whenever something changed that might effect when we 3488 * Called whenever something changed that might effect when we
3450 * try to do the next transmission on @a queue using #transmit_on_queue(). 3489 * try to do the next transmission on @a queue using #transmit_on_queue().
3451 * 3490 *
@@ -3456,6 +3495,11 @@ static void
3456schedule_transmit_on_queue (struct Queue *queue, 3495schedule_transmit_on_queue (struct Queue *queue,
3457 enum GNUNET_SCHEDULER_Priority p) 3496 enum GNUNET_SCHEDULER_Priority p)
3458{ 3497{
3498 if (check_for_queue_with_higher_prio (queue,
3499 queue->tc->details.communicator.
3500 queue_head))
3501 return;
3502
3459 if (queue->tc->details.communicator.total_queue_length >= 3503 if (queue->tc->details.communicator.total_queue_length >=
3460 COMMUNICATOR_TOTAL_QUEUE_LIMIT) 3504 COMMUNICATOR_TOTAL_QUEUE_LIMIT)
3461 { 3505 {
@@ -3480,6 +3524,19 @@ schedule_transmit_on_queue (struct Queue *queue,
3480 queue->idle = GNUNET_NO; 3524 queue->idle = GNUNET_NO;
3481 return; 3525 return;
3482 } 3526 }
3527 if (0 == queue->q_capacity)
3528 {
3529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3530 "Transmission throttled due to communicator message queue qid %u has capacity %lu.\n",
3531 queue->qid,
3532 queue->q_capacity);
3533 GNUNET_STATISTICS_update (GST_stats,
3534 "# Transmission throttled due to message queue capacity",
3535 1,
3536 GNUNET_NO);
3537 queue->idle = GNUNET_NO;
3538 return;
3539 }
3483 /* queue might indeed be ready, schedule it */ 3540 /* queue might indeed be ready, schedule it */
3484 if (NULL != queue->transmit_task) 3541 if (NULL != queue->transmit_task)
3485 GNUNET_SCHEDULER_cancel (queue->transmit_task); 3542 GNUNET_SCHEDULER_cancel (queue->transmit_task);
@@ -3582,8 +3639,9 @@ free_queue (struct Queue *queue)
3582 tc->details.communicator.queue_head, 3639 tc->details.communicator.queue_head,
3583 tc->details.communicator.queue_tail, 3640 tc->details.communicator.queue_tail,
3584 queue); 3641 queue);
3585 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= 3642 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT <=
3586 tc->details.communicator.total_queue_length); 3643 tc->details.communicator.
3644 total_queue_length);
3587 while (NULL != (qe = queue->queue_head)) 3645 while (NULL != (qe = queue->queue_head))
3588 { 3646 {
3589 GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe); 3647 GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe);
@@ -3597,7 +3655,7 @@ free_queue (struct Queue *queue)
3597 GNUNET_free (qe); 3655 GNUNET_free (qe);
3598 } 3656 }
3599 GNUNET_assert (0 == queue->queue_length); 3657 GNUNET_assert (0 == queue->queue_length);
3600 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT < 3658 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT >
3601 tc->details.communicator.total_queue_length)) 3659 tc->details.communicator.total_queue_length))
3602 { 3660 {
3603 /* Communicator dropped below threshold, resume all _other_ queues */ 3661 /* Communicator dropped below threshold, resume all _other_ queues */
@@ -4223,18 +4281,36 @@ queue_send_msg (struct Queue *queue,
4223 if (NULL != pm) 4281 if (NULL != pm)
4224 { 4282 {
4225 qe->pm = pm; 4283 qe->pm = pm;
4226 GNUNET_assert (NULL == pm->qe); 4284 // TODO Why do we have a retransmission. When we know, make decision if we still want this.
4285 // GNUNET_assert (NULL == pm->qe);
4286 /*if (NULL != pm->qe)
4287 {
4288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4289 "Retransmitting message <%llu> remove pm from qe with MID: %llu \n",
4290 pm->logging_uuid,
4291 (unsigned long long) pm->qe->mid);
4292 pm->qe->pm = NULL;
4293 }*/
4227 pm->qe = qe; 4294 pm->qe = qe;
4228 } 4295 }
4229 GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe); 4296 GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe);
4230 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); 4297 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type);
4231 queue->queue_length++; 4298 queue->queue_length++;
4232 queue->tc->details.communicator.total_queue_length++; 4299 queue->tc->details.communicator.total_queue_length++;
4300 if (GNUNET_NO == queue->unlimited_length)
4301 queue->q_capacity--;
4302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4303 "Queue %s with qid %u has capacity %lu\n",
4304 queue->address,
4305 queue->qid,
4306 queue->q_capacity);
4233 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT == 4307 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT ==
4234 queue->tc->details.communicator.total_queue_length) 4308 queue->tc->details.communicator.total_queue_length)
4235 queue->idle = GNUNET_NO; 4309 queue->idle = GNUNET_NO;
4236 if (QUEUE_LENGTH_LIMIT == queue->queue_length) 4310 if (QUEUE_LENGTH_LIMIT == queue->queue_length)
4237 queue->idle = GNUNET_NO; 4311 queue->idle = GNUNET_NO;
4312 if (0 == queue->q_capacity)
4313 queue->idle = GNUNET_NO;
4238 GNUNET_MQ_send (queue->tc->mq, env); 4314 GNUNET_MQ_send (queue->tc->mq, env);
4239 } 4315 }
4240} 4316}
@@ -4672,8 +4748,16 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4672 struct GNUNET_TIME_Relative rtt1; 4748 struct GNUNET_TIME_Relative rtt1;
4673 struct GNUNET_TIME_Relative rtt2; 4749 struct GNUNET_TIME_Relative rtt2;
4674 4750
4751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4752 "Trying to route message of type %u to %s without fc\n",
4753 ntohs (hdr->type),
4754 GNUNET_i2s (target));
4755
4756 // TODO Do this elsewhere. vl should be given as parameter to method.
4675 vl = lookup_virtual_link (target); 4757 vl = lookup_virtual_link (target);
4676 GNUNET_assert (NULL != vl); 4758 GNUNET_assert (NULL != vl);
4759 if (NULL == vl)
4760 return GNUNET_TIME_UNIT_FOREVER_REL;
4677 n = vl->n; 4761 n = vl->n;
4678 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL; 4762 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL;
4679 if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) 4763 if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
@@ -4718,6 +4802,10 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4718 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL; 4802 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL;
4719 if (NULL != n) 4803 if (NULL != n)
4720 { 4804 {
4805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4806 "Try to route message of type %u to %s without fc via neighbour\n",
4807 ntohs (hdr->type),
4808 GNUNET_i2s (target));
4721 rtt1 = route_via_neighbour (n, hdr, options); 4809 rtt1 = route_via_neighbour (n, hdr, options);
4722 } 4810 }
4723 if (NULL != dv) 4811 if (NULL != dv)
@@ -4889,7 +4977,9 @@ check_vl_transmission (struct VirtualLink *vl)
4889 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 4977 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
4890 else 4978 else
4891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4892 "Queue busy or invalid\n"); 4980 "Neighbour Queue QID: %u (%u) busy or invalid\n",
4981 queue->qid,
4982 queue->idle);
4893 } 4983 }
4894 } 4984 }
4895 /* Notify queues via DV that we are interested */ 4985 /* Notify queues via DV that we are interested */
@@ -4910,6 +5000,11 @@ check_vl_transmission (struct VirtualLink *vl)
4910 (queue->validated_until.abs_value_us > now.abs_value_us)) 5000 (queue->validated_until.abs_value_us > now.abs_value_us))
4911 schedule_transmit_on_queue (queue, 5001 schedule_transmit_on_queue (queue,
4912 GNUNET_SCHEDULER_PRIORITY_BACKGROUND); 5002 GNUNET_SCHEDULER_PRIORITY_BACKGROUND);
5003 else
5004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5005 "DV Queue QID: %u (%u) busy or invalid\n",
5006 queue->qid,
5007 queue->idle);
4913 } 5008 }
4914 } 5009 }
4915} 5010}
@@ -4996,8 +5091,9 @@ handle_communicator_backchannel (
4996 (const struct GNUNET_MessageHeader *) &cb[1]; 5091 (const struct GNUNET_MessageHeader *) &cb[1];
4997 uint16_t isize = ntohs (inbox->size); 5092 uint16_t isize = ntohs (inbox->size);
4998 const char *is = ((const char *) &cb[1]) + isize; 5093 const char *is = ((const char *) &cb[1]) + isize;
5094 size_t slen = strlen (is) + 1;
4999 char 5095 char
5000 mbuf[isize 5096 mbuf[slen + isize
5001 + sizeof(struct 5097 + sizeof(struct
5002 TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN; 5098 TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN;
5003 struct TransportBackchannelEncapsulationMessage *be = 5099 struct TransportBackchannelEncapsulationMessage *be =
@@ -5006,9 +5102,10 @@ handle_communicator_backchannel (
5006 /* 0-termination of 'is' was checked already in 5102 /* 0-termination of 'is' was checked already in
5007 #check_communicator_backchannel() */ 5103 #check_communicator_backchannel() */
5008 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5009 "Preparing backchannel transmission to %s:%s of type %u\n", 5105 "Preparing backchannel transmission to %s:%s of type %u and size %u\n",
5010 GNUNET_i2s (&cb->pid), 5106 GNUNET_i2s (&cb->pid),
5011 is, 5107 is,
5108 ntohs (inbox->type),
5012 ntohs (inbox->size)); 5109 ntohs (inbox->size));
5013 /* encapsulate and encrypt message */ 5110 /* encapsulate and encrypt message */
5014 be->header.type = 5111 be->header.type =
@@ -5264,6 +5361,11 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5264 uint16_t size = ntohs (mh->size); 5361 uint16_t size = ntohs (mh->size);
5265 int have_core; 5362 int have_core;
5266 5363
5364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5365 "Handling message of type %u with %u bytes\n",
5366 (unsigned int) ntohs (mh->type),
5367 (unsigned int) ntohs (mh->size));
5368
5267 if ((size > UINT16_MAX - sizeof(struct InboundMessage)) || 5369 if ((size > UINT16_MAX - sizeof(struct InboundMessage)) ||
5268 (size < sizeof(struct GNUNET_MessageHeader))) 5370 (size < sizeof(struct GNUNET_MessageHeader)))
5269 { 5371 {
@@ -5290,6 +5392,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5290 1, 5392 1,
5291 GNUNET_NO); 5393 GNUNET_NO);
5292 5394
5395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5396 "CORE messages of type %u with %u bytes dropped (virtual link still down)\n",
5397 (unsigned int) ntohs (mh->type),
5398 (unsigned int) ntohs (mh->size));
5293 finish_cmc_handling (cmc); 5399 finish_cmc_handling (cmc);
5294 return; 5400 return;
5295 } 5401 }
@@ -5299,7 +5405,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5299 "# CORE messages dropped (FC arithmetic overflow)", 5405 "# CORE messages dropped (FC arithmetic overflow)",
5300 1, 5406 1,
5301 GNUNET_NO); 5407 GNUNET_NO);
5302 5408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5409 "CORE messages of type %u with %u bytes dropped (FC arithmetic overflow)\n",
5410 (unsigned int) ntohs (mh->type),
5411 (unsigned int) ntohs (mh->size));
5303 finish_cmc_handling (cmc); 5412 finish_cmc_handling (cmc);
5304 return; 5413 return;
5305 } 5414 }
@@ -5309,6 +5418,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5309 "# CORE messages dropped (FC window overflow)", 5418 "# CORE messages dropped (FC window overflow)",
5310 1, 5419 1,
5311 GNUNET_NO); 5420 GNUNET_NO);
5421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5422 "CORE messages of type %u with %u bytes dropped (FC window overflow)\n",
5423 (unsigned int) ntohs (mh->type),
5424 (unsigned int) ntohs (mh->size));
5312 finish_cmc_handling (cmc); 5425 finish_cmc_handling (cmc);
5313 return; 5426 return;
5314 } 5427 }
@@ -5345,6 +5458,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5345 perspective of the other peer! */ 5458 perspective of the other peer! */
5346 vl->incoming_fc_window_size_used += size; 5459 vl->incoming_fc_window_size_used += size;
5347 /* TODO-M1 */ 5460 /* TODO-M1 */
5461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5462 "Dropped message of type %u with %u bytes to CORE: no CORE client connected!",
5463 (unsigned int) ntohs (mh->type),
5464 (unsigned int) ntohs (mh->size));
5348 finish_cmc_handling (cmc); 5465 finish_cmc_handling (cmc);
5349 return; 5466 return;
5350 } 5467 }
@@ -6074,6 +6191,15 @@ handle_backchannel_encapsulation (
6074 (const struct GNUNET_MessageHeader *) &be[1]; 6191 (const struct GNUNET_MessageHeader *) &be[1];
6075 uint16_t isize = ntohs (inbox->size); 6192 uint16_t isize = ntohs (inbox->size);
6076 const char *target_communicator = ((const char *) inbox) + isize; 6193 const char *target_communicator = ((const char *) inbox) + isize;
6194 char *sender;
6195 char *self;
6196
6197 GNUNET_asprintf (&sender,
6198 "%s",
6199 GNUNET_i2s (&cmc->im.sender));
6200 GNUNET_asprintf (&self,
6201 "%s",
6202 GNUNET_i2s (&GST_my_identity));
6077 6203
6078 /* Find client providing this communicator */ 6204 /* Find client providing this communicator */
6079 for (tc = clients_head; NULL != tc; tc = tc->next) 6205 for (tc = clients_head; NULL != tc; tc = tc->next)
@@ -6095,8 +6221,9 @@ handle_backchannel_encapsulation (
6095 } 6221 }
6096 /* Finally, deliver backchannel message to communicator */ 6222 /* Finally, deliver backchannel message to communicator */
6097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6098 "Delivering backchannel message from %s of type %u to %s\n", 6224 "Delivering backchannel message from %s to %s of type %u to %s\n",
6099 GNUNET_i2s (&cmc->im.sender), 6225 sender,
6226 self,
6100 ntohs (inbox->type), 6227 ntohs (inbox->type),
6101 target_communicator); 6228 target_communicator);
6102 env = GNUNET_MQ_msg_extra ( 6229 env = GNUNET_MQ_msg_extra (
@@ -8407,14 +8534,15 @@ fragment_message (struct Queue *queue,
8407 struct PendingMessage *ff; 8534 struct PendingMessage *ff;
8408 uint16_t mtu; 8535 uint16_t mtu;
8409 8536
8410 mtu = (0 == queue->mtu) 8537 mtu = (UINT16_MAX == queue->mtu)
8411 ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo) 8538 ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)
8412 : queue->mtu; 8539 : queue->mtu;
8413 set_pending_message_uuid (pm); 8540 set_pending_message_uuid (pm);
8414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8415 "Fragmenting message %llu <%llu> to %s for MTU %u\n", 8542 "Fragmenting message %llu <%llu> with size %u to %s for MTU %u\n",
8416 (unsigned long long) pm->msg_uuid.uuid, 8543 (unsigned long long) pm->msg_uuid.uuid,
8417 pm->logging_uuid, 8544 pm->logging_uuid,
8545 pm->bytes_msg,
8418 GNUNET_i2s (&pm->vl->target), 8546 GNUNET_i2s (&pm->vl->target),
8419 (unsigned int) mtu); 8547 (unsigned int) mtu);
8420 pa = prepare_pending_acknowledgement (queue, dvh, pm); 8548 pa = prepare_pending_acknowledgement (queue, dvh, pm);
@@ -8700,7 +8828,7 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc,
8700 GNUNET_TRANSPORT_SendMessageTo)) 8828 GNUNET_TRANSPORT_SendMessageTo))
8701 || 8829 ||
8702 (NULL != pos->head_frag /* fragments already exist, should 8830 (NULL != pos->head_frag /* fragments already exist, should
8703 respect that even if MTU is 0 for 8831 respect that even if MTU is UINT16_MAX for
8704 this queue */)) 8832 this queue */))
8705 { 8833 {
8706 frag = GNUNET_YES; 8834 frag = GNUNET_YES;
@@ -9069,12 +9197,17 @@ handle_send_message_ack (void *cls,
9069 qep = qep->next) 9197 qep = qep->next)
9070 { 9198 {
9071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9072 "QueueEntry MID: %llu, Ack MID: %llu\n", 9200 "QueueEntry MID: %llu on queue QID: %llu, Ack MID: %llu\n",
9073 (unsigned long long) qep->mid, 9201 (unsigned long long) qep->mid,
9202 (unsigned long long) queue->qid,
9074 (unsigned long long) sma->mid); 9203 (unsigned long long) sma->mid);
9075 if (qep->mid != sma->mid) 9204 if (qep->mid != sma->mid)
9076 continue; 9205 continue;
9077 qe = qep; 9206 qe = qep;
9207 if ((NULL != qe->pm)&&(qe->pm->qe != qe))
9208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9209 "For pending message %llu we had retransmissions.\n",
9210 qe->pm->logging_uuid);
9078 break; 9211 break;
9079 } 9212 }
9080 } 9213 }
@@ -9125,12 +9258,26 @@ handle_send_message_ack (void *cls,
9125 GNUNET_NO); 9258 GNUNET_NO);
9126 schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 9259 schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9127 } 9260 }
9261 else if (1 == qe->queue->q_capacity)
9262 {
9263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9264 "Transmission rescheduled due to communicator message queue with qid %u has capacity %lu.\n",
9265 qe->queue->qid,
9266 qe->queue->q_capacity);
9267 /* message queue has capacity; only resume this one queue */
9268 /* queue dropped below threshold; only resume this one queue */
9269 GNUNET_STATISTICS_update (GST_stats,
9270 "# Transmission throttled due to message queue capacity",
9271 -1,
9272 GNUNET_NO);
9273 schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9274 }
9128 9275
9129 if (NULL != (pm = qe->pm)) 9276 if (NULL != (pm = qe->pm))
9130 { 9277 {
9131 struct VirtualLink *vl; 9278 struct VirtualLink *vl;
9132 9279
9133 GNUNET_assert (qe == pm->qe); 9280 // GNUNET_assert (qe == pm->qe);
9134 pm->qe = NULL; 9281 pm->qe = NULL;
9135 /* If waiting for this communicator may have blocked transmission 9282 /* If waiting for this communicator may have blocked transmission
9136 of pm on other queues for this neighbour, force schedule 9283 of pm on other queues for this neighbour, force schedule
@@ -9671,16 +9818,20 @@ handle_add_queue_message (void *cls,
9671 addr_len = ntohs (aqm->header.size) - sizeof(*aqm); 9818 addr_len = ntohs (aqm->header.size) - sizeof(*aqm);
9672 addr = (const char *) &aqm[1]; 9819 addr = (const char *) &aqm[1];
9673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9674 "New queue %s to %s available with QID %llu\n", 9821 "New queue %s to %s available with QID %llu and q_len %lu \n",
9675 addr, 9822 addr,
9676 GNUNET_i2s (&aqm->receiver), 9823 GNUNET_i2s (&aqm->receiver),
9677 (unsigned long long) aqm->qid); 9824 (unsigned long long) aqm->qid,
9825 GNUNET_ntohll (aqm->q_len));
9678 queue = GNUNET_malloc (sizeof(struct Queue) + addr_len); 9826 queue = GNUNET_malloc (sizeof(struct Queue) + addr_len);
9679 queue->tc = tc; 9827 queue->tc = tc;
9680 queue->address = (const char *) &queue[1]; 9828 queue->address = (const char *) &queue[1];
9681 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL; 9829 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL;
9682 queue->qid = aqm->qid; 9830 queue->qid = aqm->qid;
9683 queue->neighbour = neighbour; 9831 queue->neighbour = neighbour;
9832 if (GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED == GNUNET_ntohll (aqm->q_len))
9833 queue->unlimited_length = GNUNET_YES;
9834 queue->q_capacity = GNUNET_ntohll (aqm->q_len);
9684 memcpy (&queue[1], addr, addr_len); 9835 memcpy (&queue[1], addr, addr_len);
9685 /* notify monitors about new queue */ 9836 /* notify monitors about new queue */
9686 { 9837 {
@@ -9752,10 +9903,14 @@ handle_update_queue_message (void *cls,
9752 target_queue->mtu = ntohl (msg->mtu); 9903 target_queue->mtu = ntohl (msg->mtu);
9753 target_queue->cs = msg->cs; 9904 target_queue->cs = msg->cs;
9754 target_queue->priority = ntohl (msg->priority); 9905 target_queue->priority = ntohl (msg->priority);
9755 /* The update message indicates how many _additional_ 9906 /* The update message indicates how many messages
9756 * messages the queue should be able to handle 9907 * the queue should be able to handle.
9757 */ 9908 */
9758 target_queue->queue_length += GNUNET_ntohll (msg->q_len); 9909 if (GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED == GNUNET_ntohll (msg->q_len))
9910 target_queue->unlimited_length = GNUNET_YES;
9911 else
9912 target_queue->unlimited_length = GNUNET_NO;
9913 target_queue->q_capacity = GNUNET_ntohll (msg->q_len);
9759 GNUNET_SERVICE_client_continue (tc->client); 9914 GNUNET_SERVICE_client_continue (tc->client);
9760} 9915}
9761 9916
@@ -10179,8 +10334,18 @@ static void
10179shutdown_task (void *cls) 10334shutdown_task (void *cls)
10180{ 10335{
10181 in_shutdown = GNUNET_YES; 10336 in_shutdown = GNUNET_YES;
10337
10182 if (NULL == clients_head) 10338 if (NULL == clients_head)
10183 do_shutdown (cls); 10339 {
10340 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
10341 {
10342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
10343 "client still connected: %u\n",
10344 tc->type);
10345 }
10346 }
10347 do_shutdown (cls);
10348
10184} 10349}
10185 10350
10186 10351
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 07255a1a5..b578219ca 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -180,7 +180,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
180 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 180 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
181 "system-create"), 181 "system-create"),
182 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", 182 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
183 write_message) 183 write_message),
184 GNUNET_TESTING_cmd_end_without_shutdown ()
184 }; 185 };
185 186
186 GNUNET_TESTING_run (NULL, 187 GNUNET_TESTING_run (NULL,
@@ -201,6 +202,10 @@ libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
201{ 202{
202 struct GNUNET_TESTING_PluginFunctions *api; 203 struct GNUNET_TESTING_PluginFunctions *api;
203 204
205 GNUNET_log_setup ("simple-send",
206 "DEBUG",
207 NULL);
208
204 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); 209 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
205 api->start_testcase = &start_testcase; 210 api->start_testcase = &start_testcase;
206 api->all_peers_started = &all_peers_started; 211 api->all_peers_started = &all_peers_started;
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_v2.c b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
index c79b5c7e2..acfe784d6 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send_v2.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
@@ -185,7 +185,8 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
185 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 185 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
186 "system-create"), 186 "system-create"),
187 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", 187 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
188 write_message) 188 write_message),
189 GNUNET_TESTING_cmd_end_without_shutdown ()
189 }; 190 };
190 191
191 GNUNET_TESTING_run (NULL, 192 GNUNET_TESTING_run (NULL,
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index 90e474aea..e2e0b258b 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -58,6 +58,12 @@ char *cfgname;
58unsigned int are_all_peers_started; 58unsigned int are_all_peers_started;
59 59
60/** 60/**
61 * Flag indicating if all local tests are prepared to finish.
62 *
63 */
64unsigned int are_all_local_tests_prepared;
65
66/**
61 * Flag indicating a received message. 67 * Flag indicating a received message.
62 */ 68 */
63unsigned int message_received; 69unsigned int message_received;
@@ -85,6 +91,8 @@ static void
85handle_test (void *cls, 91handle_test (void *cls,
86 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 92 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
87{ 93{
94 LOG (GNUNET_ERROR_TYPE_DEBUG,
95 "Message received.\n");
88 message_received = GNUNET_YES; 96 message_received = GNUNET_YES;
89} 97}
90 98
@@ -104,6 +112,16 @@ all_peers_started ()
104 112
105 113
106/** 114/**
115 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
116 */
117static void
118all_local_tests_prepared ()
119{
120 are_all_local_tests_prepared = GNUNET_YES;
121}
122
123
124/**
107 * Function to start a local test case. 125 * Function to start a local test case.
108 * 126 *
109 * @param write_message Callback to send a message to the master loop. 127 * @param write_message Callback to send a message to the master loop.
@@ -179,17 +197,23 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
179 "system-create", 197 "system-create",
180 num, 198 num,
181 topology), 199 topology),
182 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple", 200 GNUNET_TRANSPORT_cmd_backchannel_check ("backchannel-check",
183 "start-peer", 201 "start-peer",
184 num), 202 "system-create",
185 GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive", 203 num,
186 &message_received), 204 m_int,
205 n_int,
206 topology),
207 GNUNET_TESTING_cmd_local_test_prepared ("local-test-prepared",
208 write_message,
209 &are_all_local_tests_prepared),
187 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", 210 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
188 "start-peer"), 211 "start-peer"),
189 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 212 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
190 "system-create"), 213 "system-create"),
191 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished", 214 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
192 write_message) 215 write_message),
216 GNUNET_TESTING_cmd_end_without_shutdown ()
193 }; 217 };
194 218
195 GNUNET_TESTING_run (NULL, 219 GNUNET_TESTING_run (NULL,
@@ -217,6 +241,7 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_init (void *cls)
217 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); 241 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
218 api->start_testcase = &start_testcase; 242 api->start_testcase = &start_testcase;
219 api->all_peers_started = &all_peers_started; 243 api->all_peers_started = &all_peers_started;
244 api->all_local_tests_prepared = all_local_tests_prepared;
220 return api; 245 return api;
221} 246}
222 247
diff --git a/src/transport/test_transport_udp_backchannel.sh b/src/transport/test_transport_udp_backchannel.sh
index 3322e5853..0c37be469 100755
--- a/src/transport/test_transport_udp_backchannel.sh
+++ b/src/transport/test_transport_udp_backchannel.sh
@@ -1,2 +1,4 @@
1#!/bin/bash 1#!/bin/bash
2#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"
2exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf" 3exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf"
4# 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"
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index ecdabd35f..67e5723f5 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -228,22 +228,36 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
228 struct GNUNET_MQ_MessageHandler *handlers, 228 struct GNUNET_MQ_MessageHandler *handlers,
229 const char *cfgname); 229 const char *cfgname);
230 230
231
231struct GNUNET_TESTING_Command 232struct GNUNET_TESTING_Command
232GNUNET_TRANSPORT_cmd_stop_peer (const char *label, 233GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
233 const char *start_label); 234 const char *start_label);
234 235
236
235struct GNUNET_TESTING_Command 237struct GNUNET_TESTING_Command
236GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 238GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
237 const char *start_peer_label, 239 const char *start_peer_label,
238 const char *create_label, 240 const char *create_label,
239 uint32_t num); 241 uint32_t num);
240 242
243
241struct GNUNET_TESTING_Command 244struct GNUNET_TESTING_Command
242GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label, 245GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
243 const char *start_peer_label, 246 const char *start_peer_label,
244 const char *create_label, 247 const char *create_label,
245 uint32_t num); 248 uint32_t num);
246 249
250
251/**
252 * Create command.
253 *
254 * @param label name for command.
255 * @param start_peer_label Label of the cmd to start a peer.
256 * @param create_label Label of the cmd to create the testing system.
257 * @param num Number globally identifying the node.
258 * @param The topology for the test setup.
259 * @return command.
260 */
247struct GNUNET_TESTING_Command 261struct GNUNET_TESTING_Command
248GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label, 262GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
249 const char *start_peer_label, 263 const char *start_peer_label,
@@ -252,6 +266,40 @@ GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
252 struct GNUNET_TESTING_NetjailTopology * 266 struct GNUNET_TESTING_NetjailTopology *
253 topology); 267 topology);
254 268
269
270/**
271 * Create command.
272 *
273 * @param label name for command.
274 * @param start_peer_label Label of the cmd to start a peer.
275 * @param create_label Label of the cmd to create the testing system.
276 * @param num Number globally identifying the node.
277 * @param node_n The number of the node in a network namespace.
278 * @param namespace_n The number of the network namespace.
279 * @param The topology for the test setup.
280 * @return command.
281 */
282struct GNUNET_TESTING_Command
283GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
284 const char *start_peer_label,
285 const char *create_label,
286 uint32_t num,
287 unsigned int node_n,
288 unsigned int namespace_n,
289 struct GNUNET_TESTING_NetjailTopology *
290 topology);
291
292
293/**
294 * Create command.
295 *
296 * @param label name for command.
297 * @param m The number of the local node of the actual network namespace.
298 * @param n The number of the actual namespace.
299 * @param num Number globally identifying the node.
300 * @param start_peer_label Label of the cmd to start a peer.
301 * @return command.
302 */
255struct GNUNET_TESTING_Command 303struct GNUNET_TESTING_Command
256GNUNET_TRANSPORT_cmd_send_simple (const char *label, 304GNUNET_TRANSPORT_cmd_send_simple (const char *label,
257 char *m, 305 char *m,
@@ -263,10 +311,8 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
263 * Create command. 311 * Create command.
264 * 312 *
265 * @param label name for command. 313 * @param label name for command.
266 * @param m The number of the local node of the actual network namespace.
267 * @param n The number of the actual namespace.
268 * @param num Number globally identifying the node.
269 * @param start_peer_label Label of the cmd to start a peer. 314 * @param start_peer_label Label of the cmd to start a peer.
315 * @param num Number globally identifying the node.
270 * @return command. 316 * @return command.
271 */ 317 */
272struct GNUNET_TESTING_Command 318struct GNUNET_TESTING_Command
@@ -274,6 +320,26 @@ GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label,
274 const char *start_peer_label, 320 const char *start_peer_label,
275 uint32_t num); 321 uint32_t num);
276 322
323
324/**
325 * Create command.
326 *
327 * @param label name for command.
328 * @param start_peer_label Label of the cmd to start a peer.
329 * @param start_peer_label Label of the cmd which started the test system.
330 * @param num Number globally identifying the node.
331 * @param The topology for the test setup.
332 * @return command.
333 */
334struct GNUNET_TESTING_Command
335GNUNET_TRANSPORT_cmd_send_simple_v3 (const char *label,
336 const char *start_peer_label,
337 const char *create_label,
338 uint32_t num,
339 struct GNUNET_TESTING_NetjailTopology *
340 topology);
341
342
277int 343int
278GNUNET_TRANSPORT_get_trait_peer_id (const struct 344GNUNET_TRANSPORT_get_trait_peer_id (const struct
279 GNUNET_TESTING_Command *cmd, 345 GNUNET_TESTING_Command *cmd,
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c
index 446add6f6..2a80db87b 100644
--- a/src/transport/transport_api2_communication.c
+++ b/src/transport/transport_api2_communication.c
@@ -904,6 +904,10 @@ GNUNET_TRANSPORT_communicator_receive (
904 struct GNUNET_TRANSPORT_IncomingMessage *im; 904 struct GNUNET_TRANSPORT_IncomingMessage *im;
905 uint16_t msize; 905 uint16_t msize;
906 906
907
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "communicator receive\n");
910
907 if (NULL == ch->mq) 911 if (NULL == ch->mq)
908 return GNUNET_SYSERR; 912 return GNUNET_SYSERR;
909 if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length)) 913 if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length))
@@ -986,6 +990,9 @@ GNUNET_TRANSPORT_communicator_mq_add (
986{ 990{
987 struct GNUNET_TRANSPORT_QueueHandle *qh; 991 struct GNUNET_TRANSPORT_QueueHandle *qh;
988 992
993 // Do not notify the service if there is no intial capacity.
994 GNUNET_assert (0 < q_len);
995
989 qh = GNUNET_new (struct GNUNET_TRANSPORT_QueueHandle); 996 qh = GNUNET_new (struct GNUNET_TRANSPORT_QueueHandle);
990 qh->ch = ch; 997 qh->ch = ch;
991 qh->peer = *peer; 998 qh->peer = *peer;
@@ -1106,7 +1113,7 @@ GNUNET_TRANSPORT_communicator_address_remove (
1106 */ 1113 */
1107void 1114void
1108GNUNET_TRANSPORT_communicator_address_remove_all ( 1115GNUNET_TRANSPORT_communicator_address_remove_all (
1109 struct GNUNET_TRANSPORT_CommunicatorHandle *ch) 1116 struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
1110{ 1117{
1111 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai; 1118 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai;
1112 ai = ai->next) 1119 ai = ai->next)
diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c
new file mode 100644
index 000000000..da44e91ca
--- /dev/null
+++ b/src/transport/transport_api_cmd_backchannel_check.c
@@ -0,0 +1,628 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_backchannel_check.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_common.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_transport_application_service.h"
31#include "gnunet_hello_lib.h"
32#include "gnunet_transport_service.h"
33#include "transport-testing-cmds.h"
34
35/**
36 * Generic logging shortcut
37 */
38#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
39
40#define UDP "udp"
41
42/**
43 * Maximum length allowed for line input.
44 */
45#define MAX_LINE_LENGTH 1024
46
47/**
48 * Struct to store information needed in callbacks.
49 *
50 */
51struct CheckState
52{
53 /**
54 * The number of the node in a network namespace.
55 */
56 unsigned int node_n;
57
58 /**
59 * The number of the network namespace.
60 */
61 unsigned int namespace_n;
62
63 /**
64 * The testing system of this node.
65 */
66 struct GNUNET_TESTING_System *tl_system;
67
68 // Label of the cmd which started the test system.
69 const char *create_label;
70
71 /**
72 * Number globally identifying the node.
73 *
74 */
75 uint32_t num;
76
77 /**
78 * Label of the cmd to start a peer.
79 *
80 */
81 const char *start_peer_label;
82
83 /**
84 * The topology of the test setup.
85 */
86 struct GNUNET_TESTING_NetjailTopology *topology;
87
88 /**
89 * Connections to other peers.
90 */
91 struct GNUNET_TESTING_NodeConnection *node_connections_head;
92
93 /**
94 * Number of connections.
95 */
96 unsigned int con_num;
97
98 /**
99 * Number of received backchannel messages.
100 */
101 unsigned int received_backchannel_msgs;
102
103 /**
104 * Array with search strings.
105 */
106 char **search_string;
107
108 /**
109 * File handle for log file.
110 */
111 struct GNUNET_DISK_FileHandle *fh;
112
113 /**
114 * Task which handles the reading
115 */
116 struct GNUNET_SCHEDULER_Task *task;
117
118 /**
119 * Stream to read log file lines.
120 */
121 FILE *stream;
122
123 /**
124 * Did we get all bachchannel messages.
125 */
126 enum GNUNET_GenericReturnValue finished;
127};
128
129/**
130 *
131 * @param cls The cmd state CheckState.
132 */
133static void
134read_from_log (void *cls)
135{
136 struct CheckState *cs = cls;
137 char line[MAX_LINE_LENGTH + 1];
138 char *search_string;
139
140
141 LOG (GNUNET_ERROR_TYPE_DEBUG,
142 "read_from_log\n");
143
144 cs->fh = GNUNET_DISK_file_open ("test.out",
145 GNUNET_DISK_OPEN_READ,
146 GNUNET_DISK_PERM_USER_READ);
147
148 cs->task = NULL;
149
150 /* read message from line and handle it */
151 cs->stream = fdopen (cs->fh->fd, "r");
152 memset (line, 0, MAX_LINE_LENGTH + 1);
153
154 // fgets (line, MAX_LINE_LENGTH, cs->stream);
155 // while (NULL != line && 0 != strcmp (line, ""))// '\0' != line[0])
156 while (NULL != fgets (line, MAX_LINE_LENGTH, cs->stream))
157 {
158 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
159 "cs->received_backchannel_msgs: %u\n",
160 cs->received_backchannel_msgs);*/
161 /*if (NULL == strstr (line, "line"))
162 LOG (GNUNET_ERROR_TYPE_DEBUG,
163 "line: %s",
164 line);*/
165
166
167 for (int i = 0; i < cs->con_num; i++)
168 {
169 search_string = cs->search_string[i];
170 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
171 "search %u %u: %s %p\n",
172 i,
173 cs->con_num,
174 cs->search_string[i],
175 cs->search_string);
176 fprintf (stderr,
177 line);*/
178 if (NULL != strstr (line,
179 search_string))
180 // "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"))
181 // cs->search_string[i]))
182 {
183 cs->received_backchannel_msgs++;
184 LOG (GNUNET_ERROR_TYPE_DEBUG,
185 "received_backchannel_msgs %u con_num %u\n",
186 cs->received_backchannel_msgs,
187 cs->con_num);
188 if (cs->received_backchannel_msgs == cs->con_num)
189 {
190 LOG (GNUNET_ERROR_TYPE_DEBUG,
191 "search finished %lu %lu %u\n",
192 strlen (cs->search_string[i]),
193 strlen (
194 "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"),
195 strcmp (
196 "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp",
197 cs->search_string[i]));
198 if (NULL != strstr (line,
199 cs->search_string[i]))
200 {
201 LOG (GNUNET_ERROR_TYPE_DEBUG,
202 "gaga\n");
203 }
204 cs->finished = GNUNET_YES;
205 fclose (cs->stream);
206 return;
207 }
208 }
209 }
210 }
211 LOG (GNUNET_ERROR_TYPE_DEBUG,
212 "read_from_log end\n");
213 fclose (cs->stream);
214 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
215 &read_from_log,
216 cs);
217 /*if (NULL == fgets (line, MAX_LINE_LENGTH, cs->stream))
218 {
219 LOG (GNUNET_ERROR_TYPE_DEBUG,
220 "read null\n");
221 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
222 &read_from_log,
223 cs);
224 return;
225 }*/
226 /*else {
227 cs->task =
228 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
229 cs->fh,
230 &read_from_log,
231 cs);
232
233
234 }*/
235}
236
237
238static enum GNUNET_GenericReturnValue
239will_the_other_node_connect_via_udp (
240 struct CheckState *cs,
241 const struct GNUNET_TESTING_NetjailNode *node)
242// struct GNUNET_TESTING_NodeConnection *connection)
243{
244 // struct GNUNET_TESTING_NetjailTopology *topology = cs->topology;
245 // unsigned int node_n = connection->node_n;
246 // unsigned int namespace_n = connection->namespace_n;
247 // struct GNUNET_HashCode hc;
248 // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
249 // struct GNUNET_HashCode hc_namespace;
250 /*struct GNUNET_ShortHashCode *key_namespace = GNUNET_new (struct
251 GNUNET_ShortHashCode);*/
252 // struct GNUNET_TESTING_NetjailNode *node;
253 struct GNUNET_TESTING_NodeConnection *pos_connection;
254 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
255 // struct GNUNET_TESTING_NetjailNamespace *namespace;
256 // struct GNUNET_CONTAINER_MultiShortmap *map;
257
258 /* if (0 == connection->namespace_n) */
259 /* { */
260 /* map = topology->map_globals; */
261 /* } */
262 /* else */
263 /* { */
264 /* GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc_namespace); */
265 /* memcpy (key_namespace, */
266 /* &hc_namespace, */
267 /* sizeof (*key_namespace)); */
268 /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
269 /* topology->map_namespaces, */
270 /* key_namespace)) */
271 /* { */
272 /* namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces, */
273 /* key_namespace); */
274 /* map = namespace->nodes; */
275 /* } */
276 /* else */
277 /* GNUNET_assert (0); */
278 /* } */
279
280 /* GNUNET_CRYPTO_hash (&node_n, sizeof(node_n), &hc); */
281 /* memcpy (key, */
282 /* &hc, */
283 /* sizeof (*key)); */
284 /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
285 /* map, */
286 /* key)) */
287 /* { */
288 /* node = GNUNET_CONTAINER_multishortmap_get (cs->topology->map_globals, */
289 /* key); */
290 /* for (pos_connection = node->node_connections_head; NULL != pos_connection; */
291 /* pos_connection = pos_connection->next) */
292 /* { */
293 /* if ((node->namespace_n == pos_connection->namespace_n) && */
294 /* (node->node_n == pos_connection->node_n) ) */
295 /* { */
296 /* for (pos_prefix = pos_connection->address_prefixes_head; NULL != */
297 /* pos_prefix; */
298 /* pos_prefix = */
299 /* pos_prefix->next) */
300 /* { */
301 /* if (0 == strcmp (UDP, pos_prefix->address_prefix)) */
302 /* { */
303 /* return GNUNET_YES; */
304 /* } */
305 /* } */
306 /* } */
307 /* } */
308 /* } */
309
310 for (pos_connection = node->node_connections_head; NULL != pos_connection;
311 pos_connection = pos_connection->next)
312 {
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
314 "connect via udp %u %u %u %u\n",
315 node->namespace_n,
316 cs->namespace_n,
317 node->node_n,
318 cs->node_n);
319 if ((pos_connection->namespace_n == cs->namespace_n) &&
320 (pos_connection->node_n == cs->node_n) )
321 {
322 for (pos_prefix = pos_connection->address_prefixes_head; NULL !=
323 pos_prefix;
324 pos_prefix =
325 pos_prefix->next)
326 {
327 if (0 == strcmp (UDP, pos_prefix->address_prefix))
328 {
329 return GNUNET_YES;
330 }
331 }
332 }
333 }
334
335 return GNUNET_NO;
336}
337
338static void
339add_search_string (struct CheckState *cs, const struct
340 GNUNET_TESTING_NetjailNode *node)
341{
342 unsigned int num;
343 struct GNUNET_PeerIdentity *peer;
344 struct GNUNET_PeerIdentity *us;
345 char *buf;
346 char *part_one = "Delivering backchannel message from ";
347 char *part_two = " to ";
348 char *part_three = " of type 1460 to udp";
349 char *peer_id;
350 char *us_id;
351
352 if (0 == node->namespace_n)
353 num = node->node_n;
354 else
355 num = (node->namespace_n - 1) * cs->topology->nodes_m + node->node_n
356 + cs->topology->nodes_x;
357
358 // num = GNUNET_TESTING_calculate_num (pos_connection, cs->topology);
359 peer = GNUNET_TESTING_get_pub_key (num, cs->tl_system);
360 LOG (GNUNET_ERROR_TYPE_DEBUG,
361 "peer: %s num %u\n",
362 GNUNET_i2s (peer),
363 num);
364 us = GNUNET_TESTING_get_pub_key (cs->num, cs->tl_system);
365 LOG (GNUNET_ERROR_TYPE_DEBUG,
366 "us: %s cs->num %d\n",
367 GNUNET_i2s (us),
368 cs->num);
369
370 GNUNET_asprintf (&peer_id,
371 "%s",
372 GNUNET_i2s (peer));
373 GNUNET_asprintf (&us_id,
374 "%s",
375 GNUNET_i2s (us));
376
377 if (0 < GNUNET_asprintf (&buf,
378 "%s%s%s%s%s",
379 part_one,
380 us_id,
381 part_two,
382 peer_id,
383 part_three))
384 {
385 GNUNET_array_append (cs->search_string,
386 cs->con_num,
387 buf);
388 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
389 "con_num: %u search: %s %p\n",
390 cs->con_num,
391 cs->search_string[cs->con_num - 1],
392 cs->search_string);*/
393 }
394 else
395 GNUNET_assert (0);
396}
397
398
399/**
400 * The run method of this cmd will connect to peers.
401 *
402 */
403static void
404backchannel_check_run (void *cls,
405 const struct GNUNET_TESTING_Command *cmd,
406 struct GNUNET_TESTING_Interpreter *is)
407{
408 struct CheckState *cs = cls;
409 // char *buf;
410 // char *part_one = "Delivering backchannel message from ";
411 // char *part_two = " of type 1460 to udp";
412 const struct GNUNET_TESTING_Command *system_cmd;
413 struct GNUNET_TESTING_System *tl_system;
414 const struct GNUNET_TESTING_Command *peer1_cmd;
415 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
416 // struct GNUNET_PeerIdentity *peer;
417 // uint32_t num;
418 // struct GNUNET_TESTING_NodeConnection *pos_connection;
419 // unsigned int con_num = 0;
420 struct GNUNET_CONTAINER_MultiShortmapIterator *node_it;
421 struct GNUNET_CONTAINER_MultiShortmapIterator *namespace_it;
422 struct GNUNET_ShortHashCode node_key;
423 struct GNUNET_ShortHashCode namespace_key;
424 const struct GNUNET_TESTING_NetjailNode *node;
425 const struct GNUNET_TESTING_NetjailNamespace *namespace;
426
427 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (
428 cs->start_peer_label);
429 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
430 &ah);
431
432 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cs->create_label);
433 GNUNET_TESTING_get_trait_test_system (system_cmd,
434 &tl_system);
435
436 cs->tl_system = tl_system;
437
438 cs->node_connections_head = GNUNET_TESTING_get_connections (cs->num,
439 cs->topology);
440
441 LOG (GNUNET_ERROR_TYPE_DEBUG,
442 "check run\n");
443
444
445 node_it = GNUNET_CONTAINER_multishortmap_iterator_create (
446 cs->topology->map_globals);
447
448 while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it,
449 &node_key,
450 (const
451 void**) &
452 node))
453 {
454 LOG (GNUNET_ERROR_TYPE_DEBUG,
455 "namespace_n %u node_n %u\n",
456 node->namespace_n,
457 node->node_n);
458 if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node))
459 {
460 add_search_string (cs, node);
461 }
462 }
463 namespace_it = GNUNET_CONTAINER_multishortmap_iterator_create (
464 cs->topology->map_namespaces);
465 while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (
466 namespace_it,
467 &namespace_key,
468 (const
469 void**) &namespace))
470 {
471 LOG (GNUNET_ERROR_TYPE_DEBUG,
472 "namespace_n %u\n",
473 node->namespace_n);
474 node_it = GNUNET_CONTAINER_multishortmap_iterator_create (
475 namespace->nodes);
476 while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it,
477 &node_key,
478 (const
479 void**)
480 &node))
481 {
482 LOG (GNUNET_ERROR_TYPE_DEBUG,
483 "namespace_n %u node_n %u\n",
484 node->namespace_n,
485 node->node_n);
486 if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node))
487 {
488 add_search_string (cs, node);
489 }
490 }
491 }
492 /* for (pos_connection = cs->node_connections_head; NULL != pos_connection; */
493 /* pos_connection = pos_connection->next) */
494 /* { */
495
496 /* if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node)) */
497 /* { */
498 /* num = GNUNET_TESTING_calculate_num (pos_connection, cs->topology); */
499 /* peer = GNUNET_TESTING_get_pub_key (num, tl_system); */
500 /* LOG (GNUNET_ERROR_TYPE_DEBUG, */
501 /* "peer: %s\n", */
502 /* GNUNET_i2s (peer)); */
503
504 /* if (0 < GNUNET_asprintf (&buf, */
505 /* "%s%s%s", */
506 /* part_one, */
507 /* GNUNET_i2s (peer), */
508 /* part_two)) */
509 /* { */
510 /* GNUNET_array_append (cs->search_string, */
511 /* con_num, */
512 /* buf); */
513 /* /\*LOG (GNUNET_ERROR_TYPE_DEBUG, */
514 /* "con_num: %u search: %s %p\n", */
515 /* con_num, */
516 /* cs->search_string[con_num - 1], */
517 /* cs->search_string);*\/ */
518 /* } */
519 /* else */
520 /* GNUNET_assert (0); */
521 /* } */
522
523
524 /* } */
525 // cs->con_num = con_num;
526 if (0 != cs->con_num)
527 {
528 cs->task =
529 GNUNET_SCHEDULER_add_now (&read_from_log,
530 cs);
531 }
532 else
533 cs->finished = GNUNET_YES;
534
535}
536
537
538/**
539 * The finish function of this cmd will check if the peers we are trying to
540 * connect to are in the connected peers map of the start peer cmd for this peer.
541 *
542 */
543static int
544backchannel_check_finish (void *cls,
545 GNUNET_SCHEDULER_TaskCallback cont,
546 void *cont_cls)
547{
548 struct CheckState *cs = cls;
549
550 if (cs->finished)
551 {
552 cont (cont_cls);
553 }
554 return cs->finished;
555}
556
557
558/**
559 * Trait function of this cmd does nothing.
560 *
561 */
562static int
563backchannel_check_traits (void *cls,
564 const void **ret,
565 const char *trait,
566 unsigned int index)
567{
568 return GNUNET_OK;
569}
570
571
572/**
573 * The cleanup function of this cmd frees resources the cmd allocated.
574 *
575 */
576static void
577backchannel_check_cleanup (void *cls,
578 const struct GNUNET_TESTING_Command *cmd)
579{
580 struct ConnectPeersState *cs = cls;
581
582 GNUNET_free (cs);
583}
584
585
586/**
587 * Create command.
588 *
589 * @param label name for command.
590 * @param start_peer_label Label of the cmd to start a peer.
591 * @param create_label Label of the cmd to create the testing system.
592 * @param num Number globally identifying the node.
593 * @param node_n The number of the node in a network namespace.
594 * @param namespace_n The number of the network namespace.
595 * @param The topology for the test setup.
596 * @return command.
597 */
598struct GNUNET_TESTING_Command
599GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
600 const char *start_peer_label,
601 const char *create_label,
602 uint32_t num,
603 unsigned int node_n,
604 unsigned int namespace_n,
605 struct GNUNET_TESTING_NetjailTopology *
606 topology)
607{
608 struct CheckState *cs;
609
610 cs = GNUNET_new (struct CheckState);
611 cs->start_peer_label = start_peer_label;
612 cs->num = num;
613 cs->create_label = create_label;
614 cs->topology = topology;
615 cs->node_n = node_n;
616 cs->namespace_n = namespace_n;
617
618 struct GNUNET_TESTING_Command cmd = {
619 .cls = cs,
620 .label = label,
621 .run = &backchannel_check_run,
622 .finish = &backchannel_check_finish,
623 .cleanup = &backchannel_check_cleanup,
624 .traits = &backchannel_check_traits
625 };
626
627 return cmd;
628}
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 09ca9e54c..39c7db450 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -91,7 +91,7 @@ connect_peers_run (void *cls,
91 char *hello; 91 char *hello;
92 // size_t *hello_size; 92 // size_t *hello_size;
93 enum GNUNET_NetworkType nt = 0; 93 enum GNUNET_NetworkType nt = 0;
94 char *peer_id; 94 // char *peer_id;
95 struct GNUNET_PeerIdentity *id; 95 struct GNUNET_PeerIdentity *id;
96 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity); 96 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
97 uint32_t num; 97 uint32_t num;
@@ -122,12 +122,12 @@ connect_peers_run (void *cls,
122 if (2 == num) 122 if (2 == num)
123 { 123 {
124 addr = "tcp-192.168.15.2:60002"; 124 addr = "tcp-192.168.15.2:60002";
125 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG"; 125 // peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
126 } 126 }
127 else 127 else
128 { 128 {
129 addr = "tcp-192.168.15.1:60002"; 129 addr = "tcp-192.168.15.1:60002";
130 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730"; 130 // peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
131 } 131 }
132 132
133 priv_key = GNUNET_TESTING_hostkey_get (tl_system, 133 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
@@ -137,16 +137,16 @@ connect_peers_run (void *cls,
137 GNUNET_CRYPTO_eddsa_key_get_public (priv_key, 137 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
138 pub_key); 138 pub_key);
139 139
140 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, 140 /*GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
141 strlen (peer_id), 141 strlen (peer_id),
142 &peer->public_key); 142 &peer->public_key);*/
143 143
144 peer->public_key = *pub_key; 144 peer->public_key = *pub_key;
145 145
146 LOG (GNUNET_ERROR_TYPE_ERROR, 146 LOG (GNUNET_ERROR_TYPE_ERROR,
147 "\nnum: %u\n peer_id: %s\n pub_key %s\n", 147 "num: %u id: %s pub_key %s\n",
148 num, 148 num,
149 peer_id, 149 GNUNET_i2s_full (id),
150 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key)); 150 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
151 151
152 cps->id = peer; 152 cps->id = peer;
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c
index e90781637..2273d9852 100644
--- a/src/transport/transport_api_cmd_connecting_peers_v3.c
+++ b/src/transport/transport_api_cmd_connecting_peers_v3.c
@@ -36,22 +36,6 @@
36 */ 36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38 38
39#define CONNECT_ADDRESS_TEMPLATE_TCP "tcp-192.168.15.%u:60002"
40
41#define CONNECT_ADDRESS_TEMPLATE_UDP "udp-192.168.15.%u:60002"
42
43#define ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.150.%u:60002"
44
45#define ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.150.%u:60002"
46
47#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.151.%u:60002"
48
49#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.151.%u:60002"
50
51#define PREFIX_TCP "tcp"
52
53#define PREFIX_UDP "udp"
54
55/** 39/**
56 * Struct to store information needed in callbacks. 40 * Struct to store information needed in callbacks.
57 * 41 *
@@ -101,222 +85,6 @@ struct ConnectPeersState
101}; 85};
102 86
103 87
104static struct GNUNET_PeerIdentity *
105get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
106{
107 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
108 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
109 GNUNET_CRYPTO_EddsaPublicKey);
110 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
111 GNUNET_CRYPTO_EddsaPrivateKey);
112
113 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
114 num,
115 peer);
116
117 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
118 pub_key);
119 peer->public_key = *pub_key;
120 return peer;
121}
122
123
124static int
125log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
126{
127 struct GNUNET_TESTING_NetjailNode *node = value;
128 struct GNUNET_TESTING_NodeConnection *pos_connection;
129 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
130
131 LOG (GNUNET_ERROR_TYPE_ERROR,
132 "plugin: %s space: %u node: %u global: %u\n",
133 node->plugin,
134 node->namespace_n,
135 node->node_n,
136 node->is_global);
137
138 for (pos_connection = node->node_connections_head; NULL != pos_connection;
139 pos_connection = pos_connection->next)
140 {
141
142 LOG (GNUNET_ERROR_TYPE_ERROR,
143 "namespace_n: %u node_n: %u node_type: %u\n",
144 pos_connection->namespace_n,
145 pos_connection->node_n,
146 pos_connection->node_type);
147
148 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
149 pos_prefix =
150 pos_prefix->next)
151 {
152 LOG (GNUNET_ERROR_TYPE_ERROR,
153 "prefix: %s\n",
154 pos_prefix->address_prefix);
155 }
156 }
157 return GNUNET_YES;
158}
159
160
161static int
162log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
163{
164 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
165 struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
166
167 LOG (GNUNET_ERROR_TYPE_ERROR,
168 "router_tcp: %u router_udp: %u spaces: %u\n",
169 router->tcp_port,
170 router->udp_port,
171 namespace->namespace_n);
172 GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
173 return GNUNET_YES;
174}
175
176
177static int
178log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
179{
180 LOG (GNUNET_ERROR_TYPE_ERROR,
181 "plugin: %s spaces: %u nodes: %u known: %u\n",
182 topology->plugin,
183 topology->namespaces_n,
184 topology->nodes_m,
185 topology->nodes_x);
186
187 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
188 log_namespaces, NULL);
189 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
190 NULL);
191 return GNUNET_YES;
192}
193
194
195static struct GNUNET_TESTING_NodeConnection *
196get_connections (unsigned int num, struct
197 GNUNET_TESTING_NetjailTopology *topology)
198{
199 struct GNUNET_TESTING_NetjailNode *node;
200 struct GNUNET_ShortHashCode *hkey;
201 struct GNUNET_HashCode hc;
202 struct GNUNET_TESTING_NetjailNamespace *namespace;
203 unsigned int namespace_n, node_m;
204
205 log_topo (topology);
206
207 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
208 if (topology->nodes_x >= num)
209 {
210
211 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
212 memcpy (hkey,
213 &hc,
214 sizeof (*hkey));
215 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
216 hkey);
217 }
218 else
219 {
220 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
221 / topology->nodes_m);
222 LOG (GNUNET_ERROR_TYPE_ERROR,
223 "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
224 num,
225 topology->nodes_x,
226 topology->nodes_m,
227 namespace_n);
228 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
229 GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
230 memcpy (hkey,
231 &hc,
232 sizeof (*hkey));
233 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
234 hkey);
235 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
236 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
237 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
238 memcpy (hkey,
239 &hc,
240 sizeof (*hkey));
241 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
242 hkey);
243 }
244
245
246 return node->node_connections_head;
247}
248
249
250static unsigned int
251calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
252 struct GNUNET_TESTING_NetjailTopology *topology)
253{
254 unsigned int n, m, num;
255
256 n = node_connection->namespace_n;
257 m = node_connection->node_n;
258
259 if (0 == n)
260 num = m;
261 else
262 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
263
264 return num;
265}
266
267static char *
268get_address (struct GNUNET_TESTING_NodeConnection *connection,
269 char *prefix)
270{
271 struct GNUNET_TESTING_NetjailNode *node;
272 char *addr;
273
274 node = connection->node;
275 if (connection->namespace_n == node->namespace_n)
276 {
277 if (0 == strcmp (PREFIX_TCP, prefix))
278 {
279
280 GNUNET_asprintf (&addr,
281 CONNECT_ADDRESS_TEMPLATE_TCP,
282 connection->node_n);
283 }
284 else if (0 == strcmp (PREFIX_UDP, prefix))
285 {
286 GNUNET_asprintf (&addr,
287 CONNECT_ADDRESS_TEMPLATE_UDP,
288 connection->node_n);
289 }
290 else
291 {
292 GNUNET_break (0);
293 }
294 }
295 else
296 {
297 if (0 == strcmp (PREFIX_TCP, prefix))
298 {
299
300 GNUNET_asprintf (&addr,
301 ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
302 connection->namespace_n);
303 }
304 else if (0 == strcmp (PREFIX_UDP, prefix))
305 {
306 GNUNET_asprintf (&addr,
307 ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
308 connection->namespace_n);
309 }
310 else
311 {
312 GNUNET_break (0);
313 }
314 }
315
316 return addr;
317}
318
319
320/** 88/**
321 * The run method of this cmd will connect to peers. 89 * The run method of this cmd will connect to peers.
322 * 90 *
@@ -338,7 +106,7 @@ connect_peers_run (void *cls,
338 enum GNUNET_NetworkType nt = 0; 106 enum GNUNET_NetworkType nt = 0;
339 uint32_t num; 107 uint32_t num;
340 struct GNUNET_TESTING_NodeConnection *pos_connection; 108 struct GNUNET_TESTING_NodeConnection *pos_connection;
341 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix; 109 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
342 unsigned int con_num = 0; 110 unsigned int con_num = 0;
343 111
344 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); 112 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
@@ -351,13 +119,14 @@ connect_peers_run (void *cls,
351 119
352 cps->tl_system = tl_system; 120 cps->tl_system = tl_system;
353 121
354 cps->node_connections_head = get_connections (cps->num, cps->topology); 122 cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num,
123 cps->topology);
355 124
356 for (pos_connection = cps->node_connections_head; NULL != pos_connection; 125 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
357 pos_connection = pos_connection->next) 126 pos_connection = pos_connection->next)
358 { 127 {
359 con_num++; 128 con_num++;
360 num = calculate_num (pos_connection, cps->topology); 129 num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
361 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; 130 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
362 pos_prefix = 131 pos_prefix =
363 pos_prefix->next) 132 pos_prefix->next)
@@ -367,9 +136,10 @@ connect_peers_run (void *cls,
367 "prefix: %s\n", 136 "prefix: %s\n",
368 pos_prefix->address_prefix); 137 pos_prefix->address_prefix);
369 138
370 addr = get_address (pos_connection, pos_prefix->address_prefix); 139 addr = GNUNET_TESTING_get_address (pos_connection,
140 pos_prefix->address_prefix);
371 141
372 peer = get_pub_key (num, tl_system); 142 peer = GNUNET_TESTING_get_pub_key (num, tl_system);
373 143
374 LOG (GNUNET_ERROR_TYPE_ERROR, 144 LOG (GNUNET_ERROR_TYPE_ERROR,
375 "num: %u pub_key %s addr: %s\n", 145 "num: %u pub_key %s addr: %s\n",
@@ -417,8 +187,8 @@ connect_peers_finish (void *cls,
417 for (pos_connection = cps->node_connections_head; NULL != pos_connection; 187 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
418 pos_connection = pos_connection->next) 188 pos_connection = pos_connection->next)
419 { 189 {
420 num = calculate_num (pos_connection, cps->topology); 190 num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
421 peer = get_pub_key (num, cps->tl_system); 191 peer = GNUNET_TESTING_get_pub_key (num, cps->tl_system);
422 GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc); 192 GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc);
423 memcpy (key, 193 memcpy (key,
424 &hc, 194 &hc,
@@ -476,6 +246,9 @@ connect_peers_cleanup (void *cls,
476 * 246 *
477 * @param label name for command. 247 * @param label name for command.
478 * @param start_peer_label Label of the cmd to start a peer. 248 * @param start_peer_label Label of the cmd to start a peer.
249 * @param create_label Label of the cmd to create the testing system.
250 * @param num Number globally identifying the node.
251 * @param The topology for the test setup.
479 * @return command. 252 * @return command.
480 */ 253 */
481struct GNUNET_TESTING_Command 254struct GNUNET_TESTING_Command
diff --git a/src/transport/transport_api_cmd_send_simple_v3.c b/src/transport/transport_api_cmd_send_simple_v3.c
new file mode 100644
index 000000000..a4ce2c4e9
--- /dev/null
+++ b/src/transport/transport_api_cmd_send_simple_v3.c
@@ -0,0 +1,194 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "transport-testing2.h"
30#include "transport-testing-cmds.h"
31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
36struct SendSimpleState
37{
38 /**
39 * Number globally identifying the node.
40 *
41 */
42 uint32_t num;
43
44 /**
45 * Label of the cmd to start a peer.
46 *
47 */
48 const char *start_peer_label;
49
50 /**
51 * Label of the cmd which started the test system.
52 *
53 */
54 const char *create_label;
55
56 /**
57 * The topology we get the connected nodes from.
58 */
59 struct GNUNET_TESTING_NetjailTopology *topology;
60};
61
62
63/**
64 * Trait function of this cmd does nothing.
65 *
66 */
67static int
68send_simple_traits (void *cls,
69 const void **ret,
70 const char *trait,
71 unsigned int index)
72{
73 return GNUNET_OK;
74}
75
76
77/**
78 * The cleanup function of this cmd frees resources the cmd allocated.
79 *
80 */
81static void
82send_simple_cleanup (void *cls,
83 const struct GNUNET_TESTING_Command *cmd)
84{
85 struct SendSimpleState *sss = cls;
86
87 GNUNET_free (sss);
88}
89
90
91/**
92 * The run method of this cmd will send a simple message to the connected peers.
93 *
94 */
95static void
96send_simple_run (void *cls,
97 const struct GNUNET_TESTING_Command *cmd,
98 struct GNUNET_TESTING_Interpreter *is)
99{
100 struct SendSimpleState *sss = cls;
101 struct GNUNET_MQ_Envelope *env;
102 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
103 struct GNUNET_MQ_Handle *mq;
104 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
105 const struct GNUNET_TESTING_Command *peer1_cmd;
106 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
107 struct GNUNET_HashCode hc;
108 struct GNUNET_TESTING_NodeConnection *node_connections_head;
109 struct GNUNET_PeerIdentity *peer;
110 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
111 uint32_t num;
112 struct GNUNET_TESTING_NodeConnection *pos_connection;
113 const struct GNUNET_TESTING_Command *system_cmd;
114 struct GNUNET_TESTING_System *tl_system;
115
116 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
117 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
118 &connected_peers_map);
119
120 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->create_label);
121 GNUNET_TESTING_get_trait_test_system (system_cmd,
122 &tl_system);
123
124 node_connections_head = GNUNET_TESTING_get_connections (sss->num,
125 sss->topology);
126
127 for (int i = 0; i < 1; i++)
128 {
129 for (pos_connection = node_connections_head; NULL != pos_connection;
130 pos_connection = pos_connection->next)
131 {
132 num = GNUNET_TESTING_calculate_num (pos_connection, sss->topology);
133 peer = GNUNET_TESTING_get_pub_key (num, tl_system);
134 public_key = peer->public_key;
135 GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
136
137 memcpy (key,
138 &hc,
139 sizeof (*key));
140 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
141 key);
142 env = GNUNET_MQ_msg_extra (test,
143 1000 - sizeof(*test),
144 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
145 test->num = htonl (sss->num);
146 memset (&test[1],
147 sss->num,
148 1000 - sizeof(*test));
149 GNUNET_MQ_send (mq,
150 env);
151 }
152 }
153
154 GNUNET_free (key);
155
156}
157
158
159/**
160 * Create command.
161 *
162 * @param label name for command.
163 * @param start_peer_label Label of the cmd to start a peer.
164 * @param start_peer_label Label of the cmd which started the test system.
165 * @param num Number globally identifying the node.
166 * @param The topology for the test setup.
167 * @return command.
168 */
169struct GNUNET_TESTING_Command
170GNUNET_TRANSPORT_cmd_send_simple_v3 (const char *label,
171 const char *start_peer_label,
172 const char *create_label,
173 uint32_t num,
174 struct GNUNET_TESTING_NetjailTopology *
175 topology)
176{
177 struct SendSimpleState *sss;
178
179 sss = GNUNET_new (struct SendSimpleState);
180 sss->num = num;
181 sss->start_peer_label = start_peer_label;
182 sss->create_label = create_label;
183 sss->topology = topology;
184
185 struct GNUNET_TESTING_Command cmd = {
186 .cls = sss,
187 .label = label,
188 .run = &send_simple_run,
189 .cleanup = &send_simple_cleanup,
190 .traits = &send_simple_traits
191 };
192
193 return cmd;
194}
diff --git a/src/util/helper.c b/src/util/helper.c
index dcb55d8c7..0809c1f17 100644
--- a/src/util/helper.c
+++ b/src/util/helper.c
@@ -407,6 +407,8 @@ start_helper (struct GNUNET_HELPER_Handle *h)
407 if ((h->helper_in == NULL) || (h->helper_out == NULL)) 407 if ((h->helper_in == NULL) || (h->helper_out == NULL))
408 { 408 {
409 /* out of file descriptors? try again later... */ 409 /* out of file descriptors? try again later... */
410 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
411 "out of file descriptors? try again later\n");
410 stop_helper (h, GNUNET_NO); 412 stop_helper (h, GNUNET_NO);
411 h->restart_task = GNUNET_SCHEDULER_add_delayed ( 413 h->restart_task = GNUNET_SCHEDULER_add_delayed (
412 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 414 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
@@ -434,6 +436,8 @@ start_helper (struct GNUNET_HELPER_Handle *h)
434 if (NULL == h->helper_proc) 436 if (NULL == h->helper_proc)
435 { 437 {
436 /* failed to start process? try again later... */ 438 /* failed to start process? try again later... */
439 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
440 "failed to start process? try again later\n");
437 stop_helper (h, GNUNET_NO); 441 stop_helper (h, GNUNET_NO);
438 h->restart_task = GNUNET_SCHEDULER_add_delayed ( 442 h->restart_task = GNUNET_SCHEDULER_add_delayed (
439 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 443 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,