diff options
Diffstat (limited to 'src/zonemaster/zonemaster_misc.c')
-rw-r--r-- | src/zonemaster/zonemaster_misc.c | 132 |
1 files changed, 0 insertions, 132 deletions
diff --git a/src/zonemaster/zonemaster_misc.c b/src/zonemaster/zonemaster_misc.c deleted file mode 100644 index f067e9c62..000000000 --- a/src/zonemaster/zonemaster_misc.c +++ /dev/null | |||
@@ -1,132 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | |||
22 | #include "zonemaster_misc.h" | ||
23 | |||
24 | /** | ||
25 | * Convert namestore records from the internal format to that | ||
26 | * suitable for publication (removes private records, converts | ||
27 | * to absolute expiration time). | ||
28 | * | ||
29 | * @param rd input records | ||
30 | * @param rd_count size of the @a rd and @a rd_public arrays | ||
31 | * @param rd_public where to write the converted records | ||
32 | * @param expire the expiration of the block | ||
33 | * @return number of records written to @a rd_public | ||
34 | */ | ||
35 | unsigned int | ||
36 | ZMSTR_convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, | ||
37 | unsigned int rd_count, | ||
38 | struct GNUNET_GNSRECORD_Data *rd_public, | ||
39 | struct GNUNET_TIME_Absolute *expiry) | ||
40 | { | ||
41 | const struct GNUNET_GNSRECORD_TombstoneRecord *tombstone; | ||
42 | struct GNUNET_TIME_Absolute expiry_tombstone; | ||
43 | struct GNUNET_TIME_Absolute now; | ||
44 | unsigned int rd_public_count; | ||
45 | |||
46 | rd_public_count = 0; | ||
47 | tombstone = NULL; | ||
48 | now = GNUNET_TIME_absolute_get (); | ||
49 | for (unsigned int i = 0; i < rd_count; i++) | ||
50 | { | ||
51 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) | ||
52 | { | ||
53 | tombstone = rd[i].data; | ||
54 | continue; | ||
55 | } | ||
56 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) | ||
57 | continue; | ||
58 | if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) && | ||
59 | (rd[i].expiration_time < now.abs_value_us)) | ||
60 | continue; /* record already expired, skip it */ | ||
61 | rd_public[rd_public_count] = rd[i]; | ||
62 | /* Make sure critical record types are published as such */ | ||
63 | if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type)) | ||
64 | rd_public[rd_public_count].flags |= GNUNET_GNSRECORD_RF_CRITICAL; | ||
65 | rd_public_count++; | ||
66 | } | ||
67 | |||
68 | *expiry = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count, | ||
69 | rd_public); | ||
70 | |||
71 | /* We need to check if the tombstone has an expiration in the fututre | ||
72 | * which would mean there was a block published under this label | ||
73 | * previously that is still valid. In this case we MUST NOT publish this | ||
74 | * block | ||
75 | */ | ||
76 | if (NULL != tombstone) | ||
77 | { | ||
78 | expiry_tombstone = GNUNET_TIME_absolute_ntoh (tombstone->time_of_death); | ||
79 | if (GNUNET_TIME_absolute_cmp (*expiry,<=,expiry_tombstone)) | ||
80 | return 0; | ||
81 | } | ||
82 | return rd_public_count; | ||
83 | } | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Update tombstone records. | ||
88 | * | ||
89 | * @param key key of the zone | ||
90 | * @param label label to store under | ||
91 | * @param rd_public public record data | ||
92 | * @param rd_public_count number of records in @a rd_public | ||
93 | * @param rd the buffer for the result. Must be rd_public_count +1 | ||
94 | * @param rd_count the actual number of records written to rd | ||
95 | * @param expire the expiration time for the tombstone | ||
96 | * @return Namestore queue entry, NULL on error | ||
97 | */ | ||
98 | void | ||
99 | ZMSTR_touch_tombstone (const struct GNUNET_IDENTITY_PrivateKey *key, | ||
100 | const char *label, | ||
101 | const struct GNUNET_GNSRECORD_Data *rd_original, | ||
102 | unsigned int rd_count_original, | ||
103 | struct GNUNET_GNSRECORD_Data *rd, | ||
104 | unsigned int *rd_count, | ||
105 | const struct GNUNET_TIME_Absolute expire) | ||
106 | { | ||
107 | struct GNUNET_TIME_AbsoluteNBO exp_nbo; | ||
108 | int tombstone_exists = GNUNET_NO; | ||
109 | unsigned int i; | ||
110 | |||
111 | exp_nbo = GNUNET_TIME_absolute_hton (expire); | ||
112 | for (i = 0; i < rd_count_original; i++) | ||
113 | { | ||
114 | memcpy (&rd[i], &rd_original[i], | ||
115 | sizeof (struct GNUNET_GNSRECORD_Data)); | ||
116 | if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type) | ||
117 | { | ||
118 | rd[i].data = &exp_nbo; | ||
119 | tombstone_exists = GNUNET_YES; | ||
120 | } | ||
121 | } | ||
122 | if (GNUNET_NO == tombstone_exists) | ||
123 | { | ||
124 | rd[i].data = &exp_nbo; | ||
125 | rd[i].data_size = sizeof (exp_nbo); | ||
126 | rd[i].record_type = GNUNET_GNSRECORD_TYPE_TOMBSTONE; | ||
127 | rd[i].flags = GNUNET_GNSRECORD_RF_PRIVATE; | ||
128 | rd[i].expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
129 | i++; | ||
130 | } | ||
131 | *rd_count = i; | ||
132 | } | ||