removed debug out
[oweals/gnunet.git] / src / dht / plugin_dhtlog_mysql_dump.c
1 /*
2      This file is part of GNUnet.
3      (C) 2006 - 2009 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file src/dht/plugin_dhtlog_mysql.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
29  *
30  * Database: MySQL
31  */
32
33 #include "platform.h"
34 #include "gnunet_util_lib.h"
35 #include "dhtlog.h"
36
37
38 #define DEBUG_DHTLOG GNUNET_NO
39
40 /**
41  * Maximum number of supported parameters for a prepared
42  * statement.  Increase if needed.
43  */
44 #define MAX_PARAM 32
45
46
47 static unsigned long max_varchar_len;
48
49 /**
50  * The configuration the DHT service is running with
51  */
52 static const struct GNUNET_CONFIGURATION_Handle *cfg;
53
54 #define INSERT_QUERIES_STMT "prepare insert_query from 'INSERT INTO queries (trialuid, querytype, hops, dhtkeyuid, dhtqueryid, succeeded, nodeuid) "\
55                           "VALUES (@temp_trial, ?, ?, ?, ?, ?, ?)'"
56
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, ?, ?, ?, ?, ?, ?, ?, ?)'"
59
60 #define INSERT_NODES_STMT "prepare insert_node from 'INSERT INTO nodes (trialuid, nodeid) "\
61                           "VALUES (@temp_trial, ?)'"
62
63 #define INSERT_TOPOLOGY_STMT "prepare insert_topology from 'INSERT INTO topology (trialuid, date, connections) "\
64                              "VALUES (@temp_trial, ?, ?)'"
65
66 #define EXTEND_TOPOLOGY_STMT "prepare extend_topology from 'INSERT INTO extended_topology (topology_uid, uid_first, uid_second) "\
67                              "VALUES (@temp_topology, ?, ?)'"
68
69 #define UPDATE_TOPOLOGY_STMT "prepare update_topology from 'update topology set connections = ?  where topology_uid = @temp_topology'"
70
71 #define INSERT_TRIALS_STMT "prepare insert_trial from 'INSERT INTO trials"\
72                            "(starttime, numnodes, topology,"\
73                            "topology_percentage, topology_probability,"\
74                            "blacklist_topology, connect_topology, connect_topology_option,"\
75                            "connect_topology_option_modifier, puts, gets, "\
76                            "concurrent, settle_time, num_rounds, malicious_getters,"\
77                            "malicious_putters, malicious_droppers, message) "\
78                            "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'"
79
80 #define INSERT_DHTKEY_STMT "prepare insert_dhtkey from 'INSERT ignore INTO dhtkeys (dhtkey, trialuid) "\
81                            "VALUES (?, @temp_trial)'"
82
83 #define UPDATE_TRIALS_STMT "prepare update_trial from 'UPDATE trials set endtime= ?, total_messages_dropped = ?, total_bytes_dropped = ?, unknownPeers = ? where trialuid = @temp_trial'"
84
85 #define UPDATE_CONNECTIONS_STMT "prepare update_conn from 'UPDATE trials set totalConnections = ? where trialuid = @temp_trial'"
86
87 #define GET_TRIAL_STMT "prepare select_trial from 'SELECT MAX( trialuid ) FROM trials into @temp_trial'"
88
89 #define GET_TOPOLOGY_STMT "prepare select_topology from 'SELECT MAX( topology_uid ) FROM topology into @temp_topology'"
90
91 #define GET_DHTKEYUID_STMT "prepare get_dhtkeyuid from 'SELECT dhtkeyuid FROM dhtkeys where dhtkey = ? and trialuid = @temp_trial'"
92
93 #define GET_NODEUID_STMT "prepare get_nodeuid from 'SELECT nodeuid FROM nodes where trialuid = @temp_trial and nodeid = ?'"
94
95 #define DATE_STR_SIZE 50
96
97 /**
98  * File to dump all sql statements to.
99  */
100 FILE *outfile;
101
102
103 static char *
104 get_sql_time()
105 {
106   static char date[DATE_STR_SIZE];
107   time_t timetmp;
108   struct tm *tmptr;
109
110   time (&timetmp);
111   memset (date, 0, DATE_STR_SIZE);
112   tmptr = localtime (&timetmp);
113   if (NULL != tmptr)
114     strftime (date, DATE_STR_SIZE, "%Y-%m-%d %H:%M:%S", tmptr);
115   else
116     strcpy (date, "");
117
118   return date;
119 }
120
121 /**
122  * Create a prepared statement.
123  *
124  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
125  */
126 static int
127 prepared_statement_create (const char *statement)
128 {
129   if (fprintf(outfile, "%s;\n", statement) > 0)
130     return GNUNET_OK;
131
132   return GNUNET_SYSERR;
133 }
134
135 /*
136  * Initialize the prepared statements for use with dht test logging
137  */
138 static int
139 iopen ()
140 {
141 #define PINIT(a) (GNUNET_OK != (prepared_statement_create(a)))
142   if (PINIT (INSERT_QUERIES_STMT) ||
143       PINIT (INSERT_ROUTES_STMT) ||
144       PINIT (INSERT_TRIALS_STMT) ||
145       PINIT (INSERT_NODES_STMT) ||
146       PINIT (INSERT_DHTKEY_STMT) ||
147       PINIT (UPDATE_TRIALS_STMT) ||
148       PINIT (GET_DHTKEYUID_STMT) ||
149       PINIT (GET_NODEUID_STMT) ||
150       PINIT (UPDATE_CONNECTIONS_STMT) ||
151       PINIT (INSERT_TOPOLOGY_STMT) ||
152       PINIT (EXTEND_TOPOLOGY_STMT) ||
153       PINIT (UPDATE_TOPOLOGY_STMT) ||
154       PINIT (GET_TRIAL_STMT) ||
155       PINIT (GET_TOPOLOGY_STMT))
156     {
157       return GNUNET_SYSERR;
158     }
159 #undef PINIT
160
161   return GNUNET_OK;
162 }
163
164
165
166 /*
167  * Records the current topology (number of connections, time, trial)
168  *
169  * @param num_connections how many connections are in the topology
170  *
171  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
172  */
173 int
174 add_topology (int num_connections)
175 {
176   int ret;
177   if (outfile == NULL)
178     return GNUNET_SYSERR;
179
180   ret = fprintf(outfile, "set @date = \"%s\", @num = %d;\n", get_sql_time(), num_connections);
181
182   if (ret < 0)
183     return GNUNET_SYSERR;
184   ret = fprintf(outfile, "execute insert_topology using "
185                          "@date, @num;\n");
186
187   ret = fprintf(outfile, "execute select_topology;\n");
188
189   if (ret >= 0)
190     return GNUNET_OK;
191   return GNUNET_SYSERR;
192 }
193
194 /*
195  * Records a connection between two peers in the current topology
196  *
197  * @param first one side of the connection
198  * @param second other side of the connection
199  *
200  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
201  */
202 int
203 add_extended_topology (struct GNUNET_PeerIdentity *first, struct GNUNET_PeerIdentity *second)
204 {
205   int ret;
206   if (outfile == NULL)
207     return GNUNET_SYSERR;
208
209   if (first != NULL)
210     ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_first_node;\n", GNUNET_h2s_full(&first->hashPubKey));
211   else
212     ret = fprintf(outfile, "set @temp_first_node = 0;\n");
213
214   if (ret < 0)
215     return GNUNET_SYSERR;
216
217   if (second != NULL)
218     ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_second_node;\n", GNUNET_h2s_full(&second->hashPubKey));
219   else
220     ret = fprintf(outfile, "set @temp_second_node = 0;\n");
221
222   if (ret < 0)
223     return GNUNET_SYSERR;
224
225   ret = fprintf(outfile, "execute extend_topology using "
226                          "@temp_first_node, @temp_second_node;\n");
227
228   if (ret >= 0)
229     return GNUNET_OK;
230   return GNUNET_SYSERR;
231 }
232
233
234 /*
235  * Inserts the specified trial into the dhttests.trials table
236  *
237  * @param trialuid return the trialuid of the newly inserted trial
238  * @param num_nodes how many nodes are in the trial
239  * @param topology integer representing topology for this trial
240  * @param blacklist_topology integer representing blacklist topology for this trial
241  * @param connect_topology integer representing connect topology for this trial
242  * @param connect_topology_option integer representing connect topology option
243  * @param connect_topology_option_modifier float to modify connect option
244  * @param topology_percentage percentage modifier for certain topologies
245  * @param topology_probability probability modifier for certain topologies
246  * @param puts number of puts to perform
247  * @param gets number of gets to perform
248  * @param concurrent number of concurrent requests
249  * @param settle_time time to wait between creating topology and starting testing
250  * @param num_rounds number of times to repeat the trial
251  * @param malicious_getters number of malicious GET peers in the trial
252  * @param malicious_putters number of malicious PUT peers in the trial
253  * @param malicious_droppers number of malicious DROP peers in the trial
254  * @param message string to put into DB for this trial
255  *
256  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
257  */
258 int
259 add_trial (unsigned long long *trialuid, int num_nodes, int topology,
260            int blacklist_topology, int connect_topology,
261            int connect_topology_option, float connect_topology_option_modifier,
262            float topology_percentage, float topology_probability,
263            int puts, int gets, int concurrent, int settle_time,
264            int num_rounds, int malicious_getters, int malicious_putters,
265            int malicious_droppers, char *message)
266 {
267   int ret;
268   if (trialuid != NULL)
269     *trialuid = 0;
270   if (outfile == NULL)
271     return GNUNET_SYSERR;
272
273   ret = fprintf(outfile, "set @date = \"%s\", @num = %d, @topology = %d, @bl = %d, "
274                    "@connect = %d, @c_t_o = %d, @c_t_o_m = %f, @t_p = %f, "
275                    "@t_pr = %f, @puts = %d, @gets = %d, "
276                    "@concurrent = %d, @settle = %d, @rounds = %d, "
277                    "@m_gets = %d, @m_puts = %d, @m_drops = %d, "
278                    "@message = \"%s\";\n", get_sql_time(), num_nodes, topology,
279                    blacklist_topology, connect_topology,
280                    connect_topology_option, connect_topology_option_modifier,
281                    topology_percentage, topology_probability,
282                    puts, gets, concurrent, settle_time,
283                    num_rounds, malicious_getters, malicious_putters,
284                    malicious_droppers, message);
285
286   if (ret < 0)
287     return GNUNET_SYSERR;
288   ret = fprintf(outfile, "execute insert_trial using "
289                          "@date, @num, @topology, @t_p, @t_pr,"
290                          " @bl, @connect, @c_t_o,"
291                          "@c_t_o_m, @puts, @gets,"
292                          "@concurrent, @settle, @rounds,"
293                          "@m_gets, @m_puts, @m_drops,"
294                          "@message;\n");
295
296   ret = fprintf(outfile, "execute select_trial;\n");
297
298   if (ret >= 0)
299     return GNUNET_OK;
300   return GNUNET_SYSERR;
301 }
302
303
304 /*
305  * Inserts the specified dhtkey into the dhttests.dhtkeys table,
306  * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
307  *
308  * @param dhtkeyuid return value
309  * @param dhtkey hashcode of key to insert
310  *
311  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
312  */
313 int
314 add_dhtkey (unsigned long long *dhtkeyuid, const GNUNET_HashCode * dhtkey)
315 {
316   int ret;
317   if (dhtkeyuid != NULL)
318     *dhtkeyuid = 0;
319
320   if (outfile == NULL)
321     return GNUNET_SYSERR;
322
323   if (dhtkey != NULL)
324     ret = fprintf(outfile, "set @dhtkey = \"%s\";\n", GNUNET_h2s_full(dhtkey));
325   else
326     ret = fprintf(outfile, "set @dhtkey = XXXXX;\n");
327
328   if (ret < 0)
329     return GNUNET_SYSERR;
330   ret = fprintf(outfile, "execute insert_dhtkey using @dhtkey;\n");
331
332   if (ret >= 0)
333     return GNUNET_OK;
334   return GNUNET_SYSERR;
335 }
336
337 /*
338  * Inserts the specified node into the dhttests.nodes table
339  *
340  * @param nodeuid the inserted node uid
341  * @param node the node to insert
342  *
343  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
344  */
345 int
346 add_node (unsigned long long *nodeuid, struct GNUNET_PeerIdentity * node)
347 {
348   int ret;
349
350   if (node == NULL)
351     return GNUNET_SYSERR;
352
353   if (outfile == NULL)
354     return GNUNET_SYSERR;
355
356   if (node != NULL)
357     ret = fprintf(outfile, "set @node = \"%s\";\n", GNUNET_h2s_full(&node->hashPubKey));
358   else
359     return GNUNET_SYSERR;
360
361   if (ret < 0)
362     return GNUNET_SYSERR;
363
364   ret = fprintf(outfile, "execute insert_node using @node;\n");
365
366   if (ret >= 0)
367     return GNUNET_OK;
368   return GNUNET_SYSERR;
369 }
370
371 /*
372  * Update dhttests.trials table with current server time as end time
373  *
374  * @param trialuid trial to update
375  * @param totalMessagesDropped stats value for messages dropped
376  * @param totalBytesDropped stats value for total bytes dropped
377  * @param unknownPeers stats value for unknown peers
378  *
379  * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
380  */
381 int
382 update_trials (unsigned long long trialuid,
383                unsigned long long totalMessagesDropped,
384                unsigned long long totalBytesDropped,
385                unsigned long long unknownPeers)
386 {
387   int ret;
388 #if DEBUG_DHTLOG
389   if (trialuid != current_trial)
390     {
391       fprintf (stderr,
392                _("Trialuid to update is not equal to current_trial\n"));
393     }
394 #endif
395
396   if (outfile == NULL)
397     return GNUNET_SYSERR;
398
399   ret = fprintf(outfile, "set @date = \"%s\", @m_dropped = %llu, @b_dropped = %llu, @unknown = %llu;\n", get_sql_time(), totalMessagesDropped, totalBytesDropped, unknownPeers);
400
401   if (ret < 0)
402     return GNUNET_SYSERR;
403
404   ret = fprintf(outfile, "execute update_trial using @date, @m_dropped, @b_dropped, @unknown;\n");
405
406   if (ret >= 0)
407     return GNUNET_OK;
408   else
409     return GNUNET_SYSERR;
410 }
411
412
413 /*
414  * Update dhttests.trials table with total connections information
415  *
416  * @param trialuid the trialuid to update
417  * @param totalConnections the number of connections
418  *
419  * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
420  */
421 int
422 add_connections (unsigned long long trialuid, unsigned int totalConnections)
423 {
424   int ret;
425 #if DEBUG_DHTLOG
426   if (trialuid != current_trial)
427     {
428       fprintf (stderr,
429                _("Trialuid to update is not equal to current_trial(!)(?)\n"));
430     }
431 #endif
432   if (outfile == NULL)
433     return GNUNET_SYSERR;
434
435   ret = fprintf(outfile, "set @conns = %u;\n", totalConnections);
436
437   if (ret < 0)
438     return GNUNET_SYSERR;
439
440   ret = fprintf(outfile, "execute update_conn using @conns;\n");
441
442   if (ret >= 0)
443     return GNUNET_OK;
444   else
445     return GNUNET_SYSERR;
446 }
447
448
449 /*
450  * Update dhttests.topology table with total connections information
451  *
452  * @param totalConnections the number of connections
453  *
454  * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
455  */
456 int
457 update_topology (unsigned int connections)
458 {
459   int ret;
460   if (outfile == NULL)
461     return GNUNET_SYSERR;
462
463   ret = fprintf(outfile, "set @temp_conns = %u;\n", connections);
464
465   if (ret < 0)
466     return GNUNET_SYSERR;
467
468   ret = fprintf(outfile, "execute update_topology using @temp_conns;\n");
469
470   if (ret >= 0)
471     return GNUNET_OK;
472   else
473     return GNUNET_SYSERR;
474 }
475
476 /*
477  * Inserts the specified query into the dhttests.queries table
478  *
479  * @param sqlqueruid inserted query uid
480  * @param queryid dht query id
481  * @param type type of the query
482  * @param hops number of hops query traveled
483  * @param succeeded whether or not query was successful
484  * @param node the node the query hit
485  * @param key the key of the query
486  *
487  * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
488  */
489 int
490 add_query (unsigned long long *sqlqueryuid, unsigned long long queryid,
491            unsigned int type, unsigned int hops, int succeeded,
492            const struct GNUNET_PeerIdentity * node, const GNUNET_HashCode * key)
493 {
494   int ret;
495
496   if (outfile == NULL)
497     return GNUNET_SYSERR;
498
499   if (sqlqueryuid != NULL)
500     *sqlqueryuid = 0;
501
502   if (key != NULL)
503     ret = fprintf(outfile, "select dhtkeyuid from dhtkeys where trialuid = @temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n", GNUNET_h2s_full(key));
504   else
505     ret = fprintf(outfile, "set @temp_dhtkey = 0;\n");
506
507   if (node != NULL)
508     ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&node->hashPubKey));
509   else
510     ret = fprintf(outfile, "set @temp_node = 0;\n");
511
512   ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ = %d;\n", queryid, type, hops, succeeded);
513
514   if (ret < 0)
515     return GNUNET_SYSERR;
516
517   ret = fprintf(outfile, "execute insert_query using @type, @hops, @temp_dhtkey, @qid, @succ, @temp_node;\n");
518
519   if (ret >= 0)
520     return GNUNET_OK;
521   else
522     return GNUNET_SYSERR;
523 }
524
525 /*
526  * Inserts the specified route information into the dhttests.routes table
527  *
528  * @param sqlqueruid inserted query uid
529  * @param queryid dht query id
530  * @param type type of the query
531  * @param hops number of hops query traveled
532  * @param succeeded whether or not query was successful
533  * @param node the node the query hit
534  * @param key the key of the query
535  * @param from_node the node that sent the message to node
536  * @param to_node next node to forward message to
537  *
538  * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
539  */
540 int
541 add_route (unsigned long long *sqlqueryuid, unsigned long long queryid,
542            unsigned int type, unsigned int hops,
543            int succeeded, const struct GNUNET_PeerIdentity * node,
544            const GNUNET_HashCode * key, const struct GNUNET_PeerIdentity * from_node,
545            const struct GNUNET_PeerIdentity * to_node)
546 {
547   int ret;
548
549   if (outfile == NULL)
550     return GNUNET_SYSERR;
551
552   if (sqlqueryuid != NULL)
553     *sqlqueryuid = 0;
554
555   if (key != NULL)
556     ret = fprintf(outfile, "select dhtkeyuid from dhtkeys where trialuid = @temp_trial and dhtkey = \"%s\" into @temp_dhtkey;\n", GNUNET_h2s_full(key));
557   else
558     ret = fprintf(outfile, "set @temp_dhtkey = 0;\n");
559
560   if (node != NULL)
561     ret = fprintf(outfile, "select nodeuid from nodes where trialuid = @temp_trial and nodeid = \"%s\" into @temp_node;\n", GNUNET_h2s_full(&node->hashPubKey));
562   else
563     ret = fprintf(outfile, "set @temp_node = 0;\n");
564
565   if (from_node != NULL)
566     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));
567   else
568     ret = fprintf(outfile, "set @temp_from_node = 0;\n");
569
570   if (to_node != NULL)
571     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));
572   else
573     ret = fprintf(outfile, "set @temp_to_node = 0;\n");
574
575   ret = fprintf(outfile, "set @qid = %llu, @type = %u, @hops = %u, @succ = %d;\n", queryid, type, hops, succeeded);
576
577   if (ret < 0)
578     return GNUNET_SYSERR;
579
580   ret = fprintf(outfile, "execute insert_route using @type, @hops, @temp_dhtkey, @qid, @succ, @temp_node, @temp_from_node, @temp_to_node;\n");
581
582   if (ret >= 0)
583     return GNUNET_OK;
584   else
585     return GNUNET_SYSERR;
586 }
587
588 /*
589  * Provides the dhtlog api
590  *
591  * @param c the configuration to use to connect to a server
592  *
593  * @return the handle to the server, or NULL on error
594  */
595 void *
596 libgnunet_plugin_dhtlog_mysql_dump_init (void * cls)
597 {
598   struct GNUNET_DHTLOG_Plugin *plugin = cls;
599   char *outfile_name;
600   char *outfile_path;
601   char *fn;
602   int dirwarn;
603
604   cfg = plugin->cfg;
605   max_varchar_len = 255;
606
607 #if DEBUG_DHTLOG
608   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MySQL (DUMP) DHT Logger: initializing\n");
609 #endif
610
611   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->cfg,
612                                                          "MYSQLDUMP", "PATH",
613                                                          &outfile_path))
614     {
615       outfile_path = GNUNET_strdup("");
616     }
617
618   GNUNET_asprintf (&outfile_name,
619                    "%s%s-%d",
620                    outfile_path,
621                    "mysqldump",
622                    getpid());
623
624   fn = GNUNET_STRINGS_filename_expand (outfile_name);
625
626   dirwarn = (GNUNET_OK !=  GNUNET_DISK_directory_create_for_file (fn));
627   outfile = FOPEN (fn, "w");
628
629   if (outfile == NULL)
630     {
631       GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn);
632       if (dirwarn)
633         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
634                     _("Failed to create or access directory for log file `%s'\n"),
635                     fn);
636       GNUNET_free(outfile_path);
637       GNUNET_free(outfile_name);
638       GNUNET_free (fn);
639       return NULL;
640     }
641
642   GNUNET_free (outfile_path);
643   GNUNET_free (outfile_name);
644   GNUNET_free (fn);
645
646   if (iopen () != GNUNET_OK)
647     {
648       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
649                   _("Failed to create file for dhtlog.\n"));
650       return NULL;
651     }
652   GNUNET_assert(plugin->dhtlog_api == NULL);
653   plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle));
654   plugin->dhtlog_api->insert_trial = &add_trial;
655   plugin->dhtlog_api->insert_query = &add_query;
656   plugin->dhtlog_api->update_trial = &update_trials;
657   plugin->dhtlog_api->insert_route = &add_route;
658   plugin->dhtlog_api->insert_node = &add_node;
659   plugin->dhtlog_api->insert_dhtkey = &add_dhtkey;
660   plugin->dhtlog_api->update_connections = &add_connections;
661   plugin->dhtlog_api->insert_topology = &add_topology;
662   plugin->dhtlog_api->insert_extended_topology = &add_extended_topology;
663   plugin->dhtlog_api->update_topology = &update_topology;
664
665   return NULL;
666 }
667
668 /**
669  * Shutdown the plugin.
670  */
671 void *
672 libgnunet_plugin_dhtlog_mysql_dump_done (void * cls)
673 {
674   struct GNUNET_DHTLOG_Handle *dhtlog_api = cls;
675 #if DEBUG_DHTLOG
676   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
677               "MySQL DHT Logger: database shutdown\n");
678 #endif
679   GNUNET_assert(dhtlog_api != NULL);
680
681   GNUNET_free(dhtlog_api);
682   return NULL;
683 }
684
685 /* end of plugin_dhtlog_mysql.c */