aboutsummaryrefslogtreecommitdiff
path: root/src/regex
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-05-22 09:38:34 +0000
committerChristian Grothoff <christian@grothoff.org>2015-05-22 09:38:34 +0000
commitc4acc825e512573e5be1f39fab799efc3b894cd2 (patch)
treecab2203b28aa19eb64878befc839fc1eb950e4a8 /src/regex
parent849c839a87423e402e978958ab3d2975d3e95dd4 (diff)
downloadgnunet-c4acc825e512573e5be1f39fab799efc3b894cd2.tar.gz
gnunet-c4acc825e512573e5be1f39fab799efc3b894cd2.zip
-fix regex shutdown: clean up clients before DHT disconnect
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/gnunet-service-regex.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/regex/gnunet-service-regex.c b/src/regex/gnunet-service-regex.c
index 65307c4d8..2e0700c0a 100644
--- a/src/regex/gnunet-service-regex.c
+++ b/src/regex/gnunet-service-regex.c
@@ -106,33 +106,14 @@ static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
106 106
107 107
108/** 108/**
109 * Task run during shutdown.
110 *
111 * @param cls unused
112 * @param tc unused
113 */
114static void
115cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
116{
117 GNUNET_DHT_disconnect (dht);
118 dht = NULL;
119 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
120 stats = NULL;
121 GNUNET_SERVER_notification_context_destroy (nc);
122 nc = NULL;
123 GNUNET_free (my_private_key);
124 my_private_key = NULL;
125}
126
127
128/**
129 * A client disconnected. Remove all of its data structure entries. 109 * A client disconnected. Remove all of its data structure entries.
130 * 110 *
131 * @param cls closure, NULL 111 * @param cls closure, NULL
132 * @param client identification of the client 112 * @param client identification of the client
133 */ 113 */
134static void 114static void
135handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) 115handle_client_disconnect (void *cls,
116 struct GNUNET_SERVER_Client *client)
136{ 117{
137 struct ClientEntry *ce; 118 struct ClientEntry *ce;
138 struct ClientEntry *nx; 119 struct ClientEntry *nx;
@@ -158,7 +139,9 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
158 REGEX_INTERNAL_search_cancel (ce->sh); 139 REGEX_INTERNAL_search_cancel (ce->sh);
159 ce->sh = NULL; 140 ce->sh = NULL;
160 } 141 }
161 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, ce); 142 GNUNET_CONTAINER_DLL_remove (client_head,
143 client_tail,
144 ce);
162 GNUNET_free (ce); 145 GNUNET_free (ce);
163 } 146 }
164 } 147 }
@@ -166,6 +149,32 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
166 149
167 150
168/** 151/**
152 * Task run during shutdown.
153 *
154 * @param cls unused
155 * @param tc unused
156 */
157static void
158cleanup_task (void *cls,
159 const struct GNUNET_SCHEDULER_TaskContext *tc)
160{
161 struct ClientEntry *ce;
162
163 while (NULL != (ce = client_head))
164 handle_client_disconnect (NULL,
165 ce->client);
166 GNUNET_DHT_disconnect (dht);
167 dht = NULL;
168 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
169 stats = NULL;
170 GNUNET_SERVER_notification_context_destroy (nc);
171 nc = NULL;
172 GNUNET_free (my_private_key);
173 my_private_key = NULL;
174}
175
176
177/**
169 * Periodic task to refresh our announcement of the regex. 178 * Periodic task to refresh our announcement of the regex.
170 * 179 *
171 * @param cls the 'struct ClientEntry' of the client that triggered the 180 * @param cls the 'struct ClientEntry' of the client that triggered the
@@ -250,9 +259,9 @@ handle_announce (void *cls,
250 * @param cls the struct ClientEntry of the client searching 259 * @param cls the struct ClientEntry of the client searching
251 * @param id Peer providing a regex that matches the string. 260 * @param id Peer providing a regex that matches the string.
252 * @param get_path Path of the get request. 261 * @param get_path Path of the get request.
253 * @param get_path_length Lenght of get_path. 262 * @param get_path_length Lenght of @a get_path.
254 * @param put_path Path of the put request. 263 * @param put_path Path of the put request.
255 * @param put_path_length Length of the put_path. 264 * @param put_path_length Length of the @a put_path.
256 */ 265 */
257static void 266static void
258handle_search_result (void *cls, 267handle_search_result (void *cls,
@@ -376,12 +385,15 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
376 GNUNET_SCHEDULER_shutdown (); 385 GNUNET_SCHEDULER_shutdown ();
377 return; 386 return;
378 } 387 }
379 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, 388 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
389 &cleanup_task,
380 NULL); 390 NULL);
381 nc = GNUNET_SERVER_notification_context_create (server, 1); 391 nc = GNUNET_SERVER_notification_context_create (server, 1);
382 stats = GNUNET_STATISTICS_create ("regex", cfg); 392 stats = GNUNET_STATISTICS_create ("regex", cfg);
383 GNUNET_SERVER_add_handlers (server, handlers); 393 GNUNET_SERVER_add_handlers (server, handlers);
384 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 394 GNUNET_SERVER_disconnect_notify (server,
395 &handle_client_disconnect,
396 NULL);
385} 397}
386 398
387 399