Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / consensus / gnunet-consensus-profiler.c
index 355ae60a33d3a00eba21d6e30150127a0459dcc4..65542f4cd133ac543d3a4463582f55d69b3396fe 100644 (file)
@@ -55,6 +55,8 @@ static struct GNUNET_HashCode session_id;
 
 static unsigned int peers_done = 0;
 
+static int dist_static;
+
 static unsigned *results_for_peer;
 
 /**
@@ -98,7 +100,7 @@ controller_cb (void *cls,
 
 
 static void
-statistics_done_db (void *cls,
+statistics_done_cb (void *cls,
                     struct
                     GNUNET_TESTBED_Operation
                     *op,
@@ -108,6 +110,7 @@ statistics_done_db (void *cls,
   GNUNET_TESTBED_operation_done (op);
   if (NULL != statistics_file)
     fclose (statistics_file);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got statistics, shutting down\n");
   GNUNET_SCHEDULER_shutdown ();
 }
 
@@ -120,8 +123,8 @@ statistics_done_db (void *cls,
  * @param subsystem name of subsystem that created the statistic
  * @param name the name of the datum
  * @param value the current value
- * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
- * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
  */
 static int
 statistics_cb (void *cls,
@@ -140,7 +143,7 @@ statistics_cb (void *cls,
 
 
 static void
-destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *ctx)
+destroy (void *cls)
 {
   struct GNUNET_CONSENSUS_Handle *consensus = cls;
 
@@ -162,7 +165,7 @@ destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *ctx)
       statistics_file = fopen (statistics_filename, "w");
     GNUNET_TESTBED_get_statistics (num_peers, peers, NULL, NULL,
                                    statistics_cb,
-                                   statistics_done_db,
+                                   statistics_done_cb,
                                    NULL);
   }
 }
@@ -182,7 +185,7 @@ conclude_cb (void *cls)
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "consensus %d done\n",
-              chp - consensus_handles);
+              (int) (chp - consensus_handles));
   GNUNET_SCHEDULER_add_now (destroy, *chp);
 }
 
@@ -216,26 +219,45 @@ do_consensus ()
 {
   int unique_indices[replication];
   unsigned int i;
+  unsigned int j;
+  struct GNUNET_HashCode val;
+  struct GNUNET_SET_Element element;
 
-  for (i = 0; i < num_values; i++)
+  if (dist_static)
   {
-    unsigned int j;
-    struct GNUNET_HashCode val;
-    struct GNUNET_SET_Element element;
+    for (i = 0; i < num_values; i++)
+    {
 
-    generate_indices (unique_indices);
-    GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &val);
+      GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &val);
 
-    element.data = &val;
-    element.size = sizeof (val);
-    for (j = 0; j < replication; j++)
+      element.data = &val;
+      element.size = sizeof (val);
+      for (j = 0; j < replication; j++)
+      {
+        GNUNET_CONSENSUS_insert (consensus_handles[j],
+                                 &element,
+                                 NULL, NULL);
+      }
+    }
+  }
+  else
+  {
+    for (i = 0; i < num_values; i++)
     {
-      int cid;
+      generate_indices (unique_indices);
+      GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &val);
+
+      element.data = &val;
+      element.size = sizeof (val);
+      for (j = 0; j < replication; j++)
+      {
+        int cid;
 
-      cid = unique_indices[j];
-      GNUNET_CONSENSUS_insert (consensus_handles[cid],
-                               &element,
-                               NULL, NULL);
+        cid = unique_indices[j];
+        GNUNET_CONSENSUS_insert (consensus_handles[cid],
+                                 &element,
+                                 NULL, NULL);
+      }
     }
   }
 
@@ -349,6 +371,8 @@ static void
 disconnect_adapter(void *cls, void *op_result)
 {
   /* FIXME: what to do here? */
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "disconnect adapter called\n");
 }
 
 
@@ -510,6 +534,9 @@ main (int argc, char **argv)
       { 's', "statistics", NULL,
         gettext_noop ("write statistics to file"),
         GNUNET_YES, &GNUNET_GETOPT_set_filename, &statistics_filename },
+      { 'S', "dist-static", NULL,
+        gettext_noop ("distribute elements to a static subset of good peers"),
+        GNUNET_YES, &GNUNET_GETOPT_set_one, &dist_static },
       { 'V', "verbose", NULL,
         gettext_noop ("be more verbose (print received values)"),
         GNUNET_NO, &GNUNET_GETOPT_set_one, &verbose },
@@ -521,4 +548,3 @@ main (int argc, char **argv)
                      options, &run, NULL, GNUNET_YES);
   return 0;
 }
-