diff options
Diffstat (limited to 'src/gns/gnunet-service-gns_resolver.c')
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 150 |
1 files changed, 123 insertions, 27 deletions
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 |