aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns_resolver.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-14 17:34:29 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-14 17:34:29 +0000
commitec1b308bf51a46f35a234ea86ce6b2784f084add (patch)
tree77ccfabd958eb75a3e30c11740fb5dfe61ad360e /src/gns/gnunet-service-gns_resolver.c
parent8576071c0bd953da120d10df71d64bdccb4aefc8 (diff)
downloadgnunet-ec1b308bf51a46f35a234ea86ce6b2784f084add.tar.gz
gnunet-ec1b308bf51a46f35a234ea86ce6b2784f084add.zip
-old code elimination
Diffstat (limited to 'src/gns/gnunet-service-gns_resolver.c')
-rw-r--r--src/gns/gnunet-service-gns_resolver.c429
1 files changed, 6 insertions, 423 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 1519d4223..4eba4dae8 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -23,6 +23,12 @@
23 * @brief GNUnet GNS resolver logic 23 * @brief GNUnet GNS resolver logic
24 * @author Martin Schanzenbach 24 * @author Martin Schanzenbach
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 *
27 * TODO:
28 * - recurive GNS resulution
29 * - recursive DNS resolution
30 * - shortening triggers
31 * - revocation checks (privacy!?)
26 */ 32 */
27#include "platform.h" 33#include "platform.h"
28#include "gnunet_util_lib.h" 34#include "gnunet_util_lib.h"
@@ -877,300 +883,6 @@ start_shorten (const char *original_label,
877/* ************************** Resolution **************************** */ 883/* ************************** Resolution **************************** */
878 884
879#if 0 885#if 0
880/**
881 * Helper function to free resolver handle
882 *
883 * @param rh the handle to free
884 */
885static void
886free_resolver_handle (struct ResolverHandle* rh)
887{
888 struct AuthorityChain *ac;
889 struct AuthorityChain *ac_next;
890
891 if (NULL == rh)
892 return;
893
894 ac_next = rh->authority_chain_head;
895 while (NULL != (ac = ac_next))
896 {
897 ac_next = ac->next;
898 GNUNET_free (ac);
899 }
900
901 if (NULL != rh->get_handle)
902 GNUNET_DHT_get_stop (rh->get_handle);
903 if (NULL != rh->dns_raw_packet)
904 GNUNET_free (rh->dns_raw_packet);
905 if (NULL != rh->namestore_task)
906 {
907 GNUNET_NAMESTORE_cancel (rh->namestore_task);
908 rh->namestore_task = NULL;
909 }
910 if (GNUNET_SCHEDULER_NO_TASK != rh->dns_read_task)
911 GNUNET_SCHEDULER_cancel (rh->dns_read_task);
912 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
913 GNUNET_SCHEDULER_cancel (rh->timeout_task);
914 if (NULL != rh->dns_sock)
915 GNUNET_NETWORK_socket_close (rh->dns_sock);
916 if (NULL != rh->dns_resolver_handle)
917 GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle);
918 if (NULL != rh->rd.data)
919 GNUNET_free ((void*)(rh->rd.data));
920 if (NULL != rh->dht_heap_node)
921 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
922 GNUNET_free (rh);
923}
924
925
926/**
927 * Callback when record data is put into namestore
928 *
929 * @param cls the closure
930 * @param success GNUNET_OK on success
931 * @param emsg the error message. NULL if SUCCESS==GNUNET_OK
932 */
933void
934on_namestore_record_put_result (void *cls,
935 int32_t success,
936 const char *emsg)
937{
938 struct NamestoreBGTask *nbg = cls;
939
940 GNUNET_CONTAINER_heap_remove_node (nbg->node);
941 GNUNET_free (nbg);
942
943 if (GNUNET_NO == success)
944 {
945 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
946 "GNS_NS: records already in namestore\n");
947 return;
948 }
949 else if (GNUNET_YES == success)
950 {
951 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
952 "GNS_NS: records successfully put in namestore\n");
953 return;
954 }
955
956 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
957 "GNS_NS: Error putting records into namestore: %s\n", emsg);
958}
959
960
961/**
962 * Function called when we get a result from the dht
963 * for our record query
964 *
965 * @param cls the request handle
966 * @param exp lifetime
967 * @param key the key the record was stored under
968 * @param get_path get path
969 * @param get_path_length get path length
970 * @param put_path put path
971 * @param put_path_length put path length
972 * @param type the block type
973 * @param size the size of the record
974 * @param data the record data
975 */
976static void
977process_record_result_dht (void* cls,
978 struct GNUNET_TIME_Absolute exp,
979 const struct GNUNET_HashCode * key,
980 const struct GNUNET_PeerIdentity *get_path,
981 unsigned int get_path_length,
982 const struct GNUNET_PeerIdentity *put_path,
983 unsigned int put_path_length,
984 enum GNUNET_BLOCK_Type type,
985 size_t size, const void *data)
986{
987 struct ResolverHandle *rh = cls;
988 struct RecordLookupHandle *rlh = rh->proc_cls;
989 const struct GNSNameRecordBlock *nrb = data;
990 uint32_t num_records;
991 const char* name;
992 const char* rd_data;
993 uint32_t i;
994 size_t rd_size;
995
996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
997 "GNS_PHASE_REC-%llu: got dht result (size=%d)\n", rh->id, size);
998 /* stop lookup and timeout task */
999 GNUNET_DHT_get_stop (rh->get_handle);
1000 rh->get_handle = NULL;
1001 if (rh->dht_heap_node != NULL)
1002 {
1003 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
1004 rh->dht_heap_node = NULL;
1005 }
1006 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1007 {
1008 GNUNET_SCHEDULER_cancel (rh->timeout_task);
1009 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1010 }
1011 rh->get_handle = NULL;
1012 name = (const char*) &nrb[1];
1013 num_records = ntohl (nrb->rd_count);
1014 {
1015 struct GNUNET_NAMESTORE_RecordData rd[num_records];
1016 struct NamestoreBGTask *ns_heap_root;
1017 struct NamestoreBGTask *namestore_bg_task;
1018
1019 rd_data = &name[strlen (name) + 1];
1020 rd_size = size - strlen (name) - 1 - sizeof (struct GNSNameRecordBlock);
1021 if (GNUNET_SYSERR ==
1022 GNUNET_NAMESTORE_records_deserialize (rd_size,
1023 rd_data,
1024 num_records,
1025 rd))
1026 {
1027 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1028 "GNS_PHASE_REC-%llu: Error deserializing data!\n", rh->id);
1029 rh->proc (rh->proc_cls, rh, 0, NULL);
1030 return;
1031 }
1032 for (i = 0; i < num_records; i++)
1033 {
1034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1035 "GNS_PHASE_REC-%llu: Got name: %s (wanted %s)\n",
1036 rh->id, name, rh->name);
1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1038 "GNS_PHASE_REC-%llu: Got type: %d (wanted %d)\n",
1039 rh->id, rd[i].record_type, rlh->record_type);
1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1041 "GNS_PHASE_REC-%llu: Got data length: %d\n",
1042 rh->id, rd[i].data_size);
1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1044 "GNS_PHASE_REC-%llu: Got flag %d\n",
1045 rh->id, rd[i].flags);
1046
1047 if ((strcmp (name, rh->name) == 0) &&
1048 (rd[i].record_type == rlh->record_type))
1049 rh->answered++;
1050
1051 }
1052
1053 /**
1054 * FIXME check pubkey against existing key in namestore?
1055 * https://gnunet.org/bugs/view.php?id=2179
1056 */
1057 if (max_allowed_ns_tasks <=
1058 GNUNET_CONTAINER_heap_get_size (ns_task_heap))
1059 {
1060 ns_heap_root = GNUNET_CONTAINER_heap_remove_root (ns_task_heap);
1061 GNUNET_NAMESTORE_cancel (ns_heap_root->qe);
1062
1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1064 "GNS_PHASE_REC-%llu: Replacing oldest background ns task\n",
1065 rh->id);
1066 }
1067
1068 /* Save to namestore */
1069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1070 "GNS_PHASE_REC-%llu: Caching record for %s\n",
1071 rh->id, name);
1072 namestore_bg_task = GNUNET_malloc (sizeof (struct NamestoreBGTask));
1073 namestore_bg_task->qe = GNUNET_NAMESTORE_record_put (namestore_handle,
1074 &nrb->public_key,
1075 name,
1076 exp,
1077 num_records,
1078 rd,
1079 &nrb->signature,
1080 &on_namestore_record_put_result, //cont
1081 namestore_bg_task);
1082
1083 namestore_bg_task->node = GNUNET_CONTAINER_heap_insert (ns_task_heap,
1084 namestore_bg_task,
1085 GNUNET_TIME_absolute_get().abs_value_us);
1086 if (0 < rh->answered)
1087 rh->proc (rh->proc_cls, rh, num_records, rd);
1088 else
1089 rh->proc (rh->proc_cls, rh, 0, NULL);
1090 }
1091}
1092
1093
1094/**
1095 * Start DHT lookup for a (name -> query->record_type) record in
1096 * rh->authority's zone
1097 *
1098 * @param rh the pending gns query context
1099 */
1100static void
1101resolve_record_dht (struct ResolverHandle *rh)
1102{
1103 struct RecordLookupHandle *rlh = rh->proc_cls;
1104 uint32_t xquery;
1105 struct GNUNET_HashCode lookup_key;
1106 struct ResolverHandle *rh_heap_root;
1107
1108 GNUNET_GNS_get_key_for_record (rh->name, &rh->authority, &lookup_key);
1109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1110 "GNS_PHASE_REC-%llu: starting dht lookup for %s with key: %s\n",
1111 rh->id, rh->name, GNUNET_h2s (&lookup_key));
1112
1113 rh->dht_heap_node = NULL;
1114
1115 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != rh->timeout.rel_value_us)
1116 {
1117 /**
1118 * Update timeout if necessary
1119 */
1120 if (GNUNET_SCHEDULER_NO_TASK == rh->timeout_task)
1121 {
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1123 "GNS_PHASE_REC-%llu: Adjusting timeout to %s/2\n",
1124 rh->id,
1125 GNUNET_STRINGS_relative_time_to_string (rh->timeout, GNUNET_YES));
1126 /*
1127 * Set timeout for authority lookup phase to 1/2
1128 */
1129 rh->timeout_task = GNUNET_SCHEDULER_add_delayed (
1130 GNUNET_TIME_relative_divide (rh->timeout, 2),
1131 &handle_lookup_timeout,
1132 rh);
1133 }
1134 rh->timeout_cont = &dht_lookup_timeout;
1135 rh->timeout_cont_cls = rh;
1136 }
1137 else
1138 {
1139 if (max_allowed_background_queries <=
1140 GNUNET_CONTAINER_heap_get_size (dht_lookup_heap))
1141 {
1142 rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap);
1143 GNUNET_DHT_get_stop (rh_heap_root->get_handle);
1144 rh_heap_root->get_handle = NULL;
1145 rh_heap_root->dht_heap_node = NULL;
1146
1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1148 "GNS_PHASE_REC-%llu: Replacing oldest background query for %s\n",
1149 rh->id, rh_heap_root->name);
1150 rh_heap_root->proc (rh_heap_root->proc_cls,
1151 rh_heap_root,
1152 0,
1153 NULL);
1154 }
1155 rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
1156 rh,
1157 GNUNET_TIME_absolute_get ().abs_value_us);
1158 }
1159
1160 xquery = htonl (rlh->record_type);
1161
1162 GNUNET_assert (rh->get_handle == NULL);
1163 rh->get_handle = GNUNET_DHT_get_start (dht_handle,
1164 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
1165 &lookup_key,
1166 DHT_GNS_REPLICATION_LEVEL,
1167 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1168 &xquery,
1169 sizeof (xquery),
1170 &process_record_result_dht,
1171 rh);
1172
1173}
1174 886
1175 887
1176/** 888/**
@@ -1279,7 +991,6 @@ process_record_result_ns (void* cls,
1279} 991}
1280 992
1281 993
1282#ifndef WINDOWS
1283/** 994/**
1284 * VPN redirect result callback 995 * VPN redirect result callback
1285 * 996 *
@@ -1345,7 +1056,6 @@ process_record_result_vpn (void* cls, int af, const void *address)
1345 rh->id); 1056 rh->id);
1346 rh->proc (rh->proc_cls, rh, 0, NULL); 1057 rh->proc (rh->proc_cls, rh, 0, NULL);
1347} 1058}
1348#endif
1349 1059
1350 1060
1351/** 1061/**
@@ -1638,75 +1348,6 @@ resolve_record_ns(struct ResolverHandle *rh)
1638 1348
1639 1349
1640/** 1350/**
1641 * Handle timeout for DHT requests
1642 *
1643 * @param cls the request handle as closure
1644 * @param tc the task context
1645 */
1646static void
1647dht_authority_lookup_timeout (void *cls,
1648 const struct GNUNET_SCHEDULER_TaskContext *tc)
1649{
1650 struct ResolverHandle *rh = cls;
1651 struct RecordLookupHandle *rlh = rh->proc_cls;
1652 char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
1653
1654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1655 "GNS_PHASE_DELEGATE_DHT-%llu: dht lookup for query %s (%s) timed out.\n",
1656 rh->id, rh->authority_name,
1657 GNUNET_STRINGS_relative_time_to_string (rh->timeout,
1658 GNUNET_YES));
1659
1660 rh->status |= RSL_TIMED_OUT;
1661 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1662 if (NULL != rh->get_handle)
1663 {
1664 GNUNET_DHT_get_stop (rh->get_handle);
1665 rh->get_handle = NULL;
1666 }
1667 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1668 {
1669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1670 "GNS_PHASE_DELEGATE_DHT-%llu: Got shutdown\n",
1671 rh->id);
1672 rh->proc (rh->proc_cls, rh, 0, NULL);
1673 return;
1674 }
1675 if (0 == strcmp (rh->name, ""))
1676 {
1677 /*
1678 * promote authority back to name and try to resolve record
1679 */
1680 strcpy (rh->name, rh->authority_name);
1681 rh->proc (rh->proc_cls, rh, 0, NULL);
1682 return;
1683 }
1684
1685 /**
1686 * Start resolution in bg
1687 */
1688 GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
1689 "%s.%s.%s",
1690 rh->name, rh->authority_name, GNUNET_GNS_TLD);
1691 strcpy (rh->name, new_name);
1692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1693 "GNS_PHASE_DELEGATE_DHT-%llu: Starting background query for %s type %d\n",
1694 rh->id, rh->name,
1695 rlh->record_type);
1696 gns_resolver_lookup_record (rh->authority,
1697 rh->private_local_zone,
1698 rlh->record_type,
1699 new_name,
1700 NULL,
1701 GNUNET_TIME_UNIT_FOREVER_REL,
1702 GNUNET_NO,
1703 &background_lookup_result_processor,
1704 NULL);
1705 rh->proc (rh->proc_cls, rh, 0, NULL);
1706}
1707
1708
1709/**
1710 * This is a callback function that checks for key revocation 1351 * This is a callback function that checks for key revocation
1711 * 1352 *
1712 * @param cls the pending query 1353 * @param cls the pending query
@@ -1785,41 +1426,6 @@ process_pkey_revocation_result_ns (void *cls,
1785 1426
1786 1427
1787/** 1428/**
1788 * Callback when record data is put into namestore
1789 *
1790 * @param cls the closure
1791 * @param success GNUNET_OK on success
1792 * @param emsg the error message. NULL if SUCCESS==GNUNET_OK
1793 */
1794static void
1795on_namestore_delegation_put_result(void *cls,
1796 int32_t success,
1797 const char *emsg)
1798{
1799 struct NamestoreBGTask *nbg = cls;
1800
1801 GNUNET_CONTAINER_heap_remove_node (nbg->node);
1802 GNUNET_free (nbg);
1803
1804 if (GNUNET_NO == success)
1805 {
1806 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1807 "GNS_NS: records already in namestore\n");
1808 return;
1809 }
1810 else if (GNUNET_YES == success)
1811 {
1812 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1813 "GNS_NS: records successfully put in namestore\n");
1814 return;
1815 }
1816
1817 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1818 "GNS_NS: Error putting records into namestore: %s\n", emsg);
1819}
1820
1821
1822/**
1823 * Function called when we get a result from the dht 1429 * Function called when we get a result from the dht
1824 * for our query. Recursively tries to resolve authorities 1430 * for our query. Recursively tries to resolve authorities
1825 * for name in DHT. 1431 * for name in DHT.
@@ -2946,29 +2552,6 @@ process_delegation_result_ns (void* cls,
2946} 2552}
2947 2553
2948 2554
2949/**
2950 * Resolve the delegation chain for the request in our namestore
2951 * (as in, find the respective authority for the leftmost label).
2952 *
2953 * @param rh the resolver handle
2954 */
2955static void
2956resolve_delegation_ns (struct ResolverHandle *rh)
2957{
2958 pop_tld (rh->name, rh->authority_name);
2959 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2960 "GNS_PHASE_DELEGATE_NS-%llu: Finding authority for `%s' by looking up `%s' in GADS zone `%s'\n",
2961 rh->id,
2962 rh->name,
2963 rh->authority_name,
2964 GNUNET_short_h2s (&rh->authority));
2965 rh->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
2966 &rh->authority,
2967 rh->authority_name,
2968 &process_delegation_result_ns,
2969 rh);
2970}
2971
2972#endif 2555#endif
2973 2556
2974/////////////////////////////////////////////////////////////////////////////////////////////////// 2557///////////////////////////////////////////////////////////////////////////////////////////////////