-handle failure to load certs more nicely
[oweals/gnunet.git] / src / gns / test_gns_proxy.c
index 916ea7392a8e1f6ec31a302b95f0515eb00a3bf6..16c94eced1bb3cc4ef3fc707ce6fcb04a74969f3 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
 #include <microhttpd.h>
 #include "gnunet_namestore_service.h"
 #include "gnunet_gns_service.h"
-#include "gnunet_testing_lib-new.h"
+#include "gnunet_testing_lib.h"
 #include "gnunet_os_lib.h"
 
 #define PORT 8080
-#define TEST_DOMAIN "www.gnunet"
+#define TEST_DOMAIN "www.gnu"
 
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
 
@@ -135,11 +135,21 @@ do_shutdown ()
   GNUNET_free_non_null (url);
 
   if (NULL != tmp_cfgfile)
-    remove (tmp_cfgfile);
-
+    {
+      if (0 != remove (tmp_cfgfile))
+       GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "remove", tmp_cfgfile);
+      GNUNET_free (tmp_cfgfile);
+      tmp_cfgfile = NULL;
+    }
   if (NULL != proxy_proc)
-    GNUNET_OS_process_kill (proxy_proc, 9);
+    {
+      (void) GNUNET_OS_process_kill (proxy_proc, SIGKILL);
+      GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proxy_proc));
+      GNUNET_OS_process_destroy (proxy_proc);
+      proxy_proc = NULL;
+    }
   url = NULL;
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -286,7 +296,7 @@ commence_testing (void *cls, int32_t success, const char *emsg)
     return;
   }
   
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), start_curl, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), start_curl, NULL);
 
 }
 
@@ -354,7 +364,7 @@ run (void *cls,
      struct GNUNET_TESTING_Peer *peer)
 {
   enum MHD_FLAG flags;
-  struct GNUNET_CRYPTO_RsaPrivateKey *host_key;
+  struct GNUNET_CRYPTO_EccPrivateKey *host_key;
   struct GNUNET_NAMESTORE_RecordData rd;
   char *zone_keyfile;
   
@@ -383,6 +393,7 @@ run (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Failed to write tmp cfg\n");
+    do_shutdown ();
     return;
   }
   
@@ -394,7 +405,13 @@ run (void *cls,
                                         "gnunet-gns-proxy",
                                         "-c", tmp_cfgfile, NULL);
 
-  GNUNET_assert (NULL != proxy_proc);
+  if (NULL == proxy_proc)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to start proxy\n");
+    do_shutdown ();
+    return;
+  }
   
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
                                                             "ZONEKEY",
@@ -404,13 +421,13 @@ run (void *cls,
     return;
   }
 
-  host_key = GNUNET_CRYPTO_rsa_key_create_from_file (zone_keyfile);
-  rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value;
-  GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_string_to_value (GNUNET_GNS_RECORD_A,
+  host_key = GNUNET_CRYPTO_ecc_key_create_from_file (zone_keyfile);
+  rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
+  GNUNET_assert (GNUNET_OK == GNUNET_NAMESTORE_string_to_value (GNUNET_DNSPARSER_TYPE_A,
                                                                "127.0.0.1",
                                                                (void**)&rd.data,
                                                                &rd.data_size));
-  rd.record_type = GNUNET_GNS_RECORD_A;
+  rd.record_type = GNUNET_DNSPARSER_TYPE_A;
 
   GNUNET_NAMESTORE_record_create (namestore,
                                   host_key,
@@ -421,15 +438,28 @@ run (void *cls,
 
   GNUNET_free ((void**)rd.data);
   GNUNET_free (zone_keyfile);
-  GNUNET_CRYPTO_rsa_key_free (host_key);
+  GNUNET_free (host_key);
 }
 
 int
 main (int argc, char *const *argv)
 {
+  char *binary;
+
+  if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("gnunet-gns-proxy", GNUNET_NO, NULL))
+  {
+    fprintf (stderr, "Proxy binary not in PATH... skipping!\n");
+    return 0;
+  }
+  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-dns");
+  if (GNUNET_YES != GNUNET_OS_check_helper_binary (binary, GNUNET_YES, NULL)) // TODO: once we have a windows-testcase, add test parameters here
+  {
+    fprintf (stderr, "DNS helper binary has wrong permissions... skipping!\n");
+    GNUNET_free (binary);
+    return 0;
+  }
+    GNUNET_free (binary);
 
-  GNUNET_CRYPTO_setup_hostkey ("test_gns_proxy.conf");
-  
   if (0 != curl_global_init (CURL_GLOBAL_WIN32))
   {
     fprintf (stderr, "failed to initialize curl\n");