add TODO
[oweals/gnunet.git] / src / topology / test_gnunet_daemon_topology.c
index f16f382ae9c225bb978609467b1189958eedb100..5c54e0ee31f60289b1b1f9001c46d706664dfcde 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
 #include "platform.h"
 #include "gnunet_testing_lib.h"
 
 #include "platform.h"
 #include "gnunet_testing_lib.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
 #define NUM_PEERS 2
 
 /**
  * How long until we give up on connecting the peers?
  */
 
 #define NUM_PEERS 2
 
 /**
  * How long until we give up on connecting the peers?
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
 
 #define CONNECT_ATTEMPTS 3
 
 
 #define CONNECT_ATTEMPTS 3
 
@@ -48,14 +48,35 @@ static struct GNUNET_TESTING_Daemon *first;
 
 static struct GNUNET_TESTING_Daemon *last;
 
 
 static struct GNUNET_TESTING_Daemon *last;
 
-static struct GNUNET_SCHEDULER_Handle *sched;
-
+/**
+ * Check whether peers successfully shut down.
+ */
+void shutdown_callback (void *cls,
+                        const char *emsg)
+{
+  if (emsg != NULL)
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Shutdown of peers failed!\n");
+#endif
+      if (ok == 0)
+        ok = 666;
+    }
+  else
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "All peers successfully shut down!\n");
+#endif
+    }
+}
 
 static void
 clean_up_task (void *cls,
                 const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
 
 static void
 clean_up_task (void *cls,
                 const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+  GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
   ok = 0;     
 }
 
   ok = 0;     
 }
 
@@ -64,6 +85,7 @@ static void
 notify_connect_complete(void *cls,
                         const struct GNUNET_PeerIdentity *first,
                         const struct GNUNET_PeerIdentity *second,
 notify_connect_complete(void *cls,
                         const struct GNUNET_PeerIdentity *first,
                         const struct GNUNET_PeerIdentity *second,
+                        unsigned int distance,
                         const struct GNUNET_CONFIGURATION_Handle *first_cfg,
                         const struct GNUNET_CONFIGURATION_Handle *second_cfg,
                         struct GNUNET_TESTING_Daemon *first_daemon,
                         const struct GNUNET_CONFIGURATION_Handle *first_cfg,
                         const struct GNUNET_CONFIGURATION_Handle *second_cfg,
                         struct GNUNET_TESTING_Daemon *first_daemon,
@@ -75,7 +97,7 @@ notify_connect_complete(void *cls,
       fprintf (stderr,
               "Failed to connect two peers: %s\n",
               emsg);
       fprintf (stderr,
               "Failed to connect two peers: %s\n",
               emsg);
-      GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
+      GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
       GNUNET_assert (0);
       return;
     }
       GNUNET_assert (0);
       return;
     }
@@ -84,11 +106,8 @@ notify_connect_complete(void *cls,
     {
       /* FIXME: check that topology adds a few more links
         in addition to those that were seeded */
     {
       /* FIXME: check that topology adds a few more links
         in addition to those that were seeded */
-      /* For now, sleep so we can have the daemon do some work */
-      GNUNET_SCHEDULER_add_delayed (sched,
-                                   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
-                                   &clean_up_task,
-                                   NULL);
+      GNUNET_SCHEDULER_add_now (&clean_up_task,
+                               NULL);
     }
 }
 
     }
 }
 
@@ -109,12 +128,14 @@ static void my_cb(void *cls,
       return;
     }
   GNUNET_TESTING_daemons_connect (last, d, TIMEOUT, CONNECT_ATTEMPTS,
       return;
     }
   GNUNET_TESTING_daemons_connect (last, d, TIMEOUT, CONNECT_ATTEMPTS,
+                                  GNUNET_YES,
                                  &notify_connect_complete,
                                  NULL);
   if (peers_left == 0)
     {
       /* close circle */
       GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS,
                                  &notify_connect_complete,
                                  NULL);
   if (peers_left == 0)
     {
       /* close circle */
       GNUNET_TESTING_daemons_connect (d, first, TIMEOUT, CONNECT_ATTEMPTS,
+                                      GNUNET_YES,
                                      &notify_connect_complete,
                                      NULL);
     }
                                      &notify_connect_complete,
                                      NULL);
     }
@@ -123,19 +144,19 @@ static void my_cb(void *cls,
 
 static void
 run (void *cls,
 
 static void
 run (void *cls,
-     struct GNUNET_SCHEDULER_Handle *s,
      char *const *args,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
      char *const *args,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  sched = s;
   ok = 1;
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Starting daemons.\n");
 #endif
   peers_left = NUM_PEERS;
   ok = 1;
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Starting daemons.\n");
 #endif
   peers_left = NUM_PEERS;
-  pg = GNUNET_TESTING_daemons_start (sched, cfg, 
+  pg = GNUNET_TESTING_daemons_start (cfg,
+                                    peers_left,
+                                    peers_left,
                                     peers_left,
                                     TIMEOUT,
                                     NULL, NULL,
                                     peers_left,
                                     TIMEOUT,
                                     NULL, NULL,