transport-testing uses precomputed hostkeys to improve speed especially on slow systems
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 16 Nov 2011 14:06:33 +0000 (14:06 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 16 Nov 2011 14:06:33 +0000 (14:06 +0000)
13 files changed:
src/transport/template_cfg_peer1.conf
src/transport/template_cfg_peer2.conf
src/transport/test_quota_compliance.c
src/transport/test_transport_api.c
src/transport/test_transport_api_bidirectional_connect.c
src/transport/test_transport_api_disconnect.c
src/transport/test_transport_api_reliability.c
src/transport/test_transport_api_timeout.c
src/transport/test_transport_api_unreliability.c
src/transport/test_transport_api_unreliability_constant.c
src/transport/test_transport_testing.c
src/transport/transport-testing.c
src/transport/transport-testing.h

index fbb4f7c4f10b5175081d81937265f27fb447b575..90ad9ab06516df9b966c0b6102b2cc464460c87d 100644 (file)
@@ -3,6 +3,9 @@
 SERVICEHOME = /tmp/test-transport/api-tcp-p1/
 DEFAULTCONFIG = template_cfg_peer1.conf
 
+[gnunetd]
+HOSTKEY = $SERVICEHOME/.hostkey
+
 [nat]
 RETURN_LOCAL_ADDRESSES = YES
 DISABLEV6 = NO
@@ -30,6 +33,7 @@ UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
 
 [transport]
 PORT = 12001
+#DEBUG = YES
 UNIXPATH = /tmp/gnunet-p1-service-transport.sock
 
 [ats]
index 7249fc4cceaac06739e4b880710b2867ddf23e92..cb5935f8107e6944e828c42fa7108b906da321e8 100644 (file)
@@ -3,6 +3,9 @@
 SERVICEHOME = /tmp/test-transport/api-tcp-p2/
 DEFAULTCONFIG = template_cfg_peer2.conf
 
+[gnunetd]
+HOSTKEY = $SERVICEHOME/.hostkey
+
 [nat]
 RETURN_LOCAL_ADDRESSES = YES
 DISABLEV6 = NO
index 7d28820cbdd6d429780a7c5ab28080b9a6bdd0e9..f4bc6fc545b176aac000905debc5e4e525ce50ae 100644 (file)
@@ -587,11 +587,6 @@ main (int argc, char *argv[])
 {
   int nat_res;
 
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-
-  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
-  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
-                                                 &test_plugin);
   GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
 
   GNUNET_log_setup (test_name,
@@ -602,6 +597,12 @@ main (int argc, char *argv[])
 #endif
                     NULL);
 
+  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
+  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
+                                                 &test_plugin);
+
+  tth = GNUNET_TRANSPORT_TESTING_init ();
+
   if ((strcmp (test_plugin, "tcp_nat") == 0) ||
       (strcmp (test_plugin, "udp_nat") == 0))
   {
index 47686f8d9774eb5df87dea1c3c4716c7fed97384..a040170194108848188edaffab169932ff9f1969 100644 (file)
@@ -370,12 +370,10 @@ main (int argc, char *argv[])
   int ret;
   int nat_res;
 
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-
+  GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
   GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
   GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
                                                  &test_plugin);
-  GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
 
   GNUNET_log_setup (test_name,
 #if VERBOSE
@@ -385,6 +383,8 @@ main (int argc, char *argv[])
 #endif
                     NULL);
 
+  tth = GNUNET_TRANSPORT_TESTING_init ();
+
   if ((strcmp (test_plugin, "tcp_nat") == 0) ||
       (strcmp (test_plugin, "udp_nat") == 0))
   {
index 06d007c81e2b542ebf4fcfd7e8e9e4e413fac027..bf8de42e99f12eb00f405c4b4c5ccbb208b08a2a 100644 (file)
@@ -378,11 +378,6 @@ main (int argc, char *argv[])
   int ret;
   int nat_res;
 
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-
-  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
-  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
-                                                 &test_plugin);
   GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
 
   GNUNET_log_setup (test_name,
@@ -393,6 +388,12 @@ main (int argc, char *argv[])
 #endif
                     NULL);
 
+  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
+  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
+                                                 &test_plugin);
+
+  tth = GNUNET_TRANSPORT_TESTING_init ();
+
   if ((strcmp (test_plugin, "tcp_nat") == 0) ||
       (strcmp (test_plugin, "udp_nat") == 0))
   {
index 68881fbe851bc016a2ad8b3888d3831db0995a7e..703de2a5b9f823a4daa5bd4e09d8d45b6ce6ccb8 100644 (file)
@@ -401,11 +401,6 @@ main (int argc, char *argv[])
   int ret;
   int nat_res;
 
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-
-  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
-  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
-                                                 &test_plugin);
   GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
 
   GNUNET_log_setup (test_name,
@@ -416,6 +411,12 @@ main (int argc, char *argv[])
 #endif
                     NULL);
 
+  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
+  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
+                                                 &test_plugin);
+
+  tth = GNUNET_TRANSPORT_TESTING_init ();
+
   if ((strcmp (test_plugin, "tcp_nat") == 0) ||
       (strcmp (test_plugin, "udp_nat") == 0))
   {
index 655f6f0a3f5c67ef309a61f7165a0ccda1577e8c..7b0b9207836dee7c2404d3d6ace674aef50c4809 100644 (file)
@@ -437,6 +437,7 @@ start_cb (struct PeerContext *p, void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Test triest to send from %u (%s) -> peer %u (%s)\n", sender->no,
               sender_c, receiver->no, GNUNET_i2s (&receiver->id));
+  GNUNET_free (sender_c);
 
   cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
                                                NULL);
@@ -500,11 +501,6 @@ main (int argc, char *argv[])
   int ret;
   int nat_res;
 
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-
-  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
-  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
-                                                 &test_plugin);
   GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
 
   GNUNET_log_setup (test_name,
@@ -515,6 +511,12 @@ main (int argc, char *argv[])
 #endif
                     NULL);
 
+  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
+  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
+                                                 &test_plugin);
+
+  tth = GNUNET_TRANSPORT_TESTING_init ();
+
   if ((strcmp (test_plugin, "tcp_nat") == 0) ||
       (strcmp (test_plugin, "udp_nat") == 0))
   {
index 79a90ba0e094881b3a10cc0dcf3d5aa5a3bfecf8..9a16447f3dd4f7ad69fef6edb6c6f6f7fc79b11a 100644 (file)
@@ -321,11 +321,6 @@ main (int argc, char *argv[])
   int ret;
   int nat_res;
 
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-
-  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
-  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
-                                                 &test_plugin);
   GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
 
   GNUNET_log_setup (test_name,
@@ -336,6 +331,12 @@ main (int argc, char *argv[])
 #endif
                     NULL);
 
+  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
+  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
+                                                 &test_plugin);
+
+  tth = GNUNET_TRANSPORT_TESTING_init ();
+
   if ((strcmp (test_plugin, "tcp_nat") == 0) ||
       (strcmp (test_plugin, "udp_nat") == 0))
   {
index 2336b2bf9dd0336eb600236fde436f705f8ae835..1e93615e7c169b3ca3feb0fe0c3601dfe6436f06 100644 (file)
@@ -549,11 +549,6 @@ main (int argc, char *argv[])
   int ret;
   int nat_res;
 
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-
-  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
-  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
-                                                 &test_plugin);
   GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
 
   GNUNET_log_setup (test_name,
@@ -564,6 +559,12 @@ main (int argc, char *argv[])
 #endif
                     NULL);
 
+  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
+  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
+                                                 &test_plugin);
+
+  tth = GNUNET_TRANSPORT_TESTING_init ();
+
   if ((strcmp (test_plugin, "tcp_nat") == 0) ||
       (strcmp (test_plugin, "udp_nat") == 0))
   {
index 3ce256017fe579f75e8abe7b3e5b98bf6b2a25ac..feca0c8b729716a764be181b1763b1bdf9502f18 100644 (file)
@@ -487,11 +487,6 @@ main (int argc, char *argv[])
   int ret;
   int nat_res;
 
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-
-  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
-  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
-                                                 &test_plugin);
   GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
 
   GNUNET_log_setup (test_name,
@@ -502,6 +497,12 @@ main (int argc, char *argv[])
 #endif
                     NULL);
 
+  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
+  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
+                                                 &test_plugin);
+
+  tth = GNUNET_TRANSPORT_TESTING_init ();
+
   if ((strcmp (test_plugin, "tcp_nat") == 0) ||
       (strcmp (test_plugin, "udp_nat") == 0))
   {
index 996ea054357cc62a1783156ca06a5cf2a4542ce2..7ba78c04e40ede476b5da512faedcf0e4edd7305 100644 (file)
@@ -145,6 +145,7 @@ start_cb (struct PeerContext *p, void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
               p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
+  GNUNET_free (sender_c);
 
   cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb,
                                                NULL);
@@ -165,11 +166,16 @@ run (void *cls, char *const *args, const char *cfgfile,
                                             "test_transport_api_tcp_peer1.conf",
                                             1, &notify_receive, &notify_connect,
                                             &notify_disconnect, &start_cb, p1);
+
+  GNUNET_assert (p1->hostkeyfile != NULL);
+
   p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                             "test_transport_api_tcp_peer2.conf",
                                             2, &notify_receive, &notify_connect,
                                             &notify_disconnect, &start_cb, p2);
 
+  GNUNET_assert (p2->hostkeyfile != NULL);
+
   if (p1 == NULL)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
index fb7535750f47cd3885e059d4a92476d23989de0c..6892b2556c52c49f5d1a7a5f061f3d21ca9a7b88 100644 (file)
 #include "transport-testing.h"
 
 #define VERBOSE GNUNET_EXTRA_LOGGING
+#define HOSTKEYFILESIZE 914
 
+static const char *
+get_host_key (struct GNUNET_TRANSPORT_TESTING_handle *tth)
+{
+  if (tth->hostkey_data == NULL)
+  {
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+                     "No precomputed hostkeys available\n");
+    return NULL;
+  }
+  if (tth->hostkeys_total > tth->hostkeys_last)
+  {
+    tth->hostkeys_last++;
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+                     "Used hostkey %u of %u available hostkeys\n",
+                     tth->hostkeys_last, tth->hostkeys_total);
+    return &tth->hostkey_data[(tth->hostkeys_last - 1) * HOSTKEYFILESIZE];
+  }
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+                   "No hostkey available (%u of %u already used)\n",
+                   tth->hostkeys_last, tth->hostkeys_total);
+  return NULL;
+}
 
 static struct PeerContext *
 find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth,
@@ -246,6 +269,9 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
                                      GNUNET_TRANSPORT_TESTING_start_cb start_cb,
                                      void *cb_cls)
 {
+  const char *hostkey = NULL;
+  struct GNUNET_DISK_FileHandle *fn;
+
   GNUNET_assert (tth != NULL);
   if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO)
   {
@@ -259,13 +285,36 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
   p->cfg = GNUNET_CONFIGURATION_create ();
 
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+
+
   if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
     GNUNET_assert (GNUNET_OK ==
                    GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS",
                                                           "SERVICEHOME",
                                                           &p->servicehome));
-  if (NULL != p->servicehome)
-    GNUNET_DISK_directory_remove (p->servicehome);
+
+    if (NULL != p->servicehome)
+      GNUNET_DISK_directory_remove (p->servicehome);
+
+  hostkey = get_host_key(tth);
+  if (hostkey != NULL)
+  {
+
+    GNUNET_asprintf (&p->hostkeyfile, "%s/.hostkey", p->servicehome);
+    GNUNET_assert(GNUNET_OK == GNUNET_DISK_directory_create_for_file (p->hostkeyfile));
+    fn = GNUNET_DISK_file_open (p->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_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+                     "Wrote hostkey to file: `%s' \n", p->hostkeyfile);
+  }
+
   p->arm_proc =
       GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
                                "gnunet-service-arm", "-c", cfgname,
@@ -326,6 +375,12 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
     p->arm_proc = NULL;
   }
 
+  if (p->hostkeyfile != NULL)
+  {
+    GNUNET_DISK_directory_remove (p->hostkeyfile);
+    GNUNET_free (p->hostkeyfile);
+  }
+
   if (p->servicehome != NULL)
   {
     GNUNET_DISK_directory_remove (p->servicehome);
@@ -454,6 +509,8 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth)
     p = t;
   }
 
+  GNUNET_free_non_null (tth->hostkey_data);
+
   GNUNET_free (tth);
   tth = NULL;
 }
@@ -467,6 +524,50 @@ GNUNET_TRANSPORT_TESTING_init ()
 {
   struct GNUNET_TRANSPORT_TESTING_handle *tth =
       GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle));
+  struct GNUNET_DISK_FileHandle *fd;
+  uint64_t fs;
+  uint64_t total_hostkeys;
+
+
+  /* prepare hostkeys */
+  tth->hostkey_data = NULL;
+  char * hostkeys_file = "../../contrib/testing_hostkeys.dat";
+  if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Could not read hostkeys file!\n"));
+  }
+  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;
+
+    if (0 != (fs % HOSTKEYFILESIZE))
+    {
+      GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing",
+                  "File size %llu seems incorrect for hostkeys...\n", fs);
+    }
+    else
+    {
+      total_hostkeys = fs / HOSTKEYFILESIZE;
+      tth->hostkey_data = GNUNET_malloc_large (fs);
+      GNUNET_assert (fs == GNUNET_DISK_file_read (fd, tth->hostkey_data, fs));
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+                  "Read %llu hostkeys from file\n", total_hostkeys);
+      tth->hostkeys_total = total_hostkeys;
+    }
+    GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
+  }
 
   return tth;
 }
index 8e5d55dcd13cc9ab34726c2a18acaac8c825413b..cec7eb7241a93b9ee9478d0773de7f94e9b7e180 100644 (file)
@@ -94,6 +94,8 @@ struct PeerContext
 
   char *servicehome;
 
+  char *hostkeyfile;
+
   unsigned int no;
 };
 
@@ -118,6 +120,10 @@ struct GNUNET_TRANSPORT_TESTING_handle
   struct ConnectingContext *cc_head;
   struct ConnectingContext *cc_tail;
 
+  char *hostkey_data;
+  int hostkeys_total;
+  int hostkeys_last;
+
   struct PeerContext *p_head;
   struct PeerContext *p_tail;
 };