aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am59
-rw-r--r--src/testbed/gnunet-cmd.c123
-rw-r--r--src/testbed/gnunet-cmds-helper.c663
-rwxr-xr-xsrc/testbed/netjail_core.sh107
-rwxr-xr-xsrc/testbed/netjail_exec.sh16
-rwxr-xr-xsrc/testbed/netjail_start.sh52
-rwxr-xr-xsrc/testbed/netjail_stop.sh26
-rw-r--r--src/testbed/plugin_testcmd.c115
-rw-r--r--src/testbed/test_testbed_api_cmd_netjail.c80
-rw-r--r--src/testbed/testbed_api.h6
-rw-r--r--src/testbed/testbed_api_cmd_block_until_all_peers_started.c128
-rw-r--r--src/testbed/testbed_api_cmd_controller.c203
-rw-r--r--src/testbed/testbed_api_cmd_local_test_finished.c129
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start.c199
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start_testbed.c532
-rw-r--r--src/testbed/testbed_api_cmd_netjail_stop.c197
-rw-r--r--src/testbed/testbed_api_cmd_netjail_stop_testbed.c143
-rw-r--r--src/testbed/testbed_api_cmd_peer.c281
-rw-r--r--src/testbed/testbed_api_cmd_peer_store.c60
-rw-r--r--src/testbed/testbed_api_cmd_send_peer_ready.c103
-rw-r--r--src/testbed/testbed_api_cmd_tng_connect.c55
-rw-r--r--src/testbed/testbed_api_cmd_tng_service.c276
-rw-r--r--src/testbed/testbed_api_hosts.c53
-rw-r--r--src/testbed/testbed_helper.h54
24 files changed, 25 insertions, 3635 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index a9837daf5..11399e77c 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -23,8 +23,6 @@ if HAVE_SQLITE
23endif 23endif
24 24
25libexec_PROGRAMS = \ 25libexec_PROGRAMS = \
26 gnunet-cmd \
27 gnunet-cmds-helper \
28 gnunet-service-testbed \ 26 gnunet-service-testbed \
29 gnunet-helper-testbed \ 27 gnunet-helper-testbed \
30 gnunet-daemon-testbed-blacklist \ 28 gnunet-daemon-testbed-blacklist \
@@ -37,20 +35,6 @@ bin_PROGRAMS = \
37noinst_PROGRAMS = \ 35noinst_PROGRAMS = \
38 $(generate_underlay) 36 $(generate_underlay)
39 37
40plugin_LTLIBRARIES = \
41 libgnunet_plugin_testcmd.la
42
43libgnunet_plugin_testcmd_la_SOURCES = \
44 plugin_testcmd.c
45libgnunet_plugin_testcmd_la_LIBADD = \
46 $(top_builddir)/src/util/libgnunetutil.la \
47 $(top_builddir)/src/testing/libgnunettesting.la \
48 $(top_builddir)/src/statistics/libgnunetstatistics.la \
49 libgnunettestbed.la \
50 $(LTLIBINTL)
51libgnunet_plugin_testcmd_la_LDFLAGS = \
52 $(GN_PLUGIN_LDFLAGS)
53
54gnunet_service_testbed_SOURCES = \ 38gnunet_service_testbed_SOURCES = \
55 gnunet-service-testbed.c gnunet-service-testbed.h \ 39 gnunet-service-testbed.c gnunet-service-testbed.h \
56 gnunet-service-testbed_links.c gnunet-service-testbed_links.h \ 40 gnunet-service-testbed_links.c gnunet-service-testbed_links.h \
@@ -75,6 +59,7 @@ gnunet_service_testbed_LDADD = $(XLIB) \
75gnunet_testbed_profiler_SOURCES = \ 59gnunet_testbed_profiler_SOURCES = \
76 gnunet-testbed-profiler.c 60 gnunet-testbed-profiler.c
77gnunet_testbed_profiler_LDADD = $(XLIB) \ 61gnunet_testbed_profiler_LDADD = $(XLIB) \
62 $(top_builddir)/src/testing/libgnunettesting.la \
78 $(top_builddir)/src/util/libgnunetutil.la \ 63 $(top_builddir)/src/util/libgnunetutil.la \
79 libgnunettestbed.la 64 libgnunettestbed.la
80gnunet_testbed_profiler_LDFLAGS = \ 65gnunet_testbed_profiler_LDFLAGS = \
@@ -88,23 +73,6 @@ gnunet_helper_testbed_LDADD = $(XLIB) \
88 libgnunettestbed.la \ 73 libgnunettestbed.la \
89 $(LTLIBINTL) $(Z_LIBS) 74 $(LTLIBINTL) $(Z_LIBS)
90 75
91gnunet_cmd_SOURCES = \
92 gnunet-cmd.c
93gnunet_cmd_LDADD = $(XLIB) \
94 $(top_builddir)/src/util/libgnunetutil.la \
95 $(top_builddir)/src/testing/libgnunettesting.la \
96 libgnunettestbed.la \
97 $(LTLIBINTL) $(Z_LIBS)
98
99gnunet_cmds_helper_SOURCES = \
100 gnunet-cmds-helper.c
101gnunet_cmds_helper_LDADD = $(XLIB) \
102 $(top_builddir)/src/util/libgnunetutil.la \
103 $(top_builddir)/src/testing/libgnunettesting.la \
104 $(top_builddir)/src/transport/libgnunettransport.la \
105 libgnunettestbed.la \
106 $(LTLIBINTL) $(Z_LIBS)
107
108gnunet_daemon_testbed_blacklist_SOURCES = gnunet-daemon-testbed-blacklist.c 76gnunet_daemon_testbed_blacklist_SOURCES = gnunet-daemon-testbed-blacklist.c
109gnunet_daemon_testbed_blacklist_LDADD = $(XLIB) \ 77gnunet_daemon_testbed_blacklist_LDADD = $(XLIB) \
110 $(top_builddir)/src/transport/libgnunettransport.la \ 78 $(top_builddir)/src/transport/libgnunettransport.la \
@@ -127,17 +95,8 @@ lib_LTLIBRARIES = \
127 libgnunettestbed.la 95 libgnunettestbed.la
128 96
129libgnunettestbed_la_SOURCES = \ 97libgnunettestbed_la_SOURCES = \
130 testbed_api_cmd_local_test_finished.c \
131 testbed_api_cmd_send_peer_ready.c \
132 testbed_api_cmd_block_until_all_peers_started.c \
133 testbed_api_cmd_netjail_start.c \
134 testbed_api_cmd_netjail_start_testbed.c \
135 testbed_api_cmd_netjail_stop_testbed.c \
136 testbed_api_cmd_netjail_stop.c \
137 testbed_api.c testbed_api.h testbed.h \ 98 testbed_api.c testbed_api.h testbed.h \
138 testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \ 99 testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \
139 testbed_api_cmd_controller.c \
140 testbed_api_cmd_peer.c \
141 testbed_api_operations.c testbed_api_operations.h \ 100 testbed_api_operations.c testbed_api_operations.h \
142 testbed_api_peers.c testbed_api_peers.h \ 101 testbed_api_peers.c testbed_api_peers.h \
143 testbed_api_services.c \ 102 testbed_api_services.c \
@@ -156,24 +115,18 @@ libgnunettestbed_la_LIBADD = $(XLIB) \
156 $(top_builddir)/src/arm/libgnunetarm.la \ 115 $(top_builddir)/src/arm/libgnunetarm.la \
157 $(top_builddir)/src/util/libgnunetutil.la \ 116 $(top_builddir)/src/util/libgnunetutil.la \
158 $(LTLIBINTL) 117 $(LTLIBINTL)
159libgnunettestbed_la_DEPENDENCIES = \
160 $(top_builddir)/src/statistics/libgnunetstatistics.la \
161 $(top_builddir)/src/transport/libgnunettransport.la \
162 $(top_builddir)/src/hello/libgnunethello.la \
163 $(top_builddir)/src/testing/libgnunettesting.la \
164 $(top_builddir)/src/util/libgnunetutil.la
165libgnunettestbed_la_LDFLAGS = \ 118libgnunettestbed_la_LDFLAGS = \
166 $(GN_LIB_LDFLAGS) \ 119 $(GN_LIB_LDFLAGS) \
167 -version-info 0:0:0 120 -version-info 0:0:0
168 121
169generate_underlay_topology_SOURCES = generate-underlay-topology.c 122generate_underlay_topology_SOURCES = generate-underlay-topology.c
170generate_underlay_topology_LDADD = $(XLIB) \ 123generate_underlay_topology_LDADD = $(XLIB) \
124 $(top_builddir)/src/testing/libgnunettesting.la \
171 $(top_builddir)/src/util/libgnunetutil.la \ 125 $(top_builddir)/src/util/libgnunetutil.la \
172 libgnunettestbed.la \ 126 libgnunettestbed.la \
173 $(LTLIBINTL) -lsqlite3 127 $(LTLIBINTL) -lsqlite3
174 128
175check_PROGRAMS = \ 129check_PROGRAMS = \
176 test_testbed_api_cmd_netjail \
177 test_testbed_api_hosts \ 130 test_testbed_api_hosts \
178 test_gnunet_helper_testbed \ 131 test_gnunet_helper_testbed \
179 test_testbed_api_controllerlink \ 132 test_testbed_api_controllerlink \
@@ -208,7 +161,6 @@ check_PROGRAMS = \
208if ENABLE_TEST_RUN 161if ENABLE_TEST_RUN
209 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 162 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
210 TESTS = \ 163 TESTS = \
211 test_testbed_api_cmd_netjail \
212 test_testbed_api \ 164 test_testbed_api \
213 test_testbed_api_sd \ 165 test_testbed_api_sd \
214 test_testbed_api_operations \ 166 test_testbed_api_operations \
@@ -239,13 +191,6 @@ if ENABLE_TEST_RUN
239 $(underlay_testcases) 191 $(underlay_testcases)
240endif 192endif
241 193
242test_testbed_api_cmd_netjail_SOURCES = \
243 test_testbed_api_cmd_netjail.c
244test_testbed_api_cmd_netjail_LDADD = \
245 $(top_builddir)/src/testing/libgnunettesting.la \
246 $(top_builddir)/src/util/libgnunetutil.la \
247 libgnunettestbed.la
248
249test_testbed_api_SOURCES = \ 194test_testbed_api_SOURCES = \
250 test_testbed_api.c 195 test_testbed_api.c
251test_testbed_api_LDADD = \ 196test_testbed_api_LDADD = \
diff --git a/src/testbed/gnunet-cmd.c b/src/testbed/gnunet-cmd.c
deleted file mode 100644
index f232bd805..000000000
--- a/src/testbed/gnunet-cmd.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2008--2013, 2016 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/gnunet-cmd.c
23 *
24 * @brief Binary to start testcase plugins
25 *
26 * @author t3sserakt
27 */
28
29#include "platform.h"
30#include "gnunet_util_lib.h"
31#include "gnunet_testing_lib.h"
32#include "gnunet_testing_plugin.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39#define NODE_BASE_IP "192.168.15."
40
41#define ROUTER_BASE_IP "92.68.150."
42
43/**
44 * Handle for a plugin.
45 */
46struct Plugin
47{
48 /**
49 * Name of the shared library.
50 */
51 char *library_name;
52
53 /**
54 * Plugin API.
55 */
56 struct GNUNET_TESTING_PluginFunctions *api;
57
58 char *node_ip;
59
60 char *plugin_name;
61
62 char *global_n;
63
64 char *local_m;
65
66 char *n;
67
68 char *m;
69};
70
71
72/**
73 * Main function to run the test cases.
74 *
75 * @param cls plugin to use.
76 *
77 */
78static void
79run (void *cls)
80{
81 struct Plugin *plugin = cls;
82 char *router_ip;
83 char *node_ip;
84
85 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) + 1);
86 strcpy (router_ip, ROUTER_BASE_IP);
87 strcat (router_ip, plugin->m);
88
89 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
90 strcat (node_ip, NODE_BASE_IP);
91 strcat (node_ip, plugin->n);
92
93 plugin->api->start_testcase (NULL, router_ip, node_ip, NULL, NULL);
94
95}
96
97
98int
99main (int argc, char *const *argv)
100{
101 int rv = 0;
102 struct Plugin *plugin;
103
104 GNUNET_log_setup ("gnunet-cmd",
105 "DEBUG",
106 NULL);
107
108 plugin = GNUNET_new (struct Plugin);
109 plugin->api = GNUNET_PLUGIN_load (argv[0],
110 NULL);
111 plugin->library_name = GNUNET_strdup (argv[0]);
112
113 plugin->global_n = argv[1];
114 plugin->local_m = argv[2];
115 plugin->n = argv[3];
116 plugin->m = argv[4];
117
118 GNUNET_SCHEDULER_run (&run,
119 plugin);
120
121 GNUNET_free (plugin);
122 return rv;
123}
diff --git a/src/testbed/gnunet-cmds-helper.c b/src/testbed/gnunet-cmds-helper.c
deleted file mode 100644
index 113e3c386..000000000
--- a/src/testbed/gnunet-cmds-helper.c
+++ /dev/null
@@ -1,663 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2008--2013, 2016 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/gnunet-cmds-helper.c
23 * @brief Helper binary that is started from a remote interpreter loop to start
24 * a local interpreter loop.
25 *
26 * This helper monitors for three termination events. They are: (1)The
27 * stdin of the helper is closed for reading; (2)the helper received
28 * SIGTERM/SIGINT; (3)the local loop crashed. In case of events 1 and 2
29 * the helper kills the interpreter loop. When the interpreter loop
30 * crashed (event 3), the helper should send a SIGTERM to its own process
31 * group; this behaviour will help terminate any child processes the loop
32 * has started and prevents them from leaking and running forever.
33 *
34 * @author t3sserakt
35 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
36 */
37
38
39#include "platform.h"
40#include "gnunet_util_lib.h"
41#include "gnunet_testing_lib.h"
42#include "gnunet_testbed_service.h"
43#include "testbed_helper.h"
44#include "testbed_api.h"
45#include "gnunet_testing_plugin.h"
46#include <zlib.h>
47
48
49/**
50 * Generic logging shortcut
51 */
52#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
53
54/**
55 * Debug logging shorthand
56 */
57#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
58
59#define NODE_BASE_IP "192.168.15."
60
61#define ROUTER_BASE_IP "92.68.150."
62
63/**
64 * Handle for a plugin.
65 */
66struct Plugin
67{
68 /**
69 * Name of the shared library.
70 */
71 char *library_name;
72
73 /**
74 * Plugin API.
75 */
76 struct GNUNET_TESTING_PluginFunctions *api;
77
78 char *node_ip;
79
80 char *plugin_name;
81
82 char *global_n;
83
84 char *local_m;
85
86 char *n;
87
88 char *m;
89};
90
91struct NodeIdentifier
92{
93 char *n;
94
95 char *m;
96
97 char *global_n;
98
99 char *local_m;
100};
101
102/**
103 * Context for a single write on a chunk of memory
104 */
105struct WriteContext
106{
107 /**
108 * The data to write
109 */
110 void *data;
111
112 /**
113 * The length of the data
114 */
115 size_t length;
116
117 /**
118 * The current position from where the write operation should begin
119 */
120 size_t pos;
121};
122
123struct Plugin *plugin;
124
125/**
126 * The process handle to the testbed service
127 */
128static struct GNUNET_OS_Process *cmd_binary_process;
129
130/**
131 * Handle to the testing system
132 */
133static struct GNUNET_TESTING_System *test_system;
134
135/**
136 * Our message stream tokenizer
137 */
138struct GNUNET_MessageStreamTokenizer *tokenizer;
139
140/**
141 * Disk handle from stdin
142 */
143static struct GNUNET_DISK_FileHandle *stdin_fd;
144
145/**
146 * Disk handle for stdout
147 */
148static struct GNUNET_DISK_FileHandle *stdout_fd;
149
150/**
151 * Pipe used to communicate shutdown via signal.
152 */
153static struct GNUNET_DISK_PipeHandle *sigpipe;
154
155/**
156 * Task identifier for the read task
157 */
158static struct GNUNET_SCHEDULER_Task *read_task_id;
159
160/**
161 * Task identifier for the write task
162 */
163static struct GNUNET_SCHEDULER_Task *write_task_id;
164
165/**
166 * Task to kill the child
167 */
168static struct GNUNET_SCHEDULER_Task *child_death_task_id;
169
170/**
171 * Are we done reading messages from stdin?
172 */
173static int done_reading;
174
175/**
176 * Result to return in case we fail
177 */
178static int status;
179
180
181/**
182 * Task to shut down cleanly
183 *
184 * @param cls NULL
185 */
186static void
187shutdown_task (void *cls)
188{
189
190 LOG_DEBUG ("Shutting down.\n");
191 LOG (GNUNET_ERROR_TYPE_ERROR,
192 "Shutting down tokenizer!\n");
193
194 if (NULL != read_task_id)
195 {
196 GNUNET_SCHEDULER_cancel (read_task_id);
197 read_task_id = NULL;
198 }
199 if (NULL != write_task_id)
200 {
201 struct WriteContext *wc;
202
203 wc = GNUNET_SCHEDULER_cancel (write_task_id);
204 write_task_id = NULL;
205 GNUNET_free (wc->data);
206 GNUNET_free (wc);
207 }
208 if (NULL != child_death_task_id)
209 {
210 GNUNET_SCHEDULER_cancel (child_death_task_id);
211 child_death_task_id = NULL;
212 }
213 if (NULL != stdin_fd)
214 (void) GNUNET_DISK_file_close (stdin_fd);
215 if (NULL != stdout_fd)
216 (void) GNUNET_DISK_file_close (stdout_fd);
217 GNUNET_MST_destroy (tokenizer);
218 tokenizer = NULL;
219
220 if (NULL != test_system)
221 {
222 GNUNET_TESTING_system_destroy (test_system, GNUNET_YES);
223 test_system = NULL;
224 }
225}
226
227
228/**
229 * Task to write to the standard out
230 *
231 * @param cls the WriteContext
232 */
233static void
234write_task (void *cls)
235{
236 struct WriteContext *wc = cls;
237 ssize_t bytes_wrote;
238
239 LOG (GNUNET_ERROR_TYPE_ERROR,
240 "Writing data!\n");
241
242 GNUNET_assert (NULL != wc);
243 write_task_id = NULL;
244 bytes_wrote = GNUNET_DISK_file_write (stdout_fd,
245 wc->data + wc->pos,
246 wc->length - wc->pos);
247 if (GNUNET_SYSERR == bytes_wrote)
248 {
249 LOG (GNUNET_ERROR_TYPE_WARNING,
250 "Cannot reply back successful initialization\n");
251 GNUNET_free (wc->data);
252 GNUNET_free (wc);
253 return;
254 }
255 wc->pos += bytes_wrote;
256 if (wc->pos == wc->length)
257 {
258 GNUNET_free (wc->data);
259 GNUNET_free (wc);
260 LOG (GNUNET_ERROR_TYPE_ERROR,
261 "Written successfully!\n");
262 return;
263 }
264 LOG (GNUNET_ERROR_TYPE_ERROR,
265 "Written data!\n");
266 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
267 stdout_fd,
268 &write_task,
269 wc);
270}
271
272
273/**
274 * Task triggered whenever we receive a SIGCHLD (child
275 * process died).
276 *
277 * @param cls closure, NULL if we need to self-restart
278 */
279static void
280child_death_task (void *cls)
281{
282 const struct GNUNET_DISK_FileHandle *pr;
283 char c[16];
284
285 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
286 child_death_task_id = NULL;
287 /* consume the signal */
288 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c)));
289 LOG_DEBUG ("Got SIGCHLD\n");
290
291 LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n");
292 child_death_task_id =
293 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
294 pr,
295 &child_death_task,
296 NULL);
297}
298
299
300static void
301write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
302{
303 struct WriteContext *wc;
304
305 LOG (GNUNET_ERROR_TYPE_ERROR,
306 "enter write_message!\n");
307 wc = GNUNET_new (struct WriteContext);
308 wc->length = msg_length;
309 wc->data = message;
310 write_task_id = GNUNET_SCHEDULER_add_write_file (
311 GNUNET_TIME_UNIT_FOREVER_REL,
312 stdout_fd,
313 &write_task,
314 wc);
315 LOG (GNUNET_ERROR_TYPE_ERROR,
316 "leave write_message!\n");
317}
318
319
320/**
321 * Function to run the test cases.
322 *
323 * @param cls plugin to use.
324 *
325 */
326/*static void
327run_plugin (void *cls)
328{
329 struct Plugin *plugin = cls;
330 char *router_ip;
331 char *node_ip;
332
333 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) + 1);
334 strcpy (router_ip, ROUTER_BASE_IP);
335 strcat (router_ip, plugin->m);
336
337 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
338 strcat (node_ip, NODE_BASE_IP);
339 strcat (node_ip, plugin->n);
340
341 plugin->api->start_testcase (&write_message, router_ip, node_ip);
342
343}*/
344
345
346/**
347 * Functions with this signature are called whenever a
348 * complete message is received by the tokenizer.
349 *
350 * Do not call #GNUNET_mst_destroy() in this callback
351 *
352 * @param cls identification of the client
353 * @param message the actual message
354 * @return #GNUNET_OK on success,
355 * #GNUNET_NO to stop further processing (no error)
356 * #GNUNET_SYSERR to stop further processing with error
357 */
358static int
359tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
360{
361 struct NodeIdentifier *ni = cls;
362 const struct GNUNET_CMDS_HelperInit *msg;
363 struct GNUNET_CMDS_HelperReply *reply;
364 char *binary;
365 char *plugin_name;
366 size_t plugin_name_size;
367 uint16_t msize;
368 size_t msg_length;
369 char *router_ip;
370 char *node_ip;
371
372 LOG (GNUNET_ERROR_TYPE_ERROR,
373 "tokenizer \n");
374
375 msize = ntohs (message->size);
376 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
377 {
378 msg = (const struct GNUNET_CMDS_HelperInit *) message;
379 plugin_name_size = ntohs (msg->plugin_name_size);
380 if ((sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_size) > msize)
381 {
382 GNUNET_break (0);
383 LOG (GNUNET_ERROR_TYPE_WARNING,
384 "Received unexpected message -- exiting\n");
385 goto error;
386 }
387 plugin_name = GNUNET_malloc (plugin_name_size + 1);
388 GNUNET_strlcpy (plugin_name,
389 ((char *) &msg[1]),
390 plugin_name_size + 1);
391
392 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd");
393
394 LOG (GNUNET_ERROR_TYPE_ERROR,
395 "plugin_name: %s \n",
396 plugin_name);
397
398 // cmd_binary_process = GNUNET_OS_start_process (
399 /*GNUNET_OS_INHERIT_STD_ERR verbose? ,
400 NULL,
401 NULL,
402 NULL,
403 binary,
404 plugin_name,
405 ni->global_n,
406 ni->local_m,
407 ni->n,
408 ni->m,
409 NULL);*/
410
411 plugin = GNUNET_new (struct Plugin);
412 plugin->api = GNUNET_PLUGIN_load (plugin_name,
413 NULL);
414 plugin->library_name = GNUNET_strdup (plugin_name);
415
416 plugin->global_n = ni->global_n;
417 plugin->local_m = ni->local_m;
418 plugin->n = ni->n;
419 plugin->m = ni->m;
420
421 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m)
422 + 1);
423 strcpy (router_ip, ROUTER_BASE_IP);
424 strcat (router_ip, plugin->m);
425
426 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
427 strcat (node_ip, NODE_BASE_IP);
428 strcat (node_ip, plugin->n);
429
430 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
431 plugin->n);
432
433 LOG (GNUNET_ERROR_TYPE_ERROR,
434 "We got here!\n");
435
436 /*if (NULL == cmd_binary_process)
437 {
438 LOG (GNUNET_ERROR_TYPE_ERROR,
439 "Starting plugin failed!\n");
440 return GNUNET_SYSERR;
441 }*/
442
443 LOG (GNUNET_ERROR_TYPE_ERROR,
444 "We got here 2!\n");
445
446 LOG (GNUNET_ERROR_TYPE_ERROR,
447 "global_n: %s local_n: %s n: %s m: %s.\n",
448 ni->global_n,
449 ni->local_m,
450 ni->n,
451 ni->m);
452
453 LOG (GNUNET_ERROR_TYPE_ERROR,
454 "We got here 3!\n");
455
456 GNUNET_free (binary);
457
458 // done_reading = GNUNET_YES;
459
460 msg_length = sizeof(struct GNUNET_CMDS_HelperReply);
461 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply);
462 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY);
463 reply->header.size = htons ((uint16_t) msg_length);
464
465 LOG (GNUNET_ERROR_TYPE_ERROR,
466 "We got here 4!\n");
467
468 write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
469
470 LOG (GNUNET_ERROR_TYPE_ERROR,
471 "We got here 5!\n");
472
473 /*child_death_task_id = GNUNET_SCHEDULER_add_read_file (
474 GNUNET_TIME_UNIT_FOREVER_REL,
475 GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
476 &child_death_task,
477 NULL);*/
478 return GNUNET_OK;
479 }
480 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
481 message->type))
482 {
483 plugin->api->all_peers_started ();
484 return GNUNET_OK;
485 }
486 else
487 {
488 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
489 goto error;
490 }
491
492
493 error:
494 status = GNUNET_SYSERR;
495 LOG (GNUNET_ERROR_TYPE_ERROR,
496 "tokenizer shutting down!\n");
497 GNUNET_SCHEDULER_shutdown ();
498 return GNUNET_SYSERR;
499}
500
501
502/**
503 * Task to read from stdin
504 *
505 * @param cls NULL
506 */
507static void
508read_task (void *cls)
509{
510 char buf[GNUNET_MAX_MESSAGE_SIZE];
511 ssize_t sread;
512
513 read_task_id = NULL;
514 sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof(buf));
515 if ((GNUNET_SYSERR == sread) || (0 == sread))
516 {
517 LOG_DEBUG ("STDIN closed\n");
518 LOG (GNUNET_ERROR_TYPE_ERROR,
519 "tokenizer shutting down during reading!\n");
520 GNUNET_SCHEDULER_shutdown ();
521 return;
522 }
523 if (GNUNET_YES == done_reading)
524 {
525 /* didn't expect any more data! */
526 GNUNET_break_op (0);
527 LOG (GNUNET_ERROR_TYPE_ERROR,
528 "tokenizer shutting down during reading, didn't expect any more data!\n");
529 GNUNET_SCHEDULER_shutdown ();
530 return;
531 }
532 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread);
533 LOG (GNUNET_ERROR_TYPE_ERROR,
534 "Read %u bytes\n", (unsigned int) sread);
535 /* FIXME: could introduce a GNUNET_MST_read2 to read
536 directly from 'stdin_fd' and save a memcpy() here */
537 if (GNUNET_OK !=
538 GNUNET_MST_from_buffer (tokenizer, buf, sread, GNUNET_NO, GNUNET_NO))
539 {
540 GNUNET_break (0);
541 LOG (GNUNET_ERROR_TYPE_ERROR,
542 "tokenizer shutting down during reading, writing to buffer failed!\n");
543 GNUNET_SCHEDULER_shutdown ();
544 return;
545 }
546 read_task_id /* No timeout while reading */
547 = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
548 stdin_fd,
549 &read_task,
550 NULL);
551}
552
553
554/**
555 * Main function that will be run.
556 *
557 * @param cls closure
558 * @param args remaining command-line arguments
559 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
560 * @param cfg configuration
561 */
562static void
563run (void *cls,
564 char *const *args,
565 const char *cfgfile,
566 const struct GNUNET_CONFIGURATION_Handle *cfg)
567{
568 struct NodeIdentifier *ni = cls;
569
570 LOG_DEBUG ("Starting interpreter loop helper...\n");
571
572 tokenizer = GNUNET_MST_create (&tokenizer_cb, ni);
573 stdin_fd = GNUNET_DISK_get_handle_from_native (stdin);
574 stdout_fd = GNUNET_DISK_get_handle_from_native (stdout);
575 read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
576 stdin_fd,
577 &read_task,
578 NULL);
579 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
580}
581
582
583/**
584 * Signal handler called for SIGCHLD.
585 */
586static void
587sighandler_child_death ()
588{
589 static char c;
590 int old_errno; /* back-up errno */
591
592 old_errno = errno;
593 GNUNET_break (
594 1 ==
595 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe,
596 GNUNET_DISK_PIPE_END_WRITE),
597 &c,
598 sizeof(c)));
599 errno = old_errno;
600}
601
602
603/**
604 * Main function
605 *
606 * @param argc the number of command line arguments
607 * @param argv command line arg array
608 * @return return code
609 */
610int
611main (int argc, char **argv)
612{
613 struct NodeIdentifier *ni;
614 struct GNUNET_SIGNAL_Context *shc_chld;
615 struct GNUNET_GETOPT_CommandLineOption options[] =
616 { GNUNET_GETOPT_OPTION_END };
617 int ret;
618
619 GNUNET_log_setup ("gnunet-cmds-helper",
620 "DEBUG",
621 NULL);
622 ni = GNUNET_new (struct NodeIdentifier);
623 ni->global_n = argv[1];
624 ni->local_m = argv[2];
625 ni->n = argv[3];
626 ni->m = argv[4];
627
628 LOG (GNUNET_ERROR_TYPE_ERROR,
629 "global_n: %s local_n: %s n: %s m: %s.\n",
630 ni->global_n,
631 ni->local_m,
632 ni->n,
633 ni->m);
634
635 status = GNUNET_OK;
636 if (NULL ==
637 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
638 {
639 GNUNET_break (0);
640 return 1;
641 }
642 shc_chld =
643 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
644 ret = GNUNET_PROGRAM_run (argc,
645 argv,
646 "gnunet-cmds-helper",
647 "Helper for starting a local interpreter loop",
648 options,
649 &run,
650 ni);
651 LOG (GNUNET_ERROR_TYPE_ERROR,
652 "run finished\n");
653 GNUNET_SIGNAL_handler_uninstall (shc_chld);
654 shc_chld = NULL;
655 GNUNET_DISK_pipe_close (sigpipe);
656 GNUNET_free (ni);
657 if (GNUNET_OK != ret)
658 return 1;
659 return (GNUNET_OK == status) ? 0 : 1;
660}
661
662
663/* end of gnunet-cmds-helper.c */
diff --git a/src/testbed/netjail_core.sh b/src/testbed/netjail_core.sh
deleted file mode 100755
index 792b1df24..000000000
--- a/src/testbed/netjail_core.sh
+++ /dev/null
@@ -1,107 +0,0 @@
1#!/bin/sh
2#
3
4JAILOR=${SUDO_USER:?must run in sudo}
5
6# running with `sudo` is required to be
7# able running the actual commands as the
8# original user.
9
10export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
11
12netjail_check() {
13 NODE_COUNT=$1
14
15 FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4))
16
17 # quit if `$FD_COUNT < ($LOCAL_M * $GLOBAL_N * 2)`:
18 # the script also requires `sudo -C ($FD_COUNT + 4)`
19 # so you need 'Defaults closefrom_override' in the
20 # sudoers file.
21
22 if [ $FD_COUNT -lt $(($NODE_COUNT * 2)) ]; then
23 echo "File descriptors do not match requirements!" >&2
24 exit 1
25 fi
26}
27
28netjail_print_name() {
29 printf "%s%02x%02x" $1 $2 ${3:-0}
30}
31
32netjail_bridge() {
33 BRIDGE=$1
34
35 ip link add $BRIDGE type bridge
36 ip link set dev $BRIDGE up
37}
38
39netjail_bridge_clear() {
40 BRIDGE=$1
41
42 ip link delete $BRIDGE
43}
44
45netjail_node() {
46 NODE=$1
47
48 ip netns add $NODE
49}
50
51netjail_node_clear() {
52 NODE=$1
53
54 ip netns delete $NODE
55}
56
57netjail_node_link_bridge() {
58 NODE=$1
59 BRIDGE=$2
60 ADDRESS=$3
61 MASK=$4
62
63 LINK_IF="$NODE-$BRIDGE-0"
64 LINK_BR="$NODE-$BRIDGE-1"
65
66 ip link add $LINK_IF type veth peer name $LINK_BR
67 ip link set $LINK_IF netns $NODE
68 ip link set $LINK_BR master $BRIDGE
69
70 ip -n $NODE addr add "$ADDRESS/$MASK" dev $LINK_IF
71 ip -n $NODE link set $LINK_IF up
72 ip -n $NODE link set up dev lo
73
74 ip link set $LINK_BR up
75}
76
77netjail_node_add_nat() {
78 NODE=$1
79 ADDRESS=$2
80 MASK=$3
81
82 ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE
83}
84
85netjail_node_add_default() {
86 NODE=$1
87 ADDRESS=$2
88
89 ip -n $NODE route add default via $ADDRESS
90}
91
92netjail_node_exec() {
93 NODE=$1
94 FD_IN=$2
95 FD_OUT=$3
96 shift 3
97
98 unshare -fp --kill-child -- ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN
99}
100
101netjail_node_exec_without_fds() {
102 NODE=$1
103 shift 1
104
105 unshare -fp --kill-child -- ip netns exec $NODE sudo -u $JAILOR -- $@
106}
107
diff --git a/src/testbed/netjail_exec.sh b/src/testbed/netjail_exec.sh
deleted file mode 100755
index b76d2e444..000000000
--- a/src/testbed/netjail_exec.sh
+++ /dev/null
@@ -1,16 +0,0 @@
1#!/bin/sh
2. "./../testbed/netjail_core.sh"
3
4set -eu
5set -x
6
7export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
8
9M=$1
10N=$2
11
12NODE=$(netjail_print_name "N" $N $M)
13
14
15
16netjail_node_exec_without_fds $NODE $3 $4 $5 $1 $2
diff --git a/src/testbed/netjail_start.sh b/src/testbed/netjail_start.sh
deleted file mode 100755
index 4c1c33c83..000000000
--- a/src/testbed/netjail_start.sh
+++ /dev/null
@@ -1,52 +0,0 @@
1#!/bin/sh
2. "./../testbed/netjail_core.sh"
3
4set -eu
5set -x
6
7export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
8
9LOCAL_M=$1
10GLOBAL_N=$2
11
12# TODO: stunserver? ..and globally known peer?
13
14shift 2
15
16LOCAL_GROUP="192.168.15"
17GLOBAL_GROUP="92.68.150"
18
19NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M)
20
21netjail_bridge $NETWORK_NET
22
23for N in $(seq $GLOBAL_N); do
24 ROUTER=$(netjail_print_name "R" $N)
25
26 netjail_node $ROUTER
27 netjail_node_link_bridge $ROUTER $NETWORK_NET "$GLOBAL_GROUP.$N" 24
28
29 ROUTER_NET=$(netjail_print_name "r" $N)
30
31 netjail_bridge $ROUTER_NET
32
33 for M in $(seq $LOCAL_M); do
34 NODE=$(netjail_print_name "N" $N $M)
35
36 netjail_node $NODE
37 netjail_node_link_bridge $NODE $ROUTER_NET "$LOCAL_GROUP.$M" 24
38 done
39
40 ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))"
41
42 netjail_node_link_bridge $ROUTER $ROUTER_NET $ROUTER_ADDR 24
43 netjail_node_add_nat $ROUTER $ROUTER_ADDR 24
44
45 for M in $(seq $LOCAL_M); do
46 NODE=$(netjail_print_name "N" $N $M)
47
48 netjail_node_add_default $NODE $ROUTER_ADDR
49 done
50done
51
52
diff --git a/src/testbed/netjail_stop.sh b/src/testbed/netjail_stop.sh
deleted file mode 100755
index 689bf7ae9..000000000
--- a/src/testbed/netjail_stop.sh
+++ /dev/null
@@ -1,26 +0,0 @@
1#!/bin/sh
2. "./../testbed/netjail_core.sh"
3
4set -eu
5set -x
6
7export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
8
9LOCAL_M=$1
10GLOBAL_N=$2
11NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M)
12
13shift 2
14
15for N in $(seq $GLOBAL_N); do
16 for M in $(seq $LOCAL_M); do
17 netjail_node_clear $(netjail_print_name "N" $N $M)
18 done
19
20 netjail_bridge_clear $(netjail_print_name "r" $N)
21 netjail_node_clear $(netjail_print_name "R" $N)
22done
23
24netjail_bridge_clear $NETWORK_NET
25
26echo "Done"
diff --git a/src/testbed/plugin_testcmd.c b/src/testbed/plugin_testcmd.c
deleted file mode 100644
index 797826781..000000000
--- a/src/testbed/plugin_testcmd.c
+++ /dev/null
@@ -1,115 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_testcmd.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testbed_ng_service.h"
30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
36unsigned int are_all_peers_started;
37
38static void
39all_peers_started ()
40{
41 are_all_peers_started = GNUNET_YES;
42 LOG (GNUNET_ERROR_TYPE_ERROR,
43 "setting are_all_peers_started: %d\n",
44 are_all_peers_started);
45}
46
47static void
48start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip,
49 char *node_ip,
50 char *n,
51 char *m)
52{
53 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
54
55 LOG (GNUNET_ERROR_TYPE_ERROR,
56 "We got here 6!\n");
57
58 are_all_peers_started = GNUNET_NO;
59
60 struct GNUNET_TESTING_Command commands[] = {
61 GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
62 &now),
63 GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
64 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1",
65 write_message),
66 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
67 &are_all_peers_started),
68 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1",
69 write_message)
70 };
71
72 GNUNET_TESTING_run (NULL,
73 commands,
74 GNUNET_TIME_UNIT_FOREVER_REL);
75 LOG (GNUNET_ERROR_TYPE_ERROR,
76 "We got here 7!\n");
77
78}
79
80
81/**
82 * Entry point for the plugin.
83 *
84 * @param cls NULL
85 * @return the exported block API
86 */
87void *
88libgnunet_plugin_testcmd_init (void *cls)
89{
90 struct GNUNET_TESTING_PluginFunctions *api;
91
92 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
93 api->start_testcase = &start_testcase;
94 api->all_peers_started = &all_peers_started;
95 return api;
96}
97
98
99/**
100 * Exit point from the plugin.
101 *
102 * @param cls the return value from #libgnunet_plugin_block_test_init
103 * @return NULL
104 */
105void *
106libgnunet_plugin_testcmd_done (void *cls)
107{
108 struct GNUNET_TESTING_PluginFunctions *api = cls;
109
110 GNUNET_free (api);
111 return NULL;
112}
113
114
115/* end of plugin_testcmd.c */
diff --git a/src/testbed/test_testbed_api_cmd_netjail.c b/src/testbed/test_testbed_api_cmd_netjail.c
deleted file mode 100644
index 8bb9e40e8..000000000
--- a/src/testbed/test_testbed_api_cmd_netjail.c
+++ /dev/null
@@ -1,80 +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/test_testbed_api_cmd_netjail.c
23 * @brief Test case executing a script in a network name space.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testbed_ng_service.h"
29#include "gnunet_util_lib.h"
30
31
32/**
33 * Main function to run the test cases.
34 *
35 * @param cls not used.
36 *
37 */
38static void
39run (void *cls)
40{
41 struct GNUNET_TESTING_Command commands[] = {
42 GNUNET_TESTBED_cmd_netjail_start ("netjail-start-1",
43 "2",
44 "2"),
45 GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-start-testbed-1",
46 "2",
47 "2",
48 "libgnunet_plugin_testcmd"),
49 GNUNET_TESTBED_cmd_stop_testbed ("stop-testbed",
50 "netjail-start-testbed-1",
51 "2",
52 "2"),
53 GNUNET_TESTBED_cmd_netjail_stop ("netjail-stop-1",
54 "2",
55 "2"),
56 GNUNET_TESTING_cmd_end ()
57 };
58
59 GNUNET_TESTING_run (NULL,
60 commands,
61 GNUNET_TIME_UNIT_FOREVER_REL);
62}
63
64
65int
66main (int argc,
67 char *const *argv)
68{
69 int rv = 0;
70
71 GNUNET_log_setup ("test-netjail",
72 "DEBUG",
73 NULL);
74 GNUNET_SCHEDULER_run (&run,
75 NULL);
76
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
78 "Test finished!\n");
79 return rv;
80}
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index 9a54ca36c..d4ef832ad 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -37,11 +37,6 @@
37 */ 37 */
38#define HELPER_TESTBED_BINARY "gnunet-helper-testbed" 38#define HELPER_TESTBED_BINARY "gnunet-helper-testbed"
39 39
40/**
41 * Cmds Helper binary name
42 */
43#define HELPER_CMDS_BINARY "gnunet-cmds-helper"
44
45 40
46/** 41/**
47 * Enumeration of operations 42 * Enumeration of operations
@@ -185,6 +180,7 @@ struct OperationContext
185typedef void 180typedef void
186(*TESTBED_opcq_empty_cb) (void *cls); 181(*TESTBED_opcq_empty_cb) (void *cls);
187 182
183
188/** 184/**
189 * Handle to interact with a GNUnet testbed controller. Each 185 * Handle to interact with a GNUnet testbed controller. Each
190 * controller has at least one master handle which is created when the 186 * controller has at least one master handle which is created when the
diff --git a/src/testbed/testbed_api_cmd_block_until_all_peers_started.c b/src/testbed/testbed_api_cmd_block_until_all_peers_started.c
deleted file mode 100644
index 8659fbb46..000000000
--- a/src/testbed/testbed_api_cmd_block_until_all_peers_started.c
+++ /dev/null
@@ -1,128 +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_block_until_all_peers_started.c
23 * @brief cmd to block the interpreter loop until all peers started.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30/**
31 * Generic logging shortcut
32 */
33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
34
35struct BlockState
36{
37 unsigned int *all_peers_started;
38};
39
40
41static int
42block_until_all_peers_started_traits (void *cls,
43 const void **ret,
44 const char *trait,
45 unsigned int index)
46{
47 return GNUNET_OK;
48}
49
50
51static void
52block_until_all_peers_started_cleanup (void *cls,
53 const struct GNUNET_TESTING_Command *cmd)
54{
55 struct BlockState *bs = cls;
56
57 GNUNET_free (bs);
58}
59
60
61static void
62block_until_all_peers_started_run (void *cls,
63 const struct GNUNET_TESTING_Command *cmd,
64 struct GNUNET_TESTING_Interpreter *is)
65{
66 LOG (GNUNET_ERROR_TYPE_ERROR,
67 "block_until_all_peers_started_run!\n");
68}
69
70
71static int
72block_until_all_peers_started_finish (void *cls,
73 GNUNET_SCHEDULER_TaskCallback cont,
74 void *cont_cls)
75{
76 struct BlockState *bs = cls;
77 unsigned int *ret = bs->all_peers_started;
78
79 LOG (GNUNET_ERROR_TYPE_ERROR,
80 "We got here 10\n");
81
82 if (GNUNET_YES == *ret)
83 {
84 LOG (GNUNET_ERROR_TYPE_ERROR,
85 "We do not need to block anymore!\n");
86 cont (cont_cls);
87 }
88 else
89 {
90 LOG (GNUNET_ERROR_TYPE_ERROR,
91 "You shall not pass!\n");
92 }
93
94 return *ret;
95}
96
97
98/**
99 * Create command.
100 *
101 * @param label name for command.
102 * @return command.
103 */
104struct GNUNET_TESTING_Command
105GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
106 unsigned int *
107 all_peers_started)
108{
109 struct BlockState *bs;
110
111 LOG (GNUNET_ERROR_TYPE_ERROR,
112 "we have all_peers_started: %u\n",
113 *all_peers_started);
114
115 bs = GNUNET_new (struct BlockState);
116 bs->all_peers_started = all_peers_started;
117
118 struct GNUNET_TESTING_Command cmd = {
119 .cls = bs,
120 .label = label,
121 .run = &block_until_all_peers_started_run,
122 .finish = &block_until_all_peers_started_finish,
123 .cleanup = &block_until_all_peers_started_cleanup,
124 .traits = &block_until_all_peers_started_traits
125 };
126
127 return cmd;
128}
diff --git a/src/testbed/testbed_api_cmd_controller.c b/src/testbed/testbed_api_cmd_controller.c
deleted file mode 100644
index 794b1ccf3..000000000
--- a/src/testbed/testbed_api_cmd_controller.c
+++ /dev/null
@@ -1,203 +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/testbed_api_cmd_controller.c
23 * @brief Command to create a controller.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet-service-testbed.h"
30#include "testbed_api_hosts.h"
31#include "gnunet_testbed_ng_service.h"
32
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) \
38 GNUNET_log (kind, __VA_ARGS__)
39
40
41/**
42*
43*
44* @param cls closure
45* @param cmd current CMD being cleaned up.
46*/
47static void
48controller_cleanup (void *cls,
49 const struct GNUNET_TESTING_Command *cmd)
50{
51 (void) cls;
52}
53
54
55/**
56 * Signature of the event handler function called by the
57 * respective event controller.
58 *
59 * @param cls closure
60 * @param event information about the event
61 */
62static void
63controller_cb (void *cls,
64 const struct GNUNET_TESTBED_EventInformation *event)
65{
66 struct ControllerState *cs = cls;
67
68 if (NULL != event->details.operation_finished.emsg)
69 {
70 LOG (GNUNET_ERROR_TYPE_ERROR, "There was an operation error: %s\n",
71 event->details.operation_finished.emsg);
72 GNUNET_TESTBED_shutdown_controller (cs);
73 }
74 else if (NULL == event->details.operation_finished.generic)
75 {
76 GNUNET_TESTBED_operation_done (event->op);
77 }
78}
79
80
81static void
82controller_run (void *cls,
83 const struct GNUNET_TESTING_Command *cmd,
84 struct GNUNET_TESTING_Interpreter *is)
85{
86 struct ControllerState *cs = cls;
87
88 cs->is = is;
89
90 cs->controller =
91 GNUNET_TESTBED_controller_connect (cs->host, cs->event_mask, &controller_cb,
92 cs);
93
94
95}
96
97/**
98*
99*
100* @param cls closure.
101* @param[out] ret result
102* @param trait name of the trait.
103* @param index index number of the object to offer.
104* @return #GNUNET_OK on success.
105*/
106static int
107controller_traits (void *cls,
108 const void **ret,
109 const char *trait,
110 unsigned int index)
111{
112 (void) cls;
113
114 struct ControllerState *cs = cls;
115
116
117 struct GNUNET_TESTING_Trait traits[] = {
118 {
119 .index = 0,
120 .trait_name = "controller",
121 .ptr = (const void *) cs->controller,
122 },
123 GNUNET_TESTING_trait_end ()
124 };
125
126 return GNUNET_TESTING_get_trait (traits,
127 ret,
128 trait,
129 index);
130 return GNUNET_OK;
131}
132
133
134/**
135 * Offer data from trait
136 *
137 * @param cmd command to extract the controller from.
138 * @param pt pointer to controller.
139 * @return #GNUNET_OK on success.
140 */
141int
142GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd,
143 struct GNUNET_TESTBED_Controller **
144 controller)
145{
146 return cmd->traits (cmd->cls,
147 (const void **) controller,
148 "controller",
149 (unsigned int) 0);
150}
151
152
153/**
154 * Shutdown nicely
155 *
156 * @param cs controller state.
157 */
158void
159GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs)
160{
161 LOG (GNUNET_ERROR_TYPE_DEBUG,
162 "Shutting down...\n");
163
164 cs->controller_going_down = GNUNET_YES;
165
166 if (NULL != cs->abort_task)
167 GNUNET_SCHEDULER_cancel (cs->abort_task);
168 if (NULL != cs->reg_handle)
169 GNUNET_TESTBED_cancel_registration (cs->reg_handle);
170 if (NULL != cs->controller)
171 GNUNET_TESTBED_controller_disconnect (cs->controller);
172 if (NULL != cs->cfg)
173 GNUNET_CONFIGURATION_destroy (cs->cfg);
174 if (NULL != cs->cp)
175 GNUNET_TESTBED_controller_stop (cs->cp);
176 if (NULL != cs->host)
177 GNUNET_TESTBED_host_destroy (cs->host);
178}
179
180
181
182struct GNUNET_TESTING_Command
183GNUNET_TESTBED_cmd_controller (const char *label,
184 const char *host,
185 uint64_t event_mask)
186{
187 struct ControllerState *cs;
188
189 cs = GNUNET_new (struct ControllerState);
190 cs->event_mask = event_mask;
191 cs->hostname = host;
192
193
194 struct GNUNET_TESTING_Command cmd = {
195 .cls = cs,
196 .label = label,
197 .run = &controller_run,
198 .cleanup = &controller_cleanup,
199 .traits = &controller_traits
200 };
201
202 return cmd;
203}
diff --git a/src/testbed/testbed_api_cmd_local_test_finished.c b/src/testbed/testbed_api_cmd_local_test_finished.c
deleted file mode 100644
index 8829f1b9a..000000000
--- a/src/testbed/testbed_api_cmd_local_test_finished.c
+++ /dev/null
@@ -1,129 +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_block_until_all_peers_started.c
23 * @brief cmd to block the interpreter loop until all peers started.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "testbed_helper.h"
30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
36struct LocalFinishedState
37{
38 TESTBED_CMD_HELPER_write_cb write_message;
39
40 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
41};
42
43
44static int
45local_test_finished_traits (void *cls,
46 const void **ret,
47 const char *trait,
48 unsigned int index)
49{
50 return GNUNET_OK;
51}
52
53
54static void
55local_test_finished_cleanup (void *cls,
56 const struct GNUNET_TESTING_Command *cmd)
57{
58 struct LocalFinishedState *lfs = cls;
59
60 GNUNET_free (lfs->reply);
61 GNUNET_free (lfs);
62}
63
64
65static void
66local_test_finished_run (void *cls,
67 const struct GNUNET_TESTING_Command *cmd,
68 struct GNUNET_TESTING_Interpreter *is)
69{
70 struct LocalFinishedState *lfs = cls;
71
72 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
73 size_t msg_length;
74
75 LOG (GNUNET_ERROR_TYPE_ERROR,
76 "We got here 12!\n");
77
78 msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
79 reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
80 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
81 reply->header.size = htons ((uint16_t) msg_length);
82 lfs->reply = reply;
83 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
84
85 LOG (GNUNET_ERROR_TYPE_ERROR,
86 "We got here 13!\n");
87}
88
89
90static int
91local_test_finished_finish (void *cls,
92 GNUNET_SCHEDULER_TaskCallback cont,
93 void *cont_cls)
94{
95 // This will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
96 return GNUNET_YES;
97}
98
99
100/**
101 * Create command.
102 *
103 * @param label name for command.
104 * @return command.
105 */
106struct GNUNET_TESTING_Command
107GNUNET_TESTING_cmd_local_test_finished (const char *label,
108 TESTBED_CMD_HELPER_write_cb
109 write_message)
110{
111 struct LocalFinishedState *lfs;
112
113 LOG (GNUNET_ERROR_TYPE_ERROR,
114 "We got here 11!\n");
115
116 lfs = GNUNET_new (struct LocalFinishedState);
117 lfs->write_message = write_message;
118
119 struct GNUNET_TESTING_Command cmd = {
120 .cls = lfs,
121 .label = label,
122 .run = &local_test_finished_run,
123 .finish = &local_test_finished_finish,
124 .cleanup = &local_test_finished_cleanup,
125 .traits = &local_test_finished_traits
126 };
127
128 return cmd;
129}
diff --git a/src/testbed/testbed_api_cmd_netjail_start.c b/src/testbed/testbed_api_cmd_netjail_start.c
deleted file mode 100644
index bc035abe7..000000000
--- a/src/testbed/testbed_api_cmd_netjail_start.c
+++ /dev/null
@@ -1,199 +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/testing_api_cmd_hello_world.c
23 * @brief Command to start the netjail script.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testbed_ng_service.h"
30
31#define NETJAIL_START_SCRIPT "./../testbed/netjail_start.sh"
32
33struct NetJailState
34{
35 struct GNUNET_ChildWaitHandle *cwh;
36
37 char *local_m;
38
39 char *global_n;
40
41 /**
42 * The process id of the start script.
43 */
44 struct GNUNET_OS_Process *start_proc;
45
46 unsigned int finished;
47};
48
49
50/**
51*
52*
53* @param cls closure
54* @param cmd current CMD being cleaned up.
55*/
56static void
57netjail_start_cleanup (void *cls,
58 const struct GNUNET_TESTING_Command *cmd)
59{
60 struct NetJailState *ns = cls;
61
62 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
63 "netjail_start_cleanup!\n");
64
65 if (NULL != ns->cwh)
66 {
67 GNUNET_wait_child_cancel (ns->cwh);
68 ns->cwh = NULL;
69 }
70 if (NULL != ns->start_proc)
71 {
72 GNUNET_assert (0 ==
73 GNUNET_OS_process_kill (ns->start_proc,
74 SIGKILL));
75 GNUNET_assert (GNUNET_OK ==
76 GNUNET_OS_process_wait (ns->start_proc));
77 GNUNET_OS_process_destroy (ns->start_proc);
78 ns->start_proc = NULL;
79 }
80 GNUNET_free (ns);
81}
82
83
84/**
85*
86*
87* @param cls closure.
88* @param[out] ret result
89* @param trait name of the trait.
90* @param index index number of the object to offer.
91* @return #GNUNET_OK on success.
92*/
93static int
94netjail_start_traits (void *cls,
95 const void **ret,
96 const char *trait,
97 unsigned int index)
98{
99 return GNUNET_OK;
100}
101
102static void
103child_completed_callback (void *cls,
104 enum GNUNET_OS_ProcessStatusType type,
105 long unsigned int exit_code)
106{
107 struct NetJailState *ns = cls;
108
109 if (0 == exit_code)
110 {
111 ns->finished = GNUNET_YES;
112 }
113 else
114 {
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 "Child completed with an error!\n");
117 ns->finished = GNUNET_SYSERR;
118 }
119 GNUNET_OS_process_destroy (ns->start_proc);
120 ns->start_proc = NULL;
121}
122
123
124
125/**
126* Run the "hello world" CMD.
127*
128* @param cls closure.
129* @param cmd CMD being run.
130* @param is interpreter state.
131*/
132static void
133netjail_start_run (void *cls,
134 const struct GNUNET_TESTING_Command *cmd,
135 struct GNUNET_TESTING_Interpreter *is)
136{
137 struct NetJailState *ns = cls;
138 char *const script_argv[] = {NETJAIL_START_SCRIPT,
139 ns->local_m,
140 ns->global_n,
141 NULL};
142
143 ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
144 NULL,
145 NULL,
146 NULL,
147 NETJAIL_START_SCRIPT,
148 script_argv);
149
150 ns->cwh = GNUNET_wait_child (ns->start_proc,
151 &child_completed_callback,
152 ns);
153 GNUNET_break (NULL != ns->cwh);
154}
155
156static int
157netjail_start_finish (void *cls,
158 GNUNET_SCHEDULER_TaskCallback cont,
159 void *cont_cls)
160{
161 struct NetJailState *ns = cls;
162
163 if (ns->finished)
164 {
165 cont (cont_cls);
166 }
167 return ns->finished;
168}
169
170/**
171 * Create command.
172 *
173 * @param label name for command.
174 * @param binaryname to start.
175 * @return command.
176 */
177struct GNUNET_TESTING_Command
178GNUNET_TESTBED_cmd_netjail_start (const char *label,
179 char *local_m,
180 char *global_n)
181{
182 struct NetJailState *ns;
183
184 ns = GNUNET_new (struct NetJailState);
185 ns->local_m = local_m;
186 ns->global_n = global_n;
187 ns->finished = GNUNET_NO;
188
189 struct GNUNET_TESTING_Command cmd = {
190 .cls = ns,
191 .label = label,
192 .run = &netjail_start_run,
193 .finish = &netjail_start_finish,
194 .cleanup = &netjail_start_cleanup,
195 .traits = &netjail_start_traits
196 };
197
198 return cmd;
199}
diff --git a/src/testbed/testbed_api_cmd_netjail_start_testbed.c b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
deleted file mode 100644
index 67f0ef55c..000000000
--- a/src/testbed/testbed_api_cmd_netjail_start_testbed.c
+++ /dev/null
@@ -1,532 +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/testing_api_cmd_hello_world.c
23 * @brief Command to start the netjail peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testbed_ng_service.h"
29#include "testbed_api.h"
30#include "testbed_api_hosts.h"
31#include "testbed_helper.h"
32
33#define NETJAIL_EXEC_SCRIPT "./../testbed/netjail_exec.sh"
34
35struct HelperMessage;
36
37struct HelperMessage
38{
39
40 struct HelperMessage *next;
41
42 struct HelperMessage *prev;
43
44 /**
45 * Size of the original message.
46 */
47 uint16_t bytes_msg;
48
49 /* Followed by @e bytes_msg of msg.*/
50};
51
52
53
54struct NetJailState
55{
56
57 struct HelperMessage *hp_messages_head;
58
59 struct HelperMessage *hp_messages_tail;
60
61 /**
62 * The process handle
63 */
64 struct GNUNET_HELPER_Handle **helper;
65
66 unsigned int n_helper;
67
68 char *binary_name;
69
70 char *local_m;
71
72 char *global_n;
73
74 /**
75 * The send handle for the helper
76 */
77 struct GNUNET_HELPER_SendHandle **shandle;
78
79 unsigned int n_shandle;
80
81 /**
82 * The message corresponding to send handle
83 */
84 struct GNUNET_MessageHeader **msg;
85
86 unsigned int n_msg;
87
88 unsigned int number_of_testbeds_started;
89
90 unsigned int number_of_peers_started;
91
92 unsigned int number_of_local_test_finished;
93
94 /**
95 * The host where the controller is running
96 */
97 struct GNUNET_TESTBED_Host **host;
98
99 unsigned int n_host;
100
101 char *plugin_name;
102};
103
104struct TestbedCount
105{
106 unsigned int count;
107
108 struct NetJailState *ns;
109};
110
111/**
112*
113*
114* @param cls closure
115* @param cmd current CMD being cleaned up.
116*/
117static void
118netjail_exec_cleanup (void *cls,
119 const struct GNUNET_TESTING_Command *cmd)
120{
121 struct NetJailState *ns = cls;
122
123 GNUNET_free (ns->binary_name);
124}
125
126
127/**
128*
129*
130* @param cls closure.
131* @param[out] ret result
132* @param trait name of the trait.
133* @param index index number of the object to offer.
134* @return #GNUNET_OK on success.
135*/
136static int
137netjail_exec_traits (void *cls,
138 const void **ret,
139 const char *trait,
140 unsigned int index)
141{
142 struct NetJailState *ns = cls;
143 struct GNUNET_HELPER_Handle **helper = ns->helper;
144 struct HelperMessage *hp_messages_head = ns->hp_messages_head;
145
146
147 struct GNUNET_TESTING_Trait traits[] = {
148 {
149 .index = 0,
150 .trait_name = "helper_handles",
151 .ptr = (const void *) helper,
152 },
153 {
154 .index = 1,
155 .trait_name = "hp_msgs_head",
156 .ptr = (const void *) hp_messages_head,
157 },
158 GNUNET_TESTING_trait_end ()
159 };
160
161 return GNUNET_TESTING_get_trait (traits,
162 ret,
163 trait,
164 index);
165}
166
167
168/**
169 * Offer handles to testbed helper from trait
170 *
171 * @param cmd command to extract the message from.
172 * @param pt pointer to message.
173 * @return #GNUNET_OK on success.
174 */
175int
176GNUNET_TESTBED_get_trait_helper_handles (const struct
177 GNUNET_TESTING_Command *cmd,
178 struct GNUNET_HELPER_Handle ***helper)
179{
180 return cmd->traits (cmd->cls,
181 (const void **) helper,
182 "helper_handles",
183 (unsigned int) 0);
184}
185
186/**
187 * Offer handles to testbed helper from trait
188 *
189 * @param cmd command to extract the message from.
190 * @param pt pointer to message.
191 * @return #GNUNET_OK on success.
192 */
193int
194GNUNET_TESTBED_get_trait_helper_messages (const struct
195 GNUNET_TESTING_Command *cmd,
196 struct HelperMessage ***
197 hp_messages_head)
198{
199 return cmd->traits (cmd->cls,
200 (const void **) hp_messages_head,
201 "hp_msgs_head",
202 (unsigned int) 1);
203}
204
205
206/**
207 * Continuation function from GNUNET_HELPER_send()
208 *
209 * @param cls closure
210 * @param result GNUNET_OK on success,
211 * GNUNET_NO if helper process died
212 * GNUNET_SYSERR during GNUNET_HELPER_stop
213 */
214static void
215clear_msg (void *cls, int result)
216{
217 struct TestbedCount *tbc = cls;
218 struct NetJailState *ns = tbc->ns;
219
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
221 "clear_msg tbc->count: %d\n",
222 tbc->count);
223 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
224 ns->shandle[tbc->count - 1] = NULL;
225 GNUNET_free (ns->msg[tbc->count - 1]);
226 ns->msg[tbc->count - 1] = NULL;
227}
228
229
230/**
231 * Functions with this signature are called whenever a
232 * complete message is received by the tokenizer.
233 *
234 * Do not call GNUNET_SERVER_mst_destroy in callback
235 *
236 * @param cls closure
237 * @param client identification of the client
238 * @param message the actual message
239 *
240 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
241 */
242static int
243helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
244{
245 struct TestbedCount *tbc = cls;
246 struct NetJailState *ns = tbc->ns;
247 struct HelperMessage *hp_msg;
248
249 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
250 {
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "helper_mst tbc->count: %d\n",
253 tbc->count);
254 // GNUNET_TESTBED_extract_cfg (host, message);
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
256 "Received message from helper.\n");
257 ns->number_of_testbeds_started++;
258 }
259 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
260 message->type))
261 {
262 ns->number_of_peers_started++;
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "number_of_peers_started: %d\n",
265 ns->number_of_peers_started);
266 }
267 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
268 message->type))
269 {
270 ns->number_of_local_test_finished++;
271 }
272 else
273 {
274 hp_msg = GNUNET_new (struct HelperMessage);
275 hp_msg->bytes_msg = message->size;
276 memcpy (&hp_msg[1], message, message->size);
277 GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail,
278 hp_msg);
279 }
280
281 return GNUNET_OK;
282}
283
284
285static void
286exp_cb (void *cls)
287{
288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
289 GNUNET_TESTING_interpreter_fail ();
290}
291
292
293static struct GNUNET_CMDS_HelperInit *
294create_helper_init_msg_ (char *m_char,
295 char *n_char,
296 const char *plugin_name)
297{
298 struct GNUNET_CMDS_HelperInit *msg;
299 uint16_t plugin_name_len;
300 uint16_t msg_size;
301
302 GNUNET_assert (NULL != plugin_name);
303 plugin_name_len = strlen (plugin_name);
304 msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
306 "msg_size: %d \n",
307 msg_size);
308 msg = GNUNET_malloc (msg_size);
309 msg->header.size = htons (msg_size);
310 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
311 msg->plugin_name_size = htons (plugin_name_len);
312 GNUNET_memcpy ((char *) &msg[1],
313 plugin_name,
314 plugin_name_len);
315 return msg;
316}
317
318
319static void
320start_testbed (struct NetJailState *ns, struct
321 GNUNET_CONFIGURATION_Handle *config,
322 char *m_char,
323 char *n_char)
324{
325 // struct GNUNET_CONFIGURATION_Handle *cfg;
326 struct GNUNET_CMDS_HelperInit *msg;
327 struct TestbedCount *tbc;
328 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
329 m_char,
330 n_char,
331 GNUNET_OS_get_libexec_binary_path (
332 HELPER_CMDS_BINARY),
333 ns->global_n,
334 ns->local_m,
335 NULL};
336 unsigned int m = atoi (m_char);
337 unsigned int n = atoi (n_char);
338
339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
340 "m: %d n: %d\n",
341 m,
342 n);
343
344 tbc = GNUNET_new (struct TestbedCount);
345 tbc->ns = ns;
346 tbc->count = (n - 1) * atoi (ns->local_m) + m;
347
348 // cfg = GNUNET_CONFIGURATION_dup (config);
349
350 // TODO We do not need this?
351 /*GNUNET_array_append (ns->host, ns->n_host,
352 GNUNET_TESTBED_host_create_with_id (tbc->count - 1,
353 NULL,
354 NULL,
355 cfg,
356 0));*/
357
358 /*if ((GNUNET_YES != GNUNET_DISK_file_test ("test_testbed_api.conf")) ||
359 (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (config,
360 "test_testbed_api.conf")))
361 {
362 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
363 _ (
364 "Unreadable or malformed configuration file `%s', exit ...\n"),
365 "test_testbed_api.conf");
366 }*/
367
368 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
369 GNUNET_YES,
370 NETJAIL_EXEC_SCRIPT,
371 script_argv,
372 &helper_mst,
373 &exp_cb,
374 tbc));
375
376 struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1];
377
378 msg = create_helper_init_msg_ (m_char,
379 n_char,
380 ns->plugin_name);
381 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
382
383 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
384 helper,
385 &msg->header,
386 GNUNET_NO,
387 &clear_msg,
388 tbc));
389
390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
391 "Message %d send!\n",
392 tbc->count);
393
394 if (NULL == ns->shandle[tbc->count - 1])
395 {
396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
397 "Send handle is NULL!\n");
398 GNUNET_free (msg);
399 GNUNET_TESTING_interpreter_fail ();
400 }
401}
402
403
404/**
405* Run the "hello world" CMD.
406*
407* @param cls closure.
408* @param cmd CMD being run.
409* @param is interpreter state.
410*/
411static void
412netjail_exec_run (void *cls,
413 const struct GNUNET_TESTING_Command *cmd,
414 struct GNUNET_TESTING_Interpreter *is)
415{
416 char str_m[12];
417 char str_n[12];
418 struct NetJailState *ns = cls;
419 struct GNUNET_CONFIGURATION_Handle *config =
420 GNUNET_CONFIGURATION_create ();
421
422 for (int i = 1; i <= atoi (ns->global_n); i++) {
423 for (int j = 1; j <= atoi (ns->local_m); j++)
424 {
425 sprintf (str_n, "%d", i);
426 sprintf (str_m, "%d", j);
427 start_testbed (ns, config,
428 str_m,
429 str_n);
430 }
431 }
432}
433
434
435static int
436netjail_start_finish (void *cls,
437 GNUNET_SCHEDULER_TaskCallback cont,
438 void *cont_cls)
439{
440 unsigned int ret = GNUNET_NO;
441 struct NetJailState *ns = cls;
442 unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n);
443 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
444 size_t msg_length;
445 struct GNUNET_HELPER_Handle *helper;
446 struct TestbedCount *tbc;
447
448 if (ns->number_of_local_test_finished == total_number)
449 {
450 ret = GNUNET_YES;
451 cont (cont_cls);
452 }
453
454 if (ns->number_of_testbeds_started == total_number)
455 {
456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
457 "All helpers started!\n");
458 ns->number_of_testbeds_started = 0;
459 }
460
461 if (ns->number_of_peers_started == total_number)
462 {
463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
464 "All peers started!\n");
465
466 for (int i = 1; i <= atoi (ns->global_n); i++) {
467 for (int j = 1; j <= atoi (ns->local_m); j++)
468 {
469 tbc = GNUNET_new (struct TestbedCount);
470 tbc->ns = ns;
471 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
472 tbc->count = (j - 1) * atoi (ns->local_m) + i + total_number;
473 helper = ns->helper[tbc->count - 1 - total_number];
474 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
475 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
476 reply->header.type = htons (
477 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
478 reply->header.size = htons ((uint16_t) msg_length);
479
480 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
481
482 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
483 helper,
484 &reply->header,
485 GNUNET_NO,
486 &clear_msg,
487 tbc);
488
489 GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
490
491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
492 "All peers started message %d send!\n",
493 tbc->count);
494 }
495 }
496 ns->number_of_peers_started = 0;
497 }
498 return ret;
499}
500
501
502/**
503 * Create command.
504 *
505 * @param label name for command.
506 * @param binaryname to exec.
507 * @return command.
508 */
509struct GNUNET_TESTING_Command
510GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label,
511 char *local_m,
512 char *global_n,
513 char *plugin_name)
514{
515 struct NetJailState *ns;
516
517 ns = GNUNET_new (struct NetJailState);
518 ns->local_m = local_m;
519 ns->global_n = global_n;
520 ns->plugin_name = plugin_name;
521
522 struct GNUNET_TESTING_Command cmd = {
523 .cls = ns,
524 .label = label,
525 .run = &netjail_exec_run,
526 .finish = &netjail_start_finish,
527 .cleanup = &netjail_exec_cleanup,
528 .traits = &netjail_exec_traits
529 };
530
531 return cmd;
532}
diff --git a/src/testbed/testbed_api_cmd_netjail_stop.c b/src/testbed/testbed_api_cmd_netjail_stop.c
deleted file mode 100644
index c0fc33ff9..000000000
--- a/src/testbed/testbed_api_cmd_netjail_stop.c
+++ /dev/null
@@ -1,197 +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/testing_api_cmd_hello_world.c
23 * @brief Command to stop the netjail script.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testbed_ng_service.h"
30
31
32#define NETJAIL_STOP_SCRIPT "./../testbed/netjail_stop.sh"
33
34struct GNUNET_ChildWaitHandle *cwh;
35
36struct NetJailState
37{
38 char *local_m;
39
40 char *global_n;
41
42 /**
43 * The process id of the start script.
44 */
45 struct GNUNET_OS_Process *stop_proc;
46
47 unsigned int finished;
48};
49
50
51/**
52*
53*
54* @param cls closure
55* @param cmd current CMD being cleaned up.
56*/
57static void
58netjail_stop_cleanup (void *cls,
59 const struct GNUNET_TESTING_Command *cmd)
60{
61 struct NetJailState *ns = cls;
62
63 if (NULL != cwh)
64 {
65 GNUNET_wait_child_cancel (cwh);
66 cwh = NULL;
67 }
68 if (NULL != ns->stop_proc)
69 {
70 GNUNET_assert (0 ==
71 GNUNET_OS_process_kill (ns->stop_proc,
72 SIGKILL));
73 GNUNET_assert (GNUNET_OK ==
74 GNUNET_OS_process_wait (ns->stop_proc));
75 GNUNET_OS_process_destroy (ns->stop_proc);
76 ns->stop_proc = NULL;
77 }
78}
79
80
81/**
82*
83*
84* @param cls closure.
85* @param[out] ret result
86* @param trait name of the trait.
87* @param index index number of the object to offer.
88* @return #GNUNET_OK on success.
89*/
90static int
91netjail_stop_traits (void *cls,
92 const void **ret,
93 const char *trait,
94 unsigned int index)
95{
96 return GNUNET_OK;
97}
98
99
100static void
101child_completed_callback (void *cls,
102 enum GNUNET_OS_ProcessStatusType type,
103 long unsigned int exit_code)
104{
105 struct NetJailState *ns = cls;
106
107 cwh = NULL;
108 if (0 == exit_code)
109 {
110 ns->finished = GNUNET_YES;
111 }
112 else
113 {
114 ns->finished = GNUNET_SYSERR;
115 }
116 GNUNET_OS_process_destroy (ns->stop_proc);
117 ns->stop_proc = NULL;
118}
119
120
121/**
122* Run the "hello world" CMD.
123*
124* @param cls closure.
125* @param cmd CMD being run.
126* @param is interpreter state.
127*/
128static void
129netjail_stop_run (void *cls,
130 const struct GNUNET_TESTING_Command *cmd,
131 struct GNUNET_TESTING_Interpreter *is)
132{
133 struct NetJailState *ns = cls;
134 char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
135 ns->local_m,
136 ns->global_n,
137 NULL};
138
139 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
140 NULL,
141 NULL,
142 NULL,
143 NETJAIL_STOP_SCRIPT,
144 script_argv);
145
146 cwh = GNUNET_wait_child (ns->stop_proc,
147 &child_completed_callback,
148 ns);
149 GNUNET_break (NULL != cwh);
150
151}
152
153
154static int
155netjail_stop_finish (void *cls,
156 GNUNET_SCHEDULER_TaskCallback cont,
157 void *cont_cls)
158{
159 struct NetJailState *ns = cls;
160
161 if (ns->finished)
162 {
163 cont (cont_cls);
164 }
165 return ns->finished;
166}
167
168
169/**
170 * Create command.
171 *
172 * @param label name for command.
173 * @param binaryname to stop.
174 * @return command.
175 */
176struct GNUNET_TESTING_Command
177GNUNET_TESTBED_cmd_netjail_stop (const char *label,
178 char *local_m,
179 char *global_n)
180{
181 struct NetJailState *ns;
182
183 ns = GNUNET_new (struct NetJailState);
184 ns->local_m = local_m;
185 ns->global_n = global_n;
186
187 struct GNUNET_TESTING_Command cmd = {
188 .cls = ns,
189 .label = label,
190 .run = &netjail_stop_run,
191 .finish = &netjail_stop_finish,
192 .cleanup = &netjail_stop_cleanup,
193 .traits = &netjail_stop_traits
194 };
195
196 return cmd;
197}
diff --git a/src/testbed/testbed_api_cmd_netjail_stop_testbed.c b/src/testbed/testbed_api_cmd_netjail_stop_testbed.c
deleted file mode 100644
index 9a9d489a7..000000000
--- a/src/testbed/testbed_api_cmd_netjail_stop_testbed.c
+++ /dev/null
@@ -1,143 +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/testing_api_cmd_hello_world.c
23 * @brief Command to start the netjail peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testbed_ng_service.h"
29#include "testbed_api.h"
30#include "testbed_api_hosts.h"
31
32
33struct StopHelperState
34{
35
36 const char *helper_start_label;
37
38 /**
39 * The process handle
40 */
41 struct GNUNET_HELPER_Handle **helper;
42
43 char *local_m;
44
45 char *global_n;
46};
47
48
49/**
50*
51*
52* @param cls closure
53* @param cmd current CMD being cleaned up.
54*/
55static void
56stop_testbed_cleanup (void *cls,
57 const struct GNUNET_TESTING_Command *cmd)
58{
59
60}
61
62
63/**
64*
65*
66* @param cls closure.
67* @param[out] ret result
68* @param trait name of the trait.
69* @param index index number of the object to offer.
70* @return #GNUNET_OK on success.
71*/
72static int
73stop_testbed_traits (void *cls,
74 const void **ret,
75 const char *trait,
76 unsigned int index)
77{
78 return GNUNET_OK;
79}
80
81
82/**
83* Run the "hello world" CMD.
84*
85* @param cls closure.
86* @param cmd CMD being run.
87* @param is interpreter state.
88*/
89static void
90stop_testbed_run (void *cls,
91 const struct GNUNET_TESTING_Command *cmd,
92 struct GNUNET_TESTING_Interpreter *is)
93{
94 struct StopHelperState *shs = cls;
95 struct GNUNET_HELPER_Handle **helper;
96 const struct GNUNET_TESTING_Command *start_helper_cmd;
97
98 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (
99 shs->helper_start_label);
100 GNUNET_TESTBED_get_trait_helper_handles (start_helper_cmd,
101 &helper);
102
103 for (int i = 1; i <= atoi (shs->global_n); i++) {
104 for (int j = 1; j <= atoi (shs->local_m); j++)
105 {
106 GNUNET_HELPER_stop (helper[(i - 1) * atoi (shs->local_m) + j - 1],
107 GNUNET_YES);
108 }
109 }
110}
111
112
113/**
114 * Create command.
115 *
116 * @param label name for command.
117 * @param binaryname to exec.
118 * @return command.
119 */
120struct GNUNET_TESTING_Command
121GNUNET_TESTBED_cmd_stop_testbed (const char *label,
122 const char *helper_start_label,
123 char *local_m,
124 char *global_n
125 )
126{
127 struct StopHelperState *shs;
128
129 shs = GNUNET_new (struct StopHelperState);
130 shs->helper_start_label = helper_start_label;
131 shs->local_m = local_m;
132 shs->global_n = global_n;
133
134 struct GNUNET_TESTING_Command cmd = {
135 .cls = shs,
136 .label = label,
137 .run = &stop_testbed_run,
138 .cleanup = &stop_testbed_cleanup,
139 .traits = &stop_testbed_traits
140 };
141
142 return cmd;
143}
diff --git a/src/testbed/testbed_api_cmd_peer.c b/src/testbed/testbed_api_cmd_peer.c
deleted file mode 100644
index 2e253e408..000000000
--- a/src/testbed/testbed_api_cmd_peer.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/**
23 * @file testbed/testbed_api_cmd_peer.c
24 * @brief Command to create a peer.
25 * @author t3sserakt
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_testbed_ng_service.h"
31#include "gnunet-service-testbed.h"
32#include "testbed_api_peers.h"
33
34
35/**
36 * Generic logging shortcut
37 */
38#define LOG(kind, ...) \
39 GNUNET_log (kind, __VA_ARGS__)
40
41
42/**
43*
44*
45* @param cls closure.
46* @param[out] ret result
47* @param trait name of the trait.
48* @param index index number of the object to offer.
49* @return #GNUNET_OK on success.
50*/
51static int
52peer_traits (void *cls,
53 const void **ret,
54 const char *trait,
55 unsigned int index)
56{
57 struct PeerCmdState *ps = cls;
58
59 struct GNUNET_TESTING_Trait traits[] = {
60 {
61 .index = 0,
62 .trait_name = "peer",
63 .ptr = (const void *) ps->peer,
64 },
65 GNUNET_TESTING_trait_end ()
66 };
67
68 return GNUNET_TESTING_get_trait (traits,
69 ret,
70 trait,
71 index);
72
73 return GNUNET_OK;
74}
75
76/**
77 * Offer data from trait
78 *
79 * @param cmd command to extract the controller from.
80 * @param peer pointer GNUNET_TESTBED_PEER
81 * @return #GNUNET_OK on success.
82 */
83int
84GNUNET_TESTBED_get_trait_peer (const struct GNUNET_TESTING_Command *cmd,
85 struct GNUNET_TESTBED_Peer **
86 peer)
87{
88 return cmd->traits (cmd->cls,
89 (const void **) peer,
90 "peer",
91 (unsigned int) 0);
92}
93
94
95/**
96*
97*
98* @param cls closure
99* @param cmd current CMD being cleaned up.
100*/
101static void
102peer_cleanup (void *cls,
103 const struct GNUNET_TESTING_Command *cmd)
104{
105 (void) cls;
106}
107
108
109/**
110 * abort task to run on test timed out
111 *
112 * @param cls NULL
113 * @param tc the task context
114 */
115static void
116do_abort (void *cls)
117{
118 struct PeerCmdState *ps = cls;
119
120 if (GNUNET_NO == ps->peer_ready)
121 {
122 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
123 ps->abort_task = NULL;
124 GNUNET_TESTBED_shutdown_peer (ps);
125 }
126}
127
128
129/**
130 * Functions of this signature are called when a peer has been successfully
131 * created
132 *
133 * @param cls the closure from GNUNET_TESTBED_peer_create()
134 * @param emsg MAY contain an error description, if starting peer failed.
135 */
136static void
137peer_started_cb (void *cls,
138 const char *emsg)
139{
140 struct PeerCmdState *ps = cls;
141
142 GNUNET_TESTBED_operation_done (ps->operation);
143 if (NULL == emsg)
144 {
145 ps->peer_ready = GNUNET_YES;
146 }
147 else
148 {
149 LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error starting a peer: %s\n",
150 emsg);
151 }
152
153}
154
155
156/**
157 * Functions of this signature are called when a peer has been successfully
158 * created
159 *
160 * @param cls the closure from GNUNET_TESTBED_peer_create()
161 * @param peer the handle for the created peer; NULL on any error during
162 * creation
163 * @param emsg NULL if peer is not NULL; else MAY contain the error description
164 */
165static void
166peer_create_cb (void *cls,
167 struct GNUNET_TESTBED_Peer *peer,
168 const char *emsg)
169{
170 struct PeerCmdState *ps = cls;
171
172 ps->peer = peer;
173 GNUNET_TESTBED_operation_done (ps->operation);
174 ps->operation = GNUNET_TESTBED_peer_start (NULL,
175 peer,
176 &peer_started_cb,
177 ps);
178}
179
180
181static void
182peer_run (void *cls,
183 const struct GNUNET_TESTING_Command *cmd,
184 struct GNUNET_TESTING_Interpreter *is)
185{
186 struct PeerCmdState *ps = cls;
187 const struct GNUNET_TESTING_Command *controller_cmd;
188 struct GNUNET_TESTBED_Controller *controller;
189
190 ps->is = is;
191 controller_cmd = GNUNET_TESTING_interpreter_lookup_command (
192 ps->controller_label);
193 GNUNET_TESTBED_get_trait_controller (controller_cmd,
194 &controller);
195 ps->host = GNUNET_TESTBED_host_create (ps->hostname, ps->username, ps->cfg,
196 ps->port);
197 ps->operation =
198 GNUNET_TESTBED_peer_create (controller,
199 ps->host,
200 ps->cfg,
201 &peer_create_cb,
202 ps);
203
204 ps->abort_task =
205 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
206 (GNUNET_TIME_UNIT_MINUTES, 5),
207 &do_abort,
208 ps);
209}
210
211
212void
213peer_stopped_cb (void *cls,
214 const char *emsg)
215{
216 struct PeerCmdState *ps = cls;
217
218 if (NULL != emsg)
219 {
220 LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error stopping a peer: %s\n",
221 emsg);
222 }
223 GNUNET_TESTBED_operation_done (ps->operation);
224 GNUNET_TESTBED_peer_destroy (ps->peer);
225}
226
227
228/**
229 * Shutdown nicely
230 *
231 * @param cs controller state.
232 */
233void
234GNUNET_TESTBED_shutdown_peer (struct PeerCmdState *ps)
235{
236 LOG (GNUNET_ERROR_TYPE_DEBUG,
237 "Shutting down...\n");
238
239 ps->peer_going_down = GNUNET_YES;
240
241 if (NULL != ps->abort_task)
242 GNUNET_SCHEDULER_cancel (ps->abort_task);
243 if (NULL != ps->cfg)
244 GNUNET_CONFIGURATION_destroy (ps->cfg);
245 if (NULL != ps->host)
246 GNUNET_TESTBED_host_destroy (ps->host);
247
248 GNUNET_TESTBED_operation_done (ps->operation);
249 ps->operation = GNUNET_TESTBED_peer_stop (NULL, ps->peer, peer_stopped_cb,
250 ps);
251
252}
253
254
255struct GNUNET_TESTING_Command
256GNUNET_TESTBED_cmd_peer (const char *label,
257 const char *controller_label,
258 const char *hostname,
259 const char *username,
260 uint16_t port,
261 struct GNUNET_CONFIGURATION_Handle *cfg)
262{
263 struct PeerCmdState *ps;
264
265 ps = GNUNET_new (struct PeerCmdState);
266 ps->hostname = hostname;
267 ps->username = username;
268 ps->port = port;
269 ps->cfg = cfg;
270 ps->controller_label = controller_label;
271
272 struct GNUNET_TESTING_Command cmd = {
273 .cls = ps,
274 .label = label,
275 .run = &peer_run,
276 .cleanup = &peer_cleanup,
277 .traits = &peer_traits
278 };
279
280 return cmd;
281}
diff --git a/src/testbed/testbed_api_cmd_peer_store.c b/src/testbed/testbed_api_cmd_peer_store.c
deleted file mode 100644
index fc96f589c..000000000
--- a/src/testbed/testbed_api_cmd_peer_store.c
+++ /dev/null
@@ -1,60 +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/testbed_api_cmd_peer_store.c
23 * @brief Command to start the peer store service of a peer.
24 * @author t3sserakt
25 */
26
27
28static void
29service_run (void *cls,
30 const struct GNUNET_TESTING_Command *cmd,
31 struct GNUNET_TESTING_Interpreter *is)
32{
33 struct PeerStoreState *pss = cls;
34
35 pss->psh = GNUNET_PEERSTORE_connect (pss->cfg);
36 GNUNET_TESTING_interpreter_next (ps->is);
37}
38
39
40struct GNUNET_TESTING_Command
41GNUNET_TESTBED_cmd_peer_store (const char *label,
42 struct GNUNET_CONFIGURATION_Handle *cfg)
43{
44
45 struct PeerStoreState *pss;
46
47 pss = GNUNET_new (struct PeerStoreState);
48 pss->cfg = cfg;
49
50 struct GNUNET_TESTING_Command cmd = {
51 .cls = pss,
52 .label = label,
53 .run = &peer_store_run,
54 .cleanup = &peer_store_cleanup,
55 .traits = &peer_store_traits
56 };
57
58 return cmd;
59
60}
diff --git a/src/testbed/testbed_api_cmd_send_peer_ready.c b/src/testbed/testbed_api_cmd_send_peer_ready.c
deleted file mode 100644
index f175a3e18..000000000
--- a/src/testbed/testbed_api_cmd_send_peer_ready.c
+++ /dev/null
@@ -1,103 +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_send_peer_ready.c
23 * @brief cmd to send a helper message if peer is ready.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "testbed_helper.h"
30
31
32struct SendPeerReadyState
33{
34 TESTBED_CMD_HELPER_write_cb write_message;
35
36 struct GNUNET_CMDS_PEER_STARTED *reply;
37};
38
39
40static int
41send_peer_ready_traits (void *cls,
42 const void **ret,
43 const char *trait,
44 unsigned int index)
45{
46 return GNUNET_OK;
47}
48
49
50static void
51send_peer_ready_cleanup (void *cls,
52 const struct GNUNET_TESTING_Command *cmd)
53{
54 struct SendPeerReadyState *sprs = cls;
55
56 GNUNET_free (sprs->reply);
57 GNUNET_free (sprs);
58}
59
60
61static void
62send_peer_ready_run (void *cls,
63 const struct GNUNET_TESTING_Command *cmd,
64 struct GNUNET_TESTING_Interpreter *is)
65{
66 struct SendPeerReadyState *sprs = cls;
67 struct GNUNET_CMDS_PEER_STARTED *reply;
68 size_t msg_length;
69
70 msg_length = sizeof(struct GNUNET_CMDS_PEER_STARTED);
71 reply = GNUNET_new (struct GNUNET_CMDS_PEER_STARTED);
72 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED);
73 reply->header.size = htons ((uint16_t) msg_length);
74 sprs->reply = reply;
75 sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
76}
77
78
79/**
80 * Create command.
81 *
82 * @param label name for command.
83 * @return command.
84 */
85struct GNUNET_TESTING_Command
86GNUNET_TESTING_cmd_send_peer_ready (const char *label,
87 TESTBED_CMD_HELPER_write_cb write_message)
88{
89 struct SendPeerReadyState *sprs;
90
91 sprs = GNUNET_new (struct SendPeerReadyState);
92 sprs->write_message = write_message;
93
94 struct GNUNET_TESTING_Command cmd = {
95 .cls = sprs,
96 .label = label,
97 .run = &send_peer_ready_run,
98 .cleanup = &send_peer_ready_cleanup,
99 .traits = &send_peer_ready_traits
100 };
101
102 return cmd;
103}
diff --git a/src/testbed/testbed_api_cmd_tng_connect.c b/src/testbed/testbed_api_cmd_tng_connect.c
deleted file mode 100644
index e52cd3c76..000000000
--- a/src/testbed/testbed_api_cmd_tng_connect.c
+++ /dev/null
@@ -1,55 +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/**
23 * @file testbed/testbed_api_cmd_peer.c
24 * @brief Command to create a peer.
25 * @author t3sserakt
26 */
27
28
29static void
30tng_connect_run (void *cls,
31 const struct GNUNET_TESTING_Command *cmd,
32 struct GNUNET_TESTING_Interpreter *is)
33{
34 struct TngConnectState *tcs = cls;
35
36 tcs->ah = GNUNET_TRANSPORT_application_init (tcs->cfg);
37}
38
39struct GNUNET_TESTING_Command
40GNUNET_TESTBED_cmd_tng_connect (const char *label)
41{
42 struct TngConnectState *tcs;
43
44 ts = GNUNET_new (struct TngConnectState);
45
46 struct GNUNET_TESTING_Command cmd = {
47 .cls = tcs,
48 .label = label,
49 .run = &tng_connect_run,
50 .cleanup = &tmg_connect_cleanup,
51 .traits = &tng_connect_traits
52 };
53
54 return cmd;
55}
diff --git a/src/testbed/testbed_api_cmd_tng_service.c b/src/testbed/testbed_api_cmd_tng_service.c
deleted file mode 100644
index cce2e14e3..000000000
--- a/src/testbed/testbed_api_cmd_tng_service.c
+++ /dev/null
@@ -1,276 +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/testbed_api_cmd_tng.c
23 * @brief Command to start the transport service of 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-service-testbed.h"
30#include "testbed_api_hosts.h"
31#include "gnunet_testbed_ng_service.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) \
37 GNUNET_log (kind, __VA_ARGS__)
38
39
40/**
41 * abort task to run on test timed out
42 *
43 * @param cls NULL
44 * @param tc the task context
45 */
46static void
47do_abort (void *cls)
48{
49 struct TngState *ts = cls;
50
51 if (GNUNET_NO == ts->service_ready)
52 {
53 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
54 ts->abort_task = NULL;
55 GNUNET_TESTBED_shutdown_service (ts);
56 }
57}
58
59/**
60*
61*
62* @param cls closure
63* @param cmd current CMD being cleaned up.
64*/
65static void
66tng_service_cleanup (void *cls,
67 const struct GNUNET_TESTING_Command *cmd)
68{
69 (void) cls;
70}
71
72/**
73*
74*
75* @param cls closure.
76* @param[out] ret result
77* @param trait name of the trait.
78* @param index index number of the object to offer.
79* @return #GNUNET_OK on success.
80*/
81static int
82tng_service_traits (void *cls,
83 const void **ret,
84 const char *trait,
85 unsigned int index)
86{
87 (void) cls;
88 return GNUNET_OK;
89}
90
91
92static void *
93notify_connect (void *cls,
94 const struct GNUNET_PeerIdentity *peer,
95 struct GNUNET_MQ_Handle *mq)
96{
97 struct TngState *ts = cls;
98
99 if (NULL != emsg)
100 {
101 LOG (GNUNET_ERROR_TYPE_ERROR,
102 "There was an error starting the transport subsystem: %s\n",
103 emsg);
104 }
105 GNUNET_TESTING_interpreter_next (ps->is);
106 return ts->nc (ts->cb_cls);
107
108}
109
110
111static void
112notify_disconnect (void *cls,
113 const struct GNUNET_PeerIdentity *peer,
114 void *handler_cls)
115{
116}
117
118
119
120
121/**
122 * Adapter function called to establish a connection to
123 * a service.
124 *
125 * @param cls closure
126 * @param cfg configuration of the peer to connect to; will be available until
127 * GNUNET_TESTBED_operation_done() is called on the operation returned
128 * from GNUNET_TESTBED_service_connect()
129 * @return service handle to return in 'op_result', NULL on error
130 */
131static void *
132connect_adapter (void *cls,
133 const struct GNUNET_CONFIGURATION_Handle *cfg)
134{
135 struct TngState *ts = cls;
136
137 service_handle = GNUNET_TRANSPORT_core_connect (cfg,
138 ts->peer_identity,
139 ts->handlers,
140 ts,
141 &notify_connect,
142 &notify_disconnect);
143 return service_handle;
144}
145
146
147/**
148 * Adapter function called to destroy a connection to
149 * a service.
150 *
151 * @param cls closure
152 * @param op_result service handle returned from the connect adapter
153 */
154static void
155disconnect_adapter (void *cls,
156 void *op_result)
157{
158}
159
160/**
161 * Callback to be called when a service connect operation is completed
162 *
163 * @param cls the callback closure from functions generating an operation
164 * @param op the operation that has been finished
165 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
166 * @param emsg error message in case the operation has failed; will be NULL if
167 * operation has executed successfully.
168 */
169static void
170service_connect_comp_cb (void *cls,
171 struct GNUNET_TESTBED_Operation *op,
172 void *ca_result,
173 const char *emsg)
174{
175 struct TngState *ts = cls;
176
177 if (NULL != emsg)
178 {
179 LOG (GNUNET_ERROR_TYPE_DEBUG,
180 "An error occurred connecting to service %s\n",
181 emsg);
182 GNUNET_TESTBED_operation_done (ts->operation);
183 }
184}
185
186
187/**
188 * Callback to be called when the requested peer information is available
189 *
190 * @param cls the closure from GNUNET_TESTBED_peer_getinformation()
191 * @param op the operation this callback corresponds to
192 * @param pinfo the result; will be NULL if the operation has failed
193 * @param emsg error message if the operation has failed;
194 * NULL if the operation is successful
195 */
196static void
197pi_cb (void *cls,
198 struct GNUNET_TESTBED_Operation *op,
199 const struct GNUNET_TESTBED_PeerInformation *pinfo,
200 const char *emsg)
201{
202 struct TngState *ts = cls;
203
204 ts->peer_identity = pinfo->id;
205 ts->operation =
206 GNUNET_TESTBED_service_connect (NULL, peer, NULL,
207 &service_connect_comp_cb, ts,
208 &connect_adapter,
209 &disconnect_adapter,
210 ts);
211}
212
213
214static void
215tng_service_run (void *cls,
216 const struct GNUNET_TESTING_Command *cmd,
217 struct GNUNET_TESTING_Interpreter *is)
218{
219 struct TngState *ts = cls;
220 struct GNUNET_TESTBED_Peer *peer;
221 const struct GNUNET_TESTING_Command *peer_cmd;
222
223 ts->is = is;
224 peer_cmd = GNUNET_TESTING_interpreter_lookup_command (
225 ts->peer_label);
226 GNUNET_TESTBED_get_trait_peer (peer_cmd,
227 &peer);
228
229 ts->operation = GNUNET_TESTBED_peer_get_information (peer,
230 GNUNET_TESTBED_PIT_IDENTITY,
231 &pi_cb,
232 ts);
233}
234
235/**
236 * Shutdown nicely
237 *
238 * @param cs service state.
239 */
240void
241GNUNET_TESTBED_shutdown_service (struct TngState *cs)
242{
243 LOG (GNUNET_ERROR_TYPE_DEBUG,
244 "Shutting down...\n");
245}
246
247
248struct GNUNET_TESTING_Command
249GNUNET_TESTBED_cmd_tng_service (const char *label,
250 const char *peer_label,
251 const struct GNUNET_MQ_MessageHandler *handlers,
252 GNUNET_TRANSPORT_NotifyConnect nc,
253 void *cb_cls)
254
255{
256 struct TngState *ts;
257
258 ts = GNUNET_new (struct TngState);
259 ts->servicename = servicename;
260 ts->peer_label = peer_label;
261 ts->handlers = handlers;
262 ts->nc = nc;
263 ts->nd = nd;
264 ts->cb_cls;
265
266
267 struct GNUNET_TESTING_Command cmd = {
268 .cls = ts,
269 .label = label,
270 .run = &tng_service_run,
271 .cleanup = &tmg_service_cleanup,
272 .traits = &tng_service_traits
273 };
274
275 return cmd;
276}
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index d0a460fe6..1a8d9976d 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -964,10 +964,22 @@ gen_rsh_suffix_args (const char *const *append_args)
964} 964}
965 965
966 966
967void 967/**
968GNUNET_TESTBED_extract_cfg (struct GNUNET_TESTBED_Host *host, const struct 968 * Functions with this signature are called whenever a
969 GNUNET_MessageHeader *message) 969 * complete message is received by the tokenizer.
970 *
971 * Do not call GNUNET_SERVER_mst_destroy in callback
972 *
973 * @param cls closure
974 * @param client identification of the client
975 * @param message the actual message
976 *
977 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
978 */
979static int
980helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
970{ 981{
982 struct GNUNET_TESTBED_ControllerProc *cp = cls;
971 const struct GNUNET_TESTBED_HelperReply *msg; 983 const struct GNUNET_TESTBED_HelperReply *msg;
972 const char *hostname; 984 const char *hostname;
973 char *config; 985 char *config;
@@ -989,43 +1001,22 @@ GNUNET_TESTBED_extract_cfg (struct GNUNET_TESTBED_Host *host, const struct
989 xconfig_size)); 1001 xconfig_size));
990 /* Replace the configuration template present in the host with the 1002 /* Replace the configuration template present in the host with the
991 controller's running configuration */ 1003 controller's running configuration */
992 GNUNET_CONFIGURATION_destroy (host->cfg); 1004 GNUNET_CONFIGURATION_destroy (cp->host->cfg);
993 host->cfg = GNUNET_CONFIGURATION_create (); 1005 cp->host->cfg = GNUNET_CONFIGURATION_create ();
994 GNUNET_assert (GNUNET_CONFIGURATION_deserialize (host->cfg, 1006 GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg,
995 config, 1007 config,
996 config_size, 1008 config_size,
997 NULL)); 1009 NULL));
998 GNUNET_free (config); 1010 GNUNET_free (config);
999 if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (host))) 1011 if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))
1000 hostname = "localhost"; 1012 hostname = "localhost";
1001 /* Change the hostname so that we can connect to it */ 1013 /* Change the hostname so that we can connect to it */
1002 GNUNET_CONFIGURATION_set_value_string (host->cfg, 1014 GNUNET_CONFIGURATION_set_value_string (cp->host->cfg,
1003 "testbed", 1015 "testbed",
1004 "hostname", 1016 "hostname",
1005 hostname); 1017 hostname);
1006 host->locked = GNUNET_NO; 1018 cp->host->locked = GNUNET_NO;
1007} 1019 cp->host->controller_started = GNUNET_YES;
1008
1009/**
1010 * Functions with this signature are called whenever a
1011 * complete message is received by the tokenizer.
1012 *
1013 * Do not call GNUNET_SERVER_mst_destroy in callback
1014 *
1015 * @param cls closure
1016 * @param client identification of the client
1017 * @param message the actual message
1018 *
1019 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
1020 */
1021static int
1022helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
1023{
1024 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1025 struct GNUNET_TESTBED_Host *host = cp->host;
1026
1027 GNUNET_TESTBED_extract_cfg (host, message);
1028
1029 cp->cb (cp->cls, cp->host->cfg, GNUNET_OK); 1020 cp->cb (cp->cls, cp->host->cfg, GNUNET_OK);
1030 return GNUNET_OK; 1021 return GNUNET_OK;
1031} 1022}
diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h
index af90ce85d..817ad559d 100644
--- a/src/testbed/testbed_helper.h
+++ b/src/testbed/testbed_helper.h
@@ -84,60 +84,6 @@ struct GNUNET_TESTBED_HelperReply
84 * un-compressed */ 84 * un-compressed */
85}; 85};
86 86
87/**
88 * Initialization message for gnunet-cmds-testbed to start cmd binary.
89 */
90struct GNUNET_CMDS_HelperInit
91{
92 /**
93 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT
94 */
95 struct GNUNET_MessageHeader header;
96
97 /**
98 *
99 */
100 uint16_t plugin_name_size GNUNET_PACKED;
101
102 /* Followed by plugin name of the plugin running the test case. This is not NULL
103 * terminated */
104};
105
106/**
107 * Reply message from cmds helper process
108 */
109struct GNUNET_CMDS_HelperReply
110{
111 /**
112 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY
113 */
114 struct GNUNET_MessageHeader header;
115};
116
117struct GNUNET_CMDS_PEER_STARTED
118{
119 /**
120 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED
121 */
122 struct GNUNET_MessageHeader header;
123};
124
125struct GNUNET_CMDS_ALL_PEERS_STARTED
126{
127 /**
128 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED
129 */
130 struct GNUNET_MessageHeader header;
131};
132
133struct GNUNET_CMDS_LOCAL_FINISHED
134{
135 /**
136 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
137 */
138 struct GNUNET_MessageHeader header;
139};
140
141GNUNET_NETWORK_STRUCT_END 87GNUNET_NETWORK_STRUCT_END
142#endif 88#endif
143/* end of testbed_helper.h */ 89/* end of testbed_helper.h */