From 81f52a300c6569a292db1137690347b0986fe953 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 7 Dec 2011 15:34:26 +0000 Subject: [PATCH] --- src/include/gnunet_testing_lib.h | 23 ++++++++++++++++ src/testing/gnunet-testing.c | 46 +++++++++++++++++++++++++++++++- src/testing/testing_group.c | 11 ++++---- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index e3e10ce45..711d676a2 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h @@ -614,6 +614,29 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, int delete_files, int allow_restart); + +/** + * Create a new configuration using the given configuration + * as a template; however, each PORT in the existing cfg + * must be renumbered by incrementing "*port". If we run + * out of "*port" numbers, return NULL. + * + * @param cfg template configuration + * @param off the current peer offset + * @param port port numbers to use, update to reflect + * port numbers that were used + * @param upnum number to make unix domain socket names unique + * @param hostname hostname of the controlling host, to allow control connections from + * @param fdnum number used to offset the unix domain socket for grouped processes + * (such as statistics or peerinfo, which can be shared among others) + * + * @return new configuration, NULL on error + */ +struct GNUNET_CONFIGURATION_Handle * +GNUNET_TESTING_create_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, + uint16_t * port, uint32_t * upnum, const char *hostname, + uint32_t * fdnum); + /** * Changes the configuration of a GNUnet daemon. * diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c index a65e19d6f..e0d5d4f28 100644 --- a/src/testing/gnunet-testing.c +++ b/src/testing/gnunet-testing.c @@ -43,12 +43,56 @@ static char * create_cfg_template; static int create_unique_cfgs (const char * template, const unsigned int no) { + int fail = GNUNET_NO; + + uint16_t port = 20000; + uint32_t upnum = 1; + uint32_t fdnum = 1; + 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; } - return 0; + + int cur = 0; + char * cur_file; + struct GNUNET_CONFIGURATION_Handle *cfg_tmpl = GNUNET_CONFIGURATION_create(); + struct GNUNET_CONFIGURATION_Handle *cfg_new = NULL; + + if (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; + } + + while (cur < no) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating configuration no. %u \n", cur); + GNUNET_asprintf(&cur_file,"%04u-%s",cur, create_cfg_template); + cfg_new = GNUNET_TESTING_create_cfg(cfg_tmpl, cur, &port, &upnum, NULL, &fdnum); + + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "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_free (cur_file); + if (fail == GNUNET_YES) + break; + cur ++; + } + + GNUNET_CONFIGURATION_destroy(cfg_tmpl); + if (fail == GNUNET_NO) + return 0; + else + return 1; } /** diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 26aac5e7c..f56c51381 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -1435,8 +1435,8 @@ update_config (void *cls, const char *section, const char *option, * * @return new configuration, NULL on error */ -static struct GNUNET_CONFIGURATION_Handle * -make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, +struct GNUNET_CONFIGURATION_Handle * +GNUNET_TESTING_create_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, uint16_t * port, uint32_t * upnum, const char *hostname, uint32_t * fdnum) { @@ -1540,6 +1540,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, } else { + GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-tcp", "USE_LOCALADDR", "YES"); GNUNET_CONFIGURATION_set_value_string (uc.ret, "transport-udp", @@ -1550,7 +1551,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, "127.0.0.1"); GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "EXTERNAL_ADDRESS", "127.0.0.1"); - GNUNET_CONFIGURATION_set_value_string (uc.ret, "disablev6", "BINDTO", + GNUNET_CONFIGURATION_set_value_string (uc.ret, "nat", "disablev6", "YES"); } @@ -6159,7 +6160,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, username = pg->hosts[off % hostcnt].username; sshport = pg->hosts[off % hostcnt].sshport; pcfg = - make_config (cfg, off, &pg->hosts[off % hostcnt].minport, &upnum, + GNUNET_TESTING_create_cfg (cfg, off, &pg->hosts[off % hostcnt].minport, &upnum, hostname, &fdnum); } else @@ -6167,7 +6168,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, hostname = NULL; username = NULL; sshport = 0; - pcfg = make_config (cfg, off, &minport, &upnum, hostname, &fdnum); + pcfg = GNUNET_TESTING_create_cfg (cfg, off, &minport, &upnum, hostname, &fdnum); } if (NULL == pcfg) -- 2.25.1