aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-15 21:02:03 +0200
committert3sserakt <t3ss@posteo.de>2021-10-15 21:02:03 +0200
commit513f23e74650db9408267e82ef8bcb8f770d1015 (patch)
tree312db7072dc444e9d1e6a13000b79482eb14de82 /src/transport
parentd190d23831dae1a77075557f2ff6e0c713d747d5 (diff)
parentd64ac269856744b9bab170964e1d6f36896ecc55 (diff)
downloadgnunet-513f23e74650db9408267e82ef8bcb8f770d1015.tar.gz
gnunet-513f23e74650db9408267e82ef8bcb8f770d1015.zip
Merge branch 'master' into dev/t3ss/tng
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am53
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c195
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_v2.c237
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c177
-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_topo.conf4
-rw-r--r--src/transport/test_transport_simple_send_v2.c89
-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.h253
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c515
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v2.c242
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v3.c281
-rw-r--r--src/transport/transport_api_cmd_send_simple.c48
-rw-r--r--src/transport/transport_api_cmd_send_simple_v2.c156
-rw-r--r--src/transport/transport_api_cmd_start_peer.c101
-rw-r--r--src/transport/transport_api_cmd_start_peer_v2.c607
-rw-r--r--src/transport/transport_api_cmd_start_peer_v3.c619
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c27
21 files changed, 763 insertions, 3075 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 73544a8d5..d281c4ffb 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -128,11 +128,9 @@ noinst_PROGRAMS = \
128 $(WLAN_BIN_SENDER) \ 128 $(WLAN_BIN_SENDER) \
129 $(WLAN_BIN_RECEIVER) 129 $(WLAN_BIN_RECEIVER)
130 130
131if HAVE_TESTING
132TESTING_LIBS = \ 131TESTING_LIBS = \
133 libgnunettransporttesting.la \ 132 libgnunettransporttesting.la \
134 libgnunettransporttesting2.la 133 libgnunettransporttesting2.la
135endif
136 134
137lib_LTLIBRARIES = \ 135lib_LTLIBRARIES = \
138 libgnunettransport.la \ 136 libgnunettransport.la \
@@ -161,16 +159,10 @@ libgnunettransporttesting_la_LDFLAGS = \
161 159
162libgnunettransporttesting2_la_SOURCES = \ 160libgnunettransporttesting2_la_SOURCES = \
163 transport_api_cmd_connecting_peers.c \ 161 transport_api_cmd_connecting_peers.c \
164 transport_api_cmd_connecting_peers_v2.c \
165 transport_api_cmd_connecting_peers_v3.c \
166 transport_api_cmd_backchannel_check.c \ 162 transport_api_cmd_backchannel_check.c \
167 transport_api_cmd_start_peer.c \ 163 transport_api_cmd_start_peer.c \
168 transport_api_cmd_start_peer_v2.c \
169 transport_api_cmd_start_peer_v3.c \
170 transport_api_cmd_stop_peer.c \ 164 transport_api_cmd_stop_peer.c \
171 transport_api_cmd_send_simple.c \ 165 transport_api_cmd_send_simple.c \
172 transport_api_cmd_send_simple_v2.c \
173 transport_api_cmd_send_simple_v3.c \
174 transport-testing2.c transport-testing2.h \ 166 transport-testing2.c transport-testing2.h \
175 transport-testing-cmds.h \ 167 transport-testing-cmds.h \
176 transport-testing-filenames2.c \ 168 transport-testing-filenames2.c \
@@ -398,7 +390,6 @@ plugin_LTLIBRARIES = \
398 $(WLAN_PLUGIN_LA) \ 390 $(WLAN_PLUGIN_LA) \
399 $(BT_PLUGIN_LA) \ 391 $(BT_PLUGIN_LA) \
400 libgnunet_test_transport_plugin_cmd_simple_send.la \ 392 libgnunet_test_transport_plugin_cmd_simple_send.la \
401 libgnunet_test_transport_plugin_cmd_simple_send_v2.la \
402 libgnunet_test_transport_plugin_cmd_udp_backchannel.la 393 libgnunet_test_transport_plugin_cmd_udp_backchannel.la
403 394
404libgnunet_test_transport_plugin_cmd_udp_backchannel_la_SOURCES = \ 395libgnunet_test_transport_plugin_cmd_udp_backchannel_la_SOURCES = \
@@ -435,23 +426,6 @@ libgnunet_test_transport_plugin_cmd_simple_send_la_LIBADD = \
435libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \ 426libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \
436 $(GN_PLUGIN_LDFLAGS) 427 $(GN_PLUGIN_LDFLAGS)
437 428
438libgnunet_test_transport_plugin_cmd_simple_send_v2_la_SOURCES = \
439 test_transport_plugin_cmd_simple_send_v2.c
440libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LIBADD = \
441 libgnunettransporttesting2.la \
442 libgnunettransportapplication.la \
443 libgnunettransportcore.la \
444 $(top_builddir)/src/testing/libgnunettesting.la \
445 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
446 $(top_builddir)/src/statistics/libgnunetstatistics.la \
447 $(top_builddir)/src/hello/libgnunethello.la \
448 $(top_builddir)/src/ats/libgnunetats.la \
449 $(top_builddir)/src/arm/libgnunetarm.la \
450 $(top_builddir)/src/util/libgnunetutil.la \
451 $(LTLIBINTL)
452libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LDFLAGS = \
453 $(GN_PLUGIN_LDFLAGS)
454
455if HAVE_EXPERIMENTAL 429if HAVE_EXPERIMENTAL
456plugin_LTLIBRARIES += \ 430plugin_LTLIBRARIES += \
457 libgnunet_plugin_transport_udp.la 431 libgnunet_plugin_transport_udp.la
@@ -596,10 +570,7 @@ libgnunet_plugin_transport_https_server_la_LDFLAGS = \
596libgnunet_plugin_transport_https_server_la_CFLAGS = \ 570libgnunet_plugin_transport_https_server_la_CFLAGS = \
597 $(MHD_CFLAGS) $(AM_CFLAGS) -DBUILD_HTTPS 571 $(MHD_CFLAGS) $(AM_CFLAGS) -DBUILD_HTTPS
598 572
599if HAVE_TESTING
600check_PROGRAMS = \ 573check_PROGRAMS = \
601 test_transport_simple_send \
602 test_transport_simple_send_v2 \
603 test_transport_start_with_config \ 574 test_transport_start_with_config \
604 test_transport_address_switch_tcp \ 575 test_transport_address_switch_tcp \
605 test_transport_testing_startstop \ 576 test_transport_testing_startstop \
@@ -684,7 +655,6 @@ check_PROGRAMS += \
684 test_communicator_backchannel-udp \ 655 test_communicator_backchannel-udp \
685 test_communicator_bidirect-tcp 656 test_communicator_bidirect-tcp
686endif 657endif
687endif
688 658
689if ENABLE_TEST_RUN 659if ENABLE_TEST_RUN
690AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 660AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
@@ -749,8 +719,6 @@ test_transport_api_slow_ats
749endif 719endif
750if HAVE_EXPERIMENTAL 720if HAVE_EXPERIMENTAL
751TESTS += \ 721TESTS += \
752 test_transport_simple_send \
753 test_transport_simple_send_v2 \
754 test_transport_start_with_config \ 722 test_transport_start_with_config \
755 test_transport_address_switch_udp \ 723 test_transport_address_switch_udp \
756 test_plugin_udp \ 724 test_plugin_udp \
@@ -771,7 +739,6 @@ endif
771 739
772check_SCRIPTS= \ 740check_SCRIPTS= \
773 test_transport_simple_send.sh \ 741 test_transport_simple_send.sh \
774 test_transport_simple_send_v2.sh \
775 test_transport_udp_backchannel.sh 742 test_transport_udp_backchannel.sh
776 743
777test_transport_start_with_config_SOURCES = \ 744test_transport_start_with_config_SOURCES = \
@@ -784,26 +751,6 @@ test_transport_start_with_config_LDADD = \
784 libgnunettransportcore.la \ 751 libgnunettransportcore.la \
785 libgnunettransporttesting2.la 752 libgnunettransporttesting2.la
786 753
787test_transport_simple_send_SOURCES = \
788 test_transport_simple_send.c
789test_transport_simple_send_LDADD = \
790 $(top_builddir)/src/testing/libgnunettesting.la \
791 $(top_builddir)/src/util/libgnunetutil.la \
792 $(top_builddir)/src/testbed/libgnunettestbed.la \
793 $(top_builddir)/src/hello/libgnunethello.la \
794 libgnunettransportcore.la \
795 libgnunettransporttesting2.la
796
797test_transport_simple_send_v2_SOURCES = \
798 test_transport_simple_send_v2.c
799test_transport_simple_send_v2_LDADD = \
800 $(top_builddir)/src/testing/libgnunettesting.la \
801 $(top_builddir)/src/util/libgnunetutil.la \
802 $(top_builddir)/src/testbed/libgnunettestbed.la \
803 $(top_builddir)/src/hello/libgnunethello.la \
804 libgnunettransportcore.la \
805 libgnunettransporttesting2.la
806
807test_transport_testing_startstop_SOURCES = \ 754test_transport_testing_startstop_SOURCES = \
808 test_transport_testing_startstop.c 755 test_transport_testing_startstop.c
809test_transport_testing_startstop_LDADD = \ 756test_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 b578219ca..8889f9d06 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -37,28 +37,33 @@
37 37
38#define BASE_DIR "testdir" 38#define BASE_DIR "testdir"
39 39
40/**
41 * The name for a specific test environment directory.
42 *
43 */
44char *testdir;
45 40
46/** 41struct TestState
47 * The name for the configuration file of the specific node. 42{
48 * 43 /**
49 */ 44 * Callback to write messages to the master loop.
50char *cfgname; 45 *
46 */
47 TESTING_CMD_HELPER_write_cb write_message;
51 48
52/** 49 /**
53 * Flag indicating if all peers have been started. 50 * The name for a specific test environment directory.
54 * 51 *
55 */ 52 */
56unsigned int are_all_peers_started; 53 char *testdir;
57 54
58/** 55 /**
59 * Flag indicating a received message. 56 * The name for the configuration file of the specific node.
60 */ 57 *
61unsigned int message_received; 58 */
59 char *cfgname;
60};
61
62static struct GNUNET_TESTING_Command block_send;
63
64static struct GNUNET_TESTING_Command block_receive;
65
66static struct GNUNET_TESTING_Command connect_peers;
62 67
63 68
64/** 69/**
@@ -83,7 +88,14 @@ static void
83handle_test (void *cls, 88handle_test (void *cls,
84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 89 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
85{ 90{
86 message_received = GNUNET_YES; 91 struct GNUNET_TESTING_AsyncContext *ac;
92
93 GNUNET_TESTING_get_trait_async_context (&block_receive,
94 &ac);
95 if ((NULL == ac) || (NULL == ac->cont))
96 GNUNET_TESTING_async_fail (ac);
97 else
98 GNUNET_TESTING_async_finish (ac);
87} 99}
88 100
89 101
@@ -94,7 +106,62 @@ handle_test (void *cls,
94static void 106static void
95all_peers_started () 107all_peers_started ()
96{ 108{
97 are_all_peers_started = GNUNET_YES; 109 struct GNUNET_TESTING_AsyncContext *ac;
110
111 GNUNET_TESTING_get_trait_async_context (&block_send,
112 &ac);
113 if ((NULL == ac) || (NULL == ac->cont))
114 GNUNET_TESTING_async_fail (ac);
115 else
116 GNUNET_TESTING_async_finish (ac);
117}
118
119
120/**
121 * Function called with the final result of the test.
122 *
123 * @param cls the `struct MainParams`
124 * @param rv #GNUNET_OK if the test passed
125 */
126static void
127handle_result (void *cls,
128 enum GNUNET_GenericReturnValue rv)
129{
130 struct TestState *ts = cls;
131 struct GNUNET_MessageHeader *reply;
132
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
134 "Local test exits with status %d\n",
135 rv);
136 reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
137
138 ts->write_message (reply,
139 ntohs (reply->size));
140 GNUNET_free (ts->testdir);
141 GNUNET_free (ts->cfgname);
142 GNUNET_free (ts);
143}
144
145
146/**
147 * Callback from start peer cmd for signaling a peer got connected.
148 *
149 */
150static void *
151notify_connect (void *cls,
152 const struct GNUNET_PeerIdentity *peer,
153 struct GNUNET_MQ_Handle *mq)
154{
155 struct ConnectPeersState *cps;
156
157 GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
158 &cps);
159 void *ret = NULL;
160
161 cps->notify_connect (cps,
162 peer,
163 mq);
164 return ret;
98} 165}
99 166
100 167
@@ -116,24 +183,46 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
116 char *local_m) 183 char *local_m)
117{ 184{
118 185
119 GNUNET_asprintf (&cfgname, 186 unsigned int n_int;
120 "test_transport_api2_tcp_node%s.conf", 187 unsigned int m_int;
121 "1"); 188 unsigned int local_m_int;
189 unsigned int num;
190 struct TestState *ts = GNUNET_new (struct TestState);
191 struct GNUNET_TESTING_NetjailTopology *topology =
192 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
193
194 if (0 == m_int)
195 num = n_int;
196 else
197 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
198
199 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
200 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
201 "block-receive");
202 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
203 "start-peer",
204 "system-create",
205 num,
206 NULL);
207
208
209
210 sscanf (m, "%u", &m_int);
211 sscanf (n, "%u", &n_int);
212 sscanf (local_m, "%u", &local_m_int);
213
214 GNUNET_asprintf (&ts->cfgname,
215 "test_transport_api2_tcp_node1.conf");
122 216
123 LOG (GNUNET_ERROR_TYPE_ERROR, 217 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "plugin cfgname: %s\n", 218 "plugin cfgname: %s\n",
125 cfgname); 219 ts->cfgname);
126 220
127 LOG (GNUNET_ERROR_TYPE_ERROR, 221 LOG (GNUNET_ERROR_TYPE_ERROR,
128 "node ip: %s\n", 222 "node ip: %s\n",
129 node_ip); 223 node_ip);
130 224
131 LOG (GNUNET_ERROR_TYPE_ERROR, 225 GNUNET_asprintf (&ts->testdir,
132 "m: %s n: %s\n",
133 m,
134 n);
135
136 GNUNET_asprintf (&testdir,
137 "%s%s%s", 226 "%s%s%s",
138 BASE_DIR, 227 BASE_DIR,
139 m, 228 m,
@@ -143,50 +232,38 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
143 GNUNET_MQ_hd_var_size (test, 232 GNUNET_MQ_hd_var_size (test,
144 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 233 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
145 struct GNUNET_TRANSPORT_TESTING_TestMessage, 234 struct GNUNET_TRANSPORT_TESTING_TestMessage,
146 NULL), 235 ts),
147 GNUNET_MQ_handler_end () 236 GNUNET_MQ_handler_end ()
148 }; 237 };
149 238
150 struct GNUNET_TESTING_Command commands[] = { 239 struct GNUNET_TESTING_Command commands[] = {
151 GNUNET_TESTING_cmd_system_create ("system-create", 240 GNUNET_TESTING_cmd_system_create ("system-create",
152 testdir), 241 ts->testdir),
153 GNUNET_TRANSPORT_cmd_start_peer ("start-peer", 242 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
154 "system-create", 243 "system-create",
155 m, 244 num,
156 n,
157 local_m,
158 node_ip, 245 node_ip,
159 handlers, 246 handlers,
160 cfgname), 247 ts->cfgname,
248 notify_connect),
161 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", 249 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
162 write_message), 250 write_message),
163 GNUNET_TESTING_cmd_block_until_all_peers_started ("block", 251 block_send,
164 &are_all_peers_started), 252 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", 253 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
171 m, 254 "start-peer",
172 n, 255 num),
173 (atoi (n) - 1) * atoi (local_m) + atoi ( 256 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", 257 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
179 "start-peer"), 258 "start-peer"),
180 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 259 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
181 "system-create"), 260 "system-create")
182 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
183 write_message),
184 GNUNET_TESTING_cmd_end_without_shutdown ()
185 }; 261 };
186 262
187 GNUNET_TESTING_run (NULL, 263 GNUNET_TESTING_run (commands,
188 commands, 264 GNUNET_TIME_UNIT_FOREVER_REL,
189 GNUNET_TIME_UNIT_FOREVER_REL); 265 &handle_result,
266 ts);
190 267
191} 268}
192 269
@@ -225,8 +302,6 @@ libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
225 struct GNUNET_TESTING_PluginFunctions *api = cls; 302 struct GNUNET_TESTING_PluginFunctions *api = cls;
226 303
227 GNUNET_free (api); 304 GNUNET_free (api);
228 GNUNET_free (testdir);
229 GNUNET_free (cfgname);
230 return NULL; 305 return NULL;
231} 306}
232 307
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 c308d9a29..000000000
--- a/src/transport/test_transport_plugin_cmd_simple_send_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 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 LOG (GNUNET_ERROR_TYPE_DEBUG,
89 "Message received\n");
90 message_received = GNUNET_YES;
91}
92
93
94/**
95 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
96 *
97 */
98static void
99all_peers_started ()
100{
101 are_all_peers_started = GNUNET_YES;
102}
103
104
105/**
106 * Function to start a local test case.
107 *
108 * @param write_message Callback to send a message to the master loop.
109 * @param router_ip Global address of the network namespace.
110 * @param node_ip Local address of a node i a network namespace.
111 * @param m The number of the node in a network namespace.
112 * @param n The number of the network namespace.
113 * @param local_m The number of nodes in a network namespace.
114 */
115static void
116start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
117 char *node_ip,
118 char *m,
119 char *n,
120 char *local_m)
121{
122
123 unsigned int n_int, m_int, local_m_int, num;
124
125 struct GNUNET_TESTING_NetjailTopology *topology =
126 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
127
128 sscanf (m, "%u", &m_int);
129 sscanf (n, "%u", &n_int);
130 sscanf (local_m, "%u", &local_m_int);
131
132
133 if (0 == m_int)
134 num = n_int;
135 else
136 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
137
138 GNUNET_asprintf (&cfgname,
139 "test_transport_api2_tcp_node1.conf");
140
141 LOG (GNUNET_ERROR_TYPE_ERROR,
142 "plugin cfgname: %s\n",
143 cfgname);
144
145 LOG (GNUNET_ERROR_TYPE_ERROR,
146 "node ip: %s\n",
147 node_ip);
148
149 GNUNET_asprintf (&testdir,
150 "%s%s%s",
151 BASE_DIR,
152 m,
153 n);
154
155 struct GNUNET_MQ_MessageHandler handlers[] = {
156 GNUNET_MQ_hd_var_size (test,
157 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
158 struct GNUNET_TRANSPORT_TESTING_TestMessage,
159 NULL),
160 GNUNET_MQ_handler_end ()
161 };
162
163 struct GNUNET_TESTING_Command commands[] = {
164 GNUNET_TESTING_cmd_system_create ("system-create",
165 testdir),
166 GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
167 "system-create",
168 num,
169 node_ip,
170 handlers,
171 cfgname),
172 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
173 write_message),
174 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
175 &are_all_peers_started),
176 GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
177 "start-peer",
178 "system-create",
179 num),
180 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
181 "start-peer",
182 num),
183 GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive",
184 &message_received),
185 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
186 "start-peer"),
187 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
188 "system-create"),
189 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
190 write_message),
191 GNUNET_TESTING_cmd_end_without_shutdown ()
192 };
193
194 GNUNET_TESTING_run (NULL,
195 commands,
196 GNUNET_TIME_UNIT_FOREVER_REL);
197
198}
199
200
201/**
202 * Entry point for the plugin.
203 *
204 * @param cls NULL
205 * @return the exported block API
206 */
207void *
208libgnunet_test_transport_plugin_cmd_simple_send_v2_init (void *cls)
209{
210 struct GNUNET_TESTING_PluginFunctions *api;
211
212 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
213 api->start_testcase = &start_testcase;
214 api->all_peers_started = &all_peers_started;
215 return api;
216}
217
218
219/**
220 * Exit point from the plugin.
221 *
222 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
223 * @return NULL
224 */
225void *
226libgnunet_test_transport_plugin_cmd_simple_send_v2_done (void *cls)
227{
228 struct GNUNET_TESTING_PluginFunctions *api = cls;
229
230 GNUNET_free (api);
231 GNUNET_free (testdir);
232 GNUNET_free (cfgname);
233 return NULL;
234}
235
236
237/* 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 e2e0b258b..b0ca37447 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -39,34 +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 if all local tests are prepared to finish.
62 *
63 */
64unsigned int are_all_local_tests_prepared;
65 64
66/** 65static struct GNUNET_TESTING_Command block_receive;
67 * Flag indicating a received message. 66
68 */ 67static struct GNUNET_TESTING_Command connect_peers;
69unsigned int message_received;
70 68
71 69
72/** 70/**
@@ -91,9 +89,14 @@ static void
91handle_test (void *cls, 89handle_test (void *cls,
92 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 90 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
93{ 91{
94 LOG (GNUNET_ERROR_TYPE_DEBUG, 92 struct GNUNET_TESTING_AsyncContext *ac;
95 "Message received.\n"); 93
96 message_received = GNUNET_YES; 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);
97} 100}
98 101
99 102
@@ -104,14 +107,65 @@ handle_test (void *cls,
104static void 107static void
105all_peers_started () 108all_peers_started ()
106{ 109{
107 are_all_peers_started = GNUNET_YES; 110 struct GNUNET_TESTING_AsyncContext *ac;
108 LOG (GNUNET_ERROR_TYPE_ERROR, 111
109 "setting are_all_peers_started: %d\n", 112 GNUNET_TESTING_get_trait_async_context (&block_send,
110 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);
111} 118}
112 119
113 120
114/** 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;
166}
167
168/**
115 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api. 169 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
116 */ 170 */
117static void 171static void
@@ -120,7 +174,6 @@ all_local_tests_prepared ()
120 are_all_local_tests_prepared = GNUNET_YES; 174 are_all_local_tests_prepared = GNUNET_YES;
121} 175}
122 176
123
124/** 177/**
125 * Function to start a local test case. 178 * Function to start a local test case.
126 * 179 *
@@ -139,7 +192,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
139 char *local_m) 192 char *local_m)
140{ 193{
141 194
142 unsigned int n_int, m_int, local_m_int, num; 195 unsigned int n_int;
196 unsigned int m_int;
197 unsigned int local_m_int;
198 unsigned int num;
199 struct TestState *ts = GNUNET_new (struct TestState);
143 200
144 struct GNUNET_TESTING_NetjailTopology *topology = 201 struct GNUNET_TESTING_NetjailTopology *topology =
145 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); 202 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
@@ -154,18 +211,27 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
154 else 211 else
155 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; 212 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
156 213
157 GNUNET_asprintf (&cfgname, 214 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
215 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
216 "block-receive");
217 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
218 "start-peer",
219 "system-create",
220 num,
221 NULL);
222
223 GNUNET_asprintf (&ts->cfgname,
158 "test_transport_api2_tcp_node1.conf"); 224 "test_transport_api2_tcp_node1.conf");
159 225
160 LOG (GNUNET_ERROR_TYPE_ERROR, 226 LOG (GNUNET_ERROR_TYPE_ERROR,
161 "plugin cfgname: %s\n", 227 "plugin cfgname: %s\n",
162 cfgname); 228 ts->cfgname);
163 229
164 LOG (GNUNET_ERROR_TYPE_ERROR, 230 LOG (GNUNET_ERROR_TYPE_ERROR,
165 "node ip: %s\n", 231 "node ip: %s\n",
166 node_ip); 232 node_ip);
167 233
168 GNUNET_asprintf (&testdir, 234 GNUNET_asprintf (&ts->testdir,
169 "%s%s%s", 235 "%s%s%s",
170 BASE_DIR, 236 BASE_DIR,
171 m, 237 m,
@@ -181,22 +247,18 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
181 247
182 struct GNUNET_TESTING_Command commands[] = { 248 struct GNUNET_TESTING_Command commands[] = {
183 GNUNET_TESTING_cmd_system_create ("system-create", 249 GNUNET_TESTING_cmd_system_create ("system-create",
184 testdir), 250 ts->testdir),
185 GNUNET_TRANSPORT_cmd_start_peer_v3 ("start-peer", 251 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
186 "system-create", 252 "system-create",
187 num, 253 num,
188 node_ip, 254 node_ip,
189 handlers, 255 handlers,
190 cfgname), 256 ts->cfgname,
257 notify_connect),
191 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", 258 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
192 write_message), 259 write_message),
193 GNUNET_TESTING_cmd_block_until_all_peers_started ("block", 260 block_send,
194 &are_all_peers_started), 261 connect_peers,
195 GNUNET_TRANSPORT_cmd_connect_peers_v3 ("connect-peers",
196 "start-peer",
197 "system-create",
198 num,
199 topology),
200 GNUNET_TRANSPORT_cmd_backchannel_check ("backchannel-check", 262 GNUNET_TRANSPORT_cmd_backchannel_check ("backchannel-check",
201 "start-peer", 263 "start-peer",
202 "system-create", 264 "system-create",
@@ -207,18 +269,17 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
207 GNUNET_TESTING_cmd_local_test_prepared ("local-test-prepared", 269 GNUNET_TESTING_cmd_local_test_prepared ("local-test-prepared",
208 write_message, 270 write_message,
209 &are_all_local_tests_prepared), 271 &are_all_local_tests_prepared),
272 block_receive,
210 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", 273 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
211 "start-peer"), 274 "start-peer"),
212 GNUNET_TESTING_cmd_system_destroy ("system-destroy", 275 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
213 "system-create"), 276 "system-create")
214 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
215 write_message),
216 GNUNET_TESTING_cmd_end_without_shutdown ()
217 }; 277 };
218 278
219 GNUNET_TESTING_run (NULL, 279 GNUNET_TESTING_run (commands,
220 commands, 280 GNUNET_TIME_UNIT_FOREVER_REL,
221 GNUNET_TIME_UNIT_FOREVER_REL); 281 &handle_result,
282 ts);
222 283
223} 284}
224 285
@@ -258,8 +319,6 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_done (void *cls)
258 struct GNUNET_TESTING_PluginFunctions *api = cls; 319 struct GNUNET_TESTING_PluginFunctions *api = cls;
259 320
260 GNUNET_free (api); 321 GNUNET_free (api);
261 GNUNET_free (testdir);
262 GNUNET_free (cfgname);
263 return NULL; 322 return NULL;
264} 323}
265 324
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_topo.conf b/src/transport/test_transport_simple_send_topo.conf
new file mode 100644
index 000000000..f878f9719
--- /dev/null
+++ b/src/transport/test_transport_simple_send_topo.conf
@@ -0,0 +1,4 @@
1M:2
2N:1
3X:0
4T:libgnunet_test_transport_plugin_cmd_simple_send \ No newline at end of file
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 feb65468a..000000000
--- a/src/transport/test_transport_simple_send_v2.c
+++ /dev/null
@@ -1,89 +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 cmd = GNUNET_TESTING_cmd_end ();
51
52 if (GNUNET_YES == cmd.shutdown_on_end)
53 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
54 "gaga %p\n",
55 cmd);
56 struct GNUNET_TESTING_Command commands[] = {
57 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
58 TOPOLOGY_CONFIG),
59 GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed",
60 TOPOLOGY_CONFIG,
61 &rv),
62 GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed",
63 "netjail-start-testbed",
64 TOPOLOGY_CONFIG),
65 GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
66 TOPOLOGY_CONFIG),
67 cmd
68 };
69
70 GNUNET_TESTING_run (NULL,
71 commands,
72 TIMEOUT);
73}
74
75
76int
77main (int argc,
78 char *const *argv)
79{
80 GNUNET_log_setup ("test-netjail",
81 "DEBUG",
82 NULL);
83 GNUNET_SCHEDULER_run (&run,
84 NULL);
85
86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
87 "Test finished!\n");
88 return rv;
89}
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 67e5723f5..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 49
51 struct GNUNET_TESTING_Peer *peer; 50 // Label of the cmd which started the test system.
51 const char *create_label;
52 52
53 /** 53 /**
54 * Peer identity 54 * Number globally identifying the node.
55 *
55 */ 56 */
56 struct GNUNET_PeerIdentity id; 57 uint32_t num;
57 58
58 /** 59 /**
59 * Peer's transport service handle 60 * Label of the cmd to start a peer.
61 *
60 */ 62 */
61 struct GNUNET_TRANSPORT_CoreHandle *th; 63 const char *start_peer_label;
62 64
63 /** 65 /**
64 * Application handle 66 * The peer identity of this peer.
67 *
65 */ 68 */
66 struct GNUNET_TRANSPORT_ApplicationHandle *ah; 69 struct GNUNET_PeerIdentity *id;
67 70
68 /** 71 /**
69 * Peer's PEERSTORE Handle 72 * The topology of the test setup.
70 */ 73 */
71 struct GNUNET_PEERSTORE_Handle *ph; 74 struct GNUNET_TESTING_NetjailTopology *topology;
72 75
73 /** 76 /**
74 * Hello get task 77 * Connections to other peers.
75 */ 78 */
76 struct GNUNET_SCHEDULER_Task *rh_task; 79 struct GNUNET_TESTING_NodeConnection *node_connections_head;
77 80
78 /** 81 struct GNUNET_TESTING_Interpreter *is;
79 * Peer's transport get hello handle to retrieve peer's HELLO message
80 */
81 struct GNUNET_PEERSTORE_IterateContext *pic;
82 82
83 /** 83 /**
84 * Hello 84 * Number of connections.
85 */ 85 */
86 char *hello; 86 unsigned int con_num;
87
88 /**
89 * Hello size
90 */
91 size_t hello_size;
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,30 +195,13 @@ 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);
230 205
231 206
232struct GNUNET_TESTING_Command 207struct GNUNET_TESTING_Command
@@ -238,56 +213,9 @@ struct GNUNET_TESTING_Command
238GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 213GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
239 const char *start_peer_label, 214 const char *start_peer_label,
240 const char *create_label, 215 const char *create_label,
241 uint32_t num); 216 uint32_t num,
242 217 struct GNUNET_TESTING_NetjailTopology *
243 218 topology);
244struct GNUNET_TESTING_Command
245GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
246 const char *start_peer_label,
247 const char *create_label,
248 uint32_t num);
249
250
251/**
252 * Create command.
253 *
254 * @param label name for command.
255 * @param start_peer_label Label of the cmd to start a peer.
256 * @param create_label Label of the cmd to create the testing system.
257 * @param num Number globally identifying the node.
258 * @param The topology for the test setup.
259 * @return command.
260 */
261struct GNUNET_TESTING_Command
262GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
263 const char *start_peer_label,
264 const char *create_label,
265 uint32_t num,
266 struct GNUNET_TESTING_NetjailTopology *
267 topology);
268
269
270/**
271 * Create command.
272 *
273 * @param label name for command.
274 * @param start_peer_label Label of the cmd to start a peer.
275 * @param create_label Label of the cmd to create the testing system.
276 * @param num Number globally identifying the node.
277 * @param node_n The number of the node in a network namespace.
278 * @param namespace_n The number of the network namespace.
279 * @param The topology for the test setup.
280 * @return command.
281 */
282struct GNUNET_TESTING_Command
283GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
284 const char *start_peer_label,
285 const char *create_label,
286 uint32_t num,
287 unsigned int node_n,
288 unsigned int namespace_n,
289 struct GNUNET_TESTING_NetjailTopology *
290 topology);
291 219
292 220
293/** 221/**
@@ -302,42 +230,11 @@ GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
302 */ 230 */
303struct GNUNET_TESTING_Command 231struct GNUNET_TESTING_Command
304GNUNET_TRANSPORT_cmd_send_simple (const char *label, 232GNUNET_TRANSPORT_cmd_send_simple (const char *label,
305 char *m, 233 const char *start_peer_label,
306 char *n, 234 uint32_t num);
307 uint32_t num,
308 const char *start_peer_label);
309 235
310/**
311 * Create command.
312 *
313 * @param label name for command.
314 * @param start_peer_label Label of the cmd to start a peer.
315 * @param num Number globally identifying the node.
316 * @return command.
317 */
318struct GNUNET_TESTING_Command
319GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label,
320 const char *start_peer_label,
321 uint32_t num);
322 236
323 237
324/**
325 * Create command.
326 *
327 * @param label name for command.
328 * @param start_peer_label Label of the cmd to start a peer.
329 * @param start_peer_label Label of the cmd which started the test system.
330 * @param num Number globally identifying the node.
331 * @param The topology for the test setup.
332 * @return command.
333 */
334struct GNUNET_TESTING_Command
335GNUNET_TRANSPORT_cmd_send_simple_v3 (const char *label,
336 const char *start_peer_label,
337 const char *create_label,
338 uint32_t num,
339 struct GNUNET_TESTING_NetjailTopology *
340 topology);
341 238
342 239
343int 240int
@@ -345,34 +242,16 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct
345 GNUNET_TESTING_Command *cmd, 242 GNUNET_TESTING_Command *cmd,
346 struct GNUNET_PeerIdentity **id); 243 struct GNUNET_PeerIdentity **id);
347 244
245
348int 246int
349GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct 247GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
350 GNUNET_TESTING_Command 248 GNUNET_TESTING_Command
351 *cmd, 249 *cmd,
352 struct 250 struct
353 GNUNET_CONTAINER_MultiShortmap * 251 GNUNET_CONTAINER_MultiShortmap
252 *
354 * 253 *
355 connected_peers_map); 254 connected_peers_map);
356
357int
358GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct
359 GNUNET_TESTING_Command
360 *cmd,
361 struct
362 GNUNET_CONTAINER_MultiShortmap
363 *
364 *
365 connected_peers_map);
366
367int
368GNUNET_TRANSPORT_get_trait_connected_peers_map_v3 (const struct
369 GNUNET_TESTING_Command
370 *cmd,
371 struct
372 GNUNET_CONTAINER_MultiShortmap
373 *
374 *
375 connected_peers_map);
376int 255int
377GNUNET_TRANSPORT_get_trait_hello_size (const struct 256GNUNET_TRANSPORT_get_trait_hello_size (const struct
378 GNUNET_TESTING_Command 257 GNUNET_TESTING_Command
@@ -393,19 +272,5 @@ GNUNET_TRANSPORT_get_trait_application_handle (const struct
393 GNUNET_TRANSPORT_ApplicationHandle 272 GNUNET_TRANSPORT_ApplicationHandle
394 **ah); 273 **ah);
395 274
396int
397GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
398 GNUNET_TESTING_Command *cmd,
399 struct
400 GNUNET_TRANSPORT_ApplicationHandle
401 **ah);
402
403int
404GNUNET_TRANSPORT_get_trait_application_handle_v3 (const struct
405 GNUNET_TESTING_Command *cmd,
406 struct
407 GNUNET_TRANSPORT_ApplicationHandle
408 **ah);
409
410#endif 275#endif
411/* 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 39c7db450..2e51363f6 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -36,199 +36,348 @@
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.
41 *
42 */
43struct ConnectPeersState
44{
45 // Label of the cmd which started the test system.
46 const char *create_label;
47 40
48 /** 41#define CONNECT_ADDRESS_TEMPLATE_UDP "udp-192.168.15.%u:60002"
49 * Number globally identifying the node.
50 *
51 */
52 uint32_t num;
53 42
54 /** 43#define ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.150.%u:60002"
55 * Label of the cmd to start a peer.
56 *
57 */
58 const char *start_peer_label;
59 44
60 /** 45#define ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.150.%u:60002"
61 * The peer identity of this peer.
62 *
63 */
64 struct GNUNET_PeerIdentity *id;
65};
66 46
47#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.151.%u:60002"
67 48
68/** 49#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.151.%u:60002"
69 * The run method of this cmd will connect to peers. 50
70 * 51#define PREFIX_TCP "tcp"
71 */ 52
72static void 53#define PREFIX_UDP "udp"
73connect_peers_run (void *cls, 54
74 const struct GNUNET_TESTING_Command *cmd, 55
75 struct GNUNET_TESTING_Interpreter *is) 56
57
58static struct GNUNET_PeerIdentity *
59get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
76{ 60{
77 struct ConnectPeersState *cps = cls; 61 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
78 const struct GNUNET_TESTING_Command *system_cmd;
79 struct GNUNET_TESTING_System *tl_system;
80 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
81 GNUNET_CRYPTO_EddsaPrivateKey);
82 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct 62 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
83 GNUNET_CRYPTO_EddsaPublicKey); 63 GNUNET_CRYPTO_EddsaPublicKey);
84 ; 64 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
85 const struct GNUNET_TESTING_Command *peer1_cmd; 65 GNUNET_CRYPTO_EddsaPrivateKey);
86 // const struct GNUNET_TESTING_Command *peer2_cmd;
87 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
88 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
89 char *addr;
90 // struct GNUNET_TIME_Absolute t;
91 char *hello;
92 // size_t *hello_size;
93 enum GNUNET_NetworkType nt = 0;
94 // char *peer_id;
95 struct GNUNET_PeerIdentity *id;
96 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
97 uint32_t num;
98 66
99 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); 67 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
100 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, 68 num,
101 &ah); 69 peer);
102 70
103 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd, 71 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
104 &hello); 72 pub_key);
73 peer->public_key = *pub_key;
74 return peer;
75}
105 76
106 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
107 &id);
108 77
109 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label); 78static int
110 GNUNET_TESTING_get_trait_test_system (system_cmd, 79log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
111 &tl_system); 80{
81 struct GNUNET_TESTING_NetjailNode *node = value;
82 struct GNUNET_TESTING_NodeConnection *pos_connection;
83 struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
112 84
113 if (2 == cps->num) 85 LOG (GNUNET_ERROR_TYPE_ERROR,
114 num = 1; 86 "plugin: %s space: %u node: %u global: %u\n",
115 else 87 node->plugin,
116 num = 2; 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}
117 129
118 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;
119 158
159 log_topo (topology);
120 160
121 // if (strstr (hello, "60002") != NULL) 161 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
122 if (2 == num) 162 if (topology->nodes_x >= num)
123 { 163 {
124 addr = "tcp-192.168.15.2:60002"; 164
125 // peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG"; 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);
126 } 171 }
127 else 172 else
128 { 173 {
129 addr = "tcp-192.168.15.1:60002"; 174 namespace_n = (unsigned int) floor ((num - topology->nodes_x)
130 // peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730"; 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);
131 } 197 }
132 198
133 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
134 num,
135 other);
136 199
137 GNUNET_CRYPTO_eddsa_key_get_public (priv_key, 200 return node->node_connections_head;
138 pub_key); 201}
139 202
140 /*GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
141 strlen (peer_id),
142 &peer->public_key);*/
143 203
144 peer->public_key = *pub_key; 204static unsigned int
205calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
206 struct GNUNET_TESTING_NetjailTopology *topology)
207{
208 unsigned int n, m, num;
145 209
146 LOG (GNUNET_ERROR_TYPE_ERROR, 210 n = node_connection->namespace_n;
147 "num: %u id: %s pub_key %s\n", 211 m = node_connection->node_n;
148 num, 212
149 GNUNET_i2s_full (id), 213 if (0 == n)
150 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key)); 214 num = m;
151 215 else
152 cps->id = peer; 216 num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
153 217
154 // 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. 218 return num;
155 // --------------------------------------------- 219}
156 /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label); 220
157 GNUNET_TRANSPORT_get_trait_peer_id (peer2_cmd, 221
158 &id); 222static char *
159 GNUNET_TRANSPORT_get_trait_hello (peer2_cmd, 223get_address (struct GNUNET_TESTING_NodeConnection *connection,
160 &hello); 224 char *prefix)
161 GNUNET_TRANSPORT_get_trait_hello_size (peer2_cmd, 225{
162 &hello_size); 226 struct GNUNET_TESTING_NetjailNode *node;
163 227 char *addr;
164 addr = GNUNET_HELLO_extract_address (hello, 228
165 *hello_size, 229 node = connection->node;
166 id, 230 if (connection->namespace_n == node->namespace_n)
167 &nt, 231 {
168 &t);*/ 232 if (0 == strcmp (PREFIX_TCP, prefix))
169 233 {
170 // ---------------------------------------------- 234
171 235 GNUNET_asprintf (&addr,
172 236 CONNECT_ADDRESS_TEMPLATE_TCP,
173 GNUNET_TRANSPORT_application_validate (ah, 237 connection->node_n);
174 peer, 238 }
175 nt, 239 else if (0 == strcmp (PREFIX_UDP, prefix))
176 addr); 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;
177} 272}
178 273
179 274
180/** 275/**
181 * 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. 276 * The run method of this cmd will connect to peers.
182 * 277 *
183 */ 278 */
184static int 279static void
185connect_peers_finish (void *cls, 280connect_peers_run (void *cls,
186 GNUNET_SCHEDULER_TaskCallback cont, 281 struct GNUNET_TESTING_Interpreter *is)
187 void *cont_cls)
188{ 282{
189 struct ConnectPeersState *cps = cls; 283 struct ConnectPeersState *cps = cls;
284 const struct GNUNET_TESTING_Command *system_cmd;
285 struct GNUNET_TESTING_System *tl_system;
286
287
190 const struct GNUNET_TESTING_Command *peer1_cmd; 288 const struct GNUNET_TESTING_Command *peer1_cmd;
191 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; 289 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
192 unsigned int ret; 290 struct GNUNET_PeerIdentity *peer;
193 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); 291 char *addr;
194 struct GNUNET_HashCode hc; 292 enum GNUNET_NetworkType nt = 0;
195 int node_number; 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;
196 297
197 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); 298 cps->is = is;
198 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, 299 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
199 &connected_peers_map); 300 cps->start_peer_label);
301 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
302 &ah);
200 303
201 node_number = 1; 304 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
202 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); 305 cps->create_label);
306 GNUNET_TESTING_get_trait_test_system (system_cmd,
307 &tl_system);
308
309 cps->tl_system = tl_system;
203 310
204 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. 311 cps->node_connections_head = get_connections (cps->num, cps->topology);
205 memcpy (key,
206 &hc,
207 sizeof (*key));
208 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
209 key);
210 312
211 if (GNUNET_YES == ret) 313 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
314 pos_connection = pos_connection->next)
212 { 315 {
213 cont (cont_cls); 316 con_num++;
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 }
214 } 344 }
215 345 cps->con_num = con_num;
216 GNUNET_free (key);
217 return ret;
218} 346}
219 347
220 348
221/** 349/**
222 * Trait function of this cmd does nothing. 350 * Callback from start peer cmd for signaling a peer got connected.
223 * 351 *
224 */ 352 */
225static int 353static void *
226connect_peers_traits (void *cls, 354notify_connect (void *cls,
227 const void **ret, 355 const struct GNUNET_PeerIdentity *peer,
228 const char *trait, 356 struct GNUNET_MQ_Handle *mq)
229 unsigned int index)
230{ 357{
231 return GNUNET_OK; 358 struct ConnectPeersState *cps = cls;
359 struct GNUNET_PeerIdentity *peer_connection;
360 unsigned int con_num = 0;
361 struct GNUNET_TESTING_NodeConnection *pos_connection;
362 unsigned int num;
363 void *ret = NULL;
364
365 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
366 pos_connection = pos_connection->next)
367 {
368 num = calculate_num (pos_connection, cps->topology);
369 peer_connection = get_pub_key (num, cps->tl_system);
370 if (0 == GNUNET_memcmp (peer,
371 peer_connection))
372 con_num++;
373 }
374
375
376 if (cps->con_num == con_num)
377 {
378 GNUNET_TESTING_async_finish (&cps->ac);
379 }
380 return ret;
232} 381}
233 382
234 383
@@ -237,8 +386,7 @@ connect_peers_traits (void *cls,
237 * 386 *
238 */ 387 */
239static void 388static void
240connect_peers_cleanup (void *cls, 389connect_peers_cleanup (void *cls)
241 const struct GNUNET_TESTING_Command *cmd)
242{ 390{
243 struct ConnectPeersState *cps = cls; 391 struct ConnectPeersState *cps = cls;
244 392
@@ -248,17 +396,57 @@ connect_peers_cleanup (void *cls,
248 396
249 397
250/** 398/**
251 * Create command. 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.
252 * 429 *
253 * @param label name for command.
254 * @param start_peer_label Label of the cmd to start a peer.
255 * @return command.
256 */ 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
257struct GNUNET_TESTING_Command 443struct GNUNET_TESTING_Command
258GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 444GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
259 const char *start_peer_label, 445 const char *start_peer_label,
260 const char *create_label, 446 const char *create_label,
261 uint32_t num) 447 uint32_t num,
448 struct GNUNET_TESTING_NetjailTopology *
449 topology)
262{ 450{
263 struct ConnectPeersState *cps; 451 struct ConnectPeersState *cps;
264 452
@@ -266,16 +454,19 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
266 cps->start_peer_label = start_peer_label; 454 cps->start_peer_label = start_peer_label;
267 cps->num = num; 455 cps->num = num;
268 cps->create_label = create_label; 456 cps->create_label = create_label;
457 cps->topology = topology;
458 cps->notify_connect = &notify_connect;
269 459
270 460 {
271 struct GNUNET_TESTING_Command cmd = { 461 struct GNUNET_TESTING_Command cmd = {
272 .cls = cps, 462 .cls = cps,
273 .label = label, 463 .label = label,
274 .run = &connect_peers_run, 464 .run = &connect_peers_run,
275 .finish = &connect_peers_finish, 465 .ac = &cps->ac,
276 .cleanup = &connect_peers_cleanup, 466 .cleanup = &connect_peers_cleanup,
277 .traits = &connect_peers_traits 467 .traits = &connect_peers_traits
278 }; 468 };
279 469
280 return cmd; 470 return cmd;
471 }
281} 472}
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 0d286b714..000000000
--- a/src/transport/transport_api_cmd_connecting_peers_v2.c
+++ /dev/null
@@ -1,242 +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 // Label of the cmd which started the test system.
48 const char *create_label;
49
50 /**
51 * Number globally identifying the node.
52 *
53 */
54 uint32_t num;
55
56 /**
57 * Label of the cmd to start a peer.
58 *
59 */
60 const char *start_peer_label;
61
62 /**
63 * The peer identity of this peer.
64 *
65 */
66 struct GNUNET_PeerIdentity *id;
67};
68
69
70/**
71 * The run method of this cmd will connect to peers.
72 *
73 */
74static void
75connect_peers_run (void *cls,
76 const struct GNUNET_TESTING_Command *cmd,
77 struct GNUNET_TESTING_Interpreter *is)
78{
79 struct ConnectPeersState *cps = cls;
80 const struct GNUNET_TESTING_Command *system_cmd;
81 struct GNUNET_TESTING_System *tl_system;
82 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
83 GNUNET_CRYPTO_EddsaPrivateKey);
84 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
85 GNUNET_CRYPTO_EddsaPublicKey);
86 const struct GNUNET_TESTING_Command *peer1_cmd;
87 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
88 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
89 char *addr;
90 enum GNUNET_NetworkType nt = 0;
91 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
92 uint32_t num;
93
94 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
95 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
96 &ah);
97
98 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label);
99 GNUNET_TESTING_get_trait_test_system (system_cmd,
100 &tl_system);
101
102 if (1 == cps->num)
103 {
104 num = 2;
105 // addr = "tcp-192.168.15.2:60002";
106 }
107 else
108 {
109 num = 1;
110 // addr = "tcp-192.168.15.1:60002";
111 }
112
113 GNUNET_asprintf (&addr,
114 CONNECT_ADDRESS_TEMPLATE,
115 num);
116
117 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
118 num,
119 other);
120
121 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
122 pub_key);
123
124
125 peer->public_key = *pub_key;
126
127 LOG (GNUNET_ERROR_TYPE_ERROR,
128 "num: %u pub_key %s\n",
129 num,
130 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
131
132 cps->id = peer;
133
134 GNUNET_TRANSPORT_application_validate (ah,
135 peer,
136 nt,
137 addr);
138}
139
140
141/**
142 * 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.
143 *
144 */
145static int
146connect_peers_finish (void *cls,
147 GNUNET_SCHEDULER_TaskCallback cont,
148 void *cont_cls)
149{
150 struct ConnectPeersState *cps = cls;
151 const struct GNUNET_TESTING_Command *peer1_cmd;
152 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
153 unsigned int ret;
154 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
155 struct GNUNET_HashCode hc;
156 int node_number;
157
158 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
159 GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
160 &connected_peers_map);
161
162 node_number = 1;
163 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
164
165 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
166 memcpy (key,
167 &hc,
168 sizeof (*key));
169 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
170 key);
171
172 if (GNUNET_YES == ret)
173 {
174 cont (cont_cls);
175 }
176
177 GNUNET_free (key);
178 return ret;
179}
180
181
182/**
183 * Trait function of this cmd does nothing.
184 *
185 */
186static int
187connect_peers_traits (void *cls,
188 const void **ret,
189 const char *trait,
190 unsigned int index)
191{
192 return GNUNET_OK;
193}
194
195
196/**
197 * The cleanup function of this cmd frees resources the cmd allocated.
198 *
199 */
200static void
201connect_peers_cleanup (void *cls,
202 const struct GNUNET_TESTING_Command *cmd)
203{
204 struct ConnectPeersState *cps = cls;
205
206 GNUNET_free (cps->id);
207 GNUNET_free (cps);
208}
209
210
211/**
212 * Create command.
213 *
214 * @param label name for command.
215 * @param start_peer_label Label of the cmd to start a peer.
216 * @return command.
217 */
218struct GNUNET_TESTING_Command
219GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
220 const char *start_peer_label,
221 const char *create_label,
222 uint32_t num)
223{
224 struct ConnectPeersState *cps;
225
226 cps = GNUNET_new (struct ConnectPeersState);
227 cps->start_peer_label = start_peer_label;
228 cps->num = num;
229 cps->create_label = create_label;
230
231
232 struct GNUNET_TESTING_Command cmd = {
233 .cls = cps,
234 .label = label,
235 .run = &connect_peers_run,
236 .finish = &connect_peers_finish,
237 .cleanup = &connect_peers_cleanup,
238 .traits = &connect_peers_traits
239 };
240
241 return cmd;
242}
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 2273d9852..000000000
--- a/src/transport/transport_api_cmd_connecting_peers_v3.c
+++ /dev/null
@@ -1,281 +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/**
40 * Struct to store information needed in callbacks.
41 *
42 */
43struct ConnectPeersState
44{
45 /**
46 * The testing system of this node.
47 */
48 struct GNUNET_TESTING_System *tl_system;
49
50 // Label of the cmd which started the test system.
51 const char *create_label;
52
53 /**
54 * Number globally identifying the node.
55 *
56 */
57 uint32_t num;
58
59 /**
60 * Label of the cmd to start a peer.
61 *
62 */
63 const char *start_peer_label;
64
65 /**
66 * The peer identity of this peer.
67 *
68 */
69 struct GNUNET_PeerIdentity *id;
70
71 /**
72 * The topology of the test setup.
73 */
74 struct GNUNET_TESTING_NetjailTopology *topology;
75
76 /**
77 * Connections to other peers.
78 */
79 struct GNUNET_TESTING_NodeConnection *node_connections_head;
80
81 /**
82 * Number of connections.
83 */
84 unsigned int con_num;
85};
86
87
88/**
89 * The run method of this cmd will connect to peers.
90 *
91 */
92static void
93connect_peers_run (void *cls,
94 const struct GNUNET_TESTING_Command *cmd,
95 struct GNUNET_TESTING_Interpreter *is)
96{
97 struct ConnectPeersState *cps = cls;
98 const struct GNUNET_TESTING_Command *system_cmd;
99 struct GNUNET_TESTING_System *tl_system;
100
101
102 const struct GNUNET_TESTING_Command *peer1_cmd;
103 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
104 struct GNUNET_PeerIdentity *peer;
105 char *addr;
106 enum GNUNET_NetworkType nt = 0;
107 uint32_t num;
108 struct GNUNET_TESTING_NodeConnection *pos_connection;
109 struct GNUNET_TESTING_AddressPrefix *pos_prefix;
110 unsigned int con_num = 0;
111
112 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
113 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
114 &ah);
115
116 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label);
117 GNUNET_TESTING_get_trait_test_system (system_cmd,
118 &tl_system);
119
120 cps->tl_system = tl_system;
121
122 cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num,
123 cps->topology);
124
125 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
126 pos_connection = pos_connection->next)
127 {
128 con_num++;
129 num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
130 for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
131 pos_prefix =
132 pos_prefix->next)
133 {
134
135 LOG (GNUNET_ERROR_TYPE_ERROR,
136 "prefix: %s\n",
137 pos_prefix->address_prefix);
138
139 addr = GNUNET_TESTING_get_address (pos_connection,
140 pos_prefix->address_prefix);
141
142 peer = GNUNET_TESTING_get_pub_key (num, tl_system);
143
144 LOG (GNUNET_ERROR_TYPE_ERROR,
145 "num: %u pub_key %s addr: %s\n",
146 num,
147 GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)),
148 addr);
149
150 cps->id = peer;
151
152 GNUNET_TRANSPORT_application_validate (ah,
153 peer,
154 nt,
155 addr);
156 }
157 }
158 cps->con_num = con_num;
159}
160
161
162/**
163 * The finish function of this cmd will check if the peers we are trying to
164 * connect to are in the connected peers map of the start peer cmd for this peer.
165 *
166 */
167static int
168connect_peers_finish (void *cls,
169 GNUNET_SCHEDULER_TaskCallback cont,
170 void *cont_cls)
171{
172 struct ConnectPeersState *cps = cls;
173 const struct GNUNET_TESTING_Command *peer1_cmd;
174 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
175 unsigned int ret;
176 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
177 struct GNUNET_HashCode hc;
178 struct GNUNET_PeerIdentity *peer;
179 unsigned int con_num = 0;
180 struct GNUNET_TESTING_NodeConnection *pos_connection;
181 unsigned int num;
182
183 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
184 GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
185 &connected_peers_map);
186
187 for (pos_connection = cps->node_connections_head; NULL != pos_connection;
188 pos_connection = pos_connection->next)
189 {
190 num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
191 peer = GNUNET_TESTING_get_pub_key (num, cps->tl_system);
192 GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc);
193 memcpy (key,
194 &hc,
195 sizeof (*key));
196 if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
197 connected_peers_map,
198 key))
199 con_num++;
200 }
201
202
203
204 if (cps->con_num == con_num)
205 {
206 cont (cont_cls);
207 ret = GNUNET_YES;
208 }
209
210 GNUNET_free (key);
211 return ret;
212}
213
214
215/**
216 * Trait function of this cmd does nothing.
217 *
218 */
219static int
220connect_peers_traits (void *cls,
221 const void **ret,
222 const char *trait,
223 unsigned int index)
224{
225 return GNUNET_OK;
226}
227
228
229/**
230 * The cleanup function of this cmd frees resources the cmd allocated.
231 *
232 */
233static void
234connect_peers_cleanup (void *cls,
235 const struct GNUNET_TESTING_Command *cmd)
236{
237 struct ConnectPeersState *cps = cls;
238
239 GNUNET_free (cps->id);
240 GNUNET_free (cps);
241}
242
243
244/**
245 * Create command.
246 *
247 * @param label name for command.
248 * @param start_peer_label Label of the cmd to start a peer.
249 * @param create_label Label of the cmd to create the testing system.
250 * @param num Number globally identifying the node.
251 * @param The topology for the test setup.
252 * @return command.
253 */
254struct GNUNET_TESTING_Command
255GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
256 const char *start_peer_label,
257 const char *create_label,
258 uint32_t num,
259 struct GNUNET_TESTING_NetjailTopology *
260 topology)
261{
262 struct ConnectPeersState *cps;
263
264 cps = GNUNET_new (struct ConnectPeersState);
265 cps->start_peer_label = start_peer_label;
266 cps->num = num;
267 cps->create_label = create_label;
268 cps->topology = topology;
269
270
271 struct GNUNET_TESTING_Command cmd = {
272 .cls = cps,
273 .label = label,
274 .run = &connect_peers_run,
275 .finish = &connect_peers_finish,
276 .cleanup = &connect_peers_cleanup,
277 .traits = &connect_peers_traits
278 };
279
280 return cmd;
281}
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
index f9e515c0f..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 */
@@ -80,8 +68,7 @@ send_simple_traits (void *cls,
80 * 68 *
81 */ 69 */
82static void 70static void
83send_simple_cleanup (void *cls, 71send_simple_cleanup (void *cls)
84 const struct GNUNET_TESTING_Command *cmd)
85{ 72{
86 struct SendSimpleState *sss = cls; 73 struct SendSimpleState *sss = cls;
87 74
@@ -95,7 +82,6 @@ send_simple_cleanup (void *cls,
95 */ 82 */
96static void 83static void
97send_simple_run (void *cls, 84send_simple_run (void *cls,
98 const struct GNUNET_TESTING_Command *cmd,
99 struct GNUNET_TESTING_Interpreter *is) 85 struct GNUNET_TESTING_Interpreter *is)
100{ 86{
101 struct SendSimpleState *sss = cls; 87 struct SendSimpleState *sss = cls;
@@ -108,7 +94,8 @@ send_simple_run (void *cls,
108 struct GNUNET_HashCode hc; 94 struct GNUNET_HashCode hc;
109 int node_number; 95 int node_number;
110 96
111 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label); 97 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
98 sss->start_peer_label);
112 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, 99 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
113 &connected_peers_map); 100 &connected_peers_map);
114 101
@@ -147,26 +134,23 @@ send_simple_run (void *cls,
147 */ 134 */
148struct GNUNET_TESTING_Command 135struct GNUNET_TESTING_Command
149GNUNET_TRANSPORT_cmd_send_simple (const char *label, 136GNUNET_TRANSPORT_cmd_send_simple (const char *label,
150 char *m, 137 const char *start_peer_label,
151 char *n, 138 uint32_t num)
152 uint32_t num,
153 const char *start_peer_label)
154{ 139{
155 struct SendSimpleState *sss; 140 struct SendSimpleState *sss;
156 141
157 sss = GNUNET_new (struct SendSimpleState); 142 sss = GNUNET_new (struct SendSimpleState);
158 sss->m = m;
159 sss->n = n;
160 sss->num = num; 143 sss->num = num;
161 sss->start_peer_label = start_peer_label; 144 sss->start_peer_label = start_peer_label;
162 145 {
163 struct GNUNET_TESTING_Command cmd = { 146 struct GNUNET_TESTING_Command cmd = {
164 .cls = sss, 147 .cls = sss,
165 .label = label, 148 .label = label,
166 .run = &send_simple_run, 149 .run = &send_simple_run,
167 .cleanup = &send_simple_cleanup, 150 .cleanup = &send_simple_cleanup,
168 .traits = &send_simple_traits 151 .traits = &send_simple_traits
169 }; 152 };
170 153
171 return cmd; 154 return cmd;
155 }
172} 156}
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 d43c0b425..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 const struct GNUNET_TESTING_Command *cmd)
73{
74 struct SendSimpleState *sss = cls;
75
76 GNUNET_free (sss);
77}
78
79
80/**
81 * The run method of this cmd will send a simple message to the connected peer.
82 *
83 */
84static void
85send_simple_run (void *cls,
86 const struct GNUNET_TESTING_Command *cmd,
87 struct GNUNET_TESTING_Interpreter *is)
88{
89 struct SendSimpleState *sss = cls;
90 struct GNUNET_MQ_Envelope *env;
91 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
92 struct GNUNET_MQ_Handle *mq;
93 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
94 const struct GNUNET_TESTING_Command *peer1_cmd;
95 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
96 struct GNUNET_HashCode hc;
97 int node_number;
98
99 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
100 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
101 &connected_peers_map);
102
103 node_number = 1;
104 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
105 memcpy (key,
106 &hc,
107 sizeof (*key));
108
109 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
110 key);
111
112 env = GNUNET_MQ_msg_extra (test,
113 2600 - sizeof(*test),
114 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
115 test->num = htonl (sss->num);
116 memset (&test[1],
117 sss->num,
118 2600 - sizeof(*test));
119 GNUNET_MQ_send (mq,
120 env);
121 GNUNET_free (key);
122
123}
124
125
126/**
127 * Create command.
128 *
129 * @param label name for command.
130 * @param m The number of the local node of the actual network namespace.
131 * @param n The number of the actual namespace.
132 * @param num Number globally identifying the node.
133 * @param start_peer_label Label of the cmd to start a peer.
134 * @return command.
135 */
136struct GNUNET_TESTING_Command
137GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label,
138 const char *start_peer_label,
139 uint32_t num)
140{
141 struct SendSimpleState *sss;
142
143 sss = GNUNET_new (struct SendSimpleState);
144 sss->num = num;
145 sss->start_peer_label = start_peer_label;
146
147 struct GNUNET_TESTING_Command cmd = {
148 .cls = sss,
149 .label = label,
150 .run = &send_simple_run,
151 .cleanup = &send_simple_cleanup,
152 .traits = &send_simple_traits
153 };
154
155 return cmd;
156}
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index f4e92944b..dc19f10eb 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -65,7 +65,7 @@ hello_iter_cb (void *cb_cls,
65 65
66 GNUNET_PEERSTORE_iterate_cancel (sps->pic); 66 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
67 sps->pic = NULL; 67 sps->pic = NULL;
68 sps->finished = GNUNET_YES; 68 GNUNET_TESTING_async_finish (&sps->ac);
69} 69}
70 70
71 71
@@ -90,26 +90,6 @@ retrieve_hello (void *cls)
90 90
91 91
92/** 92/**
93 * This function checks StartPeerState#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 *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. 93 * Disconnect callback for the connection to the core service.
114 * 94 *
115 */ 95 */
@@ -141,7 +121,7 @@ notify_connect (void *cls,
141 struct StartPeerState *sps = cls; 121 struct StartPeerState *sps = cls;
142 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); 122 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
143 struct GNUNET_HashCode hc; 123 struct GNUNET_HashCode hc;
144 int node_number; 124 struct GNUNET_CRYPTO_EddsaPublicKey public_key = peer->public_key;
145 125
146 void *ret = NULL; 126 void *ret = NULL;
147 127
@@ -152,9 +132,7 @@ notify_connect (void *cls,
152 sps->no, 132 sps->no,
153 GNUNET_i2s (&sps->id)); 133 GNUNET_i2s (&sps->id));
154 134
155 // 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);
156 node_number = 1;
157 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
158 136
159 137
160 memcpy (key, 138 memcpy (key,
@@ -166,6 +144,11 @@ notify_connect (void *cls,
166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 144 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
167 145
168 GNUNET_free (key); 146 GNUNET_free (key);
147
148 sps->notify_connect (cls,
149 peer,
150 mq);
151
169 // TODO what does the handler function need? 152 // TODO what does the handler function need?
170 return ret; 153 return ret;
171} 154}
@@ -177,7 +160,6 @@ notify_connect (void *cls,
177 */ 160 */
178static void 161static void
179start_peer_run (void *cls, 162start_peer_run (void *cls,
180 const struct GNUNET_TESTING_Command *cmd,
181 struct GNUNET_TESTING_Interpreter *is) 163 struct GNUNET_TESTING_Interpreter *is)
182{ 164{
183 struct StartPeerState *sps = cls; 165 struct StartPeerState *sps = cls;
@@ -187,7 +169,8 @@ start_peer_run (void *cls,
187 struct GNUNET_TESTING_System *tl_system; 169 struct GNUNET_TESTING_System *tl_system;
188 char *home; 170 char *home;
189 char *transport_unix_path; 171 char *transport_unix_path;
190 char *communicator_unix_path; 172 char *tcp_communicator_unix_path;
173 char *udp_communicator_unix_path;
191 char *bindto; 174 char *bindto;
192 175
193 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) 176 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
@@ -195,7 +178,7 @@ start_peer_run (void *cls,
195 LOG (GNUNET_ERROR_TYPE_ERROR, 178 LOG (GNUNET_ERROR_TYPE_ERROR,
196 "File not found: `%s'\n", 179 "File not found: `%s'\n",
197 sps->cfgname); 180 sps->cfgname);
198 GNUNET_TESTING_interpreter_fail (); 181 GNUNET_TESTING_interpreter_fail (is);
199 return; 182 return;
200 } 183 }
201 184
@@ -212,7 +195,11 @@ start_peer_run (void *cls,
212 "$GNUNET_RUNTIME_DIR/tng-p%u.sock", 195 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
213 sps->no); 196 sps->no);
214 197
215 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,
216 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock", 203 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
217 sps->no); 204 sps->no);
218 205
@@ -220,6 +207,9 @@ start_peer_run (void *cls,
220 "%s:60002", 207 "%s:60002",
221 sps->node_ip); 208 sps->node_ip);
222 209
210 LOG (GNUNET_ERROR_TYPE_ERROR,
211 "node_ip %s\n",
212 bindto);
223 213
224 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME", 214 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
225 home); 215 home);
@@ -228,11 +218,18 @@ start_peer_run (void *cls,
228 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", 218 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
229 "BINDTO", 219 "BINDTO",
230 bindto); 220 bindto);
221 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
222 "BINDTO",
223 bindto);
231 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp", 224 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
232 "UNIXPATH", 225 "UNIXPATH",
233 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);
234 230
235 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label); 231 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
232 sps->system_label);
236 GNUNET_TESTING_get_trait_test_system (system_cmd, 233 GNUNET_TESTING_get_trait_test_system (system_cmd,
237 &tl_system); 234 &tl_system);
238 235
@@ -246,7 +243,7 @@ start_peer_run (void *cls,
246 "Testing library failed to create unique configuration based on `%s'\n", 243 "Testing library failed to create unique configuration based on `%s'\n",
247 sps->cfgname); 244 sps->cfgname);
248 GNUNET_CONFIGURATION_destroy (sps->cfg); 245 GNUNET_CONFIGURATION_destroy (sps->cfg);
249 GNUNET_TESTING_interpreter_fail (); 246 GNUNET_TESTING_interpreter_fail (is);
250 return; 247 return;
251 } 248 }
252 249
@@ -262,7 +259,7 @@ start_peer_run (void *cls,
262 sps->cfgname, 259 sps->cfgname,
263 emsg); 260 emsg);
264 GNUNET_free (emsg); 261 GNUNET_free (emsg);
265 GNUNET_TESTING_interpreter_fail (); 262 GNUNET_TESTING_interpreter_fail (is);
266 return; 263 return;
267 } 264 }
268 265
@@ -272,7 +269,7 @@ start_peer_run (void *cls,
272 "Testing library failed to create unique configuration based on `%s'\n", 269 "Testing library failed to create unique configuration based on `%s'\n",
273 sps->cfgname); 270 sps->cfgname);
274 GNUNET_free (emsg); 271 GNUNET_free (emsg);
275 GNUNET_TESTING_interpreter_fail (); 272 GNUNET_TESTING_interpreter_fail (is);
276 return; 273 return;
277 } 274 }
278 275
@@ -291,7 +288,7 @@ start_peer_run (void *cls,
291 "Testing library failed to obtain peer identity for peer %u\n", 288 "Testing library failed to obtain peer identity for peer %u\n",
292 sps->no); 289 sps->no);
293 GNUNET_free (emsg); 290 GNUNET_free (emsg);
294 GNUNET_TESTING_interpreter_fail (); 291 GNUNET_TESTING_interpreter_fail (is);
295 return; 292 return;
296 } 293 }
297 LOG (GNUNET_ERROR_TYPE_DEBUG, 294 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -312,7 +309,7 @@ start_peer_run (void *cls,
312 sps->cfgname, 309 sps->cfgname,
313 emsg); 310 emsg);
314 GNUNET_free (emsg); 311 GNUNET_free (emsg);
315 GNUNET_TESTING_interpreter_fail (); 312 GNUNET_TESTING_interpreter_fail (is);
316 return; 313 return;
317 } 314 }
318 315
@@ -324,7 +321,7 @@ start_peer_run (void *cls,
324 sps->cfgname, 321 sps->cfgname,
325 emsg); 322 emsg);
326 GNUNET_free (emsg); 323 GNUNET_free (emsg);
327 GNUNET_TESTING_interpreter_fail (); 324 GNUNET_TESTING_interpreter_fail (is);
328 return; 325 return;
329 } 326 }
330 327
@@ -336,7 +333,7 @@ start_peer_run (void *cls,
336 sps->cfgname, 333 sps->cfgname,
337 emsg); 334 emsg);
338 GNUNET_free (emsg); 335 GNUNET_free (emsg);
339 GNUNET_TESTING_interpreter_fail (); 336 GNUNET_TESTING_interpreter_fail (is);
340 return; 337 return;
341 } 338 }
342 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); 339 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
@@ -348,8 +345,7 @@ start_peer_run (void *cls,
348 * 345 *
349 */ 346 */
350static void 347static void
351start_peer_cleanup (void *cls, 348start_peer_cleanup (void *cls)
352 const struct GNUNET_TESTING_Command *cmd)
353{ 349{
354 struct StartPeerState *sps = cls; 350 struct StartPeerState *sps = cls;
355 351
@@ -437,10 +433,9 @@ start_peer_traits (void *cls,
437 * 433 *
438 */ 434 */
439int 435int
440GNUNET_TRANSPORT_get_trait_state (const struct 436GNUNET_TRANSPORT_get_trait_state (
441 GNUNET_TESTING_Command 437 const struct GNUNET_TESTING_Command *cmd,
442 *cmd, 438 struct StartPeerState **sps)
443 struct StartPeerState **sps)
444{ 439{
445 return cmd->traits (cmd->cls, 440 return cmd->traits (cmd->cls,
446 (const void **) sps, 441 (const void **) sps,
@@ -501,7 +496,8 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
501 GNUNET_TESTING_Command 496 GNUNET_TESTING_Command
502 *cmd, 497 *cmd,
503 struct 498 struct
504 GNUNET_CONTAINER_MultiShortmap * 499 GNUNET_CONTAINER_MultiShortmap
500 *
505 * 501 *
506 connected_peers_map) 502 connected_peers_map)
507{ 503{
@@ -565,12 +561,11 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct
565struct GNUNET_TESTING_Command 561struct GNUNET_TESTING_Command
566GNUNET_TRANSPORT_cmd_start_peer (const char *label, 562GNUNET_TRANSPORT_cmd_start_peer (const char *label,
567 const char *system_label, 563 const char *system_label,
568 char *m, 564 uint32_t no,
569 char *n,
570 char *local_m,
571 char *node_ip, 565 char *node_ip,
572 struct GNUNET_MQ_MessageHandler *handlers, 566 struct GNUNET_MQ_MessageHandler *handlers,
573 const char *cfgname) 567 const char *cfgname,
568 GNUNET_TRANSPORT_NotifyConnect notify_connect)
574{ 569{
575 struct StartPeerState *sps; 570 struct StartPeerState *sps;
576 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map = 571 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
@@ -578,14 +573,12 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
578 unsigned int i; 573 unsigned int i;
579 574
580 sps = GNUNET_new (struct StartPeerState); 575 sps = GNUNET_new (struct StartPeerState);
581 sps->m = m; 576 sps->no = no;
582 sps->n = n;
583 sps->local_m = local_m;
584 sps->no = (atoi (n) - 1) * atoi (sps->local_m) + atoi (m);
585 sps->system_label = system_label; 577 sps->system_label = system_label;
586 sps->connected_peers_map = connected_peers_map; 578 sps->connected_peers_map = connected_peers_map;
587 sps->cfgname = cfgname; 579 sps->cfgname = cfgname;
588 sps->node_ip = node_ip; 580 sps->node_ip = node_ip;
581 sps->notify_connect = notify_connect;
589 582
590 if (NULL != handlers) 583 if (NULL != handlers)
591 { 584 {
@@ -602,7 +595,7 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
602 .cls = sps, 595 .cls = sps,
603 .label = label, 596 .label = label,
604 .run = &start_peer_run, 597 .run = &start_peer_run,
605 .finish = &start_peer_finish, 598 .ac = &sps->ac,
606 .cleanup = &start_peer_cleanup, 599 .cleanup = &start_peer_cleanup,
607 .traits = &start_peer_traits 600 .traits = &start_peer_traits
608 }; 601 };
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 0e39bd915..000000000
--- a/src/transport/transport_api_cmd_start_peer_v2.c
+++ /dev/null
@@ -1,607 +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 const struct GNUNET_TESTING_Command *cmd,
181 struct GNUNET_TESTING_Interpreter *is)
182{
183 struct StartPeerState_v2 *sps = cls;
184 char *emsg = NULL;
185 struct GNUNET_PeerIdentity dummy;
186 const struct GNUNET_TESTING_Command *system_cmd;
187 struct GNUNET_TESTING_System *tl_system;
188 char *home;
189 char *transport_unix_path;
190 char *communicator_unix_path;
191 char *bindto;
192
193 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
194 {
195 LOG (GNUNET_ERROR_TYPE_ERROR,
196 "File not found: `%s'\n",
197 sps->cfgname);
198 GNUNET_TESTING_interpreter_fail ();
199 return;
200 }
201
202
203 sps->cfg = GNUNET_CONFIGURATION_create ();
204 GNUNET_assert (GNUNET_OK ==
205 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
206
207 GNUNET_asprintf (&home,
208 "$GNUNET_TMP/test-transport/api-tcp-p%u",
209 sps->no);
210
211 GNUNET_asprintf (&transport_unix_path,
212 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
213 sps->no);
214
215 GNUNET_asprintf (&communicator_unix_path,
216 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
217 sps->no);
218
219 GNUNET_asprintf (&bindto,
220 "%s:60002",
221 sps->node_ip);
222
223
224 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
225 home);
226 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
227 transport_unix_path);
228 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
229 "BINDTO",
230 bindto);
231 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
232 "UNIXPATH",
233 communicator_unix_path);
234
235 system_cmd = GNUNET_TESTING_interpreter_lookup_command (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 ();
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 ();
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 ();
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 ();
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 ();
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 ();
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 ();
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 const struct GNUNET_TESTING_Command *cmd)
353{
354 struct StartPeerState_v2 *sps = cls;
355
356 if (NULL != sps->handlers)
357 {
358 GNUNET_free (sps->handlers);
359 sps->handlers = NULL;
360 }
361 if (NULL != sps->cfg)
362 {
363 GNUNET_CONFIGURATION_destroy (sps->cfg);
364 sps->cfg = NULL;
365 }
366 GNUNET_free (sps->hello);
367 GNUNET_free (sps->connected_peers_map);
368 GNUNET_free (sps);
369}
370
371
372/**
373 * This function prepares an array with traits.
374 *
375 */
376static int
377start_peer_traits (void *cls,
378 const void **ret,
379 const char *trait,
380 unsigned int index)
381{
382 struct StartPeerState_v2 *sps = cls;
383 struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah;
384 struct GNUNET_PeerIdentity *id = &sps->id;
385 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
386 sps->connected_peers_map;
387 char *hello = sps->hello;
388 size_t hello_size = sps->hello_size;
389
390
391 struct GNUNET_TESTING_Trait traits[] = {
392 {
393 .index = 0,
394 .trait_name = "application_handle",
395 .ptr = (const void *) ah,
396 },
397 {
398 .index = 1,
399 .trait_name = "peer_id",
400 .ptr = (const void *) id,
401 },
402 {
403 .index = 2,
404 .trait_name = "connected_peers_map",
405 .ptr = (const void *) connected_peers_map,
406 },
407 {
408 .index = 3,
409 .trait_name = "hello",
410 .ptr = (const void *) hello,
411 },
412 {
413 .index = 4,
414 .trait_name = "hello_size",
415 .ptr = (const void *) hello_size,
416 },
417 {
418 .index = 5,
419 .trait_name = "state",
420 .ptr = (const void *) sps,
421 },
422 GNUNET_TESTING_trait_end ()
423 };
424
425 return GNUNET_TESTING_get_trait (traits,
426 ret,
427 trait,
428 index);
429}
430
431
432/**
433 * Function to get the trait with the struct StartPeerState_v2.
434 *
435 * @param[out] sps struct StartPeerState_v2.
436 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
437 *
438 */
439int
440GNUNET_TRANSPORT_get_trait_state_v2 (const struct
441 GNUNET_TESTING_Command
442 *cmd,
443 struct StartPeerState_v2 **sps)
444{
445 return cmd->traits (cmd->cls,
446 (const void **) sps,
447 "state",
448 (unsigned int) 5);
449}
450
451
452/**
453 * Function to get the trait with the size of the hello.
454 *
455 * @param[out] hello_size size of hello.
456 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
457 *
458 */
459int
460GNUNET_TRANSPORT_get_trait_hello_size_v2 (const struct
461 GNUNET_TESTING_Command
462 *cmd,
463 size_t **hello_size)
464{
465 return cmd->traits (cmd->cls,
466 (const void **) hello_size,
467 "hello_size",
468 (unsigned int) 4);
469}
470
471
472/**
473 * Function to get the trait with the hello.
474 *
475 * @param[out] hello The hello for the peer.
476 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
477 *
478 */
479int
480GNUNET_TRANSPORT_get_trait_hello_v2 (const struct
481 GNUNET_TESTING_Command
482 *cmd,
483 char **hello)
484{
485 return cmd->traits (cmd->cls,
486 (const void **) hello,
487 "hello",
488 (unsigned int) 3);
489}
490
491
492/**
493 * Function to get the trait with the map of connected peers.
494 *
495 * @param[out] connected_peers_map The map with connected peers.
496 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
497 *
498 */
499int
500GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct
501 GNUNET_TESTING_Command
502 *cmd,
503 struct
504 GNUNET_CONTAINER_MultiShortmap
505 *
506 *
507 connected_peers_map)
508{
509 return cmd->traits (cmd->cls,
510 (const void **) connected_peers_map,
511 "connected_peers_map",
512 (unsigned int) 2);
513}
514
515
516/**
517 * Function to get the trait with the transport application handle.
518 *
519 * @param[out] ah The application handle.
520 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
521 */
522int
523GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
524 GNUNET_TESTING_Command *cmd,
525 struct
526 GNUNET_TRANSPORT_ApplicationHandle
527 **ah)
528{
529 return cmd->traits (cmd->cls,
530 (const void **) ah,
531 "application_handle",
532 (unsigned int) 0);
533}
534
535
536/**
537 * Function to get the trait with the peer id.
538 *
539 * @param[out] id The peer id.
540 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
541 */
542int
543GNUNET_TRANSPORT_get_trait_peer_id_v2 (const struct
544 GNUNET_TESTING_Command *cmd,
545 struct GNUNET_PeerIdentity **id)
546{
547 return cmd->traits (cmd->cls,
548 (const void **) id,
549 "peer_id",
550 (unsigned int) 1);
551}
552
553
554/**
555 * Create command.
556 *
557 * @param label name for command.
558 * @param system_label Label of the cmd to setup a test environment.
559 * @param m The number of the local node of the actual network namespace.
560 * @param n The number of the actual namespace.
561 * @param local_m Number of local nodes in each namespace.
562 * @param handlers Handler for messages received by this peer.
563 * @param cfgname Configuration file name for this peer.
564 * @return command.
565 */
566struct GNUNET_TESTING_Command
567GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
568 const char *system_label,
569 uint32_t no,
570 char *node_ip,
571 struct GNUNET_MQ_MessageHandler *handlers,
572 const char *cfgname)
573{
574 struct StartPeerState_v2 *sps;
575 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
576 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
577 unsigned int i;
578
579 sps = GNUNET_new (struct StartPeerState_v2);
580 sps->no = no;
581 sps->system_label = system_label;
582 sps->connected_peers_map = connected_peers_map;
583 sps->cfgname = cfgname;
584 sps->node_ip = node_ip;
585
586 if (NULL != handlers)
587 {
588 for (i = 0; NULL != handlers[i].cb; i++)
589 ;
590 sps->handlers = GNUNET_new_array (i + 1,
591 struct GNUNET_MQ_MessageHandler);
592 GNUNET_memcpy (sps->handlers,
593 handlers,
594 i * sizeof(struct GNUNET_MQ_MessageHandler));
595 }
596
597 struct GNUNET_TESTING_Command cmd = {
598 .cls = sps,
599 .label = label,
600 .run = &start_peer_run,
601 .finish = &start_peer_finish,
602 .cleanup = &start_peer_cleanup,
603 .traits = &start_peer_traits
604 };
605
606 return cmd;
607}
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 b5cefecc8..000000000
--- a/src/transport/transport_api_cmd_start_peer_v3.c
+++ /dev/null
@@ -1,619 +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 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}
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
index 4d7228378..dcb982a65 100644
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -54,14 +54,14 @@ struct StopPeerState
54 */ 54 */
55static void 55static void
56stop_peer_run (void *cls, 56stop_peer_run (void *cls,
57 const struct GNUNET_TESTING_Command *cmd,
58 struct GNUNET_TESTING_Interpreter *is) 57 struct GNUNET_TESTING_Interpreter *is)
59{ 58{
60 struct StopPeerState *stop_ps = cls; 59 struct StopPeerState *stop_ps = cls;
61 struct StartPeerState *sps; 60 struct StartPeerState *sps;
62 const struct GNUNET_TESTING_Command *start_cmd; 61 const struct GNUNET_TESTING_Command *start_cmd;
63 62
64 start_cmd = GNUNET_TESTING_interpreter_lookup_command (stop_ps->start_label); 63 start_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
64 stop_ps->start_label);
65 GNUNET_TRANSPORT_get_trait_state (start_cmd, 65 GNUNET_TRANSPORT_get_trait_state (start_cmd,
66 &sps); 66 &sps);
67 67
@@ -112,8 +112,7 @@ stop_peer_run (void *cls,
112 * 112 *
113 */ 113 */
114static void 114static void
115stop_peer_cleanup (void *cls, 115stop_peer_cleanup (void *cls)
116 const struct GNUNET_TESTING_Command *cmd)
117{ 116{
118 struct StopPeerState *sps = cls; 117 struct StopPeerState *sps = cls;
119 118
@@ -150,14 +149,14 @@ GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
150 149
151 sps = GNUNET_new (struct StopPeerState); 150 sps = GNUNET_new (struct StopPeerState);
152 sps->start_label = start_label; 151 sps->start_label = start_label;
153 152 {
154 struct GNUNET_TESTING_Command cmd = { 153 struct GNUNET_TESTING_Command cmd = {
155 .cls = sps, 154 .cls = sps,
156 .label = label, 155 .label = label,
157 .run = &stop_peer_run, 156 .run = &stop_peer_run,
158 .cleanup = &stop_peer_cleanup, 157 .cleanup = &stop_peer_cleanup,
159 .traits = &stop_peer_traits 158 .traits = &stop_peer_traits
160 }; 159 };
161 160 return cmd;
162 return cmd; 161 }
163} 162}