aboutsummaryrefslogtreecommitdiff
path: root/src/testing/gnunet-cmds-helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/gnunet-cmds-helper.c')
-rw-r--r--src/testing/gnunet-cmds-helper.c190
1 files changed, 47 insertions, 143 deletions
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 5705f46c2..21ea33888 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -47,7 +47,7 @@
47 47
48/** 48/**
49 * Generic logging shortcut 49 * Generic logging shortcut
50 */ 50testing_api_cmd_block_until_all_peers_started.c */
51#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 51#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
52 52
53/** 53/**
@@ -74,27 +74,71 @@ struct Plugin
74 */ 74 */
75 struct GNUNET_TESTING_PluginFunctions *api; 75 struct GNUNET_TESTING_PluginFunctions *api;
76 76
77 /**
78 * IP address of the specific node the helper is running for.
79 *
80 */
77 char *node_ip; 81 char *node_ip;
78 82
83 /**
84 * Name of the test case plugin.
85 *
86 */
79 char *plugin_name; 87 char *plugin_name;
80 88
89 /**
90 * The number of namespaces
91 *
92 */
81 char *global_n; 93 char *global_n;
82 94
95 /**
96 * The number of local nodes per namespace.
97 *
98 */
83 char *local_m; 99 char *local_m;
84 100
101 /**
102 * The number of the namespace this node is in.
103 *
104 */
85 char *n; 105 char *n;
86 106
107 /**
108 * The number of the node in the namespace.
109 *
110 */
87 char *m; 111 char *m;
88}; 112};
89 113
114/**
115 * Struct with information about a specific node and the whole network namespace setup.
116 *
117 */
90struct NodeIdentifier 118struct NodeIdentifier
91{ 119{
120 /**
121 * The number of the namespace this node is in.
122 *
123 */
92 char *n; 124 char *n;
93 125
126 /**
127 * The number of the node in the namespace.
128 *
129 */
94 char *m; 130 char *m;
95 131
132 /**
133 * The number of namespaces
134 *
135 */
96 char *global_n; 136 char *global_n;
97 137
138 /**
139 * The number of local nodes per namespace.
140 *
141 */
98 char *local_m; 142 char *local_m;
99}; 143};
100 144
@@ -162,11 +206,6 @@ static struct GNUNET_SCHEDULER_Task *read_task_id;
162static struct GNUNET_SCHEDULER_Task *write_task_id; 206static struct GNUNET_SCHEDULER_Task *write_task_id;
163 207
164/** 208/**
165 * Task to kill the child
166 */
167static struct GNUNET_SCHEDULER_Task *child_death_task_id;
168
169/**
170 * Are we done reading messages from stdin? 209 * Are we done reading messages from stdin?
171 */ 210 */
172static int done_reading; 211static int done_reading;
@@ -187,8 +226,6 @@ shutdown_task (void *cls)
187{ 226{
188 227
189 LOG_DEBUG ("Shutting down.\n"); 228 LOG_DEBUG ("Shutting down.\n");
190 LOG (GNUNET_ERROR_TYPE_ERROR,
191 "Shutting down tokenizer!\n");
192 229
193 if (NULL != read_task_id) 230 if (NULL != read_task_id)
194 { 231 {
@@ -204,11 +241,6 @@ shutdown_task (void *cls)
204 GNUNET_free (wc->data); 241 GNUNET_free (wc->data);
205 GNUNET_free (wc); 242 GNUNET_free (wc);
206 } 243 }
207 if (NULL != child_death_task_id)
208 {
209 GNUNET_SCHEDULER_cancel (child_death_task_id);
210 child_death_task_id = NULL;
211 }
212 if (NULL != stdin_fd) 244 if (NULL != stdin_fd)
213 (void) GNUNET_DISK_file_close (stdin_fd); 245 (void) GNUNET_DISK_file_close (stdin_fd);
214 if (NULL != stdout_fd) 246 if (NULL != stdout_fd)
@@ -235,9 +267,6 @@ write_task (void *cls)
235 struct WriteContext *wc = cls; 267 struct WriteContext *wc = cls;
236 ssize_t bytes_wrote; 268 ssize_t bytes_wrote;
237 269
238 LOG (GNUNET_ERROR_TYPE_ERROR,
239 "Writing data!\n");
240
241 GNUNET_assert (NULL != wc); 270 GNUNET_assert (NULL != wc);
242 write_task_id = NULL; 271 write_task_id = NULL;
243 bytes_wrote = GNUNET_DISK_file_write (stdout_fd, 272 bytes_wrote = GNUNET_DISK_file_write (stdout_fd,
@@ -256,12 +285,8 @@ write_task (void *cls)
256 { 285 {
257 GNUNET_free (wc->data); 286 GNUNET_free (wc->data);
258 GNUNET_free (wc); 287 GNUNET_free (wc);
259 LOG (GNUNET_ERROR_TYPE_ERROR,
260 "Written successfully!\n");
261 return; 288 return;
262 } 289 }
263 LOG (GNUNET_ERROR_TYPE_ERROR,
264 "Written data!\n");
265 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 290 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
266 stdout_fd, 291 stdout_fd,
267 &write_task, 292 &write_task,
@@ -270,39 +295,14 @@ write_task (void *cls)
270 295
271 296
272/** 297/**
273 * Task triggered whenever we receive a SIGCHLD (child 298 * Callback to write a message to the master loop.
274 * process died).
275 * 299 *
276 * @param cls closure, NULL if we need to self-restart
277 */ 300 */
278/*static void
279child_death_task (void *cls)
280{
281 const struct GNUNET_DISK_FileHandle *pr;
282 char c[16];
283
284 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
285 child_death_task_id = NULL;
286 // consume the signal
287 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c)));
288 LOG_DEBUG ("Got SIGCHLD\n");
289
290 LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n");
291 child_death_task_id =
292 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
293 pr,
294 &child_death_task,
295 NULL);
296}*/
297
298
299static void 301static void
300write_message (struct GNUNET_MessageHeader *message, size_t msg_length) 302write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
301{ 303{
302 struct WriteContext *wc; 304 struct WriteContext *wc;
303 305
304 LOG (GNUNET_ERROR_TYPE_ERROR,
305 "enter write_message!\n");
306 wc = GNUNET_new (struct WriteContext); 306 wc = GNUNET_new (struct WriteContext);
307 wc->length = msg_length; 307 wc->length = msg_length;
308 wc->data = message; 308 wc->data = message;
@@ -311,38 +311,10 @@ write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
311 stdout_fd, 311 stdout_fd,
312 &write_task, 312 &write_task,
313 wc); 313 wc);
314 LOG (GNUNET_ERROR_TYPE_ERROR,
315 "leave write_message!\n");
316} 314}
317 315
318 316
319/** 317/**
320 * Function to run the test cases.
321 *
322 * @param cls plugin to use.
323 *
324 */
325/*static void
326run_plugin (void *cls)
327{
328 struct Plugin *plugin = cls;
329 char *router_ip;
330 char *node_ip;
331
332 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) + 1);
333 strcpy (router_ip, ROUTER_BASE_IP);
334 strcat (router_ip, plugin->m);
335
336 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
337 strcat (node_ip, NODE_BASE_IP);
338 strcat (node_ip, plugin->n);
339
340 plugin->api->start_testcase (&write_message, router_ip, node_ip);
341
342}*/
343
344
345/**
346 * Functions with this signature are called whenever a 318 * Functions with this signature are called whenever a
347 * complete message is received by the tokenizer. 319 * complete message is received by the tokenizer.
348 * 320 *
@@ -368,9 +340,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
368 char *router_ip; 340 char *router_ip;
369 char *node_ip; 341 char *node_ip;
370 342
371 LOG (GNUNET_ERROR_TYPE_ERROR,
372 "tokenizer \n");
373
374 msize = ntohs (message->size); 343 msize = ntohs (message->size);
375 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type)) 344 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
376 { 345 {
@@ -390,23 +359,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
390 359
391 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd"); 360 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd");
392 361
393 LOG (GNUNET_ERROR_TYPE_ERROR,
394 "plugin_name: %s \n",
395 plugin_name);
396
397 // cmd_binary_process = GNUNET_OS_start_process (
398 /*GNUNET_OS_INHERIT_STD_ERR verbose? ,
399 NULL,
400 NULL,
401 NULL,
402 binary,
403 plugin_name,
404 ni->global_n,
405 ni->local_m,
406 ni->n,
407 ni->m,
408 NULL);*/
409
410 plugin = GNUNET_new (struct Plugin); 362 plugin = GNUNET_new (struct Plugin);
411 plugin->api = GNUNET_PLUGIN_load (plugin_name, 363 plugin->api = GNUNET_PLUGIN_load (plugin_name,
412 NULL); 364 NULL);
@@ -429,51 +381,15 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
429 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, 381 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
430 plugin->n, plugin->local_m); 382 plugin->n, plugin->local_m);
431 383
432 LOG (GNUNET_ERROR_TYPE_ERROR,
433 "We got here!\n");
434
435 /*if (NULL == cmd_binary_process)
436 {
437 LOG (GNUNET_ERROR_TYPE_ERROR,
438 "Starting plugin failed!\n");
439 return GNUNET_SYSERR;
440 }*/
441
442 LOG (GNUNET_ERROR_TYPE_ERROR,
443 "We got here 2!\n");
444
445 LOG (GNUNET_ERROR_TYPE_ERROR,
446 "global_n: %s local_n: %s n: %s m: %s.\n",
447 ni->global_n,
448 ni->local_m,
449 ni->n,
450 ni->m);
451
452 LOG (GNUNET_ERROR_TYPE_ERROR,
453 "We got here 3!\n");
454
455 GNUNET_free (binary); 384 GNUNET_free (binary);
456 385
457 // done_reading = GNUNET_YES;
458
459 msg_length = sizeof(struct GNUNET_CMDS_HelperReply); 386 msg_length = sizeof(struct GNUNET_CMDS_HelperReply);
460 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply); 387 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply);
461 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY); 388 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY);
462 reply->header.size = htons ((uint16_t) msg_length); 389 reply->header.size = htons ((uint16_t) msg_length);
463 390
464 LOG (GNUNET_ERROR_TYPE_ERROR,
465 "We got here 4!\n");
466
467 write_message ((struct GNUNET_MessageHeader *) reply, msg_length); 391 write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
468 392
469 LOG (GNUNET_ERROR_TYPE_ERROR,
470 "We got here 5!\n");
471
472 /*child_death_task_id = GNUNET_SCHEDULER_add_read_file (
473 GNUNET_TIME_UNIT_FOREVER_REL,
474 GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
475 &child_death_task,
476 NULL);*/
477 return GNUNET_OK; 393 return GNUNET_OK;
478 } 394 }
479 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( 395 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
@@ -514,8 +430,6 @@ read_task (void *cls)
514 if ((GNUNET_SYSERR == sread) || (0 == sread)) 430 if ((GNUNET_SYSERR == sread) || (0 == sread))
515 { 431 {
516 LOG_DEBUG ("STDIN closed\n"); 432 LOG_DEBUG ("STDIN closed\n");
517 LOG (GNUNET_ERROR_TYPE_ERROR,
518 "tokenizer shutting down during reading!\n");
519 GNUNET_SCHEDULER_shutdown (); 433 GNUNET_SCHEDULER_shutdown ();
520 return; 434 return;
521 } 435 }
@@ -529,8 +443,6 @@ read_task (void *cls)
529 return; 443 return;
530 } 444 }
531 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread); 445 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread);
532 LOG (GNUNET_ERROR_TYPE_ERROR,
533 "Read %u bytes\n", (unsigned int) sread);
534 /* FIXME: could introduce a GNUNET_MST_read2 to read 446 /* FIXME: could introduce a GNUNET_MST_read2 to read
535 directly from 'stdin_fd' and save a memcpy() here */ 447 directly from 'stdin_fd' and save a memcpy() here */
536 if (GNUNET_OK != 448 if (GNUNET_OK !=
@@ -624,13 +536,6 @@ main (int argc, char **argv)
624 ni->n = argv[3]; 536 ni->n = argv[3];
625 ni->m = argv[4]; 537 ni->m = argv[4];
626 538
627 LOG (GNUNET_ERROR_TYPE_ERROR,
628 "global_n: %s local_n: %s n: %s m: %s.\n",
629 ni->global_n,
630 ni->local_m,
631 ni->n,
632 ni->m);
633
634 status = GNUNET_OK; 539 status = GNUNET_OK;
635 if (NULL == 540 if (NULL ==
636 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) 541 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
@@ -647,8 +552,7 @@ main (int argc, char **argv)
647 options, 552 options,
648 &run, 553 &run,
649 ni); 554 ni);
650 LOG (GNUNET_ERROR_TYPE_ERROR, 555
651 "run finished\n");
652 GNUNET_SIGNAL_handler_uninstall (shc_chld); 556 GNUNET_SIGNAL_handler_uninstall (shc_chld);
653 shc_chld = NULL; 557 shc_chld = NULL;
654 GNUNET_DISK_pipe_close (sigpipe); 558 GNUNET_DISK_pipe_close (sigpipe);