summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-11-16 14:06:33 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-11-16 14:06:33 +0000
commitceb61a7028230e7d1faba3f01f1d9b0e1f9ab8e4 (patch)
tree09f5c7a16a59c1ffad083c6600d19f7ec1c86161
parent961745754238752335b14293ef819d0b45ae8867 (diff)
transport-testing uses precomputed hostkeys to improve speed especially on slow systems
-rw-r--r--src/transport/template_cfg_peer1.conf4
-rw-r--r--src/transport/template_cfg_peer2.conf3
-rw-r--r--src/transport/test_quota_compliance.c11
-rw-r--r--src/transport/test_transport_api.c6
-rw-r--r--src/transport/test_transport_api_bidirectional_connect.c11
-rw-r--r--src/transport/test_transport_api_disconnect.c11
-rw-r--r--src/transport/test_transport_api_reliability.c12
-rw-r--r--src/transport/test_transport_api_timeout.c11
-rw-r--r--src/transport/test_transport_api_unreliability.c11
-rw-r--r--src/transport/test_transport_api_unreliability_constant.c11
-rw-r--r--src/transport/test_transport_testing.c6
-rw-r--r--src/transport/transport-testing.c105
-rw-r--r--src/transport/transport-testing.h6
13 files changed, 168 insertions, 40 deletions
diff --git a/src/transport/template_cfg_peer1.conf b/src/transport/template_cfg_peer1.conf
index fbb4f7c4f..90ad9ab06 100644
--- a/src/transport/template_cfg_peer1.conf
+++ b/src/transport/template_cfg_peer1.conf
@@ -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]
diff --git a/src/transport/template_cfg_peer2.conf b/src/transport/template_cfg_peer2.conf
index 7249fc4cc..cb5935f81 100644
--- a/src/transport/template_cfg_peer2.conf
+++ b/src/transport/template_cfg_peer2.conf
@@ -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
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index 7d28820cb..f4bc6fc54 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -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))
{
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 47686f8d9..a04017019 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -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))
{
diff --git a/src/transport/test_transport_api_bidirectional_connect.c b/src/transport/test_transport_api_bidirectional_connect.c
index 06d007c81..bf8de42e9 100644
--- a/src/transport/test_transport_api_bidirectional_connect.c
+++ b/src/transport/test_transport_api_bidirectional_connect.c
@@ -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))
{
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c
index 68881fbe8..703de2a5b 100644
--- a/src/transport/test_transport_api_disconnect.c
+++ b/src/transport/test_transport_api_disconnect.c
@@ -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))
{
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 655f6f0a3..7b0b92078 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -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))
{
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c
index 79a90ba0e..9a16447f3 100644
--- a/src/transport/test_transport_api_timeout.c
+++ b/src/transport/test_transport_api_timeout.c
@@ -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))
{
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c
index 2336b2bf9..1e93615e7 100644
--- a/src/transport/test_transport_api_unreliability.c
+++ b/src/transport/test_transport_api_unreliability.c
@@ -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))
{
diff --git a/src/transport/test_transport_api_unreliability_constant.c b/src/transport/test_transport_api_unreliability_constant.c
index 3ce256017..feca0c8b7 100644
--- a/src/transport/test_transport_api_unreliability_constant.c
+++ b/src/transport/test_transport_api_unreliability_constant.c
@@ -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))
{
diff --git a/src/transport/test_transport_testing.c b/src/transport/test_transport_testing.c
index 996ea0543..7ba78c04e 100644
--- a/src/transport/test_transport_testing.c
+++ b/src/transport/test_transport_testing.c
@@ -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,
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index fb7535750..6892b2556 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -28,7 +28,30 @@
#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;
}
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 8e5d55dcd..cec7eb724 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -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;
};