diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-10-18 12:20:09 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-10-18 12:20:09 +0000 |
commit | 284ad241eec0f741d3221208017fb42931c5838c (patch) | |
tree | 1d82c1c217765fea2a2e565f29da3168d7d83ec9 /src | |
parent | f81f2291a4f9c427bfe1cf43c168655f3760f324 (diff) | |
download | gnunet-284ad241eec0f741d3221208017fb42931c5838c.tar.gz gnunet-284ad241eec0f741d3221208017fb42931c5838c.zip |
- cancel all DHT GET request while shutting down
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh_dht.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/mesh/gnunet-service-mesh_dht.c b/src/mesh/gnunet-service-mesh_dht.c index 68a99cf89..bb342d619 100644 --- a/src/mesh/gnunet-service-mesh_dht.c +++ b/src/mesh/gnunet-service-mesh_dht.c | |||
@@ -50,6 +50,9 @@ struct GMD_search_handle | |||
50 | 50 | ||
51 | /** Provided closure. */ | 51 | /** Provided closure. */ |
52 | void *cls; | 52 | void *cls; |
53 | |||
54 | /** Peer ID searched for */ | ||
55 | GNUNET_PEER_Id peer_id; | ||
53 | }; | 56 | }; |
54 | 57 | ||
55 | 58 | ||
@@ -92,6 +95,10 @@ static unsigned long long dht_replication_level; | |||
92 | */ | 95 | */ |
93 | static GNUNET_SCHEDULER_TaskIdentifier announce_id_task; | 96 | static GNUNET_SCHEDULER_TaskIdentifier announce_id_task; |
94 | 97 | ||
98 | /** | ||
99 | * GET requests to stop on shutdown. | ||
100 | */ | ||
101 | static struct GNUNET_CONTAINER_MultiHashMap32 *get_requests; | ||
95 | 102 | ||
96 | /******************************************************************************/ | 103 | /******************************************************************************/ |
97 | /******************************** STATIC ***********************************/ | 104 | /******************************** STATIC ***********************************/ |
@@ -261,6 +268,27 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
261 | GNUNET_SCHEDULER_add_delayed (id_announce_time, &announce_id, cls); | 268 | GNUNET_SCHEDULER_add_delayed (id_announce_time, &announce_id, cls); |
262 | } | 269 | } |
263 | 270 | ||
271 | /** | ||
272 | * Iterator over hash map entries and stop GET requests before disconnecting | ||
273 | * from the DHT. | ||
274 | * | ||
275 | * @param cls Closure (unused) | ||
276 | * @param key Current peer ID. | ||
277 | * @param value Value in the hash map (GMD_search_handle). | ||
278 | * | ||
279 | * @return #GNUNET_YES, we should continue to iterate, | ||
280 | */ | ||
281 | int | ||
282 | stop_get (void *cls, | ||
283 | uint32_t key, | ||
284 | void *value) | ||
285 | { | ||
286 | struct GMD_search_handle *h = value; | ||
287 | |||
288 | GMD_search_stop (h); | ||
289 | return GNUNET_YES; | ||
290 | } | ||
291 | |||
264 | 292 | ||
265 | /******************************************************************************/ | 293 | /******************************************************************************/ |
266 | /******************************** API ***********************************/ | 294 | /******************************** API ***********************************/ |
@@ -301,6 +329,7 @@ GMD_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
301 | } | 329 | } |
302 | 330 | ||
303 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, NULL); | 331 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, NULL); |
332 | get_requests = GNUNET_CONTAINER_multihashmap32_create (32); | ||
304 | } | 333 | } |
305 | 334 | ||
306 | 335 | ||
@@ -308,8 +337,10 @@ GMD_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
308 | * Shut down the DHT subsystem. | 337 | * Shut down the DHT subsystem. |
309 | */ | 338 | */ |
310 | void | 339 | void |
311 | GMD_shutdown(void ) | 340 | GMD_shutdown (void) |
312 | { | 341 | { |
342 | GNUNET_CONTAINER_multihashmap32_iterate (get_requests, &stop_get, NULL); | ||
343 | GNUNET_CONTAINER_multihashmap32_destroy (get_requests); | ||
313 | if (dht_handle != NULL) | 344 | if (dht_handle != NULL) |
314 | { | 345 | { |
315 | GNUNET_DHT_disconnect (dht_handle); | 346 | GNUNET_DHT_disconnect (dht_handle); |
@@ -333,6 +364,7 @@ GMD_search (const struct GNUNET_PeerIdentity *peer_id, | |||
333 | " Starting DHT GET for peer %s\n", GNUNET_i2s (peer_id)); | 364 | " Starting DHT GET for peer %s\n", GNUNET_i2s (peer_id)); |
334 | GNUNET_CRYPTO_hash (peer_id, sizeof (struct GNUNET_PeerIdentity), &phash); | 365 | GNUNET_CRYPTO_hash (peer_id, sizeof (struct GNUNET_PeerIdentity), &phash); |
335 | h = GNUNET_new (struct GMD_search_handle); | 366 | h = GNUNET_new (struct GMD_search_handle); |
367 | h->peer_id = GNUNET_PEER_intern (peer_id); | ||
336 | h->callback = callback; | 368 | h->callback = callback; |
337 | h->cls = cls; | 369 | h->cls = cls; |
338 | h->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ | 370 | h->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ |
@@ -344,12 +376,15 @@ GMD_search (const struct GNUNET_PeerIdentity *peer_id, | |||
344 | NULL, /* xquery */ | 376 | NULL, /* xquery */ |
345 | 0, /* xquery bits */ | 377 | 0, /* xquery bits */ |
346 | &dht_get_id_handler, h); | 378 | &dht_get_id_handler, h); |
379 | GNUNET_CONTAINER_multihashmap32_put (get_requests, h->peer_id, h, | ||
380 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
347 | return h; | 381 | return h; |
348 | } | 382 | } |
349 | 383 | ||
350 | void | 384 | void |
351 | GMD_search_stop (struct GMD_search_handle *h) | 385 | GMD_search_stop (struct GMD_search_handle *h) |
352 | { | 386 | { |
387 | GNUNET_CONTAINER_multihashmap32_remove (get_requests, h->peer_id, h); | ||
353 | GNUNET_DHT_get_stop (h->dhtget); | 388 | GNUNET_DHT_get_stop (h->dhtget); |
354 | GNUNET_free (h); | 389 | GNUNET_free (h); |
355 | } \ No newline at end of file | 390 | } \ No newline at end of file |