aboutsummaryrefslogtreecommitdiff
path: root/src/zonemaster
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-02-06 14:30:00 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2022-02-06 14:30:00 +0100
commit215032563755ba48d4e871b82c9c6697611726f8 (patch)
tree51123c26b3d1418d0d400593438e23da48a8b4c8 /src/zonemaster
parentd322de96b95a7afad7f5bd255bf70642840a3778 (diff)
downloadgnunet-215032563755ba48d4e871b82c9c6697611726f8.tar.gz
gnunet-215032563755ba48d4e871b82c9c6697611726f8.zip
-simlify and correct tombstone logic
Diffstat (limited to 'src/zonemaster')
-rw-r--r--src/zonemaster/Makefile.am6
-rw-r--r--src/zonemaster/gnunet-service-zonemaster-monitor.c89
-rw-r--r--src/zonemaster/gnunet-service-zonemaster.c88
-rw-r--r--src/zonemaster/zonemaster_misc.c132
-rw-r--r--src/zonemaster/zonemaster_misc.h62
5 files changed, 10 insertions, 367 deletions
diff --git a/src/zonemaster/Makefile.am b/src/zonemaster/Makefile.am
index d561d75fe..f2d569c75 100644
--- a/src/zonemaster/Makefile.am
+++ b/src/zonemaster/Makefile.am
@@ -20,8 +20,7 @@ libexec_PROGRAMS = \
20 gnunet-service-zonemaster-monitor 20 gnunet-service-zonemaster-monitor
21 21
22gnunet_service_zonemaster_SOURCES = \ 22gnunet_service_zonemaster_SOURCES = \
23 gnunet-service-zonemaster.c \ 23 gnunet-service-zonemaster.c
24 zonemaster_misc.c zonemaster_misc.h
25gnunet_service_zonemaster_LDADD = \ 24gnunet_service_zonemaster_LDADD = \
26 $(top_builddir)/src/dht/libgnunetdht.la \ 25 $(top_builddir)/src/dht/libgnunetdht.la \
27 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 26 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
@@ -33,8 +32,7 @@ gnunet_service_zonemaster_LDADD = \
33 32
34 33
35gnunet_service_zonemaster_monitor_SOURCES = \ 34gnunet_service_zonemaster_monitor_SOURCES = \
36 gnunet-service-zonemaster-monitor.c \ 35 gnunet-service-zonemaster-monitor.c
37 zonemaster_misc.c zonemaster_misc.h
38gnunet_service_zonemaster_monitor_LDADD = \ 36gnunet_service_zonemaster_monitor_LDADD = \
39 $(top_builddir)/src/dht/libgnunetdht.la \ 37 $(top_builddir)/src/dht/libgnunetdht.la \
40 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 38 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
diff --git a/src/zonemaster/gnunet-service-zonemaster-monitor.c b/src/zonemaster/gnunet-service-zonemaster-monitor.c
index dcacec60f..fef9e6b82 100644
--- a/src/zonemaster/gnunet-service-zonemaster-monitor.c
+++ b/src/zonemaster/gnunet-service-zonemaster-monitor.c
@@ -28,7 +28,6 @@
28#include "gnunet_dht_service.h" 28#include "gnunet_dht_service.h"
29#include "gnunet_namestore_service.h" 29#include "gnunet_namestore_service.h"
30#include "gnunet_statistics_service.h" 30#include "gnunet_statistics_service.h"
31#include "zonemaster_misc.h"
32 31
33#define LOG_STRERROR_FILE(kind, syscall, \ 32#define LOG_STRERROR_FILE(kind, syscall, \
34 filename) GNUNET_log_from_strerror_file (kind, "util", \ 33 filename) GNUNET_log_from_strerror_file (kind, "util", \
@@ -59,30 +58,6 @@
59#define DHT_GNS_REPLICATION_LEVEL 5 58#define DHT_GNS_REPLICATION_LEVEL 5
60 59
61/** 60/**
62 * Handle for tombston updates which are executed for each published
63 * record set.
64 */
65struct TombstoneActivity
66{
67 /**
68 * Kept in a DLL.
69 */
70 struct TombstoneActivity *next;
71
72 /**
73 * Kept in a DLL.
74 */
75 struct TombstoneActivity *prev;
76
77 /**
78 * Handle for the store operation.
79 */
80 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
81
82};
83
84
85/**
86 * Handle for DHT PUT activity triggered from the namestore monitor. 61 * Handle for DHT PUT activity triggered from the namestore monitor.
87 */ 62 */
88struct DhtPutActivity 63struct DhtPutActivity
@@ -130,17 +105,6 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle;
130static struct GNUNET_NAMESTORE_ZoneMonitor *zmon; 105static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
131 106
132/** 107/**
133 * Head of the tombstone operations
134 */
135static struct TombstoneActivity *ta_head;
136
137/**
138 * Tail of the tombstone operations
139 */
140static struct TombstoneActivity *ta_tail;
141
142
143/**
144 * Head of monitor activities; kept in a DLL. 108 * Head of monitor activities; kept in a DLL.
145 */ 109 */
146static struct DhtPutActivity *ma_head; 110static struct DhtPutActivity *ma_head;
@@ -186,14 +150,6 @@ shutdown_task (void *cls)
186 ma); 150 ma);
187 GNUNET_free (ma); 151 GNUNET_free (ma);
188 } 152 }
189 while (NULL != (ta = ta_head))
190 {
191 GNUNET_NAMESTORE_cancel (ta->ns_qe);
192 GNUNET_CONTAINER_DLL_remove (ta_head,
193 ta_tail,
194 ta);
195 GNUNET_free (ta);
196 }
197 if (NULL != statistics) 153 if (NULL != statistics)
198 { 154 {
199 GNUNET_STATISTICS_destroy (statistics, 155 GNUNET_STATISTICS_destroy (statistics,
@@ -309,21 +265,6 @@ perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key,
309 return ret; 265 return ret;
310} 266}
311 267
312static void
313ts_store_cont (void *cls, int32_t success, const char *emsg)
314{
315 struct TombstoneActivity *ta = cls;
316
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
318 "Tombstone update complete\n");
319 GNUNET_CONTAINER_DLL_remove (ta_head,
320 ta_tail,
321 ta);
322 GNUNET_free (ta);
323
324}
325
326
327/** 268/**
328 * Process a record that was stored in the namestore 269 * Process a record that was stored in the namestore
329 * (invoked by the monitor). 270 * (invoked by the monitor).
@@ -346,7 +287,6 @@ handle_monitor_event (void *cls,
346 unsigned int rd_public_count; 287 unsigned int rd_public_count;
347 unsigned int rd_fresh_count; 288 unsigned int rd_fresh_count;
348 struct DhtPutActivity *ma; 289 struct DhtPutActivity *ma;
349 struct TombstoneActivity *ta;
350 struct GNUNET_TIME_Absolute expire; 290 struct GNUNET_TIME_Absolute expire;
351 291
352 (void) cls; 292 (void) cls;
@@ -360,10 +300,10 @@ handle_monitor_event (void *cls,
360 label); 300 label);
361 /* filter out records that are not public, and convert to 301 /* filter out records that are not public, and convert to
362 absolute expiration time. */ 302 absolute expiration time. */
363 rd_public_count = ZMSTR_convert_records_for_export (rd, 303 rd_public_count = GNUNET_GNSRECORD_convert_records_for_export (rd,
364 rd_count, 304 rd_count,
365 rd_public, 305 rd_public,
366 &expire); 306 &expire);
367 if (0 == rd_public_count) 307 if (0 == rd_public_count)
368 { 308 {
369 GNUNET_NAMESTORE_zone_monitor_next (zmon, 309 GNUNET_NAMESTORE_zone_monitor_next (zmon,
@@ -378,27 +318,6 @@ handle_monitor_event (void *cls,
378 rd_count, 318 rd_count,
379 expire, 319 expire,
380 ma); 320 ma);
381 ta = GNUNET_new (struct TombstoneActivity);
382 ZMSTR_touch_tombstone (zone,
383 label,
384 rd,
385 rd_count,
386 rd_fresh,
387 &rd_fresh_count,
388 expire);
389 ta->ns_qe = GNUNET_NAMESTORE_records_store_ (namestore_handle,
390 zone,
391 label,
392 rd_fresh_count,
393 rd_fresh,
394 GNUNET_YES,
395 &ts_store_cont,
396 ta);
397
398
399 GNUNET_CONTAINER_DLL_insert_tail (ta_head,
400 ta_tail,
401 ta);
402 if (NULL == ma->ph) 321 if (NULL == ma->ph)
403 { 322 {
404 /* PUT failed, do not remember operation */ 323 /* PUT failed, do not remember operation */
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c
index 9f0de8a54..9eb3432ee 100644
--- a/src/zonemaster/gnunet-service-zonemaster.c
+++ b/src/zonemaster/gnunet-service-zonemaster.c
@@ -29,7 +29,6 @@
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#include "zonemaster_misc.h"
33 32
34#define LOG_STRERROR_FILE(kind, syscall, \ 33#define LOG_STRERROR_FILE(kind, syscall, \
35 filename) GNUNET_log_from_strerror_file (kind, "util", \ 34 filename) GNUNET_log_from_strerror_file (kind, "util", \
@@ -91,30 +90,6 @@
91#define DHT_GNS_REPLICATION_LEVEL 5 90#define DHT_GNS_REPLICATION_LEVEL 5
92 91
93/** 92/**
94 * Handle for tombston updates which are executed for each published
95 * record set.
96 */
97struct TombstoneActivity
98{
99 /**
100 * Kept in a DLL.
101 */
102 struct TombstoneActivity *next;
103
104 /**
105 * Kept in a DLL.
106 */
107 struct TombstoneActivity *prev;
108
109 /**
110 * Handle for the store operation.
111 */
112 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
113
114};
115
116
117/**
118 * Handle for DHT PUT activity triggered from the namestore monitor. 93 * Handle for DHT PUT activity triggered from the namestore monitor.
119 */ 94 */
120struct DhtPutActivity 95struct DhtPutActivity
@@ -172,16 +147,6 @@ static struct DhtPutActivity *it_head;
172static struct DhtPutActivity *it_tail; 147static struct DhtPutActivity *it_tail;
173 148
174/** 149/**
175 * Head of the tombstone operations
176 */
177static struct TombstoneActivity *ta_head;
178
179/**
180 * Tail of the tombstone operations
181 */
182static struct TombstoneActivity *ta_tail;
183
184/**
185 * Number of entries in the DHT queue #it_head. 150 * Number of entries in the DHT queue #it_head.
186 */ 151 */
187static unsigned int dht_queue_length; 152static unsigned int dht_queue_length;
@@ -296,14 +261,6 @@ shutdown_task (void *cls)
296 dht_queue_length--; 261 dht_queue_length--;
297 GNUNET_free (ma); 262 GNUNET_free (ma);
298 } 263 }
299 while (NULL != (ta = ta_head))
300 {
301 GNUNET_NAMESTORE_cancel (ta->ns_qe);
302 GNUNET_CONTAINER_DLL_remove (ta_head,
303 ta_tail,
304 ta);
305 GNUNET_free (ta);
306 }
307 if (NULL != statistics) 264 if (NULL != statistics)
308 { 265 {
309 GNUNET_STATISTICS_destroy (statistics, 266 GNUNET_STATISTICS_destroy (statistics,
@@ -713,21 +670,6 @@ zone_iteration_finished (void *cls)
713 } 670 }
714} 671}
715 672
716static void
717ts_store_cont (void *cls, int32_t success, const char *emsg)
718{
719 struct TombstoneActivity *ta = cls;
720
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
722 "Tombstone update complete\n");
723 GNUNET_CONTAINER_DLL_remove (ta_head,
724 ta_tail,
725 ta);
726 GNUNET_free (ta);
727
728}
729
730
731/** 673/**
732 * Function used to put all records successively into the DHT. 674 * Function used to put all records successively into the DHT.
733 * 675 *
@@ -749,15 +691,14 @@ put_gns_record (void *cls,
749 unsigned int rd_public_count; 691 unsigned int rd_public_count;
750 unsigned int rd_fresh_count = 0; 692 unsigned int rd_fresh_count = 0;
751 struct DhtPutActivity *ma; 693 struct DhtPutActivity *ma;
752 struct TombstoneActivity *ta;
753 struct GNUNET_TIME_Absolute expire; 694 struct GNUNET_TIME_Absolute expire;
754 695
755 (void) cls; 696 (void) cls;
756 ns_iteration_left--; 697 ns_iteration_left--;
757 rd_public_count = ZMSTR_convert_records_for_export (rd, 698 rd_public_count = GNUNET_GNSRECORD_convert_records_for_export (rd,
758 rd_count, 699 rd_count,
759 rd_public, 700 rd_public,
760 &expire); 701 &expire);
761 if (0 == rd_public_count) 702 if (0 == rd_public_count)
762 { 703 {
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -790,27 +731,6 @@ put_gns_record (void *cls,
790 rd_public_count, 731 rd_public_count,
791 expire, 732 expire,
792 ma); 733 ma);
793 ta = GNUNET_new (struct TombstoneActivity);
794 ZMSTR_touch_tombstone (key,
795 label,
796 rd,
797 rd_count,
798 rd_fresh,
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
811 GNUNET_CONTAINER_DLL_insert_tail (ta_head,
812 ta_tail,
813 ta);
814 put_cnt++; 734 put_cnt++;
815 if (0 == put_cnt % DELTA_INTERVAL) 735 if (0 == put_cnt % DELTA_INTERVAL)
816 update_velocity (DELTA_INTERVAL); 736 update_velocity (DELTA_INTERVAL);
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 */
35unsigned int
36ZMSTR_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 */
98void
99ZMSTR_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}
diff --git a/src/zonemaster/zonemaster_misc.h b/src/zonemaster/zonemaster_misc.h
deleted file mode 100644
index 27ef3aab7..000000000
--- a/src/zonemaster/zonemaster_misc.h
+++ /dev/null
@@ -1,62 +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#include "platform.h"
22#include "gnunet_util_lib.h"
23#include "gnunet_namestore_service.h"
24
25
26/**
27 * Convert namestore records from the internal format to that
28 * suitable for publication (removes private records, converts
29 * to absolute expiration time).
30 *
31 * @param rd input records
32 * @param rd_count size of the @a rd and @a rd_public arrays
33 * @param rd_public where to write the converted records
34 * @param expire the expiration of the block
35 * @return number of records written to @a rd_public
36 */
37unsigned int
38ZMSTR_convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
39 unsigned int rd_count,
40 struct GNUNET_GNSRECORD_Data *rd_public,
41 struct GNUNET_TIME_Absolute *expiry);
42
43/**
44 * Update tombstone records.
45 *
46 * @param key key of the zone
47 * @param label label to store under
48 * @param rd_public public record data
49 * @param rd_public_count number of records in @a rd_public
50 * @param rd the buffer for the result. Must be rd_public_count +1
51 * @param rd_count the actual number of records written to rd
52 * @param expire the expiration time for the tombstone
53 * @return Namestore queue entry, NULL on error
54 */
55void
56ZMSTR_touch_tombstone (const struct GNUNET_IDENTITY_PrivateKey *key,
57 const char *label,
58 const struct GNUNET_GNSRECORD_Data *rd_original,
59 unsigned int rd_count_original,
60 struct GNUNET_GNSRECORD_Data *rd,
61 unsigned int *rd_count,
62 const struct GNUNET_TIME_Absolute expire);