WiP
[oweals/gnunet.git] / src / dht / plugin_dhtlog_mysql.c
index 127db015d18d2f450e7c7f3915edfa27a72c54fd..0cce99d6d8f7bc050cf3049268bddbb9f2bef3e6 100644 (file)
@@ -108,6 +108,11 @@ static struct StatementHandle *insert_node;
 
 static struct StatementHandle *insert_round;
 
+#define INSERT_ROUND_DETAILS_STMT "INSERT INTO rounds (trialuid, round_type, round_count, starttime, endtime, num_messages, num_messages_succeeded) "\
+                          "VALUES (?, ?, ?, NOW(), NOW(), ?, ?)"
+
+static struct StatementHandle *insert_round_details;
+
 #define INSERT_TRIALS_STMT "INSERT INTO trials"\
                             "(starttime, other_trial_identifier, numnodes, topology,"\
                             "topology_percentage, topology_probability,"\
@@ -454,6 +459,7 @@ iopen (struct GNUNET_DHTLOG_Plugin *plugin)
       PINIT (insert_route, INSERT_ROUTES_STMT) ||
       PINIT (insert_trial, INSERT_TRIALS_STMT) ||
       PINIT (insert_round, INSERT_ROUNDS_STMT) ||
+      PINIT (insert_round, INSERT_ROUND_DETAILS_STMT) ||
       PINIT (insert_stat, INSERT_STAT_STMT) ||
       PINIT (insert_generic_stat, INSERT_GENERIC_STAT_STMT) ||
       PINIT (insert_node, INSERT_NODES_STMT) ||
@@ -850,7 +856,7 @@ int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
 
   stmt = mysql_stmt_init(conn);
   if (GNUNET_OK !=
-      (ret = prepared_statement_run (insert_trial, &trial_info->trialuid,
+      (ret = prepared_statement_run (insert_trial, &current_trial,
                                      MYSQL_TYPE_LONG, &trial_info->other_identifier, GNUNET_YES,
                                      MYSQL_TYPE_LONG, &trial_info->num_nodes, GNUNET_YES,
                                      MYSQL_TYPE_LONG, &trial_info->topology, GNUNET_YES,
@@ -917,6 +923,38 @@ int add_round (unsigned int round_type, unsigned int round_count)
   return ret;
 }
 
+/*
+ * 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)
+{
+  MYSQL_STMT *stmt;
+  int ret;
+
+  stmt = mysql_stmt_init(conn);
+  ret = prepared_statement_run (insert_round_details,
+                                NULL,
+                                MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES,
+                                MYSQL_TYPE_LONG, &round_type, GNUNET_YES,
+                                MYSQL_TYPE_LONG, &round_count, GNUNET_YES,
+                                MYSQL_TYPE_LONG, &num_messages, GNUNET_YES,
+                                MYSQL_TYPE_LONG, &num_messages_succeeded, GNUNET_YES,
+                                -1);
+  mysql_stmt_close(stmt);
+  if (ret != GNUNET_OK)
+    return GNUNET_SYSERR;
+  return ret;
+}
+
 /*
  * Inserts the specified stats into the dhttests.node_statistics table
  *
@@ -1149,14 +1187,12 @@ 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;
 
@@ -1164,7 +1200,7 @@ update_trials (unsigned long long trialuid,
       (ret = prepared_statement_run (update_trial,
                                     NULL,
                                     MYSQL_TYPE_LONG, &gets_succeeded, GNUNET_YES,
-                                    MYSQL_TYPE_LONGLONG, &trialuid, GNUNET_YES,
+                                    MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES,
                                     -1)))
     {
       if (ret == GNUNET_SYSERR)
@@ -1215,13 +1251,12 @@ int 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;
 
@@ -1232,7 +1267,7 @@ add_connections (unsigned long long trialuid, unsigned int totalConnections)
                                                   &totalConnections,
                                                   GNUNET_YES,
                                                   MYSQL_TYPE_LONGLONG,
-                                                  &trialuid, GNUNET_YES, -1)))
+                                                  &current_trial, GNUNET_YES, -1)))
     {
       if (ret == GNUNET_SYSERR)
         {
@@ -1564,6 +1599,7 @@ libgnunet_plugin_dhtlog_mysql_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->add_generic_stat = &add_generic_stat;
   plugin->dhtlog_api->insert_query = &add_query;
   plugin->dhtlog_api->update_trial = &update_trials;
@@ -1596,6 +1632,7 @@ libgnunet_plugin_dhtlog_mysql_done (void * cls)
   prepared_statement_close(insert_route);
   prepared_statement_close(insert_trial);
   prepared_statement_close(insert_round);
+  prepared_statement_close(insert_round_details);
   prepared_statement_close(insert_node);
   prepared_statement_close(insert_dhtkey);
   prepared_statement_close(update_trial);