GNUnet  0.11.x
gnunet-service-zonemaster.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012, 2013, 2014, 2017, 2018 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 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_dnsparser_lib.h"
29 #include "gnunet_dht_service.h"
32 
33 
34 #define LOG_STRERROR_FILE(kind, syscall, \
35  filename) GNUNET_log_from_strerror_file (kind, "util", \
36  syscall, \
37  filename)
38 
39 
44 #define PUBLISH_OPS_PER_EXPIRATION 4
45 
51 #define DELTA_INTERVAL 100
52 
56 #define NS_BLOCK_SIZE 1000
57 
61 #define DHT_QUEUE_LIMIT 2000
62 
67 #define NAMESTORE_QUEUE_LIMIT 50
68 
73 #define INITIAL_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS
74 
79 #define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply ( \
80  GNUNET_TIME_UNIT_MINUTES, 15)
81 
86 #define LATE_ITERATION_SPEEDUP_FACTOR 2
87 
91 #define DHT_GNS_REPLICATION_LEVEL 5
92 
93 
97 struct DhtPutActivity
98 {
102  struct DhtPutActivity *next;
103 
107  struct DhtPutActivity *prev;
108 
112  struct GNUNET_DHT_PutHandle *ph;
113 
117  struct GNUNET_TIME_Absolute start_date;
118 };
119 
120 
125 
130 
135 
140 
144 static struct DhtPutActivity *it_head;
145 
149 static struct DhtPutActivity *it_tail;
150 
154 static unsigned int dht_queue_length;
155 
159 static unsigned long long num_public_records;
160 
164 static unsigned long long last_num_public_records;
165 
170 static unsigned long long put_cnt;
171 
180 
186 
192 
197 
203 
209 
217 
222 
227 static unsigned int ns_iteration_left;
228 
233 
238 static int cache_keys;
239 
240 
247 static void
248 shutdown_task (void *cls)
249 {
250  struct DhtPutActivity *ma;
251 
252  (void) cls;
254  "Shutting down!\n");
255  while (NULL != (ma = it_head))
256  {
260  it_tail,
261  ma);
263  GNUNET_free (ma);
264  }
265  if (NULL != statistics)
266  {
267  GNUNET_STATISTICS_destroy (statistics,
268  GNUNET_NO);
269  statistics = NULL;
270  }
271  if (NULL != zone_publish_task)
272  {
273  GNUNET_SCHEDULER_cancel (zone_publish_task);
274  zone_publish_task = NULL;
275  }
276  if (NULL != namestore_iter)
277  {
278  GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
279  namestore_iter = NULL;
280  }
281  if (NULL != namestore_handle)
282  {
283  GNUNET_NAMESTORE_disconnect (namestore_handle);
284  namestore_handle = NULL;
285  }
286  if (NULL != dht_handle)
287  {
288  GNUNET_DHT_disconnect (dht_handle);
289  dht_handle = NULL;
290  }
291 }
292 
293 
299 static void
301 {
302  (void) cls;
303  zone_publish_task = NULL;
304  GNUNET_assert (NULL != namestore_iter);
307  GNUNET_NAMESTORE_zone_iterator_next (namestore_iter,
308  NS_BLOCK_SIZE);
309 }
310 
311 
317 static void
318 publish_zone_dht_start (void *cls);
319 
320 
324 static void
326 {
327  if (0 == num_public_records)
335  "No records in namestore database.\n");
336  }
337  else
338  {
350  }
354  GNUNET_STATISTICS_set (statistics,
355  "Minimum relative record expiration (in μs)",
357  GNUNET_NO);
358  GNUNET_STATISTICS_set (statistics,
359  "Zone publication time window (in μs)",
361  GNUNET_NO);
362  GNUNET_STATISTICS_set (statistics,
363  "Target zone iteration velocity (μs)",
365  GNUNET_NO);
366 }
367 
368 
376 static void
377 update_velocity (unsigned int cnt)
378 {
379  struct GNUNET_TIME_Relative delta;
380  unsigned long long pct = 0;
381 
382  if (0 == cnt)
383  return;
384  /* How fast were we really? */
386  delta.rel_value_us /= cnt;
388 
389  /* calculate expected frequency */
392  {
394  "Last record count was lower than current record count. Reducing interval.\n");
398  }
400  "Desired global zone iteration interval is %s/record!\n",
403  GNUNET_YES));
404 
405  /* Tell statistics actual vs. desired speed */
406  GNUNET_STATISTICS_set (statistics,
407  "Current zone iteration velocity (μs/record)",
408  delta.rel_value_us,
409  GNUNET_NO);
410  /* update "sub_delta" based on difference, taking
411  previous sub_delta into account! */
413  {
414  /* We were too fast, reduce sub_delta! */
415  struct GNUNET_TIME_Relative corr;
416 
418  delta);
419  if (sub_delta.rel_value_us > delta.rel_value_us)
420  {
421  /* Reduce sub_delta by corr */
423  corr);
424  }
425  else
426  {
427  /* We're doing fine with waiting the full time, this
428  should theoretically only happen if we run at
429  infinite speed. */
431  }
432  }
434  delta.rel_value_us)
435  {
436  /* We were too slow, increase sub_delta! */
437  struct GNUNET_TIME_Relative corr;
438 
439  corr = GNUNET_TIME_relative_subtract (delta,
442  corr);
443  if (sub_delta.rel_value_us >
445  {
446  /* CPU overload detected, we cannot go at desired speed,
447  as this would mean using a negative delay. */
448  /* compute how much faster we would want to be for
449  the desired velocity */
451  pct = UINT64_MAX; /* desired speed is infinity ... */
452  else
453  pct = (sub_delta.rel_value_us
457  }
458  }
459  GNUNET_STATISTICS_set (statistics,
460  "# size of the DHT queue (it)",
462  GNUNET_NO);
463  GNUNET_STATISTICS_set (statistics,
464  "% speed increase needed for target velocity",
465  pct,
466  GNUNET_NO);
467  GNUNET_STATISTICS_set (statistics,
468  "# records processed in current iteration",
470  GNUNET_NO);
471 }
472 
473 
478 static void
480 {
481  struct GNUNET_TIME_Relative delay;
482 
483  if (0 != ns_iteration_left)
484  return; /* current NAMESTORE iteration not yet done */
486  put_cnt = 0;
488  sub_delta);
489  /* We delay *once* per #NS_BLOCK_SIZE, so we need to multiply the
490  per-record delay calculated so far with the #NS_BLOCK_SIZE */
491  GNUNET_STATISTICS_set (statistics,
492  "Current artificial NAMESTORE delay (μs/record)",
493  delay.rel_value_us,
494  GNUNET_NO);
495  delay = GNUNET_TIME_relative_multiply (delay,
496  NS_BLOCK_SIZE);
497  /* make sure we do not overshoot because of the #NS_BLOCK_SIZE factor */
499  delay);
500  /* no delays on first iteration */
502  delay = GNUNET_TIME_UNIT_ZERO;
503  GNUNET_assert (NULL == zone_publish_task);
504  zone_publish_task = GNUNET_SCHEDULER_add_delayed (delay,
506  NULL);
507 }
508 
509 
515 static void
517 {
518  struct DhtPutActivity *ma = cls;
519 
521  "PUT complete\n");
524  it_tail,
525  ma);
526  GNUNET_free (ma);
527 }
528 
529 
540 static unsigned int
542  unsigned int rd_count,
543  struct GNUNET_GNSRECORD_Data *rd_public)
544 {
545  struct GNUNET_TIME_Absolute now;
546  unsigned int rd_public_count;
547 
548  rd_public_count = 0;
549  now = GNUNET_TIME_absolute_get ();
550  for (unsigned int i = 0; i < rd_count; i++)
551  {
552  if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
553  continue;
554  if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
555  (rd[i].expiration_time < now.abs_value_us))
556  continue; /* record already expired, skip it */
557  if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
558  {
559  /* GNUNET_GNSRECORD_block_create will convert to absolute time;
560  we just need to adjust our iteration frequency */
562  GNUNET_MIN (rd[i].expiration_time,
564  }
565  rd_public[rd_public_count++] = rd[i];
566  }
567  return rd_public_count;
568 }
569 
570 
581 static struct GNUNET_DHT_PutHandle *
583  const char *label,
584  const struct GNUNET_GNSRECORD_Data *rd_public,
585  unsigned int rd_public_count,
586  struct DhtPutActivity *ma)
587 {
588  struct GNUNET_GNSRECORD_Block *block;
589  struct GNUNET_HashCode query;
590  struct GNUNET_TIME_Absolute expire;
591  size_t block_size;
592  struct GNUNET_DHT_PutHandle *ret;
593 
594  expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count,
595  rd_public);
596  if (cache_keys)
597  block = GNUNET_GNSRECORD_block_create2 (key,
598  expire,
599  label,
600  rd_public,
601  rd_public_count);
602  else
603  block = GNUNET_GNSRECORD_block_create (key,
604  expire,
605  label,
606  rd_public,
607  rd_public_count);
608  if (NULL == block)
609  {
610  GNUNET_break (0);
611  return NULL; /* whoops */
612  }
613  block_size = GNUNET_GNSRECORD_block_get_size (block);
615  label,
616  &query);
617  GNUNET_STATISTICS_update (statistics,
618  "DHT put operations initiated",
619  1,
620  GNUNET_NO);
622  "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n",
623  rd_public_count,
624  label,
626  GNUNET_h2s (&query));
628  ret = GNUNET_DHT_put (dht_handle,
629  &query,
633  block_size,
634  block,
635  expire,
637  ma);
638  GNUNET_free (block);
639  return ret;
640 }
641 
642 
648 static void
650 {
651  (void) cls;
653  "Got disconnected from namestore database, retrying.\n");
654  namestore_iter = NULL;
655  /* We end up here on error/disconnect/shutdown, so potentially
656  while a zone publish task or a DHT put is still running; hence
657  we need to cancel those. */
658  if (NULL != zone_publish_task)
659  {
660  GNUNET_SCHEDULER_cancel (zone_publish_task);
661  zone_publish_task = NULL;
662  }
663  zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
664  NULL);
665 }
666 
667 
673 static void
675 {
676  (void) cls;
677  /* we're done with one iteration, calculate when to do the next one */
678  namestore_iter = NULL;
683  /* reset for next iteration */
687  "Zone iteration finished. Adjusted zone iteration interval to %s\n",
690  GNUNET_YES));
691  GNUNET_STATISTICS_set (statistics,
692  "Target zone iteration velocity (μs)",
694  GNUNET_NO);
695  GNUNET_STATISTICS_set (statistics,
696  "Number of public records in DHT",
698  GNUNET_NO);
699  GNUNET_assert (NULL == zone_publish_task);
700  if (0 == last_num_public_records)
701  {
702  zone_publish_task = GNUNET_SCHEDULER_add_delayed (
705  NULL);
706  }
707  else
708  {
709  zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
710  NULL);
711  }
712 }
713 
714 
724 static void
725 put_gns_record (void *cls,
726  const struct GNUNET_IDENTITY_PrivateKey *key,
727  const char *label,
728  unsigned int rd_count,
729  const struct GNUNET_GNSRECORD_Data *rd)
730 {
731  struct GNUNET_GNSRECORD_Data rd_public[rd_count];
732  unsigned int rd_public_count;
733  struct DhtPutActivity *ma;
734 
735  (void) cls;
737  rd_public_count = convert_records_for_export (rd,
738  rd_count,
739  rd_public);
740  if (0 == rd_public_count)
741  {
743  "Record set empty, moving to next record set\n");
745  return;
746  }
747  /* We got a set of records to publish */
749  "Starting DHT PUT\n");
750  ma = GNUNET_new (struct DhtPutActivity);
752  ma->ph = perform_dht_put (key,
753  label,
754  rd_public,
755  rd_public_count,
756  ma);
757  put_cnt++;
758  if (0 == put_cnt % DELTA_INTERVAL)
759  update_velocity (DELTA_INTERVAL);
761  if (NULL == ma->ph)
762  {
764  "Could not perform DHT PUT, is the DHT running?\n");
765  GNUNET_free (ma);
766  return;
767  }
770  it_tail,
771  ma);
773  {
774  ma = it_head;
776  it_tail,
777  ma);
781  "DHT PUT unconfirmed after %s, aborting PUT\n",
784  GNUNET_YES));
785  GNUNET_free (ma);
786  }
787 }
788 
789 
795 static void
797 {
798  (void) cls;
799  zone_publish_task = NULL;
800  GNUNET_STATISTICS_update (statistics,
801  "Full zone iterations launched",
802  1,
803  GNUNET_NO);
805  "Starting DHT zone update!\n");
806  /* start counting again */
807  num_public_records = 0;
808  GNUNET_assert (NULL == namestore_iter);
809  ns_iteration_left = 1;
810  namestore_iter
811  = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
812  NULL, /* All zones */
814  NULL,
816  NULL,
818  NULL);
819  GNUNET_assert (NULL != namestore_iter);
820 }
821 
822 
830 static void
831 run (void *cls,
832  const struct GNUNET_CONFIGURATION_Handle *c,
834 {
835  unsigned long long max_parallel_bg_queries = 128;
836 
837  (void) cls;
838  (void) service;
839  last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */
843  namestore_handle = GNUNET_NAMESTORE_connect (c);
844  if (NULL == namestore_handle)
845  {
847  _ ("Failed to connect to the namestore!\n"));
849  return;
850  }
852  "namestore",
853  "CACHE_KEYS");
855  if (GNUNET_OK ==
857  "zonemaster",
858  "ZONE_PUBLISH_TIME_WINDOW",
860  {
862  "Time window for zone iteration: %s\n",
865  GNUNET_YES));
866  }
868  if (GNUNET_OK ==
870  "zonemaster",
871  "MAX_PARALLEL_BACKGROUND_QUERIES",
872  &max_parallel_bg_queries))
873  {
875  "Number of allowed parallel background queries: %llu\n",
876  max_parallel_bg_queries);
877  }
878  if (0 == max_parallel_bg_queries)
879  max_parallel_bg_queries = 1;
880  dht_handle = GNUNET_DHT_connect (c,
881  (unsigned int) max_parallel_bg_queries);
882  if (NULL == dht_handle)
883  {
885  _ ("Could not connect to DHT!\n"));
887  NULL);
888  return;
889  }
890 
891  /* Schedule periodic put for our records. */
893  statistics = GNUNET_STATISTICS_create ("zonemaster",
894  c);
895  GNUNET_STATISTICS_set (statistics,
896  "Target zone iteration velocity (μs)",
898  GNUNET_NO);
899  zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
900  NULL);
902  NULL);
903 }
904 
905 
910  ("zonemaster",
912  &run,
913  NULL,
914  NULL,
915  NULL,
917 
918 
919 /* end of gnunet-service-zonemaster.c */
static void dht_put_continuation(void *cls)
Continuation called from DHT once the PUT operation is done.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_TIME_Relative min_relative_record_time
Minimum relative expiration time of records seem during the current zone iteration.
#define NS_BLOCK_SIZE
How many records do we fetch in one shot from the namestore?
GNUNET_SERVICE_MAIN("zonemaster", GNUNET_SERVICE_OPTION_NONE, &run, NULL, NULL, NULL, GNUNET_MQ_handler_end())
Define "main" method using service macro.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
struct GNUNET_DHT_PutHandle * ph
Handle for the DHT PUT operation.
struct DhtPutActivity * prev
Kept in a DLL.
uint64_t rel_value_us
The actual value.
void GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph)
Cancels a DHT PUT operation.
Definition: dht_api.c:1035
static void shutdown_task(void *cls)
Task run during shutdown.
static void update_velocity(unsigned int cnt)
Re-calculate our velocity and the desired velocity.
static unsigned long long last_num_public_records
Last seen record count.
Handle to a service.
Definition: service.c:116
static unsigned int dht_queue_length
Number of entries in the DHT queue it_head.
static int first_zone_iteration
GNUNET_YES if zone has never been published before
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
#define DELTA_INTERVAL
How often do we measure the delta between desired zone iteration speed and actual speed...
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void zone_iteration_error(void *cls)
We encountered an error in our zone iteration.
struct GNUNET_TIME_Absolute start_date
When was this PUT initiated?
static struct GNUNET_TIME_Relative zone_publish_time_window
Time window for zone iteration, adjusted based on relative record expiration times in our zone...
static void publish_zone_namestore_next(void *cls)
Method called periodically that triggers iteration over authoritative records.
static struct GNUNET_TIME_Relative zone_publish_time_window_default
Default time window for zone iteration.
A private key for an identity as per LSD0001.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record...
static struct DhtPutActivity * it_tail
Tail of iteration put activities; kept in a DLL.
#define PUBLISH_OPS_PER_EXPIRATION
How often should we (re)publish each record before it expires?
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
Handle for the service.
static struct GNUNET_TIME_Relative last_min_relative_record_time
Minimum relative expiration time of records seem during the last zone iteration.
static void put_gns_record(void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function used to put all records successively into the DHT.
uint64_t abs_value_us
The actual value.
static unsigned long long num_public_records
Useful for zone update for DHT put.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_GNSRECORD_Block * GNUNET_GNSRECORD_block_create(const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
Sign name and records.
Handle for DHT PUT activity triggered from the namestore monitor.
Connection to the DHT service.
Definition: dht_api.c:201
#define MAXIMUM_ZONE_ITERATION_INTERVAL
The upper bound for the zone iteration interval (per record).
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
#define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY
Default republication frequency for stored data in the DHT.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
Handle for a zone iterator operation.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
static unsigned int convert_records_for_export(const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *rd_public)
Convert namestore records from the internal format to that suitable for publication (removes private ...
#define LATE_ITERATION_SPEEDUP_FACTOR
The factor the current zone iteration interval is divided by for each additional new record...
size_t GNUNET_GNSRECORD_block_get_size(const struct GNUNET_GNSRECORD_Block *block)
Returns the length of this block in bytes.
Connection to the NAMESTORE service.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
#define INITIAL_ZONE_ITERATION_INTERVAL
The initial interval in milliseconds btween puts in a zone iteration.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:93
static void calculate_put_interval()
Calculate target_iteration_velocity_per_record.
struct GNUNET_GNSRECORD_Block * GNUNET_GNSRECORD_block_create2(const struct GNUNET_IDENTITY_PrivateKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
Sign name and records, cache derived public key (also keeps the private key in static memory...
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:702
#define DHT_GNS_REPLICATION_LEVEL
What replication level do we use for DHT PUT operations?
static struct GNUNET_TIME_Relative sub_delta
By how much should we try to increase our per-record iteration speed (over the desired speed calculat...
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:442
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
This is a private record of this peer and it should thus not be handed out to other peers...
struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Subtract relative timestamp from the other.
Definition: time.c:604
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT)...
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
Block for storing record data.
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
A 512-bit hashcode.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Returns the expiration time of the given block of records.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:272
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_DHT_PutHandle * GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, size_t size, const void *data, struct GNUNET_TIME_Absolute exp, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Perform a PUT operation storing data in the DHT.
Definition: dht_api.c:966
#define DHT_QUEUE_LIMIT
How many pending DHT operations do we allow at most?
static struct DhtPutActivity * it_head
Head of iteration put activities; kept in a DLL.
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
Definition: dht_api.c:890
static struct GNUNET_DHT_Handle * dht_handle
Our handle to the DHT.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:918
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
static struct GNUNET_NAMESTORE_ZoneIterator * namestore_iter
Handle to iterate over our authoritative zone in namestore.
static struct GNUNET_TIME_Relative target_iteration_velocity_per_record
What is the frequency at which we currently would like to perform DHT puts (per record)? Calculated in update_velocity() from the zone_publish_time_window() and the total number of record sets we have (so far) observed in the zone.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
static void check_zone_namestore_next()
Check if the current zone iteration needs to be continued by calling publish_zone_namestore_next(), and if so with what delay.
static struct GNUNET_SCHEDULER_Task * zone_publish_task
zone publish task
void GNUNET_GNSRECORD_query_from_private_key(const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
static void publish_zone_dht_start(void *cls)
Periodically iterate over our zone and store everything in dht.
static int cache_keys
Optimize block insertion by caching map of private keys to public keys in memory? ...
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition: time.c:579
Handle to a PUT request.
Definition: dht_api.c:43
configuration data
Definition: configuration.c:84
static unsigned int ns_iteration_left
How many more values are left for the current query before we need to explicitly ask the namestore fo...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
static unsigned long long put_cnt
Number of successful put operations performed in the current measurement cycle (as measured in check_...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:375
static struct GNUNET_NAMESTORE_Handle * namestore_handle
Our handle to the namestore service.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Performe zonemaster duties: watch namestore, publish records.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
static struct GNUNET_TIME_Absolute last_put_100
When did we last start measuring the DELTA_INTERVAL successful DHT puts? Used for velocity calculatio...
static void zone_iteration_finished(void *cls)
Zone iteration is completed.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:527
Time for absolute times used by GNUnet, in microseconds.
This expiration time of the record is a relative time (not an absolute time).
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:758
struct DhtPutActivity * next
Kept in a DLL.
static struct GNUNET_DHT_PutHandle * perform_dht_put(const struct GNUNET_IDENTITY_PrivateKey *key, const char *label, const struct GNUNET_GNSRECORD_Data *rd_public, unsigned int rd_public_count, struct DhtPutActivity *ma)
Store GNS records in the DHT.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Each peer along the way should look at &#39;enc&#39; (otherwise only the k-peers closest to the key should lo...
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972