aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-23 14:27:40 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-23 14:27:40 +0000
commitfdd29c5663f10fadca628793e72ef9d56a9d2fe6 (patch)
treed17370de7bdf1e504e573cd19d8f88b5e8f852b8 /src
parent924311893e9ea66d32edd0d477ba32c8861b3528 (diff)
downloadgnunet-fdd29c5663f10fadca628793e72ef9d56a9d2fe6.tar.gz
gnunet-fdd29c5663f10fadca628793e72ef9d56a9d2fe6.zip
fix shutdown
Diffstat (limited to 'src')
-rw-r--r--src/nse/gnunet-service-nse.c31
-rw-r--r--src/nse/test_nse_api.c38
2 files changed, 39 insertions, 30 deletions
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 @@
40 * - handle messages for future round (one into the future, see FIXME) 40 * - handle messages for future round (one into the future, see FIXME)
41 */ 41 */
42#include "platform.h" 42#include "platform.h"
43#include "gnunet_client_lib.h" 43#include "gnunet_util_lib.h"
44#include "gnunet_constants.h" 44#include "gnunet_constants.h"
45#include "gnunet_container_lib.h"
46#include "gnunet_protocols.h" 45#include "gnunet_protocols.h"
47#include "gnunet_signatures.h" 46#include "gnunet_signatures.h"
48#include "gnunet_service_lib.h"
49#include "gnunet_server_lib.h"
50#include "gnunet_statistics_service.h" 47#include "gnunet_statistics_service.h"
51#include "gnunet_core_service.h" 48#include "gnunet_core_service.h"
52#include "gnunet_time_lib.h"
53#include "gnunet_nse_service.h" 49#include "gnunet_nse_service.h"
54#include "nse.h" 50#include "nse.h"
55 51
@@ -992,8 +988,11 @@ shutdown_task(void *cls,
992 GNUNET_SCHEDULER_cancel (flood_task); 988 GNUNET_SCHEDULER_cancel (flood_task);
993 flood_task = GNUNET_SCHEDULER_NO_TASK; 989 flood_task = GNUNET_SCHEDULER_NO_TASK;
994 } 990 }
995 GNUNET_SERVER_notification_context_destroy (nc); 991 if (nc != NULL)
996 nc = NULL; 992 {
993 GNUNET_SERVER_notification_context_destroy (nc);
994 nc = NULL;
995 }
997 if (coreAPI != NULL) 996 if (coreAPI != NULL)
998 { 997 {
999 GNUNET_CORE_disconnect (coreAPI); 998 GNUNET_CORE_disconnect (coreAPI);
@@ -1004,6 +1003,11 @@ shutdown_task(void *cls,
1004 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 1003 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
1005 stats = NULL; 1004 stats = NULL;
1006 } 1005 }
1006 if (peers != NULL)
1007 {
1008 GNUNET_CONTAINER_multihashmap_destroy (peers);
1009 peers = NULL;
1010 }
1007} 1011}
1008 1012
1009 1013
@@ -1016,9 +1020,9 @@ shutdown_task(void *cls,
1016 * @param publicKey the public key of this peer 1020 * @param publicKey the public key of this peer
1017 */ 1021 */
1018void 1022void
1019core_init(void *cls, struct GNUNET_CORE_Handle *server, 1023core_init (void *cls, struct GNUNET_CORE_Handle *server,
1020 const struct GNUNET_PeerIdentity *identity, 1024 const struct GNUNET_PeerIdentity *identity,
1021 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 1025 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
1022{ 1026{
1023 struct GNUNET_TIME_Absolute now; 1027 struct GNUNET_TIME_Absolute now;
1024 struct GNUNET_TIME_Absolute prev_time; 1028 struct GNUNET_TIME_Absolute prev_time;
@@ -1030,7 +1034,7 @@ core_init(void *cls, struct GNUNET_CORE_Handle *server,
1030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1031 "Connection to core FAILED!\n"); 1035 "Connection to core FAILED!\n");
1032#endif 1036#endif
1033 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 1037 GNUNET_SCHEDULER_shutdown ();
1034 return; 1038 return;
1035 } 1039 }
1036 my_identity = *identity; 1040 my_identity = *identity;
@@ -1096,6 +1100,7 @@ run(void *cls, struct GNUNET_SERVER_Handle *server,
1096 GNUNET_SCHEDULER_shutdown (); 1100 GNUNET_SCHEDULER_shutdown ();
1097 return; 1101 return;
1098 } 1102 }
1103 peers = GNUNET_CONTAINER_multihashmap_create (128);
1099 GNUNET_SERVER_add_handlers (server, handlers); 1104 GNUNET_SERVER_add_handlers (server, handlers);
1100 nc = GNUNET_SERVER_notification_context_create (server, 1); 1105 nc = GNUNET_SERVER_notification_context_create (server, 1);
1101 /* Connect to core service and register core handlers */ 1106 /* Connect to core service and register core handlers */
@@ -1111,9 +1116,11 @@ run(void *cls, struct GNUNET_SERVER_Handle *server,
1111 NULL, /* Don't want notified about all outbound messages */ 1116 NULL, /* Don't want notified about all outbound messages */
1112 GNUNET_NO, /* For header only outbound notification */ 1117 GNUNET_NO, /* For header only outbound notification */
1113 core_handlers); /* Register these handlers */ 1118 core_handlers); /* Register these handlers */
1119 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1120 &shutdown_task, NULL);
1114 if (coreAPI == NULL) 1121 if (coreAPI == NULL)
1115 { 1122 {
1116 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 1123 GNUNET_SCHEDULER_shutdown ();
1117 return; 1124 return;
1118 } 1125 }
1119 stats = GNUNET_STATISTICS_create ("NSE", cfg); 1126 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
47 47
48static struct PeerContext p1; 48static struct PeerContext p1;
49 49
50
51static void
52stop_arm (struct PeerContext *p)
53{
54#if START_ARM
55 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
56 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
57 GNUNET_OS_process_wait (p->arm_proc);
58 GNUNET_OS_process_close (p->arm_proc);
59 p->arm_proc = NULL;
60#endif
61 GNUNET_CONFIGURATION_destroy (p->cfg);
62}
63
50/** 64/**
51 * Signature of the main function of a task. 65 * Signature of the main function of a task.
52 * 66 *
53 * @param cls closure 67 * @param cls closure
54 * @param tc context information (why was this task triggered now) 68 * @param tc context information (why was this task triggered now)
55 */ 69 */
56static void end_test (void *cls, 70static void
57 const struct GNUNET_SCHEDULER_TaskContext * tc) 71end_test (void *cls,
72 const struct GNUNET_SCHEDULER_TaskContext * tc)
58{ 73{
59 if (h != NULL) 74 if (h != NULL)
60 { 75 {
@@ -78,11 +93,10 @@ check_nse_message (void *cls, double estimate, double std_dev)
78{ 93{
79 int *ok = cls; 94 int *ok = cls;
80 95
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 96 fprintf (stderr,
82 "Received NSE message, estimate %f, standard deviation %f.\n"); 97 "Received NSE message, estimate %f, standard deviation %f.\n");
83 /* Fantastic check below. Expect NaN, the only thing not equal to itself. */ 98 /* Fantastic check below. Expect NaN, the only thing not equal to itself. */
84 if ((estimate != estimate) && (std_dev != std_dev)) 99 (*ok) = 0;
85 (*ok) = 0;
86 if (die_task != GNUNET_SCHEDULER_NO_TASK) 100 if (die_task != GNUNET_SCHEDULER_NO_TASK)
87 GNUNET_SCHEDULER_cancel(die_task); 101 GNUNET_SCHEDULER_cancel(die_task);
88 die_task = GNUNET_SCHEDULER_add_now(&end_test, NULL); 102 die_task = GNUNET_SCHEDULER_add_now(&end_test, NULL);
@@ -106,18 +120,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
106 120
107} 121}
108 122
109static void
110stop_arm (struct PeerContext *p)
111{
112#if START_ARM
113 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
114 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
115 GNUNET_OS_process_wait (p->arm_proc);
116 GNUNET_OS_process_close (p->arm_proc);
117 p->arm_proc = NULL;
118#endif
119 GNUNET_CONFIGURATION_destroy (p->cfg);
120}
121 123
122 124
123static void 125static void