gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r16194 - in gnunet/src: include nse testing


From: gnunet
Subject: [GNUnet-SVN] r16194 - in gnunet/src: include nse testing
Date: Tue, 26 Jul 2011 14:39:23 +0200

Author: nevans
Date: 2011-07-26 14:39:23 +0200 (Tue, 26 Jul 2011)
New Revision: 16194

Modified:
   gnunet/src/include/gnunet_testing_lib.h
   gnunet/src/nse/nse-profiler.c
   gnunet/src/testing/testing_group.c
Log:
load hosts from file, implementation in testing

Modified: gnunet/src/include/gnunet_testing_lib.h
===================================================================
--- gnunet/src/include/gnunet_testing_lib.h     2011-07-26 10:33:53 UTC (rev 
16193)
+++ gnunet/src/include/gnunet_testing_lib.h     2011-07-26 12:39:23 UTC (rev 
16194)
@@ -602,33 +602,19 @@
                                     struct GNUNET_TIME_Relative timeout,
                                     GNUNET_TESTING_NotifyCompletion cb, void 
*cb_cls);
 
-
 /**
- * Establish a connection between two GNUnet daemons.
+ * Read a testing hosts file based on a configuration.
+ * Returns a DLL of hosts (caller must free!) on success
+ * or NULL on failure.
  *
- * @param d1 handle for the first daemon
- * @param d2 handle for the second daemon
- * @param timeout how long is the connection attempt
- *        allowed to take?
- * @param max_connect_attempts how many times should we try to reconnect
- *        (within timeout)
- * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume
- *                   the HELLO has already been exchanged
- * @param cb function to call at the end
- * @param cb_cls closure for cb
+ * @param cfg a configuration with a testing section
+ *
+ * @return DLL of hosts on success, NULL on failure
  */
-void
-GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
-                                struct GNUNET_TESTING_Daemon *d2,
-                                struct GNUNET_TIME_Relative timeout,
-                                unsigned int max_connect_attempts,
-                                int send_hello,
-                                GNUNET_TESTING_NotifyConnection cb,
-                                void *cb_cls);
+struct GNUNET_TESTING_Host *
+GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg);
 
 
-
-
 /**
  * Start count gnunet instances with the same set of transports and
  * applications.  The port numbers (any option called "PORT") will be
@@ -679,7 +665,32 @@
 void
 GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg);
 
+
 /**
+ * Establish a connection between two GNUnet daemons.
+ *
+ * @param d1 handle for the first daemon
+ * @param d2 handle for the second daemon
+ * @param timeout how long is the connection attempt
+ *        allowed to take?
+ * @param max_connect_attempts how many times should we try to reconnect
+ *        (within timeout)
+ * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume
+ *                   the HELLO has already been exchanged
+ * @param cb function to call at the end
+ * @param cb_cls closure for cb
+ */
+void
+GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
+                                struct GNUNET_TESTING_Daemon *d2,
+                                struct GNUNET_TIME_Relative timeout,
+                                unsigned int max_connect_attempts,
+                                int send_hello,
+                                GNUNET_TESTING_NotifyConnection cb,
+                                void *cb_cls);
+
+
+/**
  * Restart all peers in the given group.
  *
  * @param pg the handle to the peer group

Modified: gnunet/src/nse/nse-profiler.c
===================================================================
--- gnunet/src/nse/nse-profiler.c       2011-07-26 10:33:53 UTC (rev 16193)
+++ gnunet/src/nse/nse-profiler.c       2011-07-26 12:39:23 UTC (rev 16194)
@@ -580,6 +580,7 @@
 {
   char *temp_str;
   unsigned long long temp_wait;
+  struct GNUNET_TESTING_Host *hosts;
 
   ok = 1;
   testing_cfg = GNUNET_CONFIGURATION_create();
@@ -673,12 +674,14 @@
     }
   GNUNET_free_non_null(temp_str);
 
+  hosts = GNUNET_TESTING_hosts_load (testing_cfg);
+
   pg = GNUNET_TESTING_peergroup_start(testing_cfg,
                                       num_peers,
                                       TIMEOUT,
                                       &connect_cb,
                                       &my_cb, NULL,
-                                      NULL);
+                                      hosts);
   GNUNET_assert (pg != NULL);
   shutdown_handle = GNUNET_SCHEDULER_add_delayed 
(GNUNET_TIME_relative_get_forever(),
                                                  &shutdown_task,

Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c  2011-07-26 10:33:53 UTC (rev 16193)
+++ gnunet/src/testing/testing_group.c  2011-07-26 12:39:23 UTC (rev 16194)
@@ -6811,7 +6811,106 @@
 
 }
 
+/**
+ * Read a testing hosts file based on a configuration.
+ * Returns a DLL of hosts (caller must free!) on success
+ * or NULL on failure.
+ *
+ * @param cfg a configuration with a testing section
+ *
+ * @return DLL of hosts on success, NULL on failure
+ */
+struct GNUNET_TESTING_Host *
+GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct GNUNET_TESTING_Host *hosts;
+  struct GNUNET_TESTING_Host *temphost;
+  char *data;
+  char *buf;
+  char *hostfile;
+  struct stat frstat;
+  int count;
+  int ret;
 
+  /* Check for a hostfile containing address@hidden:port triples */
+  if (GNUNET_OK
+      != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
+                                                &hostfile))
+    return NULL;
+
+  hosts = NULL;
+  temphost = NULL;
+  data = NULL;
+  if (hostfile != NULL)
+    {
+      if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
+        GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
+            | GNUNET_DISK_PERM_USER_WRITE);
+      if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Could not open file specified for host list, ending 
test!");
+          GNUNET_free(hostfile);
+          return NULL;
+        }
+
+      data = GNUNET_malloc_large (frstat.st_size);
+      GNUNET_assert(data != NULL);
+      if (frstat.st_size
+          != GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
+        {
+          GNUNET_log (
+                      GNUNET_ERROR_TYPE_ERROR,
+                      "Could not read file %s specified for host list, ending 
test!",
+                      hostfile);
+          GNUNET_free (hostfile);
+          GNUNET_free (data);
+          return NULL;
+        }
+
+      GNUNET_free_non_null(hostfile);
+
+      buf = data;
+      count = 0;
+      while (count < frstat.st_size - 1)
+        {
+          count++;
+          if (((data[count] == '\n')) && (buf != &data[count]))
+            {
+              data[count] = '\0';
+              temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
+              ret = sscanf (buf, "address@hidden:%hd",
+                            &temphost->username, &temphost->hostname,
+                            &temphost->port);
+              if (3 == ret)
+                {
+                  GNUNET_log (
+                              GNUNET_ERROR_TYPE_DEBUG,
+                              "Successfully read host %s, port %d and user %s 
from file\n",
+                              temphost->hostname, temphost->port,
+                              temphost->username);
+                }
+              else
+                {
+                  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                              "Error reading line `%s' in hostfile\n", buf);
+                  GNUNET_free(temphost);
+                  buf = &data[count + 1];
+                  continue;
+                }
+              temphost->next = hosts;
+              hosts = temphost;
+              buf = &data[count + 1];
+            }
+          else if ((data[count] == '\n') || (data[count] == '\0'))
+            buf = &data[count + 1];
+        }
+    }
+  GNUNET_free_non_null(data);
+
+  return hosts;
+}
+
 /**
  * Shutdown all peers started in the given group.
  *




reply via email to

[Prev in Thread] Current Thread [Next in Thread]