diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-07 11:54:45 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-07 11:54:45 +0000 |
commit | 551918714f3b0de77ef729e23bf80e1313d3c99d (patch) | |
tree | aa1b1257950390c201e957ab9f9cb2a7bb28c23c /src/testbed | |
parent | 37bdc65ff066590a0dcaa695135f9a5689f991b6 (diff) | |
download | gnunet-551918714f3b0de77ef729e23bf80e1313d3c99d.tar.gz gnunet-551918714f3b0de77ef729e23bf80e1313d3c99d.zip |
use new MST API in helper
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-helper-testbed.c | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c index f3c56eb9d..6368fb74b 100644 --- a/src/testbed/gnunet-helper-testbed.c +++ b/src/testbed/gnunet-helper-testbed.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -99,7 +99,7 @@ static struct GNUNET_TESTING_System *test_system; | |||
99 | /** | 99 | /** |
100 | * Our message stream tokenizer | 100 | * Our message stream tokenizer |
101 | */ | 101 | */ |
102 | struct GNUNET_SERVER_MessageStreamTokenizer *tokenizer; | 102 | struct GNUNET_MessageStreamTokenizer *tokenizer; |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Disk handle from stdin | 105 | * Disk handle from stdin |
@@ -134,7 +134,7 @@ static struct GNUNET_SCHEDULER_Task *write_task_id; | |||
134 | /** | 134 | /** |
135 | * Task to kill the child | 135 | * Task to kill the child |
136 | */ | 136 | */ |
137 | static struct GNUNET_SCHEDULER_Task * child_death_task_id; | 137 | static struct GNUNET_SCHEDULER_Task *child_death_task_id; |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * Are we done reading messages from stdin? | 140 | * Are we done reading messages from stdin? |
@@ -184,7 +184,7 @@ shutdown_task (void *cls) | |||
184 | (void) GNUNET_DISK_file_close (stdin_fd); | 184 | (void) GNUNET_DISK_file_close (stdin_fd); |
185 | if (NULL != stdout_fd) | 185 | if (NULL != stdout_fd) |
186 | (void) GNUNET_DISK_file_close (stdout_fd); | 186 | (void) GNUNET_DISK_file_close (stdout_fd); |
187 | GNUNET_SERVER_mst_destroy (tokenizer); | 187 | GNUNET_MST_destroy (tokenizer); |
188 | tokenizer = NULL; | 188 | tokenizer = NULL; |
189 | if (NULL != testbed) | 189 | if (NULL != testbed) |
190 | { | 190 | { |
@@ -288,16 +288,15 @@ child_death_task (void *cls) | |||
288 | * Functions with this signature are called whenever a | 288 | * Functions with this signature are called whenever a |
289 | * complete message is received by the tokenizer. | 289 | * complete message is received by the tokenizer. |
290 | * | 290 | * |
291 | * Do not call #GNUNET_SERVER_mst_destroy() in this callback | 291 | * Do not call #GNUNET_mst_destroy() in this callback |
292 | * | 292 | * |
293 | * @param cls closure | 293 | * @param cls identification of the client |
294 | * @param client identification of the client | ||
295 | * @param message the actual message | 294 | * @param message the actual message |
296 | * | 295 | * |
297 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | 296 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing |
298 | */ | 297 | */ |
299 | static int | 298 | static int |
300 | tokenizer_cb (void *cls, void *client, | 299 | tokenizer_cb (void *cls, |
301 | const struct GNUNET_MessageHeader *message) | 300 | const struct GNUNET_MessageHeader *message) |
302 | { | 301 | { |
303 | const struct GNUNET_TESTBED_HelperInit *msg; | 302 | const struct GNUNET_TESTBED_HelperInit *msg; |
@@ -322,7 +321,8 @@ tokenizer_cb (void *cls, void *client, | |||
322 | if ((sizeof (struct GNUNET_TESTBED_HelperInit) >= msize) || | 321 | if ((sizeof (struct GNUNET_TESTBED_HelperInit) >= msize) || |
323 | (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type))) | 322 | (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type))) |
324 | { | 323 | { |
325 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); | 324 | LOG (GNUNET_ERROR_TYPE_WARNING, |
325 | "Received unexpected message -- exiting\n"); | ||
326 | goto error; | 326 | goto error; |
327 | } | 327 | } |
328 | msg = (const struct GNUNET_TESTBED_HelperInit *) message; | 328 | msg = (const struct GNUNET_TESTBED_HelperInit *) message; |
@@ -499,8 +499,11 @@ read_task (void *cls) | |||
499 | ssize_t sread; | 499 | ssize_t sread; |
500 | 500 | ||
501 | read_task_id = NULL; | 501 | read_task_id = NULL; |
502 | sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf)); | 502 | sread = GNUNET_DISK_file_read (stdin_fd, |
503 | if ((GNUNET_SYSERR == sread) || (0 == sread)) | 503 | buf, |
504 | sizeof (buf)); | ||
505 | if ( (GNUNET_SYSERR == sread) || | ||
506 | (0 == sread) ) | ||
504 | { | 507 | { |
505 | LOG_DEBUG ("STDIN closed\n"); | 508 | LOG_DEBUG ("STDIN closed\n"); |
506 | GNUNET_SCHEDULER_shutdown (); | 509 | GNUNET_SCHEDULER_shutdown (); |
@@ -515,18 +518,24 @@ read_task (void *cls) | |||
515 | } | 518 | } |
516 | LOG_DEBUG ("Read %u bytes\n", | 519 | LOG_DEBUG ("Read %u bytes\n", |
517 | (unsigned int) sread); | 520 | (unsigned int) sread); |
521 | /* FIXME: could introduce a GNUNET_MST_read2 to read | ||
522 | directly from 'stdin_fd' and save a memcpy() here */ | ||
518 | if (GNUNET_OK != | 523 | if (GNUNET_OK != |
519 | GNUNET_SERVER_mst_receive (tokenizer, NULL, buf, sread, GNUNET_NO, | 524 | GNUNET_MST_from_buffer (tokenizer, |
520 | GNUNET_NO)) | 525 | buf, |
526 | sread, | ||
527 | GNUNET_NO, | ||
528 | GNUNET_NO)) | ||
521 | { | 529 | { |
522 | GNUNET_break (0); | 530 | GNUNET_break (0); |
523 | GNUNET_SCHEDULER_shutdown (); | 531 | GNUNET_SCHEDULER_shutdown (); |
524 | return; | 532 | return; |
525 | } | 533 | } |
526 | read_task_id = /* No timeout while reading */ | 534 | read_task_id /* No timeout while reading */ |
527 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 535 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
528 | stdin_fd, | 536 | stdin_fd, |
529 | &read_task, NULL); | 537 | &read_task, |
538 | NULL); | ||
530 | } | 539 | } |
531 | 540 | ||
532 | 541 | ||
@@ -545,7 +554,7 @@ run (void *cls, | |||
545 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 554 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
546 | { | 555 | { |
547 | LOG_DEBUG ("Starting testbed helper...\n"); | 556 | LOG_DEBUG ("Starting testbed helper...\n"); |
548 | tokenizer = GNUNET_SERVER_mst_create (&tokenizer_cb, NULL); | 557 | tokenizer = GNUNET_MST_create (&tokenizer_cb, NULL); |
549 | stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); | 558 | stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); |
550 | stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); | 559 | stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); |
551 | read_task_id = | 560 | read_task_id = |
@@ -583,10 +592,10 @@ sighandler_child_death () | |||
583 | * @return return code | 592 | * @return return code |
584 | */ | 593 | */ |
585 | int | 594 | int |
586 | main (int argc, char **argv) | 595 | main (int argc, |
596 | char **argv) | ||
587 | { | 597 | { |
588 | struct GNUNET_SIGNAL_Context *shc_chld; | 598 | struct GNUNET_SIGNAL_Context *shc_chld; |
589 | |||
590 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 599 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
591 | GNUNET_GETOPT_OPTION_END | 600 | GNUNET_GETOPT_OPTION_END |
592 | }; | 601 | }; |
@@ -599,12 +608,14 @@ main (int argc, char **argv) | |||
599 | GNUNET_break (0); | 608 | GNUNET_break (0); |
600 | return 1; | 609 | return 1; |
601 | } | 610 | } |
602 | shc_chld = | 611 | shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, |
603 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 612 | &sighandler_child_death); |
604 | ret = | 613 | ret = GNUNET_PROGRAM_run (argc, argv, |
605 | GNUNET_PROGRAM_run (argc, argv, "gnunet-helper-testbed", | 614 | "gnunet-helper-testbed", |
606 | "Helper for starting gnunet-service-testbed", options, | 615 | "Helper for starting gnunet-service-testbed", |
607 | &run, NULL); | 616 | options, |
617 | &run, | ||
618 | NULL); | ||
608 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 619 | GNUNET_SIGNAL_handler_uninstall (shc_chld); |
609 | shc_chld = NULL; | 620 | shc_chld = NULL; |
610 | GNUNET_DISK_pipe_close (sigpipe); | 621 | GNUNET_DISK_pipe_close (sigpipe); |