-fixing #2985
[oweals/gnunet.git] / src / gns / test_gns_ns_lookup.c
index f48ab803040e24f3df9844139a7b84904c77a9cd..6a150e86a6b9a76ab950528a13567f696e771c01 100644 (file)
 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20)
 
 /**
- * Name to resolve for testing.  NS record on 'homepage.gads' redirects to
+ * Name to resolve for testing.  NS record on 'homepage.gnu' redirects to
  * DNS 'TEST_RECORD_NS' domain and thus names should be resolved within
  * that target domain.
  */
-#define TEST_DOMAIN "www.homepage.gads"
+#define TEST_DOMAIN "www.homepage.gnu"
 
 /**
- * Name to resolve for testing.  NS record on 'homepage.gads' redirects to
+ * Name to resolve for testing.  NS record on 'homepage.gnu' redirects to
  * DNS 'TEST_RECORD_NS' domain and thus names should be resolved within
  * that target domain.
  */
-#define TEST_DOMAIN_ALT "homepage.gads"
+#define TEST_DOMAIN_ALT "homepage.gnu"
 
 /**
- * Name to resolve for testing.  NS record on 'homepage.gads' redirects to
+ * Name to resolve for testing.  NS record on 'homepage.gnu' redirects to
  * DNS 'TEST_RECORD_NS' domain and thus names should be resolved within
  * that target domain.
  */
-#define TEST_DOMAIN_ALT2 "uk.homepage.gads"
+#define TEST_DOMAIN_ALT2 "uk.homepage.gnu"
 
 /**
  * Expected test value (matching TEST_DOMAIN_ALT2).
@@ -134,7 +134,7 @@ static struct GNUNET_NAMESTORE_QueueEntry *qe;
 /**
  * Our private key for signing records.
  */
-static struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
+static struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
 
 
 /**
@@ -174,7 +174,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
   if (NULL != alice_key)
   {
-    GNUNET_CRYPTO_rsa_key_free (alice_key);
+    GNUNET_CRYPTO_ecc_key_free (alice_key);
     alice_key = NULL;
   }
   GNUNET_break (0);
@@ -229,7 +229,7 @@ end_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
   if (NULL != alice_key)
   {
-    GNUNET_CRYPTO_rsa_key_free (alice_key);
+    GNUNET_CRYPTO_ecc_key_free (alice_key);
     alice_key = NULL;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
@@ -267,7 +267,7 @@ on_lookup_result_alt2 (void *cls, uint32_t rd_count,
   ok = 1;
   for (i=0; i<rd_count; i++)
   {
-    if (rd[i].record_type == GNUNET_GNS_RECORD_A)
+    if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_A)
     {
       memcpy(&a, rd[i].data, sizeof(a));
       addr = inet_ntoa(a);
@@ -335,7 +335,7 @@ on_lookup_result_alt (void *cls, uint32_t rd_count,
   ok = 1;
   for (i=0; i<rd_count; i++)
   {
-    if (rd[i].record_type == GNUNET_GNS_RECORD_A)
+    if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_A)
     {
       memcpy (&a, rd[i].data, sizeof(a));
       addr = inet_ntoa (a);
@@ -366,7 +366,7 @@ on_lookup_result_alt (void *cls, uint32_t rd_count,
              "Starting lookup for `%s'\n",
              TEST_DOMAIN_ALT2);
   lr = GNUNET_GNS_lookup (gns_handle, 
-                         TEST_DOMAIN_ALT2, GNUNET_GNS_RECORD_A,
+                         TEST_DOMAIN_ALT2, GNUNET_DNSPARSER_TYPE_A,
                          GNUNET_YES,
                          NULL,
                          &on_lookup_result_alt2, NULL);
@@ -407,7 +407,7 @@ on_lookup_result (void *cls, uint32_t rd_count,
   ok = 1;
   for (i=0; i<rd_count; i++)
   {
-    if (rd[i].record_type == GNUNET_GNS_RECORD_A)
+    if (rd[i].record_type == GNUNET_DNSPARSER_TYPE_A)
     {
       memcpy (&a, rd[i].data, sizeof(a));
       addr = inet_ntoa(a);
@@ -438,7 +438,7 @@ on_lookup_result (void *cls, uint32_t rd_count,
              "Starting lookup for `%s'\n",
              TEST_DOMAIN_ALT);
 
-  lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_ALT, GNUNET_GNS_RECORD_A,
+  lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_ALT, GNUNET_DNSPARSER_TYPE_A,
                          GNUNET_YES,
                          NULL,
                          &on_lookup_result_alt, NULL);
@@ -462,7 +462,7 @@ start_lookup ()
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
              "Records ready, starting lookup for `%s'\n",
              TEST_DOMAIN);
-  lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
+  lr = GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_DNSPARSER_TYPE_A,
                          GNUNET_YES,
                          NULL,
                          &on_lookup_result, NULL);
@@ -548,37 +548,6 @@ commence_testing (void *cls, int32_t success, const char *emsg)
 }
 
 
-/**
- * Function called once we've created the first NS record,
- * create the second one.
- *
- * @param cls closure, unused
- * @param success GNUNET_OK on success
- * @param emsg error message, NULL on success
- */
-static void
-create_next_record (void *cls,
-                   int32_t success,
-                   const char *emsg)
-{
-  struct GNUNET_NAMESTORE_RecordData rd;
-
-  qe = NULL;
-  if (NULL != emsg)
-    FPRINTF (stderr, "Failed to create record: %s\n", emsg);
-  GNUNET_assert (GNUNET_YES == success);
-  rd.data_size = strlen (TEST_RECORD_NS);
-  rd.data = TEST_RECORD_NS;
-  rd.record_type = GNUNET_GNS_RECORD_NS;
-  qe = GNUNET_NAMESTORE_record_create (namestore_handle,
-                                      alice_key,
-                                      TEST_RECORD_NAME,
-                                      &rd,
-                                      &commence_testing,
-                                      NULL);
-}
-
-
 /**
  * Peer is ready, run the actual test.  Begins by storing
  * a record in the namestore.
@@ -592,9 +561,9 @@ do_check (void *cls,
           const struct GNUNET_CONFIGURATION_Handle *ccfg,
           struct GNUNET_TESTING_Peer *peer)
 {
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
+  struct GNUNET_CRYPTO_EccPublicKey alice_pkey;
   char* alice_keyfile;
-  struct GNUNET_NAMESTORE_RecordData rd;
+  struct GNUNET_NAMESTORE_RecordData rd[2];
   struct in_addr ns;
   
   cfg = ccfg;
@@ -621,25 +590,31 @@ do_check (void *cls,
     return;
   }
 
-  alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile);
-  GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
+  alice_key = GNUNET_CRYPTO_ecc_key_create_from_file (alice_keyfile);
+  GNUNET_CRYPTO_ecc_key_get_public (alice_key, &alice_pkey);
   GNUNET_free (alice_keyfile);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Creating NS records\n");
-  rd.expiration_time = UINT64_MAX;
+  rd[0].expiration_time = UINT64_MAX;
   GNUNET_assert(1 == inet_pton (AF_INET, TEST_IP_NS, &ns));
-  rd.data_size = sizeof (struct in_addr);
-  rd.data = &ns;
-  rd.record_type = GNUNET_DNSPARSER_TYPE_A;
-  rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
-
-  qe = GNUNET_NAMESTORE_record_create (namestore_handle,
-                                      alice_key,
-                                      TEST_RECORD_NAME,
-                                      &rd,
-                                      &create_next_record,
-                                      NULL);
+  rd[0].data_size = sizeof (struct in_addr);
+  rd[0].data = &ns;
+  rd[0].record_type = GNUNET_DNSPARSER_TYPE_A;
+  rd[0].flags = GNUNET_NAMESTORE_RF_AUTHORITY;
+  
+  rd[1].expiration_time = UINT64_MAX;
+  rd[1].data_size = strlen (TEST_RECORD_NS);
+  rd[1].data = TEST_RECORD_NS;
+  rd[1].record_type = GNUNET_DNSPARSER_TYPE_NS;
+  rd[1].flags = GNUNET_NAMESTORE_RF_AUTHORITY;
+
+  qe = GNUNET_NAMESTORE_record_put_by_authority (namestore_handle,
+                                                alice_key,
+                                                TEST_RECORD_NAME,
+                                                2, rd,
+                                                &commence_testing,
+                                                NULL);
 }