fix
[oweals/gnunet.git] / src / gns / test_gns_dht_threepeer.c
index 04cbc2b8127dda961c927eea38ec4f8bf265eabb..8bcc06464715e9a3ed971956f528e5a8c7e6b295 100644 (file)
@@ -42,7 +42,7 @@
 #define VERBOSE GNUNET_YES
 
 /* Timeout for entire testcase */
-#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80)
+#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
 #define ZONE_PUT_WAIT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
 
 /* If number of peers not in config file, use this number */
@@ -105,7 +105,7 @@ static int ok;
 
 int bob_online, alice_online, dave_online;
 
-struct GNUNET_CONFIGURATION_Handle *alice_cfg;
+const struct GNUNET_CONFIGURATION_Handle *alice_cfg;
 struct GNUNET_CONFIGURATION_Handle *cfg_bob;
 struct GNUNET_CONFIGURATION_Handle *cfg_dave;
 
@@ -135,6 +135,7 @@ finish_testing (void *cls, const char *emsg)
 static void
 end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  die_task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &finish_testing, NULL);
 }
 
@@ -146,9 +147,10 @@ end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static void
 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  die_task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failing test with error: `%s'!\n",
               (char *) cls);
-  GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
+  die_task = GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL);
   ok = 1;
 }
 
@@ -159,7 +161,6 @@ on_lookup_result(void *cls, uint32_t rd_count,
 {
   int i;
   char* string_val;
-  const char* typename;
 
   if (rd_count == 0)
   {
@@ -173,11 +174,9 @@ on_lookup_result(void *cls, uint32_t rd_count,
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
     for (i=0; i<rd_count; i++)
     {
-      typename = GNUNET_NAMESTORE_number_to_typename (rd[i].record_type);
       string_val = GNUNET_NAMESTORE_value_to_string(rd[i].record_type,
                                                     rd[i].data,
                                                     rd[i].data_size);
-      printf("Got %s record: %s\n", typename, string_val);
       if (0 == strcmp(string_val, TEST_IP))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -188,6 +187,7 @@ on_lookup_result(void *cls, uint32_t rd_count,
   }
   GNUNET_GNS_disconnect(gh);
   GNUNET_SCHEDULER_cancel(die_task);
+  die_task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &finish_testing, NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down!\n");
 
@@ -197,10 +197,11 @@ static void
 commence_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   
-
   gh = GNUNET_GNS_connect(alice_cfg);
 
-  GNUNET_GNS_lookup(gh, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
+  GNUNET_GNS_lookup(gh, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
+                    GNUNET_NO,
+                    NULL,
                     &on_lookup_result, TEST_DOMAIN);
   die_task =
     GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from lookup");
@@ -252,6 +253,7 @@ daemon_connected (void *cls, const struct GNUNET_PeerIdentity *first,
                 total_connections);
 #endif
     GNUNET_SCHEDULER_cancel (die_task);
+    die_task = GNUNET_SCHEDULER_NO_TASK;
     //die_task =
     //    GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from connect");
    
@@ -275,10 +277,16 @@ all_connected(void *cls, const char *emsg)
   GNUNET_SCHEDULER_add_delayed (ZONE_PUT_WAIT_TIME, &commence_testing, NULL);
 }
 
-void
-ns_create_cont(void *cls, int32_t s, const char *emsg)
+static void
+disconnect_ns (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  GNUNET_NAMESTORE_disconnect (cls);
+}
+
+static void
+cont_ns (void* cls, int32_t s, const char* emsg)
 {
-  GNUNET_NAMESTORE_disconnect((struct GNUNET_NAMESTORE_Handle *)cls, 0);
+  GNUNET_SCHEDULER_add_now (&disconnect_ns, cls);
 }
 
 static void
@@ -294,7 +302,7 @@ daemon_started (void *cls, const struct GNUNET_PeerIdentity *id,
   struct GNUNET_NAMESTORE_RecordData rd;
 
   rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE;
-  rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
+  rd.expiration_time = UINT64_MAX;
   
   if (NULL == dave_daemon)
   {
@@ -320,7 +328,8 @@ daemon_started (void *cls, const struct GNUNET_PeerIdentity *id,
     GNUNET_assert(1 == inet_pton (AF_INET, TEST_IP, web));
     rd.data_size = sizeof(struct in_addr);
     rd.data = web;
-    rd.record_type = GNUNET_GNS_RECORD_TYPE_A;
+    rd.record_type = GNUNET_GNS_RECORD_A;
+    rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
 
     GNUNET_NAMESTORE_record_create (ns, key, "www", &rd, NULL, NULL);
 
@@ -328,7 +337,7 @@ daemon_started (void *cls, const struct GNUNET_PeerIdentity *id,
     rd.data = TEST_DAVE_PSEU;
     rd.record_type = GNUNET_GNS_RECORD_PSEU;
 
-    GNUNET_NAMESTORE_record_create (ns, key, "+", &rd, ns_create_cont, ns);
+    GNUNET_NAMESTORE_record_create (ns, key, "+", &rd, &cont_ns, ns);
 
     GNUNET_CRYPTO_rsa_key_free(key);
     GNUNET_free(keyfile);
@@ -361,8 +370,9 @@ daemon_started (void *cls, const struct GNUNET_PeerIdentity *id,
     rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
     rd.data = &dave_hash;
     rd.record_type = GNUNET_GNS_RECORD_PKEY;
+    rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
 
-    GNUNET_NAMESTORE_record_create (ns, key, "buddy", &rd, ns_create_cont, ns);
+    GNUNET_NAMESTORE_record_create (ns, key, "buddy", &rd, &cont_ns, ns);
 
     GNUNET_CRYPTO_rsa_key_free(key);
     GNUNET_free(keyfile);
@@ -394,8 +404,9 @@ daemon_started (void *cls, const struct GNUNET_PeerIdentity *id,
     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;
 
-    GNUNET_NAMESTORE_record_create (ns, key, "bob", &rd, ns_create_cont, ns);
+    GNUNET_NAMESTORE_record_create (ns, key, "bob", &rd, &cont_ns, ns);
 
     GNUNET_CRYPTO_rsa_key_free(key);
     GNUNET_free(keyfile);
@@ -487,12 +498,12 @@ check ()
   /* Run the run function as a new program */
   ret =
       GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
-                          "test-gns-twopeer", "nohelp", options, &run,
+                          "test-gns-threepeer", "nohelp", options, &run,
                           &ok);
   if (ret != GNUNET_OK)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "`test-gns-twopeer': Failed with error code %d\n", ret);
+                "`test-gns-threepeer': Failed with error code %d\n", ret);
   }
   return ok;
 }
@@ -502,7 +513,7 @@ main (int argc, char *argv[])
 {
   int ret;
 
-  GNUNET_log_setup ("test-gns-twopeer",
+  GNUNET_log_setup ("test-gns-threepeer",
 #if VERBOSE
                     "DEBUG",
 #else
@@ -517,4 +528,4 @@ main (int argc, char *argv[])
   return ret;
 }
 
-/* end of test_gns_twopeer.c */
+/* end of test_gns_threepeer.c */