- fix
[oweals/gnunet.git] / src / transport / test_plugin_transport.c
index e512716bc575a19aef59b670f263bbe7ea924aab..3c4c6f6244b6b6433b9f69b436698b2ed0d6e720 100644 (file)
 #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
+#define HOSTKEY_FILE "test_plugin_hostkey.ecc"
+
 /**
  * Our public key.
  */
-static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
 
 /**
  * Our identity.
@@ -56,7 +58,7 @@ static struct GNUNET_PeerIdentity my_identity;
 /**
  * Our private key.
  */
-static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
+static struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
 
 /**
  * Our configuration.
@@ -290,8 +292,6 @@ static struct GNUNET_TIME_Relative
 env_receive (void *cls,
             const struct GNUNET_PeerIdentity *peer,
             const struct GNUNET_MessageHeader *message,
-            const struct GNUNET_ATS_Information *ats,
-            uint32_t ats_count,
             struct Session * session,
             const char *sender_address,
             uint16_t sender_address_len)
@@ -482,6 +482,18 @@ env_session_end (void *cls,
 }
 
 
+static void
+env_update_metrics (void *cls,
+                                                                               const struct GNUNET_PeerIdentity *peer,
+                                                                               const char *address,
+                                                                               uint16_t address_len,
+                                                                               struct Session *session,
+                                                                               struct GNUNET_ATS_Information *ats,
+                                                                               uint32_t ats_count)
+{
+}
+
+
 static void
 setup_plugin_environment ()
 {
@@ -494,6 +506,7 @@ setup_plugin_environment ()
   env.receive = &env_receive;
   env.notify_address = &env_notify_address;
   env.get_address_type = &env_get_address_type;
+  env.update_address_metrics = &env_update_metrics;
   env.get_our_hello = &env_get_our_hello;
   env.session_end = &env_session_end;
 }
@@ -531,7 +544,7 @@ run (void *cls, char *const *args, const char *cfgfile,
                                                            "NEIGHBOUR_LIMIT",
                                                            &tneigh)) ||
        (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c,
-                                                             "GNUNETD", "HOSTKEY",
+                                                             "PEER", "PRIVATE_KEY",
                                                              &keyfile)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -547,8 +560,34 @@ run (void *cls, char *const *args, const char *cfgfile,
     return;
   }
 
+  if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE))
+  {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  _("Hostkey `%s' missing.  Exiting.\n"),
+                  HOSTKEY_FILE);
+  }
+
+  if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile))
+  {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  _("Could not create a directory for hostkey `%s'.  Exiting.\n"),
+                  keyfile);
+      end_badly_now ();
+      return;
+  }
+
+  if (GNUNET_OK !=  GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile))
+  {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  _("Could not copy hostkey `%s' to destination `%s'.  Exiting.\n"),
+                  HOSTKEY_FILE, keyfile);
+      end_badly_now ();
+      return;
+  }
+
+
   max_connect_per_transport = (uint32_t) tneigh;
-  my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+  my_private_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
   GNUNET_free (keyfile);
   if (NULL == my_private_key)
   {
@@ -557,7 +596,7 @@ run (void *cls, char *const *args, const char *cfgfile,
     end_badly_now ();
     return;
   }
-  GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
+  GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key);
   GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
                       &my_identity.hashPubKey);
 
@@ -674,6 +713,8 @@ main (int argc, char *const *argv)
   };
   int ret;
 
+  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport");
+
   char *const argv_prog[] = {
     "test_plugin_transport",
     "-c",