From d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 8 Sep 2019 12:33:09 +0000 Subject: uncrustify as demanded. --- src/testing/gnunet-testing.c | 470 ++++----- src/testing/list-keys.c | 112 +-- src/testing/test_testing_peerstartup.c | 73 +- src/testing/test_testing_peerstartup2.c | 140 +-- src/testing/test_testing_portreservation.c | 68 +- src/testing/test_testing_servicestartup.c | 30 +- src/testing/test_testing_sharedservices.c | 104 +- src/testing/testing.c | 1474 ++++++++++++++-------------- 8 files changed, 1233 insertions(+), 1238 deletions(-) (limited to 'src/testing') diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c index bc402227c..834cf6cea 100644 --- a/src/testing/gnunet-testing.c +++ b/src/testing/gnunet-testing.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file testing/gnunet-testing.c @@ -28,7 +28,7 @@ #include "gnunet_testing_lib.h" -#define LOG(kind, ...) GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from(kind, "gnunet-testing", __VA_ARGS__) /** @@ -84,7 +84,7 @@ static struct GNUNET_TESTING_Peer *my_peer; static int -create_unique_cfgs (const char *template, const unsigned int no) +create_unique_cfgs(const char *template, const unsigned int no) { struct GNUNET_TESTING_System *system; int fail; @@ -93,76 +93,76 @@ create_unique_cfgs (const char *template, const unsigned int no) struct GNUNET_CONFIGURATION_Handle *cfg_new; struct GNUNET_CONFIGURATION_Handle *cfg_tmpl; - if (GNUNET_NO == GNUNET_DISK_file_test (template)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Configuration template `%s': file not found\n", - create_cfg_template); - return 1; - } - cfg_tmpl = GNUNET_CONFIGURATION_create (); + if (GNUNET_NO == GNUNET_DISK_file_test(template)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Configuration template `%s': file not found\n", + create_cfg_template); + return 1; + } + cfg_tmpl = GNUNET_CONFIGURATION_create(); /* load template */ if ((create_cfg_template != NULL) && - (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, create_cfg_template))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not load template `%s'\n", - create_cfg_template); - GNUNET_CONFIGURATION_destroy (cfg_tmpl); + (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, create_cfg_template))) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Could not load template `%s'\n", + create_cfg_template); + GNUNET_CONFIGURATION_destroy(cfg_tmpl); - return 1; - } + return 1; + } /* load defaults */ - if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not load template `%s'\n", - create_cfg_template); - GNUNET_CONFIGURATION_destroy (cfg_tmpl); - return 1; - } + if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, NULL)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Could not load template `%s'\n", + create_cfg_template); + GNUNET_CONFIGURATION_destroy(cfg_tmpl); + return 1; + } fail = GNUNET_NO; system = - GNUNET_TESTING_system_create ("testing", NULL /* controller */, NULL, NULL); + GNUNET_TESTING_system_create("testing", NULL /* controller */, NULL, NULL); for (cur = 0; cur < no; cur++) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating configuration no. %u \n", - cur); - if (create_cfg_template != NULL) - GNUNET_asprintf (&cur_file, "%04u-%s", cur, create_cfg_template); - else - GNUNET_asprintf (&cur_file, "%04u%s", cur, ".conf"); - - cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl); - if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg_new)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not create another configuration\n"); - GNUNET_CONFIGURATION_destroy (cfg_new); - fail = GNUNET_YES; - break; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Creating configuration no. %u \n", + cur); + if (create_cfg_template != NULL) + GNUNET_asprintf(&cur_file, "%04u-%s", cur, create_cfg_template); + else + GNUNET_asprintf(&cur_file, "%04u%s", cur, ".conf"); + + cfg_new = GNUNET_CONFIGURATION_dup(cfg_tmpl); + if (GNUNET_OK != GNUNET_TESTING_configuration_create(system, cfg_new)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Could not create another configuration\n"); + GNUNET_CONFIGURATION_destroy(cfg_new); + fail = GNUNET_YES; + break; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Writing configuration no. %u to file `%s' \n", + cur, + cur_file); + if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg_new, cur_file)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to write configuration no. %u \n", + cur); + fail = GNUNET_YES; + } + GNUNET_CONFIGURATION_destroy(cfg_new); + GNUNET_free(cur_file); + if (GNUNET_YES == fail) + break; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Writing configuration no. %u to file `%s' \n", - cur, - cur_file); - if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg_new, cur_file)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to write configuration no. %u \n", - cur); - fail = GNUNET_YES; - } - GNUNET_CONFIGURATION_destroy (cfg_new); - GNUNET_free (cur_file); - if (GNUNET_YES == fail) - break; - } - GNUNET_CONFIGURATION_destroy (cfg_tmpl); - GNUNET_TESTING_system_destroy (system, GNUNET_NO); + GNUNET_CONFIGURATION_destroy(cfg_tmpl); + GNUNET_TESTING_system_destroy(system, GNUNET_NO); if (GNUNET_YES == fail) return 1; return 0; @@ -170,40 +170,40 @@ create_unique_cfgs (const char *template, const unsigned int no) static int -create_hostkeys (const unsigned int no) +create_hostkeys(const unsigned int no) { struct GNUNET_TESTING_System *system; struct GNUNET_PeerIdentity id; struct GNUNET_DISK_FileHandle *fd; struct GNUNET_CRYPTO_EddsaPrivateKey *pk; - system = GNUNET_TESTING_system_create ("testing", NULL, NULL, NULL); - pk = GNUNET_TESTING_hostkey_get (system, create_no, &id); + system = GNUNET_TESTING_system_create("testing", NULL, NULL, NULL); + pk = GNUNET_TESTING_hostkey_get(system, create_no, &id); if (NULL == pk) - { - fprintf (stderr, - _ ("Could not extract hostkey %u (offset too large?)\n"), - create_no); - GNUNET_TESTING_system_destroy (system, GNUNET_YES); - return 1; - } - (void) GNUNET_DISK_directory_create_for_file (create_hostkey); + { + fprintf(stderr, + _("Could not extract hostkey %u (offset too large?)\n"), + create_no); + GNUNET_TESTING_system_destroy(system, GNUNET_YES); + return 1; + } + (void)GNUNET_DISK_directory_create_for_file(create_hostkey); fd = - GNUNET_DISK_file_open (create_hostkey, - GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); - GNUNET_assert (fd != NULL); - ret = GNUNET_DISK_file_write (fd, - pk, - sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); - GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "transport-testing", - "Wrote hostkey to file: `%s'\n", - create_hostkey); - GNUNET_free (pk); - GNUNET_TESTING_system_destroy (system, GNUNET_YES); + GNUNET_DISK_file_open(create_hostkey, + GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); + GNUNET_assert(fd != NULL); + ret = GNUNET_DISK_file_write(fd, + pk, + sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey)); + GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd)); + GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, + "transport-testing", + "Wrote hostkey to file: `%s'\n", + create_hostkey); + GNUNET_free(pk); + GNUNET_TESTING_system_destroy(system, GNUNET_YES); return 0; } @@ -215,25 +215,25 @@ create_hostkeys (const unsigned int no) * @param cls unused */ static void -cleanup (void *cls) +cleanup(void *cls) { if (NULL != tmpfilename) - { - if (0 != unlink (tmpfilename)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "unlink", - tmpfilename); - } + { + if (0 != unlink(tmpfilename)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, + "unlink", + tmpfilename); + } if (NULL != tid) - { - GNUNET_SCHEDULER_cancel (tid); - tid = NULL; - } + { + GNUNET_SCHEDULER_cancel(tid); + tid = NULL; + } if (NULL != fh) - { - GNUNET_DISK_file_close (fh); - fh = NULL; - } + { + GNUNET_DISK_file_close(fh); + fh = NULL; + } } @@ -243,39 +243,42 @@ cleanup (void *cls) * @param cls unused */ static void -stdin_cb (void *cls) +stdin_cb(void *cls) { int c; tid = NULL; - c = getchar (); + c = getchar(); switch (c) - { - case EOF: - case 'q': - GNUNET_SCHEDULER_shutdown (); - return; - case 'r': - if (GNUNET_OK != GNUNET_TESTING_peer_stop (my_peer)) - LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to stop the peer\n"); - if (GNUNET_OK != GNUNET_TESTING_peer_start (my_peer)) - LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start the peer\n"); - printf ("restarted\n"); - fflush (stdout); - break; - case '\n': - case '\r': - /* ignore whitespace */ - break; - default: - fprintf (stderr, - _ ("Unknown command, use 'q' to quit or 'r' to restart peer\n")); - break; - } - tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - fh, - &stdin_cb, - NULL); + { + case EOF: + case 'q': + GNUNET_SCHEDULER_shutdown(); + return; + + case 'r': + if (GNUNET_OK != GNUNET_TESTING_peer_stop(my_peer)) + LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to stop the peer\n"); + if (GNUNET_OK != GNUNET_TESTING_peer_start(my_peer)) + LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to start the peer\n"); + printf("restarted\n"); + fflush(stdout); + break; + + case '\n': + case '\r': + /* ignore whitespace */ + break; + + default: + fprintf(stderr, + _("Unknown command, use 'q' to quit or 'r' to restart peer\n")); + break; + } + tid = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, + fh, + &stdin_cb, + NULL); } @@ -288,32 +291,32 @@ stdin_cb (void *cls) * @param peer handle to the peer */ static void -testing_main (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +testing_main(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { my_peer = peer; - if (NULL == (tmpfilename = GNUNET_DISK_mktemp ("gnunet-testing"))) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } + if (NULL == (tmpfilename = GNUNET_DISK_mktemp("gnunet-testing"))) + { + GNUNET_break(0); + GNUNET_SCHEDULER_shutdown(); + return; + } if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_write ((struct GNUNET_CONFIGURATION_Handle *) cfg, - tmpfilename)) - { - GNUNET_break (0); - return; - } - printf ("ok\n%s\n", tmpfilename); - fflush (stdout); - GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); - fh = GNUNET_DISK_get_handle_from_native (stdin); - tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - fh, - &stdin_cb, - NULL); + GNUNET_CONFIGURATION_write((struct GNUNET_CONFIGURATION_Handle *)cfg, + tmpfilename)) + { + GNUNET_break(0); + return; + } + printf("ok\n%s\n", tmpfilename); + fflush(stdout); + GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); + fh = GNUNET_DISK_get_handle_from_native(stdin); + tid = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, + fh, + &stdin_cb, + NULL); } @@ -326,43 +329,43 @@ testing_main (void *cls, * @param cfg configuration */ static void -run_no_scheduler (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run_no_scheduler(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { if (NULL != run_service_name) - { - ret = GNUNET_TESTING_service_run ("gnunet_service_test", - run_service_name, - cfgfile, - &testing_main, - NULL); - return; - } + { + ret = GNUNET_TESTING_service_run("gnunet_service_test", + run_service_name, + cfgfile, + &testing_main, + NULL); + return; + } if (GNUNET_YES == create_cfg) - { - if (create_no > 0) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating %u configuration files based on template `%s'\n", - create_no, - create_cfg_template); - ret = create_unique_cfgs (create_cfg_template, create_no); + if (create_no > 0) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Creating %u configuration files based on template `%s'\n", + create_no, + create_cfg_template); + ret = create_unique_cfgs(create_cfg_template, create_no); + } + else + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Missing arguments! \n"); + ret = 1; + } } - else + if (NULL != create_hostkey) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing arguments! \n"); - ret = 1; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Extracting hostkey %u\n", create_no); + ret = create_hostkeys(create_no); } - } - if (NULL != create_hostkey) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Extracting hostkey %u\n", create_no); - ret = create_hostkeys (create_no); - } - GNUNET_free_non_null (create_cfg_template); + GNUNET_free_non_null(create_cfg_template); } @@ -374,45 +377,46 @@ run_no_scheduler (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = - {GNUNET_GETOPT_option_flag ('C', - "cfg", - gettext_noop ( - "create unique configuration files"), - &create_cfg), - GNUNET_GETOPT_option_string ( - 'k', - "key", - "FILENAME", - gettext_noop ("extract hostkey file from pre-computed hostkey list"), - &create_hostkey), - - GNUNET_GETOPT_option_uint ( - 'n', - "number", - "NUMBER", - gettext_noop ( - "number of unique configuration files to create, or number of the hostkey to extract"), - &create_no), - - - GNUNET_GETOPT_option_string ('t', - "template", - "FILENAME", - gettext_noop ("configuration template"), - &create_cfg_template), - - GNUNET_GETOPT_option_string ( - 'r', - "run", - "SERVICE", - gettext_noop ( - "run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"), - &run_service_name), - GNUNET_GETOPT_OPTION_END}; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + { GNUNET_GETOPT_option_flag('C', + "cfg", + gettext_noop( + "create unique configuration files"), + &create_cfg), + GNUNET_GETOPT_option_string( + 'k', + "key", + "FILENAME", + gettext_noop("extract hostkey file from pre-computed hostkey list"), + &create_hostkey), + + GNUNET_GETOPT_option_uint( + 'n', + "number", + "NUMBER", + gettext_noop( + "number of unique configuration files to create, or number of the hostkey to extract"), + &create_no), + + + GNUNET_GETOPT_option_string('t', + "template", + "FILENAME", + gettext_noop("configuration template"), + &create_cfg_template), + + GNUNET_GETOPT_option_string( + 'r', + "run", + "SERVICE", + gettext_noop( + "run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"), + &run_service_name), + GNUNET_GETOPT_OPTION_END }; + + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; /* Run without scheduler, because we may want to call @@ -421,18 +425,18 @@ main (int argc, char *const *argv) * but beware when extending gnunet-testing. */ ret = (GNUNET_OK == - GNUNET_PROGRAM_run2 (argc, - argv, - "gnunet-testing", - gettext_noop ( - "Command line tool to access the testing library"), - options, - &run_no_scheduler, - NULL, - GNUNET_YES)) - ? ret - : 1; - GNUNET_free ((void *) argv); + GNUNET_PROGRAM_run2(argc, + argv, + "gnunet-testing", + gettext_noop( + "Command line tool to access the testing library"), + options, + &run_no_scheduler, + NULL, + GNUNET_YES)) + ? ret + : 1; + GNUNET_free((void *)argv); return ret; } diff --git a/src/testing/list-keys.c b/src/testing/list-keys.c index 39a48d071..37b880b49 100644 --- a/src/testing/list-keys.c +++ b/src/testing/list-keys.c @@ -15,10 +15,10 @@ static int result; * @param cfg the configuration file handle */ static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *config) +run(void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *config) { char *idfile; struct GNUNET_DISK_FileHandle *f; @@ -31,79 +31,79 @@ run (void *cls, unsigned int nmax; if ((NULL == args) || (NULL == args[0])) - { - fprintf (stderr, "Need the hostkey file\n"); - return; - } + { + fprintf(stderr, "Need the hostkey file\n"); + return; + } idfile = args[0]; if (GNUNET_OK != - GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES)) - { - GNUNET_break (0); - return; - } + GNUNET_DISK_file_size(idfile, &fsize, GNUNET_YES, GNUNET_YES)) + { + GNUNET_break(0); + return; + } if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) - { - fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), idfile); - return; - } - f = GNUNET_DISK_file_open (idfile, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + { + fprintf(stderr, _("Incorrect hostkey file format: %s\n"), idfile); + return; + } + f = GNUNET_DISK_file_open(idfile, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (NULL == f) - { - GNUNET_break (0); - return; - } - data = GNUNET_DISK_file_map (f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize); + { + GNUNET_break(0); + return; + } + data = GNUNET_DISK_file_map(f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize); if (NULL == data) - { - GNUNET_break (0); - GNUNET_DISK_file_close (f); - return; - } + { + GNUNET_break(0); + GNUNET_DISK_file_close(f); + return; + } nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; for (cnt = nskip; cnt < (nskip + nkeys); cnt++) - { - if (nskip + cnt >= nmax) { - printf ("Max keys %u reached\n", nmax); - break; + if (nskip + cnt >= nmax) + { + printf("Max keys %u reached\n", nmax); + break; + } + GNUNET_memcpy(&pkey, + data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE), + GNUNET_TESTING_HOSTKEYFILESIZE); + GNUNET_CRYPTO_eddsa_key_get_public(&pkey, &id.public_key); + printf("Key %u: %s\n", cnt, GNUNET_i2s_full(&id)); } - GNUNET_memcpy (&pkey, - data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE), - GNUNET_TESTING_HOSTKEYFILESIZE); - GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key); - printf ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id)); - } result = GNUNET_OK; - GNUNET_DISK_file_unmap (map); - GNUNET_DISK_file_close (f); + GNUNET_DISK_file_unmap(map); + GNUNET_DISK_file_close(f); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { struct GNUNET_GETOPT_CommandLineOption option[] = - {GNUNET_GETOPT_option_uint ('n', - "num-keys", - "COUNT", - gettext_noop ("list COUNT number of keys"), - &nkeys), - GNUNET_GETOPT_OPTION_END}; + { GNUNET_GETOPT_option_uint('n', + "num-keys", + "COUNT", + gettext_noop("list COUNT number of keys"), + &nkeys), + GNUNET_GETOPT_OPTION_END }; int ret; result = GNUNET_SYSERR; nkeys = 10; ret = - GNUNET_PROGRAM_run (argc, - argv, - "list-keys", - "Lists the peer IDs corresponding to the given keys file\n", - option, - &run, - NULL); + GNUNET_PROGRAM_run(argc, + argv, + "list-keys", + "Lists the peer IDs corresponding to the given keys file\n", + option, + &run, + NULL); if (GNUNET_OK != ret) return 1; if (GNUNET_SYSERR == result) diff --git a/src/testing/test_testing_peerstartup.c b/src/testing/test_testing_peerstartup.c index 241bc63a7..a03e6b596 100644 --- a/src/testing/test_testing_peerstartup.c +++ b/src/testing/test_testing_peerstartup.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -29,8 +29,8 @@ #include "gnunet_util_lib.h" #include "gnunet_testing_lib.h" -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * The status of the test @@ -40,8 +40,7 @@ int status; /** * The testing context */ -struct TestingContext -{ +struct TestingContext { /** * The testing system */ @@ -65,21 +64,21 @@ struct TestingContext * @param cls the testing context */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { struct TestingContext *test_ctx = cls; - GNUNET_assert (NULL != test_ctx); + GNUNET_assert(NULL != test_ctx); if (NULL != test_ctx->peer) - { - (void) GNUNET_TESTING_peer_stop (test_ctx->peer); - GNUNET_TESTING_peer_destroy (test_ctx->peer); - } + { + (void)GNUNET_TESTING_peer_stop(test_ctx->peer); + GNUNET_TESTING_peer_destroy(test_ctx->peer); + } if (NULL != test_ctx->cfg) - GNUNET_CONFIGURATION_destroy (test_ctx->cfg); + GNUNET_CONFIGURATION_destroy(test_ctx->cfg); if (NULL != test_ctx->system) - GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); - GNUNET_free (test_ctx); + GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES); + GNUNET_free(test_ctx); } @@ -87,42 +86,42 @@ do_shutdown (void *cls) * Main point of test execution */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct TestingContext *test_ctx; char *emsg; struct GNUNET_PeerIdentity id; - test_ctx = GNUNET_new (struct TestingContext); + test_ctx = GNUNET_new(struct TestingContext); test_ctx->system = - GNUNET_TESTING_system_create ("test-gnunet-testing", - "127.0.0.1", NULL, NULL); + GNUNET_TESTING_system_create("test-gnunet-testing", + "127.0.0.1", NULL, NULL); emsg = NULL; if (NULL == test_ctx->system) goto end; - test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); + test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg); test_ctx->peer = - GNUNET_TESTING_peer_configure (test_ctx->system, - test_ctx->cfg, - 0, &id, &emsg); + GNUNET_TESTING_peer_configure(test_ctx->system, + test_ctx->cfg, + 0, &id, &emsg); if (NULL == test_ctx->peer) - { - if (NULL != emsg) - printf ("Test failed upon error: %s", emsg); - goto end; - } - if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) + { + if (NULL != emsg) + printf("Test failed upon error: %s", emsg); + goto end; + } + if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer)) goto end; status = GNUNET_OK; - end: - GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); - GNUNET_free_non_null (emsg); +end: + GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx); + GNUNET_free_non_null(emsg); } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END @@ -130,10 +129,10 @@ int main (int argc, char *argv[]) status = GNUNET_SYSERR; if (GNUNET_OK != - GNUNET_PROGRAM_run (argc, argv, - "test_testing_peerstartup", - "test case for peerstartup using new testing library", - options, &run, NULL)) + GNUNET_PROGRAM_run(argc, argv, + "test_testing_peerstartup", + "test case for peerstartup using new testing library", + options, &run, NULL)) return 1; return (GNUNET_OK == status) ? 0 : 1; } diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c index a077ddcc2..80a3b719a 100644 --- a/src/testing/test_testing_peerstartup2.c +++ b/src/testing/test_testing_peerstartup2.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -29,19 +29,19 @@ #include "gnunet_util_lib.h" #include "gnunet_testing_lib.h" -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) #define FAIL_TEST(cond) \ do { \ - if (!(cond)) { \ - GNUNET_break (0); \ - if (GNUNET_OK == status) { \ - status = GNUNET_SYSERR; \ - } \ - } \ - } while (0) \ + if (!(cond)) { \ + GNUNET_break(0); \ + if (GNUNET_OK == status) { \ + status = GNUNET_SYSERR; \ + } \ + } \ + } while (0) \ /** @@ -52,8 +52,7 @@ int status; /** * The testing context */ -struct TestingContext -{ +struct TestingContext { /** * The testing system */ @@ -83,18 +82,17 @@ struct TestingContext static void -do_shutdown2 (void *cls) +do_shutdown2(void *cls) { struct TestingContext *test_ctx = cls; if (NULL != test_ctx->peer) - GNUNET_TESTING_peer_destroy (test_ctx->peer); + GNUNET_TESTING_peer_destroy(test_ctx->peer); if (NULL != test_ctx->cfg) - GNUNET_CONFIGURATION_destroy (test_ctx->cfg); + GNUNET_CONFIGURATION_destroy(test_ctx->cfg); if (NULL != test_ctx->system) - GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); - GNUNET_free (test_ctx); - + GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES); + GNUNET_free(test_ctx); } @@ -104,27 +102,29 @@ do_shutdown2 (void *cls) * @param cls the testing context */ static void -do_shutdown (void *cls); +do_shutdown(void *cls); static void -peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) +peer_status_cb(void *cls, struct GNUNET_TESTING_Peer *peer, int success) { struct TestingContext *test_ctx = cls; switch (test_ctx->state) - { - case PEER_INIT: - FAIL_TEST (0); - break; - case PEER_STARTED: - FAIL_TEST (GNUNET_YES == success); - test_ctx->state = PEER_STOPPED; - GNUNET_SCHEDULER_add_now (&do_shutdown2, cls); - break; - case PEER_STOPPED: - FAIL_TEST (0); - } + { + case PEER_INIT: + FAIL_TEST(0); + break; + + case PEER_STARTED: + FAIL_TEST(GNUNET_YES == success); + test_ctx->state = PEER_STOPPED; + GNUNET_SCHEDULER_add_now(&do_shutdown2, cls); + break; + + case PEER_STOPPED: + FAIL_TEST(0); + } } @@ -134,20 +134,20 @@ peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) * @param cls the testing context */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { struct TestingContext *test_ctx = cls; - GNUNET_assert (NULL != test_ctx); + GNUNET_assert(NULL != test_ctx); if (NULL != test_ctx->peer) - { - FAIL_TEST (GNUNET_OK == - GNUNET_TESTING_peer_stop_async (test_ctx->peer, + { + FAIL_TEST(GNUNET_OK == + GNUNET_TESTING_peer_stop_async(test_ctx->peer, &peer_status_cb, test_ctx)); - } + } else - do_shutdown2 (test_ctx); + do_shutdown2(test_ctx); } @@ -155,51 +155,51 @@ do_shutdown (void *cls) * Main point of test execution */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct TestingContext *test_ctx; char *emsg; struct GNUNET_PeerIdentity id; - test_ctx = GNUNET_new (struct TestingContext); + test_ctx = GNUNET_new(struct TestingContext); test_ctx->system = - GNUNET_TESTING_system_create ("test-gnunet-testing", - "127.0.0.1", NULL, NULL); + GNUNET_TESTING_system_create("test-gnunet-testing", + "127.0.0.1", NULL, NULL); emsg = NULL; if (NULL == test_ctx->system) goto end; - test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); + test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg); test_ctx->peer = - GNUNET_TESTING_peer_configure (test_ctx->system, - test_ctx->cfg, - 0, &id, &emsg); + GNUNET_TESTING_peer_configure(test_ctx->system, + test_ctx->cfg, + 0, &id, &emsg); if (NULL == test_ctx->peer) - { - if (NULL != emsg) - printf ("Test failed upon error: %s", emsg); - goto end; - } - if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) + { + if (NULL != emsg) + printf("Test failed upon error: %s", emsg); + goto end; + } + if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer)) goto end; test_ctx->state = PEER_STARTED; - FAIL_TEST (GNUNET_OK == - GNUNET_TESTING_peer_stop_async (test_ctx->peer, - &peer_status_cb, - test_ctx)); - GNUNET_TESTING_peer_stop_async_cancel (test_ctx->peer); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &do_shutdown, test_ctx); + FAIL_TEST(GNUNET_OK == + GNUNET_TESTING_peer_stop_async(test_ctx->peer, + &peer_status_cb, + test_ctx)); + GNUNET_TESTING_peer_stop_async_cancel(test_ctx->peer); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, + &do_shutdown, test_ctx); return; - end: - FAIL_TEST (0); - GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); - GNUNET_free_non_null (emsg); +end: + FAIL_TEST(0); + GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx); + GNUNET_free_non_null(emsg); } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END @@ -207,10 +207,10 @@ int main (int argc, char *argv[]) status = GNUNET_OK; if (GNUNET_OK != - GNUNET_PROGRAM_run (argc, argv, - "test_testing_new_peerstartup", - "test case for peerstartup using new testing library", - options, &run, NULL)) + GNUNET_PROGRAM_run(argc, argv, + "test_testing_new_peerstartup", + "test case for peerstartup using new testing library", + options, &run, NULL)) return 1; return (GNUNET_OK == status) ? 0 : 1; } diff --git a/src/testing/test_testing_portreservation.c b/src/testing/test_testing_portreservation.c index 86ecc494a..308d462b7 100644 --- a/src/testing/test_testing_portreservation.c +++ b/src/testing/test_testing_portreservation.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -29,8 +29,8 @@ #include "gnunet_util_lib.h" #include "gnunet_testing_lib.h" -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** * The status of the test @@ -41,46 +41,46 @@ int status; * Main point of test execution */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_TESTING_System *system; uint16_t new_port1; uint16_t new_port2; uint16_t old_port1; - system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new", - "localhost", NULL, NULL); - GNUNET_assert (NULL != system); - new_port1 = GNUNET_TESTING_reserve_port (system); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Reserved TCP port %u\n", new_port1); + system = GNUNET_TESTING_system_create("/tmp/gnunet-testing-new", + "localhost", NULL, NULL); + GNUNET_assert(NULL != system); + new_port1 = GNUNET_TESTING_reserve_port(system); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Reserved TCP port %u\n", new_port1); if (0 == new_port1) goto end; - new_port2 = GNUNET_TESTING_reserve_port (system); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Reserved TCP port %u\n", new_port2); + new_port2 = GNUNET_TESTING_reserve_port(system); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Reserved TCP port %u\n", new_port2); if (0 == new_port2) goto end; - GNUNET_assert (new_port1 != new_port2); - GNUNET_TESTING_release_port (system, new_port1); + GNUNET_assert(new_port1 != new_port2); + GNUNET_TESTING_release_port(system, new_port1); old_port1 = new_port1; new_port1 = 0; - new_port1 = GNUNET_TESTING_reserve_port (system); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Reserved TCP port %u\n", new_port1); - GNUNET_assert (0 != new_port1); - GNUNET_assert (old_port1 == new_port1); - GNUNET_TESTING_release_port (system, new_port1); - GNUNET_TESTING_release_port (system, new_port2); + new_port1 = GNUNET_TESTING_reserve_port(system); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Reserved TCP port %u\n", new_port1); + GNUNET_assert(0 != new_port1); + GNUNET_assert(old_port1 == new_port1); + GNUNET_TESTING_release_port(system, new_port1); + GNUNET_TESTING_release_port(system, new_port2); status = GNUNET_OK; - end: - GNUNET_TESTING_system_destroy (system, GNUNET_YES); +end: + GNUNET_TESTING_system_destroy(system, GNUNET_YES); } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END @@ -88,14 +88,14 @@ int main (int argc, char *argv[]) status = GNUNET_SYSERR; if (GNUNET_OK != - GNUNET_PROGRAM_run (argc, - argv, - "test_testing_new_portreservation", - "test case for testing port reservation routines" - " from the new testing library API", - options, - &run, - NULL)) + GNUNET_PROGRAM_run(argc, + argv, + "test_testing_new_portreservation", + "test case for testing port reservation routines" + " from the new testing library API", + options, + &run, + NULL)) return 1; return (GNUNET_OK == status) ? 0 : 1; } diff --git a/src/testing/test_testing_servicestartup.c b/src/testing/test_testing_servicestartup.c index e0cadfb06..18786ea86 100644 --- a/src/testing/test_testing_servicestartup.c +++ b/src/testing/test_testing_servicestartup.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -28,8 +28,8 @@ #include "gnunet_testing_lib.h" -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) /** @@ -45,28 +45,28 @@ static int test_success; * @param cfg the configuration with which the current testing service is run */ static void -test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +test_run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - GNUNET_assert (NULL == cls); - GNUNET_assert (NULL != cfg); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Service arm started successfully\n"); + GNUNET_assert(NULL == cls); + GNUNET_assert(NULL != cfg); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Service arm started successfully\n"); test_success = GNUNET_YES; - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } /** * The main point of execution */ -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { test_success = GNUNET_NO; - GNUNET_assert (0 == GNUNET_TESTING_service_run ("test-testing-servicestartup", - "arm", - "test_testing_defaults.conf", - &test_run, - NULL)); + GNUNET_assert(0 == GNUNET_TESTING_service_run("test-testing-servicestartup", + "arm", + "test_testing_defaults.conf", + &test_run, + NULL)); return (GNUNET_YES == test_success) ? 0 : 1; } diff --git a/src/testing/test_testing_sharedservices.c b/src/testing/test_testing_sharedservices.c index e7d285bb9..86e9f017c 100644 --- a/src/testing/test_testing_sharedservices.c +++ b/src/testing/test_testing_sharedservices.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -28,8 +28,8 @@ #include "gnunet_util_lib.h" #include "gnunet_testing_lib.h" -#define LOG(kind,...) \ - GNUNET_log (kind, __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log(kind, __VA_ARGS__) #define NUM_PEERS 4 @@ -41,8 +41,7 @@ int status; /** * The testing context */ -struct TestingContext -{ +struct TestingContext { /** * The testing system */ @@ -66,26 +65,26 @@ struct TestingContext * @param cls the testing context */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { struct TestingContext *test_ctx = cls; struct GNUNET_TESTING_Peer *peer; unsigned int cnt; - GNUNET_assert (NULL != test_ctx); + GNUNET_assert(NULL != test_ctx); for (cnt = 0; cnt < NUM_PEERS; cnt++) - { - peer = test_ctx->peers[cnt]; - if (NULL == peer) - continue; - (void) GNUNET_TESTING_peer_stop (peer); - GNUNET_TESTING_peer_destroy (peer); - } + { + peer = test_ctx->peers[cnt]; + if (NULL == peer) + continue; + (void)GNUNET_TESTING_peer_stop(peer); + GNUNET_TESTING_peer_destroy(peer); + } if (NULL != test_ctx->cfg) - GNUNET_CONFIGURATION_destroy (test_ctx->cfg); + GNUNET_CONFIGURATION_destroy(test_ctx->cfg); if (NULL != test_ctx->system) - GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); - GNUNET_free (test_ctx); + GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES); + GNUNET_free(test_ctx); } @@ -93,72 +92,71 @@ do_shutdown (void *cls) * Main point of test execution */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct TestingContext *test_ctx; char *emsg; struct GNUNET_PeerIdentity id; struct GNUNET_TESTING_SharedService ss[] = { - {"peerinfo", cfg, 2}, - {NULL, NULL, 0} + { "peerinfo", cfg, 2 }, + { NULL, NULL, 0 } }; struct GNUNET_TESTING_Peer *peer; unsigned int cnt; - test_ctx = GNUNET_new (struct TestingContext); + test_ctx = GNUNET_new(struct TestingContext); test_ctx->system = - GNUNET_TESTING_system_create ("test-gnunet-testing", - "127.0.0.1", NULL, ss); + GNUNET_TESTING_system_create("test-gnunet-testing", + "127.0.0.1", NULL, ss); emsg = NULL; if (NULL == test_ctx->system) goto end; - test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); + test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg); for (cnt = 0; cnt < NUM_PEERS; cnt++) - { - peer = GNUNET_TESTING_peer_configure (test_ctx->system, - test_ctx->cfg, - 0, &id, &emsg); - if (NULL == peer) { - if (NULL != emsg) - printf ("Test failed upon error: %s", emsg); - goto end; + peer = GNUNET_TESTING_peer_configure(test_ctx->system, + test_ctx->cfg, + 0, &id, &emsg); + if (NULL == peer) + { + if (NULL != emsg) + printf("Test failed upon error: %s", emsg); + goto end; + } + if (GNUNET_OK != GNUNET_TESTING_peer_start(peer)) + { + GNUNET_TESTING_peer_destroy(peer); + goto end; + } + test_ctx->peers[cnt] = peer; } - if (GNUNET_OK != GNUNET_TESTING_peer_start (peer)) - { - GNUNET_TESTING_peer_destroy (peer); - goto end; - } - test_ctx->peers[cnt] = peer; - } status = GNUNET_OK; - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &do_shutdown, test_ctx); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, + &do_shutdown, test_ctx); return; - end: - GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); - GNUNET_free_non_null (emsg); +end: + GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx); + GNUNET_free_non_null(emsg); } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; char *const argv2[] = { "test_testing_sharedservices", - "-c", "test_testing_sharedservices.conf", - NULL - }; + "-c", "test_testing_sharedservices.conf", + NULL }; status = GNUNET_SYSERR; if (GNUNET_OK != - GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, - "test_testing_sharedservices", - "test case for testing service sharing among peers started by testing", - options, &run, NULL)) + GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, + "test_testing_sharedservices", + "test case for testing service sharing among peers started by testing", + options, &run, NULL)) return 1; return (GNUNET_OK == status) ? 0 : 3; } diff --git a/src/testing/testing.c b/src/testing/testing.c index c5c240b37..9c5c32012 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -34,7 +34,7 @@ #include "gnunet_arm_service.h" #include "gnunet_testing_lib.h" -#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from(kind, "testing-api", __VA_ARGS__) /** @@ -63,8 +63,7 @@ #define HIGH_PORT 56000 -struct SharedServiceInstance -{ +struct SharedServiceInstance { struct SharedService *ss; char *cfg_fn; @@ -78,8 +77,7 @@ struct SharedServiceInstance unsigned int n_refs; }; -struct SharedService -{ +struct SharedService { char *sname; struct SharedServiceInstance **instances; @@ -98,8 +96,7 @@ struct SharedService * Handle for a system on which GNUnet peers are executed; * a system is used for reserving unique paths and ports. */ -struct GNUNET_TESTING_System -{ +struct GNUNET_TESTING_System { /** * Prefix (i.e. "/tmp/gnunet-testing/") we prepend to each * GNUNET_HOME. @@ -171,8 +168,7 @@ struct GNUNET_TESTING_System /** * Handle for a GNUnet peer controlled by testing. */ -struct GNUNET_TESTING_Peer -{ +struct GNUNET_TESTING_Peer { /** * The TESTING system associated with this peer */ @@ -253,56 +249,56 @@ struct GNUNET_TESTING_Peer * @return #GNUNET_OK on success; #GNUNET_SYSERR on error */ static int -hostkeys_load (struct GNUNET_TESTING_System *system) +hostkeys_load(struct GNUNET_TESTING_System *system) { uint64_t fs; char *data_dir; char *filename; struct GNUNET_DISK_FileHandle *fd; - GNUNET_assert (NULL == system->hostkeys_data); - data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); - GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir); - GNUNET_free (data_dir); - - if (GNUNET_YES != GNUNET_DISK_file_test (filename)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ ("Hostkeys file not found: %s\n"), - filename); - GNUNET_free (filename); - return GNUNET_SYSERR; - } + GNUNET_assert(NULL == system->hostkeys_data); + data_dir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); + GNUNET_asprintf(&filename, "%s/testing_hostkeys.ecc", data_dir); + GNUNET_free(data_dir); + + if (GNUNET_YES != GNUNET_DISK_file_test(filename)) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Hostkeys file not found: %s\n"), + filename); + GNUNET_free(filename); + return GNUNET_SYSERR; + } /* Check hostkey file size, read entire thing into memory */ if (GNUNET_OK != - GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) + GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) fs = 0; if (0 == fs) - { - GNUNET_free (filename); - return GNUNET_SYSERR; /* File is empty */ - } + { + GNUNET_free(filename); + return GNUNET_SYSERR; /* File is empty */ + } if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ ("Incorrect hostkey file format: %s\n"), - filename); - GNUNET_free (filename); - return GNUNET_SYSERR; - } - fd = GNUNET_DISK_file_open (filename, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Incorrect hostkey file format: %s\n"), + filename); + GNUNET_free(filename); + return GNUNET_SYSERR; + } + fd = GNUNET_DISK_file_open(filename, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (NULL == fd) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); - GNUNET_free (filename); - return GNUNET_SYSERR; - } - GNUNET_free (filename); + { + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", filename); + GNUNET_free(filename); + return GNUNET_SYSERR; + } + GNUNET_free(filename); system->hostkeys_data = - GNUNET_DISK_file_map (fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs); - GNUNET_DISK_file_close (fd); + GNUNET_DISK_file_map(fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs); + GNUNET_DISK_file_close(fd); if (NULL == system->hostkeys_data) return GNUNET_SYSERR; system->total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE; @@ -316,11 +312,11 @@ hostkeys_load (struct GNUNET_TESTING_System *system) * @param system the testing system handle */ static void -hostkeys_unload (struct GNUNET_TESTING_System *system) +hostkeys_unload(struct GNUNET_TESTING_System *system) { - GNUNET_break (NULL != system->hostkeys_data); + GNUNET_break(NULL != system->hostkeys_data); system->hostkeys_data = NULL; - GNUNET_DISK_file_unmap (system->map); + GNUNET_DISK_file_unmap(system->map); system->map = NULL; system->hostkeys_data = NULL; system->total_hostkeys = 0; @@ -336,14 +332,14 @@ hostkeys_unload (struct GNUNET_TESTING_System *system) * @param value value of the option */ static void -cfg_copy_iterator (void *cls, - const char *section, - const char *option, - const char *value) +cfg_copy_iterator(void *cls, + const char *section, + const char *option, + const char *value) { struct GNUNET_CONFIGURATION_Handle *cfg2 = cls; - GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value); + GNUNET_CONFIGURATION_set_value_string(cfg2, section, option, value); } @@ -369,7 +365,7 @@ cfg_copy_iterator (void *cls, * @return handle to this system, NULL on error */ struct GNUNET_TESTING_System * -GNUNET_TESTING_system_create_with_portrange ( +GNUNET_TESTING_system_create_with_portrange( const char *testdir, const char *trusted_ip, const char *hostname, @@ -382,53 +378,53 @@ GNUNET_TESTING_system_create_with_portrange ( struct SharedService *ss; unsigned int cnt; - GNUNET_assert (NULL != testdir); - system = GNUNET_new (struct GNUNET_TESTING_System); - if (NULL == (system->tmppath = getenv (GNUNET_TESTING_PREFIX))) - system->tmppath = GNUNET_DISK_mkdtemp (testdir); + GNUNET_assert(NULL != testdir); + system = GNUNET_new(struct GNUNET_TESTING_System); + if (NULL == (system->tmppath = getenv(GNUNET_TESTING_PREFIX))) + system->tmppath = GNUNET_DISK_mkdtemp(testdir); else - system->tmppath = GNUNET_strdup (system->tmppath); + system->tmppath = GNUNET_strdup(system->tmppath); system->lowport = lowport; system->highport = highport; if (NULL == system->tmppath) - { - GNUNET_free (system); - return NULL; - } + { + GNUNET_free(system); + return NULL; + } if (NULL != trusted_ip) - system->trusted_ip = GNUNET_strdup (trusted_ip); + system->trusted_ip = GNUNET_strdup(trusted_ip); if (NULL != hostname) - system->hostname = GNUNET_strdup (hostname); - if (GNUNET_OK != hostkeys_load (system)) - { - GNUNET_TESTING_system_destroy (system, GNUNET_YES); - return NULL; - } + system->hostname = GNUNET_strdup(hostname); + if (GNUNET_OK != hostkeys_load(system)) + { + GNUNET_TESTING_system_destroy(system, GNUNET_YES); + return NULL; + } if (NULL == shared_services) return system; for (cnt = 0; NULL != shared_services[cnt].service; cnt++) - { - tss = shared_services[cnt]; - ss = GNUNET_new (struct SharedService); - ss->sname = GNUNET_strdup (tss.service); - ss->cfg = GNUNET_CONFIGURATION_create (); - GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, - ss->sname, - &cfg_copy_iterator, - ss->cfg); - GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, - "TESTING", - &cfg_copy_iterator, - ss->cfg); - GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, - "PATHS", - &cfg_copy_iterator, - ss->cfg); - ss->share = tss.share; - GNUNET_array_append (system->shared_services, - system->n_shared_services, - ss); - } + { + tss = shared_services[cnt]; + ss = GNUNET_new(struct SharedService); + ss->sname = GNUNET_strdup(tss.service); + ss->cfg = GNUNET_CONFIGURATION_create(); + GNUNET_CONFIGURATION_iterate_section_values(tss.cfg, + ss->sname, + &cfg_copy_iterator, + ss->cfg); + GNUNET_CONFIGURATION_iterate_section_values(tss.cfg, + "TESTING", + &cfg_copy_iterator, + ss->cfg); + GNUNET_CONFIGURATION_iterate_section_values(tss.cfg, + "PATHS", + &cfg_copy_iterator, + ss->cfg); + ss->share = tss.share; + GNUNET_array_append(system->shared_services, + system->n_shared_services, + ss); + } return system; } @@ -454,59 +450,59 @@ GNUNET_TESTING_system_create_with_portrange ( * @return handle to this system, NULL on error */ struct GNUNET_TESTING_System * -GNUNET_TESTING_system_create ( +GNUNET_TESTING_system_create( const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services) { - return GNUNET_TESTING_system_create_with_portrange (testdir, - trusted_ip, - hostname, - shared_services, - LOW_PORT, - HIGH_PORT); + return GNUNET_TESTING_system_create_with_portrange(testdir, + trusted_ip, + hostname, + shared_services, + LOW_PORT, + HIGH_PORT); } static void -cleanup_shared_service_instance (struct SharedServiceInstance *i) +cleanup_shared_service_instance(struct SharedServiceInstance *i) { if (NULL != i->cfg_fn) - { - (void) unlink (i->cfg_fn); - GNUNET_free (i->cfg_fn); - } - GNUNET_free_non_null (i->unix_sock); - GNUNET_free_non_null (i->port_str); - GNUNET_break (NULL == i->proc); - GNUNET_break (0 == i->n_refs); - GNUNET_free (i); + { + (void)unlink(i->cfg_fn); + GNUNET_free(i->cfg_fn); + } + GNUNET_free_non_null(i->unix_sock); + GNUNET_free_non_null(i->port_str); + GNUNET_break(NULL == i->proc); + GNUNET_break(0 == i->n_refs); + GNUNET_free(i); } static int -start_shared_service_instance (struct SharedServiceInstance *i) +start_shared_service_instance(struct SharedServiceInstance *i) { char *binary; char *libexec_binary; - GNUNET_assert (NULL == i->proc); - GNUNET_assert (NULL != i->cfg_fn); - (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname); - libexec_binary = GNUNET_OS_get_libexec_binary_path (binary); - GNUNET_free (binary); - i->proc = GNUNET_OS_start_process (PIPE_CONTROL, - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - NULL, - NULL, - NULL, - libexec_binary, - libexec_binary, - "-c", - i->cfg_fn, - NULL); - GNUNET_free (libexec_binary); + GNUNET_assert(NULL == i->proc); + GNUNET_assert(NULL != i->cfg_fn); + (void)GNUNET_asprintf(&binary, "gnunet-service-%s", i->ss->sname); + libexec_binary = GNUNET_OS_get_libexec_binary_path(binary); + GNUNET_free(binary); + i->proc = GNUNET_OS_start_process(PIPE_CONTROL, + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + NULL, + NULL, + NULL, + libexec_binary, + libexec_binary, + "-c", + i->cfg_fn, + NULL); + GNUNET_free(libexec_binary); if (NULL == i->proc) return GNUNET_SYSERR; return GNUNET_OK; @@ -514,15 +510,15 @@ start_shared_service_instance (struct SharedServiceInstance *i) static void -stop_shared_service_instance (struct SharedServiceInstance *i) +stop_shared_service_instance(struct SharedServiceInstance *i) { - GNUNET_break (0 == i->n_refs); - if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG)) - LOG (GNUNET_ERROR_TYPE_WARNING, - "Killing shared service instance (%s) failed\n", - i->ss->sname); - (void) GNUNET_OS_process_wait (i->proc); - GNUNET_OS_process_destroy (i->proc); + GNUNET_break(0 == i->n_refs); + if (0 != GNUNET_OS_process_kill(i->proc, GNUNET_TERM_SIG)) + LOG(GNUNET_ERROR_TYPE_WARNING, + "Killing shared service instance (%s) failed\n", + i->ss->sname); + (void)GNUNET_OS_process_wait(i->proc); + GNUNET_OS_process_destroy(i->proc); i->proc = NULL; } @@ -535,8 +531,8 @@ stop_shared_service_instance (struct SharedServiceInstance *i) * be removed (clean up on shutdown)? */ void -GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, - int remove_paths) +GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, + int remove_paths) { struct SharedService *ss; struct SharedServiceInstance *i; @@ -544,29 +540,29 @@ GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, unsigned int i_cnt; if (NULL != system->hostkeys_data) - hostkeys_unload (system); + hostkeys_unload(system); for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++) - { - ss = system->shared_services[ss_cnt]; - for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++) { - i = ss->instances[i_cnt]; - if (NULL != i->proc) - stop_shared_service_instance (i); - cleanup_shared_service_instance (i); + ss = system->shared_services[ss_cnt]; + for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++) + { + i = ss->instances[i_cnt]; + if (NULL != i->proc) + stop_shared_service_instance(i); + cleanup_shared_service_instance(i); + } + GNUNET_free_non_null(ss->instances); + GNUNET_CONFIGURATION_destroy(ss->cfg); + GNUNET_free(ss->sname); + GNUNET_free(ss); } - GNUNET_free_non_null (ss->instances); - GNUNET_CONFIGURATION_destroy (ss->cfg); - GNUNET_free (ss->sname); - GNUNET_free (ss); - } - GNUNET_free_non_null (system->shared_services); + GNUNET_free_non_null(system->shared_services); if (GNUNET_YES == remove_paths) - GNUNET_DISK_directory_remove (system->tmppath); - GNUNET_free (system->tmppath); - GNUNET_free_non_null (system->trusted_ip); - GNUNET_free_non_null (system->hostname); - GNUNET_free (system); + GNUNET_DISK_directory_remove(system->tmppath); + GNUNET_free(system->tmppath); + GNUNET_free_non_null(system->trusted_ip); + GNUNET_free_non_null(system->hostname); + GNUNET_free(system); } @@ -577,7 +573,7 @@ GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, * @return 0 if no free port was available */ uint16_t -GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) +GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system) { struct GNUNET_NETWORK_Handle *socket; struct addrinfo hint; @@ -592,14 +588,14 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) uint16_t pos; /* - FIXME: Instead of using getaddrinfo we should try to determine the port + FIXME: Instead of using getaddrinfo we should try to determine the port status by the following heurestics. - On systems which support both IPv4 and IPv6, only ports open on both - address families are considered open. - On system with either IPv4 or IPv6. A port is considered open if it's - open in the respective address family - */ + On systems which support both IPv4 and IPv6, only ports open on both + address families are considered open. + On system with either IPv4 or IPv6. A port is considered open if it's + open in the respective address family + */ hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ hint.ai_socktype = 0; hint.ai_protocol = 0; @@ -611,57 +607,57 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) port_buckets = system->reserved_ports; for (index = (system->lowport / 32) + 1; index < (system->highport / 32); index++) - { - xor_image = (UINT32_MAX ^ port_buckets[index]); - if (0 == xor_image) /* Ports in the bucket are full */ - continue; - pos = system->lowport % 32; - while (pos < 32) { - if (0 == ((xor_image >> pos) & 1U)) - { - pos++; + xor_image = (UINT32_MAX ^ port_buckets[index]); + if (0 == xor_image) /* Ports in the bucket are full */ continue; - } - open_port = (index * 32) + pos; - if (open_port >= system->highport) - return 0; - GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port); - ret = NULL; - GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret)); - GNUNET_free (open_port_str); - bind_status = GNUNET_NO; - for (ai = ret; NULL != ai; ai = ai->ai_next) - { - socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0); - if (NULL == socket) - continue; - bind_status = - GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen); - GNUNET_NETWORK_socket_close (socket); - if (GNUNET_OK != bind_status) - break; - socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0); - if (NULL == socket) - continue; - bind_status = - GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen); - GNUNET_NETWORK_socket_close (socket); - if (GNUNET_OK != bind_status) - break; - } - port_buckets[index] |= (1U << pos); /* Set the port bit */ - freeaddrinfo (ret); - if (GNUNET_OK == bind_status) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found a free port %u\n", - (unsigned int) open_port); - return open_port; - } - pos++; + pos = system->lowport % 32; + while (pos < 32) + { + if (0 == ((xor_image >> pos) & 1U)) + { + pos++; + continue; + } + open_port = (index * 32) + pos; + if (open_port >= system->highport) + return 0; + GNUNET_asprintf(&open_port_str, "%u", (unsigned int)open_port); + ret = NULL; + GNUNET_assert(0 == getaddrinfo(NULL, open_port_str, &hint, &ret)); + GNUNET_free(open_port_str); + bind_status = GNUNET_NO; + for (ai = ret; NULL != ai; ai = ai->ai_next) + { + socket = GNUNET_NETWORK_socket_create(ai->ai_family, SOCK_STREAM, 0); + if (NULL == socket) + continue; + bind_status = + GNUNET_NETWORK_socket_bind(socket, ai->ai_addr, ai->ai_addrlen); + GNUNET_NETWORK_socket_close(socket); + if (GNUNET_OK != bind_status) + break; + socket = GNUNET_NETWORK_socket_create(ai->ai_family, SOCK_DGRAM, 0); + if (NULL == socket) + continue; + bind_status = + GNUNET_NETWORK_socket_bind(socket, ai->ai_addr, ai->ai_addrlen); + GNUNET_NETWORK_socket_close(socket); + if (GNUNET_OK != bind_status) + break; + } + port_buckets[index] |= (1U << pos); /* Set the port bit */ + freeaddrinfo(ret); + if (GNUNET_OK == bind_status) + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Found a free port %u\n", + (unsigned int)open_port); + return open_port; + } + pos++; + } } - } return 0; } @@ -674,8 +670,8 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) * @param port reserved port to release */ void -GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, - uint16_t port) +GNUNET_TESTING_release_port(struct GNUNET_TESTING_System *system, + uint16_t port) { uint32_t *port_buckets; uint16_t bucket; @@ -684,12 +680,12 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, port_buckets = system->reserved_ports; bucket = port / 32; pos = port % 32; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); if (0 == (port_buckets[bucket] & (1U << pos))) - { - GNUNET_break (0); /* Port was not reserved by us using reserve_port() */ - return; - } + { + GNUNET_break(0); /* Port was not reserved by us using reserve_port() */ + return; + } port_buckets[bucket] &= ~(1U << pos); } @@ -712,27 +708,27 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, * @return NULL on error (not enough keys) */ struct GNUNET_CRYPTO_EddsaPrivateKey * -GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, - uint32_t key_number, - struct GNUNET_PeerIdentity *id) +GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system, + uint32_t key_number, + struct GNUNET_PeerIdentity *id) { struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; if ((NULL == id) || (NULL == system->hostkeys_data)) return NULL; if (key_number >= system->total_hostkeys) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ ("Key number %u does not exist\n"), - key_number); - return NULL; - } - private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); - GNUNET_memcpy (private_key, - system->hostkeys_data + - (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), - GNUNET_TESTING_HOSTKEYFILESIZE); - GNUNET_CRYPTO_eddsa_key_get_public (private_key, &id->public_key); + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Key number %u does not exist\n"), + key_number); + return NULL; + } + private_key = GNUNET_new(struct GNUNET_CRYPTO_EddsaPrivateKey); + GNUNET_memcpy(private_key, + system->hostkeys_data + + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), + GNUNET_TESTING_HOSTKEYFILESIZE); + GNUNET_CRYPTO_eddsa_key_get_public(private_key, &id->public_key); return private_key; } @@ -741,8 +737,7 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, * Structure for holding data to build new configurations from a configuration * template */ -struct UpdateContext -{ +struct UpdateContext { /** * The system for which we are building configurations */ @@ -788,10 +783,10 @@ struct UpdateContext * @param value value of the option */ static void -update_config (void *cls, - const char *section, - const char *option, - const char *value) +update_config(void *cls, + const char *section, + const char *option, + const char *value) { struct UpdateContext *uc = cls; unsigned int ival; @@ -804,76 +799,76 @@ update_config (void *cls, if (GNUNET_OK != uc->status) return; - if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) || - (0 == strcmp (option, "HOSTNAME")))) + if (!((0 == strcmp(option, "PORT")) || (0 == strcmp(option, "UNIXPATH")) || + (0 == strcmp(option, "HOSTNAME")))) return; - GNUNET_asprintf (&single_variable, "single_%s_per_host", section); - GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); - if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) - { - if ((ival != 0) && - (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, - "testing", - single_variable))) + GNUNET_asprintf(&single_variable, "single_%s_per_host", section); + GNUNET_asprintf(&per_host_variable, "num_%s_per_host", section); + if ((0 == strcmp(option, "PORT")) && (1 == sscanf(value, "%u", &ival))) { - new_port = GNUNET_TESTING_reserve_port (uc->system); - if (0 == new_port) - { - uc->status = GNUNET_SYSERR; - GNUNET_free (single_variable); - GNUNET_free (per_host_variable); - return; - } - GNUNET_snprintf (cval, sizeof (cval), "%u", new_port); - value = cval; - GNUNET_array_append (uc->ports, uc->nports, new_port); - } - else if ((ival != 0) && - (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, - "testing", - single_variable)) && - GNUNET_CONFIGURATION_get_value_number (uc->cfg, - "testing", - per_host_variable, - &num_per_host)) - { - /* GNUNET_snprintf (cval, sizeof (cval), "%u", */ - /* ival + ctx->fdnum % num_per_host); */ - /* value = cval; */ - GNUNET_break (0); /* FIXME */ + if ((ival != 0) && + (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(uc->cfg, + "testing", + single_variable))) + { + new_port = GNUNET_TESTING_reserve_port(uc->system); + if (0 == new_port) + { + uc->status = GNUNET_SYSERR; + GNUNET_free(single_variable); + GNUNET_free(per_host_variable); + return; + } + GNUNET_snprintf(cval, sizeof(cval), "%u", new_port); + value = cval; + GNUNET_array_append(uc->ports, uc->nports, new_port); + } + else if ((ival != 0) && + (GNUNET_YES == + GNUNET_CONFIGURATION_get_value_yesno(uc->cfg, + "testing", + single_variable)) && + GNUNET_CONFIGURATION_get_value_number(uc->cfg, + "testing", + per_host_variable, + &num_per_host)) + { + /* GNUNET_snprintf (cval, sizeof (cval), "%u", */ + /* ival + ctx->fdnum % num_per_host); */ + /* value = cval; */ + GNUNET_break(0); /* FIXME */ + } } - } - if (0 == strcmp (option, "UNIXPATH")) - { - if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, - "testing", - single_variable)) + if (0 == strcmp(option, "UNIXPATH")) { - GNUNET_snprintf (uval, - sizeof (uval), - "%s/%s.sock", - uc->gnunet_home, - section); - value = uval; + if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(uc->cfg, + "testing", + single_variable)) + { + GNUNET_snprintf(uval, + sizeof(uval), + "%s/%s.sock", + uc->gnunet_home, + section); + value = uval; + } + else if ((GNUNET_YES == + GNUNET_CONFIGURATION_get_value_number(uc->cfg, + "testing", + per_host_variable, + &num_per_host)) && + (num_per_host > 0)) + { + GNUNET_break(0); /* FIXME */ + } } - else if ((GNUNET_YES == - GNUNET_CONFIGURATION_get_value_number (uc->cfg, - "testing", - per_host_variable, - &num_per_host)) && - (num_per_host > 0)) + if (0 == strcmp(option, "HOSTNAME")) { - GNUNET_break (0); /* FIXME */ + value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname; } - } - if (0 == strcmp (option, "HOSTNAME")) - { - value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname; - } - GNUNET_free (single_variable); - GNUNET_free (per_host_variable); - GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value); + GNUNET_free(single_variable); + GNUNET_free(per_host_variable); + GNUNET_CONFIGURATION_set_value_string(uc->cfg, section, option, value); } @@ -885,7 +880,7 @@ update_config (void *cls, * @param section name of the section */ static void -update_config_sections (void *cls, const char *section) +update_config_sections(void *cls, const char *section) { struct UpdateContext *uc = cls; char **ikeys; @@ -902,98 +897,98 @@ update_config_sections (void *cls, const char *section) /* Ignore certain options from sections. See https://gnunet.org/bugs/view.php?id=2476 */ if (GNUNET_YES == - GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS")) - { - GNUNET_assert (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_string (uc->cfg, + GNUNET_CONFIGURATION_have_value(uc->cfg, section, "TESTING_IGNORE_KEYS")) + { + GNUNET_assert(GNUNET_YES == + GNUNET_CONFIGURATION_get_value_string(uc->cfg, section, "TESTING_IGNORE_KEYS", &val)); - ptr = val; - for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++) - ptr++; - if (0 == ikeys_cnt) - GNUNET_break (0); - else - { - ikeys = GNUNET_malloc ((sizeof (char *)) * ikeys_cnt); ptr = val; - for (key = 0; key < ikeys_cnt; key++) - { - ikeys[key] = ptr; - ptr = strstr (ptr, ";"); - GNUNET_assert (NULL != ptr); /* worked just before... */ - *ptr = '\0'; + for (ikeys_cnt = 0; NULL != (ptr = strstr(ptr, ";")); ikeys_cnt++) ptr++; - } + if (0 == ikeys_cnt) + GNUNET_break(0); + else + { + ikeys = GNUNET_malloc((sizeof(char *)) * ikeys_cnt); + ptr = val; + for (key = 0; key < ikeys_cnt; key++) + { + ikeys[key] = ptr; + ptr = strstr(ptr, ";"); + GNUNET_assert(NULL != ptr); /* worked just before... */ + *ptr = '\0'; + ptr++; + } + } } - } if (0 != ikeys_cnt) - { - for (key = 0; key < ikeys_cnt; key++) - { - if (NULL != strstr (ikeys[key], "ADVERTISED_PORT")) - break; - } - if ((key == ikeys_cnt) && - (GNUNET_YES == - GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT"))) { - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (uc->cfg, - section, - "PORT", - &ptr)) - { - GNUNET_CONFIGURATION_set_value_string (uc->cfg, - section, - "ADVERTISED_PORT", - ptr); - GNUNET_free (ptr); - } - } - for (key = 0; key < ikeys_cnt; key++) - { - if (NULL != strstr (ikeys[key], "ACCEPT_FROM")) - { - GNUNET_free (ikeys); - GNUNET_free (val); - return; - } + for (key = 0; key < ikeys_cnt; key++) + { + if (NULL != strstr(ikeys[key], "ADVERTISED_PORT")) + break; + } + if ((key == ikeys_cnt) && + (GNUNET_YES == + GNUNET_CONFIGURATION_have_value(uc->cfg, section, "ADVERTISED_PORT"))) + { + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(uc->cfg, + section, + "PORT", + &ptr)) + { + GNUNET_CONFIGURATION_set_value_string(uc->cfg, + section, + "ADVERTISED_PORT", + ptr); + GNUNET_free(ptr); + } + } + for (key = 0; key < ikeys_cnt; key++) + { + if (NULL != strstr(ikeys[key], "ACCEPT_FROM")) + { + GNUNET_free(ikeys); + GNUNET_free(val); + return; + } + } + GNUNET_free(ikeys); } - GNUNET_free (ikeys); - } - GNUNET_free_non_null (val); + GNUNET_free_non_null(val); ACCEPT_FROM_key = "ACCEPT_FROM"; if ((NULL != uc->system->trusted_ip) && - (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */ + (NULL != strstr(uc->system->trusted_ip, ":"))) /* IPv6 in use */ ACCEPT_FROM_key = "ACCEPT_FROM6"; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (uc->cfg, - section, - ACCEPT_FROM_key, - &orig_allowed_hosts)) - { - orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;"); - } + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(uc->cfg, + section, + ACCEPT_FROM_key, + &orig_allowed_hosts)) + { + orig_allowed_hosts = GNUNET_strdup("127.0.0.1;"); + } if (NULL == uc->system->trusted_ip) - allowed_hosts = GNUNET_strdup (orig_allowed_hosts); + allowed_hosts = GNUNET_strdup(orig_allowed_hosts); else - GNUNET_asprintf (&allowed_hosts, - "%s%s;", - orig_allowed_hosts, - uc->system->trusted_ip); - GNUNET_free (orig_allowed_hosts); - GNUNET_CONFIGURATION_set_value_string (uc->cfg, - section, - ACCEPT_FROM_key, - allowed_hosts); - GNUNET_free (allowed_hosts); + GNUNET_asprintf(&allowed_hosts, + "%s%s;", + orig_allowed_hosts, + uc->system->trusted_ip); + GNUNET_free(orig_allowed_hosts); + GNUNET_CONFIGURATION_set_value_string(uc->cfg, + section, + ACCEPT_FROM_key, + allowed_hosts); + GNUNET_free(allowed_hosts); } static struct SharedServiceInstance * -associate_shared_service (struct GNUNET_TESTING_System *system, - struct SharedService *ss, - struct GNUNET_CONFIGURATION_Handle *cfg) +associate_shared_service(struct GNUNET_TESTING_System *system, + struct SharedService *ss, + struct GNUNET_CONFIGURATION_Handle *cfg) { struct SharedServiceInstance *i; struct GNUNET_CONFIGURATION_Handle *temp; @@ -1004,62 +999,62 @@ associate_shared_service (struct GNUNET_TESTING_System *system, if (((0 == ss->share) && (NULL == ss->instances)) || ((0 != ss->share) && (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)))) - { - i = GNUNET_new (struct SharedServiceInstance); - i->ss = ss; - (void) GNUNET_asprintf (&gnunet_home, + { + i = GNUNET_new(struct SharedServiceInstance); + i->ss = ss; + (void)GNUNET_asprintf(&gnunet_home, "%s/shared/%s/%u", system->tmppath, ss->sname, ss->n_instances); - (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home); - port = GNUNET_TESTING_reserve_port (system); - if (0 == port) - { - GNUNET_free (gnunet_home); - cleanup_shared_service_instance (i); - return NULL; + (void)GNUNET_asprintf(&i->unix_sock, "%s/sock", gnunet_home); + port = GNUNET_TESTING_reserve_port(system); + if (0 == port) + { + GNUNET_free(gnunet_home); + cleanup_shared_service_instance(i); + return NULL; + } + GNUNET_array_append(ss->instances, ss->n_instances, i); + temp = GNUNET_CONFIGURATION_dup(ss->cfg); + (void)GNUNET_asprintf(&i->port_str, "%u", port); + (void)GNUNET_asprintf(&i->cfg_fn, "%s/config", gnunet_home); + GNUNET_CONFIGURATION_set_value_string(temp, + "PATHS", + "GNUNET_HOME", + gnunet_home); + GNUNET_free(gnunet_home); + GNUNET_CONFIGURATION_set_value_string(temp, + ss->sname, + "UNIXPATH", + i->unix_sock); + GNUNET_CONFIGURATION_set_value_string(temp, + ss->sname, + "PORT", + i->port_str); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write(temp, i->cfg_fn)) + { + GNUNET_CONFIGURATION_destroy(temp); + cleanup_shared_service_instance(i); + return NULL; + } + GNUNET_CONFIGURATION_destroy(temp); } - GNUNET_array_append (ss->instances, ss->n_instances, i); - temp = GNUNET_CONFIGURATION_dup (ss->cfg); - (void) GNUNET_asprintf (&i->port_str, "%u", port); - (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home); - GNUNET_CONFIGURATION_set_value_string (temp, - "PATHS", - "GNUNET_HOME", - gnunet_home); - GNUNET_free (gnunet_home); - GNUNET_CONFIGURATION_set_value_string (temp, - ss->sname, - "UNIXPATH", - i->unix_sock); - GNUNET_CONFIGURATION_set_value_string (temp, - ss->sname, - "PORT", - i->port_str); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn)) + else { - GNUNET_CONFIGURATION_destroy (temp); - cleanup_shared_service_instance (i); - return NULL; + GNUNET_assert(NULL != ss->instances); + GNUNET_assert(0 < ss->n_instances); + i = ss->instances[ss->n_instances - 1]; } - GNUNET_CONFIGURATION_destroy (temp); - } - else - { - GNUNET_assert (NULL != ss->instances); - GNUNET_assert (0 < ss->n_instances); - i = ss->instances[ss->n_instances - 1]; - } - GNUNET_CONFIGURATION_iterate_section_values (ss->cfg, - ss->sname, - &cfg_copy_iterator, - cfg); - GNUNET_CONFIGURATION_set_value_string (cfg, - ss->sname, - "UNIXPATH", - i->unix_sock); - GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str); + GNUNET_CONFIGURATION_iterate_section_values(ss->cfg, + ss->sname, + &cfg_copy_iterator, + cfg); + GNUNET_CONFIGURATION_set_value_string(cfg, + ss->sname, + "UNIXPATH", + i->unix_sock); + GNUNET_CONFIGURATION_set_value_string(cfg, ss->sname, "PORT", i->port_str); return i; } @@ -1084,10 +1079,10 @@ associate_shared_service (struct GNUNET_TESTING_System *system, * be incomplete and should not be used there upon */ static int -GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system, - struct GNUNET_CONFIGURATION_Handle *cfg, - uint16_t **ports, - unsigned int *nports) +GNUNET_TESTING_configuration_create_(struct GNUNET_TESTING_System *system, + struct GNUNET_CONFIGURATION_Handle *cfg, + uint16_t **ports, + unsigned int *nports) { struct UpdateContext uc; char *default_config; @@ -1097,35 +1092,35 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system, uc.status = GNUNET_OK; uc.ports = NULL; uc.nports = 0; - GNUNET_asprintf (&uc.gnunet_home, - "%s/%u", - system->tmppath, - system->path_counter++); - GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home); - GNUNET_CONFIGURATION_set_value_string (cfg, - "PATHS", - "DEFAULTCONFIG", - default_config); - GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config); - GNUNET_free (default_config); - GNUNET_CONFIGURATION_set_value_string (cfg, - "PATHS", - "GNUNET_HOME", - uc.gnunet_home); + GNUNET_asprintf(&uc.gnunet_home, + "%s/%u", + system->tmppath, + system->path_counter++); + GNUNET_asprintf(&default_config, "%s/config", uc.gnunet_home); + GNUNET_CONFIGURATION_set_value_string(cfg, + "PATHS", + "DEFAULTCONFIG", + default_config); + GNUNET_CONFIGURATION_set_value_string(cfg, "arm", "CONFIG", default_config); + GNUNET_free(default_config); + GNUNET_CONFIGURATION_set_value_string(cfg, + "PATHS", + "GNUNET_HOME", + uc.gnunet_home); /* make PORTs and UNIXPATHs unique */ - GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); + GNUNET_CONFIGURATION_iterate(cfg, &update_config, &uc); /* allow connections to services from system trusted_ip host */ - GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc); + GNUNET_CONFIGURATION_iterate_sections(cfg, &update_config_sections, &uc); /* enable loopback-based connections between peers */ - GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES"); - GNUNET_free (uc.gnunet_home); + GNUNET_CONFIGURATION_set_value_string(cfg, "nat", "USE_LOCALADDR", "YES"); + GNUNET_free(uc.gnunet_home); if ((NULL != ports) && (NULL != nports)) - { - *ports = uc.ports; - *nports = uc.nports; - } + { + *ports = uc.ports; + *nports = uc.nports; + } else - GNUNET_free_non_null (uc.ports); + GNUNET_free_non_null(uc.ports); return uc.status; } @@ -1147,10 +1142,10 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system, * be incomplete and should not be used there upon */ int -GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, - struct GNUNET_CONFIGURATION_Handle *cfg) +GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system, + struct GNUNET_CONFIGURATION_Handle *cfg) { - return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL); + return GNUNET_TESTING_configuration_create_(system, cfg, NULL, NULL); } @@ -1168,11 +1163,11 @@ GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, * @return handle to the peer, NULL on error */ struct GNUNET_TESTING_Peer * -GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, - struct GNUNET_CONFIGURATION_Handle *cfg, - uint32_t key_number, - struct GNUNET_PeerIdentity *id, - char **emsg) +GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system, + struct GNUNET_CONFIGURATION_Handle *cfg, + uint32_t key_number, + struct GNUNET_PeerIdentity *id, + char **emsg) { struct GNUNET_TESTING_Peer *peer; struct GNUNET_DISK_FileHandle *fd; @@ -1193,141 +1188,141 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, if (NULL != emsg) *emsg = NULL; if (key_number >= system->total_hostkeys) - { - GNUNET_asprintf ( - &emsg_, - _ ( - "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"), - (unsigned int) system->total_hostkeys); - goto err_ret; - } + { + GNUNET_asprintf( + &emsg_, + _( + "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"), + (unsigned int)system->total_hostkeys); + goto err_ret; + } pk = NULL; if ((NULL != id) && - (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id)))) - { - GNUNET_asprintf (&emsg_, - _ ("Failed to initialize hostkey for peer %u\n"), - (unsigned int) key_number); - goto err_ret; - } + (NULL == (pk = GNUNET_TESTING_hostkey_get(system, key_number, id)))) + { + GNUNET_asprintf(&emsg_, + _("Failed to initialize hostkey for peer %u\n"), + (unsigned int)key_number); + goto err_ret; + } if (NULL != pk) - GNUNET_free (pk); - if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY")) - { - GNUNET_asprintf ( - &emsg_, - _ ("PRIVATE_KEY option in PEER section missing in configuration\n")); - goto err_ret; - } + GNUNET_free(pk); + if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(cfg, "PEER", "PRIVATE_KEY")) + { + GNUNET_asprintf( + &emsg_, + _("PRIVATE_KEY option in PEER section missing in configuration\n")); + goto err_ret; + } /* Remove sections for shared services */ for (cnt = 0; cnt < system->n_shared_services; cnt++) - { - ss = system->shared_services[cnt]; - GNUNET_CONFIGURATION_remove_section (cfg, ss->sname); - } + { + ss = system->shared_services[cnt]; + GNUNET_CONFIGURATION_remove_section(cfg, ss->sname); + } if (GNUNET_OK != - GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports)) - { - GNUNET_asprintf (&emsg_, - _ ("Failed to create configuration for peer " + GNUNET_TESTING_configuration_create_(system, cfg, &ports, &nports)) + { + GNUNET_asprintf(&emsg_, + _("Failed to create configuration for peer " "(not enough free ports?)\n")); - goto err_ret; - } - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename (cfg, - "PEER", - "PRIVATE_KEY", - &hostkey_filename)); - fd = GNUNET_DISK_file_open (hostkey_filename, - GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + goto err_ret; + } + GNUNET_assert(GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename(cfg, + "PEER", + "PRIVATE_KEY", + &hostkey_filename)); + fd = GNUNET_DISK_file_open(hostkey_filename, + GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); if (NULL == fd) - { - GNUNET_asprintf (&emsg_, - _ ("Cannot open hostkey file `%s': %s\n"), - hostkey_filename, - strerror (errno)); - GNUNET_free (hostkey_filename); - goto err_ret; - } - GNUNET_free (hostkey_filename); + { + GNUNET_asprintf(&emsg_, + _("Cannot open hostkey file `%s': %s\n"), + hostkey_filename, + strerror(errno)); + GNUNET_free(hostkey_filename); + goto err_ret; + } + GNUNET_free(hostkey_filename); if (GNUNET_TESTING_HOSTKEYFILESIZE != - GNUNET_DISK_file_write (fd, - system->hostkeys_data + - (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), - GNUNET_TESTING_HOSTKEYFILESIZE)) - { - GNUNET_asprintf (&emsg_, - _ ("Failed to write hostkey file for peer %u: %s\n"), - (unsigned int) key_number, - strerror (errno)); - GNUNET_DISK_file_close (fd); - goto err_ret; - } - GNUNET_DISK_file_close (fd); - ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *) * - system->n_shared_services); + GNUNET_DISK_file_write(fd, + system->hostkeys_data + + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), + GNUNET_TESTING_HOSTKEYFILESIZE)) + { + GNUNET_asprintf(&emsg_, + _("Failed to write hostkey file for peer %u: %s\n"), + (unsigned int)key_number, + strerror(errno)); + GNUNET_DISK_file_close(fd); + goto err_ret; + } + GNUNET_DISK_file_close(fd); + ss_instances = GNUNET_malloc(sizeof(struct SharedServiceInstance *) * + system->n_shared_services); for (cnt = 0; cnt < system->n_shared_services; cnt++) - { - ss = system->shared_services[cnt]; - ss_instances[cnt] = associate_shared_service (system, ss, cfg); - if (NULL == ss_instances[cnt]) { - emsg_ = GNUNET_strdup ("FIXME"); + ss = system->shared_services[cnt]; + ss_instances[cnt] = associate_shared_service(system, ss, cfg); + if (NULL == ss_instances[cnt]) + { + emsg_ = GNUNET_strdup("FIXME"); + goto err_ret; + } + } + GNUNET_assert(GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename(cfg, + "PATHS", + "DEFAULTCONFIG", + &config_filename)); + if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, config_filename)) + { + GNUNET_asprintf(&emsg_, + _( + "Failed to write configuration file `%s' for peer %u: %s\n"), + config_filename, + (unsigned int)key_number, + strerror(errno)); + GNUNET_free(config_filename); goto err_ret; } - } - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename (cfg, - "PATHS", - "DEFAULTCONFIG", - &config_filename)); - if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename)) - { - GNUNET_asprintf (&emsg_, - _ ( - "Failed to write configuration file `%s' for peer %u: %s\n"), - config_filename, - (unsigned int) key_number, - strerror (errno)); - GNUNET_free (config_filename); - goto err_ret; - } - peer = GNUNET_new (struct GNUNET_TESTING_Peer); + peer = GNUNET_new(struct GNUNET_TESTING_Peer); peer->ss_instances = ss_instances; peer->cfgfile = config_filename; /* Free in peer_destroy */ - peer->cfg = GNUNET_CONFIGURATION_dup (cfg); - libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); + peer->cfg = GNUNET_CONFIGURATION_dup(cfg); + libexec_binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, - "arm", - "PREFIX", - &peer->main_binary)) - { - /* No prefix */ - GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary); - peer->args = GNUNET_strdup (""); - } + GNUNET_CONFIGURATION_get_value_string(cfg, + "arm", + "PREFIX", + &peer->main_binary)) + { + /* No prefix */ + GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); + peer->args = GNUNET_strdup(""); + } else - { - peer->args = GNUNET_strdup (libexec_binary); - } + { + peer->args = GNUNET_strdup(libexec_binary); + } peer->system = system; peer->key_number = key_number; - GNUNET_free (libexec_binary); + GNUNET_free(libexec_binary); peer->ports = ports; /* Free in peer_destroy */ peer->nports = nports; return peer; err_ret: - GNUNET_free_non_null (ss_instances); - GNUNET_free_non_null (ports); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); + GNUNET_free_non_null(ss_instances); + GNUNET_free_non_null(ports); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); if (NULL != emsg) *emsg = emsg_; else - GNUNET_free (emsg_); + GNUNET_free(emsg_); return NULL; } @@ -1339,18 +1334,18 @@ err_ret: * @param id identifier for the daemon, will be set */ void -GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, - struct GNUNET_PeerIdentity *id) +GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer, + struct GNUNET_PeerIdentity *id) { if (NULL != peer->id) - { - GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity)); - return; - } - peer->id = GNUNET_new (struct GNUNET_PeerIdentity); - GNUNET_free ( - GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id)); - GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity)); + { + GNUNET_memcpy(id, peer->id, sizeof(struct GNUNET_PeerIdentity)); + return; + } + peer->id = GNUNET_new(struct GNUNET_PeerIdentity); + GNUNET_free( + GNUNET_TESTING_hostkey_get(peer->system, peer->key_number, peer->id)); + GNUNET_memcpy(id, peer->id, sizeof(struct GNUNET_PeerIdentity)); } @@ -1361,44 +1356,44 @@ GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (i.e. peer already running) */ int -GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer) +GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer) { struct SharedServiceInstance *i; unsigned int cnt; if (NULL != peer->main_process) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - GNUNET_assert (NULL != peer->cfgfile); - for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) - { - i = peer->ss_instances[cnt]; - if ((0 == i->n_refs) && - (GNUNET_SYSERR == start_shared_service_instance (i))) + { + GNUNET_break(0); return GNUNET_SYSERR; - i->n_refs++; - } + } + GNUNET_assert(NULL != peer->cfgfile); + for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) + { + i = peer->ss_instances[cnt]; + if ((0 == i->n_refs) && + (GNUNET_SYSERR == start_shared_service_instance(i))) + return GNUNET_SYSERR; + i->n_refs++; + } peer->main_binary = - GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary); + GNUNET_CONFIGURATION_expand_dollar(peer->cfg, peer->main_binary); peer->main_process = - GNUNET_OS_start_process_s (PIPE_CONTROL, - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - NULL, - peer->main_binary, - peer->args, - "-c", - peer->cfgfile, - NULL); + GNUNET_OS_start_process_s(PIPE_CONTROL, + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + NULL, + peer->main_binary, + peer->args, + "-c", + peer->cfgfile, + NULL); if (NULL == peer->main_process) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to start `%s': %s\n"), - peer->main_binary, - strerror (errno)); - return GNUNET_SYSERR; - } + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to start `%s': %s\n"), + peer->main_binary, + strerror(errno)); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -1411,26 +1406,26 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer) * or upon any error while sending SIGTERM */ int -GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer) +GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer) { struct SharedServiceInstance *i; unsigned int cnt; if (NULL == peer->main_process) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - if (0 != GNUNET_OS_process_kill (peer->main_process, GNUNET_TERM_SIG)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + if (0 != GNUNET_OS_process_kill(peer->main_process, GNUNET_TERM_SIG)) return GNUNET_SYSERR; for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) - { - i = peer->ss_instances[cnt]; - GNUNET_assert (0 != i->n_refs); - i->n_refs--; - if (0 == i->n_refs) - stop_shared_service_instance (i); - } + { + i = peer->ss_instances[cnt]; + GNUNET_assert(0 != i->n_refs); + i->n_refs--; + if (0 == i->n_refs) + stop_shared_service_instance(i); + } return GNUNET_OK; } @@ -1443,17 +1438,17 @@ GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer) * or upon any error while waiting */ int -GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer) +GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer) { int ret; if (NULL == peer->main_process) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - ret = GNUNET_OS_process_wait (peer->main_process); - GNUNET_OS_process_destroy (peer->main_process); + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + ret = GNUNET_OS_process_wait(peer->main_process); + GNUNET_OS_process_destroy(peer->main_process); peer->main_process = NULL; return ret; } @@ -1466,11 +1461,11 @@ GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer) * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer) +GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer) { - if (GNUNET_SYSERR == GNUNET_TESTING_peer_kill (peer)) + if (GNUNET_SYSERR == GNUNET_TESTING_peer_kill(peer)) return GNUNET_SYSERR; - if (GNUNET_SYSERR == GNUNET_TESTING_peer_wait (peer)) + if (GNUNET_SYSERR == GNUNET_TESTING_peer_wait(peer)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -1484,24 +1479,24 @@ GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer) * #GNUNET_SYSERR on error. */ static void -disconn_status (void *cls, int connected) +disconn_status(void *cls, int connected) { struct GNUNET_TESTING_Peer *peer = cls; if (GNUNET_SYSERR == connected) - { - peer->cb (peer->cb_cls, peer, connected); - return; - } + { + peer->cb(peer->cb_cls, peer, connected); + return; + } if (GNUNET_YES == connected) - { - GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_kill (peer)); - return; - } - GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_wait (peer)); - GNUNET_ARM_disconnect (peer->ah); + { + GNUNET_break(GNUNET_OK == GNUNET_TESTING_peer_kill(peer)); + return; + } + GNUNET_break(GNUNET_OK == GNUNET_TESTING_peer_wait(peer)); + GNUNET_ARM_disconnect(peer->ah); peer->ah = NULL; - peer->cb (peer->cb_cls, peer, GNUNET_YES); + peer->cb(peer->cb_cls, peer, GNUNET_YES); } @@ -1517,13 +1512,13 @@ disconn_status (void *cls, int connected) * upon any error. */ int -GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, - GNUNET_TESTING_PeerStopCallback cb, - void *cb_cls) +GNUNET_TESTING_peer_stop_async(struct GNUNET_TESTING_Peer *peer, + GNUNET_TESTING_PeerStopCallback cb, + void *cb_cls) { if (NULL == peer->main_process) return GNUNET_SYSERR; - peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer); + peer->ah = GNUNET_ARM_connect(peer->cfg, &disconn_status, peer); if (NULL == peer->ah) return GNUNET_SYSERR; peer->cb = cb; @@ -1542,10 +1537,10 @@ GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, * before. */ void -GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer) +GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer) { - GNUNET_assert (NULL != peer->ah); - GNUNET_ARM_disconnect (peer->ah); + GNUNET_assert(NULL != peer->ah); + GNUNET_ARM_disconnect(peer->ah); peer->ah = NULL; } @@ -1558,28 +1553,28 @@ GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer) * @param peer peer to destroy */ void -GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer) +GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer) { unsigned int cnt; if (NULL != peer->main_process) - GNUNET_TESTING_peer_stop (peer); + GNUNET_TESTING_peer_stop(peer); if (NULL != peer->ah) - GNUNET_ARM_disconnect (peer->ah); - GNUNET_free (peer->cfgfile); + GNUNET_ARM_disconnect(peer->ah); + GNUNET_free(peer->cfgfile); if (NULL != peer->cfg) - GNUNET_CONFIGURATION_destroy (peer->cfg); - GNUNET_free (peer->main_binary); - GNUNET_free (peer->args); - GNUNET_free_non_null (peer->id); - GNUNET_free_non_null (peer->ss_instances); + GNUNET_CONFIGURATION_destroy(peer->cfg); + GNUNET_free(peer->main_binary); + GNUNET_free(peer->args); + GNUNET_free_non_null(peer->id); + GNUNET_free_non_null(peer->ss_instances); if (NULL != peer->ports) - { - for (cnt = 0; cnt < peer->nports; cnt++) - GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]); - GNUNET_free (peer->ports); - } - GNUNET_free (peer); + { + for (cnt = 0; cnt < peer->nports; cnt++) + GNUNET_TESTING_release_port(peer->system, peer->ports[cnt]); + GNUNET_free(peer->ports); + } + GNUNET_free(peer); } @@ -1600,20 +1595,19 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer) * @return 0 on success, 1 on error */ int -GNUNET_TESTING_peer_run (const char *testdir, - const char *cfgfilename, - GNUNET_TESTING_TestMain tm, - void *tm_cls) +GNUNET_TESTING_peer_run(const char *testdir, + const char *cfgfilename, + GNUNET_TESTING_TestMain tm, + void *tm_cls) { - return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls); + return GNUNET_TESTING_service_run(testdir, "arm", cfgfilename, tm, tm_cls); } /** * Structure for holding service data */ -struct ServiceContext -{ +struct ServiceContext { /** * The configuration of the peer in which the service is run */ @@ -1642,11 +1636,11 @@ struct ServiceContext * @param cls the ServiceContext */ static void -service_run_main (void *cls) +service_run_main(void *cls) { struct ServiceContext *sc = cls; - sc->tm (sc->tm_cls, sc->cfg, sc->peer); + sc->tm(sc->tm_cls, sc->cfg, sc->peer); } @@ -1672,11 +1666,11 @@ service_run_main (void *cls) * @return 0 on success, 1 on error */ int -GNUNET_TESTING_service_run (const char *testdir, - const char *service_name, - const char *cfgfilename, - GNUNET_TESTING_TestMain tm, - void *tm_cls) +GNUNET_TESTING_service_run(const char *testdir, + const char *service_name, + const char *cfgfilename, + GNUNET_TESTING_TestMain tm, + void *tm_cls) { struct ServiceContext sc; struct GNUNET_TESTING_System *system; @@ -1685,70 +1679,70 @@ GNUNET_TESTING_service_run (const char *testdir, char *binary; char *libexec_binary; - GNUNET_log_setup (testdir, "WARNING", NULL); - system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL); + GNUNET_log_setup(testdir, "WARNING", NULL); + system = GNUNET_TESTING_system_create(testdir, "127.0.0.1", NULL, NULL); if (NULL == system) return 1; - cfg = GNUNET_CONFIGURATION_create (); - if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename)) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to load configuration from %s\n"), - cfgfilename); - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_TESTING_system_destroy (system, GNUNET_YES); - return 1; - } - peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL); + cfg = GNUNET_CONFIGURATION_create(); + if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfgfilename)) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Failed to load configuration from %s\n"), + cfgfilename); + GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_TESTING_system_destroy(system, GNUNET_YES); + return 1; + } + peer = GNUNET_TESTING_peer_configure(system, cfg, 0, NULL, NULL); if (NULL == peer) - { - GNUNET_CONFIGURATION_destroy (cfg); - hostkeys_unload (system); - GNUNET_TESTING_system_destroy (system, GNUNET_YES); - return 1; - } - GNUNET_free (peer->main_binary); - GNUNET_free (peer->args); - GNUNET_asprintf (&binary, "gnunet-service-%s", service_name); - libexec_binary = GNUNET_OS_get_libexec_binary_path (binary); + { + GNUNET_CONFIGURATION_destroy(cfg); + hostkeys_unload(system); + GNUNET_TESTING_system_destroy(system, GNUNET_YES); + return 1; + } + GNUNET_free(peer->main_binary); + GNUNET_free(peer->args); + GNUNET_asprintf(&binary, "gnunet-service-%s", service_name); + libexec_binary = GNUNET_OS_get_libexec_binary_path(binary); if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, - service_name, - "PREFIX", - &peer->main_binary)) - { - /* No prefix */ - GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary); - peer->args = GNUNET_strdup (""); - } + GNUNET_CONFIGURATION_get_value_string(cfg, + service_name, + "PREFIX", + &peer->main_binary)) + { + /* No prefix */ + GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary); + peer->args = GNUNET_strdup(""); + } else - peer->args = GNUNET_strdup (libexec_binary); - - GNUNET_free (libexec_binary); - GNUNET_free (binary); - if (GNUNET_OK != GNUNET_TESTING_peer_start (peer)) - { - GNUNET_TESTING_peer_destroy (peer); - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_TESTING_system_destroy (system, GNUNET_YES); - return 1; - } + peer->args = GNUNET_strdup(libexec_binary); + + GNUNET_free(libexec_binary); + GNUNET_free(binary); + if (GNUNET_OK != GNUNET_TESTING_peer_start(peer)) + { + GNUNET_TESTING_peer_destroy(peer); + GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_TESTING_system_destroy(system, GNUNET_YES); + return 1; + } sc.cfg = cfg; sc.tm = tm; sc.tm_cls = tm_cls; sc.peer = peer; - GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */ + GNUNET_SCHEDULER_run(&service_run_main, &sc); /* Scheduler loop */ if ((NULL != peer->main_process) && - (GNUNET_OK != GNUNET_TESTING_peer_stop (peer))) - { - GNUNET_TESTING_peer_destroy (peer); - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_TESTING_system_destroy (system, GNUNET_YES); - return 1; - } - GNUNET_TESTING_peer_destroy (peer); - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_TESTING_system_destroy (system, GNUNET_YES); + (GNUNET_OK != GNUNET_TESTING_peer_stop(peer))) + { + GNUNET_TESTING_peer_destroy(peer); + GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_TESTING_system_destroy(system, GNUNET_YES); + return 1; + } + GNUNET_TESTING_peer_destroy(peer); + GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_TESTING_system_destroy(system, GNUNET_YES); return 0; } @@ -1767,22 +1761,22 @@ GNUNET_TESTING_service_run (const char *testdir, * NULL if argv0 has no '_' */ char * -GNUNET_TESTING_get_testname_from_underscore (const char *argv0) +GNUNET_TESTING_get_testname_from_underscore(const char *argv0) { - size_t slen = strlen (argv0) + 1; + size_t slen = strlen(argv0) + 1; char sbuf[slen]; char *ret; char *dot; - GNUNET_memcpy (sbuf, argv0, slen); - ret = strrchr (sbuf, '_'); + GNUNET_memcpy(sbuf, argv0, slen); + ret = strrchr(sbuf, '_'); if (NULL == ret) return NULL; ret++; /* skip underscore */ - dot = strchr (ret, '.'); + dot = strchr(ret, '.'); if (NULL != dot) *dot = '\0'; - return GNUNET_strdup (ret); + return GNUNET_strdup(ret); } -- cgit v1.2.3