aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
committert3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
commitd64ac269856744b9bab170964e1d6f36896ecc55 (patch)
treeed5aa79b91fe3cf9388433a5611581b7ce3b846c /src/transport
parent003910fc614cd347919707d1bf3c37a939978459 (diff)
downloadgnunet-d64ac269856744b9bab170964e1d6f36896ecc55.tar.gz
gnunet-d64ac269856744b9bab170964e1d6f36896ecc55.zip
removed versioned artefacts with v2 and v3. changes to reflect the changes in testing_api_loop.c
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am48
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c192
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_v2.c235
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c175
-rw-r--r--src/transport/test_transport_port_forward.c85
-rw-r--r--src/transport/test_transport_simple_send.c86
-rwxr-xr-xsrc/transport/test_transport_simple_send.sh2
-rw-r--r--src/transport/test_transport_simple_send_v2.c83
-rwxr-xr-xsrc/transport/test_transport_simple_send_v2.sh2
-rw-r--r--src/transport/test_transport_start_with_config.c59
-rw-r--r--src/transport/transport-testing-cmds.h201
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c482
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v2.c237
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v3.c496
-rw-r--r--src/transport/transport_api_cmd_send_simple.c20
-rw-r--r--src/transport/transport_api_cmd_send_simple_v2.c156
-rw-r--r--src/transport/transport_api_cmd_start_peer.c78
-rw-r--r--src/transport/transport_api_cmd_start_peer_v2.c605
-rw-r--r--src/transport/transport_api_cmd_start_peer_v3.c617
19 files changed, 729 insertions, 3130 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index a539f3f25..0df422976 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -159,14 +159,9 @@ libgnunettransporttesting_la_LDFLAGS = \
159 159
160libgnunettransporttesting2_la_SOURCES = \ 160libgnunettransporttesting2_la_SOURCES = \
161 transport_api_cmd_connecting_peers.c \ 161 transport_api_cmd_connecting_peers.c \
162 transport_api_cmd_connecting_peers_v2.c \
163 transport_api_cmd_connecting_peers_v3.c \
164 transport_api_cmd_start_peer.c \ 162 transport_api_cmd_start_peer.c \
165 transport_api_cmd_start_peer_v2.c \
166 transport_api_cmd_start_peer_v3.c \
167 transport_api_cmd_stop_peer.c \ 163 transport_api_cmd_stop_peer.c \
168 transport_api_cmd_send_simple.c \ 164 transport_api_cmd_send_simple.c \
169 transport_api_cmd_send_simple_v2.c \
170 transport-testing2.c transport-testing2.h \ 165 transport-testing2.c transport-testing2.h \
171 transport-testing-cmds.h \ 166 transport-testing-cmds.h \
172 transport-testing-filenames2.c \ 167 transport-testing-filenames2.c \
@@ -394,7 +389,6 @@ plugin_LTLIBRARIES = \
394 $(WLAN_PLUGIN_LA) \ 389 $(WLAN_PLUGIN_LA) \
395 $(BT_PLUGIN_LA) \ 390 $(BT_PLUGIN_LA) \
396 libgnunet_test_transport_plugin_cmd_simple_send.la \ 391 libgnunet_test_transport_plugin_cmd_simple_send.la \
397 libgnunet_test_transport_plugin_cmd_simple_send_v2.la \
398 libgnunet_test_transport_plugin_cmd_udp_backchannel.la 392 libgnunet_test_transport_plugin_cmd_udp_backchannel.la
399 393
400libgnunet_test_transport_plugin_cmd_udp_backchannel_la_SOURCES = \ 394libgnunet_test_transport_plugin_cmd_udp_backchannel_la_SOURCES = \
@@ -431,23 +425,6 @@ libgnunet_test_transport_plugin_cmd_simple_send_la_LIBADD = \
431libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \ 425libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \
432 $(GN_PLUGIN_LDFLAGS) 426 $(GN_PLUGIN_LDFLAGS)
433 427
434libgnunet_test_transport_plugin_cmd_simple_send_v2_la_SOURCES = \
435 test_transport_plugin_cmd_simple_send_v2.c
436libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LIBADD = \
437 libgnunettransporttesting2.la \
438 libgnunettransportapplication.la \
439 libgnunettransportcore.la \
440 $(top_builddir)/src/testing/libgnunettesting.la \
441 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
442 $(top_builddir)/src/statistics/libgnunetstatistics.la \
443 $(top_builddir)/src/hello/libgnunethello.la \
444 $(top_builddir)/src/ats/libgnunetats.la \
445 $(top_builddir)/src/arm/libgnunetarm.la \
446 $(top_builddir)/src/util/libgnunetutil.la \
447 $(LTLIBINTL)
448libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LDFLAGS = \
449 $(GN_PLUGIN_LDFLAGS)
450
451if HAVE_EXPERIMENTAL 428if HAVE_EXPERIMENTAL
452plugin_LTLIBRARIES += \ 429plugin_LTLIBRARIES += \
453 libgnunet_plugin_transport_udp.la 430 libgnunet_plugin_transport_udp.la
@@ -593,8 +570,6 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \
593 $(MHD_CFLAGS) $(AM_CFLAGS) -DBUILD_HTTPS 570 $(MHD_CFLAGS) $(AM_CFLAGS) -DBUILD_HTTPS
594 571
595check_PROGRAMS = \ 572check_PROGRAMS = \
596 test_transport_simple_send \
597 test_transport_simple_send_v2 \
598 test_transport_start_with_config \ 573 test_transport_start_with_config \
599 test_transport_address_switch_tcp \ 574 test_transport_address_switch_tcp \
600 test_transport_testing_startstop \ 575 test_transport_testing_startstop \
@@ -743,8 +718,6 @@ test_transport_api_slow_ats
743endif 718endif
744if HAVE_EXPERIMENTAL 719if HAVE_EXPERIMENTAL
745TESTS += \ 720TESTS += \
746 test_transport_simple_send \
747 test_transport_simple_send_v2 \
748 test_transport_start_with_config \ 721 test_transport_start_with_config \
749 test_transport_address_switch_udp \ 722 test_transport_address_switch_udp \
750 test_plugin_udp \ 723 test_plugin_udp \
@@ -765,7 +738,6 @@ endif
765 738
766check_SCRIPTS= \ 739check_SCRIPTS= \
767 test_transport_simple_send.sh \ 740 test_transport_simple_send.sh \
768 test_transport_simple_send_v2.sh \
769 test_transport_udp_backchannel.sh 741 test_transport_udp_backchannel.sh
770 742
771test_transport_start_with_config_SOURCES = \ 743test_transport_start_with_config_SOURCES = \
@@ -778,26 +750,6 @@ test_transport_start_with_config_LDADD = \
778 libgnunettransportcore.la \ 750 libgnunettransportcore.la \
779 libgnunettransporttesting2.la 751 libgnunettransporttesting2.la
780 752
781test_transport_simple_send_SOURCES = \
782 test_transport_simple_send.c
783test_transport_simple_send_LDADD = \
784 $(top_builddir)/src/testing/libgnunettesting.la \
785 $(top_builddir)/src/util/libgnunetutil.la \
786 $(top_builddir)/src/testbed/libgnunettestbed.la \
787 $(top_builddir)/src/hello/libgnunethello.la \
788 libgnunettransportcore.la \
789 libgnunettransporttesting2.la
790
791test_transport_simple_send_v2_SOURCES = \
792 test_transport_simple_send_v2.c
793test_transport_simple_send_v2_LDADD = \
794 $(top_builddir)/src/testing/libgnunettesting.la \
795 $(top_builddir)/src/util/libgnunetutil.la \
796 $(top_builddir)/src/testbed/libgnunettestbed.la \
797 $(top_builddir)/src/hello/libgnunethello.la \
798 libgnunettransportcore.la \
799 libgnunettransporttesting2.la
800
801test_transport_testing_startstop_SOURCES = \ 753test_transport_testing_startstop_SOURCES = \
802 test_transport_testing_startstop.c 754 test_transport_testing_startstop.c
803test_transport_testing_startstop_LDADD = \ 755test_transport_testing_startstop_LDADD = \
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 21167415d..5384bf24d 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -37,28 +37,34 @@
37 37
38#define BASE_DIR "testdir" 38#define BASE_DIR "testdir"
39 39
40/** 40#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
41 * The name for a specific test environment directory.
42 *
43 */
44char *testdir;
45 41
46/** 42struct TestState
47 * The name for the configuration file of the specific node. 43{
48 * 44 /**
49 */ 45 * Callback to write messages to the master loop.
50char *cfgname; 46 *
47 */
48 TESTING_CMD_HELPER_write_cb write_message;
51 49
52/** 50 /**
53 * Flag indicating if all peers have been started. 51 * The name for a specific test environment directory.
54 * 52 *
55 */ 53 */
56unsigned int are_all_peers_started; 54 char *testdir;
57 55
58/** 56 /**
59 * Flag indicating a received message. 57 * The name for the configuration file of the specific node.
60 */ 58 *
61unsigned int message_received; 59 */
60 char *cfgname;
61};
62
63static struct GNUNET_TESTING_Command block_send;
64
65static struct GNUNET_TESTING_Command block_receive;
66
67static struct GNUNET_TESTING_Command connect_peers;
62 68
63 69
64/** 70/**
@@ -83,7 +89,14 @@ static void
83handle_test (void *cls, 89handle_test (void *cls,
84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 90 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
85{ 91{
86 message_received = GNUNET_YES; 92 struct GNUNET_TESTING_AsyncContext *ac;
93
94 GNUNET_TESTING_get_trait_async_context (&block_receive,
95 &ac);
96 if ((NULL == ac) || (NULL == ac->cont))
97 GNUNET_TESTING_async_fail (ac);
98 else
99 GNUNET_TESTING_async_finish (ac);
87} 100}
88 101
89 102
@@ -94,7 +107,62 @@ handle_test (void *cls,
94static void 107static void
95all_peers_started () 108all_peers_started ()
96{ 109{
97 are_all_peers_started = GNUNET_YES; 110 struct GNUNET_TESTING_AsyncContext *ac;
111
112 GNUNET_TESTING_get_trait_async_context (&block_send,
113 &ac);
114 if ((NULL == ac) || (NULL == ac->cont))
115 GNUNET_TESTING_async_fail (ac);
116 else
117 GNUNET_TESTING_async_finish (ac);
118}
119
120
121/**
122 * Function called with the final result of the test.
123 *
124 * @param cls the `struct MainParams`
125 * @param rv #GNUNET_OK if the test passed
126 */
127static void
128handle_result (void *cls,
129 enum GNUNET_GenericReturnValue rv)
130{
131 struct TestState *ts = cls;
132 struct GNUNET_MessageHeader *reply;
133
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
135 "Local test exits with status %d\n",
136 rv);
137 reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
138
139 ts->write_message (reply,
140 ntohs (reply->size));
141 GNUNET_free (ts->testdir);
142 GNUNET_free (ts->cfgname);
143 GNUNET_free (ts);
144}
145
146
147/**
148 * Callback from start peer cmd for signaling a peer got connected.
149 *
150 */
151static void *
152notify_connect (void *cls,
153 const struct GNUNET_PeerIdentity *peer,
154 struct GNUNET_MQ_Handle *mq)
155{
156 struct ConnectPeersState *cps;
157
158 GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
159 &cps);
160 void *ret = NULL;
161
162 cps->notify_connect (cps,
163 peer,
164 mq);
165 return ret;
98} 166}
99 167
100 168
@@ -116,24 +184,46 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
116 char *local_m) 184 char *local_m)
117{ 185{
118 186
119 GNUNET_asprintf (&cfgname, 187 unsigned int n_int;
120 "test_transport_api2_tcp_node%s.conf", 188 unsigned int m_int;
121 "1"); 189 unsigned int local_m_int;
190 unsigned int num;
191 struct TestState *ts = GNUNET_new (struct TestState);
192 struct GNUNET_TESTING_NetjailTopology *topology =
193 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
194
195 if (0 == m_int)
196 num = n_int;
197 else
198 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
199
200 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
201 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
202 "block-receive");
203 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
204 "start-peer",
205 "system-create",
206 num,
207 NULL);
208
209
210
211 sscanf (m, "%u", &m_int);
212 sscanf (n, "%u", &n_int);
213 sscanf (local_m, "%u", &local_m_int);
214
215 GNUNET_asprintf (&ts->cfgname,
216 "test_transport_api2_tcp_node1.conf");
122 217
123 LOG (GNUNET_ERROR_TYPE_ERROR, 218 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "plugin cfgname: %s\n", 219 "plugin cfgname: %s\n",
125 cfgname); 220 ts->cfgname);
126 221
127 LOG (GNUNET_ERROR_TYPE_ERROR, 222 LOG (GNUNET_ERROR_TYPE_ERROR,
128 "node ip: %s\n", 223 "node ip: %s\n",
129 node_ip); 224 node_ip);
130 225
131 LOG (GNUNET_ERROR_TYPE_ERROR, 226 GNUNET_asprintf (&ts->testdir,
132 "m: %s n: %s\n",
133 m,
134 n);
135
136 GNUNET_asprintf (&testdir,
137 "%s%s%s", 227 "%s%s%s",
138 BASE_DIR, 228 BASE_DIR,
139 m, 229 m,
@@ -143,50 +233,38 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
143 GNUNET_MQ_hd_var_size (test, 233 GNUNET_MQ_hd_var_size (test,
144 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 234 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
145 struct GNUNET_TRANSPORT_TESTING_TestMessage, 235 struct GNUNET_TRANSPORT_TESTING_TestMessage,
146 NULL), 236 ts),
147 GNUNET_MQ_handler_end () 237 GNUNET_MQ_handler_end ()
148 }; 238 };
149 239
150 struct GNUNET_TESTING_Command commands[] = { 240 struct GNUNET_TESTING_Command commands[] = {
151 GNUNET_TESTING_cmd_system_create ("system-create", 241 GNUNET_TESTING_cmd_system_create ("system-create",
152 testdir), 242 ts->testdir),
153 GNUNET_TRANSPORT_cmd_start_peer ("start-peer", 243 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
154 "system-create", 244 "system-create",
155 m, 245 num,
156 n,
157 local_m,
158 node_ip, 246 node_ip,
159 handlers, 247 handlers,
160 cfgname), 248 ts->cfgname,
249 notify_connect),
161 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", 250 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
162 write_message), 251 write_message),
163 GNUNET_TESTING_cmd_block_until_all_peers_started ("block", 252 block_send,
164 &are_all_peers_started), 253 connect_peers,
165 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
166 "start-peer",
167 "system-create",
168 (atoi (n) - 1) * atoi (local_m) + atoi (
169 m)),
170 GNUNET_TRANSPORT_cmd_send_simple ("send-simple", 254 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
171 m, 255 "start-peer",
172 n, 256 num),
173 (atoi (n) - 1) * atoi (local_m) + atoi ( 257 block_receive,
174 m),
175 "start-peer"),
176 GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive",
177 &message_received),
178 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", 258 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
179 "start-peer"), 259 "start-peer"),
180 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 260 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
181 "system-create"), 261 "system-create")
182 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
183 write_message)
184 }; 262 };
185 263
186 GNUNET_TESTING_run (commands, 264 GNUNET_TESTING_run (commands,
187 GNUNET_TIME_UNIT_FOREVER_REL, 265 GNUNET_TIME_UNIT_FOREVER_REL,
188 NULL, /* FIXME: will crash */ 266 &handle_result,
189 NULL); 267 ts);
190 268
191} 269}
192 270
@@ -221,8 +299,6 @@ libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
221 struct GNUNET_TESTING_PluginFunctions *api = cls; 299 struct GNUNET_TESTING_PluginFunctions *api = cls;
222 300
223 GNUNET_free (api); 301 GNUNET_free (api);
224 GNUNET_free (testdir);
225 GNUNET_free (cfgname);
226 return NULL; 302 return NULL;
227} 303}
228 304
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_v2.c b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
deleted file mode 100644
index 98e9d5fca..000000000
--- a/src/transport/test_transport_plugin_cmd_simple_send_v2.c
+++ /dev/null
@@ -1,235 +0,0 @@
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_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h"
31#include "transport-testing-cmds.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38#define BASE_DIR "testdir"
39
40#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
41
42/**
43 * The name for a specific test environment directory.
44 *
45 */
46char *testdir;
47
48/**
49 * The name for the configuration file of the specific node.
50 *
51 */
52char *cfgname;
53
54/**
55 * Flag indicating if all peers have been started.
56 *
57 */
58unsigned int are_all_peers_started;
59
60/**
61 * Flag indicating a received message.
62 */
63unsigned int message_received;
64
65
66/**
67 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
68 * received.
69 *
70 */
71static int
72check_test (void *cls,
73 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
74{
75 return GNUNET_OK;
76}
77
78
79/**
80 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
81 * being received.
82 *
83 */
84static void
85handle_test (void *cls,
86 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
87{
88 message_received = GNUNET_YES;
89}
90
91
92/**
93 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
94 *
95 */
96static void
97all_peers_started ()
98{
99 are_all_peers_started = GNUNET_YES;
100}
101
102
103/**
104 * Function to start a local test case.
105 *
106 * @param write_message Callback to send a message to the master loop.
107 * @param router_ip Global address of the network namespace.
108 * @param node_ip Local address of a node i a network namespace.
109 * @param m The number of the node in a network namespace.
110 * @param n The number of the network namespace.
111 * @param local_m The number of nodes in a network namespace.
112 */
113static void
114start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
115 char *node_ip,
116 char *m,
117 char *n,
118 char *local_m)
119{
120
121 unsigned int n_int, m_int, local_m_int, num;
122
123 struct GNUNET_TESTING_NetjailTopology *topology =
124 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
125
126 sscanf (m, "%u", &m_int);
127 sscanf (n, "%u", &n_int);
128 sscanf (local_m, "%u", &local_m_int);
129
130
131 if (0 == m_int)
132 num = n_int;
133 else
134 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
135
136 GNUNET_asprintf (&cfgname,
137 "test_transport_api2_tcp_node1.conf");
138
139 LOG (GNUNET_ERROR_TYPE_ERROR,
140 "plugin cfgname: %s\n",
141 cfgname);
142
143 LOG (GNUNET_ERROR_TYPE_ERROR,
144 "node ip: %s\n",
145 node_ip);
146
147 GNUNET_asprintf (&testdir,
148 "%s%s%s",
149 BASE_DIR,
150 m,
151 n);
152
153 struct GNUNET_MQ_MessageHandler handlers[] = {
154 GNUNET_MQ_hd_var_size (test,
155 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
156 struct GNUNET_TRANSPORT_TESTING_TestMessage,
157 NULL),
158 GNUNET_MQ_handler_end ()
159 };
160
161 struct GNUNET_TESTING_Command commands[] = {
162 GNUNET_TESTING_cmd_system_create ("system-create",
163 testdir),
164 GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
165 "system-create",
166 num,
167 node_ip,
168 handlers,
169 cfgname),
170 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
171 write_message),
172 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
173 &are_all_peers_started),
174 GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
175 "start-peer",
176 "system-create",
177 num),
178 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
179 "start-peer",
180 num),
181 GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive",
182 &message_received),
183 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
184 "start-peer"),
185 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
186 "system-create"),
187 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
188 write_message)
189 };
190
191 GNUNET_TESTING_run (commands,
192 GNUNET_TIME_UNIT_FOREVER_REL,
193 NULL, /* FIXME: will crash */
194 NULL);
195
196}
197
198
199/**
200 * Entry point for the plugin.
201 *
202 * @param cls NULL
203 * @return the exported block API
204 */
205void *
206libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
207{
208 struct GNUNET_TESTING_PluginFunctions *api;
209
210 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
211 api->start_testcase = &start_testcase;
212 api->all_peers_started = &all_peers_started;
213 return api;
214}
215
216
217/**
218 * Exit point from the plugin.
219 *
220 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
221 * @return NULL
222 */
223void *
224libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
225{
226 struct GNUNET_TESTING_PluginFunctions *api = cls;
227
228 GNUNET_free (api);
229 GNUNET_free (testdir);
230 GNUNET_free (cfgname);
231 return NULL;
232}
233
234
235/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index 6b0342e51..108e1ac09 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -39,28 +39,32 @@
39 39
40#define TOPOLOGY_CONFIG "test_transport_udp_backchannel_topo.conf" 40#define TOPOLOGY_CONFIG "test_transport_udp_backchannel_topo.conf"
41 41
42/** 42struct TestState
43 * The name for a specific test environment directory. 43{
44 * 44 /**
45 */ 45 * Callback to write messages to the master loop.
46char *testdir; 46 *
47 */
48 TESTING_CMD_HELPER_write_cb write_message;
47 49
48/** 50 /**
49 * The name for the configuration file of the specific node. 51 * The name for a specific test environment directory.
50 * 52 *
51 */ 53 */
52char *cfgname; 54 char *testdir;
53 55
54/** 56 /**
55 * Flag indicating if all peers have been started. 57 * The name for the configuration file of the specific node.
56 * 58 *
57 */ 59 */
58unsigned int are_all_peers_started; 60 char *cfgname;
61};
59 62
60/** 63static struct GNUNET_TESTING_Command block_send;
61 * Flag indicating a received message. 64
62 */ 65static struct GNUNET_TESTING_Command block_receive;
63unsigned int message_received; 66
67static struct GNUNET_TESTING_Command connect_peers;
64 68
65 69
66/** 70/**
@@ -85,7 +89,14 @@ static void
85handle_test (void *cls, 89handle_test (void *cls,
86 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 90 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
87{ 91{
88 message_received = GNUNET_YES; 92 struct GNUNET_TESTING_AsyncContext *ac;
93
94 GNUNET_TESTING_get_trait_async_context (&block_receive,
95 &ac);
96 if ((NULL == ac) || (NULL == ac->cont))
97 GNUNET_TESTING_async_fail (ac);
98 else
99 GNUNET_TESTING_async_finish (ac);
89} 100}
90 101
91 102
@@ -96,10 +107,62 @@ handle_test (void *cls,
96static void 107static void
97all_peers_started () 108all_peers_started ()
98{ 109{
99 are_all_peers_started = GNUNET_YES; 110 struct GNUNET_TESTING_AsyncContext *ac;
100 LOG (GNUNET_ERROR_TYPE_ERROR, 111
101 "setting are_all_peers_started: %d\n", 112 GNUNET_TESTING_get_trait_async_context (&block_send,
102 are_all_peers_started); 113 &ac);
114 if ((NULL == ac) || (NULL == ac->cont))
115 GNUNET_TESTING_async_fail (ac);
116 else
117 GNUNET_TESTING_async_finish (ac);
118}
119
120
121/**
122* Function called with the final result of the test.
123*
124* @param cls the `struct MainParams`
125* @param rv #GNUNET_OK if the test passed
126*/
127static void
128handle_result (void *cls,
129 enum GNUNET_GenericReturnValue rv)
130{
131 struct TestState *ts = cls;
132 struct GNUNET_MessageHeader *reply;
133
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
135 "Local test exits with status %d\n",
136 rv);
137 reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
138
139 ts->write_message (reply,
140 ntohs (reply->size));
141 GNUNET_free (ts->testdir);
142 GNUNET_free (ts->cfgname);
143 GNUNET_free (ts);
144}
145
146
147/**
148 * Callback from start peer cmd for signaling a peer got connected.
149 *
150 */
151static void *
152notify_connect (void *cls,
153 const struct GNUNET_PeerIdentity *peer,
154 struct GNUNET_MQ_Handle *mq)
155{
156 struct ConnectPeersState *cps;
157
158 GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
159 &cps);
160 void *ret = NULL;
161
162 cps->notify_connect (cps,
163 peer,
164 mq);
165 return ret;
103} 166}
104 167
105 168
@@ -121,7 +184,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
121 char *local_m) 184 char *local_m)
122{ 185{
123 186
124 unsigned int n_int, m_int, local_m_int, num; 187 unsigned int n_int;
188 unsigned int m_int;
189 unsigned int local_m_int;
190 unsigned int num;
191 struct TestState *ts = GNUNET_new (struct TestState);
125 192
126 struct GNUNET_TESTING_NetjailTopology *topology = 193 struct GNUNET_TESTING_NetjailTopology *topology =
127 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); 194 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
@@ -136,18 +203,27 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
136 else 203 else
137 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; 204 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
138 205
139 GNUNET_asprintf (&cfgname, 206 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
207 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
208 "block-receive");
209 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
210 "start-peer",
211 "system-create",
212 num,
213 NULL);
214
215 GNUNET_asprintf (&ts->cfgname,
140 "test_transport_api2_tcp_node1.conf"); 216 "test_transport_api2_tcp_node1.conf");
141 217
142 LOG (GNUNET_ERROR_TYPE_ERROR, 218 LOG (GNUNET_ERROR_TYPE_ERROR,
143 "plugin cfgname: %s\n", 219 "plugin cfgname: %s\n",
144 cfgname); 220 ts->cfgname);
145 221
146 LOG (GNUNET_ERROR_TYPE_ERROR, 222 LOG (GNUNET_ERROR_TYPE_ERROR,
147 "node ip: %s\n", 223 "node ip: %s\n",
148 node_ip); 224 node_ip);
149 225
150 GNUNET_asprintf (&testdir, 226 GNUNET_asprintf (&ts->testdir,
151 "%s%s%s", 227 "%s%s%s",
152 BASE_DIR, 228 BASE_DIR,
153 m, 229 m,
@@ -163,39 +239,32 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
163 239
164 struct GNUNET_TESTING_Command commands[] = { 240 struct GNUNET_TESTING_Command commands[] = {
165 GNUNET_TESTING_cmd_system_create ("system-create", 241 GNUNET_TESTING_cmd_system_create ("system-create",
166 testdir), 242 ts->testdir),
167 GNUNET_TRANSPORT_cmd_start_peer_v3 ("start-peer", 243 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
168 "system-create", 244 "system-create",
169 num, 245 num,
170 node_ip, 246 node_ip,
171 handlers, 247 handlers,
172 cfgname), 248 ts->cfgname,
249 notify_connect),
173 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", 250 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
174 write_message), 251 write_message),
175 GNUNET_TESTING_cmd_block_until_all_peers_started ("block", 252 block_send,
176 &are_all_peers_started), 253 connect_peers,
177 GNUNET_TRANSPORT_cmd_connect_peers_v3 ("connect-peers", 254 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
178 "start-peer", 255 "start-peer",
179 "system-create", 256 num),
180 num, 257 block_receive,
181 topology),
182 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
183 "start-peer",
184 num),
185 GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive",
186 &message_received),
187 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", 258 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
188 "start-peer"), 259 "start-peer"),
189 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 260 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
190 "system-create"), 261 "system-create")
191 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
192 write_message)
193 }; 262 };
194 263
195 GNUNET_TESTING_run (commands, 264 GNUNET_TESTING_run (commands,
196 GNUNET_TIME_UNIT_FOREVER_REL, 265 GNUNET_TIME_UNIT_FOREVER_REL,
197 NULL, /* FIMXE: will crash */ 266 &handle_result,
198 NULL); 267 ts);
199 268
200} 269}
201 270
@@ -234,8 +303,6 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_done (void *cls)
234 struct GNUNET_TESTING_PluginFunctions *api = cls; 303 struct GNUNET_TESTING_PluginFunctions *api = cls;
235 304
236 GNUNET_free (api); 305 GNUNET_free (api);
237 GNUNET_free (testdir);
238 GNUNET_free (cfgname);
239 return NULL; 306 return NULL;
240} 307}
241 308
diff --git a/src/transport/test_transport_port_forward.c b/src/transport/test_transport_port_forward.c
deleted file mode 100644
index d3233c2da..000000000
--- a/src/transport/test_transport_port_forward.c
+++ /dev/null
@@ -1,85 +0,0 @@
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 transport/test_transport_port_forward.c
23 * @brief Test case executing a script which sends a test UDP message from a nated peer
24 * to a global known peer. There is a tcp port forwarding in place towards the
25 * natted peer to test the backchannel functionality of the TNG service.
26 * @author t3sserakt
27 */
28#include "platform.h"
29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_util_lib.h"
31
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
33
34/**
35 * Return value of the test.
36 *
37 */
38static unsigned int rv = 0;
39
40
41/**
42 * Main function to run the test cases.
43 *
44 * @param cls not used.
45 *
46 */
47static void
48run (void *cls)
49{
50 const char *topology_config = "test_topology_port_forward.conf";
51
52 struct GNUNET_TESTING_Command commands[] = {
53 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
54 topology_config),
55 GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed",
56 topology_config,
57 &rv),
58 GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed",
59 "netjail-start-testbed",
60 topology_config),
61 GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
62 topology_config),
63 GNUNET_TESTING_cmd_end ()
64 };
65
66 GNUNET_TESTING_run (NULL,
67 commands,
68 TIMEOUT);
69}
70
71
72int
73main (int argc,
74 char *const *argv)
75{
76 GNUNET_log_setup ("test-netjail",
77 "DEBUG",
78 NULL);
79 GNUNET_SCHEDULER_run (&run,
80 NULL);
81
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
83 "Test finished!\n");
84 return rv;
85}
diff --git a/src/transport/test_transport_simple_send.c b/src/transport/test_transport_simple_send.c
deleted file mode 100644
index 924990d0a..000000000
--- a/src/transport/test_transport_simple_send.c
+++ /dev/null
@@ -1,86 +0,0 @@
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 transport/test_transport_api_cmd_simple_send.c
23 * @brief Test case executing a script which sends a test message between two peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
31
32/**
33 * Return value of the test.
34 *
35 */
36static unsigned int rv = 0;
37
38
39/**
40 * Main function to run the test cases.
41 *
42 * @param cls not used.
43 *
44 */
45static void
46run (void *cls)
47{
48 struct GNUNET_TESTING_Command commands[] = {
49 GNUNET_TESTING_cmd_netjail_start ("netjail-start",
50 "2",
51 "1"),
52 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed",
53 "2",
54 "1",
55 "libgnunet_test_transport_plugin_cmd_simple_send",
56 &rv),
57 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
58 "netjail-start-testbed",
59 "2",
60 "1"),
61 GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
62 "2",
63 "1"),
64 GNUNET_TESTING_cmd_end ()
65 };
66
67 GNUNET_TESTING_run (NULL,
68 commands,
69 TIMEOUT);
70}
71
72
73int
74main (int argc,
75 char *const *argv)
76{
77 GNUNET_log_setup ("test-netjail",
78 "DEBUG",
79 NULL);
80 GNUNET_SCHEDULER_run (&run,
81 NULL);
82
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
84 "Test finished!\n");
85 return rv;
86}
diff --git a/src/transport/test_transport_simple_send.sh b/src/transport/test_transport_simple_send.sh
index 25d5b6797..2dd269fcc 100755
--- a/src/transport/test_transport_simple_send.sh
+++ b/src/transport/test_transport_simple_send.sh
@@ -1,2 +1,2 @@
1#!/bin/bash 1#!/bin/bash
2exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_simple_send" 2exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_topo.conf"
diff --git a/src/transport/test_transport_simple_send_v2.c b/src/transport/test_transport_simple_send_v2.c
deleted file mode 100644
index aeac1bfb6..000000000
--- a/src/transport/test_transport_simple_send_v2.c
+++ /dev/null
@@ -1,83 +0,0 @@
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 transport/test_transport_api_cmd_simple_send.c
23 * @brief Test case executing a script which sends a test message between two peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
31
32#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
33
34/**
35 * Return value of the test.
36 *
37 */
38static unsigned int rv = 0;
39
40
41/**
42 * Main function to run the test cases.
43 *
44 * @param cls not used.
45 *
46 */
47static void
48run (void *cls)
49{
50 struct GNUNET_TESTING_Command commands[] = {
51 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
52 TOPOLOGY_CONFIG),
53 GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed",
54 TOPOLOGY_CONFIG,
55 &rv),
56 GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed",
57 "netjail-start-testbed",
58 TOPOLOGY_CONFIG),
59 GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
60 TOPOLOGY_CONFIG),
61 GNUNET_TESTING_cmd_end ()
62 };
63
64 GNUNET_TESTING_run (NULL,
65 commands,
66 TIMEOUT);
67}
68
69
70int
71main (int argc,
72 char *const *argv)
73{
74 GNUNET_log_setup ("test-netjail",
75 "DEBUG",
76 NULL);
77 GNUNET_SCHEDULER_run (&run,
78 NULL);
79
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Test finished!\n");
82 return rv;
83}
diff --git a/src/transport/test_transport_simple_send_v2.sh b/src/transport/test_transport_simple_send_v2.sh
deleted file mode 100755
index 8462d1849..000000000
--- a/src/transport/test_transport_simple_send_v2.sh
+++ /dev/null
@@ -1,2 +0,0 @@
1#!/bin/bash
2exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_simple_send_v2"
diff --git a/src/transport/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c
index 795c157d7..932b0e583 100644
--- a/src/transport/test_transport_start_with_config.c
+++ b/src/transport/test_transport_start_with_config.c
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file transport/test_transport_start_with_config.c 22 * @file transport/test_transport_start_with_config.c
23 * @brief Test case executing a script which sends a test message between two peers. 23 * @brief Generic program to start testcases in an configurable topology.
24 * @author t3sserakt 24 * @author t3sserakt
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
@@ -29,57 +29,32 @@
29 29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
31 31
32/**
33 * Return value of the test.
34 *
35 */
36static unsigned int rv = 0;
37
38static char *topology_config;
39
40/**
41 * Main function to run the test cases.
42 *
43 * @param cls not used.
44 *
45 */
46static void
47run (void *cls)
48{
49 struct GNUNET_TESTING_Command commands[] = {
50 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
51 topology_config),
52 GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed",
53 topology_config,
54 &rv),
55 GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed",
56 "netjail-start-testbed",
57 topology_config),
58 GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
59 topology_config),
60 GNUNET_TESTING_cmd_end ()
61 };
62
63 GNUNET_TESTING_run (NULL,
64 commands,
65 TIMEOUT);
66}
67
68 32
69int 33int
70main (int argc, 34main (int argc,
71 char *const *argv) 35 char *const *argv)
72{ 36{
37 char *topology_config;
38
73 GNUNET_log_setup ("test-netjail", 39 GNUNET_log_setup ("test-netjail",
74 "DEBUG", 40 "DEBUG",
75 NULL); 41 NULL);
76 42
77 topology_config = argv[1]; 43 topology_config = argv[1];
78 44
79 GNUNET_SCHEDULER_run (&run, 45 struct GNUNET_TESTING_Command commands[] = {
80 NULL); 46 GNUNET_TESTING_cmd_netjail_start ("netjail-start",
47 topology_config),
48 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed",
49 topology_config),
50 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
51 "netjail-start-testbed",
52 topology_config),
53 GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
54 topology_config),
55 GNUNET_TESTING_cmd_end ()
56 };
81 57
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 58 return GNUNET_TESTING_main (commands,
83 "Test finished!\n"); 59 TIMEOUT);
84 return rv;
85} 60}
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index ecdabd35f..f6e34df62 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -29,92 +29,71 @@
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31 31
32struct StartPeerState_v2 32/**
33 * Struct to store information needed in callbacks.
34 *
35 */
36struct ConnectPeersState
33{ 37{
34 /** 38 /**
35 * The ip of a node. 39 * Context for our asynchronous completion.
36 */
37 char *node_ip;
38
39 /**
40 * Receive callback
41 */ 40 */
42 struct GNUNET_MQ_MessageHandler *handlers; 41 struct GNUNET_TESTING_AsyncContext ac;
43 42
44 const char *cfgname; 43 GNUNET_TRANSPORT_NotifyConnect notify_connect;
45 44
46 /** 45 /**
47 * Peer's configuration 46 * The testing system of this node.
48 */ 47 */
49 struct GNUNET_CONFIGURATION_Handle *cfg; 48 struct GNUNET_TESTING_System *tl_system;
50
51 struct GNUNET_TESTING_Peer *peer;
52 49
53 /** 50 // Label of the cmd which started the test system.
54 * Peer identity 51 const char *create_label;
55 */
56 struct GNUNET_PeerIdentity id;
57 52
58 /** 53 /**
59 * Peer's transport service handle 54 * Number globally identifying the node.
55 *
60 */ 56 */
61 struct GNUNET_TRANSPORT_CoreHandle *th; 57 uint32_t num;
62 58
63 /** 59 /**
64 * Application handle 60 * Label of the cmd to start a peer.
61 *
65 */ 62 */
66 struct GNUNET_TRANSPORT_ApplicationHandle *ah; 63 const char *start_peer_label;
67 64
68 /** 65 /**
69 * Peer's PEERSTORE Handle 66 * The peer identity of this peer.
67 *
70 */ 68 */
71 struct GNUNET_PEERSTORE_Handle *ph; 69 struct GNUNET_PeerIdentity *id;
72 70
73 /** 71 /**
74 * Hello get task 72 * The topology of the test setup.
75 */ 73 */
76 struct GNUNET_SCHEDULER_Task *rh_task; 74 struct GNUNET_TESTING_NetjailTopology *topology;
77 75
78 /** 76 /**
79 * Peer's transport get hello handle to retrieve peer's HELLO message 77 * Connections to other peers.
80 */ 78 */
81 struct GNUNET_PEERSTORE_IterateContext *pic; 79 struct GNUNET_TESTING_NodeConnection *node_connections_head;
82 80
83 /** 81 struct GNUNET_TESTING_Interpreter *is;
84 * Hello
85 */
86 char *hello;
87 82
88 /** 83 /**
89 * Hello size 84 * Number of connections.
90 */ 85 */
91 size_t hello_size; 86 unsigned int con_num;
92
93 char *m;
94
95 char *n;
96
97 char *local_m;
98
99 unsigned int finished;
100
101 const char *system_label;
102
103 /**
104 * An unique number to identify the peer
105 */
106 unsigned int no;
107
108 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
109
110 struct GNUNET_TESTING_System *tl_system;
111
112}; 87};
113 88
114
115struct StartPeerState 89struct StartPeerState
116{ 90{
117 /** 91 /**
92 * Context for our asynchronous completion.
93 */
94 struct GNUNET_TESTING_AsyncContext ac;
95
96 /**
118 * The ip of a node. 97 * The ip of a node.
119 */ 98 */
120 char *node_ip; 99 char *node_ip;
@@ -179,8 +158,6 @@ struct StartPeerState
179 158
180 char *local_m; 159 char *local_m;
181 160
182 unsigned int finished;
183
184 const char *system_label; 161 const char *system_label;
185 162
186 /** 163 /**
@@ -192,9 +169,24 @@ struct StartPeerState
192 169
193 struct GNUNET_TESTING_System *tl_system; 170 struct GNUNET_TESTING_System *tl_system;
194 171
172 GNUNET_TRANSPORT_NotifyConnect notify_connect;
173
195}; 174};
196 175
197 176
177/**
178 * Function to get the trait with the struct ConnectPeersState.
179 *
180 * @param[out] sps struct ConnectPeersState.
181 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
182 *
183 */
184int
185GNUNET_TESTING_get_trait_connect_peer_state (
186 const struct GNUNET_TESTING_Command *cmd,
187 struct ConnectPeersState **cps);
188
189
198int 190int
199GNUNET_TRANSPORT_get_trait_state (const struct 191GNUNET_TRANSPORT_get_trait_state (const struct
200 GNUNET_TESTING_Command 192 GNUNET_TESTING_Command
@@ -203,61 +195,28 @@ GNUNET_TRANSPORT_get_trait_state (const struct
203 195
204 196
205struct GNUNET_TESTING_Command 197struct GNUNET_TESTING_Command
206GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
207 const char *system_label,
208 uint32_t no,
209 char *node_ip,
210 struct GNUNET_MQ_MessageHandler *handlers,
211 const char *cfgname);
212
213struct GNUNET_TESTING_Command
214GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label,
215 const char *system_label,
216 uint32_t no,
217 char *node_ip,
218 struct GNUNET_MQ_MessageHandler *handlers,
219 const char *cfgname);
220
221struct GNUNET_TESTING_Command
222GNUNET_TRANSPORT_cmd_start_peer (const char *label, 198GNUNET_TRANSPORT_cmd_start_peer (const char *label,
223 const char *system_label, 199 const char *system_label,
224 char *m, 200 uint32_t no,
225 char *n,
226 char *local_m,
227 char *node_ip, 201 char *node_ip,
228 struct GNUNET_MQ_MessageHandler *handlers, 202 struct GNUNET_MQ_MessageHandler *handlers,
229 const char *cfgname); 203 const char *cfgname,
204 GNUNET_TRANSPORT_NotifyConnect notify_connect);
205
230 206
231struct GNUNET_TESTING_Command 207struct GNUNET_TESTING_Command
232GNUNET_TRANSPORT_cmd_stop_peer (const char *label, 208GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
233 const char *start_label); 209 const char *start_label);
234 210
211
235struct GNUNET_TESTING_Command 212struct GNUNET_TESTING_Command
236GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 213GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
237 const char *start_peer_label, 214 const char *start_peer_label,
238 const char *create_label, 215 const char *create_label,
239 uint32_t num); 216 uint32_t num,
240 217 struct GNUNET_TESTING_NetjailTopology *
241struct GNUNET_TESTING_Command 218 topology);
242GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
243 const char *start_peer_label,
244 const char *create_label,
245 uint32_t num);
246
247struct GNUNET_TESTING_Command
248GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
249 const char *start_peer_label,
250 const char *create_label,
251 uint32_t num,
252 struct GNUNET_TESTING_NetjailTopology *
253 topology);
254 219
255struct GNUNET_TESTING_Command
256GNUNET_TRANSPORT_cmd_send_simple (const char *label,
257 char *m,
258 char *n,
259 uint32_t num,
260 const char *start_peer_label);
261 220
262/** 221/**
263 * Create command. 222 * Create command.
@@ -270,43 +229,29 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
270 * @return command. 229 * @return command.
271 */ 230 */
272struct GNUNET_TESTING_Command 231struct GNUNET_TESTING_Command
273GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label, 232GNUNET_TRANSPORT_cmd_send_simple (const char *label,
274 const char *start_peer_label, 233 const char *start_peer_label,
275 uint32_t num); 234 uint32_t num);
235
236
237
238
276 239
277int 240int
278GNUNET_TRANSPORT_get_trait_peer_id (const struct 241GNUNET_TRANSPORT_get_trait_peer_id (const struct
279 GNUNET_TESTING_Command *cmd, 242 GNUNET_TESTING_Command *cmd,
280 struct GNUNET_PeerIdentity **id); 243 struct GNUNET_PeerIdentity **id);
281 244
245
282int 246int
283GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct 247GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
284 GNUNET_TESTING_Command 248 GNUNET_TESTING_Command
285 *cmd, 249 *cmd,
286 struct 250 struct
287 GNUNET_CONTAINER_MultiShortmap * 251 GNUNET_CONTAINER_MultiShortmap
252 *
288 * 253 *
289 connected_peers_map); 254 connected_peers_map);
290
291int
292GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct
293 GNUNET_TESTING_Command
294 *cmd,
295 struct
296 GNUNET_CONTAINER_MultiShortmap
297 *
298 *
299 connected_peers_map);
300
301int
302GNUNET_TRANSPORT_get_trait_connected_peers_map_v3 (const struct
303 GNUNET_TESTING_Command
304 *cmd,
305 struct
306 GNUNET_CONTAINER_MultiShortmap
307 *
308 *
309 connected_peers_map);
310int 255int
311GNUNET_TRANSPORT_get_trait_hello_size (const struct 256GNUNET_TRANSPORT_get_trait_hello_size (const struct
312 GNUNET_TESTING_Command 257 GNUNET_TESTING_Command
@@ -327,19 +272,5 @@ GNUNET_TRANSPORT_get_trait_application_handle (const struct
327 GNUNET_TRANSPORT_ApplicationHandle 272 GNUNET_TRANSPORT_ApplicationHandle
328 **ah); 273 **ah);
329 274
330int
331GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
332 GNUNET_TESTING_Command *cmd,
333 struct
334 GNUNET_TRANSPORT_ApplicationHandle
335 **ah);
336
337int
338GNUNET_TRANSPORT_get_trait_application_handle_v3 (const struct
339 GNUNET_TESTING_Command *cmd,
340 struct
341 GNUNET_TRANSPORT_ApplicationHandle
342 **ah);
343
344#endif 275#endif
345/* end of transport_testing.h */ 276/* end of transport_testing.h */
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 82194ff15..2e51363f6 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -36,40 +36,240 @@
36 */ 36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38 38
39/** 39#define CONNECT_ADDRESS_TEMPLATE_TCP "tcp-192.168.15.%u:60002"
40 * Struct to store information needed in callbacks. 40
41 * 41#define CONNECT_ADDRESS_TEMPLATE_UDP "udp-192.168.15.%u:60002"
42 */ 42
43struct ConnectPeersState 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
56
57
58static struct GNUNET_PeerIdentity *
59get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
44{ 60{
45 /** 61 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
46 * Context for our asynchronous completion. 62 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
47 */ 63 GNUNET_CRYPTO_EddsaPublicKey);
48 struct GNUNET_TESTING_AsyncContext ac; 64 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
49 65 GNUNET_CRYPTO_EddsaPrivateKey);
50 // Label of the cmd which started the test system. 66
51 const char *create_label; 67 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
52 68 num,
53 /** 69 peer);
54 * Number globally identifying the node. 70
55 * 71 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
56 */ 72 pub_key);
57 uint32_t num; 73 peer->public_key = *pub_key;
74 return peer;
75}
76
77
78static int
79log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
80{
81 struct GNUNET_TESTING_NetjailNode *node = value;
82 struct GNUNET_TESTING_NodeConnection *pos_connection;
83 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
84
85 LOG (GNUNET_ERROR_TYPE_ERROR,
86 "plugin: %s space: %u node: %u global: %u\n",
87 node->plugin,
88 node->namespace_n,
89 node->node_n,
90 node->is_global);
91
92 for (pos_connection = node->node_connections_head; NULL != pos_connection;
93 pos_connection = pos_connection->next)
94 {
95
96 LOG (GNUNET_ERROR_TYPE_ERROR,
97 "namespace_n: %u node_n: %u node_type: %u\n",
98 pos_connection->namespace_n,
99 pos_connection->node_n,
100 pos_connection->node_type);
101
102 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
103 pos_prefix =
104 pos_prefix->next)
105 {
106 LOG (GNUNET_ERROR_TYPE_ERROR,
107 "prefix: %s\n",
108 pos_prefix->address_prefix);
109 }
110 }
111 return GNUNET_YES;
112}
113
114
115static int
116log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
117{
118 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
119 struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
120
121 LOG (GNUNET_ERROR_TYPE_ERROR,
122 "router_tcp: %u router_udp: %u spaces: %u\n",
123 router->tcp_port,
124 router->udp_port,
125 namespace->namespace_n);
126 GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
127 return GNUNET_YES;
128}
129
130
131static int
132log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
133{
134 LOG (GNUNET_ERROR_TYPE_ERROR,
135 "plugin: %s spaces: %u nodes: %u known: %u\n",
136 topology->plugin,
137 topology->namespaces_n,
138 topology->nodes_m,
139 topology->nodes_x);
140
141 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
142 log_namespaces, NULL);
143 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
144 NULL);
145 return GNUNET_YES;
146}
147
148
149static struct GNUNET_TESTING_NodeConnection *
150get_connections (unsigned int num, struct
151 GNUNET_TESTING_NetjailTopology *topology)
152{
153 struct GNUNET_TESTING_NetjailNode *node;
154 struct GNUNET_ShortHashCode *hkey;
155 struct GNUNET_HashCode hc;
156 struct GNUNET_TESTING_NetjailNamespace *namespace;
157 unsigned int namespace_n, node_m;
158
159 log_topo (topology);
160
161 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
162 if (topology->nodes_x >= num)
163 {
164
165 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
166 memcpy (hkey,
167 &hc,
168 sizeof (*hkey));
169 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
170 hkey);
171 }
172 else
173 {
174 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
175 / topology->nodes_m);
176 LOG (GNUNET_ERROR_TYPE_ERROR,
177 "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
178 num,
179 topology->nodes_x,
180 topology->nodes_m,
181 namespace_n);
182 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
183 GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
184 memcpy (hkey,
185 &hc,
186 sizeof (*hkey));
187 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
188 hkey);
189 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
190 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
191 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
192 memcpy (hkey,
193 &hc,
194 sizeof (*hkey));
195 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
196 hkey);
197 }
198
199
200 return node->node_connections_head;
201}
58 202
59 /**
60 * Label of the cmd to start a peer.
61 *
62 */
63 const char *start_peer_label;
64 203
65 /** 204static unsigned int
66 * The peer identity of this peer. 205calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
67 * 206 struct GNUNET_TESTING_NetjailTopology *topology)
68 */ 207{
69 struct GNUNET_PeerIdentity *id; 208 unsigned int n, m, num;
209
210 n = node_connection->namespace_n;
211 m = node_connection->node_n;
70 212
71 struct GNUNET_TESTING_Interpreter *is; 213 if (0 == n)
72}; 214 num = m;
215 else
216 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
217
218 return num;
219}
220
221
222static char *
223get_address (struct GNUNET_TESTING_NodeConnection *connection,
224 char *prefix)
225{
226 struct GNUNET_TESTING_NetjailNode *node;
227 char *addr;
228
229 node = connection->node;
230 if (connection->namespace_n == node->namespace_n)
231 {
232 if (0 == strcmp (PREFIX_TCP, prefix))
233 {
234
235 GNUNET_asprintf (&addr,
236 CONNECT_ADDRESS_TEMPLATE_TCP,
237 connection->node_n);
238 }
239 else if (0 == strcmp (PREFIX_UDP, prefix))
240 {
241 GNUNET_asprintf (&addr,
242 CONNECT_ADDRESS_TEMPLATE_UDP,
243 connection->node_n);
244 }
245 else
246 {
247 GNUNET_break (0);
248 }
249 }
250 else
251 {
252 if (0 == strcmp (PREFIX_TCP, prefix))
253 {
254
255 GNUNET_asprintf (&addr,
256 ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
257 connection->namespace_n);
258 }
259 else if (0 == strcmp (PREFIX_UDP, prefix))
260 {
261 GNUNET_asprintf (&addr,
262 ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
263 connection->namespace_n);
264 }
265 else
266 {
267 GNUNET_break (0);
268 }
269 }
270
271 return addr;
272}
73 273
74 274
75/** 275/**
@@ -83,24 +283,17 @@ connect_peers_run (void *cls,
83 struct ConnectPeersState *cps = cls; 283 struct ConnectPeersState *cps = cls;
84 const struct GNUNET_TESTING_Command *system_cmd; 284 const struct GNUNET_TESTING_Command *system_cmd;
85 struct GNUNET_TESTING_System *tl_system; 285 struct GNUNET_TESTING_System *tl_system;
86 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct 286
87 GNUNET_CRYPTO_EddsaPrivateKey); 287
88 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
89 GNUNET_CRYPTO_EddsaPublicKey);
90 ;
91 const struct GNUNET_TESTING_Command *peer1_cmd; 288 const struct GNUNET_TESTING_Command *peer1_cmd;
92 // const struct GNUNET_TESTING_Command *peer2_cmd;
93 struct GNUNET_TRANSPORT_ApplicationHandle *ah; 289 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
94 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); 290 struct GNUNET_PeerIdentity *peer;
95 char *addr; 291 char *addr;
96 // struct GNUNET_TIME_Absolute t;
97 char *hello;
98 // size_t *hello_size;
99 enum GNUNET_NetworkType nt = 0; 292 enum GNUNET_NetworkType nt = 0;
100 char *peer_id;
101 struct GNUNET_PeerIdentity *id;
102 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
103 uint32_t num; 293 uint32_t num;
294 struct GNUNET_TESTING_NodeConnection *pos_connection;
295 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
296 unsigned int con_num = 0;
104 297
105 cps->is = is; 298 cps->is = is;
106 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 299 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
@@ -108,121 +301,82 @@ connect_peers_run (void *cls,
108 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, 301 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
109 &ah); 302 &ah);
110 303
111 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd,
112 &hello);
113
114 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
115 &id);
116
117 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 304 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
118 cps->create_label); 305 cps->create_label);
119 GNUNET_TESTING_get_trait_test_system (system_cmd, 306 GNUNET_TESTING_get_trait_test_system (system_cmd,
120 &tl_system); 307 &tl_system);
121 308
122 if (2 == cps->num) 309 cps->tl_system = tl_system;
123 num = 1;
124 else
125 num = 2;
126 310
311 cps->node_connections_head = get_connections (cps->num, cps->topology);
127 312
128 // if (strstr (hello, "60002") != NULL) 313 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
129 if (2 == num) 314 pos_connection = pos_connection->next)
130 {
131 addr = "tcp-192.168.15.2:60002";
132 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
133 }
134 else
135 { 315 {
136 addr = "tcp-192.168.15.1:60002"; 316 con_num++;
137 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730"; 317 num = calculate_num (pos_connection, cps->topology);
318 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
319 pos_prefix =
320 pos_prefix->next)
321 {
322
323 LOG (GNUNET_ERROR_TYPE_ERROR,
324 "prefix: %s\n",
325 pos_prefix->address_prefix);
326
327 addr = get_address (pos_connection, pos_prefix->address_prefix);
328
329 peer = get_pub_key (num, tl_system);
330
331 LOG (GNUNET_ERROR_TYPE_ERROR,
332 "num: %u pub_key %s addr: %s\n",
333 num,
334 GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)),
335 addr);
336
337 cps->id = peer;
338
339 GNUNET_TRANSPORT_application_validate (ah,
340 peer,
341 nt,
342 addr);
343 }
138 } 344 }
139 345 cps->con_num = con_num;
140 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
141 num,
142 other);
143
144 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
145 pub_key);
146
147 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
148 strlen (peer_id),
149 &peer->public_key);
150
151 peer->public_key = *pub_key;
152
153 LOG (GNUNET_ERROR_TYPE_ERROR,
154 "\nnum: %u\n peer_id: %s\n pub_key %s\n",
155 num,
156 peer_id,
157 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
158
159 cps->id = peer;
160
161 // TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers.
162 // ---------------------------------------------
163 /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label);
164 GNUNET_TRANSPORT_get_trait_peer_id (peer2_cmd,
165 &id);
166 GNUNET_TRANSPORT_get_trait_hello (peer2_cmd,
167 &hello);
168 GNUNET_TRANSPORT_get_trait_hello_size (peer2_cmd,
169 &hello_size);
170
171 addr = GNUNET_HELLO_extract_address (hello,
172 *hello_size,
173 id,
174 &nt,
175 &t);*/
176
177 // ----------------------------------------------
178
179
180 GNUNET_TRANSPORT_application_validate (ah,
181 peer,
182 nt,
183 addr);
184} 346}
185 347
186 348
187/** 349/**
188 * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer. 350 * Callback from start peer cmd for signaling a peer got connected.
189 * 351 *
190 */ 352 */
191// FIXME: this needs a complete rewrite! 353static void *
192static int 354notify_connect (void *cls,
193connect_peers_finish (void *cls, 355 const struct GNUNET_PeerIdentity *peer,
194 GNUNET_SCHEDULER_TaskCallback cont, 356 struct GNUNET_MQ_Handle *mq)
195 void *cont_cls)
196{ 357{
197 struct ConnectPeersState *cps = cls; 358 struct ConnectPeersState *cps = cls;
198 const struct GNUNET_TESTING_Command *peer1_cmd; 359 struct GNUNET_PeerIdentity *peer_connection;
199 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; 360 unsigned int con_num = 0;
200 unsigned int ret; 361 struct GNUNET_TESTING_NodeConnection *pos_connection;
201 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); 362 unsigned int num;
202 struct GNUNET_HashCode hc; 363 void *ret = NULL;
203 int node_number; 364
204 365 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
205 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is, 366 pos_connection = pos_connection->next)
206 cps->start_peer_label); 367 {
207 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, 368 num = calculate_num (pos_connection, cps->topology);
208 &connected_peers_map); 369 peer_connection = get_pub_key (num, cps->tl_system);
209 370 if (0 == GNUNET_memcmp (peer,
210 node_number = 1; 371 peer_connection))
211 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); 372 con_num++;
373 }
212 374
213 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
214 memcpy (key,
215 &hc,
216 sizeof (*key));
217 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
218 key);
219 375
220 if (GNUNET_YES == ret) 376 if (cps->con_num == con_num)
221 { 377 {
222 cont (cont_cls); 378 GNUNET_TESTING_async_finish (&cps->ac);
223 } 379 }
224
225 GNUNET_free (key);
226 return ret; 380 return ret;
227} 381}
228 382
@@ -241,11 +395,58 @@ connect_peers_cleanup (void *cls)
241} 395}
242 396
243 397
398/**
399 * This function prepares an array with traits.
400 *
401 */
402static int
403connect_peers_traits (void *cls,
404 const void **ret,
405 const char *trait,
406 unsigned int index)
407{
408 struct StartPeerState *cps = cls;
409 struct GNUNET_TESTING_Trait traits[] = {
410 {
411 .index = 0,
412 .trait_name = "state",
413 .ptr = (const void *) cps,
414 },
415 GNUNET_TESTING_trait_end ()
416 };
417 return GNUNET_TESTING_get_trait (traits,
418 ret,
419 trait,
420 index);
421}
422
423
424/**
425 * Function to get the trait with the struct ConnectPeersState.
426 *
427 * @param[out] sps struct ConnectPeersState.
428 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
429 *
430 */
431int
432GNUNET_TESTING_get_trait_connect_peer_state (
433 const struct GNUNET_TESTING_Command *cmd,
434 struct ConnectPeersState **cps)
435{
436 return cmd->traits (cmd->cls,
437 (const void **) cps,
438 "state",
439 (unsigned int) 0);
440}
441
442
244struct GNUNET_TESTING_Command 443struct GNUNET_TESTING_Command
245GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 444GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
246 const char *start_peer_label, 445 const char *start_peer_label,
247 const char *create_label, 446 const char *create_label,
248 uint32_t num) 447 uint32_t num,
448 struct GNUNET_TESTING_NetjailTopology *
449 topology)
249{ 450{
250 struct ConnectPeersState *cps; 451 struct ConnectPeersState *cps;
251 452
@@ -253,6 +454,8 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
253 cps->start_peer_label = start_peer_label; 454 cps->start_peer_label = start_peer_label;
254 cps->num = num; 455 cps->num = num;
255 cps->create_label = create_label; 456 cps->create_label = create_label;
457 cps->topology = topology;
458 cps->notify_connect = &notify_connect;
256 459
257 { 460 {
258 struct GNUNET_TESTING_Command cmd = { 461 struct GNUNET_TESTING_Command cmd = {
@@ -260,7 +463,8 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
260 .label = label, 463 .label = label,
261 .run = &connect_peers_run, 464 .run = &connect_peers_run,
262 .ac = &cps->ac, 465 .ac = &cps->ac,
263 .cleanup = &connect_peers_cleanup 466 .cleanup = &connect_peers_cleanup,
467 .traits = &connect_peers_traits
264 }; 468 };
265 469
266 return cmd; 470 return cmd;
diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c
deleted file mode 100644
index 8d0f74916..000000000
--- a/src/transport/transport_api_cmd_connecting_peers_v2.c
+++ /dev/null
@@ -1,237 +0,0 @@
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 "gnunet_transport_application_service.h"
30#include "gnunet_hello_lib.h"
31#include "gnunet_transport_service.h"
32#include "transport-testing-cmds.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39#define CONNECT_ADDRESS_TEMPLATE "tcp-192.168.15.%u:60002"
40
41/**
42 * Struct to store information needed in callbacks.
43 *
44 */
45struct ConnectPeersState
46{
47 /**
48 * Context for our asynchronous completion.
49 */
50 struct GNUNET_TESTING_AsyncContext ac;
51
52 // Label of the cmd which started the test system.
53 const char *create_label;
54
55 /**
56 * Number globally identifying the node.
57 *
58 */
59 uint32_t num;
60
61 /**
62 * Label of the cmd to start a peer.
63 *
64 */
65 const char *start_peer_label;
66
67 /**
68 * The peer identity of this peer.
69 *
70 */
71 struct GNUNET_PeerIdentity *id;
72
73 struct GNUNET_TESTING_Interpreter *is;
74};
75
76
77/**
78 * The run method of this cmd will connect to peers.
79 *
80 */
81static void
82connect_peers_run (void *cls,
83 struct GNUNET_TESTING_Interpreter *is)
84{
85 struct ConnectPeersState *cps = cls;
86 const struct GNUNET_TESTING_Command *system_cmd;
87 struct GNUNET_TESTING_System *tl_system;
88 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
89 GNUNET_CRYPTO_EddsaPrivateKey);
90 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
91 GNUNET_CRYPTO_EddsaPublicKey);
92 const struct GNUNET_TESTING_Command *peer1_cmd;
93 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
94 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
95 char *addr;
96 enum GNUNET_NetworkType nt = 0;
97 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
98 uint32_t num;
99
100 cps->is = is;
101 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
102 cps->start_peer_label);
103 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
104 &ah);
105
106 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
107 cps->create_label);
108 GNUNET_TESTING_get_trait_test_system (system_cmd,
109 &tl_system);
110
111 if (1 == cps->num)
112 {
113 num = 2;
114 // addr = "tcp-192.168.15.2:60002";
115 }
116 else
117 {
118 num = 1;
119 // addr = "tcp-192.168.15.1:60002";
120 }
121
122 GNUNET_asprintf (&addr,
123 CONNECT_ADDRESS_TEMPLATE,
124 num);
125
126 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
127 num,
128 other);
129
130 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
131 pub_key);
132
133
134 peer->public_key = *pub_key;
135
136 LOG (GNUNET_ERROR_TYPE_ERROR,
137 "num: %u pub_key %s\n",
138 num,
139 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
140
141 cps->id = peer;
142
143 GNUNET_TRANSPORT_application_validate (ah,
144 peer,
145 nt,
146 addr);
147}
148
149
150/**
151 * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer.
152 *
153 */
154static int
155connect_peers_finish (void *cls,
156 GNUNET_SCHEDULER_TaskCallback cont,
157 void *cont_cls)
158{
159 struct ConnectPeersState *cps = cls;
160 const struct GNUNET_TESTING_Command *peer1_cmd;
161 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
162 unsigned int ret;
163 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
164 struct GNUNET_HashCode hc;
165 int node_number;
166
167 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is,
168 cps->start_peer_label);
169 GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
170 &connected_peers_map);
171
172 node_number = 1;
173 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
174
175 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
176 memcpy (key,
177 &hc,
178 sizeof (*key));
179 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
180 key);
181
182 if (GNUNET_YES == ret)
183 {
184 cont (cont_cls);
185 }
186
187 GNUNET_free (key);
188 return ret;
189}
190
191
192/**
193 * The cleanup function of this cmd frees resources the cmd allocated.
194 *
195 */
196static void
197connect_peers_cleanup (void *cls)
198{
199 struct ConnectPeersState *cps = cls;
200
201 GNUNET_free (cps->id);
202 GNUNET_free (cps);
203}
204
205
206/**
207 * Create command.
208 *
209 * @param label name for command.
210 * @param start_peer_label Label of the cmd to start a peer.
211 * @return command.
212 */
213struct GNUNET_TESTING_Command
214GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
215 const char *start_peer_label,
216 const char *create_label,
217 uint32_t num)
218{
219 struct ConnectPeersState *cps;
220
221 cps = GNUNET_new (struct ConnectPeersState);
222 cps->start_peer_label = start_peer_label;
223 cps->num = num;
224 cps->create_label = create_label;
225
226 {
227 struct GNUNET_TESTING_Command cmd = {
228 .cls = cps,
229 .label = label,
230 .run = &connect_peers_run,
231 .ac = &cps->ac,
232 .cleanup = &connect_peers_cleanup
233 };
234
235 return cmd;
236 }
237}
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c
deleted file mode 100644
index ae32a087a..000000000
--- a/src/transport/transport_api_cmd_connecting_peers_v3.c
+++ /dev/null
@@ -1,496 +0,0 @@
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 "gnunet_transport_application_service.h"
30#include "gnunet_hello_lib.h"
31#include "gnunet_transport_service.h"
32#include "transport-testing-cmds.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
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/**
56 * Struct to store information needed in callbacks.
57 *
58 */
59struct ConnectPeersState
60{
61 /**
62 * Context for our asynchronous completion.
63 */
64 struct GNUNET_TESTING_AsyncContext ac;
65
66 /**
67 * The testing system of this node.
68 */
69 struct GNUNET_TESTING_System *tl_system;
70
71 // Label of the cmd which started the test system.
72 const char *create_label;
73
74 /**
75 * Number globally identifying the node.
76 *
77 */
78 uint32_t num;
79
80 /**
81 * Label of the cmd to start a peer.
82 *
83 */
84 const char *start_peer_label;
85
86 /**
87 * The peer identity of this peer.
88 *
89 */
90 struct GNUNET_PeerIdentity *id;
91
92 /**
93 * The topology of the test setup.
94 */
95 struct GNUNET_TESTING_NetjailTopology *topology;
96
97 /**
98 * Connections to other peers.
99 */
100 struct GNUNET_TESTING_NodeConnection *node_connections_head;
101
102 struct GNUNET_TESTING_Interpreter *is;
103
104 /**
105 * Number of connections.
106 */
107 unsigned int con_num;
108};
109
110
111static struct GNUNET_PeerIdentity *
112get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
113{
114 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
115 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
116 GNUNET_CRYPTO_EddsaPublicKey);
117 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
118 GNUNET_CRYPTO_EddsaPrivateKey);
119
120 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
121 num,
122 peer);
123
124 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
125 pub_key);
126 peer->public_key = *pub_key;
127 return peer;
128}
129
130
131static int
132log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
133{
134 struct GNUNET_TESTING_NetjailNode *node = value;
135 struct GNUNET_TESTING_NodeConnection *pos_connection;
136 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
137
138 LOG (GNUNET_ERROR_TYPE_ERROR,
139 "plugin: %s space: %u node: %u global: %u\n",
140 node->plugin,
141 node->namespace_n,
142 node->node_n,
143 node->is_global);
144
145 for (pos_connection = node->node_connections_head; NULL != pos_connection;
146 pos_connection = pos_connection->next)
147 {
148
149 LOG (GNUNET_ERROR_TYPE_ERROR,
150 "namespace_n: %u node_n: %u node_type: %u\n",
151 pos_connection->namespace_n,
152 pos_connection->node_n,
153 pos_connection->node_type);
154
155 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
156 pos_prefix =
157 pos_prefix->next)
158 {
159 LOG (GNUNET_ERROR_TYPE_ERROR,
160 "prefix: %s\n",
161 pos_prefix->address_prefix);
162 }
163 }
164 return GNUNET_YES;
165}
166
167
168static int
169log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
170{
171 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
172 struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
173
174 LOG (GNUNET_ERROR_TYPE_ERROR,
175 "router_tcp: %u router_udp: %u spaces: %u\n",
176 router->tcp_port,
177 router->udp_port,
178 namespace->namespace_n);
179 GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
180 return GNUNET_YES;
181}
182
183
184static int
185log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
186{
187 LOG (GNUNET_ERROR_TYPE_ERROR,
188 "plugin: %s spaces: %u nodes: %u known: %u\n",
189 topology->plugin,
190 topology->namespaces_n,
191 topology->nodes_m,
192 topology->nodes_x);
193
194 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
195 log_namespaces, NULL);
196 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
197 NULL);
198 return GNUNET_YES;
199}
200
201
202static struct GNUNET_TESTING_NodeConnection *
203get_connections (unsigned int num, struct
204 GNUNET_TESTING_NetjailTopology *topology)
205{
206 struct GNUNET_TESTING_NetjailNode *node;
207 struct GNUNET_ShortHashCode *hkey;
208 struct GNUNET_HashCode hc;
209 struct GNUNET_TESTING_NetjailNamespace *namespace;
210 unsigned int namespace_n, node_m;
211
212 log_topo (topology);
213
214 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
215 if (topology->nodes_x >= num)
216 {
217
218 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
219 memcpy (hkey,
220 &hc,
221 sizeof (*hkey));
222 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
223 hkey);
224 }
225 else
226 {
227 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
228 / topology->nodes_m);
229 LOG (GNUNET_ERROR_TYPE_ERROR,
230 "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
231 num,
232 topology->nodes_x,
233 topology->nodes_m,
234 namespace_n);
235 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
236 GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
237 memcpy (hkey,
238 &hc,
239 sizeof (*hkey));
240 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
241 hkey);
242 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
243 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
244 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
245 memcpy (hkey,
246 &hc,
247 sizeof (*hkey));
248 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
249 hkey);
250 }
251
252
253 return node->node_connections_head;
254}
255
256
257static unsigned int
258calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
259 struct GNUNET_TESTING_NetjailTopology *topology)
260{
261 unsigned int n, m, num;
262
263 n = node_connection->namespace_n;
264 m = node_connection->node_n;
265
266 if (0 == n)
267 num = m;
268 else
269 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
270
271 return num;
272}
273
274
275static char *
276get_address (struct GNUNET_TESTING_NodeConnection *connection,
277 char *prefix)
278{
279 struct GNUNET_TESTING_NetjailNode *node;
280 char *addr;
281
282 node = connection->node;
283 if (connection->namespace_n == node->namespace_n)
284 {
285 if (0 == strcmp (PREFIX_TCP, prefix))
286 {
287
288 GNUNET_asprintf (&addr,
289 CONNECT_ADDRESS_TEMPLATE_TCP,
290 connection->node_n);
291 }
292 else if (0 == strcmp (PREFIX_UDP, prefix))
293 {
294 GNUNET_asprintf (&addr,
295 CONNECT_ADDRESS_TEMPLATE_UDP,
296 connection->node_n);
297 }
298 else
299 {
300 GNUNET_break (0);
301 }
302 }
303 else
304 {
305 if (0 == strcmp (PREFIX_TCP, prefix))
306 {
307
308 GNUNET_asprintf (&addr,
309 ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
310 connection->namespace_n);
311 }
312 else if (0 == strcmp (PREFIX_UDP, prefix))
313 {
314 GNUNET_asprintf (&addr,
315 ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
316 connection->namespace_n);
317 }
318 else
319 {
320 GNUNET_break (0);
321 }
322 }
323
324 return addr;
325}
326
327
328/**
329 * The run method of this cmd will connect to peers.
330 *
331 */
332static void
333connect_peers_run (void *cls,
334 struct GNUNET_TESTING_Interpreter *is)
335{
336 struct ConnectPeersState *cps = cls;
337 const struct GNUNET_TESTING_Command *system_cmd;
338 struct GNUNET_TESTING_System *tl_system;
339
340
341 const struct GNUNET_TESTING_Command *peer1_cmd;
342 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
343 struct GNUNET_PeerIdentity *peer;
344 char *addr;
345 enum GNUNET_NetworkType nt = 0;
346 uint32_t num;
347 struct GNUNET_TESTING_NodeConnection *pos_connection;
348 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
349 unsigned int con_num = 0;
350
351 cps->is = is;
352 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
353 cps->start_peer_label);
354 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
355 &ah);
356
357 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
358 cps->create_label);
359 GNUNET_TESTING_get_trait_test_system (system_cmd,
360 &tl_system);
361
362 cps->tl_system = tl_system;
363
364 cps->node_connections_head = get_connections (cps->num, cps->topology);
365
366 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
367 pos_connection = pos_connection->next)
368 {
369 con_num++;
370 num = calculate_num (pos_connection, cps->topology);
371 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
372 pos_prefix =
373 pos_prefix->next)
374 {
375
376 LOG (GNUNET_ERROR_TYPE_ERROR,
377 "prefix: %s\n",
378 pos_prefix->address_prefix);
379
380 addr = get_address (pos_connection, pos_prefix->address_prefix);
381
382 peer = get_pub_key (num, tl_system);
383
384 LOG (GNUNET_ERROR_TYPE_ERROR,
385 "num: %u pub_key %s addr: %s\n",
386 num,
387 GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)),
388 addr);
389
390 cps->id = peer;
391
392 GNUNET_TRANSPORT_application_validate (ah,
393 peer,
394 nt,
395 addr);
396 }
397 }
398 cps->con_num = con_num;
399}
400
401
402/**
403 * The finish function of this cmd will check if the peers we are trying to
404 * connect to are in the connected peers map of the start peer cmd for this peer.
405 *
406 */
407static int
408connect_peers_finish (void *cls,
409 GNUNET_SCHEDULER_TaskCallback cont,
410 void *cont_cls)
411{
412 struct ConnectPeersState *cps = cls;
413 const struct GNUNET_TESTING_Command *peer1_cmd;
414 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
415 unsigned int ret;
416 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
417 struct GNUNET_HashCode hc;
418 struct GNUNET_PeerIdentity *peer;
419 unsigned int con_num = 0;
420 struct GNUNET_TESTING_NodeConnection *pos_connection;
421 unsigned int num;
422
423 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is,
424 cps->start_peer_label);
425 GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
426 &connected_peers_map);
427
428 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
429 pos_connection = pos_connection->next)
430 {
431 num = calculate_num (pos_connection, cps->topology);
432 peer = get_pub_key (num, cps->tl_system);
433 GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc);
434 memcpy (key,
435 &hc,
436 sizeof (*key));
437 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
438 connected_peers_map,
439 key))
440 con_num++;
441 }
442
443
444 if (cps->con_num == con_num)
445 {
446 cont (cont_cls);
447 ret = GNUNET_YES;
448 }
449
450 GNUNET_free (key);
451 return ret;
452}
453
454
455/**
456 * The cleanup function of this cmd frees resources the cmd allocated.
457 *
458 */
459static void
460connect_peers_cleanup (void *cls)
461{
462 struct ConnectPeersState *cps = cls;
463
464 GNUNET_free (cps->id);
465 GNUNET_free (cps);
466}
467
468
469struct GNUNET_TESTING_Command
470GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
471 const char *start_peer_label,
472 const char *create_label,
473 uint32_t num,
474 struct GNUNET_TESTING_NetjailTopology *
475 topology)
476{
477 struct ConnectPeersState *cps;
478
479 cps = GNUNET_new (struct ConnectPeersState);
480 cps->start_peer_label = start_peer_label;
481 cps->num = num;
482 cps->create_label = create_label;
483 cps->topology = topology;
484
485 {
486 struct GNUNET_TESTING_Command cmd = {
487 .cls = cps,
488 .label = label,
489 .run = &connect_peers_run,
490 .ac = &cps->ac,
491 .cleanup = &connect_peers_cleanup
492 };
493
494 return cmd;
495 }
496}
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
index 1599dfe97..0631f7051 100644
--- a/src/transport/transport_api_cmd_send_simple.c
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -36,18 +36,6 @@
36struct SendSimpleState 36struct SendSimpleState
37{ 37{
38 /** 38 /**
39 * The number of the local node of the actual network namespace.
40 *
41 */
42 char *m;
43
44 /**
45 * The number of the actual namespace.
46 *
47 */
48 char *n;
49
50 /**
51 * Number globally identifying the node. 39 * Number globally identifying the node.
52 * 40 *
53 */ 41 */
@@ -146,16 +134,12 @@ send_simple_run (void *cls,
146 */ 134 */
147struct GNUNET_TESTING_Command 135struct GNUNET_TESTING_Command
148GNUNET_TRANSPORT_cmd_send_simple (const char *label, 136GNUNET_TRANSPORT_cmd_send_simple (const char *label,
149 char *m, 137 const char *start_peer_label,
150 char *n, 138 uint32_t num)
151 uint32_t num,
152 const char *start_peer_label)
153{ 139{
154 struct SendSimpleState *sss; 140 struct SendSimpleState *sss;
155 141
156 sss = GNUNET_new (struct SendSimpleState); 142 sss = GNUNET_new (struct SendSimpleState);
157 sss->m = m;
158 sss->n = n;
159 sss->num = num; 143 sss->num = num;
160 sss->start_peer_label = start_peer_label; 144 sss->start_peer_label = start_peer_label;
161 { 145 {
diff --git a/src/transport/transport_api_cmd_send_simple_v2.c b/src/transport/transport_api_cmd_send_simple_v2.c
deleted file mode 100644
index 8d65eb684..000000000
--- a/src/transport/transport_api_cmd_send_simple_v2.c
+++ /dev/null
@@ -1,156 +0,0 @@
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
52/**
53 * Trait function of this cmd does nothing.
54 *
55 */
56static int
57send_simple_traits (void *cls,
58 const void **ret,
59 const char *trait,
60 unsigned int index)
61{
62 return GNUNET_OK;
63}
64
65
66/**
67 * The cleanup function of this cmd frees resources the cmd allocated.
68 *
69 */
70static void
71send_simple_cleanup (void *cls)
72{
73 struct SendSimpleState *sss = cls;
74
75 GNUNET_free (sss);
76}
77
78
79/**
80 * The run method of this cmd will send a simple message to the connected peer.
81 *
82 */
83static void
84send_simple_run (void *cls,
85 struct GNUNET_TESTING_Interpreter *is)
86{
87 struct SendSimpleState *sss = cls;
88 struct GNUNET_MQ_Envelope *env;
89 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
90 struct GNUNET_MQ_Handle *mq;
91 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
92 const struct GNUNET_TESTING_Command *peer1_cmd;
93 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
94 struct GNUNET_HashCode hc;
95 int node_number;
96
97 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
98 sss->start_peer_label);
99 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
100 &connected_peers_map);
101
102 node_number = 1;
103 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
104 memcpy (key,
105 &hc,
106 sizeof (*key));
107
108 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
109 key);
110
111 env = GNUNET_MQ_msg_extra (test,
112 2600 - sizeof(*test),
113 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
114 test->num = htonl (sss->num);
115 memset (&test[1],
116 sss->num,
117 2600 - sizeof(*test));
118 GNUNET_MQ_send (mq,
119 env);
120 GNUNET_free (key);
121
122}
123
124
125/**
126 * Create command.
127 *
128 * @param label name for command.
129 * @param m The number of the local node of the actual network namespace.
130 * @param n The number of the actual namespace.
131 * @param num Number globally identifying the node.
132 * @param start_peer_label Label of the cmd to start a peer.
133 * @return command.
134 */
135struct GNUNET_TESTING_Command
136GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label,
137 const char *start_peer_label,
138 uint32_t num)
139{
140 struct SendSimpleState *sss;
141
142 sss = GNUNET_new (struct SendSimpleState);
143 sss->num = num;
144 sss->start_peer_label = start_peer_label;
145 {
146 struct GNUNET_TESTING_Command cmd = {
147 .cls = sss,
148 .label = label,
149 .run = &send_simple_run,
150 .cleanup = &send_simple_cleanup,
151 .traits = &send_simple_traits
152 };
153
154 return cmd;
155 }
156}
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index 44fc68807..dc19f10eb 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -51,7 +51,6 @@ hello_iter_cb (void *cb_cls,
51 const char *emsg) 51 const char *emsg)
52{ 52{
53 struct StartPeerState *sps = cb_cls; 53 struct StartPeerState *sps = cb_cls;
54
55 if (NULL == record) 54 if (NULL == record)
56 { 55 {
57 sps->pic = NULL; 56 sps->pic = NULL;
@@ -66,7 +65,7 @@ hello_iter_cb (void *cb_cls,
66 65
67 GNUNET_PEERSTORE_iterate_cancel (sps->pic); 66 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
68 sps->pic = NULL; 67 sps->pic = NULL;
69 sps->finished = GNUNET_YES; 68 GNUNET_TESTING_async_finish (&sps->ac);
70} 69}
71 70
72 71
@@ -122,7 +121,7 @@ notify_connect (void *cls,
122 struct StartPeerState *sps = cls; 121 struct StartPeerState *sps = cls;
123 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); 122 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
124 struct GNUNET_HashCode hc; 123 struct GNUNET_HashCode hc;
125 int node_number; 124 struct GNUNET_CRYPTO_EddsaPublicKey public_key = peer->public_key;
126 125
127 void *ret = NULL; 126 void *ret = NULL;
128 127
@@ -133,9 +132,7 @@ notify_connect (void *cls,
133 sps->no, 132 sps->no,
134 GNUNET_i2s (&sps->id)); 133 GNUNET_i2s (&sps->id));
135 134
136 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. 135 GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
137 node_number = 1;
138 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
139 136
140 137
141 memcpy (key, 138 memcpy (key,
@@ -147,6 +144,11 @@ notify_connect (void *cls,
147 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 144 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
148 145
149 GNUNET_free (key); 146 GNUNET_free (key);
147
148 sps->notify_connect (cls,
149 peer,
150 mq);
151
150 // TODO what does the handler function need? 152 // TODO what does the handler function need?
151 return ret; 153 return ret;
152} 154}
@@ -167,7 +169,8 @@ start_peer_run (void *cls,
167 struct GNUNET_TESTING_System *tl_system; 169 struct GNUNET_TESTING_System *tl_system;
168 char *home; 170 char *home;
169 char *transport_unix_path; 171 char *transport_unix_path;
170 char *communicator_unix_path; 172 char *tcp_communicator_unix_path;
173 char *udp_communicator_unix_path;
171 char *bindto; 174 char *bindto;
172 175
173 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) 176 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
@@ -192,7 +195,11 @@ start_peer_run (void *cls,
192 "$GNUNET_RUNTIME_DIR/tng-p%u.sock", 195 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
193 sps->no); 196 sps->no);
194 197
195 GNUNET_asprintf (&communicator_unix_path, 198 GNUNET_asprintf (&tcp_communicator_unix_path,
199 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
200 sps->no);
201
202 GNUNET_asprintf (&udp_communicator_unix_path,
196 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", 203 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
197 sps->no); 204 sps->no);
198 205
@@ -200,6 +207,9 @@ start_peer_run (void *cls,
200 "%s:60002", 207 "%s:60002",
201 sps->node_ip); 208 sps->node_ip);
202 209
210 LOG (GNUNET_ERROR_TYPE_ERROR,
211 "node_ip %s\n",
212 bindto);
203 213
204 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME", 214 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
205 home); 215 home);
@@ -208,9 +218,15 @@ start_peer_run (void *cls,
208 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", 218 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
209 "BINDTO", 219 "BINDTO",
210 bindto); 220 bindto);
221 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
222 "BINDTO",
223 bindto);
211 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", 224 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
212 "UNIXPATH", 225 "UNIXPATH",
213 communicator_unix_path); 226 tcp_communicator_unix_path);
227 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
228 "UNIXPATH",
229 udp_communicator_unix_path);
214 230
215 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 231 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
216 sps->system_label); 232 sps->system_label);
@@ -417,10 +433,9 @@ start_peer_traits (void *cls,
417 * 433 *
418 */ 434 */
419int 435int
420GNUNET_TRANSPORT_get_trait_state (const struct 436GNUNET_TRANSPORT_get_trait_state (
421 GNUNET_TESTING_Command 437 const struct GNUNET_TESTING_Command *cmd,
422 *cmd, 438 struct StartPeerState **sps)
423 struct StartPeerState **sps)
424{ 439{
425 return cmd->traits (cmd->cls, 440 return cmd->traits (cmd->cls,
426 (const void **) sps, 441 (const void **) sps,
@@ -481,7 +496,8 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
481 GNUNET_TESTING_Command 496 GNUNET_TESTING_Command
482 *cmd, 497 *cmd,
483 struct 498 struct
484 GNUNET_CONTAINER_MultiShortmap * 499 GNUNET_CONTAINER_MultiShortmap
500 *
485 * 501 *
486 connected_peers_map) 502 connected_peers_map)
487{ 503{
@@ -545,12 +561,11 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct
545struct GNUNET_TESTING_Command 561struct GNUNET_TESTING_Command
546GNUNET_TRANSPORT_cmd_start_peer (const char *label, 562GNUNET_TRANSPORT_cmd_start_peer (const char *label,
547 const char *system_label, 563 const char *system_label,
548 char *m, 564 uint32_t no,
549 char *n,
550 char *local_m,
551 char *node_ip, 565 char *node_ip,
552 struct GNUNET_MQ_MessageHandler *handlers, 566 struct GNUNET_MQ_MessageHandler *handlers,
553 const char *cfgname) 567 const char *cfgname,
568 GNUNET_TRANSPORT_NotifyConnect notify_connect)
554{ 569{
555 struct StartPeerState *sps; 570 struct StartPeerState *sps;
556 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = 571 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
@@ -558,14 +573,12 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
558 unsigned int i; 573 unsigned int i;
559 574
560 sps = GNUNET_new (struct StartPeerState); 575 sps = GNUNET_new (struct StartPeerState);
561 sps->m = m; 576 sps->no = no;
562 sps->n = n;
563 sps->local_m = local_m;
564 sps->no = (atoi (n) - 1) * atoi (sps->local_m) + atoi (m);
565 sps->system_label = system_label; 577 sps->system_label = system_label;
566 sps->connected_peers_map = connected_peers_map; 578 sps->connected_peers_map = connected_peers_map;
567 sps->cfgname = cfgname; 579 sps->cfgname = cfgname;
568 sps->node_ip = node_ip; 580 sps->node_ip = node_ip;
581 sps->notify_connect = notify_connect;
569 582
570 if (NULL != handlers) 583 if (NULL != handlers)
571 { 584 {
@@ -578,15 +591,14 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
578 i * sizeof(struct GNUNET_MQ_MessageHandler)); 591 i * sizeof(struct GNUNET_MQ_MessageHandler));
579 } 592 }
580 593
581 { 594 struct GNUNET_TESTING_Command cmd = {
582 struct GNUNET_TESTING_Command cmd = { 595 .cls = sps,
583 .cls = sps, 596 .label = label,
584 .label = label, 597 .run = &start_peer_run,
585 .run = &start_peer_run, 598 .ac = &sps->ac,
586 .cleanup = &start_peer_cleanup, 599 .cleanup = &start_peer_cleanup,
587 .traits = &start_peer_traits 600 .traits = &start_peer_traits
588 }; 601 };
589 602
590 return cmd; 603 return cmd;
591 }
592} 604}
diff --git a/src/transport/transport_api_cmd_start_peer_v2.c b/src/transport/transport_api_cmd_start_peer_v2.c
deleted file mode 100644
index 94799eddd..000000000
--- a/src/transport/transport_api_cmd_start_peer_v2.c
+++ /dev/null
@@ -1,605 +0,0 @@
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 "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h"
32#include "transport-testing-cmds.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39
40static void
41retrieve_hello (void *cls);
42
43
44/**
45 * Callback delivering the hello of this peer from peerstore.
46 *
47 */
48static void
49hello_iter_cb (void *cb_cls,
50 const struct GNUNET_PEERSTORE_Record *record,
51 const char *emsg)
52{
53 struct StartPeerState_v2 *sps = cb_cls;
54 if (NULL == record)
55 {
56 sps->pic = NULL;
57 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
58 return;
59 }
60 // Check record type et al?
61 sps->hello_size = record->value_size;
62 sps->hello = GNUNET_malloc (sps->hello_size);
63 memcpy (sps->hello, record->value, sps->hello_size);
64 sps->hello[sps->hello_size - 1] = '\0';
65
66 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
67 sps->pic = NULL;
68 sps->finished = GNUNET_YES;
69}
70
71
72/**
73 * Function to start the retrieval task to retrieve the hello of this peer
74 * from the peerstore.
75 *
76 */
77static void
78retrieve_hello (void *cls)
79{
80 struct StartPeerState_v2 *sps = cls;
81 sps->rh_task = NULL;
82 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
83 "transport",
84 &sps->id,
85 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
86 hello_iter_cb,
87 sps);
88
89}
90
91
92/**
93 * This function checks StartPeerState_v2#finished, which is set when the hello was retrieved.
94 *
95 */
96static int
97start_peer_finish (void *cls,
98 GNUNET_SCHEDULER_TaskCallback cont,
99 void *cont_cls)
100{
101 struct StartPeerState_v2 *sps = cls;
102
103 if (GNUNET_YES == sps->finished)
104 {
105 cont (cont_cls);
106 }
107
108 return sps->finished;
109}
110
111
112/**
113 * Disconnect callback for the connection to the core service.
114 *
115 */
116static void
117notify_disconnect (void *cls,
118 const struct GNUNET_PeerIdentity *peer,
119 void *handler_cls)
120{
121 struct StartPeerState_v2 *sps = cls;
122
123 LOG (GNUNET_ERROR_TYPE_DEBUG,
124 "Peer %s disconnected from peer %u (`%s')\n",
125 GNUNET_i2s (peer),
126 sps->no,
127 GNUNET_i2s (&sps->id));
128
129}
130
131
132/**
133 * Connect callback for the connection to the core service.
134 *
135 */
136static void *
137notify_connect (void *cls,
138 const struct GNUNET_PeerIdentity *peer,
139 struct GNUNET_MQ_Handle *mq)
140{
141 struct StartPeerState_v2 *sps = cls;
142 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
143 struct GNUNET_HashCode hc;
144 int node_number;
145
146 void *ret = NULL;
147
148
149 LOG (GNUNET_ERROR_TYPE_DEBUG,
150 "Peer %s connected to peer %u (`%s')\n",
151 GNUNET_i2s (peer),
152 sps->no,
153 GNUNET_i2s (&sps->id));
154
155 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
156 node_number = 1;
157 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
158
159
160 memcpy (key,
161 &hc,
162 sizeof (*key));
163 GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map,
164 key,
165 mq,
166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
167
168 GNUNET_free (key);
169 // TODO what does the handler function need?
170 return ret;
171}
172
173
174/**
175 * The run method of this cmd will start all services of a peer to test the transport service.
176 *
177 */
178static void
179start_peer_run (void *cls,
180 struct GNUNET_TESTING_Interpreter *is)
181{
182 struct StartPeerState_v2 *sps = cls;
183 char *emsg = NULL;
184 struct GNUNET_PeerIdentity dummy;
185 const struct GNUNET_TESTING_Command *system_cmd;
186 struct GNUNET_TESTING_System *tl_system;
187 char *home;
188 char *transport_unix_path;
189 char *communicator_unix_path;
190 char *bindto;
191
192 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
193 {
194 LOG (GNUNET_ERROR_TYPE_ERROR,
195 "File not found: `%s'\n",
196 sps->cfgname);
197 GNUNET_TESTING_interpreter_fail (is);
198 return;
199 }
200
201
202 sps->cfg = GNUNET_CONFIGURATION_create ();
203 GNUNET_assert (GNUNET_OK ==
204 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
205
206 GNUNET_asprintf (&home,
207 "$GNUNET_TMP/test-transport/api-tcp-p%u",
208 sps->no);
209
210 GNUNET_asprintf (&transport_unix_path,
211 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
212 sps->no);
213
214 GNUNET_asprintf (&communicator_unix_path,
215 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
216 sps->no);
217
218 GNUNET_asprintf (&bindto,
219 "%s:60002",
220 sps->node_ip);
221
222
223 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
224 home);
225 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
226 transport_unix_path);
227 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
228 "BINDTO",
229 bindto);
230 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
231 "UNIXPATH",
232 communicator_unix_path);
233
234 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
235 sps->system_label);
236 GNUNET_TESTING_get_trait_test_system (system_cmd,
237 &tl_system);
238
239 sps->tl_system = tl_system;
240
241 if (GNUNET_SYSERR ==
242 GNUNET_TESTING_configuration_create (tl_system,
243 sps->cfg))
244 {
245 LOG (GNUNET_ERROR_TYPE_ERROR,
246 "Testing library failed to create unique configuration based on `%s'\n",
247 sps->cfgname);
248 GNUNET_CONFIGURATION_destroy (sps->cfg);
249 GNUNET_TESTING_interpreter_fail (is);
250 return;
251 }
252
253 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
254 sps->cfg,
255 sps->no,
256 NULL,
257 &emsg);
258 if (NULL == sps->peer)
259 {
260 LOG (GNUNET_ERROR_TYPE_ERROR,
261 "Testing library failed to create unique configuration based on `%s': `%s'\n",
262 sps->cfgname,
263 emsg);
264 GNUNET_free (emsg);
265 GNUNET_TESTING_interpreter_fail (is);
266 return;
267 }
268
269 if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer))
270 {
271 LOG (GNUNET_ERROR_TYPE_ERROR,
272 "Testing library failed to create unique configuration based on `%s'\n",
273 sps->cfgname);
274 GNUNET_free (emsg);
275 GNUNET_TESTING_interpreter_fail (is);
276 return;
277 }
278
279 memset (&dummy,
280 '\0',
281 sizeof(dummy));
282
283 GNUNET_TESTING_peer_get_identity (sps->peer,
284 &sps->id);
285
286 if (0 == memcmp (&dummy,
287 &sps->id,
288 sizeof(struct GNUNET_PeerIdentity)))
289 {
290 LOG (GNUNET_ERROR_TYPE_ERROR,
291 "Testing library failed to obtain peer identity for peer %u\n",
292 sps->no);
293 GNUNET_free (emsg);
294 GNUNET_TESTING_interpreter_fail (is);
295 return;
296 }
297 LOG (GNUNET_ERROR_TYPE_DEBUG,
298 "Peer %u configured with identity `%s'\n",
299 sps->no,
300 GNUNET_i2s_full (&sps->id));
301
302 sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg,
303 NULL,
304 sps->handlers,
305 sps,
306 &notify_connect,
307 &notify_disconnect);
308 if (NULL == sps->th)
309 {
310 LOG (GNUNET_ERROR_TYPE_ERROR,
311 "Failed to connect to transport service for peer `%s': `%s'\n",
312 sps->cfgname,
313 emsg);
314 GNUNET_free (emsg);
315 GNUNET_TESTING_interpreter_fail (is);
316 return;
317 }
318
319 sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
320 if (NULL == sps->th)
321 {
322 LOG (GNUNET_ERROR_TYPE_ERROR,
323 "Failed to connect to peerstore service for peer `%s': `%s'\n",
324 sps->cfgname,
325 emsg);
326 GNUNET_free (emsg);
327 GNUNET_TESTING_interpreter_fail (is);
328 return;
329 }
330
331 sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
332 if (NULL == sps->ah)
333 {
334 LOG (GNUNET_ERROR_TYPE_ERROR,
335 "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
336 sps->cfgname,
337 emsg);
338 GNUNET_free (emsg);
339 GNUNET_TESTING_interpreter_fail (is);
340 return;
341 }
342 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
343}
344
345
346/**
347 * The cleanup function of this cmd frees resources the cmd allocated.
348 *
349 */
350static void
351start_peer_cleanup (void *cls)
352{
353 struct StartPeerState_v2 *sps = cls;
354
355 if (NULL != sps->handlers)
356 {
357 GNUNET_free (sps->handlers);
358 sps->handlers = NULL;
359 }
360 if (NULL != sps->cfg)
361 {
362 GNUNET_CONFIGURATION_destroy (sps->cfg);
363 sps->cfg = NULL;
364 }
365 GNUNET_free (sps->hello);
366 GNUNET_free (sps->connected_peers_map);
367 GNUNET_free (sps);
368}
369
370
371/**
372 * This function prepares an array with traits.
373 *
374 */
375static int
376start_peer_traits (void *cls,
377 const void **ret,
378 const char *trait,
379 unsigned int index)
380{
381 struct StartPeerState_v2 *sps = cls;
382 struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah;
383 struct GNUNET_PeerIdentity *id = &sps->id;
384 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
385 sps->connected_peers_map;
386 char *hello = sps->hello;
387 size_t hello_size = sps->hello_size;
388
389
390 struct GNUNET_TESTING_Trait traits[] = {
391 {
392 .index = 0,
393 .trait_name = "application_handle",
394 .ptr = (const void *) ah,
395 },
396 {
397 .index = 1,
398 .trait_name = "peer_id",
399 .ptr = (const void *) id,
400 },
401 {
402 .index = 2,
403 .trait_name = "connected_peers_map",
404 .ptr = (const void *) connected_peers_map,
405 },
406 {
407 .index = 3,
408 .trait_name = "hello",
409 .ptr = (const void *) hello,
410 },
411 {
412 .index = 4,
413 .trait_name = "hello_size",
414 .ptr = (const void *) hello_size,
415 },
416 {
417 .index = 5,
418 .trait_name = "state",
419 .ptr = (const void *) sps,
420 },
421 GNUNET_TESTING_trait_end ()
422 };
423
424 return GNUNET_TESTING_get_trait (traits,
425 ret,
426 trait,
427 index);
428}
429
430
431/**
432 * Function to get the trait with the struct StartPeerState_v2.
433 *
434 * @param[out] sps struct StartPeerState_v2.
435 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
436 *
437 */
438int
439GNUNET_TRANSPORT_get_trait_state_v2 (const struct
440 GNUNET_TESTING_Command
441 *cmd,
442 struct StartPeerState_v2 **sps)
443{
444 return cmd->traits (cmd->cls,
445 (const void **) sps,
446 "state",
447 (unsigned int) 5);
448}
449
450
451/**
452 * Function to get the trait with the size of the hello.
453 *
454 * @param[out] hello_size size of hello.
455 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
456 *
457 */
458int
459GNUNET_TRANSPORT_get_trait_hello_size_v2 (const struct
460 GNUNET_TESTING_Command
461 *cmd,
462 size_t **hello_size)
463{
464 return cmd->traits (cmd->cls,
465 (const void **) hello_size,
466 "hello_size",
467 (unsigned int) 4);
468}
469
470
471/**
472 * Function to get the trait with the hello.
473 *
474 * @param[out] hello The hello for the peer.
475 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
476 *
477 */
478int
479GNUNET_TRANSPORT_get_trait_hello_v2 (const struct
480 GNUNET_TESTING_Command
481 *cmd,
482 char **hello)
483{
484 return cmd->traits (cmd->cls,
485 (const void **) hello,
486 "hello",
487 (unsigned int) 3);
488}
489
490
491/**
492 * Function to get the trait with the map of connected peers.
493 *
494 * @param[out] connected_peers_map The map with connected peers.
495 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
496 *
497 */
498int
499GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct
500 GNUNET_TESTING_Command
501 *cmd,
502 struct
503 GNUNET_CONTAINER_MultiShortmap
504 *
505 *
506 connected_peers_map)
507{
508 return cmd->traits (cmd->cls,
509 (const void **) connected_peers_map,
510 "connected_peers_map",
511 (unsigned int) 2);
512}
513
514
515/**
516 * Function to get the trait with the transport application handle.
517 *
518 * @param[out] ah The application handle.
519 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
520 */
521int
522GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
523 GNUNET_TESTING_Command *cmd,
524 struct
525 GNUNET_TRANSPORT_ApplicationHandle
526 **ah)
527{
528 return cmd->traits (cmd->cls,
529 (const void **) ah,
530 "application_handle",
531 (unsigned int) 0);
532}
533
534
535/**
536 * Function to get the trait with the peer id.
537 *
538 * @param[out] id The peer id.
539 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
540 */
541int
542GNUNET_TRANSPORT_get_trait_peer_id_v2 (const struct
543 GNUNET_TESTING_Command *cmd,
544 struct GNUNET_PeerIdentity **id)
545{
546 return cmd->traits (cmd->cls,
547 (const void **) id,
548 "peer_id",
549 (unsigned int) 1);
550}
551
552
553/**
554 * Create command.
555 *
556 * @param label name for command.
557 * @param system_label Label of the cmd to setup a test environment.
558 * @param m The number of the local node of the actual network namespace.
559 * @param n The number of the actual namespace.
560 * @param local_m Number of local nodes in each namespace.
561 * @param handlers Handler for messages received by this peer.
562 * @param cfgname Configuration file name for this peer.
563 * @return command.
564 */
565struct GNUNET_TESTING_Command
566GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
567 const char *system_label,
568 uint32_t no,
569 char *node_ip,
570 struct GNUNET_MQ_MessageHandler *handlers,
571 const char *cfgname)
572{
573 struct StartPeerState_v2 *sps;
574 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
575 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
576 unsigned int i;
577
578 sps = GNUNET_new (struct StartPeerState_v2);
579 sps->no = no;
580 sps->system_label = system_label;
581 sps->connected_peers_map = connected_peers_map;
582 sps->cfgname = cfgname;
583 sps->node_ip = node_ip;
584
585 if (NULL != handlers)
586 {
587 for (i = 0; NULL != handlers[i].cb; i++)
588 ;
589 sps->handlers = GNUNET_new_array (i + 1,
590 struct GNUNET_MQ_MessageHandler);
591 GNUNET_memcpy (sps->handlers,
592 handlers,
593 i * sizeof(struct GNUNET_MQ_MessageHandler));
594 }
595
596 struct GNUNET_TESTING_Command cmd = {
597 .cls = sps,
598 .label = label,
599 .run = &start_peer_run,
600 .cleanup = &start_peer_cleanup,
601 .traits = &start_peer_traits
602 };
603
604 return cmd;
605}
diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c
deleted file mode 100644
index 1a19ce60e..000000000
--- a/src/transport/transport_api_cmd_start_peer_v3.c
+++ /dev/null
@@ -1,617 +0,0 @@
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 "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h"
32#include "transport-testing-cmds.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39
40static void
41retrieve_hello (void *cls);
42
43
44/**
45 * Callback delivering the hello of this peer from peerstore.
46 *
47 */
48static void
49hello_iter_cb (void *cb_cls,
50 const struct GNUNET_PEERSTORE_Record *record,
51 const char *emsg)
52{
53 struct StartPeerState_v2 *sps = cb_cls;
54 if (NULL == record)
55 {
56 sps->pic = NULL;
57 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
58 return;
59 }
60 // Check record type et al?
61 sps->hello_size = record->value_size;
62 sps->hello = GNUNET_malloc (sps->hello_size);
63 memcpy (sps->hello, record->value, sps->hello_size);
64 sps->hello[sps->hello_size - 1] = '\0';
65
66 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
67 sps->pic = NULL;
68 sps->finished = GNUNET_YES;
69}
70
71
72/**
73 * Function to start the retrieval task to retrieve the hello of this peer
74 * from the peerstore.
75 *
76 */
77static void
78retrieve_hello (void *cls)
79{
80 struct StartPeerState_v2 *sps = cls;
81 sps->rh_task = NULL;
82 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
83 "transport",
84 &sps->id,
85 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
86 hello_iter_cb,
87 sps);
88
89}
90
91
92/**
93 * This function checks StartPeerState_v2#finished, which is set when the hello was retrieved.
94 *
95 */
96static int
97start_peer_finish (void *cls,
98 GNUNET_SCHEDULER_TaskCallback cont,
99 void *cont_cls)
100{
101 struct StartPeerState_v2 *sps = cls;
102
103 if (GNUNET_YES == sps->finished)
104 {
105 cont (cont_cls);
106 }
107
108 return sps->finished;
109}
110
111
112/**
113 * Disconnect callback for the connection to the core service.
114 *
115 */
116static void
117notify_disconnect (void *cls,
118 const struct GNUNET_PeerIdentity *peer,
119 void *handler_cls)
120{
121 struct StartPeerState_v2 *sps = cls;
122
123 LOG (GNUNET_ERROR_TYPE_DEBUG,
124 "Peer %s disconnected from peer %u (`%s')\n",
125 GNUNET_i2s (peer),
126 sps->no,
127 GNUNET_i2s (&sps->id));
128
129}
130
131
132/**
133 * Connect callback for the connection to the core service.
134 *
135 */
136static void *
137notify_connect (void *cls,
138 const struct GNUNET_PeerIdentity *peer,
139 struct GNUNET_MQ_Handle *mq)
140{
141 struct StartPeerState_v2 *sps = cls;
142 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
143 struct GNUNET_HashCode hc;
144 struct GNUNET_CRYPTO_EddsaPublicKey public_key = peer->public_key;
145
146 void *ret = NULL;
147
148
149 LOG (GNUNET_ERROR_TYPE_DEBUG,
150 "Peer %s connected to peer %u (`%s')\n",
151 GNUNET_i2s (peer),
152 sps->no,
153 GNUNET_i2s (&sps->id));
154
155 GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
156
157
158 memcpy (key,
159 &hc,
160 sizeof (*key));
161 GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map,
162 key,
163 mq,
164 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
165
166 GNUNET_free (key);
167 // TODO what does the handler function need?
168 return ret;
169}
170
171
172/**
173 * The run method of this cmd will start all services of a peer to test the transport service.
174 *
175 */
176static void
177start_peer_run (void *cls,
178 struct GNUNET_TESTING_Interpreter *is)
179{
180 struct StartPeerState_v2 *sps = cls;
181 char *emsg = NULL;
182 struct GNUNET_PeerIdentity dummy;
183 const struct GNUNET_TESTING_Command *system_cmd;
184 struct GNUNET_TESTING_System *tl_system;
185 char *home;
186 char *transport_unix_path;
187 char *tcp_communicator_unix_path;
188 char *udp_communicator_unix_path;
189 char *bindto;
190
191 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
192 {
193 LOG (GNUNET_ERROR_TYPE_ERROR,
194 "File not found: `%s'\n",
195 sps->cfgname);
196 GNUNET_TESTING_interpreter_fail (is);
197 return;
198 }
199
200
201 sps->cfg = GNUNET_CONFIGURATION_create ();
202 GNUNET_assert (GNUNET_OK ==
203 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
204
205 GNUNET_asprintf (&home,
206 "$GNUNET_TMP/test-transport/api-tcp-p%u",
207 sps->no);
208
209 GNUNET_asprintf (&transport_unix_path,
210 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
211 sps->no);
212
213 GNUNET_asprintf (&tcp_communicator_unix_path,
214 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
215 sps->no);
216
217 GNUNET_asprintf (&udp_communicator_unix_path,
218 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
219 sps->no);
220
221 GNUNET_asprintf (&bindto,
222 "%s:60002",
223 sps->node_ip);
224
225 LOG (GNUNET_ERROR_TYPE_ERROR,
226 "node_ip %s\n",
227 bindto);
228
229 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
230 home);
231 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
232 transport_unix_path);
233 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
234 "BINDTO",
235 bindto);
236 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
237 "BINDTO",
238 bindto);
239 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
240 "UNIXPATH",
241 tcp_communicator_unix_path);
242 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
243 "UNIXPATH",
244 udp_communicator_unix_path);
245
246 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
247 sps->system_label);
248 GNUNET_TESTING_get_trait_test_system (system_cmd,
249 &tl_system);
250
251 sps->tl_system = tl_system;
252
253 if (GNUNET_SYSERR ==
254 GNUNET_TESTING_configuration_create (tl_system,
255 sps->cfg))
256 {
257 LOG (GNUNET_ERROR_TYPE_ERROR,
258 "Testing library failed to create unique configuration based on `%s'\n",
259 sps->cfgname);
260 GNUNET_CONFIGURATION_destroy (sps->cfg);
261 GNUNET_TESTING_interpreter_fail (is);
262 return;
263 }
264
265 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
266 sps->cfg,
267 sps->no,
268 NULL,
269 &emsg);
270 if (NULL == sps->peer)
271 {
272 LOG (GNUNET_ERROR_TYPE_ERROR,
273 "Testing library failed to create unique configuration based on `%s': `%s'\n",
274 sps->cfgname,
275 emsg);
276 GNUNET_free (emsg);
277 GNUNET_TESTING_interpreter_fail (is);
278 return;
279 }
280
281 if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer))
282 {
283 LOG (GNUNET_ERROR_TYPE_ERROR,
284 "Testing library failed to create unique configuration based on `%s'\n",
285 sps->cfgname);
286 GNUNET_free (emsg);
287 GNUNET_TESTING_interpreter_fail (is);
288 return;
289 }
290
291 memset (&dummy,
292 '\0',
293 sizeof(dummy));
294
295 GNUNET_TESTING_peer_get_identity (sps->peer,
296 &sps->id);
297
298 if (0 == memcmp (&dummy,
299 &sps->id,
300 sizeof(struct GNUNET_PeerIdentity)))
301 {
302 LOG (GNUNET_ERROR_TYPE_ERROR,
303 "Testing library failed to obtain peer identity for peer %u\n",
304 sps->no);
305 GNUNET_free (emsg);
306 GNUNET_TESTING_interpreter_fail (is);
307 return;
308 }
309 LOG (GNUNET_ERROR_TYPE_DEBUG,
310 "Peer %u configured with identity `%s'\n",
311 sps->no,
312 GNUNET_i2s_full (&sps->id));
313
314 sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg,
315 NULL,
316 sps->handlers,
317 sps,
318 &notify_connect,
319 &notify_disconnect);
320 if (NULL == sps->th)
321 {
322 LOG (GNUNET_ERROR_TYPE_ERROR,
323 "Failed to connect to transport service for peer `%s': `%s'\n",
324 sps->cfgname,
325 emsg);
326 GNUNET_free (emsg);
327 GNUNET_TESTING_interpreter_fail (is);
328 return;
329 }
330
331 sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
332 if (NULL == sps->th)
333 {
334 LOG (GNUNET_ERROR_TYPE_ERROR,
335 "Failed to connect to peerstore service for peer `%s': `%s'\n",
336 sps->cfgname,
337 emsg);
338 GNUNET_free (emsg);
339 GNUNET_TESTING_interpreter_fail (is);
340 return;
341 }
342
343 sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
344 if (NULL == sps->ah)
345 {
346 LOG (GNUNET_ERROR_TYPE_ERROR,
347 "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
348 sps->cfgname,
349 emsg);
350 GNUNET_free (emsg);
351 GNUNET_TESTING_interpreter_fail (is);
352 return;
353 }
354 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
355}
356
357
358/**
359 * The cleanup function of this cmd frees resources the cmd allocated.
360 *
361 */
362static void
363start_peer_cleanup (void *cls)
364{
365 struct StartPeerState_v2 *sps = cls;
366
367 if (NULL != sps->handlers)
368 {
369 GNUNET_free (sps->handlers);
370 sps->handlers = NULL;
371 }
372 if (NULL != sps->cfg)
373 {
374 GNUNET_CONFIGURATION_destroy (sps->cfg);
375 sps->cfg = NULL;
376 }
377 GNUNET_free (sps->hello);
378 GNUNET_free (sps->connected_peers_map);
379 GNUNET_free (sps);
380}
381
382
383/**
384 * This function prepares an array with traits.
385 *
386 */
387static int
388start_peer_traits (void *cls,
389 const void **ret,
390 const char *trait,
391 unsigned int index)
392{
393 struct StartPeerState_v2 *sps = cls;
394 struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah;
395 struct GNUNET_PeerIdentity *id = &sps->id;
396 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
397 sps->connected_peers_map;
398 char *hello = sps->hello;
399 size_t hello_size = sps->hello_size;
400
401
402 struct GNUNET_TESTING_Trait traits[] = {
403 {
404 .index = 0,
405 .trait_name = "application_handle",
406 .ptr = (const void *) ah,
407 },
408 {
409 .index = 1,
410 .trait_name = "peer_id",
411 .ptr = (const void *) id,
412 },
413 {
414 .index = 2,
415 .trait_name = "connected_peers_map",
416 .ptr = (const void *) connected_peers_map,
417 },
418 {
419 .index = 3,
420 .trait_name = "hello",
421 .ptr = (const void *) hello,
422 },
423 {
424 .index = 4,
425 .trait_name = "hello_size",
426 .ptr = (const void *) hello_size,
427 },
428 {
429 .index = 5,
430 .trait_name = "state",
431 .ptr = (const void *) sps,
432 },
433 GNUNET_TESTING_trait_end ()
434 };
435
436 return GNUNET_TESTING_get_trait (traits,
437 ret,
438 trait,
439 index);
440}
441
442
443/**
444 * Function to get the trait with the struct StartPeerState_v2.
445 *
446 * @param[out] sps struct StartPeerState_v2.
447 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
448 *
449 */
450int
451GNUNET_TRANSPORT_get_trait_state_v3 (const struct
452 GNUNET_TESTING_Command
453 *cmd,
454 struct StartPeerState_v2 **sps)
455{
456 return cmd->traits (cmd->cls,
457 (const void **) sps,
458 "state",
459 (unsigned int) 5);
460}
461
462
463/**
464 * Function to get the trait with the size of the hello.
465 *
466 * @param[out] hello_size size of hello.
467 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
468 *
469 */
470int
471GNUNET_TRANSPORT_get_trait_hello_size_v3 (const struct
472 GNUNET_TESTING_Command
473 *cmd,
474 size_t **hello_size)
475{
476 return cmd->traits (cmd->cls,
477 (const void **) hello_size,
478 "hello_size",
479 (unsigned int) 4);
480}
481
482
483/**
484 * Function to get the trait with the hello.
485 *
486 * @param[out] hello The hello for the peer.
487 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
488 *
489 */
490int
491GNUNET_TRANSPORT_get_trait_hello_v3 (const struct
492 GNUNET_TESTING_Command
493 *cmd,
494 char **hello)
495{
496 return cmd->traits (cmd->cls,
497 (const void **) hello,
498 "hello",
499 (unsigned int) 3);
500}
501
502
503/**
504 * Function to get the trait with the map of connected peers.
505 *
506 * @param[out] connected_peers_map The map with connected peers.
507 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
508 *
509 */
510int
511GNUNET_TRANSPORT_get_trait_connected_peers_map_v3 (const struct
512 GNUNET_TESTING_Command
513 *cmd,
514 struct
515 GNUNET_CONTAINER_MultiShortmap
516 *
517 *
518 connected_peers_map)
519{
520 return cmd->traits (cmd->cls,
521 (const void **) connected_peers_map,
522 "connected_peers_map",
523 (unsigned int) 2);
524}
525
526
527/**
528 * Function to get the trait with the transport application handle.
529 *
530 * @param[out] ah The application handle.
531 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
532 */
533int
534GNUNET_TRANSPORT_get_trait_application_handle_v3 (const struct
535 GNUNET_TESTING_Command *cmd,
536 struct
537 GNUNET_TRANSPORT_ApplicationHandle
538 **ah)
539{
540 return cmd->traits (cmd->cls,
541 (const void **) ah,
542 "application_handle",
543 (unsigned int) 0);
544}
545
546
547/**
548 * Function to get the trait with the peer id.
549 *
550 * @param[out] id The peer id.
551 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
552 */
553int
554GNUNET_TRANSPORT_get_trait_peer_id_v3 (const struct
555 GNUNET_TESTING_Command *cmd,
556 struct GNUNET_PeerIdentity **id)
557{
558 return cmd->traits (cmd->cls,
559 (const void **) id,
560 "peer_id",
561 (unsigned int) 1);
562}
563
564
565/**
566 * Create command.
567 *
568 * @param label name for command.
569 * @param system_label Label of the cmd to setup a test environment.
570 * @param m The number of the local node of the actual network namespace.
571 * @param n The number of the actual namespace.
572 * @param local_m Number of local nodes in each namespace.
573 * @param handlers Handler for messages received by this peer.
574 * @param cfgname Configuration file name for this peer.
575 * @return command.
576 */
577struct GNUNET_TESTING_Command
578GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label,
579 const char *system_label,
580 uint32_t no,
581 char *node_ip,
582 struct GNUNET_MQ_MessageHandler *handlers,
583 const char *cfgname)
584{
585 struct StartPeerState_v2 *sps;
586 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
587 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
588 unsigned int i;
589
590 sps = GNUNET_new (struct StartPeerState_v2);
591 sps->no = no;
592 sps->system_label = system_label;
593 sps->connected_peers_map = connected_peers_map;
594 sps->cfgname = cfgname;
595 sps->node_ip = node_ip;
596
597 if (NULL != handlers)
598 {
599 for (i = 0; NULL != handlers[i].cb; i++)
600 ;
601 sps->handlers = GNUNET_new_array (i + 1,
602 struct GNUNET_MQ_MessageHandler);
603 GNUNET_memcpy (sps->handlers,
604 handlers,
605 i * sizeof(struct GNUNET_MQ_MessageHandler));
606 }
607
608 struct GNUNET_TESTING_Command cmd = {
609 .cls = sps,
610 .label = label,
611 .run = &start_peer_run,
612 .cleanup = &start_peer_cleanup,
613 .traits = &start_peer_traits
614 };
615
616 return cmd;
617}