aboutsummaryrefslogtreecommitdiff
path: root/src/zonemaster/gnunet-service-zonemaster.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-10-04 20:31:16 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-10-04 20:31:16 +0900
commit4aeb9686fb4bd0fa686d1aa8c99211312726fcf0 (patch)
tree22c4b918f5881cf9dc19b58644b6d28f41fc850e /src/zonemaster/gnunet-service-zonemaster.c
parent34ae70a81bbfddc877593079e2e5f94f179deffc (diff)
downloadgnunet-4aeb9686fb4bd0fa686d1aa8c99211312726fcf0.tar.gz
gnunet-4aeb9686fb4bd0fa686d1aa8c99211312726fcf0.zip
NAMESTORE: Move Namecache block refresh into zonemonitor
Diffstat (limited to 'src/zonemaster/gnunet-service-zonemaster.c')
-rw-r--r--src/zonemaster/gnunet-service-zonemaster.c189
1 files changed, 179 insertions, 10 deletions
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c
index dba1b24ce..ded86c7fa 100644
--- a/src/zonemaster/gnunet-service-zonemaster.c
+++ b/src/zonemaster/gnunet-service-zonemaster.c
@@ -28,6 +28,7 @@
28#include "gnunet_dnsparser_lib.h" 28#include "gnunet_dnsparser_lib.h"
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_namecache_service.h"
31#include "gnunet_statistics_service.h" 32#include "gnunet_statistics_service.h"
32 33
33#define LOG_STRERROR_FILE(kind, syscall, \ 34#define LOG_STRERROR_FILE(kind, syscall, \
@@ -115,6 +116,28 @@ struct DhtPutActivity
115 struct GNUNET_TIME_Absolute start_date; 116 struct GNUNET_TIME_Absolute start_date;
116}; 117};
117 118
119/**
120 * Pending operation on the namecache.
121 */
122struct CacheOperation
123{
124 /**
125 * Kept in a DLL.
126 */
127 struct CacheOperation *prev;
128
129 /**
130 * Kept in a DLL.
131 */
132 struct CacheOperation *next;
133
134 /**
135 * Handle to namecache queue.
136 */
137 struct GNUNET_NAMECACHE_QueueEntry *qe;
138
139};
140
118 141
119/** 142/**
120 * Handle to the statistics service 143 * Handle to the statistics service
@@ -132,6 +155,17 @@ static struct GNUNET_DHT_Handle *dht_handle;
132static struct GNUNET_NAMESTORE_Handle *namestore_handle; 155static struct GNUNET_NAMESTORE_Handle *namestore_handle;
133 156
134/** 157/**
158 * Our handle to the namecache service
159 */
160static struct GNUNET_NAMECACHE_Handle *namecache;
161
162/**
163 * Use the namecache? Doing so creates additional cryptographic
164 * operations whenever we touch a record.
165 */
166static int disable_namecache;
167
168/**
135 * Handle to iterate over our authoritative zone in namestore 169 * Handle to iterate over our authoritative zone in namestore
136 */ 170 */
137static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; 171static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
@@ -235,6 +269,16 @@ static int first_zone_iteration;
235 */ 269 */
236static int cache_keys; 270static int cache_keys;
237 271
272/**
273 * Head of cop DLL.
274 */
275static struct CacheOperation *cop_head;
276
277/**
278 * Tail of cop DLL.
279 */
280static struct CacheOperation *cop_tail;
281
238 282
239/** 283/**
240 * Task run during shutdown. 284 * Task run during shutdown.
@@ -246,10 +290,20 @@ static void
246shutdown_task (void *cls) 290shutdown_task (void *cls)
247{ 291{
248 struct DhtPutActivity *ma; 292 struct DhtPutActivity *ma;
293 struct CacheOperation *cop;
249 294
250 (void) cls; 295 (void) cls;
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "Shutting down!\n"); 297 "Shutting down!\n");
298 while (NULL != (cop = cop_head))
299 {
300 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
301 "Aborting incomplete namecache operation\n");
302 GNUNET_NAMECACHE_cancel (cop->qe);
303 GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop);
304 GNUNET_free (cop);
305 }
306
253 while (NULL != (ma = it_head)) 307 while (NULL != (ma = it_head))
254 { 308 {
255 GNUNET_DHT_put_cancel (ma->ph); 309 GNUNET_DHT_put_cancel (ma->ph);
@@ -281,13 +335,78 @@ shutdown_task (void *cls)
281 GNUNET_NAMESTORE_disconnect (namestore_handle); 335 GNUNET_NAMESTORE_disconnect (namestore_handle);
282 namestore_handle = NULL; 336 namestore_handle = NULL;
283 } 337 }
284 if (NULL != dht_handle) 338 if (NULL != namecache)
339 {
340 GNUNET_NAMECACHE_disconnect (namecache);
341 namecache = NULL;
342 }
343if (NULL != dht_handle)
285 { 344 {
286 GNUNET_DHT_disconnect (dht_handle); 345 GNUNET_DHT_disconnect (dht_handle);
287 dht_handle = NULL; 346 dht_handle = NULL;
288 } 347 }
289} 348}
290 349
350/**
351 * Cache operation complete, clean up.
352 *
353 * @param cls the `struct CacheOperation`
354 * @param success success
355 * @param emsg error messages
356 */
357static void
358finish_cache_operation (void *cls, int32_t success, const char *emsg)
359{
360 struct CacheOperation *cop = cls;
361
362 if (NULL != emsg)
363 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
364 _ ("Failed to replicate block in namecache: %s\n"),
365 emsg);
366 else
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CACHE operation completed\n");
368 GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop);
369 GNUNET_free (cop);
370}
371
372
373/**
374 * Refresh the (encrypted) block in the namecache.
375 *
376 * @param zone_key private key of the zone
377 * @param name label for the records
378 * @param rd_count number of records
379 * @param rd records stored under the given @a name
380 */
381static void
382refresh_block (const struct GNUNET_GNSRECORD_Block *block)
383{
384 struct CacheOperation *cop;
385 struct GNUNET_TIME_Absolute exp_time;
386
387 if (GNUNET_YES == disable_namecache)
388 {
389 GNUNET_STATISTICS_update (statistics,
390 "Namecache updates skipped (NC disabled)",
391 1,
392 GNUNET_NO);
393 return;
394 }
395 GNUNET_assert (NULL != block);
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Caching block in namecache\n");
397 GNUNET_STATISTICS_update (statistics,
398 "Namecache updates pushed",
399 1,
400 GNUNET_NO);
401 cop = GNUNET_new (struct CacheOperation);
402 GNUNET_CONTAINER_DLL_insert (cop_head, cop_tail, cop);
403 cop->qe = GNUNET_NAMECACHE_block_cache (namecache,
404 block,
405 &finish_cache_operation,
406 cop);
407}
408
409
291 410
292/** 411/**
293 * Method called periodically that triggers iteration over authoritative records 412 * Method called periodically that triggers iteration over authoritative records
@@ -539,35 +658,68 @@ dht_put_continuation (void *cls)
539static struct GNUNET_DHT_PutHandle * 658static struct GNUNET_DHT_PutHandle *
540perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, 659perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key,
541 const char *label, 660 const char *label,
542 const struct GNUNET_GNSRECORD_Data *rd_public, 661 const struct GNUNET_GNSRECORD_Data *rd,
543 unsigned int rd_public_count, 662 unsigned int rd_count,
544 const struct GNUNET_TIME_Absolute expire, 663 const struct GNUNET_TIME_Absolute expire,
545 struct DhtPutActivity *ma) 664 struct DhtPutActivity *ma)
546{ 665{
666 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
547 struct GNUNET_GNSRECORD_Block *block; 667 struct GNUNET_GNSRECORD_Block *block;
668 struct GNUNET_GNSRECORD_Block *block_priv;
548 struct GNUNET_HashCode query; 669 struct GNUNET_HashCode query;
670 struct GNUNET_TIME_Absolute expire_priv;
549 size_t block_size; 671 size_t block_size;
672 unsigned int rd_public_count = 0;
550 struct GNUNET_DHT_PutHandle *ret; 673 struct GNUNET_DHT_PutHandle *ret;
674 char *emsg;
675
676 if (GNUNET_OK !=
677 GNUNET_GNSRECORD_normalize_record_set (label,
678 rd,
679 rd_count,
680 rd_public,
681 &rd_public_count,
682 &expire_priv,
683 GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE,
684 &emsg))
685 {
686 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
687 "%s\n", emsg);
688 GNUNET_free (emsg);
689 }
551 690
552 if (cache_keys) 691 if (cache_keys)
692 {
553 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create2 (key, 693 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create2 (key,
554 expire, 694 expire,
555 label, 695 label,
556 rd_public, 696 rd_public,
557 rd_public_count, 697 rd_public_count,
558 &block)); 698 &block));
699 }
559 else 700 else
560 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (key, 701 {
561 expire, 702 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (key,
562 label, 703 expire,
563 rd_public, 704 label,
564 rd_public_count, 705 rd_public,
565 &block)); 706 rd_public_count,
707 &block));
708 }
566 if (NULL == block) 709 if (NULL == block)
567 { 710 {
568 GNUNET_break (0); 711 GNUNET_break (0);
569 return NULL; /* whoops */ 712 return NULL; /* whoops */
570 } 713 }
714 if (rd_count != rd_public_count)
715 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_create (key,
716 expire_priv,
717 label,
718 rd,
719 rd_count,
720 &block_priv));
721 else
722 block_priv = block;
571 block_size = GNUNET_GNSRECORD_block_get_size (block); 723 block_size = GNUNET_GNSRECORD_block_get_size (block);
572 GNUNET_GNSRECORD_query_from_private_key (key, 724 GNUNET_GNSRECORD_query_from_private_key (key,
573 label, 725 label,
@@ -593,6 +745,9 @@ perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key,
593 expire, 745 expire,
594 &dht_put_continuation, 746 &dht_put_continuation,
595 ma); 747 ma);
748 refresh_block (block_priv);
749 if (block != block_priv)
750 GNUNET_free (block_priv);
596 GNUNET_free (block); 751 GNUNET_free (block);
597 return ret; 752 return ret;
598} 753}
@@ -783,7 +938,7 @@ publish_zone_dht_start (void *cls)
783 NULL, 938 NULL,
784 &zone_iteration_finished, 939 &zone_iteration_finished,
785 NULL, 940 NULL,
786 GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE); 941 GNUNET_GNSRECORD_FILTER_NONE);
787 GNUNET_assert (NULL != namestore_iter); 942 GNUNET_assert (NULL != namestore_iter);
788} 943}
789 944
@@ -816,6 +971,20 @@ run (void *cls,
816 GNUNET_SCHEDULER_shutdown (); 971 GNUNET_SCHEDULER_shutdown ();
817 return; 972 return;
818 } 973 }
974 disable_namecache = GNUNET_CONFIGURATION_get_value_yesno (c,
975 "namecache",
976 "DISABLE");
977 if (GNUNET_NO == disable_namecache)
978 {
979 namecache = GNUNET_NAMECACHE_connect (c);
980 if (NULL == namecache)
981 {
982 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
983 _ ("Failed to connect to the namecache!\n"));
984 GNUNET_SCHEDULER_shutdown ();
985 return;
986 }
987 }
819 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, 988 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c,
820 "namestore", 989 "namestore",
821 "CACHE_KEYS"); 990 "CACHE_KEYS");