- fix 2699
[oweals/gnunet.git] / src / testing / testing.c
index 7151cbd0971de134a26adf7d77f1ff020ce98ac4..16f90289096c01d4c83f78a7fcb0e71b184aa264 100644 (file)
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_testing_lib-new.h"
+#include "gnunet_testing_lib.h"
 
 #define LOG(kind,...)                                           \
   GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
 
+
+/**
+ * We need pipe control only on WINDOWS
+ */
+#if WINDOWS
+#define PIPE_CONTROL GNUNET_YES
+#else
+#define PIPE_CONTROL GNUNET_NO
+#endif
+
+
 /**
  * Lowest port used for GNUnet testing.  Should be high enough to not
  * conflict with other applications running on the hosts but be low
@@ -64,9 +75,10 @@ struct GNUNET_TESTING_System
   char *tmppath;
 
   /**
-   * The hostname of the controller
+   * The trusted ip. Can either be a single ip address or a network address in
+   * CIDR notation.
    */
-  char *controller;
+  char *trusted_ip;
 
   /**
    * our hostname
@@ -190,7 +202,7 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
   
   GNUNET_assert (NULL == system->hostkeys_data);
   data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
-  GNUNET_asprintf (&filename, "%s/testing_hostkeys.dat", data_dir);
+  GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir);
   GNUNET_free (data_dir);  
 
   if (GNUNET_YES != GNUNET_DISK_file_test (filename))
@@ -260,9 +272,10 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
  * @param testdir only the directory name without any path. This is used for
  *          all service homes; the directory will be created in a temporary
  *          location depending on the underlying OS
- * @param controller hostname of the controlling host, 
- *        service configurations are modified to allow 
- *        control connections from this host; can be NULL
+ * @param trusted_ip the ip address which will be set as TRUSTED HOST in all
+ *          service configurations generated to allow control connections from
+ *          this ip. This can either be a single ip address or a network address
+ *          in CIDR notation.
  * @param hostname the hostname of the system we are using for testing; NULL for
  *          localhost
  * @param lowport lowest port number this system is allowed to allocate (inclusive)
@@ -271,7 +284,7 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
  */
 struct GNUNET_TESTING_System *
 GNUNET_TESTING_system_create_with_portrange (const char *testdir,
-                                            const char *controller,
+                                            const char *trusted_ip,
                                             const char *hostname,
                                             uint16_t lowport,
                                             uint16_t highport)
@@ -288,8 +301,8 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
     GNUNET_free (system);
     return NULL;
   }
-  if (NULL != controller)
-    system->controller = GNUNET_strdup (controller);
+  if (NULL != trusted_ip)
+    system->trusted_ip = GNUNET_strdup (trusted_ip);
   if (NULL != hostname)
     system->hostname = GNUNET_strdup (hostname);
   if (GNUNET_OK != hostkeys_load (system))
@@ -309,19 +322,21 @@ GNUNET_TESTING_system_create_with_portrange (const char *testdir,
  * @param testdir only the directory name without any path. This is used for all
  *          service homes; the directory will be created in a temporary location
  *          depending on the underlying OS
- * @param controller hostname of the controlling host, service configurations
- *        are modified to allow control connections from this host; can be NULL
+ * @param trusted_ip the ip address which will be set as TRUSTED HOST in all
+ *          service configurations generated to allow control connections from
+ *          this ip. This can either be a single ip address or a network address
+ *          in CIDR notation.
  * @param hostname the hostname of the system we are using for testing; NULL for
  *          localhost
  * @return handle to this system, NULL on error
  */
 struct GNUNET_TESTING_System *
 GNUNET_TESTING_system_create (const char *testdir,
-                             const char *controller,
+                             const char *trusted_ip,
                              const char *hostname)
 {
   return GNUNET_TESTING_system_create_with_portrange (testdir,
-                                                     controller,
+                                                     trusted_ip,
                                                      hostname,
                                                      LOW_PORT,
                                                      HIGH_PORT);
@@ -344,7 +359,7 @@ GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
   if (GNUNET_YES == remove_paths)
     GNUNET_DISK_directory_remove (system->tmppath);
   GNUNET_free (system->tmppath);
-  GNUNET_free_non_null (system->controller);
+  GNUNET_free_non_null (system->trusted_ip);
   GNUNET_free_non_null (system->hostname);
   GNUNET_free (system);
 }
@@ -510,13 +525,13 @@ reserve_path (struct GNUNET_TESTING_System *system)
  *        key; if NULL, GNUNET_SYSERR is returned immediately
  * @return NULL on error (not enough keys)
  */
-struct GNUNET_CRYPTO_RsaPrivateKey *
+struct GNUNET_CRYPTO_EccPrivateKey *
 GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
                            uint32_t key_number,
                            struct GNUNET_PeerIdentity *id)
 {  
-  struct GNUNET_CRYPTO_RsaPrivateKey *private_key;
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
+  struct GNUNET_CRYPTO_EccPrivateKey *private_key;
+  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
   
   if ((NULL == id) || (NULL == system->hostkeys_data))
     return NULL;
@@ -526,7 +541,7 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
          _("Key number %u does not exist\n"), key_number);
     return NULL;
   }   
-  private_key = GNUNET_CRYPTO_rsa_decode_key (system->hostkeys_data +
+  private_key = GNUNET_CRYPTO_ecc_decode_key (system->hostkeys_data +
                                               (key_number *
                                                GNUNET_TESTING_HOSTKEYFILESIZE),
                                               GNUNET_TESTING_HOSTKEYFILESIZE);
@@ -536,9 +551,9 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
          _("Error while decoding key %u\n"), key_number);
     return NULL;
   }
-  GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key);
+  GNUNET_CRYPTO_ecc_key_get_public (private_key, &public_key);
   GNUNET_CRYPTO_hash (&public_key,
-                      sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                      sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
                       &(id->hashPubKey));
   return private_key;
 }
@@ -666,8 +681,8 @@ update_config (void *cls, const char *section, const char *option,
 
 
 /**
- * Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 depending on the ip of the
- * controller in all sections
+ * Section iterator to set ACCEPT_FROM/ACCEPT_FROM6 to include the address of
+ * 'trusted_hosts' in all sections
  *
  * @param cls the UpdateContext
  * @param section name of the section
@@ -745,8 +760,8 @@ update_config_sections (void *cls,
   }
   GNUNET_free_non_null (val);
   ACCEPT_FROM_key = "ACCEPT_FROM";  
-  if ((NULL != uc->system->controller) && 
-      (NULL != strstr (uc->system->controller, ":"))) /* IPv6 in use */
+  if ((NULL != uc->system->trusted_ip) && 
+      (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
     ACCEPT_FROM_key = "ACCEPT_FROM6";
   if (GNUNET_OK != 
       GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, ACCEPT_FROM_key,
@@ -754,11 +769,11 @@ update_config_sections (void *cls,
   {
     orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
   }
-  if (NULL == uc->system->controller)
+  if (NULL == uc->system->trusted_ip)
     allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
   else
     GNUNET_asprintf (&allowed_hosts, "%s%s;", orig_allowed_hosts,
-                     uc->system->controller);
+                     uc->system->trusted_ip);
   GNUNET_free (orig_allowed_hosts);
   GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, ACCEPT_FROM_key,
                                          allowed_hosts);
@@ -802,7 +817,7 @@ GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
                                          uc.service_home);
   /* make PORTs and UNIXPATHs unique */
   GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
-  /* allow connections to services from system controller host */
+  /* allow connections to services from system trusted_ip host */
   GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc);
   /* enable loopback-based connections between peers */
   GNUNET_CONFIGURATION_set_value_string (cfg, 
@@ -840,7 +855,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
   char *config_filename;
   char *libexec_binary;
   char *emsg_;
-  struct GNUNET_CRYPTO_RsaPrivateKey *pk;
+  struct GNUNET_CRYPTO_EccPrivateKey *pk;
 
   if (NULL != emsg)
     *emsg = NULL;
@@ -882,12 +897,13 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
     return NULL;
   }
   if (NULL != pk)
-    GNUNET_CRYPTO_rsa_key_free (pk);
+    GNUNET_CRYPTO_ecc_key_free (pk);
   GNUNET_assert (GNUNET_OK == 
                  GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
                                                         "SERVICEHOME",
                                                         &service_home));
-  GNUNET_snprintf (hostkey_filename, sizeof (hostkey_filename), "%s/.hostkey",
+  /* FIXME: might be better to evaluate actual configuration option here... */
+  GNUNET_snprintf (hostkey_filename, sizeof (hostkey_filename), "%s/private.ecc",
                    service_home);
   GNUNET_free (service_home);
   fd = GNUNET_DISK_file_open (hostkey_filename,
@@ -937,7 +953,6 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
   }
   peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
   peer->cfgfile = config_filename; /* Free in peer_destroy */
-
   libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary))
   {
@@ -947,10 +962,8 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
   }
   else
     peer->args = strdup (libexec_binary);
-
   peer->system = system;
   peer->key_number = key_number;
-
   GNUNET_free (libexec_binary);
   return peer;
 }
@@ -966,7 +979,7 @@ void
 GNUNET_TESTING_peer_get_identity (const struct GNUNET_TESTING_Peer *peer,
                                  struct GNUNET_PeerIdentity *id)
 {
-  GNUNET_CRYPTO_rsa_key_free (GNUNET_TESTING_hostkey_get (peer->system,
+  GNUNET_CRYPTO_ecc_key_free (GNUNET_TESTING_hostkey_get (peer->system,
                                                          peer->key_number,
                                                          id));
 }
@@ -987,7 +1000,9 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
     return GNUNET_SYSERR;
   }
   GNUNET_assert (NULL != peer->cfgfile);
-  peer->main_process = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL,
+  peer->main_process = GNUNET_OS_start_process (PIPE_CONTROL, 
+                                                GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                                NULL, NULL,
                                                 peer->main_binary,
                                                 peer->main_binary,
                                                 peer->args,
@@ -1216,7 +1231,7 @@ GNUNET_TESTING_service_run (const char *testdir,
     return 1;
   }
   GNUNET_free (peer->main_binary);
-
+  GNUNET_free (peer->args);
   GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
   libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, service_name, "PREFIX", &peer->main_binary))