diff options
Diffstat (limited to 'src/gns/gnunet-service-gns_resolver.c')
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 3290 |
1 files changed, 1649 insertions, 1641 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 703a0f652..da54f3dd5 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file gns/gnunet-service-gns_resolver.c | 22 | * @file gns/gnunet-service-gns_resolver.c |
@@ -45,17 +45,17 @@ | |||
45 | /** | 45 | /** |
46 | * Default DHT timeout for lookups. | 46 | * Default DHT timeout for lookups. |
47 | */ | 47 | */ |
48 | #define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 48 | #define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Default timeout for DNS lookups. | 51 | * Default timeout for DNS lookups. |
52 | */ | 52 | */ |
53 | #define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 53 | #define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Default timeout for VPN redirections. | 56 | * Default timeout for VPN redirections. |
57 | */ | 57 | */ |
58 | #define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) | 58 | #define VPN_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * DHT replication level | 61 | * DHT replication level |
@@ -80,9 +80,7 @@ struct AuthorityChain; | |||
80 | * responsible DNS server hostname in a GNS2DNS recursive | 80 | * responsible DNS server hostname in a GNS2DNS recursive |
81 | * resolution. | 81 | * resolution. |
82 | */ | 82 | */ |
83 | struct Gns2DnsPending | 83 | struct Gns2DnsPending { |
84 | { | ||
85 | |||
86 | /** | 84 | /** |
87 | * Kept in a DLL. | 85 | * Kept in a DLL. |
88 | */ | 86 | */ |
@@ -128,8 +126,7 @@ struct GNS_ResolverHandle; | |||
128 | * DLL to hold the authority chain we had to pass in the resolution | 126 | * DLL to hold the authority chain we had to pass in the resolution |
129 | * process. | 127 | * process. |
130 | */ | 128 | */ |
131 | struct AuthorityChain | 129 | struct AuthorityChain { |
132 | { | ||
133 | /** | 130 | /** |
134 | * This is a DLL. | 131 | * This is a DLL. |
135 | */ | 132 | */ |
@@ -159,16 +156,13 @@ struct AuthorityChain | |||
159 | /** | 156 | /** |
160 | * Information about the resolver authority for this label. | 157 | * Information about the resolver authority for this label. |
161 | */ | 158 | */ |
162 | union | 159 | union { |
163 | { | ||
164 | |||
165 | /** | 160 | /** |
166 | * The zone of the GNS authority | 161 | * The zone of the GNS authority |
167 | */ | 162 | */ |
168 | struct GNUNET_CRYPTO_EcdsaPublicKey gns_authority; | 163 | struct GNUNET_CRYPTO_EcdsaPublicKey gns_authority; |
169 | 164 | ||
170 | struct | 165 | struct { |
171 | { | ||
172 | /** | 166 | /** |
173 | * Domain of the DNS resolver that is the authority. | 167 | * Domain of the DNS resolver that is the authority. |
174 | * (appended to construct the DNS name to resolve; | 168 | * (appended to construct the DNS name to resolve; |
@@ -203,20 +197,15 @@ struct AuthorityChain | |||
203 | * Did we start the recursive resolution via DNS? | 197 | * Did we start the recursive resolution via DNS? |
204 | */ | 198 | */ |
205 | int launched; | 199 | int launched; |
206 | |||
207 | } dns_authority; | 200 | } dns_authority; |
208 | |||
209 | } authority_info; | 201 | } authority_info; |
210 | |||
211 | }; | 202 | }; |
212 | 203 | ||
213 | 204 | ||
214 | /** | 205 | /** |
215 | * A result we got from DNS. | 206 | * A result we got from DNS. |
216 | */ | 207 | */ |
217 | struct DnsResult | 208 | struct DnsResult { |
218 | { | ||
219 | |||
220 | /** | 209 | /** |
221 | * Kept in DLL. | 210 | * Kept in DLL. |
222 | */ | 211 | */ |
@@ -247,16 +236,13 @@ struct DnsResult | |||
247 | * Type of the GNS/DNS record. | 236 | * Type of the GNS/DNS record. |
248 | */ | 237 | */ |
249 | uint32_t record_type; | 238 | uint32_t record_type; |
250 | |||
251 | }; | 239 | }; |
252 | 240 | ||
253 | 241 | ||
254 | /** | 242 | /** |
255 | * Closure for #vpn_allocation_cb. | 243 | * Closure for #vpn_allocation_cb. |
256 | */ | 244 | */ |
257 | struct VpnContext | 245 | struct VpnContext { |
258 | { | ||
259 | |||
260 | /** | 246 | /** |
261 | * Which resolution process are we processing. | 247 | * Which resolution process are we processing. |
262 | */ | 248 | */ |
@@ -288,9 +274,7 @@ struct VpnContext | |||
288 | * Handle to a currenty pending resolution. On result (positive or | 274 | * Handle to a currenty pending resolution. On result (positive or |
289 | * negative) the #GNS_ResultProcessor is called. | 275 | * negative) the #GNS_ResultProcessor is called. |
290 | */ | 276 | */ |
291 | struct GNS_ResolverHandle | 277 | struct GNS_ResolverHandle { |
292 | { | ||
293 | |||
294 | /** | 278 | /** |
295 | * DLL | 279 | * DLL |
296 | */ | 280 | */ |
@@ -426,16 +410,13 @@ struct GNS_ResolverHandle | |||
426 | * 16 bit random ID we used in the @e dns_request. | 410 | * 16 bit random ID we used in the @e dns_request. |
427 | */ | 411 | */ |
428 | uint16_t original_dns_id; | 412 | uint16_t original_dns_id; |
429 | |||
430 | }; | 413 | }; |
431 | 414 | ||
432 | 415 | ||
433 | /** | 416 | /** |
434 | * Active namestore caching operations. | 417 | * Active namestore caching operations. |
435 | */ | 418 | */ |
436 | struct CacheOps | 419 | struct CacheOps { |
437 | { | ||
438 | |||
439 | /** | 420 | /** |
440 | * Organized in a DLL. | 421 | * Organized in a DLL. |
441 | */ | 422 | */ |
@@ -450,7 +431,6 @@ struct CacheOps | |||
450 | * Pending Namestore caching task. | 431 | * Pending Namestore caching task. |
451 | */ | 432 | */ |
452 | struct GNUNET_NAMECACHE_QueueEntry *namecache_qe_cache; | 433 | struct GNUNET_NAMECACHE_QueueEntry *namecache_qe_cache; |
453 | |||
454 | }; | 434 | }; |
455 | 435 | ||
456 | 436 | ||
@@ -526,19 +506,19 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
526 | * @return #GNUNET_YES if canonical | 506 | * @return #GNUNET_YES if canonical |
527 | */ | 507 | */ |
528 | /* dead, but keep for now */ int | 508 | /* dead, but keep for now */ int |
529 | is_canonical (const char *name) | 509 | is_canonical(const char *name) |
530 | { | 510 | { |
531 | const char *pos; | 511 | const char *pos; |
532 | const char *dot; | 512 | const char *dot; |
533 | 513 | ||
534 | if (NULL == strchr (name, | 514 | if (NULL == strchr(name, |
535 | (unsigned char) '.')) | 515 | (unsigned char)'.')) |
536 | return GNUNET_YES; | 516 | return GNUNET_YES; |
537 | if ('_' != name[0]) | 517 | if ('_' != name[0]) |
538 | return GNUNET_NO; | 518 | return GNUNET_NO; |
539 | pos = &name[1]; | 519 | pos = &name[1]; |
540 | while (NULL != (dot = strchr (pos, | 520 | while (NULL != (dot = strchr(pos, |
541 | (unsigned char) '.'))) | 521 | (unsigned char)'.'))) |
542 | if ('_' != dot[1]) | 522 | if ('_' != dot[1]) |
543 | return GNUNET_NO; | 523 | return GNUNET_NO; |
544 | else | 524 | else |
@@ -556,22 +536,22 @@ is_canonical (const char *name) | |||
556 | * @return updated name | 536 | * @return updated name |
557 | */ | 537 | */ |
558 | static char * | 538 | static char * |
559 | translate_dot_plus (struct GNS_ResolverHandle *rh, | 539 | translate_dot_plus(struct GNS_ResolverHandle *rh, |
560 | char *name) | 540 | char *name) |
561 | { | 541 | { |
562 | char *ret; | 542 | char *ret; |
563 | size_t s_len = strlen (name); | 543 | size_t s_len = strlen(name); |
564 | 544 | ||
565 | if (0 != strcmp (&name[s_len - 2], | 545 | if (0 != strcmp(&name[s_len - 2], |
566 | ".+")) | 546 | ".+")) |
567 | return name; /* did not end in ".+" */ | 547 | return name; /* did not end in ".+" */ |
568 | GNUNET_assert (GNUNET_YES == rh->ac_tail->gns_authority); | 548 | GNUNET_assert(GNUNET_YES == rh->ac_tail->gns_authority); |
569 | GNUNET_asprintf (&ret, | 549 | GNUNET_asprintf(&ret, |
570 | "%.*s.%s", | 550 | "%.*s.%s", |
571 | (int) (s_len - 2), | 551 | (int)(s_len - 2), |
572 | name, | 552 | name, |
573 | GNUNET_GNSRECORD_pkey_to_zkey (&rh->ac_tail->authority_info.gns_authority)); | 553 | GNUNET_GNSRECORD_pkey_to_zkey(&rh->ac_tail->authority_info.gns_authority)); |
574 | GNUNET_free (name); | 554 | GNUNET_free(name); |
575 | return ret; | 555 | return ret; |
576 | } | 556 | } |
577 | 557 | ||
@@ -583,12 +563,12 @@ translate_dot_plus (struct GNS_ResolverHandle *rh, | |||
583 | * @param cls the `struct GNS_ResolverHandle` | 563 | * @param cls the `struct GNS_ResolverHandle` |
584 | */ | 564 | */ |
585 | static void | 565 | static void |
586 | GNS_resolver_lookup_cancel_ (void *cls) | 566 | GNS_resolver_lookup_cancel_(void *cls) |
587 | { | 567 | { |
588 | struct GNS_ResolverHandle *rh = cls; | 568 | struct GNS_ResolverHandle *rh = cls; |
589 | 569 | ||
590 | rh->task_id = NULL; | 570 | rh->task_id = NULL; |
591 | GNS_resolver_lookup_cancel (rh); | 571 | GNS_resolver_lookup_cancel(rh); |
592 | } | 572 | } |
593 | 573 | ||
594 | 574 | ||
@@ -598,14 +578,14 @@ GNS_resolver_lookup_cancel_ (void *cls) | |||
598 | * @param rh the resolution to fail | 578 | * @param rh the resolution to fail |
599 | */ | 579 | */ |
600 | static void | 580 | static void |
601 | fail_resolution (struct GNS_ResolverHandle *rh) | 581 | fail_resolution(struct GNS_ResolverHandle *rh) |
602 | { | 582 | { |
603 | rh->proc (rh->proc_cls, | 583 | rh->proc(rh->proc_cls, |
604 | 0, | 584 | 0, |
605 | NULL); | 585 | NULL); |
606 | GNUNET_assert (NULL == rh->task_id); | 586 | GNUNET_assert(NULL == rh->task_id); |
607 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 587 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
608 | rh); | 588 | rh); |
609 | } | 589 | } |
610 | 590 | ||
611 | 591 | ||
@@ -615,12 +595,12 @@ fail_resolution (struct GNS_ResolverHandle *rh) | |||
615 | * @param cls the `struct GNS_ResolverHandle` | 595 | * @param cls the `struct GNS_ResolverHandle` |
616 | */ | 596 | */ |
617 | static void | 597 | static void |
618 | timeout_resolution (void *cls) | 598 | timeout_resolution(void *cls) |
619 | { | 599 | { |
620 | struct GNS_ResolverHandle *rh = cls; | 600 | struct GNS_ResolverHandle *rh = cls; |
621 | 601 | ||
622 | rh->task_id = NULL; | 602 | rh->task_id = NULL; |
623 | fail_resolution (rh); | 603 | fail_resolution(rh); |
624 | } | 604 | } |
625 | 605 | ||
626 | 606 | ||
@@ -642,7 +622,7 @@ timeout_resolution (void *cls) | |||
642 | * @return NULL if there are no more labels | 622 | * @return NULL if there are no more labels |
643 | */ | 623 | */ |
644 | static char * | 624 | static char * |
645 | resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh) | 625 | resolver_lookup_get_next_label(struct GNS_ResolverHandle *rh) |
646 | { | 626 | { |
647 | const char *rp; | 627 | const char *rp; |
648 | const char *dot; | 628 | const char *dot; |
@@ -655,71 +635,71 @@ resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh) | |||
655 | 635 | ||
656 | if (0 == rh->name_resolution_pos) | 636 | if (0 == rh->name_resolution_pos) |
657 | return NULL; | 637 | return NULL; |
658 | dot = memrchr (rh->name, | 638 | dot = memrchr(rh->name, |
659 | (int) '.', | 639 | (int)'.', |
660 | rh->name_resolution_pos); | 640 | rh->name_resolution_pos); |
661 | if (NULL == dot) | 641 | if (NULL == dot) |
662 | { | 642 | { |
663 | /* done, this was the last one */ | 643 | /* done, this was the last one */ |
664 | len = rh->name_resolution_pos; | 644 | len = rh->name_resolution_pos; |
665 | rp = rh->name; | 645 | rp = rh->name; |
666 | rh->name_resolution_pos = 0; | 646 | rh->name_resolution_pos = 0; |
667 | } | 647 | } |
668 | else | 648 | else |
669 | { | 649 | { |
670 | /* advance by one label */ | 650 | /* advance by one label */ |
671 | len = rh->name_resolution_pos - (dot - rh->name) - 1; | 651 | len = rh->name_resolution_pos - (dot - rh->name) - 1; |
672 | rp = dot + 1; | 652 | rp = dot + 1; |
673 | rh->name_resolution_pos = dot - rh->name; | 653 | rh->name_resolution_pos = dot - rh->name; |
674 | } | 654 | } |
675 | rh->protocol = 0; | 655 | rh->protocol = 0; |
676 | rh->service = 0; | 656 | rh->service = 0; |
677 | ret = GNUNET_strndup (rp, len); | 657 | ret = GNUNET_strndup(rp, len); |
678 | /* If we have labels starting with underscore with label on | 658 | /* If we have labels starting with underscore with label on |
679 | * the right (SRV/DANE/BOX case), determine port/protocol; | 659 | * the right (SRV/DANE/BOX case), determine port/protocol; |
680 | * The format of `rh->name` must be "_PORT._PROTOCOL". | 660 | * The format of `rh->name` must be "_PORT._PROTOCOL". |
681 | */ | 661 | */ |
682 | if ( ('_' == rh->name[0]) && | 662 | if (('_' == rh->name[0]) && |
683 | (NULL != (dot = memrchr (rh->name, | 663 | (NULL != (dot = memrchr(rh->name, |
684 | (int) '.', | 664 | (int)'.', |
685 | rh->name_resolution_pos))) && | 665 | rh->name_resolution_pos))) && |
686 | ('_' == dot[1]) && | 666 | ('_' == dot[1]) && |
687 | (NULL == memrchr (rh->name, | 667 | (NULL == memrchr(rh->name, |
688 | (int) '.', | 668 | (int)'.', |
689 | dot - rh->name)) ) | 669 | dot - rh->name))) |
690 | { | ||
691 | srv_name = GNUNET_strndup (&rh->name[1], | ||
692 | (dot - rh->name) - 1); | ||
693 | proto_name = GNUNET_strndup (&dot[2], | ||
694 | rh->name_resolution_pos - (dot - rh->name) - 1); | ||
695 | rh->name_resolution_pos = 0; | ||
696 | pe = getprotobyname (proto_name); | ||
697 | if (NULL == pe) | ||
698 | { | ||
699 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
700 | _("Protocol `%s' unknown, skipping labels.\n"), | ||
701 | proto_name); | ||
702 | GNUNET_free (proto_name); | ||
703 | GNUNET_free (srv_name); | ||
704 | return ret; | ||
705 | } | ||
706 | se = getservbyname (srv_name, | ||
707 | proto_name); | ||
708 | if (NULL == se) | ||
709 | { | 670 | { |
710 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 671 | srv_name = GNUNET_strndup(&rh->name[1], |
711 | _("Service `%s' unknown for protocol `%s', skipping labels.\n"), | 672 | (dot - rh->name) - 1); |
712 | srv_name, | 673 | proto_name = GNUNET_strndup(&dot[2], |
713 | proto_name); | 674 | rh->name_resolution_pos - (dot - rh->name) - 1); |
714 | GNUNET_free (proto_name); | 675 | rh->name_resolution_pos = 0; |
715 | GNUNET_free (srv_name); | 676 | pe = getprotobyname(proto_name); |
716 | return ret; | 677 | if (NULL == pe) |
678 | { | ||
679 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
680 | _("Protocol `%s' unknown, skipping labels.\n"), | ||
681 | proto_name); | ||
682 | GNUNET_free(proto_name); | ||
683 | GNUNET_free(srv_name); | ||
684 | return ret; | ||
685 | } | ||
686 | se = getservbyname(srv_name, | ||
687 | proto_name); | ||
688 | if (NULL == se) | ||
689 | { | ||
690 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
691 | _("Service `%s' unknown for protocol `%s', skipping labels.\n"), | ||
692 | srv_name, | ||
693 | proto_name); | ||
694 | GNUNET_free(proto_name); | ||
695 | GNUNET_free(srv_name); | ||
696 | return ret; | ||
697 | } | ||
698 | rh->protocol = pe->p_proto; | ||
699 | rh->service = se->s_port; | ||
700 | GNUNET_free(proto_name); | ||
701 | GNUNET_free(srv_name); | ||
717 | } | 702 | } |
718 | rh->protocol = pe->p_proto; | ||
719 | rh->service = se->s_port; | ||
720 | GNUNET_free (proto_name); | ||
721 | GNUNET_free (srv_name); | ||
722 | } | ||
723 | return ret; | 703 | return ret; |
724 | } | 704 | } |
725 | 705 | ||
@@ -730,7 +710,7 @@ resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh) | |||
730 | * @param rh resolution process that has culminated in a result | 710 | * @param rh resolution process that has culminated in a result |
731 | */ | 711 | */ |
732 | static void | 712 | static void |
733 | transmit_lookup_dns_result (struct GNS_ResolverHandle *rh) | 713 | transmit_lookup_dns_result(struct GNS_ResolverHandle *rh) |
734 | { | 714 | { |
735 | struct DnsResult *pos; | 715 | struct DnsResult *pos; |
736 | unsigned int n; | 716 | unsigned int n; |
@@ -744,31 +724,31 @@ transmit_lookup_dns_result (struct GNS_ResolverHandle *rh) | |||
744 | 724 | ||
745 | i = 0; | 725 | i = 0; |
746 | for (pos = rh->dns_result_head; NULL != pos; pos = pos->next) | 726 | for (pos = rh->dns_result_head; NULL != pos; pos = pos->next) |
747 | { | ||
748 | rd[i].data = pos->data; | ||
749 | rd[i].data_size = pos->data_size; | ||
750 | rd[i].record_type = pos->record_type; | ||
751 | if (0 == pos->expiration_time) | ||
752 | { | 727 | { |
753 | rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 728 | rd[i].data = pos->data; |
754 | rd[i].expiration_time = 0; | 729 | rd[i].data_size = pos->data_size; |
755 | } | 730 | rd[i].record_type = pos->record_type; |
756 | else | 731 | if (0 == pos->expiration_time) |
757 | { | 732 | { |
758 | rd[i].flags = GNUNET_GNSRECORD_RF_NONE; | 733 | rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
759 | rd[i].expiration_time = pos->expiration_time; | 734 | rd[i].expiration_time = 0; |
735 | } | ||
736 | else | ||
737 | { | ||
738 | rd[i].flags = GNUNET_GNSRECORD_RF_NONE; | ||
739 | rd[i].expiration_time = pos->expiration_time; | ||
740 | } | ||
741 | i++; | ||
760 | } | 742 | } |
761 | i++; | 743 | GNUNET_assert(i == n); |
762 | } | 744 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
763 | GNUNET_assert (i == n); | 745 | "Transmitting standard DNS result with %u records\n", |
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 746 | n); |
765 | "Transmitting standard DNS result with %u records\n", | 747 | rh->proc(rh->proc_cls, |
766 | n); | 748 | n, |
767 | rh->proc (rh->proc_cls, | 749 | rd); |
768 | n, | ||
769 | rd); | ||
770 | } | 750 | } |
771 | GNS_resolver_lookup_cancel (rh); | 751 | GNS_resolver_lookup_cancel(rh); |
772 | } | 752 | } |
773 | 753 | ||
774 | 754 | ||
@@ -782,25 +762,25 @@ transmit_lookup_dns_result (struct GNS_ResolverHandle *rh) | |||
782 | * @param data binary data to return in DNS record | 762 | * @param data binary data to return in DNS record |
783 | */ | 763 | */ |
784 | static void | 764 | static void |
785 | add_dns_result (struct GNS_ResolverHandle *rh, | 765 | add_dns_result(struct GNS_ResolverHandle *rh, |
786 | uint64_t expiration_time, | 766 | uint64_t expiration_time, |
787 | uint32_t record_type, | 767 | uint32_t record_type, |
788 | size_t data_size, | 768 | size_t data_size, |
789 | const void *data) | 769 | const void *data) |
790 | { | 770 | { |
791 | struct DnsResult *res; | 771 | struct DnsResult *res; |
792 | 772 | ||
793 | res = GNUNET_malloc (sizeof (struct DnsResult) + data_size); | 773 | res = GNUNET_malloc(sizeof(struct DnsResult) + data_size); |
794 | res->expiration_time = expiration_time; | 774 | res->expiration_time = expiration_time; |
795 | res->data_size = data_size; | 775 | res->data_size = data_size; |
796 | res->record_type = record_type; | 776 | res->record_type = record_type; |
797 | res->data = &res[1]; | 777 | res->data = &res[1]; |
798 | GNUNET_memcpy (&res[1], | 778 | GNUNET_memcpy(&res[1], |
799 | data, | 779 | data, |
800 | data_size); | 780 | data_size); |
801 | GNUNET_CONTAINER_DLL_insert (rh->dns_result_head, | 781 | GNUNET_CONTAINER_DLL_insert(rh->dns_result_head, |
802 | rh->dns_result_tail, | 782 | rh->dns_result_tail, |
803 | res); | 783 | res); |
804 | } | 784 | } |
805 | 785 | ||
806 | 786 | ||
@@ -813,45 +793,47 @@ add_dns_result (struct GNS_ResolverHandle *rh, | |||
813 | * @param addrlen length of the address | 793 | * @param addrlen length of the address |
814 | */ | 794 | */ |
815 | static void | 795 | static void |
816 | handle_dns_result (void *cls, | 796 | handle_dns_result(void *cls, |
817 | const struct sockaddr *addr, | 797 | const struct sockaddr *addr, |
818 | socklen_t addrlen) | 798 | socklen_t addrlen) |
819 | { | 799 | { |
820 | struct GNS_ResolverHandle *rh = cls; | 800 | struct GNS_ResolverHandle *rh = cls; |
821 | const struct sockaddr_in *sa4; | 801 | const struct sockaddr_in *sa4; |
822 | const struct sockaddr_in6 *sa6; | 802 | const struct sockaddr_in6 *sa6; |
823 | 803 | ||
824 | if (NULL == addr) | 804 | if (NULL == addr) |
825 | { | 805 | { |
826 | rh->std_resolve = NULL; | 806 | rh->std_resolve = NULL; |
827 | transmit_lookup_dns_result (rh); | 807 | transmit_lookup_dns_result(rh); |
828 | return; | 808 | return; |
829 | } | 809 | } |
830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 810 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
831 | "Received %u bytes of DNS IP data\n", | 811 | "Received %u bytes of DNS IP data\n", |
832 | addrlen); | 812 | addrlen); |
833 | switch (addr->sa_family) | 813 | switch (addr->sa_family) |
834 | { | 814 | { |
835 | case AF_INET: | 815 | case AF_INET: |
836 | sa4 = (const struct sockaddr_in *) addr; | 816 | sa4 = (const struct sockaddr_in *)addr; |
837 | add_dns_result (rh, | 817 | add_dns_result(rh, |
838 | 0 /* expiration time is unknown */, | 818 | 0 /* expiration time is unknown */, |
839 | GNUNET_DNSPARSER_TYPE_A, | 819 | GNUNET_DNSPARSER_TYPE_A, |
840 | sizeof (struct in_addr), | 820 | sizeof(struct in_addr), |
841 | &sa4->sin_addr); | 821 | &sa4->sin_addr); |
842 | break; | 822 | break; |
843 | case AF_INET6: | 823 | |
844 | sa6 = (const struct sockaddr_in6 *) addr; | 824 | case AF_INET6: |
845 | add_dns_result (rh, | 825 | sa6 = (const struct sockaddr_in6 *)addr; |
846 | 0 /* expiration time is unknown */, | 826 | add_dns_result(rh, |
847 | GNUNET_DNSPARSER_TYPE_AAAA, | 827 | 0 /* expiration time is unknown */, |
848 | sizeof (struct in6_addr), | 828 | GNUNET_DNSPARSER_TYPE_AAAA, |
849 | &sa6->sin6_addr); | 829 | sizeof(struct in6_addr), |
850 | break; | 830 | &sa6->sin6_addr); |
851 | default: | 831 | break; |
852 | GNUNET_break (0); | 832 | |
853 | break; | 833 | default: |
854 | } | 834 | GNUNET_break(0); |
835 | break; | ||
836 | } | ||
855 | } | 837 | } |
856 | 838 | ||
857 | 839 | ||
@@ -862,7 +844,7 @@ handle_dns_result (void *cls, | |||
862 | * @param tc task context | 844 | * @param tc task context |
863 | */ | 845 | */ |
864 | static void | 846 | static void |
865 | recursive_resolution (void *cls); | 847 | recursive_resolution(void *cls); |
866 | 848 | ||
867 | 849 | ||
868 | /** | 850 | /** |
@@ -872,7 +854,7 @@ recursive_resolution (void *cls); | |||
872 | * @param cls closure with `struct GNS_ResolverHandle *rh` | 854 | * @param cls closure with `struct GNS_ResolverHandle *rh` |
873 | */ | 855 | */ |
874 | static void | 856 | static void |
875 | start_resolver_lookup (void *cls); | 857 | start_resolver_lookup(void *cls); |
876 | 858 | ||
877 | 859 | ||
878 | /** | 860 | /** |
@@ -884,9 +866,9 @@ start_resolver_lookup (void *cls); | |||
884 | * @param dns_len number of bytes in @a dns | 866 | * @param dns_len number of bytes in @a dns |
885 | */ | 867 | */ |
886 | static void | 868 | static void |
887 | dns_result_parser (void *cls, | 869 | dns_result_parser(void *cls, |
888 | const struct GNUNET_TUN_DnsHeader *dns, | 870 | const struct GNUNET_TUN_DnsHeader *dns, |
889 | size_t dns_len) | 871 | size_t dns_len) |
890 | { | 872 | { |
891 | struct GNS_ResolverHandle *rh = cls; | 873 | struct GNS_ResolverHandle *rh = cls; |
892 | struct GNUNET_DNSPARSER_Packet *p; | 874 | struct GNUNET_DNSPARSER_Packet *p; |
@@ -894,80 +876,82 @@ dns_result_parser (void *cls, | |||
894 | unsigned int rd_count; | 876 | unsigned int rd_count; |
895 | 877 | ||
896 | if (NULL == dns) | 878 | if (NULL == dns) |
897 | { | 879 | { |
898 | rh->dns_request = NULL; | 880 | rh->dns_request = NULL; |
899 | GNUNET_SCHEDULER_cancel (rh->task_id); | 881 | GNUNET_SCHEDULER_cancel(rh->task_id); |
900 | rh->task_id = NULL; | 882 | rh->task_id = NULL; |
901 | fail_resolution (rh); | 883 | fail_resolution(rh); |
902 | return; | 884 | return; |
903 | } | 885 | } |
904 | if (rh->original_dns_id != dns->id) | 886 | if (rh->original_dns_id != dns->id) |
905 | { | 887 | { |
906 | /* DNS answer, but for another query */ | 888 | /* DNS answer, but for another query */ |
907 | return; | 889 | return; |
908 | } | 890 | } |
909 | p = GNUNET_DNSPARSER_parse ((const char *) dns, | 891 | p = GNUNET_DNSPARSER_parse((const char *)dns, |
910 | dns_len); | 892 | dns_len); |
911 | if (NULL == p) | 893 | if (NULL == p) |
912 | { | ||
913 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
914 | _("Failed to parse DNS response\n")); | ||
915 | return; | ||
916 | } | ||
917 | |||
918 | /* We got a result from DNS */ | ||
919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
920 | "Received DNS response for `%s' with %u answers\n", | ||
921 | rh->ac_tail->label, | ||
922 | (unsigned int) p->num_answers); | ||
923 | if ( (p->num_answers > 0) && | ||
924 | (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && | ||
925 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) ) | ||
926 | { | ||
927 | int af; | ||
928 | |||
929 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
930 | "Got CNAME `%s' from DNS for `%s'\n", | ||
931 | p->answers[0].data.hostname, | ||
932 | rh->name); | ||
933 | if (NULL != rh->std_resolve) | ||
934 | { | 894 | { |
935 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 895 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
936 | "Multiple CNAME results from DNS resolving `%s'! Not really allowed...\n", | 896 | _("Failed to parse DNS response\n")); |
937 | rh->name); | 897 | return; |
938 | GNUNET_RESOLVER_request_cancel (rh->std_resolve); | ||
939 | } | 898 | } |
940 | GNUNET_free (rh->name); | 899 | |
941 | rh->name = GNUNET_strdup (p->answers[0].data.hostname); | 900 | /* We got a result from DNS */ |
942 | rh->name_resolution_pos = strlen (rh->name); | 901 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
943 | switch (rh->record_type) | 902 | "Received DNS response for `%s' with %u answers\n", |
903 | rh->ac_tail->label, | ||
904 | (unsigned int)p->num_answers); | ||
905 | if ((p->num_answers > 0) && | ||
906 | (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && | ||
907 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type)) | ||
944 | { | 908 | { |
945 | case GNUNET_DNSPARSER_TYPE_A: | 909 | int af; |
946 | af = AF_INET; | 910 | |
947 | break; | 911 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
948 | case GNUNET_DNSPARSER_TYPE_AAAA: | 912 | "Got CNAME `%s' from DNS for `%s'\n", |
949 | af = AF_INET6; | 913 | p->answers[0].data.hostname, |
950 | break; | 914 | rh->name); |
951 | default: | 915 | if (NULL != rh->std_resolve) |
952 | af = AF_UNSPEC; | 916 | { |
953 | break; | 917 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
918 | "Multiple CNAME results from DNS resolving `%s'! Not really allowed...\n", | ||
919 | rh->name); | ||
920 | GNUNET_RESOLVER_request_cancel(rh->std_resolve); | ||
921 | } | ||
922 | GNUNET_free(rh->name); | ||
923 | rh->name = GNUNET_strdup(p->answers[0].data.hostname); | ||
924 | rh->name_resolution_pos = strlen(rh->name); | ||
925 | switch (rh->record_type) | ||
926 | { | ||
927 | case GNUNET_DNSPARSER_TYPE_A: | ||
928 | af = AF_INET; | ||
929 | break; | ||
930 | |||
931 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
932 | af = AF_INET6; | ||
933 | break; | ||
934 | |||
935 | default: | ||
936 | af = AF_UNSPEC; | ||
937 | break; | ||
938 | } | ||
939 | if (NULL != rh->leho) | ||
940 | add_dns_result(rh, | ||
941 | GNUNET_TIME_UNIT_HOURS.rel_value_us, | ||
942 | GNUNET_GNSRECORD_TYPE_LEHO, | ||
943 | strlen(rh->leho), | ||
944 | rh->leho); | ||
945 | rh->std_resolve = GNUNET_RESOLVER_ip_get(rh->name, | ||
946 | af, | ||
947 | DNS_LOOKUP_TIMEOUT, | ||
948 | &handle_dns_result, | ||
949 | rh); | ||
950 | GNUNET_DNSPARSER_free_packet(p); | ||
951 | GNUNET_DNSSTUB_resolve_cancel(rh->dns_request); | ||
952 | rh->dns_request = NULL; | ||
953 | return; | ||
954 | } | 954 | } |
955 | if (NULL != rh->leho) | ||
956 | add_dns_result (rh, | ||
957 | GNUNET_TIME_UNIT_HOURS.rel_value_us, | ||
958 | GNUNET_GNSRECORD_TYPE_LEHO, | ||
959 | strlen (rh->leho), | ||
960 | rh->leho); | ||
961 | rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, | ||
962 | af, | ||
963 | DNS_LOOKUP_TIMEOUT, | ||
964 | &handle_dns_result, | ||
965 | rh); | ||
966 | GNUNET_DNSPARSER_free_packet (p); | ||
967 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); | ||
968 | rh->dns_request = NULL; | ||
969 | return; | ||
970 | } | ||
971 | 955 | ||
972 | /* convert from (parsed) DNS to (binary) GNS format! */ | 956 | /* convert from (parsed) DNS to (binary) GNS format! */ |
973 | rd_count = p->num_answers + p->num_authority_records + p->num_additional_records; | 957 | rd_count = p->num_answers + p->num_authority_records + p->num_additional_records; |
@@ -980,151 +964,157 @@ dns_result_parser (void *cls, | |||
980 | 964 | ||
981 | buf_off = 0; | 965 | buf_off = 0; |
982 | skip = 0; | 966 | skip = 0; |
983 | memset (rd, | 967 | memset(rd, |
984 | 0, | 968 | 0, |
985 | sizeof (rd)); | 969 | sizeof(rd)); |
986 | for (unsigned int i=0;i<rd_count;i++) | 970 | for (unsigned int i = 0; i < rd_count; i++) |
987 | { | ||
988 | if (i < p->num_answers) | ||
989 | rec = &p->answers[i]; | ||
990 | else if (i < p->num_answers + p->num_authority_records) | ||
991 | rec = &p->authority_records[i - p->num_answers]; | ||
992 | else | ||
993 | rec = &p->additional_records[i - p->num_answers - p->num_authority_records]; | ||
994 | /* As we copied the full DNS name to 'rh->ac_tail->label', this | ||
995 | should be the correct check to see if this record is actually | ||
996 | a record for our label... */ | ||
997 | if (0 != strcmp (rec->name, | ||
998 | rh->ac_tail->label)) | ||
999 | { | 971 | { |
1000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 972 | if (i < p->num_answers) |
1001 | "Dropping record `%s', does not match desired name `%s'\n", | 973 | rec = &p->answers[i]; |
1002 | rec->name, | 974 | else if (i < p->num_answers + p->num_authority_records) |
1003 | rh->ac_tail->label); | 975 | rec = &p->authority_records[i - p->num_answers]; |
1004 | skip++; | 976 | else |
1005 | continue; | 977 | rec = &p->additional_records[i - p->num_answers - p->num_authority_records]; |
1006 | } | 978 | /* As we copied the full DNS name to 'rh->ac_tail->label', this |
1007 | rd[i - skip].record_type = rec->type; | 979 | should be the correct check to see if this record is actually |
1008 | rd[i - skip].expiration_time = rec->expiration_time.abs_value_us; | 980 | a record for our label... */ |
1009 | switch (rec->type) | 981 | if (0 != strcmp(rec->name, |
982 | rh->ac_tail->label)) | ||
983 | { | ||
984 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
985 | "Dropping record `%s', does not match desired name `%s'\n", | ||
986 | rec->name, | ||
987 | rh->ac_tail->label); | ||
988 | skip++; | ||
989 | continue; | ||
990 | } | ||
991 | rd[i - skip].record_type = rec->type; | ||
992 | rd[i - skip].expiration_time = rec->expiration_time.abs_value_us; | ||
993 | switch (rec->type) | ||
994 | { | ||
995 | case GNUNET_DNSPARSER_TYPE_A: | ||
996 | if (rec->data.raw.data_len != sizeof(struct in_addr)) | ||
997 | { | ||
998 | GNUNET_break_op(0); | ||
999 | skip++; | ||
1000 | continue; | ||
1001 | } | ||
1002 | rd[i - skip].data_size = rec->data.raw.data_len; | ||
1003 | rd[i - skip].data = rec->data.raw.data; | ||
1004 | break; | ||
1005 | |||
1006 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
1007 | if (rec->data.raw.data_len != sizeof(struct in6_addr)) | ||
1008 | { | ||
1009 | GNUNET_break_op(0); | ||
1010 | skip++; | ||
1011 | continue; | ||
1012 | } | ||
1013 | rd[i - skip].data_size = rec->data.raw.data_len; | ||
1014 | rd[i - skip].data = rec->data.raw.data; | ||
1015 | break; | ||
1016 | |||
1017 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
1018 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
1019 | case GNUNET_DNSPARSER_TYPE_NS: | ||
1020 | buf_start = buf_off; | ||
1021 | if (GNUNET_OK != | ||
1022 | GNUNET_DNSPARSER_builder_add_name(buf, | ||
1023 | sizeof(buf), | ||
1024 | &buf_off, | ||
1025 | rec->data.hostname)) | ||
1026 | { | ||
1027 | GNUNET_break(0); | ||
1028 | skip++; | ||
1029 | continue; | ||
1030 | } | ||
1031 | rd[i - skip].data_size = buf_off - buf_start; | ||
1032 | rd[i - skip].data = &buf[buf_start]; | ||
1033 | break; | ||
1034 | |||
1035 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
1036 | buf_start = buf_off; | ||
1037 | if (GNUNET_OK != | ||
1038 | GNUNET_DNSPARSER_builder_add_soa(buf, | ||
1039 | sizeof(buf), | ||
1040 | &buf_off, | ||
1041 | rec->data.soa)) | ||
1042 | { | ||
1043 | GNUNET_break(0); | ||
1044 | skip++; | ||
1045 | continue; | ||
1046 | } | ||
1047 | rd[i - skip].data_size = buf_off - buf_start; | ||
1048 | rd[i - skip].data = &buf[buf_start]; | ||
1049 | break; | ||
1050 | |||
1051 | case GNUNET_DNSPARSER_TYPE_MX: | ||
1052 | buf_start = buf_off; | ||
1053 | if (GNUNET_OK != | ||
1054 | GNUNET_DNSPARSER_builder_add_mx(buf, | ||
1055 | sizeof(buf), | ||
1056 | &buf_off, | ||
1057 | rec->data.mx)) | ||
1058 | { | ||
1059 | GNUNET_break(0); | ||
1060 | skip++; | ||
1061 | continue; | ||
1062 | } | ||
1063 | rd[i - skip].data_size = buf_off - buf_start; | ||
1064 | rd[i - skip].data = &buf[buf_start]; | ||
1065 | break; | ||
1066 | |||
1067 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
1068 | buf_start = buf_off; | ||
1069 | if (GNUNET_OK != | ||
1070 | GNUNET_DNSPARSER_builder_add_srv(buf, | ||
1071 | sizeof(buf), | ||
1072 | &buf_off, | ||
1073 | rec->data.srv)) | ||
1074 | { | ||
1075 | GNUNET_break(0); | ||
1076 | skip++; | ||
1077 | continue; | ||
1078 | } | ||
1079 | rd[i - skip].data_size = buf_off - buf_start; | ||
1080 | rd[i - skip].data = &buf[buf_start]; | ||
1081 | break; | ||
1082 | |||
1083 | default: | ||
1084 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1085 | _("Skipping record of unsupported type %d\n"), | ||
1086 | rec->type); | ||
1087 | skip++; | ||
1088 | continue; | ||
1089 | } | ||
1090 | } /* end of for all records in answer */ | ||
1091 | if (NULL != rh->leho) | ||
1010 | { | 1092 | { |
1011 | case GNUNET_DNSPARSER_TYPE_A: | 1093 | rd[rd_count - skip].record_type = GNUNET_GNSRECORD_TYPE_LEHO; |
1012 | if (rec->data.raw.data_len != sizeof (struct in_addr)) | 1094 | rd[rd_count - skip].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
1013 | { | 1095 | rd[rd_count - skip].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; |
1014 | GNUNET_break_op (0); | 1096 | rd[rd_count - skip].data = rh->leho; |
1015 | skip++; | 1097 | rd[rd_count - skip].data_size = strlen(rh->leho); |
1016 | continue; | 1098 | skip--; /* skip one LESS */ |
1017 | } | 1099 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1018 | rd[i - skip].data_size = rec->data.raw.data_len; | 1100 | "Adding LEHO %s\n", |
1019 | rd[i - skip].data = rec->data.raw.data; | 1101 | rh->leho); |
1020 | break; | ||
1021 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
1022 | if (rec->data.raw.data_len != sizeof (struct in6_addr)) | ||
1023 | { | ||
1024 | GNUNET_break_op (0); | ||
1025 | skip++; | ||
1026 | continue; | ||
1027 | } | ||
1028 | rd[i - skip].data_size = rec->data.raw.data_len; | ||
1029 | rd[i - skip].data = rec->data.raw.data; | ||
1030 | break; | ||
1031 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
1032 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
1033 | case GNUNET_DNSPARSER_TYPE_NS: | ||
1034 | buf_start = buf_off; | ||
1035 | if (GNUNET_OK != | ||
1036 | GNUNET_DNSPARSER_builder_add_name (buf, | ||
1037 | sizeof (buf), | ||
1038 | &buf_off, | ||
1039 | rec->data.hostname)) | ||
1040 | { | ||
1041 | GNUNET_break (0); | ||
1042 | skip++; | ||
1043 | continue; | ||
1044 | } | ||
1045 | rd[i - skip].data_size = buf_off - buf_start; | ||
1046 | rd[i - skip].data = &buf[buf_start]; | ||
1047 | break; | ||
1048 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
1049 | buf_start = buf_off; | ||
1050 | if (GNUNET_OK != | ||
1051 | GNUNET_DNSPARSER_builder_add_soa (buf, | ||
1052 | sizeof (buf), | ||
1053 | &buf_off, | ||
1054 | rec->data.soa)) | ||
1055 | { | ||
1056 | GNUNET_break (0); | ||
1057 | skip++; | ||
1058 | continue; | ||
1059 | } | ||
1060 | rd[i - skip].data_size = buf_off - buf_start; | ||
1061 | rd[i - skip].data = &buf[buf_start]; | ||
1062 | break; | ||
1063 | case GNUNET_DNSPARSER_TYPE_MX: | ||
1064 | buf_start = buf_off; | ||
1065 | if (GNUNET_OK != | ||
1066 | GNUNET_DNSPARSER_builder_add_mx (buf, | ||
1067 | sizeof (buf), | ||
1068 | &buf_off, | ||
1069 | rec->data.mx)) | ||
1070 | { | ||
1071 | GNUNET_break (0); | ||
1072 | skip++; | ||
1073 | continue; | ||
1074 | } | ||
1075 | rd[i - skip].data_size = buf_off - buf_start; | ||
1076 | rd[i - skip].data = &buf[buf_start]; | ||
1077 | break; | ||
1078 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
1079 | buf_start = buf_off; | ||
1080 | if (GNUNET_OK != | ||
1081 | GNUNET_DNSPARSER_builder_add_srv (buf, | ||
1082 | sizeof (buf), | ||
1083 | &buf_off, | ||
1084 | rec->data.srv)) | ||
1085 | { | ||
1086 | GNUNET_break (0); | ||
1087 | skip++; | ||
1088 | continue; | ||
1089 | } | ||
1090 | rd[i - skip].data_size = buf_off - buf_start; | ||
1091 | rd[i - skip].data = &buf[buf_start]; | ||
1092 | break; | ||
1093 | default: | ||
1094 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1095 | _("Skipping record of unsupported type %d\n"), | ||
1096 | rec->type); | ||
1097 | skip++; | ||
1098 | continue; | ||
1099 | } | 1102 | } |
1100 | } /* end of for all records in answer */ | 1103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1101 | if (NULL != rh->leho) | 1104 | "Returning DNS response for `%s' with %u answers\n", |
1102 | { | 1105 | rh->ac_tail->label, |
1103 | rd[rd_count - skip].record_type = GNUNET_GNSRECORD_TYPE_LEHO; | 1106 | (unsigned int)(rd_count - skip)); |
1104 | rd[rd_count - skip].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1107 | rh->proc(rh->proc_cls, |
1105 | rd[rd_count - skip].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; | 1108 | rd_count - skip, |
1106 | rd[rd_count - skip].data = rh->leho; | 1109 | rd); |
1107 | rd[rd_count - skip].data_size = strlen (rh->leho); | 1110 | GNUNET_DNSSTUB_resolve_cancel(rh->dns_request); |
1108 | skip--; /* skip one LESS */ | ||
1109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1110 | "Adding LEHO %s\n", | ||
1111 | rh->leho); | ||
1112 | } | ||
1113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1114 | "Returning DNS response for `%s' with %u answers\n", | ||
1115 | rh->ac_tail->label, | ||
1116 | (unsigned int) (rd_count - skip)); | ||
1117 | rh->proc (rh->proc_cls, | ||
1118 | rd_count - skip, | ||
1119 | rd); | ||
1120 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); | ||
1121 | rh->dns_request = NULL; | 1111 | rh->dns_request = NULL; |
1122 | } | 1112 | } |
1123 | GNUNET_DNSPARSER_free_packet (p); | 1113 | GNUNET_DNSPARSER_free_packet(p); |
1124 | if (NULL != rh->task_id) | 1114 | if (NULL != rh->task_id) |
1125 | GNUNET_SCHEDULER_cancel (rh->task_id); /* should be timeout task */ | 1115 | GNUNET_SCHEDULER_cancel(rh->task_id); /* should be timeout task */ |
1126 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 1116 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
1127 | rh); | 1117 | rh); |
1128 | } | 1118 | } |
1129 | 1119 | ||
1130 | 1120 | ||
@@ -1137,7 +1127,7 @@ dns_result_parser (void *cls, | |||
1137 | * @param rh resolution information | 1127 | * @param rh resolution information |
1138 | */ | 1128 | */ |
1139 | static void | 1129 | static void |
1140 | recursive_dns_resolution (struct GNS_ResolverHandle *rh) | 1130 | recursive_dns_resolution(struct GNS_ResolverHandle *rh) |
1141 | { | 1131 | { |
1142 | struct AuthorityChain *ac; | 1132 | struct AuthorityChain *ac; |
1143 | struct GNUNET_DNSPARSER_Query *query; | 1133 | struct GNUNET_DNSPARSER_Query *query; |
@@ -1147,54 +1137,54 @@ recursive_dns_resolution (struct GNS_ResolverHandle *rh) | |||
1147 | int ret; | 1137 | int ret; |
1148 | 1138 | ||
1149 | ac = rh->ac_tail; | 1139 | ac = rh->ac_tail; |
1150 | GNUNET_assert (NULL != ac); | 1140 | GNUNET_assert(NULL != ac); |
1151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1152 | "Starting DNS lookup for `%s'\n", | 1142 | "Starting DNS lookup for `%s'\n", |
1153 | ac->label); | 1143 | ac->label); |
1154 | GNUNET_assert (GNUNET_NO == ac->gns_authority); | 1144 | GNUNET_assert(GNUNET_NO == ac->gns_authority); |
1155 | query = GNUNET_new (struct GNUNET_DNSPARSER_Query); | 1145 | query = GNUNET_new(struct GNUNET_DNSPARSER_Query); |
1156 | query->name = GNUNET_strdup (ac->label); | 1146 | query->name = GNUNET_strdup(ac->label); |
1157 | query->type = rh->record_type; | 1147 | query->type = rh->record_type; |
1158 | query->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 1148 | query->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
1159 | p = GNUNET_new (struct GNUNET_DNSPARSER_Packet); | 1149 | p = GNUNET_new(struct GNUNET_DNSPARSER_Packet); |
1160 | p->queries = query; | 1150 | p->queries = query; |
1161 | p->num_queries = 1; | 1151 | p->num_queries = 1; |
1162 | p->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 1152 | p->id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, |
1163 | UINT16_MAX); | 1153 | UINT16_MAX); |
1164 | p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY; | 1154 | p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY; |
1165 | p->flags.recursion_desired = 1; | 1155 | p->flags.recursion_desired = 1; |
1166 | ret = GNUNET_DNSPARSER_pack (p, | 1156 | ret = GNUNET_DNSPARSER_pack(p, |
1167 | 1024, | 1157 | 1024, |
1168 | &dns_request, | 1158 | &dns_request, |
1169 | &dns_request_length); | 1159 | &dns_request_length); |
1170 | if (GNUNET_OK != ret) | 1160 | if (GNUNET_OK != ret) |
1171 | { | 1161 | { |
1172 | GNUNET_break (0); | 1162 | GNUNET_break(0); |
1173 | rh->proc (rh->proc_cls, | 1163 | rh->proc(rh->proc_cls, |
1174 | 0, | 1164 | 0, |
1175 | NULL); | 1165 | NULL); |
1176 | GNUNET_assert (NULL == rh->task_id); | 1166 | GNUNET_assert(NULL == rh->task_id); |
1177 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 1167 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
1178 | rh); | 1168 | rh); |
1179 | } | 1169 | } |
1180 | else | 1170 | else |
1181 | { | 1171 | { |
1182 | rh->original_dns_id = p->id; | 1172 | rh->original_dns_id = p->id; |
1183 | GNUNET_assert (NULL != ac->authority_info.dns_authority.dns_handle); | 1173 | GNUNET_assert(NULL != ac->authority_info.dns_authority.dns_handle); |
1184 | GNUNET_assert (NULL == rh->dns_request); | 1174 | GNUNET_assert(NULL == rh->dns_request); |
1185 | rh->leho = GNUNET_strdup (ac->label); | 1175 | rh->leho = GNUNET_strdup(ac->label); |
1186 | rh->dns_request = GNUNET_DNSSTUB_resolve (ac->authority_info.dns_authority.dns_handle, | 1176 | rh->dns_request = GNUNET_DNSSTUB_resolve(ac->authority_info.dns_authority.dns_handle, |
1187 | dns_request, | 1177 | dns_request, |
1188 | dns_request_length, | 1178 | dns_request_length, |
1189 | &dns_result_parser, | 1179 | &dns_result_parser, |
1190 | rh); | 1180 | rh); |
1191 | rh->task_id = GNUNET_SCHEDULER_add_delayed (DNS_LOOKUP_TIMEOUT, | 1181 | rh->task_id = GNUNET_SCHEDULER_add_delayed(DNS_LOOKUP_TIMEOUT, |
1192 | &timeout_resolution, | 1182 | &timeout_resolution, |
1193 | rh); | 1183 | rh); |
1194 | } | 1184 | } |
1195 | if (GNUNET_SYSERR != ret) | 1185 | if (GNUNET_SYSERR != ret) |
1196 | GNUNET_free (dns_request); | 1186 | GNUNET_free(dns_request); |
1197 | GNUNET_DNSPARSER_free_packet (p); | 1187 | GNUNET_DNSPARSER_free_packet(p); |
1198 | } | 1188 | } |
1199 | 1189 | ||
1200 | 1190 | ||
@@ -1207,85 +1197,87 @@ recursive_dns_resolution (struct GNS_ResolverHandle *rh) | |||
1207 | * authority chain tail | 1197 | * authority chain tail |
1208 | */ | 1198 | */ |
1209 | static void | 1199 | static void |
1210 | handle_gns_cname_result (struct GNS_ResolverHandle *rh, | 1200 | handle_gns_cname_result(struct GNS_ResolverHandle *rh, |
1211 | const char *cname) | 1201 | const char *cname) |
1212 | { | 1202 | { |
1213 | size_t nlen; | 1203 | size_t nlen; |
1214 | char *res; | 1204 | char *res; |
1215 | struct AuthorityChain *ac; | 1205 | struct AuthorityChain *ac; |
1216 | int af; | 1206 | int af; |
1217 | 1207 | ||
1218 | nlen = strlen (cname); | 1208 | nlen = strlen(cname); |
1219 | if ( (nlen > 2) && | 1209 | if ((nlen > 2) && |
1220 | (0 == strcmp (".+", | 1210 | (0 == strcmp(".+", |
1221 | &cname[nlen - 2])) ) | 1211 | &cname[nlen - 2]))) |
1222 | { | ||
1223 | /* CNAME resolution continues relative to current domain */ | ||
1224 | if (0 == rh->name_resolution_pos) | ||
1225 | { | 1212 | { |
1226 | res = GNUNET_strndup (cname, nlen - 2); | 1213 | /* CNAME resolution continues relative to current domain */ |
1227 | rh->name_resolution_pos = nlen - 2; | 1214 | if (0 == rh->name_resolution_pos) |
1215 | { | ||
1216 | res = GNUNET_strndup(cname, nlen - 2); | ||
1217 | rh->name_resolution_pos = nlen - 2; | ||
1218 | } | ||
1219 | else | ||
1220 | { | ||
1221 | GNUNET_asprintf(&res, | ||
1222 | "%.*s.%.*s", | ||
1223 | (int)rh->name_resolution_pos, | ||
1224 | rh->name, | ||
1225 | (int)(nlen - 2), | ||
1226 | cname); | ||
1227 | rh->name_resolution_pos = strlen(res); | ||
1228 | } | ||
1229 | GNUNET_free(rh->name); | ||
1230 | rh->name = res; | ||
1231 | ac = GNUNET_new(struct AuthorityChain); | ||
1232 | ac->rh = rh; | ||
1233 | ac->gns_authority = GNUNET_YES; | ||
1234 | ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority; | ||
1235 | ac->label = resolver_lookup_get_next_label(rh); | ||
1236 | /* add AC to tail */ | ||
1237 | GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, | ||
1238 | rh->ac_tail, | ||
1239 | ac); | ||
1240 | rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, | ||
1241 | rh); | ||
1242 | return; | ||
1228 | } | 1243 | } |
1229 | else | 1244 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1245 | "Got CNAME `%s' from GNS for `%s'\n", | ||
1246 | cname, | ||
1247 | rh->name); | ||
1248 | if (NULL != rh->std_resolve) | ||
1230 | { | 1249 | { |
1231 | GNUNET_asprintf (&res, | 1250 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1232 | "%.*s.%.*s", | 1251 | "Multiple CNAME results from GNS resolving `%s'! Not really allowed...\n", |
1233 | (int) rh->name_resolution_pos, | 1252 | rh->name); |
1234 | rh->name, | 1253 | GNUNET_RESOLVER_request_cancel(rh->std_resolve); |
1235 | (int) (nlen - 2), | ||
1236 | cname); | ||
1237 | rh->name_resolution_pos = strlen (res); | ||
1238 | } | 1254 | } |
1239 | GNUNET_free (rh->name); | ||
1240 | rh->name = res; | ||
1241 | ac = GNUNET_new (struct AuthorityChain); | ||
1242 | ac->rh = rh; | ||
1243 | ac->gns_authority = GNUNET_YES; | ||
1244 | ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority; | ||
1245 | ac->label = resolver_lookup_get_next_label (rh); | ||
1246 | /* add AC to tail */ | ||
1247 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | ||
1248 | rh->ac_tail, | ||
1249 | ac); | ||
1250 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | ||
1251 | rh); | ||
1252 | return; | ||
1253 | } | ||
1254 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1255 | "Got CNAME `%s' from GNS for `%s'\n", | ||
1256 | cname, | ||
1257 | rh->name); | ||
1258 | if (NULL != rh->std_resolve) | ||
1259 | { | ||
1260 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1261 | "Multiple CNAME results from GNS resolving `%s'! Not really allowed...\n", | ||
1262 | rh->name); | ||
1263 | GNUNET_RESOLVER_request_cancel (rh->std_resolve); | ||
1264 | } | ||
1265 | /* name is absolute, go to DNS */ | 1255 | /* name is absolute, go to DNS */ |
1266 | GNUNET_free (rh->name); | 1256 | GNUNET_free(rh->name); |
1267 | rh->name = GNUNET_strdup (cname); | 1257 | rh->name = GNUNET_strdup(cname); |
1268 | rh->name_resolution_pos = strlen (rh->name); | 1258 | rh->name_resolution_pos = strlen(rh->name); |
1269 | switch (rh->record_type) | 1259 | switch (rh->record_type) |
1270 | { | 1260 | { |
1271 | case GNUNET_DNSPARSER_TYPE_A: | 1261 | case GNUNET_DNSPARSER_TYPE_A: |
1272 | af = AF_INET; | 1262 | af = AF_INET; |
1273 | break; | 1263 | break; |
1274 | case GNUNET_DNSPARSER_TYPE_AAAA: | 1264 | |
1275 | af = AF_INET6; | 1265 | case GNUNET_DNSPARSER_TYPE_AAAA: |
1276 | break; | 1266 | af = AF_INET6; |
1277 | default: | 1267 | break; |
1278 | af = AF_UNSPEC; | 1268 | |
1279 | break; | 1269 | default: |
1280 | } | 1270 | af = AF_UNSPEC; |
1281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1271 | break; |
1282 | "Doing standard DNS lookup for `%s'\n", | 1272 | } |
1283 | rh->name); | 1273 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1284 | rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, | 1274 | "Doing standard DNS lookup for `%s'\n", |
1285 | af, | 1275 | rh->name); |
1286 | DNS_LOOKUP_TIMEOUT, | 1276 | rh->std_resolve = GNUNET_RESOLVER_ip_get(rh->name, |
1287 | &handle_dns_result, | 1277 | af, |
1288 | rh); | 1278 | DNS_LOOKUP_TIMEOUT, |
1279 | &handle_dns_result, | ||
1280 | rh); | ||
1289 | } | 1281 | } |
1290 | 1282 | ||
1291 | 1283 | ||
@@ -1297,9 +1289,9 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, | |||
1297 | * @param rd array of records with data to store | 1289 | * @param rd array of records with data to store |
1298 | */ | 1290 | */ |
1299 | static void | 1291 | static void |
1300 | handle_gns_resolution_result (void *cls, | 1292 | handle_gns_resolution_result(void *cls, |
1301 | unsigned int rd_count, | 1293 | unsigned int rd_count, |
1302 | const struct GNUNET_GNSRECORD_Data *rd); | 1294 | const struct GNUNET_GNSRECORD_Data *rd); |
1303 | 1295 | ||
1304 | 1296 | ||
1305 | /** | 1297 | /** |
@@ -1317,9 +1309,9 @@ handle_gns_resolution_result (void *cls, | |||
1317 | * specified target peer; NULL on error | 1309 | * specified target peer; NULL on error |
1318 | */ | 1310 | */ |
1319 | static void | 1311 | static void |
1320 | vpn_allocation_cb (void *cls, | 1312 | vpn_allocation_cb(void *cls, |
1321 | int af, | 1313 | int af, |
1322 | const void *address) | 1314 | const void *address) |
1323 | { | 1315 | { |
1324 | struct VpnContext *vpn_ctx = cls; | 1316 | struct VpnContext *vpn_ctx = cls; |
1325 | struct GNS_ResolverHandle *rh = vpn_ctx->rh; | 1317 | struct GNS_ResolverHandle *rh = vpn_ctx->rh; |
@@ -1328,47 +1320,49 @@ vpn_allocation_cb (void *cls, | |||
1328 | 1320 | ||
1329 | vpn_ctx->vpn_request = NULL; | 1321 | vpn_ctx->vpn_request = NULL; |
1330 | rh->vpn_ctx = NULL; | 1322 | rh->vpn_ctx = NULL; |
1331 | GNUNET_assert (GNUNET_OK == | 1323 | GNUNET_assert(GNUNET_OK == |
1332 | GNUNET_GNSRECORD_records_deserialize ((size_t) vpn_ctx->rd_data_size, | 1324 | GNUNET_GNSRECORD_records_deserialize((size_t)vpn_ctx->rd_data_size, |
1333 | vpn_ctx->rd_data, | 1325 | vpn_ctx->rd_data, |
1334 | vpn_ctx->rd_count, | 1326 | vpn_ctx->rd_count, |
1335 | rd)); | 1327 | rd)); |
1336 | for (i=0;i<vpn_ctx->rd_count;i++) | 1328 | for (i = 0; i < vpn_ctx->rd_count; i++) |
1337 | { | ||
1338 | if (GNUNET_GNSRECORD_TYPE_VPN == rd[i].record_type) | ||
1339 | { | 1329 | { |
1340 | switch (af) | 1330 | if (GNUNET_GNSRECORD_TYPE_VPN == rd[i].record_type) |
1341 | { | 1331 | { |
1342 | case AF_INET: | 1332 | switch (af) |
1343 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_A; | 1333 | { |
1344 | rd[i].data_size = sizeof (struct in_addr); | 1334 | case AF_INET: |
1345 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us; | 1335 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_A; |
1346 | rd[i].flags = 0; | 1336 | rd[i].data_size = sizeof(struct in_addr); |
1347 | rd[i].data = address; | 1337 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute(VPN_TIMEOUT).abs_value_us; |
1348 | break; | 1338 | rd[i].flags = 0; |
1349 | case AF_INET6: | 1339 | rd[i].data = address; |
1350 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA; | 1340 | break; |
1351 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT).abs_value_us; | 1341 | |
1352 | rd[i].flags = 0; | 1342 | case AF_INET6: |
1353 | rd[i].data = address; | 1343 | rd[i].record_type = GNUNET_DNSPARSER_TYPE_AAAA; |
1354 | rd[i].data_size = sizeof (struct in6_addr); | 1344 | rd[i].expiration_time = GNUNET_TIME_relative_to_absolute(VPN_TIMEOUT).abs_value_us; |
1355 | break; | 1345 | rd[i].flags = 0; |
1356 | default: | 1346 | rd[i].data = address; |
1357 | GNUNET_assert (0); | 1347 | rd[i].data_size = sizeof(struct in6_addr); |
1358 | } | 1348 | break; |
1359 | break; | 1349 | |
1350 | default: | ||
1351 | GNUNET_assert(0); | ||
1352 | } | ||
1353 | break; | ||
1354 | } | ||
1360 | } | 1355 | } |
1361 | } | 1356 | GNUNET_assert(i < vpn_ctx->rd_count); |
1362 | GNUNET_assert (i < vpn_ctx->rd_count); | ||
1363 | if (0 == vpn_ctx->rd_count) | 1357 | if (0 == vpn_ctx->rd_count) |
1364 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1358 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1365 | _("VPN returned empty result for `%s'\n"), | 1359 | _("VPN returned empty result for `%s'\n"), |
1366 | rh->name); | 1360 | rh->name); |
1367 | handle_gns_resolution_result (rh, | 1361 | handle_gns_resolution_result(rh, |
1368 | vpn_ctx->rd_count, | 1362 | vpn_ctx->rd_count, |
1369 | rd); | 1363 | rd); |
1370 | GNUNET_free (vpn_ctx->rd_data); | 1364 | GNUNET_free(vpn_ctx->rd_data); |
1371 | GNUNET_free (vpn_ctx); | 1365 | GNUNET_free(vpn_ctx); |
1372 | } | 1366 | } |
1373 | 1367 | ||
1374 | 1368 | ||
@@ -1380,32 +1374,31 @@ vpn_allocation_cb (void *cls, | |||
1380 | * @param ac context for GNS2DNS resolution | 1374 | * @param ac context for GNS2DNS resolution |
1381 | */ | 1375 | */ |
1382 | static void | 1376 | static void |
1383 | continue_with_gns2dns (struct AuthorityChain *ac) | 1377 | continue_with_gns2dns(struct AuthorityChain *ac) |
1384 | { | 1378 | { |
1385 | struct GNS_ResolverHandle *rh = ac->rh; | 1379 | struct GNS_ResolverHandle *rh = ac->rh; |
1386 | 1380 | ||
1387 | if ( (NULL != ac->authority_info.dns_authority.gp_head) && | 1381 | if ((NULL != ac->authority_info.dns_authority.gp_head) && |
1388 | (GNUNET_NO == ac->authority_info.dns_authority.found) ) | 1382 | (GNUNET_NO == ac->authority_info.dns_authority.found)) |
1389 | return; /* more pending and none found yet */ | 1383 | return; /* more pending and none found yet */ |
1390 | if (GNUNET_NO == ac->authority_info.dns_authority.found) | 1384 | if (GNUNET_NO == ac->authority_info.dns_authority.found) |
1391 | { | 1385 | { |
1392 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1386 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1393 | "Failed to resolve DNS server for `%s' in GNS2DNS resolution\n", | 1387 | "Failed to resolve DNS server for `%s' in GNS2DNS resolution\n", |
1394 | ac->authority_info.dns_authority.name); | 1388 | ac->authority_info.dns_authority.name); |
1395 | fail_resolution (rh); | 1389 | fail_resolution(rh); |
1396 | return; | 1390 | return; |
1397 | } | 1391 | } |
1398 | if (GNUNET_NO != ac->authority_info.dns_authority.launched) | 1392 | if (GNUNET_NO != ac->authority_info.dns_authority.launched) |
1399 | return; /* already running, do not launch again! */ | 1393 | return; /* already running, do not launch again! */ |
1400 | /* recurse */ | 1394 | /* recurse */ |
1401 | ac->authority_info.dns_authority.launched = GNUNET_YES; | 1395 | ac->authority_info.dns_authority.launched = GNUNET_YES; |
1402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1396 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1403 | "Will continue resolution using DNS to resolve `%s'\n", | 1397 | "Will continue resolution using DNS to resolve `%s'\n", |
1404 | ac->label); | 1398 | ac->label); |
1405 | GNUNET_assert (NULL == rh->task_id); | 1399 | GNUNET_assert(NULL == rh->task_id); |
1406 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | 1400 | rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, |
1407 | rh); | 1401 | rh); |
1408 | |||
1409 | } | 1402 | } |
1410 | 1403 | ||
1411 | 1404 | ||
@@ -1418,93 +1411,95 @@ continue_with_gns2dns (struct AuthorityChain *ac) | |||
1418 | * @param rd addresses for the DNS resolver (presumably) | 1411 | * @param rd addresses for the DNS resolver (presumably) |
1419 | */ | 1412 | */ |
1420 | static void | 1413 | static void |
1421 | handle_gns2dns_result (void *cls, | 1414 | handle_gns2dns_result(void *cls, |
1422 | unsigned int rd_count, | 1415 | unsigned int rd_count, |
1423 | const struct GNUNET_GNSRECORD_Data *rd) | 1416 | const struct GNUNET_GNSRECORD_Data *rd) |
1424 | { | 1417 | { |
1425 | struct Gns2DnsPending *gp = cls; | 1418 | struct Gns2DnsPending *gp = cls; |
1426 | struct AuthorityChain *ac = gp->ac; | 1419 | struct AuthorityChain *ac = gp->ac; |
1427 | 1420 | ||
1428 | GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head, | 1421 | GNUNET_CONTAINER_DLL_remove(ac->authority_info.dns_authority.gp_head, |
1429 | ac->authority_info.dns_authority.gp_tail, | 1422 | ac->authority_info.dns_authority.gp_tail, |
1430 | gp); | 1423 | gp); |
1431 | /* enable cleanup of 'rh' handle that automatically comes after we return, | 1424 | /* enable cleanup of 'rh' handle that automatically comes after we return, |
1432 | and which expects 'rh' to be in the #rlh_head DLL. */ | 1425 | and which expects 'rh' to be in the #rlh_head DLL. */ |
1433 | if (NULL != gp->rh) | 1426 | if (NULL != gp->rh) |
1434 | { | 1427 | { |
1435 | GNUNET_CONTAINER_DLL_insert (rlh_head, | 1428 | GNUNET_CONTAINER_DLL_insert(rlh_head, |
1436 | rlh_tail, | 1429 | rlh_tail, |
1437 | gp->rh); | 1430 | gp->rh); |
1438 | gp->rh = NULL; | 1431 | gp->rh = NULL; |
1439 | } | 1432 | } |
1440 | GNUNET_free (gp); | 1433 | GNUNET_free(gp); |
1441 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1434 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1442 | "Received %u results for IP address of DNS server for GNS2DNS transition\n", | 1435 | "Received %u results for IP address of DNS server for GNS2DNS transition\n", |
1443 | rd_count); | 1436 | rd_count); |
1444 | /* find suitable A/AAAA record */ | 1437 | /* find suitable A/AAAA record */ |
1445 | for (unsigned int j=0;j<rd_count;j++) | 1438 | for (unsigned int j = 0; j < rd_count; j++) |
1446 | { | ||
1447 | switch (rd[j].record_type) | ||
1448 | { | 1439 | { |
1449 | case GNUNET_DNSPARSER_TYPE_A: | 1440 | switch (rd[j].record_type) |
1450 | { | ||
1451 | struct sockaddr_in v4; | ||
1452 | |||
1453 | if (sizeof (struct in_addr) != rd[j].data_size) | ||
1454 | { | 1441 | { |
1455 | GNUNET_break_op (0); | 1442 | case GNUNET_DNSPARSER_TYPE_A: |
1456 | continue; | 1443 | { |
1457 | } | 1444 | struct sockaddr_in v4; |
1458 | memset (&v4, | 1445 | |
1459 | 0, | 1446 | if (sizeof(struct in_addr) != rd[j].data_size) |
1460 | sizeof (v4)); | 1447 | { |
1461 | v4.sin_family = AF_INET; | 1448 | GNUNET_break_op(0); |
1462 | v4.sin_port = htons (53); | 1449 | continue; |
1450 | } | ||
1451 | memset(&v4, | ||
1452 | 0, | ||
1453 | sizeof(v4)); | ||
1454 | v4.sin_family = AF_INET; | ||
1455 | v4.sin_port = htons(53); | ||
1463 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1456 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1464 | v4.sin_len = (u_char) sizeof (v4); | 1457 | v4.sin_len = (u_char)sizeof(v4); |
1465 | #endif | 1458 | #endif |
1466 | GNUNET_memcpy (&v4.sin_addr, | 1459 | GNUNET_memcpy(&v4.sin_addr, |
1467 | rd[j].data, | 1460 | rd[j].data, |
1468 | sizeof (struct in_addr)); | 1461 | sizeof(struct in_addr)); |
1469 | if (GNUNET_OK == | 1462 | if (GNUNET_OK == |
1470 | GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle, | 1463 | GNUNET_DNSSTUB_add_dns_sa(ac->authority_info.dns_authority.dns_handle, |
1471 | (const struct sockaddr *) &v4)) | 1464 | (const struct sockaddr *)&v4)) |
1472 | ac->authority_info.dns_authority.found = GNUNET_YES; | 1465 | ac->authority_info.dns_authority.found = GNUNET_YES; |
1473 | break; | 1466 | break; |
1474 | } | 1467 | } |
1475 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
1476 | { | ||
1477 | struct sockaddr_in6 v6; | ||
1478 | 1468 | ||
1479 | if (sizeof (struct in6_addr) != rd[j].data_size) | 1469 | case GNUNET_DNSPARSER_TYPE_AAAA: |
1480 | { | 1470 | { |
1481 | GNUNET_break_op (0); | 1471 | struct sockaddr_in6 v6; |
1482 | continue; | 1472 | |
1483 | } | 1473 | if (sizeof(struct in6_addr) != rd[j].data_size) |
1484 | /* FIXME: might want to check if we support IPv6 here, | 1474 | { |
1485 | and otherwise skip this one and hope we find another */ | 1475 | GNUNET_break_op(0); |
1486 | memset (&v6, | 1476 | continue; |
1487 | 0, | 1477 | } |
1488 | sizeof (v6)); | 1478 | /* FIXME: might want to check if we support IPv6 here, |
1489 | v6.sin6_family = AF_INET6; | 1479 | and otherwise skip this one and hope we find another */ |
1490 | v6.sin6_port = htons (53); | 1480 | memset(&v6, |
1481 | 0, | ||
1482 | sizeof(v6)); | ||
1483 | v6.sin6_family = AF_INET6; | ||
1484 | v6.sin6_port = htons(53); | ||
1491 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1485 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1492 | v6.sin6_len = (u_char) sizeof (v6); | 1486 | v6.sin6_len = (u_char)sizeof(v6); |
1493 | #endif | 1487 | #endif |
1494 | GNUNET_memcpy (&v6.sin6_addr, | 1488 | GNUNET_memcpy(&v6.sin6_addr, |
1495 | rd[j].data, | 1489 | rd[j].data, |
1496 | sizeof (struct in6_addr)); | 1490 | sizeof(struct in6_addr)); |
1497 | if (GNUNET_OK == | 1491 | if (GNUNET_OK == |
1498 | GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle, | 1492 | GNUNET_DNSSTUB_add_dns_sa(ac->authority_info.dns_authority.dns_handle, |
1499 | (const struct sockaddr *) &v6)) | 1493 | (const struct sockaddr *)&v6)) |
1500 | ac->authority_info.dns_authority.found = GNUNET_YES; | 1494 | ac->authority_info.dns_authority.found = GNUNET_YES; |
1501 | break; | 1495 | break; |
1502 | } | 1496 | } |
1503 | default: | 1497 | |
1504 | break; | 1498 | default: |
1499 | break; | ||
1500 | } | ||
1505 | } | 1501 | } |
1506 | } | 1502 | continue_with_gns2dns(ac); |
1507 | continue_with_gns2dns (ac); | ||
1508 | } | 1503 | } |
1509 | 1504 | ||
1510 | 1505 | ||
@@ -1516,9 +1511,9 @@ handle_gns2dns_result (void *cls, | |||
1516 | * @param addrlen length of @a addr | 1511 | * @param addrlen length of @a addr |
1517 | */ | 1512 | */ |
1518 | static void | 1513 | static void |
1519 | handle_gns2dns_ip (void *cls, | 1514 | handle_gns2dns_ip(void *cls, |
1520 | const struct sockaddr *addr, | 1515 | const struct sockaddr *addr, |
1521 | socklen_t addrlen) | 1516 | socklen_t addrlen) |
1522 | { | 1517 | { |
1523 | struct Gns2DnsPending *gp = cls; | 1518 | struct Gns2DnsPending *gp = cls; |
1524 | struct AuthorityChain *ac = gp->ac; | 1519 | struct AuthorityChain *ac = gp->ac; |
@@ -1527,42 +1522,44 @@ handle_gns2dns_ip (void *cls, | |||
1527 | struct sockaddr_in6 *v6; | 1522 | struct sockaddr_in6 *v6; |
1528 | 1523 | ||
1529 | if (NULL == addr) | 1524 | if (NULL == addr) |
1530 | { | 1525 | { |
1531 | /* DNS resolution finished */ | 1526 | /* DNS resolution finished */ |
1532 | if (0 == gp->num_results) | 1527 | if (0 == gp->num_results) |
1533 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1528 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1534 | "Failed to use DNS to resolve name of DNS resolver\n"); | 1529 | "Failed to use DNS to resolve name of DNS resolver\n"); |
1535 | GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head, | 1530 | GNUNET_CONTAINER_DLL_remove(ac->authority_info.dns_authority.gp_head, |
1536 | ac->authority_info.dns_authority.gp_tail, | 1531 | ac->authority_info.dns_authority.gp_tail, |
1537 | gp); | 1532 | gp); |
1538 | GNUNET_free (gp); | 1533 | GNUNET_free(gp); |
1539 | continue_with_gns2dns (ac); | 1534 | continue_with_gns2dns(ac); |
1540 | return; | 1535 | return; |
1541 | } | 1536 | } |
1542 | GNUNET_memcpy (&ss, | 1537 | GNUNET_memcpy(&ss, |
1543 | addr, | 1538 | addr, |
1544 | addrlen); | 1539 | addrlen); |
1545 | switch (ss.ss_family) | 1540 | switch (ss.ss_family) |
1546 | { | 1541 | { |
1547 | case AF_INET: | 1542 | case AF_INET: |
1548 | v4 = (struct sockaddr_in *) &ss; | 1543 | v4 = (struct sockaddr_in *)&ss; |
1549 | v4->sin_port = htons (53); | 1544 | v4->sin_port = htons(53); |
1550 | gp->num_results++; | 1545 | gp->num_results++; |
1551 | break; | 1546 | break; |
1552 | case AF_INET6: | 1547 | |
1553 | v6 = (struct sockaddr_in6 *) &ss; | 1548 | case AF_INET6: |
1554 | v6->sin6_port = htons (53); | 1549 | v6 = (struct sockaddr_in6 *)&ss; |
1555 | gp->num_results++; | 1550 | v6->sin6_port = htons(53); |
1556 | break; | 1551 | gp->num_results++; |
1557 | default: | 1552 | break; |
1558 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1553 | |
1559 | "Unsupported AF %d\n", | 1554 | default: |
1560 | ss.ss_family); | 1555 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1561 | return; | 1556 | "Unsupported AF %d\n", |
1562 | } | 1557 | ss.ss_family); |
1558 | return; | ||
1559 | } | ||
1563 | if (GNUNET_OK == | 1560 | if (GNUNET_OK == |
1564 | GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle, | 1561 | GNUNET_DNSSTUB_add_dns_sa(ac->authority_info.dns_authority.dns_handle, |
1565 | (struct sockaddr *) &ss)) | 1562 | (struct sockaddr *)&ss)) |
1566 | ac->authority_info.dns_authority.found = GNUNET_YES; | 1563 | ac->authority_info.dns_authority.found = GNUNET_YES; |
1567 | } | 1564 | } |
1568 | 1565 | ||
@@ -1574,27 +1571,27 @@ handle_gns2dns_ip (void *cls, | |||
1574 | * @param rd record with CNAME to resolve recursively | 1571 | * @param rd record with CNAME to resolve recursively |
1575 | */ | 1572 | */ |
1576 | static void | 1573 | static void |
1577 | recursive_cname_resolution (struct GNS_ResolverHandle *rh, | 1574 | recursive_cname_resolution(struct GNS_ResolverHandle *rh, |
1578 | const struct GNUNET_GNSRECORD_Data *rd) | 1575 | const struct GNUNET_GNSRECORD_Data *rd) |
1579 | { | 1576 | { |
1580 | char *cname; | 1577 | char *cname; |
1581 | size_t off; | 1578 | size_t off; |
1582 | 1579 | ||
1583 | off = 0; | 1580 | off = 0; |
1584 | cname = GNUNET_DNSPARSER_parse_name (rd->data, | 1581 | cname = GNUNET_DNSPARSER_parse_name(rd->data, |
1585 | rd->data_size, | 1582 | rd->data_size, |
1586 | &off); | 1583 | &off); |
1587 | if ( (NULL == cname) || | 1584 | if ((NULL == cname) || |
1588 | (off != rd->data_size) ) | 1585 | (off != rd->data_size)) |
1589 | { | 1586 | { |
1590 | GNUNET_break_op (0); /* record not well-formed */ | 1587 | GNUNET_break_op(0); /* record not well-formed */ |
1591 | GNUNET_free_non_null (cname); | 1588 | GNUNET_free_non_null(cname); |
1592 | fail_resolution (rh); | 1589 | fail_resolution(rh); |
1593 | return; | 1590 | return; |
1594 | } | 1591 | } |
1595 | handle_gns_cname_result (rh, | 1592 | handle_gns_cname_result(rh, |
1596 | cname); | 1593 | cname); |
1597 | GNUNET_free (cname); | 1594 | GNUNET_free(cname); |
1598 | } | 1595 | } |
1599 | 1596 | ||
1600 | 1597 | ||
@@ -1605,34 +1602,34 @@ recursive_cname_resolution (struct GNS_ResolverHandle *rh, | |||
1605 | * @param rd record with PKEY to resolve recursively | 1602 | * @param rd record with PKEY to resolve recursively |
1606 | */ | 1603 | */ |
1607 | static void | 1604 | static void |
1608 | recursive_pkey_resolution (struct GNS_ResolverHandle *rh, | 1605 | recursive_pkey_resolution(struct GNS_ResolverHandle *rh, |
1609 | const struct GNUNET_GNSRECORD_Data *rd) | 1606 | const struct GNUNET_GNSRECORD_Data *rd) |
1610 | { | 1607 | { |
1611 | struct AuthorityChain *ac; | 1608 | struct AuthorityChain *ac; |
1612 | 1609 | ||
1613 | /* delegation to another zone */ | 1610 | /* delegation to another zone */ |
1614 | if (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) != | 1611 | if (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != |
1615 | rd->data_size) | 1612 | rd->data_size) |
1616 | { | 1613 | { |
1617 | GNUNET_break_op (0); | 1614 | GNUNET_break_op(0); |
1618 | fail_resolution (rh); | 1615 | fail_resolution(rh); |
1619 | return; | 1616 | return; |
1620 | } | 1617 | } |
1621 | /* expand authority chain */ | 1618 | /* expand authority chain */ |
1622 | ac = GNUNET_new (struct AuthorityChain); | 1619 | ac = GNUNET_new(struct AuthorityChain); |
1623 | ac->rh = rh; | 1620 | ac->rh = rh; |
1624 | ac->gns_authority = GNUNET_YES; | 1621 | ac->gns_authority = GNUNET_YES; |
1625 | GNUNET_memcpy (&ac->authority_info.gns_authority, | 1622 | GNUNET_memcpy(&ac->authority_info.gns_authority, |
1626 | rd->data, | 1623 | rd->data, |
1627 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 1624 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); |
1628 | ac->label = resolver_lookup_get_next_label (rh); | 1625 | ac->label = resolver_lookup_get_next_label(rh); |
1629 | /* add AC to tail */ | 1626 | /* add AC to tail */ |
1630 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 1627 | GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, |
1631 | rh->ac_tail, | 1628 | rh->ac_tail, |
1632 | ac); | 1629 | ac); |
1633 | /* recurse */ | 1630 | /* recurse */ |
1634 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | 1631 | rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, |
1635 | rh); | 1632 | rh); |
1636 | } | 1633 | } |
1637 | 1634 | ||
1638 | 1635 | ||
@@ -1647,9 +1644,9 @@ recursive_pkey_resolution (struct GNS_ResolverHandle *rh, | |||
1647 | * @return #GNUNET_OK if this worked, #GNUNET_SYSERR if no GNS2DNS records were in @a rd | 1644 | * @return #GNUNET_OK if this worked, #GNUNET_SYSERR if no GNS2DNS records were in @a rd |
1648 | */ | 1645 | */ |
1649 | static int | 1646 | static int |
1650 | recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | 1647 | recursive_gns2dns_resolution(struct GNS_ResolverHandle *rh, |
1651 | unsigned int rd_count, | 1648 | unsigned int rd_count, |
1652 | const struct GNUNET_GNSRECORD_Data *rd) | 1649 | const struct GNUNET_GNSRECORD_Data *rd) |
1653 | { | 1650 | { |
1654 | struct AuthorityChain *ac; | 1651 | struct AuthorityChain *ac; |
1655 | const char *tld; | 1652 | const char *tld; |
@@ -1657,157 +1654,157 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | |||
1657 | 1654 | ||
1658 | ns = NULL; | 1655 | ns = NULL; |
1659 | /* expand authority chain */ | 1656 | /* expand authority chain */ |
1660 | ac = GNUNET_new (struct AuthorityChain); | 1657 | ac = GNUNET_new(struct AuthorityChain); |
1661 | ac->rh = rh; | 1658 | ac->rh = rh; |
1662 | ac->authority_info.dns_authority.dns_handle = GNUNET_DNSSTUB_start (4); | 1659 | ac->authority_info.dns_authority.dns_handle = GNUNET_DNSSTUB_start(4); |
1663 | 1660 | ||
1664 | for (unsigned int i=0;i<rd_count;i++) | 1661 | for (unsigned int i = 0; i < rd_count; i++) |
1665 | { | ||
1666 | char *ip; | ||
1667 | char *n; | ||
1668 | size_t off; | ||
1669 | struct Gns2DnsPending *gp; | ||
1670 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | ||
1671 | struct sockaddr_in v4; | ||
1672 | struct sockaddr_in6 v6; | ||
1673 | |||
1674 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) | ||
1675 | continue; | ||
1676 | off = 0; | ||
1677 | n = GNUNET_DNSPARSER_parse_name (rd[i].data, | ||
1678 | rd[i].data_size, | ||
1679 | &off); | ||
1680 | ip = GNUNET_DNSPARSER_parse_name (rd[i].data, | ||
1681 | rd[i].data_size, | ||
1682 | &off); | ||
1683 | if ( (NULL == n) || | ||
1684 | (NULL == ip) || | ||
1685 | (off != rd[i].data_size) ) | ||
1686 | { | 1662 | { |
1687 | GNUNET_break_op (0); | 1663 | char *ip; |
1688 | GNUNET_free_non_null (n); | 1664 | char *n; |
1689 | GNUNET_free_non_null (ip); | 1665 | size_t off; |
1690 | continue; | 1666 | struct Gns2DnsPending *gp; |
1691 | } | 1667 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; |
1692 | /* resolve 'ip' to determine the IP(s) of the DNS | 1668 | struct sockaddr_in v4; |
1693 | resolver to use for lookup of 'ns' */ | 1669 | struct sockaddr_in6 v6; |
1694 | if (NULL != ns) | 1670 | |
1695 | { | 1671 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) |
1696 | if (0 != strcasecmp (ns, | ||
1697 | n)) | ||
1698 | { | ||
1699 | /* NS values must all be the same for all GNS2DNS records, | ||
1700 | anything else leads to insanity */ | ||
1701 | GNUNET_break_op (0); | ||
1702 | GNUNET_free (n); | ||
1703 | GNUNET_free (ip); | ||
1704 | continue; | 1672 | continue; |
1705 | } | 1673 | off = 0; |
1706 | GNUNET_free (n); | 1674 | n = GNUNET_DNSPARSER_parse_name(rd[i].data, |
1707 | } | 1675 | rd[i].data_size, |
1708 | else | 1676 | &off); |
1709 | { | 1677 | ip = GNUNET_DNSPARSER_parse_name(rd[i].data, |
1710 | ns = n; | 1678 | rd[i].data_size, |
1711 | } | 1679 | &off); |
1680 | if ((NULL == n) || | ||
1681 | (NULL == ip) || | ||
1682 | (off != rd[i].data_size)) | ||
1683 | { | ||
1684 | GNUNET_break_op(0); | ||
1685 | GNUNET_free_non_null(n); | ||
1686 | GNUNET_free_non_null(ip); | ||
1687 | continue; | ||
1688 | } | ||
1689 | /* resolve 'ip' to determine the IP(s) of the DNS | ||
1690 | resolver to use for lookup of 'ns' */ | ||
1691 | if (NULL != ns) | ||
1692 | { | ||
1693 | if (0 != strcasecmp(ns, | ||
1694 | n)) | ||
1695 | { | ||
1696 | /* NS values must all be the same for all GNS2DNS records, | ||
1697 | anything else leads to insanity */ | ||
1698 | GNUNET_break_op(0); | ||
1699 | GNUNET_free(n); | ||
1700 | GNUNET_free(ip); | ||
1701 | continue; | ||
1702 | } | ||
1703 | GNUNET_free(n); | ||
1704 | } | ||
1705 | else | ||
1706 | { | ||
1707 | ns = n; | ||
1708 | } | ||
1712 | 1709 | ||
1713 | /* check if 'ip' is already an IPv4/IPv6 address */ | 1710 | /* check if 'ip' is already an IPv4/IPv6 address */ |
1714 | if ( (1 == inet_pton (AF_INET, | 1711 | if ((1 == inet_pton(AF_INET, |
1715 | ip, | 1712 | ip, |
1716 | &v4)) || | 1713 | &v4)) || |
1717 | (1 == inet_pton (AF_INET6, | 1714 | (1 == inet_pton(AF_INET6, |
1718 | ip, | 1715 | ip, |
1719 | &v6)) ) | 1716 | &v6))) |
1720 | { | 1717 | { |
1721 | GNUNET_break (GNUNET_OK == | 1718 | GNUNET_break(GNUNET_OK == |
1722 | GNUNET_DNSSTUB_add_dns_ip (ac->authority_info.dns_authority.dns_handle, | 1719 | GNUNET_DNSSTUB_add_dns_ip(ac->authority_info.dns_authority.dns_handle, |
1723 | ip)); | 1720 | ip)); |
1724 | ac->authority_info.dns_authority.found = GNUNET_YES; | 1721 | ac->authority_info.dns_authority.found = GNUNET_YES; |
1725 | GNUNET_free (ip); | 1722 | GNUNET_free(ip); |
1726 | continue; | 1723 | continue; |
1727 | } | 1724 | } |
1728 | tld = GNS_get_tld (ip); | 1725 | tld = GNS_get_tld(ip); |
1729 | if (0 != strcmp (tld, | 1726 | if (0 != strcmp(tld, |
1730 | "+")) | 1727 | "+")) |
1731 | { | 1728 | { |
1732 | /* 'ip' is a DNS name */ | 1729 | /* 'ip' is a DNS name */ |
1733 | gp = GNUNET_new (struct Gns2DnsPending); | 1730 | gp = GNUNET_new(struct Gns2DnsPending); |
1731 | gp->ac = ac; | ||
1732 | GNUNET_CONTAINER_DLL_insert(ac->authority_info.dns_authority.gp_head, | ||
1733 | ac->authority_info.dns_authority.gp_tail, | ||
1734 | gp); | ||
1735 | gp->dns_rh = GNUNET_RESOLVER_ip_get(ip, | ||
1736 | AF_UNSPEC, | ||
1737 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1738 | &handle_gns2dns_ip, | ||
1739 | gp); | ||
1740 | GNUNET_free(ip); | ||
1741 | continue; | ||
1742 | } | ||
1743 | /* 'ip' should be a GNS name */ | ||
1744 | gp = GNUNET_new(struct Gns2DnsPending); | ||
1734 | gp->ac = ac; | 1745 | gp->ac = ac; |
1735 | GNUNET_CONTAINER_DLL_insert (ac->authority_info.dns_authority.gp_head, | 1746 | GNUNET_CONTAINER_DLL_insert(ac->authority_info.dns_authority.gp_head, |
1736 | ac->authority_info.dns_authority.gp_tail, | 1747 | ac->authority_info.dns_authority.gp_tail, |
1737 | gp); | 1748 | gp); |
1738 | gp->dns_rh = GNUNET_RESOLVER_ip_get (ip, | 1749 | gp->rh = GNUNET_new(struct GNS_ResolverHandle); |
1739 | AF_UNSPEC, | 1750 | ip = translate_dot_plus(rh, |
1740 | GNUNET_TIME_UNIT_FOREVER_REL, | 1751 | ip); |
1741 | &handle_gns2dns_ip, | 1752 | tld = GNS_get_tld(ip); |
1742 | gp); | 1753 | if (GNUNET_OK != |
1743 | GNUNET_free (ip); | 1754 | GNUNET_GNSRECORD_zkey_to_pkey(tld, |
1744 | continue; | 1755 | &zone)) |
1745 | } | 1756 | { |
1746 | /* 'ip' should be a GNS name */ | 1757 | GNUNET_break_op(0); |
1747 | gp = GNUNET_new (struct Gns2DnsPending); | 1758 | GNUNET_free(ip); |
1748 | gp->ac = ac; | 1759 | continue; |
1749 | GNUNET_CONTAINER_DLL_insert (ac->authority_info.dns_authority.gp_head, | 1760 | } |
1750 | ac->authority_info.dns_authority.gp_tail, | 1761 | gp->rh->authority_zone = zone; |
1751 | gp); | 1762 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1752 | gp->rh = GNUNET_new (struct GNS_ResolverHandle); | 1763 | "Resolving `%s' to determine IP address of DNS server for GNS2DNS transition for `%s'\n", |
1753 | ip = translate_dot_plus (rh, | 1764 | ip, |
1754 | ip); | 1765 | ns); |
1755 | tld = GNS_get_tld (ip); | 1766 | gp->rh->name = ip; |
1756 | if (GNUNET_OK != | 1767 | gp->rh->name_resolution_pos = strlen(ip) - strlen(tld) - 1; |
1757 | GNUNET_GNSRECORD_zkey_to_pkey (tld, | 1768 | gp->rh->proc = &handle_gns2dns_result; |
1758 | &zone)) | 1769 | gp->rh->proc_cls = gp; |
1759 | { | 1770 | gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY; |
1760 | GNUNET_break_op (0); | 1771 | gp->rh->options = GNUNET_GNS_LO_DEFAULT; |
1761 | GNUNET_free (ip); | 1772 | gp->rh->loop_limiter = rh->loop_limiter + 1; |
1762 | continue; | 1773 | gp->rh->task_id |
1763 | } | 1774 | = GNUNET_SCHEDULER_add_now(&start_resolver_lookup, |
1764 | gp->rh->authority_zone = zone; | 1775 | gp->rh); |
1765 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1776 | } /* end 'for all records' */ |
1766 | "Resolving `%s' to determine IP address of DNS server for GNS2DNS transition for `%s'\n", | ||
1767 | ip, | ||
1768 | ns); | ||
1769 | gp->rh->name = ip; | ||
1770 | gp->rh->name_resolution_pos = strlen (ip) - strlen (tld) - 1; | ||
1771 | gp->rh->proc = &handle_gns2dns_result; | ||
1772 | gp->rh->proc_cls = gp; | ||
1773 | gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY; | ||
1774 | gp->rh->options = GNUNET_GNS_LO_DEFAULT; | ||
1775 | gp->rh->loop_limiter = rh->loop_limiter + 1; | ||
1776 | gp->rh->task_id | ||
1777 | = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, | ||
1778 | gp->rh); | ||
1779 | } /* end 'for all records' */ | ||
1780 | 1777 | ||
1781 | if (NULL == ns) | 1778 | if (NULL == ns) |
1782 | { | 1779 | { |
1783 | /* not a single GNS2DNS record found */ | 1780 | /* not a single GNS2DNS record found */ |
1784 | GNUNET_free (ac); | 1781 | GNUNET_free(ac); |
1785 | return GNUNET_SYSERR; | 1782 | return GNUNET_SYSERR; |
1786 | } | 1783 | } |
1787 | GNUNET_assert (strlen (ns) <= GNUNET_DNSPARSER_MAX_NAME_LENGTH); | 1784 | GNUNET_assert(strlen(ns) <= GNUNET_DNSPARSER_MAX_NAME_LENGTH); |
1788 | strcpy (ac->authority_info.dns_authority.name, | 1785 | strcpy(ac->authority_info.dns_authority.name, |
1789 | ns); | 1786 | ns); |
1790 | /* for DNS recursion, the label is the full DNS name, | 1787 | /* for DNS recursion, the label is the full DNS name, |
1791 | created from the remainder of the GNS name and the | 1788 | created from the remainder of the GNS name and the |
1792 | name in the NS record */ | 1789 | name in the NS record */ |
1793 | GNUNET_asprintf (&ac->label, | 1790 | GNUNET_asprintf(&ac->label, |
1794 | "%.*s%s%s", | 1791 | "%.*s%s%s", |
1795 | (int) rh->name_resolution_pos, | 1792 | (int)rh->name_resolution_pos, |
1796 | rh->name, | 1793 | rh->name, |
1797 | (0 != rh->name_resolution_pos) ? "." : "", | 1794 | (0 != rh->name_resolution_pos) ? "." : "", |
1798 | ns); | 1795 | ns); |
1799 | GNUNET_free (ns); | 1796 | GNUNET_free(ns); |
1800 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 1797 | GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, |
1801 | rh->ac_tail, | 1798 | rh->ac_tail, |
1802 | ac); | 1799 | ac); |
1803 | if (strlen (ac->label) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) | 1800 | if (strlen(ac->label) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) |
1804 | { | 1801 | { |
1805 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1802 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1806 | _("GNS lookup resulted in DNS name that is too long (`%s')\n"), | 1803 | _("GNS lookup resulted in DNS name that is too long (`%s')\n"), |
1807 | ac->label); | 1804 | ac->label); |
1808 | return GNUNET_SYSERR; | 1805 | return GNUNET_SYSERR; |
1809 | } | 1806 | } |
1810 | continue_with_gns2dns (ac); | 1807 | continue_with_gns2dns(ac); |
1811 | return GNUNET_OK; | 1808 | return GNUNET_OK; |
1812 | } | 1809 | } |
1813 | 1810 | ||
@@ -1820,9 +1817,9 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | |||
1820 | * @param rd array of records with data to store | 1817 | * @param rd array of records with data to store |
1821 | */ | 1818 | */ |
1822 | static void | 1819 | static void |
1823 | handle_gns_resolution_result (void *cls, | 1820 | handle_gns_resolution_result(void *cls, |
1824 | unsigned int rd_count, | 1821 | unsigned int rd_count, |
1825 | const struct GNUNET_GNSRECORD_Data *rd) | 1822 | const struct GNUNET_GNSRECORD_Data *rd) |
1826 | { | 1823 | { |
1827 | struct GNS_ResolverHandle *rh = cls; | 1824 | struct GNS_ResolverHandle *rh = cls; |
1828 | char *cname; | 1825 | char *cname; |
@@ -1838,431 +1835,442 @@ handle_gns_resolution_result (void *cls, | |||
1838 | struct GNUNET_GNSRECORD_Data rd_new[rd_count]; | 1835 | struct GNUNET_GNSRECORD_Data rd_new[rd_count]; |
1839 | unsigned int rd_off; | 1836 | unsigned int rd_off; |
1840 | 1837 | ||
1841 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1838 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1842 | "Resolution succeeded for `%s' in zone %s, got %u records\n", | 1839 | "Resolution succeeded for `%s' in zone %s, got %u records\n", |
1843 | rh->ac_tail->label, | 1840 | rh->ac_tail->label, |
1844 | GNUNET_GNSRECORD_z2s (&rh->ac_tail->authority_info.gns_authority), | 1841 | GNUNET_GNSRECORD_z2s(&rh->ac_tail->authority_info.gns_authority), |
1845 | rd_count); | 1842 | rd_count); |
1846 | if (0 == rd_count) | 1843 | if (0 == rd_count) |
1847 | { | ||
1848 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1849 | _("GNS lookup failed (zero records found for `%s')\n"), | ||
1850 | rh->name); | ||
1851 | fail_resolution (rh); | ||
1852 | return; | ||
1853 | } | ||
1854 | |||
1855 | if (0 == rh->name_resolution_pos) | ||
1856 | { | ||
1857 | /* top-level match, are we done yet? */ | ||
1858 | if ( (rd_count > 0) && | ||
1859 | (GNUNET_DNSPARSER_TYPE_CNAME == rd[0].record_type) && | ||
1860 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) ) | ||
1861 | { | 1844 | { |
1862 | off = 0; | 1845 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1863 | cname = GNUNET_DNSPARSER_parse_name (rd[0].data, | 1846 | _("GNS lookup failed (zero records found for `%s')\n"), |
1864 | rd[0].data_size, | 1847 | rh->name); |
1865 | &off); | 1848 | fail_resolution(rh); |
1866 | if ( (NULL == cname) || | ||
1867 | (off != rd[0].data_size) ) | ||
1868 | { | ||
1869 | GNUNET_break_op (0); | ||
1870 | GNUNET_free_non_null (cname); | ||
1871 | fail_resolution (rh); | ||
1872 | return; | ||
1873 | } | ||
1874 | handle_gns_cname_result (rh, | ||
1875 | cname); | ||
1876 | GNUNET_free (cname); | ||
1877 | return; | 1849 | return; |
1878 | } | 1850 | } |
1879 | /* If A/AAAA was requested, but we got a VPN | 1851 | |
1880 | record, we convert it to A/AAAA using GNUnet VPN */ | 1852 | if (0 == rh->name_resolution_pos) |
1881 | if ( (GNUNET_DNSPARSER_TYPE_A == rh->record_type) || | ||
1882 | (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type) ) | ||
1883 | { | 1853 | { |
1884 | for (unsigned int i=0;i<rd_count;i++) | 1854 | /* top-level match, are we done yet? */ |
1885 | { | 1855 | if ((rd_count > 0) && |
1886 | switch (rd[i].record_type) | 1856 | (GNUNET_DNSPARSER_TYPE_CNAME == rd[0].record_type) && |
1887 | { | 1857 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type)) |
1888 | case GNUNET_GNSRECORD_TYPE_VPN: | 1858 | { |
1889 | { | 1859 | off = 0; |
1890 | af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : AF_INET6; | 1860 | cname = GNUNET_DNSPARSER_parse_name(rd[0].data, |
1891 | if (sizeof (struct GNUNET_TUN_GnsVpnRecord) > | 1861 | rd[0].data_size, |
1892 | rd[i].data_size) | 1862 | &off); |
1893 | { | 1863 | if ((NULL == cname) || |
1894 | GNUNET_break_op (0); | 1864 | (off != rd[0].data_size)) |
1895 | fail_resolution (rh); | ||
1896 | return; | ||
1897 | } | ||
1898 | vpn = (const struct GNUNET_TUN_GnsVpnRecord *) rd[i].data; | ||
1899 | vname = (const char *) &vpn[1]; | ||
1900 | if ('\0' != vname[rd[i].data_size - 1 - sizeof (struct GNUNET_TUN_GnsVpnRecord)]) | ||
1901 | { | ||
1902 | GNUNET_break_op (0); | ||
1903 | fail_resolution (rh); | ||
1904 | return; | ||
1905 | } | ||
1906 | GNUNET_TUN_service_name_to_hash (vname, | ||
1907 | &vhash); | ||
1908 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1909 | "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n", | ||
1910 | GNUNET_i2s (&vpn->peer), | ||
1911 | vname, | ||
1912 | (int) af, | ||
1913 | (int) ntohs (vpn->proto)); | ||
1914 | vpn_ctx = GNUNET_new (struct VpnContext); | ||
1915 | rh->vpn_ctx = vpn_ctx; | ||
1916 | vpn_ctx->rh = rh; | ||
1917 | vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
1918 | rd); | ||
1919 | if (vpn_ctx->rd_data_size < 0) | ||
1920 | { | 1865 | { |
1921 | GNUNET_break_op (0); | 1866 | GNUNET_break_op(0); |
1922 | GNUNET_free (vpn_ctx); | 1867 | GNUNET_free_non_null(cname); |
1923 | fail_resolution (rh); | 1868 | fail_resolution(rh); |
1924 | return; | ||
1925 | } | ||
1926 | vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size); | ||
1927 | vpn_ctx->rd_count = rd_count; | ||
1928 | GNUNET_assert (vpn_ctx->rd_data_size == | ||
1929 | GNUNET_GNSRECORD_records_serialize (rd_count, | ||
1930 | rd, | ||
1931 | (size_t) vpn_ctx->rd_data_size, | ||
1932 | vpn_ctx->rd_data)); | ||
1933 | vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle, | ||
1934 | af, | ||
1935 | ntohs (vpn->proto), | ||
1936 | &vpn->peer, | ||
1937 | &vhash, | ||
1938 | GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT), | ||
1939 | &vpn_allocation_cb, | ||
1940 | vpn_ctx); | ||
1941 | return; | ||
1942 | } | ||
1943 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | ||
1944 | { | ||
1945 | /* delegation to DNS */ | ||
1946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1947 | "Found GNS2DNS record, delegating to DNS!\n"); | ||
1948 | if (GNUNET_OK == | ||
1949 | recursive_gns2dns_resolution (rh, | ||
1950 | rd_count, | ||
1951 | rd)) | ||
1952 | return; | 1869 | return; |
1953 | else | 1870 | } |
1954 | goto fail; | 1871 | handle_gns_cname_result(rh, |
1955 | } | 1872 | cname); |
1956 | default: | 1873 | GNUNET_free(cname); |
1957 | break; | 1874 | return; |
1958 | } /* end: switch */ | ||
1959 | } /* end: for rd */ | ||
1960 | } /* end: name_resolution_pos */ | ||
1961 | /* convert relative names in record values to absolute names, | ||
1962 | using 'scratch' array for memory allocations */ | ||
1963 | scratch_off = 0; | ||
1964 | rd_off = 0; | ||
1965 | for (unsigned int i=0;i<rd_count;i++) | ||
1966 | { | ||
1967 | GNUNET_assert (rd_off <= i); | ||
1968 | if ( (0 != rh->protocol) && | ||
1969 | (0 != rh->service) && | ||
1970 | (GNUNET_GNSRECORD_TYPE_BOX != rd[i].record_type) ) | ||
1971 | continue; /* we _only_ care about boxed records */ | ||
1972 | |||
1973 | GNUNET_assert (rd_off < rd_count); | ||
1974 | rd_new[rd_off] = rd[i]; | ||
1975 | /* Check if the embedded name(s) end in "+", and if so, | ||
1976 | replace the "+" with the zone at "ac_tail", changing the name | ||
1977 | to a ".ZONEKEY". The name is allocated on the 'scratch' array, | ||
1978 | so we can free it afterwards. */ | ||
1979 | switch (rd[i].record_type) | ||
1980 | { | ||
1981 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
1982 | { | ||
1983 | char *cname; | ||
1984 | |||
1985 | off = 0; | ||
1986 | cname = GNUNET_DNSPARSER_parse_name (rd[i].data, | ||
1987 | rd[i].data_size, | ||
1988 | &off); | ||
1989 | if ( (NULL == cname) || | ||
1990 | (off != rd[i].data_size) ) | ||
1991 | { | ||
1992 | GNUNET_break_op (0); /* record not well-formed */ | ||
1993 | } | ||
1994 | else | ||
1995 | { | ||
1996 | cname = translate_dot_plus (rh, cname); | ||
1997 | GNUNET_break (NULL != cname); | ||
1998 | scratch_start = scratch_off; | ||
1999 | if (GNUNET_OK != | ||
2000 | GNUNET_DNSPARSER_builder_add_name (scratch, | ||
2001 | sizeof (scratch), | ||
2002 | &scratch_off, | ||
2003 | cname)) | ||
2004 | { | ||
2005 | GNUNET_break (0); | ||
2006 | } | ||
2007 | else | ||
2008 | { | ||
2009 | GNUNET_assert (rd_off < rd_count); | ||
2010 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2011 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2012 | rd_off++; | ||
2013 | } | ||
2014 | } | ||
2015 | GNUNET_free_non_null (cname); | ||
2016 | } | ||
2017 | break; | ||
2018 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
2019 | { | ||
2020 | struct GNUNET_DNSPARSER_SoaRecord *soa; | ||
2021 | |||
2022 | off = 0; | ||
2023 | soa = GNUNET_DNSPARSER_parse_soa (rd[i].data, | ||
2024 | rd[i].data_size, | ||
2025 | &off); | ||
2026 | if ( (NULL == soa) || | ||
2027 | (off != rd[i].data_size) ) | ||
2028 | { | ||
2029 | GNUNET_break_op (0); /* record not well-formed */ | ||
2030 | } | ||
2031 | else | ||
2032 | { | ||
2033 | soa->mname = translate_dot_plus (rh, soa->mname); | ||
2034 | soa->rname = translate_dot_plus (rh, soa->rname); | ||
2035 | scratch_start = scratch_off; | ||
2036 | if (GNUNET_OK != | ||
2037 | GNUNET_DNSPARSER_builder_add_soa (scratch, | ||
2038 | sizeof (scratch), | ||
2039 | &scratch_off, | ||
2040 | soa)) | ||
2041 | { | ||
2042 | GNUNET_break (0); | ||
2043 | } | ||
2044 | else | ||
2045 | { | ||
2046 | GNUNET_assert (rd_off < rd_count); | ||
2047 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2048 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2049 | rd_off++; | ||
2050 | } | ||
2051 | } | ||
2052 | if (NULL != soa) | ||
2053 | GNUNET_DNSPARSER_free_soa (soa); | ||
2054 | } | ||
2055 | break; | ||
2056 | case GNUNET_DNSPARSER_TYPE_MX: | ||
2057 | { | ||
2058 | struct GNUNET_DNSPARSER_MxRecord *mx; | ||
2059 | |||
2060 | off = 0; | ||
2061 | mx = GNUNET_DNSPARSER_parse_mx (rd[i].data, | ||
2062 | rd[i].data_size, | ||
2063 | &off); | ||
2064 | if ( (NULL == mx) || | ||
2065 | (off != rd[i].data_size) ) | ||
2066 | { | ||
2067 | GNUNET_break_op (0); /* record not well-formed */ | ||
2068 | } | ||
2069 | else | ||
2070 | { | ||
2071 | mx->mxhost = translate_dot_plus (rh, mx->mxhost); | ||
2072 | scratch_start = scratch_off; | ||
2073 | if (GNUNET_OK != | ||
2074 | GNUNET_DNSPARSER_builder_add_mx (scratch, | ||
2075 | sizeof (scratch), | ||
2076 | &scratch_off, | ||
2077 | mx)) | ||
2078 | { | ||
2079 | GNUNET_break (0); | ||
2080 | } | ||
2081 | else | ||
2082 | { | ||
2083 | GNUNET_assert (rd_off < rd_count); | ||
2084 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2085 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2086 | rd_off++; | ||
2087 | } | ||
2088 | } | ||
2089 | if (NULL != mx) | ||
2090 | GNUNET_DNSPARSER_free_mx (mx); | ||
2091 | } | ||
2092 | break; | ||
2093 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
2094 | { | ||
2095 | struct GNUNET_DNSPARSER_SrvRecord *srv; | ||
2096 | |||
2097 | off = 0; | ||
2098 | srv = GNUNET_DNSPARSER_parse_srv (rd[i].data, | ||
2099 | rd[i].data_size, | ||
2100 | &off); | ||
2101 | if ( (NULL == srv) || | ||
2102 | (off != rd[i].data_size) ) | ||
2103 | { | ||
2104 | GNUNET_break_op (0); /* record not well-formed */ | ||
2105 | } | ||
2106 | else | ||
2107 | { | ||
2108 | srv->target = translate_dot_plus (rh, srv->target); | ||
2109 | scratch_start = scratch_off; | ||
2110 | if (GNUNET_OK != | ||
2111 | GNUNET_DNSPARSER_builder_add_srv (scratch, | ||
2112 | sizeof (scratch), | ||
2113 | &scratch_off, | ||
2114 | srv)) | ||
2115 | { | ||
2116 | GNUNET_break (0); | ||
2117 | } | ||
2118 | else | ||
2119 | { | ||
2120 | GNUNET_assert (rd_off < rd_count); | ||
2121 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2122 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2123 | rd_off++; | ||
2124 | } | ||
2125 | } | ||
2126 | if (NULL != srv) | ||
2127 | GNUNET_DNSPARSER_free_srv (srv); | ||
2128 | } | ||
2129 | break; | ||
2130 | |||
2131 | case GNUNET_GNSRECORD_TYPE_NICK: | ||
2132 | { | ||
2133 | const char *nick; | ||
2134 | |||
2135 | nick = rd[i].data; | ||
2136 | if ((rd[i].data_size > 0) && | ||
2137 | (nick[rd[i].data_size -1] != '\0')) | ||
2138 | { | ||
2139 | GNUNET_break_op (0); | ||
2140 | break; | ||
2141 | } | ||
2142 | break; | ||
2143 | } | ||
2144 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
2145 | { | ||
2146 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
2147 | |||
2148 | if (rd[i].data_size != sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)) | ||
2149 | { | ||
2150 | GNUNET_break_op (0); | ||
2151 | break; | ||
2152 | } | ||
2153 | GNUNET_memcpy (&pub, | ||
2154 | rd[i].data, | ||
2155 | rd[i].data_size); | ||
2156 | rd_off++; | ||
2157 | if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type) | ||
2158 | { | ||
2159 | /* try to resolve "@" */ | ||
2160 | struct AuthorityChain *ac; | ||
2161 | |||
2162 | ac = GNUNET_new (struct AuthorityChain); | ||
2163 | ac->rh = rh; | ||
2164 | ac->gns_authority = GNUNET_YES; | ||
2165 | ac->authority_info.gns_authority = pub; | ||
2166 | ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); | ||
2167 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | ||
2168 | rh->ac_tail, | ||
2169 | ac); | ||
2170 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | ||
2171 | rh); | ||
2172 | return; | ||
2173 | } | ||
2174 | } | 1875 | } |
2175 | break; | 1876 | /* If A/AAAA was requested, but we got a VPN |
2176 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | 1877 | record, we convert it to A/AAAA using GNUnet VPN */ |
1878 | if ((GNUNET_DNSPARSER_TYPE_A == rh->record_type) || | ||
1879 | (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type)) | ||
2177 | { | 1880 | { |
2178 | /* delegation to DNS */ | 1881 | for (unsigned int i = 0; i < rd_count; i++) |
2179 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rh->record_type) | 1882 | { |
2180 | { | 1883 | switch (rd[i].record_type) |
2181 | rd_off++; | 1884 | { |
2182 | break; /* do not follow to DNS, we wanted the GNS2DNS record! */ | 1885 | case GNUNET_GNSRECORD_TYPE_VPN: |
2183 | } | 1886 | { |
2184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1887 | af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : AF_INET6; |
2185 | "Found GNS2DNS record, delegating to DNS!\n"); | 1888 | if (sizeof(struct GNUNET_TUN_GnsVpnRecord) > |
2186 | if (GNUNET_OK == | 1889 | rd[i].data_size) |
2187 | recursive_gns2dns_resolution (rh, | 1890 | { |
2188 | rd_count, | 1891 | GNUNET_break_op(0); |
2189 | rd)) | 1892 | fail_resolution(rh); |
2190 | return; | 1893 | return; |
2191 | else | 1894 | } |
2192 | goto fail; | 1895 | vpn = (const struct GNUNET_TUN_GnsVpnRecord *)rd[i].data; |
2193 | } | 1896 | vname = (const char *)&vpn[1]; |
2194 | case GNUNET_GNSRECORD_TYPE_BOX: | 1897 | if ('\0' != vname[rd[i].data_size - 1 - sizeof(struct GNUNET_TUN_GnsVpnRecord)]) |
1898 | { | ||
1899 | GNUNET_break_op(0); | ||
1900 | fail_resolution(rh); | ||
1901 | return; | ||
1902 | } | ||
1903 | GNUNET_TUN_service_name_to_hash(vname, | ||
1904 | &vhash); | ||
1905 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1906 | "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n", | ||
1907 | GNUNET_i2s(&vpn->peer), | ||
1908 | vname, | ||
1909 | (int)af, | ||
1910 | (int)ntohs(vpn->proto)); | ||
1911 | vpn_ctx = GNUNET_new(struct VpnContext); | ||
1912 | rh->vpn_ctx = vpn_ctx; | ||
1913 | vpn_ctx->rh = rh; | ||
1914 | vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size(rd_count, | ||
1915 | rd); | ||
1916 | if (vpn_ctx->rd_data_size < 0) | ||
1917 | { | ||
1918 | GNUNET_break_op(0); | ||
1919 | GNUNET_free(vpn_ctx); | ||
1920 | fail_resolution(rh); | ||
1921 | return; | ||
1922 | } | ||
1923 | vpn_ctx->rd_data = GNUNET_malloc((size_t)vpn_ctx->rd_data_size); | ||
1924 | vpn_ctx->rd_count = rd_count; | ||
1925 | GNUNET_assert(vpn_ctx->rd_data_size == | ||
1926 | GNUNET_GNSRECORD_records_serialize(rd_count, | ||
1927 | rd, | ||
1928 | (size_t)vpn_ctx->rd_data_size, | ||
1929 | vpn_ctx->rd_data)); | ||
1930 | vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer(vpn_handle, | ||
1931 | af, | ||
1932 | ntohs(vpn->proto), | ||
1933 | &vpn->peer, | ||
1934 | &vhash, | ||
1935 | GNUNET_TIME_relative_to_absolute(VPN_TIMEOUT), | ||
1936 | &vpn_allocation_cb, | ||
1937 | vpn_ctx); | ||
1938 | return; | ||
1939 | } | ||
1940 | |||
1941 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | ||
1942 | { | ||
1943 | /* delegation to DNS */ | ||
1944 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1945 | "Found GNS2DNS record, delegating to DNS!\n"); | ||
1946 | if (GNUNET_OK == | ||
1947 | recursive_gns2dns_resolution(rh, | ||
1948 | rd_count, | ||
1949 | rd)) | ||
1950 | return; | ||
1951 | else | ||
1952 | goto fail; | ||
1953 | } | ||
1954 | |||
1955 | default: | ||
1956 | break; | ||
1957 | } /* end: switch */ | ||
1958 | } /* end: for rd */ | ||
1959 | } /* end: name_resolution_pos */ | ||
1960 | /* convert relative names in record values to absolute names, | ||
1961 | using 'scratch' array for memory allocations */ | ||
1962 | scratch_off = 0; | ||
1963 | rd_off = 0; | ||
1964 | for (unsigned int i = 0; i < rd_count; i++) | ||
2195 | { | 1965 | { |
2196 | /* unbox SRV/TLSA records if a specific one was requested */ | 1966 | GNUNET_assert(rd_off <= i); |
2197 | if ( (0 != rh->protocol) && | 1967 | if ((0 != rh->protocol) && |
2198 | (0 != rh->service) && | 1968 | (0 != rh->service) && |
2199 | (rd[i].data_size >= sizeof (struct GNUNET_GNSRECORD_BoxRecord)) ) | 1969 | (GNUNET_GNSRECORD_TYPE_BOX != rd[i].record_type)) |
2200 | { | 1970 | continue; /* we _only_ care about boxed records */ |
2201 | const struct GNUNET_GNSRECORD_BoxRecord *box; | 1971 | |
1972 | GNUNET_assert(rd_off < rd_count); | ||
1973 | rd_new[rd_off] = rd[i]; | ||
1974 | /* Check if the embedded name(s) end in "+", and if so, | ||
1975 | replace the "+" with the zone at "ac_tail", changing the name | ||
1976 | to a ".ZONEKEY". The name is allocated on the 'scratch' array, | ||
1977 | so we can free it afterwards. */ | ||
1978 | switch (rd[i].record_type) | ||
1979 | { | ||
1980 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
1981 | { | ||
1982 | char *cname; | ||
1983 | |||
1984 | off = 0; | ||
1985 | cname = GNUNET_DNSPARSER_parse_name(rd[i].data, | ||
1986 | rd[i].data_size, | ||
1987 | &off); | ||
1988 | if ((NULL == cname) || | ||
1989 | (off != rd[i].data_size)) | ||
1990 | { | ||
1991 | GNUNET_break_op(0); /* record not well-formed */ | ||
1992 | } | ||
1993 | else | ||
1994 | { | ||
1995 | cname = translate_dot_plus(rh, cname); | ||
1996 | GNUNET_break(NULL != cname); | ||
1997 | scratch_start = scratch_off; | ||
1998 | if (GNUNET_OK != | ||
1999 | GNUNET_DNSPARSER_builder_add_name(scratch, | ||
2000 | sizeof(scratch), | ||
2001 | &scratch_off, | ||
2002 | cname)) | ||
2003 | { | ||
2004 | GNUNET_break(0); | ||
2005 | } | ||
2006 | else | ||
2007 | { | ||
2008 | GNUNET_assert(rd_off < rd_count); | ||
2009 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2010 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2011 | rd_off++; | ||
2012 | } | ||
2013 | } | ||
2014 | GNUNET_free_non_null(cname); | ||
2015 | } | ||
2016 | break; | ||
2017 | |||
2018 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
2019 | { | ||
2020 | struct GNUNET_DNSPARSER_SoaRecord *soa; | ||
2021 | |||
2022 | off = 0; | ||
2023 | soa = GNUNET_DNSPARSER_parse_soa(rd[i].data, | ||
2024 | rd[i].data_size, | ||
2025 | &off); | ||
2026 | if ((NULL == soa) || | ||
2027 | (off != rd[i].data_size)) | ||
2028 | { | ||
2029 | GNUNET_break_op(0); /* record not well-formed */ | ||
2030 | } | ||
2031 | else | ||
2032 | { | ||
2033 | soa->mname = translate_dot_plus(rh, soa->mname); | ||
2034 | soa->rname = translate_dot_plus(rh, soa->rname); | ||
2035 | scratch_start = scratch_off; | ||
2036 | if (GNUNET_OK != | ||
2037 | GNUNET_DNSPARSER_builder_add_soa(scratch, | ||
2038 | sizeof(scratch), | ||
2039 | &scratch_off, | ||
2040 | soa)) | ||
2041 | { | ||
2042 | GNUNET_break(0); | ||
2043 | } | ||
2044 | else | ||
2045 | { | ||
2046 | GNUNET_assert(rd_off < rd_count); | ||
2047 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2048 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2049 | rd_off++; | ||
2050 | } | ||
2051 | } | ||
2052 | if (NULL != soa) | ||
2053 | GNUNET_DNSPARSER_free_soa(soa); | ||
2054 | } | ||
2055 | break; | ||
2056 | |||
2057 | case GNUNET_DNSPARSER_TYPE_MX: | ||
2058 | { | ||
2059 | struct GNUNET_DNSPARSER_MxRecord *mx; | ||
2060 | |||
2061 | off = 0; | ||
2062 | mx = GNUNET_DNSPARSER_parse_mx(rd[i].data, | ||
2063 | rd[i].data_size, | ||
2064 | &off); | ||
2065 | if ((NULL == mx) || | ||
2066 | (off != rd[i].data_size)) | ||
2067 | { | ||
2068 | GNUNET_break_op(0); /* record not well-formed */ | ||
2069 | } | ||
2070 | else | ||
2071 | { | ||
2072 | mx->mxhost = translate_dot_plus(rh, mx->mxhost); | ||
2073 | scratch_start = scratch_off; | ||
2074 | if (GNUNET_OK != | ||
2075 | GNUNET_DNSPARSER_builder_add_mx(scratch, | ||
2076 | sizeof(scratch), | ||
2077 | &scratch_off, | ||
2078 | mx)) | ||
2079 | { | ||
2080 | GNUNET_break(0); | ||
2081 | } | ||
2082 | else | ||
2083 | { | ||
2084 | GNUNET_assert(rd_off < rd_count); | ||
2085 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2086 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2087 | rd_off++; | ||
2088 | } | ||
2089 | } | ||
2090 | if (NULL != mx) | ||
2091 | GNUNET_DNSPARSER_free_mx(mx); | ||
2092 | } | ||
2093 | break; | ||
2094 | |||
2095 | case GNUNET_DNSPARSER_TYPE_SRV: | ||
2096 | { | ||
2097 | struct GNUNET_DNSPARSER_SrvRecord *srv; | ||
2098 | |||
2099 | off = 0; | ||
2100 | srv = GNUNET_DNSPARSER_parse_srv(rd[i].data, | ||
2101 | rd[i].data_size, | ||
2102 | &off); | ||
2103 | if ((NULL == srv) || | ||
2104 | (off != rd[i].data_size)) | ||
2105 | { | ||
2106 | GNUNET_break_op(0); /* record not well-formed */ | ||
2107 | } | ||
2108 | else | ||
2109 | { | ||
2110 | srv->target = translate_dot_plus(rh, srv->target); | ||
2111 | scratch_start = scratch_off; | ||
2112 | if (GNUNET_OK != | ||
2113 | GNUNET_DNSPARSER_builder_add_srv(scratch, | ||
2114 | sizeof(scratch), | ||
2115 | &scratch_off, | ||
2116 | srv)) | ||
2117 | { | ||
2118 | GNUNET_break(0); | ||
2119 | } | ||
2120 | else | ||
2121 | { | ||
2122 | GNUNET_assert(rd_off < rd_count); | ||
2123 | rd_new[rd_off].data = &scratch[scratch_start]; | ||
2124 | rd_new[rd_off].data_size = scratch_off - scratch_start; | ||
2125 | rd_off++; | ||
2126 | } | ||
2127 | } | ||
2128 | if (NULL != srv) | ||
2129 | GNUNET_DNSPARSER_free_srv(srv); | ||
2130 | } | ||
2131 | break; | ||
2132 | |||
2133 | case GNUNET_GNSRECORD_TYPE_NICK: | ||
2134 | { | ||
2135 | const char *nick; | ||
2136 | |||
2137 | nick = rd[i].data; | ||
2138 | if ((rd[i].data_size > 0) && | ||
2139 | (nick[rd[i].data_size - 1] != '\0')) | ||
2140 | { | ||
2141 | GNUNET_break_op(0); | ||
2142 | break; | ||
2143 | } | ||
2144 | break; | ||
2145 | } | ||
2202 | 2146 | ||
2203 | box = rd[i].data; | 2147 | case GNUNET_GNSRECORD_TYPE_PKEY: |
2204 | if ( (ntohs (box->protocol) == rh->protocol) && | ||
2205 | (ntohs (box->service) == rh->service) ) | ||
2206 | { | 2148 | { |
2207 | /* Box matches, unbox! */ | 2149 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
2208 | GNUNET_assert (rd_off < rd_count); | 2150 | |
2209 | rd_new[rd_off].record_type = ntohl (box->record_type); | 2151 | if (rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) |
2210 | rd_new[rd_off].data_size -= sizeof (struct GNUNET_GNSRECORD_BoxRecord); | 2152 | { |
2211 | rd_new[rd_off].data = &box[1]; | 2153 | GNUNET_break_op(0); |
2154 | break; | ||
2155 | } | ||
2156 | GNUNET_memcpy(&pub, | ||
2157 | rd[i].data, | ||
2158 | rd[i].data_size); | ||
2212 | rd_off++; | 2159 | rd_off++; |
2160 | if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type) | ||
2161 | { | ||
2162 | /* try to resolve "@" */ | ||
2163 | struct AuthorityChain *ac; | ||
2164 | |||
2165 | ac = GNUNET_new(struct AuthorityChain); | ||
2166 | ac->rh = rh; | ||
2167 | ac->gns_authority = GNUNET_YES; | ||
2168 | ac->authority_info.gns_authority = pub; | ||
2169 | ac->label = GNUNET_strdup(GNUNET_GNS_EMPTY_LABEL_AT); | ||
2170 | GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, | ||
2171 | rh->ac_tail, | ||
2172 | ac); | ||
2173 | rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, | ||
2174 | rh); | ||
2175 | return; | ||
2176 | } | ||
2213 | } | 2177 | } |
2214 | } | 2178 | break; |
2215 | else | 2179 | |
2216 | { | 2180 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: |
2217 | /* no specific protocol/service specified, preserve all BOX | 2181 | { |
2218 | records (for modern, GNS-enabled applications) */ | 2182 | /* delegation to DNS */ |
2219 | rd_off++; | 2183 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rh->record_type) |
2220 | } | 2184 | { |
2221 | break; | 2185 | rd_off++; |
2222 | } | 2186 | break; /* do not follow to DNS, we wanted the GNS2DNS record! */ |
2223 | default: | 2187 | } |
2224 | rd_off++; | 2188 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2225 | break; | 2189 | "Found GNS2DNS record, delegating to DNS!\n"); |
2226 | } /* end: switch */ | 2190 | if (GNUNET_OK == |
2227 | } /* end: for rd_count */ | 2191 | recursive_gns2dns_resolution(rh, |
2228 | 2192 | rd_count, | |
2229 | /* yes, we are done, return result */ | 2193 | rd)) |
2230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2194 | return; |
2231 | "Returning GNS response for `%s' with %u answers\n", | 2195 | else |
2232 | rh->ac_tail->label, | 2196 | goto fail; |
2233 | rd_off); | 2197 | } |
2234 | rh->proc (rh->proc_cls, | 2198 | |
2235 | rd_off, | 2199 | case GNUNET_GNSRECORD_TYPE_BOX: |
2236 | rd_new); | 2200 | { |
2237 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 2201 | /* unbox SRV/TLSA records if a specific one was requested */ |
2238 | rh); | 2202 | if ((0 != rh->protocol) && |
2239 | return; | 2203 | (0 != rh->service) && |
2240 | } | 2204 | (rd[i].data_size >= sizeof(struct GNUNET_GNSRECORD_BoxRecord))) |
2205 | { | ||
2206 | const struct GNUNET_GNSRECORD_BoxRecord *box; | ||
2207 | |||
2208 | box = rd[i].data; | ||
2209 | if ((ntohs(box->protocol) == rh->protocol) && | ||
2210 | (ntohs(box->service) == rh->service)) | ||
2211 | { | ||
2212 | /* Box matches, unbox! */ | ||
2213 | GNUNET_assert(rd_off < rd_count); | ||
2214 | rd_new[rd_off].record_type = ntohl(box->record_type); | ||
2215 | rd_new[rd_off].data_size -= sizeof(struct GNUNET_GNSRECORD_BoxRecord); | ||
2216 | rd_new[rd_off].data = &box[1]; | ||
2217 | rd_off++; | ||
2218 | } | ||
2219 | } | ||
2220 | else | ||
2221 | { | ||
2222 | /* no specific protocol/service specified, preserve all BOX | ||
2223 | records (for modern, GNS-enabled applications) */ | ||
2224 | rd_off++; | ||
2225 | } | ||
2226 | break; | ||
2227 | } | ||
2228 | |||
2229 | default: | ||
2230 | rd_off++; | ||
2231 | break; | ||
2232 | } /* end: switch */ | ||
2233 | } /* end: for rd_count */ | ||
2234 | |||
2235 | /* yes, we are done, return result */ | ||
2236 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2237 | "Returning GNS response for `%s' with %u answers\n", | ||
2238 | rh->ac_tail->label, | ||
2239 | rd_off); | ||
2240 | rh->proc(rh->proc_cls, | ||
2241 | rd_off, | ||
2242 | rd_new); | ||
2243 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, | ||
2244 | rh); | ||
2245 | return; | ||
2246 | } | ||
2241 | 2247 | ||
2242 | switch (rd[0].record_type) | 2248 | switch (rd[0].record_type) |
2243 | { | 2249 | { |
2244 | case GNUNET_DNSPARSER_TYPE_CNAME: | 2250 | case GNUNET_DNSPARSER_TYPE_CNAME: |
2245 | GNUNET_break_op (1 == rd_count); /* CNAME should be unique */ | 2251 | GNUNET_break_op(1 == rd_count); /* CNAME should be unique */ |
2246 | recursive_cname_resolution (rh, | 2252 | recursive_cname_resolution(rh, |
2253 | &rd[0]); | ||
2254 | return; | ||
2255 | |||
2256 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
2257 | GNUNET_break_op(1 == rd_count); /* PKEY should be unique */ | ||
2258 | recursive_pkey_resolution(rh, | ||
2247 | &rd[0]); | 2259 | &rd[0]); |
2248 | return; | ||
2249 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
2250 | GNUNET_break_op (1 == rd_count); /* PKEY should be unique */ | ||
2251 | recursive_pkey_resolution (rh, | ||
2252 | &rd[0]); | ||
2253 | return; | ||
2254 | default: | ||
2255 | if (GNUNET_OK == | ||
2256 | recursive_gns2dns_resolution (rh, | ||
2257 | rd_count, | ||
2258 | rd)) | ||
2259 | return; | 2260 | return; |
2260 | break; | 2261 | |
2261 | } | 2262 | default: |
2262 | fail: | 2263 | if (GNUNET_OK == |
2263 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2264 | recursive_gns2dns_resolution(rh, |
2264 | _("GNS lookup recursion failed (no delegation record found)\n")); | 2265 | rd_count, |
2265 | fail_resolution (rh); | 2266 | rd)) |
2267 | return; | ||
2268 | break; | ||
2269 | } | ||
2270 | fail: | ||
2271 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
2272 | _("GNS lookup recursion failed (no delegation record found)\n")); | ||
2273 | fail_resolution(rh); | ||
2266 | } | 2274 | } |
2267 | 2275 | ||
2268 | 2276 | ||
@@ -2275,21 +2283,21 @@ handle_gns_resolution_result (void *cls, | |||
2275 | * @param emsg error message | 2283 | * @param emsg error message |
2276 | */ | 2284 | */ |
2277 | static void | 2285 | static void |
2278 | namecache_cache_continuation (void *cls, | 2286 | namecache_cache_continuation(void *cls, |
2279 | int32_t success, | 2287 | int32_t success, |
2280 | const char *emsg) | 2288 | const char *emsg) |
2281 | { | 2289 | { |
2282 | struct CacheOps *co = cls; | 2290 | struct CacheOps *co = cls; |
2283 | 2291 | ||
2284 | co->namecache_qe_cache = NULL; | 2292 | co->namecache_qe_cache = NULL; |
2285 | if (GNUNET_OK != success) | 2293 | if (GNUNET_OK != success) |
2286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2294 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2287 | _("Failed to cache GNS resolution: %s\n"), | 2295 | _("Failed to cache GNS resolution: %s\n"), |
2288 | emsg); | 2296 | emsg); |
2289 | GNUNET_CONTAINER_DLL_remove (co_head, | 2297 | GNUNET_CONTAINER_DLL_remove(co_head, |
2290 | co_tail, | 2298 | co_tail, |
2291 | co); | 2299 | co); |
2292 | GNUNET_free (co); | 2300 | GNUNET_free(co); |
2293 | } | 2301 | } |
2294 | 2302 | ||
2295 | 2303 | ||
@@ -2311,88 +2319,88 @@ namecache_cache_continuation (void *cls, | |||
2311 | * @param data pointer to the result data | 2319 | * @param data pointer to the result data |
2312 | */ | 2320 | */ |
2313 | static void | 2321 | static void |
2314 | handle_dht_response (void *cls, | 2322 | handle_dht_response(void *cls, |
2315 | struct GNUNET_TIME_Absolute exp, | 2323 | struct GNUNET_TIME_Absolute exp, |
2316 | const struct GNUNET_HashCode *key, | 2324 | const struct GNUNET_HashCode *key, |
2317 | const struct GNUNET_PeerIdentity *get_path, | 2325 | const struct GNUNET_PeerIdentity *get_path, |
2318 | unsigned int get_path_length, | 2326 | unsigned int get_path_length, |
2319 | const struct GNUNET_PeerIdentity *put_path, | 2327 | const struct GNUNET_PeerIdentity *put_path, |
2320 | unsigned int put_path_length, | 2328 | unsigned int put_path_length, |
2321 | enum GNUNET_BLOCK_Type type, | 2329 | enum GNUNET_BLOCK_Type type, |
2322 | size_t size, | 2330 | size_t size, |
2323 | const void *data) | 2331 | const void *data) |
2324 | { | 2332 | { |
2325 | struct GNS_ResolverHandle *rh = cls; | 2333 | struct GNS_ResolverHandle *rh = cls; |
2326 | struct AuthorityChain *ac = rh->ac_tail; | 2334 | struct AuthorityChain *ac = rh->ac_tail; |
2327 | const struct GNUNET_GNSRECORD_Block *block; | 2335 | const struct GNUNET_GNSRECORD_Block *block; |
2328 | struct CacheOps *co; | 2336 | struct CacheOps *co; |
2329 | 2337 | ||
2330 | (void) exp; | 2338 | (void)exp; |
2331 | (void) key; | 2339 | (void)key; |
2332 | (void) get_path; | 2340 | (void)get_path; |
2333 | (void) get_path_length; | 2341 | (void)get_path_length; |
2334 | (void) put_path; | 2342 | (void)put_path; |
2335 | (void) put_path_length; | 2343 | (void)put_path_length; |
2336 | (void) type; | 2344 | (void)type; |
2337 | GNUNET_DHT_get_stop (rh->get_handle); | 2345 | GNUNET_DHT_get_stop(rh->get_handle); |
2338 | rh->get_handle = NULL; | 2346 | rh->get_handle = NULL; |
2339 | GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node); | 2347 | GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node); |
2340 | rh->dht_heap_node = NULL; | 2348 | rh->dht_heap_node = NULL; |
2341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2349 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2342 | "Handling response from the DHT\n"); | 2350 | "Handling response from the DHT\n"); |
2343 | if (size < sizeof (struct GNUNET_GNSRECORD_Block)) | 2351 | if (size < sizeof(struct GNUNET_GNSRECORD_Block)) |
2344 | { | 2352 | { |
2345 | /* how did this pass DHT block validation!? */ | 2353 | /* how did this pass DHT block validation!? */ |
2346 | GNUNET_break (0); | 2354 | GNUNET_break(0); |
2347 | fail_resolution (rh); | 2355 | fail_resolution(rh); |
2348 | return; | 2356 | return; |
2349 | } | 2357 | } |
2350 | block = data; | 2358 | block = data; |
2351 | if (size != | 2359 | if (size != |
2352 | ntohl (block->purpose.size) + | 2360 | ntohl(block->purpose.size) + |
2353 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + | 2361 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) + |
2354 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature)) | 2362 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature)) |
2355 | { | 2363 | { |
2356 | /* how did this pass DHT block validation!? */ | 2364 | /* how did this pass DHT block validation!? */ |
2357 | GNUNET_break (0); | 2365 | GNUNET_break(0); |
2358 | fail_resolution (rh); | 2366 | fail_resolution(rh); |
2359 | return; | 2367 | return; |
2360 | } | 2368 | } |
2361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2369 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2362 | "Decrypting DHT block of size %u for `%s', expires %s\n", | 2370 | "Decrypting DHT block of size %u for `%s', expires %s\n", |
2363 | ntohl (block->purpose.size), | 2371 | ntohl(block->purpose.size), |
2364 | rh->name, | 2372 | rh->name, |
2365 | GNUNET_STRINGS_absolute_time_to_string (exp)); | 2373 | GNUNET_STRINGS_absolute_time_to_string(exp)); |
2366 | if (GNUNET_OK != | 2374 | if (GNUNET_OK != |
2367 | GNUNET_GNSRECORD_block_decrypt (block, | 2375 | GNUNET_GNSRECORD_block_decrypt(block, |
2368 | &ac->authority_info.gns_authority, | 2376 | &ac->authority_info.gns_authority, |
2369 | ac->label, | 2377 | ac->label, |
2370 | &handle_gns_resolution_result, | 2378 | &handle_gns_resolution_result, |
2371 | rh)) | 2379 | rh)) |
2372 | { | 2380 | { |
2373 | GNUNET_break_op (0); /* block was ill-formed */ | 2381 | GNUNET_break_op(0); /* block was ill-formed */ |
2374 | fail_resolution (rh); | 2382 | fail_resolution(rh); |
2375 | return; | 2383 | return; |
2376 | } | 2384 | } |
2377 | if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) | 2385 | if (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(block->expiration_time)).rel_value_us) |
2378 | { | 2386 | { |
2379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2387 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2380 | "Received expired block from the DHT, will not cache it.\n"); | 2388 | "Received expired block from the DHT, will not cache it.\n"); |
2381 | return; | 2389 | return; |
2382 | } | 2390 | } |
2383 | if (GNUNET_YES == disable_cache) | 2391 | if (GNUNET_YES == disable_cache) |
2384 | return; | 2392 | return; |
2385 | /* Cache well-formed blocks */ | 2393 | /* Cache well-formed blocks */ |
2386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2394 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2387 | "Caching response from the DHT in namecache\n"); | 2395 | "Caching response from the DHT in namecache\n"); |
2388 | co = GNUNET_new (struct CacheOps); | 2396 | co = GNUNET_new(struct CacheOps); |
2389 | co->namecache_qe_cache = GNUNET_NAMECACHE_block_cache (namecache_handle, | 2397 | co->namecache_qe_cache = GNUNET_NAMECACHE_block_cache(namecache_handle, |
2390 | block, | 2398 | block, |
2391 | &namecache_cache_continuation, | 2399 | &namecache_cache_continuation, |
2392 | co); | 2400 | co); |
2393 | GNUNET_CONTAINER_DLL_insert (co_head, | 2401 | GNUNET_CONTAINER_DLL_insert(co_head, |
2394 | co_tail, | 2402 | co_tail, |
2395 | co); | 2403 | co); |
2396 | } | 2404 | } |
2397 | 2405 | ||
2398 | 2406 | ||
@@ -2403,30 +2411,30 @@ handle_dht_response (void *cls, | |||
2403 | * @param query key to use in the DHT lookup | 2411 | * @param query key to use in the DHT lookup |
2404 | */ | 2412 | */ |
2405 | static void | 2413 | static void |
2406 | start_dht_request (struct GNS_ResolverHandle *rh, | 2414 | start_dht_request(struct GNS_ResolverHandle *rh, |
2407 | const struct GNUNET_HashCode *query) | 2415 | const struct GNUNET_HashCode *query) |
2408 | { | 2416 | { |
2409 | struct GNS_ResolverHandle *rx; | 2417 | struct GNS_ResolverHandle *rx; |
2410 | 2418 | ||
2411 | GNUNET_assert (NULL == rh->get_handle); | 2419 | GNUNET_assert(NULL == rh->get_handle); |
2412 | rh->get_handle = GNUNET_DHT_get_start (dht_handle, | 2420 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, |
2413 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 2421 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
2414 | query, | 2422 | query, |
2415 | DHT_GNS_REPLICATION_LEVEL, | 2423 | DHT_GNS_REPLICATION_LEVEL, |
2416 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 2424 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
2417 | NULL, 0, | 2425 | NULL, 0, |
2418 | &handle_dht_response, rh); | 2426 | &handle_dht_response, rh); |
2419 | rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap, | 2427 | rh->dht_heap_node = GNUNET_CONTAINER_heap_insert(dht_lookup_heap, |
2420 | rh, | 2428 | rh, |
2421 | GNUNET_TIME_absolute_get ().abs_value_us); | 2429 | GNUNET_TIME_absolute_get().abs_value_us); |
2422 | if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries) | 2430 | if (GNUNET_CONTAINER_heap_get_size(dht_lookup_heap) > max_allowed_background_queries) |
2423 | { | 2431 | { |
2424 | /* fail longest-standing DHT request */ | 2432 | /* fail longest-standing DHT request */ |
2425 | rx = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap); | 2433 | rx = GNUNET_CONTAINER_heap_remove_root(dht_lookup_heap); |
2426 | rx->dht_heap_node = NULL; | 2434 | rx->dht_heap_node = NULL; |
2427 | GNUNET_assert (NULL != rx); | 2435 | GNUNET_assert(NULL != rx); |
2428 | fail_resolution (rx); | 2436 | fail_resolution(rx); |
2429 | } | 2437 | } |
2430 | } | 2438 | } |
2431 | 2439 | ||
2432 | 2440 | ||
@@ -2439,19 +2447,19 @@ start_dht_request (struct GNS_ResolverHandle *rh, | |||
2439 | * @param rd array of records with data to store | 2447 | * @param rd array of records with data to store |
2440 | */ | 2448 | */ |
2441 | static void | 2449 | static void |
2442 | handle_gns_namecache_resolution_result (void *cls, | 2450 | handle_gns_namecache_resolution_result(void *cls, |
2443 | unsigned int rd_count, | 2451 | unsigned int rd_count, |
2444 | const struct GNUNET_GNSRECORD_Data *rd) | 2452 | const struct GNUNET_GNSRECORD_Data *rd) |
2445 | { | 2453 | { |
2446 | struct GNS_ResolverHandle *rh = cls; | 2454 | struct GNS_ResolverHandle *rh = cls; |
2447 | 2455 | ||
2448 | if (0 == rd_count) | 2456 | if (0 == rd_count) |
2449 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2457 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2450 | _("GNS namecache returned empty result for `%s'\n"), | 2458 | _("GNS namecache returned empty result for `%s'\n"), |
2451 | rh->name); | 2459 | rh->name); |
2452 | handle_gns_resolution_result (rh, | 2460 | handle_gns_resolution_result(rh, |
2453 | rd_count, | 2461 | rd_count, |
2454 | rd); | 2462 | rd); |
2455 | } | 2463 | } |
2456 | 2464 | ||
2457 | 2465 | ||
@@ -2462,8 +2470,8 @@ handle_gns_namecache_resolution_result (void *cls, | |||
2462 | * @param block block that was stored in the namecache | 2470 | * @param block block that was stored in the namecache |
2463 | */ | 2471 | */ |
2464 | static void | 2472 | static void |
2465 | handle_namecache_block_response (void *cls, | 2473 | handle_namecache_block_response(void *cls, |
2466 | const struct GNUNET_GNSRECORD_Block *block) | 2474 | const struct GNUNET_GNSRECORD_Block *block) |
2467 | { | 2475 | { |
2468 | struct GNS_ResolverHandle *rh = cls; | 2476 | struct GNS_ResolverHandle *rh = cls; |
2469 | struct AuthorityChain *ac = rh->ac_tail; | 2477 | struct AuthorityChain *ac = rh->ac_tail; |
@@ -2471,62 +2479,62 @@ handle_namecache_block_response (void *cls, | |||
2471 | const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority; | 2479 | const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority; |
2472 | struct GNUNET_HashCode query; | 2480 | struct GNUNET_HashCode query; |
2473 | 2481 | ||
2474 | GNUNET_assert (NULL != rh->namecache_qe); | 2482 | GNUNET_assert(NULL != rh->namecache_qe); |
2475 | rh->namecache_qe = NULL; | 2483 | rh->namecache_qe = NULL; |
2476 | if ( ( (GNUNET_GNS_LO_DEFAULT == rh->options) || | 2484 | if (((GNUNET_GNS_LO_DEFAULT == rh->options) || |
2477 | ( (GNUNET_GNS_LO_LOCAL_MASTER == rh->options) && | 2485 | ((GNUNET_GNS_LO_LOCAL_MASTER == rh->options) && |
2478 | (ac != rh->ac_head) ) ) && | 2486 | (ac != rh->ac_head))) && |
2479 | ( (NULL == block) || | 2487 | ((NULL == block) || |
2480 | (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) ) | 2488 | (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(block->expiration_time)).rel_value_us))) |
2481 | { | 2489 | { |
2482 | /* namecache knows nothing; try DHT lookup */ | 2490 | /* namecache knows nothing; try DHT lookup */ |
2483 | GNUNET_GNSRECORD_query_from_public_key (auth, | 2491 | GNUNET_GNSRECORD_query_from_public_key(auth, |
2484 | label, | 2492 | label, |
2485 | &query); | 2493 | &query); |
2486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2494 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2487 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", | 2495 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", |
2488 | ac->label, | 2496 | ac->label, |
2489 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority), | 2497 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority), |
2490 | GNUNET_h2s (&query)); | 2498 | GNUNET_h2s(&query)); |
2491 | start_dht_request (rh, &query); | 2499 | start_dht_request(rh, &query); |
2492 | return; | 2500 | return; |
2493 | } | 2501 | } |
2494 | 2502 | ||
2495 | if ( (NULL == block) || | 2503 | if ((NULL == block) || |
2496 | (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) | 2504 | (0 == GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh(block->expiration_time)).rel_value_us)) |
2497 | { | 2505 | { |
2498 | /* DHT not permitted and no local result, fail */ | 2506 | /* DHT not permitted and no local result, fail */ |
2499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2507 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2500 | "Resolution failed for `%s' in zone %s (DHT lookup not permitted by configuration)\n", | 2508 | "Resolution failed for `%s' in zone %s (DHT lookup not permitted by configuration)\n", |
2501 | ac->label, | 2509 | ac->label, |
2502 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority)); | 2510 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); |
2503 | fail_resolution (rh); | 2511 | fail_resolution(rh); |
2504 | return; | 2512 | return; |
2505 | } | 2513 | } |
2506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2514 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2507 | "Received result from namecache for label `%s'\n", | 2515 | "Received result from namecache for label `%s'\n", |
2508 | ac->label); | 2516 | ac->label); |
2509 | 2517 | ||
2510 | if (GNUNET_OK != | 2518 | if (GNUNET_OK != |
2511 | GNUNET_GNSRECORD_block_decrypt (block, | 2519 | GNUNET_GNSRECORD_block_decrypt(block, |
2512 | auth, | 2520 | auth, |
2513 | label, | 2521 | label, |
2514 | &handle_gns_namecache_resolution_result, | 2522 | &handle_gns_namecache_resolution_result, |
2515 | rh)) | 2523 | rh)) |
2516 | { | 2524 | { |
2517 | GNUNET_break_op (0); /* block was ill-formed */ | 2525 | GNUNET_break_op(0); /* block was ill-formed */ |
2518 | /* try DHT instead */ | 2526 | /* try DHT instead */ |
2519 | GNUNET_GNSRECORD_query_from_public_key (auth, | 2527 | GNUNET_GNSRECORD_query_from_public_key(auth, |
2520 | label, | 2528 | label, |
2521 | &query); | 2529 | &query); |
2522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2530 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2523 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", | 2531 | "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n", |
2524 | ac->label, | 2532 | ac->label, |
2525 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority), | 2533 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority), |
2526 | GNUNET_h2s (&query)); | 2534 | GNUNET_h2s(&query)); |
2527 | start_dht_request (rh, &query); | 2535 | start_dht_request(rh, &query); |
2528 | return; | 2536 | return; |
2529 | } | 2537 | } |
2530 | } | 2538 | } |
2531 | 2539 | ||
2532 | 2540 | ||
@@ -2536,32 +2544,32 @@ handle_namecache_block_response (void *cls, | |||
2536 | * @param rh query we are processing | 2544 | * @param rh query we are processing |
2537 | */ | 2545 | */ |
2538 | static void | 2546 | static void |
2539 | recursive_gns_resolution_namecache (struct GNS_ResolverHandle *rh) | 2547 | recursive_gns_resolution_namecache(struct GNS_ResolverHandle *rh) |
2540 | { | 2548 | { |
2541 | struct AuthorityChain *ac = rh->ac_tail; | 2549 | struct AuthorityChain *ac = rh->ac_tail; |
2542 | struct GNUNET_HashCode query; | 2550 | struct GNUNET_HashCode query; |
2543 | 2551 | ||
2544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2552 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2545 | "Starting GNS resolution for `%s' in zone %s\n", | 2553 | "Starting GNS resolution for `%s' in zone %s\n", |
2546 | ac->label, | 2554 | ac->label, |
2547 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority)); | 2555 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); |
2548 | GNUNET_GNSRECORD_query_from_public_key (&ac->authority_info.gns_authority, | 2556 | GNUNET_GNSRECORD_query_from_public_key(&ac->authority_info.gns_authority, |
2549 | ac->label, | 2557 | ac->label, |
2550 | &query); | 2558 | &query); |
2551 | if (GNUNET_YES != disable_cache) | 2559 | if (GNUNET_YES != disable_cache) |
2552 | { | 2560 | { |
2553 | rh->namecache_qe | 2561 | rh->namecache_qe |
2554 | = GNUNET_NAMECACHE_lookup_block (namecache_handle, | 2562 | = GNUNET_NAMECACHE_lookup_block(namecache_handle, |
2555 | &query, | 2563 | &query, |
2556 | &handle_namecache_block_response, | 2564 | &handle_namecache_block_response, |
2557 | rh); | 2565 | rh); |
2558 | GNUNET_assert (NULL != rh->namecache_qe); | 2566 | GNUNET_assert(NULL != rh->namecache_qe); |
2559 | } | 2567 | } |
2560 | else | 2568 | else |
2561 | { | 2569 | { |
2562 | start_dht_request (rh, | 2570 | start_dht_request(rh, |
2563 | &query); | 2571 | &query); |
2564 | } | 2572 | } |
2565 | } | 2573 | } |
2566 | 2574 | ||
2567 | 2575 | ||
@@ -2572,22 +2580,22 @@ recursive_gns_resolution_namecache (struct GNS_ResolverHandle *rh) | |||
2572 | * @param is_valid #GNUNET_YES if the zone was not yet revoked | 2580 | * @param is_valid #GNUNET_YES if the zone was not yet revoked |
2573 | */ | 2581 | */ |
2574 | static void | 2582 | static void |
2575 | handle_revocation_result (void *cls, | 2583 | handle_revocation_result(void *cls, |
2576 | int is_valid) | 2584 | int is_valid) |
2577 | { | 2585 | { |
2578 | struct GNS_ResolverHandle *rh = cls; | 2586 | struct GNS_ResolverHandle *rh = cls; |
2579 | struct AuthorityChain *ac = rh->ac_tail; | 2587 | struct AuthorityChain *ac = rh->ac_tail; |
2580 | 2588 | ||
2581 | rh->rev_check = NULL; | 2589 | rh->rev_check = NULL; |
2582 | if (GNUNET_YES != is_valid) | 2590 | if (GNUNET_YES != is_valid) |
2583 | { | 2591 | { |
2584 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2592 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2585 | _("Zone %s was revoked, resolution fails\n"), | 2593 | _("Zone %s was revoked, resolution fails\n"), |
2586 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority)); | 2594 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); |
2587 | fail_resolution (rh); | 2595 | fail_resolution(rh); |
2588 | return; | 2596 | return; |
2589 | } | 2597 | } |
2590 | recursive_gns_resolution_namecache (rh); | 2598 | recursive_gns_resolution_namecache(rh); |
2591 | } | 2599 | } |
2592 | 2600 | ||
2593 | 2601 | ||
@@ -2597,18 +2605,18 @@ handle_revocation_result (void *cls, | |||
2597 | * @param rh query we are processing | 2605 | * @param rh query we are processing |
2598 | */ | 2606 | */ |
2599 | static void | 2607 | static void |
2600 | recursive_gns_resolution_revocation (struct GNS_ResolverHandle *rh) | 2608 | recursive_gns_resolution_revocation(struct GNS_ResolverHandle *rh) |
2601 | { | 2609 | { |
2602 | struct AuthorityChain *ac = rh->ac_tail; | 2610 | struct AuthorityChain *ac = rh->ac_tail; |
2603 | 2611 | ||
2604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2612 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2605 | "Starting revocation check for zone %s\n", | 2613 | "Starting revocation check for zone %s\n", |
2606 | GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority)); | 2614 | GNUNET_GNSRECORD_z2s(&ac->authority_info.gns_authority)); |
2607 | rh->rev_check = GNUNET_REVOCATION_query (cfg, | 2615 | rh->rev_check = GNUNET_REVOCATION_query(cfg, |
2608 | &ac->authority_info.gns_authority, | 2616 | &ac->authority_info.gns_authority, |
2609 | &handle_revocation_result, | 2617 | &handle_revocation_result, |
2610 | rh); | 2618 | rh); |
2611 | GNUNET_assert (NULL != rh->rev_check); | 2619 | GNUNET_assert(NULL != rh->rev_check); |
2612 | } | 2620 | } |
2613 | 2621 | ||
2614 | 2622 | ||
@@ -2618,23 +2626,23 @@ recursive_gns_resolution_revocation (struct GNS_ResolverHandle *rh) | |||
2618 | * @param cls the `struct GNS_ResolverHandle` of the resolution | 2626 | * @param cls the `struct GNS_ResolverHandle` of the resolution |
2619 | */ | 2627 | */ |
2620 | static void | 2628 | static void |
2621 | recursive_resolution (void *cls) | 2629 | recursive_resolution(void *cls) |
2622 | { | 2630 | { |
2623 | struct GNS_ResolverHandle *rh = cls; | 2631 | struct GNS_ResolverHandle *rh = cls; |
2624 | 2632 | ||
2625 | rh->task_id = NULL; | 2633 | rh->task_id = NULL; |
2626 | if (MAX_RECURSION < rh->loop_limiter++) | 2634 | if (MAX_RECURSION < rh->loop_limiter++) |
2627 | { | 2635 | { |
2628 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2636 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2629 | "Encountered unbounded recursion resolving `%s'\n", | 2637 | "Encountered unbounded recursion resolving `%s'\n", |
2630 | rh->name); | 2638 | rh->name); |
2631 | fail_resolution (rh); | 2639 | fail_resolution(rh); |
2632 | return; | 2640 | return; |
2633 | } | 2641 | } |
2634 | if (GNUNET_YES == rh->ac_tail->gns_authority) | 2642 | if (GNUNET_YES == rh->ac_tail->gns_authority) |
2635 | recursive_gns_resolution_revocation (rh); | 2643 | recursive_gns_resolution_revocation(rh); |
2636 | else | 2644 | else |
2637 | recursive_dns_resolution (rh); | 2645 | recursive_dns_resolution(rh); |
2638 | } | 2646 | } |
2639 | 2647 | ||
2640 | 2648 | ||
@@ -2645,7 +2653,7 @@ recursive_resolution (void *cls) | |||
2645 | * @param cls the `struct GNS_ResolverHandle` | 2653 | * @param cls the `struct GNS_ResolverHandle` |
2646 | */ | 2654 | */ |
2647 | static void | 2655 | static void |
2648 | start_resolver_lookup (void *cls) | 2656 | start_resolver_lookup(void *cls) |
2649 | { | 2657 | { |
2650 | struct GNS_ResolverHandle *rh = cls; | 2658 | struct GNS_ResolverHandle *rh = cls; |
2651 | struct AuthorityChain *ac; | 2659 | struct AuthorityChain *ac; |
@@ -2653,61 +2661,61 @@ start_resolver_lookup (void *cls) | |||
2653 | struct in6_addr v6; | 2661 | struct in6_addr v6; |
2654 | 2662 | ||
2655 | rh->task_id = NULL; | 2663 | rh->task_id = NULL; |
2656 | if (1 == inet_pton (AF_INET, | 2664 | if (1 == inet_pton(AF_INET, |
2657 | rh->name, | 2665 | rh->name, |
2658 | &v4)) | 2666 | &v4)) |
2659 | { | 2667 | { |
2660 | /* name is IPv4 address, pretend it's an A record */ | 2668 | /* name is IPv4 address, pretend it's an A record */ |
2661 | struct GNUNET_GNSRECORD_Data rd; | 2669 | struct GNUNET_GNSRECORD_Data rd; |
2662 | 2670 | ||
2663 | rd.data = &v4; | 2671 | rd.data = &v4; |
2664 | rd.data_size = sizeof (v4); | 2672 | rd.data_size = sizeof(v4); |
2665 | rd.expiration_time = UINT64_MAX; | 2673 | rd.expiration_time = UINT64_MAX; |
2666 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | 2674 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; |
2667 | rd.flags = 0; | 2675 | rd.flags = 0; |
2668 | rh->proc (rh->proc_cls, | 2676 | rh->proc(rh->proc_cls, |
2669 | 1, | 2677 | 1, |
2670 | &rd); | 2678 | &rd); |
2671 | GNUNET_assert (NULL == rh->task_id); | 2679 | GNUNET_assert(NULL == rh->task_id); |
2672 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 2680 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
2673 | rh); | 2681 | rh); |
2674 | return; | 2682 | return; |
2675 | } | 2683 | } |
2676 | if (1 == inet_pton (AF_INET6, | 2684 | if (1 == inet_pton(AF_INET6, |
2677 | rh->name, | 2685 | rh->name, |
2678 | &v6)) | 2686 | &v6)) |
2679 | { | 2687 | { |
2680 | /* name is IPv6 address, pretend it's an AAAA record */ | 2688 | /* name is IPv6 address, pretend it's an AAAA record */ |
2681 | struct GNUNET_GNSRECORD_Data rd; | 2689 | struct GNUNET_GNSRECORD_Data rd; |
2682 | 2690 | ||
2683 | rd.data = &v6; | 2691 | rd.data = &v6; |
2684 | rd.data_size = sizeof (v6); | 2692 | rd.data_size = sizeof(v6); |
2685 | rd.expiration_time = UINT64_MAX; | 2693 | rd.expiration_time = UINT64_MAX; |
2686 | rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA; | 2694 | rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA; |
2687 | rd.flags = 0; | 2695 | rd.flags = 0; |
2688 | rh->proc (rh->proc_cls, | 2696 | rh->proc(rh->proc_cls, |
2689 | 1, | 2697 | 1, |
2690 | &rd); | 2698 | &rd); |
2691 | GNUNET_assert (NULL == rh->task_id); | 2699 | GNUNET_assert(NULL == rh->task_id); |
2692 | rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | 2700 | rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, |
2693 | rh); | 2701 | rh); |
2694 | return; | 2702 | return; |
2695 | } | 2703 | } |
2696 | 2704 | ||
2697 | ac = GNUNET_new (struct AuthorityChain); | 2705 | ac = GNUNET_new(struct AuthorityChain); |
2698 | ac->rh = rh; | 2706 | ac->rh = rh; |
2699 | ac->label = resolver_lookup_get_next_label (rh); | 2707 | ac->label = resolver_lookup_get_next_label(rh); |
2700 | if (NULL == ac->label) | 2708 | if (NULL == ac->label) |
2701 | /* name was just the "TLD", so we default to label | 2709 | /* name was just the "TLD", so we default to label |
2702 | #GNUNET_GNS_EMPTY_LABEL_AT */ | 2710 | #GNUNET_GNS_EMPTY_LABEL_AT */ |
2703 | ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); | 2711 | ac->label = GNUNET_strdup(GNUNET_GNS_EMPTY_LABEL_AT); |
2704 | ac->gns_authority = GNUNET_YES; | 2712 | ac->gns_authority = GNUNET_YES; |
2705 | ac->authority_info.gns_authority = rh->authority_zone; | 2713 | ac->authority_info.gns_authority = rh->authority_zone; |
2706 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 2714 | GNUNET_CONTAINER_DLL_insert_tail(rh->ac_head, |
2707 | rh->ac_tail, | 2715 | rh->ac_tail, |
2708 | ac); | 2716 | ac); |
2709 | rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution, | 2717 | rh->task_id = GNUNET_SCHEDULER_add_now(&recursive_resolution, |
2710 | rh); | 2718 | rh); |
2711 | } | 2719 | } |
2712 | 2720 | ||
2713 | 2721 | ||
@@ -2724,31 +2732,31 @@ start_resolver_lookup (void *cls) | |||
2724 | * @return handle to cancel operation | 2732 | * @return handle to cancel operation |
2725 | */ | 2733 | */ |
2726 | struct GNS_ResolverHandle * | 2734 | struct GNS_ResolverHandle * |
2727 | GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 2735 | GNS_resolver_lookup(const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, |
2728 | uint32_t record_type, | 2736 | uint32_t record_type, |
2729 | const char *name, | 2737 | const char *name, |
2730 | enum GNUNET_GNS_LocalOptions options, | 2738 | enum GNUNET_GNS_LocalOptions options, |
2731 | GNS_ResultProcessor proc, | 2739 | GNS_ResultProcessor proc, |
2732 | void *proc_cls) | 2740 | void *proc_cls) |
2733 | { | 2741 | { |
2734 | struct GNS_ResolverHandle *rh; | 2742 | struct GNS_ResolverHandle *rh; |
2735 | 2743 | ||
2736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2744 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2737 | "Starting lookup for `%s'\n", | 2745 | "Starting lookup for `%s'\n", |
2738 | name); | 2746 | name); |
2739 | rh = GNUNET_new (struct GNS_ResolverHandle); | 2747 | rh = GNUNET_new(struct GNS_ResolverHandle); |
2740 | GNUNET_CONTAINER_DLL_insert (rlh_head, | 2748 | GNUNET_CONTAINER_DLL_insert(rlh_head, |
2741 | rlh_tail, | 2749 | rlh_tail, |
2742 | rh); | 2750 | rh); |
2743 | rh->authority_zone = *zone; | 2751 | rh->authority_zone = *zone; |
2744 | rh->proc = proc; | 2752 | rh->proc = proc; |
2745 | rh->proc_cls = proc_cls; | 2753 | rh->proc_cls = proc_cls; |
2746 | rh->options = options; | 2754 | rh->options = options; |
2747 | rh->record_type = record_type; | 2755 | rh->record_type = record_type; |
2748 | rh->name = GNUNET_strdup (name); | 2756 | rh->name = GNUNET_strdup(name); |
2749 | rh->name_resolution_pos = strlen (name); | 2757 | rh->name_resolution_pos = strlen(name); |
2750 | rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, | 2758 | rh->task_id = GNUNET_SCHEDULER_add_now(&start_resolver_lookup, |
2751 | rh); | 2759 | rh); |
2752 | return rh; | 2760 | return rh; |
2753 | } | 2761 | } |
2754 | 2762 | ||
@@ -2759,107 +2767,107 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | |||
2759 | * @param rh resolution to abort | 2767 | * @param rh resolution to abort |
2760 | */ | 2768 | */ |
2761 | void | 2769 | void |
2762 | GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | 2770 | GNS_resolver_lookup_cancel(struct GNS_ResolverHandle *rh) |
2763 | { | 2771 | { |
2764 | struct DnsResult *dr; | 2772 | struct DnsResult *dr; |
2765 | struct AuthorityChain *ac; | 2773 | struct AuthorityChain *ac; |
2766 | struct VpnContext *vpn_ctx; | 2774 | struct VpnContext *vpn_ctx; |
2767 | 2775 | ||
2768 | GNUNET_CONTAINER_DLL_remove (rlh_head, | 2776 | GNUNET_CONTAINER_DLL_remove(rlh_head, |
2769 | rlh_tail, | 2777 | rlh_tail, |
2770 | rh); | 2778 | rh); |
2771 | if (NULL != rh->dns_request) | 2779 | if (NULL != rh->dns_request) |
2772 | { | 2780 | { |
2773 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); | 2781 | GNUNET_DNSSTUB_resolve_cancel(rh->dns_request); |
2774 | rh->dns_request = NULL; | 2782 | rh->dns_request = NULL; |
2775 | } | 2783 | } |
2776 | while (NULL != (ac = rh->ac_head)) | 2784 | while (NULL != (ac = rh->ac_head)) |
2777 | { | ||
2778 | GNUNET_CONTAINER_DLL_remove (rh->ac_head, | ||
2779 | rh->ac_tail, | ||
2780 | ac); | ||
2781 | if (GNUNET_NO == ac->gns_authority) | ||
2782 | { | 2785 | { |
2783 | struct Gns2DnsPending *gp; | 2786 | GNUNET_CONTAINER_DLL_remove(rh->ac_head, |
2784 | 2787 | rh->ac_tail, | |
2785 | while (NULL != (gp = ac->authority_info.dns_authority.gp_head)) | 2788 | ac); |
2786 | { | 2789 | if (GNUNET_NO == ac->gns_authority) |
2787 | GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head, | ||
2788 | ac->authority_info.dns_authority.gp_tail, | ||
2789 | gp); | ||
2790 | if (NULL != gp->rh) | ||
2791 | { | ||
2792 | /* rh->g2dc->rh is NOT in the DLL yet, so to enable us | ||
2793 | using GNS_resolver_lookup_cancel here, we need to | ||
2794 | add it first... */ | ||
2795 | GNUNET_CONTAINER_DLL_insert (rlh_head, | ||
2796 | rlh_tail, | ||
2797 | gp->rh); | ||
2798 | GNUNET_assert (NULL == gp->rh->task_id); | ||
2799 | gp->rh->task_id = GNUNET_SCHEDULER_add_now (&GNS_resolver_lookup_cancel_, | ||
2800 | gp->rh); | ||
2801 | gp->rh = NULL; | ||
2802 | } | ||
2803 | if (NULL != gp->dns_rh) | ||
2804 | { | 2790 | { |
2805 | GNUNET_RESOLVER_request_cancel (gp->dns_rh); | 2791 | struct Gns2DnsPending *gp; |
2806 | gp->dns_rh = NULL; | 2792 | |
2793 | while (NULL != (gp = ac->authority_info.dns_authority.gp_head)) | ||
2794 | { | ||
2795 | GNUNET_CONTAINER_DLL_remove(ac->authority_info.dns_authority.gp_head, | ||
2796 | ac->authority_info.dns_authority.gp_tail, | ||
2797 | gp); | ||
2798 | if (NULL != gp->rh) | ||
2799 | { | ||
2800 | /* rh->g2dc->rh is NOT in the DLL yet, so to enable us | ||
2801 | using GNS_resolver_lookup_cancel here, we need to | ||
2802 | add it first... */ | ||
2803 | GNUNET_CONTAINER_DLL_insert(rlh_head, | ||
2804 | rlh_tail, | ||
2805 | gp->rh); | ||
2806 | GNUNET_assert(NULL == gp->rh->task_id); | ||
2807 | gp->rh->task_id = GNUNET_SCHEDULER_add_now(&GNS_resolver_lookup_cancel_, | ||
2808 | gp->rh); | ||
2809 | gp->rh = NULL; | ||
2810 | } | ||
2811 | if (NULL != gp->dns_rh) | ||
2812 | { | ||
2813 | GNUNET_RESOLVER_request_cancel(gp->dns_rh); | ||
2814 | gp->dns_rh = NULL; | ||
2815 | } | ||
2816 | GNUNET_free(gp); | ||
2817 | } | ||
2818 | GNUNET_DNSSTUB_stop(ac->authority_info.dns_authority.dns_handle); | ||
2807 | } | 2819 | } |
2808 | GNUNET_free (gp); | 2820 | GNUNET_free(ac->label); |
2809 | } | 2821 | GNUNET_free(ac); |
2810 | GNUNET_DNSSTUB_stop (ac->authority_info.dns_authority.dns_handle); | ||
2811 | } | 2822 | } |
2812 | GNUNET_free (ac->label); | ||
2813 | GNUNET_free (ac); | ||
2814 | } | ||
2815 | if (NULL != rh->task_id) | 2823 | if (NULL != rh->task_id) |
2816 | { | 2824 | { |
2817 | GNUNET_SCHEDULER_cancel (rh->task_id); | 2825 | GNUNET_SCHEDULER_cancel(rh->task_id); |
2818 | rh->task_id = NULL; | 2826 | rh->task_id = NULL; |
2819 | } | 2827 | } |
2820 | if (NULL != rh->get_handle) | 2828 | if (NULL != rh->get_handle) |
2821 | { | 2829 | { |
2822 | GNUNET_DHT_get_stop (rh->get_handle); | 2830 | GNUNET_DHT_get_stop(rh->get_handle); |
2823 | rh->get_handle = NULL; | 2831 | rh->get_handle = NULL; |
2824 | } | 2832 | } |
2825 | if (NULL != rh->dht_heap_node) | 2833 | if (NULL != rh->dht_heap_node) |
2826 | { | 2834 | { |
2827 | GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node); | 2835 | GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node); |
2828 | rh->dht_heap_node = NULL; | 2836 | rh->dht_heap_node = NULL; |
2829 | } | 2837 | } |
2830 | if (NULL != (vpn_ctx = rh->vpn_ctx)) | 2838 | if (NULL != (vpn_ctx = rh->vpn_ctx)) |
2831 | { | 2839 | { |
2832 | GNUNET_VPN_cancel_request (vpn_ctx->vpn_request); | 2840 | GNUNET_VPN_cancel_request(vpn_ctx->vpn_request); |
2833 | GNUNET_free (vpn_ctx->rd_data); | 2841 | GNUNET_free(vpn_ctx->rd_data); |
2834 | GNUNET_free (vpn_ctx); | 2842 | GNUNET_free(vpn_ctx); |
2835 | } | 2843 | } |
2836 | if (NULL != rh->namecache_qe) | 2844 | if (NULL != rh->namecache_qe) |
2837 | { | 2845 | { |
2838 | GNUNET_NAMECACHE_cancel (rh->namecache_qe); | 2846 | GNUNET_NAMECACHE_cancel(rh->namecache_qe); |
2839 | rh->namecache_qe = NULL; | 2847 | rh->namecache_qe = NULL; |
2840 | } | 2848 | } |
2841 | if (NULL != rh->rev_check) | 2849 | if (NULL != rh->rev_check) |
2842 | { | 2850 | { |
2843 | GNUNET_REVOCATION_query_cancel (rh->rev_check); | 2851 | GNUNET_REVOCATION_query_cancel(rh->rev_check); |
2844 | rh->rev_check = NULL; | 2852 | rh->rev_check = NULL; |
2845 | } | 2853 | } |
2846 | if (NULL != rh->std_resolve) | 2854 | if (NULL != rh->std_resolve) |
2847 | { | 2855 | { |
2848 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2856 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2849 | "Canceling standard DNS resolution\n"); | 2857 | "Canceling standard DNS resolution\n"); |
2850 | GNUNET_RESOLVER_request_cancel (rh->std_resolve); | 2858 | GNUNET_RESOLVER_request_cancel(rh->std_resolve); |
2851 | rh->std_resolve = NULL; | 2859 | rh->std_resolve = NULL; |
2852 | } | 2860 | } |
2853 | while (NULL != (dr = rh->dns_result_head)) | 2861 | while (NULL != (dr = rh->dns_result_head)) |
2854 | { | 2862 | { |
2855 | GNUNET_CONTAINER_DLL_remove (rh->dns_result_head, | 2863 | GNUNET_CONTAINER_DLL_remove(rh->dns_result_head, |
2856 | rh->dns_result_tail, | 2864 | rh->dns_result_tail, |
2857 | dr); | 2865 | dr); |
2858 | GNUNET_free (dr); | 2866 | GNUNET_free(dr); |
2859 | } | 2867 | } |
2860 | GNUNET_free_non_null (rh->leho); | 2868 | GNUNET_free_non_null(rh->leho); |
2861 | GNUNET_free (rh->name); | 2869 | GNUNET_free(rh->name); |
2862 | GNUNET_free (rh); | 2870 | GNUNET_free(rh); |
2863 | } | 2871 | } |
2864 | 2872 | ||
2865 | 2873 | ||
@@ -2875,24 +2883,24 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | |||
2875 | * @param max_bg_queries maximum number of parallel background queries in dht | 2883 | * @param max_bg_queries maximum number of parallel background queries in dht |
2876 | */ | 2884 | */ |
2877 | void | 2885 | void |
2878 | GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc, | 2886 | GNS_resolver_init(struct GNUNET_NAMECACHE_Handle *nc, |
2879 | struct GNUNET_DHT_Handle *dht, | 2887 | struct GNUNET_DHT_Handle *dht, |
2880 | const struct GNUNET_CONFIGURATION_Handle *c, | 2888 | const struct GNUNET_CONFIGURATION_Handle *c, |
2881 | unsigned long long max_bg_queries) | 2889 | unsigned long long max_bg_queries) |
2882 | { | 2890 | { |
2883 | cfg = c; | 2891 | cfg = c; |
2884 | namecache_handle = nc; | 2892 | namecache_handle = nc; |
2885 | dht_handle = dht; | 2893 | dht_handle = dht; |
2886 | dht_lookup_heap = | 2894 | dht_lookup_heap = |
2887 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2895 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2888 | max_allowed_background_queries = max_bg_queries; | 2896 | max_allowed_background_queries = max_bg_queries; |
2889 | disable_cache = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 2897 | disable_cache = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
2890 | "namecache", | 2898 | "namecache", |
2891 | "DISABLE"); | 2899 | "DISABLE"); |
2892 | if (GNUNET_YES == disable_cache) | 2900 | if (GNUNET_YES == disable_cache) |
2893 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2901 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2894 | "Namecache disabled\n"); | 2902 | "Namecache disabled\n"); |
2895 | vpn_handle = GNUNET_VPN_connect (cfg); | 2903 | vpn_handle = GNUNET_VPN_connect(cfg); |
2896 | } | 2904 | } |
2897 | 2905 | ||
2898 | 2906 | ||
@@ -2900,30 +2908,30 @@ GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc, | |||
2900 | * Shutdown resolver | 2908 | * Shutdown resolver |
2901 | */ | 2909 | */ |
2902 | void | 2910 | void |
2903 | GNS_resolver_done () | 2911 | GNS_resolver_done() |
2904 | { | 2912 | { |
2905 | struct GNS_ResolverHandle *rh; | 2913 | struct GNS_ResolverHandle *rh; |
2906 | struct CacheOps *co; | 2914 | struct CacheOps *co; |
2907 | 2915 | ||
2908 | /* abort active resolutions */ | 2916 | /* abort active resolutions */ |
2909 | while (NULL != (rh = rlh_head)) | 2917 | while (NULL != (rh = rlh_head)) |
2910 | { | 2918 | { |
2911 | rh->proc (rh->proc_cls, | 2919 | rh->proc(rh->proc_cls, |
2912 | 0, | 2920 | 0, |
2913 | NULL); | 2921 | NULL); |
2914 | GNS_resolver_lookup_cancel (rh); | 2922 | GNS_resolver_lookup_cancel(rh); |
2915 | } | 2923 | } |
2916 | while (NULL != (co = co_head)) | 2924 | while (NULL != (co = co_head)) |
2917 | { | 2925 | { |
2918 | GNUNET_CONTAINER_DLL_remove (co_head, | 2926 | GNUNET_CONTAINER_DLL_remove(co_head, |
2919 | co_tail, | 2927 | co_tail, |
2920 | co); | 2928 | co); |
2921 | GNUNET_NAMECACHE_cancel (co->namecache_qe_cache); | 2929 | GNUNET_NAMECACHE_cancel(co->namecache_qe_cache); |
2922 | GNUNET_free (co); | 2930 | GNUNET_free(co); |
2923 | } | 2931 | } |
2924 | GNUNET_CONTAINER_heap_destroy (dht_lookup_heap); | 2932 | GNUNET_CONTAINER_heap_destroy(dht_lookup_heap); |
2925 | dht_lookup_heap = NULL; | 2933 | dht_lookup_heap = NULL; |
2926 | GNUNET_VPN_disconnect (vpn_handle); | 2934 | GNUNET_VPN_disconnect(vpn_handle); |
2927 | vpn_handle = NULL; | 2935 | vpn_handle = NULL; |
2928 | dht_handle = NULL; | 2936 | dht_handle = NULL; |
2929 | namecache_handle = NULL; | 2937 | namecache_handle = NULL; |