-ensure external symbols have proper prefix for conversation service
[oweals/gnunet.git] / src / gns / test_gns_simple_shorten.c
index caddbae45d73b7d7efb0e8903449af1fbf57eb78..8cab0dbb237ebc90100d32a23061f063ca1a4b09 100644 (file)
@@ -23,7 +23,7 @@
  *
  */
 #include "platform.h"
-#include "gnunet_testing_lib-new.h"
+#include "gnunet_testing_lib.h"
 #include "gnunet_core_service.h"
 #include "block_dns.h"
 #include "gnunet_signatures.h"
 #include "gnunet_dnsparser_lib.h"
 #include "gnunet_gns_service.h"
 
-/* DEFINES */
-#define VERBOSE GNUNET_YES
-
 /* Timeout for entire testcase */
 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20)
 
-/* If number of peers not in config file, use this number */
-#define DEFAULT_NUM_PEERS 2
-
 /* test records to resolve */
-#define TEST_DOMAIN "www.alice.bob.gnunet"
+#define TEST_DOMAIN "www.alice.bob.gnu"
 #define TEST_IP "127.0.0.1"
 #define TEST_RECORD_NAME "www"
 
 #define TEST_AUTHORITY_BOB "bob"
 #define TEST_AUTHORITY_ALICE "alice"
 #define TEST_ALICE_PSEU "carol"
-#define TEST_EXPECTED_RESULT "www.carol.gnunet"
+#define TEST_EXPECTED_RESULT "www.carol.gnu"
 
 #define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"
 #define KEYFILE_ALICE "../namestore/zonefiles/N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"
@@ -67,27 +61,58 @@ static struct GNUNET_GNS_Handle *gns_handle;
 
 const struct GNUNET_CONFIGURATION_Handle *cfg;
 
-struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded priv_pkey;
-struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded short_pkey;
-struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
-struct GNUNET_CRYPTO_RsaPrivateKey *short_key;
+struct GNUNET_CRYPTO_EccPublicSignKey priv_pkey;
+struct GNUNET_CRYPTO_EccPublicSignKey short_pkey;
+struct GNUNET_CRYPTO_EccPrivateKey *priv_key;
+struct GNUNET_CRYPTO_EccPrivateKey *short_key;
 
 struct GNUNET_CRYPTO_ShortHashCode priv_zone;
 struct GNUNET_CRYPTO_ShortHashCode short_zone;
 
+
+/**
+ * Check if the get_handle is being used, if so stop the request.  Either
+ * way, schedule the end_badly_cont function which actually shuts down the
+ * test.
+ */
+static void
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  die_task = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_SCHEDULER_shutdown ();
+  ok = 1;
+}
+
+void end_badly_now ()
+{
+  GNUNET_SCHEDULER_cancel (die_task);
+  die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+}
+
+static void shutdown_task (void *cls,
+                           const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  GNUNET_GNS_disconnect(gns_handle);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
+  GNUNET_SCHEDULER_shutdown ();
+}
+
 /**
  * Called when gns shorten finishes
  */
 static void
 process_shorten_result(void* cls, const char* sname)
 {
-  GNUNET_GNS_disconnect(gns_handle);
 
+  if (GNUNET_SCHEDULER_NO_TASK != die_task)
+  {
+      GNUNET_SCHEDULER_cancel (die_task);
+      die_task = GNUNET_SCHEDULER_NO_TASK;
+  }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Disconnecting from namestore\n");
   GNUNET_NAMESTORE_disconnect (namestore_handle);
-  ok = 0;
 
   if (sname == NULL)
   {
@@ -110,9 +135,8 @@ process_shorten_result(void* cls, const char* sname)
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shorten test succeeded!\n");
     ok = 0;
   }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer!\n");
-  GNUNET_SCHEDULER_shutdown ();
+  
+  GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
 }
 
 /**
@@ -129,7 +153,7 @@ commence_testing (void *cls, int32_t success, const char *emsg)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Failed to connect to gns\n");
-    ok = 1;
+    end_badly_now ();
     return;
   }
 
@@ -141,31 +165,20 @@ commence_testing (void *cls, int32_t success, const char *emsg)
 }
 
 
-/**
- * Check if the get_handle is being used, if so stop the request.  Either
- * way, schedule the end_badly_cont function which actually shuts down the
- * test.
- */
-static void
-end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  ok = 1;
-}
-
 
 void do_check (void *cls,
               const struct GNUNET_CONFIGURATION_Handle *ccfg,
               struct GNUNET_TESTING_Peer *peer)
 {
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey;
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
-  struct GNUNET_CRYPTO_RsaPrivateKey *our_key;
-  struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
-  struct GNUNET_CRYPTO_RsaPrivateKey *bob_key;
+  struct GNUNET_CRYPTO_EccPublicSignKey our_pkey;
+  struct GNUNET_CRYPTO_EccPublicSignKey alice_pkey;
+  struct GNUNET_CRYPTO_EccPublicSignKey bob_pkey;
+  struct GNUNET_CRYPTO_EccPrivateKey *our_key;
+  struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
+  struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
   struct GNUNET_CRYPTO_ShortHashCode bob_hash;
   struct GNUNET_CRYPTO_ShortHashCode alice_hash;
-  struct GNUNET_CRYPTO_RsaSignature *sig;
+  struct GNUNET_CRYPTO_EccSignature *sig;
   char* our_keyfile;
   char* private_keyfile;
   char* shorten_keyfile;
@@ -180,7 +193,7 @@ void do_check (void *cls,
   if (NULL == namestore_handle)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
-    ok = -1;
+    end_badly_now ();
     return;
   }
 
@@ -189,7 +202,7 @@ void do_check (void *cls,
                                                           &our_keyfile))
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
-    ok = -1;
+    end_badly_now ();
     return;
   }
   
@@ -199,7 +212,7 @@ void do_check (void *cls,
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
                "Failed to get shorten zone key from cfg\n");
-    ok = -1;
+    end_badly_now ();
     return;
   }
   
@@ -209,26 +222,26 @@ void do_check (void *cls,
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
                "Failed to get private zone key from cfg\n");
-    ok = -1;
+    end_badly_now ();
     return;
   }
 
-  our_key = GNUNET_CRYPTO_rsa_key_create_from_file (our_keyfile);
+  our_key = GNUNET_CRYPTO_ecc_key_create_from_file (our_keyfile);
   GNUNET_free(our_keyfile);
 
-  bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB);
-  alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_ALICE);
-  priv_key = GNUNET_CRYPTO_rsa_key_create_from_file (private_keyfile);
-  short_key = GNUNET_CRYPTO_rsa_key_create_from_file (shorten_keyfile);
+  bob_key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE_BOB);
+  alice_key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE_ALICE);
+  priv_key = GNUNET_CRYPTO_ecc_key_create_from_file (private_keyfile);
+  short_key = GNUNET_CRYPTO_ecc_key_create_from_file (shorten_keyfile);
 
   GNUNET_free(shorten_keyfile);
   GNUNET_free(private_keyfile);
   
-  GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey);
-  GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
-  GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey);
-  GNUNET_CRYPTO_rsa_key_get_public (priv_key, &priv_pkey);
-  GNUNET_CRYPTO_rsa_key_get_public (short_key, &short_pkey);
+  GNUNET_CRYPTO_ecc_key_get_public_for_signature (our_key, &our_pkey);
+  GNUNET_CRYPTO_ecc_key_get_public_for_signature (alice_key, &alice_pkey);
+  GNUNET_CRYPTO_ecc_key_get_public_for_signature (bob_key, &bob_pkey);
+  GNUNET_CRYPTO_ecc_key_get_public_for_signature (priv_key, &priv_pkey);
+  GNUNET_CRYPTO_ecc_key_get_public_for_signature (short_key, &short_pkey);
 
   GNUNET_CRYPTO_short_hash(&priv_pkey, sizeof(priv_pkey), &priv_zone);
   GNUNET_CRYPTO_short_hash(&short_pkey, sizeof(short_pkey), &short_zone);
@@ -243,16 +256,17 @@ void do_check (void *cls,
 
   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
   rd.data = &bob_hash;
-  rd.record_type = GNUNET_GNS_RECORD_PKEY;
-  rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
+  rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
+  rd.flags = GNUNET_NAMESTORE_RF_NONE;
   
   /* put bob into our zone */
-  GNUNET_NAMESTORE_record_create (namestore_handle,
-                                  our_key,
-                                  TEST_AUTHORITY_BOB,
-                                  &rd,
-                                  NULL,
-                                  NULL);
+  GNUNET_NAMESTORE_record_put_by_authority (namestore_handle,
+                                           our_key,
+                                           TEST_AUTHORITY_BOB,
+                                           1,
+                                           &rd,
+                                           NULL,
+                                           NULL);
   
   /* put alice into bobs zone */
   GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash);
@@ -294,41 +308,37 @@ void do_check (void *cls,
   
   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
   rd.data = &alice_hash;
-  rd.record_type = GNUNET_GNS_RECORD_PKEY;
+  rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
   GNUNET_free(sig);
 
-  GNUNET_NAMESTORE_record_create (namestore_handle,
-                               our_key,
-                               TEST_ALICE_PSEU,
-                               &rd,
-                               &commence_testing,
-                               NULL);
+  GNUNET_NAMESTORE_record_put_by_authority (namestore_handle,
+                                           our_key,
+                                           TEST_ALICE_PSEU,
+                                           1, &rd,
+                                           &commence_testing,
+                                           NULL);
 
   GNUNET_free(web);
-  GNUNET_CRYPTO_rsa_key_free(our_key);
-  GNUNET_CRYPTO_rsa_key_free(bob_key);
-  GNUNET_CRYPTO_rsa_key_free(alice_key);
-  GNUNET_CRYPTO_rsa_key_free(priv_key);
-  GNUNET_CRYPTO_rsa_key_free(short_key);
+  GNUNET_free(our_key);
+  GNUNET_free(bob_key);
+  GNUNET_free(alice_key);
+  GNUNET_free(priv_key);
+  GNUNET_free(short_key);
 
 }
 
+
 int
 main (int argc, char *argv[])
 {
   ok = 1;
-
   GNUNET_log_setup ("test-gns-simple-shorten",
-#if VERBOSE
-                    "DEBUG",
-#else
                     "WARNING",
-#endif
                     NULL);
-
-  GNUNET_TESTING_peer_run ("test-gns-simple-shorten", "test_gns_simple_lookup.conf", &do_check, NULL);
-
+  GNUNET_TESTING_peer_run ("test-gns-simple-shorten",
+                          "test_gns_simple_lookup.conf", 
+                          &do_check, NULL);
   return ok;
 }
 
-/* end of test_gns_twopeer.c */
+/* end of test_gns_simple_shorten.c */