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