aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-07-22 18:58:13 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-07-22 18:58:13 +0000
commita11257cec68de795db5bcd1e30d47685c13d6a5f (patch)
treed3660227da7a5048a3336f0d27a3ebd7b3c28f4c
parent8ee0404fc1a3ef3fc75ba3b558f46f90dded4cfa (diff)
downloadgnunet-a11257cec68de795db5bcd1e30d47685c13d6a5f.tar.gz
gnunet-a11257cec68de795db5bcd1e30d47685c13d6a5f.zip
- add check to test, code cleanup
-rw-r--r--src/gns/gnunet-gns-proxy.c22
-rw-r--r--src/gns/gnunet-service-gns_resolver.c558
-rw-r--r--src/gns/test_gns_proxy.c6
3 files changed, 276 insertions, 310 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 4681c9d2e..44fef89c2 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -1416,7 +1416,6 @@ curl_download_prepare ()
1416 } 1416 }
1417 GNUNET_NETWORK_fdset_destroy (gws); 1417 GNUNET_NETWORK_fdset_destroy (gws);
1418 GNUNET_NETWORK_fdset_destroy (grs); 1418 GNUNET_NETWORK_fdset_destroy (grs);
1419
1420} 1419}
1421 1420
1422 1421
@@ -1790,7 +1789,8 @@ create_response (void *cls,
1790 //FIXME handle 1789 //FIXME handle
1791 if ((0 != strcasecmp (meth, MHD_HTTP_METHOD_GET)) && 1790 if ((0 != strcasecmp (meth, MHD_HTTP_METHOD_GET)) &&
1792 (0 != strcasecmp (meth, MHD_HTTP_METHOD_PUT)) && 1791 (0 != strcasecmp (meth, MHD_HTTP_METHOD_PUT)) &&
1793 (0 != strcasecmp (meth, MHD_HTTP_METHOD_POST))) 1792 (0 != strcasecmp (meth, MHD_HTTP_METHOD_POST)) &&
1793 (0 != strcasecmp (meth, MHD_HTTP_METHOD_HEAD)))
1794 { 1794 {
1795 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1795 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1796 "MHD: %s NOT IMPLEMENTED!\n", meth); 1796 "MHD: %s NOT IMPLEMENTED!\n", meth);
@@ -1839,6 +1839,7 @@ create_response (void *cls,
1839 1839
1840 if (0 == strcasecmp (meth, MHD_HTTP_METHOD_PUT)) 1840 if (0 == strcasecmp (meth, MHD_HTTP_METHOD_PUT))
1841 { 1841 {
1842 //FIXME: this prolly works like POST?
1842 if (0 == *upload_data_size) 1843 if (0 == *upload_data_size)
1843 { 1844 {
1844 curl_easy_cleanup (ctask->curl); 1845 curl_easy_cleanup (ctask->curl);
@@ -1860,6 +1861,7 @@ create_response (void *cls,
1860 1861
1861 if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST)) 1862 if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST))
1862 { 1863 {
1864 //FIXME handle multipart
1863 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1865 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1864 "Setting up POST processor\n"); 1866 "Setting up POST processor\n");
1865 ctask->post_handler = MHD_create_post_processor (con, 1867 ctask->post_handler = MHD_create_post_processor (con,
@@ -1872,15 +1874,13 @@ create_response (void *cls,
1872 curl_easy_setopt (ctask->curl, CURLOPT_READDATA, ctask); 1874 curl_easy_setopt (ctask->curl, CURLOPT_READDATA, ctask);
1873 ctask->headers = curl_slist_append (ctask->headers, 1875 ctask->headers = curl_slist_append (ctask->headers,
1874 "Transfer-Encoding: chunked"); 1876 "Transfer-Encoding: chunked");
1875 /*curl_easy_setopt (ctask->curl, CURLOPT_POST, 1); 1877 }
1876 curl_easy_setopt (ctask->curl, CURLOPT_POSTFIELDSIZE, *upload_data_size); 1878
1877 curl_easy_setopt (ctask->curl, CURLOPT_COPYPOSTFIELDS, upload_data); 1879 if (0 == strcasecmp (meth, MHD_HTTP_METHOD_HEAD))
1878 1880 {
1879 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1880 "Got POST data: %s\n", upload_data); 1882 "Setting NOBODY\n");
1881 curl_easy_cleanup (ctask->curl); 1883 curl_easy_setopt (ctask->curl, CURLOPT_NOBODY, 1);
1882 GNUNET_free (ctask);
1883 return MHD_NO;*/
1884 } 1884 }
1885 1885
1886 curl_easy_setopt (ctask->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr); 1886 curl_easy_setopt (ctask->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr);
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 67040840d..80a2785b8 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -369,9 +369,10 @@ process_auth_discovery_dht_result (void* cls,
369 const struct GNUNET_PeerIdentity *put_path, 369 const struct GNUNET_PeerIdentity *put_path,
370 unsigned int put_path_length, 370 unsigned int put_path_length,
371 enum GNUNET_BLOCK_Type type, 371 enum GNUNET_BLOCK_Type type,
372 size_t size, const void *data) 372 size_t size,
373 const void *data)
373{ 374{
374 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; 375 struct GetPseuAuthorityHandle* gph = cls;
375 struct GNSNameRecordBlock *nrb; 376 struct GNSNameRecordBlock *nrb;
376 char* rd_data = (char*)data; 377 char* rd_data = (char*)data;
377 char* name; 378 char* name;
@@ -454,18 +455,18 @@ process_auth_discovery_ns_result (void* cls,
454 const struct GNUNET_NAMESTORE_RecordData *rd, 455 const struct GNUNET_NAMESTORE_RecordData *rd,
455 const struct GNUNET_CRYPTO_RsaSignature *signature) 456 const struct GNUNET_CRYPTO_RsaSignature *signature)
456{ 457{
457 uint32_t xquery; 458 struct GetPseuAuthorityHandle* gph = cls;
458 struct GNUNET_CRYPTO_ShortHashCode name_hash; 459 struct GNUNET_CRYPTO_ShortHashCode name_hash;
459 struct GNUNET_HashCode lookup_key; 460 struct GNUNET_HashCode lookup_key;
460 struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; 461 struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string;
461 struct GNUNET_HashCode name_hash_double; 462 struct GNUNET_HashCode name_hash_double;
462 struct GNUNET_HashCode zone_hash_double; 463 struct GNUNET_HashCode zone_hash_double;
463 int i; 464 int i;
464 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; 465 uint32_t xquery;
465 466
466 gph->namestore_task = NULL; 467 gph->namestore_task = NULL;
467 /* no pseu found */ 468 /* no pseu found */
468 if (rd_count == 0) 469 if (0 == rd_count)
469 { 470 {
470 /** 471 /**
471 * check dht 472 * check dht
@@ -501,13 +502,15 @@ process_auth_discovery_ns_result (void* cls,
501 502
502 for (i=0; i < rd_count; i++) 503 for (i=0; i < rd_count; i++)
503 { 504 {
504 if ((strcmp (name, "+") == 0) && 505 if (0 != (strcmp (name, "+")))
505 (rd[i].record_type == GNUNET_GNS_RECORD_PSEU)) 506 continue;
506 { 507
507 /* found pseu */ 508 if (rd[i].record_type != GNUNET_GNS_RECORD_PSEU)
508 process_pseu_result (gph, (char*)rd[i].data); 509 continue;
509 return; 510
510 } 511 /* found pseu */
512 process_pseu_result (gph, (char*)rd[i].data);
513 return;
511 } 514 }
512 515
513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS_GET_AUTH: no pseu in namestore!\n"); 516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS_GET_AUTH: no pseu in namestore!\n");
@@ -535,31 +538,26 @@ process_zone_to_name_discover (void *cls,
535 const struct GNUNET_NAMESTORE_RecordData *rd, 538 const struct GNUNET_NAMESTORE_RecordData *rd,
536 const struct GNUNET_CRYPTO_RsaSignature *signature) 539 const struct GNUNET_CRYPTO_RsaSignature *signature)
537{ 540{
538 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; 541 struct GetPseuAuthorityHandle* gph = cls;
539 542
540 gph->namestore_task = NULL; 543 gph->namestore_task = NULL;
541 /* we found a match in our own zone */ 544 if (0 == rd_len)
542 if (rd_len != 0)
543 {
544 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
545 "GNS_AUTO_PSEU: name for zone in our root %s\n", name);
546
547 GNUNET_free (gph->auth);
548 GNUNET_CRYPTO_rsa_key_free (gph->key);
549 GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph);
550 GNUNET_free (gph);
551 }
552 else
553 { 545 {
554
555 gph->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle, 546 gph->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle,
556 &gph->auth->zone, 547 &gph->auth->zone,
557 "+", 548 "+",
558 GNUNET_GNS_RECORD_PSEU, 549 GNUNET_GNS_RECORD_PSEU,
559 &process_auth_discovery_ns_result, 550 &process_auth_discovery_ns_result,
560 gph); 551 gph);
552 return;
561 } 553 }
562 554 /* we found a match in our own zone */
555 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
556 "GNS_AUTO_PSEU: name for zone in our root %s\n", name);
557 GNUNET_free (gph->auth);
558 GNUNET_CRYPTO_rsa_key_free (gph->key);
559 GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph);
560 GNUNET_free (gph);
563} 561}
564 562
565 563
@@ -588,28 +586,38 @@ static void
588start_shorten (struct AuthorityChain *auth, 586start_shorten (struct AuthorityChain *auth,
589 struct GNUNET_CRYPTO_RsaPrivateKey *key) 587 struct GNUNET_CRYPTO_RsaPrivateKey *key)
590{ 588{
591 struct AuthorityChain *acopy;
592 struct GetPseuAuthorityHandle *gph; 589 struct GetPseuAuthorityHandle *gph;
593 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; 590 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
594 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pb_key; 591 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pb_key;
595 592
596
597 acopy = GNUNET_malloc (sizeof (struct AuthorityChain));
598 memcpy (acopy, auth, sizeof (struct AuthorityChain));
599
600 gph = GNUNET_malloc (sizeof (struct GetPseuAuthorityHandle)); 593 gph = GNUNET_malloc (sizeof (struct GetPseuAuthorityHandle));
601 594
602 GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); 595 GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
603 pb_key = GNUNET_CRYPTO_rsa_encode_key (key); 596 pb_key = GNUNET_CRYPTO_rsa_encode_key (key);
597
598 if (NULL == pb_key)
599 {
600 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
601 "Failed to encode RSA key on shorten\n");
602 return;
603 }
604
605 gph = GNUNET_malloc (sizeof (struct GetPseuAuthorityHandle));
604 gph->key = GNUNET_CRYPTO_rsa_decode_key ((char*)pb_key, ntohs (pb_key->len)); 606 gph->key = GNUNET_CRYPTO_rsa_decode_key ((char*)pb_key, ntohs (pb_key->len));
605 607
608 if (NULL == gph->key)
609 {
610 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
611 "Failed to decode RSA key on shorten\n");
612 GNUNET_free (gph);
613 return;
614 }
606 GNUNET_CRYPTO_short_hash (&pkey, 615 GNUNET_CRYPTO_short_hash (&pkey,
607 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 616 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
608 &gph->our_zone); 617 &gph->our_zone);
609 gph->auth = acopy; 618 gph->auth = GNUNET_malloc (sizeof (struct AuthorityChain));
610 619 memcpy (gph->auth, auth, sizeof (struct AuthorityChain));
611 GNUNET_CONTAINER_DLL_insert (gph_head, gph_tail, gph); 620 GNUNET_CONTAINER_DLL_insert (gph_head, gph_tail, gph);
612
613 shorten_authority_chain (gph); 621 shorten_authority_chain (gph);
614} 622}
615 623
@@ -633,6 +641,11 @@ gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
633 unsigned long long max_bg_queries, 641 unsigned long long max_bg_queries,
634 int ignore_pending) 642 int ignore_pending)
635{ 643{
644 if (NULL == nh)
645 return GNUNET_SYSERR;
646 if (NULL == dh)
647 return GNUNET_SYSERR;
648
636 cfg = c; 649 cfg = c;
637 namestore_handle = nh; 650 namestore_handle = nh;
638 dht_handle = dh; 651 dht_handle = dh;
@@ -643,9 +656,7 @@ gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
643 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 656 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
644 max_allowed_background_queries = max_bg_queries; 657 max_allowed_background_queries = max_bg_queries;
645 max_allowed_ns_tasks = GNUNET_GNS_MAX_NS_TASKS; 658 max_allowed_ns_tasks = GNUNET_GNS_MAX_NS_TASKS;
646
647 ignore_pending_records = ignore_pending; 659 ignore_pending_records = ignore_pending;
648
649 gph_head = NULL; 660 gph_head = NULL;
650 gph_tail = NULL; 661 gph_tail = NULL;
651 rlh_head = NULL; 662 rlh_head = NULL;
@@ -656,14 +667,7 @@ gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
656 nah_tail = NULL; 667 nah_tail = NULL;
657 668
658 GNUNET_RESOLVER_connect (cfg); 669 GNUNET_RESOLVER_connect (cfg);
659 670 return GNUNET_OK;
660
661 if ((namestore_handle != NULL) && (dht_handle != NULL))
662 {
663 return GNUNET_OK;
664 }
665
666 return GNUNET_SYSERR;
667} 671}
668 672
669 673
@@ -682,7 +686,7 @@ cleanup_pending_ns_tasks (void* cls,
682 void *element, 686 void *element,
683 GNUNET_CONTAINER_HeapCostType cost) 687 GNUNET_CONTAINER_HeapCostType cost)
684{ 688{
685 struct NamestoreBGTask *nbg = (struct NamestoreBGTask *)element; 689 struct NamestoreBGTask *nbg = element;
686 ResolverCleanupContinuation cont = cls; 690 ResolverCleanupContinuation cont = cls;
687 691
688 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 692 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -691,7 +695,7 @@ cleanup_pending_ns_tasks (void* cls,
691 695
692 GNUNET_CONTAINER_heap_remove_node (node); 696 GNUNET_CONTAINER_heap_remove_node (node);
693 697
694 if (GNUNET_CONTAINER_heap_get_size (ns_task_heap) == 0) 698 if (0 == GNUNET_CONTAINER_heap_get_size (ns_task_heap))
695 cont (); 699 cont ();
696 700
697 return GNUNET_YES; 701 return GNUNET_YES;
@@ -714,7 +718,8 @@ finish_lookup (struct ResolverHandle *rh,
714 718
715 719
716/** 720/**
717 * Cleanup background lookups FIXME get rid of this?? 721 * Cleanup background lookups FIXME get rid of this?? YES this doesn't do
722 * anything! => find in code and remove all references to the heap
718 * 723 *
719 * @param cls closure to iterator 724 * @param cls closure to iterator
720 * @param node heap nodes 725 * @param node heap nodes
@@ -728,16 +733,14 @@ cleanup_pending_background_queries (void* cls,
728 void *element, 733 void *element,
729 GNUNET_CONTAINER_HeapCostType cost) 734 GNUNET_CONTAINER_HeapCostType cost)
730{ 735{
731 struct ResolverHandle *rh = (struct ResolverHandle *)element; 736 struct ResolverHandle *rh = element;
732 ResolverCleanupContinuation cont = cls; 737 ResolverCleanupContinuation cont = cls;
733 738
734 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 739 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
735 "GNS_CLEANUP-%llu: Terminating background lookup for %s\n", 740 "GNS_CLEANUP-%llu: Terminating background lookup for %s\n",
736 rh->id, rh->name); 741 rh->id, rh->name);
737
738 GNUNET_CONTAINER_heap_remove_node (node); 742 GNUNET_CONTAINER_heap_remove_node (node);
739 743 if (0 == GNUNET_CONTAINER_heap_get_size (dht_lookup_heap))
740 if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) == 0)
741 { 744 {
742 if (GNUNET_CONTAINER_heap_get_size (ns_task_heap) == 0) 745 if (GNUNET_CONTAINER_heap_get_size (ns_task_heap) == 0)
743 cont (); 746 cont ();
@@ -855,12 +858,10 @@ gns_resolver_cleanup (ResolverCleanupContinuation cont)
855 { 858 {
856 finish_lookup (rlh_head, rlh_head->proc_cls, 0, NULL); 859 finish_lookup (rlh_head, rlh_head->proc_cls, 0, NULL);
857 } 860 }
858
859 while (NULL != nsh_head) 861 while (NULL != nsh_head)
860 { 862 {
861 finish_shorten (nsh_head, nsh_head->proc_cls); 863 finish_shorten (nsh_head, nsh_head->proc_cls);
862 } 864 }
863
864 while (NULL != nah_head) 865 while (NULL != nah_head)
865 { 866 {
866 finish_get_auth (nah_head, nah_head->proc_cls); 867 finish_get_auth (nah_head, nah_head->proc_cls);
@@ -957,7 +958,7 @@ static void
957dht_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 958dht_lookup_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
958{ 959{
959 struct ResolverHandle *rh = cls; 960 struct ResolverHandle *rh = cls;
960 struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls; 961 struct RecordLookupHandle *rlh = rh->proc_cls;
961 char new_name[MAX_DNS_NAME_LENGTH]; 962 char new_name[MAX_DNS_NAME_LENGTH];
962 963
963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 964 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1066,6 +1067,7 @@ process_record_result_dht (void* cls,
1066 { 1067 {
1067 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1068 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1068 "GNS_PHASE_REC-%llu: Error deserializing data!\n", rh->id); 1069 "GNS_PHASE_REC-%llu: Error deserializing data!\n", rh->id);
1070 rh->proc (rh->proc_cls, rh, 0, NULL);
1069 return; 1071 return;
1070 } 1072 }
1071 1073
@@ -1124,7 +1126,7 @@ process_record_result_dht (void* cls,
1124 GNUNET_TIME_absolute_get().abs_value); 1126 GNUNET_TIME_absolute_get().abs_value);
1125 1127
1126 1128
1127 if (rh->answered) 1129 if (0 < rh->answered)
1128 rh->proc (rh->proc_cls, rh, num_records, rd); 1130 rh->proc (rh->proc_cls, rh, num_records, rd);
1129 else 1131 else
1130 rh->proc (rh->proc_cls, rh, 0, NULL); 1132 rh->proc (rh->proc_cls, rh, 0, NULL);
@@ -1148,7 +1150,7 @@ resolve_record_dht (struct ResolverHandle *rh)
1148 struct GNUNET_HashCode name_hash_double; 1150 struct GNUNET_HashCode name_hash_double;
1149 struct GNUNET_HashCode zone_hash_double; 1151 struct GNUNET_HashCode zone_hash_double;
1150 struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; 1152 struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string;
1151 struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls; 1153 struct RecordLookupHandle *rlh = rh->proc_cls;
1152 struct ResolverHandle *rh_heap_root; 1154 struct ResolverHandle *rh_heap_root;
1153 1155
1154 GNUNET_CRYPTO_short_hash (rh->name, strlen (rh->name), &name_hash); 1156 GNUNET_CRYPTO_short_hash (rh->name, strlen (rh->name), &name_hash);
@@ -1164,14 +1166,13 @@ resolve_record_dht (struct ResolverHandle *rh)
1164 //rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1166 //rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1165 rh->dht_heap_node = NULL; 1167 rh->dht_heap_node = NULL;
1166 1168
1167 if (rh->timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 1169 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != rh->timeout.rel_value)
1168 { 1170 {
1169 /** 1171 /**
1170 * Update timeout if necessary 1172 * Update timeout if necessary
1171 */ 1173 */
1172 if (rh->timeout_task == GNUNET_SCHEDULER_NO_TASK) 1174 if (GNUNET_SCHEDULER_NO_TASK == rh->timeout_task)
1173 { 1175 {
1174
1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1176 "GNS_PHASE_REC-%llu: Adjusting timeout\n", rh->id); 1177 "GNS_PHASE_REC-%llu: Adjusting timeout\n", rh->id);
1177 /* 1178 /*
@@ -1251,8 +1252,8 @@ process_record_result_ns (void* cls,
1251 struct GNUNET_TIME_Absolute et; 1252 struct GNUNET_TIME_Absolute et;
1252 unsigned int i; 1253 unsigned int i;
1253 1254
1254 rh = (struct ResolverHandle *) cls; 1255 rh = cls;
1255 rlh = (struct RecordLookupHandle *)rh->proc_cls; 1256 rlh = rh->proc_cls;
1256 1257
1257 rh->namestore_task = NULL; 1258 rh->namestore_task = NULL;
1258 GNUNET_CRYPTO_short_hash (key, 1259 GNUNET_CRYPTO_short_hash (key,
@@ -1264,7 +1265,7 @@ process_record_result_ns (void* cls,
1264 1265
1265 rh->status = 0; 1266 rh->status = 0;
1266 1267
1267 if (name != NULL) 1268 if (NULL != name)
1268 { 1269 {
1269 rh->status |= RSL_RECORD_EXISTS; 1270 rh->status |= RSL_RECORD_EXISTS;
1270 1271
@@ -1293,55 +1294,51 @@ process_record_result_ns (void* cls,
1293 return; 1294 return;
1294 1295
1295 } 1296 }
1296 else 1297 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1298 "GNS_PHASE_REC-%llu: Processing additional result %s from namestore\n",
1299 rh->id, name);
1300 for (i=0; i<rd_count;i++)
1297 { 1301 {
1298 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1302 if (rd[i].record_type != rlh->record_type)
1299 "GNS_PHASE_REC-%llu: Processing additional result %s from namestore\n", 1303 continue;
1300 rh->id, name);
1301 for (i=0; i<rd_count;i++)
1302 {
1303 if (rd[i].record_type != rlh->record_type)
1304 continue;
1305
1306 if (ignore_pending_records &&
1307 (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING))
1308 {
1309 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1310 "GNS_PHASE_REC-%llu: Record %s is awaiting user confirmation. Skipping\n",
1311 rh->id, name);
1312 continue;
1313 }
1314 1304
1315 GNUNET_break (0 == (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)); 1305 if (ignore_pending_records &&
1316 et.abs_value = rd[i].expiration_time; 1306 (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING))
1317 if ((GNUNET_TIME_absolute_get_remaining (et)).rel_value 1307 {
1318 == 0) 1308 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1319 { 1309 "GNS_PHASE_REC-%llu: Record %s is awaiting user confirmation. Skipping\n",
1320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1310 rh->id, name);
1321 "GNS_PHASE_REC-%llu: This record is expired. Skipping\n", 1311 continue;
1322 rh->id);
1323 continue;
1324 }
1325 rh->answered++;
1326 } 1312 }
1327 1313
1328 /** 1314 //FIXME: eh? do I have to handle this here?
1329 * no answers found 1315 GNUNET_break (0 == (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION));
1330 */ 1316 et.abs_value = rd[i].expiration_time;
1331 if (rh->answered == 0) 1317 if (0 == (GNUNET_TIME_absolute_get_remaining (et)).rel_value)
1332 { 1318 {
1333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1319 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1334 "GNS_PHASE_REC-%llu: No answers found. This is odd!\n", rh->id); 1320 "GNS_PHASE_REC-%llu: This record is expired. Skipping\n",
1335 rh->proc(rh->proc_cls, rh, 0, NULL); 1321 rh->id);
1336 return; 1322 continue;
1337 } 1323 }
1324 rh->answered++;
1325 }
1338 1326
1339 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1327 /**
1340 "GNS_PHASE_REC-%llu: Found %d answer(s) to query in %d records!\n", 1328 * no answers found
1341 rh->id, rh->answered, rd_count); 1329 */
1342 1330 if (0 == rh->answered)
1343 rh->proc(rh->proc_cls, rh, rd_count, rd); 1331 {
1332 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1333 "GNS_PHASE_REC-%llu: No answers found. This is odd!\n", rh->id);
1334 rh->proc(rh->proc_cls, rh, 0, NULL);
1335 return;
1344 } 1336 }
1337
1338 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1339 "GNS_PHASE_REC-%llu: Found %d answer(s) to query in %d records!\n",
1340 rh->id, rh->answered, rd_count);
1341 rh->proc(rh->proc_cls, rh, rd_count, rd);
1345} 1342}
1346 1343
1347 1344
@@ -1359,17 +1356,17 @@ process_record_result_vpn (void* cls, int af, const void *address)
1359 struct RecordLookupHandle *rlh; 1356 struct RecordLookupHandle *rlh;
1360 struct GNUNET_NAMESTORE_RecordData rd; 1357 struct GNUNET_NAMESTORE_RecordData rd;
1361 1358
1362 rlh = (struct RecordLookupHandle *)rh->proc_cls; 1359 rlh = rh->proc_cls;
1363 1360
1364 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1361 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1365 "GNS_PHASE_REC_VPN-%llu: Got answer from VPN to query!\n", 1362 "GNS_PHASE_REC_VPN-%llu: Got answer from VPN to query!\n",
1366 rh->id); 1363 rh->id);
1367 if (af == AF_INET) 1364 if (AF_INET == af)
1368 { 1365 {
1369 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1366 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1370 "GNS_PHASE_REC-%llu: Answer is IPv4!\n", 1367 "GNS_PHASE_REC-%llu: Answer is IPv4!\n",
1371 rh->id); 1368 rh->id);
1372 if (rlh->record_type != GNUNET_GNS_RECORD_A) 1369 if (GNUNET_GNS_RECORD_A != rlh->record_type)
1373 { 1370 {
1374 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1371 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1375 "GNS_PHASE_REC-%llu: Requested record is not IPv4!\n", 1372 "GNS_PHASE_REC-%llu: Requested record is not IPv4!\n",
@@ -1385,12 +1382,12 @@ process_record_result_vpn (void* cls, int af, const void *address)
1385 rh->proc (rh->proc_cls, rh, 1, &rd); 1382 rh->proc (rh->proc_cls, rh, 1, &rd);
1386 return; 1383 return;
1387 } 1384 }
1388 else if (af == AF_INET6) 1385 else if (AF_INET6 == af)
1389 { 1386 {
1390 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1387 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1391 "GNS_PHASE_REC-%llu: Answer is IPv6!\n", 1388 "GNS_PHASE_REC-%llu: Answer is IPv6!\n",
1392 rh->id); 1389 rh->id);
1393 if (rlh->record_type != GNUNET_GNS_RECORD_AAAA) 1390 if (GNUNET_GNS_RECORD_AAAA != rlh->record_type)
1394 { 1391 {
1395 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1392 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1396 "GNS_PHASE_REC-%llu: Requested record is not IPv6!\n", 1393 "GNS_PHASE_REC-%llu: Requested record is not IPv6!\n",
@@ -1429,9 +1426,9 @@ handle_record_vpn (void* cls, struct ResolverHandle *rh,
1429 unsigned int rd_count, 1426 unsigned int rd_count,
1430 const struct GNUNET_NAMESTORE_RecordData *rd) 1427 const struct GNUNET_NAMESTORE_RecordData *rd)
1431{ 1428{
1432 struct RecordLookupHandle* rlh = (struct RecordLookupHandle*) cls; 1429 struct RecordLookupHandle* rlh = cls;
1433 1430
1434 if (rd_count == 0) 1431 if (0 == rd_count)
1435 { 1432 {
1436 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1433 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1437 "GNS_PHASE_REC_VPN-%llu: VPN returned no records. (status: %d)!\n", 1434 "GNS_PHASE_REC_VPN-%llu: VPN returned no records. (status: %d)!\n",
@@ -1478,26 +1475,30 @@ handle_dns_resolver (void *cls,
1478 return; 1475 return;
1479 } 1476 }
1480 1477
1481 if (addrlen == sizeof (struct sockaddr_in)) 1478 if (sizeof (struct sockaddr_in) == addrlen)
1482 { 1479 {
1483 sai = (struct sockaddr_in*) addr; 1480 sai = (struct sockaddr_in*) addr;
1484 rd.record_type = GNUNET_GNS_RECORD_A; 1481 rd.record_type = GNUNET_GNS_RECORD_A;
1485 rd.data_size = sizeof (struct in_addr); 1482 rd.data_size = sizeof (struct in_addr);
1486 rd.data = &sai->sin_addr; 1483 rd.data = &sai->sin_addr;
1487 } 1484 }
1488 else 1485 else if (sizeof (struct sockaddr_in6) == addrlen)
1489 { 1486 {
1490 sai6 = (struct sockaddr_in6*) addr; 1487 sai6 = (struct sockaddr_in6*) addr;
1491 rd.record_type = GNUNET_GNS_RECORD_AAAA; 1488 rd.record_type = GNUNET_GNS_RECORD_AAAA;
1492 rd.data_size = sizeof (struct in6_addr); 1489 rd.data_size = sizeof (struct in6_addr);
1493 rd.data = &sai6->sin6_addr; 1490 rd.data = &sai6->sin6_addr;
1494 } 1491 }
1495 1492 else
1493 {
1494 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1495 "Address length is garbage!\n");
1496 finish_lookup (rh, rlh, 0, NULL);
1497 return;
1498 }
1496 rd.expiration_time = UINT64_MAX; /* FIXME: should probably pick something shorter */ 1499 rd.expiration_time = UINT64_MAX; /* FIXME: should probably pick something shorter */
1497 rd.flags = 0; 1500 rd.flags = 0;
1498
1499 finish_lookup (rh, rlh, 1, &rd); 1501 finish_lookup (rh, rlh, 1, &rd);
1500
1501} 1502}
1502 1503
1503/** 1504/**
@@ -1511,8 +1512,8 @@ resolve_dns_name (struct ResolverHandle *rh)
1511 struct RecordLookupHandle *rlh = rh->proc_cls; 1512 struct RecordLookupHandle *rlh = rh->proc_cls;
1512 int af; 1513 int af;
1513 1514
1514 if ((rlh->record_type != GNUNET_GNS_RECORD_A) && 1515 if ((GNUNET_GNS_RECORD_A != rlh->record_type) &&
1515 (rlh->record_type != GNUNET_GNS_RECORD_AAAA)) 1516 (GNUNET_GNS_RECORD_AAAA != rlh->record_type))
1516 { 1517 {
1517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1518 "Can only resolve A/AAAA via stub... abort\n"); 1519 "Can only resolve A/AAAA via stub... abort\n");
@@ -1520,13 +1521,11 @@ resolve_dns_name (struct ResolverHandle *rh)
1520 return; 1521 return;
1521 } 1522 }
1522 1523
1523 if (rlh->record_type == GNUNET_GNS_RECORD_A) 1524 if (GNUNET_GNS_RECORD_A == rlh->record_type)
1524 af = AF_INET; 1525 af = AF_INET;
1525 else 1526 else
1526 af = AF_INET6; 1527 af = AF_INET6;
1527 1528
1528 //GNUNET_RESOLVER_connect (cfg); FIXME into init
1529
1530 rh->dns_resolver_handle = GNUNET_RESOLVER_ip_get (rh->dns_name, 1529 rh->dns_resolver_handle = GNUNET_RESOLVER_ip_get (rh->dns_name,
1531 af, 1530 af,
1532 rh->timeout, 1531 rh->timeout,
@@ -1607,8 +1606,6 @@ read_dns_response (void *cls,
1607 ); 1606 );
1608 strcpy (rh->dns_name, packet->answers[i].data.hostname); 1607 strcpy (rh->dns_name, packet->answers[i].data.hostname);
1609 found_cname = GNUNET_YES; 1608 found_cname = GNUNET_YES;
1610 //send_dns_packet (rh);
1611 //GNUNET_DNSPARSER_free_packet (packet);
1612 continue; 1609 continue;
1613 } 1610 }
1614 1611
@@ -1668,7 +1665,7 @@ read_dns_response (void *cls,
1668 1665
1669 for (i = 0; i < packet->num_additional_records; i++) 1666 for (i = 0; i < packet->num_additional_records; i++)
1670 { 1667 {
1671 if (found_delegation == GNUNET_NO) 1668 if (GNUNET_NO == found_delegation)
1672 break; 1669 break;
1673 1670
1674 if ((packet->additional_records[i].type == GNUNET_GNS_RECORD_A) && 1671 if ((packet->additional_records[i].type == GNUNET_GNS_RECORD_A) &&
@@ -1749,14 +1746,14 @@ resolve_record_dns (struct ResolverHandle *rh,
1749 memset (&packet, 0, sizeof (struct GNUNET_DNSPARSER_Packet)); 1746 memset (&packet, 0, sizeof (struct GNUNET_DNSPARSER_Packet));
1750 1747
1751 /* We cancel here as to not include the ns lookup in the timeout */ 1748 /* We cancel here as to not include the ns lookup in the timeout */
1752 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1749 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
1753 { 1750 {
1754 GNUNET_SCHEDULER_cancel(rh->timeout_task); 1751 GNUNET_SCHEDULER_cancel(rh->timeout_task);
1755 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1752 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1756 } 1753 }
1757 /* Start shortening */ 1754 /* Start shortening */
1758 if ((rh->priv_key != NULL) && 1755 if ((NULL != rh->priv_key) &&
1759 (is_canonical (rh->name) == GNUNET_YES)) 1756 (GNUNET_YES == is_canonical (rh->name)))
1760 { 1757 {
1761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1762 "GNS_PHASE_REC_DNS-%llu: Trying to shorten authority chain\n", 1759 "GNS_PHASE_REC_DNS-%llu: Trying to shorten authority chain\n",
@@ -1768,7 +1765,7 @@ resolve_record_dns (struct ResolverHandle *rh,
1768 for (i = 0; i < rd_count; i++) 1765 for (i = 0; i < rd_count; i++)
1769 { 1766 {
1770 /* Synthesize dns name */ 1767 /* Synthesize dns name */
1771 if (rd[i].record_type == GNUNET_GNS_RECORD_NS) 1768 if (GNUNET_GNS_RECORD_NS == rd[i].record_type)
1772 { 1769 {
1773 strcpy (rh->dns_zone, (char*)rd[i].data); 1770 strcpy (rh->dns_zone, (char*)rd[i].data);
1774 if (0 == strcmp (rh->name, "")) 1771 if (0 == strcmp (rh->name, ""))
@@ -1777,7 +1774,7 @@ resolve_record_dns (struct ResolverHandle *rh,
1777 sprintf (rh->dns_name, "%s.%s", rh->name, (char*)rd[i].data); 1774 sprintf (rh->dns_name, "%s.%s", rh->name, (char*)rd[i].data);
1778 } 1775 }
1779 /* The glue */ 1776 /* The glue */
1780 if (rd[i].record_type == GNUNET_GNS_RECORD_A) 1777 if (GNUNET_GNS_RECORD_A == rd[i].record_type)
1781 dnsip = *((struct in_addr*)rd[i].data); 1778 dnsip = *((struct in_addr*)rd[i].data);
1782 } 1779 }
1783 1780
@@ -1787,7 +1784,7 @@ resolve_record_dns (struct ResolverHandle *rh,
1787 rh->dns_name, 1784 rh->dns_name,
1788 inet_ntoa (dnsip)); 1785 inet_ntoa (dnsip));
1789 rh->dns_sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); 1786 rh->dns_sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
1790 if (rh->dns_sock == NULL) 1787 if (NULL == rh->dns_sock)
1791 { 1788 {
1792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1793 "GNS_PHASE_REC_DNS-%llu: Error creating udp socket for dns!\n", 1790 "GNS_PHASE_REC_DNS-%llu: Error creating udp socket for dns!\n",
@@ -1809,8 +1806,6 @@ resolve_record_dns (struct ResolverHandle *rh,
1809 finish_lookup (rh, rlh, 0, NULL); 1806 finish_lookup (rh, rlh, 0, NULL);
1810 return; 1807 return;
1811 } 1808 }
1812
1813 /*TODO create dnsparser query, serialize, sendto, handle reply*/
1814 query.name = rh->dns_name; 1809 query.name = rh->dns_name;
1815 query.type = rlh->record_type; 1810 query.type = rlh->record_type;
1816 query.class = GNUNET_DNSPARSER_CLASS_INTERNET; 1811 query.class = GNUNET_DNSPARSER_CLASS_INTERNET;
@@ -1869,14 +1864,14 @@ resolve_record_vpn (struct ResolverHandle *rh,
1869 int af; 1864 int af;
1870 1865
1871 /* We cancel here as to not include the ns lookup in the timeout */ 1866 /* We cancel here as to not include the ns lookup in the timeout */
1872 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1867 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
1873 { 1868 {
1874 GNUNET_SCHEDULER_cancel(rh->timeout_task); 1869 GNUNET_SCHEDULER_cancel(rh->timeout_task);
1875 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1870 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1876 } 1871 }
1877 /* Start shortening */ 1872 /* Start shortening */
1878 if ((rh->priv_key != NULL) && 1873 if ((NULL != rh->priv_key) &&
1879 (is_canonical (rh->name) == GNUNET_YES)) 1874 (GNUNET_YES == is_canonical (rh->name)))
1880 { 1875 {
1881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1882 "GNS_PHASE_REC_VPN-%llu: Trying to shorten authority chain\n", 1877 "GNS_PHASE_REC_VPN-%llu: Trying to shorten authority chain\n",
@@ -1903,15 +1898,10 @@ resolve_record_vpn (struct ResolverHandle *rh,
1903 (char*)&vpn[1], 1898 (char*)&vpn[1],
1904 GNUNET_h2s (&serv_desc)); 1899 GNUNET_h2s (&serv_desc));
1905 rh->proc = &handle_record_vpn; 1900 rh->proc = &handle_record_vpn;
1906 1901 if (GNUNET_GNS_RECORD_A == rlh->record_type)
1907
1908
1909 if (rlh->record_type == GNUNET_GNS_RECORD_A)
1910 af = AF_INET; 1902 af = AF_INET;
1911 else 1903 else
1912 af = AF_INET6; 1904 af = AF_INET6;
1913
1914 //FIXME timeout??
1915 if (NULL == vpn_handle) 1905 if (NULL == vpn_handle)
1916 { 1906 {
1917 vpn_handle = GNUNET_VPN_connect (cfg); 1907 vpn_handle = GNUNET_VPN_connect (cfg);
@@ -1948,14 +1938,14 @@ resolve_record_ns(struct ResolverHandle *rh)
1948 struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls; 1938 struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls;
1949 1939
1950 /* We cancel here as to not include the ns lookup in the timeout */ 1940 /* We cancel here as to not include the ns lookup in the timeout */
1951 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1941 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
1952 { 1942 {
1953 GNUNET_SCHEDULER_cancel(rh->timeout_task); 1943 GNUNET_SCHEDULER_cancel(rh->timeout_task);
1954 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1944 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1955 } 1945 }
1956 /* Start shortening */ 1946 /* Start shortening */
1957 if ((rh->priv_key != NULL) && 1947 if ((NULL != rh->priv_key) &&
1958 (is_canonical (rh->name) == GNUNET_YES)) 1948 (GNUNET_YES == is_canonical (rh->name)))
1959 { 1949 {
1960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1961 "GNS_PHASE_REC-%llu: Trying to shorten authority chain\n", 1951 "GNS_PHASE_REC-%llu: Trying to shorten authority chain\n",
@@ -1999,14 +1989,11 @@ dht_authority_lookup_timeout(void *cls,
1999 rh->id, rh->authority_name, rh->timeout.rel_value); 1989 rh->id, rh->authority_name, rh->timeout.rel_value);
2000 1990
2001 rh->status |= RSL_TIMED_OUT; 1991 rh->status |= RSL_TIMED_OUT;
2002
2003 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1992 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2004
2005 if (NULL != rh->get_handle) 1993 if (NULL != rh->get_handle)
2006 GNUNET_DHT_get_stop (rh->get_handle); 1994 GNUNET_DHT_get_stop (rh->get_handle);
2007 1995
2008 rh->get_handle = NULL; 1996 rh->get_handle = NULL;
2009
2010 if (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) 1997 if (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)
2011 { 1998 {
2012 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1999 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -2016,7 +2003,7 @@ dht_authority_lookup_timeout(void *cls,
2016 return; 2003 return;
2017 } 2004 }
2018 2005
2019 if (strcmp(rh->name, "") == 0) 2006 if (0 == strcmp(rh->name, ""))
2020 { 2007 {
2021 /* 2008 /*
2022 * promote authority back to name and try to resolve record 2009 * promote authority back to name and try to resolve record
@@ -2029,11 +2016,8 @@ dht_authority_lookup_timeout(void *cls,
2029 /** 2016 /**
2030 * Start resolution in bg 2017 * Start resolution in bg
2031 */ 2018 */
2032 GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, 2019 GNUNET_assert (0 < GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH,
2033 "%s.%s.%s", rh->name, rh->authority_name, GNUNET_GNS_TLD); 2020 "%s.%s.%s", rh->name, rh->authority_name, GNUNET_GNS_TLD));
2034 //strcpy(new_name, rh->name);
2035 //strcpy(new_name+strlen(new_name), ".");
2036 //memcpy(new_name+strlen(new_name), GNUNET_GNS_TLD, strlen(GNUNET_GNS_TLD));
2037 2021
2038 strcpy(rh->name, new_name); 2022 strcpy(rh->name, new_name);
2039 2023
@@ -2104,7 +2088,7 @@ process_pkey_revocation_result_ns (void *cls,
2104 2088
2105 for (i = 0; i < rd_count; i++) 2089 for (i = 0; i < rd_count; i++)
2106 { 2090 {
2107 if (rd[i].record_type == GNUNET_GNS_RECORD_REV) 2091 if (GNUNET_GNS_RECORD_REV == rd[i].record_type)
2108 { 2092 {
2109 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2093 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2110 "GNS_PHASE_DELEGATE_REV-%llu: Zone has been revoked.\n", 2094 "GNS_PHASE_DELEGATE_REV-%llu: Zone has been revoked.\n",
@@ -2115,14 +2099,14 @@ process_pkey_revocation_result_ns (void *cls,
2115 } 2099 }
2116 } 2100 }
2117 2101
2118 if ((name == NULL) || 2102 if ((NULL == name) ||
2119 (remaining_time.rel_value == 0)) 2103 (0 == remaining_time.rel_value))
2120 { 2104 {
2121 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2105 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2122 "GNS_PHASE_DELEGATE_REV-%llu: + Records don't exist or are expired.\n", 2106 "GNS_PHASE_DELEGATE_REV-%llu: + Records don't exist or are expired.\n",
2123 rh->id, name); 2107 rh->id, name);
2124 2108
2125 if (rh->timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 2109 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != rh->timeout.rel_value)
2126 { 2110 {
2127 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2111 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2128 "GNS_PHASE_DELEGATE_REV-%llu: Starting background lookup for %s type %d\n", 2112 "GNS_PHASE_DELEGATE_REV-%llu: Starting background lookup for %s type %d\n",
@@ -2150,8 +2134,6 @@ process_pkey_revocation_result_ns (void *cls,
2150 rh->proc (rh->proc_cls, rh, rh->rd_count, &rh->rd); 2134 rh->proc (rh->proc_cls, rh, rh->rd_count, &rh->rd);
2151 else 2135 else
2152 resolve_delegation_ns (rh); 2136 resolve_delegation_ns (rh);
2153
2154 return;
2155} 2137}
2156 2138
2157 2139
@@ -2216,7 +2198,7 @@ process_delegation_result_dht(void* cls,
2216 enum GNUNET_BLOCK_Type type, 2198 enum GNUNET_BLOCK_Type type,
2217 size_t size, const void *data) 2199 size_t size, const void *data)
2218{ 2200{
2219 struct ResolverHandle *rh; 2201 struct ResolverHandle *rh = cls;
2220 struct GNSNameRecordBlock *nrb; 2202 struct GNSNameRecordBlock *nrb;
2221 uint32_t num_records; 2203 uint32_t num_records;
2222 char* name = NULL; 2204 char* name = NULL;
@@ -2226,8 +2208,6 @@ process_delegation_result_dht(void* cls,
2226 struct GNUNET_CRYPTO_ShortHashCode zone, name_hash; 2208 struct GNUNET_CRYPTO_ShortHashCode zone, name_hash;
2227 struct GNUNET_HashCode zone_hash_double, name_hash_double; 2209 struct GNUNET_HashCode zone_hash_double, name_hash_double;
2228 2210
2229 rh = (struct ResolverHandle *)cls;
2230
2231 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2211 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2232 "GNS_PHASE_DELEGATE_DHT-%llu: Got DHT result\n", rh->id); 2212 "GNS_PHASE_DELEGATE_DHT-%llu: Got DHT result\n", rh->id);
2233 2213
@@ -2238,9 +2218,7 @@ process_delegation_result_dht(void* cls,
2238 2218
2239 /* stop dht lookup and timeout task */ 2219 /* stop dht lookup and timeout task */
2240 GNUNET_DHT_get_stop (rh->get_handle); 2220 GNUNET_DHT_get_stop (rh->get_handle);
2241
2242 rh->get_handle = NULL; 2221 rh->get_handle = NULL;
2243
2244 if (rh->dht_heap_node != NULL) 2222 if (rh->dht_heap_node != NULL)
2245 { 2223 {
2246 GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node); 2224 GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node);
@@ -2256,7 +2234,6 @@ process_delegation_result_dht(void* cls,
2256 2234
2257 rd_data += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock); 2235 rd_data += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock);
2258 rd_size = size - strlen(name) - 1 - sizeof(struct GNSNameRecordBlock); 2236 rd_size = size - strlen(name) - 1 - sizeof(struct GNSNameRecordBlock);
2259
2260 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, 2237 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size,
2261 rd_data, 2238 rd_data,
2262 num_records, 2239 num_records,
@@ -2287,14 +2264,14 @@ process_delegation_result_dht(void* cls,
2287 "GNS_PHASE_DELEGATE_DHT-%llu: Got flag %d\n", 2264 "GNS_PHASE_DELEGATE_DHT-%llu: Got flag %d\n",
2288 rh->id, rd[i].flags); 2265 rh->id, rd[i].flags);
2289 2266
2290 if ((rd[i].record_type == GNUNET_GNS_RECORD_VPN) || 2267 if ((GNUNET_GNS_RECORD_VPN == rd[i].record_type) ||
2291 (rd[i].record_type == GNUNET_GNS_RECORD_NS) || 2268 (GNUNET_GNS_RECORD_NS == rd[i].record_type) ||
2292 (rd[i].record_type == GNUNET_GNS_RECORD_CNAME)) 2269 (GNUNET_GNS_RECORD_CNAME == rd[i].record_type))
2293 { 2270 {
2294 /** 2271 /**
2295 * This is a VPN,NS,CNAME entry. Let namestore handle this after caching 2272 * This is a VPN,NS,CNAME entry. Let namestore handle this after caching
2296 */ 2273 */
2297 if (strcmp(rh->name, "") == 0) 2274 if (0 == strcmp(rh->name, ""))
2298 strcpy(rh->name, rh->authority_name); 2275 strcpy(rh->name, rh->authority_name);
2299 else 2276 else
2300 GNUNET_snprintf(rh->name, MAX_DNS_NAME_LENGTH, "%s.%s", 2277 GNUNET_snprintf(rh->name, MAX_DNS_NAME_LENGTH, "%s.%s",
@@ -2303,8 +2280,8 @@ process_delegation_result_dht(void* cls,
2303 break; 2280 break;
2304 } 2281 }
2305 2282
2306 if ((strcmp(name, rh->authority_name) == 0) && 2283 if ((0 == strcmp(name, rh->authority_name)) &&
2307 (rd[i].record_type == GNUNET_GNS_RECORD_PKEY)) 2284 (GNUNET_GNS_RECORD_PKEY == rd[i].record_type))
2308 { 2285 {
2309 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2286 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2310 "GNS_PHASE_DELEGATE_DHT-%llu: Authority found in DHT\n", 2287 "GNS_PHASE_DELEGATE_DHT-%llu: Authority found in DHT\n",
@@ -2375,7 +2352,7 @@ process_delegation_result_dht(void* cls,
2375 } 2352 }
2376 } 2353 }
2377 2354
2378 if (rh->answered) 2355 if (0 != rh->answered)
2379 { 2356 {
2380 rh->answered = 0; 2357 rh->answered = 0;
2381 /** 2358 /**
@@ -2386,11 +2363,11 @@ process_delegation_result_dht(void* cls,
2386 "GNS_PHASE_DELEGATE_DHT-%llu: Answer from DHT for %s. Yet to resolve: %s\n", 2363 "GNS_PHASE_DELEGATE_DHT-%llu: Answer from DHT for %s. Yet to resolve: %s\n",
2387 rh->id, rh->authority_name, rh->name); 2364 rh->id, rh->authority_name, rh->name);
2388 2365
2389 if (strcmp(rh->name, "") == 0) 2366 if (0 == strcmp(rh->name, ""))
2390 { 2367 {
2391 /* Start shortening */ 2368 /* Start shortening */
2392 if ((rh->priv_key != NULL) && 2369 if ((NULL != rh->priv_key) &&
2393 (is_canonical (rh->name) == GNUNET_YES)) 2370 (GNUNET_YES == is_canonical (rh->name)))
2394 { 2371 {
2395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2396 "GNS_PHASE_DELEGATE_DHT-%llu: Trying to shorten authority chain\n", 2373 "GNS_PHASE_DELEGATE_DHT-%llu: Trying to shorten authority chain\n",
@@ -2421,7 +2398,7 @@ process_delegation_result_dht(void* cls,
2421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2398 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2422 "GNS_PHASE_DELEGATE_DHT-%llu: Adding %s back to %s\n", 2399 "GNS_PHASE_DELEGATE_DHT-%llu: Adding %s back to %s\n",
2423 rh->id, rh->authority_name, rh->name); 2400 rh->id, rh->authority_name, rh->name);
2424 if (strcmp(rh->name, "") == 0) 2401 if (0 == strcmp(rh->name, ""))
2425 strcpy(rh->name, rh->authority_name); 2402 strcpy(rh->name, rh->authority_name);
2426 else 2403 else
2427 GNUNET_snprintf(rh->name, MAX_DNS_NAME_LENGTH, "%s.%s", 2404 GNUNET_snprintf(rh->name, MAX_DNS_NAME_LENGTH, "%s.%s",
@@ -2435,6 +2412,7 @@ process_delegation_result_dht(void* cls,
2435 rh->proc(rh->proc_cls, rh, 0, NULL); 2412 rh->proc(rh->proc_cls, rh, 0, NULL);
2436} 2413}
2437 2414
2415//FIXME maybe define somewhere else?
2438#define MAX_SOA_LENGTH sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)\ 2416#define MAX_SOA_LENGTH sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)\
2439 +(MAX_DNS_NAME_LENGTH*2) 2417 +(MAX_DNS_NAME_LENGTH*2)
2440#define MAX_MX_LENGTH sizeof(uint16_t)+MAX_DNS_NAME_LENGTH 2418#define MAX_MX_LENGTH sizeof(uint16_t)+MAX_DNS_NAME_LENGTH
@@ -2449,11 +2427,11 @@ expand_plus(char* dest, char* src, char* repl)
2449 2427
2450 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2428 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2451 "GNS_POSTPROCESS: Got %s to expand with %s\n", src, repl); 2429 "GNS_POSTPROCESS: Got %s to expand with %s\n", src, repl);
2452 2430 //Eh? I guess this is at least strlen ('x.+') == 3 FIXME
2453 if (s_len < 3) 2431 if (3 > s_len)
2454 { 2432 {
2455 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2433 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2456 "GNS_POSTPROCESS: %s to short\n", src); 2434 "GNS_POSTPROCESS: %s too short\n", src);
2457 2435
2458 /* no postprocessing */ 2436 /* no postprocessing */
2459 memcpy(dest, src, s_len+1); 2437 memcpy(dest, src, s_len+1);
@@ -2501,7 +2479,7 @@ finish_lookup (struct ResolverHandle *rh,
2501 char* pos; 2479 char* pos;
2502 unsigned int offset; 2480 unsigned int offset;
2503 2481
2504 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) 2482 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
2505 { 2483 {
2506 GNUNET_SCHEDULER_cancel(rh->timeout_task); 2484 GNUNET_SCHEDULER_cancel(rh->timeout_task);
2507 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2485 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
@@ -2509,18 +2487,18 @@ finish_lookup (struct ResolverHandle *rh,
2509 2487
2510 GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh); 2488 GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh);
2511 2489
2512 if (rd_count > 0) 2490 if (0 < rd_count)
2513 memcpy(p_rd, rd, rd_count*sizeof(struct GNUNET_NAMESTORE_RecordData)); 2491 memcpy(p_rd, rd, rd_count*sizeof(struct GNUNET_NAMESTORE_RecordData));
2514 2492
2515 for (i = 0; i < rd_count; i++) 2493 for (i = 0; i < rd_count; i++)
2516 { 2494 {
2517 2495
2518 if (rd[i].record_type != GNUNET_GNS_RECORD_NS && 2496 if ((GNUNET_GNS_RECORD_NS != rd[i].record_type) &&
2519 rd[i].record_type != GNUNET_GNS_RECORD_PTR && 2497 (GNUNET_GNS_RECORD_PTR != rd[i].record_type) &&
2520 rd[i].record_type != GNUNET_GNS_RECORD_CNAME && 2498 (GNUNET_GNS_RECORD_CNAME != rd[i].record_type) &&
2521 rd[i].record_type != GNUNET_GNS_RECORD_MX && 2499 (GNUNET_GNS_RECORD_MX != rd[i].record_type) &&
2522 rd[i].record_type != GNUNET_GNS_RECORD_SOA && 2500 (GNUNET_GNS_RECORD_SOA != rd[i].record_type) &&
2523 rd[i].record_type != GNUNET_GNS_RECORD_SRV) 2501 (GNUNET_GNS_RECORD_SRV != rd[i].record_type))
2524 { 2502 {
2525 p_rd[i].data = rd[i].data; 2503 p_rd[i].data = rd[i].data;
2526 continue; 2504 continue;
@@ -2534,14 +2512,13 @@ finish_lookup (struct ResolverHandle *rh,
2534 2512
2535 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2513 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2536 "GNS_POSTPROCESS: Postprocessing\n"); 2514 "GNS_POSTPROCESS: Postprocessing\n");
2537 2515 if (0 == strcmp(rh->name, "+"))
2538 if (strcmp(rh->name, "+") == 0)
2539 repl_string = rlh->name; 2516 repl_string = rlh->name;
2540 else 2517 else
2541 repl_string = rlh->name+strlen(rh->name)+1; 2518 repl_string = rlh->name+strlen(rh->name)+1;
2542 2519
2543 offset = 0; 2520 offset = 0;
2544 if (rd[i].record_type == GNUNET_GNS_RECORD_MX) 2521 if (GNUNET_GNS_RECORD_MX == rd[i].record_type)
2545 { 2522 {
2546 memcpy (new_mx_data, (char*)rd[i].data, sizeof(uint16_t)); 2523 memcpy (new_mx_data, (char*)rd[i].data, sizeof(uint16_t));
2547 offset = sizeof(uint16_t); 2524 offset = sizeof(uint16_t);
@@ -2552,7 +2529,7 @@ finish_lookup (struct ResolverHandle *rh,
2552 p_rd[i].data = new_mx_data; 2529 p_rd[i].data = new_mx_data;
2553 p_rd[i].data_size = offset; 2530 p_rd[i].data_size = offset;
2554 } 2531 }
2555 else if (rd[i].record_type == GNUNET_GNS_RECORD_SRV) 2532 else if (GNUNET_GNS_RECORD_SRV == rd[i].record_type)
2556 { 2533 {
2557 /* 2534 /*
2558 * Prio, weight and port 2535 * Prio, weight and port
@@ -2567,7 +2544,7 @@ finish_lookup (struct ResolverHandle *rh,
2567 p_rd[i].data = new_srv_data; 2544 p_rd[i].data = new_srv_data;
2568 p_rd[i].data_size = sizeof (struct srv_data) + strlen ((char*)&new_srv[1]) + 1; 2545 p_rd[i].data_size = sizeof (struct srv_data) + strlen ((char*)&new_srv[1]) + 1;
2569 } 2546 }
2570 else if (rd[i].record_type == GNUNET_GNS_RECORD_SOA) 2547 else if (GNUNET_GNS_RECORD_SOA == rd[i].record_type)
2571 { 2548 {
2572 /* expand mname and rname */ 2549 /* expand mname and rname */
2573 old_soa = (struct soa_data*)rd[i].data; 2550 old_soa = (struct soa_data*)rd[i].data;
@@ -2611,10 +2588,9 @@ handle_record_dht(void* cls, struct ResolverHandle *rh,
2611 unsigned int rd_count, 2588 unsigned int rd_count,
2612 const struct GNUNET_NAMESTORE_RecordData *rd) 2589 const struct GNUNET_NAMESTORE_RecordData *rd)
2613{ 2590{
2614 struct RecordLookupHandle* rlh; 2591 struct RecordLookupHandle* rlh = cls;
2615 2592
2616 rlh = (struct RecordLookupHandle*)cls; 2593 if (0 == rd_count)
2617 if (rd_count == 0)
2618 { 2594 {
2619 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2595 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2620 "GNS_PHASE_REC-%llu: No records for %s found in DHT. Aborting\n", 2596 "GNS_PHASE_REC-%llu: No records for %s found in DHT. Aborting\n",
@@ -2623,13 +2599,10 @@ handle_record_dht(void* cls, struct ResolverHandle *rh,
2623 finish_lookup(rh, rlh, 0, NULL); 2599 finish_lookup(rh, rlh, 0, NULL);
2624 return; 2600 return;
2625 } 2601 }
2626
2627 /* results found yay */ 2602 /* results found yay */
2628 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2603 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2629 "GNS_PHASE_REC-%llu: Record resolved from DHT!", rh->id); 2604 "GNS_PHASE_REC-%llu: Record resolved from DHT!", rh->id);
2630
2631 finish_lookup(rh, rlh, rd_count, rd); 2605 finish_lookup(rh, rlh, rd_count, rd);
2632
2633} 2606}
2634 2607
2635 2608
@@ -2648,61 +2621,55 @@ handle_record_ns (void* cls, struct ResolverHandle *rh,
2648 unsigned int rd_count, 2621 unsigned int rd_count,
2649 const struct GNUNET_NAMESTORE_RecordData *rd) 2622 const struct GNUNET_NAMESTORE_RecordData *rd)
2650{ 2623{
2651 struct RecordLookupHandle* rlh; 2624 struct RecordLookupHandle* rlh = cls;
2652 rlh = (struct RecordLookupHandle*) cls;
2653 int check_dht = GNUNET_YES; 2625 int check_dht = GNUNET_YES;
2654 2626
2655 if (rd_count == 0) 2627 if (0 != rd_count)
2656 { 2628 {
2629 /* results found yay */
2657 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2630 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2658 "GNS_PHASE_REC-%llu: NS returned no records. (status: %d)!\n", 2631 "GNS_PHASE_REC-%llu: Record resolved from namestore!\n", rh->id);
2659 rh->id, 2632 finish_lookup(rh, rlh, rd_count, rd);
2660 rh->status);
2661
2662 /**
2663 * There are 5 conditions that have to met for us to consult the DHT:
2664 * 1. The entry in the DHT is RSL_RECORD_EXPIRED OR
2665 * 2. No entry in the NS existed AND
2666 * 3. The zone queried is not the local resolver's zone AND
2667 * 4. The name that was looked up is '+'
2668 * because if it was any other canonical name we either already queried
2669 * the DHT for the authority in the authority lookup phase (and thus
2670 * would already have an entry in the NS for the record)
2671 * 5. We are not in cache only mode
2672 */
2673 if (((rh->status & RSL_RECORD_EXPIRED) != 0) &&
2674 ((rh->status & RSL_RECORD_EXISTS) == 0) )
2675 check_dht = GNUNET_NO;
2676
2677 if (0 != GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
2678 &rh->private_local_zone))
2679 check_dht = GNUNET_NO;
2680
2681 if ((strcmp (rh->name, "+") != 0) && (is_srv (rh->name) == GNUNET_YES))
2682 check_dht = GNUNET_NO;
2683
2684
2685 if (rh->only_cached == GNUNET_YES)
2686 check_dht = GNUNET_NO;
2687
2688 if (GNUNET_YES == check_dht)
2689 {
2690 rh->proc = &handle_record_dht;
2691 resolve_record_dht(rh);
2692 return;
2693 }
2694 /* give up, cannot resolve */
2695 finish_lookup(rh, rlh, 0, NULL);
2696 return; 2633 return;
2697 } 2634 }
2698 2635
2699 /* results found yay */
2700 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2636 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2701 "GNS_PHASE_REC-%llu: Record resolved from namestore!\n", rh->id); 2637 "GNS_PHASE_REC-%llu: NS returned no records. (status: %d)!\n",
2702 2638 rh->id,
2703 finish_lookup(rh, rlh, rd_count, rd); 2639 rh->status);
2704 2640 /**
2641 * There are 5 conditions that have to met for us to consult the DHT:
2642 * 1. The entry in the DHT is RSL_RECORD_EXPIRED OR
2643 * 2. No entry in the NS existed AND
2644 * 3. The zone queried is not the local resolver's zone AND
2645 * 4. The name that was looked up is '+'
2646 * because if it was any other canonical name we either already queried
2647 * the DHT for the authority in the authority lookup phase (and thus
2648 * would already have an entry in the NS for the record)
2649 * 5. We are not in cache only mode
2650 */
2651 if ((0 != (rh->status & RSL_RECORD_EXPIRED)) &&
2652 (0 == (rh->status & RSL_RECORD_EXISTS)) )
2653 check_dht = GNUNET_NO;
2654
2655 if (0 != GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
2656 &rh->private_local_zone))
2657 check_dht = GNUNET_NO;
2658
2659 if ((0 != strcmp (rh->name, "+")) && (GNUNET_YES == is_srv (rh->name)))
2660 check_dht = GNUNET_NO;
2705 2661
2662 if (GNUNET_YES == rh->only_cached)
2663 check_dht = GNUNET_NO;
2664
2665 if (GNUNET_YES == check_dht)
2666 {
2667 rh->proc = &handle_record_dht;
2668 resolve_record_dht(rh);
2669 return;
2670 }
2671 /* give up, cannot resolve */
2672 finish_lookup(rh, rlh, 0, NULL);
2706} 2673}
2707 2674
2708 2675
@@ -2718,21 +2685,21 @@ pop_tld(char* name, char* dest)
2718{ 2685{
2719 uint32_t len; 2686 uint32_t len;
2720 2687
2721 if (is_canonical (name) == GNUNET_YES) 2688 if (GNUNET_YES == is_canonical (name))
2722 { 2689 {
2723 strcpy(dest, name); 2690 strcpy(dest, name);
2724 strcpy(name, ""); 2691 strcpy(name, "");
2725 return; 2692 return;
2726 } 2693 }
2727 2694
2728 for (len = strlen(name); len > 0; len--) 2695 for (len = strlen(name); 0 < len; len--)
2729 { 2696 {
2730 if (*(name+len) == '.') 2697 if (*(name+len) == '.')
2731 break; 2698 break;
2732 } 2699 }
2733 2700
2734 //Was canonical? 2701 //Was canonical?
2735 if (len == 0) 2702 if (0 == len)
2736 return; 2703 return;
2737 2704
2738 name[len] = '\0'; 2705 name[len] = '\0';
@@ -2753,12 +2720,10 @@ is_tld(const char* name, const char* tld)
2753 int offset = 0; 2720 int offset = 0;
2754 2721
2755 if (strlen(name) <= strlen(tld)) 2722 if (strlen(name) <= strlen(tld))
2756 {
2757 return GNUNET_NO; 2723 return GNUNET_NO;
2758 }
2759 2724
2760 offset = strlen(name)-strlen(tld); 2725 offset = strlen(name)-strlen(tld);
2761 if (strcmp(name+offset, tld) != 0) 2726 if (0 != strcmp(name+offset, tld))
2762 { 2727 {
2763 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2728 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2764 "%s is not in .%s TLD\n", name, tld); 2729 "%s is not in .%s TLD\n", name, tld);
@@ -2781,12 +2746,12 @@ handle_delegation_dht(void* cls, struct ResolverHandle *rh,
2781 const struct GNUNET_NAMESTORE_RecordData *rd) 2746 const struct GNUNET_NAMESTORE_RecordData *rd)
2782{ 2747{
2783 struct RecordLookupHandle* rlh; 2748 struct RecordLookupHandle* rlh;
2784 rlh = (struct RecordLookupHandle*) cls; 2749 rlh = cls;
2785 2750
2786 2751
2787 if (strcmp(rh->name, "") == 0) 2752 if (0 == strcmp(rh->name, ""))
2788 { 2753 {
2789 if ((rlh->record_type == GNUNET_GNS_RECORD_PKEY)) 2754 if (GNUNET_GNS_RECORD_PKEY == rlh->record_type)
2790 { 2755 {
2791 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2756 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2792 "GNS_PHASE_DELEGATE_DHT-%llu: Resolved queried PKEY via DHT.\n", 2757 "GNS_PHASE_DELEGATE_DHT-%llu: Resolved queried PKEY via DHT.\n",
@@ -2807,7 +2772,7 @@ handle_delegation_dht(void* cls, struct ResolverHandle *rh,
2807 /** 2772 /**
2808 * we still have some left 2773 * we still have some left
2809 **/ 2774 **/
2810 if (is_canonical (rh->name) == GNUNET_YES) 2775 if (GNUNET_YES == is_canonical (rh->name))
2811 { 2776 {
2812 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2777 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2813 "GNS_PHASE_DELEGATE_DHT-%llu: Resolving canonical record %s in ns\n", 2778 "GNS_PHASE_DELEGATE_DHT-%llu: Resolving canonical record %s in ns\n",
@@ -2841,7 +2806,9 @@ resolve_delegation_dht(struct ResolverHandle *rh)
2841 struct GNUNET_HashCode lookup_key; 2806 struct GNUNET_HashCode lookup_key;
2842 struct ResolverHandle *rh_heap_root; 2807 struct ResolverHandle *rh_heap_root;
2843 2808
2844 pop_tld(rh->name, rh->authority_name); 2809 pop_tld(rh->name, rh->authority_name);
2810
2811 //FIXME handle return values here
2845 GNUNET_CRYPTO_short_hash(rh->authority_name, 2812 GNUNET_CRYPTO_short_hash(rh->authority_name,
2846 strlen(rh->authority_name), 2813 strlen(rh->authority_name),
2847 &name_hash); 2814 &name_hash);
@@ -2853,9 +2820,6 @@ resolve_delegation_dht(struct ResolverHandle *rh)
2853 2820
2854 if (rh->timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) 2821 if (rh->timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
2855 { 2822 {
2856 //rh->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
2857 // &dht_authority_lookup_timeout,
2858 // rh);
2859 rh->timeout_cont = &dht_authority_lookup_timeout; 2823 rh->timeout_cont = &dht_authority_lookup_timeout;
2860 rh->timeout_cont_cls = rh; 2824 rh->timeout_cont_cls = rh;
2861 } 2825 }
@@ -2885,7 +2849,6 @@ resolve_delegation_dht(struct ResolverHandle *rh)
2885 } 2849 }
2886 2850
2887 xquery = htonl(GNUNET_GNS_RECORD_PKEY); 2851 xquery = htonl(GNUNET_GNS_RECORD_PKEY);
2888
2889 GNUNET_assert(rh->get_handle == NULL); 2852 GNUNET_assert(rh->get_handle == NULL);
2890 rh->get_handle = GNUNET_DHT_get_start(dht_handle, 2853 rh->get_handle = GNUNET_DHT_get_start(dht_handle,
2891 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 2854 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
@@ -2896,7 +2859,6 @@ resolve_delegation_dht(struct ResolverHandle *rh)
2896 sizeof(xquery), 2859 sizeof(xquery),
2897 &process_delegation_result_dht, 2860 &process_delegation_result_dht,
2898 rh); 2861 rh);
2899
2900} 2862}
2901 2863
2902 2864
@@ -2914,7 +2876,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2914 const struct GNUNET_NAMESTORE_RecordData *rd) 2876 const struct GNUNET_NAMESTORE_RecordData *rd)
2915{ 2877{
2916 struct RecordLookupHandle* rlh; 2878 struct RecordLookupHandle* rlh;
2917 rlh = (struct RecordLookupHandle*) cls; 2879 rlh = cls;
2918 int check_dht = GNUNET_YES; 2880 int check_dht = GNUNET_YES;
2919 int s_len = 0; 2881 int s_len = 0;
2920 2882
@@ -2928,7 +2890,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2928 return; 2890 return;
2929 } 2891 }
2930 2892
2931 if (strcmp(rh->name, "") == 0) 2893 if (0 == strcmp(rh->name, ""))
2932 { 2894 {
2933 2895
2934 /* We resolved full name for delegation. resolving record */ 2896 /* We resolved full name for delegation. resolving record */
@@ -2937,7 +2899,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2937 rh->id); 2899 rh->id);
2938 if (rh->status & RSL_CNAME_FOUND) 2900 if (rh->status & RSL_CNAME_FOUND)
2939 { 2901 {
2940 if (rlh->record_type == GNUNET_GNS_RECORD_CNAME) 2902 if (GNUNET_GNS_RECORD_CNAME == rlh->record_type)
2941 { 2903 {
2942 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2904 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2943 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried CNAME in NS.\n", 2905 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried CNAME in NS.\n",
@@ -2948,7 +2910,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2948 } 2910 }
2949 2911
2950 /* A .+ CNAME */ 2912 /* A .+ CNAME */
2951 if (is_tld ((char*)rd->data, GNUNET_GNS_TLD_PLUS)) 2913 if (GNUNET_YES == is_tld ((char*)rd->data, GNUNET_GNS_TLD_PLUS))
2952 { 2914 {
2953 s_len = strlen (rd->data) - 2; 2915 s_len = strlen (rd->data) - 2;
2954 memcpy (rh->name, rd->data, s_len); 2916 memcpy (rh->name, rd->data, s_len);
@@ -2956,7 +2918,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2956 resolve_delegation_ns (rh); 2918 resolve_delegation_ns (rh);
2957 return; 2919 return;
2958 } 2920 }
2959 else if (is_tld ((char*)rd->data, GNUNET_GNS_TLD_ZKEY)) 2921 else if (GNUNET_YES == is_tld ((char*)rd->data, GNUNET_GNS_TLD_ZKEY))
2960 { 2922 {
2961 gns_resolver_lookup_record (rh->authority, 2923 gns_resolver_lookup_record (rh->authority,
2962 rh->private_local_zone, 2924 rh->private_local_zone,
@@ -2983,7 +2945,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2983 } 2945 }
2984 else if (rh->status & RSL_DELEGATE_VPN) 2946 else if (rh->status & RSL_DELEGATE_VPN)
2985 { 2947 {
2986 if (rlh->record_type == GNUNET_GNS_RECORD_VPN) 2948 if (GNUNET_GNS_RECORD_VPN == rlh->record_type)
2987 { 2949 {
2988 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2950 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2989 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried VPNRR in NS.\n", 2951 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried VPNRR in NS.\n",
@@ -3001,7 +2963,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
3001 } 2963 }
3002 else if (rh->status & RSL_DELEGATE_NS) 2964 else if (rh->status & RSL_DELEGATE_NS)
3003 { 2965 {
3004 if (rlh->record_type == GNUNET_GNS_RECORD_NS) 2966 if (GNUNET_GNS_RECORD_NS == rlh->record_type)
3005 { 2967 {
3006 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2968 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3007 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried NSRR in NS.\n", 2969 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried NSRR in NS.\n",
@@ -3028,7 +2990,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
3028 finish_lookup (rh, rlh, 0, NULL); 2990 finish_lookup (rh, rlh, 0, NULL);
3029 return; 2991 return;
3030 } 2992 }
3031 else if (rlh->record_type == GNUNET_GNS_RECORD_PKEY) 2993 else if (GNUNET_GNS_RECORD_PKEY == rlh->record_type)
3032 { 2994 {
3033 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2995 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3034 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried PKEY in NS.\n", 2996 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried PKEY in NS.\n",
@@ -3048,7 +3010,7 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
3048 3010
3049 if (rh->status & RSL_DELEGATE_NS) 3011 if (rh->status & RSL_DELEGATE_NS)
3050 { 3012 {
3051 if (rlh->record_type == GNUNET_GNS_RECORD_NS) 3013 if (GNUNET_GNS_RECORD_NS == rlh->record_type)
3052 { 3014 {
3053 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3015 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3054 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried NSRR in NS.\n", 3016 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried NSRR in NS.\n",
@@ -3081,38 +3043,36 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
3081 &rh->private_local_zone)) 3043 &rh->private_local_zone))
3082 check_dht = GNUNET_NO; 3044 check_dht = GNUNET_NO;
3083 3045
3084 if (rh->only_cached == GNUNET_YES) 3046 if (GNUNET_YES == rh->only_cached)
3085 check_dht = GNUNET_NO; 3047 check_dht = GNUNET_NO;
3086 3048
3087 if (check_dht == GNUNET_NO) 3049 if (GNUNET_YES == check_dht)
3088 { 3050 {
3089 if (is_canonical (rh->name) == GNUNET_YES) 3051
3090 { 3052 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3091 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3053 "GNS_PHASE_DELEGATE_NS-%llu: Trying to resolve delegation for %s via DHT\n",
3092 "GNS_PHASE_DELEGATE_NS-%llu: Resolving canonical record %s\n", 3054 rh->id, rh->name);
3093 rh->id, 3055 rh->proc = &handle_delegation_dht;
3094 rh->name); 3056 resolve_delegation_dht(rh);
3095 rh->proc = &handle_record_ns; 3057 return;
3096 resolve_record_ns(rh); 3058 }
3097 } 3059
3098 else 3060 if (GNUNET_NO == is_canonical (rh->name))
3099 { 3061 {
3100 /* give up, cannot resolve */ 3062 /* give up, cannot resolve */
3101 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3063 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3102 "GNS_PHASE_DELEGATE_NS-%llu: Cannot fully resolve delegation for %s!\n", 3064 "GNS_PHASE_DELEGATE_NS-%llu: Cannot fully resolve delegation for %s!\n",
3103 rh->id, 3065 rh->id,
3104 rh->name); 3066 rh->name);
3105 finish_lookup(rh, rlh, rd_count, rd); 3067 finish_lookup(rh, rlh, rd_count, rd);
3106 //rlh->proc(rlh->proc_cls, 0, NULL);
3107 }
3108 return; 3068 return;
3109 } 3069 }
3110
3111 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3070 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3112 "GNS_PHASE_DELEGATE_NS-%llu: Trying to resolve delegation for %s via DHT\n", 3071 "GNS_PHASE_DELEGATE_NS-%llu: Resolving canonical record %s\n",
3113 rh->id, rh->name); 3072 rh->id,
3114 rh->proc = &handle_delegation_dht; 3073 rh->name);
3115 resolve_delegation_dht(rh); 3074 rh->proc = &handle_record_ns;
3075 resolve_record_ns(rh);
3116} 3076}
3117 3077
3118 3078
diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c
index 35350e8bb..96fe35ede 100644
--- a/src/gns/test_gns_proxy.c
+++ b/src/gns/test_gns_proxy.c
@@ -441,6 +441,12 @@ main (int argc, char *const *argv)
441 return 0; 441 return 0;
442 } 442 }
443 443
444 if (GNUNET_YES != GNUNET_OS_check_helper_binary ("gnunet-helper-dns"))
445 {
446 fprintf (stderr, "DNS helper binary has wrong permissions... skipping!\n");
447 return 0;
448 }
449
444 GNUNET_CRYPTO_setup_hostkey ("test_gns_proxy.conf"); 450 GNUNET_CRYPTO_setup_hostkey ("test_gns_proxy.conf");
445 451
446 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 452 if (0 != curl_global_init (CURL_GLOBAL_WIN32))