diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-22 16:36:39 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-22 16:36:39 +0000 |
commit | dd333f69e55bd7e2b94b4bb281e9b0c0b63c23f2 (patch) | |
tree | bdaa5f02741deb8695a347dcfc814657907d301d /src | |
parent | 51191c78817e2634f52584b6830e4d792c239670 (diff) | |
download | gnunet-dd333f69e55bd7e2b94b4bb281e9b0c0b63c23f2.tar.gz gnunet-dd333f69e55bd7e2b94b4bb281e9b0c0b63c23f2.zip |
-parallel background lookups
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/Makefile.am | 17 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 39 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 150 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.h | 15 | ||||
-rw-r--r-- | src/gns/test_gns_simple_lookup.c | 18 | ||||
-rw-r--r-- | src/gns/test_gns_simple_lookup.conf | 3 |
6 files changed, 188 insertions, 54 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index f41de7e3c..2b62cec53 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -38,7 +38,8 @@ check_PROGRAMS = \ | |||
38 | test_gns_simple_mx_lookup \ | 38 | test_gns_simple_mx_lookup \ |
39 | test_gns_simple_zkey_lookup \ | 39 | test_gns_simple_zkey_lookup \ |
40 | test_gns_dht_delegated_lookup \ | 40 | test_gns_dht_delegated_lookup \ |
41 | test_gns_pseu_shorten | 41 | test_gns_pseu_shorten \ |
42 | test_gns_max_queries | ||
42 | 43 | ||
43 | 44 | ||
44 | # test_gns_simple_lookup | 45 | # test_gns_simple_lookup |
@@ -169,6 +170,20 @@ test_gns_pseu_shorten_DEPENDENCIES = \ | |||
169 | $(top_builddir)/src/gns/libgnunetgns.la \ | 170 | $(top_builddir)/src/gns/libgnunetgns.la \ |
170 | $(top_builddir)/src/testing/libgnunettesting.la | 171 | $(top_builddir)/src/testing/libgnunettesting.la |
171 | 172 | ||
173 | |||
174 | test_gns_max_queries_SOURCES = \ | ||
175 | test_gns_max_queries.c | ||
176 | test_gns_max_queries_LDADD = \ | ||
177 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
178 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
179 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
180 | $(top_builddir)/src/testing/libgnunettesting.la | ||
181 | test_gns_max_queries_DEPENDENCIES = \ | ||
182 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
183 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
184 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
185 | $(top_builddir)/src/testing/libgnunettesting.la | ||
186 | |||
172 | gnunet_gns_SOURCES = \ | 187 | gnunet_gns_SOURCES = \ |
173 | gnunet-gns.c | 188 | gnunet-gns.c |
174 | gnunet_gns_LDADD = \ | 189 | gnunet_gns_LDADD = \ |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 37d53bfd3..dff300bb7 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -20,10 +20,6 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * | 22 | * |
23 | * TODO: | ||
24 | * - Write xquery and block plugin | ||
25 | * - The smaller FIXME issues all around | ||
26 | * | ||
27 | * @file gns/gnunet-service-gns.c | 23 | * @file gns/gnunet-service-gns.c |
28 | * @brief GNUnet GNS service | 24 | * @brief GNUnet GNS service |
29 | * @author Martin Schanzenbach | 25 | * @author Martin Schanzenbach |
@@ -155,6 +151,9 @@ GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; | |||
155 | /* automatic pkey import for name shortening */ | 151 | /* automatic pkey import for name shortening */ |
156 | static int auto_import_pkey; | 152 | static int auto_import_pkey; |
157 | 153 | ||
154 | /* lookup timeout */ | ||
155 | static struct GNUNET_TIME_Relative default_lookup_timeout; | ||
156 | |||
158 | /** | 157 | /** |
159 | * Task run during shutdown. | 158 | * Task run during shutdown. |
160 | * | 159 | * |
@@ -174,6 +173,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
174 | GNUNET_SERVER_notification_context_destroy (nc); | 173 | GNUNET_SERVER_notification_context_destroy (nc); |
175 | 174 | ||
176 | gns_interceptor_stop(); | 175 | gns_interceptor_stop(); |
176 | gns_resolver_cleanup(); | ||
177 | 177 | ||
178 | GNUNET_NAMESTORE_disconnect(namestore_handle, 1); | 178 | GNUNET_NAMESTORE_disconnect(namestore_handle, 1); |
179 | GNUNET_DHT_disconnect(dht_handle); | 179 | GNUNET_DHT_disconnect(dht_handle); |
@@ -723,14 +723,14 @@ handle_lookup(void *cls, | |||
723 | { | 723 | { |
724 | gns_resolver_lookup_record(zone_hash, clh->type, name, | 724 | gns_resolver_lookup_record(zone_hash, clh->type, name, |
725 | zone_key, | 725 | zone_key, |
726 | GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT, | 726 | default_lookup_timeout, |
727 | &send_lookup_response, clh); | 727 | &send_lookup_response, clh); |
728 | } | 728 | } |
729 | else | 729 | else |
730 | { | 730 | { |
731 | gns_resolver_lookup_record(zone_hash, clh->type, name, | 731 | gns_resolver_lookup_record(zone_hash, clh->type, name, |
732 | NULL, | 732 | NULL, |
733 | GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT, | 733 | default_lookup_timeout, |
734 | &send_lookup_response, clh); | 734 | &send_lookup_response, clh); |
735 | } | 735 | } |
736 | } | 736 | } |
@@ -753,6 +753,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
753 | 753 | ||
754 | char* keyfile; | 754 | char* keyfile; |
755 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | 755 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; |
756 | unsigned long long max_parallel_bg_queries = 0; | ||
757 | unsigned long long default_lookup_timeout_secs = 0; | ||
756 | 758 | ||
757 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 759 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
758 | {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0}, | 760 | {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0}, |
@@ -813,8 +815,31 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
813 | auto_import_pkey = GNUNET_YES; | 815 | auto_import_pkey = GNUNET_YES; |
814 | 816 | ||
815 | } | 817 | } |
818 | |||
819 | if (GNUNET_OK == | ||
820 | GNUNET_CONFIGURATION_get_value_number(c, "gns", | ||
821 | "MAX_PARALLEL_BACKGROUND_QUERIES", | ||
822 | &max_parallel_bg_queries)) | ||
823 | { | ||
824 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
825 | "Number of allowed parallel background queries: %d\n", | ||
826 | max_parallel_bg_queries); | ||
827 | } | ||
828 | |||
829 | if (GNUNET_OK == | ||
830 | GNUNET_CONFIGURATION_get_value_number(c, "gns", | ||
831 | "DEFAULT_LOOKUP_TIMEOUT", | ||
832 | &default_lookup_timeout_secs)) | ||
833 | { | ||
834 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
835 | "Default lookup timeout: %ds\n", default_lookup_timeout_secs); | ||
836 | default_lookup_timeout = GNUNET_TIME_relative_multiply( | ||
837 | GNUNET_TIME_UNIT_SECONDS, | ||
838 | default_lookup_timeout_secs); | ||
839 | } | ||
816 | 840 | ||
817 | if (gns_resolver_init(namestore_handle, dht_handle) | 841 | if (gns_resolver_init(namestore_handle, dht_handle, zone_hash, |
842 | max_parallel_bg_queries) | ||
818 | == GNUNET_SYSERR) | 843 | == GNUNET_SYSERR) |
819 | { | 844 | { |
820 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 845 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index ed2f8797c..4e074577f 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -60,6 +60,16 @@ static struct GNUNET_DHT_Handle *dht_handle; | |||
60 | static struct GNUNET_CONTAINER_Heap *dht_lookup_heap; | 60 | static struct GNUNET_CONTAINER_Heap *dht_lookup_heap; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Maximum amount of parallel queries in background | ||
64 | */ | ||
65 | static unsigned long long max_allowed_background_queries; | ||
66 | |||
67 | /** | ||
68 | * Our local zone | ||
69 | */ | ||
70 | static struct GNUNET_CRYPTO_ShortHashCode local_zone; | ||
71 | |||
72 | /** | ||
63 | * Namestore calls this function if we have record for this name. | 73 | * Namestore calls this function if we have record for this name. |
64 | * (or with rd_count=0 to indicate no matches) | 74 | * (or with rd_count=0 to indicate no matches) |
65 | * | 75 | * |
@@ -321,7 +331,7 @@ process_zone_to_name_discover(void *cls, | |||
321 | xquery = htonl(GNUNET_GNS_RECORD_PSEU); | 331 | xquery = htonl(GNUNET_GNS_RECORD_PSEU); |
322 | 332 | ||
323 | gph->get_handle = GNUNET_DHT_get_start(dht_handle, | 333 | gph->get_handle = GNUNET_DHT_get_start(dht_handle, |
324 | DHT_OPERATION_TIMEOUT, | 334 | GNUNET_TIME_UNIT_FOREVER_REL, |
325 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 335 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
326 | &lookup_key, | 336 | &lookup_key, |
327 | DHT_GNS_REPLICATION_LEVEL, | 337 | DHT_GNS_REPLICATION_LEVEL, |
@@ -378,12 +388,17 @@ static void process_discovered_authority(char* name, | |||
378 | */ | 388 | */ |
379 | int | 389 | int |
380 | gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, | 390 | gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, |
381 | struct GNUNET_DHT_Handle *dh) | 391 | struct GNUNET_DHT_Handle *dh, |
392 | struct GNUNET_CRYPTO_ShortHashCode lz, | ||
393 | unsigned long long max_bg_queries) | ||
382 | { | 394 | { |
383 | namestore_handle = nh; | 395 | namestore_handle = nh; |
384 | dht_handle = dh; | 396 | dht_handle = dh; |
397 | local_zone = lz; | ||
385 | dht_lookup_heap = | 398 | dht_lookup_heap = |
386 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 399 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); |
400 | max_allowed_background_queries = max_bg_queries; | ||
401 | |||
387 | if ((namestore_handle != NULL) && (dht_handle != NULL)) | 402 | if ((namestore_handle != NULL) && (dht_handle != NULL)) |
388 | { | 403 | { |
389 | return GNUNET_OK; | 404 | return GNUNET_OK; |
@@ -391,6 +406,41 @@ gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, | |||
391 | return GNUNET_SYSERR; | 406 | return GNUNET_SYSERR; |
392 | } | 407 | } |
393 | 408 | ||
409 | /** | ||
410 | * Cleanup background lookups | ||
411 | */ | ||
412 | static int | ||
413 | cleanup_pending_background_queries(void* cls, | ||
414 | struct GNUNET_CONTAINER_HeapNode *node, | ||
415 | void *element, | ||
416 | GNUNET_CONTAINER_HeapCostType cost) | ||
417 | { | ||
418 | struct ResolverHandle *rh = (struct ResolverHandle *)element; | ||
419 | |||
420 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
421 | "Terminating background lookup for %s\n", | ||
422 | rh->name); | ||
423 | GNUNET_DHT_get_stop(rh->get_handle); | ||
424 | rh->proc(rh->proc_cls, rh, 0, NULL); | ||
425 | |||
426 | return GNUNET_YES; | ||
427 | } | ||
428 | |||
429 | |||
430 | /** | ||
431 | * Shutdown resolver | ||
432 | */ | ||
433 | void | ||
434 | gns_resolver_cleanup() | ||
435 | { | ||
436 | if (0 != GNUNET_CONTAINER_heap_get_size(dht_lookup_heap)) | ||
437 | { | ||
438 | GNUNET_CONTAINER_heap_iterate (dht_lookup_heap, | ||
439 | &cleanup_pending_background_queries, | ||
440 | NULL); | ||
441 | } | ||
442 | } | ||
443 | |||
394 | 444 | ||
395 | /** | 445 | /** |
396 | * Helper function to free resolver handle | 446 | * Helper function to free resolver handle |
@@ -446,6 +496,14 @@ on_namestore_record_put_result(void *cls, | |||
446 | "Error putting records into namestore: %s\n", emsg); | 496 | "Error putting records into namestore: %s\n", emsg); |
447 | } | 497 | } |
448 | 498 | ||
499 | static void | ||
500 | handle_lookup_timeout(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
501 | { | ||
502 | struct ResolverHandle *rh = cls; | ||
503 | |||
504 | if (rh->timeout_cont) | ||
505 | rh->timeout_cont(rh->timeout_cont_cls, tc); | ||
506 | } | ||
449 | 507 | ||
450 | /** | 508 | /** |
451 | * Processor for background lookups in the DHT | 509 | * Processor for background lookups in the DHT |
@@ -486,6 +544,10 @@ dht_lookup_timeout(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
486 | strcpy(new_name, rh->name); | 544 | strcpy(new_name, rh->name); |
487 | memcpy(new_name+strlen(new_name), GNUNET_GNS_TLD, strlen(GNUNET_GNS_TLD)); | 545 | memcpy(new_name+strlen(new_name), GNUNET_GNS_TLD, strlen(GNUNET_GNS_TLD)); |
488 | 546 | ||
547 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
548 | "Starting background lookup for %s type %d\n", | ||
549 | new_name, rlh->record_type); | ||
550 | |||
489 | gns_resolver_lookup_record(rh->authority, | 551 | gns_resolver_lookup_record(rh->authority, |
490 | rlh->record_type, | 552 | rlh->record_type, |
491 | new_name, | 553 | new_name, |
@@ -649,11 +711,27 @@ resolve_record_dht(struct ResolverHandle *rh) | |||
649 | "starting dht lookup for %s with key: %s\n", | 711 | "starting dht lookup for %s with key: %s\n", |
650 | rh->name, (char*)&lookup_key_string); | 712 | rh->name, (char*)&lookup_key_string); |
651 | 713 | ||
652 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 714 | //rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
653 | rh->dht_heap_node = NULL; | 715 | rh->dht_heap_node = NULL; |
654 | 716 | ||
655 | if (rh->timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 717 | if (rh->timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) |
656 | { | 718 | { |
719 | /** | ||
720 | * Update timeout if necessary | ||
721 | */ | ||
722 | if (rh->timeout_task == GNUNET_SCHEDULER_NO_TASK) | ||
723 | { | ||
724 | |||
725 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
726 | "Adjusting timeout\n"); | ||
727 | /* | ||
728 | * Set timeout for authority lookup phase to 1/2 | ||
729 | */ | ||
730 | rh->timeout_task = GNUNET_SCHEDULER_add_delayed( | ||
731 | GNUNET_TIME_relative_divide(rh->timeout, 2), | ||
732 | &handle_lookup_timeout, | ||
733 | rh); | ||
734 | } | ||
657 | //rh->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT, | 735 | //rh->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT, |
658 | // &dht_lookup_timeout, | 736 | // &dht_lookup_timeout, |
659 | // rh); | 737 | // rh); |
@@ -662,7 +740,7 @@ resolve_record_dht(struct ResolverHandle *rh) | |||
662 | } | 740 | } |
663 | else | 741 | else |
664 | { | 742 | { |
665 | if (GNUNET_GNS_MAX_PARALLEL_LOOKUPS > | 743 | if (max_allowed_background_queries <= |
666 | GNUNET_CONTAINER_heap_get_size (dht_lookup_heap)) | 744 | GNUNET_CONTAINER_heap_get_size (dht_lookup_heap)) |
667 | { | 745 | { |
668 | rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap); | 746 | rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap); |
@@ -680,7 +758,7 @@ resolve_record_dht(struct ResolverHandle *rh) | |||
680 | 758 | ||
681 | xquery = htonl(rlh->record_type); | 759 | xquery = htonl(rlh->record_type); |
682 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, | 760 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, |
683 | DHT_OPERATION_TIMEOUT, | 761 | GNUNET_TIME_UNIT_FOREVER_REL, |
684 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 762 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
685 | &lookup_key, | 763 | &lookup_key, |
686 | DHT_GNS_REPLICATION_LEVEL, | 764 | DHT_GNS_REPLICATION_LEVEL, |
@@ -827,14 +905,7 @@ resolve_record_ns(struct ResolverHandle *rh) | |||
827 | rh); | 905 | rh); |
828 | } | 906 | } |
829 | 907 | ||
830 | static void | ||
831 | handle_lookup_timeout(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
832 | { | ||
833 | struct ResolverHandle *rh = cls; | ||
834 | 908 | ||
835 | if (rh->timeout_cont) | ||
836 | rh->timeout_cont(rh->timeout_cont_cls, tc); | ||
837 | } | ||
838 | 909 | ||
839 | /** | 910 | /** |
840 | * Handle timeout for DHT requests | 911 | * Handle timeout for DHT requests |
@@ -854,6 +925,8 @@ dht_authority_lookup_timeout(void *cls, | |||
854 | "dht lookup for query %s timed out.\n", | 925 | "dht lookup for query %s timed out.\n", |
855 | rh->name); | 926 | rh->name); |
856 | 927 | ||
928 | rh->status |= TIMED_OUT; | ||
929 | |||
857 | 930 | ||
858 | if (strcmp(rh->name, "") == 0) | 931 | if (strcmp(rh->name, "") == 0) |
859 | { | 932 | { |
@@ -868,11 +941,15 @@ dht_authority_lookup_timeout(void *cls, | |||
868 | /** | 941 | /** |
869 | * Start resolution in bg | 942 | * Start resolution in bg |
870 | */ | 943 | */ |
871 | strcpy(new_name, rh->name); | 944 | GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, |
872 | strcpy(new_name+strlen(new_name), "."); | 945 | "%s.%s", rh->name, GNUNET_GNS_TLD); |
873 | memcpy(new_name+strlen(new_name), rh->authority_name, | 946 | //strcpy(new_name, rh->name); |
874 | strlen(rh->authority_name)); | 947 | //strcpy(new_name+strlen(new_name), "."); |
875 | memcpy(new_name+strlen(new_name), GNUNET_GNS_TLD, strlen(GNUNET_GNS_TLD)); | 948 | //memcpy(new_name+strlen(new_name), GNUNET_GNS_TLD, strlen(GNUNET_GNS_TLD)); |
949 | |||
950 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
951 | "Starting background query for %s type %d\n", | ||
952 | new_name, rlh->record_type); | ||
876 | 953 | ||
877 | gns_resolver_lookup_record(rh->authority, | 954 | gns_resolver_lookup_record(rh->authority, |
878 | rlh->record_type, | 955 | rlh->record_type, |
@@ -882,8 +959,16 @@ dht_authority_lookup_timeout(void *cls, | |||
882 | &background_lookup_result_processor, | 959 | &background_lookup_result_processor, |
883 | NULL); | 960 | NULL); |
884 | 961 | ||
962 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
963 | "Terminating auth lookup\n"); | ||
964 | |||
885 | GNUNET_DHT_get_stop (rh->get_handle); | 965 | GNUNET_DHT_get_stop (rh->get_handle); |
886 | 966 | ||
967 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
968 | |||
969 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
970 | "Terminating auth lookup\n"); | ||
971 | |||
887 | rh->proc(rh->proc_cls, rh, 0, NULL); | 972 | rh->proc(rh->proc_cls, rh, 0, NULL); |
888 | } | 973 | } |
889 | 974 | ||
@@ -1228,10 +1313,12 @@ handle_record_ns(void* cls, struct ResolverHandle *rh, | |||
1228 | rlh = (struct RecordLookupHandle*) cls; | 1313 | rlh = (struct RecordLookupHandle*) cls; |
1229 | if (rd_count == 0) | 1314 | if (rd_count == 0) |
1230 | { | 1315 | { |
1316 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Resolution status: %d!\n", rh->status); | ||
1317 | |||
1231 | /* ns entry expired and not ours. try dht */ | 1318 | /* ns entry expired and not ours. try dht */ |
1232 | if (rh->status & (EXPIRED | !EXISTS) && | 1319 | if (rh->status & (EXPIRED | !EXISTS) && |
1233 | GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, | 1320 | GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, |
1234 | &rh->authority_chain_tail->zone)) | 1321 | &local_zone)) |
1235 | { | 1322 | { |
1236 | rh->proc = &handle_record_dht; | 1323 | rh->proc = &handle_record_dht; |
1237 | resolve_record_dht(rh); | 1324 | resolve_record_dht(rh); |
@@ -1353,6 +1440,8 @@ handle_delegation_dht(void* cls, struct ResolverHandle *rh, | |||
1353 | struct RecordLookupHandle* rlh; | 1440 | struct RecordLookupHandle* rlh; |
1354 | rlh = (struct RecordLookupHandle*) cls; | 1441 | rlh = (struct RecordLookupHandle*) cls; |
1355 | 1442 | ||
1443 | |||
1444 | |||
1356 | if (strcmp(rh->name, "") == 0) | 1445 | if (strcmp(rh->name, "") == 0) |
1357 | { | 1446 | { |
1358 | if ((rlh->record_type == GNUNET_GNS_RECORD_PKEY)) | 1447 | if ((rlh->record_type == GNUNET_GNS_RECORD_PKEY)) |
@@ -1427,7 +1516,7 @@ resolve_delegation_dht(struct ResolverHandle *rh) | |||
1427 | } | 1516 | } |
1428 | else | 1517 | else |
1429 | { | 1518 | { |
1430 | if (GNUNET_GNS_MAX_PARALLEL_LOOKUPS > | 1519 | if (max_allowed_background_queries <= |
1431 | GNUNET_CONTAINER_heap_get_size (dht_lookup_heap)) | 1520 | GNUNET_CONTAINER_heap_get_size (dht_lookup_heap)) |
1432 | { | 1521 | { |
1433 | /* terminate oldest lookup */ | 1522 | /* terminate oldest lookup */ |
@@ -1447,7 +1536,7 @@ resolve_delegation_dht(struct ResolverHandle *rh) | |||
1447 | xquery = htonl(GNUNET_GNS_RECORD_PKEY); | 1536 | xquery = htonl(GNUNET_GNS_RECORD_PKEY); |
1448 | 1537 | ||
1449 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, | 1538 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, |
1450 | DHT_OPERATION_TIMEOUT, | 1539 | GNUNET_TIME_UNIT_FOREVER_REL, |
1451 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 1540 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
1452 | &lookup_key, | 1541 | &lookup_key, |
1453 | DHT_GNS_REPLICATION_LEVEL, | 1542 | DHT_GNS_REPLICATION_LEVEL, |
@@ -1610,11 +1699,13 @@ process_delegation_result_ns(void* cls, | |||
1610 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1699 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1611 | "Adding %s back to %s\n", | 1700 | "Adding %s back to %s\n", |
1612 | rh->authority_name, rh->name); | 1701 | rh->authority_name, rh->name); |
1613 | memset(new_name, 0, strlen(rh->name) + strlen(rh->authority_name) + 2); | 1702 | //memset(new_name, 0, strlen(rh->name) + strlen(rh->authority_name) + 2); |
1614 | strcpy(new_name, rh->name); | 1703 | strcpy(new_name, rh->name); |
1615 | strcpy(new_name+strlen(new_name)+1, "."); | 1704 | strcpy(new_name+strlen(new_name), "."); |
1616 | strcpy(new_name+strlen(new_name)+2, rh->authority_name); | 1705 | strcpy(new_name+strlen(new_name), rh->authority_name); |
1617 | strcpy(rh->name, new_name); | 1706 | strcpy(rh->name, new_name); |
1707 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1708 | "%s restored\n", rh->name); | ||
1618 | } | 1709 | } |
1619 | rh->proc(rh->proc_cls, rh, 0, NULL); | 1710 | rh->proc(rh->proc_cls, rh, 0, NULL); |
1620 | return; | 1711 | return; |
@@ -1747,14 +1838,19 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, | |||
1747 | rh->timeout = timeout; | 1838 | rh->timeout = timeout; |
1748 | if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 1839 | if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) |
1749 | { | 1840 | { |
1750 | rh->timeout_task = GNUNET_SCHEDULER_add_delayed(timeout, | 1841 | /* |
1842 | * Set timeout for authority lookup phase to 1/2 | ||
1843 | */ | ||
1844 | rh->timeout_task = GNUNET_SCHEDULER_add_delayed( | ||
1845 | GNUNET_TIME_relative_divide(timeout, 2), | ||
1751 | &handle_lookup_timeout, | 1846 | &handle_lookup_timeout, |
1752 | rh); | 1847 | rh); |
1753 | rh->timeout_cont = &handle_auth_discovery_timeout; | 1848 | rh->timeout_cont = &dht_authority_lookup_timeout; |
1754 | rh->timeout_cont_cls = rh; | 1849 | rh->timeout_cont_cls = rh; |
1755 | } | 1850 | } |
1756 | else | 1851 | else |
1757 | { | 1852 | { |
1853 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No timeout for query!\n"); | ||
1758 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1854 | rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1759 | } | 1855 | } |
1760 | 1856 | ||
@@ -1891,7 +1987,7 @@ process_zone_to_name_shorten(void *cls, | |||
1891 | free_resolver_handle(rh); | 1987 | free_resolver_handle(rh); |
1892 | } | 1988 | } |
1893 | else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, | 1989 | else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, |
1894 | &rh->authority_chain_tail->zone)) | 1990 | &local_zone)) |
1895 | { | 1991 | { |
1896 | /* our zone, just append .gnunet */ | 1992 | /* our zone, just append .gnunet */ |
1897 | answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2; | 1993 | answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2; |
@@ -1967,7 +2063,7 @@ handle_delegation_ns_shorten(void* cls, | |||
1967 | "PKEY resolved as far as possible in ns up to %s!\n", rh->name); | 2063 | "PKEY resolved as far as possible in ns up to %s!\n", rh->name); |
1968 | 2064 | ||
1969 | if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, | 2065 | if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, |
1970 | &rh->authority_chain_tail->zone) == 0) | 2066 | &local_zone) == 0) |
1971 | { | 2067 | { |
1972 | /** | 2068 | /** |
1973 | * This is our zone append .gnunet unless name is empty | 2069 | * This is our zone append .gnunet unless name is empty |
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index e973b0c52..073c19192 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h | |||
@@ -88,7 +88,8 @@ typedef void (*ResolutionResultProcessor) (void *cls, | |||
88 | enum ResolutionStatus | 88 | enum ResolutionStatus |
89 | { | 89 | { |
90 | EXISTS = 1, | 90 | EXISTS = 1, |
91 | EXPIRED = 2 | 91 | EXPIRED = 2, |
92 | TIMED_OUT = 4 | ||
92 | }; | 93 | }; |
93 | 94 | ||
94 | /** | 95 | /** |
@@ -244,11 +245,21 @@ struct GetPseuAuthorityHandle | |||
244 | * | 245 | * |
245 | * @param nh handle to the namestore | 246 | * @param nh handle to the namestore |
246 | * @param dh handle to the dht | 247 | * @param dh handle to the dht |
248 | * @param local_zone the local zone | ||
249 | * @param max_bg_queries maximum amount of background queries | ||
247 | * @returns GNUNET_OK on success | 250 | * @returns GNUNET_OK on success |
248 | */ | 251 | */ |
249 | int | 252 | int |
250 | gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, | 253 | gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, |
251 | struct GNUNET_DHT_Handle *dh); | 254 | struct GNUNET_DHT_Handle *dh, |
255 | struct GNUNET_CRYPTO_ShortHashCode local_zone, | ||
256 | unsigned long long max_bg_queries); | ||
257 | |||
258 | /** | ||
259 | * Cleanup resolver: Terminate pending lookups | ||
260 | */ | ||
261 | void | ||
262 | gns_resolver_cleanup(void); | ||
252 | 263 | ||
253 | /** | 264 | /** |
254 | * Lookup of a record in a specific zone | 265 | * Lookup of a record in a specific zone |
diff --git a/src/gns/test_gns_simple_lookup.c b/src/gns/test_gns_simple_lookup.c index e93de1a66..9cfde438d 100644 --- a/src/gns/test_gns_simple_lookup.c +++ b/src/gns/test_gns_simple_lookup.c | |||
@@ -18,23 +18,9 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gns/test_gns_twopeer.c | 21 | * @file gns/test_gns_simple_lookup.c |
22 | * @brief base testcase for testing DHT service with | 22 | * @brief base testcase for testing a local GNS record lookup |
23 | * two running peers. | ||
24 | * | 23 | * |
25 | * This testcase starts peers using the GNUNET_TESTING_daemons_start | ||
26 | * function call. On peer start, connects to the peers DHT service | ||
27 | * by calling GNUNET_DHT_connected. Once notified about all peers | ||
28 | * being started (by the peers_started_callback function), calls | ||
29 | * GNUNET_TESTING_connect_topology, which connects the peers in a | ||
30 | * "straight line" topology. On notification that all peers have | ||
31 | * been properly connected, calls the do_get function which initiates | ||
32 | * a GNUNET_DHT_get from the *second* peer. Once the GNUNET_DHT_get | ||
33 | * function starts, runs the do_put function to insert data at the first peer. | ||
34 | * If the GET is successful, schedules finish_testing | ||
35 | * to stop the test and shut down peers. If GET is unsuccessful | ||
36 | * after GET_TIMEOUT seconds, prints an error message and shuts down | ||
37 | * the peers. | ||
38 | */ | 24 | */ |
39 | #include "platform.h" | 25 | #include "platform.h" |
40 | #include "gnunet_testing_lib.h" | 26 | #include "gnunet_testing_lib.h" |
diff --git a/src/gns/test_gns_simple_lookup.conf b/src/gns/test_gns_simple_lookup.conf index bdb233b3d..c2fede933 100644 --- a/src/gns/test_gns_simple_lookup.conf +++ b/src/gns/test_gns_simple_lookup.conf | |||
@@ -80,7 +80,8 @@ UNIXPATH = /tmp/gnunet-service-gns.sock | |||
80 | HOME = $SERVICEHOME | 80 | HOME = $SERVICEHOME |
81 | CONFIG = $DEFAULTCONFIG | 81 | CONFIG = $DEFAULTCONFIG |
82 | AUTO_IMPORT_PKEY = YES | 82 | AUTO_IMPORT_PKEY = YES |
83 | 83 | MAX_PARALLEL_BACKGROUND_QUERIES = 10 | |
84 | DEFAULT_LOOKUP_TIMEOUT = 5 | ||
84 | 85 | ||
85 | [nse] | 86 | [nse] |
86 | AUTOSTART = NO | 87 | AUTOSTART = NO |