aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_protocols.h20
-rw-r--r--src/include/gnunet_testbed_ng_service.h9
-rw-r--r--src/include/gnunet_testing_ng_lib.h1
-rw-r--r--src/include/gnunet_testing_plugin.h12
-rw-r--r--src/testbed/Makefile.am11
-rw-r--r--src/testbed/gnunet-cmd.c54
-rw-r--r--src/testbed/gnunet-cmds-helper.c (renamed from src/testbed/gnunet-helper-cmds.c)480
-rwxr-xr-xsrc/testbed/netjail_exec.sh2
-rw-r--r--src/testbed/plugin_testcmd.c19
-rw-r--r--src/testbed/testbed_api.h3
-rw-r--r--src/testbed/testbed_api_cmd_block_until_all_peers_started.c102
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start.c6
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start_testbed.c162
-rw-r--r--src/testbed/testbed_api_cmd_send_peer_ready.c102
-rw-r--r--src/testbed/testbed_helper.h46
-rw-r--r--src/testing/testing_api_cmd_start_peer.c296
-rw-r--r--src/testing/testing_api_cmd_system_create.c110
-rw-r--r--src/testing/testing_api_loop.c3
-rw-r--r--src/transport/transport-testing.c4
-rw-r--r--src/transport/transport-testing2.c4
-rw-r--r--src/util/child_management.c19
21 files changed, 1239 insertions, 226 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 8e6e8b1be..1d33d986d 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -3549,6 +3549,26 @@ extern "C" {
3549 3549
3550/*********************************************************************************/ 3550/*********************************************************************************/
3551 3551
3552/*********************************************************************************/
3553/********************************** Cmd Testing **********************************/
3554/*********************************************************************************/
3555
3556/**
3557 * The initialization message towards gnunet-cmds-helper
3558 */
3559#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT 1700
3560
3561/**
3562 * The reply message from gnunet-cmds-helper
3563 */
3564#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY 1701
3565
3566#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED 1702
3567
3568#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED 1703
3569
3570/*********************************************************************************/
3571
3552/** 3572/**
3553 * Type used to match 'all' message types. 3573 * Type used to match 'all' message types.
3554 */ 3574 */
diff --git a/src/include/gnunet_testbed_ng_service.h b/src/include/gnunet_testbed_ng_service.h
index 9845b3be6..2ea5e616c 100644
--- a/src/include/gnunet_testbed_ng_service.h
+++ b/src/include/gnunet_testbed_ng_service.h
@@ -265,4 +265,13 @@ int
265GNUNET_TESTBED_get_trait_hosts (const struct 265GNUNET_TESTBED_get_trait_hosts (const struct
266 GNUNET_TESTING_Command *cmd, 266 GNUNET_TESTING_Command *cmd,
267 struct GNUNET_TESTBED_Host ***hosts); 267 struct GNUNET_TESTBED_Host ***hosts);
268
269struct GNUNET_TESTING_Command
270GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
271 unsigned int *
272 all_peers_started);
273
274struct GNUNET_TESTING_Command
275GNUNET_TESTING_cmd_send_peer_ready (const char *label,
276 TESTBED_CMD_HELPER_write_cb write_message);
268#endif 277#endif
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index a794562a9..8927fd4f1 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -28,6 +28,7 @@
28#define GNUNET_TESTING_NG_LIB_H 28#define GNUNET_TESTING_NG_LIB_H
29 29
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_testing_plugin.h"
31 32
32 33
33/* ********************* Helper functions ********************* */ 34/* ********************* Helper functions ********************* */
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
index 527f509ad..6a54cacd2 100644
--- a/src/include/gnunet_testing_plugin.h
+++ b/src/include/gnunet_testing_plugin.h
@@ -36,9 +36,17 @@ extern "C"
36#endif 36#endif
37#endif 37#endif
38 38
39typedef void
40(*TESTBED_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message, size_t
41 msg_length);
42
43typedef void
44(*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTBED_CMD_HELPER_write_cb
45 write_message, char *router_ip,
46 char *node_ip);
39 47
40typedef void 48typedef void
41(*GNUNET_TESTING_PLUGIN_StartTestCase) (); 49(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) ();
42 50
43struct GNUNET_TESTING_PluginFunctions 51struct GNUNET_TESTING_PluginFunctions
44{ 52{
@@ -48,6 +56,8 @@ struct GNUNET_TESTING_PluginFunctions
48 void *cls; 56 void *cls;
49 57
50 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase; 58 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase;
59
60 GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started;
51}; 61};
52 62
53#if 0 /* keep Emacsens' auto-indent happy */ 63#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 8c4a6342b..dc24eaf26 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -24,7 +24,7 @@ endif
24 24
25libexec_PROGRAMS = \ 25libexec_PROGRAMS = \
26 gnunet-cmd \ 26 gnunet-cmd \
27 gnunet-helper-cmds \ 27 gnunet-cmds-helper \
28 gnunet-service-testbed \ 28 gnunet-service-testbed \
29 gnunet-helper-testbed \ 29 gnunet-helper-testbed \
30 gnunet-daemon-testbed-blacklist \ 30 gnunet-daemon-testbed-blacklist \
@@ -45,6 +45,7 @@ libgnunet_plugin_testcmd_la_SOURCES = \
45libgnunet_plugin_testcmd_la_LIBADD = \ 45libgnunet_plugin_testcmd_la_LIBADD = \
46 $(top_builddir)/src/util/libgnunetutil.la \ 46 $(top_builddir)/src/util/libgnunetutil.la \
47 $(top_builddir)/src/testing/libgnunettesting.la \ 47 $(top_builddir)/src/testing/libgnunettesting.la \
48 $(top_builddir)/src/testbed/libgnunettestbed.la
48 $(LTLIBINTL) 49 $(LTLIBINTL)
49libgnunet_plugin_testcmd_la_LDFLAGS = \ 50libgnunet_plugin_testcmd_la_LDFLAGS = \
50 $(GN_PLUGIN_LDFLAGS) 51 $(GN_PLUGIN_LDFLAGS)
@@ -94,9 +95,9 @@ gnunet_cmd_LDADD = $(XLIB) \
94 libgnunettestbed.la \ 95 libgnunettestbed.la \
95 $(LTLIBINTL) $(Z_LIBS) 96 $(LTLIBINTL) $(Z_LIBS)
96 97
97gnunet_helper_cmds_SOURCES = \ 98gnunet_cmds_helper_SOURCES = \
98 gnunet-helper-cmds.c 99 gnunet-cmds-helper.c
99gnunet_helper_cmds_LDADD = $(XLIB) \ 100gnunet_cmds_helper_LDADD = $(XLIB) \
100 $(top_builddir)/src/util/libgnunetutil.la \ 101 $(top_builddir)/src/util/libgnunetutil.la \
101 $(top_builddir)/src/testing/libgnunettesting.la \ 102 $(top_builddir)/src/testing/libgnunettesting.la \
102 libgnunettestbed.la \ 103 libgnunettestbed.la \
@@ -124,6 +125,8 @@ lib_LTLIBRARIES = \
124 libgnunettestbed.la 125 libgnunettestbed.la
125 126
126libgnunettestbed_la_SOURCES = \ 127libgnunettestbed_la_SOURCES = \
128 testbed_api_cmd_send_peer_ready.c \
129 testbed_api_cmd_block_until_all_peers_started.c \
127 testbed_api_cmd_netjail_start.c \ 130 testbed_api_cmd_netjail_start.c \
128 testbed_api_cmd_netjail_start_testbed.c \ 131 testbed_api_cmd_netjail_start_testbed.c \
129 testbed_api_cmd_netjail_stop_testbed.c \ 132 testbed_api_cmd_netjail_stop_testbed.c \
diff --git a/src/testbed/gnunet-cmd.c b/src/testbed/gnunet-cmd.c
index 477c3c454..7889750ba 100644
--- a/src/testbed/gnunet-cmd.c
+++ b/src/testbed/gnunet-cmd.c
@@ -36,6 +36,9 @@
36 */ 36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38 38
39#define NODE_BASE_IP "192.168.15."
40
41#define ROUTER_BASE_IP "92.68.150."
39 42
40/** 43/**
41 * Handle for a plugin. 44 * Handle for a plugin.
@@ -51,29 +54,44 @@ struct Plugin
51 * Plugin API. 54 * Plugin API.
52 */ 55 */
53 struct GNUNET_TESTING_PluginFunctions *api; 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;
54}; 69};
55 70
56 71
57/** 72/**
58 * Main function to run the test cases. 73 * Main function to run the test cases.
59 * 74 *
60 * @param cls not used. 75 * @param cls plugin to use.
61 * 76 *
62 */ 77 */
63static void 78static void
64run (void *cls) 79run (void *cls)
65{ 80{
66 struct Plugin *plugin; 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);
67 94
68 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "gnunet-cmd",
69 "running plugin.\n");
70 LOG (GNUNET_ERROR_TYPE_ERROR,
71 "running plugin.\n");
72 plugin = GNUNET_new (struct Plugin);
73 plugin->api = GNUNET_PLUGIN_load ("libgnunet_plugin_testcmd",
74 NULL);
75 plugin->library_name = GNUNET_strdup ("libgnunet_plugin_testcmd");
76 plugin->api->start_testcase ();
77} 95}
78 96
79 97
@@ -81,13 +99,25 @@ int
81main (int argc, char *const *argv) 99main (int argc, char *const *argv)
82{ 100{
83 int rv = 0; 101 int rv = 0;
102 struct Plugin *plugin;
84 103
85 GNUNET_log_setup ("gnunet-cmd", 104 GNUNET_log_setup ("gnunet-cmd",
86 "DEBUG", 105 "DEBUG",
87 NULL); 106 NULL);
88 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
89 GNUNET_SCHEDULER_run (&run, 118 GNUNET_SCHEDULER_run (&run,
90 NULL); 119 plugin);
91 120
121 GNUNET_free (plugin);
92 return rv; 122 return rv;
93} 123}
diff --git a/src/testbed/gnunet-helper-cmds.c b/src/testbed/gnunet-cmds-helper.c
index 3073ebdfb..693892a9c 100644
--- a/src/testbed/gnunet-helper-cmds.c
+++ b/src/testbed/gnunet-cmds-helper.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file testbed/gnunet-helper-cmds.c 22 * @file testbed/gnunet-cmds-helper.c
23 * @brief Helper binary that is started from a remote interpreter loop to start 23 * @brief Helper binary that is started from a remote interpreter loop to start
24 * a local interpreter loop. 24 * a local interpreter loop.
25 * 25 *
@@ -42,7 +42,9 @@
42#include "gnunet_testbed_service.h" 42#include "gnunet_testbed_service.h"
43#include "testbed_helper.h" 43#include "testbed_helper.h"
44#include "testbed_api.h" 44#include "testbed_api.h"
45#include "gnunet_testing_plugin.h"
45#include <zlib.h> 46#include <zlib.h>
47#include "execinfo.h"
46 48
47/** 49/**
48 * Generic logging shortcut 50 * Generic logging shortcut
@@ -54,6 +56,50 @@
54 */ 56 */
55#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 57#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
56 58
59#define NODE_BASE_IP "192.168.15."
60
61#define ROUTER_BASE_IP "92.68.150."
62
63#define MAX_TRACE_DEPTH 50
64
65/**
66 * Handle for a plugin.
67 */
68struct Plugin
69{
70 /**
71 * Name of the shared library.
72 */
73 char *library_name;
74
75 /**
76 * Plugin API.
77 */
78 struct GNUNET_TESTING_PluginFunctions *api;
79
80 char *node_ip;
81
82 char *plugin_name;
83
84 char *global_n;
85
86 char *local_m;
87
88 char *n;
89
90 char *m;
91};
92
93struct NodeIdentifier
94{
95 char *n;
96
97 char *m;
98
99 char *global_n;
100
101 char *local_m;
102};
57 103
58/** 104/**
59 * Context for a single write on a chunk of memory 105 * Context for a single write on a chunk of memory
@@ -76,6 +122,8 @@ struct WriteContext
76 size_t pos; 122 size_t pos;
77}; 123};
78 124
125struct Plugin *plugin;
126
79/** 127/**
80 * The process handle to the testbed service 128 * The process handle to the testbed service
81 */ 129 */
@@ -132,6 +180,61 @@ static int done_reading;
132static int status; 180static int status;
133 181
134 182
183struct BacktraceInfo
184{
185 /**
186 * Array of strings which make up a backtrace from the point when this
187 * task was scheduled (essentially, who scheduled the task?)
188 */
189 char **backtrace_strings;
190
191 /**
192 * Size of the backtrace_strings array
193 */
194 int num_backtrace_strings;
195};
196
197/**
198 * Output stack trace of task @a t.
199 *
200 * @param t task to dump stack trace of
201 */
202static void
203dump_backtrace (struct BacktraceInfo *t)
204{
205
206 for (unsigned int i = 0; i < t->num_backtrace_strings; i++)
207 LOG (GNUNET_ERROR_TYPE_ERROR,
208 "Task %p trace %u: %s\n",
209 t,
210 i,
211 t->backtrace_strings[i]);
212
213}
214
215
216/**
217 * Initialize backtrace data for task @a t
218 *
219 * @param t task to initialize
220 */
221static void
222init_backtrace ()
223{
224 struct BacktraceInfo *t;
225 void *backtrace_array[MAX_TRACE_DEPTH];
226
227 t = GNUNET_new (struct BacktraceInfo);
228 t->num_backtrace_strings
229 = backtrace (backtrace_array, MAX_TRACE_DEPTH);
230 t->backtrace_strings =
231 backtrace_symbols (backtrace_array,
232 t->num_backtrace_strings);
233 dump_backtrace (t);
234
235}
236
237
135/** 238/**
136 * Task to shut down cleanly 239 * Task to shut down cleanly
137 * 240 *
@@ -140,7 +243,11 @@ static int status;
140static void 243static void
141shutdown_task (void *cls) 244shutdown_task (void *cls)
142{ 245{
143 LOG_DEBUG ("Shutting down\n"); 246
247 init_backtrace ();
248 LOG_DEBUG ("Shutting down.\n");
249 LOG (GNUNET_ERROR_TYPE_ERROR,
250 "Shutting down tokenizer!\n");
144 251
145 if (NULL != read_task_id) 252 if (NULL != read_task_id)
146 { 253 {
@@ -176,6 +283,8 @@ shutdown_task (void *cls)
176} 283}
177 284
178 285
286
287
179/** 288/**
180 * Task to write to the standard out 289 * Task to write to the standard out
181 * 290 *
@@ -187,6 +296,9 @@ write_task (void *cls)
187 struct WriteContext *wc = cls; 296 struct WriteContext *wc = cls;
188 ssize_t bytes_wrote; 297 ssize_t bytes_wrote;
189 298
299 LOG (GNUNET_ERROR_TYPE_ERROR,
300 "Writing data!\n");
301
190 GNUNET_assert (NULL != wc); 302 GNUNET_assert (NULL != wc);
191 write_task_id = NULL; 303 write_task_id = NULL;
192 bytes_wrote = GNUNET_DISK_file_write (stdout_fd, 304 bytes_wrote = GNUNET_DISK_file_write (stdout_fd,
@@ -194,7 +306,8 @@ write_task (void *cls)
194 wc->length - wc->pos); 306 wc->length - wc->pos);
195 if (GNUNET_SYSERR == bytes_wrote) 307 if (GNUNET_SYSERR == bytes_wrote)
196 { 308 {
197 LOG (GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); 309 LOG (GNUNET_ERROR_TYPE_WARNING,
310 "Cannot reply back successful initialization\n");
198 GNUNET_free (wc->data); 311 GNUNET_free (wc->data);
199 GNUNET_free (wc); 312 GNUNET_free (wc);
200 return; 313 return;
@@ -204,8 +317,12 @@ write_task (void *cls)
204 { 317 {
205 GNUNET_free (wc->data); 318 GNUNET_free (wc->data);
206 GNUNET_free (wc); 319 GNUNET_free (wc);
320 LOG (GNUNET_ERROR_TYPE_ERROR,
321 "Written successfully!\n");
207 return; 322 return;
208 } 323 }
324 LOG (GNUNET_ERROR_TYPE_ERROR,
325 "Written data!\n");
209 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 326 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
210 stdout_fd, 327 stdout_fd,
211 &write_task, 328 &write_task,
@@ -240,6 +357,52 @@ child_death_task (void *cls)
240} 357}
241 358
242 359
360static void
361write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
362{
363 struct WriteContext *wc;
364
365 LOG (GNUNET_ERROR_TYPE_ERROR,
366 "enter write_message!\n");
367 wc = GNUNET_new (struct WriteContext);
368 wc->length = msg_length;
369 wc->data = message;
370 write_task_id = GNUNET_SCHEDULER_add_write_file (
371 GNUNET_TIME_UNIT_FOREVER_REL,
372 stdout_fd,
373 &write_task,
374 wc);
375 LOG (GNUNET_ERROR_TYPE_ERROR,
376 "leave write_message!\n");
377}
378
379
380/**
381 * Function to run the test cases.
382 *
383 * @param cls plugin to use.
384 *
385 */
386static void
387run_plugin (void *cls)
388{
389 struct Plugin *plugin = cls;
390 char *router_ip;
391 char *node_ip;
392
393 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) + 1);
394 strcpy (router_ip, ROUTER_BASE_IP);
395 strcat (router_ip, plugin->m);
396
397 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
398 strcat (node_ip, NODE_BASE_IP);
399 strcat (node_ip, plugin->n);
400
401 plugin->api->start_testcase (&write_message, router_ip, node_ip);
402
403}
404
405
243/** 406/**
244 * Functions with this signature are called whenever a 407 * Functions with this signature are called whenever a
245 * complete message is received by the tokenizer. 408 * complete message is received by the tokenizer.
@@ -255,191 +418,140 @@ child_death_task (void *cls)
255static int 418static int
256tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) 419tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
257{ 420{
258 const struct GNUNET_TESTBED_HelperInit *msg; 421 struct NodeIdentifier *ni = cls;
259 struct GNUNET_TESTBED_HelperReply *reply; 422 const struct GNUNET_CMDS_HelperInit *msg;
260 struct GNUNET_CONFIGURATION_Handle *cfg; 423 struct GNUNET_CMDS_HelperReply *reply;
261 struct WriteContext *wc;
262 char *binary; 424 char *binary;
263 char *trusted_ip; 425 char *plugin_name;
264 char *hostname; 426 size_t plugin_name_size;
265 char *config;
266 char *xconfig;
267 char *evstr;
268 // char *str;
269 size_t config_size;
270 uLongf ul_config_size;
271 size_t xconfig_size;
272 uint16_t trusted_ip_size;
273 uint16_t hostname_size;
274 uint16_t msize; 427 uint16_t msize;
428 size_t msg_length;
429 char *router_ip;
430 char *node_ip;
431
432 LOG (GNUNET_ERROR_TYPE_ERROR,
433 "tokenizer \n");
275 434
276 msize = ntohs (message->size); 435 msize = ntohs (message->size);
277 if ((sizeof(struct GNUNET_TESTBED_HelperInit) >= msize) || 436 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
278 (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type))) 437 message->type))
279 { 438 {
280 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); 439 plugin->api->all_peers_started ();
281 goto error;
282 }
283 msg = (const struct GNUNET_TESTBED_HelperInit *) message;
284 trusted_ip_size = ntohs (msg->trusted_ip_size);
285 trusted_ip = (char *) &msg[1];
286 if ('\0' != trusted_ip[trusted_ip_size])
287 {
288 LOG (GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n");
289 goto error;
290 }
291 hostname_size = ntohs (msg->hostname_size);
292 if ((sizeof(struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1
293 + hostname_size) >= msize)
294 {
295 GNUNET_break (0);
296 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
297 goto error;
298 } 440 }
299 ul_config_size = (uLongf) ntohs (msg->config_size); 441 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
300 config = GNUNET_malloc (ul_config_size);
301 xconfig_size = msize - (trusted_ip_size + 1 + hostname_size
302 + sizeof(struct GNUNET_TESTBED_HelperInit));
303 int ret = uncompress ((Bytef *) config,
304 &ul_config_size,
305 (const Bytef *) (trusted_ip + trusted_ip_size + 1
306 + hostname_size),
307 (uLongf) xconfig_size);
308 if (Z_OK != ret)
309 { 442 {
310 switch (ret) 443 msg = (const struct GNUNET_CMDS_HelperInit *) message;
444 plugin_name_size = ntohs (msg->plugin_name_size);
445 if ((sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_size) > msize)
311 { 446 {
312 case Z_MEM_ERROR: 447 GNUNET_break (0);
313 LOG (GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); 448 LOG (GNUNET_ERROR_TYPE_WARNING,
314 break; 449 "Received unexpected message -- exiting\n");
450 goto error;
451 }
452 plugin_name = GNUNET_malloc (plugin_name_size + 1);
453 GNUNET_strlcpy (plugin_name,
454 ((char *) &msg[1]),
455 plugin_name_size + 1);
315 456
316 case Z_BUF_ERROR: 457 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd");
317 LOG (GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n");
318 break;
319 458
320 case Z_DATA_ERROR: 459 LOG (GNUNET_ERROR_TYPE_ERROR,
321 LOG (GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); 460 "plugin_name: %s \n",
322 break; 461 plugin_name);
462
463 // cmd_binary_process = GNUNET_OS_start_process (
464 /*GNUNET_OS_INHERIT_STD_ERR verbose? ,
465 NULL,
466 NULL,
467 NULL,
468 binary,
469 plugin_name,
470 ni->global_n,
471 ni->local_m,
472 ni->n,
473 ni->m,
474 NULL);*/
475
476 plugin = GNUNET_new (struct Plugin);
477 plugin->api = GNUNET_PLUGIN_load (plugin_name,
478 NULL);
479 plugin->library_name = GNUNET_strdup (plugin_name);
480
481 plugin->global_n = ni->global_n;
482 plugin->local_m = ni->local_m;
483 plugin->n = ni->n;
484 plugin->m = ni->m;
485
486 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m)
487 + 1);
488 strcpy (router_ip, ROUTER_BASE_IP);
489 strcat (router_ip, plugin->m);
490
491 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
492 strcat (node_ip, NODE_BASE_IP);
493 strcat (node_ip, plugin->n);
494
495 plugin->api->start_testcase (&write_message, router_ip, node_ip);
323 496
324 default:
325 GNUNET_break (0);
326 }
327 LOG (GNUNET_ERROR_TYPE_ERROR, 497 LOG (GNUNET_ERROR_TYPE_ERROR,
328 "Error while uncompressing config -- exiting\n"); 498 "We got here!\n");
329 GNUNET_free (config);
330 goto error;
331 }
332 cfg = GNUNET_CONFIGURATION_create ();
333 if (GNUNET_OK !=
334 GNUNET_CONFIGURATION_deserialize (cfg, config, ul_config_size, NULL))
335 {
336 LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n");
337 GNUNET_free (config);
338 goto error;
339 }
340 GNUNET_free (config);
341 hostname = NULL;
342 if (0 != hostname_size)
343 {
344 hostname = GNUNET_malloc (hostname_size + 1);
345 GNUNET_strlcpy (hostname,
346 ((char *) &msg[1]) + trusted_ip_size + 1,
347 hostname_size + 1);
348 }
349 /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */
350 evstr = getenv (GNUNET_TESTING_PREFIX);
351 if (NULL != evstr)
352 {
353 /* unsetting the variable will invalidate the pointer! */
354 evstr = GNUNET_strdup (evstr);
355 GNUNET_break (0 == unsetenv (GNUNET_TESTING_PREFIX));
356 }
357 test_system =
358 GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname, NULL);
359 if (NULL != evstr)
360 {
361 char *evar;
362 499
363 GNUNET_asprintf (&evar, GNUNET_TESTING_PREFIX "=%s", evstr); 500 /*if (NULL == cmd_binary_process)
364 GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', 501 {
365 see putenv(): becomes part of environment! */ 502 LOG (GNUNET_ERROR_TYPE_ERROR,
366 GNUNET_free (evstr); 503 "Starting plugin failed!\n");
367 evstr = NULL; 504 return GNUNET_SYSERR;
368 } 505 }*/
369 GNUNET_free (hostname);
370 hostname = NULL;
371 GNUNET_assert (NULL != test_system);
372 GNUNET_assert (GNUNET_OK ==
373 GNUNET_TESTING_configuration_create (test_system, cfg));
374 GNUNET_assert (GNUNET_OK ==
375 GNUNET_CONFIGURATION_get_value_filename (cfg,
376 "PATHS",
377 "DEFAULTCONFIG",
378 &config));
379 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config))
380 {
381 LOG (GNUNET_ERROR_TYPE_WARNING,
382 "Unable to write config file: %s -- exiting\n",
383 config);
384 GNUNET_CONFIGURATION_destroy (cfg);
385 GNUNET_free (config);
386 goto error;
387 }
388 LOG_DEBUG ("Staring testbed with config: %s\n", config);
389 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd");
390 {
391 char *evar;
392 506
393 /* expose testbed configuration through env variable */ 507 LOG (GNUNET_ERROR_TYPE_ERROR,
394 GNUNET_asprintf (&evar, "%s=%s", ENV_TESTBED_CONFIG, config); 508 "We got here 2!\n");
395 GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', 509
396 see putenv(): becomes part of environment! */ 510 LOG (GNUNET_ERROR_TYPE_ERROR,
397 evstr = NULL; 511 "global_n: %s local_n: %s n: %s m: %s.\n",
398 } 512 ni->global_n,
513 ni->local_m,
514 ni->n,
515 ni->m);
516
517 LOG (GNUNET_ERROR_TYPE_ERROR,
518 "We got here 3!\n");
399 519
400 cmd_binary_process = GNUNET_OS_start_process ( 520 GNUNET_free (binary);
401 GNUNET_OS_INHERIT_STD_ERR /*verbose? */, 521
402 NULL, 522 done_reading = GNUNET_YES;
403 NULL, 523
404 NULL, 524 msg_length = sizeof(struct GNUNET_CMDS_HelperReply);
405 binary); 525 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply);
526 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY);
527 reply->header.size = htons ((uint16_t) msg_length);
528
529 LOG (GNUNET_ERROR_TYPE_ERROR,
530 "We got here 4!\n");
406 531
407 if (NULL == cmd_binary_process) 532 write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
533
534 LOG (GNUNET_ERROR_TYPE_ERROR,
535 "We got here 5!\n");
536
537 /*child_death_task_id = GNUNET_SCHEDULER_add_read_file (
538 GNUNET_TIME_UNIT_FOREVER_REL,
539 GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
540 &child_death_task,
541 NULL);*/
542 return GNUNET_OK;
543 }
544 else
408 { 545 {
409 return GNUNET_SYSERR; 546 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
547 goto error;
410 } 548 }
411 549
412 GNUNET_free (binary);
413 GNUNET_free (config);
414
415 done_reading = GNUNET_YES;
416 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
417 GNUNET_CONFIGURATION_destroy (cfg);
418 cfg = NULL;
419 xconfig_size =
420 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
421 GNUNET_free (config);
422 wc = GNUNET_new (struct WriteContext);
423 wc->length = xconfig_size + sizeof(struct GNUNET_TESTBED_HelperReply);
424 reply = GNUNET_realloc (xconfig, wc->length);
425 memmove (&reply[1], reply, xconfig_size);
426 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY);
427 reply->header.size = htons ((uint16_t) wc->length);
428 reply->config_size = htons ((uint16_t) config_size);
429 wc->data = reply;
430 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
431 stdout_fd,
432 &write_task,
433 wc);
434 child_death_task_id = GNUNET_SCHEDULER_add_read_file (
435 GNUNET_TIME_UNIT_FOREVER_REL,
436 GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
437 &child_death_task,
438 NULL);
439 return GNUNET_OK;
440 550
441 error: 551 error:
442 status = GNUNET_SYSERR; 552 status = GNUNET_SYSERR;
553 LOG (GNUNET_ERROR_TYPE_ERROR,
554 "tokenizer shuting down!\n");
443 GNUNET_SCHEDULER_shutdown (); 555 GNUNET_SCHEDULER_shutdown ();
444 return GNUNET_SYSERR; 556 return GNUNET_SYSERR;
445} 557}
@@ -461,6 +573,8 @@ read_task (void *cls)
461 if ((GNUNET_SYSERR == sread) || (0 == sread)) 573 if ((GNUNET_SYSERR == sread) || (0 == sread))
462 { 574 {
463 LOG_DEBUG ("STDIN closed\n"); 575 LOG_DEBUG ("STDIN closed\n");
576 LOG (GNUNET_ERROR_TYPE_ERROR,
577 "tokenizer shuting down during reading!\n");
464 GNUNET_SCHEDULER_shutdown (); 578 GNUNET_SCHEDULER_shutdown ();
465 return; 579 return;
466 } 580 }
@@ -468,6 +582,8 @@ read_task (void *cls)
468 { 582 {
469 /* didn't expect any more data! */ 583 /* didn't expect any more data! */
470 GNUNET_break_op (0); 584 GNUNET_break_op (0);
585 LOG (GNUNET_ERROR_TYPE_ERROR,
586 "tokenizer shuting down during reading, didn't expect any more data!\n");
471 GNUNET_SCHEDULER_shutdown (); 587 GNUNET_SCHEDULER_shutdown ();
472 return; 588 return;
473 } 589 }
@@ -478,6 +594,8 @@ read_task (void *cls)
478 GNUNET_MST_from_buffer (tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) 594 GNUNET_MST_from_buffer (tokenizer, buf, sread, GNUNET_NO, GNUNET_NO))
479 { 595 {
480 GNUNET_break (0); 596 GNUNET_break (0);
597 LOG (GNUNET_ERROR_TYPE_ERROR,
598 "tokenizer shuting down during reading, writing to buffer failed!\n");
481 GNUNET_SCHEDULER_shutdown (); 599 GNUNET_SCHEDULER_shutdown ();
482 return; 600 return;
483 } 601 }
@@ -503,8 +621,11 @@ run (void *cls,
503 const char *cfgfile, 621 const char *cfgfile,
504 const struct GNUNET_CONFIGURATION_Handle *cfg) 622 const struct GNUNET_CONFIGURATION_Handle *cfg)
505{ 623{
624 struct NodeIdentifier *ni = cls;
625
506 LOG_DEBUG ("Starting interpreter loop helper...\n"); 626 LOG_DEBUG ("Starting interpreter loop helper...\n");
507 tokenizer = GNUNET_MST_create (&tokenizer_cb, NULL); 627
628 tokenizer = GNUNET_MST_create (&tokenizer_cb, ni);
508 stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); 629 stdin_fd = GNUNET_DISK_get_handle_from_native (stdin);
509 stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); 630 stdout_fd = GNUNET_DISK_get_handle_from_native (stdout);
510 read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 631 read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
@@ -545,14 +666,28 @@ sighandler_child_death ()
545int 666int
546main (int argc, char **argv) 667main (int argc, char **argv)
547{ 668{
669 struct NodeIdentifier *ni;
548 struct GNUNET_SIGNAL_Context *shc_chld; 670 struct GNUNET_SIGNAL_Context *shc_chld;
549 struct GNUNET_GETOPT_CommandLineOption options[] = 671 struct GNUNET_GETOPT_CommandLineOption options[] =
550 { GNUNET_GETOPT_OPTION_END }; 672 { GNUNET_GETOPT_OPTION_END };
551 int ret; 673 int ret;
552 674
553 GNUNET_log_setup ("gnunet-helper-cmds", 675 GNUNET_log_setup ("gnunet-cmds-helper",
554 "DEBUG", 676 "DEBUG",
555 NULL); 677 NULL);
678 ni = GNUNET_new (struct NodeIdentifier);
679 ni->global_n = argv[1];
680 ni->local_m = argv[2];
681 ni->n = argv[3];
682 ni->m = argv[4];
683
684 LOG (GNUNET_ERROR_TYPE_ERROR,
685 "global_n: %s local_n: %s n: %s m: %s.\n",
686 ni->global_n,
687 ni->local_m,
688 ni->n,
689 ni->m);
690
556 status = GNUNET_OK; 691 status = GNUNET_OK;
557 if (NULL == 692 if (NULL ==
558 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) 693 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
@@ -564,18 +699,21 @@ main (int argc, char **argv)
564 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); 699 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
565 ret = GNUNET_PROGRAM_run (argc, 700 ret = GNUNET_PROGRAM_run (argc,
566 argv, 701 argv,
567 "gnunet-helper-cmds", 702 "gnunet-cmds-helper",
568 "Helper for starting a local interpreter loop", 703 "Helper for starting a local interpreter loop",
569 options, 704 options,
570 &run, 705 &run,
571 NULL); 706 ni);
707 LOG (GNUNET_ERROR_TYPE_ERROR,
708 "run finished\n");
572 GNUNET_SIGNAL_handler_uninstall (shc_chld); 709 GNUNET_SIGNAL_handler_uninstall (shc_chld);
573 shc_chld = NULL; 710 shc_chld = NULL;
574 GNUNET_DISK_pipe_close (sigpipe); 711 GNUNET_DISK_pipe_close (sigpipe);
712 GNUNET_free (ni);
575 if (GNUNET_OK != ret) 713 if (GNUNET_OK != ret)
576 return 1; 714 return 1;
577 return (GNUNET_OK == status) ? 0 : 1; 715 return (GNUNET_OK == status) ? 0 : 1;
578} 716}
579 717
580 718
581/* end of gnunet-helper-testbed.c */ 719/* end of gnunet-cmds-helper.c */
diff --git a/src/testbed/netjail_exec.sh b/src/testbed/netjail_exec.sh
index 3e5d39c1c..532f4711c 100755
--- a/src/testbed/netjail_exec.sh
+++ b/src/testbed/netjail_exec.sh
@@ -13,4 +13,4 @@ NODE=$(netjail_print_name "N" $N $M)
13 13
14 14
15 15
16netjail_node_exec_without_fds $NODE $3 16netjail_node_exec_without_fds $NODE $3 $4 $5 $1 $2
diff --git a/src/testbed/plugin_testcmd.c b/src/testbed/plugin_testcmd.c
index 90e4a90a1..6f28e102d 100644
--- a/src/testbed/plugin_testcmd.c
+++ b/src/testbed/plugin_testcmd.c
@@ -26,21 +26,32 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_testing_plugin.h" 29#include "gnunet_testbed_ng_service.h"
30
31
32 30
31unsigned int are_all_peers_started;
33 32
33static void
34all_peers_started ()
35{
36 are_all_peers_started = GNUNET_YES;
37}
34 38
35static void 39static void
36start_testcase () 40start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip,
41 char *node_ip)
37{ 42{
38 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 43 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
39 44
45 are_all_peers_started = GNUNET_NO;
46
40 struct GNUNET_TESTING_Command commands[] = { 47 struct GNUNET_TESTING_Command commands[] = {
41 GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0", 48 GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
42 &now), 49 &now),
43 GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""), 50 GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
51 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1",
52 write_message),
53 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
54 &are_all_peers_started),
44 GNUNET_TESTING_cmd_end () 55 GNUNET_TESTING_cmd_end ()
45 }; 56 };
46 57
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index ea78a14ff..9a54ca36c 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -40,7 +40,7 @@
40/** 40/**
41 * Cmds Helper binary name 41 * Cmds Helper binary name
42 */ 42 */
43#define HELPER_CMDS_BINARY "gnunet-helper-cmds" 43#define HELPER_CMDS_BINARY "gnunet-cmds-helper"
44 44
45 45
46/** 46/**
@@ -185,7 +185,6 @@ struct OperationContext
185typedef void 185typedef void
186(*TESTBED_opcq_empty_cb) (void *cls); 186(*TESTBED_opcq_empty_cb) (void *cls);
187 187
188
189/** 188/**
190 * Handle to interact with a GNUnet testbed controller. Each 189 * Handle to interact with a GNUnet testbed controller. Each
191 * controller has at least one master handle which is created when the 190 * 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
new file mode 100644
index 000000000..fc872311d
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_block_until_all_peers_started.c
@@ -0,0 +1,102 @@
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
30struct BlockState
31{
32 unsigned int *all_peers_started;
33};
34
35
36static int
37block_until_all_peers_started_traits (void *cls,
38 const void **ret,
39 const char *trait,
40 unsigned int index)
41{
42 return GNUNET_OK;
43}
44
45
46static void
47block_until_all_peers_started_cleanup (void *cls,
48 const struct GNUNET_TESTING_Command *cmd)
49{
50 struct BlockState *bs = cls;
51
52 GNUNET_free (bs);
53}
54
55
56static void
57block_until_all_peers_started_run (void *cls,
58 const struct GNUNET_TESTING_Command *cmd,
59 struct GNUNET_TESTING_Interpreter *is)
60{
61}
62
63
64static int
65block_until_all_peers_started_finish (void *cls,
66 GNUNET_SCHEDULER_TaskCallback cont,
67 void *cont_cls)
68{
69 struct BlockState *bs = cls;
70 unsigned int *ret = bs->all_peers_started;
71
72 return *ret;
73}
74
75
76/**
77 * Create command.
78 *
79 * @param label name for command.
80 * @return command.
81 */
82struct GNUNET_TESTING_Command
83GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
84 unsigned int *
85 all_peers_started)
86{
87 struct BlockState *bs;
88
89 bs = GNUNET_new (struct BlockState);
90 bs->all_peers_started = all_peers_started;
91
92 struct GNUNET_TESTING_Command cmd = {
93 .cls = bs,
94 .label = label,
95 .run = &block_until_all_peers_started_run,
96 .finish = &block_until_all_peers_started_finish,
97 .cleanup = &block_until_all_peers_started_cleanup,
98 .traits = &block_until_all_peers_started_traits
99 };
100
101 return cmd;
102}
diff --git a/src/testbed/testbed_api_cmd_netjail_start.c b/src/testbed/testbed_api_cmd_netjail_start.c
index 320537a61..1e37d5475 100644
--- a/src/testbed/testbed_api_cmd_netjail_start.c
+++ b/src/testbed/testbed_api_cmd_netjail_start.c
@@ -59,6 +59,9 @@ netjail_start_cleanup (void *cls,
59{ 59{
60 struct NetJailState *ns = cls; 60 struct NetJailState *ns = cls;
61 61
62 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
63 "netjail_start_cleanup!\n");
64
62 if (NULL != ns->cwh) 65 if (NULL != ns->cwh)
63 { 66 {
64 GNUNET_wait_child_cancel (ns->cwh); 67 GNUNET_wait_child_cancel (ns->cwh);
@@ -74,6 +77,7 @@ netjail_start_cleanup (void *cls,
74 GNUNET_OS_process_destroy (ns->start_proc); 77 GNUNET_OS_process_destroy (ns->start_proc);
75 ns->start_proc = NULL; 78 ns->start_proc = NULL;
76 } 79 }
80 GNUNET_free (ns);
77} 81}
78 82
79 83
@@ -108,6 +112,8 @@ child_completed_callback (void *cls,
108 } 112 }
109 else 113 else
110 { 114 {
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 "Child completed with an error!\n");
111 ns->finished = GNUNET_SYSERR; 117 ns->finished = GNUNET_SYSERR;
112 } 118 }
113 GNUNET_OS_process_destroy (ns->start_proc); 119 GNUNET_OS_process_destroy (ns->start_proc);
diff --git a/src/testbed/testbed_api_cmd_netjail_start_testbed.c b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
index dc8196e94..585825cbc 100644
--- a/src/testbed/testbed_api_cmd_netjail_start_testbed.c
+++ b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
@@ -28,13 +28,36 @@
28#include "gnunet_testbed_ng_service.h" 28#include "gnunet_testbed_ng_service.h"
29#include "testbed_api.h" 29#include "testbed_api.h"
30#include "testbed_api_hosts.h" 30#include "testbed_api_hosts.h"
31#include "testbed_helper.h"
31 32
32#define NETJAIL_EXEC_SCRIPT "./netjail_exec.sh" 33#define NETJAIL_EXEC_SCRIPT "./netjail_exec.sh"
33 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
34 53
35struct NetJailState 54struct NetJailState
36{ 55{
37 56
57 struct HelperMessage *hp_messages_head;
58
59 struct HelperMessage *hp_messages_tail;
60
38 /** 61 /**
39 * The process handle 62 * The process handle
40 */ 63 */
@@ -64,6 +87,8 @@ struct NetJailState
64 87
65 unsigned int number_of_testbeds_started; 88 unsigned int number_of_testbeds_started;
66 89
90 unsigned int number_of_peers_started;
91
67 /** 92 /**
68 * The host where the controller is running 93 * The host where the controller is running
69 */ 94 */
@@ -112,7 +137,7 @@ netjail_exec_traits (void *cls,
112{ 137{
113 struct NetJailState *ns = cls; 138 struct NetJailState *ns = cls;
114 struct GNUNET_HELPER_Handle **helper = ns->helper; 139 struct GNUNET_HELPER_Handle **helper = ns->helper;
115 struct GNUNET_TESTBED_Host **hosts = ns->host; 140 struct HelperMessage *hp_messages_head = ns->hp_messages_head;
116 141
117 142
118 struct GNUNET_TESTING_Trait traits[] = { 143 struct GNUNET_TESTING_Trait traits[] = {
@@ -123,8 +148,8 @@ netjail_exec_traits (void *cls,
123 }, 148 },
124 { 149 {
125 .index = 1, 150 .index = 1,
126 .trait_name = "hosts", 151 .trait_name = "hp_msgs_head",
127 .ptr = (const void *) hosts, 152 .ptr = (const void *) hp_messages_head,
128 }, 153 },
129 GNUNET_TESTING_trait_end () 154 GNUNET_TESTING_trait_end ()
130 }; 155 };
@@ -162,13 +187,14 @@ GNUNET_TESTBED_get_trait_helper_handles (const struct
162 * @return #GNUNET_OK on success. 187 * @return #GNUNET_OK on success.
163 */ 188 */
164int 189int
165GNUNET_TESTBED_get_trait_hosts (const struct 190GNUNET_TESTBED_get_trait_helper_messages (const struct
166 GNUNET_TESTING_Command *cmd, 191 GNUNET_TESTING_Command *cmd,
167 struct GNUNET_TESTBED_Host ***hosts) 192 struct HelperMessage ***
193 hp_messages_head)
168{ 194{
169 return cmd->traits (cmd->cls, 195 return cmd->traits (cmd->cls,
170 (const void **) hosts, 196 (const void **) hp_messages_head,
171 "hosts", 197 "hp_msgs_head",
172 (unsigned int) 1); 198 (unsigned int) 1);
173} 199}
174 200
@@ -214,15 +240,32 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
214{ 240{
215 struct TestbedCount *tbc = cls; 241 struct TestbedCount *tbc = cls;
216 struct NetJailState *ns = tbc->ns; 242 struct NetJailState *ns = tbc->ns;
217 struct GNUNET_TESTBED_Host *host = ns->host[tbc->count - 1]; 243 struct HelperMessage *hp_msg;
244
245 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
246 {
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
248 "helper_mst tbc->count: %d\n",
249 tbc->count);
250 // GNUNET_TESTBED_extract_cfg (host, message);
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "Received message from helper.\n");
253 ns->number_of_testbeds_started++;
254 }
255 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
256 message->type))
257 {
258 ns->number_of_peers_started++;
259 }
260 else
261 {
262 hp_msg = GNUNET_new (struct HelperMessage);
263 hp_msg->bytes_msg = message->size;
264 memcpy (&hp_msg[1], message, message->size);
265 GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail,
266 hp_msg);
267 }
218 268
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
220 "helper_mst tbc->count: %d\n",
221 tbc->count);
222 GNUNET_TESTBED_extract_cfg (host, message);
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Received message from helper.\n");
225 ns->number_of_testbeds_started++;
226 return GNUNET_OK; 269 return GNUNET_OK;
227} 270}
228 271
@@ -235,6 +278,32 @@ exp_cb (void *cls)
235} 278}
236 279
237 280
281static struct GNUNET_CMDS_HelperInit *
282create_helper_init_msg_ (char *m_char,
283 char *n_char,
284 const char *plugin_name)
285{
286 struct GNUNET_CMDS_HelperInit *msg;
287 uint16_t plugin_name_len;
288 uint16_t msg_size;
289
290 GNUNET_assert (NULL != plugin_name);
291 plugin_name_len = strlen (plugin_name);
292 msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "msg_size: %d \n",
295 msg_size);
296 msg = GNUNET_malloc (msg_size);
297 msg->header.size = htons (msg_size);
298 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
299 msg->plugin_name_size = htons (plugin_name_len);
300 GNUNET_memcpy ((char *) &msg[1],
301 plugin_name,
302 plugin_name_len);
303 return msg;
304}
305
306
238static void 307static void
239start_testbed (struct NetJailState *ns, struct 308start_testbed (struct NetJailState *ns, struct
240 GNUNET_CONFIGURATION_Handle *config, 309 GNUNET_CONFIGURATION_Handle *config,
@@ -242,13 +311,15 @@ start_testbed (struct NetJailState *ns, struct
242 char *m_char) 311 char *m_char)
243{ 312{
244 struct GNUNET_CONFIGURATION_Handle *cfg; 313 struct GNUNET_CONFIGURATION_Handle *cfg;
245 struct GNUNET_TESTBED_HelperInit *msg; 314 struct GNUNET_CMDS_HelperInit *msg;
246 struct TestbedCount *tbc; 315 struct TestbedCount *tbc;
247 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, 316 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
248 m_char,
249 n_char, 317 n_char,
318 m_char,
250 GNUNET_OS_get_libexec_binary_path ( 319 GNUNET_OS_get_libexec_binary_path (
251 HELPER_CMDS_BINARY), 320 HELPER_CMDS_BINARY),
321 ns->global_n,
322 ns->local_m,
252 NULL}; 323 NULL};
253 unsigned int m = atoi (m_char); 324 unsigned int m = atoi (m_char);
254 unsigned int n = atoi (n_char); 325 unsigned int n = atoi (n_char);
@@ -291,7 +362,9 @@ start_testbed (struct NetJailState *ns, struct
291 362
292 struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1]; 363 struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1];
293 364
294 msg = GNUNET_TESTBED_create_helper_init_msg_ ("127.0.0.1", NULL, config); 365 msg = create_helper_init_msg_ (m_char,
366 n_char,
367 "libgnunet_plugin_testcmd");
295 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); 368 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
296 369
297 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( 370 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
@@ -300,6 +373,10 @@ start_testbed (struct NetJailState *ns, struct
300 GNUNET_NO, 373 GNUNET_NO,
301 &clear_msg, 374 &clear_msg,
302 tbc)); 375 tbc));
376
377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
378 "Message send!\n");
379
303 if (NULL == ns->shandle[tbc->count - 1]) 380 if (NULL == ns->shandle[tbc->count - 1])
304 { 381 {
305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 382 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -348,14 +425,49 @@ netjail_start_finish (void *cls,
348{ 425{
349 unsigned int ret = GNUNET_NO; 426 unsigned int ret = GNUNET_NO;
350 struct NetJailState *ns = cls; 427 struct NetJailState *ns = cls;
428 unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n);
429 struct GNUNET_CMDS_PEER_STARTED *reply;
430 size_t msg_length;
431 struct GNUNET_HELPER_Handle *helper;
432 struct TestbedCount *tbc;
351 433
352 if (ns->number_of_testbeds_started == atoi (ns->local_m) * atoi ( 434 if (ns->number_of_testbeds_started == total_number)
353 ns->global_n))
354 { 435 {
355 ret = GNUNET_YES; 436 /* ret = GNUNET_YES;
356 cont (cont_cls); 437 cont (cont_cls);*/
357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
358 "All helper started!\n"); 439 "All helpers started!\n");
440 }
441
442 if (ns->number_of_peers_started == total_number)
443 {
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
445 "All peers started!\n");
446
447 for (int i = 1; i <= atoi (ns->global_n); i++) {
448 for (int j = 1; j <= atoi (ns->local_m); j++)
449 {
450 tbc = GNUNET_new (struct TestbedCount);
451 tbc->ns = ns;
452 tbc->count = (j - 1) * atoi (ns->local_m) + i + atoi (ns->global_n)
453 * atoi (ns->local_m);
454 helper = ns->helper[tbc->count - 1];
455 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
456 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
457 reply->header.type = htons (
458 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
459 reply->header.size = htons ((uint16_t) msg_length);
460
461 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
462
463 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
464 helper,
465 &reply->header,
466 GNUNET_NO,
467 &clear_msg,
468 tbc));
469 }
470 }
359 } 471 }
360 return ret; 472 return ret;
361} 473}
diff --git a/src/testbed/testbed_api_cmd_send_peer_ready.c b/src/testbed/testbed_api_cmd_send_peer_ready.c
new file mode 100644
index 000000000..8a82b23a8
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_send_peer_ready.c
@@ -0,0 +1,102 @@
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
30
31struct SendPeerReadyState
32{
33 TESTBED_CMD_HELPER_write_cb write_message;
34
35 struct GNUNET_CMDS_PEER_STARTED *reply;
36};
37
38
39static int
40send_peer_ready_traits (void *cls,
41 const void **ret,
42 const char *trait,
43 unsigned int index)
44{
45 return GNUNET_OK;
46}
47
48
49static void
50send_peer_ready_cleanup (void *cls,
51 const struct GNUNET_TESTING_Command *cmd)
52{
53 struct SendPeerReadyState *sprs = cls;
54
55 GNUNET_free (sprs->reply);
56 GNUNET_free (sprs);
57}
58
59
60static void
61send_peer_ready_run (void *cls,
62 const struct GNUNET_TESTING_Command *cmd,
63 struct GNUNET_TESTING_Interpreter *is)
64{
65 /*struct SendPeerReadyState *sprs = cls;
66 struct GNUNET_CMDS_PEER_STARTED *reply;
67 size_t msg_length;
68
69 msg_length = sizeof(struct GNUNET_CMDS_PEER_STARTED);
70 reply = GNUNET_new (struct GNUNET_CMDS_PEER_STARTED);
71 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED);
72 reply->header.size = htons ((uint16_t) msg_length);
73 sprs->reply = reply;
74 sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);*/
75}
76
77
78/**
79 * Create command.
80 *
81 * @param label name for command.
82 * @return command.
83 */
84struct GNUNET_TESTING_Command
85GNUNET_TESTING_cmd_send_peer_ready (const char *label,
86 TESTBED_CMD_HELPER_write_cb write_message)
87{
88 struct SendPeerReadyState *sprs;
89
90 sprs = GNUNET_new (struct SendPeerReadyState);
91 sprs->write_message = write_message;
92
93 struct GNUNET_TESTING_Command cmd = {
94 .cls = sprs,
95 .label = label,
96 .run = &send_peer_ready_run,
97 .cleanup = &send_peer_ready_cleanup,
98 .traits = &send_peer_ready_traits
99 };
100
101 return cmd;
102}
diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h
index 817ad559d..84059fef2 100644
--- a/src/testbed/testbed_helper.h
+++ b/src/testbed/testbed_helper.h
@@ -84,6 +84,52 @@ 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
87GNUNET_NETWORK_STRUCT_END 133GNUNET_NETWORK_STRUCT_END
88#endif 134#endif
89/* end of testbed_helper.h */ 135/* end of testbed_helper.h */
diff --git a/src/testing/testing_api_cmd_start_peer.c b/src/testing/testing_api_cmd_start_peer.c
new file mode 100644
index 000000000..0f8c618b8
--- /dev/null
+++ b/src/testing/testing_api_cmd_start_peer.c
@@ -0,0 +1,296 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30
31struct StartPeerState
32{
33 /**
34 * Receive callback
35 */
36 struct GNUNET_MQ_MessageHandler *handlers;
37
38 const char *cfgname;
39
40 /**
41 * Peer's configuration
42 */
43 struct GNUNET_CONFIGURATION_Handle *cfg;
44
45 struct GNUNET_TESTING_Peer *peer;
46
47 /**
48 * Peer identity
49 */
50 struct GNUNET_PeerIdentity id;
51
52 /**
53 * Peer's transport service handle
54 */
55 struct GNUNET_TRANSPORT_CoreHandle *th;
56
57 /**
58 * Application handle
59 */
60 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
61
62 /**
63 * Peer's PEERSTORE Handle
64 */
65 struct GNUNET_PEERSTORE_Handle *ph;
66
67 /**
68 * Hello get task
69 */
70 struct GNUNET_SCHEDULER_Task *rh_task;
71
72 /**
73 * Peer's transport get hello handle to retrieve peer's HELLO message
74 */
75 struct GNUNET_PEERSTORE_IterateContext *pic;
76
77 /**
78 * Hello
79 */
80 char *hello;
81
82 /**
83 * Hello size
84 */
85 size_t hello_size;
86
87 char *m;
88
89 char *n;
90
91 unsigned int finished;
92};
93
94
95static void
96retrieve_hello (void *cls);
97
98static void
99hello_iter_cb (void *cb_cls,
100 const struct GNUNET_PEERSTORE_Record *record,
101 const char *emsg)
102{
103 struct StartPeerState *sps = cb_cls;
104 if (NULL == record)
105 {
106 sps->pic = NULL;
107 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, p);
108 return;
109 }
110 // Check record type et al?
111 sps->hello_size = record->value_size;
112 sps->hello = GNUNET_malloc (sps->hello_size);
113 memcpy (sps->hello, record->value, sps->hello_size);
114 p->hello[p->hello_size - 1] = '\0';
115
116 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
117 sps->pic = NULL;
118 sps->finished = GNUNET_YES;
119}
120
121
122static void
123retrieve_hello (void *cls)
124{
125 struct StartPeerState *sps = cls;
126 sps->rh_task = NULL;
127 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
128 "transport",
129 &sps->id,
130 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
131 hello_iter_cb,
132 sps);
133
134}
135
136static int
137start_peer_finish (void *cls,
138 GNUNET_SCHEDULER_TaskCallback cont,
139 void *cont_cls)
140{
141 struct StartPeerState *sps = cls;
142
143 return sps->finished;
144}
145
146
147static void
148start_peer_run (void *cls,
149 const struct GNUNET_TESTING_Command *cmd,
150 struct GNUNET_TESTING_Interpreter *is)
151{
152 struct StartPeerState *sps = cls;
153 char *emsg = NULL;
154 struct GNUNET_PeerIdentity dummy;
155
156 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
157 {
158 LOG (GNUNET_ERROR_TYPE_ERROR,
159 "File not found: `%s'\n",
160 cfgname);
161 return NULL;
162 }
163
164 if (NULL != handlers)
165 {
166 for (i = 0; NULL != handlers[i].cb; i++)
167 ;
168 sps->handlers = GNUNET_new_array (i + 1,
169 struct GNUNET_MQ_MessageHandler);
170 GNUNET_memcpy (sps->handlers,
171 handlers,
172 i * sizeof(struct GNUNET_MQ_MessageHandler));
173 }
174 sps->cfg = GNUNET_CONFIGURATION_create ();
175 GNUNET_assert (GNUNET_OK ==
176 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
177 if (GNUNET_SYSERR ==
178 GNUNET_TESTING_configuration_create (tl_system,
179 sps->cfg))
180 {
181 LOG (GNUNET_ERROR_TYPE_ERROR,
182 "Testing library failed to create unique configuration based on `%s'\n",
183 sps->cfgname);
184 GNUNET_CONFIGURATION_destroy (sps->cfg);
185 GNUNET_TESTING_interpreter_fail ();
186 }
187
188 sps->peer = GNUNET_TESTING_peer_configure (tth->tl_system,
189 p->cfg,
190 p->no,
191 NULL,
192 &emsg);
193 if (NULL == sps->peer)
194 {
195 LOG (GNUNET_ERROR_TYPE_ERROR,
196 "Testing library failed to create unique configuration based on `%s': `%s'\n",
197 cfgname,
198 emsg);
199 GNUNET_free (emsg);
200 GNUNET_TESTING_interpreter_fail ();
201 }
202
203 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
204 {
205 LOG (GNUNET_ERROR_TYPE_ERROR,
206 "Testing library failed to create unique configuration based on `%s'\n",
207 cfgname);
208 GNUNET_free (emsg);
209 GNUNET_TESTING_interpreter_fail ();
210 }
211
212 memset (&dummy,
213 '\0',
214 sizeof(dummy));
215 GNUNET_TESTING_peer_get_identity (sps->peer,
216 &sps->id);
217 if (0 == memcmp (&dummy,
218 &sps->id,
219 sizeof(struct GNUNET_PeerIdentity)))
220 {
221 LOG (GNUNET_ERROR_TYPE_ERROR,
222 "Testing library failed to obtain peer identity for peer %s_%s\n",
223 p->no);
224 GNUNET_free (emsg);
225 GNUNET_TESTING_interpreter_fail ();
226 }
227 LOG (GNUNET_ERROR_TYPE_DEBUG,
228 "Peer %u configured with identity `%s'\n",
229 p->no,
230 GNUNET_i2s_full (&p->id));
231 sps->th = GNUNET_TRANSPORT_core_connect (p->cfg,
232 NULL,
233 handlers,
234 p,
235 &notify_connect,
236 &notify_disconnect);
237 if (NULL == sps->th)
238 {
239 LOG (GNUNET_ERROR_TYPE_ERROR,
240 "Failed to connect to transport service for peer `%s': `%s'\n",
241 cfgname,
242 emsg);
243 GNUNET_free (emsg);
244 GNUNET_TESTING_interpreter_fail ();
245 }
246 sps->ph = GNUNET_PEERSTORE_connect (p->cfg);
247 if (NULL == sps->th)
248 {
249 LOG (GNUNET_ERROR_TYPE_ERROR,
250 "Failed to connect to peerstore service for peer `%s': `%s'\n",
251 cfgname,
252 emsg);
253 GNUNET_free (emsg);
254 GNUNET_TESTING_interpreter_fail ();
255 }
256 sps->ah = GNUNET_TRANSPORT_application_init (p->cfg);
257 if (NULL == sps->ah)
258 {
259 LOG (GNUNET_ERROR_TYPE_ERROR,
260 "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
261 cfgname,
262 emsg);
263 GNUNET_free (emsg);
264 GNUNET_TESTING_interpreter_fail ();
265 }
266 p->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, p);
267}
268
269
270/**
271 * Create command.
272 *
273 * @param label name for command.
274 * @return command.
275 */
276struct GNUNET_TESTING_Command
277GNUNET_TESTING_cmd_start_peer (const char *label,
278 char *m,
279 char *n)
280{
281 struct StartPeerState *sps;
282
283 sps = GNUNET_new (struct StartPeerState);
284 sps->m = m;
285 sps->n = n;
286
287 struct GNUNET_TESTING_Command cmd = {
288 .cls = sps,
289 .label = label,
290 .run = &start_peer_run,
291 .cleanup = &start_peer_cleanup,
292 .traits = &start_peer_traits
293 };
294
295 return cmd;
296}
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
new file mode 100644
index 000000000..ad0aa4f90
--- /dev/null
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -0,0 +1,110 @@
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_system_create.c
23 * @brief cmd to create a testing system handle.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30struct TestSystemState
31{
32 struct GNUNET_TESTING_System *test_system;
33};
34
35
36static void
37system_create_run (void *cls,
38 const struct GNUNET_TESTING_Command *cmd,
39 struct GNUNET_TESTING_Interpreter *is)
40{
41 struct TestSystemState *tss = cls;
42
43 tss->test_system = GNUNET_TESTING_system_create (tss->testdir,
44 NULL,
45 NULL,
46 NULL);
47}
48
49static int
50system_create_traits (void *cls,
51 const void **ret,
52 const char *trait,
53 unsigned int index)
54{
55 struct TestSystemState *tss = cls;
56 struct GNUNET_TESTING_System *test_system = tss->test_system;
57
58 struct GNUNET_TESTING_Trait traits[] = {
59 {
60 .index = 0,
61 .trait_name = "test_system",
62 .ptr = (const void *) test_system,
63 },
64 GNUNET_TESTING_trait_end ()
65 };
66
67 return GNUNET_TESTING_get_trait (traits,
68 ret,
69 trait,
70 index);
71}
72
73
74int
75GNUNET_TESTING_get_trait_test_system (const struct
76 GNUNET_TESTING_Command *cmd,
77 struct GNUNET_TESTING_System **test_system)
78{
79 return cmd->traits (cmd->cls,
80 (const void **) test_system,
81 "test_system",
82 (unsigned int) 0);
83}
84
85
86/**
87 * Create command.
88 *
89 * @param label name for command.
90 * @return command.
91 */
92struct GNUNET_TESTING_Command
93GNUNET_TESTING_cmd_system_create (const char *label,
94 const char *testdir)
95{
96 struct TestSystemState *tss;
97
98 tss = GNUNET_new (struct TestSystemState);
99 tss->testdir = testdir;
100
101 struct GNUNET_TESTING_Command cmd = {
102 .cls = tss,
103 .label = label,
104 .run = &system_create_run,
105 .cleanup = &system_create_cleanup,
106 .traits = &system_create_traits
107 };
108
109 return cmd;
110}
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 49ed48063..7b7dc010a 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -332,6 +332,9 @@ GNUNET_TESTING_interpreter_fail ()
332 if (GNUNET_SYSERR == is->result) 332 if (GNUNET_SYSERR == is->result)
333 return; /* ignore, we already failed! */ 333 return; /* ignore, we already failed! */
334 334
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "interpreter_fail!\n");
337
335 if (NULL != cmd) 338 if (NULL != cmd)
336 { 339 {
337 while (GNUNET_TESTING_cmd_is_batch (cmd)) 340 while (GNUNET_TESTING_cmd_is_batch (cmd))
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index a7ee563d7..00c4a08dd 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -463,7 +463,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct
463 GNUNET_free (emsg); 463 GNUNET_free (emsg);
464 return NULL; 464 return NULL;
465 } 465 }
466 GNUNET_free (emsg); 466
467 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer)) 467 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
468 { 468 {
469 LOG (GNUNET_ERROR_TYPE_ERROR, 469 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -508,6 +508,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct
508 cfgname, 508 cfgname,
509 emsg); 509 emsg);
510 GNUNET_TRANSPORT_TESTING_stop_peer (p); 510 GNUNET_TRANSPORT_TESTING_stop_peer (p);
511 GNUNET_free (emsg);
511 return NULL; 512 return NULL;
512 } 513 }
513 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 514 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
@@ -518,6 +519,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct
518 cfgname, 519 cfgname,
519 emsg); 520 emsg);
520 GNUNET_TRANSPORT_TESTING_stop_peer (p); 521 GNUNET_TRANSPORT_TESTING_stop_peer (p);
522 GNUNET_free (emsg);
521 return NULL; 523 return NULL;
522 } 524 }
523 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 525 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c
index 482aaf4d0..6d41ec098 100644
--- a/src/transport/transport-testing2.c
+++ b/src/transport/transport-testing2.c
@@ -478,7 +478,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct
478 GNUNET_free (emsg); 478 GNUNET_free (emsg);
479 return NULL; 479 return NULL;
480 } 480 }
481 GNUNET_free (emsg); 481
482 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer)) 482 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
483 { 483 {
484 LOG (GNUNET_ERROR_TYPE_ERROR, 484 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -520,6 +520,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct
520 cfgname, 520 cfgname,
521 emsg); 521 emsg);
522 GNUNET_TRANSPORT_TESTING_stop_peer (p); 522 GNUNET_TRANSPORT_TESTING_stop_peer (p);
523 GNUNET_free (emsg);
523 return NULL; 524 return NULL;
524 } 525 }
525 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 526 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
@@ -530,6 +531,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct
530 cfgname, 531 cfgname,
531 emsg); 532 emsg);
532 GNUNET_TRANSPORT_TESTING_stop_peer (p); 533 GNUNET_TRANSPORT_TESTING_stop_peer (p);
534 GNUNET_free (emsg);
533 return NULL; 535 return NULL;
534 } 536 }
535 p->ph = GNUNET_PEERSTORE_connect (p->cfg); 537 p->ph = GNUNET_PEERSTORE_connect (p->cfg);
diff --git a/src/util/child_management.c b/src/util/child_management.c
index 11fde4a61..3afd682b9 100644
--- a/src/util/child_management.c
+++ b/src/util/child_management.c
@@ -29,6 +29,11 @@
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_child_management_lib.h" 30#include "gnunet_child_management_lib.h"
31 31
32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
36
32 37
33/** 38/**
34 * Struct which defines a Child Wait handle 39 * Struct which defines a Child Wait handle
@@ -87,7 +92,7 @@ maint_child_death (void *cls)
87 (void) cls; 92 (void) cls;
88 sig_task = NULL; 93 sig_task = NULL;
89 94
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 95 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
91 "Received SIGCHLD.\n"); 96 "Received SIGCHLD.\n");
92 97
93 /* drain pipe */ 98 /* drain pipe */
@@ -193,6 +198,9 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc,
193{ 198{
194 struct GNUNET_ChildWaitHandle *cwh; 199 struct GNUNET_ChildWaitHandle *cwh;
195 200
201 LOG (GNUNET_ERROR_TYPE_ERROR,
202 "Adding child!\n");
203
196 child_management_start (); 204 child_management_start ();
197 cwh = GNUNET_new (struct GNUNET_ChildWaitHandle); 205 cwh = GNUNET_new (struct GNUNET_ChildWaitHandle);
198 cwh->proc = proc; 206 cwh->proc = proc;
@@ -216,9 +224,12 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc,
216void 224void
217GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh) 225GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh)
218{ 226{
219 GNUNET_CONTAINER_DLL_remove (cwh_head, 227 if ((NULL != cwh_head))
220 cwh_tail, 228 {
221 cwh); 229 GNUNET_CONTAINER_DLL_remove (cwh_head,
230 cwh_tail,
231 cwh);
232 }
222 if (NULL == cwh_head) 233 if (NULL == cwh_head)
223 { 234 {
224 child_management_done (); 235 child_management_done ();