- docs
[oweals/gnunet.git] / src / testbed / testbed_api_hosts.c
index 374fee8ef1302c25d4fa9acf4f3ee5982c031123..cd805dca1af7a04b6331bb6d9422406ef13b9bc8 100644 (file)
@@ -486,13 +486,13 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
     {
       data[offset] = '\0';
       ret =
-          SSCANF (buf, "%255[a-zA-Z0-9_]@%255[a-zA-Z0-9.-]:%5hd", username,
+          SSCANF (buf, "%255[a-zA-Z0-9_]@%255[.a-zA-Z0-9-]:%5hd", username,
                   hostname, &port);
       if (3 == ret)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Successfully read host %s, port %d and user %s from file\n",
-                    hostname, port, username);
+        LOG (GNUNET_ERROR_TYPE_DEBUG,
+             "Successfully read host %s, port %d and user %s from file\n",
+             hostname, port, username);
         /* We store hosts in a static list; hence we only require the starting
          * host pointer in that list to access the newly created list of hosts */
         if (NULL == starting_host)
@@ -561,6 +561,17 @@ simple_resolve (const char *host)
   return hostip;
 }
 
+#if ENABLE_LL
+static int
+cmpstringp(const void *p1, const void *p2)
+{
+  /* The actual arguments to this function are "pointers to
+     pointers to char", but strcmp(3) arguments are "pointers
+     to char", hence the following cast plus dereference */
+  
+  return strcmp(* (char * const *) p1, * (char * const *) p2);
+}
+#endif
 
 /**
  * Loads the set of host allocated by the LoadLeveler Job Scheduler.  This
@@ -589,8 +600,6 @@ GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
   char *buf;
   char *hostname;
   char **hostnames;
-  char **hostaddrs;
-  const char *hostip;
   struct GNUNET_TESTBED_Host **host_list;
   ssize_t rsize;
   uint64_t size;
@@ -603,7 +612,6 @@ GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
   } pstep;
   unsigned int host;
   unsigned int nhosts;
-  unsigned int nhostaddrs;
   
   if (NULL == (hostfile = getenv ("MP_SAVEHOSTFILE")))
   {
@@ -634,9 +642,7 @@ GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
   pstep = SCAN;
   hostname = NULL;
   hostnames = NULL;
-  hostaddrs = NULL;
   nhosts = 0;
-  nhostaddrs = 0;
   while (offset < size)
   {
     switch (pstep)
@@ -692,31 +698,18 @@ GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
   GNUNET_free_non_null (buf);
   if (NULL == hostnames)
     return 0;
-  for (host = 0; host < nhosts; host++)
-  {
-    hostip = simple_resolve (hostnames[host]);
-    if (NULL == hostip)
-    {
-      nhosts = 0;
-      goto cleanup;
-    }
-    GNUNET_array_append (hostaddrs, nhostaddrs, GNUNET_strdup (hostip));
-  }
-  GNUNET_assert (nhostaddrs == nhosts);
   if (NULL == hosts)
     goto cleanup;
-  host_list = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * nhostaddrs);
+  qsort (hostnames, nhosts, sizeof (hostnames[0]), cmpstringp);
+  host_list = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * nhosts);
   for (host = 0; host < nhosts; host++)
-    host_list[host] = GNUNET_TESTBED_host_create (hostaddrs[host], NULL, cfg, 0);
+    host_list[host] = GNUNET_TESTBED_host_create (hostnames[host], NULL, cfg, 0);
   *hosts = host_list;
 
  cleanup:
   for (host = 0; host < nhosts; host++)
     GNUNET_free (hostnames[host]);
   GNUNET_free(hostnames);
-  for (host = 0; (NULL != hostaddrs) && (host < nhostaddrs); host++)
-    GNUNET_free (hostaddrs[host]);
-  GNUNET_free (hostaddrs);
   return nhosts;
 #endif
 }
@@ -1093,8 +1086,7 @@ helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message)
   GNUNET_assert (GNUNET_CONFIGURATION_deserialize
                  (cp->host->cfg, config, config_size, GNUNET_NO));
   GNUNET_free (config);
-  if ((NULL == cp->host) ||
-      (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))))
+  if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))
     hostname = "localhost";
   /* Change the hostname so that we can connect to it */
   GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, "testbed", "hostname",
@@ -1703,12 +1695,12 @@ decide_npoc (struct GNUNET_TESTBED_Host *h)
   }
   GNUNET_assert (nvals >= h->num_parallel_connects);
   avg = GNUNET_TIME_relative_divide (avg, nvals);
-  GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != avg.rel_value);
-  sd = GNUNET_TESTBED_SD_deviation_factor_ (h->poc_sd, (unsigned int) avg.rel_value);
+  GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != avg.rel_value_us);
+  sd = GNUNET_TESTBED_SD_deviation_factor_ (h->poc_sd, (unsigned int) avg.rel_value_us);
   if ( (sd <= 5) ||
        (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
                                       h->num_parallel_connects)) )
-    GNUNET_TESTBED_SD_add_data_ (h->poc_sd, (unsigned int) avg.rel_value);
+    GNUNET_TESTBED_SD_add_data_ (h->poc_sd, (unsigned int) avg.rel_value_us);
   if (GNUNET_SYSERR == sd)
   {
     GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
@@ -1806,7 +1798,7 @@ GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Host *h,
     return;
   slot = &h->tslots[index];
   slot->nvals++;
-  if (GNUNET_TIME_UNIT_ZERO.rel_value == slot->time.rel_value)
+  if (GNUNET_TIME_UNIT_ZERO.rel_value_us == slot->time.rel_value_us)
   {
     slot->time = time;
     h->tslots_filled++;
@@ -1890,4 +1882,27 @@ GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c,
   return GNUNET_OK;
 }
 
+
+/**
+ * Resolves the hostname of the host to an ip address
+ *
+ * @param host the host whose hostname is to be resolved
+ */
+void
+GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host)
+{
+  char *hostname;
+
+  hostname = (char *) host->hostname;
+  host->hostname = simple_resolve (hostname);
+  if (NULL == host->hostname)
+  {
+    GNUNET_break (0);
+    host->hostname = hostname;
+    return;
+  }
+  GNUNET_free (hostname);
+  host->hostname = GNUNET_strdup (host->hostname);
+}
+
 /* end of testbed_api_hosts.c */