2 This file is part of GNUnet
3 (C) 2009, 2010, 2011 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 3, 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 datastore/plugin_datastore_mysql.c
23 * @brief mysql-based datastore backend
24 * @author Igor Wronsky
25 * @author Christian Grothoff
27 * NOTE: This db module does NOT work with mysql prior to 4.1 since
28 * it uses prepared statements. MySQL 5.0.46 promises to fix a bug
29 * in MyISAM that is causing us grief. At the time of this writing,
30 * that version is yet to be released. In anticipation, the code
31 * will use MyISAM with 5.0.46 (and higher). If you run such a
32 * version, please run "make check" to verify that the MySQL bug
33 * was actually fixed in your version (and if not, change the
34 * code below to use MyISAM for gn071).
39 * + On up-to-date hardware where mysql can be used comfortably, this
40 * module will have better performance than the other db choices
41 * (according to our tests).
42 * + Its often possible to recover the mysql database from internal
43 * inconsistencies. The other db choices do not support repair!
45 * - Memory usage (Comment: "I have 1G and it never caused me trouble")
48 * MANUAL SETUP INSTRUCTIONS
50 * 1) in /etc/gnunet.conf, set
55 * 2) Then access mysql as root,
59 * and do the following. [You should replace $USER with the username
60 * that will be running the gnunetd process].
62 CREATE DATABASE gnunet;
63 GRANT select,insert,update,delete,create,alter,drop,create temporary tables
64 ON gnunet.* TO $USER@localhost;
65 SET PASSWORD FOR $USER@localhost=PASSWORD('$the_password_you_like');
68 * 3) In the $HOME directory of $USER, create a ".my.cnf" file
69 * with the following lines
73 password=$the_password_you_like
76 * Thats it. Note that .my.cnf file is a security risk unless its on
77 * a safe partition etc. The $HOME/.my.cnf can of course be a symbolic
78 * link. Even greater security risk can be achieved by setting no
79 * password for $USER. Luckily $USER has only priviledges to mess
80 * up GNUnet's tables, nothing else (unless you give him more,
83 * 4) Still, perhaps you should briefly try if the DB connection
84 * works. First, login as $USER. Then use,
87 $ mysql -u $USER -p $the_password_you_like
91 * If you get the message "Database changed" it probably works.
93 * [If you get "ERROR 2002: Can't connect to local MySQL server
94 * through socket '/tmp/mysql.sock' (2)" it may be resolvable by
95 * "ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock"
96 * so there may be some additional trouble depending on your mysql setup.]
100 * - Its probably healthy to check your tables for inconsistencies
101 * every now and then.
102 * - If you get odd SEGVs on gnunetd startup, it might be that the mysql
103 * databases have been corrupted.
104 * - The tables can be verified/fixed in two ways;
105 * 1) by running mysqlcheck -A, or
106 * 2) by executing (inside of mysql using the GNUnet database):
108 mysql> REPAIR TABLE gn090;
113 * If you have problems related to the mysql module, your best
114 * friend is probably the mysql manual. The first thing to check
115 * is that mysql is basically operational, that you can connect
116 * to it, create tables, issue queries etc.
119 #include "platform.h"
120 #include "gnunet_datastore_plugin.h"
121 #include "gnunet_util_lib.h"
122 #include <mysql/mysql.h>
124 #define DEBUG_MYSQL GNUNET_NO
126 #define MAX_DATUM_SIZE 65536
129 * Maximum number of supported parameters for a prepared
130 * statement. Increase if needed.
135 * Die with an error message that indicates
136 * a failure of the command 'cmd' with the message given
137 * by strerror(errno).
139 #define DIE_MYSQL(cmd, dbh) do { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, mysql_error((dbh)->dbf)); abort(); } while(0);
142 * Log an error message at log-level 'level' that indicates
143 * a failure of the command 'cmd' on file 'filename'
144 * with the message given by strerror(errno).
146 #define LOG_MYSQL(level, cmd, dbh) do { GNUNET_log(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, mysql_error((dbh)->dbf)); } while(0);
149 struct GNUNET_MysqlStatementHandle
151 struct GNUNET_MysqlStatementHandle *next;
153 struct GNUNET_MysqlStatementHandle *prev;
157 MYSQL_STMT *statement;
165 * Context for all functions in this plugin.
170 * Our execution environment.
172 struct GNUNET_DATASTORE_PluginEnvironment *env;
175 * Handle to talk to MySQL.
180 * We keep all prepared statements in a DLL. This is the head.
182 struct GNUNET_MysqlStatementHandle *shead;
185 * We keep all prepared statements in a DLL. This is the tail.
187 struct GNUNET_MysqlStatementHandle *stail;
190 * Filename of "my.cnf" (msyql configuration).
195 * Prepared statements.
197 #define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)"
198 struct GNUNET_MysqlStatementHandle *insert_entry;
200 #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
201 struct GNUNET_MysqlStatementHandle *delete_entry_by_uid;
203 #define COUNT_ENTRY_BY_HASH "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash) WHERE hash=?"
204 struct GNUNET_MysqlStatementHandle *count_entry_by_hash;
206 #define SELECT_ENTRY_BY_HASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash) WHERE hash=? ORDER BY uid LIMIT 1 OFFSET ?"
207 struct GNUNET_MysqlStatementHandle *select_entry_by_hash;
209 #define COUNT_ENTRY_BY_HASH_AND_VHASH "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=?"
210 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_vhash;
212 #define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? ORDER BY uid LIMIT 1 OFFSET ?"
213 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_vhash;
215 #define COUNT_ENTRY_BY_HASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=?"
216 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_type;
218 #define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=? ORDER BY uid LIMIT 1 OFFSET ?"
219 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_type;
221 #define COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=?"
222 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_vhash_and_type;
224 #define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=? ORDER BY uid ASC LIMIT 1 OFFSET ?"
225 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_vhash_and_type;
227 #define UPDATE_ENTRY "UPDATE gn090 SET prio=prio+?,expire=IF(expire>=?,expire,?) WHERE uid=?"
228 struct GNUNET_MysqlStatementHandle *update_entry;
230 #define DEC_REPL "UPDATE gn090 SET repl=GREATEST (0, repl - 1) WHERE uid=?"
231 struct GNUNET_MysqlStatementHandle *dec_repl;
233 #define SELECT_SIZE "SELECT SUM(BIT_LENGTH(value) DIV 8) FROM gn090"
234 struct GNUNET_MysqlStatementHandle *get_size;
236 #define SELECT_IT_NON_ANONYMOUS "SELECT type,prio,anonLevel,expire,hash,value,uid "\
237 "FROM gn090 FORCE INDEX (idx_anonLevel_type_rvalue) "\
238 "WHERE anonLevel=0 AND type=? AND "\
240 " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_anonLevel_type_rvalue) WHERE anonLevel=0 AND type=? AND rvalue>=?)) "\
241 "ORDER BY rvalue ASC LIMIT 1"
242 struct GNUNET_MysqlStatementHandle *zero_iter;
244 #define SELECT_IT_EXPIRATION "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_expire) WHERE expire < ? ORDER BY expire ASC LIMIT 1"
245 struct GNUNET_MysqlStatementHandle *select_expiration;
247 #define SELECT_IT_PRIORITY "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_prio) ORDER BY prio ASC LIMIT 1"
248 struct GNUNET_MysqlStatementHandle *select_priority;
250 #define SELECT_IT_REPLICATION "SELECT type,prio,anonLevel,expire,hash,value,uid "\
251 "FROM gn090 FORCE INDEX (idx_repl_rvalue) "\
254 " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) "\
255 "ORDER BY rvalue ASC "\
257 struct GNUNET_MysqlStatementHandle *select_replication;
259 #define SELECT_MAX_REPL "SELECT MAX(repl) FROM gn090"
260 struct GNUNET_MysqlStatementHandle *max_repl;
266 * Obtain the location of ".my.cnf".
268 * @param cfg our configuration
269 * @return NULL on error
272 get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
284 pw = getpwuid (getuid ());
287 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "getpwuid");
291 GNUNET_CONFIGURATION_have_value (cfg, "datastore-mysql", "CONFIG"))
293 GNUNET_assert (GNUNET_OK ==
294 GNUNET_CONFIGURATION_get_value_filename (cfg,
298 configured = GNUNET_YES;
302 home_dir = GNUNET_strdup (pw->pw_dir);
303 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
304 GNUNET_free (home_dir);
305 configured = GNUNET_NO;
308 home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
309 plibc_conv_to_win_path ("~/", home_dir);
310 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
311 GNUNET_free (home_dir);
312 configured = GNUNET_NO;
315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
316 _("Trying to use file `%s' for MySQL configuration.\n"), cnffile);
317 if ((0 != STAT (cnffile, &st)) ||
318 (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode)))
320 if (configured == GNUNET_YES)
321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
322 _("Could not access file `%s': %s\n"), cnffile,
324 GNUNET_free (cnffile);
332 * Close database connection and all prepared statements (we got a DB
335 * @param plugin plugin context
338 iclose (struct Plugin *plugin)
340 struct GNUNET_MysqlStatementHandle *s;
342 for (s = plugin->shead; s != NULL; s = s->next)
346 mysql_stmt_close (s->statement);
347 s->valid = GNUNET_NO;
350 if (plugin->dbf != NULL)
352 mysql_close (plugin->dbf);
360 * Open the connection with the database (and initialize
361 * our default options).
363 * @param plugin plugin context
364 * @return GNUNET_OK on success
367 iopen (struct Plugin *plugin)
372 char *mysql_password;
373 unsigned long long mysql_port;
375 unsigned int timeout;
377 plugin->dbf = mysql_init (NULL);
378 if (plugin->dbf == NULL)
379 return GNUNET_SYSERR;
380 if (plugin->cnffile != NULL)
381 mysql_options (plugin->dbf, MYSQL_READ_DEFAULT_FILE, plugin->cnffile);
382 mysql_options (plugin->dbf, MYSQL_READ_DEFAULT_GROUP, "client");
384 mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect);
385 timeout = 120; /* in seconds */
386 mysql_options (plugin->dbf,
387 MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
388 mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
389 timeout = 60; /* in seconds */
390 mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
391 mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
393 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
396 GNUNET_assert (GNUNET_OK ==
397 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
402 mysql_dbname = GNUNET_strdup ("gnunet");
404 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
405 "datastore-mysql", "USER"))
407 GNUNET_assert (GNUNET_OK ==
408 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
410 "USER", &mysql_user));
412 mysql_password = NULL;
413 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
417 GNUNET_assert (GNUNET_OK ==
418 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
424 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
425 "datastore-mysql", "HOST"))
427 GNUNET_assert (GNUNET_OK ==
428 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
434 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
435 "datastore-mysql", "PORT"))
437 GNUNET_assert (GNUNET_OK ==
438 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
440 "PORT", &mysql_port));
443 GNUNET_assert (mysql_dbname != NULL);
444 mysql_real_connect (plugin->dbf,
446 mysql_user, mysql_password,
448 (unsigned int) mysql_port, NULL, CLIENT_IGNORE_SIGPIPE);
449 GNUNET_free_non_null (mysql_server);
450 GNUNET_free_non_null (mysql_user);
451 GNUNET_free_non_null (mysql_password);
452 GNUNET_free (mysql_dbname);
453 if (mysql_error (plugin->dbf)[0])
455 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect", plugin);
456 return GNUNET_SYSERR;
463 * Run the given MySQL statement.
465 * @param plugin plugin context
466 * @param statement SQL statement to run
467 * @return GNUNET_OK on success, GNUNET_SYSERR on error
470 run_statement (struct Plugin *plugin, const char *statement)
472 if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
473 return GNUNET_SYSERR;
474 mysql_query (plugin->dbf, statement);
475 if (mysql_error (plugin->dbf)[0])
477 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", plugin);
479 return GNUNET_SYSERR;
486 * Create a prepared statement.
488 * @param plugin plugin context
489 * @param statement SQL statement text to prepare
490 * @return NULL on error
492 static struct GNUNET_MysqlStatementHandle *
493 prepared_statement_create (struct Plugin *plugin, const char *statement)
495 struct GNUNET_MysqlStatementHandle *ret;
497 ret = GNUNET_malloc (sizeof (struct GNUNET_MysqlStatementHandle));
498 ret->query = GNUNET_strdup (statement);
499 GNUNET_CONTAINER_DLL_insert (plugin->shead, plugin->stail, ret);
505 * Prepare a statement for running.
507 * @param plugin plugin context
508 * @param ret handle to prepared statement
509 * @return GNUNET_OK on success
512 prepare_statement (struct Plugin *plugin,
513 struct GNUNET_MysqlStatementHandle *ret)
515 if (GNUNET_YES == ret->valid)
517 if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
518 return GNUNET_SYSERR;
519 ret->statement = mysql_stmt_init (plugin->dbf);
520 if (ret->statement == NULL)
523 return GNUNET_SYSERR;
525 if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
527 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
529 _("Failed to prepare statement `%s'\n"), ret->query);
530 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin);
531 mysql_stmt_close (ret->statement);
532 ret->statement = NULL;
534 return GNUNET_SYSERR;
536 ret->valid = GNUNET_YES;
543 * Bind the parameters for the given MySQL statement
546 * @param plugin plugin context
547 * @param s statement to bind and run
548 * @param ap arguments for the binding
549 * @return GNUNET_SYSERR on error, GNUNET_OK on success
552 init_params (struct Plugin *plugin,
553 struct GNUNET_MysqlStatementHandle *s, va_list ap)
555 MYSQL_BIND qbind[MAX_PARAM];
558 enum enum_field_types ft;
560 pc = mysql_stmt_param_count (s->statement);
563 /* increase internal constant! */
565 return GNUNET_SYSERR;
567 memset (qbind, 0, sizeof (qbind));
570 while ((pc > 0) && (-1 != (int) (ft = va_arg (ap, enum enum_field_types))))
572 qbind[off].buffer_type = ft;
575 case MYSQL_TYPE_FLOAT:
576 qbind[off].buffer = va_arg (ap, float *);
579 case MYSQL_TYPE_LONGLONG:
580 qbind[off].buffer = va_arg (ap, unsigned long long *);
581 qbind[off].is_unsigned = va_arg (ap, int);
584 case MYSQL_TYPE_LONG:
585 qbind[off].buffer = va_arg (ap, unsigned int *);
586 qbind[off].is_unsigned = va_arg (ap, int);
589 case MYSQL_TYPE_VAR_STRING:
590 case MYSQL_TYPE_STRING:
591 case MYSQL_TYPE_BLOB:
592 qbind[off].buffer = va_arg (ap, void *);
593 qbind[off].buffer_length = va_arg (ap, unsigned long);
594 qbind[off].length = va_arg (ap, unsigned long *);
598 /* unsupported type */
600 return GNUNET_SYSERR;
605 if (!((pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1)))
608 return GNUNET_SYSERR;
610 if (mysql_stmt_bind_param (s->statement, qbind))
612 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
613 _("`%s' failed at %s:%d with error: %s\n"),
614 "mysql_stmt_bind_param",
615 __FILE__, __LINE__, mysql_stmt_error (s->statement));
617 return GNUNET_SYSERR;
619 if (mysql_stmt_execute (s->statement))
621 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
622 _("`%s' for `%s' failed at %s:%d with error: %s\n"),
623 "mysql_stmt_execute",
624 s->query, __FILE__, __LINE__, mysql_stmt_error (s->statement));
626 return GNUNET_SYSERR;
633 * Run a prepared SELECT statement.
635 * @param plugin plugin context
636 * @param s statement to run
637 * @param result_size number of elements in results array
638 * @param results pointer to already initialized MYSQL_BIND
639 * array (of sufficient size) for passing results
640 * @param ap pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
641 * values (size + buffer-reference for pointers); terminated
643 * @return GNUNET_SYSERR on error, otherwise GNUNET_OK or GNUNET_NO (no result)
646 prepared_statement_run_select_va (struct Plugin *plugin,
647 struct GNUNET_MysqlStatementHandle *s,
648 unsigned int result_size,
649 MYSQL_BIND * results, va_list ap)
654 if (GNUNET_OK != prepare_statement (plugin, s))
657 return GNUNET_SYSERR;
659 if (GNUNET_OK != init_params (plugin, s, ap))
662 return GNUNET_SYSERR;
664 rsize = mysql_stmt_field_count (s->statement);
665 if (rsize > result_size)
668 return GNUNET_SYSERR;
670 if (mysql_stmt_bind_result (s->statement, results))
672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
673 _("`%s' failed at %s:%d with error: %s\n"),
674 "mysql_stmt_bind_result",
675 __FILE__, __LINE__, mysql_stmt_error (s->statement));
677 return GNUNET_SYSERR;
679 ret = mysql_stmt_fetch (s->statement);
680 if (ret == MYSQL_NO_DATA)
684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
685 _("`%s' failed at %s:%d with error: %s\n"),
687 __FILE__, __LINE__, mysql_stmt_error (s->statement));
689 return GNUNET_SYSERR;
691 mysql_stmt_reset (s->statement);
697 * Run a prepared SELECT statement.
699 * @param plugin plugin context
700 * @param s statement to run
701 * @param result_size number of elements in results array
702 * @param results pointer to already initialized MYSQL_BIND
703 * array (of sufficient size) for passing results
704 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
705 * values (size + buffer-reference for pointers); terminated
707 * @return GNUNET_SYSERR on error, otherwise
708 * the number of successfully affected (or queried) rows
711 prepared_statement_run_select (struct Plugin *plugin,
712 struct GNUNET_MysqlStatementHandle *s,
713 unsigned int result_size,
714 MYSQL_BIND * results, ...)
719 va_start (ap, results);
720 ret = prepared_statement_run_select_va (plugin, s, result_size, results, ap);
727 * Run a prepared statement that does NOT produce results.
729 * @param plugin plugin context
730 * @param s statement to run
731 * @param insert_id NULL or address where to store the row ID of whatever
732 * was inserted (only for INSERT statements!)
733 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
734 * values (size + buffer-reference for pointers); terminated
736 * @return GNUNET_SYSERR on error, otherwise
737 * the number of successfully affected rows
740 prepared_statement_run (struct Plugin *plugin,
741 struct GNUNET_MysqlStatementHandle *s,
742 unsigned long long *insert_id, ...)
747 if (GNUNET_OK != prepare_statement (plugin, s))
748 return GNUNET_SYSERR;
749 va_start (ap, insert_id);
750 if (GNUNET_OK != init_params (plugin, s, ap))
753 return GNUNET_SYSERR;
756 affected = mysql_stmt_affected_rows (s->statement);
757 if (NULL != insert_id)
758 *insert_id = (unsigned long long) mysql_stmt_insert_id (s->statement);
759 mysql_stmt_reset (s->statement);
765 * Delete an entry from the gn090 table.
767 * @param plugin plugin context
768 * @param uid unique ID of the entry to delete
769 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error
772 do_delete_entry (struct Plugin *plugin, unsigned long long uid)
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
778 "Deleting value %llu from gn090 table\n", uid);
780 ret = prepared_statement_run (plugin,
781 plugin->delete_entry_by_uid,
783 MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1);
786 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
787 "Deleting value %llu from gn090 table failed\n", uid);
793 * Get an estimate of how much space the database is
796 * @param cls our "struct Plugin *"
797 * @return number of bytes used on disk
799 static unsigned long long
800 mysql_plugin_estimate_size (void *cls)
802 struct Plugin *plugin = cls;
806 memset (cbind, 0, sizeof (cbind));
808 cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
809 cbind[0].buffer = &total;
810 cbind[0].is_unsigned = GNUNET_NO;
812 prepared_statement_run_select (plugin, plugin->get_size, 1, cbind, -1))
819 * Store an item in the datastore.
822 * @param key key for the item
823 * @param size number of bytes in data
824 * @param data content stored
825 * @param type type of the content
826 * @param priority priority of the content
827 * @param anonymity anonymity-level for the content
828 * @param replication replication-level for the content
829 * @param expiration expiration time for the content
830 * @param msg set to error message
831 * @return GNUNET_OK on success
834 mysql_plugin_put (void *cls,
835 const GNUNET_HashCode * key,
838 enum GNUNET_BLOCK_Type type,
841 uint32_t replication,
842 struct GNUNET_TIME_Absolute expiration, char **msg)
844 struct Plugin *plugin = cls;
845 unsigned int irepl = replication;
846 unsigned int ipriority = priority;
847 unsigned int ianonymity = anonymity;
848 unsigned long long lexpiration = expiration.abs_value;
849 unsigned long long lrvalue =
850 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
852 unsigned long hashSize;
853 unsigned long hashSize2;
855 GNUNET_HashCode vhash;
857 if (size > MAX_DATUM_SIZE)
860 return GNUNET_SYSERR;
862 hashSize = sizeof (GNUNET_HashCode);
863 hashSize2 = sizeof (GNUNET_HashCode);
865 GNUNET_CRYPTO_hash (data, size, &vhash);
867 prepared_statement_run (plugin,
868 plugin->insert_entry,
870 MYSQL_TYPE_LONG, &irepl, GNUNET_YES,
871 MYSQL_TYPE_LONG, &type, GNUNET_YES,
872 MYSQL_TYPE_LONG, &ipriority, GNUNET_YES,
873 MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES,
874 MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES,
875 MYSQL_TYPE_LONGLONG, &lrvalue, GNUNET_YES,
876 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
877 MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2,
878 MYSQL_TYPE_BLOB, data, lsize, &lsize, -1))
879 return GNUNET_SYSERR;
881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
882 "Inserted value `%s' with size %u into gn090 table\n",
883 GNUNET_h2s (key), (unsigned int) size);
886 plugin->env->duc (plugin->env->cls, size);
892 * Update the priority for a particular key in the datastore. If
893 * the expiration time in value is different than the time found in
894 * the datastore, the higher value should be kept. For the
895 * anonymity level, the lower value is to be used. The specified
896 * priority should be added to the existing priority, ignoring the
899 * Note that it is possible for multiple values to match this put.
900 * In that case, all of the respective values are updated.
902 * @param cls our "struct Plugin*"
903 * @param uid unique identifier of the datum
904 * @param delta by how much should the priority
905 * change? If priority + delta < 0 the
906 * priority should be set to 0 (never go
908 * @param expire new expiration time should be the
909 * MAX of any existing expiration time and
911 * @param msg set to error message
912 * @return GNUNET_OK on success
915 mysql_plugin_update (void *cls,
917 int delta, struct GNUNET_TIME_Absolute expire, char **msg)
919 struct Plugin *plugin = cls;
920 unsigned long long vkey = uid;
921 unsigned long long lexpire = expire.abs_value;
925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
926 "Updating value %llu adding %d to priority and maxing exp at %llu\n",
927 vkey, delta, lexpire);
929 ret = prepared_statement_run (plugin,
930 plugin->update_entry,
932 MYSQL_TYPE_LONG, &delta, GNUNET_NO,
933 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
934 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
935 MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1);
936 if (ret != GNUNET_OK)
938 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
939 "Failed to update value %llu\n", vkey);
946 * Run the given select statement and call 'proc' on the resulting
947 * values (which must be in particular positions).
949 * @param plugin the plugin handle
950 * @param stmt select statement to run
951 * @param proc function to call on result
952 * @param proc_cls closure for proc
953 * @param ... arguments to initialize stmt
956 execute_select (struct Plugin *plugin,
957 struct GNUNET_MysqlStatementHandle *stmt,
958 PluginDatumProcessor proc, void *proc_cls, ...)
963 unsigned int priority;
964 unsigned int anonymity;
965 unsigned long long exp;
966 unsigned long hashSize;
968 unsigned long long uid;
969 char value[GNUNET_DATASTORE_MAX_VALUE_SIZE];
971 struct GNUNET_TIME_Absolute expiration;
974 hashSize = sizeof (GNUNET_HashCode);
975 memset (rbind, 0, sizeof (rbind));
976 rbind[0].buffer_type = MYSQL_TYPE_LONG;
977 rbind[0].buffer = &type;
978 rbind[0].is_unsigned = 1;
979 rbind[1].buffer_type = MYSQL_TYPE_LONG;
980 rbind[1].buffer = &priority;
981 rbind[1].is_unsigned = 1;
982 rbind[2].buffer_type = MYSQL_TYPE_LONG;
983 rbind[2].buffer = &anonymity;
984 rbind[2].is_unsigned = 1;
985 rbind[3].buffer_type = MYSQL_TYPE_LONGLONG;
986 rbind[3].buffer = &exp;
987 rbind[3].is_unsigned = 1;
988 rbind[4].buffer_type = MYSQL_TYPE_BLOB;
989 rbind[4].buffer = &key;
990 rbind[4].buffer_length = hashSize;
991 rbind[4].length = &hashSize;
992 rbind[5].buffer_type = MYSQL_TYPE_BLOB;
993 rbind[5].buffer = value;
994 rbind[5].buffer_length = size = sizeof (value);
995 rbind[5].length = &size;
996 rbind[6].buffer_type = MYSQL_TYPE_LONGLONG;
997 rbind[6].buffer = &uid;
998 rbind[6].is_unsigned = 1;
1000 va_start (ap, proc_cls);
1001 ret = prepared_statement_run_select_va (plugin, stmt, 7, rbind, ap);
1005 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1008 GNUNET_assert (size <= sizeof (value));
1009 if ((rbind[4].buffer_length != sizeof (GNUNET_HashCode)) ||
1010 (hashSize != sizeof (GNUNET_HashCode)))
1013 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1018 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %llu selecting from gn090 table\n",
1019 (unsigned int) size, GNUNET_h2s (&key), priority, anonymity, exp);
1021 GNUNET_assert (size < MAX_DATUM_SIZE);
1022 expiration.abs_value = exp;
1023 ret = proc (proc_cls,
1024 &key, size, value, type, priority, anonymity, expiration, uid);
1025 if (ret == GNUNET_NO)
1027 do_delete_entry (plugin, uid);
1029 plugin->env->duc (plugin->env->cls, -size);
1036 * Get one of the results for a particular key in the datastore.
1038 * @param cls closure
1039 * @param offset offset of the result (modulo num-results);
1040 * specific ordering does not matter for the offset
1041 * @param key key to match, never NULL
1042 * @param vhash hash of the value, maybe NULL (to
1043 * match all values that have the right key).
1044 * Note that for DBlocks there is no difference
1045 * betwen key and vhash, but for other blocks
1047 * @param type entries of which type are relevant?
1048 * Use 0 for any type.
1049 * @param proc function to call on the matching value,
1050 * with NULL for if no value matches
1051 * @param proc_cls closure for proc
1054 mysql_plugin_get_key (void *cls,
1056 const GNUNET_HashCode * key,
1057 const GNUNET_HashCode * vhash,
1058 enum GNUNET_BLOCK_Type type,
1059 PluginDatumProcessor proc, void *proc_cls)
1061 struct Plugin *plugin = cls;
1063 MYSQL_BIND cbind[1];
1065 unsigned long hashSize;
1066 unsigned long hashSize2;
1067 unsigned long long off;
1069 GNUNET_assert (key != NULL);
1070 GNUNET_assert (NULL != proc);
1071 hashSize = sizeof (GNUNET_HashCode);
1072 hashSize2 = sizeof (GNUNET_HashCode);
1073 memset (cbind, 0, sizeof (cbind));
1075 cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
1076 cbind[0].buffer = &total;
1077 cbind[0].is_unsigned = GNUNET_NO;
1083 prepared_statement_run_select (plugin,
1085 count_entry_by_hash_vhash_and_type, 1,
1086 cbind, MYSQL_TYPE_BLOB, key, hashSize,
1087 &hashSize, MYSQL_TYPE_BLOB, vhash,
1088 hashSize2, &hashSize2, MYSQL_TYPE_LONG,
1089 &type, GNUNET_YES, -1);
1094 prepared_statement_run_select (plugin,
1095 plugin->count_entry_by_hash_and_type,
1097 MYSQL_TYPE_BLOB, key, hashSize,
1098 &hashSize, MYSQL_TYPE_LONG, &type,
1107 prepared_statement_run_select (plugin,
1108 plugin->count_entry_by_hash_and_vhash,
1110 MYSQL_TYPE_BLOB, key, hashSize,
1111 &hashSize, MYSQL_TYPE_BLOB, vhash,
1112 hashSize2, &hashSize2, -1);
1118 prepared_statement_run_select (plugin,
1119 plugin->count_entry_by_hash,
1121 MYSQL_TYPE_BLOB, key, hashSize,
1125 if ((ret != GNUNET_OK) || (0 >= total))
1127 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1130 offset = offset % total;
1131 off = (unsigned long long) offset;
1133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1134 "Obtaining %llu/%lld result for GET `%s'\n",
1135 off, total, GNUNET_h2s (key));
1138 if (type != GNUNET_BLOCK_TYPE_ANY)
1142 execute_select (plugin,
1143 plugin->select_entry_by_hash_vhash_and_type,
1145 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1146 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
1147 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1148 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1152 execute_select (plugin,
1153 plugin->select_entry_by_hash_and_type,
1155 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1156 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1157 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1164 execute_select (plugin,
1165 plugin->select_entry_by_hash_and_vhash,
1167 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1168 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
1169 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1173 execute_select (plugin,
1174 plugin->select_entry_by_hash,
1176 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1177 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1184 * Get a zero-anonymity datum from the datastore.
1186 * @param cls our "struct Plugin*"
1187 * @param offset offset of the result
1188 * @param type entries of which type should be considered?
1189 * Use 0 for any type.
1190 * @param proc function to call on a matching value or NULL
1191 * @param proc_cls closure for iter
1194 mysql_plugin_get_zero_anonymity (void *cls,
1196 enum GNUNET_BLOCK_Type type,
1197 PluginDatumProcessor proc, void *proc_cls)
1199 struct Plugin *plugin = cls;
1200 unsigned long long rvalue =
1201 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
1204 execute_select (plugin,
1207 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1208 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
1209 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1210 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
1215 * Context for 'repl_proc' function.
1223 struct Plugin *plugin;
1226 * Function to call for the result (or the NULL).
1228 PluginDatumProcessor proc;
1238 * Wrapper for the processor for 'mysql_plugin_get_replication'.
1239 * Decrements the replication counter and calls the original
1242 * @param cls closure
1243 * @param key key for the content
1244 * @param size number of bytes in data
1245 * @param data content stored
1246 * @param type type of the content
1247 * @param priority priority of the content
1248 * @param anonymity anonymity-level for the content
1249 * @param expiration expiration time for the content
1250 * @param uid unique identifier for the datum;
1251 * maybe 0 if no unique identifier is available
1253 * @return GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue
1254 * (continue on call to "next", of course),
1255 * GNUNET_NO to delete the item and continue (if supported)
1258 repl_proc (void *cls,
1259 const GNUNET_HashCode * key,
1262 enum GNUNET_BLOCK_Type type,
1265 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1267 struct ReplCtx *rc = cls;
1268 struct Plugin *plugin = rc->plugin;
1269 unsigned long long oid;
1273 ret = rc->proc (rc->proc_cls,
1274 key, size, data, type, priority, anonymity, expiration, uid);
1277 oid = (unsigned long long) uid;
1278 iret = prepared_statement_run (plugin,
1281 MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1);
1282 if (iret == GNUNET_SYSERR)
1284 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1285 "Failed to reduce replication counter\n");
1286 return GNUNET_SYSERR;
1294 * Get a random item for replication. Returns a single, not expired,
1295 * random item from those with the highest replication counters. The
1296 * item's replication counter is decremented by one IF it was positive
1297 * before. Call 'proc' with all values ZERO or NULL if the datastore
1300 * @param cls closure
1301 * @param proc function to call the value (once only).
1302 * @param proc_cls closure for proc
1305 mysql_plugin_get_replication (void *cls,
1306 PluginDatumProcessor proc, void *proc_cls)
1308 struct Plugin *plugin = cls;
1310 unsigned long long rvalue;
1316 rc.proc_cls = proc_cls;
1317 memset (&results, 0, sizeof (results));
1318 results.buffer_type = MYSQL_TYPE_LONG;
1319 results.buffer = &repl;
1320 results.is_unsigned = GNUNET_YES;
1323 prepared_statement_run_select (plugin, plugin->max_repl, 1, &results, -1))
1325 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1330 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
1332 execute_select (plugin, plugin->select_replication, &repl_proc, &rc,
1333 MYSQL_TYPE_LONG, &repl, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1334 &rvalue, GNUNET_YES, MYSQL_TYPE_LONG, &repl, GNUNET_YES,
1335 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
1341 * Context for 'expi_proc' function.
1349 struct Plugin *plugin;
1352 * Function to call for the result (or the NULL).
1354 PluginDatumProcessor proc;
1365 * Wrapper for the processor for 'mysql_plugin_get_expiration'.
1366 * If no expired value was found, we do a second query for
1367 * low-priority content.
1369 * @param cls closure
1370 * @param key key for the content
1371 * @param size number of bytes in data
1372 * @param data content stored
1373 * @param type type of the content
1374 * @param priority priority of the content
1375 * @param anonymity anonymity-level for the content
1376 * @param expiration expiration time for the content
1377 * @param uid unique identifier for the datum;
1378 * maybe 0 if no unique identifier is available
1380 * @return GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue
1381 * (continue on call to "next", of course),
1382 * GNUNET_NO to delete the item and continue (if supported)
1385 expi_proc (void *cls,
1386 const GNUNET_HashCode * key,
1389 enum GNUNET_BLOCK_Type type,
1392 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1394 struct ExpiCtx *rc = cls;
1395 struct Plugin *plugin = rc->plugin;
1399 execute_select (plugin,
1400 plugin->select_priority, rc->proc, rc->proc_cls, -1);
1401 return GNUNET_SYSERR;
1403 return rc->proc (rc->proc_cls,
1404 key, size, data, type, priority, anonymity, expiration, uid);
1409 * Get a random item for expiration.
1410 * Call 'proc' with all values ZERO or NULL if the datastore is empty.
1412 * @param cls closure
1413 * @param proc function to call the value (once only).
1414 * @param proc_cls closure for proc
1417 mysql_plugin_get_expiration (void *cls,
1418 PluginDatumProcessor proc, void *proc_cls)
1420 struct Plugin *plugin = cls;
1426 rc.proc_cls = proc_cls;
1427 nt = (long long) GNUNET_TIME_absolute_get ().abs_value;
1428 execute_select (plugin,
1429 plugin->select_expiration,
1430 expi_proc, &rc, MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1);
1438 * @param cls the "struct Plugin*"
1441 mysql_plugin_drop (void *cls)
1443 struct Plugin *plugin = cls;
1445 if (GNUNET_OK != run_statement (plugin, "DROP TABLE gn090"))
1447 plugin->env->duc (plugin->env->cls, 0);
1452 * Entry point for the plugin.
1454 * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
1455 * @return our "struct Plugin*"
1458 libgnunet_plugin_datastore_mysql_init (void *cls)
1460 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
1461 struct GNUNET_DATASTORE_PluginFunctions *api;
1462 struct Plugin *plugin;
1464 plugin = GNUNET_malloc (sizeof (struct Plugin));
1466 plugin->cnffile = get_my_cnf_path (env->cfg);
1467 if (GNUNET_OK != iopen (plugin))
1470 GNUNET_free_non_null (plugin->cnffile);
1471 GNUNET_free (plugin);
1474 #define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) )
1475 #define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b)))
1476 if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 ("
1477 " repl INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1478 " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1479 " prio INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1480 " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1481 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0,"
1482 " rvalue BIGINT UNSIGNED NOT NULL,"
1483 " hash BINARY(64) NOT NULL DEFAULT '',"
1484 " vhash BINARY(64) NOT NULL DEFAULT '',"
1485 " value BLOB NOT NULL DEFAULT '',"
1486 " uid BIGINT NOT NULL AUTO_INCREMENT,"
1487 " PRIMARY KEY (uid),"
1488 " INDEX idx_hash (hash(64)),"
1489 " INDEX idx_hash_uid (hash(64),uid),"
1490 " INDEX idx_hash_vhash (hash(64),vhash(64)),"
1491 " INDEX idx_hash_type_uid (hash(64),type,rvalue),"
1492 " INDEX idx_prio (prio),"
1493 " INDEX idx_repl_rvalue (repl,rvalue),"
1494 " INDEX idx_expire (expire),"
1495 " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
1496 ") ENGINE=InnoDB") ||
1497 MRUNS ("SET AUTOCOMMIT = 1") ||
1498 PINIT (plugin->insert_entry, INSERT_ENTRY) ||
1499 PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
1500 PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
1501 PINIT (plugin->select_entry_by_hash_and_vhash,
1502 SELECT_ENTRY_BY_HASH_AND_VHASH) ||
1503 PINIT (plugin->select_entry_by_hash_and_type,
1504 SELECT_ENTRY_BY_HASH_AND_TYPE) ||
1505 PINIT (plugin->select_entry_by_hash_vhash_and_type,
1506 SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE) ||
1507 PINIT (plugin->count_entry_by_hash, COUNT_ENTRY_BY_HASH) ||
1508 PINIT (plugin->get_size, SELECT_SIZE) ||
1509 PINIT (plugin->count_entry_by_hash_and_vhash,
1510 COUNT_ENTRY_BY_HASH_AND_VHASH) ||
1511 PINIT (plugin->count_entry_by_hash_and_type, COUNT_ENTRY_BY_HASH_AND_TYPE)
1512 || PINIT (plugin->count_entry_by_hash_vhash_and_type,
1513 COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE) ||
1514 PINIT (plugin->update_entry, UPDATE_ENTRY) ||
1515 PINIT (plugin->dec_repl, DEC_REPL) ||
1516 PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) ||
1517 PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) ||
1518 PINIT (plugin->select_priority, SELECT_IT_PRIORITY) ||
1519 PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
1520 PINIT (plugin->select_replication, SELECT_IT_REPLICATION))
1523 GNUNET_free_non_null (plugin->cnffile);
1524 GNUNET_free (plugin);
1530 api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
1532 api->estimate_size = &mysql_plugin_estimate_size;
1533 api->put = &mysql_plugin_put;
1534 api->update = &mysql_plugin_update;
1535 api->get_key = &mysql_plugin_get_key;
1536 api->get_replication = &mysql_plugin_get_replication;
1537 api->get_expiration = &mysql_plugin_get_expiration;
1538 api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity;
1539 api->drop = &mysql_plugin_drop;
1540 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
1541 "mysql", _("Mysql database running\n"));
1547 * Exit point from the plugin.
1548 * @param cls our "struct Plugin*"
1549 * @return always NULL
1552 libgnunet_plugin_datastore_mysql_done (void *cls)
1554 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1555 struct Plugin *plugin = api->cls;
1556 struct GNUNET_MysqlStatementHandle *s;
1559 while (NULL != (s = plugin->shead))
1561 GNUNET_CONTAINER_DLL_remove (plugin->shead, plugin->stail, s);
1562 GNUNET_free (s->query);
1565 GNUNET_free_non_null (plugin->cnffile);
1566 GNUNET_free (plugin);
1568 mysql_library_end ();
1572 /* end of plugin_datastore_mysql.c */