gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r14221 - in gnunet/src: include testing
Date: Fri, 21 Jan 2011 16:19:25 +0100

Author: nevans
Date: 2011-01-21 16:19:25 +0100 (Fri, 21 Jan 2011)
New Revision: 14221

Modified:
   gnunet/src/include/gnunet_testing_lib.h
   gnunet/src/testing/test_testing.c
   gnunet/src/testing/test_testing_connect.c
   gnunet/src/testing/test_testing_data_topology_clique.conf
   gnunet/src/testing/test_testing_topology.c
   gnunet/src/testing/testing.c
   gnunet/src/testing/testing_group.c
Log:
enable reading of hostkeys from a file for testing, also loading of topology 
from topology file

Modified: gnunet/src/include/gnunet_testing_lib.h
===================================================================
--- gnunet/src/include/gnunet_testing_lib.h     2011-01-20 19:49:22 UTC (rev 
14220)
+++ gnunet/src/include/gnunet_testing_lib.h     2011-01-21 15:19:25 UTC (rev 
14221)
@@ -43,6 +43,8 @@
 #endif
 #endif
 
+#define HOSTKEYFILESIZE 914
+
 /**
  * Handle for a GNUnet daemon (technically a set of
  * daemons; the handle is really for the master ARM
@@ -409,6 +411,7 @@
  *        (use NULL for localhost).
  * @param ssh_username ssh username to use when connecting to hostname
  * @param sshport port to pass to ssh process when connecting to hostname
+ * @param hostkey pointer to a hostkey to be written to disk (instead of being 
generated)
  * @param hostkey_callback function to call once the hostkey has been
  *        generated for this peer, but it hasn't yet been started
  *        (NULL to start immediately, otherwise waits on 
GNUNET_TESTING_daemon_continue_start)
@@ -423,8 +426,9 @@
                              const char *hostname,
                              const char *ssh_username,
                              uint16_t sshport,
-                             GNUNET_TESTING_NotifyHostkeyCreated 
hostkey_callback,
-                             void *hostkey_cls,
+                             const char *hostkey,
+                             GNUNET_TESTING_NotifyHostkeyCreated
+                             hostkey_callback, void *hostkey_cls,
                              GNUNET_TESTING_NotifyDaemonRunning cb,
                              void *cb_cls);
 

Modified: gnunet/src/testing/test_testing.c
===================================================================
--- gnunet/src/testing/test_testing.c   2011-01-20 19:49:22 UTC (rev 14220)
+++ gnunet/src/testing/test_testing.c   2011-01-21 15:19:25 UTC (rev 14221)
@@ -76,7 +76,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
 #endif
   d =
-    GNUNET_TESTING_daemon_start (cfg, TIMEOUT, NULL, NULL, 0, NULL, NULL,
+    GNUNET_TESTING_daemon_start (cfg, TIMEOUT, NULL, NULL, 0, NULL, NULL, NULL,
                                  &my_cb, NULL);
   GNUNET_assert (d != NULL);
 }

Modified: gnunet/src/testing/test_testing_connect.c
===================================================================
--- gnunet/src/testing/test_testing_connect.c   2011-01-20 19:49:22 UTC (rev 
14220)
+++ gnunet/src/testing/test_testing_connect.c   2011-01-21 15:19:25 UTC (rev 
14221)
@@ -133,7 +133,7 @@
               "Daemon `%s' started.\n", GNUNET_i2s (id));
 #endif
   d2 =
-    GNUNET_TESTING_daemon_start (c2, TIMEOUT, NULL, NULL, 0, NULL, NULL,
+    GNUNET_TESTING_daemon_start (c2, TIMEOUT, NULL, NULL, 0, NULL, NULL, NULL,
                                  &my_cb2, NULL);
   GNUNET_assert (d2 != NULL);
 
@@ -154,7 +154,7 @@
   c2 = GNUNET_CONFIGURATION_create ();
   GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf");
   d1 =
-    GNUNET_TESTING_daemon_start (c1, TIMEOUT, NULL, NULL, 0, NULL, NULL,
+    GNUNET_TESTING_daemon_start (c1, TIMEOUT, NULL, NULL, 0, NULL, NULL, NULL,
                                  &my_cb1, NULL);
   GNUNET_assert (d1 != NULL);
 }

Modified: gnunet/src/testing/test_testing_data_topology_clique.conf
===================================================================
--- gnunet/src/testing/test_testing_data_topology_clique.conf   2011-01-20 
19:49:22 UTC (rev 14220)
+++ gnunet/src/testing/test_testing_data_topology_clique.conf   2011-01-21 
15:19:25 UTC (rev 14221)
@@ -23,6 +23,7 @@
 
 [transport-tcp]
 PORT = 2568
+ENABLE_UPNP = NO
 
 [transport-udp]
 PORT = 2568

Modified: gnunet/src/testing/test_testing_topology.c
===================================================================
--- gnunet/src/testing/test_testing_topology.c  2011-01-20 19:49:22 UTC (rev 
14220)
+++ gnunet/src/testing/test_testing_topology.c  2011-01-21 15:19:25 UTC (rev 
14221)
@@ -26,7 +26,7 @@
 #include "gnunet_core_service.h"
 #include "gnunet_os_lib.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
 
 #define DELAY_FOR_LOGGING GNUNET_NO
 

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2011-01-20 19:49:22 UTC (rev 14220)
+++ gnunet/src/testing/testing.c        2011-01-21 15:19:25 UTC (rev 14221)
@@ -385,6 +385,7 @@
           return;
         }
       d->hostkeybuf[103] = '\0';
+
       if ((bytes_read < 0) ||
           (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf,
                                                         &d->id.hashPubKey)))
@@ -789,6 +790,7 @@
  *        (use NULL for localhost).
  * @param ssh_username ssh username to use when connecting to hostname
  * @param sshport port to pass to ssh process when connecting to hostname
+ * @param hostkey pointer to a hostkey to be written to disk (instead of being 
generated)
  * @param hostkey_callback function to call once the hostkey has been
  *        generated for this peer, but it hasn't yet been started
  *        (NULL to start immediately, otherwise waits on 
GNUNET_TESTING_daemon_continue_start)
@@ -803,6 +805,7 @@
                              const char *hostname,
                              const char *ssh_username,
                              uint16_t sshport,
+                             const char *hostkey,
                              GNUNET_TESTING_NotifyHostkeyCreated
                              hostkey_callback, void *hostkey_cls,
                              GNUNET_TESTING_NotifyDaemonRunning cb,
@@ -811,6 +814,9 @@
   struct GNUNET_TESTING_Daemon *ret;
   char *arg;
   char *username;
+  char *servicehome;
+  char *hostkeyfile;
+  struct GNUNET_DISK_FileHandle *fn;
 
   ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
   ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
@@ -842,6 +848,28 @@
   GNUNET_CONFIGURATION_set_value_string (ret->cfg,
                                          "PATHS",
                                          "DEFAULTCONFIG", ret->cfgfile);
+  if (hostkey != NULL)
+    {
+      GNUNET_assert(GNUNET_OK ==
+                    GNUNET_CONFIGURATION_get_value_string (ret->cfg,
+                                                           "PATHS",
+                                                           "SERVICEHOME",
+                                                           &servicehome));
+      GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome));
+      GNUNET_asprintf(&hostkeyfile, "%s/.hostkey", servicehome);
+      fn =
+      GNUNET_DISK_file_open (hostkeyfile,
+                             GNUNET_DISK_OPEN_READWRITE
+                             | GNUNET_DISK_OPEN_CREATE,
+                             GNUNET_DISK_PERM_USER_READ |
+                             GNUNET_DISK_PERM_USER_WRITE);
+      GNUNET_assert(fn != NULL);
+      GNUNET_assert(HOSTKEYFILESIZE == GNUNET_DISK_file_write(fn, hostkey, 
HOSTKEYFILESIZE));
+      GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fn));
+      GNUNET_free(servicehome);
+      GNUNET_free(hostkeyfile);
+    }
+
   /* 1) write configuration to temporary file */
   if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
     {

Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c  2011-01-20 19:49:22 UTC (rev 14220)
+++ gnunet/src/testing/testing_group.c  2011-01-21 15:19:25 UTC (rev 14221)
@@ -304,6 +304,11 @@
   const char *username;
 
   /**
+   * Pointer to starting memory location of a hostkey
+   */
+  const char *hostkey;
+
+  /**
    * Port to use for ssh.
    */
   uint16_t sshport;
@@ -629,6 +634,96 @@
   uint32_t first_uid;
 };
 
+struct RandomContext
+{
+  /**
+   * The peergroup
+   */
+  struct GNUNET_TESTING_PeerGroup *pg;
+
+  /**
+   * uid of the first peer
+   */
+  uint32_t first_uid;
+
+  /**
+   * Peer data for first peer.
+   */
+  struct PeerData *first;
+
+  /**
+   * Random percentage to use
+   */
+  double percentage;
+};
+
+struct MinimumContext
+{
+  /**
+   * The peergroup
+   */
+  struct GNUNET_TESTING_PeerGroup *pg;
+
+  /**
+   * uid of the first peer
+   */
+  uint32_t first_uid;
+
+  /**
+   * Peer data for first peer.
+   */
+  struct PeerData *first;
+
+  /**
+   * Number of conns per peer
+   */
+  unsigned int num_to_add;
+
+  /**
+   * Permuted array of all possible connections.  Only add the Nth
+   * peer if it's in the Nth position.
+   */
+  unsigned int *pg_array;
+
+  /**
+   * What number is the current element we are iterating over?
+   */
+  unsigned int current;
+};
+
+struct DFSContext
+{
+  /**
+   * The peergroup
+   */
+  struct GNUNET_TESTING_PeerGroup *pg;
+
+  /**
+   * uid of the first peer
+   */
+  uint32_t first_uid;
+
+  /**
+   * uid of the second peer
+   */
+  uint32_t second_uid;
+
+  /**
+   * Peer data for first peer.
+   */
+  struct PeerData *first;
+
+  /**
+   * Which peer has been chosen as the one to add?
+   */
+  unsigned int chosen;
+
+  /**
+   * What number is the current element we are iterating over?
+   */
+  unsigned int current;
+};
+
 /**
  * Convert unique ID to hash code.
  *
@@ -2100,6 +2195,7 @@
               return connect_attempts;
             }
           GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read %u total peers in 
topology\n", total_peers);
+          GNUNET_assert(total_peers == pg->total);
           curr_state = PEER_INDEX;
           while((buf[count] != '\n') && (count < frstat.st_size - 1))
             count++;
@@ -2131,18 +2227,19 @@
               return connect_attempts;
             }
           GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read second peer index %u\n", 
second_peer_index);
-          while((buf[count] != '\n') && (buf[count] != ' ') && (count < 
frstat.st_size - 1))
+          /* Assume file is written with first peer 1, but array index is 0 */
+          connect_attempts += proc (pg, first_peer_index - 1, 
second_peer_index - 1);
+          while((buf[count] != '\n') && (buf[count] != ',') && (count < 
frstat.st_size - 1))
             count++;
           if (buf[count] == '\n')
           {
             curr_state = PEER_INDEX;
           }
-          else if (buf[count] != ' ')
+          else if (buf[count] != ',')
           {
             curr_state = OTHER_PEER_INDEX;
           }
           count++;
-          curr_state = OTHER_PEER_INDEX;
           break;
         default:
           GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Found bad data in topology file 
while in state %d!\n", curr_state);
@@ -3078,96 +3175,7 @@
   return num_connections;
 }
 
-struct RandomContext
-{
-  /**
-   * The peergroup
-   */
-  struct GNUNET_TESTING_PeerGroup *pg;
 
-  /**
-   * uid of the first peer
-   */
-  uint32_t first_uid;
-
-  /**
-   * Peer data for first peer.
-   */
-  struct PeerData *first;
-
-  /**
-   * Random percentage to use
-   */
-  double percentage;
-};
-
-struct MinimumContext
-{
-  /**
-   * The peergroup
-   */
-  struct GNUNET_TESTING_PeerGroup *pg;
-
-  /**
-   * uid of the first peer
-   */
-  uint32_t first_uid;
-
-  /**
-   * Peer data for first peer.
-   */
-  struct PeerData *first;
-
-  /**
-   * Number of conns per peer
-   */
-  unsigned int num_to_add;
-
-  /**
-   * Permuted array of all possible connections.  Only add the Nth
-   * peer if it's in the Nth position.
-   */
-  unsigned int *pg_array;
-
-  /**
-   * What number is the current element we are iterating over?
-   */
-  unsigned int current;
-};
-
-struct DFSContext
-{
-  /**
-   * The peergroup
-   */
-  struct GNUNET_TESTING_PeerGroup *pg;
-
-  /**
-   * uid of the first peer
-   */
-  uint32_t first_uid;
-
-  /**
-   * uid of the second peer
-   */
-  uint32_t second_uid;
-
-  /**
-   * Peer data for first peer.
-   */
-  struct PeerData *first;
-
-  /**
-   * Which peer has been chosen as the one to add?
-   */
-  unsigned int chosen;
-
-  /**
-   * What number is the current element we are iterating over?
-   */
-  unsigned int current;
-};
-
 /**
  * Iterator for choosing random peers to connect.
  *
@@ -4324,6 +4332,7 @@
                                      internal_context->hostname,
                                      internal_context->username,
                                      internal_context->sshport,
+                                     internal_context->hostkey,
                                      &internal_hostkey_callback,
                                      internal_context,
                                      &internal_startup_callback,
@@ -4405,6 +4414,9 @@
   char *baseservicehome;
   char *newservicehome;
   char *tmpdir;
+  char *hostkeys_file;
+  char *hostkey_data;
+  struct GNUNET_DISK_FileHandle *fd;
   struct GNUNET_CONFIGURATION_Handle *pcfg;
   unsigned int off;
   unsigned int hostcnt;
@@ -4412,12 +4424,15 @@
   uint16_t sshport;
   uint32_t upnum;
   uint32_t fdnum;
+  uint64_t fs;
+  uint64_t total_hostkeys;
 
   if (0 == total)
     {
       GNUNET_break (0);
       return NULL;
     }
+  hostkey_data = NULL;
   upnum = 0;
   fdnum = 0;
   pg = GNUNET_malloc (sizeof (struct GNUNET_TESTING_PeerGroup));
@@ -4509,6 +4524,42 @@
       hostcnt = 0;
       minport = LOW_PORT;
     }
+
+  if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", 
"HOSTKEYSFILE",
+                                                          &hostkeys_file))
+    {
+      if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
+        GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Couldn't read hostkeys file!");
+      else
+        {
+          /* Check hostkey file size, read entire thing into memory */
+          fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ,
+                                      GNUNET_DISK_PERM_NONE);
+          if (NULL == fd)
+            {
+              GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", 
hostkeys_file);
+              return NULL;
+            }
+
+          if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, 
GNUNET_YES))
+            fs = 0;
+
+          GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found file size %llu for 
hostkeys, expect hostkeys to be size %d\n", fs, HOSTKEYFILESIZE);
+
+          if (fs % HOSTKEYFILESIZE != 0)
+            {
+              GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "File size %llu seems 
incorrect for hostkeys...\n", fs);
+            }
+          else
+            {
+              total_hostkeys = fs / HOSTKEYFILESIZE;
+              GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Will read %llu hostkeys 
from file\n", total_hostkeys);
+              hostkey_data = GNUNET_malloc_large (fs);
+              GNUNET_assert (fs == GNUNET_DISK_file_read (fd, hostkey_data, 
fs));
+            }
+        }
+    }
+
   for (off = 0; off < total; off++)
     {
       if (hostcnt > 0)
@@ -4570,6 +4621,8 @@
       pg->peers[off].internal_context.hostname = hostname;
       pg->peers[off].internal_context.username = username;
       pg->peers[off].internal_context.sshport = sshport;
+      if (hostkey_data != NULL)
+        pg->peers[off].internal_context.hostkey = &hostkey_data[off * 
HOSTKEYFILESIZE];
       pg->peers[off].internal_context.hostkey_callback = hostkey_callback;
       pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
       pg->peers[off].internal_context.start_cb = cb;




reply via email to

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