X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fdht%2Fplugin_dhtlog_mysql.c;h=b31a41f4c184f5fd63609d4bb552323296d828b4;hb=b7c95147188502651e4cb2b60c7062137f73e878;hp=a3d5ac7a5a7e3c7c6da5b88b62407f0b66c8ab77;hpb=c0ad7d994c1c7cb96a68a784f3b677f3de981f57;p=oweals%2Fgnunet.git diff --git a/src/dht/plugin_dhtlog_mysql.c b/src/dht/plugin_dhtlog_mysql.c index a3d5ac7a5..b31a41f4c 100644 --- a/src/dht/plugin_dhtlog_mysql.c +++ b/src/dht/plugin_dhtlog_mysql.c @@ -91,8 +91,8 @@ static unsigned long long current_trial = 0; /* I like to assign 0, just to r */ static MYSQL *conn; -#define INSERT_QUERIES_STMT "INSERT INTO queries (trialuid, querytype, hops, dhtkeyuid, dhtqueryid, succeeded, nodeuid) "\ - "VALUES (?, ?, ?, ?, ?, ?, ?)" +#define INSERT_QUERIES_STMT "INSERT INTO queries (trialuid, querytype, hops, dhtkeyuid, dhtqueryid, succeeded, nodeuid, time) "\ + "VALUES (?, ?, ?, ?, ?, ?, ?, NOW())" static struct StatementHandle *insert_query; #define INSERT_ROUTES_STMT "INSERT INTO routes (trialuid, querytype, hops, dhtkeyuid, dhtqueryid, succeeded, nodeuid, from_node, to_node) "\ @@ -103,6 +103,11 @@ static struct StatementHandle *insert_route; "VALUES (?, ?, ?)" static struct StatementHandle *insert_node; +#define INSERT_ROUNDS_STMT "INSERT INTO rounds (trialuid, round_type, round_count, starttime) "\ + "VALUES (?, ?, ?, NOW())" + +static struct StatementHandle *insert_round; + #define INSERT_TRIALS_STMT "INSERT INTO trials"\ "(starttime, other_trial_identifier, numnodes, topology,"\ "topology_percentage, topology_probability,"\ @@ -448,6 +453,7 @@ iopen (struct GNUNET_DHTLOG_Plugin *plugin) if (PINIT (insert_query, INSERT_QUERIES_STMT) || PINIT (insert_route, INSERT_ROUTES_STMT) || PINIT (insert_trial, INSERT_TRIALS_STMT) || + PINIT (insert_round, INSERT_ROUNDS_STMT) || PINIT (insert_stat, INSERT_STAT_STMT) || PINIT (insert_generic_stat, INSERT_GENERIC_STAT_STMT) || PINIT (insert_node, INSERT_NODES_STMT) || @@ -589,7 +595,8 @@ init_params (struct StatementHandle *s, va_list ap) /** * Run a prepared SELECT statement. * - * @param result_size number of elements in results array + * @param s handle to the statement we should execute + * @param result_size number of results in set * @param results pointer to already initialized MYSQL_BIND * array (of sufficient size) for passing results * @param processor function to call on each result @@ -597,12 +604,13 @@ init_params (struct StatementHandle *s, va_list ap) * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective * values (size + buffer-reference for pointers); terminated * with "-1" + * * @return GNUNET_SYSERR on error, otherwise * the number of successfully affected (or queried) rows */ int -prepared_statement_run_select (struct StatementHandle - *s, unsigned int result_size, +prepared_statement_run_select (struct StatementHandle *s, + unsigned int result_size, MYSQL_BIND * results, GNUNET_MysqlDataProcessor processor, void *processor_cls, @@ -783,11 +791,13 @@ get_dhtkey_uid (unsigned long long *dhtkeyuid, const GNUNET_HashCode * key) /** * Run a prepared statement that does NOT produce results. * + * @param s handle to the statement we should execute + * @param insert_id NULL or address where to store the row ID of whatever + * was inserted (only for INSERT statements!) * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective * values (size + buffer-reference for pointers); terminated * with "-1" - * @param insert_id NULL or address where to store the row ID of whatever - * was inserted (only for INSERT statements!) + * * @return GNUNET_SYSERR on error, otherwise * the number of successfully affected rows */ @@ -881,6 +891,31 @@ int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info) return GNUNET_OK; } +/* + * Inserts the specified round into the dhttests.rounds table + * + * @param round_type the type of round that is being started + * @param round_count counter for the round (if applicable) + * + * @return GNUNET_OK on success, GNUNET_SYSERR on failure + */ +int add_round (unsigned int round_type, unsigned int round_count) +{ + + MYSQL_STMT *stmt; + int ret; + + stmt = mysql_stmt_init(conn); + ret = prepared_statement_run (insert_round, + NULL, + MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES, + MYSQL_TYPE_LONG, &round_type, GNUNET_YES, + MYSQL_TYPE_LONG, &round_count, 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 @@ -1441,12 +1476,9 @@ add_topology (int num_connections) if (GNUNET_OK != (ret = prepared_statement_run (insert_topology, NULL, - MYSQL_TYPE_LONGLONG, - ¤t_trial, - GNUNET_YES, - MYSQL_TYPE_LONG, - &num_connections, - GNUNET_YES, -1))) + MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES, + MYSQL_TYPE_LONG, &num_connections, GNUNET_YES, + -1))) { if (ret == GNUNET_SYSERR) { @@ -1538,6 +1570,7 @@ libgnunet_plugin_dhtlog_mysql_init (void * cls) plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle)); plugin->dhtlog_api->insert_trial = &add_trial; plugin->dhtlog_api->insert_stat = &add_stat; + plugin->dhtlog_api->insert_round = &add_round; plugin->dhtlog_api->add_generic_stat = &add_generic_stat; plugin->dhtlog_api->insert_query = &add_query; plugin->dhtlog_api->update_trial = &update_trials; @@ -1569,6 +1602,7 @@ libgnunet_plugin_dhtlog_mysql_done (void * cls) prepared_statement_close(insert_query); prepared_statement_close(insert_route); prepared_statement_close(insert_trial); + prepared_statement_close(insert_round); prepared_statement_close(insert_node); prepared_statement_close(insert_dhtkey); prepared_statement_close(update_trial);