aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-07 11:27:12 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-07 11:27:12 +0000
commit184b1137aeb6f6142bc19a18c8491b584f817068 (patch)
treebe06927e53886214197a25340675503352dcd2c0 /src
parentb979e0a4a72f2adc156076e3ed2d1f9fe10327e6 (diff)
downloadgnunet-184b1137aeb6f6142bc19a18c8491b584f817068.tar.gz
gnunet-184b1137aeb6f6142bc19a18c8491b584f817068.zip
-new resolver (#3), for shortening
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnunet-service-gns.c477
1 files changed, 328 insertions, 149 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index c444964f3..ec4c792a6 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -58,6 +58,9 @@ struct AuthorityChain
58 struct AuthorityChain *next; 58 struct AuthorityChain *next;
59 59
60 GNUNET_HashCode zone; 60 GNUNET_HashCode zone;
61
62 /* was the ns entry fresh */
63 int fresh;
61}; 64};
62 65
63struct GNUNET_GNS_ResolverHandle; 66struct GNUNET_GNS_ResolverHandle;
@@ -67,6 +70,12 @@ typedef void (*ResolutionResultProcessor) (void *cls,
67 uint32_t rd_count, 70 uint32_t rd_count,
68 const struct GNUNET_NAMESTORE_RecordData *rd); 71 const struct GNUNET_NAMESTORE_RecordData *rd);
69 72
73enum ResolutionStatus
74{
75 EXISTS = 1,
76 EXPIRED = 2
77};
78
70/** 79/**
71 * Handle to a currenty pending resolution 80 * Handle to a currenty pending resolution
72 */ 81 */
@@ -113,6 +122,8 @@ struct GNUNET_GNS_ResolverHandle
113 struct AuthorityChain *authority_chain_head; 122 struct AuthorityChain *authority_chain_head;
114 struct AuthorityChain *authority_chain_tail; 123 struct AuthorityChain *authority_chain_tail;
115 124
125 enum ResolutionStatus status;
126
116}; 127};
117 128
118struct ClientShortenHandle 129struct ClientShortenHandle
@@ -177,7 +188,7 @@ static int num_public_records = 3600;
177struct GNUNET_TIME_Relative dht_update_interval; 188struct GNUNET_TIME_Relative dht_update_interval;
178GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; 189GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK;
179 190
180static void resolve_name(struct GNUNET_GNS_ResolverHandle *rh); 191//static void resolve_name(struct GNUNET_GNS_ResolverHandle *rh);
181 192
182/** 193/**
183 * Reply to client with the result from our lookup. 194 * Reply to client with the result from our lookup.
@@ -473,7 +484,7 @@ process_record_dht_result(void* cls,
473 * @param name the name to query record 484 * @param name the name to query record
474 */ 485 */
475static void 486static void
476resolve_record_dht(struct GNUNET_GNS_ResolverHandle *rh) 487resolve_record_from_dht(struct GNUNET_GNS_ResolverHandle *rh)
477{ 488{
478 uint32_t xquery; 489 uint32_t xquery;
479 GNUNET_HashCode name_hash; 490 GNUNET_HashCode name_hash;
@@ -519,7 +530,7 @@ resolve_record_dht(struct GNUNET_GNS_ResolverHandle *rh)
519 * @param signature the signature of the authority for the record data 530 * @param signature the signature of the authority for the record data
520 */ 531 */
521static void 532static void
522process_record_lookup(void* cls, 533process_record_lookup_ns(void* cls,
523 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, 534 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
524 struct GNUNET_TIME_Absolute expiration, 535 struct GNUNET_TIME_Absolute expiration,
525 const char *name, unsigned int rd_count, 536 const char *name, unsigned int rd_count,
@@ -536,32 +547,34 @@ process_record_lookup(void* cls,
536 &zone); 547 &zone);
537 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); 548 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
538 549
550 rh->status = 0;
551
552 if (name != NULL)
553 {
554 rh->status |= EXISTS;
555 }
556
557 if (remaining_time.rel_value == 0)
558 {
559 rh->status |= EXPIRED;
560 }
561
539 if (rd_count == 0) 562 if (rd_count == 0)
540 { 563 {
541 /** 564 /**
542 * Lookup terminated and no results 565 * Lookup terminated and no results
543 * -> DHT Phase unless data is recent
544 */ 566 */
545 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 567 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
546 "Namestore lookup for %s terminated without results\n", name); 568 "Namestore lookup for %s terminated without results\n", name);
547 569
548 /**
549 * Not our root and no record found. Try dht if expired
550 */
551 if ((0 != GNUNET_CRYPTO_hash_cmp(&rh->authority, &zone_hash)) &&
552 ((name == NULL) || (remaining_time.rel_value != 0)))
553 {
554 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
555 "Record %s unknown in namestore, trying dht\n",
556 rh->name);
557 resolve_record_dht(rh);
558 return;
559 }
560 570
571
572 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
573 "Record %s unknown in namestore\n",
574 rh->name);
561 /** 575 /**
562 * Our zone and no result? Cannot resolve TT 576 * Our zone and no result? Cannot resolve TT
563 */ 577 */
564 GNUNET_assert(rh->answered == 0);
565 rh->proc(rh->proc_cls, rh, 0, NULL); 578 rh->proc(rh->proc_cls, rh, 0, NULL);
566 return; 579 return;
567 580
@@ -607,7 +620,6 @@ process_record_lookup(void* cls,
607 } 620 }
608} 621}
609 622
610
611/** 623/**
612 * The final phase of resolution. 624 * The final phase of resolution.
613 * This is a name that is canonical and we do not have a delegation. 625 * This is a name that is canonical and we do not have a delegation.
@@ -615,7 +627,7 @@ process_record_lookup(void* cls,
615 * @param rh the pending lookup 627 * @param rh the pending lookup
616 */ 628 */
617static void 629static void
618resolve_record(struct GNUNET_GNS_ResolverHandle *rh) 630resolve_record_from_ns(struct GNUNET_GNS_ResolverHandle *rh)
619{ 631{
620 632
621 /** 633 /**
@@ -628,7 +640,7 @@ resolve_record(struct GNUNET_GNS_ResolverHandle *rh)
628 &rh->authority, 640 &rh->authority,
629 rh->name, 641 rh->name,
630 rh->query->type, 642 rh->query->type,
631 &process_record_lookup, 643 &process_record_lookup_ns,
632 rh); 644 rh);
633 645
634} 646}
@@ -657,14 +669,12 @@ dht_authority_lookup_timeout(void *cls,
657 * promote authority back to name and try to resolve record 669 * promote authority back to name and try to resolve record
658 */ 670 */
659 strcpy(rh->name, rh->authority_name); 671 strcpy(rh->name, rh->authority_name);
660 resolve_record(rh);
661 }
662 else
663 {
664 rh->proc(rh->proc_cls, rh, 0, NULL);
665 } 672 }
673 rh->proc(rh->proc_cls, rh, 0, NULL);
666} 674}
667 675
676// Prototype
677static void resolve_delegation_from_dht(struct GNUNET_GNS_ResolverHandle *rh);
668 678
669/** 679/**
670 * Function called when we get a result from the dht 680 * Function called when we get a result from the dht
@@ -786,33 +796,199 @@ process_authority_dht_result(void* cls,
786 rh->answered = 0; 796 rh->answered = 0;
787 /* delegate */ 797 /* delegate */
788 if (strcmp(rh->name, "") == 0) 798 if (strcmp(rh->name, "") == 0)
789 resolve_record(rh); 799 rh->proc(rh->proc_cls, rh, 0, NULL);
790 else 800 else
791 resolve_name(rh); 801 resolve_delegation_from_dht(rh);
792 return; 802 return;
793 } 803 }
794 804
795 /* resolve */ 805 /* resolve never get here, should timeout??*/
806
807
796 if (strcmp(rh->name, "") == 0) 808 if (strcmp(rh->name, "") == 0)
797 { 809 {
798 /* promote authority back to name */ 810 /* promote authority back to name */
799 strcpy(rh->name, rh->authority_name); 811 strcpy(rh->name, rh->authority_name);
800 resolve_record(rh);
801 return;
802 } 812 }
803 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No authority in records\n"); 813 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No authority in records\n");
804 rh->proc(rh->proc_cls, rh, 0, NULL); 814 rh->proc(rh->proc_cls, rh, 0, NULL);
805} 815}
806 816
817
818/**
819 * DHT lookup result for record.
820 *
821 * @param cls the closure
822 * @param rh resolver handle
823 * @param rd_count number of results (always 0)
824 * @param rd record data (always NULL)
825 */
826static void
827process_record_result_dht(void* cls, struct GNUNET_GNS_ResolverHandle *rh,
828 unsigned int rd_count,
829 const struct GNUNET_NAMESTORE_RecordData *rd)
830{
831 if (rd_count == 0)
832 {
833 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
834 "No records for %s found in DHT. Aborting\n",
835 rh->name);
836 /* give up, cannot resolve */
837 reply_to_dns(NULL, rh, 0, NULL);
838 return;
839 }
840
841 /* results found yay */
842 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
843 "Record resolved from namestore!");
844 reply_to_dns(NULL, rh, rd_count, rd);
845
846}
847
848
849/**
850 * Namestore lookup result for record.
851 *
852 * @param cls the closure
853 * @param rh resolver handle
854 * @param rd_count number of results (always 0)
855 * @param rd record data (always NULL)
856 */
857static void
858process_record_result_ns(void* cls, struct GNUNET_GNS_ResolverHandle *rh,
859 unsigned int rd_count,
860 const struct GNUNET_NAMESTORE_RecordData *rd)
861{
862 if (rd_count == 0)
863 {
864 /* ns entry expired. try dht */
865 if (rh->status & (EXPIRED | !EXISTS))
866 {
867 rh->proc = &process_record_result_dht;
868 resolve_record_from_dht(rh);
869 return;
870 }
871 /* give up, cannot resolve */
872 reply_to_dns(NULL, rh, 0, NULL);
873 return;
874 }
875
876 /* results found yay */
877 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
878 "Record resolved from namestore!");
879 reply_to_dns(NULL, rh, rd_count, rd);
880
881}
882
883
884/**
885 * Determine if this name is canonical.
886 * i.e.
887 * a.b.gnunet = not canonical
888 * a = canonical
889 *
890 * @param name the name to test
891 * @return 1 if canonical
892 */
893static int
894is_canonical(char* name)
895{
896 uint32_t len = strlen(name);
897 int i;
898
899 for (i=0; i<len; i++)
900 {
901 if (*(name+i) == '.')
902 return 0;
903 }
904 return 1;
905}
906
907/**
908 * Move one level up in the domain hierarchy and return the
909 * passed top level domain.
910 *
911 * @param name the domain
912 * @param dest the destination where the tld will be put
913 */
914void
915pop_tld(char* name, char* dest)
916{
917 uint32_t len;
918
919 if (is_canonical(name))
920 {
921 strcpy(dest, name);
922 strcpy(name, "");
923 return;
924 }
925
926 for (len = strlen(name); len > 0; len--)
927 {
928 if (*(name+len) == '.')
929 break;
930 }
931
932 //Was canonical?
933 if (len == 0)
934 return;
935
936 name[len] = '\0';
937
938 strcpy(dest, (name+len+1));
939}
940
941/**
942 * Namestore resolution for delegation finished. Processing result.
943 *
944 * @param cls the closure
945 * @param rh resolver handle
946 * @param rd_count number of results (always 0)
947 * @param rd record data (always NULL)
948 */
949static void
950process_dht_delegation_dns(void* cls, struct GNUNET_GNS_ResolverHandle *rh,
951 unsigned int rd_count,
952 const struct GNUNET_NAMESTORE_RecordData *rd)
953{
954 if (strcmp(rh->name, "") == 0)
955 {
956 /* We resolved full name for delegation. resolving record */
957 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
958 "Resolved full name for delegation via DHT. resolving record '' in ns\n");
959 rh->proc = &process_record_result_ns;
960 resolve_record_from_ns(rh);
961 return;
962 }
963
964 /**
965 * we still have some left
966 **/
967 if (is_canonical(rh->name))
968 {
969 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
970 "Resolving canonical record %s in ns\n", rh->name);
971 rh->proc = &process_record_result_ns;
972 resolve_record_from_ns(rh);
973 return;
974 }
975 /* give up, cannot resolve */
976 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
977 "Cannot fully resolve delegation for %s via DHT!\n",
978 rh->name);
979 reply_to_dns(NULL, rh, 0, NULL);
980}
981
982
807/** 983/**
808 * Start DHT lookup for a name -> PKEY (compare NS) record in 984 * Start DHT lookup for a name -> PKEY (compare NS) record in
809 * query->authority's zone 985 * rh->authority's zone
810 * 986 *
811 * @param rh the pending gns query 987 * @param rh the pending gns query
812 * @param name the name of the PKEY record 988 * @param name the name of the PKEY record
813 */ 989 */
814static void 990static void
815resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh) 991resolve_delegation_from_dht(struct GNUNET_GNS_ResolverHandle *rh)
816{ 992{
817 uint32_t xquery; 993 uint32_t xquery;
818 GNUNET_HashCode name_hash; 994 GNUNET_HashCode name_hash;
@@ -842,6 +1018,64 @@ resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh)
842 1018
843} 1019}
844 1020
1021
1022/**
1023 * Namestore resolution for delegation finished. Processing result.
1024 *
1025 * @param cls the closure
1026 * @param rh resolver handle
1027 * @param rd_count number of results (always 0)
1028 * @param rd record data (always NULL)
1029 */
1030static void
1031process_ns_delegation_dns(void* cls, struct GNUNET_GNS_ResolverHandle *rh,
1032 unsigned int rd_count,
1033 const struct GNUNET_NAMESTORE_RecordData *rd)
1034{
1035 if (strcmp(rh->name, "") == 0)
1036 {
1037 /* We resolved full name for delegation. resolving record */
1038 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1039 "Resolved full name for delegation. resolving record ''\n");
1040 rh->proc = &process_record_result_ns;
1041 resolve_record_from_ns(rh);
1042 return;
1043 }
1044
1045 /**
1046 * we still have some left
1047 * check if ns entry is fresh
1048 **/
1049 if (rh->status & (EXISTS | !EXPIRED))
1050 {
1051 if (is_canonical(rh->name))
1052 {
1053 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1054 "Resolving canonical record %s\n", rh->name);
1055 rh->proc = &process_record_result_ns;
1056 resolve_record_from_ns(rh);
1057 }
1058 else
1059 {
1060 /* give up, cannot resolve */
1061 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1062 "Cannot fully resolve delegation for %s!\n",
1063 rh->name);
1064 reply_to_dns(NULL, rh, 0, NULL);
1065 }
1066 return;
1067 }
1068
1069 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1070 "Trying to resolve delegation for %s via DHT\n",
1071 rh->name);
1072 rh->proc = &process_dht_delegation_dns;
1073 resolve_delegation_from_dht(rh);
1074}
1075
1076//Prototype
1077static void resolve_delegation_from_ns(struct GNUNET_GNS_ResolverHandle *rh);
1078
845/** 1079/**
846 * This is a callback function that should give us only PKEY 1080 * This is a callback function that should give us only PKEY
847 * records. Used to query the namestore for the authority (PKEY) 1081 * records. Used to query the namestore for the authority (PKEY)
@@ -856,7 +1090,7 @@ resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh)
856 * @param signature the signature of the authority for the record data 1090 * @param signature the signature of the authority for the record data
857 */ 1091 */
858static void 1092static void
859process_authority_lookup(void* cls, 1093process_authority_lookup_ns(void* cls,
860 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, 1094 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
861 struct GNUNET_TIME_Absolute expiration, 1095 struct GNUNET_TIME_Absolute expiration,
862 const char *name, 1096 const char *name,
@@ -867,6 +1101,7 @@ process_authority_lookup(void* cls,
867 struct GNUNET_GNS_ResolverHandle *rh; 1101 struct GNUNET_GNS_ResolverHandle *rh;
868 struct GNUNET_TIME_Relative remaining_time; 1102 struct GNUNET_TIME_Relative remaining_time;
869 GNUNET_HashCode zone; 1103 GNUNET_HashCode zone;
1104 char* new_name;
870 1105
871 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %d records from authority lookup\n", 1106 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %d records from authority lookup\n",
872 rd_count); 1107 rd_count);
@@ -877,6 +1112,18 @@ process_authority_lookup(void* cls,
877 &zone); 1112 &zone);
878 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); 1113 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
879 1114
1115 rh->status = 0;
1116
1117 if (name != NULL)
1118 {
1119 rh->status |= EXISTS;
1120 }
1121
1122 if (remaining_time.rel_value == 0)
1123 {
1124 rh->status |= EXPIRED;
1125 }
1126
880 /** 1127 /**
881 * No authority found in namestore. 1128 * No authority found in namestore.
882 */ 1129 */
@@ -884,65 +1131,35 @@ process_authority_lookup(void* cls,
884 { 1131 {
885 /** 1132 /**
886 * We did not find an authority in the namestore 1133 * We did not find an authority in the namestore
887 * _IF_ the current authoritative zone is us we cannot resolve
888 * _ELSE_ we can still check the _expired_ dht
889 */ 1134 */
890 1135
891 /** 1136 /**
892 * No PKEY in our root. Try to resolve actual type in our zone 1137 * No PKEY in zone.
893 * if name is canonical. Else we cannot resolve. 1138 * Promote this authority back to a name maybe it is
1139 * our record.
894 */ 1140 */
895 if (0 == GNUNET_CRYPTO_hash_cmp(&rh->authority, &zone_hash)) 1141 if (strcmp(rh->name, "") == 0)
896 { 1142 {
897 if (strcmp(rh->name, "") == 0) 1143 /* simply promote back */
898 { 1144 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
899 /** 1145 "Promoting %s back to name\n", rh->authority_name);
900 * Promote this authority back to a name 1146 strcpy(rh->name, rh->authority_name);
901 */
902 strcpy(rh->name, rh->authority_name);
903 resolve_record(rh);
904 return;
905 }
906 else
907 {
908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
909 "Authority %s for %s unknown in namestore, cannot resolve\n",
910 rh->authority_name, rh->name);
911 }
912 rh->proc(rh->proc_cls, rh, 0, NULL);
913 return;
914 } 1147 }
915 1148 else
916 /**
917 * Not our root and no PKEY found. Try dht if expired
918 * FIXME only do when expired?
919 */
920 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "AAAA %d\n", remaining_time.rel_value);
921 if ((0 != GNUNET_CRYPTO_hash_cmp(&rh->authority, &zone_hash)))
922 { 1149 {
923 if (strcmp(rh->name, "") == 0) 1150 /* add back to existing name */
924 { 1151 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
925 /** 1152 "Adding %s back to %s\n",
926 * Promote this authority back to a name 1153 rh->authority_name, rh->name);
927 */ 1154 new_name = GNUNET_malloc(strlen(rh->name)
928 strcpy(rh->name, rh->authority_name); 1155 + strlen(rh->authority_name) + 2);
929 resolve_record(rh); 1156 memset(new_name, 0, strlen(rh->name) + strlen(rh->authority_name) + 2);
930 } 1157 strcpy(new_name, rh->name);
931 else 1158 strcpy(new_name+strlen(new_name)+1, ".");
932 { 1159 strcpy(new_name+strlen(new_name)+2, rh->authority_name);
933 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1160 GNUNET_free(rh->name);
934 "Authority %s for %s unknown in namestore, trying dht\n", 1161 rh->name = new_name;
935 rh->authority_name, rh->name);
936 resolve_authority_dht(rh);
937 }
938 return;
939 } 1162 }
940
941 /**
942 * Not our root and not expired or no records. Cannot resolve
943 */
944 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Authority %s unknown\n",
945 rh->authority_name);
946 rh->proc(rh->proc_cls, rh, 0, NULL); 1163 rh->proc(rh->proc_cls, rh, 0, NULL);
947 return; 1164 return;
948 } 1165 }
@@ -966,8 +1183,9 @@ process_authority_lookup(void* cls,
966 if (remaining_time.rel_value == 0) 1183 if (remaining_time.rel_value == 0)
967 { 1184 {
968 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1185 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
969 "This dht entry is expired. Refreshing\n"); 1186 "This dht entry is expired.\n");
970 resolve_authority_dht(rh); 1187 rh->authority_chain_head->fresh = 0;
1188 rh->proc(rh->proc_cls, rh, 0, NULL);
971 return; 1189 return;
972 } 1190 }
973 1191
@@ -986,9 +1204,9 @@ process_authority_lookup(void* cls,
986 auth); 1204 auth);
987 1205
988 if (strcmp(rh->name, "") == 0) 1206 if (strcmp(rh->name, "") == 0)
989 resolve_record(rh); 1207 rh->proc(rh->proc_cls, rh, 0, NULL);
990 else 1208 else
991 resolve_name(rh); 1209 resolve_delegation_from_ns(rh);
992 return; 1210 return;
993 } 1211 }
994 1212
@@ -1001,74 +1219,33 @@ process_authority_lookup(void* cls,
1001} 1219}
1002 1220
1003 1221
1004/**
1005 * Determine if this name is canonical.
1006 * i.e.
1007 * a.b.gnunet = not canonical
1008 * a = canonical
1009 *
1010 * @param name the name to test
1011 * @return 1 if canonical
1012 */
1013static int
1014is_canonical(char* name)
1015{
1016 uint32_t len = strlen(name);
1017 int i;
1018
1019 for (i=0; i<len; i++)
1020 {
1021 if (*(name+i) == '.')
1022 return 0;
1023 }
1024 return 1;
1025}
1026 1222
1027/** 1223/**
1028 * Move one level up in the domain hierarchy and return the 1224 * The first phase of resolution.
1029 * passed top level domain. 1225 * First check if the name is canonical.
1226 * If it is then try to resolve directly.
1227 * If not then we first have to resolve the authoritative entities.
1030 * 1228 *
1031 * @param name the domain 1229 * @param rh the pending lookup
1032 * @param dest the destination where the tld will be put
1033 */ 1230 */
1034void 1231/*static void
1035pop_tld(char* name, char* dest) 1232resolve_name(struct GNUNET_GNS_ResolverHandle *rh)
1036{ 1233{
1037 uint32_t len;
1038
1039 if (is_canonical(name))
1040 {
1041 strcpy(dest, name);
1042 strcpy(name, "");
1043 return;
1044 }
1045
1046 for (len = strlen(name); len > 0; len--)
1047 {
1048 if (*(name+len) == '.')
1049 break;
1050 }
1051 1234
1052 //Was canonical? 1235 pop_tld(rh->name, rh->authority_name);
1053 if (len == 0) 1236 GNUNET_NAMESTORE_lookup_record(namestore_handle,
1054 return; 1237 &rh->authority,
1238 rh->authority_name,
1239 GNUNET_GNS_RECORD_PKEY,
1240 &process_authority_lookup,
1241 rh);
1055 1242
1056 name[len] = '\0'; 1243}*/
1057 1244
1058 strcpy(dest, (name+len+1));
1059}
1060 1245
1061 1246
1062/**
1063 * The first phase of resolution.
1064 * First check if the name is canonical.
1065 * If it is then try to resolve directly.
1066 * If not then we first have to resolve the authoritative entities.
1067 *
1068 * @param rh the pending lookup
1069 */
1070static void 1247static void
1071resolve_name(struct GNUNET_GNS_ResolverHandle *rh) 1248resolve_delegation_from_ns(struct GNUNET_GNS_ResolverHandle *rh)
1072{ 1249{
1073 1250
1074 /** 1251 /**
@@ -1079,7 +1256,7 @@ resolve_name(struct GNUNET_GNS_ResolverHandle *rh)
1079 &rh->authority, 1256 &rh->authority,
1080 rh->authority_name, 1257 rh->authority_name,
1081 GNUNET_GNS_RECORD_PKEY, 1258 GNUNET_GNS_RECORD_PKEY,
1082 &process_authority_lookup, 1259 &process_authority_lookup_ns,
1083 rh); 1260 rh);
1084 1261
1085} 1262}
@@ -1107,7 +1284,7 @@ start_resolution_from_dns(struct GNUNET_DNS_RequestHandle *request,
1107 rh->packet = p; 1284 rh->packet = p;
1108 rh->query = q; 1285 rh->query = q;
1109 rh->authority = zone_hash; 1286 rh->authority = zone_hash;
1110 rh->proc = &reply_to_dns; 1287
1111 1288
1112 rh->name = GNUNET_malloc(strlen(q->name) 1289 rh->name = GNUNET_malloc(strlen(q->name)
1113 - strlen(gnunet_tld) + 1); 1290 - strlen(gnunet_tld) + 1);
@@ -1125,7 +1302,9 @@ start_resolution_from_dns(struct GNUNET_DNS_RequestHandle *request,
1125 rh->authority_chain_head->zone = zone_hash; 1302 rh->authority_chain_head->zone = zone_hash;
1126 1303
1127 /* Start resolution in our zone */ 1304 /* Start resolution in our zone */
1128 resolve_name(rh); 1305 rh->proc = &process_ns_delegation_dns;
1306 resolve_delegation_from_ns(rh);
1307 //resolve_name(rh);
1129} 1308}
1130 1309
1131/** 1310/**
@@ -1494,7 +1673,7 @@ shorten_name(char* name, struct ClientShortenHandle* csh)
1494 rh->proc_cls = (void*)csh; 1673 rh->proc_cls = (void*)csh;
1495 1674
1496 /* Start resolution in our zone */ 1675 /* Start resolution in our zone */
1497 resolve_name(rh); 1676 //resolve_name(rh);
1498 1677
1499} 1678}
1500 1679