even longer timeout, still timing out on hostkey generation (sparcbot)
[oweals/gnunet.git] / src / hostlist / test_gnunet_daemon_hostlist_learning.c
index cb2ca9d0222cb2a1b6400f0a0b948c5016ea2dfb..43199bd91e571b002fd99653ca40949546d1175d 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -38,7 +38,7 @@
 /**
  * How long until wait until testcases fails
  */
 /**
  * How long until wait until testcases fails
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 240)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 180)
 #define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
 static int timeout;
 #define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
 static int timeout;
@@ -50,6 +50,7 @@ static int learned_hostlist_downloaded;
 
 static char * current_adv_uri;
 
 
 static char * current_adv_uri;
 
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
 static struct GNUNET_SCHEDULER_Handle *sched;
 
 static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
 static struct GNUNET_SCHEDULER_Handle *sched;
 
 static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
@@ -75,48 +76,35 @@ static struct GNUNET_STATISTICS_GetHandle * download_stats;
 static struct GNUNET_STATISTICS_GetHandle * urisrecv_stat;
 static struct GNUNET_STATISTICS_GetHandle * advsent_stat;
 
 static struct GNUNET_STATISTICS_GetHandle * urisrecv_stat;
 static struct GNUNET_STATISTICS_GetHandle * advsent_stat;
 
-
-static void
-waitpid_task (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct PeerContext *p = cls;
-
-#if START_ARM
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Killing ARM process.\n");
-  if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-  if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "ARM process %u stopped\n", p->arm_pid);
-#endif
-  GNUNET_CONFIGURATION_destroy (p->cfg);
-}
-
-
 static void shutdown_testcase()
 {
 static void shutdown_testcase()
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown testcase....\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping Timeout Task.\n");
   if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
   {
   if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
   {
-    GNUNET_SCHEDULER_cancel (sched,
-                             timeout_task);
+    GNUNET_SCHEDULER_cancel (sched, timeout_task);
     timeout_task = GNUNET_SCHEDULER_NO_TASK;
   }
     timeout_task = GNUNET_SCHEDULER_NO_TASK;
   }
-  if (check_task != GNUNET_SCHEDULER_NO_TASK)
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping Statistics Task.\n");
+/*
+  if ((NULL != learn_peer.stats) && (NULL != download_stats))
+    GNUNET_STATISTICS_get_cancel (download_stats);
+  if ((NULL != learn_peer.stats) && (NULL != urisrecv_stat))
+    GNUNET_STATISTICS_get_cancel (urisrecv_stat);
+  if ((NULL != adv_peer.stats) && (NULL != advsent_stat))
+    GNUNET_STATISTICS_get_cancel (advsent_stat);
+*/
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping Statistics Check Task.\n");
+  if ((check_task != GNUNET_SCHEDULER_NO_TASK) && (sched !=NULL))
   {
     GNUNET_SCHEDULER_cancel (sched, check_task);
     check_task = GNUNET_SCHEDULER_NO_TASK;
   }
   {
     GNUNET_SCHEDULER_cancel (sched, check_task);
     check_task = GNUNET_SCHEDULER_NO_TASK;
   }
-  if (NULL != download_stats)
-    GNUNET_STATISTICS_get_cancel (download_stats);
-  if (NULL != urisrecv_stat)
-    GNUNET_STATISTICS_get_cancel (urisrecv_stat);
-  if (NULL != advsent_stat)
-    GNUNET_STATISTICS_get_cancel (advsent_stat);
-  if ( NULL != current_adv_uri ) GNUNET_free (current_adv_uri);
 
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Freeing uri\n");
+  if ( NULL != current_adv_uri ) GNUNET_free (current_adv_uri);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from Transport.\n");
   if (adv_peer.th != NULL)
   {
     GNUNET_TRANSPORT_disconnect (adv_peer.th);
   if (adv_peer.th != NULL)
   {
     GNUNET_TRANSPORT_disconnect (adv_peer.th);
@@ -127,6 +115,8 @@ static void shutdown_testcase()
     GNUNET_TRANSPORT_disconnect (learn_peer.th);
     learn_peer.th = NULL;
   }
     GNUNET_TRANSPORT_disconnect (learn_peer.th);
     learn_peer.th = NULL;
   }
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from Core.\n");
   if (adv_peer.core != NULL)
   {
     GNUNET_CORE_disconnect (adv_peer.core);
   if (adv_peer.core != NULL)
   {
     GNUNET_CORE_disconnect (adv_peer.core);
@@ -140,11 +130,34 @@ static void shutdown_testcase()
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Asking ARM to stop core services\n");
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Asking ARM to stop core services\n");
 
-  GNUNET_SCHEDULER_add_now (sched,                         
-                           &waitpid_task, &learn_peer);
-  GNUNET_SCHEDULER_add_now (sched,
-                           &waitpid_task, &adv_peer);
+
+#if START_ARM
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Killing hostlist server ARM process.\n");
+  if (0 != PLIBC_KILL (adv_peer.arm_pid, SIGTERM))
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+  if (GNUNET_OS_process_wait(adv_peer.arm_pid) != GNUNET_OK)
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Hostlist server ARM process %u stopped\n", adv_peer.arm_pid);
+#endif
+  
+
+#if START_ARM
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Killing hostlist client ARM process.\n");
+  if (0 != PLIBC_KILL (learn_peer.arm_pid, SIGTERM))
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+  if (GNUNET_OS_process_wait(learn_peer.arm_pid) != GNUNET_OK)
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Hostlist client ARM process %u stopped\n", learn_peer.arm_pid);
+#endif
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down scheduler\n");
   GNUNET_SCHEDULER_shutdown (sched);
   GNUNET_SCHEDULER_shutdown (sched);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown complete....\n");
+
 }
 
 /**
 }
 
 /**
@@ -154,6 +167,8 @@ static void
 timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   timeout_task = GNUNET_SCHEDULER_NO_TASK;
 timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    return;
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
               "Timeout while executing testcase, test failed.\n");
   timeout = GNUNET_YES;
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
               "Timeout while executing testcase, test failed.\n");
   timeout = GNUNET_YES;
@@ -167,16 +182,14 @@ process_downloads (void *cls,
               uint64_t value,
               int is_persistent)
 {
               uint64_t value,
               int is_persistent)
 {
-
   download_stats = NULL;
   download_stats = NULL;
-  if ( ((struct PeerContext *) cls == &learn_peer) && (value == 2) && (learned_hostlist_downloaded == GNUNET_NO) )
+  if ( (value == 2) && (learned_hostlist_downloaded == GNUNET_NO) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 _("Peer has successfully downloaded advertised URI \n"));
     learned_hostlist_downloaded = GNUNET_YES;
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                 _("Peer has successfully downloaded advertised URI \n"));
     learned_hostlist_downloaded = GNUNET_YES;
-  }
-  if (GNUNET_NO != learned_hostlist_downloaded)
     shutdown_testcase();
     shutdown_testcase();
+  }
   return GNUNET_OK;
 }
 
   return GNUNET_OK;
 }
 
@@ -222,32 +235,43 @@ static void
 check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   char *stat;
 check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   char *stat;
+
+  check_task = GNUNET_SCHEDULER_NO_TASK;
+    if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+      return;
+
   GNUNET_asprintf (&stat,
                    gettext_noop("# advertised URI `%s' downloaded"),
                    current_adv_uri);
   GNUNET_asprintf (&stat,
                    gettext_noop("# advertised URI `%s' downloaded"),
                    current_adv_uri);
-  download_stats = GNUNET_STATISTICS_get (learn_peer.stats,
-                         "hostlist",
-                         stat,
-                         GNUNET_TIME_UNIT_MINUTES,
-                         NULL,
-                         &process_downloads,
-                         &learn_peer);
+  if ( NULL != learn_peer.stats)
+  {
+    download_stats = GNUNET_STATISTICS_get (learn_peer.stats,
+                           "hostlist",
+                           stat,
+                           GNUNET_TIME_UNIT_MINUTES,
+                           NULL,
+                           &process_downloads,
+                           &learn_peer);
+
+    urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats,
+                           "hostlist",
+                           gettext_noop("# advertised hostlist URIs"),
+                           GNUNET_TIME_UNIT_MINUTES,
+                           NULL,
+                           &process_uris_recv,
+                           &learn_peer);
+  }
   GNUNET_free (stat);
   GNUNET_free (stat);
-
-  urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats,
-                         "hostlist",
-                         gettext_noop("# advertised hostlist URIs"),
-                         GNUNET_TIME_UNIT_MINUTES,
-                         NULL,
-                         &process_uris_recv,
-                         &learn_peer);
-  advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats,
-                         "hostlist",
-                         gettext_noop("# hostlist advertisements send"),
-                         GNUNET_TIME_UNIT_MINUTES,
-                         NULL,
-                         &process_adv_sent,
-                         NULL);
+  if ( NULL != adv_peer.stats)
+  {
+    advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats,
+                           "hostlist",
+                           gettext_noop("# hostlist advertisements send"),
+                           GNUNET_TIME_UNIT_MINUTES,
+                           NULL,
+                           &process_adv_sent,
+                           NULL);
+  }
   check_task = GNUNET_SCHEDULER_add_delayed (sched,
                                 CHECK_INTERVALL,
                                 &check_statistics,
   check_task = GNUNET_SCHEDULER_add_delayed (sched,
                                 CHECK_INTERVALL,
                                 &check_statistics,
@@ -264,10 +288,8 @@ static int ad_arrive_handler (void *cls,
                              uint32_t distance)
 {
   char *hostname;
                              uint32_t distance)
 {
   char *hostname;
-  char *expected_uri = GNUNET_malloc (MAX_URL_LEN);
-
+  char *expected_uri;
   unsigned long long port;
   unsigned long long port;
-  size_t size;
   const struct GNUNET_MessageHeader * incoming;
 
   if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg,
   const struct GNUNET_MessageHeader * incoming;
 
   if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg,
@@ -275,10 +297,9 @@ static int ad_arrive_handler (void *cls,
                                                    "HTTPPORT",
                                                    &port))
     {
                                                    "HTTPPORT",
                                                    &port))
     {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Could not read advertising server's configuration\n" );
-    if ( NULL != expected_uri ) GNUNET_free ( expected_uri );
-    return GNUNET_SYSERR;
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "Could not read advertising server's configuration\n" );
+      return GNUNET_SYSERR;
     }
 
   if ( GNUNET_SYSERR  == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg,
     }
 
   if ( GNUNET_SYSERR  == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg,
@@ -287,34 +308,23 @@ static int ad_arrive_handler (void *cls,
                                                    &hostname))
     hostname = GNUNET_RESOLVER_local_fqdn_get ();
 
                                                    &hostname))
     hostname = GNUNET_RESOLVER_local_fqdn_get ();
 
-  if (NULL != hostname)
-    {
-      size = strlen (hostname);
-      if (size + 15 > MAX_URL_LEN)
-        {
-          GNUNET_break (0);
-        }
-      else
-        {
-          GNUNET_asprintf (&expected_uri,
-                           "http://%s:%u/",
-                           hostname,
-                           (unsigned int) port);
-        }
-    }
-
+  GNUNET_asprintf (&expected_uri,
+                  "http://%s:%u/",
+                  hostname != NULL ? hostname : "localhost",
+                  (unsigned int) port);   
   incoming = (const struct GNUNET_MessageHeader *) message;
   current_adv_uri = strdup ((char*) &incoming[1]);
   if ( 0 == strcmp( expected_uri, current_adv_uri ) )
   incoming = (const struct GNUNET_MessageHeader *) message;
   current_adv_uri = strdup ((char*) &incoming[1]);
   if ( 0 == strcmp( expected_uri, current_adv_uri ) )
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Recieved hostlist advertisement with URI `%s' as expected\n", current_adv_uri);
-    adv_arrived = GNUNET_YES;
-  }
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                 "Recieved hostlist advertisement with URI `%s' as expected\n", current_adv_uri);
+      adv_arrived = GNUNET_YES;
+      adv_sent = GNUNET_YES;
+    }
   else
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Expected URI `%s' and recieved URI `%s' differ\n", expected_uri, current_adv_uri);
   else
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Expected URI `%s' and recieved URI `%s' differ\n", expected_uri, current_adv_uri);
-  GNUNET_free_non_null (expected_uri);
+  GNUNET_free (expected_uri);
   GNUNET_free_non_null (hostname);
   return GNUNET_OK;
 }
   GNUNET_free_non_null (hostname);
   return GNUNET_OK;
 }
@@ -358,13 +368,13 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname)
   if ( NULL != filename)  GNUNET_free ( filename );
 
   p->core = GNUNET_CORE_connect (sched, p->cfg,
   if ( NULL != filename)  GNUNET_free ( filename );
 
   p->core = GNUNET_CORE_connect (sched, p->cfg,
-                              GNUNET_TIME_UNIT_FOREVER_REL,
-                              NULL,
-                              NULL,
-                              NULL, NULL,
-                              NULL, GNUNET_NO,
-                              NULL, GNUNET_NO,
-                              learn_handlers );
+                                GNUNET_TIME_UNIT_FOREVER_REL,
+                                NULL,
+                                NULL,
+                                NULL, NULL, NULL,
+                                NULL, GNUNET_NO,
+                                NULL, GNUNET_NO,
+                                learn_handlers );
   GNUNET_assert ( NULL != p->core );
   p->stats = GNUNET_STATISTICS_create (sched, "hostlist", p->cfg);
   GNUNET_assert ( NULL != p->stats );
   GNUNET_assert ( NULL != p->core );
   p->stats = GNUNET_STATISTICS_create (sched, "hostlist", p->cfg);
   GNUNET_assert ( NULL != p->stats );
@@ -395,7 +405,7 @@ run (void *cls,
      struct GNUNET_SCHEDULER_Handle *s,
      char *const *args,
      const char *cfgfile, 
      struct GNUNET_SCHEDULER_Handle *s,
      char *const *args,
      const char *cfgfile, 
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+     const struct GNUNET_CONFIGURATION_Handle *c)
 {
   timeout = GNUNET_NO;
   adv_sent =GNUNET_NO;
 {
   timeout = GNUNET_NO;
   adv_sent =GNUNET_NO;
@@ -404,13 +414,9 @@ run (void *cls,
   learned_hostlist_saved = GNUNET_NO;
   learned_hostlist_downloaded = GNUNET_NO;
 
   learned_hostlist_saved = GNUNET_NO;
   learned_hostlist_downloaded = GNUNET_NO;
 
+  cfg = c;
   sched = s;
 
   sched = s;
 
-  check_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                CHECK_INTERVALL,
-                                &check_statistics,
-                                NULL);
-
   setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf");
   setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf");
   timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
   setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf");
   setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf");
   timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
@@ -418,9 +424,12 @@ run (void *cls,
                                                &timeout_error,
                                                NULL);
 
                                                &timeout_error,
                                                NULL);
 
+  check_task = GNUNET_SCHEDULER_add_delayed (sched,
+                                CHECK_INTERVALL,
+                                &check_statistics,
+                                NULL);
 }
 
 }
 
-
 static int
 check ()
 {
 static int
 check ()
 {
@@ -442,6 +451,9 @@ check ()
 
   failed = GNUNET_NO;
 
 
   failed = GNUNET_NO;
 
+  if (learned_hostlist_downloaded == GNUNET_YES)
+    return GNUNET_NO;
+
   if (timeout == GNUNET_YES)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
   if (timeout == GNUNET_YES)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,