aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am41
-rw-r--r--src/testbed/gnunet-cmds-helper.c663
-rw-r--r--src/testbed/plugin_testcmd.c116
-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_local_test_finished.c131
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start.c218
-rw-r--r--src/testbed/testbed_api_cmd_netjail_stop.c216
-rw-r--r--src/testbed/testbed_api_cmd_netjail_stop_testbed.c143
-rw-r--r--src/testbed/testbed_api_cmd_send_peer_ready.c103
-rw-r--r--src/testbed/testbed_api_hosts.c53
-rw-r--r--src/testbed/testbed_helper.h54
13 files changed, 23 insertions, 1929 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 5a221cd69..d1f43f0f6 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -23,7 +23,6 @@ if HAVE_SQLITE
23endif 23endif
24 24
25libexec_PROGRAMS = \ 25libexec_PROGRAMS = \
26 gnunet-cmds-helper \
27 gnunet-service-testbed \ 26 gnunet-service-testbed \
28 gnunet-helper-testbed \ 27 gnunet-helper-testbed \
29 gnunet-daemon-testbed-blacklist \ 28 gnunet-daemon-testbed-blacklist \
@@ -36,21 +35,6 @@ bin_PROGRAMS = \
36noinst_PROGRAMS = \ 35noinst_PROGRAMS = \
37 $(generate_underlay) 36 $(generate_underlay)
38 37
39plugin_LTLIBRARIES = \
40 libgnunet_plugin_testcmd.la
41
42libgnunet_plugin_testcmd_la_SOURCES = \
43 plugin_testcmd.c
44libgnunet_plugin_testcmd_la_LIBADD = \
45 $(top_builddir)/src/util/libgnunetutil.la \
46 $(top_builddir)/src/arm/libgnunetarm.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 \
@@ -89,15 +73,6 @@ gnunet_helper_testbed_LDADD = $(XLIB) \
89 libgnunettestbed.la \ 73 libgnunettestbed.la \
90 $(LTLIBINTL) $(Z_LIBS) 74 $(LTLIBINTL) $(Z_LIBS)
91 75
92gnunet_cmds_helper_SOURCES = \
93 gnunet-cmds-helper.c
94gnunet_cmds_helper_LDADD = $(XLIB) \
95 $(top_builddir)/src/util/libgnunetutil.la \
96 $(top_builddir)/src/testing/libgnunettesting.la \
97 $(top_builddir)/src/transport/libgnunettransporttesting2.la \
98 libgnunettestbed.la \
99 $(LTLIBINTL) $(Z_LIBS)
100
101gnunet_daemon_testbed_blacklist_SOURCES = gnunet-daemon-testbed-blacklist.c 76gnunet_daemon_testbed_blacklist_SOURCES = gnunet-daemon-testbed-blacklist.c
102gnunet_daemon_testbed_blacklist_LDADD = $(XLIB) \ 77gnunet_daemon_testbed_blacklist_LDADD = $(XLIB) \
103 $(top_builddir)/src/transport/libgnunettransport.la \ 78 $(top_builddir)/src/transport/libgnunettransport.la \
@@ -120,13 +95,6 @@ lib_LTLIBRARIES = \
120 libgnunettestbed.la 95 libgnunettestbed.la
121 96
122libgnunettestbed_la_SOURCES = \ 97libgnunettestbed_la_SOURCES = \
123 testbed_api_cmd_local_test_finished.c \
124 testbed_api_cmd_send_peer_ready.c \
125 testbed_api_cmd_block_until_all_peers_started.c \
126 testbed_api_cmd_netjail_start.c \
127 testbed_api_cmd_netjail_start_testbed.c \
128 testbed_api_cmd_netjail_stop_testbed.c \
129 testbed_api_cmd_netjail_stop.c \
130 testbed_api.c testbed_api.h testbed.h \ 98 testbed_api.c testbed_api.h testbed.h \
131 testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \ 99 testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \
132 testbed_api_operations.c testbed_api_operations.h \ 100 testbed_api_operations.c testbed_api_operations.h \
@@ -165,7 +133,6 @@ generate_underlay_topology_LDADD = $(XLIB) \
165 $(LTLIBINTL) -lsqlite3 133 $(LTLIBINTL) -lsqlite3
166 134
167check_PROGRAMS = \ 135check_PROGRAMS = \
168 test_testbed_api_cmd_netjail \
169 test_testbed_api_hosts \ 136 test_testbed_api_hosts \
170 test_gnunet_helper_testbed \ 137 test_gnunet_helper_testbed \
171 test_testbed_api_controllerlink \ 138 test_testbed_api_controllerlink \
@@ -200,7 +167,6 @@ check_PROGRAMS = \
200if ENABLE_TEST_RUN 167if ENABLE_TEST_RUN
201 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 168 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
202 TESTS = \ 169 TESTS = \
203 test_testbed_api_cmd_netjail \
204 test_testbed_api \ 170 test_testbed_api \
205 test_testbed_api_sd \ 171 test_testbed_api_sd \
206 test_testbed_api_operations \ 172 test_testbed_api_operations \
@@ -231,13 +197,6 @@ if ENABLE_TEST_RUN
231 $(underlay_testcases) 197 $(underlay_testcases)
232endif 198endif
233 199
234test_testbed_api_cmd_netjail_SOURCES = \
235 test_testbed_api_cmd_netjail.c
236test_testbed_api_cmd_netjail_LDADD = \
237 $(top_builddir)/src/testing/libgnunettesting.la \
238 $(top_builddir)/src/util/libgnunetutil.la \
239 libgnunettestbed.la
240
241test_testbed_api_SOURCES = \ 200test_testbed_api_SOURCES = \
242 test_testbed_api.c 201 test_testbed_api.c
243test_testbed_api_LDADD = \ 202test_testbed_api_LDADD = \
diff --git a/src/testbed/gnunet-cmds-helper.c b/src/testbed/gnunet-cmds-helper.c
deleted file mode 100644
index 4bc0656de..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 */
279/*static 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 (basename(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, plugin->local_m);
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/plugin_testcmd.c b/src/testbed/plugin_testcmd.c
deleted file mode 100644
index b74b67240..000000000
--- a/src/testbed/plugin_testcmd.c
+++ /dev/null
@@ -1,116 +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 (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
49 char *node_ip,
50 char *n,
51 char *m,
52 char *local_m)
53{
54 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
55
56 LOG (GNUNET_ERROR_TYPE_ERROR,
57 "We got here 6!\n");
58
59 are_all_peers_started = GNUNET_NO;
60
61 struct GNUNET_TESTING_Command commands[] = {
62 GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
63 &now),
64 GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
65 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1",
66 write_message),
67 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
68 &are_all_peers_started),
69 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1",
70 write_message)
71 };
72
73 GNUNET_TESTING_run (NULL,
74 commands,
75 GNUNET_TIME_UNIT_FOREVER_REL);
76 LOG (GNUNET_ERROR_TYPE_ERROR,
77 "We got here 7!\n");
78
79}
80
81
82/**
83 * Entry point for the plugin.
84 *
85 * @param cls NULL
86 * @return the exported block API
87 */
88void *
89libgnunet_plugin_testcmd_init (void *cls)
90{
91 struct GNUNET_TESTING_PluginFunctions *api;
92
93 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
94 api->start_testcase = &start_testcase;
95 api->all_peers_started = &all_peers_started;
96 return api;
97}
98
99
100/**
101 * Exit point from the plugin.
102 *
103 * @param cls the return value from #libgnunet_plugin_block_test_init
104 * @return NULL
105 */
106void *
107libgnunet_plugin_testcmd_done (void *cls)
108{
109 struct GNUNET_TESTING_PluginFunctions *api = cls;
110
111 GNUNET_free (api);
112 return NULL;
113}
114
115
116/* 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 85da39f0e..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_TESTING_cmd_netjail_start ("netjail-start-1",
43 "2",
44 "2"),
45 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1",
46 "2",
47 "2",
48 "libgnunet_plugin_testcmd"),
49 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
50 "netjail-start-testbed-1",
51 "2",
52 "2"),
53 GNUNET_TESTING_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_local_test_finished.c b/src/testbed/testbed_api_cmd_local_test_finished.c
deleted file mode 100644
index c02546945..000000000
--- a/src/testbed/testbed_api_cmd_local_test_finished.c
+++ /dev/null
@@ -1,131 +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 TESTING_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 LOG (GNUNET_ERROR_TYPE_ERROR,
97 "Stopping local loop\n");
98 return GNUNET_YES;
99}
100
101
102/**
103 * Create command.
104 *
105 * @param label name for command.
106 * @return command.
107 */
108struct GNUNET_TESTING_Command
109GNUNET_TESTING_cmd_local_test_finished (const char *label,
110 TESTING_CMD_HELPER_write_cb
111 write_message)
112{
113 struct LocalFinishedState *lfs;
114
115 LOG (GNUNET_ERROR_TYPE_ERROR,
116 "We got here 11!\n");
117
118 lfs = GNUNET_new (struct LocalFinishedState);
119 lfs->write_message = write_message;
120
121 struct GNUNET_TESTING_Command cmd = {
122 .cls = lfs,
123 .label = label,
124 .run = &local_test_finished_run,
125 .finish = &local_test_finished_finish,
126 .cleanup = &local_test_finished_cleanup,
127 .traits = &local_test_finished_traits
128 };
129
130 return cmd;
131}
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 0cc020275..000000000
--- a/src/testbed/testbed_api_cmd_netjail_start.c
+++ /dev/null
@@ -1,218 +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 "./../testing/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 unsigned int helper_check = GNUNET_OS_check_helper_binary (
143 NETJAIL_START_SCRIPT,
144 GNUNET_YES,
145 NULL);
146
147 if (GNUNET_NO == helper_check)
148 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "No SUID for %s!\n",
151 NETJAIL_START_SCRIPT);
152 GNUNET_TESTING_interpreter_fail ();
153 }
154 else if (GNUNET_NO == helper_check)
155 {
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
157 "%s not found!\n",
158 NETJAIL_START_SCRIPT);
159 GNUNET_TESTING_interpreter_fail ();
160 }
161
162 ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
163 NULL,
164 NULL,
165 NULL,
166 NETJAIL_START_SCRIPT,
167 script_argv);
168
169 ns->cwh = GNUNET_wait_child (ns->start_proc,
170 &child_completed_callback,
171 ns);
172 GNUNET_break (NULL != ns->cwh);
173}
174
175static int
176netjail_start_finish (void *cls,
177 GNUNET_SCHEDULER_TaskCallback cont,
178 void *cont_cls)
179{
180 struct NetJailState *ns = cls;
181
182 if (ns->finished)
183 {
184 cont (cont_cls);
185 }
186 return ns->finished;
187}
188
189/**
190 * Create command.
191 *
192 * @param label name for command.
193 * @param binaryname to start.
194 * @return command.
195 */
196struct GNUNET_TESTING_Command
197GNUNET_TESTING_cmd_netjail_start (const char *label,
198 char *local_m,
199 char *global_n)
200{
201 struct NetJailState *ns;
202
203 ns = GNUNET_new (struct NetJailState);
204 ns->local_m = local_m;
205 ns->global_n = global_n;
206 ns->finished = GNUNET_NO;
207
208 struct GNUNET_TESTING_Command cmd = {
209 .cls = ns,
210 .label = label,
211 .run = &netjail_start_run,
212 .finish = &netjail_start_finish,
213 .cleanup = &netjail_start_cleanup,
214 .traits = &netjail_start_traits
215 };
216
217 return cmd;
218}
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 f837ec08c..000000000
--- a/src/testbed/testbed_api_cmd_netjail_stop.c
+++ /dev/null
@@ -1,216 +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 "./../testing/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 unsigned int helper_check = GNUNET_OS_check_helper_binary (
139 NETJAIL_STOP_SCRIPT,
140 GNUNET_YES,
141 NULL);
142
143 if (GNUNET_NO == helper_check)
144 {
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
146 "No SUID for %s!\n",
147 NETJAIL_STOP_SCRIPT);
148 GNUNET_TESTING_interpreter_fail ();
149 }
150 else if (GNUNET_NO == helper_check)
151 {
152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
153 "%s not found!\n",
154 NETJAIL_STOP_SCRIPT);
155 GNUNET_TESTING_interpreter_fail ();
156 }
157
158 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
159 NULL,
160 NULL,
161 NULL,
162 NETJAIL_STOP_SCRIPT,
163 script_argv);
164
165 cwh = GNUNET_wait_child (ns->stop_proc,
166 &child_completed_callback,
167 ns);
168 GNUNET_break (NULL != cwh);
169
170}
171
172
173static int
174netjail_stop_finish (void *cls,
175 GNUNET_SCHEDULER_TaskCallback cont,
176 void *cont_cls)
177{
178 struct NetJailState *ns = cls;
179
180 if (ns->finished)
181 {
182 cont (cont_cls);
183 }
184 return ns->finished;
185}
186
187
188/**
189 * Create command.
190 *
191 * @param label name for command.
192 * @param binaryname to stop.
193 * @return command.
194 */
195struct GNUNET_TESTING_Command
196GNUNET_TESTING_cmd_netjail_stop (const char *label,
197 char *local_m,
198 char *global_n)
199{
200 struct NetJailState *ns;
201
202 ns = GNUNET_new (struct NetJailState);
203 ns->local_m = local_m;
204 ns->global_n = global_n;
205
206 struct GNUNET_TESTING_Command cmd = {
207 .cls = ns,
208 .label = label,
209 .run = &netjail_stop_run,
210 .finish = &netjail_stop_finish,
211 .cleanup = &netjail_stop_cleanup,
212 .traits = &netjail_stop_traits
213 };
214
215 return cmd;
216}
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 c74c1e94f..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_testing_system_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_testing_system_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_testing_system_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_TESTING_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_TESTING_cmd_stop_testing_system (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_testing_system_run,
138 .cleanup = &stop_testing_system_cleanup,
139 .traits = &stop_testing_system_traits
140 };
141
142 return cmd;
143}
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 987f0853e..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 TESTING_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 TESTING_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_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 */