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.c198
1 files changed, 3 insertions, 195 deletions
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c
index 8220e6eab..482d3a203 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)
@@ -90,11 +88,6 @@
90#define LATE_ITERATION_SPEEDUP_FACTOR 2 88#define LATE_ITERATION_SPEEDUP_FACTOR 2
91 89
92/** 90/**
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? 91 * What replication level do we use for DHT PUT operations?
99 */ 92 */
100#define DHT_GNS_REPLICATION_LEVEL 5 93#define DHT_GNS_REPLICATION_LEVEL 5
@@ -148,21 +141,6 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle;
148static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; 141static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
149 142
150/** 143/**
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. 144 * Head of iteration put activities; kept in a DLL.
167 */ 145 */
168static struct DhtPutActivity *it_head; 146static struct DhtPutActivity *it_head;
@@ -281,15 +259,6 @@ shutdown_task (void *cls)
281 (void) cls; 259 (void) cls;
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "Shutting down!\n"); 261 "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)) 262 while (NULL != (ma = it_head))
294 { 263 {
295 GNUNET_DHT_put_cancel (ma->ph); 264 GNUNET_DHT_put_cancel (ma->ph);
@@ -316,11 +285,6 @@ shutdown_task (void *cls)
316 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); 285 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
317 namestore_iter = NULL; 286 namestore_iter = NULL;
318 } 287 }
319 if (NULL != zmon)
320 {
321 GNUNET_NAMESTORE_zone_monitor_stop (zmon);
322 zmon = NULL;
323 }
324 if (NULL != namestore_handle) 288 if (NULL != namestore_handle)
325 { 289 {
326 GNUNET_NAMESTORE_disconnect (namestore_handle); 290 GNUNET_NAMESTORE_disconnect (namestore_handle);
@@ -362,27 +326,6 @@ publish_zone_dht_start (void *cls);
362 326
363 327
364/** 328/**
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. 329 * Calculate #target_iteration_velocity_per_record.
387 */ 330 */
388static void 331static void
@@ -884,131 +827,6 @@ publish_zone_dht_start (void *cls)
884 827
885 828
886/** 829/**
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. 830 * Performe zonemaster duties: watch namestore, publish records.
1013 * 831 *
1014 * @param cls closure 832 * @param cls closure
@@ -1084,18 +902,8 @@ run (void *cls,
1084 "Target zone iteration velocity (μs)", 902 "Target zone iteration velocity (μs)",
1085 target_iteration_velocity_per_record.rel_value_us, 903 target_iteration_velocity_per_record.rel_value_us,
1086 GNUNET_NO); 904 GNUNET_NO);
1087 zmon = GNUNET_NAMESTORE_zone_monitor_start (c, 905 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
1088 NULL, 906 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, 907 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1100 NULL); 908 NULL);
1101} 909}