WiP
[oweals/gnunet.git] / src / dht / gnunet-dht-driver.c
index a2dc68001e9055b81782d03e50d58f727df44663..2010326e6fe61eeab0b9dd13eb94220ebabd961f 100644 (file)
@@ -425,12 +425,27 @@ static struct GNUNET_TIME_Absolute connect_start_time;
  */
 static struct GNUNET_TIME_Absolute connect_last_time;
 
+/**
+ * At what time did we start the hostkey creation process.
+ */
+static struct GNUNET_TIME_Absolute hostkey_start_time;
+
+/**
+ * At what time did we start the peer startup process.
+ */
+static struct GNUNET_TIME_Absolute peer_start_time;
+
 /**
  * Boolean value, should the driver issue find peer requests
  * (GNUNET_YES) or should it be left to the service (GNUNET_NO)
  */
 static unsigned int do_find_peer;
 
+/**
+ * Whether or not to insert gauger data.
+ */
+static unsigned int insert_gauger_data;
+
 #if ONLY_TESTING
 /**
  * Are we currently trying to connect two peers repeatedly?
@@ -966,9 +981,10 @@ finish_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
     free_meter (get_meter);
 
   GNUNET_asprintf (&temp_get_string,
-                   "DHT Successful GETs (trial %d)", trial_to_run);
+                   "DHT Successful GETs", trial_to_run);
   GNUNET_asprintf (&revision_str, "%llu", revision);
-  GAUGER_ID("DHT_TESTING", temp_get_string, cumulative_successful_gets / (double)cumulative_num_gets, "percent successful", revision_str);
+  if (GNUNET_YES == insert_gauger_data)
+    GAUGER_ID("DHT_TESTING", temp_get_string, cumulative_successful_gets / (double)cumulative_num_gets, "percent successful", revision_str);
   fprintf (
            stderr,
            "Finished trial, had %llu successful gets out of %llu total, %.2f percent succeeded\n",
@@ -1243,10 +1259,8 @@ do_get(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
 static int
 remove_peer_count(void *cls, const GNUNET_HashCode * key, void *value)
 {
-  struct FindPeerContext *find_peer_ctx = cls;
   struct PeerCount *peer_count = value;
-  GNUNET_CONTAINER_heap_remove_node (find_peer_ctx->peer_min_heap,
-                                     peer_count->heap_node);
+  GNUNET_CONTAINER_heap_remove_node (peer_count->heap_node);
   GNUNET_free(peer_count);
 
   return GNUNET_YES;
@@ -2028,7 +2042,7 @@ get_stop_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
   struct TestGetContext *test_get = cls;
 
-  if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
+  if ( (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
     gets_failed++;
   else
     cumulative_successful_gets++;
@@ -2166,7 +2180,7 @@ put_finished(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
   outstanding_puts--;
   puts_completed++;
 
-  if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
+  if ( (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
     fprintf (stderr, "PUT Request failed!\n");
 
   /* Reset the daemon (which peer to insert at) for later put request iterations */
@@ -2690,7 +2704,7 @@ continue_puts_and_gets(void *cls,
  */
 static void
 malicious_disconnect_task(void *cls,
-    const struct GNUNET_SCHEDULER_TaskContext * tc)
+                          const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
   struct MaliciousContext *ctx = cls;
   outstanding_malicious--;
@@ -2705,7 +2719,6 @@ malicious_disconnect_task(void *cls,
     {
       fprintf (stderr, "Finished setting all malicious peers up!\n");
     }
-
 }
 
 /**
@@ -2753,16 +2766,13 @@ set_malicious(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
   switch (ctx->malicious_type)
     {
   case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET:
-    GNUNET_DHT_set_malicious_getter (ctx->dht_handle, malicious_get_frequency);
-    GNUNET_SCHEDULER_add_now (&malicious_done_task, ctx);
+    GNUNET_DHT_set_malicious_getter (ctx->dht_handle, malicious_get_frequency, &malicious_done_task, ctx);
     break;
   case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT:
-    GNUNET_DHT_set_malicious_putter (ctx->dht_handle, malicious_put_frequency);
-    GNUNET_SCHEDULER_add_now (&malicious_done_task, ctx);
+    GNUNET_DHT_set_malicious_putter (ctx->dht_handle, malicious_put_frequency, &malicious_done_task, ctx);
     break;
   case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP:
-    GNUNET_DHT_set_malicious_dropper (ctx->dht_handle);
-    GNUNET_SCHEDULER_add_now (&malicious_done_task, ctx);
+    GNUNET_DHT_set_malicious_dropper (ctx->dht_handle, &malicious_done_task, ctx);
     break;
   default:
     break;
@@ -2933,21 +2943,21 @@ repeat_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
  */
 static void
 topology_callback(void *cls, const struct GNUNET_PeerIdentity *first,
-    const struct GNUNET_PeerIdentity *second, uint32_t distance,
-    const struct GNUNET_CONFIGURATION_Handle *first_cfg,
-    const struct GNUNET_CONFIGURATION_Handle *second_cfg,
-    struct GNUNET_TESTING_Daemon *first_daemon,
-    struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
+                  const struct GNUNET_PeerIdentity *second, uint32_t distance,
+                  const struct GNUNET_CONFIGURATION_Handle *first_cfg,
+                  const struct GNUNET_CONFIGURATION_Handle *second_cfg,
+                  struct GNUNET_TESTING_Daemon *first_daemon,
+                  struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
 {
   struct TopologyIteratorContext *topo_ctx;
   unsigned long long duration;
   unsigned long long total_duration;
   unsigned int new_connections;
   unsigned int new_failed_connections;
-  double conns_per_sec_recent;
-  double conns_per_sec_total;
-  double failed_conns_per_sec_recent;
-  double failed_conns_per_sec_total;
+  long double conns_per_sec_recent;
+  long double conns_per_sec_total;
+  long double failed_conns_per_sec_recent;
+  long double failed_conns_per_sec_total;
   char *temp_conn_string;
   char *temp_conn_failed_string;
   char *revision_str;
@@ -2999,14 +3009,14 @@ topology_callback(void *cls, const struct GNUNET_PeerIdentity *first,
                                                  GNUNET_TIME_absolute_get ()).rel_value
               / 1000;
 
-      failed_conns_per_sec_recent = (double) new_failed_connections / duration;
-      failed_conns_per_sec_total = (double) failed_connections / total_duration;
-      conns_per_sec_recent = (double) new_connections / duration;
-      conns_per_sec_total = (double) total_connections / total_duration;
+      failed_conns_per_sec_recent = (long double) new_failed_connections / duration;
+      failed_conns_per_sec_total = (long double) failed_connections / total_duration;
+      conns_per_sec_recent = (long double) new_connections / duration;
+      conns_per_sec_total = (long double) total_connections / total_duration;
       GNUNET_log (
                   GNUNET_ERROR_TYPE_WARNING,
                   "Recent: %.2f/s, Total: %.2f/s, Recent failed: %.2f/s, total failed %.2f/s\n",
-                  conns_per_sec_recent, CONN_UPDATE_DURATION,
+                  conns_per_sec_recent,
                   conns_per_sec_total, failed_conns_per_sec_recent,
                   failed_conns_per_sec_total);
       connect_last_time = GNUNET_TIME_absolute_get ();
@@ -3085,8 +3095,8 @@ topology_callback(void *cls, const struct GNUNET_PeerIdentity *first,
           = GNUNET_TIME_absolute_get_difference (connect_start_time,
                                                  GNUNET_TIME_absolute_get ()).rel_value
               / 1000;
-      failed_conns_per_sec_total = (double) failed_connections / total_duration;
-      conns_per_sec_total = (double) total_connections / total_duration;
+      failed_conns_per_sec_total = (long double) failed_connections / total_duration;
+      conns_per_sec_total = (long double) total_connections / total_duration;
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   "Overall connection info --- Total: %u, Total Failed %u/s\n",
                   total_connections, failed_connections);
@@ -3096,25 +3106,31 @@ topology_callback(void *cls, const struct GNUNET_PeerIdentity *first,
                   conns_per_sec_total, failed_conns_per_sec_total);
 
       GNUNET_asprintf (&temp_conn_string,
-                       "DHT Profiler Connection (trial %d)",
+                       "DHT Profiler Connection/s",
                        trial_to_run);
       GNUNET_asprintf (&temp_conn_failed_string,
-                       "DHT Profiler Connection failed (trial %d)",
+                       "DHT Profiler Connection/s failed",
                        trial_to_run);
       GNUNET_asprintf (&revision_str, "%llu", revision);
-      GAUGER_ID("DHT_TESTING", temp_conn_string, conns_per_sec_total, "conns/s", revision_str);
-      GAUGER_ID("DHT_TESTING", temp_conn_failed_string, failed_conns_per_sec_total, "failed_conns", revision_str);
+
+      if (GNUNET_YES == insert_gauger_data)
+        GAUGER_ID("DHT_TESTING", temp_conn_string, (float)conns_per_sec_total, "conns/s", revision_str);
+      if (GNUNET_YES == insert_gauger_data)
+        GAUGER_ID("DHT_TESTING", temp_conn_failed_string, (float)failed_conns_per_sec_total, "failed_conns", revision_str);
+
       GNUNET_free(temp_conn_string);
       GNUNET_free(temp_conn_failed_string);
       GNUNET_asprintf (&temp_conn_string,
-                       "DHT Profiler Total Connections (trial %d)",
+                       "DHT Profiler Total Connections",
                        trial_to_run);
       GNUNET_asprintf (
                        &temp_conn_failed_string,
-                       "DHT Profiler Total Connections failed (trial %d)",
+                       "DHT Profiler Total Connections failed",
                        trial_to_run);
-      GAUGER_ID("DHT_TESTING", temp_conn_string, total_connections, "conns", revision_str);
-      GAUGER_ID("DHT_TESTING", temp_conn_failed_string, failed_connections, "failed conns", revision_str);
+      if (GNUNET_YES == insert_gauger_data)
+        GAUGER_ID("DHT_TESTING", temp_conn_string, total_connections, "conns", revision_str);
+      if (GNUNET_YES == insert_gauger_data)
+        GAUGER_ID("DHT_TESTING", temp_conn_failed_string, failed_connections, "failed conns", revision_str);
       GNUNET_free(temp_conn_string);
       GNUNET_free(temp_conn_failed_string);
       GNUNET_free(revision_str);
@@ -3154,6 +3170,7 @@ peers_started_callback(void *cls, const struct GNUNET_PeerIdentity *id,
     const struct GNUNET_CONFIGURATION_Handle *cfg,
     struct GNUNET_TESTING_Daemon *d, const char *emsg)
 {
+  char *revision_str;
   if (emsg != NULL)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3178,6 +3195,14 @@ peers_started_callback(void *cls, const struct GNUNET_PeerIdentity *id,
 #endif
       GNUNET_SCHEDULER_cancel (die_task);
 
+      GNUNET_asprintf (&revision_str, "%llu", revision);
+      if (GNUNET_YES == insert_gauger_data)
+        GAUGER_ID("DHT_TESTING",
+                  "peer_startup_time",
+                  GNUNET_TIME_absolute_get_duration(peer_start_time).rel_value / (double)num_peers,
+                  "ms/peer", revision_str);
+      GNUNET_free(revision_str);
+
       expected_connections = UINT_MAX;
       if ((pg != NULL) && (peers_left == 0))
         {
@@ -3197,7 +3222,7 @@ peers_started_callback(void *cls, const struct GNUNET_PeerIdentity *id,
                    expected_connections);
         }
 
-      if (expected_connections == GNUNET_SYSERR)
+      if (expected_connections == 0)
         {
           die_task
               = GNUNET_SCHEDULER_add_now (&end_badly,
@@ -3220,13 +3245,16 @@ peers_started_callback(void *cls, const struct GNUNET_PeerIdentity *id,
 static void
 create_topology()
 {
+  unsigned int create_expected_connections;
   peers_left = num_peers; /* Reset counter */
-  if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology,
-                                      blacklist_transports) != GNUNET_SYSERR)
+  create_expected_connections = GNUNET_TESTING_create_topology (pg, topology, blacklist_topology,
+                                                                blacklist_transports);
+  if (create_expected_connections > 0)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "Topology set up, now starting peers!\n");
+                  "Topology set up, have %u expected connections, now starting peers!\n", create_expected_connections);
       GNUNET_TESTING_daemons_continue_startup (pg);
+      peer_start_time = GNUNET_TIME_absolute_get();
     }
   else
     {
@@ -3257,6 +3285,7 @@ static void
 hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id,
     struct GNUNET_TESTING_Daemon *d, const char *emsg)
 {
+  char * revision_str;
   if (emsg != NULL)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -3275,6 +3304,29 @@ hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id,
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                   "All %d hostkeys created, now creating topology!\n",
                   num_peers);
+
+      GNUNET_asprintf (&revision_str, "%llu", revision);
+      if (GNUNET_YES == insert_gauger_data)
+        {
+          if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (config, "TESTING",
+                                                                   "HOSTKEYSFILE"))
+            {
+              GAUGER_ID("DHT_TESTING",
+                        "HOSTKEY_GENERATION",
+                        GNUNET_TIME_absolute_get_duration(hostkey_start_time).rel_value / (double)num_peers,
+                        "ms/hostkey", revision_str);
+            }
+          else
+            {
+              GAUGER_ID("DHT_TESTING",
+                        "HOSTKEY_GENERATION_REAL",
+                        GNUNET_TIME_absolute_get_duration(hostkey_start_time).rel_value / (double)num_peers,
+                        "ms/hostkey", revision_str);
+            }
+        }
+
+      GNUNET_free(revision_str);
+
       GNUNET_SCHEDULER_cancel (die_task);
       /* Set up task in case topology creation doesn't finish
        * within a reasonable amount of time */
@@ -3582,7 +3634,6 @@ run(void *cls, char * const *args, const char *cfgfile,
       while (count < frstat.st_size - 1)
         {
           count++;
-          /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))*/
           if (((data[count] == '\n')) && (buf != &data[count]))
             {
               data[count] = '\0';
@@ -3593,7 +3644,7 @@ run(void *cls, char * const *args, const char *cfgfile,
               if (3 == ret)
                 {
                   GNUNET_log (
-                              GNUNET_ERROR_TYPE_WARNING,
+                              GNUNET_ERROR_TYPE_DEBUG,
                               "Successfully read host %s, port %d and user %s from file\n",
                               temphost->hostname, temphost->port,
                               temphost->username);
@@ -3606,7 +3657,6 @@ run(void *cls, char * const *args, const char *cfgfile,
                   buf = &data[count + 1];
                   continue;
                 }
-              /* temphost->hostname = buf; */
               temphost->next = hosts;
               hosts = temphost;
               buf = &data[count + 1];
@@ -3797,6 +3847,10 @@ run(void *cls, char * const *args, const char *cfgfile,
                                                          "do_find_peer"))
     do_find_peer = GNUNET_YES;
 
+  if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht_testing",
+                                                           "insert_gauger_data"))
+    insert_gauger_data = GNUNET_YES;
+
   if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht",
                                                           "republish"))
     in_dht_replication = GNUNET_YES;
@@ -4007,6 +4061,7 @@ run(void *cls, char * const *args, const char *cfgfile,
 
   put_meter = create_meter (num_puts, "Puts completed ", GNUNET_YES);
   get_meter = create_meter (num_gets, "Gets completed ", GNUNET_YES);
+  hostkey_start_time = GNUNET_TIME_absolute_get();
   pg
       = GNUNET_TESTING_daemons_start (
                                       cfg,