aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-04 11:57:59 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-04 11:57:59 +0200
commit58002acac13b2eef407a20ee3ddc5f458cd5e483 (patch)
tree8285fc1b32a8c9ac55f970667e7d29b791b6758e /src/namestore
parent9ce956ea4c93f038995a21c6c1c0133eee6bff75 (diff)
downloadgnunet-58002acac13b2eef407a20ee3ddc5f458cd5e483.tar.gz
gnunet-58002acac13b2eef407a20ee3ddc5f458cd5e483.zip
nicer loop structure
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-zoneimport.c844
1 files changed, 321 insertions, 523 deletions
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c
index f36106332..4c5205ab3 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.c
@@ -56,7 +56,8 @@
56/** 56/**
57 * How long do we wait at least between series of requests? 57 * How long do we wait at least between series of requests?
58 */ 58 */
59#define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) 59#define SERIES_DELAY \
60 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10)
60 61
61/** 62/**
62 * How long do DNS records have to last at least after being imported? 63 * How long do DNS records have to last at least after being imported?
@@ -97,7 +98,6 @@ struct Zone
97 * Private key of the zone. 98 * Private key of the zone.
98 */ 99 */
99 struct GNUNET_CRYPTO_EcdsaPrivateKey key; 100 struct GNUNET_CRYPTO_EcdsaPrivateKey key;
100
101}; 101};
102 102
103 103
@@ -120,7 +120,6 @@ struct Record
120 * GNS record. 120 * GNS record.
121 */ 121 */
122 struct GNUNET_GNSRECORD_Data grd; 122 struct GNUNET_GNSRECORD_Data grd;
123
124}; 123};
125 124
126 125
@@ -367,9 +366,8 @@ static struct GNUNET_TIME_Relative idle_time;
367 * @param cls closure 366 * @param cls closure
368 * @param rec a DNS record 367 * @param rec a DNS record
369 */ 368 */
370typedef void 369typedef void (*RecordProcessor) (void *cls,
371(*RecordProcessor) (void *cls, 370 const struct GNUNET_DNSPARSER_Record *rec);
372 const struct GNUNET_DNSPARSER_Record *rec);
373 371
374 372
375/** 373/**
@@ -382,29 +380,26 @@ typedef void
382 */ 380 */
383static void 381static void
384for_all_records (const struct GNUNET_DNSPARSER_Packet *p, 382for_all_records (const struct GNUNET_DNSPARSER_Packet *p,
385 RecordProcessor rp, 383 RecordProcessor rp,
386 void *rp_cls) 384 void *rp_cls)
387{ 385{
388 for (unsigned int i=0;i<p->num_answers;i++) 386 for (unsigned int i = 0; i < p->num_answers; i++)
389 { 387 {
390 struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; 388 struct GNUNET_DNSPARSER_Record *rs = &p->answers[i];
391 389
392 rp (rp_cls, 390 rp (rp_cls, rs);
393 rs);
394 } 391 }
395 for (unsigned int i=0;i<p->num_authority_records;i++) 392 for (unsigned int i = 0; i < p->num_authority_records; i++)
396 { 393 {
397 struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; 394 struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i];
398 395
399 rp (rp_cls, 396 rp (rp_cls, rs);
400 rs);
401 } 397 }
402 for (unsigned int i=0;i<p->num_additional_records;i++) 398 for (unsigned int i = 0; i < p->num_additional_records; i++)
403 { 399 {
404 struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; 400 struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i];
405 401
406 rp (rp_cls, 402 rp (rp_cls, rs);
407 rs);
408 } 403 }
409} 404}
410 405
@@ -422,8 +417,7 @@ get_label (struct Request *req)
422 static char label[64]; 417 static char label[64];
423 const char *dot; 418 const char *dot;
424 419
425 dot = strchr (req->hostname, 420 dot = strchr (req->hostname, (unsigned char) '.');
426 (unsigned char) '.');
427 if (NULL == dot) 421 if (NULL == dot)
428 { 422 {
429 GNUNET_break (0); 423 GNUNET_break (0);
@@ -434,9 +428,7 @@ get_label (struct Request *req)
434 GNUNET_break (0); 428 GNUNET_break (0);
435 return NULL; 429 return NULL;
436 } 430 }
437 GNUNET_memcpy (label, 431 GNUNET_memcpy (label, req->hostname, dot - req->hostname);
438 req->hostname,
439 dot - req->hostname);
440 label[dot - req->hostname] = '\0'; 432 label[dot - req->hostname] = '\0';
441 return label; 433 return label;
442} 434}
@@ -451,8 +443,7 @@ get_label (struct Request *req)
451 * allocated query buffer 443 * allocated query buffer
452 */ 444 */
453static void * 445static void *
454build_dns_query (struct Request *req, 446build_dns_query (struct Request *req, size_t *raw_size)
455 size_t *raw_size)
456{ 447{
457 static char raw[512]; 448 static char raw[512];
458 char *rawp; 449 char *rawp;
@@ -464,16 +455,11 @@ build_dns_query (struct Request *req,
464 q.type = GNUNET_DNSPARSER_TYPE_NS; 455 q.type = GNUNET_DNSPARSER_TYPE_NS;
465 q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; 456 q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
466 457
467 memset (&p, 458 memset (&p, 0, sizeof (p));
468 0,
469 sizeof (p));
470 p.num_queries = 1; 459 p.num_queries = 1;
471 p.queries = &q; 460 p.queries = &q;
472 p.id = req->id; 461 p.id = req->id;
473 ret = GNUNET_DNSPARSER_pack (&p, 462 ret = GNUNET_DNSPARSER_pack (&p, UINT16_MAX, &rawp, raw_size);
474 UINT16_MAX,
475 &rawp,
476 raw_size);
477 if (GNUNET_OK != ret) 463 if (GNUNET_OK != ret)
478 { 464 {
479 if (GNUNET_NO == ret) 465 if (GNUNET_NO == ret)
@@ -494,15 +480,12 @@ build_dns_query (struct Request *req,
494 GNUNET_free (rawp); 480 GNUNET_free (rawp);
495 return NULL; 481 return NULL;
496 } 482 }
497 GNUNET_memcpy (raw, 483 GNUNET_memcpy (raw, rawp, *raw_size);
498 rawp,
499 *raw_size);
500 GNUNET_free (rawp); 484 GNUNET_free (rawp);
501 return raw; 485 return raw;
502} 486}
503 487
504 488
505
506/** 489/**
507 * Free records associated with @a req. 490 * Free records associated with @a req.
508 * 491 *
@@ -516,9 +499,7 @@ free_records (struct Request *req)
516 /* Free records */ 499 /* Free records */
517 while (NULL != (rec = req->rec_head)) 500 while (NULL != (rec = req->rec_head))
518 { 501 {
519 GNUNET_CONTAINER_DLL_remove (req->rec_head, 502 GNUNET_CONTAINER_DLL_remove (req->rec_head, req->rec_tail, rec);
520 req->rec_tail,
521 rec);
522 GNUNET_free (rec); 503 GNUNET_free (rec);
523 } 504 }
524} 505}
@@ -554,17 +535,14 @@ process_queue (void *cls);
554static void 535static void
555insert_sorted (struct Request *req) 536insert_sorted (struct Request *req)
556{ 537{
557 req->hn = GNUNET_CONTAINER_heap_insert (req_heap, 538 req->hn =
558 req, 539 GNUNET_CONTAINER_heap_insert (req_heap, req, req->expires.abs_value_us);
559 req->expires.abs_value_us);
560 if (req == GNUNET_CONTAINER_heap_peek (req_heap)) 540 if (req == GNUNET_CONTAINER_heap_peek (req_heap))
561 { 541 {
562 if (NULL != t) 542 if (NULL != t)
563 GNUNET_SCHEDULER_cancel (t); 543 GNUNET_SCHEDULER_cancel (t);
564 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 544 sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
565 t = GNUNET_SCHEDULER_add_at (req->expires, 545 t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL);
566 &process_queue,
567 NULL);
568 } 546 }
569} 547}
570 548
@@ -580,10 +558,10 @@ insert_sorted (struct Request *req)
580 */ 558 */
581static void 559static void
582add_record (struct Request *req, 560add_record (struct Request *req,
583 uint32_t type, 561 uint32_t type,
584 struct GNUNET_TIME_Absolute expiration_time, 562 struct GNUNET_TIME_Absolute expiration_time,
585 const void *data, 563 const void *data,
586 size_t data_len) 564 size_t data_len)
587{ 565{
588 struct Record *rec; 566 struct Record *rec;
589 567
@@ -593,12 +571,8 @@ add_record (struct Request *req,
593 rec->grd.data_size = data_len; 571 rec->grd.data_size = data_len;
594 rec->grd.record_type = type; 572 rec->grd.record_type = type;
595 rec->grd.flags = GNUNET_GNSRECORD_RF_NONE; 573 rec->grd.flags = GNUNET_GNSRECORD_RF_NONE;
596 GNUNET_memcpy (&rec[1], 574 GNUNET_memcpy (&rec[1], data, data_len);
597 data, 575 GNUNET_CONTAINER_DLL_insert (req->rec_head, req->rec_tail, rec);
598 data_len);
599 GNUNET_CONTAINER_DLL_insert (req->rec_head,
600 req->rec_tail,
601 rec);
602} 576}
603 577
604 578
@@ -631,20 +605,18 @@ struct GlueClosure
631 * @param rec record that may contain glue information 605 * @param rec record that may contain glue information
632 */ 606 */
633static void 607static void
634check_for_glue (void *cls, 608check_for_glue (void *cls, const struct GNUNET_DNSPARSER_Record *rec)
635 const struct GNUNET_DNSPARSER_Record *rec)
636{ 609{
637 struct GlueClosure *gc = cls; 610 struct GlueClosure *gc = cls;
638 char dst[65536]; 611 char dst[65536];
639 size_t dst_len; 612 size_t dst_len;
640 size_t off; 613 size_t off;
641 char ip[INET6_ADDRSTRLEN+1]; 614 char ip[INET6_ADDRSTRLEN + 1];
642 socklen_t ip_size = (socklen_t) sizeof (ip); 615 socklen_t ip_size = (socklen_t) sizeof (ip);
643 struct GNUNET_TIME_Absolute expiration_time; 616 struct GNUNET_TIME_Absolute expiration_time;
644 struct GNUNET_TIME_Relative left; 617 struct GNUNET_TIME_Relative left;
645 618
646 if (0 != strcasecmp (rec->name, 619 if (0 != strcasecmp (rec->name, gc->ns))
647 gc->ns))
648 return; 620 return;
649 expiration_time = rec->expiration_time; 621 expiration_time = rec->expiration_time;
650 left = GNUNET_TIME_absolute_get_remaining (expiration_time); 622 left = GNUNET_TIME_absolute_get_remaining (expiration_time);
@@ -652,7 +624,8 @@ check_for_glue (void *cls,
652 return; /* ignore expired glue records */ 624 return; /* ignore expired glue records */
653 /* if expiration window is too short, bump it to configured minimum */ 625 /* if expiration window is too short, bump it to configured minimum */
654 if (left.rel_value_us < minimum_expiration_time.rel_value_us) 626 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
655 expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time); 627 expiration_time =
628 GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
656 dst_len = sizeof (dst); 629 dst_len = sizeof (dst);
657 off = 0; 630 off = 0;
658 switch (rec->type) 631 switch (rec->type)
@@ -663,31 +636,23 @@ check_for_glue (void *cls,
663 GNUNET_break (0); 636 GNUNET_break (0);
664 return; 637 return;
665 } 638 }
666 if (NULL == 639 if (NULL == inet_ntop (AF_INET, rec->data.raw.data, ip, ip_size))
667 inet_ntop (AF_INET,
668 rec->data.raw.data,
669 ip,
670 ip_size))
671 { 640 {
672 GNUNET_break (0); 641 GNUNET_break (0);
673 return; 642 return;
674 } 643 }
675 if ( (GNUNET_OK == 644 if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
676 GNUNET_DNSPARSER_builder_add_name (dst, 645 dst_len,
677 dst_len, 646 &off,
678 &off, 647 gc->req->hostname)) &&
679 gc->req->hostname)) && 648 (GNUNET_OK ==
680 (GNUNET_OK == 649 GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip)))
681 GNUNET_DNSPARSER_builder_add_name (dst,
682 dst_len,
683 &off,
684 ip)) )
685 { 650 {
686 add_record (gc->req, 651 add_record (gc->req,
687 GNUNET_GNSRECORD_TYPE_GNS2DNS, 652 GNUNET_GNSRECORD_TYPE_GNS2DNS,
688 expiration_time, 653 expiration_time,
689 dst, 654 dst,
690 off); 655 off);
691 gc->found = GNUNET_YES; 656 gc->found = GNUNET_YES;
692 } 657 }
693 break; 658 break;
@@ -697,51 +662,41 @@ check_for_glue (void *cls,
697 GNUNET_break (0); 662 GNUNET_break (0);
698 return; 663 return;
699 } 664 }
700 if (NULL == 665 if (NULL == inet_ntop (AF_INET6, rec->data.raw.data, ip, ip_size))
701 inet_ntop (AF_INET6,
702 rec->data.raw.data,
703 ip,
704 ip_size))
705 { 666 {
706 GNUNET_break (0); 667 GNUNET_break (0);
707 return; 668 return;
708 } 669 }
709 if ( (GNUNET_OK == 670 if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
710 GNUNET_DNSPARSER_builder_add_name (dst, 671 dst_len,
711 dst_len, 672 &off,
712 &off, 673 gc->req->hostname)) &&
713 gc->req->hostname)) && 674 (GNUNET_OK ==
714 (GNUNET_OK == 675 GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip)))
715 GNUNET_DNSPARSER_builder_add_name (dst,
716 dst_len,
717 &off,
718 ip)) )
719 { 676 {
720 add_record (gc->req, 677 add_record (gc->req,
721 GNUNET_GNSRECORD_TYPE_GNS2DNS, 678 GNUNET_GNSRECORD_TYPE_GNS2DNS,
722 expiration_time, 679 expiration_time,
723 dst, 680 dst,
724 off); 681 off);
725 gc->found = GNUNET_YES; 682 gc->found = GNUNET_YES;
726 } 683 }
727 break; 684 break;
728 case GNUNET_DNSPARSER_TYPE_CNAME: 685 case GNUNET_DNSPARSER_TYPE_CNAME:
729 if ( (GNUNET_OK == 686 if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
730 GNUNET_DNSPARSER_builder_add_name (dst, 687 dst_len,
731 dst_len, 688 &off,
732 &off, 689 gc->req->hostname)) &&
733 gc->req->hostname)) && 690 (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
734 (GNUNET_OK == 691 dst_len,
735 GNUNET_DNSPARSER_builder_add_name (dst, 692 &off,
736 dst_len, 693 rec->data.hostname)))
737 &off,
738 rec->data.hostname)) )
739 { 694 {
740 add_record (gc->req, 695 add_record (gc->req,
741 GNUNET_GNSRECORD_TYPE_GNS2DNS, 696 GNUNET_GNSRECORD_TYPE_GNS2DNS,
742 expiration_time, 697 expiration_time,
743 dst, 698 dst,
744 off); 699 off);
745 gc->found = GNUNET_YES; 700 gc->found = GNUNET_YES;
746 } 701 }
747 break; 702 break;
@@ -777,8 +732,7 @@ struct ProcessRecordContext
777 * @param rec response 732 * @param rec response
778 */ 733 */
779static void 734static void
780process_record (void *cls, 735process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec)
781 const struct GNUNET_DNSPARSER_Record *rec)
782{ 736{
783 struct ProcessRecordContext *prc = cls; 737 struct ProcessRecordContext *prc = cls;
784 struct Request *req = prc->req; 738 struct Request *req = prc->req;
@@ -791,14 +745,14 @@ process_record (void *cls,
791 dst_len = sizeof (dst); 745 dst_len = sizeof (dst);
792 off = 0; 746 off = 0;
793 records++; 747 records++;
794 if (0 != strcasecmp (rec->name, 748 if (0 != strcasecmp (rec->name, req->hostname))
795 req->hostname))
796 { 749 {
797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 750 GNUNET_log (
798 "DNS returned record from zone `%s' of type %u while resolving `%s'\n", 751 GNUNET_ERROR_TYPE_DEBUG,
799 rec->name, 752 "DNS returned record from zone `%s' of type %u while resolving `%s'\n",
800 (unsigned int) rec->type, 753 rec->name,
801 req->hostname); 754 (unsigned int) rec->type,
755 req->hostname);
802 return; /* does not match hostname, might be glue, but 756 return; /* does not match hostname, might be glue, but
803 not useful for this pass! */ 757 not useful for this pass! */
804 } 758 }
@@ -807,8 +761,8 @@ process_record (void *cls,
807 if (0 == left.rel_value_us) 761 if (0 == left.rel_value_us)
808 { 762 {
809 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
810 "DNS returned expired record for `%s'\n", 764 "DNS returned expired record for `%s'\n",
811 req->hostname); 765 req->hostname);
812 GNUNET_STATISTICS_update (stats, 766 GNUNET_STATISTICS_update (stats,
813 "# expired records obtained from DNS", 767 "# expired records obtained from DNS",
814 1, 768 1,
@@ -822,68 +776,59 @@ process_record (void *cls,
822 req->hostname); 776 req->hostname);
823 /* if expiration window is too short, bump it to configured minimum */ 777 /* if expiration window is too short, bump it to configured minimum */
824 if (left.rel_value_us < minimum_expiration_time.rel_value_us) 778 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
825 expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time); 779 expiration_time =
780 GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
826 switch (rec->type) 781 switch (rec->type)
827 { 782 {
828 case GNUNET_DNSPARSER_TYPE_NS: 783 case GNUNET_DNSPARSER_TYPE_NS: {
784 struct GlueClosure gc;
785
786 /* check for glue */
787 gc.req = req;
788 gc.ns = rec->data.hostname;
789 gc.found = GNUNET_NO;
790 for_all_records (prc->p, &check_for_glue, &gc);
791 if ((GNUNET_NO == gc.found) &&
792 (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
793 dst_len,
794 &off,
795 req->hostname)) &&
796 (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
797 dst_len,
798 &off,
799 rec->data.hostname)))
829 { 800 {
830 struct GlueClosure gc; 801 /* FIXME: actually check if this is out-of-bailiwick,
831
832 /* check for glue */
833 gc.req = req;
834 gc.ns = rec->data.hostname;
835 gc.found = GNUNET_NO;
836 for_all_records (prc->p,
837 &check_for_glue,
838 &gc);
839 if ( (GNUNET_NO == gc.found) &&
840 (GNUNET_OK ==
841 GNUNET_DNSPARSER_builder_add_name (dst,
842 dst_len,
843 &off,
844 req->hostname)) &&
845 (GNUNET_OK ==
846 GNUNET_DNSPARSER_builder_add_name (dst,
847 dst_len,
848 &off,
849 rec->data.hostname)) )
850 {
851 /* FIXME: actually check if this is out-of-bailiwick,
852 and if not request explicit resolution... */ 802 and if not request explicit resolution... */
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
854 "Converted OOB (`%s') NS record for `%s'\n", 804 "Converted OOB (`%s') NS record for `%s'\n",
855 rec->data.hostname, 805 rec->data.hostname,
856 rec->name); 806 rec->name);
857 add_record (req, 807 add_record (req,
858 GNUNET_GNSRECORD_TYPE_GNS2DNS, 808 GNUNET_GNSRECORD_TYPE_GNS2DNS,
859 expiration_time, 809 expiration_time,
860 dst, 810 dst,
861 off); 811 off);
862 } 812 }
863 else 813 else
864 { 814 {
865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
866 "Converted NS record for `%s' using glue\n", 816 "Converted NS record for `%s' using glue\n",
867 rec->name); 817 rec->name);
868 }
869 break;
870 } 818 }
819 break;
820 }
871 case GNUNET_DNSPARSER_TYPE_CNAME: 821 case GNUNET_DNSPARSER_TYPE_CNAME:
872 if (GNUNET_OK == 822 if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
873 GNUNET_DNSPARSER_builder_add_name (dst, 823 dst_len,
874 dst_len, 824 &off,
875 &off, 825 rec->data.hostname))
876 rec->data.hostname))
877 { 826 {
878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
879 "Converting CNAME (`%s') record for `%s'\n", 828 "Converting CNAME (`%s') record for `%s'\n",
880 rec->data.hostname, 829 rec->data.hostname,
881 rec->name); 830 rec->name);
882 add_record (req, 831 add_record (req, rec->type, expiration_time, dst, off);
883 rec->type,
884 expiration_time,
885 dst,
886 off);
887 } 832 }
888 break; 833 break;
889 case GNUNET_DNSPARSER_TYPE_DNAME: 834 case GNUNET_DNSPARSER_TYPE_DNAME:
@@ -895,90 +840,57 @@ process_record (void *cls,
895 break; 840 break;
896 case GNUNET_DNSPARSER_TYPE_MX: 841 case GNUNET_DNSPARSER_TYPE_MX:
897 if (GNUNET_OK == 842 if (GNUNET_OK ==
898 GNUNET_DNSPARSER_builder_add_mx (dst, 843 GNUNET_DNSPARSER_builder_add_mx (dst, dst_len, &off, rec->data.mx))
899 dst_len,
900 &off,
901 rec->data.mx))
902 { 844 {
903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
904 "Converting MX (`%s') record for `%s'\n", 846 "Converting MX (`%s') record for `%s'\n",
905 rec->data.mx->mxhost, 847 rec->data.mx->mxhost,
906 rec->name); 848 rec->name);
907 add_record (req, 849 add_record (req, rec->type, expiration_time, dst, off);
908 rec->type,
909 expiration_time,
910 dst,
911 off);
912 } 850 }
913 break; 851 break;
914 case GNUNET_DNSPARSER_TYPE_SOA: 852 case GNUNET_DNSPARSER_TYPE_SOA:
915 if (GNUNET_OK == 853 if (GNUNET_OK ==
916 GNUNET_DNSPARSER_builder_add_soa (dst, 854 GNUNET_DNSPARSER_builder_add_soa (dst, dst_len, &off, rec->data.soa))
917 dst_len,
918 &off,
919 rec->data.soa))
920 { 855 {
921 /* NOTE: GNS does not really use SOAs */ 856 /* NOTE: GNS does not really use SOAs */
922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
923 "Converting SOA record for `%s'\n", 858 "Converting SOA record for `%s'\n",
924 rec->name); 859 rec->name);
925 add_record (req, 860 add_record (req, rec->type, expiration_time, dst, off);
926 rec->type,
927 expiration_time,
928 dst,
929 off);
930 } 861 }
931 break; 862 break;
932 case GNUNET_DNSPARSER_TYPE_SRV: 863 case GNUNET_DNSPARSER_TYPE_SRV:
933 if (GNUNET_OK == 864 if (GNUNET_OK ==
934 GNUNET_DNSPARSER_builder_add_srv (dst, 865 GNUNET_DNSPARSER_builder_add_srv (dst, dst_len, &off, rec->data.srv))
935 dst_len,
936 &off,
937 rec->data.srv))
938 { 866 {
939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
940 "Converting SRV record for `%s'\n", 868 "Converting SRV record for `%s'\n",
941 rec->name); 869 rec->name);
942 add_record (req, 870 add_record (req, rec->type, expiration_time, dst, off);
943 rec->type,
944 expiration_time,
945 dst,
946 off);
947 } 871 }
948 break; 872 break;
949 case GNUNET_DNSPARSER_TYPE_PTR: 873 case GNUNET_DNSPARSER_TYPE_PTR:
950 if (GNUNET_OK == 874 if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
951 GNUNET_DNSPARSER_builder_add_name (dst, 875 dst_len,
952 dst_len, 876 &off,
953 &off, 877 rec->data.hostname))
954 rec->data.hostname))
955 { 878 {
956 /* !?: what does a PTR record do in a regular TLD??? */ 879 /* !?: what does a PTR record do in a regular TLD??? */
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
958 "Converting PTR record for `%s' (weird)\n", 881 "Converting PTR record for `%s' (weird)\n",
959 rec->name); 882 rec->name);
960 add_record (req, 883 add_record (req, rec->type, expiration_time, dst, off);
961 rec->type,
962 expiration_time,
963 dst,
964 off);
965 } 884 }
966 break; 885 break;
967 case GNUNET_DNSPARSER_TYPE_CERT: 886 case GNUNET_DNSPARSER_TYPE_CERT:
968 if (GNUNET_OK == 887 if (GNUNET_OK ==
969 GNUNET_DNSPARSER_builder_add_cert (dst, 888 GNUNET_DNSPARSER_builder_add_cert (dst, dst_len, &off, rec->data.cert))
970 dst_len,
971 &off,
972 rec->data.cert))
973 { 889 {
974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
975 "Converting CERT record for `%s'\n", 891 "Converting CERT record for `%s'\n",
976 rec->name); 892 rec->name);
977 add_record (req, 893 add_record (req, rec->type, expiration_time, dst, off);
978 rec->type,
979 expiration_time,
980 dst,
981 off);
982 } 894 }
983 break; 895 break;
984 /* Rest is 'raw' encoded and just needs to be copied IF 896 /* Rest is 'raw' encoded and just needs to be copied IF
@@ -989,14 +901,14 @@ process_record (void *cls,
989 case GNUNET_DNSPARSER_TYPE_TXT: 901 case GNUNET_DNSPARSER_TYPE_TXT:
990 default: 902 default:
991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
992 "Converting record of type %u for `%s'\n", 904 "Converting record of type %u for `%s'\n",
993 (unsigned int) rec->type, 905 (unsigned int) rec->type,
994 rec->name); 906 rec->name);
995 add_record (req, 907 add_record (req,
996 rec->type, 908 rec->type,
997 expiration_time, 909 expiration_time,
998 rec->data.raw.data, 910 rec->data.raw.data,
999 rec->data.raw.data_len); 911 rec->data.raw.data_len);
1000 break; 912 break;
1001 } 913 }
1002} 914}
@@ -1013,9 +925,7 @@ process_record (void *cls,
1013 * @param emsg NULL on success, otherwise an error message 925 * @param emsg NULL on success, otherwise an error message
1014 */ 926 */
1015static void 927static void
1016store_completed_cb (void *cls, 928store_completed_cb (void *cls, int32_t success, const char *emsg)
1017 int32_t success,
1018 const char *emsg)
1019{ 929{
1020 static struct GNUNET_TIME_Absolute last; 930 static struct GNUNET_TIME_Absolute last;
1021 struct Request *req = cls; 931 struct Request *req = cls;
@@ -1024,15 +934,15 @@ store_completed_cb (void *cls,
1024 if (GNUNET_SYSERR == success) 934 if (GNUNET_SYSERR == success)
1025 { 935 {
1026 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 936 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1027 "Failed to store zone data for `%s': %s\n", 937 "Failed to store zone data for `%s': %s\n",
1028 req->hostname, 938 req->hostname,
1029 emsg); 939 emsg);
1030 } 940 }
1031 else 941 else
1032 { 942 {
1033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 943 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1034 "Stored records under `%s' (%d)\n", 944 "Stored records under `%s' (%d)\n",
1035 req->hostname, 945 req->hostname,
1036 success); 946 success);
1037 } 947 }
1038 total_reg_proc_dns_ns++; /* finished regular processing */ 948 total_reg_proc_dns_ns++; /* finished regular processing */
@@ -1045,8 +955,7 @@ store_completed_cb (void *cls,
1045 struct GNUNET_TIME_Relative ns_latency; 955 struct GNUNET_TIME_Relative ns_latency;
1046 956
1047 ns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); 957 ns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time);
1048 total_ns_latency = GNUNET_TIME_relative_add (total_ns_latency, 958 total_ns_latency = GNUNET_TIME_relative_add (total_ns_latency, ns_latency);
1049 ns_latency);
1050 if (0 == total_ns_latency_cnt) 959 if (0 == total_ns_latency_cnt)
1051 last = GNUNET_TIME_absolute_get (); 960 last = GNUNET_TIME_absolute_get ();
1052 total_ns_latency_cnt++; 961 total_ns_latency_cnt++;
@@ -1057,25 +966,25 @@ store_completed_cb (void *cls,
1057 delta = GNUNET_TIME_absolute_get_duration (last); 966 delta = GNUNET_TIME_absolute_get_duration (last);
1058 last = GNUNET_TIME_absolute_get (); 967 last = GNUNET_TIME_absolute_get ();
1059 fprintf (stderr, 968 fprintf (stderr,
1060 "Processed 1000 records in %s\n", 969 "Processed 1000 records in %s\n",
1061 GNUNET_STRINGS_relative_time_to_string (delta, 970 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
1062 GNUNET_YES));
1063 GNUNET_STATISTICS_set (stats, 971 GNUNET_STATISTICS_set (stats,
1064 "# average NAMESTORE PUT latency (μs)", 972 "# average NAMESTORE PUT latency (μs)",
1065 total_ns_latency.rel_value_us / total_ns_latency_cnt, 973 total_ns_latency.rel_value_us /
974 total_ns_latency_cnt,
1066 GNUNET_NO); 975 GNUNET_NO);
1067 } 976 }
1068 } 977 }
1069 /* compute and publish overall velocity */ 978 /* compute and publish overall velocity */
1070 if (0 == (total_reg_proc_dns_ns % 100) ) 979 if (0 == (total_reg_proc_dns_ns % 100))
1071 { 980 {
1072 struct GNUNET_TIME_Relative runtime; 981 struct GNUNET_TIME_Relative runtime;
1073 982
1074 runtime = GNUNET_TIME_absolute_get_duration (start_time_reg_proc); 983 runtime = GNUNET_TIME_absolute_get_duration (start_time_reg_proc);
1075 runtime = GNUNET_TIME_relative_subtract (runtime, 984 runtime = GNUNET_TIME_relative_subtract (runtime, idle_time);
1076 idle_time); 985 runtime =
1077 runtime = GNUNET_TIME_relative_divide (runtime, 986 GNUNET_TIME_relative_divide (runtime,
1078 total_reg_proc_dns + total_reg_proc_dns_ns); 987 total_reg_proc_dns + total_reg_proc_dns_ns);
1079 GNUNET_STATISTICS_set (stats, 988 GNUNET_STATISTICS_set (stats,
1080 "# Regular processing completed without NAMESTORE", 989 "# Regular processing completed without NAMESTORE",
1081 total_reg_proc_dns, 990 total_reg_proc_dns,
@@ -1097,8 +1006,7 @@ store_completed_cb (void *cls,
1097 if (NULL == t) 1006 if (NULL == t)
1098 { 1007 {
1099 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 1008 sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
1100 t = GNUNET_SCHEDULER_add_now (&process_queue, 1009 t = GNUNET_SCHEDULER_add_now (&process_queue, NULL);
1101 NULL);
1102 } 1010 }
1103} 1011}
1104 1012
@@ -1124,31 +1032,22 @@ process_result (void *cls,
1124 if (NULL == dns) 1032 if (NULL == dns)
1125 { 1033 {
1126 /* stub gave up */ 1034 /* stub gave up */
1127 GNUNET_CONTAINER_DLL_remove (req_head, 1035 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req);
1128 req_tail,
1129 req);
1130 pending--; 1036 pending--;
1131 if (NULL == t) 1037 if (NULL == t)
1132 { 1038 {
1133 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 1039 sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
1134 t = GNUNET_SCHEDULER_add_now (&process_queue, 1040 t = GNUNET_SCHEDULER_add_now (&process_queue, NULL);
1135 NULL);
1136 } 1041 }
1137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1042 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1138 "Stub gave up on DNS reply for `%s'\n", 1043 "Stub gave up on DNS reply for `%s'\n",
1139 req->hostname); 1044 req->hostname);
1140 GNUNET_STATISTICS_update (stats, 1045 GNUNET_STATISTICS_update (stats, "# DNS lookups timed out", 1, GNUNET_NO);
1141 "# DNS lookups timed out",
1142 1,
1143 GNUNET_NO);
1144 if (req->issue_num > MAX_RETRIES) 1046 if (req->issue_num > MAX_RETRIES)
1145 { 1047 {
1146 failures++; 1048 failures++;
1147 free_request (req); 1049 free_request (req);
1148 GNUNET_STATISTICS_update (stats, 1050 GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO);
1149 "# requests given up on",
1150 1,
1151 GNUNET_NO);
1152 return; 1051 return;
1153 } 1052 }
1154 total_reg_proc_dns++; 1053 total_reg_proc_dns++;
@@ -1160,43 +1059,30 @@ process_result (void *cls,
1160 { 1059 {
1161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1162 "DNS ID did not match request, ignoring reply\n"); 1061 "DNS ID did not match request, ignoring reply\n");
1163 GNUNET_STATISTICS_update (stats, 1062 GNUNET_STATISTICS_update (stats, "# DNS ID mismatches", 1, GNUNET_NO);
1164 "# DNS ID mismatches",
1165 1,
1166 GNUNET_NO);
1167 return; 1063 return;
1168 } 1064 }
1169 GNUNET_CONTAINER_DLL_remove (req_head, 1065 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req);
1170 req_tail,
1171 req);
1172 GNUNET_DNSSTUB_resolve_cancel (req->rs); 1066 GNUNET_DNSSTUB_resolve_cancel (req->rs);
1173 req->rs = NULL; 1067 req->rs = NULL;
1174 pending--; 1068 pending--;
1175 p = GNUNET_DNSPARSER_parse ((const char *) dns, 1069 p = GNUNET_DNSPARSER_parse ((const char *) dns, dns_len);
1176 dns_len);
1177 if (NULL == p) 1070 if (NULL == p)
1178 { 1071 {
1179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1072 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1180 "Failed to parse DNS reply for `%s'\n", 1073 "Failed to parse DNS reply for `%s'\n",
1181 req->hostname); 1074 req->hostname);
1182 GNUNET_STATISTICS_update (stats, 1075 GNUNET_STATISTICS_update (stats, "# DNS parser errors", 1, GNUNET_NO);
1183 "# DNS parser errors",
1184 1,
1185 GNUNET_NO);
1186 if (NULL == t) 1076 if (NULL == t)
1187 { 1077 {
1188 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 1078 sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
1189 t = GNUNET_SCHEDULER_add_now (&process_queue, 1079 t = GNUNET_SCHEDULER_add_now (&process_queue, NULL);
1190 NULL);
1191 } 1080 }
1192 if (req->issue_num > MAX_RETRIES) 1081 if (req->issue_num > MAX_RETRIES)
1193 { 1082 {
1194 failures++; 1083 failures++;
1195 free_request (req); 1084 free_request (req);
1196 GNUNET_STATISTICS_update (stats, 1085 GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO);
1197 "# requests given up on",
1198 1,
1199 GNUNET_NO);
1200 return; 1086 return;
1201 } 1087 }
1202 insert_sorted (req); 1088 insert_sorted (req);
@@ -1205,14 +1091,9 @@ process_result (void *cls,
1205 /* import new records */ 1091 /* import new records */
1206 req->issue_num = 0; /* success, reset counter! */ 1092 req->issue_num = 0; /* success, reset counter! */
1207 { 1093 {
1208 struct ProcessRecordContext prc = { 1094 struct ProcessRecordContext prc = {.req = req, .p = p};
1209 .req = req, 1095
1210 .p = p 1096 for_all_records (p, &process_record, &prc);
1211 };
1212
1213 for_all_records (p,
1214 &process_record,
1215 &prc);
1216 } 1097 }
1217 GNUNET_DNSPARSER_free_packet (p); 1098 GNUNET_DNSPARSER_free_packet (p);
1218 /* count records found, determine minimum expiration time */ 1099 /* count records found, determine minimum expiration time */
@@ -1221,14 +1102,15 @@ process_result (void *cls,
1221 struct GNUNET_TIME_Relative dns_latency; 1102 struct GNUNET_TIME_Relative dns_latency;
1222 1103
1223 dns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); 1104 dns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time);
1224 total_dns_latency = GNUNET_TIME_relative_add (total_dns_latency, 1105 total_dns_latency =
1225 dns_latency); 1106 GNUNET_TIME_relative_add (total_dns_latency, dns_latency);
1226 total_dns_latency_cnt++; 1107 total_dns_latency_cnt++;
1227 if (0 == (total_dns_latency_cnt % 1000)) 1108 if (0 == (total_dns_latency_cnt % 1000))
1228 { 1109 {
1229 GNUNET_STATISTICS_set (stats, 1110 GNUNET_STATISTICS_set (stats,
1230 "# average DNS lookup latency (μs)", 1111 "# average DNS lookup latency (μs)",
1231 total_dns_latency.rel_value_us / total_dns_latency_cnt, 1112 total_dns_latency.rel_value_us /
1113 total_dns_latency_cnt,
1232 GNUNET_NO); 1114 GNUNET_NO);
1233 } 1115 }
1234 } 1116 }
@@ -1238,20 +1120,18 @@ process_result (void *cls,
1238 struct GNUNET_TIME_Absolute at; 1120 struct GNUNET_TIME_Absolute at;
1239 1121
1240 at.abs_value_us = rec->grd.expiration_time; 1122 at.abs_value_us = rec->grd.expiration_time;
1241 req->expires = GNUNET_TIME_absolute_min (req->expires, 1123 req->expires = GNUNET_TIME_absolute_min (req->expires, at);
1242 at);
1243 rd_count++; 1124 rd_count++;
1244 } 1125 }
1245 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1126 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1246 "Obtained %u records for `%s'\n", 1127 "Obtained %u records for `%s'\n",
1247 rd_count, 1128 rd_count,
1248 req->hostname); 1129 req->hostname);
1249 /* Instead of going for SOA, simplified for now to look each 1130 /* Instead of going for SOA, simplified for now to look each
1250 day in case we got an empty response */ 1131 day in case we got an empty response */
1251 if (0 == rd_count) 1132 if (0 == rd_count)
1252 { 1133 {
1253 req->expires 1134 req->expires = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS);
1254 = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS);
1255 GNUNET_STATISTICS_update (stats, 1135 GNUNET_STATISTICS_update (stats,
1256 "# empty DNS replies (usually NXDOMAIN)", 1136 "# empty DNS replies (usually NXDOMAIN)",
1257 1, 1137 1,
@@ -1263,21 +1143,21 @@ process_result (void *cls,
1263 } 1143 }
1264 /* convert records to namestore import format */ 1144 /* convert records to namestore import format */
1265 { 1145 {
1266 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; 1146 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)];
1267 unsigned int off = 0; 1147 unsigned int off = 0;
1268 1148
1269 /* convert linked list into array */ 1149 /* convert linked list into array */
1270 for (rec = req->rec_head; NULL != rec; rec =rec->next) 1150 for (rec = req->rec_head; NULL != rec; rec = rec->next)
1271 rd[off++] = rec->grd; 1151 rd[off++] = rec->grd;
1272 pending_rs++; 1152 pending_rs++;
1273 req->op_start_time = GNUNET_TIME_absolute_get (); 1153 req->op_start_time = GNUNET_TIME_absolute_get ();
1274 req->qe = GNUNET_NAMESTORE_records_store (ns, 1154 req->qe = GNUNET_NAMESTORE_records_store (ns,
1275 &req->zone->key, 1155 &req->zone->key,
1276 get_label (req), 1156 get_label (req),
1277 rd_count, 1157 rd_count,
1278 rd, 1158 rd,
1279 &store_completed_cb, 1159 &store_completed_cb,
1280 req); 1160 req);
1281 GNUNET_assert (NULL != req->qe); 1161 GNUNET_assert (NULL != req->qe);
1282 } 1162 }
1283 insert_sorted (req); 1163 insert_sorted (req);
@@ -1300,8 +1180,7 @@ process_queue (void *cls)
1300 1180
1301 (void) cls; 1181 (void) cls;
1302 delay = GNUNET_TIME_absolute_get_duration (sleep_time_reg_proc); 1182 delay = GNUNET_TIME_absolute_get_duration (sleep_time_reg_proc);
1303 idle_time = GNUNET_TIME_relative_add (idle_time, 1183 idle_time = GNUNET_TIME_relative_add (idle_time, delay);
1304 delay);
1305 series = 0; 1184 series = 0;
1306 t = NULL; 1185 t = NULL;
1307 while (pending + pending_rs < THRESH) 1186 while (pending + pending_rs < THRESH)
@@ -1318,18 +1197,14 @@ process_queue (void *cls)
1318 } 1197 }
1319 if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) 1198 if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0)
1320 break; 1199 break;
1321 GNUNET_assert (req == 1200 GNUNET_assert (req == GNUNET_CONTAINER_heap_remove_root (req_heap));
1322 GNUNET_CONTAINER_heap_remove_root (req_heap));
1323 req->hn = NULL; 1201 req->hn = NULL;
1324 GNUNET_CONTAINER_DLL_insert (req_head, 1202 GNUNET_CONTAINER_DLL_insert (req_head, req_tail, req);
1325 req_tail,
1326 req);
1327 GNUNET_assert (NULL == req->rs); 1203 GNUNET_assert (NULL == req->rs);
1328 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1329 "Requesting resolution for `%s'\n", 1205 "Requesting resolution for `%s'\n",
1330 req->hostname); 1206 req->hostname);
1331 raw = build_dns_query (req, 1207 raw = build_dns_query (req, &raw_size);
1332 &raw_size);
1333 if (NULL == raw) 1208 if (NULL == raw)
1334 { 1209 {
1335 GNUNET_break (0); 1210 GNUNET_break (0);
@@ -1337,11 +1212,7 @@ process_queue (void *cls)
1337 continue; 1212 continue;
1338 } 1213 }
1339 req->op_start_time = GNUNET_TIME_absolute_get (); 1214 req->op_start_time = GNUNET_TIME_absolute_get ();
1340 req->rs = GNUNET_DNSSTUB_resolve (ctx, 1215 req->rs = GNUNET_DNSSTUB_resolve (ctx, raw, raw_size, &process_result, req);
1341 raw,
1342 raw_size,
1343 &process_result,
1344 req);
1345 GNUNET_assert (NULL != req->rs); 1216 GNUNET_assert (NULL != req->rs);
1346 req->issue_num++; 1217 req->issue_num++;
1347 lookups++; 1218 lookups++;
@@ -1353,41 +1224,36 @@ process_queue (void *cls)
1353 if (pending + pending_rs >= THRESH) 1224 if (pending + pending_rs >= THRESH)
1354 { 1225 {
1355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1356 "Stopped processing queue (%u+%u/%u)]\n", 1227 "Stopped processing queue (%u+%u/%u)]\n",
1357 pending, 1228 pending,
1358 pending_rs, 1229 pending_rs,
1359 THRESH); 1230 THRESH);
1360 return; /* wait for replies */ 1231 return; /* wait for replies */
1361 } 1232 }
1362 req = GNUNET_CONTAINER_heap_peek (req_heap); 1233 req = GNUNET_CONTAINER_heap_peek (req_heap);
1363 if (NULL == req) 1234 if (NULL == req)
1364 { 1235 {
1365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1366 "Stopped processing queue: empty queue\n"); 1237 "Stopped processing queue: empty queue\n");
1367 return; 1238 return;
1368 } 1239 }
1369 if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) 1240 if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0)
1370 { 1241 {
1371 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1242 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1372 "Waiting until %s for next record (`%s') to expire\n", 1243 "Waiting until %s for next record (`%s') to expire\n",
1373 GNUNET_STRINGS_absolute_time_to_string (req->expires), 1244 GNUNET_STRINGS_absolute_time_to_string (req->expires),
1374 req->hostname); 1245 req->hostname);
1375 if (NULL != t) 1246 if (NULL != t)
1376 GNUNET_SCHEDULER_cancel (t); 1247 GNUNET_SCHEDULER_cancel (t);
1377 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 1248 sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
1378 t = GNUNET_SCHEDULER_add_at (req->expires, 1249 t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL);
1379 &process_queue,
1380 NULL);
1381 return; 1250 return;
1382 } 1251 }
1383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Throttling\n");
1384 "Throttling\n");
1385 if (NULL != t) 1253 if (NULL != t)
1386 GNUNET_SCHEDULER_cancel (t); 1254 GNUNET_SCHEDULER_cancel (t);
1387 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 1255 sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
1388 t = GNUNET_SCHEDULER_add_delayed (SERIES_DELAY, 1256 t = GNUNET_SCHEDULER_add_delayed (SERIES_DELAY, &process_queue, NULL);
1389 &process_queue,
1390 NULL);
1391} 1257}
1392 1258
1393 1259
@@ -1401,9 +1267,7 @@ process_queue (void *cls)
1401 * @return #GNUNET_OK 1267 * @return #GNUNET_OK
1402 */ 1268 */
1403static int 1269static int
1404free_request_it (void *cls, 1270free_request_it (void *cls, const struct GNUNET_HashCode *key, void *value)
1405 const struct GNUNET_HashCode *key,
1406 void *value)
1407{ 1271{
1408 struct Request *req = value; 1272 struct Request *req = value;
1409 1273
@@ -1438,9 +1302,7 @@ do_shutdown (void *cls)
1438 } 1302 }
1439 while (NULL != (req = req_head)) 1303 while (NULL != (req = req_head))
1440 { 1304 {
1441 GNUNET_CONTAINER_DLL_remove (req_head, 1305 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req);
1442 req_tail,
1443 req);
1444 if (NULL != req->qe) 1306 if (NULL != req->qe)
1445 GNUNET_NAMESTORE_cancel (req->qe); 1307 GNUNET_NAMESTORE_cancel (req->qe);
1446 free_request (req); 1308 free_request (req);
@@ -1474,17 +1336,13 @@ do_shutdown (void *cls)
1474 } 1336 }
1475 if (NULL != ns_pending) 1337 if (NULL != ns_pending)
1476 { 1338 {
1477 GNUNET_CONTAINER_multihashmap_iterate (ns_pending, 1339 GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &free_request_it, NULL);
1478 &free_request_it,
1479 NULL);
1480 GNUNET_CONTAINER_multihashmap_destroy (ns_pending); 1340 GNUNET_CONTAINER_multihashmap_destroy (ns_pending);
1481 ns_pending = NULL; 1341 ns_pending = NULL;
1482 } 1342 }
1483 while (NULL != (zone = zone_head)) 1343 while (NULL != (zone = zone_head))
1484 { 1344 {
1485 GNUNET_CONTAINER_DLL_remove (zone_head, 1345 GNUNET_CONTAINER_DLL_remove (zone_head, zone_tail, zone);
1486 zone_tail,
1487 zone);
1488 GNUNET_free (zone->domain); 1346 GNUNET_free (zone->domain);
1489 GNUNET_free (zone); 1347 GNUNET_free (zone);
1490 } 1348 }
@@ -1518,8 +1376,8 @@ ns_lookup_error_cb (void *cls)
1518 struct Zone *zone = cls; 1376 struct Zone *zone = cls;
1519 1377
1520 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1378 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1521 "Failed to load data from namestore for zone `%s'\n", 1379 "Failed to load data from namestore for zone `%s'\n",
1522 zone->domain); 1380 zone->domain);
1523 zone_it = NULL; 1381 zone_it = NULL;
1524 ns_iterator_trigger_next = 0; 1382 ns_iterator_trigger_next = 0;
1525 iterate_zones (NULL); 1383 iterate_zones (NULL);
@@ -1537,10 +1395,10 @@ ns_lookup_error_cb (void *cls)
1537 */ 1395 */
1538static void 1396static void
1539ns_lookup_result_cb (void *cls, 1397ns_lookup_result_cb (void *cls,
1540 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 1398 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
1541 const char *label, 1399 const char *label,
1542 unsigned int rd_count, 1400 unsigned int rd_count,
1543 const struct GNUNET_GNSRECORD_Data *rd) 1401 const struct GNUNET_GNSRECORD_Data *rd)
1544{ 1402{
1545 struct Zone *zone = cls; 1403 struct Zone *zone = cls;
1546 struct Request *req; 1404 struct Request *req;
@@ -1549,8 +1407,8 @@ ns_lookup_result_cb (void *cls,
1549 1407
1550 ns_iterator_trigger_next--; 1408 ns_iterator_trigger_next--;
1551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1552 "Obtained NAMESTORE reply, %llu left in round\n", 1410 "Obtained NAMESTORE reply, %llu left in round\n",
1553 (unsigned long long) ns_iterator_trigger_next); 1411 (unsigned long long) ns_iterator_trigger_next);
1554 if (0 == ns_iterator_trigger_next) 1412 if (0 == ns_iterator_trigger_next)
1555 { 1413 {
1556 ns_iterator_trigger_next = NS_BATCH_SIZE; 1414 ns_iterator_trigger_next = NS_BATCH_SIZE;
@@ -1558,19 +1416,12 @@ ns_lookup_result_cb (void *cls,
1558 "# NAMESTORE records requested from cache", 1416 "# NAMESTORE records requested from cache",
1559 ns_iterator_trigger_next, 1417 ns_iterator_trigger_next,
1560 GNUNET_NO); 1418 GNUNET_NO);
1561 GNUNET_NAMESTORE_zone_iterator_next (zone_it, 1419 GNUNET_NAMESTORE_zone_iterator_next (zone_it, ns_iterator_trigger_next);
1562 ns_iterator_trigger_next);
1563 } 1420 }
1564 GNUNET_asprintf (&fqdn, 1421 GNUNET_asprintf (&fqdn, "%s.%s", label, zone->domain);
1565 "%s.%s", 1422 GNUNET_CRYPTO_hash (fqdn, strlen (fqdn) + 1, &hc);
1566 label,
1567 zone->domain);
1568 GNUNET_CRYPTO_hash (fqdn,
1569 strlen (fqdn) + 1,
1570 &hc);
1571 GNUNET_free (fqdn); 1423 GNUNET_free (fqdn);
1572 req = GNUNET_CONTAINER_multihashmap_get (ns_pending, 1424 req = GNUNET_CONTAINER_multihashmap_get (ns_pending, &hc);
1573 &hc);
1574 if (NULL == req) 1425 if (NULL == req)
1575 { 1426 {
1576 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1427 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -1580,14 +1431,10 @@ ns_lookup_result_cb (void *cls,
1580 return; 1431 return;
1581 } 1432 }
1582 GNUNET_assert (GNUNET_OK == 1433 GNUNET_assert (GNUNET_OK ==
1583 GNUNET_CONTAINER_multihashmap_remove (ns_pending, 1434 GNUNET_CONTAINER_multihashmap_remove (ns_pending, &hc, req));
1584 &hc, 1435 GNUNET_break (0 == GNUNET_memcmp (key, &req->zone->key));
1585 req)); 1436 GNUNET_break (0 == strcasecmp (label, get_label (req)));
1586 GNUNET_break (0 == GNUNET_memcmp (key, 1437 for (unsigned int i = 0; i < rd_count; i++)
1587 &req->zone->key));
1588 GNUNET_break (0 == strcasecmp (label,
1589 get_label (req)));
1590 for (unsigned int i=0;i<rd_count;i++)
1591 { 1438 {
1592 struct GNUNET_TIME_Absolute at; 1439 struct GNUNET_TIME_Absolute at;
1593 1440
@@ -1602,17 +1449,13 @@ ns_lookup_result_cb (void *cls,
1602 { 1449 {
1603 at.abs_value_us = rd->expiration_time; 1450 at.abs_value_us = rd->expiration_time;
1604 } 1451 }
1605 add_record (req, 1452 add_record (req, rd->record_type, at, rd->data, rd->data_size);
1606 rd->record_type,
1607 at,
1608 rd->data,
1609 rd->data_size);
1610 } 1453 }
1611 if (0 == rd_count) 1454 if (0 == rd_count)
1612 { 1455 {
1613 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1456 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1614 "Empty record set in namestore for `%s'\n", 1457 "Empty record set in namestore for `%s'\n",
1615 req->hostname); 1458 req->hostname);
1616 } 1459 }
1617 else 1460 else
1618 { 1461 {
@@ -1620,30 +1463,27 @@ ns_lookup_result_cb (void *cls,
1620 1463
1621 cached++; 1464 cached++;
1622 req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; 1465 req->expires = GNUNET_TIME_UNIT_FOREVER_ABS;
1623 for (struct Record *rec = req->rec_head; 1466 for (struct Record *rec = req->rec_head; NULL != rec; rec = rec->next)
1624 NULL != rec;
1625 rec = rec->next)
1626 { 1467 {
1627 struct GNUNET_TIME_Absolute at; 1468 struct GNUNET_TIME_Absolute at;
1628 1469
1629 at.abs_value_us = rec->grd.expiration_time; 1470 at.abs_value_us = rec->grd.expiration_time;
1630 req->expires = GNUNET_TIME_absolute_min (req->expires, 1471 req->expires = GNUNET_TIME_absolute_min (req->expires, at);
1631 at);
1632 pos++; 1472 pos++;
1633 } 1473 }
1634 if (0 == pos) 1474 if (0 == pos)
1635 req->expires = GNUNET_TIME_UNIT_ZERO_ABS; 1475 req->expires = GNUNET_TIME_UNIT_ZERO_ABS;
1636 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1476 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1637 "Hot-start with %u existing records for `%s'\n", 1477 "Hot-start with %u existing records for `%s'\n",
1638 pos, 1478 pos,
1639 req->hostname); 1479 req->hostname);
1640 } 1480 }
1641 free_records (req); 1481 free_records (req);
1642 1482
1643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1644 "Adding `%s' to worklist to start at %s\n", 1484 "Adding `%s' to worklist to start at %s\n",
1645 req->hostname, 1485 req->hostname,
1646 GNUNET_STRINGS_absolute_time_to_string (req->expires)); 1486 GNUNET_STRINGS_absolute_time_to_string (req->expires));
1647 insert_sorted (req); 1487 insert_sorted (req);
1648} 1488}
1649 1489
@@ -1662,8 +1502,7 @@ queue (const char *hostname)
1662 size_t hlen; 1502 size_t hlen;
1663 struct GNUNET_HashCode hc; 1503 struct GNUNET_HashCode hc;
1664 1504
1665 if (GNUNET_OK != 1505 if (GNUNET_OK != GNUNET_DNSPARSER_check_name (hostname))
1666 GNUNET_DNSPARSER_check_name (hostname))
1667 { 1506 {
1668 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1507 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1669 "Refusing invalid hostname `%s'\n", 1508 "Refusing invalid hostname `%s'\n",
@@ -1671,8 +1510,7 @@ queue (const char *hostname)
1671 rejects++; 1510 rejects++;
1672 return; 1511 return;
1673 } 1512 }
1674 dot = strchr (hostname, 1513 dot = strchr (hostname, (unsigned char) '.');
1675 (unsigned char) '.');
1676 if (NULL == dot) 1514 if (NULL == dot)
1677 { 1515 {
1678 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1516 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1682,8 +1520,7 @@ queue (const char *hostname)
1682 return; 1520 return;
1683 } 1521 }
1684 for (zone = zone_head; NULL != zone; zone = zone->next) 1522 for (zone = zone_head; NULL != zone; zone = zone->next)
1685 if (0 == strcmp (zone->domain, 1523 if (0 == strcmp (zone->domain, dot + 1))
1686 dot + 1))
1687 break; 1524 break;
1688 if (NULL == zone) 1525 if (NULL == zone)
1689 { 1526 {
@@ -1698,19 +1535,15 @@ queue (const char *hostname)
1698 req = GNUNET_malloc (sizeof (struct Request) + hlen); 1535 req = GNUNET_malloc (sizeof (struct Request) + hlen);
1699 req->zone = zone; 1536 req->zone = zone;
1700 req->hostname = (char *) &req[1]; 1537 req->hostname = (char *) &req[1];
1701 GNUNET_memcpy (req->hostname, 1538 GNUNET_memcpy (req->hostname, hostname, hlen);
1702 hostname,
1703 hlen);
1704 req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1539 req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1705 UINT16_MAX); 1540 UINT16_MAX);
1706 GNUNET_CRYPTO_hash (req->hostname, 1541 GNUNET_CRYPTO_hash (req->hostname, hlen, &hc);
1707 hlen, 1542 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (
1708 &hc); 1543 ns_pending,
1709 if (GNUNET_OK != 1544 &hc,
1710 GNUNET_CONTAINER_multihashmap_put (ns_pending, 1545 req,
1711 &hc, 1546 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1712 req,
1713 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1714 { 1547 {
1715 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1548 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1716 "Duplicate hostname `%s' ignored\n", 1549 "Duplicate hostname `%s' ignored\n",
@@ -1733,9 +1566,7 @@ queue (const char *hostname)
1733 * @return #GNUNET_OK (continue to iterate) 1566 * @return #GNUNET_OK (continue to iterate)
1734 */ 1567 */
1735static int 1568static int
1736move_to_queue (void *cls, 1569move_to_queue (void *cls, const struct GNUNET_HashCode *key, void *value)
1737 const struct GNUNET_HashCode *key,
1738 void *value)
1739{ 1570{
1740 struct Request *req = value; 1571 struct Request *req = value;
1741 1572
@@ -1766,9 +1597,9 @@ iterate_zones (void *cls)
1766 last->domain); 1597 last->domain);
1767 /* subtract left-overs from previous iteration */ 1598 /* subtract left-overs from previous iteration */
1768 GNUNET_STATISTICS_update (stats, 1599 GNUNET_STATISTICS_update (stats,
1769 "# NAMESTORE records requested from cache", 1600 "# NAMESTORE records requested from cache",
1770 (long long) (- ns_iterator_trigger_next), 1601 (long long) (-ns_iterator_trigger_next),
1771 GNUNET_NO); 1602 GNUNET_NO);
1772 ns_iterator_trigger_next = 0; 1603 ns_iterator_trigger_next = 0;
1773 } 1604 }
1774 GNUNET_assert (NULL != zone_tail); 1605 GNUNET_assert (NULL != zone_tail);
@@ -1777,14 +1608,12 @@ iterate_zones (void *cls)
1777 /* Done iterating over relevant zones in NAMESTORE, move 1608 /* Done iterating over relevant zones in NAMESTORE, move
1778 rest of hash map to work queue as well. */ 1609 rest of hash map to work queue as well. */
1779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1780 "Finished all NAMESTORE iterations!\n"); 1611 "Finished all NAMESTORE iterations!\n");
1781 GNUNET_STATISTICS_set (stats, 1612 GNUNET_STATISTICS_set (stats,
1782 "# Domain names without cached reply", 1613 "# Domain names without cached reply",
1783 GNUNET_CONTAINER_multihashmap_size (ns_pending), 1614 GNUNET_CONTAINER_multihashmap_size (ns_pending),
1784 GNUNET_NO); 1615 GNUNET_NO);
1785 GNUNET_CONTAINER_multihashmap_iterate (ns_pending, 1616 GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &move_to_queue, NULL);
1786 &move_to_queue,
1787 NULL);
1788 GNUNET_CONTAINER_multihashmap_destroy (ns_pending); 1617 GNUNET_CONTAINER_multihashmap_destroy (ns_pending);
1789 ns_pending = NULL; 1618 ns_pending = NULL;
1790 start_time_reg_proc = GNUNET_TIME_absolute_get (); 1619 start_time_reg_proc = GNUNET_TIME_absolute_get ();
@@ -1801,14 +1630,11 @@ iterate_zones (void *cls)
1801 last->domain); 1630 last->domain);
1802 /* subtract left-overs from previous iteration */ 1631 /* subtract left-overs from previous iteration */
1803 GNUNET_STATISTICS_update (stats, 1632 GNUNET_STATISTICS_update (stats,
1804 "# NAMESTORE records requested from cache", 1633 "# NAMESTORE records requested from cache",
1805 1, 1634 1,
1806 GNUNET_NO); 1635 GNUNET_NO);
1807 ns_iterator_trigger_next = 1; 1636 ns_iterator_trigger_next = 1;
1808 GNUNET_STATISTICS_update (stats, 1637 GNUNET_STATISTICS_update (stats, "# zones iterated", 1, GNUNET_NO);
1809 "# zones iterated",
1810 1,
1811 GNUNET_NO);
1812 zone_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 1638 zone_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
1813 &last->key, 1639 &last->key,
1814 &ns_lookup_error_cb, 1640 &ns_lookup_error_cb,
@@ -1817,7 +1643,6 @@ iterate_zones (void *cls)
1817 last, 1643 last,
1818 &iterate_zones, 1644 &iterate_zones,
1819 NULL); 1645 NULL);
1820
1821} 1646}
1822 1647
1823 1648
@@ -1840,13 +1665,10 @@ process_stdin (void *cls)
1840 GNUNET_IDENTITY_disconnect (id); 1665 GNUNET_IDENTITY_disconnect (id);
1841 id = NULL; 1666 id = NULL;
1842 } 1667 }
1843 while (NULL != 1668 while (NULL != fgets (hn, sizeof (hn), stdin))
1844 fgets (hn,
1845 sizeof (hn),
1846 stdin))
1847 { 1669 {
1848 if (strlen(hn) > 0) 1670 if (strlen (hn) > 0)
1849 hn[strlen(hn)-1] = '\0'; /* eat newline */ 1671 hn[strlen (hn) - 1] = '\0'; /* eat newline */
1850 if (0 == idot) 1672 if (0 == idot)
1851 last = GNUNET_TIME_absolute_get (); 1673 last = GNUNET_TIME_absolute_get ();
1852 idot++; 1674 idot++;
@@ -1857,23 +1679,16 @@ process_stdin (void *cls)
1857 delta = GNUNET_TIME_absolute_get_duration (last); 1679 delta = GNUNET_TIME_absolute_get_duration (last);
1858 last = GNUNET_TIME_absolute_get (); 1680 last = GNUNET_TIME_absolute_get ();
1859 fprintf (stderr, 1681 fprintf (stderr,
1860 "Read 100000 domain names in %s\n", 1682 "Read 100000 domain names in %s\n",
1861 GNUNET_STRINGS_relative_time_to_string (delta, 1683 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
1862 GNUNET_YES)); 1684 GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO);
1863 GNUNET_STATISTICS_set (stats,
1864 "# domain names provided",
1865 idot,
1866 GNUNET_NO);
1867 } 1685 }
1868 queue (hn); 1686 queue (hn);
1869 } 1687 }
1870 fprintf (stderr, 1688 fprintf (stderr,
1871 "Done reading %llu domain names\n", 1689 "Done reading %llu domain names\n",
1872 (unsigned long long) idot); 1690 (unsigned long long) idot);
1873 GNUNET_STATISTICS_set (stats, 1691 GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO);
1874 "# domain names provided",
1875 idot,
1876 GNUNET_NO);
1877 iterate_zones (NULL); 1692 iterate_zones (NULL);
1878} 1693}
1879 1694
@@ -1905,7 +1720,7 @@ process_stdin (void *cls)
1905 * cleaned up). 1720 * cleaned up).
1906 * 1721 *
1907 * @param cls closure 1722 * @param cls closure
1908 * @param ego ego handle 1723 * @param ego ego handle, NULL for end of list
1909 * @param ctx context for application to store data for this ego 1724 * @param ctx context for application to store data for this ego
1910 * (during the lifetime of this process, initially NULL) 1725 * (during the lifetime of this process, initially NULL)
1911 * @param name name assigned by the user for this ego, 1726 * @param name name assigned by the user for this ego,
@@ -1914,26 +1729,25 @@ process_stdin (void *cls)
1914 */ 1729 */
1915static void 1730static void
1916identity_cb (void *cls, 1731identity_cb (void *cls,
1917 struct GNUNET_IDENTITY_Ego *ego, 1732 struct GNUNET_IDENTITY_Ego *ego,
1918 void **ctx, 1733 void **ctx,
1919 const char *name) 1734 const char *name)
1920{ 1735{
1921 (void) cls; 1736 (void) cls;
1922 (void) ctx; 1737 (void) ctx;
1738
1923 if (NULL == ego) 1739 if (NULL == ego)
1924 { 1740 {
1925 if (NULL != zone_head) 1741 /* end of iteration */
1742 if (NULL == zone_head)
1926 { 1743 {
1927 t = GNUNET_SCHEDULER_add_now (&process_stdin, 1744 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No zone found\n");
1928 NULL);
1929 }
1930 else
1931 {
1932 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1933 "No zone found\n");
1934 GNUNET_SCHEDULER_shutdown (); 1745 GNUNET_SCHEDULER_shutdown ();
1935 return; 1746 return;
1936 } 1747 }
1748 /* zone_head non-null, process hostnames from stdin */
1749 t = GNUNET_SCHEDULER_add_now (&process_stdin, NULL);
1750 return;
1937 } 1751 }
1938 if (NULL != name) 1752 if (NULL != name)
1939 { 1753 {
@@ -1942,9 +1756,7 @@ identity_cb (void *cls,
1942 zone = GNUNET_new (struct Zone); 1756 zone = GNUNET_new (struct Zone);
1943 zone->key = *GNUNET_IDENTITY_ego_get_private_key (ego); 1757 zone->key = *GNUNET_IDENTITY_ego_get_private_key (ego);
1944 zone->domain = GNUNET_strdup (name); 1758 zone->domain = GNUNET_strdup (name);
1945 GNUNET_CONTAINER_DLL_insert (zone_head, 1759 GNUNET_CONTAINER_DLL_insert (zone_head, zone_tail, zone);
1946 zone_tail,
1947 zone);
1948 } 1760 }
1949} 1761}
1950 1762
@@ -1967,22 +1779,18 @@ run (void *cls,
1967 (void) cls; 1779 (void) cls;
1968 (void) args; 1780 (void) args;
1969 (void) cfgfile; 1781 (void) cfgfile;
1970 stats = GNUNET_STATISTICS_create ("zoneimport", 1782 stats = GNUNET_STATISTICS_create ("zoneimport", cfg);
1971 cfg);
1972 req_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1783 req_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1973 ns_pending = GNUNET_CONTAINER_multihashmap_create (map_size, 1784 ns_pending = GNUNET_CONTAINER_multihashmap_create (map_size, GNUNET_NO);
1974 GNUNET_NO);
1975 if (NULL == ns_pending) 1785 if (NULL == ns_pending)
1976 { 1786 {
1977 fprintf (stderr, 1787 fprintf (stderr, "Failed to allocate memory for main hash map\n");
1978 "Failed to allocate memory for main hash map\n");
1979 return; 1788 return;
1980 } 1789 }
1981 ctx = GNUNET_DNSSTUB_start (256); 1790 ctx = GNUNET_DNSSTUB_start (256);
1982 if (NULL == ctx) 1791 if (NULL == ctx)
1983 { 1792 {
1984 fprintf (stderr, 1793 fprintf (stderr, "Failed to initialize GNUnet DNS STUB\n");
1985 "Failed to initialize GNUnet DNS STUB\n");
1986 return; 1794 return;
1987 } 1795 }
1988 if (NULL == args[0]) 1796 if (NULL == args[0])
@@ -1991,31 +1799,24 @@ run (void *cls,
1991 "You must provide a list of DNS resolvers on the command line\n"); 1799 "You must provide a list of DNS resolvers on the command line\n");
1992 return; 1800 return;
1993 } 1801 }
1994 for (unsigned int i=0;NULL != args[i];i++) 1802 for (unsigned int i = 0; NULL != args[i]; i++)
1995 { 1803 {
1996 if (GNUNET_OK != 1804 if (GNUNET_OK != GNUNET_DNSSTUB_add_dns_ip (ctx, args[i]))
1997 GNUNET_DNSSTUB_add_dns_ip (ctx,
1998 args[i]))
1999 { 1805 {
2000 fprintf (stderr, 1806 fprintf (stderr, "Failed to use `%s' for DNS resolver\n", args[i]);
2001 "Failed to use `%s' for DNS resolver\n",
2002 args[i]);
2003 return; 1807 return;
2004 } 1808 }
2005 } 1809 }
2006 1810
2007 1811
2008 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 1812 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
2009 NULL);
2010 ns = GNUNET_NAMESTORE_connect (cfg); 1813 ns = GNUNET_NAMESTORE_connect (cfg);
2011 if (NULL == ns) 1814 if (NULL == ns)
2012 { 1815 {
2013 GNUNET_SCHEDULER_shutdown (); 1816 GNUNET_SCHEDULER_shutdown ();
2014 return; 1817 return;
2015 } 1818 }
2016 id = GNUNET_IDENTITY_connect (cfg, 1819 id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
2017 &identity_cb,
2018 NULL);
2019} 1820}
2020 1821
2021 1822
@@ -2027,38 +1828,35 @@ run (void *cls,
2027 * @return 0 on success 1828 * @return 0 on success
2028 */ 1829 */
2029int 1830int
2030main (int argc, 1831main (int argc, char *const *argv)
2031 char *const*argv)
2032{ 1832{
2033 struct GNUNET_GETOPT_CommandLineOption options[] = { 1833 struct GNUNET_GETOPT_CommandLineOption options[] =
2034 GNUNET_GETOPT_option_uint ('s', 1834 {GNUNET_GETOPT_option_uint ('s',
2035 "size", 1835 "size",
2036 "MAPSIZE", 1836 "MAPSIZE",
2037 gettext_noop ("size to use for the main hash map"), 1837 gettext_noop (
2038 &map_size), 1838 "size to use for the main hash map"),
2039 GNUNET_GETOPT_option_relative_time ('m', 1839 &map_size),
2040 "minimum-expiration", 1840 GNUNET_GETOPT_option_relative_time (
2041 "RELATIVETIME", 1841 'm',
2042 gettext_noop ("minimum expiration time we assume for imported records"), 1842 "minimum-expiration",
2043 &minimum_expiration_time), 1843 "RELATIVETIME",
2044 GNUNET_GETOPT_OPTION_END 1844 gettext_noop ("minimum expiration time we assume for imported records"),
2045 }; 1845 &minimum_expiration_time),
1846 GNUNET_GETOPT_OPTION_END};
2046 int ret; 1847 int ret;
2047 1848
2048 if (GNUNET_OK != 1849 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
2049 GNUNET_STRINGS_get_utf8_args (argc, argv,
2050 &argc, &argv))
2051 return 2; 1850 return 2;
2052 if (GNUNET_OK != 1851 if (GNUNET_OK != (ret = GNUNET_PROGRAM_run (argc,
2053 (ret = GNUNET_PROGRAM_run (argc, 1852 argv,
2054 argv, 1853 "gnunet-zoneimport",
2055 "gnunet-zoneimport", 1854 "import DNS zone into namestore",
2056 "import DNS zone into namestore", 1855 options,
2057 options, 1856 &run,
2058 &run, 1857 NULL)))
2059 NULL)))
2060 return ret; 1858 return ret;
2061 GNUNET_free ((void*) argv); 1859 GNUNET_free ((void *) argv);
2062 fprintf (stderr, 1860 fprintf (stderr,
2063 "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" 1861 "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n"
2064 "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", 1862 "Found %u records, %u lookups failed, %u/%u pending on shutdown\n",