aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-05-10 12:48:53 +0200
committerChristian Grothoff <christian@grothoff.org>2018-05-10 12:48:53 +0200
commit60b697dc2e61bec2d49c13d4d8855e1506efba9b (patch)
treedaa773d2fb46db438d43e1b13012ec04fad684ef
parent4c8b719d9fcb5c67b4f461961d436532cbd4c8c1 (diff)
downloadgnunet-60b697dc2e61bec2d49c13d4d8855e1506efba9b.tar.gz
gnunet-60b697dc2e61bec2d49c13d4d8855e1506efba9b.zip
add option to bump lifetime
-rw-r--r--doc/man/gnunet-zoneimport.18
-rw-r--r--src/namestore/gnunet-zoneimport.c70
2 files changed, 63 insertions, 15 deletions
diff --git a/doc/man/gnunet-zoneimport.1 b/doc/man/gnunet-zoneimport.1
index bcfa7b734..cf76b86ee 100644
--- a/doc/man/gnunet-zoneimport.1
+++ b/doc/man/gnunet-zoneimport.1
@@ -48,6 +48,14 @@ Use the configuration file FILENAME.
48.IP "\-h, \-\-help" 48.IP "\-h, \-\-help"
49Print short help on options. 49Print short help on options.
50.B 50.B
51.IP "\-m RELATIVETIME, \-\-minimum-expiration=RELATIVETIME"
52.B
53Ensure that imported DNS records never have an expiration time that
54is less than RELATIVETIME into the future. RELATIVETIME is a time
55given like "1 week" or "1 h". If DNS returns records with a shorter
56lifetime, gnunet\-zoneimport will simply bump the lifetime to the
57specified value (relative to the time of the import). Default is zero.
58
51.IP "\-s MAPSIZE, \-\-size=MAPSIZE" 59.IP "\-s MAPSIZE, \-\-size=MAPSIZE"
52Specifies the size (in number of entries) to use for the main hash 60Specifies the size (in number of entries) to use for the main hash
53map. The value provided should be at least twice the number of domain 61map. The value provided should be at least twice the number of domain
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c
index 0fd0a4ab8..f9e3ad99e 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.c
@@ -59,6 +59,11 @@
59#define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) 59#define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10)
60 60
61/** 61/**
62 * How long do DNS records have to last at least after being imported?
63 */
64static struct GNUNET_TIME_Relative minimum_expiration_time;
65
66/**
62 * How many requests do we request from NAMESTORE in one batch 67 * How many requests do we request from NAMESTORE in one batch
63 * during our initial iteration? 68 * during our initial iteration?
64 */ 69 */
@@ -632,10 +637,19 @@ check_for_glue (void *cls,
632 size_t off; 637 size_t off;
633 char ip[INET6_ADDRSTRLEN+1]; 638 char ip[INET6_ADDRSTRLEN+1];
634 socklen_t ip_size = (socklen_t) sizeof (ip); 639 socklen_t ip_size = (socklen_t) sizeof (ip);
640 struct GNUNET_TIME_Absolute expiration_time;
641 struct GNUNET_TIME_Relative left;
635 642
636 if (0 != strcasecmp (rec->name, 643 if (0 != strcasecmp (rec->name,
637 gc->ns)) 644 gc->ns))
638 return; 645 return;
646 expiration_time = rec->expiration_time;
647 left = GNUNET_TIME_absolute_get_remaining (expiration_time);
648 if (0 == left.rel_value_us)
649 return; /* ignore expired glue records */
650 /* if expiration window is too short, bump it to configured minimum */
651 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
652 expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
639 dst_len = sizeof (dst); 653 dst_len = sizeof (dst);
640 off = 0; 654 off = 0;
641 switch (rec->type) 655 switch (rec->type)
@@ -668,7 +682,7 @@ check_for_glue (void *cls,
668 { 682 {
669 add_record (gc->req, 683 add_record (gc->req,
670 GNUNET_GNSRECORD_TYPE_GNS2DNS, 684 GNUNET_GNSRECORD_TYPE_GNS2DNS,
671 rec->expiration_time, 685 expiration_time,
672 dst, 686 dst,
673 off); 687 off);
674 gc->found = GNUNET_YES; 688 gc->found = GNUNET_YES;
@@ -702,7 +716,7 @@ check_for_glue (void *cls,
702 { 716 {
703 add_record (gc->req, 717 add_record (gc->req,
704 GNUNET_GNSRECORD_TYPE_GNS2DNS, 718 GNUNET_GNSRECORD_TYPE_GNS2DNS,
705 rec->expiration_time, 719 expiration_time,
706 dst, 720 dst,
707 off); 721 off);
708 gc->found = GNUNET_YES; 722 gc->found = GNUNET_YES;
@@ -722,7 +736,7 @@ check_for_glue (void *cls,
722 { 736 {
723 add_record (gc->req, 737 add_record (gc->req,
724 GNUNET_GNSRECORD_TYPE_GNS2DNS, 738 GNUNET_GNSRECORD_TYPE_GNS2DNS,
725 rec->expiration_time, 739 expiration_time,
726 dst, 740 dst,
727 off); 741 off);
728 gc->found = GNUNET_YES; 742 gc->found = GNUNET_YES;
@@ -768,6 +782,8 @@ process_record (void *cls,
768 char dst[65536]; 782 char dst[65536];
769 size_t dst_len; 783 size_t dst_len;
770 size_t off; 784 size_t off;
785 struct GNUNET_TIME_Absolute expiration_time;
786 struct GNUNET_TIME_Relative left;
771 787
772 dst_len = sizeof (dst); 788 dst_len = sizeof (dst);
773 off = 0; 789 off = 0;
@@ -783,18 +799,27 @@ process_record (void *cls,
783 return; /* does not match hostname, might be glue, but 799 return; /* does not match hostname, might be glue, but
784 not useful for this pass! */ 800 not useful for this pass! */
785 } 801 }
786 if (0 == 802 expiration_time = rec->expiration_time;
787 GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value_us) 803 left = GNUNET_TIME_absolute_get_remaining (expiration_time);
804 if (0 == left.rel_value_us)
788 { 805 {
789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
790 "DNS returned expired record for `%s'\n", 807 "DNS returned expired record for `%s'\n",
791 req->hostname); 808 req->hostname);
809 GNUNET_STATISTICS_update (stats,
810 "# expired records obtained from DNS",
811 1,
812 GNUNET_NO);
792 return; /* record expired */ 813 return; /* record expired */
793 } 814 }
815
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
795 "DNS returned record that expires at %s for `%s'\n", 817 "DNS returned record that expires at %s for `%s'\n",
796 GNUNET_STRINGS_absolute_time_to_string (rec->expiration_time), 818 GNUNET_STRINGS_absolute_time_to_string (expiration_time),
797 req->hostname); 819 req->hostname);
820 /* if expiration window is too short, bump it to configured minimum */
821 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
822 expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
798 switch (rec->type) 823 switch (rec->type)
799 { 824 {
800 case GNUNET_DNSPARSER_TYPE_NS: 825 case GNUNET_DNSPARSER_TYPE_NS:
@@ -828,7 +853,7 @@ process_record (void *cls,
828 rec->name); 853 rec->name);
829 add_record (req, 854 add_record (req,
830 GNUNET_GNSRECORD_TYPE_GNS2DNS, 855 GNUNET_GNSRECORD_TYPE_GNS2DNS,
831 rec->expiration_time, 856 expiration_time,
832 dst, 857 dst,
833 off); 858 off);
834 } 859 }
@@ -853,7 +878,7 @@ process_record (void *cls,
853 rec->name); 878 rec->name);
854 add_record (req, 879 add_record (req,
855 rec->type, 880 rec->type,
856 rec->expiration_time, 881 expiration_time,
857 dst, 882 dst,
858 off); 883 off);
859 } 884 }
@@ -878,7 +903,7 @@ process_record (void *cls,
878 rec->name); 903 rec->name);
879 add_record (req, 904 add_record (req,
880 rec->type, 905 rec->type,
881 rec->expiration_time, 906 expiration_time,
882 dst, 907 dst,
883 off); 908 off);
884 } 909 }
@@ -896,7 +921,7 @@ process_record (void *cls,
896 rec->name); 921 rec->name);
897 add_record (req, 922 add_record (req,
898 rec->type, 923 rec->type,
899 rec->expiration_time, 924 expiration_time,
900 dst, 925 dst,
901 off); 926 off);
902 } 927 }
@@ -913,7 +938,7 @@ process_record (void *cls,
913 rec->name); 938 rec->name);
914 add_record (req, 939 add_record (req,
915 rec->type, 940 rec->type,
916 rec->expiration_time, 941 expiration_time,
917 dst, 942 dst,
918 off); 943 off);
919 } 944 }
@@ -931,7 +956,7 @@ process_record (void *cls,
931 rec->name); 956 rec->name);
932 add_record (req, 957 add_record (req,
933 rec->type, 958 rec->type,
934 rec->expiration_time, 959 expiration_time,
935 dst, 960 dst,
936 off); 961 off);
937 } 962 }
@@ -948,7 +973,7 @@ process_record (void *cls,
948 rec->name); 973 rec->name);
949 add_record (req, 974 add_record (req,
950 rec->type, 975 rec->type,
951 rec->expiration_time, 976 expiration_time,
952 dst, 977 dst,
953 off); 978 off);
954 } 979 }
@@ -966,7 +991,7 @@ process_record (void *cls,
966 rec->name); 991 rec->name);
967 add_record (req, 992 add_record (req,
968 rec->type, 993 rec->type,
969 rec->expiration_time, 994 expiration_time,
970 rec->data.raw.data, 995 rec->data.raw.data,
971 rec->data.raw.data_len); 996 rec->data.raw.data_len);
972 break; 997 break;
@@ -1551,7 +1576,17 @@ ns_lookup_result_cb (void *cls,
1551 { 1576 {
1552 struct GNUNET_TIME_Absolute at; 1577 struct GNUNET_TIME_Absolute at;
1553 1578
1554 at.abs_value_us = rd->expiration_time; 1579 if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
1580 {
1581 struct GNUNET_TIME_Relative rel;
1582
1583 rel.rel_value_us = rd->expiration_time;
1584 at = GNUNET_TIME_relative_to_absolute (rel);
1585 }
1586 else
1587 {
1588 at.abs_value_us = rd->expiration_time;
1589 }
1555 add_record (req, 1590 add_record (req,
1556 rd->record_type, 1591 rd->record_type,
1557 at, 1592 at,
@@ -1986,6 +2021,11 @@ main (int argc,
1986 "MAPSIZE", 2021 "MAPSIZE",
1987 gettext_noop ("size to use for the main hash map"), 2022 gettext_noop ("size to use for the main hash map"),
1988 &map_size), 2023 &map_size),
2024 GNUNET_GETOPT_option_relative_time ('m',
2025 "minimum-expiration",
2026 "RELATIVETIME",
2027 gettext_noop ("minimum expiration time we assume for imported records"),
2028 &minimum_expiration_time),
1989 GNUNET_GETOPT_OPTION_END 2029 GNUNET_GETOPT_OPTION_END
1990 }; 2030 };
1991 2031