From: Christian Grothoff Date: Sat, 23 Jul 2011 14:27:40 +0000 (+0000) Subject: fix shutdown X-Git-Tag: initial-import-from-subversion-38251~17691 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=fdd29c5663f10fadca628793e72ef9d56a9d2fe6;p=oweals%2Fgnunet.git fix shutdown --- diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 2d323a36a..f11c6e5f4 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c @@ -40,16 +40,12 @@ * - 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); diff --git a/src/nse/test_nse_api.c b/src/nse/test_nse_api.c index 273cff294..03ea41d18 100644 --- a/src/nse/test_nse_api.c +++ b/src/nse/test_nse_api.c @@ -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