2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
17 * @file gns/gnunet-service-gns_resolver.c
18 * @brief GNU Name System resolver logic
19 * @author Martin Schanzenbach
20 * @author Christian Grothoff
23 #include "gnunet_util_lib.h"
24 #include "gnunet_dnsstub_lib.h"
25 #include "gnunet_dht_service.h"
26 #include "gnunet_gnsrecord_lib.h"
27 #include "gnunet_namecache_service.h"
28 #include "gnunet_dns_service.h"
29 #include "gnunet_resolver_service.h"
30 #include "gnunet_revocation_service.h"
31 #include "gnunet_dnsparser_lib.h"
32 #include "gnunet_tun_lib.h"
33 #include "gnunet_gns_service.h"
35 #include "gnunet-service-gns.h"
36 #include "gnunet-service-gns_resolver.h"
37 #include "gnunet_vpn_service.h"
41 * Default DHT timeout for lookups.
43 #define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
46 * Default timeout for DNS lookups.
48 #define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
51 * Default timeout for VPN redirections.
53 #define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
56 * DHT replication level
58 #define DHT_GNS_REPLICATION_LEVEL 10
61 * How deep do we allow recursions to go before we abort?
63 #define MAX_RECURSION 256
67 * DLL to hold the authority chain we had to pass in the resolution
70 struct AuthorityChain;
74 * Element of a resolution process for looking up the
75 * responsible DNS server hostname in a GNS2DNS recursive
84 struct Gns2DnsPending *next;
89 struct Gns2DnsPending *prev;
92 * Context this activity belongs with.
94 struct AuthorityChain *ac;
97 * Handle for the resolution of the IP part of the
98 * GNS2DNS record. Will return to us the addresses
99 * of the DNS resolver to use.
101 struct GNS_ResolverHandle *rh;
104 * Handle for DNS resolution of the DNS nameserver.
106 struct GNUNET_RESOLVER_RequestHandle *dns_rh;
109 * How many results did we get?
111 unsigned int num_results;
116 * Handle to a currenty pending resolution. On result (positive or
117 * negative) the #GNS_ResultProcessor is called.
119 struct GNS_ResolverHandle;
123 * DLL to hold the authority chain we had to pass in the resolution
126 struct AuthorityChain
131 struct AuthorityChain *prev;
136 struct AuthorityChain *next;
139 * Resolver handle this entry in the chain belongs to.
141 struct GNS_ResolverHandle *rh;
144 * label/name corresponding to the authority
149 * #GNUNET_YES if the authority was a GNS authority,
150 * #GNUNET_NO if the authority was a DNS authority.
155 * Information about the resolver authority for this label.
161 * The zone of the GNS authority
163 struct GNUNET_CRYPTO_EcdsaPublicKey gns_authority;
168 * Domain of the DNS resolver that is the authority.
169 * (appended to construct the DNS name to resolve;
170 * this is NOT the DNS name of the DNS server!).
172 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1];
175 * List of resolutions of the 'ip' of the name server that
178 struct Gns2DnsPending *gp_head;
181 * Tail of list of resolutions of the 'ip' of the name server that
184 struct Gns2DnsPending *gp_tail;
187 * Handle to perform DNS lookups with this authority (in GNS2DNS handling).
189 struct GNUNET_DNSSTUB_Context *dns_handle;
192 * Did we succeed in getting an IP address for *any* of the DNS servers listed?
193 * Once we do, we can start with DNS queries.
198 * Did we start the recursive resolution via DNS?
210 * A result we got from DNS.
218 struct DnsResult *next;
223 struct DnsResult *prev;
226 * Binary value stored in the DNS record (appended to this struct)
231 * Expiration time for the DNS record, 0 if we didn't
232 * get anything useful (i.e. 'gethostbyname()' was used).
234 uint64_t expiration_time;
237 * Number of bytes in @e data.
242 * Type of the GNS/DNS record.
244 uint32_t record_type;
250 * Closure for #vpn_allocation_cb.
256 * Which resolution process are we processing.
258 struct GNS_ResolverHandle *rh;
261 * Handle to the VPN request that we were performing.
263 struct GNUNET_VPN_RedirectionRequest *vpn_request;
266 * Number of records serialized in @e rd_data.
268 unsigned int rd_count;
271 * Serialized records.
276 * Number of bytes in @e rd_data.
278 ssize_t rd_data_size;
283 * Handle to a currenty pending resolution. On result (positive or
284 * negative) the #GNS_ResultProcessor is called.
286 struct GNS_ResolverHandle
292 struct GNS_ResolverHandle *next;
297 struct GNS_ResolverHandle *prev;
300 * The top-level GNS authoritative zone to query
302 struct GNUNET_CRYPTO_EcdsaPublicKey authority_zone;
305 * called when resolution phase finishes
307 GNS_ResultProcessor proc;
310 * closure passed to @e proc
315 * Handle for DHT lookups. should be NULL if no lookups are in progress
317 struct GNUNET_DHT_GetHandle *get_handle;
320 * Handle to a VPN request, NULL if none is active.
322 struct VpnContext *vpn_ctx;
325 * Socket for a DNS request, NULL if none is active.
327 struct GNUNET_DNSSTUB_RequestSocket *dns_request;
330 * Handle for standard DNS resolution, NULL if none is active.
332 struct GNUNET_RESOLVER_RequestHandle *std_resolve;
335 * Pending Namecache lookup task
337 struct GNUNET_NAMECACHE_QueueEntry *namecache_qe;
340 * Pending revocation check.
342 struct GNUNET_REVOCATION_Query *rev_check;
345 * Heap node associated with this lookup. Used to limit number of
346 * concurrent requests.
348 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
351 * DLL to store the authority chain
353 struct AuthorityChain *ac_head;
356 * DLL to store the authority chain
358 struct AuthorityChain *ac_tail;
361 * ID of a task associated with the resolution process.
363 struct GNUNET_SCHEDULER_Task *task_id;
366 * The name to resolve
371 * DLL of results we got from DNS.
373 struct DnsResult *dns_result_head;
376 * DLL of results we got from DNS.
378 struct DnsResult *dns_result_tail;
381 * Current offset in 'name' where we are resolving.
383 size_t name_resolution_pos;
388 enum GNUNET_GNS_LocalOptions options;
391 * For SRV and TLSA records, the number of the
392 * protocol specified in the name. 0 if no protocol was given.
397 * For SRV and TLSA records, the number of the
398 * service specified in the name. 0 if no service was given.
403 * Desired type for the resolution.
408 * We increment the loop limiter for each step in a recursive
409 * resolution. If it passes our threshold (i.e. due to
410 * self-recursion in the resolution, i.e CNAME fun), we stop.
412 unsigned int loop_limiter;
415 * 16 bit random ID we used in the @e dns_request.
417 uint16_t original_dns_id;
423 * Active namestore caching operations.
429 * Organized in a DLL.
431 struct CacheOps *next;
434 * Organized in a DLL.
436 struct CacheOps *prev;
439 * Pending Namestore caching task.
441 struct GNUNET_NAMECACHE_QueueEntry *namecache_qe_cache;
447 * Our handle to the namecache service
449 static struct GNUNET_NAMECACHE_Handle *namecache_handle;
452 * Our handle to the vpn service
454 static struct GNUNET_VPN_Handle *vpn_handle;
457 * Resolver handle to the dht
459 static struct GNUNET_DHT_Handle *dht_handle;
462 * Heap for limiting parallel DHT lookups
464 static struct GNUNET_CONTAINER_Heap *dht_lookup_heap;
467 * Maximum amount of parallel queries to the DHT
469 static unsigned long long max_allowed_background_queries;
472 * Head of resolver lookup list
474 static struct GNS_ResolverHandle *rlh_head;
477 * Tail of resolver lookup list
479 static struct GNS_ResolverHandle *rlh_tail;
482 * Organized in a DLL.
484 static struct CacheOps *co_head;
487 * Organized in a DLL.
489 static struct CacheOps *co_tail;
494 static int disable_cache;
497 * Global configuration.
499 static const struct GNUNET_CONFIGURATION_Handle *cfg;
503 * Determine if this name is canonical (is a legal name in a zone, without delegation);
504 * note that we do not test that the name does not contain illegal characters, we only
505 * test for delegation. Note that service records (i.e. _foo._srv) are canonical names
506 * even though they consist of multiple labels.
509 * a.b.gnu = not canonical
511 * _foo._srv = canonical
512 * _f.bar = not canonical
514 * @param name the name to test
515 * @return #GNUNET_YES if canonical
517 /* dead, but keep for now */ int
518 is_canonical (const char *name)
523 if (NULL == strchr (name,
524 (unsigned char) '.'))
529 while (NULL != (dot = strchr (pos,
530 (unsigned char) '.')))
538 /* ************************** Resolution **************************** */
541 * Expands a name ending in .+ with the zone of origin.
543 * @param rh resolution context
544 * @param name name to modify (to be free'd or returned)
545 * @return updated name
548 translate_dot_plus (struct GNS_ResolverHandle *rh,
552 size_t s_len = strlen (name);
554 if (0 != strcmp (&name[s_len - 2],
556 return name; /* did not end in ".+" */
557 GNUNET_assert (GNUNET_YES == rh->ac_tail->gns_authority);
558 GNUNET_asprintf (&ret,
562 GNUNET_GNSRECORD_pkey_to_zkey (&rh->ac_tail->authority_info.gns_authority));
569 * Wrapper around #GNS_resolver_lookup_cancel() as a task.
570 * Used for delayed cleanup so we can unwind the stack first.
572 * @param cls the `struct GNS_ResolverHandle`
575 GNS_resolver_lookup_cancel_ (void *cls)
577 struct GNS_ResolverHandle *rh = cls;
580 GNS_resolver_lookup_cancel (rh);
585 * Function called to asynchronously fail a resolution.
587 * @param rh the resolution to fail
590 fail_resolution (struct GNS_ResolverHandle *rh)
592 rh->proc (rh->proc_cls,
595 GNUNET_assert (NULL == rh->task_id);
596 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
602 * Function called when a resolution times out.
604 * @param cls the `struct GNS_ResolverHandle`
607 timeout_resolution (void *cls)
609 struct GNS_ResolverHandle *rh = cls;
612 fail_resolution (rh);
616 #if (defined WINDOWS) || (defined DARWIN)
617 /* Don't have this on W32, here's a naive implementation
618 * Was somehow removed on OS X ... */
620 memrchr (const void *s,
624 const unsigned char *ucs = s;
627 for (i = n - 1; i >= 0; i--)
628 if (c == (int) ucs[i])
629 return (void *) &ucs[i];
636 * Get the next, rightmost label from the name that we are trying to resolve,
637 * and update the resolution position accordingly. Labels usually consist
638 * of up to 63 characters without a period ("."); however, we use a special
639 * convention to support SRV and TLSA records where the domain name
640 * includes an encoding for a service and protocol in the name. The
641 * syntax (see RFC 2782) here is "_Service._Proto.Name" and in this
642 * special case we include the "_Service._Proto" in the rightmost label.
643 * Thus, for "_443._tcp.foo.bar" we first return the label "bar" and then
644 * the label "_443._tcp.foo". The special case is detected by the
645 * presence of labels beginning with an underscore. Whenever a label
646 * begins with an underscore, it is combined with the label to its right
647 * (and the "." is preserved).
649 * @param rh handle to the resolution operation to get the next label from
650 * @return NULL if there are no more labels
653 resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh)
664 if (0 == rh->name_resolution_pos)
666 dot = memrchr (rh->name,
668 rh->name_resolution_pos);
671 /* done, this was the last one */
672 len = rh->name_resolution_pos;
674 rh->name_resolution_pos = 0;
678 /* advance by one label */
679 len = rh->name_resolution_pos - (dot - rh->name) - 1;
681 rh->name_resolution_pos = dot - rh->name;
685 ret = GNUNET_strndup (rp, len);
686 /* If we have labels starting with underscore with label on
687 * the right (SRV/DANE/BOX case), determine port/protocol;
688 * The format of `rh->name` must be "_PORT._PROTOCOL".
690 if ( ('_' == rh->name[0]) &&
691 (NULL != (dot = memrchr (rh->name,
693 rh->name_resolution_pos))) &&
695 (NULL == memrchr (rh->name,
699 srv_name = GNUNET_strndup (&rh->name[1],
700 (dot - rh->name) - 1);
701 proto_name = GNUNET_strndup (&dot[2],
702 rh->name_resolution_pos - (dot - rh->name) - 1);
703 rh->name_resolution_pos = 0;
704 pe = getprotobyname (proto_name);
707 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
708 _("Protocol `%s' unknown, skipping labels.\n"),
710 GNUNET_free (proto_name);
711 GNUNET_free (srv_name);
714 se = getservbyname (srv_name,
718 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
719 _("Service `%s' unknown for protocol `%s', skipping labels.\n"),
722 GNUNET_free (proto_name);
723 GNUNET_free (srv_name);
726 rh->protocol = pe->p_proto;
727 rh->service = se->s_port;
728 GNUNET_free (proto_name);
729 GNUNET_free (srv_name);
736 * Gives the cummulative result obtained to the callback and clean up the request.
738 * @param rh resolution process that has culminated in a result
741 transmit_lookup_dns_result (struct GNS_ResolverHandle *rh)
743 struct DnsResult *pos;
748 for (pos = rh->dns_result_head; NULL != pos; pos = pos->next)
751 struct GNUNET_GNSRECORD_Data rd[n];
754 for (pos = rh->dns_result_head; NULL != pos; pos = pos->next)
756 rd[i].data = pos->data;
757 rd[i].data_size = pos->data_size;
758 rd[i].record_type = pos->record_type;
759 if (0 == pos->expiration_time)
761 rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
762 rd[i].expiration_time = 0;
766 rd[i].flags = GNUNET_GNSRECORD_RF_NONE;
767 rd[i].expiration_time = pos->expiration_time;
771 GNUNET_assert (i == n);
772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
773 "Transmitting standard DNS result with %u records\n",
775 rh->proc (rh->proc_cls,
779 GNS_resolver_lookup_cancel (rh);
784 * Add a result from DNS to the records to be returned to the application.
786 * @param rh resolution request to extend with a result
787 * @param expiration_time expiration time for the answer
788 * @param record_type DNS record type of the answer
789 * @param data_size number of bytes in @a data
790 * @param data binary data to return in DNS record
793 add_dns_result (struct GNS_ResolverHandle *rh,
794 uint64_t expiration_time,
795 uint32_t record_type,
799 struct DnsResult *res;
801 res = GNUNET_malloc (sizeof (struct DnsResult) + data_size);
802 res->expiration_time = expiration_time;
803 res->data_size = data_size;
804 res->record_type = record_type;
806 GNUNET_memcpy (&res[1],
809 GNUNET_CONTAINER_DLL_insert (rh->dns_result_head,
816 * We had to do a DNS lookup. Convert the result (if any) and return
819 * @param cls closure with the `struct GNS_ResolverHandle`
820 * @param addr one of the addresses of the host, NULL for the last address
821 * @param addrlen length of the address
824 handle_dns_result (void *cls,
825 const struct sockaddr *addr,
828 struct GNS_ResolverHandle *rh = cls;
829 const struct sockaddr_in *sa4;
830 const struct sockaddr_in6 *sa6;
834 rh->std_resolve = NULL;
835 transmit_lookup_dns_result (rh);
838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
839 "Received %u bytes of DNS IP data\n",
841 switch (addr->sa_family)
844 sa4 = (const struct sockaddr_in *) addr;
846 0 /* expiration time is unknown */,
847 GNUNET_DNSPARSER_TYPE_A,
848 sizeof (struct in_addr),
852 sa6 = (const struct sockaddr_in6 *) addr;
854 0 /* expiration time is unknown */,
855 GNUNET_DNSPARSER_TYPE_AAAA,
856 sizeof (struct in6_addr),
867 * Task scheduled to continue with the resolution process.
869 * @param cls the 'struct GNS_ResolverHandle' of the resolution
870 * @param tc task context
873 recursive_resolution (void *cls);
877 * Begin the resolution process from 'name', starting with
878 * the identification of the zone specified by 'name'.
880 * @param cls closure with `struct GNS_ResolverHandle *rh`
883 start_resolver_lookup (void *cls);
887 * Function called with the result of a DNS resolution.
889 * @param cls the request handle of the resolution that
890 * we were attempting to make
891 * @param dns dns response, never NULL
892 * @param dns_len number of bytes in @a dns
895 dns_result_parser (void *cls,
896 const struct GNUNET_TUN_DnsHeader *dns,
899 struct GNS_ResolverHandle *rh = cls;
900 struct GNUNET_DNSPARSER_Packet *p;
901 const struct GNUNET_DNSPARSER_Record *rec;
902 unsigned int rd_count;
906 rh->dns_request = NULL;
907 GNUNET_SCHEDULER_cancel (rh->task_id);
909 fail_resolution (rh);
912 if (rh->original_dns_id != dns->id)
914 /* DNS answer, but for another query */
917 p = GNUNET_DNSPARSER_parse ((const char *) dns,
921 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
922 _("Failed to parse DNS response\n"));
926 /* We got a result from DNS */
927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
928 "Received DNS response for `%s' with %u answers\n",
930 (unsigned int) p->num_answers);
931 if ( (p->num_answers > 0) &&
932 (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) &&
933 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) )
937 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
938 "Got CNAME `%s' from DNS for `%s'\n",
939 p->answers[0].data.hostname,
941 if (NULL != rh->std_resolve)
943 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
944 "Multiple CNAME results from DNS resolving `%s'! Not really allowed...\n",
946 GNUNET_RESOLVER_request_cancel (rh->std_resolve);
948 GNUNET_free (rh->name);
949 rh->name = GNUNET_strdup (p->answers[0].data.hostname);
950 rh->name_resolution_pos = strlen (rh->name);
951 switch (rh->record_type)
953 case GNUNET_DNSPARSER_TYPE_A:
956 case GNUNET_DNSPARSER_TYPE_AAAA:
963 rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name,
968 GNUNET_DNSPARSER_free_packet (p);
969 GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
970 rh->dns_request = NULL;
974 /* convert from (parsed) DNS to (binary) GNS format! */
975 rd_count = p->num_answers + p->num_authority_records + p->num_additional_records;
977 struct GNUNET_GNSRECORD_Data rd[rd_count];
979 char buf[UINT16_MAX];
988 for (unsigned int i=0;i<rd_count;i++)
990 if (i < p->num_answers)
991 rec = &p->answers[i];
992 else if (i < p->num_answers + p->num_authority_records)
993 rec = &p->authority_records[i - p->num_answers];
995 rec = &p->additional_records[i - p->num_answers - p->num_authority_records];
996 /* As we copied the full DNS name to 'rh->ac_tail->label', this
997 should be the correct check to see if this record is actually
998 a record for our label... */
999 if (0 != strcmp (rec->name,
1000 rh->ac_tail->label))
1002 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1003 "Dropping record `%s', does not match desired name `%s'\n",
1005 rh->ac_tail->label);
1009 rd[i - skip].record_type = rec->type;
1010 rd[i - skip].expiration_time = rec->expiration_time.abs_value_us;
1013 case GNUNET_DNSPARSER_TYPE_A:
1014 if (rec->data.raw.data_len != sizeof (struct in_addr))
1016 GNUNET_break_op (0);
1020 rd[i - skip].data_size = rec->data.raw.data_len;
1021 rd[i - skip].data = rec->data.raw.data;
1023 case GNUNET_DNSPARSER_TYPE_AAAA:
1024 if (rec->data.raw.data_len != sizeof (struct in6_addr))
1026 GNUNET_break_op (0);
1030 rd[i - skip].data_size = rec->data.raw.data_len;
1031 rd[i - skip].data = rec->data.raw.data;
1033 case GNUNET_DNSPARSER_TYPE_CNAME:
1034 case GNUNET_DNSPARSER_TYPE_PTR:
1035 case GNUNET_DNSPARSER_TYPE_NS:
1036 buf_start = buf_off;
1038 GNUNET_DNSPARSER_builder_add_name (buf,
1041 rec->data.hostname))
1047 rd[i - skip].data_size = buf_off - buf_start;
1048 rd[i - skip].data = &buf[buf_start];
1050 case GNUNET_DNSPARSER_TYPE_SOA:
1051 buf_start = buf_off;
1053 GNUNET_DNSPARSER_builder_add_soa (buf,
1062 rd[i - skip].data_size = buf_off - buf_start;
1063 rd[i - skip].data = &buf[buf_start];
1065 case GNUNET_DNSPARSER_TYPE_MX:
1066 buf_start = buf_off;
1068 GNUNET_DNSPARSER_builder_add_mx (buf,
1077 rd[i - skip].data_size = buf_off - buf_start;
1078 rd[i - skip].data = &buf[buf_start];
1080 case GNUNET_DNSPARSER_TYPE_SRV:
1081 buf_start = buf_off;
1083 GNUNET_DNSPARSER_builder_add_srv (buf,
1092 rd[i - skip].data_size = buf_off - buf_start;
1093 rd[i - skip].data = &buf[buf_start];
1096 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1097 _("Skipping record of unsupported type %d\n"),
1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1104 "Returning DNS response for `%s' with %u answers\n",
1106 (unsigned int) p->num_answers);
1107 rh->proc (rh->proc_cls,
1110 GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
1111 rh->dns_request = NULL;
1113 GNUNET_DNSPARSER_free_packet (p);
1114 if (NULL != rh->task_id)
1115 GNUNET_SCHEDULER_cancel (rh->task_id); /* should be timeout task */
1116 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
1122 * Perform recursive DNS resolution. Asks the given DNS resolver to
1123 * resolve "rh->dns_name", possibly recursively proceeding following
1124 * NS delegations, CNAMES, etc., until 'rh->loop_limiter' bounds us or
1125 * we find the answer.
1127 * @param rh resolution information
1130 recursive_dns_resolution (struct GNS_ResolverHandle *rh)
1132 struct AuthorityChain *ac;
1133 struct GNUNET_DNSPARSER_Query *query;
1134 struct GNUNET_DNSPARSER_Packet *p;
1136 size_t dns_request_length;
1140 GNUNET_assert (NULL != ac);
1141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1142 "Starting DNS lookup for `%s'\n",
1144 GNUNET_assert (GNUNET_NO == ac->gns_authority);
1145 query = GNUNET_new (struct GNUNET_DNSPARSER_Query);
1146 query->name = GNUNET_strdup (ac->label);
1147 query->type = rh->record_type;
1148 query->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
1149 p = GNUNET_new (struct GNUNET_DNSPARSER_Packet);
1152 p->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1154 p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY;
1155 p->flags.recursion_desired = 1;
1156 ret = GNUNET_DNSPARSER_pack (p,
1159 &dns_request_length);
1160 if (GNUNET_OK != ret)
1163 rh->proc (rh->proc_cls,
1166 GNUNET_assert (NULL == rh->task_id);
1167 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
1172 rh->original_dns_id = p->id;
1173 GNUNET_assert (NULL != ac->authority_info.dns_authority.dns_handle);
1174 GNUNET_assert (NULL == rh->dns_request);
1175 rh->dns_request = GNUNET_DNSSTUB_resolve (ac->authority_info.dns_authority.dns_handle,
1180 rh->task_id = GNUNET_SCHEDULER_add_delayed (DNS_LOOKUP_TIMEOUT,
1181 &timeout_resolution,
1184 if (GNUNET_SYSERR != ret)
1185 GNUNET_free (dns_request);
1186 GNUNET_DNSPARSER_free_packet (p);
1191 * We encountered a CNAME record during our resolution.
1192 * Merge it into our chain.
1194 * @param rh resolution we are performing
1195 * @param cname value of the cname record we got for the current
1196 * authority chain tail
1199 handle_gns_cname_result (struct GNS_ResolverHandle *rh,
1204 struct AuthorityChain *ac;
1207 nlen = strlen (cname);
1210 &cname[nlen - 2])) )
1212 /* CNAME resolution continues relative to current domain */
1213 if (0 == rh->name_resolution_pos)
1215 res = GNUNET_strndup (cname, nlen - 2);
1216 rh->name_resolution_pos = nlen - 2;
1220 GNUNET_asprintf (&res,
1222 (int) rh->name_resolution_pos,
1226 rh->name_resolution_pos = strlen (res);
1228 GNUNET_free (rh->name);
1230 ac = GNUNET_new (struct AuthorityChain);
1232 ac->gns_authority = GNUNET_YES;
1233 ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority;
1234 ac->label = resolver_lookup_get_next_label (rh);
1235 /* add AC to tail */
1236 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1239 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1243 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1244 "Got CNAME `%s' from GNS for `%s'\n",
1247 if (NULL != rh->std_resolve)
1249 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1250 "Multiple CNAME results from GNS resolving `%s'! Not really allowed...\n",
1252 GNUNET_RESOLVER_request_cancel (rh->std_resolve);
1254 /* name is absolute, go to DNS */
1255 GNUNET_free (rh->name);
1256 rh->name = GNUNET_strdup (cname);
1257 rh->name_resolution_pos = strlen (rh->name);
1258 switch (rh->record_type)
1260 case GNUNET_DNSPARSER_TYPE_A:
1263 case GNUNET_DNSPARSER_TYPE_AAAA:
1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1271 "Doing standard DNS lookup for `%s'\n",
1273 rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name,
1282 * Process a records that were decrypted from a block.
1284 * @param cls closure with the 'struct GNS_ResolverHandle'
1285 * @param rd_count number of entries in @a rd array
1286 * @param rd array of records with data to store
1289 handle_gns_resolution_result (void *cls,
1290 unsigned int rd_count,
1291 const struct GNUNET_GNSRECORD_Data *rd);
1295 * Callback invoked from the VPN service once a redirection is
1296 * available. Provides the IP address that can now be used to
1297 * reach the requested destination. Replaces the "VPN" record
1298 * with the respective A/AAAA record and continues processing.
1300 * @param cls closure
1301 * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error;
1302 * will match 'result_af' from the request
1303 * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
1304 * that the VPN allocated for the redirection;
1305 * traffic to this IP will now be redirected to the
1306 * specified target peer; NULL on error
1309 vpn_allocation_cb (void *cls,
1311 const void *address)
1313 struct VpnContext *vpn_ctx = cls;
1314 struct GNS_ResolverHandle *rh = vpn_ctx->rh;
1315 struct GNUNET_GNSRECORD_Data rd[vpn_ctx->rd_count];
1318 vpn_ctx->vpn_request = NULL;
1320 GNUNET_assert (GNUNET_OK ==
1321 GNUNET_GNSRECORD_records_deserialize ((size_t) vpn_ctx->rd_data_size,
1325 for (i=0;i<vpn_ctx->rd_count;i++)
1327 if (GNUNET_GNSRECORD_TYPE_VPN == rd[i].record_type)
1332 rd[i].record_type = GNUNET_DNSPARSER_TYPE_A;
1333 rd[i].data_size = sizeof (struct in_addr);
1334 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us;
1336 rd[i].data = address;
1339 rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA;
1340 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us;
1342 rd[i].data = address;
1343 rd[i].data_size = sizeof (struct in6_addr);
1351 GNUNET_assert (i < vpn_ctx->rd_count);
1352 handle_gns_resolution_result (rh,
1355 GNUNET_free (vpn_ctx->rd_data);
1356 GNUNET_free (vpn_ctx);
1361 * We have resolved one or more of the nameservers for a
1362 * GNS2DNS lookup. Once we have some of them, begin using
1363 * the DNSSTUB resolver.
1365 * @param ac context for GNS2DNS resolution
1368 continue_with_gns2dns (struct AuthorityChain *ac)
1370 struct GNS_ResolverHandle *rh = ac->rh;
1372 if ( (NULL != ac->authority_info.dns_authority.gp_head) &&
1373 (GNUNET_NO == ac->authority_info.dns_authority.found) )
1374 return; /* more pending and none found yet */
1375 if (GNUNET_NO == ac->authority_info.dns_authority.found)
1377 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1378 "Failed to resolve DNS server for `%s' in GNS2DNS resolution\n",
1379 ac->authority_info.dns_authority.name);
1380 fail_resolution (rh);
1383 if (GNUNET_NO != ac->authority_info.dns_authority.launched)
1384 return; /* already running, do not launch again! */
1386 ac->authority_info.dns_authority.launched = GNUNET_YES;
1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1388 "Will continue resolution using DNS to resolve `%s'\n",
1390 GNUNET_assert (NULL == rh->task_id);
1391 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1398 * We've resolved the IP address for the DNS resolver to use
1399 * after encountering a GNS2DNS record.
1401 * @param cls the `struct Gns2DnsPending` used for this request
1402 * @param rd_count number of records in @a rd
1403 * @param rd addresses for the DNS resolver (presumably)
1406 handle_gns2dns_result (void *cls,
1407 unsigned int rd_count,
1408 const struct GNUNET_GNSRECORD_Data *rd)
1410 struct Gns2DnsPending *gp = cls;
1411 struct AuthorityChain *ac = gp->ac;
1413 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
1414 ac->authority_info.dns_authority.gp_tail,
1416 /* enable cleanup of 'rh' handle that automatically comes after we return,
1417 and which expects 'rh' to be in the #rlh_head DLL. */
1420 GNUNET_CONTAINER_DLL_insert (rlh_head,
1426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1427 "Received %u results for IP address of DNS server for GNS2DNS transition\n",
1429 /* find suitable A/AAAA record */
1430 for (unsigned int j=0;j<rd_count;j++)
1432 switch (rd[j].record_type)
1434 case GNUNET_DNSPARSER_TYPE_A:
1436 struct sockaddr_in v4;
1438 if (sizeof (struct in_addr) != rd[j].data_size)
1440 GNUNET_break_op (0);
1446 v4.sin_family = AF_INET;
1447 v4.sin_port = htons (53);
1448 #if HAVE_SOCKADDR_IN_SIN_LEN
1449 v4.sin_len = (u_char) sizeof (v4);
1451 GNUNET_memcpy (&v4.sin_addr,
1453 sizeof (struct in_addr));
1455 GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
1456 (const struct sockaddr *) &v4))
1457 ac->authority_info.dns_authority.found = GNUNET_YES;
1460 case GNUNET_DNSPARSER_TYPE_AAAA:
1462 struct sockaddr_in6 v6;
1464 if (sizeof (struct in6_addr) != rd[j].data_size)
1466 GNUNET_break_op (0);
1469 /* FIXME: might want to check if we support IPv6 here,
1470 and otherwise skip this one and hope we find another */
1474 v6.sin6_family = AF_INET6;
1475 v6.sin6_port = htons (53);
1476 #if HAVE_SOCKADDR_IN_SIN_LEN
1477 v6.sin6_len = (u_char) sizeof (v6);
1479 GNUNET_memcpy (&v6.sin6_addr,
1481 sizeof (struct in6_addr));
1483 GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
1484 (const struct sockaddr *) &v6))
1485 ac->authority_info.dns_authority.found = GNUNET_YES;
1492 continue_with_gns2dns (ac);
1497 * Function called by the resolver for each address obtained from DNS.
1499 * @param cls closure, a `struct Gns2DnsPending *`
1500 * @param addr one of the addresses of the host, NULL for the last address
1501 * @param addrlen length of @a addr
1504 handle_gns2dns_ip (void *cls,
1505 const struct sockaddr *addr,
1508 struct Gns2DnsPending *gp = cls;
1509 struct AuthorityChain *ac = gp->ac;
1510 struct sockaddr_storage ss;
1511 struct sockaddr_in *v4;
1512 struct sockaddr_in6 *v6;
1516 /* DNS resolution finished */
1517 if (0 == gp->num_results)
1518 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1519 "Failed to use DNS to resolve name of DNS resolver\n");
1520 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
1521 ac->authority_info.dns_authority.gp_tail,
1524 continue_with_gns2dns (ac);
1530 switch (ss.ss_family)
1533 v4 = (struct sockaddr_in *) &ss;
1534 v4->sin_port = htons (53);
1538 v6 = (struct sockaddr_in6 *) &ss;
1539 v6->sin6_port = htons (53);
1543 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1544 "Unsupported AF %d\n",
1549 GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
1550 (struct sockaddr *) &ss))
1551 ac->authority_info.dns_authority.found = GNUNET_YES;
1556 * We found a CNAME record, perform recursive resolution on it.
1558 * @param rh resolution handle
1559 * @param rd record with CNAME to resolve recursively
1562 recursive_cname_resolution (struct GNS_ResolverHandle *rh,
1563 const struct GNUNET_GNSRECORD_Data *rd)
1569 cname = GNUNET_DNSPARSER_parse_name (rd->data,
1572 if ( (NULL == cname) ||
1573 (off != rd->data_size) )
1575 GNUNET_break_op (0); /* record not well-formed */
1576 GNUNET_free_non_null (cname);
1577 fail_resolution (rh);
1580 handle_gns_cname_result (rh,
1582 GNUNET_free (cname);
1587 * We found a PKEY record, perform recursive resolution on it.
1589 * @param rh resolution handle
1590 * @param rd record with PKEY to resolve recursively
1593 recursive_pkey_resolution (struct GNS_ResolverHandle *rh,
1594 const struct GNUNET_GNSRECORD_Data *rd)
1596 struct AuthorityChain *ac;
1598 /* delegation to another zone */
1599 if (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) !=
1602 GNUNET_break_op (0);
1603 fail_resolution (rh);
1606 /* expand authority chain */
1607 ac = GNUNET_new (struct AuthorityChain);
1609 ac->gns_authority = GNUNET_YES;
1610 GNUNET_memcpy (&ac->authority_info.gns_authority,
1612 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
1613 ac->label = resolver_lookup_get_next_label (rh);
1614 /* add AC to tail */
1615 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1619 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1625 * We found one or more GNS2DNS records, perform recursive resolution on it.
1626 * (to be precise, one or more records in @a rd is GNS2DNS, there may be others,
1627 * so this function still needs to check which ones are GNS2DNS).
1629 * @param rh resolution handle
1630 * @param rd_count length of the @a rd array
1631 * @param rd record with PKEY to resolve recursively
1632 * @return #GNUNET_OK if this worked, #GNUNET_SYSERR if no GNS2DNS records were in @a rd
1635 recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh,
1636 unsigned int rd_count,
1637 const struct GNUNET_GNSRECORD_Data *rd)
1639 struct AuthorityChain *ac;
1644 /* expand authority chain */
1645 ac = GNUNET_new (struct AuthorityChain);
1647 ac->authority_info.dns_authority.dns_handle = GNUNET_DNSSTUB_start (4);
1649 for (unsigned int i=0;i<rd_count;i++)
1654 struct Gns2DnsPending *gp;
1655 struct GNUNET_CRYPTO_EcdsaPublicKey zone;
1656 struct sockaddr_in v4;
1657 struct sockaddr_in6 v6;
1659 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type)
1662 n = GNUNET_DNSPARSER_parse_name (rd[i].data,
1665 ip = GNUNET_DNSPARSER_parse_name (rd[i].data,
1670 (off != rd[i].data_size) )
1672 GNUNET_break_op (0);
1673 GNUNET_free_non_null (n);
1674 GNUNET_free_non_null (ip);
1677 /* resolve 'ip' to determine the IP(s) of the DNS
1678 resolver to use for lookup of 'ns' */
1681 if (0 != strcasecmp (ns,
1684 /* NS values must all be the same for all GNS2DNS records,
1685 anything else leads to insanity */
1686 GNUNET_break_op (0);
1698 /* check if 'ip' is already an IPv4/IPv6 address */
1699 if ( (1 == inet_pton (AF_INET,
1702 (1 == inet_pton (AF_INET6,
1706 GNUNET_break (GNUNET_OK ==
1707 GNUNET_DNSSTUB_add_dns_ip (ac->authority_info.dns_authority.dns_handle,
1709 ac->authority_info.dns_authority.found = GNUNET_YES;
1713 tld = GNS_get_tld (ip);
1714 if (0 != strcmp (tld,
1717 /* 'ip' is a DNS name */
1718 gp = GNUNET_new (struct Gns2DnsPending);
1720 GNUNET_CONTAINER_DLL_insert (ac->authority_info.dns_authority.gp_head,
1721 ac->authority_info.dns_authority.gp_tail,
1723 gp->dns_rh = GNUNET_RESOLVER_ip_get (ip,
1725 GNUNET_TIME_UNIT_FOREVER_REL,
1731 /* 'ip' should be a GNS name */
1732 gp = GNUNET_new (struct Gns2DnsPending);
1734 GNUNET_CONTAINER_DLL_insert (ac->authority_info.dns_authority.gp_head,
1735 ac->authority_info.dns_authority.gp_tail,
1737 gp->rh = GNUNET_new (struct GNS_ResolverHandle);
1738 ip = translate_dot_plus (rh,
1740 tld = GNS_get_tld (ip);
1742 GNUNET_GNSRECORD_zkey_to_pkey (tld,
1745 GNUNET_break_op (0);
1749 gp->rh->authority_zone = zone;
1750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1751 "Resolving `%s' to determine IP address of DNS server for GNS2DNS transition for `%s'\n",
1755 gp->rh->name_resolution_pos = strlen (ip) - strlen (tld) - 1;
1756 gp->rh->proc = &handle_gns2dns_result;
1757 gp->rh->proc_cls = gp;
1758 gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY;
1759 gp->rh->options = GNUNET_GNS_LO_DEFAULT;
1760 gp->rh->loop_limiter = rh->loop_limiter + 1;
1762 = GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
1764 } /* end 'for all records' */
1768 /* not a single GNS2DNS record found */
1770 return GNUNET_SYSERR;
1772 GNUNET_assert (strlen (ns) <= GNUNET_DNSPARSER_MAX_NAME_LENGTH);
1773 strcpy (ac->authority_info.dns_authority.name,
1775 /* for DNS recursion, the label is the full DNS name,
1776 created from the remainder of the GNS name and the
1777 name in the NS record */
1778 GNUNET_asprintf (&ac->label,
1780 (int) rh->name_resolution_pos,
1782 (0 != rh->name_resolution_pos) ? "." : "",
1785 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1788 if (strlen (ac->label) > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
1790 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1791 _("GNS lookup resulted in DNS name that is too long (`%s')\n"),
1793 return GNUNET_SYSERR;
1795 continue_with_gns2dns (ac);
1801 * Process a records that were decrypted from a block.
1803 * @param cls closure with the `struct GNS_ResolverHandle`
1804 * @param rd_count number of entries in @a rd array
1805 * @param rd array of records with data to store
1808 handle_gns_resolution_result (void *cls,
1809 unsigned int rd_count,
1810 const struct GNUNET_GNSRECORD_Data *rd)
1812 struct GNS_ResolverHandle *rh = cls;
1814 struct VpnContext *vpn_ctx;
1815 const struct GNUNET_TUN_GnsVpnRecord *vpn;
1817 struct GNUNET_HashCode vhash;
1819 char scratch[UINT16_MAX];
1821 size_t scratch_start;
1823 struct GNUNET_GNSRECORD_Data rd_new[rd_count];
1824 unsigned int rd_off;
1826 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1827 "Resolution succeeded for `%s' in zone %s, got %u records\n",
1829 GNUNET_GNSRECORD_z2s (&rh->ac_tail->authority_info.gns_authority),
1833 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1834 _("GNS lookup failed (zero records found)\n"));
1835 fail_resolution (rh);
1839 if (0 == rh->name_resolution_pos)
1841 /* top-level match, are we done yet? */
1842 if ( (rd_count > 0) &&
1843 (GNUNET_DNSPARSER_TYPE_CNAME == rd[0].record_type) &&
1844 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) )
1847 cname = GNUNET_DNSPARSER_parse_name (rd[0].data,
1850 if ( (NULL == cname) ||
1851 (off != rd[0].data_size) )
1853 GNUNET_break_op (0);
1854 GNUNET_free_non_null (cname);
1855 fail_resolution (rh);
1858 handle_gns_cname_result (rh,
1860 GNUNET_free (cname);
1863 /* If A/AAAA was requested, but we got a VPN
1864 record, we convert it to A/AAAA using GNUnet VPN */
1865 if ( (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ||
1866 (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type) )
1868 for (unsigned int i=0;i<rd_count;i++)
1870 switch (rd[i].record_type)
1872 case GNUNET_GNSRECORD_TYPE_VPN:
1874 af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : AF_INET6;
1875 if (sizeof (struct GNUNET_TUN_GnsVpnRecord) >
1878 GNUNET_break_op (0);
1879 fail_resolution (rh);
1882 vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data;
1883 vname = (const char *) &vpn[1];
1884 if ('\0' != vname[rd[i].data_size - 1 - sizeof (struct GNUNET_TUN_GnsVpnRecord)])
1886 GNUNET_break_op (0);
1887 fail_resolution (rh);
1890 GNUNET_TUN_service_name_to_hash (vname,
1892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1893 "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n",
1894 GNUNET_i2s (&vpn->peer),
1897 (int) ntohs (vpn->proto));
1898 vpn_ctx = GNUNET_new (struct VpnContext);
1899 rh->vpn_ctx = vpn_ctx;
1901 vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count,
1903 if (vpn_ctx->rd_data_size < 0)
1905 GNUNET_break_op (0);
1906 GNUNET_free (vpn_ctx);
1907 fail_resolution (rh);
1910 vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size);
1911 vpn_ctx->rd_count = rd_count;
1912 GNUNET_assert (vpn_ctx->rd_data_size ==
1913 GNUNET_GNSRECORD_records_serialize (rd_count,
1915 (size_t) vpn_ctx->rd_data_size,
1917 vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle,
1922 GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT),
1927 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
1929 /* delegation to DNS */
1930 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1931 "Found GNS2DNS record, delegating to DNS!\n");
1933 recursive_gns2dns_resolution (rh,
1944 } /* end: name_resolution_pos */
1945 /* convert relative names in record values to absolute names,
1946 using 'scratch' array for memory allocations */
1949 for (unsigned int i=0;i<rd_count;i++)
1951 GNUNET_assert (rd_off <= i);
1952 if ( (0 != rh->protocol) &&
1953 (0 != rh->service) &&
1954 (GNUNET_GNSRECORD_TYPE_BOX != rd[i].record_type) )
1955 continue; /* we _only_ care about boxed records */
1957 GNUNET_assert (rd_off < rd_count);
1958 rd_new[rd_off] = rd[i];
1959 /* Check if the embedded name(s) end in "+", and if so,
1960 replace the "+" with the zone at "ac_tail", changing the name
1961 to a ".ZONEKEY". The name is allocated on the 'scratch' array,
1962 so we can free it afterwards. */
1963 switch (rd[i].record_type)
1965 case GNUNET_DNSPARSER_TYPE_CNAME:
1970 cname = GNUNET_DNSPARSER_parse_name (rd[i].data,
1973 if ( (NULL == cname) ||
1974 (off != rd[i].data_size) )
1976 GNUNET_break_op (0); /* record not well-formed */
1980 cname = translate_dot_plus (rh, cname);
1981 GNUNET_break (NULL != cname);
1982 scratch_start = scratch_off;
1984 GNUNET_DNSPARSER_builder_add_name (scratch,
1993 GNUNET_assert (rd_off < rd_count);
1994 rd_new[rd_off].data = &scratch[scratch_start];
1995 rd_new[rd_off].data_size = scratch_off - scratch_start;
1999 GNUNET_free_non_null (cname);
2002 case GNUNET_DNSPARSER_TYPE_SOA:
2004 struct GNUNET_DNSPARSER_SoaRecord *soa;
2007 soa = GNUNET_DNSPARSER_parse_soa (rd[i].data,
2010 if ( (NULL == soa) ||
2011 (off != rd[i].data_size) )
2013 GNUNET_break_op (0); /* record not well-formed */
2017 soa->mname = translate_dot_plus (rh, soa->mname);
2018 soa->rname = translate_dot_plus (rh, soa->rname);
2019 scratch_start = scratch_off;
2021 GNUNET_DNSPARSER_builder_add_soa (scratch,
2030 GNUNET_assert (rd_off < rd_count);
2031 rd_new[rd_off].data = &scratch[scratch_start];
2032 rd_new[rd_off].data_size = scratch_off - scratch_start;
2037 GNUNET_DNSPARSER_free_soa (soa);
2040 case GNUNET_DNSPARSER_TYPE_MX:
2042 struct GNUNET_DNSPARSER_MxRecord *mx;
2045 mx = GNUNET_DNSPARSER_parse_mx (rd[i].data,
2048 if ( (NULL == mx) ||
2049 (off != rd[i].data_size) )
2051 GNUNET_break_op (0); /* record not well-formed */
2055 mx->mxhost = translate_dot_plus (rh, mx->mxhost);
2056 scratch_start = scratch_off;
2058 GNUNET_DNSPARSER_builder_add_mx (scratch,
2067 GNUNET_assert (rd_off < rd_count);
2068 rd_new[rd_off].data = &scratch[scratch_start];
2069 rd_new[rd_off].data_size = scratch_off - scratch_start;
2074 GNUNET_DNSPARSER_free_mx (mx);
2077 case GNUNET_DNSPARSER_TYPE_SRV:
2079 struct GNUNET_DNSPARSER_SrvRecord *srv;
2082 srv = GNUNET_DNSPARSER_parse_srv (rd[i].data,
2085 if ( (NULL == srv) ||
2086 (off != rd[i].data_size) )
2088 GNUNET_break_op (0); /* record not well-formed */
2092 srv->target = translate_dot_plus (rh, srv->target);
2093 scratch_start = scratch_off;
2095 GNUNET_DNSPARSER_builder_add_srv (scratch,
2104 GNUNET_assert (rd_off < rd_count);
2105 rd_new[rd_off].data = &scratch[scratch_start];
2106 rd_new[rd_off].data_size = scratch_off - scratch_start;
2111 GNUNET_DNSPARSER_free_srv (srv);
2115 case GNUNET_GNSRECORD_TYPE_NICK:
2120 if ((rd[i].data_size > 0) &&
2121 (nick[rd[i].data_size -1] != '\0'))
2123 GNUNET_break_op (0);
2128 case GNUNET_GNSRECORD_TYPE_PKEY:
2130 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
2132 if (rd[i].data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))
2134 GNUNET_break_op (0);
2137 GNUNET_memcpy (&pub,
2141 if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type)
2143 /* try to resolve "@" */
2144 struct AuthorityChain *ac;
2146 ac = GNUNET_new (struct AuthorityChain);
2148 ac->gns_authority = GNUNET_YES;
2149 ac->authority_info.gns_authority = pub;
2150 ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT);
2151 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
2154 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
2160 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
2162 /* delegation to DNS */
2163 if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rh->record_type)
2166 break; /* do not follow to DNS, we wanted the GNS2DNS record! */
2168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2169 "Found GNS2DNS record, delegating to DNS!\n");
2171 recursive_gns2dns_resolution (rh,
2178 case GNUNET_GNSRECORD_TYPE_BOX:
2180 /* unbox SRV/TLSA records if a specific one was requested */
2181 if ( (0 != rh->protocol) &&
2182 (0 != rh->service) &&
2183 (rd[i].data_size >= sizeof (struct GNUNET_GNSRECORD_BoxRecord)) )
2185 const struct GNUNET_GNSRECORD_BoxRecord *box;
2188 if ( (ntohs (box->protocol) == rh->protocol) &&
2189 (ntohs (box->service) == rh->service) )
2191 /* Box matches, unbox! */
2192 GNUNET_assert (rd_off < rd_count);
2193 rd_new[rd_off].record_type = ntohl (box->record_type);
2194 rd_new[rd_off].data_size -= sizeof (struct GNUNET_GNSRECORD_BoxRecord);
2195 rd_new[rd_off].data = &box[1];
2201 /* no specific protocol/service specified, preserve all BOX
2202 records (for modern, GNS-enabled applications) */
2211 } /* end: for rd_count */
2213 /* yes, we are done, return result */
2214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2215 "Returning GNS response for `%s' with %u answers\n",
2218 rh->proc (rh->proc_cls,
2221 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
2226 switch (rd[0].record_type)
2228 case GNUNET_DNSPARSER_TYPE_CNAME:
2229 GNUNET_break_op (1 == rd_count); /* CNAME should be unique */
2230 recursive_cname_resolution (rh,
2233 case GNUNET_GNSRECORD_TYPE_PKEY:
2234 GNUNET_break_op (1 == rd_count); /* PKEY should be unique */
2235 recursive_pkey_resolution (rh,
2240 recursive_gns2dns_resolution (rh,
2247 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2248 _("GNS lookup recursion failed (no delegation record found)\n"));
2249 fail_resolution (rh);
2254 * Function called once the namestore has completed the request for
2257 * @param cls closure with the `struct CacheOps`
2258 * @param success #GNUNET_OK on success
2259 * @param emsg error message
2262 namecache_cache_continuation (void *cls,
2266 struct CacheOps *co = cls;
2268 co->namecache_qe_cache = NULL;
2269 if (GNUNET_OK != success)
2270 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2271 _("Failed to cache GNS resolution: %s\n"),
2273 GNUNET_CONTAINER_DLL_remove (co_head,
2281 * Iterator called on each result obtained for a DHT
2282 * operation that expects a reply
2284 * @param cls closure with the `struct GNS_ResolverHandle`
2285 * @param exp when will this value expire
2286 * @param key key of the result
2287 * @param get_path peers on reply path (or NULL if not recorded)
2288 * [0] = datastore's first neighbor, [length - 1] = local peer
2289 * @param get_path_length number of entries in @a get_path
2290 * @param put_path peers on the PUT path (or NULL if not recorded)
2291 * [0] = origin, [length - 1] = datastore
2292 * @param put_path_length number of entries in @a put_path
2293 * @param type type of the result
2294 * @param size number of bytes in data
2295 * @param data pointer to the result data
2298 handle_dht_response (void *cls,
2299 struct GNUNET_TIME_Absolute exp,
2300 const struct GNUNET_HashCode *key,
2301 const struct GNUNET_PeerIdentity *get_path,
2302 unsigned int get_path_length,
2303 const struct GNUNET_PeerIdentity *put_path,
2304 unsigned int put_path_length,
2305 enum GNUNET_BLOCK_Type type,
2309 struct GNS_ResolverHandle *rh = cls;
2310 struct AuthorityChain *ac = rh->ac_tail;
2311 const struct GNUNET_GNSRECORD_Block *block;
2312 struct CacheOps *co;
2317 (void) get_path_length;
2319 (void) put_path_length;
2321 GNUNET_DHT_get_stop (rh->get_handle);
2322 rh->get_handle = NULL;
2323 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
2324 rh->dht_heap_node = NULL;
2325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2326 "Handling response from the DHT\n");
2327 if (size < sizeof (struct GNUNET_GNSRECORD_Block))
2329 /* how did this pass DHT block validation!? */
2331 fail_resolution (rh);
2336 ntohl (block->purpose.size) +
2337 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) +
2338 sizeof (struct GNUNET_CRYPTO_EcdsaSignature))
2340 /* how did this pass DHT block validation!? */
2342 fail_resolution (rh);
2346 GNUNET_GNSRECORD_block_decrypt (block,
2347 &ac->authority_info.gns_authority,
2349 &handle_gns_resolution_result,
2352 GNUNET_break_op (0); /* block was ill-formed */
2353 fail_resolution (rh);
2356 if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us)
2358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2359 "Received expired block from the DHT, will not cache it.\n");
2362 /* Cache well-formed blocks */
2363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2364 "Caching response from the DHT in namecache\n");
2365 co = GNUNET_new (struct CacheOps);
2366 co->namecache_qe_cache = GNUNET_NAMECACHE_block_cache (namecache_handle,
2368 &namecache_cache_continuation,
2370 GNUNET_CONTAINER_DLL_insert (co_head,
2377 * Initiate a DHT query for a set of GNS records.
2379 * @param rh resolution handle
2380 * @param query key to use in the DHT lookup
2383 start_dht_request (struct GNS_ResolverHandle *rh,
2384 const struct GNUNET_HashCode *query)
2386 struct GNS_ResolverHandle *rx;
2388 GNUNET_assert (NULL == rh->get_handle);
2389 rh->get_handle = GNUNET_DHT_get_start (dht_handle,
2390 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
2392 DHT_GNS_REPLICATION_LEVEL,
2393 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
2395 &handle_dht_response, rh);
2396 rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
2398 GNUNET_TIME_absolute_get ().abs_value_us);
2399 if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries)
2401 /* fail longest-standing DHT request */
2402 rx = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap);
2403 rx->dht_heap_node = NULL;
2404 GNUNET_assert (NULL != rx);
2405 fail_resolution (rx);
2411 * Process a records that were decrypted from a block that we got from
2412 * the namecache. Simply calls #handle_gns_resolution_result().
2414 * @param cls closure with the `struct GNS_ResolverHandle`
2415 * @param rd_count number of entries in @a rd array
2416 * @param rd array of records with data to store
2419 handle_gns_namecache_resolution_result (void *cls,
2420 unsigned int rd_count,
2421 const struct GNUNET_GNSRECORD_Data *rd)
2423 struct GNS_ResolverHandle *rh = cls;
2425 handle_gns_resolution_result (rh,
2432 * Process a record that was stored in the namecache.
2434 * @param cls closure with the `struct GNS_ResolverHandle`
2435 * @param block block that was stored in the namecache
2438 handle_namecache_block_response (void *cls,
2439 const struct GNUNET_GNSRECORD_Block *block)
2441 struct GNS_ResolverHandle *rh = cls;
2442 struct AuthorityChain *ac = rh->ac_tail;
2443 const char *label = ac->label;
2444 const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority;
2445 struct GNUNET_HashCode query;
2447 GNUNET_assert (NULL != rh->namecache_qe);
2448 rh->namecache_qe = NULL;
2449 if ( ( (GNUNET_GNS_LO_DEFAULT == rh->options) ||
2450 ( (GNUNET_GNS_LO_LOCAL_MASTER == rh->options) &&
2451 (ac != rh->ac_head) ) ) &&
2452 ( (NULL == block) ||
2453 (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) )
2455 /* namecache knows nothing; try DHT lookup */
2456 GNUNET_GNSRECORD_query_from_public_key (auth,
2459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2460 "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n",
2462 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority),
2463 GNUNET_h2s (&query));
2464 start_dht_request (rh, &query);
2468 if ( (NULL == block) ||
2469 (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) )
2471 /* DHT not permitted and no local result, fail */
2472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2473 "Resolution failed for `%s' in zone %s (DHT lookup not permitted by configuration)\n",
2475 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority));
2476 fail_resolution (rh);
2479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2480 "Received result from namecache for label `%s'\n",
2484 GNUNET_GNSRECORD_block_decrypt (block,
2487 &handle_gns_namecache_resolution_result,
2490 GNUNET_break_op (0); /* block was ill-formed */
2491 /* try DHT instead */
2492 GNUNET_GNSRECORD_query_from_public_key (auth,
2495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2496 "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n",
2498 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority),
2499 GNUNET_h2s (&query));
2500 start_dht_request (rh, &query);
2507 * Lookup tail of our authority chain in the namecache.
2509 * @param rh query we are processing
2512 recursive_gns_resolution_namecache (struct GNS_ResolverHandle *rh)
2514 struct AuthorityChain *ac = rh->ac_tail;
2515 struct GNUNET_HashCode query;
2517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2518 "Starting GNS resolution for `%s' in zone %s\n",
2520 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority));
2521 GNUNET_GNSRECORD_query_from_public_key (&ac->authority_info.gns_authority,
2524 if (GNUNET_YES != disable_cache)
2527 = GNUNET_NAMECACHE_lookup_block (namecache_handle,
2529 &handle_namecache_block_response,
2531 GNUNET_assert (NULL != rh->namecache_qe);
2535 start_dht_request (rh,
2542 * Function called with the result from a revocation check.
2544 * @param cls the `struct GNS_ResovlerHandle`
2545 * @param is_valid #GNUNET_YES if the zone was not yet revoked
2548 handle_revocation_result (void *cls,
2551 struct GNS_ResolverHandle *rh = cls;
2552 struct AuthorityChain *ac = rh->ac_tail;
2554 rh->rev_check = NULL;
2555 if (GNUNET_YES != is_valid)
2557 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2558 _("Zone %s was revoked, resolution fails\n"),
2559 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority));
2560 fail_resolution (rh);
2563 recursive_gns_resolution_namecache (rh);
2568 * Perform revocation check on tail of our authority chain.
2570 * @param rh query we are processing
2573 recursive_gns_resolution_revocation (struct GNS_ResolverHandle *rh)
2575 struct AuthorityChain *ac = rh->ac_tail;
2577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2578 "Starting revocation check for zone %s\n",
2579 GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority));
2580 rh->rev_check = GNUNET_REVOCATION_query (cfg,
2581 &ac->authority_info.gns_authority,
2582 &handle_revocation_result,
2584 GNUNET_assert (NULL != rh->rev_check);
2589 * Task scheduled to continue with the resolution process.
2591 * @param cls the `struct GNS_ResolverHandle` of the resolution
2594 recursive_resolution (void *cls)
2596 struct GNS_ResolverHandle *rh = cls;
2599 if (MAX_RECURSION < rh->loop_limiter++)
2601 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2602 "Encountered unbounded recursion resolving `%s'\n",
2604 fail_resolution (rh);
2607 if (GNUNET_YES == rh->ac_tail->gns_authority)
2608 recursive_gns_resolution_revocation (rh);
2610 recursive_dns_resolution (rh);
2615 * Begin the resolution process from 'name', starting with
2616 * the identification of the zone specified by 'name'.
2618 * @param cls the `struct GNS_ResolverHandle`
2621 start_resolver_lookup (void *cls)
2623 struct GNS_ResolverHandle *rh = cls;
2624 struct AuthorityChain *ac;
2629 if (1 == inet_pton (AF_INET,
2633 /* name is IPv4 address, pretend it's an A record */
2634 struct GNUNET_GNSRECORD_Data rd;
2637 rd.data_size = sizeof (v4);
2638 rd.expiration_time = UINT64_MAX;
2639 rd.record_type = GNUNET_DNSPARSER_TYPE_A;
2641 rh->proc (rh->proc_cls,
2644 GNUNET_assert (NULL == rh->task_id);
2645 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
2649 if (1 == inet_pton (AF_INET6,
2653 /* name is IPv6 address, pretend it's an AAAA record */
2654 struct GNUNET_GNSRECORD_Data rd;
2657 rd.data_size = sizeof (v6);
2658 rd.expiration_time = UINT64_MAX;
2659 rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA;
2661 rh->proc (rh->proc_cls,
2664 GNUNET_assert (NULL == rh->task_id);
2665 rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
2670 ac = GNUNET_new (struct AuthorityChain);
2672 ac->label = resolver_lookup_get_next_label (rh);
2673 if (NULL == ac->label)
2674 /* name was just the "TLD", so we default to label
2675 #GNUNET_GNS_EMPTY_LABEL_AT */
2676 ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT);
2677 ac->gns_authority = GNUNET_YES;
2678 ac->authority_info.gns_authority = rh->authority_zone;
2679 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
2682 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
2688 * Lookup of a record in a specific zone calls lookup result processor
2691 * @param zone the zone to perform the lookup in
2692 * @param record_type the record type to look up
2693 * @param name the name to look up
2694 * @param options local options to control local lookup
2695 * @param proc the processor to call on result
2696 * @param proc_cls the closure to pass to @a proc
2697 * @return handle to cancel operation
2699 struct GNS_ResolverHandle *
2700 GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
2701 uint32_t record_type,
2703 enum GNUNET_GNS_LocalOptions options,
2704 GNS_ResultProcessor proc,
2707 struct GNS_ResolverHandle *rh;
2709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2710 "Starting lookup for `%s'\n",
2712 rh = GNUNET_new (struct GNS_ResolverHandle);
2713 GNUNET_CONTAINER_DLL_insert (rlh_head,
2716 rh->authority_zone = *zone;
2718 rh->proc_cls = proc_cls;
2719 rh->options = options;
2720 rh->record_type = record_type;
2721 rh->name = GNUNET_strdup (name);
2722 rh->name_resolution_pos = strlen (name);
2723 rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
2730 * Cancel active resolution (i.e. client disconnected).
2732 * @param rh resolution to abort
2735 GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh)
2737 struct DnsResult *dr;
2738 struct AuthorityChain *ac;
2739 struct VpnContext *vpn_ctx;
2741 GNUNET_CONTAINER_DLL_remove (rlh_head,
2744 if (NULL != rh->dns_request)
2746 GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
2747 rh->dns_request = NULL;
2749 while (NULL != (ac = rh->ac_head))
2751 GNUNET_CONTAINER_DLL_remove (rh->ac_head,
2754 if (GNUNET_NO == ac->gns_authority)
2756 struct Gns2DnsPending *gp;
2758 while (NULL != (gp = ac->authority_info.dns_authority.gp_head))
2760 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
2761 ac->authority_info.dns_authority.gp_tail,
2765 /* rh->g2dc->rh is NOT in the DLL yet, so to enable us
2766 using GNS_resolver_lookup_cancel here, we need to
2768 GNUNET_CONTAINER_DLL_insert (rlh_head,
2771 GNUNET_assert (NULL == gp->rh->task_id);
2772 gp->rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_,
2776 if (NULL != gp->dns_rh)
2778 GNUNET_RESOLVER_request_cancel (gp->dns_rh);
2783 GNUNET_DNSSTUB_stop (ac->authority_info.dns_authority.dns_handle);
2785 GNUNET_free (ac->label);
2788 if (NULL != rh->task_id)
2790 GNUNET_SCHEDULER_cancel (rh->task_id);
2793 if (NULL != rh->get_handle)
2795 GNUNET_DHT_get_stop (rh->get_handle);
2796 rh->get_handle = NULL;
2798 if (NULL != rh->dht_heap_node)
2800 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
2801 rh->dht_heap_node = NULL;
2803 if (NULL != (vpn_ctx = rh->vpn_ctx))
2805 GNUNET_VPN_cancel_request (vpn_ctx->vpn_request);
2806 GNUNET_free (vpn_ctx->rd_data);
2807 GNUNET_free (vpn_ctx);
2809 if (NULL != rh->namecache_qe)
2811 GNUNET_NAMECACHE_cancel (rh->namecache_qe);
2812 rh->namecache_qe = NULL;
2814 if (NULL != rh->rev_check)
2816 GNUNET_REVOCATION_query_cancel (rh->rev_check);
2817 rh->rev_check = NULL;
2819 if (NULL != rh->std_resolve)
2821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2822 "Canceling standard DNS resolution\n");
2823 GNUNET_RESOLVER_request_cancel (rh->std_resolve);
2824 rh->std_resolve = NULL;
2826 while (NULL != (dr = rh->dns_result_head))
2828 GNUNET_CONTAINER_DLL_remove (rh->dns_result_head,
2829 rh->dns_result_tail,
2833 GNUNET_free (rh->name);
2838 /* ***************** Resolver initialization ********************* */
2842 * Initialize the resolver
2844 * @param nc the namecache handle
2845 * @param dht the dht handle
2846 * @param c configuration handle
2847 * @param max_bg_queries maximum number of parallel background queries in dht
2850 GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc,
2851 struct GNUNET_DHT_Handle *dht,
2852 const struct GNUNET_CONFIGURATION_Handle *c,
2853 unsigned long long max_bg_queries)
2856 namecache_handle = nc;
2859 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2860 max_allowed_background_queries = max_bg_queries;
2861 disable_cache = GNUNET_CONFIGURATION_get_value_yesno (cfg,
2864 if (GNUNET_YES == disable_cache)
2865 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2866 "Namecache disabled\n");
2867 vpn_handle = GNUNET_VPN_connect (cfg);
2875 GNS_resolver_done ()
2877 struct GNS_ResolverHandle *rh;
2878 struct CacheOps *co;
2880 /* abort active resolutions */
2881 while (NULL != (rh = rlh_head))
2883 rh->proc (rh->proc_cls,
2886 GNS_resolver_lookup_cancel (rh);
2888 while (NULL != (co = co_head))
2890 GNUNET_CONTAINER_DLL_remove (co_head,
2893 GNUNET_NAMECACHE_cancel (co->namecache_qe_cache);
2896 GNUNET_CONTAINER_heap_destroy (dht_lookup_heap);
2897 dht_lookup_heap = NULL;
2898 GNUNET_VPN_disconnect (vpn_handle);
2901 namecache_handle = NULL;
2905 /* end of gnunet-service-gns_resolver.c */