2 This file is part of GNUnet.
3 (C) 2006 - 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file src/dht/plugin_dhtlog_mysql.c
23 * @brief MySQL logging plugin to record DHT operations to MySQL server
24 * @author Nathan Evans
30 #include "gnunet_util_lib.h"
32 #include <mysql/mysql.h>
35 #define DEBUG_DHTLOG GNUNET_YES
38 * Maximum number of supported parameters for a prepared
39 * statement. Increase if needed.
44 * A generic statement handle to use
45 * for prepared statements. This way,
46 * once the statement is initialized
49 struct StatementHandle
54 MYSQL_STMT *statement;
62 * Whether or not the handle is valid
68 * Type of a callback that will be called for each
69 * data set returned from MySQL.
71 * @param cls user-defined argument
72 * @param num_values number of elements in values
73 * @param values values returned by MySQL
74 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
76 typedef int (*GNUNET_MysqlDataProcessor) (void *cls,
77 unsigned int num_values,
80 static unsigned long max_varchar_len;
83 * The configuration the DHT service is running with
85 static const struct GNUNET_CONFIGURATION_Handle *cfg;
87 static unsigned long long current_trial = 0; /* I like to assign 0, just to remember */
90 * Connection to the MySQL Server.
94 #define INSERT_QUERIES_STMT "INSERT INTO queries (trialuid, querytype, hops, dhtkeyuid, dhtqueryid, succeeded, nodeuid, time) "\
95 "VALUES (?, ?, ?, ?, ?, ?, ?, NOW())"
96 static struct StatementHandle *insert_query;
98 #define INSERT_ROUTES_STMT "INSERT INTO routes (trialuid, querytype, hops, dhtkeyuid, dhtqueryid, succeeded, nodeuid, from_node, to_node) "\
99 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
100 static struct StatementHandle *insert_route;
102 #define INSERT_NODES_STMT "INSERT INTO nodes (trialuid, nodeid, nodebits) "\
104 static struct StatementHandle *insert_node;
106 #define INSERT_ROUNDS_STMT "INSERT INTO rounds (trialuid, round_type, round_count, starttime) "\
107 "VALUES (?, ?, ?, NOW())"
109 static struct StatementHandle *insert_round;
111 #define INSERT_ROUND_DETAILS_STMT "INSERT INTO rounds (trialuid, round_type, round_count, starttime, endtime, num_messages, num_messages_succeeded) "\
112 "VALUES (?, ?, ?, NOW(), NOW(), ?, ?)"
114 static struct StatementHandle *insert_round_details;
116 #define INSERT_TRIALS_STMT "INSERT INTO trials"\
117 "(starttime, other_trial_identifier, numnodes, topology,"\
118 "topology_percentage, topology_probability,"\
119 "blacklist_topology, connect_topology, connect_topology_option,"\
120 "connect_topology_option_modifier, puts, gets, "\
121 "concurrent, settle_time, num_rounds, malicious_getters,"\
122 "malicious_putters, malicious_droppers, malicious_get_frequency,"\
123 "malicious_put_frequency, stop_closest, stop_found, strict_kademlia, "\
124 "gets_succeeded, message) "\
125 "VALUES (NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
127 static struct StatementHandle *insert_trial;
129 #define INSERT_STAT_STMT "INSERT INTO node_statistics"\
130 "(trialuid, nodeuid, route_requests,"\
131 "route_forwards, result_requests,"\
132 "client_results, result_forwards, gets,"\
133 "puts, data_inserts, find_peer_requests, "\
134 "find_peers_started, gets_started, puts_started, find_peer_responses_received,"\
135 "get_responses_received, find_peer_responses_sent, get_responses_sent) "\
136 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
138 static struct StatementHandle *insert_stat;
140 #define INSERT_GENERIC_STAT_STMT "INSERT INTO generic_stats" \
141 "(trialuid, nodeuid, section, name, value)"\
142 "VALUES (?, ?, ?, ?, ?)"
143 static struct StatementHandle *insert_generic_stat;
145 #define INSERT_DHTKEY_STMT "INSERT INTO dhtkeys (dhtkey, trialuid, keybits) "\
147 static struct StatementHandle *insert_dhtkey;
149 #define UPDATE_TRIALS_STMT "UPDATE trials set endtime=NOW(), gets_succeeded = ? where trialuid = ?"
150 static struct StatementHandle *update_trial;
152 #define UPDATE_CONNECTIONS_STMT "UPDATE trials set totalConnections = ? where trialuid = ?"
153 static struct StatementHandle *update_connection;
155 #define GET_TRIAL_STMT "SELECT MAX( trialuid ) FROM trials"
156 static struct StatementHandle *get_trial;
158 #define GET_TOPOLOGY_STMT "SELECT MAX( topology_uid ) FROM topology"
159 static struct StatementHandle *get_topology;
161 #define GET_DHTKEYUID_STMT "SELECT dhtkeyuid FROM dhtkeys where dhtkey = ? and trialuid = ?"
162 static struct StatementHandle *get_dhtkeyuid;
164 #define GET_NODEUID_STMT "SELECT nodeuid FROM nodes where trialuid = ? and nodeid = ?"
165 static struct StatementHandle *get_nodeuid;
167 #define INSERT_TOPOLOGY_STMT "INSERT INTO topology (trialuid, date, connections) "\
168 "VALUES (?, NOW(), ?)"
169 static struct StatementHandle *insert_topology;
171 #define EXTEND_TOPOLOGY_STMT "INSERT INTO extended_topology (topology_uid, uid_first, uid_second) "\
173 static struct StatementHandle *extend_topology;
175 #define SET_MALICIOUS_STMT "update nodes set malicious_dropper = 1 where trialuid = ? and nodeid = ?"
176 static struct StatementHandle *update_node_malicious;
178 #define UPDATE_TOPOLOGY_STMT "update topology set connections = ? where topology_uid = ?"
179 static struct StatementHandle *update_topology;
182 * Run a query (not a select statement)
184 * @return GNUNET_OK if executed, GNUNET_SYSERR if an error occurred
187 run_statement (const char *statement)
189 mysql_query (conn, statement);
190 if (mysql_error (conn)[0])
192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
194 return GNUNET_SYSERR;
200 * Creates tables if they don't already exist for dht logging
205 #define MRUNS(a) (GNUNET_OK != run_statement (a) )
207 if (MRUNS ("CREATE TABLE IF NOT EXISTS `dhtkeys` ("
208 "dhtkeyuid int(10) unsigned NOT NULL auto_increment COMMENT 'Unique Key given to each query',"
209 "`dhtkey` varchar(255) NOT NULL COMMENT 'The ASCII value of the key being searched for',"
210 "trialuid int(10) unsigned NOT NULL,"
211 "keybits blob NOT NULL,"
212 "UNIQUE KEY `dhtkeyuid` (`dhtkeyuid`)"
213 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
214 return GNUNET_SYSERR;
216 if (MRUNS ("CREATE TABLE IF NOT EXISTS `nodes` ("
217 "`nodeuid` int(10) unsigned NOT NULL auto_increment,"
218 "`trialuid` int(10) unsigned NOT NULL,"
219 "`nodeid` varchar(255) NOT NULL,"
220 "`nodebits` blob NOT NULL,"
221 "PRIMARY KEY (`nodeuid`)"
222 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
223 return GNUNET_SYSERR;
225 if (MRUNS ("CREATE TABLE IF NOT EXISTS `queries` ("
226 "`trialuid` int(10) unsigned NOT NULL,"
227 "`queryuid` int(10) unsigned NOT NULL auto_increment,"
228 "`dhtqueryid` bigint(20) NOT NULL,"
229 "`querytype` enum('1','2','3','4','5') NOT NULL,"
230 "`hops` int(10) unsigned NOT NULL,"
231 "`succeeded` tinyint NOT NULL,"
232 "`nodeuid` int(10) unsigned NOT NULL,"
233 "`time` timestamp NOT NULL default CURRENT_TIMESTAMP,"
234 "`dhtkeyuid` int(10) unsigned NOT NULL,"
235 "PRIMARY KEY (`queryuid`)"
236 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
237 return GNUNET_SYSERR;
239 if (MRUNS ("CREATE TABLE IF NOT EXISTS `routes` ("
240 "`trialuid` int(10) unsigned NOT NULL,"
241 "`queryuid` int(10) unsigned NOT NULL auto_increment,"
242 "`dhtqueryid` bigint(20) NOT NULL,"
243 "`querytype` enum('1','2','3','4','5') NOT NULL,"
244 "`hops` int(10) unsigned NOT NULL,"
245 "`succeeded` tinyint NOT NULL,"
246 "`nodeuid` int(10) unsigned NOT NULL,"
247 "`time` timestamp NOT NULL default CURRENT_TIMESTAMP,"
248 "`dhtkeyuid` int(10) unsigned NOT NULL,"
249 "`from_node` int(10) unsigned NOT NULL,"
250 "`to_node` int(10) unsigned NOT NULL,"
251 "PRIMARY KEY (`queryuid`)"
252 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
253 return GNUNET_SYSERR;
255 if (MRUNS ("CREATE TABLE IF NOT EXISTS `trials` ("
256 "`trialuid` int(10) unsigned NOT NULL auto_increment,"
257 "`other_trial_identifier` int(10) unsigned NOT NULL default '0',"
258 "`numnodes` int(10) unsigned NOT NULL,"
259 "`topology` int(10) NOT NULL,"
260 "`blacklist_topology` int(11) NOT NULL,"
261 "`connect_topology` int(11) NOT NULL,"
262 "`connect_topology_option` int(11) NOT NULL,"
263 "`topology_percentage` float NOT NULL,"
264 "`topology_probability` float NOT NULL,"
265 "`connect_topology_option_modifier` float NOT NULL,"
266 "`starttime` datetime NOT NULL,"
267 "`endtime` datetime NOT NULL,"
268 "`puts` int(10) unsigned NOT NULL,"
269 "`gets` int(10) unsigned NOT NULL,"
270 "`concurrent` int(10) unsigned NOT NULL,"
271 "`settle_time` int(10) unsigned NOT NULL,"
272 "`totalConnections` int(10) unsigned NOT NULL,"
273 "`message` text NOT NULL,"
274 "`num_rounds` int(10) unsigned NOT NULL,"
275 "`malicious_getters` int(10) unsigned NOT NULL,"
276 "`malicious_putters` int(10) unsigned NOT NULL,"
277 "`malicious_droppers` int(10) unsigned NOT NULL,"
278 "`topology_modifier` double NOT NULL,"
279 "`malicious_get_frequency` int(10) unsigned NOT NULL,"
280 "`malicious_put_frequency` int(10) unsigned NOT NULL,"
281 "`stop_closest` int(10) unsigned NOT NULL,"
282 "`stop_found` int(10) unsigned NOT NULL,"
283 "`strict_kademlia` int(10) unsigned NOT NULL,"
284 "`gets_succeeded` int(10) unsigned NOT NULL,"
285 "PRIMARY KEY (`trialuid`),"
286 "UNIQUE KEY `trialuid` (`trialuid`)"
287 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
288 return GNUNET_SYSERR;
290 if (MRUNS ("CREATE TABLE IF NOT EXISTS `topology` ("
291 "`topology_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
292 "`trialuid` int(10) unsigned NOT NULL,"
293 "`date` datetime NOT NULL,"
294 "`connections` int(10) unsigned NOT NULL,"
295 "PRIMARY KEY (`topology_uid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
296 return GNUNET_SYSERR;
298 if (MRUNS ("CREATE TABLE IF NOT EXISTS `extended_topology` ("
299 "`extended_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
300 "`topology_uid` int(10) unsigned NOT NULL,"
301 "`uid_first` int(10) unsigned NOT NULL,"
302 "`uid_second` int(10) unsigned NOT NULL,"
303 "PRIMARY KEY (`extended_uid`)"
304 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"))
305 return GNUNET_SYSERR;
307 if (MRUNS ("CREATE TABLE IF NOT EXISTS `node_statistics` ("
308 "`stat_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,"
309 "`trialuid` int(10) unsigned NOT NULL,"
310 "`nodeuid` int(10) unsigned NOT NULL,"
311 "`route_requests` int(10) unsigned NOT NULL,"
312 "`route_forwards` int(10) unsigned NOT NULL,"
313 "`result_requests` int(10) unsigned NOT NULL,"
314 "`client_results` int(10) unsigned NOT NULL,"
315 "`result_forwards` int(10) unsigned NOT NULL,"
316 "`gets` int(10) unsigned NOT NULL,"
317 "`puts` int(10) unsigned NOT NULL,"
318 "`data_inserts` int(10) unsigned NOT NULL,"
319 "`find_peer_requests` int(10) unsigned NOT NULL,"
320 "`find_peers_started` int(10) unsigned NOT NULL,"
321 "`gets_started` int(10) unsigned NOT NULL,"
322 "`puts_started` int(10) unsigned NOT NULL,"
323 "`find_peer_responses_received` int(10) unsigned NOT NULL,"
324 "`get_responses_received` int(10) unsigned NOT NULL,"
325 "`find_peer_responses_sent` int(10) unsigned NOT NULL,"
326 "`get_responses_sent` int(10) unsigned NOT NULL,"
327 "PRIMARY KEY (`stat_uid`)"
328 ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"))
329 return GNUNET_SYSERR;
331 if (MRUNS ("SET AUTOCOMMIT = 1"))
332 return GNUNET_SYSERR;
339 * Create a prepared statement.
341 * @return NULL on error
343 struct StatementHandle *
344 prepared_statement_create (const char *statement)
346 struct StatementHandle *ret;
348 ret = GNUNET_malloc (sizeof (struct StatementHandle));
349 ret->query = GNUNET_strdup (statement);
354 * Close a prepared statement.
356 * @return NULL on error
359 prepared_statement_close (struct StatementHandle *s)
366 GNUNET_free_non_null(s->query);
368 if (s->valid == GNUNET_YES)
369 mysql_stmt_close(s->statement);
374 * Initialize the prepared statements for use with dht test logging
377 iopen (struct GNUNET_DHTLOG_Plugin *plugin)
381 unsigned int timeout;
386 unsigned long long port;
388 conn = mysql_init (NULL);
390 return GNUNET_SYSERR;
392 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
396 database = GNUNET_strdup("gnunet");
399 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
400 "MYSQL", "USER", &user))
402 user = GNUNET_strdup("dht");
405 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
406 "MYSQL", "PASSWORD", &password))
408 password = GNUNET_strdup("dhttest**");
411 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
412 "MYSQL", "SERVER", &server))
414 server = GNUNET_strdup("localhost");
417 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->cfg,
418 "MYSQL", "MYSQL_PORT", &port))
423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to mysql with: user %s, pass %s, server %s, database %s, port %d\n",
424 user, password, server, database, port);
427 timeout = 60; /* in seconds */
428 mysql_options (conn, MYSQL_OPT_RECONNECT, &reconnect);
430 MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
431 mysql_options(conn, MYSQL_SET_CHARSET_NAME, "UTF8");
432 mysql_options (conn, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
433 mysql_options (conn, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
434 mysql_real_connect (conn, server, user, password,
435 database, (unsigned int) port, NULL, CLIENT_IGNORE_SIGPIPE);
437 GNUNET_free_non_null(server);
438 GNUNET_free_non_null(password);
439 GNUNET_free_non_null(user);
440 GNUNET_free_non_null(database);
442 if (mysql_error (conn)[0])
444 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
445 "mysql_real_connect");
446 return GNUNET_SYSERR;
450 db = GNUNET_MYSQL_database_open (coreAPI->ectx, coreAPI->cfg);
452 return GNUNET_SYSERR;
457 #define PINIT(a,b) (NULL == (a = prepared_statement_create(b)))
458 if (PINIT (insert_query, INSERT_QUERIES_STMT) ||
459 PINIT (insert_route, INSERT_ROUTES_STMT) ||
460 PINIT (insert_trial, INSERT_TRIALS_STMT) ||
461 PINIT (insert_round, INSERT_ROUNDS_STMT) ||
462 PINIT (insert_round, INSERT_ROUND_DETAILS_STMT) ||
463 PINIT (insert_stat, INSERT_STAT_STMT) ||
464 PINIT (insert_generic_stat, INSERT_GENERIC_STAT_STMT) ||
465 PINIT (insert_node, INSERT_NODES_STMT) ||
466 PINIT (insert_dhtkey, INSERT_DHTKEY_STMT) ||
467 PINIT (update_trial, UPDATE_TRIALS_STMT) ||
468 PINIT (get_dhtkeyuid, GET_DHTKEYUID_STMT) ||
469 PINIT (get_nodeuid, GET_NODEUID_STMT) ||
470 PINIT (update_connection, UPDATE_CONNECTIONS_STMT) ||
471 PINIT (get_trial, GET_TRIAL_STMT) ||
472 PINIT (get_topology, GET_TOPOLOGY_STMT) ||
473 PINIT (insert_topology, INSERT_TOPOLOGY_STMT) ||
474 PINIT (update_topology, UPDATE_TOPOLOGY_STMT) ||
475 PINIT (extend_topology, EXTEND_TOPOLOGY_STMT) ||
476 PINIT (update_node_malicious, SET_MALICIOUS_STMT) )
478 return GNUNET_SYSERR;
486 return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values)
492 * Prepare a statement for running.
494 * @return GNUNET_OK on success
497 prepare_statement (struct StatementHandle *ret)
499 if (GNUNET_YES == ret->valid)
502 ret->statement = mysql_stmt_init (conn);
503 if (ret->statement == NULL)
504 return GNUNET_SYSERR;
506 if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
508 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
509 "mysql_stmt_prepare `%s', %s", ret->query, mysql_error(conn));
510 mysql_stmt_close (ret->statement);
511 ret->statement = NULL;
512 return GNUNET_SYSERR;
514 ret->valid = GNUNET_YES;
519 * Bind the parameters for the given MySQL statement
522 * @param s statement to bind and run
523 * @param ap arguments for the binding
524 * @return GNUNET_SYSERR on error, GNUNET_OK on success
527 init_params (struct StatementHandle *s, va_list ap)
529 MYSQL_BIND qbind[MAX_PARAM];
532 enum enum_field_types ft;
534 pc = mysql_stmt_param_count (s->statement);
537 /* increase internal constant! */
539 return GNUNET_SYSERR;
541 memset (qbind, 0, sizeof (qbind));
544 while ((pc > 0) && (-1 != (ft = va_arg (ap, enum enum_field_types))))
546 qbind[off].buffer_type = ft;
549 case MYSQL_TYPE_FLOAT:
550 qbind[off].buffer = va_arg (ap, float *);
552 case MYSQL_TYPE_LONGLONG:
553 qbind[off].buffer = va_arg (ap, unsigned long long *);
554 qbind[off].is_unsigned = va_arg (ap, int);
556 case MYSQL_TYPE_LONG:
557 qbind[off].buffer = va_arg (ap, unsigned int *);
558 qbind[off].is_unsigned = va_arg (ap, int);
560 case MYSQL_TYPE_VAR_STRING:
561 case MYSQL_TYPE_STRING:
562 case MYSQL_TYPE_BLOB:
563 qbind[off].buffer = va_arg (ap, void *);
564 qbind[off].buffer_length = va_arg (ap, unsigned long);
565 qbind[off].length = va_arg (ap, unsigned long *);
568 /* unsupported type */
570 return GNUNET_SYSERR;
575 if (!((pc == 0) && (ft != -1) && (va_arg (ap, int) == -1)))
578 return GNUNET_SYSERR;
580 if (mysql_stmt_bind_param (s->statement, qbind))
582 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
583 _("`%s' failed at %s:%d with error: %s\n"),
584 "mysql_stmt_bind_param",
585 __FILE__, __LINE__, mysql_stmt_error (s->statement));
586 return GNUNET_SYSERR;
589 if (mysql_stmt_execute (s->statement))
591 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
592 _("`%s' failed at %s:%d with error: %s\n"),
593 "mysql_stmt_execute",
594 __FILE__, __LINE__, mysql_stmt_error (s->statement));
595 return GNUNET_SYSERR;
602 * Run a prepared SELECT statement.
604 * @param s handle to the statement we should execute
605 * @param result_size number of results in set
606 * @param results pointer to already initialized MYSQL_BIND
607 * array (of sufficient size) for passing results
608 * @param processor function to call on each result
609 * @param processor_cls extra argument to processor
610 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
611 * values (size + buffer-reference for pointers); terminated
614 * @return GNUNET_SYSERR on error, otherwise
615 * the number of successfully affected (or queried) rows
618 prepared_statement_run_select (struct StatementHandle *s,
619 unsigned int result_size,
620 MYSQL_BIND * results,
621 GNUNET_MysqlDataProcessor
622 processor, void *processor_cls,
630 if (GNUNET_OK != prepare_statement (s))
633 return GNUNET_SYSERR;
635 va_start (ap, processor_cls);
636 if (GNUNET_OK != init_params (s, ap))
640 return GNUNET_SYSERR;
643 rsize = mysql_stmt_field_count (s->statement);
644 if (rsize > result_size)
647 return GNUNET_SYSERR;
649 if (mysql_stmt_bind_result (s->statement, results))
651 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
652 _("`%s' failed at %s:%d with error: %s\n"),
653 "mysql_stmt_bind_result",
654 __FILE__, __LINE__, mysql_stmt_error (s->statement));
655 return GNUNET_SYSERR;
661 ret = mysql_stmt_fetch (s->statement);
662 if (ret == MYSQL_NO_DATA)
666 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
667 _("`%s' failed at %s:%d with error: %s\n"),
669 __FILE__, __LINE__, mysql_stmt_error (s->statement));
670 return GNUNET_SYSERR;
672 if (processor != NULL)
673 if (GNUNET_OK != processor (processor_cls, rsize, results))
677 mysql_stmt_reset (s->statement);
683 get_node_uid (unsigned long long *nodeuid, const GNUNET_HashCode * peerHash)
686 struct GNUNET_CRYPTO_HashAsciiEncoded encPeer;
687 unsigned long long p_len;
690 memset (rbind, 0, sizeof (rbind));
691 rbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
692 rbind[0].buffer = nodeuid;
693 rbind[0].is_unsigned = GNUNET_YES;
695 GNUNET_CRYPTO_hash_to_enc (peerHash, &encPeer);
696 p_len = strlen ((char *) &encPeer);
698 if (1 != (ret = prepared_statement_run_select (get_nodeuid,
706 MYSQL_TYPE_VAR_STRING,
712 fprintf (stderr, "FAILED\n");
714 return GNUNET_SYSERR;
720 get_current_trial (unsigned long long *trialuid)
724 memset (rbind, 0, sizeof (rbind));
725 rbind[0].buffer_type = MYSQL_TYPE_LONG;
726 rbind[0].is_unsigned = 1;
727 rbind[0].buffer = trialuid;
730 prepared_statement_run_select (get_trial,
733 return_ok, NULL, -1)))
735 return GNUNET_SYSERR;
742 get_current_topology (unsigned long long *topologyuid)
746 memset (rbind, 0, sizeof (rbind));
747 rbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
748 rbind[0].is_unsigned = 1;
749 rbind[0].buffer = topologyuid;
752 prepared_statement_run_select (get_topology,
755 return_ok, NULL, -1)))
757 return GNUNET_SYSERR;
764 get_dhtkey_uid (unsigned long long *dhtkeyuid, const GNUNET_HashCode * key)
767 struct GNUNET_CRYPTO_HashAsciiEncoded encKey;
768 unsigned long long k_len;
769 memset (rbind, 0, sizeof (rbind));
770 rbind[0].buffer_type = MYSQL_TYPE_LONG;
771 rbind[0].is_unsigned = 1;
772 rbind[0].buffer = dhtkeyuid;
773 GNUNET_CRYPTO_hash_to_enc (key, &encKey);
774 k_len = strlen ((char *) &encKey);
776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Searching for dhtkey `%s' in trial %llu\n", GNUNET_h2s(key), current_trial);
779 prepared_statement_run_select (get_dhtkeyuid,
783 MYSQL_TYPE_VAR_STRING,
791 return GNUNET_SYSERR;
798 * Run a prepared statement that does NOT produce results.
800 * @param s handle to the statement we should execute
801 * @param insert_id NULL or address where to store the row ID of whatever
802 * was inserted (only for INSERT statements!)
803 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
804 * values (size + buffer-reference for pointers); terminated
807 * @return GNUNET_SYSERR on error, otherwise
808 * the number of successfully affected rows
811 prepared_statement_run (struct StatementHandle *s,
812 unsigned long long *insert_id, ...)
817 if (GNUNET_OK != prepare_statement(s))
820 return GNUNET_SYSERR;
822 GNUNET_assert(s->valid == GNUNET_YES);
823 if (s->statement == NULL)
824 return GNUNET_SYSERR;
826 va_start (ap, insert_id);
828 if (GNUNET_OK != init_params (s, ap))
831 return GNUNET_SYSERR;
835 affected = mysql_stmt_affected_rows (s->statement);
836 if (NULL != insert_id)
837 *insert_id = (unsigned long long) mysql_stmt_insert_id (s->statement);
838 mysql_stmt_reset (s->statement);
844 * Inserts the specified trial into the dhttests.trials table
846 * @param trial_info struct containing the data to insert about this trial
848 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
850 int add_trial (struct GNUNET_DHTLOG_TrialInfo *trial_info)
854 unsigned long long m_len;
855 m_len = strlen (trial_info->message);
857 stmt = mysql_stmt_init(conn);
859 (ret = prepared_statement_run (insert_trial, ¤t_trial,
860 MYSQL_TYPE_LONG, &trial_info->other_identifier, GNUNET_YES,
861 MYSQL_TYPE_LONG, &trial_info->num_nodes, GNUNET_YES,
862 MYSQL_TYPE_LONG, &trial_info->topology, GNUNET_YES,
863 MYSQL_TYPE_FLOAT, &trial_info->topology_percentage,
864 MYSQL_TYPE_FLOAT, &trial_info->topology_probability,
865 MYSQL_TYPE_LONG, &trial_info->blacklist_topology, GNUNET_YES,
866 MYSQL_TYPE_LONG, &trial_info->connect_topology, GNUNET_YES,
867 MYSQL_TYPE_LONG, &trial_info->connect_topology_option, GNUNET_YES,
868 MYSQL_TYPE_FLOAT, &trial_info->connect_topology_option_modifier,
869 MYSQL_TYPE_LONG, &trial_info->puts, GNUNET_YES,
870 MYSQL_TYPE_LONG, &trial_info->gets, GNUNET_YES,
871 MYSQL_TYPE_LONG, &trial_info->concurrent, GNUNET_YES,
872 MYSQL_TYPE_LONG, &trial_info->settle_time, GNUNET_YES,
873 MYSQL_TYPE_LONG, &trial_info->num_rounds, GNUNET_YES,
874 MYSQL_TYPE_LONG, &trial_info->malicious_getters, GNUNET_YES,
875 MYSQL_TYPE_LONG, &trial_info->malicious_putters, GNUNET_YES,
876 MYSQL_TYPE_LONG, &trial_info->malicious_droppers, GNUNET_YES,
877 MYSQL_TYPE_LONG, &trial_info->malicious_get_frequency, GNUNET_YES,
878 MYSQL_TYPE_LONG, &trial_info->malicious_put_frequency, GNUNET_YES,
879 MYSQL_TYPE_LONG, &trial_info->stop_closest, GNUNET_YES,
880 MYSQL_TYPE_LONG, &trial_info->stop_found, GNUNET_YES,
881 MYSQL_TYPE_LONG, &trial_info->strict_kademlia, GNUNET_YES,
882 MYSQL_TYPE_LONG, &trial_info->gets_succeeded, GNUNET_YES,
883 MYSQL_TYPE_BLOB, trial_info->message, max_varchar_len +
884 max_varchar_len, &m_len,
887 if (ret == GNUNET_SYSERR)
889 mysql_stmt_close(stmt);
890 return GNUNET_SYSERR;
894 get_current_trial (¤t_trial);
896 mysql_stmt_close(stmt);
901 * Inserts the specified round into the dhttests.rounds table
903 * @param round_type the type of round that is being started
904 * @param round_count counter for the round (if applicable)
906 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
908 int add_round (unsigned int round_type, unsigned int round_count)
914 stmt = mysql_stmt_init(conn);
915 ret = prepared_statement_run (insert_round,
917 MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES,
918 MYSQL_TYPE_LONG, &round_type, GNUNET_YES,
919 MYSQL_TYPE_LONG, &round_count, GNUNET_YES, -1);
920 mysql_stmt_close(stmt);
921 if (ret != GNUNET_OK)
922 return GNUNET_SYSERR;
927 * Inserts the specified round results into the
928 * dhttests.processed_round_details table
930 * @param round_type the type of round that is being started
931 * @param round_count counter for the round (if applicable)
932 * @param num_messages the total number of messages initiated
933 * @param num_messages_succeeded the number of messages that succeeded
935 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
937 int add_round_details (unsigned int round_type, unsigned int round_count,
938 unsigned int num_messages, unsigned int num_messages_succeeded)
943 stmt = mysql_stmt_init(conn);
944 ret = prepared_statement_run (insert_round_details,
946 MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES,
947 MYSQL_TYPE_LONG, &round_type, GNUNET_YES,
948 MYSQL_TYPE_LONG, &round_count, GNUNET_YES,
949 MYSQL_TYPE_LONG, &num_messages, GNUNET_YES,
950 MYSQL_TYPE_LONG, &num_messages_succeeded, GNUNET_YES,
952 mysql_stmt_close(stmt);
953 if (ret != GNUNET_OK)
954 return GNUNET_SYSERR;
959 * Inserts the specified stats into the dhttests.node_statistics table
961 * @param peer the peer inserting the statistic
962 * @param route_requests route requests seen
963 * @param route_forwards route requests forwarded
964 * @param result_requests route result requests seen
965 * @param client_requests client requests initiated
966 * @param result_forwards route results forwarded
967 * @param gets get requests handled
968 * @param puts put requests handle
969 * @param data_inserts data inserted at this node
970 * @param find_peer_requests find peer requests seen
971 * @param find_peers_started find peer requests initiated at this node
972 * @param gets_started get requests initiated at this node
973 * @param puts_started put requests initiated at this node
974 * @param find_peer_responses_received find peer responses received locally
975 * @param get_responses_received get responses received locally
976 * @param find_peer_responses_sent find peer responses sent from this node
977 * @param get_responses_sent get responses sent from this node
979 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
982 add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
983 unsigned int route_forwards, unsigned int result_requests,
984 unsigned int client_requests, unsigned int result_forwards,
985 unsigned int gets, unsigned int puts,
986 unsigned int data_inserts, unsigned int find_peer_requests,
987 unsigned int find_peers_started, unsigned int gets_started,
988 unsigned int puts_started, unsigned int find_peer_responses_received,
989 unsigned int get_responses_received, unsigned int find_peer_responses_sent,
990 unsigned int get_responses_sent)
994 unsigned long long peer_uid;
995 unsigned long long return_uid;
997 return GNUNET_SYSERR;
999 if (GNUNET_OK != get_node_uid (&peer_uid, &peer->hashPubKey))
1001 return GNUNET_SYSERR;
1004 stmt = mysql_stmt_init(conn);
1006 (ret = prepared_statement_run (insert_stat,
1008 MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES,
1009 MYSQL_TYPE_LONGLONG, &peer_uid, GNUNET_YES,
1010 MYSQL_TYPE_LONG, &route_requests, GNUNET_YES,
1011 MYSQL_TYPE_LONG, &route_forwards, GNUNET_YES,
1012 MYSQL_TYPE_LONG, &result_requests, GNUNET_YES,
1013 MYSQL_TYPE_LONG, &client_requests, GNUNET_YES,
1014 MYSQL_TYPE_LONG, &result_forwards, GNUNET_YES,
1015 MYSQL_TYPE_LONG, &gets, GNUNET_YES,
1016 MYSQL_TYPE_LONG, &puts, GNUNET_YES,
1017 MYSQL_TYPE_LONG, &data_inserts, GNUNET_YES,
1018 MYSQL_TYPE_LONG, &find_peer_requests, GNUNET_YES,
1019 MYSQL_TYPE_LONG, &find_peers_started, GNUNET_YES,
1020 MYSQL_TYPE_LONG, &gets_started, GNUNET_YES,
1021 MYSQL_TYPE_LONG, &puts_started, GNUNET_YES,
1022 MYSQL_TYPE_LONG, &find_peer_responses_received, GNUNET_YES,
1023 MYSQL_TYPE_LONG, &get_responses_received, GNUNET_YES,
1024 MYSQL_TYPE_LONG, &find_peer_responses_sent, GNUNET_YES,
1025 MYSQL_TYPE_LONG, &get_responses_sent, GNUNET_YES,
1028 if (ret == GNUNET_SYSERR)
1030 mysql_stmt_close(stmt);
1031 return GNUNET_SYSERR;
1035 mysql_stmt_close(stmt);
1040 * Inserts the specified stats into the dhttests.generic_stats table
1042 * @param peer the peer inserting the statistic
1043 * @param name the name of the statistic
1044 * @param section the section of the statistic
1045 * @param value the value of the statistic
1047 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1050 add_generic_stat (const struct GNUNET_PeerIdentity *peer,
1052 const char *section, uint64_t value)
1054 unsigned long long peer_uid;
1055 unsigned long long section_len;
1056 unsigned long long name_len;
1059 return GNUNET_SYSERR;
1061 if (GNUNET_OK != get_node_uid (&peer_uid, &peer->hashPubKey))
1063 return GNUNET_SYSERR;
1066 section_len = strlen(section);
1067 name_len = strlen(name);
1070 (ret = prepared_statement_run (insert_generic_stat,
1072 MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES,
1073 MYSQL_TYPE_LONGLONG, &peer_uid, GNUNET_YES,
1074 MYSQL_TYPE_VAR_STRING, §ion, max_varchar_len, §ion_len,
1075 MYSQL_TYPE_VAR_STRING, &name, max_varchar_len, &name_len,
1076 MYSQL_TYPE_LONGLONG, &value, GNUNET_YES,
1079 if (ret == GNUNET_SYSERR)
1081 return GNUNET_SYSERR;
1088 * Inserts the specified dhtkey into the dhttests.dhtkeys table,
1089 * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
1091 * @param dhtkeyuid return value
1092 * @param dhtkey hashcode of key to insert
1094 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1097 add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
1101 struct GNUNET_CRYPTO_HashAsciiEncoded encKey;
1102 unsigned long long k_len;
1103 unsigned long long h_len;
1104 unsigned long long curr_dhtkeyuid;
1105 GNUNET_CRYPTO_hash_to_enc (dhtkey, &encKey);
1106 k_len = strlen ((char *) &encKey);
1107 h_len = sizeof (GNUNET_HashCode);
1109 ret = get_dhtkey_uid(&curr_dhtkeyuid, dhtkey);
1110 if (curr_dhtkeyuid != 0) /* dhtkey already exists */
1112 if (dhtkeyuid != NULL)
1113 *dhtkeyuid = curr_dhtkeyuid;
1116 else if (ret == GNUNET_SYSERR)
1119 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Failed to get dhtkeyuid!\n");
1124 (ret = prepared_statement_run (insert_dhtkey,
1126 MYSQL_TYPE_VAR_STRING,
1135 sizeof (GNUNET_HashCode),
1138 if (ret == GNUNET_SYSERR)
1140 return GNUNET_SYSERR;
1150 * Inserts the specified node into the dhttests.nodes table
1152 * @param nodeuid the inserted node uid
1153 * @param node the node to insert
1155 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1158 add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
1160 struct GNUNET_CRYPTO_HashAsciiEncoded encPeer;
1161 unsigned long p_len;
1162 unsigned long h_len;
1166 return GNUNET_SYSERR;
1168 GNUNET_CRYPTO_hash_to_enc (&node->hashPubKey, &encPeer);
1169 p_len = (unsigned long) strlen ((char *) &encPeer);
1170 h_len = sizeof (GNUNET_HashCode);
1172 (ret = prepared_statement_run (insert_node,
1174 MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES,
1175 MYSQL_TYPE_VAR_STRING, &encPeer, max_varchar_len, &p_len,
1176 MYSQL_TYPE_BLOB, &node->hashPubKey, sizeof (GNUNET_HashCode),
1179 if (ret == GNUNET_SYSERR)
1181 return GNUNET_SYSERR;
1188 * Update dhttests.trials table with current server time as end time
1190 * @param gets_succeeded how many gets did the testcase report as successful
1192 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
1195 update_trials (unsigned int gets_succeeded)
1200 (ret = prepared_statement_run (update_trial,
1202 MYSQL_TYPE_LONG, &gets_succeeded, GNUNET_YES,
1203 MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES,
1206 if (ret == GNUNET_SYSERR)
1208 return GNUNET_SYSERR;
1214 return GNUNET_SYSERR;
1219 * Update dhttests.nodes table setting the identified
1220 * node as a malicious dropper.
1222 * @param peer the peer that was set to be malicious
1224 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
1226 int set_malicious (struct GNUNET_PeerIdentity *peer)
1228 unsigned long long p_len;
1232 temp_str = GNUNET_strdup(GNUNET_h2s_full(&peer->hashPubKey));
1233 p_len = strlen(temp_str);
1236 (ret = prepared_statement_run (update_node_malicious,
1238 MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES,
1239 MYSQL_TYPE_VAR_STRING, temp_str, max_varchar_len, &p_len,
1242 if (ret == GNUNET_SYSERR)
1244 return GNUNET_SYSERR;
1252 * Update dhttests.trials table with total connections information
1254 * @param totalConnections the number of connections
1256 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
1259 add_connections (unsigned int totalConnections)
1264 (ret = prepared_statement_run (update_connection,
1269 MYSQL_TYPE_LONGLONG,
1270 ¤t_trial, GNUNET_YES, -1)))
1272 if (ret == GNUNET_SYSERR)
1274 return GNUNET_SYSERR;
1280 return GNUNET_SYSERR;
1284 * Inserts the specified query into the dhttests.queries table
1286 * @param sqlqueruid inserted query uid
1287 * @param queryid dht query id
1288 * @param type type of the query
1289 * @param hops number of hops query traveled
1290 * @param succeeded whether or not query was successful
1291 * @param node the node the query hit
1292 * @param key the key of the query
1294 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
1297 add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
1298 unsigned int type, unsigned int hops, int succeeded,
1299 const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode * key)
1302 unsigned long long peer_uid, key_uid;
1307 && (GNUNET_OK == get_node_uid (&peer_uid, &node->hashPubKey)))
1313 return GNUNET_SYSERR;
1316 if ((key != NULL) && (GNUNET_OK == get_dhtkey_uid (&key_uid, key)))
1320 else if ((key != NULL) && (key->bits[(512 / 8 / sizeof (unsigned int)) - 1] == 42)) /* Malicious marker */
1326 return GNUNET_SYSERR;
1330 (ret = prepared_statement_run (insert_query,
1332 MYSQL_TYPE_LONGLONG,
1341 MYSQL_TYPE_LONGLONG,
1344 MYSQL_TYPE_LONGLONG,
1350 MYSQL_TYPE_LONGLONG,
1351 &peer_uid, GNUNET_YES, -1)))
1353 if (ret == GNUNET_SYSERR)
1355 return GNUNET_SYSERR;
1361 return GNUNET_SYSERR;
1365 * Inserts the specified route information into the dhttests.routes table
1367 * @param sqlqueruid inserted query uid
1368 * @param queryid dht query id
1369 * @param type type of the query
1370 * @param hops number of hops query traveled
1371 * @param succeeded whether or not query was successful
1372 * @param node the node the query hit
1373 * @param key the key of the query
1374 * @param from_node the node that sent the message to node
1375 * @param to_node next node to forward message to
1377 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
1380 add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
1381 unsigned int type, unsigned int hops,
1382 int succeeded, const struct GNUNET_PeerIdentity * node,
1383 const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity * from_node,
1384 const struct GNUNET_PeerIdentity * to_node)
1386 unsigned long long peer_uid = 0;
1387 unsigned long long key_uid = 0;
1388 unsigned long long from_uid = 0;
1389 unsigned long long to_uid = 0;
1392 if (from_node != NULL)
1393 get_node_uid (&from_uid, &from_node->hashPubKey);
1395 if (to_node != NULL)
1396 get_node_uid (&to_uid, &to_node->hashPubKey);
1402 if (1 != get_node_uid (&peer_uid, &node->hashPubKey))
1404 return GNUNET_SYSERR;
1408 return GNUNET_SYSERR;
1412 if (1 != get_dhtkey_uid (&key_uid, key))
1414 return GNUNET_SYSERR;
1418 return GNUNET_SYSERR;
1421 (ret = prepared_statement_run (insert_route,
1423 MYSQL_TYPE_LONGLONG,
1432 MYSQL_TYPE_LONGLONG,
1435 MYSQL_TYPE_LONGLONG,
1441 MYSQL_TYPE_LONGLONG,
1444 MYSQL_TYPE_LONGLONG,
1447 MYSQL_TYPE_LONGLONG,
1448 &to_uid, GNUNET_YES, -1)))
1450 if (ret == GNUNET_SYSERR)
1452 return GNUNET_SYSERR;
1458 return GNUNET_SYSERR;
1462 * Update dhttests.topology table with total connections information
1464 * @param totalConnections the number of connections
1466 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
1469 update_current_topology (unsigned int connections)
1472 unsigned long long topologyuid;
1474 get_current_topology(&topologyuid);
1477 (ret = prepared_statement_run (update_topology,
1482 MYSQL_TYPE_LONGLONG,
1483 &topologyuid, GNUNET_YES, -1)))
1485 if (ret == GNUNET_SYSERR)
1487 return GNUNET_SYSERR;
1492 return GNUNET_SYSERR;
1497 * Records the current topology (number of connections, time, trial)
1499 * @param num_connections how many connections are in the topology
1501 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1504 add_topology (int num_connections)
1509 (ret = prepared_statement_run (insert_topology,
1511 MYSQL_TYPE_LONGLONG, ¤t_trial, GNUNET_YES,
1512 MYSQL_TYPE_LONG, &num_connections, GNUNET_YES,
1515 if (ret == GNUNET_SYSERR)
1517 return GNUNET_SYSERR;
1522 return GNUNET_SYSERR;
1526 * Records a connection between two peers in the current topology
1528 * @param first one side of the connection
1529 * @param second other side of the connection
1531 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1534 add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second)
1537 unsigned long long first_uid;
1538 unsigned long long second_uid;
1539 unsigned long long topologyuid;
1541 if (GNUNET_OK != get_current_topology(&topologyuid))
1542 return GNUNET_SYSERR;
1543 if (GNUNET_OK != get_node_uid(&first_uid, &first->hashPubKey))
1544 return GNUNET_SYSERR;
1545 if (GNUNET_OK != get_node_uid(&second_uid, &second->hashPubKey))
1546 return GNUNET_SYSERR;
1549 (ret = prepared_statement_run (extend_topology,
1551 MYSQL_TYPE_LONGLONG,
1554 MYSQL_TYPE_LONGLONG,
1557 MYSQL_TYPE_LONGLONG,
1561 if (ret == GNUNET_SYSERR)
1563 return GNUNET_SYSERR;
1568 return GNUNET_SYSERR;
1573 * Provides the dhtlog api
1575 * @param c the configuration to use to connect to a server
1577 * @return the handle to the server, or NULL on error
1580 libgnunet_plugin_dhtlog_mysql_init (void * cls)
1582 struct GNUNET_DHTLOG_Plugin *plugin = cls;
1585 max_varchar_len = 255;
1587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL DHT Logger: initializing database\n");
1590 if (iopen (plugin) != GNUNET_OK)
1592 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1593 _("Failed to initialize MySQL database connection for dhtlog.\n"));
1597 GNUNET_assert(plugin->dhtlog_api == NULL);
1598 plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle));
1599 plugin->dhtlog_api->insert_trial = &add_trial;
1600 plugin->dhtlog_api->insert_stat = &add_stat;
1601 plugin->dhtlog_api->insert_round = &add_round;
1602 plugin->dhtlog_api->insert_round_details = &add_round_details;
1603 plugin->dhtlog_api->add_generic_stat = &add_generic_stat;
1604 plugin->dhtlog_api->insert_query = &add_query;
1605 plugin->dhtlog_api->update_trial = &update_trials;
1606 plugin->dhtlog_api->insert_route = &add_route;
1607 plugin->dhtlog_api->insert_node = &add_node;
1608 plugin->dhtlog_api->insert_dhtkey = &add_dhtkey;
1609 plugin->dhtlog_api->update_connections = &add_connections;
1610 plugin->dhtlog_api->insert_topology = &add_topology;
1611 plugin->dhtlog_api->update_topology = &update_current_topology;
1612 plugin->dhtlog_api->insert_extended_topology = &add_extended_topology;
1613 plugin->dhtlog_api->set_malicious = &set_malicious;
1614 plugin->dhtlog_api->add_generic_stat = &add_generic_stat;
1615 get_current_trial (¤t_trial);
1621 * Shutdown the plugin.
1624 libgnunet_plugin_dhtlog_mysql_done (void * cls)
1626 struct GNUNET_DHTLOG_Handle *dhtlog_api = cls;
1628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1629 "MySQL DHT Logger: database shutdown\n");
1630 GNUNET_assert(dhtlog_api != NULL);
1631 prepared_statement_close(insert_query);
1632 prepared_statement_close(insert_route);
1633 prepared_statement_close(insert_trial);
1634 prepared_statement_close(insert_round);
1635 prepared_statement_close(insert_round_details);
1636 prepared_statement_close(insert_node);
1637 prepared_statement_close(insert_dhtkey);
1638 prepared_statement_close(update_trial);
1639 prepared_statement_close(get_dhtkeyuid);
1640 prepared_statement_close(get_nodeuid);
1641 prepared_statement_close(update_connection);
1642 prepared_statement_close(get_trial);
1643 prepared_statement_close(get_topology);
1644 prepared_statement_close(insert_topology);
1645 prepared_statement_close(update_topology);
1646 prepared_statement_close(extend_topology);
1647 prepared_statement_close(update_node_malicious);
1652 mysql_library_end();
1653 GNUNET_free(dhtlog_api);
1657 /* end of plugin_dhtlog_mysql.c */