aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am37
-rw-r--r--src/transport/test_transport_api2_tcp_node1.conf7
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c36
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c262
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel_send.c262
-rw-r--r--src/transport/test_transport_start_with_config.c85
-rw-r--r--src/transport/transport-testing-cmds.h33
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v3.c508
-rw-r--r--src/transport/transport_api_cmd_start_peer_v3.c619
9 files changed, 1287 insertions, 562 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 561ac5e60..c8290628f 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -162,8 +162,10 @@ libgnunettransporttesting_la_LDFLAGS = \
162libgnunettransporttesting2_la_SOURCES = \ 162libgnunettransporttesting2_la_SOURCES = \
163 transport_api_cmd_connecting_peers.c \ 163 transport_api_cmd_connecting_peers.c \
164 transport_api_cmd_connecting_peers_v2.c \ 164 transport_api_cmd_connecting_peers_v2.c \
165 transport_api_cmd_connecting_peers_v3.c \
165 transport_api_cmd_start_peer.c \ 166 transport_api_cmd_start_peer.c \
166 transport_api_cmd_start_peer_v2.c \ 167 transport_api_cmd_start_peer_v2.c \
168 transport_api_cmd_start_peer_v3.c \
167 transport_api_cmd_stop_peer.c \ 169 transport_api_cmd_stop_peer.c \
168 transport_api_cmd_send_simple.c \ 170 transport_api_cmd_send_simple.c \
169 transport_api_cmd_send_simple_v2.c \ 171 transport_api_cmd_send_simple_v2.c \
@@ -394,7 +396,25 @@ plugin_LTLIBRARIES = \
394 $(WLAN_PLUGIN_LA) \ 396 $(WLAN_PLUGIN_LA) \
395 $(BT_PLUGIN_LA) \ 397 $(BT_PLUGIN_LA) \
396 libgnunet_test_transport_plugin_cmd_simple_send.la \ 398 libgnunet_test_transport_plugin_cmd_simple_send.la \
397 libgnunet_test_transport_plugin_cmd_simple_send_v2.la 399 libgnunet_test_transport_plugin_cmd_simple_send_v2.la \
400 libgnunet_test_transport_plugin_cmd_udp_backchannel.la
401
402libgnunet_test_transport_plugin_cmd_udp_backchannel_la_SOURCES = \
403 test_transport_plugin_cmd_udp_backchannel.c
404libgnunet_test_transport_plugin_cmd_udp_backchannel_la_LIBADD = \
405 libgnunettransporttesting2.la \
406 libgnunettransportapplication.la \
407 libgnunettransportcore.la \
408 $(top_builddir)/src/testing/libgnunettesting.la \
409 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
410 $(top_builddir)/src/statistics/libgnunetstatistics.la \
411 $(top_builddir)/src/hello/libgnunethello.la \
412 $(top_builddir)/src/ats/libgnunetats.la \
413 $(top_builddir)/src/arm/libgnunetarm.la \
414 $(top_builddir)/src/util/libgnunetutil.la \
415 $(LTLIBINTL)
416libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \
417 $(GN_PLUGIN_LDFLAGS)
398 418
399libgnunet_test_transport_plugin_cmd_simple_send_la_SOURCES = \ 419libgnunet_test_transport_plugin_cmd_simple_send_la_SOURCES = \
400 test_transport_plugin_cmd_simple_send.c 420 test_transport_plugin_cmd_simple_send.c
@@ -578,6 +598,7 @@ if HAVE_TESTING
578check_PROGRAMS = \ 598check_PROGRAMS = \
579 test_transport_simple_send \ 599 test_transport_simple_send \
580 test_transport_simple_send_v2 \ 600 test_transport_simple_send_v2 \
601 test_transport_start_with_config \
581 test_transport_address_switch_tcp \ 602 test_transport_address_switch_tcp \
582 test_transport_testing_startstop \ 603 test_transport_testing_startstop \
583 test_transport_testing_restart \ 604 test_transport_testing_restart \
@@ -728,6 +749,7 @@ if HAVE_EXPERIMENTAL
728TESTS += \ 749TESTS += \
729 test_transport_simple_send \ 750 test_transport_simple_send \
730 test_transport_simple_send_v2 \ 751 test_transport_simple_send_v2 \
752 test_transport_start_with_config \
731 test_transport_address_switch_udp \ 753 test_transport_address_switch_udp \
732 test_plugin_udp \ 754 test_plugin_udp \
733 test_transport_api_udp \ 755 test_transport_api_udp \
@@ -747,7 +769,18 @@ endif
747 769
748check_SCRIPTS= \ 770check_SCRIPTS= \
749 test_transport_simple_send.sh \ 771 test_transport_simple_send.sh \
750 test_transport_simple_send_v2.sh 772 test_transport_simple_send_v2.sh \
773 test_transport_udp_backchannel.sh
774
775test_transport_start_with_config_SOURCES = \
776 test_transport_start_with_config.c
777test_transport_start_with_config_LDADD = \
778 $(top_builddir)/src/testing/libgnunettesting.la \
779 $(top_builddir)/src/util/libgnunetutil.la \
780 $(top_builddir)/src/testbed/libgnunettestbed.la \
781 $(top_builddir)/src/hello/libgnunethello.la \
782 libgnunettransportcore.la \
783 libgnunettransporttesting2.la
751 784
752test_transport_simple_send_SOURCES = \ 785test_transport_simple_send_SOURCES = \
753 test_transport_simple_send.c 786 test_transport_simple_send.c
diff --git a/src/transport/test_transport_api2_tcp_node1.conf b/src/transport/test_transport_api2_tcp_node1.conf
index a867ea81a..11306fd6a 100644
--- a/src/transport/test_transport_api2_tcp_node1.conf
+++ b/src/transport/test_transport_api2_tcp_node1.conf
@@ -16,6 +16,13 @@ IMMEDIATE_START = YES
16UNIXPATH = $GNUNET_RUNTIME_DIR/tcp-comm-p1.sock 16UNIXPATH = $GNUNET_RUNTIME_DIR/tcp-comm-p1.sock
17#PREFIX = valgrind --log-file=/tmp/vg_cpeer1-%p 17#PREFIX = valgrind --log-file=/tmp/vg_cpeer1-%p
18 18
19[communicator-udp]
20BINARY = gnunet-communicator-udp
21BINDTO = 192.168.15.1:60002
22DISABLE_V6 = YES
23IMMEDIATE_START = YES
24UNIXPATH = $GNUNET_RUNTIME_DIR/udp-comm-p1.sock
25
19[peerstore] 26[peerstore]
20IMMEDIATE_START = YES 27IMMEDIATE_START = YES
21 28
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 35aa07ecd..07255a1a5 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -83,40 +83,11 @@ static void
83handle_test (void *cls, 83handle_test (void *cls,
84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
85{ 85{
86 LOG (GNUNET_ERROR_TYPE_ERROR,
87 "message received\n");
88 message_received = GNUNET_YES; 86 message_received = GNUNET_YES;
89} 87}
90 88
91 89
92/** 90/**
93 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
94 * being received.
95 *
96 */
97static int
98check_test2 (void *cls,
99 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
100{
101 return GNUNET_OK;
102}
103
104
105/**
106 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
107 * being received.
108 *
109 */
110static void
111handle_test2 (void *cls,
112 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
113{
114 LOG (GNUNET_ERROR_TYPE_ERROR,
115 "message received\n");
116}
117
118
119/**
120 * Callback to set the flag indicating all peers started. Will be called via the plugin api. 91 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
121 * 92 *
122 */ 93 */
@@ -124,9 +95,6 @@ static void
124all_peers_started () 95all_peers_started ()
125{ 96{
126 are_all_peers_started = GNUNET_YES; 97 are_all_peers_started = GNUNET_YES;
127 LOG (GNUNET_ERROR_TYPE_ERROR,
128 "setting are_all_peers_started: %d\n",
129 are_all_peers_started);
130} 98}
131 99
132 100
@@ -176,10 +144,6 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
176 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 144 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
177 struct GNUNET_TRANSPORT_TESTING_TestMessage, 145 struct GNUNET_TRANSPORT_TESTING_TestMessage,
178 NULL), 146 NULL),
179 GNUNET_MQ_hd_var_size (test2,
180 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
181 struct GNUNET_TRANSPORT_TESTING_TestMessage,
182 NULL),
183 GNUNET_MQ_handler_end () 147 GNUNET_MQ_handler_end ()
184 }; 148 };
185 149
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c b/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c
deleted file mode 100644
index ce1245296..000000000
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c
+++ /dev/null
@@ -1,262 +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/**
62 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
63 * received.
64 *
65 */
66static int
67check_test (void *cls,
68 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
69{
70 return GNUNET_OK;
71}
72
73
74/**
75 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
76 * being received.
77 *
78 */
79static void
80handle_test (void *cls,
81 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
82{
83 LOG (GNUNET_ERROR_TYPE_ERROR,
84 "message received\n");
85}
86
87
88/**
89 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
90 * being received.
91 *
92 */
93static int
94check_test2 (void *cls,
95 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
96{
97 return GNUNET_OK;
98}
99
100
101/**
102 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
103 * being received.
104 *
105 */
106static void
107handle_test2 (void *cls,
108 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
109{
110 LOG (GNUNET_ERROR_TYPE_ERROR,
111 "message received\n");
112}
113
114
115/**
116 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
117 *
118 */
119static void
120all_peers_started ()
121{
122 are_all_peers_started = GNUNET_YES;
123 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "setting are_all_peers_started: %d\n",
125 are_all_peers_started);
126}
127
128
129/**
130 * Function to start a local test case.
131 *
132 * @param write_message Callback to send a message to the master loop.
133 * @param router_ip Global address of the network namespace.
134 * @param node_ip Local address of a node i a network namespace.
135 * @param m The number of the node in a network namespace.
136 * @param n The number of the network namespace.
137 * @param local_m The number of nodes in a network namespace.
138 */
139static void
140start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
141 char *node_ip,
142 char *m,
143 char *n,
144 char *local_m)
145{
146
147 unsigned int n_int, m_int, local_m_int, num;
148
149 struct GNUNET_TESTING_NetjailTopology *topology =
150 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
151
152 sscanf (m, "%u", &m_int);
153 sscanf (n, "%u", &n_int);
154 sscanf (local_m, "%u", &local_m_int);
155
156
157 if (0 == m_int)
158 num = n_int;
159 else
160 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
161
162 GNUNET_asprintf (&cfgname,
163 "test_transport_api2_tcp_node1.conf");
164
165 LOG (GNUNET_ERROR_TYPE_ERROR,
166 "plugin cfgname: %s\n",
167 cfgname);
168
169 LOG (GNUNET_ERROR_TYPE_ERROR,
170 "node ip: %s\n",
171 node_ip);
172
173 GNUNET_asprintf (&testdir,
174 "%s%s%s",
175 BASE_DIR,
176 m,
177 n);
178
179 struct GNUNET_MQ_MessageHandler handlers[] = {
180 GNUNET_MQ_hd_var_size (test,
181 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
182 struct GNUNET_TRANSPORT_TESTING_TestMessage,
183 NULL),
184 GNUNET_MQ_hd_var_size (test2,
185 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
186 struct GNUNET_TRANSPORT_TESTING_TestMessage,
187 NULL),
188 GNUNET_MQ_handler_end ()
189 };
190
191 struct GNUNET_TESTING_Command commands[] = {
192 GNUNET_TESTING_cmd_system_create ("system-create",
193 testdir),
194 GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
195 "system-create",
196 num,
197 node_ip,
198 handlers,
199 cfgname),
200 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
201 write_message),
202 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
203 &are_all_peers_started),
204 GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
205 "start-peer",
206 "system-create",
207 num),
208 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
209 "start-peer",
210 num),
211 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
212 "start-peer"),
213 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
214 "system-create"),
215 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
216 write_message)
217 };
218
219 GNUNET_TESTING_run (NULL,
220 commands,
221 GNUNET_TIME_UNIT_FOREVER_REL);
222
223}
224
225
226/**
227 * Entry point for the plugin.
228 *
229 * @param cls NULL
230 * @return the exported block API
231 */
232void *
233libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
234{
235 struct GNUNET_TESTING_PluginFunctions *api;
236
237 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
238 api->start_testcase = &start_testcase;
239 api->all_peers_started = &all_peers_started;
240 return api;
241}
242
243
244/**
245 * Exit point from the plugin.
246 *
247 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
248 * @return NULL
249 */
250void *
251libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
252{
253 struct GNUNET_TESTING_PluginFunctions *api = cls;
254
255 GNUNET_free (api);
256 GNUNET_free (testdir);
257 GNUNET_free (cfgname);
258 return NULL;
259}
260
261
262/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c b/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c
deleted file mode 100644
index ce1245296..000000000
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c
+++ /dev/null
@@ -1,262 +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/**
62 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
63 * received.
64 *
65 */
66static int
67check_test (void *cls,
68 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
69{
70 return GNUNET_OK;
71}
72
73
74/**
75 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
76 * being received.
77 *
78 */
79static void
80handle_test (void *cls,
81 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
82{
83 LOG (GNUNET_ERROR_TYPE_ERROR,
84 "message received\n");
85}
86
87
88/**
89 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
90 * being received.
91 *
92 */
93static int
94check_test2 (void *cls,
95 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
96{
97 return GNUNET_OK;
98}
99
100
101/**
102 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
103 * being received.
104 *
105 */
106static void
107handle_test2 (void *cls,
108 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
109{
110 LOG (GNUNET_ERROR_TYPE_ERROR,
111 "message received\n");
112}
113
114
115/**
116 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
117 *
118 */
119static void
120all_peers_started ()
121{
122 are_all_peers_started = GNUNET_YES;
123 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "setting are_all_peers_started: %d\n",
125 are_all_peers_started);
126}
127
128
129/**
130 * Function to start a local test case.
131 *
132 * @param write_message Callback to send a message to the master loop.
133 * @param router_ip Global address of the network namespace.
134 * @param node_ip Local address of a node i a network namespace.
135 * @param m The number of the node in a network namespace.
136 * @param n The number of the network namespace.
137 * @param local_m The number of nodes in a network namespace.
138 */
139static void
140start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
141 char *node_ip,
142 char *m,
143 char *n,
144 char *local_m)
145{
146
147 unsigned int n_int, m_int, local_m_int, num;
148
149 struct GNUNET_TESTING_NetjailTopology *topology =
150 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
151
152 sscanf (m, "%u", &m_int);
153 sscanf (n, "%u", &n_int);
154 sscanf (local_m, "%u", &local_m_int);
155
156
157 if (0 == m_int)
158 num = n_int;
159 else
160 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
161
162 GNUNET_asprintf (&cfgname,
163 "test_transport_api2_tcp_node1.conf");
164
165 LOG (GNUNET_ERROR_TYPE_ERROR,
166 "plugin cfgname: %s\n",
167 cfgname);
168
169 LOG (GNUNET_ERROR_TYPE_ERROR,
170 "node ip: %s\n",
171 node_ip);
172
173 GNUNET_asprintf (&testdir,
174 "%s%s%s",
175 BASE_DIR,
176 m,
177 n);
178
179 struct GNUNET_MQ_MessageHandler handlers[] = {
180 GNUNET_MQ_hd_var_size (test,
181 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
182 struct GNUNET_TRANSPORT_TESTING_TestMessage,
183 NULL),
184 GNUNET_MQ_hd_var_size (test2,
185 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
186 struct GNUNET_TRANSPORT_TESTING_TestMessage,
187 NULL),
188 GNUNET_MQ_handler_end ()
189 };
190
191 struct GNUNET_TESTING_Command commands[] = {
192 GNUNET_TESTING_cmd_system_create ("system-create",
193 testdir),
194 GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
195 "system-create",
196 num,
197 node_ip,
198 handlers,
199 cfgname),
200 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
201 write_message),
202 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
203 &are_all_peers_started),
204 GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
205 "start-peer",
206 "system-create",
207 num),
208 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
209 "start-peer",
210 num),
211 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
212 "start-peer"),
213 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
214 "system-create"),
215 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
216 write_message)
217 };
218
219 GNUNET_TESTING_run (NULL,
220 commands,
221 GNUNET_TIME_UNIT_FOREVER_REL);
222
223}
224
225
226/**
227 * Entry point for the plugin.
228 *
229 * @param cls NULL
230 * @return the exported block API
231 */
232void *
233libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
234{
235 struct GNUNET_TESTING_PluginFunctions *api;
236
237 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
238 api->start_testcase = &start_testcase;
239 api->all_peers_started = &all_peers_started;
240 return api;
241}
242
243
244/**
245 * Exit point from the plugin.
246 *
247 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
248 * @return NULL
249 */
250void *
251libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
252{
253 struct GNUNET_TESTING_PluginFunctions *api = cls;
254
255 GNUNET_free (api);
256 GNUNET_free (testdir);
257 GNUNET_free (cfgname);
258 return NULL;
259}
260
261
262/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c
new file mode 100644
index 000000000..795c157d7
--- /dev/null
+++ b/src/transport/test_transport_start_with_config.c
@@ -0,0 +1,85 @@
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_start_with_config.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
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
69int
70main (int argc,
71 char *const *argv)
72{
73 GNUNET_log_setup ("test-netjail",
74 "DEBUG",
75 NULL);
76
77 topology_config = argv[1];
78
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/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index f9ebafade..ecdabd35f 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -211,6 +211,14 @@ GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
211 const char *cfgname); 211 const char *cfgname);
212 212
213struct GNUNET_TESTING_Command 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
214GNUNET_TRANSPORT_cmd_start_peer (const char *label, 222GNUNET_TRANSPORT_cmd_start_peer (const char *label,
215 const char *system_label, 223 const char *system_label,
216 char *m, 224 char *m,
@@ -237,6 +245,14 @@ GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
237 uint32_t num); 245 uint32_t num);
238 246
239struct GNUNET_TESTING_Command 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
255struct GNUNET_TESTING_Command
240GNUNET_TRANSPORT_cmd_send_simple (const char *label, 256GNUNET_TRANSPORT_cmd_send_simple (const char *label,
241 char *m, 257 char *m,
242 char *n, 258 char *n,
@@ -281,6 +297,16 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct
281 * 297 *
282 * 298 *
283 connected_peers_map); 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);
284int 310int
285GNUNET_TRANSPORT_get_trait_hello_size (const struct 311GNUNET_TRANSPORT_get_trait_hello_size (const struct
286 GNUNET_TESTING_Command 312 GNUNET_TESTING_Command
@@ -308,5 +334,12 @@ GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
308 GNUNET_TRANSPORT_ApplicationHandle 334 GNUNET_TRANSPORT_ApplicationHandle
309 **ah); 335 **ah);
310 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
311#endif 344#endif
312/* end of transport_testing.h */ 345/* end of transport_testing.h */
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c
new file mode 100644
index 000000000..e90781637
--- /dev/null
+++ b/src/transport/transport_api_cmd_connecting_peers_v3.c
@@ -0,0 +1,508 @@
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 * The testing system of this node.
63 */
64 struct GNUNET_TESTING_System *tl_system;
65
66 // Label of the cmd which started the test system.
67 const char *create_label;
68
69 /**
70 * Number globally identifying the node.
71 *
72 */
73 uint32_t num;
74
75 /**
76 * Label of the cmd to start a peer.
77 *
78 */
79 const char *start_peer_label;
80
81 /**
82 * The peer identity of this peer.
83 *
84 */
85 struct GNUNET_PeerIdentity *id;
86
87 /**
88 * The topology of the test setup.
89 */
90 struct GNUNET_TESTING_NetjailTopology *topology;
91
92 /**
93 * Connections to other peers.
94 */
95 struct GNUNET_TESTING_NodeConnection *node_connections_head;
96
97 /**
98 * Number of connections.
99 */
100 unsigned int con_num;
101};
102
103
104static struct GNUNET_PeerIdentity *
105get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
106{
107 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
108 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
109 GNUNET_CRYPTO_EddsaPublicKey);
110 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
111 GNUNET_CRYPTO_EddsaPrivateKey);
112
113 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
114 num,
115 peer);
116
117 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
118 pub_key);
119 peer->public_key = *pub_key;
120 return peer;
121}
122
123
124static int
125log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
126{
127 struct GNUNET_TESTING_NetjailNode *node = value;
128 struct GNUNET_TESTING_NodeConnection *pos_connection;
129 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
130
131 LOG (GNUNET_ERROR_TYPE_ERROR,
132 "plugin: %s space: %u node: %u global: %u\n",
133 node->plugin,
134 node->namespace_n,
135 node->node_n,
136 node->is_global);
137
138 for (pos_connection = node->node_connections_head; NULL != pos_connection;
139 pos_connection = pos_connection->next)
140 {
141
142 LOG (GNUNET_ERROR_TYPE_ERROR,
143 "namespace_n: %u node_n: %u node_type: %u\n",
144 pos_connection->namespace_n,
145 pos_connection->node_n,
146 pos_connection->node_type);
147
148 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
149 pos_prefix =
150 pos_prefix->next)
151 {
152 LOG (GNUNET_ERROR_TYPE_ERROR,
153 "prefix: %s\n",
154 pos_prefix->address_prefix);
155 }
156 }
157 return GNUNET_YES;
158}
159
160
161static int
162log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
163{
164 struct GNUNET_TESTING_NetjailNamespace *namespace = value;
165 struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
166
167 LOG (GNUNET_ERROR_TYPE_ERROR,
168 "router_tcp: %u router_udp: %u spaces: %u\n",
169 router->tcp_port,
170 router->udp_port,
171 namespace->namespace_n);
172 GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
173 return GNUNET_YES;
174}
175
176
177static int
178log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
179{
180 LOG (GNUNET_ERROR_TYPE_ERROR,
181 "plugin: %s spaces: %u nodes: %u known: %u\n",
182 topology->plugin,
183 topology->namespaces_n,
184 topology->nodes_m,
185 topology->nodes_x);
186
187 GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
188 log_namespaces, NULL);
189 GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
190 NULL);
191 return GNUNET_YES;
192}
193
194
195static struct GNUNET_TESTING_NodeConnection *
196get_connections (unsigned int num, struct
197 GNUNET_TESTING_NetjailTopology *topology)
198{
199 struct GNUNET_TESTING_NetjailNode *node;
200 struct GNUNET_ShortHashCode *hkey;
201 struct GNUNET_HashCode hc;
202 struct GNUNET_TESTING_NetjailNamespace *namespace;
203 unsigned int namespace_n, node_m;
204
205 log_topo (topology);
206
207 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
208 if (topology->nodes_x >= num)
209 {
210
211 GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
212 memcpy (hkey,
213 &hc,
214 sizeof (*hkey));
215 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
216 hkey);
217 }
218 else
219 {
220 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
221 / topology->nodes_m);
222 LOG (GNUNET_ERROR_TYPE_ERROR,
223 "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
224 num,
225 topology->nodes_x,
226 topology->nodes_m,
227 namespace_n);
228 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
229 GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
230 memcpy (hkey,
231 &hc,
232 sizeof (*hkey));
233 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
234 hkey);
235 node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
236 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
237 GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
238 memcpy (hkey,
239 &hc,
240 sizeof (*hkey));
241 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
242 hkey);
243 }
244
245
246 return node->node_connections_head;
247}
248
249
250static unsigned int
251calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
252 struct GNUNET_TESTING_NetjailTopology *topology)
253{
254 unsigned int n, m, num;
255
256 n = node_connection->namespace_n;
257 m = node_connection->node_n;
258
259 if (0 == n)
260 num = m;
261 else
262 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
263
264 return num;
265}
266
267static char *
268get_address (struct GNUNET_TESTING_NodeConnection *connection,
269 char *prefix)
270{
271 struct GNUNET_TESTING_NetjailNode *node;
272 char *addr;
273
274 node = connection->node;
275 if (connection->namespace_n == node->namespace_n)
276 {
277 if (0 == strcmp (PREFIX_TCP, prefix))
278 {
279
280 GNUNET_asprintf (&addr,
281 CONNECT_ADDRESS_TEMPLATE_TCP,
282 connection->node_n);
283 }
284 else if (0 == strcmp (PREFIX_UDP, prefix))
285 {
286 GNUNET_asprintf (&addr,
287 CONNECT_ADDRESS_TEMPLATE_UDP,
288 connection->node_n);
289 }
290 else
291 {
292 GNUNET_break (0);
293 }
294 }
295 else
296 {
297 if (0 == strcmp (PREFIX_TCP, prefix))
298 {
299
300 GNUNET_asprintf (&addr,
301 ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
302 connection->namespace_n);
303 }
304 else if (0 == strcmp (PREFIX_UDP, prefix))
305 {
306 GNUNET_asprintf (&addr,
307 ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
308 connection->namespace_n);
309 }
310 else
311 {
312 GNUNET_break (0);
313 }
314 }
315
316 return addr;
317}
318
319
320/**
321 * The run method of this cmd will connect to peers.
322 *
323 */
324static void
325connect_peers_run (void *cls,
326 const struct GNUNET_TESTING_Command *cmd,
327 struct GNUNET_TESTING_Interpreter *is)
328{
329 struct ConnectPeersState *cps = cls;
330 const struct GNUNET_TESTING_Command *system_cmd;
331 struct GNUNET_TESTING_System *tl_system;
332
333
334 const struct GNUNET_TESTING_Command *peer1_cmd;
335 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
336 struct GNUNET_PeerIdentity *peer;
337 char *addr;
338 enum GNUNET_NetworkType nt = 0;
339 uint32_t num;
340 struct GNUNET_TESTING_NodeConnection *pos_connection;
341 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
342 unsigned int con_num = 0;
343
344 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
345 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
346 &ah);
347
348 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label);
349 GNUNET_TESTING_get_trait_test_system (system_cmd,
350 &tl_system);
351
352 cps->tl_system = tl_system;
353
354 cps->node_connections_head = get_connections (cps->num, cps->topology);
355
356 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
357 pos_connection = pos_connection->next)
358 {
359 con_num++;
360 num = calculate_num (pos_connection, cps->topology);
361 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
362 pos_prefix =
363 pos_prefix->next)
364 {
365
366 LOG (GNUNET_ERROR_TYPE_ERROR,
367 "prefix: %s\n",
368 pos_prefix->address_prefix);
369
370 addr = get_address (pos_connection, pos_prefix->address_prefix);
371
372 peer = get_pub_key (num, tl_system);
373
374 LOG (GNUNET_ERROR_TYPE_ERROR,
375 "num: %u pub_key %s addr: %s\n",
376 num,
377 GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)),
378 addr);
379
380 cps->id = peer;
381
382 GNUNET_TRANSPORT_application_validate (ah,
383 peer,
384 nt,
385 addr);
386 }
387 }
388 cps->con_num = con_num;
389}
390
391
392/**
393 * The finish function of this cmd will check if the peers we are trying to
394 * connect to are in the connected peers map of the start peer cmd for this peer.
395 *
396 */
397static int
398connect_peers_finish (void *cls,
399 GNUNET_SCHEDULER_TaskCallback cont,
400 void *cont_cls)
401{
402 struct ConnectPeersState *cps = cls;
403 const struct GNUNET_TESTING_Command *peer1_cmd;
404 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
405 unsigned int ret;
406 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
407 struct GNUNET_HashCode hc;
408 struct GNUNET_PeerIdentity *peer;
409 unsigned int con_num = 0;
410 struct GNUNET_TESTING_NodeConnection *pos_connection;
411 unsigned int num;
412
413 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
414 GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
415 &connected_peers_map);
416
417 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
418 pos_connection = pos_connection->next)
419 {
420 num = calculate_num (pos_connection, cps->topology);
421 peer = get_pub_key (num, cps->tl_system);
422 GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc);
423 memcpy (key,
424 &hc,
425 sizeof (*key));
426 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
427 connected_peers_map,
428 key))
429 con_num++;
430 }
431
432
433
434 if (cps->con_num == con_num)
435 {
436 cont (cont_cls);
437 ret = GNUNET_YES;
438 }
439
440 GNUNET_free (key);
441 return ret;
442}
443
444
445/**
446 * Trait function of this cmd does nothing.
447 *
448 */
449static int
450connect_peers_traits (void *cls,
451 const void **ret,
452 const char *trait,
453 unsigned int index)
454{
455 return GNUNET_OK;
456}
457
458
459/**
460 * The cleanup function of this cmd frees resources the cmd allocated.
461 *
462 */
463static void
464connect_peers_cleanup (void *cls,
465 const struct GNUNET_TESTING_Command *cmd)
466{
467 struct ConnectPeersState *cps = cls;
468
469 GNUNET_free (cps->id);
470 GNUNET_free (cps);
471}
472
473
474/**
475 * Create command.
476 *
477 * @param label name for command.
478 * @param start_peer_label Label of the cmd to start a peer.
479 * @return command.
480 */
481struct GNUNET_TESTING_Command
482GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
483 const char *start_peer_label,
484 const char *create_label,
485 uint32_t num,
486 struct GNUNET_TESTING_NetjailTopology *
487 topology)
488{
489 struct ConnectPeersState *cps;
490
491 cps = GNUNET_new (struct ConnectPeersState);
492 cps->start_peer_label = start_peer_label;
493 cps->num = num;
494 cps->create_label = create_label;
495 cps->topology = topology;
496
497
498 struct GNUNET_TESTING_Command cmd = {
499 .cls = cps,
500 .label = label,
501 .run = &connect_peers_run,
502 .finish = &connect_peers_finish,
503 .cleanup = &connect_peers_cleanup,
504 .traits = &connect_peers_traits
505 };
506
507 return cmd;
508}
diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c
new file mode 100644
index 000000000..b5cefecc8
--- /dev/null
+++ b/src/transport/transport_api_cmd_start_peer_v3.c
@@ -0,0 +1,619 @@
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 const struct GNUNET_TESTING_Command *cmd,
179 struct GNUNET_TESTING_Interpreter *is)
180{
181 struct StartPeerState_v2 *sps = cls;
182 char *emsg = NULL;
183 struct GNUNET_PeerIdentity dummy;
184 const struct GNUNET_TESTING_Command *system_cmd;
185 struct GNUNET_TESTING_System *tl_system;
186 char *home;
187 char *transport_unix_path;
188 char *tcp_communicator_unix_path;
189 char *udp_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 ();
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 (&tcp_communicator_unix_path,
215 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
216 sps->no);
217
218 GNUNET_asprintf (&udp_communicator_unix_path,
219 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
220 sps->no);
221
222 GNUNET_asprintf (&bindto,
223 "%s:60002",
224 sps->node_ip);
225
226 LOG (GNUNET_ERROR_TYPE_ERROR,
227 "node_ip %s\n",
228 bindto);
229
230 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
231 home);
232 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
233 transport_unix_path);
234 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
235 "BINDTO",
236 bindto);
237 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
238 "BINDTO",
239 bindto);
240 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
241 "UNIXPATH",
242 tcp_communicator_unix_path);
243 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
244 "UNIXPATH",
245 udp_communicator_unix_path);
246
247 system_cmd = GNUNET_TESTING_interpreter_lookup_command (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 ();
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 ();
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 ();
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 ();
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 ();
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 ();
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 ();
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 const struct GNUNET_TESTING_Command *cmd)
365{
366 struct StartPeerState_v2 *sps = cls;
367
368 if (NULL != sps->handlers)
369 {
370 GNUNET_free (sps->handlers);
371 sps->handlers = NULL;
372 }
373 if (NULL != sps->cfg)
374 {
375 GNUNET_CONFIGURATION_destroy (sps->cfg);
376 sps->cfg = NULL;
377 }
378 GNUNET_free (sps->hello);
379 GNUNET_free (sps->connected_peers_map);
380 GNUNET_free (sps);
381}
382
383
384/**
385 * This function prepares an array with traits.
386 *
387 */
388static int
389start_peer_traits (void *cls,
390 const void **ret,
391 const char *trait,
392 unsigned int index)
393{
394 struct StartPeerState_v2 *sps = cls;
395 struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah;
396 struct GNUNET_PeerIdentity *id = &sps->id;
397 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
398 sps->connected_peers_map;
399 char *hello = sps->hello;
400 size_t hello_size = sps->hello_size;
401
402
403 struct GNUNET_TESTING_Trait traits[] = {
404 {
405 .index = 0,
406 .trait_name = "application_handle",
407 .ptr = (const void *) ah,
408 },
409 {
410 .index = 1,
411 .trait_name = "peer_id",
412 .ptr = (const void *) id,
413 },
414 {
415 .index = 2,
416 .trait_name = "connected_peers_map",
417 .ptr = (const void *) connected_peers_map,
418 },
419 {
420 .index = 3,
421 .trait_name = "hello",
422 .ptr = (const void *) hello,
423 },
424 {
425 .index = 4,
426 .trait_name = "hello_size",
427 .ptr = (const void *) hello_size,
428 },
429 {
430 .index = 5,
431 .trait_name = "state",
432 .ptr = (const void *) sps,
433 },
434 GNUNET_TESTING_trait_end ()
435 };
436
437 return GNUNET_TESTING_get_trait (traits,
438 ret,
439 trait,
440 index);
441}
442
443
444/**
445 * Function to get the trait with the struct StartPeerState_v2.
446 *
447 * @param[out] sps struct StartPeerState_v2.
448 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
449 *
450 */
451int
452GNUNET_TRANSPORT_get_trait_state_v3 (const struct
453 GNUNET_TESTING_Command
454 *cmd,
455 struct StartPeerState_v2 **sps)
456{
457 return cmd->traits (cmd->cls,
458 (const void **) sps,
459 "state",
460 (unsigned int) 5);
461}
462
463
464/**
465 * Function to get the trait with the size of the hello.
466 *
467 * @param[out] hello_size size of hello.
468 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
469 *
470 */
471int
472GNUNET_TRANSPORT_get_trait_hello_size_v3 (const struct
473 GNUNET_TESTING_Command
474 *cmd,
475 size_t **hello_size)
476{
477 return cmd->traits (cmd->cls,
478 (const void **) hello_size,
479 "hello_size",
480 (unsigned int) 4);
481}
482
483
484/**
485 * Function to get the trait with the hello.
486 *
487 * @param[out] hello The hello for the peer.
488 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
489 *
490 */
491int
492GNUNET_TRANSPORT_get_trait_hello_v3 (const struct
493 GNUNET_TESTING_Command
494 *cmd,
495 char **hello)
496{
497 return cmd->traits (cmd->cls,
498 (const void **) hello,
499 "hello",
500 (unsigned int) 3);
501}
502
503
504/**
505 * Function to get the trait with the map of connected peers.
506 *
507 * @param[out] connected_peers_map The map with connected peers.
508 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
509 *
510 */
511int
512GNUNET_TRANSPORT_get_trait_connected_peers_map_v3 (const struct
513 GNUNET_TESTING_Command
514 *cmd,
515 struct
516 GNUNET_CONTAINER_MultiShortmap
517 *
518 *
519 connected_peers_map)
520{
521 return cmd->traits (cmd->cls,
522 (const void **) connected_peers_map,
523 "connected_peers_map",
524 (unsigned int) 2);
525}
526
527
528/**
529 * Function to get the trait with the transport application handle.
530 *
531 * @param[out] ah The application handle.
532 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
533 */
534int
535GNUNET_TRANSPORT_get_trait_application_handle_v3 (const struct
536 GNUNET_TESTING_Command *cmd,
537 struct
538 GNUNET_TRANSPORT_ApplicationHandle
539 **ah)
540{
541 return cmd->traits (cmd->cls,
542 (const void **) ah,
543 "application_handle",
544 (unsigned int) 0);
545}
546
547
548/**
549 * Function to get the trait with the peer id.
550 *
551 * @param[out] id The peer id.
552 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
553 */
554int
555GNUNET_TRANSPORT_get_trait_peer_id_v3 (const struct
556 GNUNET_TESTING_Command *cmd,
557 struct GNUNET_PeerIdentity **id)
558{
559 return cmd->traits (cmd->cls,
560 (const void **) id,
561 "peer_id",
562 (unsigned int) 1);
563}
564
565
566/**
567 * Create command.
568 *
569 * @param label name for command.
570 * @param system_label Label of the cmd to setup a test environment.
571 * @param m The number of the local node of the actual network namespace.
572 * @param n The number of the actual namespace.
573 * @param local_m Number of local nodes in each namespace.
574 * @param handlers Handler for messages received by this peer.
575 * @param cfgname Configuration file name for this peer.
576 * @return command.
577 */
578struct GNUNET_TESTING_Command
579GNUNET_TRANSPORT_cmd_start_peer_v3 (const char *label,
580 const char *system_label,
581 uint32_t no,
582 char *node_ip,
583 struct GNUNET_MQ_MessageHandler *handlers,
584 const char *cfgname)
585{
586 struct StartPeerState_v2 *sps;
587 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
588 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
589 unsigned int i;
590
591 sps = GNUNET_new (struct StartPeerState_v2);
592 sps->no = no;
593 sps->system_label = system_label;
594 sps->connected_peers_map = connected_peers_map;
595 sps->cfgname = cfgname;
596 sps->node_ip = node_ip;
597
598 if (NULL != handlers)
599 {
600 for (i = 0; NULL != handlers[i].cb; i++)
601 ;
602 sps->handlers = GNUNET_new_array (i + 1,
603 struct GNUNET_MQ_MessageHandler);
604 GNUNET_memcpy (sps->handlers,
605 handlers,
606 i * sizeof(struct GNUNET_MQ_MessageHandler));
607 }
608
609 struct GNUNET_TESTING_Command cmd = {
610 .cls = sps,
611 .label = label,
612 .run = &start_peer_run,
613 .finish = &start_peer_finish,
614 .cleanup = &start_peer_cleanup,
615 .traits = &start_peer_traits
616 };
617
618 return cmd;
619}