- added check against statistics
[oweals/gnunet.git] / src / gns / test_gns_simple_shorten.c
index 0f36447f6cd64ca4e2440b36d17826c8c5b958fd..8a4dd2ec9c29dd17ae360ce299929d33b66428f2 100644 (file)
@@ -36,7 +36,7 @@
 #define VERBOSE GNUNET_YES
 
 /* Timeout for entire testcase */
-#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
+#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
 
 /* If number of peers not in config file, use this number */
 #define DEFAULT_NUM_PEERS 2
@@ -93,7 +93,7 @@ shutdown_callback (void *cls, const char *emsg)
  * Called when gns shorten finishes
  */
 static void
-process_shorten_result(void* cls, const char* lname, const char* sname)
+process_shorten_result(void* cls, const char* sname)
 {
   GNUNET_GNS_disconnect(gns_handle);
 
@@ -108,12 +108,12 @@ process_shorten_result(void* cls, const char* lname, const char* sname)
   else
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "%s shortened to %s\n", lname, sname);
+                "%s shortened to %s\n", (char*)cls, sname);
     if (0 != strcmp(sname, TEST_EXPECTED_RESULT))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "shorten test failed! (wanted: %s got: %s\n",
-                  lname, sname);
+                  (char*)cls, sname);
       ok = 1;
     }
 
@@ -152,7 +152,8 @@ commence_testing (void *cls, int32_t success, const char *emsg)
     return;
   }
 
-  GNUNET_GNS_shorten(gns_handle, TEST_DOMAIN, &process_shorten_result, NULL);
+  GNUNET_GNS_shorten(gns_handle, TEST_DOMAIN, &process_shorten_result,
+                     TEST_DOMAIN);
   
 }
 
@@ -195,8 +196,8 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
   struct GNUNET_CRYPTO_RsaPrivateKey *our_key;
   struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
   struct GNUNET_CRYPTO_RsaPrivateKey *bob_key;
-  GNUNET_HashCode bob_hash;
-  GNUNET_HashCode alice_hash;
+  struct GNUNET_CRYPTO_ShortHashCode bob_hash;
+  struct GNUNET_CRYPTO_ShortHashCode alice_hash;
   struct GNUNET_CRYPTO_RsaSignature *sig;
   char* our_keyfile;
 
@@ -211,7 +212,7 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
     return;
   }
 
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns",
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
                                                           "ZONEKEY",
                                                           &our_keyfile))
   {
@@ -236,9 +237,9 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
   rd.expiration = GNUNET_TIME_absolute_get_forever ();
   GNUNET_assert(1 == inet_pton (AF_INET, ip, web));
   
-  GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash);
+  GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash);
 
-  rd.data_size = sizeof(GNUNET_HashCode);
+  rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
   rd.data = &bob_hash;
   rd.record_type = GNUNET_GNS_RECORD_PKEY;
   
@@ -251,9 +252,11 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
                                   NULL);
   
   /* put alice into bobs zone */
-  GNUNET_CRYPTO_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash);
+  GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash);
   rd.data = &alice_hash;
-  sig = GNUNET_NAMESTORE_create_signature(bob_key, TEST_AUTHORITY_ALICE,
+  sig = GNUNET_NAMESTORE_create_signature(bob_key,
+                                          GNUNET_TIME_absolute_get_forever(),
+                                          TEST_AUTHORITY_ALICE,
                                           &rd, 1);
 
   GNUNET_NAMESTORE_record_put (namestore_handle,
@@ -265,13 +268,15 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
                                sig,
                                NULL,
                                NULL);
-
+  GNUNET_free(sig);
   /* put www A record and PSEU into alice's zone */
 
   rd.data_size = sizeof(struct in_addr);
   rd.data = web;
   rd.record_type = GNUNET_DNSPARSER_TYPE_A;
-  sig = GNUNET_NAMESTORE_create_signature(alice_key, TEST_RECORD_NAME,
+  sig = GNUNET_NAMESTORE_create_signature(alice_key,
+                                          GNUNET_TIME_absolute_get_forever(),
+                                          TEST_RECORD_NAME,
                                           &rd, 1);
 
   GNUNET_NAMESTORE_record_put (namestore_handle,
@@ -283,27 +288,23 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id,
                                sig,
                                NULL,
                                NULL);
-
-  rd.data_size = strlen(TEST_ALICE_PSEU);
-  rd.data = TEST_ALICE_PSEU;
-  rd.record_type = GNUNET_GNS_RECORD_PSEU;
+  
+  rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
+  rd.data = &alice_hash;
+  rd.record_type = GNUNET_GNS_RECORD_PKEY;
   GNUNET_free(sig);
 
-  sig = GNUNET_NAMESTORE_create_signature(alice_key, "",
-                                          &rd, 1);
-
-  GNUNET_NAMESTORE_record_put (namestore_handle,
-                               &alice_pkey,
-                               "",
-                               GNUNET_TIME_absolute_get_forever(),
-                               1,
+  GNUNET_NAMESTORE_record_create (namestore_handle,
+                               our_key,
+                               TEST_ALICE_PSEU,
                                &rd,
-                               sig,
                                &commence_testing,
                                NULL);
 
-  GNUNET_free(sig);
-
+  GNUNET_free(web);
+  GNUNET_CRYPTO_rsa_key_free(our_key);
+  GNUNET_CRYPTO_rsa_key_free(bob_key);
+  GNUNET_CRYPTO_rsa_key_free(alice_key);
 }
 
 static void
@@ -337,7 +338,7 @@ check ()
   int ret;
 
   /* Arguments for GNUNET_PROGRAM_run */
-  char *const argv[] = { "test-gns-simple-lookup", /* Name to give running binary */
+  char *const argv[] = { "test-gns-simple-shorten", /* Name to give running binary */
     "-c",
     "test_gns_simple_lookup.conf",       /* Config file to use */
 #if VERBOSE
@@ -351,12 +352,12 @@ check ()
   /* Run the run function as a new program */
   ret =
       GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
-                          "test-gns-simple-lookup", "nohelp", options, &run,
+                          "test-gns-simple-shorten", "nohelp", options, &run,
                           &ok);
   if (ret != GNUNET_OK)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "`test-gns-simple-lookup': Failed with error code %d\n", ret);
+                "`test-gns-simple-shorten': Failed with error code %d\n", ret);
   }
   return ok;
 }