Add missing include
[oweals/gnunet.git] / src / consensus / gnunet-consensus-profiler.c
index 42040527f0d6fa0c6499ae720ca30310d6d9e1c9..bade332b5996270fd3305f3a4db0cb431b14b143 100644 (file)
@@ -4,7 +4,7 @@
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
-      by the Free Software Foundation; either version 2, or (at your
+      by the Free Software Foundation; either version 3, or (at your
       option) any later version.
 
       GNUnet is distributed in the hope that it will be useful, but
  */
 
 /**
- * @file consensus/gnunet-consensus.c
+ * @file consensus/gnunet-consensus-profiler.c
  * @brief profiling tool for gnunet-consensus
  * @author Florian Dold
  */
 #include "platform.h"
-#include "gnunet_common.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_consensus_service.h"
 #include "gnunet_testbed_service.h"
@@ -55,6 +54,8 @@ static unsigned int peers_done = 0;
 
 static unsigned *results_for_peer;
 
+static int verbose;
+
 
 /**
  * Signature of the event handler function called by the
@@ -202,10 +203,18 @@ new_element_cb (void *cls,
                 const struct GNUNET_SET_Element *element)
 {
   struct GNUNET_CONSENSUS_Handle **chp = cls;
+  int idx = chp - consensus_handles;
 
   GNUNET_assert (NULL != cls);
-  
-  results_for_peer[chp - consensus_handles]++;
+
+  results_for_peer[idx]++;
+
+  GNUNET_assert (sizeof (struct GNUNET_HashCode) == element->size);
+
+  if (GNUNET_YES == verbose)
+  {
+    printf ("P%d received %s\n", idx, GNUNET_h2s ((struct GNUNET_HashCode *) element->data));
+  }
 }
 
 
@@ -293,6 +302,7 @@ peer_info_cb (void *cb_cls,
  * Signature of a main function for a testcase.
  *
  * @param cls closure
+ * @param h the run handle
  * @param num_peers number of peers in 'peers'
  * @param started_peers handle to peers run in the testbed.  NULL upon timeout (see
  *          GNUNET_TESTBED_test_run()).
@@ -303,6 +313,7 @@ peer_info_cb (void *cb_cls,
  */
 static void
 test_master (void *cls,
+             struct GNUNET_TESTBED_RunHandle *h,
              unsigned int num_peers,
              struct GNUNET_TESTBED_Peer **started_peers,
              unsigned int links_succeeded,
@@ -335,6 +346,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 {
   static char *session_str = "gnunet-consensus/test";
   char *topology;
+  int topology_cmp_result;
 
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", "OVERLAY_TOPOLOGY", &topology))
   {
@@ -343,15 +355,16 @@ run (void *cls, char *const *args, const char *cfgfile,
     return;
   }
 
-  if (0 == strcasecmp (topology, "NONE"))
+  topology_cmp_result = strcasecmp (topology, "NONE");
+  GNUNET_free (topology);
+
+  if (0 == topology_cmp_result)
   {
     fprintf (stderr, "'OVERLAY_TOPOLOGY' set to 'NONE', "
                      "seems like you passed the wrong configuration file\n");
     return;
   }
 
-  GNUNET_free (topology);
-
   if (num_peers < replication)
   {
     fprintf (stderr, "k must be <=n\n");
@@ -389,6 +402,9 @@ main (int argc, char **argv)
       { 't', "timeout", NULL,
         gettext_noop ("consensus timeout"),
         GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &conclude_timeout },
+      { 'V', "verbose", NULL,
+        gettext_noop ("be more verbose (print received values)"),
+        GNUNET_NO, &GNUNET_GETOPT_set_one, &verbose },
       GNUNET_GETOPT_OPTION_END
   };
   conclude_timeout = GNUNET_TIME_UNIT_SECONDS;