GNUnet  0.19.4
gnunet_dht_profiler.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2014, 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 
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_dht_service.h"
31 #include "gnunet_constants.h"
32 
33 
34 #define MESSAGE(...) \
35  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, __VA_ARGS__)
36 
37 #define DEBUG(...) \
38  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
39 
43 static unsigned int put_probability = 100;
44 
48 static const struct GNUNET_CONFIGURATION_Handle *cfg;
49 
53 static char *hosts_file;
54 
58 struct ActiveContext;
59 
63 struct Context
64 {
69 
74 
78  struct ActiveContext *ac;
79 };
80 
81 
86 {
90  struct Context *ctx;
91 
96 
101 
106 
111 
117 
122 
126  unsigned int put_count;
127 
131  uint16_t nrefs;
132 };
133 
134 
138 static struct Context *a_ctx;
139 
143 static struct ActiveContext *a_ac;
144 
148 static struct GNUNET_TIME_Relative delay_stats;
149 
153 static struct GNUNET_TIME_Relative delay_put;
154 
158 static struct GNUNET_TIME_Relative delay_get;
159 
163 static struct GNUNET_TIME_Relative timeout;
164 
168 static unsigned int num_peers;
169 
173 static unsigned int n_active;
174 
178 static unsigned int n_dht;
179 
183 static unsigned long long n_puts;
184 
188 static unsigned int num_puts_per_peer = 1;
189 
193 static unsigned long long n_puts_ok;
194 
198 static unsigned int n_gets;
199 
203 static unsigned int n_gets_ok;
204 
208 static unsigned int n_gets_fail;
209 
213 static unsigned int replication;
214 
219 
224 
228 static uint64_t outgoing_bandwidth;
229 
233 static uint64_t incoming_bandwidth;
234 
239 
244 
248 static unsigned int total_put_path_length;
249 
253 static unsigned int total_get_path_length;
254 
258 static int peers_started = 0;
259 
263 static enum
264 {
265  MODE_PUT = 0,
266 
267  MODE_GET = 1
269 
270 
274 static int in_shutdown = 0;
275 
276 
280 static void
281 start_profiling (void);
282 
283 
289 static void
290 do_shutdown (void *cls)
291 {
292  struct ActiveContext *ac;
293 
295  if (NULL != a_ctx)
296  {
297  for (unsigned int cnt = 0; cnt < num_peers; cnt++)
298  {
299  /* Cleanup active context if this peer is an active peer */
300  ac = a_ctx[cnt].ac;
301  if (NULL != ac)
302  {
303  if (NULL != ac->delay_task)
304  GNUNET_SCHEDULER_cancel (ac->delay_task);
305  if (NULL != ac->hash)
306  free (ac->hash);
307  if (NULL != ac->dht_put)
308  GNUNET_DHT_put_cancel (ac->dht_put);
309  if (NULL != ac->dht_get)
310  GNUNET_DHT_get_stop (ac->dht_get);
311  }
312  /* Cleanup testbed operation handle at the last as this operation may
313  contain service connection to DHT */
314  if (NULL != a_ctx[cnt].op)
316  }
317  GNUNET_free (a_ctx);
318  a_ctx = NULL;
319  }
320  // FIXME: Should we collect stats only for put/get not for other messages.
321  if (NULL != bandwidth_stats_op)
322  {
324  bandwidth_stats_op = NULL;
325  }
326  GNUNET_free (a_ac);
327 }
328 
329 
339 static void
342  const char *emsg)
343 {
344  MESSAGE ("# Outgoing (core) bandwidth: %llu bytes\n",
345  (unsigned long long) outgoing_bandwidth);
346  MESSAGE ("# Incoming (core) bandwidth: %llu bytes\n",
347  (unsigned long long) incoming_bandwidth);
348  fprintf (stderr,
349  "Benchmark done. Collect data via gnunet-statistics, then press ENTER to exit.\n");
350  (void) getchar ();
352 }
353 
354 
366 static int
368  const struct GNUNET_TESTBED_Peer *peer,
369  const char *subsystem,
370  const char *name,
371  uint64_t value,
372  int is_persistent)
373 {
374  static const char *s_sent = "# bytes encrypted";
375  static const char *s_recv = "# bytes decrypted";
376 
377  if (0 == strncmp (s_sent, name, strlen (s_sent)))
379  else if (0 == strncmp (s_recv, name, strlen (s_recv)))
381  return GNUNET_OK;
382 }
383 
384 
385 static void
387 {
388  MESSAGE ("# PUTS started: %llu\n",
389  n_puts);
390  MESSAGE ("# PUTS succeeded: %llu\n",
391  n_puts_ok);
392  MESSAGE ("# GETS made: %u\n",
393  n_gets);
394  MESSAGE ("# GETS succeeded: %u\n",
395  n_gets_ok);
396  MESSAGE ("# GETS failed: %u\n",
397  n_gets_fail);
398  MESSAGE ("# average_put_path_length: %f\n",
400  MESSAGE ("# average_get_path_length: %f\n",
402 
403  if (NULL == testbed_handles)
404  {
405  MESSAGE ("No peers found\n");
406  return;
407  }
408  /* Collect Stats*/
411  "core",
412  NULL,
415  NULL);
416 }
417 
418 
424 static void
425 cancel_get (void *cls)
426 {
427  struct ActiveContext *ac = cls;
428  struct Context *ctx = ac->ctx;
429 
430  ac->delay_task = NULL;
431  GNUNET_assert (NULL != ac->dht_get);
432  GNUNET_DHT_get_stop (ac->dht_get);
433  ac->dht_get = NULL;
434  n_gets_fail++;
435  GNUNET_assert (NULL != ctx->op);
437  ctx->op = NULL;
438 
439  /* If profiling is complete, summarize */
440  if (n_active == n_gets_fail + n_gets_ok)
441  {
443  / (double) n_active;
445  / (double ) n_gets_ok;
446  summarize ();
447  }
448 }
449 
450 
469 static void
470 get_iter (void *cls,
471  struct GNUNET_TIME_Absolute exp,
472  const struct GNUNET_HashCode *key,
473  const struct GNUNET_PeerIdentity *trunc_peer,
474  const struct GNUNET_DHT_PathElement *get_path,
475  unsigned int get_path_length,
476  const struct GNUNET_DHT_PathElement *put_path,
477  unsigned int put_path_length,
478  enum GNUNET_BLOCK_Type type,
479  size_t size,
480  const void *data)
481 {
482  struct ActiveContext *ac = cls;
483  struct ActiveContext *get_ac = ac->get_ac;
484  struct Context *ctx = ac->ctx;
485 
486  /* we found the data we are looking for */
487  DEBUG ("We found a GET request; %u remaining\n",
488  n_gets - (n_gets_fail + n_gets_ok)); // FIXME: It always prints 1.
489  n_gets_ok++;
490  get_ac->nrefs--;
491  GNUNET_DHT_get_stop (ac->dht_get);
492  ac->dht_get = NULL;
493  if (ac->delay_task != NULL)
494  GNUNET_SCHEDULER_cancel (ac->delay_task);
495  ac->delay_task = NULL;
496  GNUNET_assert (NULL != ctx->op);
498  ctx->op = NULL;
499 
500  total_put_path_length = total_put_path_length + (double) put_path_length;
501  total_get_path_length = total_get_path_length + (double) get_path_length;
502  DEBUG ("total_put_path_length = %u,put_path \n",
504  /* Summarize if profiling is complete */
505  if (n_active == n_gets_fail + n_gets_ok)
506  {
508  / (double) n_active;
510  / (double ) n_gets_ok;
511  summarize ();
512  }
513 }
514 
515 
521 static void
522 delayed_get (void *cls)
523 {
524  struct ActiveContext *ac = cls;
525  struct ActiveContext *get_ac;
526  unsigned int r;
527 
528  ac->delay_task = NULL;
529  get_ac = NULL;
530  while (1)
531  {
533  n_active);
534  get_ac = &a_ac[r];
535  if (NULL != get_ac->hash)
536  break;
537  }
538  get_ac->nrefs++;
539  ac->get_ac = get_ac;
542  DEBUG ("GET_REQUEST_START key %s \n",
543  GNUNET_h2s (&get_ac->hash[r]));
544  ac->dht_get = GNUNET_DHT_get_start (ac->dht,
546  &get_ac->hash[r],
547  1, /* replication level */
549  NULL,
550  0, /* extended query and size */
551  &get_iter,
552  ac); /* GET iterator and closure */
553  n_gets++;
554 
555  /* schedule the timeout task for GET */
556  ac->delay_task = GNUNET_SCHEDULER_add_delayed (timeout,
557  &cancel_get,
558  ac);
559 }
560 
561 
569 static void
570 delayed_put (void *cls);
571 
572 
579 static void
580 put_cont (void *cls)
581 {
582  struct ActiveContext *ac = cls;
583 
584  ac->dht_put = NULL;
585  n_puts_ok++;
586  ac->delay_task = GNUNET_SCHEDULER_add_now (&delayed_put,
587  ac);
588 }
589 
590 
598 static void
599 delayed_put (void *cls)
600 {
601  struct ActiveContext *ac = cls;
602  char block[65536];
603  size_t block_size;
604 
605  ac->delay_task = NULL;
606  if (0 == ac->put_count)
607  {
608  struct Context *ctx = ac->ctx;
610 
611  GNUNET_assert (NULL != ctx);
612  op = ctx->op;
613  ctx->op = NULL;
615  return;
616  }
617 
618 
619  /* Generate and DHT PUT some random data */
620  block_size = 16; /* minimum */
621  /* make random payload, reserve 512 - 16 bytes for DHT headers */
624  - 512);
626  block,
627  block_size);
628  ac->put_count--;
629  GNUNET_CRYPTO_hash (block,
630  block_size,
631  &ac->hash[ac->put_count]);
632  DEBUG ("PUT_REQUEST_START key %s\n",
633  GNUNET_h2s (&ac->hash[ac->put_count]));
634  ac->dht_put = GNUNET_DHT_put (ac->dht,
635  &ac->hash[ac->put_count],
636  replication,
639  block_size,
640  block,
641  GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */
642  &put_cont,
643  ac); /* continuation and its closure */
644  n_puts++;
645 }
646 
647 
657 static void
658 dht_connected (void *cls,
660  void *ca_result,
661  const char *emsg)
662 {
663  struct ActiveContext *ac = cls;
664  struct Context *ctx = ac->ctx;
665 
666  GNUNET_assert (NULL != ctx); // FIXME: Fails
667  GNUNET_assert (NULL != ctx->op);
668  GNUNET_assert (ctx->op == op);
669  ac->dht = (struct GNUNET_DHT_Handle *) ca_result;
670  if (NULL != emsg)
671  {
673  "Connection to DHT service failed: %s\n",
674  emsg);
675  GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect() */
676  ctx->op = NULL;
677  return;
678  }
679  switch (mode)
680  {
681  case MODE_PUT:
682  {
683  struct GNUNET_TIME_Relative peer_delay_put;
684 
685  peer_delay_put.rel_value_us =
688  ac->put_count = num_puts_per_peer;
689  ac->hash = calloc (ac->put_count,
690  sizeof(struct GNUNET_HashCode));
691  if (NULL == ac->hash)
692  {
694  "calloc");
696  return;
697  }
698  ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_put,
699  &delayed_put,
700  ac);
701  break;
702  }
703 
704  case MODE_GET:
705  {
706  struct GNUNET_TIME_Relative peer_delay_get;
707 
708  peer_delay_get.rel_value_us =
712  ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_get,
713  &delayed_get,
714  ac);
715  break;
716  }
717  }
718 }
719 
720 
730 static void *
731 dht_connect (void *cls,
732  const struct GNUNET_CONFIGURATION_Handle *cfg)
733 {
734  n_dht++;
735  return GNUNET_DHT_connect (cfg,
736  10);
737 }
738 
739 
747 static void
748 dht_disconnect (void *cls,
749  void *op_result)
750 {
751  struct ActiveContext *ac = cls;
752 
753  GNUNET_assert (NULL != ac->dht);
754  GNUNET_assert (ac->dht == op_result);
755  GNUNET_DHT_disconnect (ac->dht);
756  ac->dht = NULL;
757  n_dht--;
758  if (0 != n_dht)
759  return;
760  if (GNUNET_YES == in_shutdown)
761  return;
762  switch (mode)
763  {
764  case MODE_PUT:
765  if (n_puts_ok != ((unsigned long long) n_active) * num_puts_per_peer)
766  return;
767  /* Start GETs if all PUTs have been made */
768  mode = MODE_GET;
769  start_profiling ();
770  return;
771 
772  case MODE_GET:
773  if ((n_gets_ok + n_gets_fail) != n_active)
774  return;
775  break;
776  }
777 }
778 
779 
783 static void
785 {
786  struct Context *ctx;
787 
788  DEBUG ("GNUNET_TESTBED_service_connect\n");
790  for (unsigned int i = 0; i < n_active; i++)
791  {
792  struct ActiveContext *ac = &a_ac[i];
793  GNUNET_assert (NULL != (ctx = ac->ctx));
794  GNUNET_assert (NULL == ctx->op);
796  ctx->peer,
797  "dht",
798  &dht_connected, ac,
799  &dht_connect,
801  ac);
802  }
803 }
804 
805 
814 static void
815 service_started (void *cls,
817  const char *emsg)
818 {
819  struct Context *ctx = cls;
820 
821  GNUNET_assert (NULL != ctx);
822  GNUNET_assert (NULL != ctx->op);
824  ctx->op = NULL;
825  peers_started++;
826  DEBUG ("Peers Started = %d; num_peers = %d \n",
828  num_peers);
829  if (peers_started == num_peers)
830  start_profiling ();
831 }
832 
833 
845 static void
846 test_run (void *cls,
847  struct GNUNET_TESTBED_RunHandle *h,
848  unsigned int num_peers,
849  struct GNUNET_TESTBED_Peer **peers,
850  unsigned int links_succeeded,
851  unsigned int links_failed)
852 {
853  unsigned int ac_cnt;
854 
856  if (NULL == peers)
857  {
858  /* exit */
859  GNUNET_assert (0);
860  }
861  MESSAGE ("%u peers started, %u/%u links up\n",
862  num_peers,
863  links_succeeded,
864  links_succeeded + links_failed);
866  struct Context);
867  /* select the peers which actively participate in profiling */
869  if (0 == n_active)
870  {
872  GNUNET_free (a_ctx);
873  a_ctx = NULL;
874  return;
875  }
876 
878  struct ActiveContext);
879  ac_cnt = 0;
880  for (unsigned int cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
881  {
883  100) >= put_probability)
884  continue;
885 
886  a_ctx[cnt].ac = &a_ac[ac_cnt];
887  a_ac[ac_cnt].ctx = &a_ctx[cnt];
888  ac_cnt++;
889  }
890  n_active = ac_cnt;
891 
892  /* start DHT service on all peers */
893  for (unsigned int cnt = 0; cnt < num_peers; cnt++)
894  {
895  a_ctx[cnt].peer = peers[cnt];
897  peers[cnt],
898  "dht",
900  &a_ctx[cnt],
901  1);
902  }
903 }
904 
905 
914 static void
915 run (void *cls,
916  char *const *args,
917  const char *cfgfile,
918  const struct GNUNET_CONFIGURATION_Handle *config)
919 {
920  uint64_t event_mask;
921 
922  if (0 == num_peers)
923  {
925  _ ("Exiting as the number of peers is %u\n"),
926  num_peers);
927  return;
928  }
929  cfg = config;
930  event_mask = 0;
932  cfg,
933  num_peers,
934  event_mask,
935  NULL,
936  NULL,
937  &test_run,
938  NULL);
940  NULL);
941 }
942 
943 
949 int
950 main (int argc,
951  char *const *argv)
952 {
953  int rc;
956  "peers",
957  "COUNT",
958  gettext_noop ("number of peers to start"),
959  &num_peers),
961  "peer-put-count",
962  "COUNT",
963  gettext_noop (
964  "number of PUTs to perform per peer"),
967  "hosts",
968  "FILENAME",
969  gettext_noop (
970  "name of the file with the login information for the testbed"),
971  &hosts_file),
973  "delay",
974  "DELAY",
975  gettext_noop (
976  "delay between rounds for collecting statistics (default: 30 sec)"),
977  &delay_stats),
979  "PUT-delay",
980  "DELAY",
981  gettext_noop (
982  "delay to start doing PUTs (default: 1 sec)"),
983  &delay_put),
985  "GET-delay",
986  "DELAY",
987  gettext_noop (
988  "delay to start doing GETs (default: 5 min)"),
989  &delay_get),
991  "replication",
992  "DEGREE",
993  gettext_noop ("replication degree for DHT PUTs"),
994  &replication),
996  "random-chance",
997  "PROBABILITY",
998  gettext_noop (
999  "chance that a peer is selected at random for PUTs"),
1000  &put_probability),
1002  "timeout",
1003  "TIMEOUT",
1004  gettext_noop (
1005  "timeout for DHT PUT and GET requests (default: 1 min)"),
1006  &timeout),
1008  };
1009 
1010  if (GNUNET_OK !=
1011  GNUNET_STRINGS_get_utf8_args (argc, argv,
1012  &argc, &argv))
1013  return 2;
1014  /* set default delays */
1019  replication = 1; /* default replication */
1020  rc = 0;
1021  if (GNUNET_OK !=
1022  GNUNET_PROGRAM_run (argc,
1023  argv,
1024  "gnunet-dht-profiler",
1025  gettext_noop (
1026  "Measure quality and performance of the DHT service."),
1027  options,
1028  &run,
1029  NULL))
1030  rc = 1;
1031  return rc;
1032 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_TEST
Block for testing.
#define gettext_noop(String)
Definition: gettext.h:70
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct CadetPeer * peers
Operation to get peer ids.
struct GNUNET_HashCode key
The key used in the DHT.
uint32_t data
The data value.
static char * value
Value of the record to add/remove.
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
static const struct GNUNET_CONFIGURATION_Handle * config
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
uint64_t event_mask
Global event mask for all testbed events.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static struct GNUNET_TESTBED_Peer ** testbed_handles
Testbed peer handles.
static unsigned long long n_puts_ok
Number of DHT PUTs succeeded.
static void get_iter(void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const struct GNUNET_PeerIdentity *trunc_peer, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data)
Iterator called on each result obtained for a DHT operation that expects a reply.
static void test_run(void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, unsigned int links_failed)
Signature of a main function for a testcase.
static void dht_connected(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Connection to DHT has been established.
static struct GNUNET_TIME_Relative delay_put
The delay to start puts.
static unsigned int n_gets_ok
Number of DHT GETs succeeded.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration.
static int bandwidth_stats_iterator(void *cls, const struct GNUNET_TESTBED_Peer *peer, const char *subsystem, const char *name, uint64_t value, int is_persistent)
Process statistic values.
static double average_get_path_length
Average number of hops taken to do get.
static int in_shutdown
Are we shutting down.
static void delayed_get(void *cls)
Task to do DHT GETs.
static struct GNUNET_TESTBED_Operation * bandwidth_stats_op
Testbed Operation (to get stats).
static void do_shutdown(void *cls)
Shutdown task.
static void delayed_put(void *cls)
Task to do DHT PUTs.
static unsigned int n_active
Number of active peers.
static char * hosts_file
Name of the file with the hosts to run the test over.
static struct GNUNET_TIME_Relative delay_get
The delay to start puts.
static unsigned int total_put_path_length
Total put path length across all peers.
static unsigned int n_dht
Number of DHT service connections we currently have.
static void summarize()
static void bandwidth_stats_cont(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
Stats callback.
#define DEBUG(...)
static void cancel_get(void *cls)
Task to cancel DHT GET.
static unsigned int n_gets_fail
Number of DHT GETs succeeded.
static unsigned int replication
Replication degree.
static void service_started(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
Callback called when DHT service on the peer is started.
static void start_profiling(void)
Connect to DHT services of active peers.
static struct GNUNET_TIME_Relative timeout
The timeout for GET and PUT.
static unsigned long long n_puts
Number of DHT PUTs made.
static struct GNUNET_TIME_Relative delay_stats
The delay between rounds for collecting statistics.
static struct Context * a_ctx
An array of contexts.
@ MODE_GET
@ MODE_PUT
static unsigned int total_get_path_length
Total get path length across all peers.
static enum @8 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
static uint64_t outgoing_bandwidth
Total number of messages sent by peer.
static double average_put_path_length
Average number of hops taken to do put.
int main(int argc, char *const *argv)
Main function.
#define MESSAGE(...)
static unsigned int put_probability
Number of peers which should perform a PUT out of 100 peers.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main function that will be run by the scheduler.
static unsigned int num_puts_per_peer
Number of DHT PUTs to be made per peer.
static void dht_disconnect(void *cls, void *op_result)
Adapter function called to destroy a connection to a service.
static void * dht_connect(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to DHT service and return the DHT client handler.
static struct ActiveContext * a_ac
Array of active peers.
static unsigned int num_peers
Number of peers.
static int peers_started
Counter to keep track of peers added to peer_context lists.
static uint64_t incoming_bandwidth
Total number of messages received by peer.
static unsigned int n_gets
Number of DHT GETs made.
static void put_cont(void *cls)
Conclude individual PUT operation, schedule the next one.
API to the DHT service.
API for writing tests and creating large-scale emulation testbeds for GNUnet.
#define GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE
What is the maximum size for encrypted messages? Note that this number imposes a clear limit on the m...
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
void GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph)
Cancels a DHT PUT operation.
Definition: dht_api.c:1148
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition: dht_api.c:1237
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:1039
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:1090
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:1062
struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, const void *xquery, size_t xquery_size, GNUNET_DHT_GetIterator iter, void *iter_cls)
Perform an asynchronous GET operation on the DHT identified.
Definition: dht_api.c:1164
@ GNUNET_DHT_RO_NONE
Default.
@ GNUNET_DHT_RO_RECORD_ROUTE
We should keep track of the route that the message took in the P2P network.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
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:1299
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,...
Definition: scheduler.c:1334
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
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:1272
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1222
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2021
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_manage_service(void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_OperationCompletionCallback cb, void *cb_cls, unsigned int start)
Start or stop given service at a peer.
void GNUNET_TESTBED_run(const char *host_filename, const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int num_peers, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, GNUNET_TESTBED_TestMaster test_master, void *test_master_cls)
Convenience method for running a testbed with a single call.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_ServiceConnectCompletionCallback cb, void *cb_cls, GNUNET_TESTBED_ConnectAdapter ca, GNUNET_TESTBED_DisconnectAdapter da, void *cada_cls)
Connect to a service offered by the given peer.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_get_statistics(unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, const char *subsystem, const char *name, GNUNET_TESTBED_StatisticsIterator proc, GNUNET_TESTBED_OperationCompletionCallback cont, void *cls)
Convenience method that iterates over all (running) peers and retrieves all statistics from each peer...
#define GNUNET_TIME_UNIT_SECONDS
One second.
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:484
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static int op_result(struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx, uint8_t cancel)
Remove an operation, and call its result callback (unless it was cancelled).
Definition: op.c:246
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
const char * name
Context for a peer which actively does DHT PUT/GET.
struct GNUNET_HashCode * hash
The hashes of the values stored via this activity context.
struct GNUNET_DHT_Handle * dht
Handler to the DHT service.
uint16_t nrefs
The number of peers currently doing GET on our data.
unsigned int put_count
How many puts should we still issue?
struct GNUNET_SCHEDULER_Task * delay_task
Delay task.
struct ActiveContext * get_ac
The active context used for our DHT GET.
struct GNUNET_DHT_PutHandle * dht_put
The put handle.
struct Context * ctx
The linked peer context.
struct GNUNET_DHT_GetHandle * dht_get
The get handle.
Context to hold data of peer.
struct GNUNET_TESTBED_Peer * peer
The testbed peer this context belongs to.
struct ActiveContext * ac
Active context; NULL if this peer is not an active peer.
struct GNUNET_TESTBED_Operation * op
Testbed operation acting on this peer.
Handle to a GET request.
Definition: dht_api.c:81
Connection to the DHT service.
Definition: dht_api.c:237
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
Handle to a PUT request.
Definition: dht_api.c:45
Definition of a command line option.
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:136
Opaque handle to an abstract operation to be executed by the testing framework.
A peer controlled by the testing framework.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.