2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014, 2017 GNUnet e.V.
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file zonemaster/gnunet-service-zonemaster.c
23 * @brief publish records from namestore to GNUnet name system
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_dnsparser_lib.h"
29 #include "gnunet_dht_service.h"
30 #include "gnunet_namestore_service.h"
31 #include "gnunet_statistics_service.h"
32 #include "gnunet_namestore_plugin.h"
33 #include "gnunet_signatures.h"
36 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
40 * How often should we (re)publish each record before
43 #define PUBLISH_OPS_PER_EXPIRATION 4
46 * How often do we measure the delta between desired zone
47 * iteration speed and actual speed, and tell statistics
50 #define DELTA_INTERVAL 100
53 * How many records do we fetch in one shot from the namestore?
55 #define NS_BLOCK_SIZE 1000
58 * How many pending DHT operations do we allow at most?
60 #define DHT_QUEUE_LIMIT 2000
63 * The initial interval in milliseconds btween puts in
66 #define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS
69 * The upper bound for the zone iteration interval
72 #define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
75 * The default put interval for the zone iteration. In case
78 #define DEFAULT_ZONE_PUBLISH_TIME_WINDOW GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
81 * The factor the current zone iteration interval is divided by for each
82 * additional new record
84 #define LATE_ITERATION_SPEEDUP_FACTOR 2
87 * How long until a DHT PUT attempt should time out?
89 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
92 * What replication level do we use for DHT PUT operations?
94 #define DHT_GNS_REPLICATION_LEVEL 5
98 * Handle for DHT PUT activity triggered from the namestore monitor.
100 struct DhtPutActivity
105 struct DhtPutActivity *next;
110 struct DhtPutActivity *prev;
113 * Handle for the DHT PUT operation.
115 struct GNUNET_DHT_PutHandle *ph;
118 * When was this PUT initiated?
120 struct GNUNET_TIME_Absolute start_date;
125 * Handle to the statistics service
127 static struct GNUNET_STATISTICS_Handle *statistics;
130 * Our handle to the DHT
132 static struct GNUNET_DHT_Handle *dht_handle;
135 * Active DHT put operation (or NULL)
137 static struct GNUNET_DHT_PutHandle *active_put;
140 * Our handle to the namestore service
142 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
145 * Handle to iterate over our authoritative zone in namestore
147 static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
150 * Handle to monitor namestore changes to instant propagation.
152 static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
155 * Head of monitor activities; kept in a DLL.
157 static struct DhtPutActivity *ma_head;
160 * Tail of monitor activities; kept in a DLL.
162 static struct DhtPutActivity *ma_tail;
165 * Head of iteration put activities; kept in a DLL.
167 static struct DhtPutActivity *it_head;
170 * Tail of iteration put activities; kept in a DLL.
172 static struct DhtPutActivity *it_tail;
175 * Number of entries in the DHT queue.
177 static unsigned int dht_queue_length;
180 * Useful for zone update for DHT put
182 static unsigned long long num_public_records;
185 * Last seen record count
187 static unsigned long long last_num_public_records;
190 * Number of successful put operations performed in the current
191 * measurement cycle (as measured in #check_zone_namestore_next()).
193 static unsigned long long put_cnt;
196 * What is the frequency at which we currently would like
197 * to perform DHT puts (per record)? Calculated in
198 * update_velocity() from the #zone_publish_time_window()
199 * and the total number of record sets we have (so far)
200 * observed in the zone.
202 static struct GNUNET_TIME_Relative next_put_interval;
205 * Minimum relative expiration time of records seem during the current
208 static struct GNUNET_TIME_Relative min_relative_record_time;
211 * Minimum relative expiration time of records seem during the last
214 static struct GNUNET_TIME_Relative last_min_relative_record_time;
217 * Default time window for zone iteration
219 static struct GNUNET_TIME_Relative zone_publish_time_window_default;
222 * Time window for zone iteration, adjusted based on relative record
223 * expiration times in our zone.
225 static struct GNUNET_TIME_Relative zone_publish_time_window;
228 * When did we last start measuring the #DELTA_INTERVAL successful
229 * DHT puts? Used for velocity calculations.
231 static struct GNUNET_TIME_Absolute last_put_100;
234 * By how much should we try to increase our per-record iteration speed
235 * (over the desired speed calculated directly from the #put_interval)?
236 * Basically this value corresponds to the per-record CPU time overhead
239 static struct GNUNET_TIME_Relative sub_delta;
244 static struct GNUNET_SCHEDULER_Task *zone_publish_task;
247 * How many more values are left for the current query before we need
248 * to explicitly ask the namestore for more?
250 static unsigned int ns_iteration_left;
253 * #GNUNET_YES if zone has never been published before
255 static int first_zone_iteration;
258 * Optimize block insertion by caching map of private keys to
259 * public keys in memory?
261 static int cache_keys;
265 * Task run during shutdown.
271 shutdown_task (void *cls)
273 struct DhtPutActivity *ma;
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
278 while (NULL != (ma = ma_head))
280 GNUNET_DHT_put_cancel (ma->ph);
281 GNUNET_CONTAINER_DLL_remove (ma_head,
286 while (NULL != (ma = it_head))
288 GNUNET_DHT_put_cancel (ma->ph);
289 GNUNET_CONTAINER_DLL_remove (it_head,
295 if (NULL != statistics)
297 GNUNET_STATISTICS_destroy (statistics,
301 if (NULL != zone_publish_task)
303 GNUNET_SCHEDULER_cancel (zone_publish_task);
304 zone_publish_task = NULL;
306 if (NULL != namestore_iter)
308 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
309 namestore_iter = NULL;
313 GNUNET_NAMESTORE_zone_monitor_stop (zmon);
316 if (NULL != namestore_handle)
318 GNUNET_NAMESTORE_disconnect (namestore_handle);
319 namestore_handle = NULL;
321 if (NULL != active_put)
323 GNUNET_DHT_put_cancel (active_put);
326 if (NULL != dht_handle)
328 GNUNET_DHT_disconnect (dht_handle);
335 * Method called periodically that triggers iteration over authoritative records
340 publish_zone_namestore_next (void *cls)
343 zone_publish_task = NULL;
344 GNUNET_assert (NULL != namestore_iter);
345 GNUNET_assert (0 == ns_iteration_left);
346 ns_iteration_left = NS_BLOCK_SIZE;
347 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter,
353 * Periodically iterate over our zone and store everything in dht
358 publish_zone_dht_start (void *cls);
362 * Continuation called from DHT once the PUT operation triggered
363 * by a monitor is done.
365 * @param cls a `struct DhtPutActivity`
368 dht_put_monitor_continuation (void *cls)
370 struct DhtPutActivity *ma = cls;
372 num_public_records++;
373 GNUNET_CONTAINER_DLL_remove (ma_head,
381 * Check if the current zone iteration needs to be continued
382 * by calling #publish_zone_namestore_next(), and if so with what delay.
385 check_zone_namestore_next ()
387 struct GNUNET_TIME_Relative delay;
389 if (0 != ns_iteration_left)
390 return; /* current NAMESTORE iteration not yet done */
391 delay = GNUNET_TIME_relative_subtract (next_put_interval,
393 /* We delay *once* per #NS_BLOCK_SIZE, so we need to multiply the
394 per-record delay calculated so far with the #NS_BLOCK_SIZE */
395 delay = GNUNET_TIME_relative_multiply (delay,
397 GNUNET_assert (NULL == zone_publish_task);
398 GNUNET_STATISTICS_set (statistics,
399 "Current artificial NAMESTORE delay (μs)",
402 zone_publish_task = GNUNET_SCHEDULER_add_delayed (delay,
403 &publish_zone_namestore_next,
409 * Calculate #next_put_interval.
412 calculate_put_interval ()
414 if (0 == num_public_records)
417 * If no records are known (startup) or none present
418 * we can safely set the interval to the value for a single
421 next_put_interval = zone_publish_time_window;
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
423 "No records in namestore database.\n");
427 last_min_relative_record_time
428 = GNUNET_TIME_relative_min (last_min_relative_record_time,
429 min_relative_record_time);
430 zone_publish_time_window
431 = GNUNET_TIME_relative_min (GNUNET_TIME_relative_divide (last_min_relative_record_time,
432 PUBLISH_OPS_PER_EXPIRATION),
433 zone_publish_time_window_default);
435 = GNUNET_TIME_relative_divide (zone_publish_time_window,
436 last_num_public_records);
438 = GNUNET_TIME_relative_min (next_put_interval,
439 MAXIMUM_ZONE_ITERATION_INTERVAL);
441 GNUNET_STATISTICS_set (statistics,
442 "Minimum relative record expiration (in ms)",
443 last_min_relative_record_time.rel_value_us / 1000LL,
445 GNUNET_STATISTICS_set (statistics,
446 "Zone publication time window (in ms)",
447 zone_publish_time_window.rel_value_us / 1000LL,
453 * Re-calculate our velocity and the desired velocity.
454 * We have succeeded in making #DELTA_INTERVAL puts, so
455 * now calculate the new desired delay between puts.
460 struct GNUNET_TIME_Relative delta;
461 unsigned long long pct = 0;
463 /* How fast were we really? */
464 delta = GNUNET_TIME_absolute_get_duration (last_put_100);
465 delta.rel_value_us /= DELTA_INTERVAL;
466 last_put_100 = GNUNET_TIME_absolute_get ();
468 /* calculate expected frequency */
469 if ( (num_public_records > last_num_public_records) &&
470 (GNUNET_NO == first_zone_iteration) )
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473 "Last record count was lower than current record count. Reducing interval.\n");
474 last_num_public_records = num_public_records * LATE_ITERATION_SPEEDUP_FACTOR;
475 calculate_put_interval ();
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
478 "Desired global zone iteration interval is %s/record!\n",
479 GNUNET_STRINGS_relative_time_to_string (next_put_interval,
482 /* Tell statistics actual vs. desired speed */
483 GNUNET_STATISTICS_set (statistics,
484 "Target zone iteration velocity (μs)",
485 next_put_interval.rel_value_us,
487 GNUNET_STATISTICS_set (statistics,
488 "Current zone iteration velocity (μs)",
491 /* update "sub_delta" based on difference, taking
492 previous sub_delta into account! */
493 if (next_put_interval.rel_value_us > delta.rel_value_us)
495 /* We were too fast, reduce sub_delta! */
496 struct GNUNET_TIME_Relative corr;
498 corr = GNUNET_TIME_relative_subtract (next_put_interval,
500 if (sub_delta.rel_value_us > delta.rel_value_us)
502 /* Reduce sub_delta by corr */
503 sub_delta = GNUNET_TIME_relative_subtract (sub_delta,
508 /* We're doing fine with waiting the full time, this
509 should theoretically only happen if we run at
511 sub_delta = GNUNET_TIME_UNIT_ZERO;
514 else if (next_put_interval.rel_value_us < delta.rel_value_us)
516 /* We were too slow, increase sub_delta! */
517 struct GNUNET_TIME_Relative corr;
519 corr = GNUNET_TIME_relative_subtract (delta,
521 sub_delta = GNUNET_TIME_relative_add (sub_delta,
523 if (sub_delta.rel_value_us > next_put_interval.rel_value_us)
525 /* CPU overload detected, we cannot go at desired speed,
526 as this would mean using a negative delay. */
527 /* compute how much faster we would want to be for
528 the desired velocity */
529 if (0 == next_put_interval.rel_value_us)
530 pct = UINT64_MAX; /* desired speed is infinity ... */
532 pct = (sub_delta.rel_value_us - next_put_interval.rel_value_us) * 100LLU
533 / next_put_interval.rel_value_us;
534 sub_delta = next_put_interval;
537 GNUNET_STATISTICS_set (statistics,
538 "# size of the DHT queue",
541 GNUNET_STATISTICS_set (statistics,
542 "% speed increase needed for target velocity",
545 GNUNET_STATISTICS_set (statistics,
546 "# records processed in current iteration",
553 * Continuation called from DHT once the PUT operation is done.
555 * @param cls a `struct DhtPutActivity`
558 dht_put_continuation (void *cls)
560 struct DhtPutActivity *ma = cls;
562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
565 GNUNET_CONTAINER_DLL_remove (it_head,
573 * Convert namestore records from the internal format to that
574 * suitable for publication (removes private records, converts
575 * to absolute expiration time).
577 * @param rd input records
578 * @param rd_count size of the @a rd and @a rd_public arrays
579 * @param rd_public where to write the converted records
580 * @return number of records written to @a rd_public
583 convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
584 unsigned int rd_count,
585 struct GNUNET_GNSRECORD_Data *rd_public)
587 struct GNUNET_TIME_Absolute now;
588 unsigned int rd_public_count;
591 now = GNUNET_TIME_absolute_get ();
592 for (unsigned int i=0;i<rd_count;i++)
593 if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
595 rd_public[rd_public_count] = rd[i];
596 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
598 /* GNUNET_GNSRECORD_block_create will convert to absolute time;
599 we just need to adjust our iteration frequency */
600 min_relative_record_time.rel_value_us =
601 GNUNET_MIN (rd_public[rd_public_count].expiration_time,
602 min_relative_record_time.rel_value_us);
604 else if (rd_public[rd_public_count].expiration_time < now.abs_value_us)
606 /* record already expired, skip it */
611 return rd_public_count;
616 * Store GNS records in the DHT.
618 * @param key key of the zone
619 * @param label label to store under
620 * @param rd_public public record data
621 * @param rd_public_count number of records in @a rd_public
622 * @param cont function to call with PUT result
623 * @param cont_cls closure for @a cont
624 * @return DHT PUT handle, NULL on error
626 static struct GNUNET_DHT_PutHandle *
627 perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
629 const struct GNUNET_GNSRECORD_Data *rd_public,
630 unsigned int rd_public_count,
631 GNUNET_SCHEDULER_TaskCallback cont,
634 struct GNUNET_GNSRECORD_Block *block;
635 struct GNUNET_HashCode query;
636 struct GNUNET_TIME_Absolute expire;
638 struct GNUNET_DHT_PutHandle *ret;
640 expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count,
643 block = GNUNET_GNSRECORD_block_create2 (key,
649 block = GNUNET_GNSRECORD_block_create (key,
657 return NULL; /* whoops */
659 block_size = ntohl (block->purpose.size)
660 + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)
661 + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
662 GNUNET_GNSRECORD_query_from_private_key (key,
665 GNUNET_STATISTICS_update (statistics,
666 "DHT put operations initiated",
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
670 "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n",
673 GNUNET_STRINGS_absolute_time_to_string (expire),
674 GNUNET_h2s (&query));
675 num_public_records++;
676 ret = GNUNET_DHT_put (dht_handle,
678 DHT_GNS_REPLICATION_LEVEL,
679 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
680 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
692 * We encountered an error in our zone iteration.
697 zone_iteration_error (void *cls)
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
701 "Got disconnected from namestore database, retrying.\n");
702 namestore_iter = NULL;
703 /* We end up here on error/disconnect/shutdown, so potentially
704 while a zone publish task or a DHT put is still running; hence
705 we need to cancel those. */
706 if (NULL != zone_publish_task)
708 GNUNET_SCHEDULER_cancel (zone_publish_task);
709 zone_publish_task = NULL;
711 if (NULL != active_put)
713 GNUNET_DHT_put_cancel (active_put);
716 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
722 * Zone iteration is completed.
727 zone_iteration_finished (void *cls)
730 /* we're done with one iteration, calculate when to do the next one */
731 namestore_iter = NULL;
732 last_num_public_records = num_public_records;
733 first_zone_iteration = GNUNET_NO;
734 last_min_relative_record_time = min_relative_record_time;
735 calculate_put_interval ();
736 /* reset for next iteration */
737 min_relative_record_time
738 = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
739 PUBLISH_OPS_PER_EXPIRATION);
740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
741 "Zone iteration finished. Adjusted zone iteration interval to %s\n",
742 GNUNET_STRINGS_relative_time_to_string (next_put_interval,
744 GNUNET_STATISTICS_set (statistics,
745 "Current zone iteration interval (in ms)",
746 next_put_interval.rel_value_us / 1000LL,
748 GNUNET_STATISTICS_set (statistics,
749 "Number of public records in DHT",
750 last_num_public_records,
752 GNUNET_assert (NULL == zone_publish_task);
753 if (0 == last_num_public_records)
754 zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval,
755 &publish_zone_dht_start,
758 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
764 * Function used to put all records successively into the DHT.
766 * @param cls the closure (NULL)
767 * @param key the private key of the authority (ours)
768 * @param label the name of the records, NULL once the iteration is done
769 * @param rd_count the number of records in @a rd
770 * @param rd the record data
773 put_gns_record (void *cls,
774 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
776 unsigned int rd_count,
777 const struct GNUNET_GNSRECORD_Data *rd)
779 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
780 unsigned int rd_public_count;
781 struct DhtPutActivity *ma;
785 rd_public_count = convert_records_for_export (rd,
788 if (0 == rd_public_count)
790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
791 "Record set empty, moving to next record set\n");
792 check_zone_namestore_next ();
795 /* We got a set of records to publish */
796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
797 "Starting DHT PUT\n");
798 ma = GNUNET_new (struct DhtPutActivity);
799 ma->start_date = GNUNET_TIME_absolute_get ();
800 ma->ph = perform_dht_put (key,
804 &dht_put_continuation,
807 if (0 == put_cnt % DELTA_INTERVAL)
809 check_zone_namestore_next ();
812 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
813 "Could not perform DHT PUT, is the DHT running?\n");
818 GNUNET_CONTAINER_DLL_insert_tail (it_head,
821 if (dht_queue_length > DHT_QUEUE_LIMIT)
824 GNUNET_CONTAINER_DLL_remove (it_head,
827 GNUNET_DHT_put_cancel (ma->ph);
829 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
830 "DHT PUT unconfirmed after %s, aborting PUT\n",
831 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date),
839 * Periodically iterate over all zones and store everything in DHT
844 publish_zone_dht_start (void *cls)
847 zone_publish_task = NULL;
848 GNUNET_STATISTICS_update (statistics,
849 "Full zone iterations launched",
852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
853 "Starting DHT zone update!\n");
854 /* start counting again */
855 num_public_records = 0;
856 GNUNET_assert (NULL == namestore_iter);
857 ns_iteration_left = 1;
859 = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
860 NULL, /* All zones */
861 &zone_iteration_error,
865 &zone_iteration_finished,
867 GNUNET_assert (NULL != namestore_iter);
872 * Process a record that was stored in the namestore
873 * (invoked by the monitor).
875 * @param cls closure, NULL
876 * @param zone private key of the zone; NULL on disconnect
877 * @param label label of the records; NULL on disconnect
878 * @param rd_count number of entries in @a rd array, 0 if label was deleted
879 * @param rd array of records with data to store
882 handle_monitor_event (void *cls,
883 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
885 unsigned int rd_count,
886 const struct GNUNET_GNSRECORD_Data *rd)
888 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
889 unsigned int rd_public_count;
890 struct DhtPutActivity *ma;
893 GNUNET_STATISTICS_update (statistics,
894 "Namestore monitor events received",
897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
898 "Received %u records for label `%s' via namestore monitor\n",
901 /* filter out records that are not public, and convert to
902 absolute expiration time. */
903 rd_public_count = convert_records_for_export (rd,
906 if (0 == rd_public_count)
907 return; /* nothing to do */
908 ma = GNUNET_new (struct DhtPutActivity);
909 ma->start_date = GNUNET_TIME_absolute_get ();
910 ma->ph = perform_dht_put (zone,
914 &dht_put_monitor_continuation,
918 /* PUT failed, do not remember operation */
922 GNUNET_CONTAINER_DLL_insert (ma_head,
929 * The zone monitor is now in SYNC with the current state of the
930 * name store. Start to perform periodic iterations.
935 monitor_sync_event (void *cls)
938 if ( (NULL == zone_publish_task) &&
939 (NULL == namestore_iter) )
940 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
946 * The zone monitor encountered an IPC error trying to to get in
947 * sync. Restart from the beginning.
952 handle_monitor_error (void *cls)
955 GNUNET_STATISTICS_update (statistics,
956 "Namestore monitor errors encountered",
959 if (NULL != zone_publish_task)
961 GNUNET_SCHEDULER_cancel (zone_publish_task);
962 zone_publish_task = NULL;
964 if (NULL != namestore_iter)
966 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
967 namestore_iter = NULL;
969 if (NULL != active_put)
971 GNUNET_DHT_put_cancel (active_put);
974 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
980 * Performe zonemaster duties: watch namestore, publish records.
983 * @param server the initialized server
984 * @param c configuration to use
988 const struct GNUNET_CONFIGURATION_Handle *c,
989 struct GNUNET_SERVICE_Handle *service)
991 unsigned long long max_parallel_bg_queries = 128;
995 last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */
996 min_relative_record_time
997 = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
998 PUBLISH_OPS_PER_EXPIRATION);
999 next_put_interval = INITIAL_PUT_INTERVAL;
1000 namestore_handle = GNUNET_NAMESTORE_connect (c);
1001 if (NULL == namestore_handle)
1003 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1004 _("Failed to connect to the namestore!\n"));
1005 GNUNET_SCHEDULER_shutdown ();
1008 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c,
1011 zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
1013 GNUNET_CONFIGURATION_get_value_time (c,
1015 "ZONE_PUBLISH_TIME_WINDOW",
1016 &zone_publish_time_window_default))
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1019 "Time window for zone iteration: %s\n",
1020 GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window,
1023 zone_publish_time_window = zone_publish_time_window_default;
1025 GNUNET_CONFIGURATION_get_value_number (c,
1027 "MAX_PARALLEL_BACKGROUND_QUERIES",
1028 &max_parallel_bg_queries))
1030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1031 "Number of allowed parallel background queries: %llu\n",
1032 max_parallel_bg_queries);
1034 if (0 == max_parallel_bg_queries)
1035 max_parallel_bg_queries = 1;
1036 dht_handle = GNUNET_DHT_connect (c,
1037 (unsigned int) max_parallel_bg_queries);
1038 if (NULL == dht_handle)
1040 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1041 _("Could not connect to DHT!\n"));
1042 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
1046 /* Schedule periodic put for our records. */
1047 first_zone_iteration = GNUNET_YES;\
1048 statistics = GNUNET_STATISTICS_create ("zonemaster",
1050 zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
1053 &handle_monitor_error,
1055 &handle_monitor_event,
1057 &monitor_sync_event,
1059 GNUNET_break (NULL != zmon);
1060 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1066 * Define "main" method using service macro.
1070 GNUNET_SERVICE_OPTION_NONE,
1075 GNUNET_MQ_handler_end());
1078 /* end of gnunet-service-zonemaster.c */