aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-17 09:59:54 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-17 09:59:54 +0000
commit9e3600dfdff1323c0312fac527f9e5e9da4be055 (patch)
treefd8a2d8e00cfeba862b136c3416b79599dc52b84 /src/gns
parentd89f437df5f75c2eebcea71ba6adc6e8452b2d27 (diff)
downloadgnunet-9e3600dfdff1323c0312fac527f9e5e9da4be055.tar.gz
gnunet-9e3600dfdff1323c0312fac527f9e5e9da4be055.zip
-fix cname, more ns/vpn delegation
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gnunet-service-gns.c2
-rw-r--r--src/gns/gnunet-service-gns_resolver.c297
-rw-r--r--src/gns/gnunet-service-gns_resolver.h8
3 files changed, 216 insertions, 91 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 79aedccf4..1618e27ef 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -1121,7 +1121,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1121 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n"); 1121 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
1122 } 1122 }
1123 1123
1124 if (gns_resolver_init(namestore_handle, dht_handle, zone_hash, 1124 if (gns_resolver_init(namestore_handle, dht_handle, zone_hash, c,
1125 max_parallel_bg_queries, 1125 max_parallel_bg_queries,
1126 ignore_pending) 1126 ignore_pending)
1127 == GNUNET_SYSERR) 1127 == GNUNET_SYSERR)
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 565d50eaf..8e8629c4d 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -33,6 +33,7 @@
33#include "gnunet_namestore_service.h" 33#include "gnunet_namestore_service.h"
34#include "gnunet_vpn_service.h" 34#include "gnunet_vpn_service.h"
35#include "gnunet_dns_service.h" 35#include "gnunet_dns_service.h"
36#include "gnunet_resolver_service.h"
36#include "gnunet_dnsparser_lib.h" 37#include "gnunet_dnsparser_lib.h"
37#include "gnunet_gns_service.h" 38#include "gnunet_gns_service.h"
38#include "block_gns.h" 39#include "block_gns.h"
@@ -552,10 +553,7 @@ process_zone_to_name_discover (void *cls,
552/** 553/**
553 * Callback that shortens authorities 554 * Callback that shortens authorities
554 * 555 *
555 * @param name the name given by delegation 556 * @param gph the handle to the shorten request
556 * @param zone the authority
557 * @param our_zone our local zone
558 * @param key the private key of our authority
559 */ 557 */
560static void 558static void
561shorten_authority_chain (struct GetPseuAuthorityHandle *gph) 559shorten_authority_chain (struct GetPseuAuthorityHandle *gph)
@@ -626,6 +624,7 @@ int
626gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, 624gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
627 struct GNUNET_DHT_Handle *dh, 625 struct GNUNET_DHT_Handle *dh,
628 struct GNUNET_CRYPTO_ShortHashCode lz, 626 struct GNUNET_CRYPTO_ShortHashCode lz,
627 const struct GNUNET_CONFIGURATION_Handle *cfg,
629 unsigned long long max_bg_queries, 628 unsigned long long max_bg_queries,
630 int ignore_pending) 629 int ignore_pending)
631{ 630{
@@ -636,11 +635,24 @@ gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
636 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 635 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
637 max_allowed_background_queries = max_bg_queries; 636 max_allowed_background_queries = max_bg_queries;
638 ignore_pending_records = ignore_pending; 637 ignore_pending_records = ignore_pending;
638
639 if (NULL == vpn_handle)
640 {
641 vpn_handle = GNUNET_VPN_connect (cfg);
642 if (NULL == vpn_handle)
643 {
644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
645 "GNS_PHASE_INIT: Error connecting to VPN!\n");
646
647 return GNUNET_SYSERR;
648 }
649 }
639 650
640 if ((namestore_handle != NULL) && (dht_handle != NULL)) 651 if ((namestore_handle != NULL) && (dht_handle != NULL))
641 { 652 {
642 return GNUNET_OK; 653 return GNUNET_OK;
643 } 654 }
655
644 return GNUNET_SYSERR; 656 return GNUNET_SYSERR;
645} 657}
646 658
@@ -661,7 +673,7 @@ cleanup_pending_background_queries(void* cls,
661{ 673{
662 struct ResolverHandle *rh = (struct ResolverHandle *)element; 674 struct ResolverHandle *rh = (struct ResolverHandle *)element;
663 ResolverCleanupContinuation cont = cls; 675 ResolverCleanupContinuation cont = cls;
664 676
665 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 677 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
666 "GNS_CLEANUP-%llu: Terminating background lookup for %s\n", 678 "GNS_CLEANUP-%llu: Terminating background lookup for %s\n",
667 rh->id, rh->name); 679 rh->id, rh->name);
@@ -720,7 +732,7 @@ free_resolver_handle(struct ResolverHandle* rh)
720 GNUNET_free(ac); 732 GNUNET_free(ac);
721 ac = ac_next; 733 ac = ac_next;
722 } 734 }
723 735
724 if (NULL != rh->dns_raw_packet) 736 if (NULL != rh->dns_raw_packet)
725 GNUNET_free (rh->dns_raw_packet); 737 GNUNET_free (rh->dns_raw_packet);
726 738
@@ -822,7 +834,7 @@ dht_lookup_timeout(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
822 &background_lookup_result_processor, 834 &background_lookup_result_processor,
823 NULL); 835 NULL);
824 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 836 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
825 837
826 GNUNET_DHT_get_stop (rh->get_handle); 838 GNUNET_DHT_get_stop (rh->get_handle);
827 rh->get_handle = NULL; 839 rh->get_handle = NULL;
828 rh->proc(rh->proc_cls, rh, 0, NULL); 840 rh->proc(rh->proc_cls, rh, 0, NULL);
@@ -846,14 +858,14 @@ dht_lookup_timeout(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
846 */ 858 */
847static void 859static void
848process_record_result_dht(void* cls, 860process_record_result_dht(void* cls,
849 struct GNUNET_TIME_Absolute exp, 861 struct GNUNET_TIME_Absolute exp,
850 const struct GNUNET_HashCode * key, 862 const struct GNUNET_HashCode * key,
851 const struct GNUNET_PeerIdentity *get_path, 863 const struct GNUNET_PeerIdentity *get_path,
852 unsigned int get_path_length, 864 unsigned int get_path_length,
853 const struct GNUNET_PeerIdentity *put_path, 865 const struct GNUNET_PeerIdentity *put_path,
854 unsigned int put_path_length, 866 unsigned int put_path_length,
855 enum GNUNET_BLOCK_Type type, 867 enum GNUNET_BLOCK_Type type,
856 size_t size, const void *data) 868 size_t size, const void *data)
857{ 869{
858 struct ResolverHandle *rh; 870 struct ResolverHandle *rh;
859 struct RecordLookupHandle *rlh; 871 struct RecordLookupHandle *rlh;
@@ -867,26 +879,26 @@ process_record_result_dht(void* cls,
867 rh = (struct ResolverHandle *)cls; 879 rh = (struct ResolverHandle *)cls;
868 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 880 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
869 "GNS_PHASE_REC-%d: got dht result (size=%d)\n", rh->id, size); 881 "GNS_PHASE_REC-%d: got dht result (size=%d)\n", rh->id, size);
870 882
871 if (data == NULL) 883 if (data == NULL)
872 return; 884 return;
873 885
874 //FIXME maybe check expiration here, check block type 886 //FIXME maybe check expiration here, check block type
875 887
876 888
877 rlh = (struct RecordLookupHandle *) rh->proc_cls; 889 rlh = (struct RecordLookupHandle *) rh->proc_cls;
878 nrb = (struct GNSNameRecordBlock*)data; 890 nrb = (struct GNSNameRecordBlock*)data;
879 891
880 /* stop lookup and timeout task */ 892 /* stop lookup and timeout task */
881 GNUNET_DHT_get_stop (rh->get_handle); 893 GNUNET_DHT_get_stop (rh->get_handle);
882 rh->get_handle = NULL; 894 rh->get_handle = NULL;
883 895
884 if (rh->dht_heap_node != NULL) 896 if (rh->dht_heap_node != NULL)
885 { 897 {
886 GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node); 898 GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node);
887 rh->dht_heap_node = NULL; 899 rh->dht_heap_node = NULL;
888 } 900 }
889 901
890 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) 902 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK)
891 { 903 {
892 GNUNET_SCHEDULER_cancel(rh->timeout_task); 904 GNUNET_SCHEDULER_cancel(rh->timeout_task);
@@ -901,7 +913,7 @@ process_record_result_dht(void* cls,
901 913
902 rd_data += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock); 914 rd_data += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock);
903 rd_size = size - strlen(name) - 1 - sizeof(struct GNSNameRecordBlock); 915 rd_size = size - strlen(name) - 1 - sizeof(struct GNSNameRecordBlock);
904 916
905 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, 917 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size,
906 rd_data, 918 rd_data,
907 num_records, 919 num_records,
@@ -915,20 +927,20 @@ process_record_result_dht(void* cls,
915 for (i=0; i<num_records; i++) 927 for (i=0; i<num_records; i++)
916 { 928 {
917 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
918 "GNS_PHASE_REC-%d: Got name: %s (wanted %s)\n", 930 "GNS_PHASE_REC-%d: Got name: %s (wanted %s)\n",
919 rh->id, name, rh->name); 931 rh->id, name, rh->name);
920 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 932 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
921 "GNS_PHASE_REC-%d: Got type: %d\n", 933 "GNS_PHASE_REC-%d: Got type: %d\n",
922 rh->id, rd[i].record_type); 934 rh->id, rd[i].record_type);
923 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 935 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
924 "GNS_PHASE_REC-%d: Got data length: %d\n", 936 "GNS_PHASE_REC-%d: Got data length: %d\n",
925 rh->id, rd[i].data_size); 937 rh->id, rd[i].data_size);
926 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 938 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
927 "GNS_PHASE_REC-%d: Got flag %d\n", 939 "GNS_PHASE_REC-%d: Got flag %d\n",
928 rh->id, rd[i].flags); 940 rh->id, rd[i].flags);
929 941
930 if ((strcmp(name, rh->name) == 0) && 942 if ((strcmp(name, rh->name) == 0) &&
931 (rd[i].record_type == rlh->record_type)) 943 (rd[i].record_type == rlh->record_type))
932 { 944 {
933 rh->answered++; 945 rh->answered++;
934 } 946 }
@@ -951,7 +963,7 @@ process_record_result_dht(void* cls,
951 &on_namestore_record_put_result, //cont 963 &on_namestore_record_put_result, //cont
952 NULL); //cls 964 NULL); //cls
953 965
954 966
955 if (rh->answered) 967 if (rh->answered)
956 rh->proc(rh->proc_cls, rh, num_records, rd); 968 rh->proc(rh->proc_cls, rh, num_records, rd);
957 else 969 else
@@ -978,13 +990,13 @@ resolve_record_dht(struct ResolverHandle *rh)
978 struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; 990 struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string;
979 struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls; 991 struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls;
980 struct ResolverHandle *rh_heap_root; 992 struct ResolverHandle *rh_heap_root;
981 993
982 GNUNET_CRYPTO_short_hash(rh->name, strlen(rh->name), &name_hash); 994 GNUNET_CRYPTO_short_hash(rh->name, strlen(rh->name), &name_hash);
983 GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double); 995 GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
984 GNUNET_CRYPTO_short_hash_double(&rh->authority, &zone_hash_double); 996 GNUNET_CRYPTO_short_hash_double(&rh->authority, &zone_hash_double);
985 GNUNET_CRYPTO_hash_xor(&name_hash_double, &zone_hash_double, &lookup_key); 997 GNUNET_CRYPTO_hash_xor(&name_hash_double, &zone_hash_double, &lookup_key);
986 GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string); 998 GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string);
987 999
988 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1000 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
989 "GNS_PHASE_REC-%d: starting dht lookup for %s with key: %s\n", 1001 "GNS_PHASE_REC-%d: starting dht lookup for %s with key: %s\n",
990 rh->id, rh->name, (char*)&lookup_key_string); 1002 rh->id, rh->name, (char*)&lookup_key_string);
@@ -1000,15 +1012,15 @@ resolve_record_dht(struct ResolverHandle *rh)
1000 if (rh->timeout_task == GNUNET_SCHEDULER_NO_TASK) 1012 if (rh->timeout_task == GNUNET_SCHEDULER_NO_TASK)
1001 { 1013 {
1002 1014
1003 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1015 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1004 "GNS_PHASE_REC-%d: Adjusting timeout\n", rh->id); 1016 "GNS_PHASE_REC-%d: Adjusting timeout\n", rh->id);
1005 /* 1017 /*
1006 * Set timeout for authority lookup phase to 1/2 1018 * Set timeout for authority lookup phase to 1/2
1007 */ 1019 */
1008 rh->timeout_task = GNUNET_SCHEDULER_add_delayed( 1020 rh->timeout_task = GNUNET_SCHEDULER_add_delayed(
1009 GNUNET_TIME_relative_divide(rh->timeout, 2), 1021 GNUNET_TIME_relative_divide(rh->timeout, 2),
1010 &handle_lookup_timeout, 1022 &handle_lookup_timeout,
1011 rh); 1023 rh);
1012 } 1024 }
1013 //rh->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT, 1025 //rh->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
1014 // &dht_lookup_timeout, 1026 // &dht_lookup_timeout,
@@ -1025,9 +1037,9 @@ resolve_record_dht(struct ResolverHandle *rh)
1025 GNUNET_DHT_get_stop(rh_heap_root->get_handle); 1037 GNUNET_DHT_get_stop(rh_heap_root->get_handle);
1026 rh_heap_root->get_handle = NULL; 1038 rh_heap_root->get_handle = NULL;
1027 rh_heap_root->dht_heap_node = NULL; 1039 rh_heap_root->dht_heap_node = NULL;
1028 1040
1029 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1041 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1030 "GNS_PHASE_REC-%d: Replacing oldest background query for %s\n", 1042 "GNS_PHASE_REC-%d: Replacing oldest background query for %s\n",
1031 rh->id, rh_heap_root->name); 1043 rh->id, rh_heap_root->name);
1032 rh_heap_root->proc(rh_heap_root->proc_cls, 1044 rh_heap_root->proc(rh_heap_root->proc_cls,
1033 rh_heap_root, 1045 rh_heap_root,
@@ -1035,22 +1047,22 @@ resolve_record_dht(struct ResolverHandle *rh)
1035 NULL); 1047 NULL);
1036 } 1048 }
1037 rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap, 1049 rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
1038 rh, 1050 rh,
1039 GNUNET_TIME_absolute_get().abs_value); 1051 GNUNET_TIME_absolute_get().abs_value);
1040 } 1052 }
1041 1053
1042 xquery = htonl(rlh->record_type); 1054 xquery = htonl(rlh->record_type);
1043 1055
1044 GNUNET_assert(rh->get_handle == NULL); 1056 GNUNET_assert(rh->get_handle == NULL);
1045 rh->get_handle = GNUNET_DHT_get_start(dht_handle, 1057 rh->get_handle = GNUNET_DHT_get_start(dht_handle,
1046 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 1058 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
1047 &lookup_key, 1059 &lookup_key,
1048 DHT_GNS_REPLICATION_LEVEL, 1060 DHT_GNS_REPLICATION_LEVEL,
1049 GNUNET_DHT_RO_NONE, 1061 GNUNET_DHT_RO_NONE,
1050 &xquery, 1062 &xquery,
1051 sizeof(xquery), 1063 sizeof(xquery),
1052 &process_record_result_dht, 1064 &process_record_result_dht,
1053 rh); 1065 rh);
1054 1066
1055} 1067}
1056 1068
@@ -1069,11 +1081,11 @@ resolve_record_dht(struct ResolverHandle *rh)
1069 */ 1081 */
1070static void 1082static void
1071process_record_result_ns(void* cls, 1083process_record_result_ns(void* cls,
1072 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, 1084 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
1073 struct GNUNET_TIME_Absolute expiration, 1085 struct GNUNET_TIME_Absolute expiration,
1074 const char *name, unsigned int rd_count, 1086 const char *name, unsigned int rd_count,
1075 const struct GNUNET_NAMESTORE_RecordData *rd, 1087 const struct GNUNET_NAMESTORE_RecordData *rd,
1076 const struct GNUNET_CRYPTO_RsaSignature *signature) 1088 const struct GNUNET_CRYPTO_RsaSignature *signature)
1077{ 1089{
1078 struct ResolverHandle *rh; 1090 struct ResolverHandle *rh;
1079 struct RecordLookupHandle *rlh; 1091 struct RecordLookupHandle *rlh;
@@ -1083,32 +1095,32 @@ process_record_result_ns(void* cls,
1083 rh = (struct ResolverHandle *) cls; 1095 rh = (struct ResolverHandle *) cls;
1084 rlh = (struct RecordLookupHandle *)rh->proc_cls; 1096 rlh = (struct RecordLookupHandle *)rh->proc_cls;
1085 GNUNET_CRYPTO_short_hash(key, 1097 GNUNET_CRYPTO_short_hash(key,
1086 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1098 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1087 &zone); 1099 &zone);
1088 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); 1100 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
1089 1101
1090 1102
1091 1103
1092 rh->status = 0; 1104 rh->status = 0;
1093 1105
1094 if (name != NULL) 1106 if (name != NULL)
1095 { 1107 {
1096 rh->status |= RSL_RECORD_EXISTS; 1108 rh->status |= RSL_RECORD_EXISTS;
1097 } 1109 }
1098 1110
1099 if (remaining_time.rel_value == 0) 1111 if (remaining_time.rel_value == 0)
1100 { 1112 {
1101 rh->status |= RSL_RECORD_EXPIRED; 1113 rh->status |= RSL_RECORD_EXPIRED;
1102 } 1114 }
1103 1115
1104 if (rd_count == 0) 1116 if (rd_count == 0)
1105 { 1117 {
1106 /** 1118 /**
1107 * Lookup terminated and no results 1119 * Lookup terminated and no results
1108 */ 1120 */
1109 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1121 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1110 "GNS_PHASE_REC-%d: Namestore lookup for %s terminated without results\n", 1122 "GNS_PHASE_REC-%d: Namestore lookup for %s terminated without results\n",
1111 rh->id, name); 1123 rh->id, name);
1112 1124
1113 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1125 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1114 "GNS_PHASE_REC-%d: Record %s unknown in namestore\n", 1126 "GNS_PHASE_REC-%d: Record %s unknown in namestore\n",
@@ -1122,10 +1134,10 @@ process_record_result_ns(void* cls,
1122 } 1134 }
1123 else 1135 else
1124 { 1136 {
1125 1137
1126 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1138 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1127 "GNS_PHASE_REC-%d: Processing additional result %s from namestore\n", 1139 "GNS_PHASE_REC-%d: Processing additional result %s from namestore\n",
1128 rh->id, name); 1140 rh->id, name);
1129 int i; 1141 int i;
1130 for (i=0; i<rd_count;i++) 1142 for (i=0; i<rd_count;i++)
1131 { 1143 {
@@ -1137,11 +1149,11 @@ process_record_result_ns(void* cls,
1137 (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING)) 1149 (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING))
1138 { 1150 {
1139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1151 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1140 "GNS_PHASE_REC-%d: Record %s is awaiting user confirmation. Skipping\n", 1152 "GNS_PHASE_REC-%d: Record %s is awaiting user confirmation. Skipping\n",
1141 rh->id, name); 1153 rh->id, name);
1142 continue; 1154 continue;
1143 } 1155 }
1144 1156
1145 if ((GNUNET_TIME_absolute_get_remaining (rd[i].expiration)).rel_value 1157 if ((GNUNET_TIME_absolute_get_remaining (rd[i].expiration)).rel_value
1146 == 0) 1158 == 0)
1147 { 1159 {
@@ -1150,11 +1162,11 @@ process_record_result_ns(void* cls,
1150 rh->id); 1162 rh->id);
1151 continue; 1163 continue;
1152 } 1164 }
1153 1165
1154 rh->answered++; 1166 rh->answered++;
1155 1167
1156 } 1168 }
1157 1169
1158 /** 1170 /**
1159 * no answers found 1171 * no answers found
1160 */ 1172 */
@@ -1165,7 +1177,7 @@ process_record_result_ns(void* cls,
1165 rh->proc(rh->proc_cls, rh, 0, NULL); 1177 rh->proc(rh->proc_cls, rh, 0, NULL);
1166 return; 1178 return;
1167 } 1179 }
1168 1180
1169 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1181 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1170 "GNS_PHASE_REC-%d: Found %d answer(s) to query in %d records!\n", 1182 "GNS_PHASE_REC-%d: Found %d answer(s) to query in %d records!\n",
1171 rh->id, rh->answered, rd_count); 1183 rh->id, rh->answered, rd_count);
@@ -1236,7 +1248,7 @@ process_record_result_vpn (void* cls, int af, const void *address)
1236 rh->proc (rh->proc_cls, rh, 1, &rd); 1248 rh->proc (rh->proc_cls, rh, 1, &rd);
1237 return; 1249 return;
1238 } 1250 }
1239 1251
1240 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1252 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1241 "GNS_PHASE_REC-%d: Got garbage from VPN!\n", 1253 "GNS_PHASE_REC-%d: Got garbage from VPN!\n",
1242 rh->id); 1254 rh->id);
@@ -1249,7 +1261,7 @@ process_record_result_vpn (void* cls, int af, const void *address)
1249 * 1261 *
1250 * @param rh resolver handle 1262 * @param rh resolver handle
1251 * @param rlh record lookup handle 1263 * @param rlh record lookup handle
1252 * @param rd_cound number of results 1264 * @param rd_count number of results
1253 * @param rd results 1265 * @param rd results
1254 */ 1266 */
1255static void 1267static void
@@ -1298,12 +1310,84 @@ handle_record_vpn (void* cls, struct ResolverHandle *rh,
1298/** 1310/**
1299 * Sends a UDP dns query to a nameserver specified in the rh 1311 * Sends a UDP dns query to a nameserver specified in the rh
1300 * 1312 *
1301 * @param rh the request handle 1313 * @param rh the resolver handle
1302 */ 1314 */
1303static void 1315static void
1304send_dns_packet (struct ResolverHandle *rh); 1316send_dns_packet (struct ResolverHandle *rh);
1305 1317
1318static void
1319handle_dns_resolver (void *cls,
1320 const struct sockaddr *addr,
1321 socklen_t addrlen)
1322{
1323 struct ResolverHandle *rh = cls;
1324 struct RecordLookupHandle *rlh = rh->proc_cls;
1325 struct GNUNET_NAMESTORE_RecordData rd;
1326
1327 if (NULL == addr)
1328 {
1329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1330 "No address found in DNS!\n");
1331 finish_lookup (rh, rlh, 0, NULL);
1332 free_resolver_handle (rh);
1333 return;
1334 }
1335
1336 if (addrlen == sizeof (struct sockaddr_in))
1337 rd.record_type = GNUNET_GNS_RECORD_TYPE_A;
1338 else
1339 rd.record_type = GNUNET_GNS_RECORD_AAAA;
1340
1341 rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
1342 rd.data_size = addrlen;
1343 rd.data = addr;
1344
1345 finish_lookup (rh, rlh, 1, &rd);
1346 free_resolver_handle (rh);
1347}
1348
1349/**
1350 * Resolve DNS name via local stub resolver
1351 *
1352 * @param rh the resolver handle
1353 */
1354static void
1355resolve_dns_name (struct ResolverHandle *rh)
1356{
1357 struct RecordLookupHandle *rlh = rh->proc_cls;
1358 int af;
1359
1360 if ((rlh->record_type != GNUNET_GNS_RECORD_TYPE_A) &&
1361 (rlh->record_type != GNUNET_GNS_RECORD_AAAA))
1362 {
1363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1364 "Can only resolve A/AAAA via stub... abort\n");
1365 finish_lookup (rh, rlh, 0, NULL);
1366 free_resolver_handle (rh);
1367 return;
1368 }
1369
1370 if (rlh->record_type == GNUNET_GNS_RECORD_TYPE_A)
1371 af = AF_INET;
1372 else
1373 af = AF_INET6;
1306 1374
1375 //GNUNET_RESOLVER_connect (cfg); FIXME into init
1376
1377 rh->dns_resolver_handle = GNUNET_RESOLVER_ip_get (rh->dns_name,
1378 af,
1379 rh->timeout,
1380 &handle_dns_resolver,
1381 rh);
1382}
1383
1384
1385/**
1386 * Read DNS udp packet from socket
1387 *
1388 * @param cls the resolver handle
1389 * @param tc task context
1390 */
1307static void 1391static void
1308read_dns_response (void *cls, 1392read_dns_response (void *cls,
1309 const struct GNUNET_SCHEDULER_TaskContext *tc) 1393 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -1317,7 +1401,9 @@ read_dns_response (void *cls,
1317 struct GNUNET_DNSPARSER_Packet *packet; 1401 struct GNUNET_DNSPARSER_Packet *packet;
1318 struct GNUNET_NAMESTORE_RecordData rd; 1402 struct GNUNET_NAMESTORE_RecordData rd;
1319 int found_delegation = GNUNET_NO; 1403 int found_delegation = GNUNET_NO;
1404 int found_cname = GNUNET_NO;
1320 char* delegation_name = NULL; 1405 char* delegation_name = NULL;
1406 int zone_offset = 0;
1321 int i; 1407 int i;
1322 1408
1323 rh->dns_read_task = GNUNET_SCHEDULER_NO_TASK; 1409 rh->dns_read_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1367,9 +1453,10 @@ read_dns_response (void *cls,
1367 packet->answers[i].data.hostname 1453 packet->answers[i].data.hostname
1368 ); 1454 );
1369 strcpy (rh->dns_name, packet->answers[i].data.hostname); 1455 strcpy (rh->dns_name, packet->answers[i].data.hostname);
1370 send_dns_packet (rh); 1456 found_cname = GNUNET_YES;
1371 GNUNET_DNSPARSER_free_packet (packet); 1457 //send_dns_packet (rh);
1372 return; 1458 //GNUNET_DNSPARSER_free_packet (packet);
1459 continue;
1373 } 1460 }
1374 1461
1375 if ((packet->answers[i].type == rlh->record_type) && 1462 if ((packet->answers[i].type == rlh->record_type) &&
@@ -1390,6 +1477,23 @@ read_dns_response (void *cls,
1390 } 1477 }
1391 } 1478 }
1392 1479
1480 if (GNUNET_YES == found_cname)
1481 {
1482 zone_offset = strlen (rh->dns_name) - strlen (rh->dns_zone) - 1;
1483
1484 if (0 > zone_offset)
1485 zone_offset = 0;
1486
1487 /* restart query with CNAME */
1488 if (0 == strcmp (rh->dns_name+zone_offset, rh->dns_zone))
1489 send_dns_packet (rh);
1490 else
1491 resolve_dns_name (rh);
1492
1493 GNUNET_DNSPARSER_free_packet (packet);
1494 return;
1495 }
1496
1393 for (i = 0; i < packet->num_authority_records; i++) 1497 for (i = 0; i < packet->num_authority_records; i++)
1394 { 1498 {
1395 1499
@@ -1503,6 +1607,7 @@ resolve_record_dns (struct ResolverHandle *rh,
1503 /* Synthesize dns name */ 1607 /* Synthesize dns name */
1504 if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_NS) 1608 if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_NS)
1505 { 1609 {
1610 strcpy (rh->dns_zone, (char*)rd[i].data);
1506 if (0 == strcmp (rh->name, "")) 1611 if (0 == strcmp (rh->name, ""))
1507 strcpy (rh->dns_name, (char*)rd[i].data); 1612 strcpy (rh->dns_name, (char*)rd[i].data);
1508 else 1613 else
@@ -1637,7 +1742,8 @@ resolve_record_vpn (struct ResolverHandle *rh,
1637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1638 "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR!\n", 1743 "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR!\n",
1639 rh->id); 1744 rh->id);
1640 rh->proc(rh->proc_cls, rh, 0, NULL); 1745 finish_lookup (rh, rh->proc_cls, 0, NULL);
1746 free_resolver_handle (rh);
1641 return; 1747 return;
1642 } 1748 }
1643 1749
@@ -1657,11 +1763,22 @@ resolve_record_vpn (struct ResolverHandle *rh,
1657 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1658 "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR hashes!\n", 1764 "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR hashes!\n",
1659 rh->id); 1765 rh->id);
1660 rh->proc(rh->proc_cls, rh, 0, NULL); 1766 finish_lookup (rh, rh->proc_cls, 0, NULL);
1767 free_resolver_handle (rh);
1661 return; 1768 return;
1662 } 1769 }
1663 1770
1664 rh->proc = &handle_record_vpn; 1771 rh->proc = &handle_record_vpn;
1772
1773 if (NULL == vpn_handle)
1774 {
1775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1776 "GNS_PHASE_REC_VPN-%llu: VPN not connected!\n",
1777 rh->id);
1778 finish_lookup (rh, rh->proc_cls, 0, NULL);
1779 free_resolver_handle (rh);
1780 return;
1781 }
1665 1782
1666 //FIXME timeout?? 1783 //FIXME timeout??
1667 rh->vpn_handle = GNUNET_VPN_redirect_to_peer (vpn_handle, 1784 rh->vpn_handle = GNUNET_VPN_redirect_to_peer (vpn_handle,
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index d7ad17d5f..768451205 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -142,9 +142,15 @@ struct ResolverHandle
142 /* a synthesized dns name */ 142 /* a synthesized dns name */
143 char dns_name[MAX_DNS_NAME_LENGTH]; 143 char dns_name[MAX_DNS_NAME_LENGTH];
144 144
145 /* the authoritative dns zone */
146 char dns_zone[MAX_DNS_NAME_LENGTH];
147
145 /* the address of the DNS server FIXME not needed? */ 148 /* the address of the DNS server FIXME not needed? */
146 struct sockaddr_in dns_addr; 149 struct sockaddr_in dns_addr;
147 150
151 /* handle to the local stub resolver request */
152 struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
153
148 /* select task for DNS */ 154 /* select task for DNS */
149 GNUNET_SCHEDULER_TaskIdentifier dns_read_task; 155 GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
150 156
@@ -301,6 +307,7 @@ struct GetPseuAuthorityHandle
301 * @param nh handle to the namestore 307 * @param nh handle to the namestore
302 * @param dh handle to the dht 308 * @param dh handle to the dht
303 * @param lz the local zone 309 * @param lz the local zone
310 * @param cfg configuration handle
304 * @param max_bg_queries maximum amount of background queries 311 * @param max_bg_queries maximum amount of background queries
305 * @param ignore_pending ignore records that still require user confirmation 312 * @param ignore_pending ignore records that still require user confirmation
306 * on lookup 313 * on lookup
@@ -310,6 +317,7 @@ int
310gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, 317gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
311 struct GNUNET_DHT_Handle *dh, 318 struct GNUNET_DHT_Handle *dh,
312 struct GNUNET_CRYPTO_ShortHashCode lz, 319 struct GNUNET_CRYPTO_ShortHashCode lz,
320 const struct GNUNET_CONFIGURATION_Handle *cfg,
313 unsigned long long max_bg_queries, 321 unsigned long long max_bg_queries,
314 int ignore_pending); 322 int ignore_pending);
315 323