WiP
[oweals/gnunet.git] / src / dht / plugin_dhtlog_mysql_dump_load.c
index e1c1e65801a6480477526635a172ba662c000e5b..956af6bdd371e9850100c6f0ec0c7d5ec4e8006e 100644 (file)
@@ -36,7 +36,7 @@
 #include "dhtlog.h"
 
 
-#define DEBUG_DHTLOG GNUNET_NO
+#define DEBUG_DHTLOG GNUNET_YES
 
 /**
  * Maximum number of supported parameters for a prepared
@@ -131,6 +131,32 @@ int add_round (unsigned int round_type, unsigned int round_count)
 
 }
 
+/*
+ * Inserts the specified round results into the
+ * dhttests.processed_round_details table
+ *
+ * @param round_type the type of round that is being started
+ * @param round_count counter for the round (if applicable)
+ * @param num_messages the total number of messages initiated
+ * @param num_messages_succeeded the number of messages that succeeded
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int add_round_details (unsigned int round_type, unsigned int round_count,
+                       unsigned int num_messages, unsigned int num_messages_succeeded)
+{
+  int ret;
+  if (outfile == NULL)
+    return GNUNET_SYSERR;
+
+  ret = fprintf(outfile, "insert into processed_trial_rounds (trialuid, round_type, round_count, starttime, endtime, num_messages, num_messages_succeeded) values (@temp_trial, \"%u\", \"%u\", \"%s\", \"%s\", \"%u\", \"%u\");\n",
+                                                              round_type, round_count, get_sql_time(), get_sql_time(), num_messages, num_messages_succeeded);
+
+  if (ret >= 0)
+    return GNUNET_OK;
+  return GNUNET_SYSERR;
+}
+
 /*
  * Records a connection between two peers in the current topology
  *
@@ -167,7 +193,6 @@ add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNU
 int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
 {
   int ret;
-  trial_info->trialuid = 0;
   if (outfile == NULL)
     return GNUNET_SYSERR;
 
@@ -327,7 +352,7 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
     return GNUNET_SYSERR;
 
   ret = fprintf(node_outfile, "TRIALUID\t%s\n", GNUNET_h2s_full(&node->hashPubKey));
-
+  fflush(node_outfile);
   if (ret >= 0)
     return GNUNET_OK;
   return GNUNET_SYSERR;
@@ -336,29 +361,20 @@ add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
 /*
  * Update dhttests.trials table with current server time as end time
  *
- * @param trialuid trial to update
  * @param gets_succeeded how many gets did the testcase report as successful
  *
  * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
  */
 int
-update_trials (unsigned long long trialuid,
-               unsigned int gets_succeeded)
+update_trials (unsigned int gets_succeeded)
 {
   int ret;
-#if DEBUG_DHTLOG
-  if (trialuid != current_trial)
-    {
-      fprintf (stderr,
-               _("Trialuid to update is not equal to current_trial\n"));
-    }
-#endif
 
   if (outfile == NULL)
     return GNUNET_SYSERR;
 
   ret = fprintf(outfile, "update trials set endtime=\"%s\", gets_succeeded=%u where trialuid = @temp_trial;\n", get_sql_time(), gets_succeeded);
-
+  fflush(node_outfile);
   if (ret >= 0)
     return GNUNET_OK;
   else
@@ -383,7 +399,7 @@ set_malicious (struct GNUNET_PeerIdentity *peer)
     return GNUNET_SYSERR;
 
   ret = fprintf(outfile, "update nodes set malicious_dropper = 1 where trialuid = @temp_trial and nodeid = \"%s\";\n", GNUNET_h2s_full(&peer->hashPubKey));
-
+  fflush(node_outfile);
   if (ret >= 0)
     return GNUNET_OK;
   else
@@ -394,27 +410,20 @@ set_malicious (struct GNUNET_PeerIdentity *peer)
 /*
  * Update dhttests.trials table with total connections information
  *
- * @param trialuid the trialuid to update
  * @param totalConnections the number of connections
  *
  * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
  */
 int
-add_connections (unsigned long long trialuid, unsigned int totalConnections)
+add_connections (unsigned int totalConnections)
 {
   int ret;
-#if DEBUG_DHTLOG
-  if (trialuid != current_trial)
-    {
-      fprintf (stderr,
-               _("Trialuid to update is not equal to current_trial(!)(?)\n"));
-    }
-#endif
+
   if (outfile == NULL)
     return GNUNET_SYSERR;
 
   ret = fprintf(outfile, "update trials set totalConnections = %u where trialuid = @temp_trial;\n", totalConnections);
-
+  fflush(node_outfile);
   if (ret >= 0)
     return GNUNET_OK;
   else
@@ -475,7 +484,7 @@ add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
   if (ret < 0)
     return GNUNET_SYSERR;
 
-  ret = fprintf(query_outfile, "%s\t%llu\t%u\t%u\t%u\n", GNUNET_h2s_full(&node->hashPubKey), queryid, type, hops, succeeded);
+  ret = fprintf(query_outfile, "%s\t%llu\t%u\t%u\t%u\t%s\n", GNUNET_h2s_full(&node->hashPubKey), queryid, type, hops, succeeded, get_sql_time());
 
   if (ret >= 0)
     return GNUNET_OK;
@@ -598,12 +607,13 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
       return NULL;
     }
 
+  GNUNET_free(outfile_name);
   GNUNET_asprintf (&outfile_name,
                    "%s%s-%d",
                    outfile_path,
                    "mysqldump_nodes",
                    getpid());
-
+  GNUNET_free(fn);
   fn = GNUNET_STRINGS_filename_expand (outfile_name);
 
   if (fn == NULL)
@@ -630,12 +640,14 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
       return NULL;
     }
 
+  GNUNET_free(outfile_name);
   GNUNET_asprintf (&outfile_name,
                    "%s%s-%d",
                    outfile_path,
                    "mysqldump_routes",
                    getpid());
 
+  GNUNET_free(fn);
   fn = GNUNET_STRINGS_filename_expand (outfile_name);
 
   if (fn == NULL)
@@ -662,12 +674,14 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
       return NULL;
     }
 
+  GNUNET_free(outfile_name);
   GNUNET_asprintf (&outfile_name,
                    "%s%s-%d",
                    outfile_path,
                    "mysqldump_queries",
                    getpid());
 
+  GNUNET_free(fn);
   fn = GNUNET_STRINGS_filename_expand (outfile_name);
 
   if (fn == NULL)
@@ -694,12 +708,14 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
       return NULL;
     }
 
+  GNUNET_free(outfile_name);
   GNUNET_asprintf (&outfile_name,
                    "%s%s-%d",
                    outfile_path,
                    "mysqldump_stats",
                    getpid());
 
+  GNUNET_free(fn);
   fn = GNUNET_STRINGS_filename_expand (outfile_name);
 
   if (fn == NULL)
@@ -726,12 +742,13 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
       return NULL;
     }
 
+  GNUNET_free(outfile_name);
   GNUNET_asprintf (&outfile_name,
                    "%s%s-%d",
                    outfile_path,
                    "mysqldump_generic_stats",
                    getpid());
-
+  GNUNET_free(fn);
   fn = GNUNET_STRINGS_filename_expand (outfile_name);
 
   if (fn == NULL)
@@ -758,12 +775,13 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
       return NULL;
     }
 
+  GNUNET_free(outfile_name);
   GNUNET_asprintf (&outfile_name,
                    "%s%s-%d",
                    outfile_path,
                    "mysqldump_dhtkey",
                    getpid());
-
+  GNUNET_free(fn);
   fn = GNUNET_STRINGS_filename_expand (outfile_name);
 
   if (fn == NULL)
@@ -790,12 +808,13 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
       return NULL;
     }
 
+  GNUNET_free(outfile_name);
   GNUNET_asprintf (&outfile_name,
                    "%s%s-%d",
                    outfile_path,
                    "mysqldump_extended_topology",
                    getpid());
-
+  GNUNET_free(fn);
   fn = GNUNET_STRINGS_filename_expand (outfile_name);
 
   if (fn == NULL)
@@ -831,6 +850,7 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
   plugin->dhtlog_api->insert_trial = &add_trial;
   plugin->dhtlog_api->insert_stat = &add_stat;
   plugin->dhtlog_api->insert_round = &add_round;
+  plugin->dhtlog_api->insert_round_details = &add_round_details;
   plugin->dhtlog_api->insert_query = &add_query;
   plugin->dhtlog_api->update_trial = &update_trials;
   plugin->dhtlog_api->insert_route = &add_route;