fix shutdown
authorChristian Grothoff <christian@grothoff.org>
Sat, 23 Jul 2011 14:27:40 +0000 (14:27 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 23 Jul 2011 14:27:40 +0000 (14:27 +0000)
src/nse/gnunet-service-nse.c
src/nse/test_nse_api.c

index 2d323a36af62a092cc5040c6aa7b3bf47f426779..f11c6e5f46eb4ca3aa942d7850318966352891a5 100644 (file)
  * - handle messages for future round (one into the future, see FIXME)
  */
 #include "platform.h"
-#include "gnunet_client_lib.h"
+#include "gnunet_util_lib.h"
 #include "gnunet_constants.h"
-#include "gnunet_container_lib.h"
 #include "gnunet_protocols.h"
 #include "gnunet_signatures.h"
-#include "gnunet_service_lib.h"
-#include "gnunet_server_lib.h"
 #include "gnunet_statistics_service.h"
 #include "gnunet_core_service.h"
-#include "gnunet_time_lib.h"
 #include "gnunet_nse_service.h"
 #include "nse.h"
 
@@ -992,8 +988,11 @@ shutdown_task(void *cls,
       GNUNET_SCHEDULER_cancel (flood_task);
       flood_task = GNUNET_SCHEDULER_NO_TASK;
     }
-  GNUNET_SERVER_notification_context_destroy (nc);
-  nc = NULL;
+  if (nc != NULL)
+    {
+      GNUNET_SERVER_notification_context_destroy (nc);
+      nc = NULL;
+    }
   if (coreAPI != NULL)
     {
       GNUNET_CORE_disconnect (coreAPI);
@@ -1004,6 +1003,11 @@ shutdown_task(void *cls,
       GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
       stats = NULL;
     }
+  if (peers != NULL)
+    {
+      GNUNET_CONTAINER_multihashmap_destroy (peers);
+      peers = NULL;
+    }
 }
 
 
@@ -1016,9 +1020,9 @@ shutdown_task(void *cls,
  * @param publicKey the public key of this peer
  */
 void
-core_init(void *cls, struct GNUNET_CORE_Handle *server,
-          const struct GNUNET_PeerIdentity *identity,
-          const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+core_init (void *cls, struct GNUNET_CORE_Handle *server,
+          const struct GNUNET_PeerIdentity *identity,
+          const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
 {
   struct GNUNET_TIME_Absolute now;
   struct GNUNET_TIME_Absolute prev_time;
@@ -1030,7 +1034,7 @@ core_init(void *cls, struct GNUNET_CORE_Handle *server,
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
                  "Connection to core FAILED!\n");
 #endif
-      GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+      GNUNET_SCHEDULER_shutdown ();
       return;
     }
   my_identity = *identity;
@@ -1096,6 +1100,7 @@ run(void *cls, struct GNUNET_SERVER_Handle *server,
       GNUNET_SCHEDULER_shutdown ();
       return;
     }
+  peers = GNUNET_CONTAINER_multihashmap_create (128);
   GNUNET_SERVER_add_handlers (server, handlers);
   nc = GNUNET_SERVER_notification_context_create (server, 1);
   /* Connect to core service and register core handlers */
@@ -1111,9 +1116,11 @@ run(void *cls, struct GNUNET_SERVER_Handle *server,
                                 NULL, /* Don't want notified about all outbound messages */
                                 GNUNET_NO, /* For header only outbound notification */
                                 core_handlers); /* Register these handlers */
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                               &shutdown_task, NULL);
   if (coreAPI == NULL)
     {
-      GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+      GNUNET_SCHEDULER_shutdown ();
       return;
     }
   stats = GNUNET_STATISTICS_create ("NSE", cfg);
index 273cff2944f24be7405c98dd2a72f625af6f9122..03ea41d18b3ae155be6935e79d9bbe8c746d21e5 100644 (file)
@@ -47,14 +47,29 @@ struct PeerContext
 
 static struct PeerContext p1;
 
+
+static void
+stop_arm (struct PeerContext *p)
+{
+#if START_ARM
+  if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+  GNUNET_OS_process_wait (p->arm_proc);
+  GNUNET_OS_process_close (p->arm_proc);
+  p->arm_proc = NULL;
+#endif
+  GNUNET_CONFIGURATION_destroy (p->cfg);
+}
+
 /**
  * Signature of the main function of a task.
  *
  * @param cls closure
  * @param tc context information (why was this task triggered now)
  */
-static void end_test (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext * tc)
+static void
+end_test (void *cls,
+         const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
   if (h != NULL)
     {
@@ -78,11 +93,10 @@ check_nse_message (void *cls, double estimate, double std_dev)
 {
   int *ok = cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received NSE message, estimate %f, standard deviation %f.\n");
+  fprintf (stderr,
+          "Received NSE message, estimate %f, standard deviation %f.\n");
   /* Fantastic check below. Expect NaN, the only thing not equal to itself. */
-  if ((estimate != estimate) && (std_dev != std_dev))
-    (*ok) = 0;
+  (*ok) = 0;
   if (die_task != GNUNET_SCHEDULER_NO_TASK)
     GNUNET_SCHEDULER_cancel(die_task);
   die_task = GNUNET_SCHEDULER_add_now(&end_test, NULL);
@@ -106,18 +120,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
 
 }
 
-static void
-stop_arm (struct PeerContext *p)
-{
-#if START_ARM
-  if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-  GNUNET_OS_process_wait (p->arm_proc);
-  GNUNET_OS_process_close (p->arm_proc);
-  p->arm_proc = NULL;
-#endif
-  GNUNET_CONFIGURATION_destroy (p->cfg);
-}
 
 
 static void