-just replacing if by switch, in preparation for future changes
[oweals/gnunet.git] / src / gns / gnunet-service-gns_resolver.c
1 /*
2      This file is part of GNUnet.
3      (C) 2011-2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file gns/gnunet-service-gns_resolver.c
23  * @brief GNU Name System resolver logic
24  * @author Martin Schanzenbach
25  * @author Christian Grothoff
26  *
27  * TODO:
28  * - GNS: handle special SRV names --- no delegation, direct lookup;
29  *        can likely be done in 'resolver_lookup_get_next_label'. (#3003)
30  * - revocation checks (use CORE-level broadcasts!), (#3004)
31  * - DNAME support (#3005)
32  */
33 #include "platform.h"
34 #include "gnunet_util_lib.h"
35 #include "gnunet_dnsstub_lib.h"
36 #include "gnunet_dht_service.h"
37 #include "gnunet_namestore_service.h"
38 #include "gnunet_dns_service.h"
39 #include "gnunet_resolver_service.h"
40 #include "gnunet_dnsparser_lib.h"
41 #include "gnunet_gns_service.h"
42 #include "gns.h"
43 #include "gnunet-service-gns_resolver.h"
44 #include "gnunet-service-gns_shorten.h"
45 #include "gnunet_vpn_service.h"
46
47
48 /**
49  * Default DHT timeout for lookups.
50  */
51 #define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
52
53 /**
54  * Default timeout for DNS lookups.
55  */
56 #define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
57
58 /**
59  * Default timeout for VPN redirections.
60  */
61 #define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
62
63 /**
64  * DHT replication level
65  */
66 #define DHT_GNS_REPLICATION_LEVEL 5
67
68 /**
69  * How deep do we allow recursions to go before we abort?
70  */
71 #define MAX_RECURSION 256
72
73
74 /**
75  * DLL to hold the authority chain we had to pass in the resolution
76  * process.
77  */
78 struct AuthorityChain
79 {
80   /**
81    * This is a DLL.
82    */
83   struct AuthorityChain *prev;
84
85   /**
86    * This is a DLL.
87    */
88   struct AuthorityChain *next;
89
90   /**
91    * Resolver handle this entry in the chain belongs to.
92    */
93   struct GNS_ResolverHandle *rh;
94
95   /**
96    * label/name corresponding to the authority 
97    */
98   char *label;
99   
100   /**
101    * #GNUNET_YES if the authority was a GNS authority,
102    * #GNUNET_NO if the authority was a DNS authority.
103    */
104   int gns_authority;
105
106   /**
107    * Information about the resolver authority for this label.
108    */
109   union
110   {
111
112     /**
113      * The zone of the GNS authority 
114      */
115     struct GNUNET_CRYPTO_EccPublicSignKey gns_authority;
116
117     struct
118     {
119       /**
120        * Domain of the DNS resolver that is the authority.
121        * (appended to construct the DNS name to resolve;
122        * this is NOT the DNS name of the DNS server!).
123        */
124       char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1];
125
126       /**
127        * IP address of the DNS resolver that is authoritative.
128        * (this implementation currently only supports one
129        * IP at a time).
130        */
131       struct sockaddr_storage dns_ip;
132
133     } dns_authority;
134
135   } authority_info;
136   
137 };
138
139
140 /**
141  * A result we got from DNS.
142  */
143 struct DnsResult
144 {
145
146   /**
147    * Kept in DLL.
148    */
149   struct DnsResult *next;
150
151   /**
152    * Kept in DLL.
153    */
154   struct DnsResult *prev;
155
156   /**
157    * Binary value stored in the DNS record (appended to this struct)
158    */
159   const void *data;
160
161   /**
162    * Expiration time for the DNS record, 0 if we didn't
163    * get anything useful (i.e. 'gethostbyname' was used).
164    */
165   uint64_t expiration_time;
166
167   /**
168    * Number of bytes in 'data'.
169    */
170   size_t data_size;
171
172   /**
173    * Type of the GNS/DNS record.
174    */
175   uint32_t record_type;
176
177 };
178
179
180 /**
181  * Closure for #vpn_allocation_cb.
182  */
183 struct VpnContext 
184 {
185
186   /** 
187    * Which resolution process are we processing.
188    */
189   struct GNS_ResolverHandle *rh;
190
191   /**
192    * Handle to the VPN request that we were performing.
193    */
194   struct GNUNET_VPN_RedirectionRequest *vpn_request;
195
196   /**
197    * Number of records serialized in 'rd_data'.
198    */
199   unsigned int rd_count;
200   
201   /**
202    * Serialized records.
203    */
204   char *rd_data;
205   
206   /**
207    * Number of bytes in 'rd_data'.
208    */
209   size_t rd_data_size;
210 };
211
212
213 /**
214  * Handle to a currenty pending resolution.  On result (positive or
215  * negative) the #GNS_ResultProcessor is called.  
216  */
217 struct GNS_ResolverHandle
218 {
219
220   /**
221    * DLL 
222    */
223   struct GNS_ResolverHandle *next;
224
225   /**
226    * DLL 
227    */
228   struct GNS_ResolverHandle *prev;
229
230   /**
231    * The top-level GNS authoritative zone to query 
232    */
233   struct GNUNET_CRYPTO_EccPublicSignKey authority_zone;
234
235   /**
236    * called when resolution phase finishes 
237    */
238   GNS_ResultProcessor proc;
239   
240   /**
241    * closure passed to proc 
242    */
243   void* proc_cls;
244
245   /**
246    * Handle for DHT lookups. should be NULL if no lookups are in progress 
247    */
248   struct GNUNET_DHT_GetHandle *get_handle;
249
250   /**
251    * Handle to a VPN request, NULL if none is active.
252    */
253   struct VpnContext *vpn_ctx;
254
255   /**
256    * Socket for a DNS request, NULL if none is active.
257    */
258   struct GNUNET_DNSSTUB_RequestSocket *dns_request;
259
260   /**
261    * Handle for standard DNS resolution, NULL if none is active.
262    */
263   struct GNUNET_RESOLVER_RequestHandle *std_resolve;
264
265   /**
266    * Pending Namestore task
267    */
268   struct GNUNET_NAMESTORE_QueueEntry *namestore_qe;
269
270   /**
271    * Heap node associated with this lookup.  Used to limit number of
272    * concurrent requests.
273    */
274   struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
275
276   /**
277    * DLL to store the authority chain 
278    */
279   struct AuthorityChain *ac_head;
280
281   /**
282    * DLL to store the authority chain 
283    */
284   struct AuthorityChain *ac_tail;
285
286   /**
287    * Private key of the shorten zone, NULL to not shorten.
288    */
289   struct GNUNET_CRYPTO_EccPrivateKey *shorten_key;
290
291   /**
292    * ID of a task associated with the resolution process.
293    */
294   GNUNET_SCHEDULER_TaskIdentifier task_id;
295
296   /**
297    * The name to resolve 
298    */
299   char *name;
300
301   /**
302    * DLL of results we got from DNS.
303    */
304   struct DnsResult *dns_result_head;
305
306   /**
307    * DLL of results we got from DNS.
308    */
309   struct DnsResult *dns_result_tail;
310
311   /**
312    * Current offset in 'name' where we are resolving.
313    */
314   size_t name_resolution_pos;
315
316   /**
317    * Use only cache 
318    */
319   int only_cached;
320
321   /**
322    * Desired type for the resolution.
323    */
324   int record_type;
325
326   /**
327    * We increment the loop limiter for each step in a recursive
328    * resolution.  If it passes our threshold (i.e. due to 
329    * self-recursion in the resolution, i.e CNAME fun), we stop.
330    */
331   unsigned int loop_limiter;
332
333 };
334
335
336 /**
337  * Our handle to the namestore service
338  */
339 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
340
341 /**
342  * Our handle to the vpn service
343  */
344 static struct GNUNET_VPN_Handle *vpn_handle;
345
346 /**
347  * Resolver handle to the dht
348  */
349 static struct GNUNET_DHT_Handle *dht_handle;
350
351 /**
352  * Handle to perform DNS lookups.
353  */
354 static struct GNUNET_DNSSTUB_Context *dns_handle;
355
356 /**
357  * Heap for limiting parallel DHT lookups
358  */
359 static struct GNUNET_CONTAINER_Heap *dht_lookup_heap;
360
361 /**
362  * Maximum amount of parallel queries to the DHT
363  */
364 static unsigned long long max_allowed_background_queries;
365
366 /**
367  * Head of resolver lookup list
368  */
369 static struct GNS_ResolverHandle *rlh_head;
370
371 /**
372  * Tail of resolver lookup list
373  */
374 static struct GNS_ResolverHandle *rlh_tail;
375
376 /**
377  * Global configuration.
378  */
379 static const struct GNUNET_CONFIGURATION_Handle *cfg;
380
381
382 /**
383  * Check if name is in srv format (_x._y.xxx)
384  *
385  * @param name
386  * @return #GNUNET_YES if true
387  */
388 static int
389 is_srv (const char *name)
390 {
391   char *ndup;
392   int ret;
393
394   if (*name != '_')
395     return GNUNET_NO;
396   if (NULL == strstr (name, "._"))
397     return GNUNET_NO;
398   ret = GNUNET_YES;
399   ndup = GNUNET_strdup (name);
400   strtok (ndup, ".");
401   if (NULL == strtok (NULL, "."))
402     ret = GNUNET_NO;
403   if (NULL == strtok (NULL, "."))
404     ret = GNUNET_NO;
405   if (NULL != strtok (NULL, "."))
406     ret = GNUNET_NO;
407   GNUNET_free (ndup);
408   return ret;
409 }
410
411
412 /**
413  * Determine if this name is canonical (is a legal name in a zone, without delegation);
414  * note that we do not test that the name does not contain illegal characters, we only
415  * test for delegation.  Note that service records (i.e. _foo._srv) are canonical names
416  * even though they consist of multiple labels.
417  *
418  * Examples:
419  * a.b.gnu  = not canonical
420  * a         = canonical
421  * _foo._srv = canonical
422  * _f.bar    = not canonical
423  *
424  * @param name the name to test
425  * @return #GNUNET_YES if canonical
426  */
427 static int
428 is_canonical (const char *name)
429 {
430   const char *pos;
431   const char *dot;
432
433   if (NULL == strchr (name, '.'))
434     return GNUNET_YES;
435   if ('_' != name[0])
436     return GNUNET_NO;
437   pos = &name[1];
438   while (NULL != (dot = strchr (pos, '.')))    
439     if ('_' != dot[1])
440       return GNUNET_NO;
441     else
442       pos = dot + 1;
443   return GNUNET_YES;
444 }
445
446 /* ************************** Resolution **************************** */
447
448 /**
449  * Exands a name ending in .+ with the zone of origin.
450  *
451  * @param rh resolution context
452  * @param name name to modify (to be free'd or returned)
453  * @return updated name
454  */
455 static char *
456 translate_dot_plus (struct GNS_ResolverHandle *rh,
457                     char *name)
458 {
459   char *ret;
460   size_t s_len = strlen (name);
461
462   if (0 != strcmp (&name[s_len - 2],
463                    ".+"))
464     return name; /* did not end in ".+" */
465   GNUNET_assert (GNUNET_YES == rh->ac_tail->gns_authority);
466   GNUNET_asprintf (&ret,
467                    "%.*s.%s",
468                    (int) (s_len - 2),
469                    name,
470                    GNUNET_NAMESTORE_pkey_to_zkey (&rh->ac_tail->authority_info.gns_authority));
471   GNUNET_free (name);
472   return ret;
473 }
474
475
476 /**
477  * Task scheduled to asynchronously fail a resolution.
478  *
479  * @param cls the 'struct GNS_ResolverHandle' of the resolution to fail
480  * @param tc task context
481  */
482 static void
483 fail_resolution (void *cls,
484                  const struct GNUNET_SCHEDULER_TaskContext *tc)
485 {
486   struct GNS_ResolverHandle *rh = cls;
487
488   rh->task_id = GNUNET_SCHEDULER_NO_TASK;
489   rh->proc (rh->proc_cls, 0, NULL);
490   GNS_resolver_lookup_cancel (rh);
491 }
492
493
494 #if (defined WINDOWS) || (defined DARWIN)
495 /* Don't have this on W32, here's a naive implementation
496  * Was somehow removed on OS X ...  */
497 void *
498 memrchr (const void *s, 
499          int c, 
500          size_t n)
501 {
502   const unsigned char *ucs = s;
503   ssize_t i;
504
505   for (i = n - 1; i >= 0; i--)
506     if (c == (int) ucs[i])
507       return (void *) &ucs[i];
508   return NULL;
509 }
510 #endif
511
512
513 /**
514  * Get the next, rightmost label from the name that we are trying to resolve,
515  * and update the resolution position accordingly.
516  *
517  * @param rh handle to the resolution operation to get the next label from
518  * @return NULL if there are no more labels
519  */
520 static char *
521 resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh)
522 {
523   const char *rp;
524   const char *dot;
525   size_t len;
526
527   if (0 == rh->name_resolution_pos)
528     return NULL;
529   dot = memrchr (rh->name, (int) '.', rh->name_resolution_pos);
530   if (NULL == dot)
531   {
532     /* done, this was the last one */
533     len = rh->name_resolution_pos;
534     rp = rh->name;
535     rh->name_resolution_pos = 0; 
536   }
537   else
538   {
539     /* advance by one label */
540     len = rh->name_resolution_pos - (dot - rh->name) - 1;
541     rp = dot + 1;
542     rh->name_resolution_pos = dot - rh->name;
543   }  
544   return GNUNET_strndup (rp, len);  
545 }
546
547
548 /**
549  * Gives the cummulative result obtained to the callback and clean up the request.
550  *
551  * @param rh resolution process that has culminated in a result
552  */
553 static void
554 transmit_lookup_dns_result (struct GNS_ResolverHandle *rh)
555 {
556   struct DnsResult *pos;
557   unsigned int n;
558   unsigned int i;
559
560   n = 0;
561   for (pos = rh->dns_result_head; NULL != pos; pos = pos->next)
562     n++;
563   {
564     struct GNUNET_NAMESTORE_RecordData rd[n];
565
566     i = 0;
567     for (pos = rh->dns_result_head; NULL != pos; pos = pos->next)
568     {
569       rd[i].data = pos->data;
570       rd[i].data_size = pos->data_size;
571       rd[i].record_type = pos->record_type;
572       if (0 == pos->expiration_time)
573       {
574         rd[i].flags = GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
575         rd[i].expiration_time = 0;
576       }
577       else
578       {
579         rd[i].flags = GNUNET_NAMESTORE_RF_NONE;
580         rd[i].expiration_time = pos->expiration_time;
581       }
582       i++;
583     }
584     GNUNET_assert (i == n);
585     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
586                 "Transmitting standard DNS result with %u records\n",
587                 n);
588     rh->proc (rh->proc_cls,
589               n,
590               rd);
591   }
592   GNS_resolver_lookup_cancel (rh);
593 }
594
595
596 /**
597  * Add a result from DNS to the records to be returned to the application.
598  *
599  * @param rh resolution request to extend with a result
600  * @param expiration_time expiration time for the answer
601  * @param record_type DNS record type of the answer
602  * @param data_size number of bytes in @a data
603  * @param data binary data to return in DNS record
604  */
605 static void
606 add_dns_result (struct GNS_ResolverHandle *rh,
607                 uint64_t expiration_time,
608                 uint32_t record_type,
609                 size_t data_size,
610                 const void *data)
611 {
612   struct DnsResult *res;
613
614   res = GNUNET_malloc (sizeof (struct DnsResult) + data_size);
615   res->expiration_time = expiration_time;
616   res->data_size = data_size;
617   res->record_type = record_type;
618   res->data = &res[1];
619   memcpy (&res[1], data, data_size);
620   GNUNET_CONTAINER_DLL_insert (rh->dns_result_head,
621                                rh->dns_result_tail,
622                                res);
623 }
624
625
626 /**
627  * We had to do a DNS lookup.  Convert the result (if any) and return
628  * it.
629  *
630  * @param cls closure with the 'struct GNS_ResolverHandle'
631  * @param addr one of the addresses of the host, NULL for the last address
632  * @param addrlen length of the address
633  */
634 static void
635 handle_dns_result (void *cls,
636                    const struct sockaddr *addr,
637                    socklen_t addrlen)
638 {
639   struct GNS_ResolverHandle *rh = cls;
640   const struct sockaddr_in *sa4;
641   const struct sockaddr_in6 *sa6;
642
643   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
644               "Received %u bytes of DNS IP data\n",
645               addrlen);
646   if (NULL == addr)
647   {
648     rh->std_resolve = NULL;
649     transmit_lookup_dns_result (rh);
650     return;
651   }
652   switch (addr->sa_family)
653   {
654   case AF_INET:
655     sa4 = (const struct sockaddr_in *) addr;
656     add_dns_result (rh,
657                     0 /* expiration time is unknown */,
658                     GNUNET_DNSPARSER_TYPE_A,
659                     sizeof (struct in_addr),
660                     &sa4->sin_addr);
661     break;
662   case AF_INET6:
663     sa6 = (const struct sockaddr_in6 *) addr;
664     add_dns_result (rh,
665                     0 /* expiration time is unknown */,
666                     GNUNET_DNSPARSER_TYPE_AAAA,
667                     sizeof (struct in6_addr),
668                     &sa6->sin6_addr);
669     break;
670   default:
671     GNUNET_break (0);
672     break;
673   }
674 }
675
676
677 /**
678  * Task scheduled to continue with the resolution process.
679  *
680  * @param cls the 'struct GNS_ResolverHandle' of the resolution
681  * @param tc task context
682  */
683 static void
684 recursive_resolution (void *cls,
685                       const struct GNUNET_SCHEDULER_TaskContext *tc);
686
687
688 /**
689  * Begin the resolution process from 'name', starting with
690  * the identification of the zone specified by 'name'.
691  *
692  * @param rh resolution to perform
693  */
694 static void
695 start_resolver_lookup (struct GNS_ResolverHandle *rh);
696
697
698 /**
699  * Function called with the result of a DNS resolution.
700  *
701  * @param cls the request handle of the resolution that
702  *        we were attempting to make
703  * @param rs socket that received the response
704  * @param dns dns response, never NULL
705  * @param dns_len number of bytes in @a dns
706  */
707 static void
708 dns_result_parser (void *cls,
709                    struct GNUNET_DNSSTUB_RequestSocket *rs,
710                    const struct GNUNET_TUN_DnsHeader *dns,
711                    size_t dns_len)
712 {
713   struct GNS_ResolverHandle *rh = cls;
714   struct GNUNET_DNSPARSER_Packet *p;
715   const struct GNUNET_DNSPARSER_Record *rec;
716   unsigned int rd_count;
717   unsigned int i;
718
719   rh->dns_request = NULL;
720   GNUNET_SCHEDULER_cancel (rh->task_id);
721   rh->task_id = GNUNET_SCHEDULER_NO_TASK;
722   p = GNUNET_DNSPARSER_parse ((const char *) dns, 
723                               dns_len);
724   if (NULL == p)
725   {
726     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
727                 _("Failed to parse DNS response\n"));
728     rh->proc (rh->proc_cls, 0, NULL);
729     GNS_resolver_lookup_cancel (rh);
730     return;
731   }
732   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
733               "Received DNS response for `%s' with %u answers\n",
734               rh->ac_tail->label,
735               (unsigned int) p->num_answers);
736   if ( (p->num_answers > 0) &&
737        (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) &&
738        (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) )
739     {
740       GNUNET_free (rh->name);
741       rh->name = GNUNET_strdup (p->answers[0].data.hostname);
742       start_resolver_lookup (rh);
743       GNUNET_DNSPARSER_free_packet (p);
744       return;     
745     }
746   /* FIXME: add DNAME support */
747
748   /* convert from (parsed) DNS to (binary) GNS format! */
749   rd_count = p->num_answers + p->num_authority_records + p->num_additional_records;
750   {
751     struct GNUNET_NAMESTORE_RecordData rd[rd_count];
752     unsigned int skip;
753     char buf[UINT16_MAX];
754     size_t buf_off;
755
756     buf_off = 0;
757     skip = 0;
758     memset (rd, 0, sizeof (rd));
759     for (i=0;i<rd_count;i++)
760     {
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];
765       else 
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,
771                        rh->ac_tail->label))
772       {
773         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
774                     "Dropping record `%s', does not match desired name `%s'\n",
775                     rec->name,
776                     rh->ac_tail->label);
777         skip++;
778         continue;
779       }
780       rd[i - skip].record_type = rec->type;
781       rd[i - skip].expiration_time = rec->expiration_time.abs_value_us;
782       switch (rec->type)
783       {
784       case GNUNET_DNSPARSER_TYPE_A:
785         if (rec->data.raw.data_len != sizeof (struct in_addr))
786         {
787           GNUNET_break_op (0);
788           skip++;
789           continue;
790         }
791         rd[i - skip].data_size = rec->data.raw.data_len;
792         rd[i - skip].data = rec->data.raw.data;
793         break;
794       case GNUNET_DNSPARSER_TYPE_AAAA:
795         if (rec->data.raw.data_len != sizeof (struct in6_addr))
796         {
797           GNUNET_break_op (0);
798           skip++;
799           continue;
800         }
801         rd[i - skip].data_size = rec->data.raw.data_len;
802         rd[i - skip].data = rec->data.raw.data;
803         break;
804       case GNUNET_DNSPARSER_TYPE_CNAME:
805       case GNUNET_DNSPARSER_TYPE_PTR:
806       case GNUNET_DNSPARSER_TYPE_NS:
807         if (GNUNET_OK !=
808             GNUNET_DNSPARSER_builder_add_name (buf,
809                                                sizeof (buf),
810                                                &buf_off,
811                                                rec->data.hostname))
812         {
813           GNUNET_break (0);
814           skip++;
815           continue;
816         }
817         break;
818       case GNUNET_DNSPARSER_TYPE_SOA:
819         if (GNUNET_OK !=
820             GNUNET_DNSPARSER_builder_add_soa (buf,
821                                                sizeof (buf),
822                                                &buf_off,
823                                                rec->data.soa))
824         {
825           GNUNET_break (0);
826           skip++;
827           continue;
828         }
829         break;
830       case GNUNET_DNSPARSER_TYPE_MX:
831         if (GNUNET_OK !=
832             GNUNET_DNSPARSER_builder_add_mx (buf,
833                                              sizeof (buf),
834                                              &buf_off,
835                                              rec->data.mx))
836         {
837           GNUNET_break (0);
838           skip++;
839           continue;
840         }
841         break;
842       case GNUNET_DNSPARSER_TYPE_SRV:
843         if (GNUNET_OK !=
844             GNUNET_DNSPARSER_builder_add_srv (buf,
845                                               sizeof (buf),
846                                               &buf_off,
847                                               rec->data.srv))
848         {
849           GNUNET_break (0);
850           skip++;
851           continue;
852         }
853         break;
854       default:
855         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
856                     _("Skipping record of unsupported type %d\n"),
857                     rec->type);
858         skip++;
859         continue;
860       }
861     }
862     rh->proc (rh->proc_cls, rd_count - skip, rd);
863     GNS_resolver_lookup_cancel (rh);
864   }  
865   GNUNET_DNSPARSER_free_packet (p);
866 }
867
868
869 /**
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.
874  *
875  * @param rh resolution information
876  */
877 static void
878 recursive_dns_resolution (struct GNS_ResolverHandle *rh)
879 {
880   struct AuthorityChain *ac;
881   socklen_t sa_len;
882   struct GNUNET_DNSPARSER_Query *query;
883   struct GNUNET_DNSPARSER_Packet *p;
884   char *dns_request;
885   size_t dns_request_length;
886
887   ac = rh->ac_tail;
888   GNUNET_assert (NULL != ac);
889   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
890               "Starting DNS lookup for `%s'\n",
891               ac->label);
892   GNUNET_assert (GNUNET_NO == ac->gns_authority);
893   switch (((const struct sockaddr *) &ac->authority_info.dns_authority.dns_ip)->sa_family)
894   {
895   case AF_INET:
896     sa_len = sizeof (struct sockaddr_in);
897     break;
898   case AF_INET6:
899     sa_len = sizeof (struct sockaddr_in6);
900     break;
901   default:
902     GNUNET_break (0);
903     rh->proc (rh->proc_cls, 0, NULL);
904     GNS_resolver_lookup_cancel (rh);
905     return;
906   }
907   query = GNUNET_new (struct GNUNET_DNSPARSER_Query);
908   query->name = GNUNET_strdup (ac->label);
909   query->type = rh->record_type;
910   query->class = GNUNET_TUN_DNS_CLASS_INTERNET;
911   p = GNUNET_new (struct GNUNET_DNSPARSER_Packet);
912   p->queries = query;
913   p->num_queries = 1;
914   p->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
915                                                UINT16_MAX);
916   p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY;
917   p->flags.recursion_desired = 1;
918   if (GNUNET_OK != 
919       GNUNET_DNSPARSER_pack (p, 1024, &dns_request, &dns_request_length))
920   {
921     GNUNET_break (0);
922     rh->proc (rh->proc_cls, 0, NULL);
923     GNS_resolver_lookup_cancel (rh);
924   }
925   else
926   {
927     rh->dns_request = GNUNET_DNSSTUB_resolve (dns_handle,
928                                               (const struct sockaddr *) &ac->authority_info.dns_authority.dns_ip,
929                                               sa_len,
930                                               dns_request,
931                                               dns_request_length,
932                                               &dns_result_parser,
933                                               rh);
934     rh->task_id = GNUNET_SCHEDULER_add_delayed (DNS_LOOKUP_TIMEOUT,
935                                                 &fail_resolution,
936                                                 rh);
937   }
938   GNUNET_free (dns_request);
939   GNUNET_DNSPARSER_free_packet (p);
940 }
941
942
943 /**
944  * We encountered a CNAME record during our resolution.
945  * Merge it into our chain.
946  *
947  * @param rh resolution we are performing
948  * @param cname value of the cname record we got for the current 
949  *        authority chain tail
950  */
951 static void
952 handle_gns_cname_result (struct GNS_ResolverHandle *rh,
953                          const char *cname)
954 {
955   size_t nlen;
956   char *res;
957   struct AuthorityChain *ac;
958
959   nlen = strlen (cname);
960   if ( (nlen > 2) &&
961        (0 == strcmp (".+",
962                      &cname[nlen - 2])) )
963   {
964     /* CNAME resolution continues relative to current domain */
965     if (0 == rh->name_resolution_pos)
966     {
967       res = GNUNET_strndup (cname, nlen - 2);
968       rh->name_resolution_pos = nlen - 2;
969     }
970     else
971     {
972       GNUNET_asprintf (&res,
973                        "%.*s.%.*s",
974                        (int) rh->name_resolution_pos,
975                        rh->name,
976                        (int) (nlen - 2),
977                        cname);
978       rh->name_resolution_pos = strlen (res);
979     }
980     GNUNET_free (rh->name);
981     rh->name = res;
982     ac = GNUNET_new (struct AuthorityChain);
983     ac->rh = rh;
984     ac->gns_authority = GNUNET_YES;
985     ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority;    
986     ac->label = resolver_lookup_get_next_label (rh);
987     /* tigger shortening */
988     if (NULL != rh->shorten_key)      
989       GNS_shorten_start (rh->ac_tail->label,
990                          &ac->authority_info.gns_authority,
991                          rh->shorten_key);      
992     /* add AC to tail */
993     GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
994                                       rh->ac_tail,
995                                       ac);
996     rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
997                                             rh);
998     return;
999   }
1000   /* name is absolute, start from the beginning */
1001   GNUNET_free (rh->name);
1002   rh->name = GNUNET_strdup (cname);
1003   start_resolver_lookup (rh);
1004 }
1005
1006
1007 /**
1008  * Process a records that were decrypted from a block.
1009  *
1010  * @param cls closure with the 'struct GNS_ResolverHandle'
1011  * @param rd_count number of entries in @a rd array
1012  * @param rd array of records with data to store
1013  */
1014 static void
1015 handle_gns_resolution_result (void *cls,
1016                               unsigned int rd_count,
1017                               const struct GNUNET_NAMESTORE_RecordData *rd);
1018
1019
1020 /**
1021  * Callback invoked from the VPN service once a redirection is
1022  * available.  Provides the IP address that can now be used to
1023  * reach the requested destination.  Replaces the "VPN" record
1024  * with the respective A/AAAA record and continues processing.
1025  *
1026  * @param cls closure
1027  * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error;
1028  *                will match 'result_af' from the request
1029  * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
1030  *                that the VPN allocated for the redirection;
1031  *                traffic to this IP will now be redirected to the 
1032  *                specified target peer; NULL on error
1033  */
1034 static void
1035 vpn_allocation_cb (void *cls,
1036                    int af,
1037                    const void *address)
1038 {
1039   struct VpnContext *vpn_ctx = cls;
1040   struct GNS_ResolverHandle *rh = vpn_ctx->rh;
1041   struct GNUNET_NAMESTORE_RecordData rd[vpn_ctx->rd_count];
1042   unsigned int i;
1043
1044   vpn_ctx->vpn_request = NULL;
1045   rh->vpn_ctx = NULL;
1046   GNUNET_assert (GNUNET_OK ==
1047                  GNUNET_NAMESTORE_records_deserialize (vpn_ctx->rd_data_size,
1048                                                        vpn_ctx->rd_data,
1049                                                        vpn_ctx->rd_count,
1050                                                        rd));
1051   for (i=0;i<vpn_ctx->rd_count;i++)
1052   {
1053     if (GNUNET_NAMESTORE_TYPE_VPN == rd[i].record_type)
1054     {
1055       switch (af)
1056       {
1057       case AF_INET: 
1058         rd[i].record_type = GNUNET_DNSPARSER_TYPE_A;
1059         rd[i].data_size = sizeof (struct in_addr);
1060         rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us;
1061         rd[i].flags = 0;
1062         rd[i].data = address;
1063         break;
1064       case AF_INET6:
1065         rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA;
1066         rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us;
1067         rd[i].flags = 0;
1068         rd[i].data = address;
1069         rd[i].data_size = sizeof (struct in6_addr);
1070         break;
1071       default:
1072         GNUNET_assert (0);
1073       }     
1074       break;
1075     }
1076   }
1077   GNUNET_assert (i < vpn_ctx->rd_count);
1078   handle_gns_resolution_result (rh, 
1079                                 vpn_ctx->rd_count,
1080                                 rd);
1081   GNUNET_free (vpn_ctx->rd_data);
1082   GNUNET_free (vpn_ctx);
1083 }
1084
1085
1086 /**
1087  * Process a records that were decrypted from a block.
1088  *
1089  * @param cls closure with the `struct GNS_ResolverHandle`
1090  * @param rd_count number of entries in @a rd array
1091  * @param rd array of records with data to store
1092  */
1093 static void
1094 handle_gns_resolution_result (void *cls,
1095                               unsigned int rd_count,
1096                               const struct GNUNET_NAMESTORE_RecordData *rd)
1097 {
1098   struct GNS_ResolverHandle *rh = cls;
1099   struct AuthorityChain *ac;
1100   unsigned int i;
1101   unsigned int j;
1102   struct sockaddr *sa;
1103   struct sockaddr_in v4;
1104   struct sockaddr_in6 v6;
1105   size_t sa_len;
1106   char *cname;
1107   struct VpnContext *vpn_ctx;
1108   const struct GNUNET_TUN_GnsVpnRecord *vpn;
1109   const char *vname;
1110   struct GNUNET_HashCode vhash;
1111   int af;
1112   char scratch[UINT16_MAX];
1113   size_t scratch_off;
1114   size_t scratch_start;
1115   size_t off;
1116   struct GNUNET_NAMESTORE_RecordData rd_new[rd_count];
1117   unsigned int rd_off;
1118
1119   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1120               "Resolution succeeded for `%s' in zone %s, got %u records\n",
1121               rh->ac_tail->label,
1122               GNUNET_NAMESTORE_z2s (&rh->ac_tail->authority_info.gns_authority),
1123               rd_count);  
1124   if (0 == rh->name_resolution_pos)
1125   {
1126     /* top-level match, are we done yet? */
1127     if ( (rd_count > 0) &&
1128          (GNUNET_DNSPARSER_TYPE_CNAME == rd[0].record_type) &&
1129          (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) )
1130     {
1131       off = 0;
1132       cname = GNUNET_DNSPARSER_parse_name (rd[0].data,
1133                                            rd[0].data_size,
1134                                            &off);
1135       if ( (NULL == cname) ||
1136            (off != rd[0].data_size) )
1137       {
1138         GNUNET_break_op (0);
1139         rh->proc (rh->proc_cls, 0, NULL);
1140         GNS_resolver_lookup_cancel (rh);
1141         return;                 
1142       }
1143       handle_gns_cname_result (rh, 
1144                                cname);
1145       GNUNET_free (cname);
1146       return;     
1147     }
1148     /* If A/AAAA was requested, but we got a VPN
1149        record, we convert it to A/AAAA using GNUnet VPN */
1150     if ( (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ||
1151          (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type) )
1152     {
1153       for (i=0;i<rd_count;i++)
1154       {
1155         switch (rd[i].record_type)
1156         {
1157         case GNUNET_NAMESTORE_TYPE_VPN:
1158           {
1159             af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : AF_INET6;
1160             if (sizeof (struct GNUNET_TUN_GnsVpnRecord) <
1161                 rd[i].data_size)
1162             {
1163               GNUNET_break_op (0);
1164               rh->proc (rh->proc_cls, 0, NULL);
1165               GNS_resolver_lookup_cancel (rh);
1166               return;         
1167             }
1168             vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data;
1169             vname = (const char *) &vpn[1];
1170             if ('\0' != vname[rd[i].data_size - 1 - sizeof (struct GNUNET_TUN_GnsVpnRecord)])
1171             {
1172               GNUNET_break_op (0);
1173               rh->proc (rh->proc_cls, 0, NULL);
1174               GNS_resolver_lookup_cancel (rh);
1175               return;
1176             }
1177             GNUNET_CRYPTO_hash (vname,
1178                                 strlen (vname), // FIXME: +1?
1179                                 &vhash);
1180             vpn_ctx = GNUNET_new (struct VpnContext);
1181             rh->vpn_ctx = vpn_ctx;
1182             vpn_ctx->rh = rh;
1183             vpn_ctx->rd_data_size = GNUNET_NAMESTORE_records_get_size (rd_count,
1184                                                                        rd);
1185             vpn_ctx->rd_data = GNUNET_malloc (vpn_ctx->rd_data_size);
1186             (void) GNUNET_NAMESTORE_records_serialize (rd_count,
1187                                                        rd,
1188                                                        vpn_ctx->rd_data_size,
1189                                                        vpn_ctx->rd_data);
1190             vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle,
1191                                                                 af,
1192                                                                 ntohs (vpn->proto),
1193                                                                 &vpn->peer,
1194                                                                 &vhash,
1195                                                                 GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT),
1196                                                                 &vpn_allocation_cb,
1197                                                                 rh);
1198             return;
1199           }
1200         default:
1201           break;
1202         }
1203       }
1204     }
1205     /* convert relative names in record values to absolute names,
1206        using 'scratch' array for memory allocations */
1207     scratch_off = 0;
1208     rd_off = 0;
1209     for (i=0;i<rd_count;i++)
1210     {
1211       rd_new[rd_off] = rd[i];
1212       /* Check if the embedded name(s) end in "+", and if so,
1213          replace the "+" with the zone at "ac_tail", changing the name
1214          to a ".zkey".  The name is allocated on the 'scratch' array,
1215          so we can free it afterwards. */
1216       switch (rd[i].record_type)
1217       {
1218       case GNUNET_DNSPARSER_TYPE_CNAME:
1219         {
1220           char *cname;
1221
1222           off = 0;
1223           cname = GNUNET_DNSPARSER_parse_name (rd[i].data,
1224                                                rd[i].data_size,
1225                                                &off);
1226           if ( (NULL == cname) ||
1227                (off != rd[i].data_size) )
1228           {
1229             GNUNET_break_op (0); /* record not well-formed */
1230           }
1231           else
1232           {
1233             cname = translate_dot_plus (rh, cname);
1234             scratch_start = scratch_off;
1235             if (GNUNET_OK !=
1236                 GNUNET_DNSPARSER_builder_add_name (scratch,
1237                                                    sizeof (scratch),
1238                                                    &scratch_off,
1239                                                    cname))
1240             {
1241               GNUNET_break (0);
1242             }
1243             else
1244             {
1245               rd_new[rd_off].data = &scratch[scratch_start];
1246               rd_new[rd_off].data_size = scratch_off - scratch_start;
1247               rd_off++;
1248             }
1249           }
1250           GNUNET_free_non_null (cname);   
1251         }
1252         break;
1253       case GNUNET_DNSPARSER_TYPE_SOA:
1254         {
1255           struct GNUNET_DNSPARSER_SoaRecord *soa;
1256
1257           off = 0;
1258           soa = GNUNET_DNSPARSER_parse_soa (rd[i].data,
1259                                             rd[i].data_size,
1260                                             &off);
1261           if ( (NULL == soa) ||
1262                (off != rd[i].data_size) )
1263           {
1264             GNUNET_break_op (0); /* record not well-formed */
1265           }
1266           else
1267           {
1268             soa->mname = translate_dot_plus (rh, soa->mname);
1269             soa->rname = translate_dot_plus (rh, soa->rname);
1270             scratch_start = scratch_off;
1271             if (GNUNET_OK !=
1272                 GNUNET_DNSPARSER_builder_add_soa (scratch,
1273                                                   sizeof (scratch),
1274                                                   &scratch_off,
1275                                                   soa))
1276             {
1277               GNUNET_break (0);
1278             }
1279             else
1280             {
1281               rd_new[rd_off].data = &scratch[scratch_start];
1282               rd_new[rd_off].data_size = scratch_off - scratch_start;
1283               rd_off++;
1284             }
1285           }
1286           if (NULL != soa)
1287             GNUNET_DNSPARSER_free_soa (soa);      
1288         }
1289         break;
1290       case GNUNET_DNSPARSER_TYPE_MX:
1291         {
1292           struct GNUNET_DNSPARSER_MxRecord *mx;
1293
1294           off = 0;
1295           mx = GNUNET_DNSPARSER_parse_mx (rd[i].data,
1296                                           rd[i].data_size,
1297                                           &off);
1298           if ( (NULL == mx) ||
1299                (off != rd[i].data_size) )
1300           {
1301             GNUNET_break_op (0); /* record not well-formed */
1302           }
1303           else
1304           {
1305             mx->mxhost = translate_dot_plus (rh, mx->mxhost);
1306             scratch_start = scratch_off;
1307             if (GNUNET_OK !=
1308                 GNUNET_DNSPARSER_builder_add_mx (scratch,
1309                                                  sizeof (scratch),
1310                                                  &scratch_off,
1311                                                  mx))
1312             {
1313               GNUNET_break (0);
1314             }
1315             else
1316             {
1317               rd_new[rd_off].data = &scratch[scratch_start];
1318               rd_new[rd_off].data_size = scratch_off - scratch_start;
1319               rd_off++;
1320             }
1321           }
1322           if (NULL != mx)
1323             GNUNET_DNSPARSER_free_mx (mx);        
1324         }       
1325         break;
1326       case GNUNET_DNSPARSER_TYPE_SRV:
1327         {
1328           struct GNUNET_DNSPARSER_SrvRecord *srv;
1329
1330           off = 0;
1331           /* FIXME: passing rh->name here is is not necessarily what we want 
1332              (SRV support not finished) */
1333           srv = GNUNET_DNSPARSER_parse_srv (rh->name,
1334                                             rd[i].data,
1335                                             rd[i].data_size,
1336                                             &off);
1337           if ( (NULL == srv) ||
1338                (off != rd[i].data_size) )
1339           {
1340             GNUNET_break_op (0); /* record not well-formed */
1341           }
1342           else
1343           {
1344             srv->domain_name = translate_dot_plus (rh, srv->domain_name);
1345             srv->target = translate_dot_plus (rh, srv->target);
1346             scratch_start = scratch_off;
1347             if (GNUNET_OK !=
1348                 GNUNET_DNSPARSER_builder_add_srv (scratch,
1349                                                   sizeof (scratch),
1350                                                   &scratch_off,
1351                                                   srv))
1352             {
1353               GNUNET_break (0);
1354             }
1355             else
1356             {
1357               rd_new[rd_off].data = &scratch[scratch_start];
1358               rd_new[rd_off].data_size = scratch_off - scratch_start;
1359               rd_off++;
1360             }
1361           }
1362           if (NULL != srv)
1363             GNUNET_DNSPARSER_free_srv (srv);      
1364         }
1365         break;
1366       case GNUNET_NAMESTORE_TYPE_PKEY:
1367         /* tigger shortening */
1368         if (NULL != rh->shorten_key)
1369         {
1370           struct GNUNET_CRYPTO_EccPublicSignKey pub;
1371           
1372           if (rd[i].data_size != sizeof (struct GNUNET_CRYPTO_EccPublicSignKey))
1373           {
1374             GNUNET_break_op (0);
1375             break;
1376           }
1377           memcpy (&pub, rd[i].data, rd[i].data_size);
1378           GNS_shorten_start (rh->ac_tail->label,
1379                              &pub,
1380                              rh->shorten_key);
1381         }
1382         rd_off++;
1383         break;
1384       default:
1385         rd_off++;
1386         break;
1387       }
1388     }
1389     
1390     /* yes, we are done, return result */
1391     rh->proc (rh->proc_cls, rd_off, rd_new);
1392     GNS_resolver_lookup_cancel (rh);
1393     return;         
1394   }
1395   /* need to recurse, check if we can */
1396   for (i=0;i<rd_count;i++)
1397   {
1398     switch (rd[i].record_type)
1399     {
1400     case GNUNET_NAMESTORE_TYPE_PKEY:
1401       /* delegation to another zone */
1402       if (sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) !=
1403           rd[i].data_size)
1404       {
1405         GNUNET_break_op (0);
1406         rh->proc (rh->proc_cls, 0, NULL);
1407         GNS_resolver_lookup_cancel (rh);
1408         return;     
1409       }
1410       /* expand authority chain */
1411       ac = GNUNET_new (struct AuthorityChain);
1412       ac->rh = rh;
1413       ac->gns_authority = GNUNET_YES;
1414       memcpy (&ac->authority_info.gns_authority,
1415               rd[i].data,
1416               sizeof (struct GNUNET_CRYPTO_EccPublicSignKey));
1417       ac->label = resolver_lookup_get_next_label (rh);
1418       /* tigger shortening */
1419       if (NULL != rh->shorten_key)      
1420         GNS_shorten_start (rh->ac_tail->label,
1421                            &ac->authority_info.gns_authority,
1422                            rh->shorten_key);      
1423       /* add AC to tail */
1424       GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1425                                         rh->ac_tail,
1426                                         ac);
1427       /* recurse */
1428       rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1429                                               rh);
1430       return;
1431     case GNUNET_DNSPARSER_TYPE_NS:
1432       {
1433         char *ns;
1434         /* resolution continues within DNS */
1435         if (GNUNET_DNSPARSER_MAX_NAME_LENGTH < rd[i].data_size)
1436         {
1437           GNUNET_break_op (0);
1438           rh->proc (rh->proc_cls, 0, NULL);
1439           GNS_resolver_lookup_cancel (rh);
1440           return;     
1441         }
1442         /* find associated A/AAAA record */
1443         sa = NULL;
1444         sa_len = 0;
1445         for (j=0;j<rd_count;j++)
1446         {
1447           switch (rd[j].record_type)
1448             {
1449             case GNUNET_DNSPARSER_TYPE_A:
1450               if (sizeof (struct in_addr) != rd[j].data_size)
1451               {
1452                 GNUNET_break_op (0);
1453                 rh->proc (rh->proc_cls, 0, NULL);
1454                 GNS_resolver_lookup_cancel (rh);
1455                 return;     
1456               }
1457               /* FIXME: might want to check if we support IPv4 here,
1458                  and otherwise skip this one and hope we find another */
1459               memset (&v4, 0, sizeof (v4));
1460               sa_len = sizeof (v4);
1461               v4.sin_family = AF_INET;
1462               v4.sin_port = htons (53);
1463 #if HAVE_SOCKADDR_IN_SIN_LEN
1464               v4.sin_len = (u_char) sa_len;
1465 #endif
1466               memcpy (&v4.sin_addr,
1467                       rd[j].data,
1468                       sizeof (struct in_addr));
1469               sa = (struct sockaddr *) &v4;
1470               break;
1471             case GNUNET_DNSPARSER_TYPE_AAAA:
1472               if (sizeof (struct in6_addr) != rd[j].data_size)
1473               {
1474                 GNUNET_break_op (0);
1475                 rh->proc (rh->proc_cls, 0, NULL);
1476                 GNS_resolver_lookup_cancel (rh);
1477                 return;     
1478               }
1479               /* FIXME: might want to check if we support IPv6 here,
1480                  and otherwise skip this one and hope we find another */
1481               memset (&v6, 0, sizeof (v6));
1482               sa_len = sizeof (v6);
1483               v6.sin6_family = AF_INET6;
1484               v6.sin6_port = htons (53);
1485 #if HAVE_SOCKADDR_IN_SIN_LEN
1486               v6.sin6_len = (u_char) sa_len;
1487 #endif
1488               memcpy (&v6.sin6_addr,
1489                       rd[j].data,
1490                       sizeof (struct in6_addr));
1491               sa = (struct sockaddr *) &v6;
1492               break;
1493             default:
1494               break;
1495             }
1496           if (NULL != sa)
1497             break;
1498         }
1499         if (NULL == sa)
1500         {
1501           /* we cannot continue; NS without A/AAAA */
1502           rh->proc (rh->proc_cls, 0, NULL);
1503           GNS_resolver_lookup_cancel (rh);
1504           return;
1505         }
1506         /* expand authority chain */
1507         ac = GNUNET_new (struct AuthorityChain);
1508         ac->rh = rh;
1509         off = 0;
1510         ns = GNUNET_DNSPARSER_parse_name (rd[i].data,
1511                                           rd[i].data_size,
1512                                           &off);
1513         if ( (NULL == ns) ||
1514              (off != rd[i].data_size) )
1515         {
1516           GNUNET_break_op (0); /* record not well-formed */
1517           rh->proc (rh->proc_cls, 0, NULL);
1518           GNS_resolver_lookup_cancel (rh);
1519           return;
1520         }
1521         strcpy (ac->authority_info.dns_authority.name,
1522                 ns);
1523         memcpy (&ac->authority_info.dns_authority.dns_ip,
1524                 sa,
1525                 sa_len);
1526         /* for DNS recursion, the label is the full DNS name,
1527            created from the remainder of the GNS name and the
1528            name in the NS record */
1529         GNUNET_asprintf (&ac->label,
1530                          "%.*s.%s",
1531                          (int) rh->name_resolution_pos,
1532                          rh->name,
1533                          ns);
1534         GNUNET_free (ns);
1535         GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1536                                           rh->ac_tail,
1537                                           ac);
1538         if (strlen (ac->label) > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
1539         {
1540           GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1541                       _("GNS lookup resulted in DNS name that is too long (`%s')\n"),
1542                       ac->label);
1543           rh->proc (rh->proc_cls, 0, NULL);
1544           GNS_resolver_lookup_cancel (rh);
1545           return;
1546         }
1547         /* recurse */
1548         rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1549                                                 rh);
1550         return;
1551       }
1552     case GNUNET_DNSPARSER_TYPE_CNAME:
1553       {
1554         char *cname;
1555         
1556         off = 0;
1557         cname = GNUNET_DNSPARSER_parse_name (rd[i].data,
1558                                              rd[i].data_size,
1559                                              &off);
1560         if ( (NULL == cname) ||
1561              (off != rd[i].data_size) )
1562         {
1563           GNUNET_break_op (0); /* record not well-formed */
1564           rh->proc (rh->proc_cls, 0, NULL);
1565           GNS_resolver_lookup_cancel (rh);
1566           return;
1567         }
1568         handle_gns_cname_result (rh, 
1569                                  cname);
1570         GNUNET_free (cname);
1571         return;
1572       }
1573       /* FIXME: handle DNAME */
1574     default:
1575       /* skip */
1576       break;
1577     }
1578   }
1579   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1580               _("GNS lookup recursion failed (no delegation record found)\n"));
1581   rh->proc (rh->proc_cls, 0, NULL);
1582   GNS_resolver_lookup_cancel (rh);
1583 }
1584
1585
1586 /**
1587  * Function called once the namestore has completed the request for
1588  * caching a block.
1589  *
1590  * @param cls closure with the 'struct GNS_ResolverHandle'
1591  * @param success #GNUNET_OK on success
1592  * @param emsg error message
1593  */
1594 static void
1595 namestore_cache_continuation (void *cls,
1596                               int32_t success,
1597                               const char *emsg)
1598 {
1599   struct GNS_ResolverHandle *rh = cls;
1600
1601   rh->namestore_qe = NULL;
1602   if (NULL != emsg)
1603     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1604                 _("Failed to cache GNS resolution: %s\n"),
1605                 emsg);
1606 }
1607
1608
1609 /**
1610  * Iterator called on each result obtained for a DHT
1611  * operation that expects a reply
1612  *
1613  * @param cls closure with the `struct GNS_ResolverHandle`
1614  * @param exp when will this value expire
1615  * @param key key of the result
1616  * @param get_path peers on reply path (or NULL if not recorded)
1617  *                 [0] = datastore's first neighbor, [length - 1] = local peer
1618  * @param get_path_length number of entries in @a get_path
1619  * @param put_path peers on the PUT path (or NULL if not recorded)
1620  *                 [0] = origin, [length - 1] = datastore
1621  * @param put_path_length number of entries in @a put_path
1622  * @param type type of the result
1623  * @param size number of bytes in data
1624  * @param data pointer to the result data
1625  */
1626 static void
1627 handle_dht_response (void *cls,
1628                      struct GNUNET_TIME_Absolute exp,
1629                      const struct GNUNET_HashCode *key,
1630                      const struct GNUNET_PeerIdentity *get_path,
1631                      unsigned int get_path_length,
1632                      const struct GNUNET_PeerIdentity *put_path, 
1633                      unsigned int put_path_length,
1634                      enum GNUNET_BLOCK_Type type,
1635                      size_t size, const void *data)
1636 {
1637   struct GNS_ResolverHandle *rh = cls;
1638   struct AuthorityChain *ac = rh->ac_tail;
1639   const struct GNUNET_NAMESTORE_Block *block;
1640   
1641   GNUNET_DHT_get_stop (rh->get_handle);
1642   rh->get_handle = NULL;
1643   GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
1644   rh->dht_heap_node = NULL;  
1645   if (size < sizeof (struct GNUNET_NAMESTORE_Block))
1646   {
1647     /* how did this pass DHT block validation!? */
1648     GNUNET_break (0);
1649     rh->proc (rh->proc_cls, 0, NULL);
1650     GNS_resolver_lookup_cancel (rh);
1651     return;   
1652   }
1653   block = data; 
1654   if (size !=
1655       ntohl (block->purpose.size) + 
1656       sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) +
1657       sizeof (struct GNUNET_CRYPTO_EccSignature))
1658   {
1659     /* how did this pass DHT block validation!? */
1660     GNUNET_break (0);
1661     rh->proc (rh->proc_cls, 0, NULL);
1662     GNS_resolver_lookup_cancel (rh);
1663     return;   
1664   }
1665   if (GNUNET_OK !=
1666       GNUNET_NAMESTORE_block_decrypt (block,
1667                                       &ac->authority_info.gns_authority,
1668                                       ac->label,
1669                                       &handle_gns_resolution_result,
1670                                       rh))
1671   {
1672     GNUNET_break_op (0); /* block was ill-formed */
1673     rh->proc (rh->proc_cls, 0, NULL);
1674     GNS_resolver_lookup_cancel (rh);
1675     return;
1676   }
1677   /* Cache well-formed blocks */
1678   rh->namestore_qe = GNUNET_NAMESTORE_block_cache (namestore_handle,
1679                                                    block,
1680                                                    &namestore_cache_continuation,
1681                                                    rh);
1682 }
1683
1684
1685 /**
1686  * Process a record that was stored in the namestore.
1687  *
1688  * @param cls closure with the `struct GNS_ResolverHandle`
1689  * @param block block that was stored in the namestore
1690  */
1691 static void 
1692 handle_namestore_block_response (void *cls,
1693                                  const struct GNUNET_NAMESTORE_Block *block)
1694 {
1695   struct GNS_ResolverHandle *rh = cls;
1696   struct GNS_ResolverHandle *rx;
1697   struct AuthorityChain *ac = rh->ac_tail;
1698   const char *label = ac->label;
1699   const struct GNUNET_CRYPTO_EccPublicSignKey *auth = &ac->authority_info.gns_authority;
1700   struct GNUNET_HashCode query;
1701
1702   GNUNET_NAMESTORE_query_from_public_key (auth,
1703                                           label,
1704                                           &query);
1705   rh->namestore_qe = NULL;
1706   if ( (GNUNET_NO == rh->only_cached) &&
1707        ( (NULL == block) ||
1708          (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) )
1709   {
1710     /* Namestore knows nothing; try DHT lookup */
1711     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1712                 "Starting DHT lookup for `%s' in zone %s\n",
1713                 ac->label,
1714                 GNUNET_NAMESTORE_z2s (&ac->authority_info.gns_authority));
1715     rh->get_handle = GNUNET_DHT_get_start (dht_handle,
1716                                            GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
1717                                            &query,
1718                                            DHT_GNS_REPLICATION_LEVEL,
1719                                            GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1720                                            NULL, 0,
1721                                            &handle_dht_response, rh);
1722     rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
1723                                                       rh,
1724                                                       GNUNET_TIME_absolute_get ().abs_value_us);
1725     if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries)
1726     {
1727       /* fail longest-standing DHT request */
1728       rx = GNUNET_CONTAINER_heap_peek (dht_lookup_heap);
1729       GNUNET_assert (NULL != rx);
1730       rx->proc (rx->proc_cls, 0, NULL);
1731       GNS_resolver_lookup_cancel (rx);
1732     }
1733     return;
1734   }
1735   if ( (NULL == block) ||
1736        (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) )
1737   {
1738     /* DHT not permitted and no local result, fail */
1739     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1740                 "Resolution failed for `%s' in zone %s (DHT lookup not permitted by configuration)\n",
1741                 ac->label,
1742                 GNUNET_NAMESTORE_z2s (&ac->authority_info.gns_authority));
1743     rh->proc (rh->proc_cls, 0, NULL);
1744     GNS_resolver_lookup_cancel (rh);
1745     return;
1746   }
1747   if (GNUNET_OK !=
1748       GNUNET_NAMESTORE_block_decrypt (block,
1749                                       auth,
1750                                       label,
1751                                       &handle_gns_resolution_result,
1752                                       rh))
1753   {
1754     GNUNET_break_op (0); /* block was ill-formed */
1755     rh->proc (rh->proc_cls, 0, NULL);
1756     GNS_resolver_lookup_cancel (rh);
1757     return;
1758   }
1759 }
1760
1761
1762 /**
1763  * Lookup tail of our authority chain in the namestore.
1764  *
1765  * @param rh query we are processing
1766  */
1767 static void
1768 recursive_gns_resolution_namestore (struct GNS_ResolverHandle *rh)
1769 {
1770   struct AuthorityChain *ac = rh->ac_tail;
1771   struct GNUNET_HashCode query;
1772
1773   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1774               "Starting GNS resolution for `%s' in zone %s\n",
1775               ac->label,
1776               GNUNET_NAMESTORE_z2s (&ac->authority_info.gns_authority));
1777   GNUNET_NAMESTORE_query_from_public_key (&ac->authority_info.gns_authority,
1778                                           ac->label,
1779                                           &query);
1780   rh->namestore_qe = GNUNET_NAMESTORE_lookup_block (namestore_handle,
1781                                                     &query,
1782                                                     &handle_namestore_block_response,
1783                                                     rh);
1784 }
1785
1786
1787 /**
1788  * Task scheduled to continue with the resolution process.
1789  *
1790  * @param cls the `struct GNS_ResolverHandle` of the resolution
1791  * @param tc task context
1792  */
1793 static void
1794 recursive_resolution (void *cls,
1795                       const struct GNUNET_SCHEDULER_TaskContext *tc)
1796 {
1797   struct GNS_ResolverHandle *rh = cls;
1798
1799   rh->task_id = GNUNET_SCHEDULER_NO_TASK;
1800   if (MAX_RECURSION < rh->loop_limiter++)
1801   {
1802     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1803                 "Encountered unbounded recursion resolving `%s'\n",
1804                 rh->name);
1805     rh->proc (rh->proc_cls, 0, NULL);
1806     GNS_resolver_lookup_cancel (rh);
1807     return;
1808   }
1809   if (GNUNET_YES == rh->ac_tail->gns_authority) 
1810     recursive_gns_resolution_namestore (rh);  
1811   else  
1812     recursive_dns_resolution (rh);  
1813 }
1814
1815
1816 /**
1817  * Begin the resolution process from 'name', starting with
1818  * the identification of the zone specified by 'name'.
1819  *
1820  * @param rh resolution to perform
1821  */
1822 static void
1823 start_resolver_lookup (struct GNS_ResolverHandle *rh)
1824 {
1825   struct AuthorityChain *ac;
1826   char *x;
1827   char *y;
1828   char *pkey;
1829
1830   if ( ( (GNUNET_YES == is_canonical (rh->name)) &&
1831          (0 != strcmp (GNUNET_GNS_TLD, rh->name)) ) ||
1832        ( (GNUNET_YES != is_gnu_tld (rh->name)) &&
1833          (GNUNET_YES != is_zkey_tld (rh->name)) ) )
1834   {
1835     /* use standard DNS lookup */
1836     int af;
1837
1838     switch (rh->record_type)
1839     {
1840     case GNUNET_DNSPARSER_TYPE_A:
1841       af = AF_INET;
1842       break;
1843     case GNUNET_DNSPARSER_TYPE_AAAA:
1844       af = AF_INET6;
1845       break;
1846     default:
1847       af = AF_UNSPEC;
1848       break;
1849     }  
1850     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
1851                 "Doing standard DNS lookup for `%s'\n",
1852                 rh->name);
1853     rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, 
1854                                               af,
1855                                               DNS_LOOKUP_TIMEOUT,
1856                                               &handle_dns_result,
1857                                               rh);
1858     return;
1859   }
1860   if (is_zkey_tld (rh->name))
1861   {
1862     /* Name ends with ".zkey", try to replace authority zone with zkey
1863        authority */
1864     GNUNET_free (resolver_lookup_get_next_label (rh)); /* will return "zkey" */
1865     x = resolver_lookup_get_next_label (rh); /* will return 'x' coordinate */
1866     y = resolver_lookup_get_next_label (rh); /* will return 'y' coordinate */
1867     GNUNET_asprintf (&pkey,
1868                      "%s%s",
1869                      x, y);
1870     if ( (NULL == x) ||
1871          (NULL == y) ||
1872          (GNUNET_OK !=
1873           GNUNET_CRYPTO_ecc_public_sign_key_from_string (pkey,
1874                                                     strlen (pkey),
1875                                                     &rh->authority_zone)) )
1876     {
1877       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1878                   _("Hostname `%s' is not well-formed, resolution fails\n"),
1879                   rh->name);
1880       rh->task_id = GNUNET_SCHEDULER_add_now (&fail_resolution, rh);
1881     }
1882     GNUNET_free_non_null (x);
1883     GNUNET_free_non_null (y);
1884     GNUNET_free (pkey);
1885   }
1886   else
1887   {
1888     /* Name ends with ".gnu", eat ".gnu" and continue with resolution */
1889     GNUNET_free (resolver_lookup_get_next_label (rh));
1890   }
1891   ac = GNUNET_new (struct AuthorityChain);
1892   ac->rh = rh;
1893   ac->label = resolver_lookup_get_next_label (rh);
1894   if (NULL == ac->label)
1895     /* name was just "gnu", so we default to label '+' */
1896     ac->label = GNUNET_strdup (GNUNET_GNS_MASTERZONE_STR);
1897   ac->gns_authority = GNUNET_YES;
1898   ac->authority_info.gns_authority = rh->authority_zone;
1899   GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1900                                     rh->ac_tail,
1901                                     ac);
1902   rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
1903                                           rh);
1904 }
1905
1906
1907 /**
1908  * Lookup of a record in a specific zone calls lookup result processor
1909  * on result.
1910  *
1911  * @param zone the zone to perform the lookup in
1912  * @param record_type the record type to look up
1913  * @param name the name to look up
1914  * @param shorten_key a private key for use with PSEU import (can be NULL)
1915  * @param only_cached #GNUNET_NO to only check locally not DHT for performance
1916  * @param proc the processor to call on result
1917  * @param proc_cls the closure to pass to @a proc
1918  * @return handle to cancel operation
1919  */
1920 struct GNS_ResolverHandle *
1921 GNS_resolver_lookup (const struct GNUNET_CRYPTO_EccPublicSignKey *zone,
1922                      uint32_t record_type,
1923                      const char *name,
1924                      const struct GNUNET_CRYPTO_EccPrivateKey *shorten_key,
1925                      int only_cached,
1926                      GNS_ResultProcessor proc, void *proc_cls)
1927 {
1928   struct GNS_ResolverHandle *rh;
1929
1930   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1931               "Starting lookup for `%s'\n",
1932               name);
1933   rh = GNUNET_new (struct GNS_ResolverHandle);
1934   GNUNET_CONTAINER_DLL_insert (rlh_head,
1935                                rlh_tail,
1936                                rh);
1937   rh->authority_zone = *zone;
1938   rh->proc = proc;
1939   rh->proc_cls = proc_cls;
1940   rh->only_cached = only_cached;
1941   rh->record_type = record_type;
1942   rh->name = GNUNET_strdup (name);
1943   rh->name_resolution_pos = strlen (name);
1944   if (NULL != shorten_key)
1945   {
1946     rh->shorten_key = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
1947     *rh->shorten_key = *shorten_key;
1948   }
1949   start_resolver_lookup (rh);
1950   return rh;
1951 }
1952
1953
1954 /**
1955  * Cancel active resolution (i.e. client disconnected).
1956  *
1957  * @param rh resolution to abort
1958  */
1959 void
1960 GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh)
1961 {
1962   struct DnsResult *dr;
1963   struct AuthorityChain *ac;
1964   struct VpnContext *vpn_ctx;
1965
1966   GNUNET_CONTAINER_DLL_remove (rlh_head,
1967                                rlh_tail,
1968                                rh);
1969   while (NULL != (ac = rh->ac_head))
1970   {
1971     GNUNET_CONTAINER_DLL_remove (rh->ac_head,
1972                                  rh->ac_tail,
1973                                  ac);
1974     GNUNET_free (ac->label);
1975     GNUNET_free (ac);
1976   }
1977   if (GNUNET_SCHEDULER_NO_TASK != rh->task_id)
1978   {
1979     GNUNET_SCHEDULER_cancel (rh->task_id);
1980     rh->task_id = GNUNET_SCHEDULER_NO_TASK;
1981   }
1982   if (NULL != rh->get_handle)
1983   {
1984     GNUNET_DHT_get_stop (rh->get_handle);
1985     rh->get_handle = NULL;
1986   }
1987   if (NULL != rh->dht_heap_node)
1988   {
1989     GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
1990     rh->dht_heap_node = NULL;
1991   }
1992   if (NULL != (vpn_ctx = rh->vpn_ctx))
1993   {
1994     GNUNET_VPN_cancel_request (vpn_ctx->vpn_request);
1995     GNUNET_free (vpn_ctx->rd_data);
1996     GNUNET_free (vpn_ctx);
1997   }
1998   if (NULL != rh->dns_request)
1999   {
2000     GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
2001     rh->dns_request = NULL;
2002   }
2003   if (NULL != rh->namestore_qe)
2004   {
2005     GNUNET_NAMESTORE_cancel (rh->namestore_qe);
2006     rh->namestore_qe = NULL;
2007   }
2008   if (NULL != rh->std_resolve)
2009   {
2010     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2011                 "Canceling standard DNS resolution\n");
2012     GNUNET_RESOLVER_request_cancel (rh->std_resolve);
2013     rh->std_resolve = NULL;
2014   }
2015   while (NULL != (dr = rh->dns_result_head))
2016   {
2017     GNUNET_CONTAINER_DLL_remove (rh->dns_result_head,
2018                                  rh->dns_result_tail,
2019                                  dr);
2020     GNUNET_free (dr);
2021   }
2022   GNUNET_free_non_null (rh->shorten_key);
2023   GNUNET_free (rh->name);
2024   GNUNET_free (rh);
2025 }
2026
2027
2028 /* ***************** Resolver initialization ********************* */
2029
2030
2031 /**
2032  * Initialize the resolver
2033  *
2034  * @param nh the namestore handle
2035  * @param dht the dht handle
2036  * @param c configuration handle
2037  * @param max_bg_queries maximum number of parallel background queries in dht
2038  */
2039 void
2040 GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
2041                    struct GNUNET_DHT_Handle *dht,
2042                    const struct GNUNET_CONFIGURATION_Handle *c,
2043                    unsigned long long max_bg_queries)
2044 {
2045   char *dns_ip;
2046
2047   cfg = c;
2048   namestore_handle = nh;
2049   dht_handle = dht;
2050   dht_lookup_heap =
2051     GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2052   max_allowed_background_queries = max_bg_queries;
2053   if (GNUNET_OK !=
2054       GNUNET_CONFIGURATION_get_value_string (c,
2055                                              "gns",
2056                                              "DNS_RESOLVER",
2057                                              &dns_ip))
2058   {
2059     /* user did not specify DNS resolver, use 8.8.8.8 */
2060     dns_ip = GNUNET_strdup ("8.8.8.8");
2061   }
2062   dns_handle = GNUNET_DNSSTUB_start (dns_ip);
2063   GNUNET_free (dns_ip);
2064   vpn_handle = GNUNET_VPN_connect (cfg);
2065 }
2066
2067
2068 /**
2069  * Shutdown resolver
2070  */
2071 void
2072 GNS_resolver_done ()
2073 {
2074   struct GNS_ResolverHandle *rh;
2075
2076   /* abort active resolutions */
2077   while (NULL != (rh = rlh_head))
2078   {
2079     rh->proc (rh->proc_cls, 0, NULL);
2080     GNS_resolver_lookup_cancel (rh);    
2081   }
2082   GNUNET_CONTAINER_heap_destroy (dht_lookup_heap);
2083   dht_lookup_heap = NULL;
2084   GNUNET_DNSSTUB_stop (dns_handle);
2085   dns_handle = NULL;
2086   GNUNET_VPN_disconnect (vpn_handle);
2087   vpn_handle = NULL;
2088   dht_handle = NULL;
2089   namestore_handle = NULL;
2090 }
2091
2092
2093 /* *************** common helper functions (do not really belong here) *********** */
2094
2095 /**
2096  * Checks if @a name ends in ".TLD"
2097  *
2098  * @param name the name to check
2099  * @param tld the TLD to check for
2100  * @return GNUNET_YES or GNUNET_NO
2101  */
2102 int
2103 is_tld (const char* name, const char* tld)
2104 {
2105   size_t offset = 0;
2106
2107   if (strlen (name) <= strlen (tld))
2108     return GNUNET_NO;
2109   offset = strlen (name) - strlen (tld);
2110   if (0 != strcmp (name + offset, tld))
2111     return GNUNET_NO;
2112   return GNUNET_YES;
2113 }
2114
2115
2116 /* end of gnunet-service-gns_resolver.c */