aboutsummaryrefslogtreecommitdiff
path: root/src/zonemaster/gnunet-service-zonemaster.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zonemaster/gnunet-service-zonemaster.c')
-rw-r--r--src/zonemaster/gnunet-service-zonemaster.c268
1 files changed, 30 insertions, 238 deletions
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c
index 8220e6eab..81d6fa2d9 100644
--- a/src/zonemaster/gnunet-service-zonemaster.c
+++ b/src/zonemaster/gnunet-service-zonemaster.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014, 2017 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2014, 2017, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -29,8 +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 "gnunet_namestore_plugin.h"
33#include "gnunet_signatures.h"
34 32
35 33
36#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) 34#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
@@ -78,23 +76,12 @@
78#define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 76#define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
79 77
80/** 78/**
81 * The default put interval for the zone iteration. In case
82 * no option is found
83 */
84#define DEFAULT_ZONE_PUBLISH_TIME_WINDOW GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
85
86/**
87 * The factor the current zone iteration interval is divided by for each 79 * The factor the current zone iteration interval is divided by for each
88 * additional new record 80 * additional new record
89 */ 81 */
90#define LATE_ITERATION_SPEEDUP_FACTOR 2 82#define LATE_ITERATION_SPEEDUP_FACTOR 2
91 83
92/** 84/**
93 * How long until a DHT PUT attempt should time out?
94 */
95#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
96
97/**
98 * What replication level do we use for DHT PUT operations? 85 * What replication level do we use for DHT PUT operations?
99 */ 86 */
100#define DHT_GNS_REPLICATION_LEVEL 5 87#define DHT_GNS_REPLICATION_LEVEL 5
@@ -148,21 +135,6 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle;
148static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; 135static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
149 136
150/** 137/**
151 * Handle to monitor namestore changes to instant propagation.
152 */
153static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
154
155/**
156 * Head of monitor activities; kept in a DLL.
157 */
158static struct DhtPutActivity *ma_head;
159
160/**
161 * Tail of monitor activities; kept in a DLL.
162 */
163static struct DhtPutActivity *ma_tail;
164
165/**
166 * Head of iteration put activities; kept in a DLL. 138 * Head of iteration put activities; kept in a DLL.
167 */ 139 */
168static struct DhtPutActivity *it_head; 140static struct DhtPutActivity *it_head;
@@ -178,11 +150,6 @@ static struct DhtPutActivity *it_tail;
178static unsigned int dht_queue_length; 150static unsigned int dht_queue_length;
179 151
180/** 152/**
181 * Number of entries in the DHT queue #ma_head.
182 */
183static unsigned int ma_queue_length;
184
185/**
186 * Useful for zone update for DHT put 153 * Useful for zone update for DHT put
187 */ 154 */
188static unsigned long long num_public_records; 155static unsigned long long num_public_records;
@@ -281,15 +248,6 @@ shutdown_task (void *cls)
281 (void) cls; 248 (void) cls;
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "Shutting down!\n"); 250 "Shutting down!\n");
284 while (NULL != (ma = ma_head))
285 {
286 GNUNET_DHT_put_cancel (ma->ph);
287 ma_queue_length--;
288 GNUNET_CONTAINER_DLL_remove (ma_head,
289 ma_tail,
290 ma);
291 GNUNET_free (ma);
292 }
293 while (NULL != (ma = it_head)) 251 while (NULL != (ma = it_head))
294 { 252 {
295 GNUNET_DHT_put_cancel (ma->ph); 253 GNUNET_DHT_put_cancel (ma->ph);
@@ -316,11 +274,6 @@ shutdown_task (void *cls)
316 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); 274 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
317 namestore_iter = NULL; 275 namestore_iter = NULL;
318 } 276 }
319 if (NULL != zmon)
320 {
321 GNUNET_NAMESTORE_zone_monitor_stop (zmon);
322 zmon = NULL;
323 }
324 if (NULL != namestore_handle) 277 if (NULL != namestore_handle)
325 { 278 {
326 GNUNET_NAMESTORE_disconnect (namestore_handle); 279 GNUNET_NAMESTORE_disconnect (namestore_handle);
@@ -362,27 +315,6 @@ publish_zone_dht_start (void *cls);
362 315
363 316
364/** 317/**
365 * Continuation called from DHT once the PUT operation triggered
366 * by a monitor is done.
367 *
368 * @param cls a `struct DhtPutActivity`
369 */
370static void
371dht_put_monitor_continuation (void *cls)
372{
373 struct DhtPutActivity *ma = cls;
374
375 GNUNET_NAMESTORE_zone_monitor_next (zmon,
376 1);
377 ma_queue_length--;
378 GNUNET_CONTAINER_DLL_remove (ma_head,
379 ma_tail,
380 ma);
381 GNUNET_free (ma);
382}
383
384
385/**
386 * Calculate #target_iteration_velocity_per_record. 318 * Calculate #target_iteration_velocity_per_record.
387 */ 319 */
388static void 320static void
@@ -521,10 +453,6 @@ update_velocity (unsigned int cnt)
521 dht_queue_length, 453 dht_queue_length,
522 GNUNET_NO); 454 GNUNET_NO);
523 GNUNET_STATISTICS_set (statistics, 455 GNUNET_STATISTICS_set (statistics,
524 "# size of the DHT queue (mon)",
525 ma_queue_length,
526 GNUNET_NO);
527 GNUNET_STATISTICS_set (statistics,
528 "% speed increase needed for target velocity", 456 "% speed increase needed for target velocity",
529 pct, 457 pct,
530 GNUNET_NO); 458 GNUNET_NO);
@@ -558,6 +486,12 @@ check_zone_namestore_next ()
558 GNUNET_NO); 486 GNUNET_NO);
559 delay = GNUNET_TIME_relative_multiply (delay, 487 delay = GNUNET_TIME_relative_multiply (delay,
560 NS_BLOCK_SIZE); 488 NS_BLOCK_SIZE);
489 /* make sure we do not overshoot because of the #NS_BLOCK_SIZE factor */
490 delay = GNUNET_TIME_relative_min (MAXIMUM_ZONE_ITERATION_INTERVAL,
491 delay);
492 /* no delays on first iteration */
493 if (GNUNET_YES == first_zone_iteration)
494 delay = GNUNET_TIME_UNIT_ZERO;
561 GNUNET_assert (NULL == zone_publish_task); 495 GNUNET_assert (NULL == zone_publish_task);
562 zone_publish_task = GNUNET_SCHEDULER_add_delayed (delay, 496 zone_publish_task = GNUNET_SCHEDULER_add_delayed (delay,
563 &publish_zone_namestore_next, 497 &publish_zone_namestore_next,
@@ -606,24 +540,22 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
606 rd_public_count = 0; 540 rd_public_count = 0;
607 now = GNUNET_TIME_absolute_get (); 541 now = GNUNET_TIME_absolute_get ();
608 for (unsigned int i=0;i<rd_count;i++) 542 for (unsigned int i=0;i<rd_count;i++)
609 if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) 543 {
544 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
545 continue;
546 if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
547 (rd[i].expiration_time < now.abs_value_us) )
548 continue; /* record already expired, skip it */
549 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
610 { 550 {
611 rd_public[rd_public_count] = rd[i]; 551 /* GNUNET_GNSRECORD_block_create will convert to absolute time;
612 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 552 we just need to adjust our iteration frequency */
613 { 553 min_relative_record_time.rel_value_us =
614 /* GNUNET_GNSRECORD_block_create will convert to absolute time; 554 GNUNET_MIN (rd[i].expiration_time,
615 we just need to adjust our iteration frequency */ 555 min_relative_record_time.rel_value_us);
616 min_relative_record_time.rel_value_us =
617 GNUNET_MIN (rd_public[rd_public_count].expiration_time,
618 min_relative_record_time.rel_value_us);
619 }
620 else if (rd_public[rd_public_count].expiration_time < now.abs_value_us)
621 {
622 /* record already expired, skip it */
623 continue;
624 }
625 rd_public_count++;
626 } 556 }
557 rd_public[rd_public_count++] = rd[i];
558 }
627 return rd_public_count; 559 return rd_public_count;
628} 560}
629 561
@@ -635,8 +567,7 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
635 * @param label label to store under 567 * @param label label to store under
636 * @param rd_public public record data 568 * @param rd_public public record data
637 * @param rd_public_count number of records in @a rd_public 569 * @param rd_public_count number of records in @a rd_public
638 * @param cont function to call with PUT result 570 * @param ma handle for the put operation
639 * @param cont_cls closure for @a cont
640 * @return DHT PUT handle, NULL on error 571 * @return DHT PUT handle, NULL on error
641 */ 572 */
642static struct GNUNET_DHT_PutHandle * 573static struct GNUNET_DHT_PutHandle *
@@ -644,8 +575,7 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
644 const char *label, 575 const char *label,
645 const struct GNUNET_GNSRECORD_Data *rd_public, 576 const struct GNUNET_GNSRECORD_Data *rd_public,
646 unsigned int rd_public_count, 577 unsigned int rd_public_count,
647 GNUNET_SCHEDULER_TaskCallback cont, 578 struct DhtPutActivity *ma)
648 void *cont_cls)
649{ 579{
650 struct GNUNET_GNSRECORD_Block *block; 580 struct GNUNET_GNSRECORD_Block *block;
651 struct GNUNET_HashCode query; 581 struct GNUNET_HashCode query;
@@ -697,8 +627,8 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
697 block_size, 627 block_size,
698 block, 628 block,
699 expire, 629 expire,
700 cont, 630 &dht_put_continuation,
701 cont_cls); 631 ma);
702 GNUNET_free (block); 632 GNUNET_free (block);
703 return ret; 633 return ret;
704} 634}
@@ -746,8 +676,7 @@ zone_iteration_finished (void *cls)
746 calculate_put_interval (); 676 calculate_put_interval ();
747 /* reset for next iteration */ 677 /* reset for next iteration */
748 min_relative_record_time 678 min_relative_record_time
749 = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, 679 = GNUNET_TIME_UNIT_FOREVER_REL;
750 PUBLISH_OPS_PER_EXPIRATION);
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Zone iteration finished. Adjusted zone iteration interval to %s\n", 681 "Zone iteration finished. Adjusted zone iteration interval to %s\n",
753 GNUNET_STRINGS_relative_time_to_string (target_iteration_velocity_per_record, 682 GNUNET_STRINGS_relative_time_to_string (target_iteration_velocity_per_record,
@@ -816,7 +745,6 @@ put_gns_record (void *cls,
816 label, 745 label,
817 rd_public, 746 rd_public,
818 rd_public_count, 747 rd_public_count,
819 &dht_put_continuation,
820 ma); 748 ma);
821 put_cnt++; 749 put_cnt++;
822 if (0 == put_cnt % DELTA_INTERVAL) 750 if (0 == put_cnt % DELTA_INTERVAL)
@@ -884,131 +812,6 @@ publish_zone_dht_start (void *cls)
884 812
885 813
886/** 814/**
887 * Process a record that was stored in the namestore
888 * (invoked by the monitor).
889 *
890 * @param cls closure, NULL
891 * @param zone private key of the zone; NULL on disconnect
892 * @param label label of the records; NULL on disconnect
893 * @param rd_count number of entries in @a rd array, 0 if label was deleted
894 * @param rd array of records with data to store
895 */
896static void
897handle_monitor_event (void *cls,
898 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
899 const char *label,
900 unsigned int rd_count,
901 const struct GNUNET_GNSRECORD_Data *rd)
902{
903 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
904 unsigned int rd_public_count;
905 struct DhtPutActivity *ma;
906
907 (void) cls;
908 GNUNET_STATISTICS_update (statistics,
909 "Namestore monitor events received",
910 1,
911 GNUNET_NO);
912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
913 "Received %u records for label `%s' via namestore monitor\n",
914 rd_count,
915 label);
916 /* filter out records that are not public, and convert to
917 absolute expiration time. */
918 rd_public_count = convert_records_for_export (rd,
919 rd_count,
920 rd_public);
921 if (0 == rd_public_count)
922 {
923 GNUNET_NAMESTORE_zone_monitor_next (zmon,
924 1);
925 return; /* nothing to do */
926 }
927 num_public_records++;
928 ma = GNUNET_new (struct DhtPutActivity);
929 ma->start_date = GNUNET_TIME_absolute_get ();
930 ma->ph = perform_dht_put (zone,
931 label,
932 rd,
933 rd_count,
934 &dht_put_monitor_continuation,
935 ma);
936 if (NULL == ma->ph)
937 {
938 /* PUT failed, do not remember operation */
939 GNUNET_free (ma);
940 GNUNET_NAMESTORE_zone_monitor_next (zmon,
941 1);
942 return;
943 }
944 GNUNET_CONTAINER_DLL_insert_tail (ma_head,
945 ma_tail,
946 ma);
947 ma_queue_length++;
948 if (ma_queue_length > DHT_QUEUE_LIMIT)
949 {
950 ma = ma_head;
951 GNUNET_CONTAINER_DLL_remove (ma_head,
952 ma_tail,
953 ma);
954 GNUNET_DHT_put_cancel (ma->ph);
955 ma_queue_length--;
956 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
957 "DHT PUT unconfirmed after %s, aborting PUT\n",
958 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date),
959 GNUNET_YES));
960 GNUNET_free (ma);
961 }
962}
963
964
965/**
966 * The zone monitor is now in SYNC with the current state of the
967 * name store. Start to perform periodic iterations.
968 *
969 * @param cls NULL
970 */
971static void
972monitor_sync_event (void *cls)
973{
974 (void) cls;
975 if ( (NULL == zone_publish_task) &&
976 (NULL == namestore_iter) )
977 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
978 NULL);
979}
980
981
982/**
983 * The zone monitor encountered an IPC error trying to to get in
984 * sync. Restart from the beginning.
985 *
986 * @param cls NULL
987 */
988static void
989handle_monitor_error (void *cls)
990{
991 (void) cls;
992 GNUNET_STATISTICS_update (statistics,
993 "Namestore monitor errors encountered",
994 1,
995 GNUNET_NO);
996 if (NULL != zone_publish_task)
997 {
998 GNUNET_SCHEDULER_cancel (zone_publish_task);
999 zone_publish_task = NULL;
1000 }
1001 if (NULL != namestore_iter)
1002 {
1003 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
1004 namestore_iter = NULL;
1005 }
1006 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
1007 NULL);
1008}
1009
1010
1011/**
1012 * Performe zonemaster duties: watch namestore, publish records. 815 * Performe zonemaster duties: watch namestore, publish records.
1013 * 816 *
1014 * @param cls closure 817 * @param cls closure
@@ -1026,8 +829,7 @@ run (void *cls,
1026 (void) service; 829 (void) service;
1027 last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */ 830 last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */
1028 min_relative_record_time 831 min_relative_record_time
1029 = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, 832 = GNUNET_TIME_UNIT_FOREVER_REL;
1030 PUBLISH_OPS_PER_EXPIRATION);
1031 target_iteration_velocity_per_record = INITIAL_ZONE_ITERATION_INTERVAL; 833 target_iteration_velocity_per_record = INITIAL_ZONE_ITERATION_INTERVAL;
1032 namestore_handle = GNUNET_NAMESTORE_connect (c); 834 namestore_handle = GNUNET_NAMESTORE_connect (c);
1033 if (NULL == namestore_handle) 835 if (NULL == namestore_handle)
@@ -1040,7 +842,7 @@ run (void *cls,
1040 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, 842 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c,
1041 "namestore", 843 "namestore",
1042 "CACHE_KEYS"); 844 "CACHE_KEYS");
1043 zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; 845 zone_publish_time_window_default = GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY;
1044 if (GNUNET_OK == 846 if (GNUNET_OK ==
1045 GNUNET_CONFIGURATION_get_value_time (c, 847 GNUNET_CONFIGURATION_get_value_time (c,
1046 "zonemaster", 848 "zonemaster",
@@ -1084,18 +886,8 @@ run (void *cls,
1084 "Target zone iteration velocity (μs)", 886 "Target zone iteration velocity (μs)",
1085 target_iteration_velocity_per_record.rel_value_us, 887 target_iteration_velocity_per_record.rel_value_us,
1086 GNUNET_NO); 888 GNUNET_NO);
1087 zmon = GNUNET_NAMESTORE_zone_monitor_start (c, 889 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
1088 NULL, 890 NULL);
1089 GNUNET_NO,
1090 &handle_monitor_error,
1091 NULL,
1092 &handle_monitor_event,
1093 NULL,
1094 &monitor_sync_event,
1095 NULL);
1096 GNUNET_NAMESTORE_zone_monitor_next (zmon,
1097 NAMESTORE_QUEUE_LIMIT - 1);
1098 GNUNET_break (NULL != zmon);
1099 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 891 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1100 NULL); 892 NULL);
1101} 893}