(no commit message)
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 7 Dec 2011 15:34:26 +0000 (15:34 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 7 Dec 2011 15:34:26 +0000 (15:34 +0000)
src/include/gnunet_testing_lib.h
src/testing/gnunet-testing.c
src/testing/testing_group.c

index e3e10ce45fd8b1474707f395b1b8328a8610a99d..711d676a263f5b2ca590bb66646f86b6a41fc800 100644 (file)
@@ -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.
  *
index a65e19d6ff6e917bb0f78117094dcbf32b02c78b..e0d5d4f2864900c7a03144a2a3c533b75345559f 100644 (file)
@@ -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;
 }
 
 /**
index 26aac5e7cd922adcfc64b80a349176aab03497ea..f56c51381b6518350237a8c371b5857723345b56 100644 (file)
@@ -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)