diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-02-05 21:37:40 +0100 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-02-05 21:37:40 +0100 |
commit | 3ab4b92da2ff2aeb135c2ddf2a51eeec93e33468 (patch) | |
tree | 3b35806d183f51706e2b16be204970c7bf859eda /src/zonemaster/gnunet-service-zonemaster.c | |
parent | a3563c94b702719db253b05dab99b2783e35a0de (diff) | |
download | gnunet-3ab4b92da2ff2aeb135c2ddf2a51eeec93e33468.tar.gz gnunet-3ab4b92da2ff2aeb135c2ddf2a51eeec93e33468.zip |
-refactor zonemaster
Diffstat (limited to 'src/zonemaster/gnunet-service-zonemaster.c')
-rw-r--r-- | src/zonemaster/gnunet-service-zonemaster.c | 172 |
1 files changed, 37 insertions, 135 deletions
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c index 3a8ac4be1..9f0de8a54 100644 --- a/src/zonemaster/gnunet-service-zonemaster.c +++ b/src/zonemaster/gnunet-service-zonemaster.c | |||
@@ -29,7 +29,7 @@ | |||
29 | #include "gnunet_dht_service.h" | 29 | #include "gnunet_dht_service.h" |
30 | #include "gnunet_namestore_service.h" | 30 | #include "gnunet_namestore_service.h" |
31 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
32 | 32 | #include "zonemaster_misc.h" | |
33 | 33 | ||
34 | #define LOG_STRERROR_FILE(kind, syscall, \ | 34 | #define LOG_STRERROR_FILE(kind, syscall, \ |
35 | filename) GNUNET_log_from_strerror_file (kind, "util", \ | 35 | filename) GNUNET_log_from_strerror_file (kind, "util", \ |
@@ -569,75 +569,6 @@ dht_put_continuation (void *cls) | |||
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | /** | ||
573 | * Convert namestore records from the internal format to that | ||
574 | * suitable for publication (removes private records, converts | ||
575 | * to absolute expiration time). | ||
576 | * | ||
577 | * @param rd input records | ||
578 | * @param rd_count size of the @a rd and @a rd_public arrays | ||
579 | * @param rd_public where to write the converted records | ||
580 | * @param expire the expiration of the block | ||
581 | * @return number of records written to @a rd_public | ||
582 | */ | ||
583 | static unsigned int | ||
584 | convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, | ||
585 | unsigned int rd_count, | ||
586 | struct GNUNET_GNSRECORD_Data *rd_public, | ||
587 | struct GNUNET_TIME_Absolute *expiry) | ||
588 | { | ||
589 | const struct GNUNET_GNSRECORD_TombstoneRecord *tombstone; | ||
590 | struct GNUNET_TIME_Absolute expiry_tombstone; | ||
591 | struct GNUNET_TIME_Absolute now; | ||
592 | unsigned int rd_public_count; | ||
593 | |||
594 | rd_public_count = 0; | ||
595 | tombstone = NULL; | ||
596 | now = GNUNET_TIME_absolute_get (); | ||
597 | for (unsigned int i = 0; i < rd_count; i++) | ||
598 | { | ||
599 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) | ||
600 | { | ||
601 | tombstone = rd[i].data; | ||
602 | continue; | ||
603 | } | ||
604 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) | ||
605 | continue; | ||
606 | if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) && | ||
607 | (rd[i].expiration_time < now.abs_value_us)) | ||
608 | continue; /* record already expired, skip it */ | ||
609 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | ||
610 | { | ||
611 | /* GNUNET_GNSRECORD_block_create will convert to absolute time; | ||
612 | we just need to adjust our iteration frequency */ | ||
613 | min_relative_record_time.rel_value_us = | ||
614 | GNUNET_MIN (rd[i].expiration_time, | ||
615 | min_relative_record_time.rel_value_us); | ||
616 | } | ||
617 | rd_public[rd_public_count] = rd[i]; | ||
618 | /* Make sure critical record types are published as such */ | ||
619 | if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type)) | ||
620 | rd_public[rd_public_count].flags |= GNUNET_GNSRECORD_RF_CRITICAL; | ||
621 | rd_public_count++; | ||
622 | } | ||
623 | |||
624 | *expiry = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count, | ||
625 | rd_public); | ||
626 | |||
627 | /* We need to check if the tombstone has an expiration in the fututre | ||
628 | * which would mean there was a block published under this label | ||
629 | * previously that is still valid. In this case we MUST NOT publish this | ||
630 | * block | ||
631 | */ | ||
632 | if (NULL != tombstone) | ||
633 | { | ||
634 | expiry_tombstone = GNUNET_TIME_absolute_ntoh (tombstone->time_of_death); | ||
635 | if (GNUNET_TIME_absolute_cmp (*expiry,<=,expiry_tombstone)) | ||
636 | return 0; | ||
637 | } | ||
638 | return rd_public_count; | ||
639 | } | ||
640 | |||
641 | 572 | ||
642 | /** | 573 | /** |
643 | * Store GNS records in the DHT. | 574 | * Store GNS records in the DHT. |
@@ -796,60 +727,6 @@ ts_store_cont (void *cls, int32_t success, const char *emsg) | |||
796 | 727 | ||
797 | } | 728 | } |
798 | 729 | ||
799 | /** | ||
800 | * Update tombstone records. | ||
801 | * | ||
802 | * @param key key of the zone | ||
803 | * @param label label to store under | ||
804 | * @param rd_public public record data | ||
805 | * @param rd_public_count number of records in @a rd_public | ||
806 | * @param expire the expiration time for the tombstone | ||
807 | * @param ta handle for the put operation | ||
808 | * @return Namestore queue entry, NULL on error | ||
809 | */ | ||
810 | static struct GNUNET_NAMESTORE_QueueEntry * | ||
811 | touch_tombstone (const struct GNUNET_IDENTITY_PrivateKey *key, | ||
812 | const char *label, | ||
813 | const struct GNUNET_GNSRECORD_Data *rd_original, | ||
814 | unsigned int rd_count_original, | ||
815 | const struct GNUNET_TIME_Absolute expire, | ||
816 | struct TombstoneActivity *ta) | ||
817 | { | ||
818 | struct GNUNET_TIME_AbsoluteNBO exp_nbo; | ||
819 | struct GNUNET_GNSRECORD_Data rd[rd_count_original + 1]; | ||
820 | int tombstone_exists = GNUNET_NO; | ||
821 | unsigned int rd_count; | ||
822 | |||
823 | exp_nbo = GNUNET_TIME_absolute_hton (expire); | ||
824 | for (rd_count = 0; rd_count < rd_count_original; rd_count++) | ||
825 | { | ||
826 | memcpy (&rd[rd_count], &rd_original[rd_count], | ||
827 | sizeof (struct GNUNET_GNSRECORD_Data)); | ||
828 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[rd_count].record_type) | ||
829 | { | ||
830 | rd[rd_count].data = &exp_nbo; | ||
831 | tombstone_exists = GNUNET_YES; | ||
832 | } | ||
833 | } | ||
834 | if (GNUNET_NO == tombstone_exists) | ||
835 | { | ||
836 | rd[rd_count].data = &exp_nbo; | ||
837 | rd[rd_count].data_size = sizeof (exp_nbo); | ||
838 | rd[rd_count].record_type = GNUNET_GNSRECORD_TYPE_TOMBSTONE; | ||
839 | rd[rd_count].flags = GNUNET_GNSRECORD_RF_PRIVATE; | ||
840 | rd[rd_count].expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
841 | rd_count++; | ||
842 | } | ||
843 | return GNUNET_NAMESTORE_records_store_ (namestore_handle, | ||
844 | key, | ||
845 | label, | ||
846 | rd_count, | ||
847 | rd, | ||
848 | GNUNET_YES, | ||
849 | &ts_store_cont, | ||
850 | ta); | ||
851 | } | ||
852 | |||
853 | 730 | ||
854 | /** | 731 | /** |
855 | * Function used to put all records successively into the DHT. | 732 | * Function used to put all records successively into the DHT. |
@@ -868,17 +745,19 @@ put_gns_record (void *cls, | |||
868 | const struct GNUNET_GNSRECORD_Data *rd) | 745 | const struct GNUNET_GNSRECORD_Data *rd) |
869 | { | 746 | { |
870 | struct GNUNET_GNSRECORD_Data rd_public[rd_count]; | 747 | struct GNUNET_GNSRECORD_Data rd_public[rd_count]; |
748 | struct GNUNET_GNSRECORD_Data rd_fresh[rd_count + 1]; | ||
871 | unsigned int rd_public_count; | 749 | unsigned int rd_public_count; |
750 | unsigned int rd_fresh_count = 0; | ||
872 | struct DhtPutActivity *ma; | 751 | struct DhtPutActivity *ma; |
873 | struct TombstoneActivity *ta; | 752 | struct TombstoneActivity *ta; |
874 | struct GNUNET_TIME_Absolute expire; | 753 | struct GNUNET_TIME_Absolute expire; |
875 | 754 | ||
876 | (void) cls; | 755 | (void) cls; |
877 | ns_iteration_left--; | 756 | ns_iteration_left--; |
878 | rd_public_count = convert_records_for_export (rd, | 757 | rd_public_count = ZMSTR_convert_records_for_export (rd, |
879 | rd_count, | 758 | rd_count, |
880 | rd_public, | 759 | rd_public, |
881 | &expire); | 760 | &expire); |
882 | if (0 == rd_public_count) | 761 | if (0 == rd_public_count) |
883 | { | 762 | { |
884 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -886,6 +765,19 @@ put_gns_record (void *cls, | |||
886 | check_zone_namestore_next (); | 765 | check_zone_namestore_next (); |
887 | return; | 766 | return; |
888 | } | 767 | } |
768 | for (unsigned int i = 0; i < rd_public_count; i++) | ||
769 | { | ||
770 | if (0 != (rd_public[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | ||
771 | { | ||
772 | /* GNUNET_GNSRECORD_block_create will convert to absolute time; | ||
773 | we just need to adjust our iteration frequency */ | ||
774 | min_relative_record_time.rel_value_us = | ||
775 | GNUNET_MIN (rd_public[i].expiration_time, | ||
776 | min_relative_record_time.rel_value_us); | ||
777 | } | ||
778 | } | ||
779 | |||
780 | |||
889 | /* We got a set of records to publish */ | 781 | /* We got a set of records to publish */ |
890 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
891 | "Starting DHT PUT\n"); | 783 | "Starting DHT PUT\n"); |
@@ -899,12 +791,23 @@ put_gns_record (void *cls, | |||
899 | expire, | 791 | expire, |
900 | ma); | 792 | ma); |
901 | ta = GNUNET_new (struct TombstoneActivity); | 793 | ta = GNUNET_new (struct TombstoneActivity); |
902 | ta->ns_qe = touch_tombstone (key, | 794 | ZMSTR_touch_tombstone (key, |
903 | label, | 795 | label, |
904 | rd, | 796 | rd, |
905 | rd_count, | 797 | rd_count, |
906 | expire, | 798 | rd_fresh, |
907 | ta); | 799 | &rd_fresh_count, |
800 | expire); | ||
801 | ta->ns_qe = GNUNET_NAMESTORE_records_store_ (namestore_handle, | ||
802 | key, | ||
803 | label, | ||
804 | rd_fresh_count, | ||
805 | rd_fresh, | ||
806 | GNUNET_YES, | ||
807 | &ts_store_cont, | ||
808 | ta); | ||
809 | |||
810 | |||
908 | GNUNET_CONTAINER_DLL_insert_tail (ta_head, | 811 | GNUNET_CONTAINER_DLL_insert_tail (ta_head, |
909 | ta_tail, | 812 | ta_tail, |
910 | ta); | 813 | ta); |
@@ -940,7 +843,6 @@ put_gns_record (void *cls, | |||
940 | } | 843 | } |
941 | } | 844 | } |
942 | 845 | ||
943 | |||
944 | /** | 846 | /** |
945 | * Periodically iterate over all zones and store everything in DHT | 847 | * Periodically iterate over all zones and store everything in DHT |
946 | * | 848 | * |