From 79453be1daf8fbda661a2bd1f701a9733f0ba8c8 Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Thu, 16 Sep 2010 14:11:49 +0000 Subject: [PATCH] feature creep --- src/dht/plugin_dhtlog_dummy.c | 14 +++++++++ src/dht/plugin_dhtlog_mysql.c | 42 +++++++++++++++++++++---- src/dht/plugin_dhtlog_mysql_dump.c | 27 ++++++++++++++++ src/dht/plugin_dhtlog_mysql_dump_load.c | 23 ++++++++++++++ 4 files changed, 100 insertions(+), 6 deletions(-) diff --git a/src/dht/plugin_dhtlog_dummy.c b/src/dht/plugin_dhtlog_dummy.c index 856d119c7..803ad92ac 100644 --- a/src/dht/plugin_dhtlog_dummy.c +++ b/src/dht/plugin_dhtlog_dummy.c @@ -45,6 +45,19 @@ 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) +{ + return GNUNET_OK; +} + /* * Inserts the specified dhtkey into the dhttests.dhtkeys table, * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid @@ -282,6 +295,7 @@ libgnunet_plugin_dhtlog_dummy_init (void * cls) GNUNET_assert(plugin->dhtlog_api == NULL); plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle)); plugin->dhtlog_api->add_generic_stat = &add_generic_stat; + plugin->dhtlog_api->insert_round = &add_round; plugin->dhtlog_api->insert_stat = &insert_stat; plugin->dhtlog_api->insert_trial = &add_trial; plugin->dhtlog_api->insert_query = &add_query; diff --git a/src/dht/plugin_dhtlog_mysql.c b/src/dht/plugin_dhtlog_mysql.c index 5e47ec2f5..465a987e0 100644 --- a/src/dht/plugin_dhtlog_mysql.c +++ b/src/dht/plugin_dhtlog_mysql.c @@ -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) || @@ -885,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 @@ -1445,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) { @@ -1542,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; @@ -1573,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); diff --git a/src/dht/plugin_dhtlog_mysql_dump.c b/src/dht/plugin_dhtlog_mysql_dump.c index f58d6782a..2582bca41 100644 --- a/src/dht/plugin_dhtlog_mysql_dump.c +++ b/src/dht/plugin_dhtlog_mysql_dump.c @@ -63,6 +63,8 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; #define INSERT_TOPOLOGY_STMT "prepare insert_topology from 'INSERT INTO topology (trialuid, date, connections) "\ "VALUES (@temp_trial, ?, ?)'" +#define INSERT_ROUND_STMT "prepare insert_round from 'INSERT INTO rounds (trialuid, round_type, round_count, starttime) VALUES (@temp_trial, @rtype, @rcount, @curr_time)'" + #define EXTEND_TOPOLOGY_STMT "prepare extend_topology from 'INSERT INTO extended_topology (topology_uid, uid_first, uid_second) "\ "VALUES (@temp_topology, ?, ?)'" @@ -158,6 +160,7 @@ iopen () #define PINIT(a) (GNUNET_OK != (prepared_statement_create(a))) if (PINIT (INSERT_QUERIES_STMT) || PINIT (INSERT_ROUTES_STMT) || + PINIT (INSERT_ROUND_STMT) || PINIT (INSERT_TRIALS_STMT) || PINIT (SET_MALICIOUS_STMT) || PINIT (INSERT_GENERIC_STAT_STMT) || @@ -181,7 +184,30 @@ iopen () 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) +{ + int ret; + if (outfile == NULL) + return GNUNET_SYSERR; + + ret = fprintf(outfile, "set @curr_time = \"%s\", @rtype = \"%u\", @rcount = \"%u\";\n", get_sql_time(), round_type, round_count); + + if (ret < 0) + return GNUNET_SYSERR; + ret = fprintf(outfile, "execute insert_round;\n"); + if (ret >= 0) + return GNUNET_OK; + return GNUNET_SYSERR; +} /* * Records the current topology (number of connections, time, trial) @@ -813,6 +839,7 @@ libgnunet_plugin_dhtlog_mysql_dump_init (void * cls) GNUNET_assert(plugin->dhtlog_api == NULL); plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle)); plugin->dhtlog_api->insert_trial = &add_trial; + plugin->dhtlog_api->insert_round = &add_round; plugin->dhtlog_api->insert_stat = &add_stat; plugin->dhtlog_api->insert_query = &add_query; plugin->dhtlog_api->update_trial = &update_trials; diff --git a/src/dht/plugin_dhtlog_mysql_dump_load.c b/src/dht/plugin_dhtlog_mysql_dump_load.c index 32733d03a..e1c1e6580 100644 --- a/src/dht/plugin_dhtlog_mysql_dump_load.c +++ b/src/dht/plugin_dhtlog_mysql_dump_load.c @@ -109,6 +109,28 @@ add_topology (int num_connections) return GNUNET_SYSERR; } +/* + * 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) +{ + int ret; + if (outfile == NULL) + return GNUNET_SYSERR; + + ret = fprintf(outfile, "insert into rounds (trialuid, round_type, round_count, starttime) values (@temp_trial, \"%u\", \"%u\", \"%s\");\n", round_type, round_count, get_sql_time()); + + if (ret >= 0) + return GNUNET_OK; + return GNUNET_SYSERR; + +} + /* * Records a connection between two peers in the current topology * @@ -808,6 +830,7 @@ libgnunet_plugin_dhtlog_mysql_dump_load_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->insert_query = &add_query; plugin->dhtlog_api->update_trial = &update_trials; plugin->dhtlog_api->insert_route = &add_route; -- 2.25.1