2 This file is part of GNUnet.
3 (C) 2011-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file gns/gnunet-service-gns_resolver.c
23 * @brief GNUnet GNS resolver logic
24 * @author Martin Schanzenbach
25 * @author Christian Grothoff
28 * - shortening triggers
29 * - We currently go to the DHT simply if we find no local reply; this
30 * is incorrect; the correct rules for going to DHT are:
32 * 1. The entry in the DHT is RSL_RECORD_EXPIRED OR
33 * 2. No entry in the NS existed AND
34 * 3. The zone queried is not the local resolver's zone AND
35 * 4. The name that was looked up is '+'
36 * because if it was any other canonical name we either already queried
37 * the DHT for the authority in the authority lookup phase (and thus
38 * would already have an entry in the NS for the record)
39 * 5. We are not in cache only mode
43 * - GNS: handle special SRV names --- no delegation, direct lookup;
44 * can likely be done in 'resolver_lookup_get_next_label'. (#3003)
45 * - revocation checks (make optional: privacy!), (#3004)
46 * - DNAME support (#3005)
49 #include "gnunet_util_lib.h"
50 #include "gnunet_dnsstub_lib.h"
51 #include "gnunet_dht_service.h"
52 #include "gnunet_namestore_service.h"
53 #include "gnunet_dns_service.h"
54 #include "gnunet_resolver_service.h"
55 #include "gnunet_dnsparser_lib.h"
56 #include "gnunet_gns_service.h"
58 #include "gnunet-service-gns_resolver.h"
59 #include "gnunet-service-gns_shorten.h"
60 #include "gnunet_vpn_service.h"
64 * Default DHT timeout for lookups.
66 #define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
69 * Default timeout for DNS lookups.
71 #define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
74 * Default timeout for VPN redirections.
76 #define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
79 * DHT replication level
81 #define DHT_GNS_REPLICATION_LEVEL 5
84 * How deep do we allow recursions to go before we abort?
86 #define MAX_RECURSION 256
90 * DLL to hold the authority chain we had to pass in the resolution
98 struct AuthorityChain *prev;
103 struct AuthorityChain *next;
106 * Resolver handle this entry in the chain belongs to.
108 struct GNS_ResolverHandle *rh;
111 * label/name corresponding to the authority
116 * #GNUNET_YES if the authority was a GNS authority,
117 * #GNUNET_NO if the authority was a DNS authority.
122 * Information about the resolver authority for this label.
128 * The zone of the GNS authority
130 struct GNUNET_CRYPTO_EccPublicKey gns_authority;
135 * Domain of the DNS resolver that is the authority.
136 * (appended to construct the DNS name to resolve;
137 * this is NOT the DNS name of the DNS server!).
139 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1];
142 * IP address of the DNS resolver that is authoritative.
143 * (this implementation currently only supports one
146 struct sockaddr_storage dns_ip;
156 * A result we got from DNS.
164 struct DnsResult *next;
169 struct DnsResult *prev;
172 * Binary value stored in the DNS record (appended to this struct)
177 * Expiration time for the DNS record, 0 if we didn't
178 * get anything useful (i.e. 'gethostbyname' was used).
180 uint64_t expiration_time;
183 * Number of bytes in 'data'.
188 * Type of the GNS/DNS record.
190 uint32_t record_type;
196 * Closure for #vpn_allocation_cb.
202 * Which resolution process are we processing.
204 struct GNS_ResolverHandle *rh;
207 * Handle to the VPN request that we were performing.
209 struct GNUNET_VPN_RedirectionRequest *vpn_request;
212 * Number of records serialized in 'rd_data'.
214 unsigned int rd_count;
217 * Serialized records.
222 * Number of bytes in 'rd_data'.
229 * Handle to a currenty pending resolution. On result (positive or
230 * negative) the #GNS_ResultProcessor is called.
232 struct GNS_ResolverHandle
238 struct GNS_ResolverHandle *next;
243 struct GNS_ResolverHandle *prev;
246 * The top-level GNS authoritative zone to query
248 struct GNUNET_CRYPTO_EccPublicKey authority_zone;
251 * called when resolution phase finishes
253 GNS_ResultProcessor proc;
256 * closure passed to proc
261 * Handle for DHT lookups. should be NULL if no lookups are in progress
263 struct GNUNET_DHT_GetHandle *get_handle;
266 * Handle to a VPN request, NULL if none is active.
268 struct VpnContext *vpn_ctx;
271 * Socket for a DNS request, NULL if none is active.
273 struct GNUNET_DNSSTUB_RequestSocket *dns_request;
276 * Handle for standard DNS resolution, NULL if none is active.
278 struct GNUNET_RESOLVER_RequestHandle *std_resolve;
281 * Pending Namestore task
283 struct GNUNET_NAMESTORE_QueueEntry *namestore_qe;
286 * Heap node associated with this lookup. Used to limit number of
287 * concurrent requests.
289 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
292 * DLL to store the authority chain
294 struct AuthorityChain *ac_head;
297 * DLL to store the authority chain
299 struct AuthorityChain *ac_tail;
302 * Private key of the shorten zone, NULL to not shorten.
304 struct GNUNET_CRYPTO_EccPrivateKey *shorten_key;
307 * ID of a task associated with the resolution process.
309 GNUNET_SCHEDULER_TaskIdentifier task_id;
312 * The name to resolve
317 * DLL of results we got from DNS.
319 struct DnsResult *dns_result_head;
322 * DLL of results we got from DNS.
324 struct DnsResult *dns_result_tail;
327 * Current offset in 'name' where we are resolving.
329 size_t name_resolution_pos;
337 * Desired type for the resolution.
342 * We increment the loop limiter for each step in a recursive
343 * resolution. If it passes our threshold (i.e. due to
344 * self-recursion in the resolution, i.e CNAME fun), we stop.
346 unsigned int loop_limiter;
352 * Our handle to the namestore service
354 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
357 * Our handle to the vpn service
359 static struct GNUNET_VPN_Handle *vpn_handle;
362 * Resolver handle to the dht
364 static struct GNUNET_DHT_Handle *dht_handle;
367 * Handle to perform DNS lookups.
369 static struct GNUNET_DNSSTUB_Context *dns_handle;
372 * Heap for limiting parallel DHT lookups
374 static struct GNUNET_CONTAINER_Heap *dht_lookup_heap;
377 * Maximum amount of parallel queries to the DHT
379 static unsigned long long max_allowed_background_queries;
382 * Head of resolver lookup list
384 static struct GNS_ResolverHandle *rlh_head;
387 * Tail of resolver lookup list
389 static struct GNS_ResolverHandle *rlh_tail;
393 * Global configuration.
395 static const struct GNUNET_CONFIGURATION_Handle *cfg;
399 * Check if name is in srv format (_x._y.xxx)
402 * @return #GNUNET_YES if true
405 is_srv (const char *name)
412 if (NULL == strstr (name, "._"))
415 ndup = GNUNET_strdup (name);
417 if (NULL == strtok (NULL, "."))
419 if (NULL == strtok (NULL, "."))
421 if (NULL != strtok (NULL, "."))
429 * Determine if this name is canonical (is a legal name in a zone, without delegation);
430 * note that we do not test that the name does not contain illegal characters, we only
431 * test for delegation. Note that service records (i.e. _foo._srv) are canonical names
432 * even though they consist of multiple labels.
435 * a.b.gnu = not canonical
437 * _foo._srv = canonical
438 * _f.bar = not canonical
440 * @param name the name to test
441 * @return #GNUNET_YES if canonical
444 is_canonical (const char *name)
449 if (NULL == strchr (name, '.'))
454 while (NULL != (dot = strchr (pos, '.')))
462 /* ************************** Resolution **************************** */
465 * Exands a name ending in .+ with the zone of origin.
467 * @param rh resolution context
468 * @param name name to modify (to be free'd or returned)
469 * @return updated name
472 translate_dot_plus (struct GNS_ResolverHandle *rh,
476 size_t s_len = strlen (name);
478 if (0 != strcmp (&name[s_len - 2],
480 return name; /* did not end in ".+" */
481 GNUNET_assert (GNUNET_YES == rh->ac_tail->gns_authority);
482 GNUNET_asprintf (&ret,
486 GNUNET_NAMESTORE_pkey_to_zkey (&rh->ac_tail->authority_info.gns_authority));
493 * Task scheduled to asynchronously fail a resolution.
495 * @param cls the 'struct GNS_ResolverHandle' of the resolution to fail
496 * @param tc task context
499 fail_resolution (void *cls,
500 const struct GNUNET_SCHEDULER_TaskContext *tc)
502 struct GNS_ResolverHandle *rh = cls;
504 rh->task_id = GNUNET_SCHEDULER_NO_TASK;
505 rh->proc (rh->proc_cls, 0, NULL);
506 GNS_resolver_lookup_cancel (rh);
509 #if (defined WINDOWS) || (defined DARWIN)
510 /* Don't have this on W32, here's a naive implementation
511 * Was somehow removed on OS X ... */
513 memrchr (const void *s, int c, size_t n)
516 unsigned char *ucs = (unsigned char *) s;
518 for (i = n - 1; i >= 0; i--)
520 return (void *) &ucs[i];
526 * Get the next, rightmost label from the name that we are trying to resolve,
527 * and update the resolution position accordingly.
529 * @param rh handle to the resolution operation to get the next label from
530 * @return NULL if there are no more labels
533 resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh)
539 if (0 == rh->name_resolution_pos)
541 dot = memrchr (rh->name, (int) '.', rh->name_resolution_pos);
544 /* done, this was the last one */
545 len = rh->name_resolution_pos;
547 rh->name_resolution_pos = 0;
551 /* advance by one label */
552 len = rh->name_resolution_pos - (dot - rh->name) - 1;
554 rh->name_resolution_pos = dot - rh->name;
556 return GNUNET_strndup (rp, len);
561 * Gives the cummulative result obtained to the callback and clean up the request.
563 * @param rh resolution process that has culminated in a result
566 transmit_lookup_dns_result (struct GNS_ResolverHandle *rh)
568 struct DnsResult *pos;
573 for (pos = rh->dns_result_head; NULL != pos; pos = pos->next)
576 struct GNUNET_NAMESTORE_RecordData rd[n];
579 for (pos = rh->dns_result_head; NULL != pos; pos = pos->next)
581 rd[i].data = pos->data;
582 rd[i].data_size = pos->data_size;
583 rd[i].record_type = pos->record_type;
584 if (0 == pos->expiration_time)
586 rd[i].flags = GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
587 rd[i].expiration_time = 0;
591 rd[i].flags = GNUNET_NAMESTORE_RF_NONE;
592 rd[i].expiration_time = pos->expiration_time;
595 rh->proc (rh->proc_cls,
599 GNS_resolver_lookup_cancel (rh);
604 * Add a result from DNS to the records to be returned to the application.
606 * @param rh resolution request to extend with a result
607 * @param expiration_time expiration time for the answer
608 * @param record_type DNS record type of the answer
609 * @param data_size number of bytes in @a data
610 * @param data binary data to return in DNS record
613 add_dns_result (struct GNS_ResolverHandle *rh,
614 uint64_t expiration_time,
615 uint32_t record_type,
619 struct DnsResult *res;
621 res = GNUNET_malloc (sizeof (struct DnsResult) + data_size);
622 res->expiration_time = expiration_time;
623 res->data_size = data_size;
624 res->record_type = record_type;
626 memcpy (&res[1], data, data_size);
627 GNUNET_CONTAINER_DLL_insert (rh->dns_result_head,
634 * We had to do a DNS lookup. Convert the result (if any) and return
637 * @param cls closure with the 'struct GNS_ResolverHandle'
638 * @param addr one of the addresses of the host, NULL for the last address
639 * @param addrlen length of the address
642 handle_dns_result (void *cls,
643 const struct sockaddr *addr,
646 struct GNS_ResolverHandle *rh = cls;
647 const struct sockaddr_in *sa4;
648 const struct sockaddr_in6 *sa6;
650 rh->std_resolve = NULL;
653 transmit_lookup_dns_result (rh);
656 switch (addr->sa_family)
659 sa4 = (const struct sockaddr_in *) addr;
661 0 /* expiration time is unknown */,
662 GNUNET_DNSPARSER_TYPE_A,
663 sizeof (struct in_addr),
667 sa6 = (const struct sockaddr_in6 *) addr;
669 0 /* expiration time is unknown */,
670 GNUNET_DNSPARSER_TYPE_AAAA,
671 sizeof (struct in6_addr),
682 * Task scheduled to continue with the resolution process.
684 * @param cls the 'struct GNS_ResolverHandle' of the resolution
685 * @param tc task context
688 recursive_resolution (void *cls,
689 const struct GNUNET_SCHEDULER_TaskContext *tc);
693 * Begin the resolution process from 'name', starting with
694 * the identification of the zone specified by 'name'.
696 * @param rh resolution to perform
699 start_resolver_lookup (struct GNS_ResolverHandle *rh);
703 * Function called with the result of a DNS resolution.
705 * @param cls the request handle of the resolution that
706 * we were attempting to make
707 * @param rs socket that received the response
708 * @param dns dns response, never NULL
709 * @param dns_len number of bytes in 'dns'
712 dns_result_parser (void *cls,
713 struct GNUNET_DNSSTUB_RequestSocket *rs,
714 const struct GNUNET_TUN_DnsHeader *dns,
717 struct GNS_ResolverHandle *rh = cls;
718 struct GNUNET_DNSPARSER_Packet *p;
719 const struct GNUNET_DNSPARSER_Record *rec;
720 unsigned int rd_count;
723 rh->dns_request = NULL;
724 GNUNET_SCHEDULER_cancel (rh->task_id);
725 rh->task_id = GNUNET_SCHEDULER_NO_TASK;
726 p = GNUNET_DNSPARSER_parse ((const char *) dns,
730 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
731 _("Failed to parse DNS response\n"));
732 rh->proc (rh->proc_cls, 0, NULL);
733 GNS_resolver_lookup_cancel (rh);
737 if ( (p->num_answers > 0) &&
738 (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) &&
739 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) )
741 GNUNET_free (rh->name);
742 rh->name = GNUNET_strdup (p->answers[0].data.hostname);
743 start_resolver_lookup (rh);
746 /* FIXME: add DNAME support */
748 /* convert from (parsed) DNS to (binary) GNS format! */
749 rd_count = p->num_answers + p->num_authority_records + p->num_additional_records;
751 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
753 char buf[UINT16_MAX];
758 memset (rd, 0, sizeof (rd));
759 for (i=0;i<rd_count;i++)
761 if (i < p->num_answers)
762 rec = &p->answers[i];
763 else if (i < p->num_answers + p->num_authority_records)
764 rec = &p->authority_records[i - p->num_answers];
766 rec = &p->authority_records[i - p->num_answers - p->num_authority_records];
767 /* As we copied the full DNS name to 'rh->ac_tail->label', this
768 should be the correct check to see if this record is actually
769 a record for our label... */
770 if (0 != strcmp (rec->name,
773 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
774 "Dropping record `%s', does not match desired name `%s'\n",
780 rd[i - skip].record_type = rec->type;
781 rd[i - skip].expiration_time = rec->expiration_time.abs_value_us;
784 case GNUNET_DNSPARSER_TYPE_A:
785 if (rec->data.raw.data_len != sizeof (struct in_addr))
791 rd[i - skip].data_size = rec->data.raw.data_len;
792 rd[i - skip].data = rec->data.raw.data;
794 case GNUNET_DNSPARSER_TYPE_AAAA:
795 if (rec->data.raw.data_len != sizeof (struct in6_addr))
801 rd[i - skip].data_size = rec->data.raw.data_len;
802 rd[i - skip].data = rec->data.raw.data;
804 case GNUNET_DNSPARSER_TYPE_CNAME:
805 case GNUNET_DNSPARSER_TYPE_PTR:
806 case GNUNET_DNSPARSER_TYPE_NS:
808 GNUNET_DNSPARSER_builder_add_name (buf,
818 case GNUNET_DNSPARSER_TYPE_SOA:
820 GNUNET_DNSPARSER_builder_add_soa (buf,
830 case GNUNET_DNSPARSER_TYPE_MX:
832 GNUNET_DNSPARSER_builder_add_mx (buf,
842 case GNUNET_DNSPARSER_TYPE_SRV:
844 GNUNET_DNSPARSER_builder_add_srv (buf,
855 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
856 _("Skipping record of unsupported type %d\n"),
862 rh->proc (rh->proc_cls, rd_count - skip, rd);
863 GNS_resolver_lookup_cancel (rh);
865 GNUNET_DNSPARSER_free_packet (p);
870 * Perform recursive DNS resolution. Asks the given DNS resolver to
871 * resolve "rh->dns_name", possibly recursively proceeding following
872 * NS delegations, CNAMES, etc., until 'rh->loop_limiter' bounds us or
873 * we find the answer.
875 * @param rh resolution information
878 recursive_dns_resolution (struct GNS_ResolverHandle *rh)
880 struct AuthorityChain *ac;
882 struct GNUNET_DNSPARSER_Query *query;
883 struct GNUNET_DNSPARSER_Packet *p;
885 size_t dns_request_length;
888 GNUNET_assert (NULL != ac);
889 GNUNET_assert (GNUNET_NO == ac->gns_authority);
890 switch (((const struct sockaddr *) &ac->authority_info.dns_authority.dns_ip)->sa_family)
893 sa_len = sizeof (struct sockaddr_in);
896 sa_len = sizeof (struct sockaddr_in6);
900 rh->proc (rh->proc_cls, 0, NULL);
901 GNS_resolver_lookup_cancel (rh);
904 query = GNUNET_new (struct GNUNET_DNSPARSER_Query);
905 query->name = GNUNET_strdup (ac->label);
906 query->type = rh->record_type;
907 query->class = GNUNET_TUN_DNS_CLASS_INTERNET;
908 p = GNUNET_new (struct GNUNET_DNSPARSER_Packet);
911 p->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
913 p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY;
914 p->flags.recursion_desired = 1;
916 GNUNET_DNSPARSER_pack (p, 1024, &dns_request, &dns_request_length))
919 rh->proc (rh->proc_cls, 0, NULL);
920 GNS_resolver_lookup_cancel (rh);
924 rh->dns_request = GNUNET_DNSSTUB_resolve (dns_handle,
925 (const struct sockaddr *) &ac->authority_info.dns_authority.dns_ip,
931 rh->task_id = GNUNET_SCHEDULER_add_delayed (DNS_LOOKUP_TIMEOUT,
935 GNUNET_free (dns_request);
936 GNUNET_DNSPARSER_free_packet (p);
941 * We encountered a CNAME record during our resolution.
942 * Merge it into our chain.
944 * @param rh resolution we are performing
945 * @param cname value of the cname record we got for the current
946 * authority chain tail
949 handle_gns_cname_result (struct GNS_ResolverHandle *rh,
955 nlen = strlen (cname);
960 /* CNAME resolution continues relative to current domain */
961 if (0 == rh->name_resolution_pos)
963 res = GNUNET_strndup (cname, nlen - 2);
964 rh->name_resolution_pos = nlen - 2;
968 GNUNET_asprintf (&res,
970 (int) rh->name_resolution_pos,
974 rh->name_resolution_pos = strlen (res);
976 GNUNET_free (rh->name);
978 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
982 /* name is absolute, start from the beginning */
983 GNUNET_free (rh->name);
984 rh->name = GNUNET_strdup (cname);
985 start_resolver_lookup (rh);
990 * Process a records that were decrypted from a block.
992 * @param cls closure with the 'struct GNS_ResolverHandle'
993 * @param rd_count number of entries in @a rd array
994 * @param rd array of records with data to store
997 handle_gns_resolution_result (void *cls,
998 unsigned int rd_count,
999 const struct GNUNET_NAMESTORE_RecordData *rd);
1003 * Callback invoked from the VPN service once a redirection is
1004 * available. Provides the IP address that can now be used to
1005 * reach the requested destination. Replaces the "VPN" record
1006 * with the respective A/AAAA record and continues processing.
1008 * @param cls closure
1009 * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error;
1010 * will match 'result_af' from the request
1011 * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
1012 * that the VPN allocated for the redirection;
1013 * traffic to this IP will now be redirected to the
1014 * specified target peer; NULL on error
1017 vpn_allocation_cb (void *cls,
1019 const void *address)
1021 struct VpnContext *vpn_ctx = cls;
1022 struct GNS_ResolverHandle *rh = vpn_ctx->rh;
1023 struct GNUNET_NAMESTORE_RecordData rd[vpn_ctx->rd_count];
1026 vpn_ctx->vpn_request = NULL;
1028 GNUNET_assert (GNUNET_OK ==
1029 GNUNET_NAMESTORE_records_deserialize (vpn_ctx->rd_data_size,
1033 for (i=0;i<vpn_ctx->rd_count;i++)
1035 if (GNUNET_NAMESTORE_TYPE_VPN == rd[i].record_type)
1040 rd[i].record_type = GNUNET_DNSPARSER_TYPE_A;
1041 rd[i].data_size = sizeof (struct in_addr);
1042 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us;
1044 rd[i].data = address;
1047 rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA;
1048 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us;
1050 rd[i].data = address;
1051 rd[i].data_size = sizeof (struct in6_addr);
1059 GNUNET_assert (i < vpn_ctx->rd_count);
1060 handle_gns_resolution_result (rh,
1063 GNUNET_free (vpn_ctx->rd_data);
1064 GNUNET_free (vpn_ctx);
1069 * Process a records that were decrypted from a block.
1071 * @param cls closure with the 'struct GNS_ResolverHandle'
1072 * @param rd_count number of entries in @a rd array
1073 * @param rd array of records with data to store
1076 handle_gns_resolution_result (void *cls,
1077 unsigned int rd_count,
1078 const struct GNUNET_NAMESTORE_RecordData *rd)
1080 struct GNS_ResolverHandle *rh = cls;
1081 struct AuthorityChain *ac;
1084 struct sockaddr *sa;
1085 struct sockaddr_in v4;
1086 struct sockaddr_in6 v6;
1089 struct VpnContext *vpn_ctx;
1090 const struct GNUNET_TUN_GnsVpnRecord *vpn;
1092 struct GNUNET_HashCode vhash;
1094 char scratch[UINT16_MAX];
1096 size_t scratch_start;
1098 struct GNUNET_NAMESTORE_RecordData rd_new[rd_count];
1099 unsigned int rd_off;
1101 if (0 == rh->name_resolution_pos)
1103 /* top-level match, are we done yet? */
1104 if ( (rd_count > 0) &&
1105 (GNUNET_DNSPARSER_TYPE_CNAME == rd[0].record_type) &&
1106 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) )
1108 cname = GNUNET_strndup (rd[0].data,
1110 handle_gns_cname_result (rh,
1112 GNUNET_free (cname);
1115 /* If A/AAAA was requested, but we got a VPN
1116 record, we convert it to A/AAAA using GNUnet VPN */
1117 if ( (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ||
1118 (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type) )
1120 for (i=0;i<rd_count;i++)
1122 if (GNUNET_NAMESTORE_TYPE_VPN == rd[i].record_type)
1124 af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : AF_INET6;
1125 if (sizeof (struct GNUNET_TUN_GnsVpnRecord) <
1128 GNUNET_break_op (0);
1129 rh->proc (rh->proc_cls, 0, NULL);
1130 GNS_resolver_lookup_cancel (rh);
1133 vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data;
1134 vname = (const char *) &vpn[1];
1135 if ('\0' != vname[rd[i].data_size - 1 - sizeof (struct GNUNET_TUN_GnsVpnRecord)])
1137 GNUNET_break_op (0);
1138 rh->proc (rh->proc_cls, 0, NULL);
1139 GNS_resolver_lookup_cancel (rh);
1142 GNUNET_CRYPTO_hash (vname,
1143 strlen (vname), // FIXME: +1?
1145 vpn_ctx = GNUNET_new (struct VpnContext);
1146 rh->vpn_ctx = vpn_ctx;
1148 vpn_ctx->rd_data_size = GNUNET_NAMESTORE_records_get_size (rd_count,
1150 vpn_ctx->rd_data = GNUNET_malloc (vpn_ctx->rd_data_size);
1151 (void) GNUNET_NAMESTORE_records_serialize (rd_count,
1153 vpn_ctx->rd_data_size,
1155 vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle,
1161 GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT),
1168 /* convert relative names in record values to absolute names,
1169 using 'scratch' array for memory allocations */
1172 for (i=0;i<rd_count;i++)
1174 rd_new[rd_off] = rd[i];
1175 /* Check if the embedded name(s) end in "+", and if so,
1176 replace the "+" with the zone at "ac_tail", changing the name
1177 to a ".zkey". The name is allocated on the 'scratch' array,
1178 so we can free it afterwards. */
1179 switch (rd[i].record_type)
1181 case GNUNET_DNSPARSER_TYPE_CNAME:
1186 cname = GNUNET_DNSPARSER_parse_name (rd[i].data,
1189 if ( (NULL == cname) ||
1190 (off != rd[i].data_size) )
1192 GNUNET_break_op (0); /* record not well-formed */
1196 cname = translate_dot_plus (rh, cname);
1197 scratch_start = scratch_off;
1199 GNUNET_DNSPARSER_builder_add_name (scratch,
1208 rd_new[rd_off].data = &scratch[scratch_start];
1209 rd_new[rd_off].data_size = scratch_off - scratch_start;
1212 GNUNET_free (cname);
1216 case GNUNET_DNSPARSER_TYPE_SOA:
1218 struct GNUNET_DNSPARSER_SoaRecord *soa;
1221 soa = GNUNET_DNSPARSER_parse_soa (rd[i].data,
1224 if ( (NULL == soa) ||
1225 (off != rd[i].data_size) )
1227 GNUNET_break_op (0); /* record not well-formed */
1231 soa->mname = translate_dot_plus (rh, soa->mname);
1232 soa->rname = translate_dot_plus (rh, soa->rname);
1233 scratch_start = scratch_off;
1235 GNUNET_DNSPARSER_builder_add_soa (scratch,
1244 rd_new[rd_off].data = &scratch[scratch_start];
1245 rd_new[rd_off].data_size = scratch_off - scratch_start;
1248 GNUNET_DNSPARSER_free_soa (soa);
1252 case GNUNET_DNSPARSER_TYPE_MX:
1254 struct GNUNET_DNSPARSER_MxRecord *mx;
1257 mx = GNUNET_DNSPARSER_parse_mx (rd[i].data,
1260 if ( (NULL == mx) ||
1261 (off != rd[i].data_size) )
1263 GNUNET_break_op (0); /* record not well-formed */
1267 mx->mxhost = translate_dot_plus (rh, mx->mxhost);
1268 scratch_start = scratch_off;
1270 GNUNET_DNSPARSER_builder_add_mx (scratch,
1279 rd_new[rd_off].data = &scratch[scratch_start];
1280 rd_new[rd_off].data_size = scratch_off - scratch_start;
1283 GNUNET_DNSPARSER_free_mx (mx);
1287 case GNUNET_DNSPARSER_TYPE_SRV:
1289 struct GNUNET_DNSPARSER_SrvRecord *srv;
1292 /* FIXME: passing rh->name here is is not necessarily what we want
1293 (SRV support not finished) */
1294 srv = GNUNET_DNSPARSER_parse_srv (rh->name,
1298 if ( (NULL == srv) ||
1299 (off != rd[i].data_size) )
1301 GNUNET_break_op (0); /* record not well-formed */
1305 srv->domain_name = translate_dot_plus (rh, srv->domain_name);
1306 srv->target = translate_dot_plus (rh, srv->target);
1307 scratch_start = scratch_off;
1309 GNUNET_DNSPARSER_builder_add_srv (scratch,
1318 rd_new[rd_off].data = &scratch[scratch_start];
1319 rd_new[rd_off].data_size = scratch_off - scratch_start;
1322 GNUNET_DNSPARSER_free_srv (srv);
1331 /* yes, we are done, return result */
1332 rh->proc (rh->proc_cls, rd_off, rd_new);
1333 GNS_resolver_lookup_cancel (rh);
1336 /* need to recurse, check if we can */
1337 for (i=0;i<rd_count;i++)
1339 switch (rd[i].record_type)
1341 case GNUNET_NAMESTORE_TYPE_PKEY:
1342 /* delegation to another zone */
1343 if (sizeof (struct GNUNET_CRYPTO_EccPublicKey) !=
1346 GNUNET_break_op (0);
1347 rh->proc (rh->proc_cls, 0, NULL);
1348 GNS_resolver_lookup_cancel (rh);
1351 /* expand authority chain */
1352 ac = GNUNET_new (struct AuthorityChain);
1354 ac->gns_authority = GNUNET_YES;
1355 memcpy (&ac->authority_info.gns_authority,
1357 sizeof (struct GNUNET_CRYPTO_EccPublicKey));
1358 ac->label = resolver_lookup_get_next_label (rh);
1359 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1363 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1366 case GNUNET_DNSPARSER_TYPE_NS:
1367 /* resolution continues within DNS */
1368 if (GNUNET_DNSPARSER_MAX_NAME_LENGTH < rd[i].data_size)
1370 GNUNET_break_op (0);
1371 rh->proc (rh->proc_cls, 0, NULL);
1372 GNS_resolver_lookup_cancel (rh);
1375 /* find associated A/AAAA record */
1377 for (j=0;j<rd_count;j++)
1379 switch (rd[j].record_type)
1381 case GNUNET_DNSPARSER_TYPE_A:
1382 if (sizeof (struct in_addr) != rd[i].data_size)
1384 GNUNET_break_op (0);
1385 rh->proc (rh->proc_cls, 0, NULL);
1386 GNS_resolver_lookup_cancel (rh);
1389 /* FIXME: might want to check if we support IPv4 here,
1390 and otherwise skip this one and hope we find another */
1391 memset (&v4, 0, sizeof (v4));
1392 sa_len = sizeof (v4);
1393 v4.sin_family = AF_INET;
1394 v4.sin_port = htons (53);
1395 #if HAVE_SOCKADDR_IN_SIN_LEN
1396 v4.sin_len = (u_char) sa_len;
1398 memcpy (&v4.sin_addr,
1400 sizeof (struct in_addr));
1401 sa = (struct sockaddr *) &v4;
1403 case GNUNET_DNSPARSER_TYPE_AAAA:
1404 if (sizeof (struct in6_addr) != rd[i].data_size)
1406 GNUNET_break_op (0);
1407 rh->proc (rh->proc_cls, 0, NULL);
1408 GNS_resolver_lookup_cancel (rh);
1411 /* FIXME: might want to check if we support IPv6 here,
1412 and otherwise skip this one and hope we find another */
1413 memset (&v6, 0, sizeof (v6));
1414 sa_len = sizeof (v6);
1415 v6.sin6_family = AF_INET6;
1416 v6.sin6_port = htons (53);
1417 #if HAVE_SOCKADDR_IN_SIN_LEN
1418 v6.sin6_len = (u_char) sa_len;
1420 memcpy (&v6.sin6_addr,
1422 sizeof (struct in6_addr));
1423 sa = (struct sockaddr *) &v6;
1429 /* expand authority chain */
1430 ac = GNUNET_new (struct AuthorityChain);
1432 strncpy (ac->authority_info.dns_authority.name,
1435 ac->authority_info.dns_authority.name[rd[i].data_size] = '\0';
1436 memcpy (&ac->authority_info.dns_authority.dns_ip,
1439 /* for DNS recursion, the label is the full DNS name,
1440 created from the remainder of the GNS name and the
1441 name in the NS record */
1442 GNUNET_asprintf (&ac->label,
1444 (int) rh->name_resolution_pos,
1446 ac->authority_info.dns_authority.name);
1447 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1450 if (strlen (ac->label) > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
1452 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1453 _("GNS lookup resulted in DNS name that is too long (`%s')\n"),
1455 rh->proc (rh->proc_cls, 0, NULL);
1456 GNS_resolver_lookup_cancel (rh);
1460 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1463 case GNUNET_DNSPARSER_TYPE_CNAME:
1464 cname = GNUNET_strndup (rd[i].data,
1466 handle_gns_cname_result (rh,
1468 GNUNET_free (cname);
1470 /* FIXME: handle DNAME */
1476 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1477 _("GNS lookup recursion failed (no delegation record found)\n"));
1478 rh->proc (rh->proc_cls, 0, NULL);
1479 GNS_resolver_lookup_cancel (rh);
1484 * Function called once the namestore has completed the request for
1487 * @param cls closure with the 'struct GNS_ResolverHandle'
1488 * @param success #GNUNET_OK on success
1489 * @param emsg error message
1492 namestore_cache_continuation (void *cls,
1496 struct GNS_ResolverHandle *rh = cls;
1498 rh->namestore_qe = NULL;
1500 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1501 _("Failed to cache GNS resolution: %s\n"),
1507 * Iterator called on each result obtained for a DHT
1508 * operation that expects a reply
1510 * @param cls closure with the 'struct GNS_ResolverHandle'
1511 * @param exp when will this value expire
1512 * @param key key of the result
1513 * @param get_path peers on reply path (or NULL if not recorded)
1514 * [0] = datastore's first neighbor, [length - 1] = local peer
1515 * @param get_path_length number of entries in get_path
1516 * @param put_path peers on the PUT path (or NULL if not recorded)
1517 * [0] = origin, [length - 1] = datastore
1518 * @param put_path_length number of entries in get_path
1519 * @param type type of the result
1520 * @param size number of bytes in data
1521 * @param data pointer to the result data
1524 handle_dht_response (void *cls,
1525 struct GNUNET_TIME_Absolute exp,
1526 const struct GNUNET_HashCode * key,
1527 const struct GNUNET_PeerIdentity *get_path,
1528 unsigned int get_path_length,
1529 const struct GNUNET_PeerIdentity *put_path,
1530 unsigned int put_path_length,
1531 enum GNUNET_BLOCK_Type type,
1532 size_t size, const void *data)
1534 struct GNS_ResolverHandle *rh = cls;
1535 struct AuthorityChain *ac = rh->ac_tail;
1536 const struct GNUNET_NAMESTORE_Block *block;
1538 GNUNET_DHT_get_stop (rh->get_handle);
1539 rh->get_handle = NULL;
1540 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
1541 rh->dht_heap_node = NULL;
1542 if (size < sizeof (struct GNUNET_NAMESTORE_Block))
1544 /* how did this pass DHT block validation!? */
1546 rh->proc (rh->proc_cls, 0, NULL);
1547 GNS_resolver_lookup_cancel (rh);
1552 ntohs (block->purpose.size) +
1553 sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
1554 sizeof (struct GNUNET_CRYPTO_EccSignature))
1556 /* how did this pass DHT block validation!? */
1558 rh->proc (rh->proc_cls, 0, NULL);
1559 GNS_resolver_lookup_cancel (rh);
1563 GNUNET_NAMESTORE_block_decrypt (block,
1564 &ac->authority_info.gns_authority,
1566 &handle_gns_resolution_result,
1569 GNUNET_break_op (0); /* block was ill-formed */
1570 rh->proc (rh->proc_cls, 0, NULL);
1571 GNS_resolver_lookup_cancel (rh);
1574 /* Cache well-formed blocks */
1575 rh->namestore_qe = GNUNET_NAMESTORE_block_cache (namestore_handle,
1577 &namestore_cache_continuation,
1583 * Process a record that was stored in the namestore.
1585 * @param cls closure with the `struct GNS_ResolverHandle`
1586 * @param block block that was stored in the namestore
1589 handle_namestore_block_response (void *cls,
1590 const struct GNUNET_NAMESTORE_Block *block)
1592 struct GNS_ResolverHandle *rh = cls;
1593 struct GNS_ResolverHandle *rx;
1594 struct AuthorityChain *ac = rh->ac_tail;
1595 const char *label = ac->label;
1596 const struct GNUNET_CRYPTO_EccPublicKey *auth = &ac->authority_info.gns_authority;
1597 struct GNUNET_HashCode query;
1599 GNUNET_NAMESTORE_query_from_public_key (auth,
1602 rh->namestore_qe = NULL;
1605 /* Namestore knows nothing; try DHT lookup */
1606 rh->get_handle = GNUNET_DHT_get_start (dht_handle,
1607 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
1609 DHT_GNS_REPLICATION_LEVEL,
1610 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1612 &handle_dht_response, rh);
1613 rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
1615 GNUNET_TIME_absolute_get ().abs_value_us);
1616 if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries)
1618 /* fail longest-standing DHT request */
1619 rx = GNUNET_CONTAINER_heap_peek (dht_lookup_heap);
1620 rx->proc (rx->proc_cls, 0, NULL);
1621 GNS_resolver_lookup_cancel (rx);
1626 GNUNET_NAMESTORE_block_decrypt (block,
1629 &handle_gns_resolution_result,
1632 GNUNET_break_op (0); /* block was ill-formed */
1633 rh->proc (rh->proc_cls, 0, NULL);
1634 GNS_resolver_lookup_cancel (rh);
1641 * Lookup tail of our authority chain in the namestore.
1643 * @param rh query we are processing
1646 recursive_gns_resolution_namestore (struct GNS_ResolverHandle *rh)
1648 struct AuthorityChain *ac = rh->ac_tail;
1649 struct GNUNET_HashCode query;
1651 GNUNET_NAMESTORE_query_from_public_key (&ac->authority_info.gns_authority,
1654 rh->namestore_qe = GNUNET_NAMESTORE_lookup_block (namestore_handle,
1656 &handle_namestore_block_response,
1662 * Task scheduled to continue with the resolution process.
1664 * @param cls the `struct GNS_ResolverHandle` of the resolution
1665 * @param tc task context
1668 recursive_resolution (void *cls,
1669 const struct GNUNET_SCHEDULER_TaskContext *tc)
1671 struct GNS_ResolverHandle *rh = cls;
1673 rh->task_id = GNUNET_SCHEDULER_NO_TASK;
1674 if (MAX_RECURSION < rh->loop_limiter++)
1676 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1677 "Encountered unbounded recursion resolving `%s'\n",
1679 rh->proc (rh->proc_cls, 0, NULL);
1680 GNS_resolver_lookup_cancel (rh);
1683 if (GNUNET_YES == rh->ac_tail->gns_authority)
1684 recursive_gns_resolution_namestore (rh);
1686 recursive_dns_resolution (rh);
1691 * Begin the resolution process from 'name', starting with
1692 * the identification of the zone specified by 'name'.
1694 * @param rh resolution to perform
1697 start_resolver_lookup (struct GNS_ResolverHandle *rh)
1699 struct AuthorityChain *ac;
1704 if ( ( (GNUNET_YES == is_canonical (rh->name)) &&
1705 (0 != strcmp (GNUNET_GNS_TLD, rh->name)) ) ||
1706 ( (GNUNET_YES != is_gnu_tld (rh->name)) &&
1707 (GNUNET_YES != is_zkey_tld (rh->name)) ) )
1709 /* use standard DNS lookup */
1712 switch (rh->record_type)
1714 case GNUNET_DNSPARSER_TYPE_A:
1717 case GNUNET_DNSPARSER_TYPE_AAAA:
1724 rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name,
1731 if (is_zkey_tld (rh->name))
1733 /* Name ends with ".zkey", try to replace authority zone with zkey
1735 GNUNET_free (resolver_lookup_get_next_label (rh)); /* will return "zkey" */
1736 x = resolver_lookup_get_next_label (rh); /* will return 'x' coordinate */
1737 y = resolver_lookup_get_next_label (rh); /* will return 'y' coordinate */
1738 GNUNET_asprintf (&pkey,
1744 GNUNET_CRYPTO_ecc_public_key_from_string (pkey,
1746 &rh->authority_zone)) )
1748 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1749 _("Hostname `%s' is not well-formed, resolution fails\n"),
1751 rh->task_id = GNUNET_SCHEDULER_add_now (&fail_resolution, rh);
1753 GNUNET_free_non_null (x);
1754 GNUNET_free_non_null (y);
1759 /* Name ends with ".gnu", eat ".gnu" and continue with resolution */
1760 GNUNET_free (resolver_lookup_get_next_label (rh));
1762 ac = GNUNET_new (struct AuthorityChain);
1764 ac->label = resolver_lookup_get_next_label (rh);
1765 if (NULL == ac->label)
1766 /* name was just "gnu", so we default to label '+' */
1767 ac->label = GNUNET_strdup (GNUNET_GNS_MASTERZONE_STR);
1768 ac->gns_authority = GNUNET_YES;
1769 ac->authority_info.gns_authority = rh->authority_zone;
1770 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1773 rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1779 * Lookup of a record in a specific zone calls lookup result processor
1782 * @param zone the zone to perform the lookup in
1783 * @param record_type the record type to look up
1784 * @param name the name to look up
1785 * @param shorten_key a private key for use with PSEU import (can be NULL)
1786 * @param only_cached #GNUNET_NO to only check locally not DHT for performance
1787 * @param proc the processor to call on result
1788 * @param proc_cls the closure to pass to @a proc
1789 * @return handle to cancel operation
1791 struct GNS_ResolverHandle *
1792 GNS_resolver_lookup (const struct GNUNET_CRYPTO_EccPublicKey *zone,
1793 uint32_t record_type,
1795 const struct GNUNET_CRYPTO_EccPrivateKey *shorten_key,
1797 GNS_ResultProcessor proc, void *proc_cls)
1799 struct GNS_ResolverHandle *rh;
1801 rh = GNUNET_new (struct GNS_ResolverHandle);
1802 GNUNET_CONTAINER_DLL_insert (rlh_head,
1805 rh->authority_zone = *zone;
1807 rh->proc_cls = proc_cls;
1808 rh->only_cached = only_cached;
1809 rh->record_type = record_type;
1810 rh->name = GNUNET_strdup (name);
1811 rh->name_resolution_pos = strlen (name);
1812 if (NULL != shorten_key)
1814 rh->shorten_key = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
1815 *rh->shorten_key = *shorten_key;
1817 start_resolver_lookup (rh);
1823 * Cancel active resolution (i.e. client disconnected).
1825 * @param rh resolution to abort
1828 GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh)
1830 struct DnsResult *dr;
1831 struct AuthorityChain *ac;
1832 struct VpnContext *vpn_ctx;
1834 GNUNET_CONTAINER_DLL_remove (rlh_head,
1837 while (NULL != (ac = rh->ac_head))
1839 GNUNET_CONTAINER_DLL_remove (rh->ac_head,
1842 GNUNET_free (ac->label);
1845 if (GNUNET_SCHEDULER_NO_TASK != rh->task_id)
1847 GNUNET_SCHEDULER_cancel (rh->task_id);
1848 rh->task_id = GNUNET_SCHEDULER_NO_TASK;
1850 if (NULL != rh->get_handle)
1852 GNUNET_DHT_get_stop (rh->get_handle);
1853 rh->get_handle = NULL;
1855 if (NULL != rh->dht_heap_node)
1857 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
1858 rh->dht_heap_node = NULL;
1860 if (NULL != (vpn_ctx = rh->vpn_ctx))
1862 GNUNET_VPN_cancel_request (vpn_ctx->vpn_request);
1863 GNUNET_free (vpn_ctx->rd_data);
1864 GNUNET_free (vpn_ctx);
1866 if (NULL != rh->dns_request)
1868 GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
1869 rh->dns_request = NULL;
1871 if (NULL != rh->namestore_qe)
1873 GNUNET_NAMESTORE_cancel (rh->namestore_qe);
1874 rh->namestore_qe = NULL;
1876 if (NULL != rh->std_resolve)
1878 GNUNET_RESOLVER_request_cancel (rh->std_resolve);
1879 rh->std_resolve = NULL;
1881 while (NULL != (dr = rh->dns_result_head))
1883 GNUNET_CONTAINER_DLL_remove (rh->dns_result_head,
1884 rh->dns_result_tail,
1888 GNUNET_free_non_null (rh->shorten_key);
1889 GNUNET_free (rh->name);
1894 /* ***************** Resolver initialization ********************* */
1898 * Initialize the resolver
1900 * @param nh the namestore handle
1901 * @param dht the dht handle
1902 * @param c configuration handle
1903 * @param max_bg_queries maximum number of parallel background queries in dht
1906 GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
1907 struct GNUNET_DHT_Handle *dht,
1908 const struct GNUNET_CONFIGURATION_Handle *c,
1909 unsigned long long max_bg_queries)
1914 namestore_handle = nh;
1917 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1918 max_allowed_background_queries = max_bg_queries;
1920 GNUNET_CONFIGURATION_get_value_string (c,
1925 /* user did not specify DNS resolver, use 8.8.8.8 */
1926 dns_ip = GNUNET_strdup ("8.8.8.8");
1928 dns_handle = GNUNET_DNSSTUB_start (dns_ip);
1929 GNUNET_free (dns_ip);
1930 vpn_handle = GNUNET_VPN_connect (cfg);
1938 GNS_resolver_done ()
1940 struct GNS_ResolverHandle *rh;
1942 /* abort active resolutions */
1943 while (NULL != (rh = rlh_head))
1945 rh->proc (rh->proc_cls, 0, NULL);
1946 GNS_resolver_lookup_cancel (rh);
1948 GNUNET_CONTAINER_heap_destroy (dht_lookup_heap);
1949 dht_lookup_heap = NULL;
1950 GNUNET_DNSSTUB_stop (dns_handle);
1952 GNUNET_VPN_disconnect (vpn_handle);
1955 namestore_handle = NULL;
1959 /* *************** common helper functions (do not really belong here) *********** */
1962 * Checks if @a name ends in ".TLD"
1964 * @param name the name to check
1965 * @param tld the TLD to check for
1966 * @return GNUNET_YES or GNUNET_NO
1969 is_tld (const char* name, const char* tld)
1973 if (strlen (name) <= strlen (tld))
1975 offset = strlen (name) - strlen (tld);
1976 if (0 != strcmp (name + offset, tld))
1982 /* end of gnunet-service-gns_resolver.c */