diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 14 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 50 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.h | 8 |
3 files changed, 57 insertions, 15 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 31b3822fb..c07131548 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -155,6 +155,16 @@ static int auto_import_pkey; | |||
155 | static struct GNUNET_TIME_Relative default_lookup_timeout; | 155 | static struct GNUNET_TIME_Relative default_lookup_timeout; |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * Continue shutdown | ||
159 | */ | ||
160 | static void | ||
161 | on_resolver_cleanup(void) | ||
162 | { | ||
163 | GNUNET_NAMESTORE_disconnect(namestore_handle, 1); | ||
164 | GNUNET_DHT_disconnect(dht_handle); | ||
165 | } | ||
166 | |||
167 | /** | ||
158 | * Task run during shutdown. | 168 | * Task run during shutdown. |
159 | * | 169 | * |
160 | * @param cls unused | 170 | * @param cls unused |
@@ -173,10 +183,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
173 | GNUNET_SERVER_notification_context_destroy (nc); | 183 | GNUNET_SERVER_notification_context_destroy (nc); |
174 | 184 | ||
175 | gns_interceptor_stop(); | 185 | gns_interceptor_stop(); |
176 | gns_resolver_cleanup(); | 186 | gns_resolver_cleanup(&on_resolver_cleanup); |
177 | 187 | ||
178 | GNUNET_NAMESTORE_disconnect(namestore_handle, 1); | ||
179 | GNUNET_DHT_disconnect(dht_handle); | ||
180 | } | 188 | } |
181 | 189 | ||
182 | 190 | ||
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index e0ec393ed..aef9df4d7 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -182,6 +182,7 @@ handle_auth_discovery_timeout(void *cls, | |||
182 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 182 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
183 | "GNS_GET_AUTH: dht lookup for query PSEU timed out.\n"); | 183 | "GNS_GET_AUTH: dht lookup for query PSEU timed out.\n"); |
184 | GNUNET_DHT_get_stop (gph->get_handle); | 184 | GNUNET_DHT_get_stop (gph->get_handle); |
185 | gph->get_handle = NULL; | ||
185 | process_pseu_result(gph, NULL); | 186 | process_pseu_result(gph, NULL); |
186 | } | 187 | } |
187 | 188 | ||
@@ -234,6 +235,7 @@ process_auth_discovery_dht_result(void* cls, | |||
234 | 235 | ||
235 | /* stop lookup and timeout task */ | 236 | /* stop lookup and timeout task */ |
236 | GNUNET_DHT_get_stop (gph->get_handle); | 237 | GNUNET_DHT_get_stop (gph->get_handle); |
238 | gph->get_handle = NULL; | ||
237 | GNUNET_SCHEDULER_cancel(gph->timeout); | 239 | GNUNET_SCHEDULER_cancel(gph->timeout); |
238 | 240 | ||
239 | gph->get_handle = NULL; | 241 | gph->get_handle = NULL; |
@@ -333,7 +335,8 @@ process_zone_to_name_discover(void *cls, | |||
333 | &handle_auth_discovery_timeout, gph); | 335 | &handle_auth_discovery_timeout, gph); |
334 | 336 | ||
335 | xquery = htonl(GNUNET_GNS_RECORD_PSEU); | 337 | xquery = htonl(GNUNET_GNS_RECORD_PSEU); |
336 | 338 | ||
339 | GNUNET_assert(gph->get_handle == NULL); | ||
337 | gph->get_handle = GNUNET_DHT_get_start(dht_handle, | 340 | gph->get_handle = GNUNET_DHT_get_start(dht_handle, |
338 | GNUNET_TIME_UNIT_FOREVER_REL, | 341 | GNUNET_TIME_UNIT_FOREVER_REL, |
339 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 342 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
@@ -416,7 +419,7 @@ gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, | |||
416 | /** | 419 | /** |
417 | * Cleanup background lookups | 420 | * Cleanup background lookups |
418 | * | 421 | * |
419 | * @param cks closure to iterator | 422 | * @param cls closure to iterator |
420 | * @param node heap nodes | 423 | * @param node heap nodes |
421 | * @param element the resolver handle | 424 | * @param element the resolver handle |
422 | * @param cost heap cost | 425 | * @param cost heap cost |
@@ -429,13 +432,21 @@ cleanup_pending_background_queries(void* cls, | |||
429 | GNUNET_CONTAINER_HeapCostType cost) | 432 | GNUNET_CONTAINER_HeapCostType cost) |
430 | { | 433 | { |
431 | struct ResolverHandle *rh = (struct ResolverHandle *)element; | 434 | struct ResolverHandle *rh = (struct ResolverHandle *)element; |
435 | ResolverCleanupContinuation cont = cls; | ||
432 | 436 | ||
433 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 437 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
434 | "GNS_CLEANUP: Terminating background lookup for %s\n", | 438 | "GNS_CLEANUP: Terminating background lookup for %s\n", |
435 | rh->name); | 439 | rh->name); |
436 | GNUNET_DHT_get_stop(rh->get_handle); | 440 | GNUNET_DHT_get_stop(rh->get_handle); |
441 | rh->get_handle = NULL; | ||
437 | rh->proc(rh->proc_cls, rh, 0, NULL); | 442 | rh->proc(rh->proc_cls, rh, 0, NULL); |
438 | 443 | ||
444 | GNUNET_CONTAINER_heap_remove_node(node); | ||
445 | |||
446 | if (GNUNET_CONTAINER_heap_get_size(dht_lookup_heap) == 0) | ||
447 | cont(); | ||
448 | |||
449 | |||
439 | return GNUNET_YES; | 450 | return GNUNET_YES; |
440 | } | 451 | } |
441 | 452 | ||
@@ -444,18 +455,18 @@ cleanup_pending_background_queries(void* cls, | |||
444 | * Shutdown resolver | 455 | * Shutdown resolver |
445 | */ | 456 | */ |
446 | void | 457 | void |
447 | gns_resolver_cleanup() | 458 | gns_resolver_cleanup(ResolverCleanupContinuation cont) |
448 | { | 459 | { |
449 | unsigned int s = GNUNET_CONTAINER_heap_get_size(dht_lookup_heap); | 460 | unsigned int s = GNUNET_CONTAINER_heap_get_size(dht_lookup_heap); |
450 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 461 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
451 | "GNS_CLEANUP: %d pending background queries to terminate\n", s); | 462 | "GNS_CLEANUP: %d pending background queries to terminate\n", s); |
452 | 463 | ||
453 | if (0 != s) | 464 | if (0 != s) |
454 | { | ||
455 | GNUNET_CONTAINER_heap_iterate (dht_lookup_heap, | 465 | GNUNET_CONTAINER_heap_iterate (dht_lookup_heap, |
456 | &cleanup_pending_background_queries, | 466 | &cleanup_pending_background_queries, |
457 | NULL); | 467 | cont); |
458 | } | 468 | else |
469 | cont(); | ||
459 | } | 470 | } |
460 | 471 | ||
461 | 472 | ||
@@ -537,7 +548,7 @@ background_lookup_result_processor(void *cls, | |||
537 | { | 548 | { |
538 | //We could do sth verbose/more useful here but it doesn't make any difference | 549 | //We could do sth verbose/more useful here but it doesn't make any difference |
539 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 550 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
540 | "GNS_BG: background dht lookup finished.\n"); | 551 | "GNS_BG: background dht lookup for finished.\n"); |
541 | } | 552 | } |
542 | 553 | ||
543 | /** | 554 | /** |
@@ -578,6 +589,7 @@ dht_lookup_timeout(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
578 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 589 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
579 | 590 | ||
580 | GNUNET_DHT_get_stop (rh->get_handle); | 591 | GNUNET_DHT_get_stop (rh->get_handle); |
592 | rh->get_handle = NULL; | ||
581 | rh->proc(rh->proc_cls, rh, 0, NULL); | 593 | rh->proc(rh->proc_cls, rh, 0, NULL); |
582 | } | 594 | } |
583 | 595 | ||
@@ -631,6 +643,7 @@ process_record_result_dht(void* cls, | |||
631 | 643 | ||
632 | /* stop lookup and timeout task */ | 644 | /* stop lookup and timeout task */ |
633 | GNUNET_DHT_get_stop (rh->get_handle); | 645 | GNUNET_DHT_get_stop (rh->get_handle); |
646 | rh->get_handle = NULL; | ||
634 | 647 | ||
635 | if (rh->dht_heap_node != NULL) | 648 | if (rh->dht_heap_node != NULL) |
636 | { | 649 | { |
@@ -770,7 +783,12 @@ resolve_record_dht(struct ResolverHandle *rh) | |||
770 | { | 783 | { |
771 | rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap); | 784 | rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap); |
772 | GNUNET_DHT_get_stop(rh_heap_root->get_handle); | 785 | GNUNET_DHT_get_stop(rh_heap_root->get_handle); |
786 | rh_heap_root->get_handle = NULL; | ||
773 | rh_heap_root->dht_heap_node = NULL; | 787 | rh_heap_root->dht_heap_node = NULL; |
788 | |||
789 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
790 | "GNS_PHASE_REC: Replacing oldest background query for %s\n", | ||
791 | rh_heap_root->name); | ||
774 | rh_heap_root->proc(rh_heap_root->proc_cls, | 792 | rh_heap_root->proc(rh_heap_root->proc_cls, |
775 | rh_heap_root, | 793 | rh_heap_root, |
776 | 0, | 794 | 0, |
@@ -782,6 +800,8 @@ resolve_record_dht(struct ResolverHandle *rh) | |||
782 | } | 800 | } |
783 | 801 | ||
784 | xquery = htonl(rlh->record_type); | 802 | xquery = htonl(rlh->record_type); |
803 | |||
804 | GNUNET_assert(rh->get_handle == NULL); | ||
785 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, | 805 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, |
786 | GNUNET_TIME_UNIT_FOREVER_REL, | 806 | GNUNET_TIME_UNIT_FOREVER_REL, |
787 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 807 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
@@ -957,12 +977,15 @@ dht_authority_lookup_timeout(void *cls, | |||
957 | 977 | ||
958 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 978 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
959 | "GNS_PHASE_DELEGATE: dht lookup for query %s timed out.\n", | 979 | "GNS_PHASE_DELEGATE: dht lookup for query %s timed out.\n", |
960 | rh->name); | 980 | rh->authority_name); |
961 | 981 | ||
962 | rh->status |= TIMED_OUT; | 982 | rh->status |= TIMED_OUT; |
963 | 983 | ||
964 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 984 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
965 | 985 | ||
986 | GNUNET_DHT_get_stop (rh->get_handle); | ||
987 | rh->get_handle = NULL; | ||
988 | |||
966 | if (strcmp(rh->name, "") == 0) | 989 | if (strcmp(rh->name, "") == 0) |
967 | { | 990 | { |
968 | /* | 991 | /* |
@@ -994,8 +1017,6 @@ dht_authority_lookup_timeout(void *cls, | |||
994 | &background_lookup_result_processor, | 1017 | &background_lookup_result_processor, |
995 | NULL); | 1018 | NULL); |
996 | 1019 | ||
997 | GNUNET_DHT_get_stop (rh->get_handle); | ||
998 | |||
999 | rh->proc(rh->proc_cls, rh, 0, NULL); | 1020 | rh->proc(rh->proc_cls, rh, 0, NULL); |
1000 | } | 1021 | } |
1001 | 1022 | ||
@@ -1584,6 +1605,11 @@ resolve_delegation_dht(struct ResolverHandle *rh) | |||
1584 | rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap); | 1605 | rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap); |
1585 | GNUNET_DHT_get_stop(rh_heap_root->get_handle); | 1606 | GNUNET_DHT_get_stop(rh_heap_root->get_handle); |
1586 | rh_heap_root->dht_heap_node = NULL; | 1607 | rh_heap_root->dht_heap_node = NULL; |
1608 | |||
1609 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1610 | "GNS_PHASE_DELEGATE: Replacing oldest background query for %s\n", | ||
1611 | rh_heap_root->authority_name); | ||
1612 | |||
1587 | rh_heap_root->proc(rh_heap_root->proc_cls, | 1613 | rh_heap_root->proc(rh_heap_root->proc_cls, |
1588 | rh_heap_root, | 1614 | rh_heap_root, |
1589 | 0, | 1615 | 0, |
@@ -1595,7 +1621,8 @@ resolve_delegation_dht(struct ResolverHandle *rh) | |||
1595 | } | 1621 | } |
1596 | 1622 | ||
1597 | xquery = htonl(GNUNET_GNS_RECORD_PKEY); | 1623 | xquery = htonl(GNUNET_GNS_RECORD_PKEY); |
1598 | 1624 | ||
1625 | GNUNET_assert(rh->get_handle == NULL); | ||
1599 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, | 1626 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, |
1600 | GNUNET_TIME_UNIT_FOREVER_REL, | 1627 | GNUNET_TIME_UNIT_FOREVER_REL, |
1601 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 1628 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
@@ -1903,6 +1930,7 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, | |||
1903 | rh->proc_cls = rlh; | 1930 | rh->proc_cls = rlh; |
1904 | rh->priv_key = key; | 1931 | rh->priv_key = key; |
1905 | rh->timeout = timeout; | 1932 | rh->timeout = timeout; |
1933 | rh->get_handle = NULL; | ||
1906 | if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 1934 | if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) |
1907 | { | 1935 | { |
1908 | /* | 1936 | /* |
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index a63abab9d..7290e927c 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h | |||
@@ -35,6 +35,10 @@ struct AuthorityChain | |||
35 | /* handle to a resolution process */ | 35 | /* handle to a resolution process */ |
36 | struct ResolverHandle; | 36 | struct ResolverHandle; |
37 | 37 | ||
38 | /** | ||
39 | * continuation called when cleanup of resolver finishes | ||
40 | */ | ||
41 | typedef void (*ResolverCleanupContinuation) (void); | ||
38 | 42 | ||
39 | /** | 43 | /** |
40 | * processor for a resultion result | 44 | * processor for a resultion result |
@@ -256,9 +260,11 @@ gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, | |||
256 | 260 | ||
257 | /** | 261 | /** |
258 | * Cleanup resolver: Terminate pending lookups | 262 | * Cleanup resolver: Terminate pending lookups |
263 | * | ||
264 | * @param cont continuation to call when finished | ||
259 | */ | 265 | */ |
260 | void | 266 | void |
261 | gns_resolver_cleanup(void); | 267 | gns_resolver_cleanup(ResolverCleanupContinuation cont); |
262 | 268 | ||
263 | /** | 269 | /** |
264 | * Lookup of a record in a specific zone | 270 | * Lookup of a record in a specific zone |