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_dump.c
23 * @brief MySQL logging plugin to record DHT operations to MySQL server,
24 * but write all queries to file instead of the actual server
25 * so that they can be imported later. The idea is that connecting
26 * to the MySQL server X times can be really problematic, but hopefully
27 * writing to a single file is more reliable.
28 * @author Nathan Evans
34 #include "gnunet_util_lib.h"
38 #define DEBUG_DHTLOG GNUNET_NO
41 * Maximum number of supported parameters for a prepared
42 * statement. Increase if needed.
47 static unsigned long max_varchar_len;
50 * The configuration the DHT service is running with
52 static const struct GNUNET_CONFIGURATION_Handle *cfg;
54 #define INSERT_QUERIES_STMT "prepare insert_query from 'INSERT INTO queries (trialuid, querytype, hops, dhtkeyuid, dhtqueryid, succeeded, nodeuid) "\
55 "VALUES (@temp_trial, ?, ?, ?, ?, ?, ?)'"
57 #define INSERT_ROUTES_STMT "prepare insert_route from 'INSERT INTO routes (trialuid, querytype, hops, dhtkeyuid, dhtqueryid, succeeded, nodeuid, from_node, to_node) "\
58 "VALUES (@temp_trial, ?, ?, ?, ?, ?, ?, ?, ?)'"
60 #define INSERT_NODES_STMT "prepare insert_node from 'INSERT ignore INTO nodes (trialuid, nodeid) "\
61 "VALUES (@temp_trial, ?)'"
63 #define INSERT_TOPOLOGY_STMT "prepare insert_topology from 'INSERT INTO topology (trialuid, date, connections) "\
64 "VALUES (@temp_trial, ?, ?)'"
66 #define EXTEND_TOPOLOGY_STMT "prepare extend_topology from 'INSERT INTO extended_topology (topology_uid, uid_first, uid_second) "\
67 "VALUES (@temp_topology, ?, ?)'"
69 #define UPDATE_TOPOLOGY_STMT "prepare update_topology from 'update topology set connections = ? where topology_uid = @temp_topology'"
71 #define SET_MALICIOUS_STMT "prepare set_malicious from 'update nodes set malicious_dropper = 1 where trialuid = @temp_trial and nodeid = @temp_node'"
73 #define INSERT_TRIALS_STMT "prepare insert_trial from 'INSERT INTO trials"\
74 "(starttime, numnodes, topology,"\
75 "topology_percentage, topology_probability,"\
76 "blacklist_topology, connect_topology, connect_topology_option,"\
77 "connect_topology_option_modifier, puts, gets, "\
78 "concurrent, settle_time, num_rounds, malicious_getters,"\
79 "malicious_putters, malicious_droppers, malicious_get_frequency,"\
80 "malicious_put_frequency, stop_closest, stop_found, strict_kademlia, "\
81 "gets_succeeded, message) "\
82 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'"
84 #define INSERT_GENERIC_STAT_STMT "prepare insert_generic_stat from 'INSERT INTO generic_stats" \
85 "(trialuid, nodeuid, section, name, value)"\
86 "VALUES (@temp_trial, @temp_node, @temp_section, @temp_stat, @temp_value)'"
88 #define INSERT_STAT_STMT "prepare insert_stat from 'INSERT INTO node_statistics"\
89 "(trialuid, nodeuid, route_requests,"\
90 "route_forwards, result_requests,"\
91 "client_results, result_forwards, gets,"\
92 "puts, data_inserts, find_peer_requests, "\
93 "find_peers_started, gets_started, puts_started, find_peer_responses_received,"\
94 "get_responses_received, find_peer_responses_sent, get_responses_sent) "\
95 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'"
97 #define INSERT_DHTKEY_STMT "prepare insert_dhtkey from 'INSERT ignore INTO dhtkeys (dhtkey, trialuid) "\
98 "VALUES (?, @temp_trial)'"
100 #define UPDATE_TRIALS_STMT "prepare update_trial from 'UPDATE trials set endtime= ?, gets_succeeded = ? where trialuid = @temp_trial'"
102 #define UPDATE_CONNECTIONS_STMT "prepare update_conn from 'UPDATE trials set totalConnections = ? where trialuid = @temp_trial'"
104 #define GET_TRIAL_STMT "prepare select_trial from 'SELECT MAX( trialuid ) FROM trials into @temp_trial'"
106 #define GET_TOPOLOGY_STMT "prepare select_topology from 'SELECT MAX( topology_uid ) FROM topology into @temp_topology'"
108 #define GET_DHTKEYUID_STMT "prepare get_dhtkeyuid from 'SELECT dhtkeyuid FROM dhtkeys where dhtkey = ? and trialuid = @temp_trial'"
110 #define GET_NODEUID_STMT "prepare get_nodeuid from 'SELECT nodeuid FROM nodes where trialuid = @temp_trial and nodeid = ?'"
112 #define DATE_STR_SIZE 50
115 * File to dump all sql statements to.
123 static char date[DATE_STR_SIZE];
128 memset (date, 0, DATE_STR_SIZE);
129 tmptr = localtime (&timetmp);
131 strftime (date, DATE_STR_SIZE, "%Y-%m-%d %H:%M:%S", tmptr);
139 * Create a prepared statement.
141 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
144 prepared_statement_create (const char *statement)
146 if (fprintf(outfile, "%s;\n", statement) > 0)
149 return GNUNET_SYSERR;
153 * Initialize the prepared statements for use with dht test logging
158 #define PINIT(a) (GNUNET_OK != (prepared_statement_create(a)))
159 if (PINIT (INSERT_QUERIES_STMT) ||
160 PINIT (INSERT_ROUTES_STMT) ||
161 PINIT (INSERT_TRIALS_STMT) ||
162 PINIT (SET_MALICIOUS_STMT) ||
163 PINIT (INSERT_GENERIC_STAT_STMT) ||
164 PINIT (INSERT_STAT_STMT) ||
165 PINIT (INSERT_NODES_STMT) ||
166 PINIT (INSERT_DHTKEY_STMT) ||
167 PINIT (UPDATE_TRIALS_STMT) ||
168 PINIT (GET_DHTKEYUID_STMT) ||
169 PINIT (GET_NODEUID_STMT) ||
170 PINIT (UPDATE_CONNECTIONS_STMT) ||
171 PINIT (INSERT_TOPOLOGY_STMT) ||
172 PINIT (EXTEND_TOPOLOGY_STMT) ||
173 PINIT (UPDATE_TOPOLOGY_STMT) ||
174 PINIT (GET_TRIAL_STMT) ||
175 PINIT (GET_TOPOLOGY_STMT))
177 return GNUNET_SYSERR;
187 * Records the current topology (number of connections, time, trial)
189 * @param num_connections how many connections are in the topology
191 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
194 add_topology (int num_connections)
198 return GNUNET_SYSERR;
200 ret = fprintf(outfile, "set @date = \"%s\", @num = %d;\n", get_sql_time(), num_connections);
203 return GNUNET_SYSERR;
204 ret = fprintf(outfile, "execute insert_topology using "
207 return GNUNET_SYSERR;
209 ret = fprintf(outfile, "execute select_topology;\n");
213 return GNUNET_SYSERR;
217 * Records a connection between two peers in the current topology
219 * @param first one side of the connection
220 * @param second other side of the connection
222 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
225 add_extended_topology (const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second)
229 return GNUNET_SYSERR;
232 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_first_node;\n", GNUNET_h2s_full(&first->hashPubKey));
234 ret = fprintf(outfile, "set @temp_first_node = 0;\n");
237 return GNUNET_SYSERR;
240 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_second_node;\n", GNUNET_h2s_full(&second->hashPubKey));
242 ret = fprintf(outfile, "set @temp_second_node = 0;\n");
245 return GNUNET_SYSERR;
247 ret = fprintf(outfile, "execute extend_topology using "
248 "@temp_first_node, @temp_second_node;\n");
252 return GNUNET_SYSERR;
257 * Inserts the specified trial into the dhttests.trials table
259 * @param trialuid return the trialuid of the newly inserted trial
260 * @param num_nodes how many nodes are in the trial
261 * @param topology integer representing topology for this trial
262 * @param blacklist_topology integer representing blacklist topology for this trial
263 * @param connect_topology integer representing connect topology for this trial
264 * @param connect_topology_option integer representing connect topology option
265 * @param connect_topology_option_modifier float to modify connect option
266 * @param topology_percentage percentage modifier for certain topologies
267 * @param topology_probability probability modifier for certain topologies
268 * @param puts number of puts to perform
269 * @param gets number of gets to perform
270 * @param concurrent number of concurrent requests
271 * @param settle_time time to wait between creating topology and starting testing
272 * @param num_rounds number of times to repeat the trial
273 * @param malicious_getters number of malicious GET peers in the trial
274 * @param malicious_putters number of malicious PUT peers in the trial
275 * @param malicious_droppers number of malicious DROP peers in the trial
276 * @param malicious_get_frequency how often malicious gets are sent
277 * @param malicious_put_frequency how often malicious puts are sent
278 * @param stop_closest stop forwarding PUTs if closest node found
279 * @param stop_found stop forwarding GETs if data found
280 * @param strict_kademlia test used kademlia routing algorithm
281 * @param gets_succeeded how many gets did the test driver report success on
282 * @param message string to put into DB for this trial
284 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
286 int add_trial (unsigned long long *trialuid, unsigned int num_nodes, unsigned int topology,
287 unsigned int blacklist_topology, unsigned int connect_topology,
288 unsigned int connect_topology_option, float connect_topology_option_modifier,
289 float topology_percentage, float topology_probability,
290 unsigned int puts, unsigned int gets, unsigned int concurrent, unsigned int settle_time,
291 unsigned int num_rounds, unsigned int malicious_getters, unsigned int malicious_putters,
292 unsigned int malicious_droppers, unsigned int malicious_get_frequency,
293 unsigned int malicious_put_frequency, unsigned int stop_closest, unsigned int stop_found,
294 unsigned int strict_kademlia, unsigned int gets_succeeded,
298 if (trialuid != NULL)
301 return GNUNET_SYSERR;
303 ret = fprintf(outfile, "set @date = \"%s\", @num = %u, @topology = %u, @bl = %u, "
304 "@connect = %u, @c_t_o = %u, @c_t_o_m = %f, @t_p = %f, "
305 "@t_pr = %f, @puts = %u, @gets = %u, "
306 "@concurrent = %u, @settle = %u, @rounds = %u, "
307 "@m_gets = %u, @m_puts = %u, @m_drops = %u, "
308 "@m_g_f = %u, @m_p_f = %u, @s_c = %u, @s_f = %u,"
309 "@s_k = %u, @g_s = %u, @message = \"%s\";\n",
310 get_sql_time(), num_nodes, topology,
311 blacklist_topology, connect_topology,
312 connect_topology_option, connect_topology_option_modifier,
313 topology_percentage, topology_probability,
314 puts, gets, concurrent, settle_time,
315 num_rounds, malicious_getters, malicious_putters,
316 malicious_droppers, malicious_get_frequency, malicious_put_frequency,
317 stop_closest, stop_found, strict_kademlia, gets_succeeded, message);
320 return GNUNET_SYSERR;
321 ret = fprintf(outfile, "execute insert_trial using "
322 "@date, @num, @topology, @t_p, @t_pr,"
323 " @bl, @connect, @c_t_o,"
324 "@c_t_o_m, @puts, @gets,"
325 "@concurrent, @settle, @rounds,"
326 "@m_gets, @m_puts, @m_drops,"
327 "@m_g_f, @m_p_f, @s_c, @s_f,"
328 "@s_k, @g_s, @message;\n");
330 return GNUNET_SYSERR;
331 ret = fprintf(outfile, "execute select_trial;\n");
335 return GNUNET_SYSERR;
340 * Inserts the specified stats into the dhttests.generic_stats table
342 * @param peer the peer inserting the statistic
343 * @param name the name of the statistic
344 * @param section the section of the statistic
345 * @param value the value of the statistic
347 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
350 add_generic_stat (const struct GNUNET_PeerIdentity *peer,
352 const char *section, uint64_t value)
356 return GNUNET_SYSERR;
359 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&peer->hashPubKey));
361 ret = fprintf(outfile, "set @temp_node = 0;\n");
364 return GNUNET_SYSERR;
366 ret = fprintf(outfile, "set @temp_section = \"%s\", @temp_stat = \"%s\", @temp_value = %llu;\n",
367 section, name, (unsigned long long)value);
370 return GNUNET_SYSERR;
372 ret = fprintf(outfile, "execute insert_generic_stat;\n");
375 return GNUNET_SYSERR;
381 * Inserts the specified stats into the dhttests.node_statistics table
383 * @param peer the peer inserting the statistic
384 * @param route_requests route requests seen
385 * @param route_forwards route requests forwarded
386 * @param result_requests route result requests seen
387 * @param client_requests client requests initiated
388 * @param result_forwards route results forwarded
389 * @param gets get requests handled
390 * @param puts put requests handle
391 * @param data_inserts data inserted at this node
392 * @param find_peer_requests find peer requests seen
393 * @param find_peers_started find peer requests initiated at this node
394 * @param gets_started get requests initiated at this node
395 * @param puts_started put requests initiated at this node
396 * @param find_peer_responses_received find peer responses received locally
397 * @param get_responses_received get responses received locally
398 * @param find_peer_responses_sent find peer responses sent from this node
399 * @param get_responses_sent get responses sent from this node
401 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
404 add_stat (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
405 unsigned int route_forwards, unsigned int result_requests,
406 unsigned int client_requests, unsigned int result_forwards,
407 unsigned int gets, unsigned int puts,
408 unsigned int data_inserts, unsigned int find_peer_requests,
409 unsigned int find_peers_started, unsigned int gets_started,
410 unsigned int puts_started, unsigned int find_peer_responses_received,
411 unsigned int get_responses_received, unsigned int find_peer_responses_sent,
412 unsigned int get_responses_sent)
416 return GNUNET_SYSERR;
419 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&peer->hashPubKey));
421 ret = fprintf(outfile, "set @temp_node = 0;\n");
423 return GNUNET_SYSERR;
425 ret = fprintf(outfile, "set @r_r = %u, @r_f = %u, @res_r = %u, @c_r = %u, "
426 "@res_f = %u, @gets = %u, @puts = %u, @d_i = %u, "
427 "@f_p_r = %u, @f_p_s = %u, @g_s = %u, @p_s = %u, "
428 "@f_p_r_r = %u, @g_r_r = %u, @f_p_r_s = %u, @g_r_s = %u;\n",
429 route_requests, route_forwards, result_requests,
430 client_requests, result_forwards, gets, puts,
431 data_inserts, find_peer_requests, find_peers_started,
432 gets_started, puts_started, find_peer_responses_received,
433 get_responses_received, find_peer_responses_sent,
437 return GNUNET_SYSERR;
439 ret = fprintf(outfile, "execute insert_stat using "
440 "@temp_trial, @temp_node, @r_r, @r_f, @res_r, @c_r, "
441 "@res_f, @gets, @puts, @d_i, "
442 "@f_p_r, @f_p_s, @g_s, @p_s, "
443 "@f_p_r_r, @g_r_r, @f_p_r_s, @g_r_s;\n");
445 return GNUNET_SYSERR;
449 * Inserts the specified dhtkey into the dhttests.dhtkeys table,
450 * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
452 * @param dhtkeyuid return value
453 * @param dhtkey hashcode of key to insert
455 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
458 add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
461 if (dhtkeyuid != NULL)
465 return GNUNET_SYSERR;
468 ret = fprintf(outfile, "set @dhtkey = \"%s\";\n", GNUNET_h2s_full(dhtkey));
470 ret = fprintf(outfile, "set @dhtkey = XXXXX;\n");
473 return GNUNET_SYSERR;
474 ret = fprintf(outfile, "execute insert_dhtkey using @dhtkey;\n");
478 return GNUNET_SYSERR;
482 * Inserts the specified node into the dhttests.nodes table
484 * @param nodeuid the inserted node uid
485 * @param node the node to insert
487 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
490 add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
495 return GNUNET_SYSERR;
498 return GNUNET_SYSERR;
501 ret = fprintf(outfile, "set @node = \"%s\";\n", GNUNET_h2s_full(&node->hashPubKey));
503 return GNUNET_SYSERR;
506 return GNUNET_SYSERR;
508 ret = fprintf(outfile, "execute insert_node using @node;\n");
512 return GNUNET_SYSERR;
516 * Update dhttests.trials table with current server time as end time
518 * @param trialuid trial to update
519 * @param gets_succeeded how many gets did the testcase report as successful
521 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
524 update_trials (unsigned long long trialuid,
525 unsigned int gets_succeeded)
529 if (trialuid != current_trial)
532 _("Trialuid to update is not equal to current_trial\n"));
537 return GNUNET_SYSERR;
539 ret = fprintf(outfile, "set @date = \"%s\", @g_s = %u;\n", get_sql_time(), gets_succeeded);
542 return GNUNET_SYSERR;
544 ret = fprintf(outfile, "execute update_trial using @date, @g_s;\n");
549 return GNUNET_SYSERR;
554 * Update dhttests.nodes table setting the identified
555 * node as a malicious dropper.
557 * @param peer the peer that was set to be malicious
559 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
562 set_malicious (struct GNUNET_PeerIdentity *peer)
567 return GNUNET_SYSERR;
569 ret = fprintf(outfile, "set @temp_node = \"%s\";\n", GNUNET_h2s_full(&peer->hashPubKey));
572 return GNUNET_SYSERR;
574 ret = fprintf(outfile, "execute set_malicious;\n");
579 return GNUNET_SYSERR;
584 * Update dhttests.trials table with total connections information
586 * @param trialuid the trialuid to update
587 * @param totalConnections the number of connections
589 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
592 add_connections (unsigned long long trialuid, unsigned int totalConnections)
596 if (trialuid != current_trial)
599 _("Trialuid to update is not equal to current_trial(!)(?)\n"));
603 return GNUNET_SYSERR;
605 ret = fprintf(outfile, "set @conns = %u;\n", totalConnections);
608 return GNUNET_SYSERR;
610 ret = fprintf(outfile, "execute update_conn using @conns;\n");
615 return GNUNET_SYSERR;
620 * Update dhttests.topology table with total connections information
622 * @param totalConnections the number of connections
624 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
627 update_topology (unsigned int connections)
631 return GNUNET_SYSERR;
633 ret = fprintf(outfile, "set @temp_conns = %u;\n", connections);
636 return GNUNET_SYSERR;
638 ret = fprintf(outfile, "execute update_topology using @temp_conns;\n");
643 return GNUNET_SYSERR;
647 * Inserts the specified query into the dhttests.queries table
649 * @param sqlqueruid inserted query uid
650 * @param queryid dht query id
651 * @param type type of the query
652 * @param hops number of hops query traveled
653 * @param succeeded whether or not query was successful
654 * @param node the node the query hit
655 * @param key the key of the query
657 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
660 add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
661 unsigned int type, unsigned int hops, int succeeded,
662 const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode * key)
667 return GNUNET_SYSERR;
669 if (sqlqueryuid != NULL)
673 ret = fprintf(outfile, "select dhtkeyuid from dhtkeys where trialuid = @temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n", GNUNET_h2s_full(key));
675 ret = fprintf(outfile, "set @temp_dhtkey = 0;\n");
678 return GNUNET_SYSERR;
681 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&node->hashPubKey));
683 ret = fprintf(outfile, "set @temp_node = 0;\n");
686 return GNUNET_SYSERR;
688 ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ = %d;\n", queryid, type, hops, succeeded);
691 return GNUNET_SYSERR;
693 ret = fprintf(outfile, "execute insert_query using @type, @hops, @temp_dhtkey, @qid, @succ, @temp_node;\n");
698 return GNUNET_SYSERR;
702 * Inserts the specified route information into the dhttests.routes table
704 * @param sqlqueruid inserted query uid
705 * @param queryid dht query id
706 * @param type type of the query
707 * @param hops number of hops query traveled
708 * @param succeeded whether or not query was successful
709 * @param node the node the query hit
710 * @param key the key of the query
711 * @param from_node the node that sent the message to node
712 * @param to_node next node to forward message to
714 * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
717 add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
718 unsigned int type, unsigned int hops,
719 int succeeded, const struct GNUNET_PeerIdentity * node,
720 const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity * from_node,
721 const struct GNUNET_PeerIdentity * to_node)
726 return GNUNET_SYSERR;
728 if (sqlqueryuid != NULL)
732 ret = fprintf(outfile, "select dhtkeyuid from dhtkeys where trialuid = @temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n", GNUNET_h2s_full(key));
734 ret = fprintf(outfile, "set @temp_dhtkey = 0;\n");
737 return GNUNET_SYSERR;
740 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&node->hashPubKey));
742 ret = fprintf(outfile, "set @temp_node = 0;\n");
745 return GNUNET_SYSERR;
747 if (from_node != NULL)
748 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_from_node;\n", GNUNET_h2s_full(&from_node->hashPubKey));
750 ret = fprintf(outfile, "set @temp_from_node = 0;\n");
753 return GNUNET_SYSERR;
756 ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_to_node;\n", GNUNET_h2s_full(&to_node->hashPubKey));
758 ret = fprintf(outfile, "set @temp_to_node = 0;\n");
761 return GNUNET_SYSERR;
763 ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ = %d;\n", queryid, type, hops, succeeded);
766 return GNUNET_SYSERR;
768 ret = fprintf(outfile, "execute insert_route using @type, @hops, @temp_dhtkey, @qid, @succ, @temp_node, @temp_from_node, @temp_to_node;\n");
773 return GNUNET_SYSERR;
777 * Provides the dhtlog api
779 * @param c the configuration to use to connect to a server
781 * @return the handle to the server, or NULL on error
784 libgnunet_plugin_dhtlog_mysql_dump_init (void * cls)
786 struct GNUNET_DHTLOG_Plugin *plugin = cls;
793 max_varchar_len = 255;
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL (DUMP) DHT Logger: initializing\n");
797 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
801 outfile_path = GNUNET_strdup("");
804 GNUNET_asprintf (&outfile_name,
810 fn = GNUNET_STRINGS_filename_expand (outfile_name);
814 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to get full path for `%s'\n"), outfile_name);
815 GNUNET_free(outfile_path);
816 GNUNET_free(outfile_name);
820 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
821 outfile = FOPEN (fn, "w");
825 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
827 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
828 _("Failed to create or access directory for log file `%s'\n"),
830 GNUNET_free(outfile_path);
831 GNUNET_free(outfile_name);
836 GNUNET_free (outfile_path);
837 GNUNET_free (outfile_name);
840 if (iopen () != GNUNET_OK)
842 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
843 _("Failed to create file for dhtlog.\n"));
846 GNUNET_assert(plugin->dhtlog_api == NULL);
847 plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle));
848 plugin->dhtlog_api->insert_trial = &add_trial;
849 plugin->dhtlog_api->insert_stat = &add_stat;
850 plugin->dhtlog_api->insert_query = &add_query;
851 plugin->dhtlog_api->update_trial = &update_trials;
852 plugin->dhtlog_api->insert_route = &add_route;
853 plugin->dhtlog_api->insert_node = &add_node;
854 plugin->dhtlog_api->insert_dhtkey = &add_dhtkey;
855 plugin->dhtlog_api->update_connections = &add_connections;
856 plugin->dhtlog_api->insert_topology = &add_topology;
857 plugin->dhtlog_api->insert_extended_topology = &add_extended_topology;
858 plugin->dhtlog_api->update_topology = &update_topology;
859 plugin->dhtlog_api->set_malicious = &set_malicious;
860 plugin->dhtlog_api->add_generic_stat = &add_generic_stat;
866 * Shutdown the plugin.
869 libgnunet_plugin_dhtlog_mysql_dump_done (void * cls)
871 struct GNUNET_DHTLOG_Handle *dhtlog_api = cls;
872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
873 "MySQL DHT Logger: database shutdown\n");
874 GNUNET_assert(dhtlog_api != NULL);
876 GNUNET_free(dhtlog_api);
880 /* end of plugin_dhtlog_mysql.c */