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;
164 * Context for the universal iterator.
166 struct NextRequestClosure;
169 * Type of a function that will prepare
170 * the next iteration.
173 * @param nc the next context; NULL for the last
174 * call which gives the callback a chance to
175 * clean up the closure
176 * @return GNUNET_OK on success, GNUNET_NO if there are
177 * no more values, GNUNET_SYSERR on error
179 typedef int (*PrepareFunction)(void *cls,
180 struct NextRequestClosure *nc);
183 struct NextRequestClosure
185 struct Plugin *plugin;
187 struct GNUNET_TIME_Absolute now;
190 * Function to call to prepare the next
193 PrepareFunction prep;
202 enum GNUNET_BLOCK_Type type;
204 PluginIterator dviter;
215 * Context for all functions in this plugin.
220 * Our execution environment.
222 struct GNUNET_DATASTORE_PluginEnvironment *env;
225 * Handle to talk to MySQL.
230 * We keep all prepared statements in a DLL. This is the head.
232 struct GNUNET_MysqlStatementHandle *shead;
235 * We keep all prepared statements in a DLL. This is the tail.
237 struct GNUNET_MysqlStatementHandle *stail;
240 * Filename of "my.cnf" (msyql configuration).
245 * Closure of the 'next_task' (must be freed if 'next_task' is cancelled).
247 struct NextRequestClosure *next_task_nc;
250 * Pending task with scheduler for running the next request.
252 GNUNET_SCHEDULER_TaskIdentifier next_task;
255 * Prepared statements.
257 #define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?)"
258 struct GNUNET_MysqlStatementHandle *insert_entry;
260 #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
261 struct GNUNET_MysqlStatementHandle *delete_entry_by_uid;
263 #define COUNT_ENTRY_BY_HASH "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash) WHERE hash=?"
264 struct GNUNET_MysqlStatementHandle *count_entry_by_hash;
266 #define SELECT_ENTRY_BY_HASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_uid) WHERE hash=? ORDER BY uid LIMIT 1 OFFSET ?"
267 struct GNUNET_MysqlStatementHandle *select_entry_by_hash;
269 #define COUNT_ENTRY_BY_HASH_AND_VHASH "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=?"
270 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_vhash;
272 #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 ?"
273 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_vhash;
275 #define COUNT_ENTRY_BY_HASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=?"
276 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_type;
278 #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 ?"
279 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_type;
281 #define COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=?"
282 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_vhash_and_type;
284 #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 ?"
285 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_vhash_and_type;
287 #define UPDATE_ENTRY "UPDATE gn090 FORCE INDEX (uid) SET prio=prio+?,expire=IF(expire>=?,expire,?) WHERE uid=? LIMIT 1"
288 struct GNUNET_MysqlStatementHandle *update_entry;
290 #define SELECT_SIZE "SELECT SUM(BIT_LENGTH(value) DIV 8) FROM gn090"
291 struct GNUNET_MysqlStatementHandle *get_size;
293 #define SELECT_IT_NON_ANONYMOUS "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX(idx_anonLevel_uid) WHERE anonLevel=0 ORDER BY uid DESC LIMIT 1 OFFSET ?"
294 struct GNUNET_MysqlStatementHandle *zero_iter;
296 #define SELECT_IT_EXPIRATION "(SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX(idx_expire_prio) WHERE expire < ? ORDER BY prio ASC LIMIT 1) "\
298 "(SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX(idx_prio) ORDER BY prio ASC LIMIT 1) "\
299 "ORDER BY expire ASC LIMIT 1"
300 struct GNUNET_MysqlStatementHandle *select_expiration;
302 #define SELECT_IT_REPLICATION "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX(idx_repl) ORDER BY repl DESC,RAND() LIMIT 1"
303 struct GNUNET_MysqlStatementHandle *select_replication;
309 * Obtain the location of ".my.cnf".
311 * @param cfg our configuration
312 * @return NULL on error
315 get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
326 pw = getpwuid (getuid ());
329 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
334 GNUNET_CONFIGURATION_have_value (cfg,
335 "datastore-mysql", "CONFIG"))
337 GNUNET_assert (GNUNET_OK ==
338 GNUNET_CONFIGURATION_get_value_filename (cfg,
339 "datastore-mysql", "CONFIG", &cnffile));
340 configured = GNUNET_YES;
344 home_dir = GNUNET_strdup (pw->pw_dir);
346 home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
347 plibc_conv_to_win_path ("~/", home_dir);
349 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
350 GNUNET_free (home_dir);
351 configured = GNUNET_NO;
353 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
354 _("Trying to use file `%s' for MySQL configuration.\n"),
356 if ((0 != STAT (cnffile, &st)) ||
357 (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode)))
359 if (configured == GNUNET_YES)
360 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
361 _("Could not access file `%s': %s\n"), cnffile,
363 GNUNET_free (cnffile);
372 * Free a prepared statement.
374 * @param plugin plugin context
375 * @param s prepared statement
378 prepared_statement_destroy (struct Plugin *plugin,
379 struct GNUNET_MysqlStatementHandle
382 GNUNET_CONTAINER_DLL_remove (plugin->shead,
386 mysql_stmt_close (s->statement);
387 GNUNET_free (s->query);
393 * Close database connection and all prepared statements (we got a DB
397 iclose (struct Plugin *plugin)
399 struct GNUNET_MysqlStatementHandle *spos;
401 spos = plugin->shead;
402 while (NULL != plugin->shead)
403 prepared_statement_destroy (plugin,
405 if (plugin->dbf != NULL)
407 mysql_close (plugin->dbf);
415 * Open the connection with the database (and initialize
416 * our default options).
418 * @return GNUNET_OK on success
421 iopen (struct Plugin *ret)
426 char *mysql_password;
427 unsigned long long mysql_port;
429 unsigned int timeout;
431 ret->dbf = mysql_init (NULL);
432 if (ret->dbf == NULL)
433 return GNUNET_SYSERR;
434 if (ret->cnffile != NULL)
435 mysql_options (ret->dbf, MYSQL_READ_DEFAULT_FILE, ret->cnffile);
436 mysql_options (ret->dbf, MYSQL_READ_DEFAULT_GROUP, "client");
438 mysql_options (ret->dbf, MYSQL_OPT_RECONNECT, &reconnect);
439 mysql_options (ret->dbf,
440 MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
441 mysql_options(ret->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
442 timeout = 60; /* in seconds */
443 mysql_options (ret->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
444 mysql_options (ret->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
446 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
447 "datastore-mysql", "DATABASE"))
448 GNUNET_assert (GNUNET_OK ==
449 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
450 "datastore-mysql", "DATABASE",
453 mysql_dbname = GNUNET_strdup ("gnunet");
455 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
456 "datastore-mysql", "USER"))
458 GNUNET_assert (GNUNET_OK ==
459 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
460 "datastore-mysql", "USER",
463 mysql_password = NULL;
464 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
465 "datastore-mysql", "PASSWORD"))
467 GNUNET_assert (GNUNET_OK ==
468 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
469 "datastore-mysql", "PASSWORD",
473 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
474 "datastore-mysql", "HOST"))
476 GNUNET_assert (GNUNET_OK ==
477 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
478 "datastore-mysql", "HOST",
482 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
483 "datastore-mysql", "PORT"))
485 GNUNET_assert (GNUNET_OK ==
486 GNUNET_CONFIGURATION_get_value_number (ret->env->cfg, "datastore-mysql",
487 "PORT", &mysql_port));
490 GNUNET_assert (mysql_dbname != NULL);
491 mysql_real_connect (ret->dbf, mysql_server, mysql_user, mysql_password,
492 mysql_dbname, (unsigned int) mysql_port, NULL,
493 CLIENT_IGNORE_SIGPIPE);
494 GNUNET_free_non_null (mysql_server);
495 GNUNET_free_non_null (mysql_user);
496 GNUNET_free_non_null (mysql_password);
497 GNUNET_free (mysql_dbname);
498 if (mysql_error (ret->dbf)[0])
500 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
501 "mysql_real_connect", ret);
502 return GNUNET_SYSERR;
509 * Run the given MySQL statement.
511 * @param plugin plugin context
512 * @param statement SQL statement to run
513 * @return GNUNET_OK on success, GNUNET_SYSERR on error
516 run_statement (struct Plugin *plugin,
517 const char *statement)
519 if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
520 return GNUNET_SYSERR;
521 mysql_query (plugin->dbf, statement);
522 if (mysql_error (plugin->dbf)[0])
524 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
525 "mysql_query", plugin);
527 return GNUNET_SYSERR;
534 * Create a prepared statement.
536 * @param plugin plugin context
537 * @param statement SQL statement text to prepare
538 * @return NULL on error
540 static struct GNUNET_MysqlStatementHandle *
541 prepared_statement_create (struct Plugin *plugin,
542 const char *statement)
544 struct GNUNET_MysqlStatementHandle *ret;
546 ret = GNUNET_malloc (sizeof (struct GNUNET_MysqlStatementHandle));
547 ret->query = GNUNET_strdup (statement);
548 GNUNET_CONTAINER_DLL_insert (plugin->shead,
556 * Prepare a statement for running.
558 * @param plugin plugin context
559 * @param ret handle to prepared statement
560 * @return GNUNET_OK on success
563 prepare_statement (struct Plugin *plugin,
564 struct GNUNET_MysqlStatementHandle *ret)
566 if (GNUNET_YES == ret->valid)
568 if ((NULL == plugin->dbf) &&
569 (GNUNET_OK != iopen (plugin)))
570 return GNUNET_SYSERR;
571 ret->statement = mysql_stmt_init (plugin->dbf);
572 if (ret->statement == NULL)
575 return GNUNET_SYSERR;
577 if (mysql_stmt_prepare (ret->statement,
579 strlen (ret->query)))
581 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
582 "mysql_stmt_prepare",
584 mysql_stmt_close (ret->statement);
585 ret->statement = NULL;
587 return GNUNET_SYSERR;
589 ret->valid = GNUNET_YES;
596 * Bind the parameters for the given MySQL statement
599 * @param plugin plugin context
600 * @param s statement to bind and run
601 * @param ap arguments for the binding
602 * @return GNUNET_SYSERR on error, GNUNET_OK on success
605 init_params (struct Plugin *plugin,
606 struct GNUNET_MysqlStatementHandle *s,
609 MYSQL_BIND qbind[MAX_PARAM];
612 enum enum_field_types ft;
614 pc = mysql_stmt_param_count (s->statement);
617 /* increase internal constant! */
619 return GNUNET_SYSERR;
621 memset (qbind, 0, sizeof (qbind));
624 while ((pc > 0) && (-1 != (int) (ft = va_arg (ap, enum enum_field_types))))
626 qbind[off].buffer_type = ft;
629 case MYSQL_TYPE_FLOAT:
630 qbind[off].buffer = va_arg (ap, float *);
632 case MYSQL_TYPE_LONGLONG:
633 qbind[off].buffer = va_arg (ap, unsigned long long *);
634 qbind[off].is_unsigned = va_arg (ap, int);
636 case MYSQL_TYPE_LONG:
637 qbind[off].buffer = va_arg (ap, unsigned int *);
638 qbind[off].is_unsigned = va_arg (ap, int);
640 case MYSQL_TYPE_VAR_STRING:
641 case MYSQL_TYPE_STRING:
642 case MYSQL_TYPE_BLOB:
643 qbind[off].buffer = va_arg (ap, void *);
644 qbind[off].buffer_length = va_arg (ap, unsigned long);
645 qbind[off].length = va_arg (ap, unsigned long *);
648 /* unsupported type */
650 return GNUNET_SYSERR;
655 if (! ( (pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1) ) )
658 return GNUNET_SYSERR;
660 if (mysql_stmt_bind_param (s->statement, qbind))
662 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
663 _("`%s' failed at %s:%d with error: %s\n"),
664 "mysql_stmt_bind_param",
665 __FILE__, __LINE__, mysql_stmt_error (s->statement));
667 return GNUNET_SYSERR;
669 if (mysql_stmt_execute (s->statement))
671 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
672 _("`%s' failed at %s:%d with error: %s\n"),
673 "mysql_stmt_execute",
674 __FILE__, __LINE__, mysql_stmt_error (s->statement));
676 return GNUNET_SYSERR;
682 * Type of a callback that will be called for each
683 * data set returned from MySQL.
685 * @param cls user-defined argument
686 * @param num_values number of elements in values
687 * @param values values returned by MySQL
688 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
690 typedef int (*GNUNET_MysqlDataProcessor) (void *cls,
691 unsigned int num_values,
696 * Run a prepared SELECT statement.
698 * @param plugin plugin context
699 * @param s statement to run
700 * @param result_size number of elements in results array
701 * @param results pointer to already initialized MYSQL_BIND
702 * array (of sufficient size) for passing results
703 * @param processor function to call on each result
704 * @param processor_cls extra argument to processor
705 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
706 * values (size + buffer-reference for pointers); terminated
708 * @return GNUNET_SYSERR on error, otherwise
709 * the number of successfully affected (or queried) rows
712 prepared_statement_run_select (struct Plugin *plugin,
713 struct GNUNET_MysqlStatementHandle *s,
714 unsigned int result_size,
716 GNUNET_MysqlDataProcessor processor, void *processor_cls,
724 if (GNUNET_OK != prepare_statement (plugin, s))
727 return GNUNET_SYSERR;
729 va_start (ap, processor_cls);
730 if (GNUNET_OK != init_params (plugin, s, ap))
734 return GNUNET_SYSERR;
737 rsize = mysql_stmt_field_count (s->statement);
738 if (rsize > result_size)
741 return GNUNET_SYSERR;
743 if (mysql_stmt_bind_result (s->statement, results))
745 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
746 _("`%s' failed at %s:%d with error: %s\n"),
747 "mysql_stmt_bind_result",
748 __FILE__, __LINE__, mysql_stmt_error (s->statement));
750 return GNUNET_SYSERR;
756 ret = mysql_stmt_fetch (s->statement);
757 if (ret == MYSQL_NO_DATA)
761 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
762 _("`%s' failed at %s:%d with error: %s\n"),
764 __FILE__, __LINE__, mysql_stmt_error (s->statement));
766 return GNUNET_SYSERR;
768 if (processor != NULL)
769 if (GNUNET_OK != processor (processor_cls, rsize, results))
773 mysql_stmt_reset (s->statement);
779 * Run a prepared statement that does NOT produce results.
781 * @param plugin plugin context
782 * @param s statement to run
783 * @param insert_id NULL or address where to store the row ID of whatever
784 * was inserted (only for INSERT statements!)
785 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
786 * values (size + buffer-reference for pointers); terminated
788 * @return GNUNET_SYSERR on error, otherwise
789 * the number of successfully affected rows
792 prepared_statement_run (struct Plugin *plugin,
793 struct GNUNET_MysqlStatementHandle *s,
794 unsigned long long *insert_id, ...)
799 if (GNUNET_OK != prepare_statement (plugin, s))
800 return GNUNET_SYSERR;
801 va_start (ap, insert_id);
802 if (GNUNET_OK != init_params (plugin, s, ap))
805 return GNUNET_SYSERR;
808 affected = mysql_stmt_affected_rows (s->statement);
809 if (NULL != insert_id)
810 *insert_id = (unsigned long long) mysql_stmt_insert_id (s->statement);
811 mysql_stmt_reset (s->statement);
817 * Delete an entry from the gn090 table.
819 * @param plugin plugin context
820 * @param uid unique ID of the entry to delete
821 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error
824 do_delete_entry (struct Plugin *plugin,
825 unsigned long long uid)
830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
831 "Deleting value %llu from gn090 table\n",
834 ret = prepared_statement_run (plugin,
835 plugin->delete_entry_by_uid,
837 MYSQL_TYPE_LONGLONG, uid, GNUNET_YES,
841 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
842 "Deleting value %llu from gn090 table failed\n",
849 * Function that simply returns GNUNET_OK
851 * @param cls closure, not used
852 * @param num_values not used
853 * @param values not used
857 return_ok (void *cls,
858 unsigned int num_values,
866 * Continuation of "mysql_next_request".
868 * @param next_cls the next context
869 * @param tc the task context (unused)
872 mysql_next_request_cont (void *next_cls,
873 const struct GNUNET_SCHEDULER_TaskContext *tc)
875 struct NextRequestClosure *nrc = next_cls;
876 struct Plugin *plugin;
879 unsigned int priority;
880 unsigned int anonymity;
881 unsigned long long exp;
882 unsigned long hashSize;
884 unsigned long long uid;
885 char value[GNUNET_DATASTORE_MAX_VALUE_SIZE];
887 struct GNUNET_TIME_Absolute expiration;
888 MYSQL_BIND *rbind = nrc->rbind;
890 plugin = nrc->plugin;
891 plugin->next_task = GNUNET_SCHEDULER_NO_TASK;
892 plugin->next_task_nc = NULL;
894 if (GNUNET_YES == nrc->end_it)
896 GNUNET_assert (nrc->plugin->next_task == GNUNET_SCHEDULER_NO_TASK);
897 nrc->now = GNUNET_TIME_absolute_get ();
898 hashSize = sizeof (GNUNET_HashCode);
899 memset (nrc->rbind, 0, sizeof (nrc->rbind));
901 rbind[0].buffer_type = MYSQL_TYPE_LONG;
902 rbind[0].buffer = &type;
903 rbind[0].is_unsigned = 1;
904 rbind[1].buffer_type = MYSQL_TYPE_LONG;
905 rbind[1].buffer = &priority;
906 rbind[1].is_unsigned = 1;
907 rbind[2].buffer_type = MYSQL_TYPE_LONG;
908 rbind[2].buffer = &anonymity;
909 rbind[2].is_unsigned = 1;
910 rbind[3].buffer_type = MYSQL_TYPE_LONGLONG;
911 rbind[3].buffer = &exp;
912 rbind[3].is_unsigned = 1;
913 rbind[4].buffer_type = MYSQL_TYPE_BLOB;
914 rbind[4].buffer = &key;
915 rbind[4].buffer_length = hashSize;
916 rbind[4].length = &hashSize;
917 rbind[5].buffer_type = MYSQL_TYPE_BLOB;
918 rbind[5].buffer = value;
919 rbind[5].buffer_length = size = sizeof (value);
920 rbind[5].length = &size;
921 rbind[6].buffer_type = MYSQL_TYPE_LONGLONG;
922 rbind[6].buffer = &uid;
923 rbind[6].is_unsigned = 1;
925 if (GNUNET_OK != nrc->prep (nrc->prep_cls,
928 GNUNET_assert (nrc->plugin->next_task == GNUNET_SCHEDULER_NO_TASK);
929 GNUNET_assert (size <= sizeof(value));
930 if ( (rbind[4].buffer_length != sizeof (GNUNET_HashCode)) ||
931 (hashSize != sizeof (GNUNET_HashCode)) )
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
938 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %llu selecting from gn090 table\n",
945 expiration.abs_value = exp;
946 ret = nrc->dviter (nrc->dviter_cls, nrc,
949 type, priority, anonymity, expiration,
951 if (ret == GNUNET_SYSERR)
953 nrc->end_it = GNUNET_YES;
956 if (ret == GNUNET_NO)
958 do_delete_entry (plugin, uid);
960 plugin->env->duc (plugin->env->cls,
965 /* call dviter with "end of set" */
966 GNUNET_assert (nrc->plugin->next_task == GNUNET_SCHEDULER_NO_TASK);
967 nrc->dviter (nrc->dviter_cls,
968 NULL, NULL, 0, NULL, 0, 0, 0,
969 GNUNET_TIME_UNIT_ZERO_ABS, 0);
970 GNUNET_assert (nrc->plugin->next_task == GNUNET_SCHEDULER_NO_TASK);
971 nrc->prep (nrc->prep_cls, NULL);
972 GNUNET_assert (nrc->plugin->next_task == GNUNET_SCHEDULER_NO_TASK);
978 * Function invoked on behalf of a "PluginIterator"
979 * asking the database plugin to call the iterator
980 * with the next item.
982 * @param next_cls whatever argument was given
983 * to the PluginIterator as "next_cls".
984 * @param end_it set to GNUNET_YES if we
985 * should terminate the iteration early
986 * (iterator should be still called once more
987 * to signal the end of the iteration).
990 mysql_plugin_next_request (void *next_cls,
993 struct NextRequestClosure *nrc = next_cls;
995 if (GNUNET_YES == end_it)
996 nrc->end_it = GNUNET_YES;
997 nrc->plugin->next_task_nc = nrc;
998 nrc->plugin->next_task = GNUNET_SCHEDULER_add_now (&mysql_next_request_cont,
1004 * Get an estimate of how much space the database is
1007 * @param cls our "struct Plugin *"
1008 * @return number of bytes used on disk
1010 static unsigned long long
1011 mysql_plugin_get_size (void *cls)
1013 struct Plugin *plugin = cls;
1014 MYSQL_BIND cbind[1];
1017 memset (cbind, 0, sizeof (cbind));
1019 cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
1020 cbind[0].buffer = &total;
1021 cbind[0].is_unsigned = GNUNET_NO;
1023 prepared_statement_run_select (plugin,
1034 * Store an item in the datastore.
1036 * @param cls closure
1037 * @param key key for the item
1038 * @param size number of bytes in data
1039 * @param data content stored
1040 * @param type type of the content
1041 * @param priority priority of the content
1042 * @param anonymity anonymity-level for the content
1043 * @param replication replication-level for the content
1044 * @param expiration expiration time for the content
1045 * @param msg set to error message
1046 * @return GNUNET_OK on success
1049 mysql_plugin_put (void *cls,
1050 const GNUNET_HashCode * key,
1053 enum GNUNET_BLOCK_Type type,
1056 uint32_t replication,
1057 struct GNUNET_TIME_Absolute expiration,
1060 struct Plugin *plugin = cls;
1061 unsigned int irepl = replication;
1062 unsigned int itype = type;
1063 unsigned int ipriority = priority;
1064 unsigned int ianonymity = anonymity;
1065 unsigned long long lexpiration = expiration.abs_value;
1066 unsigned long hashSize;
1067 unsigned long hashSize2;
1068 unsigned long lsize;
1069 GNUNET_HashCode vhash;
1071 if (size > MAX_DATUM_SIZE)
1074 return GNUNET_SYSERR;
1076 hashSize = sizeof (GNUNET_HashCode);
1077 hashSize2 = sizeof (GNUNET_HashCode);
1079 GNUNET_CRYPTO_hash (data, size, &vhash);
1081 prepared_statement_run (plugin,
1082 plugin->insert_entry,
1084 MYSQL_TYPE_LONG, &irepl, GNUNET_YES,
1085 MYSQL_TYPE_LONG, &itype, GNUNET_YES,
1086 MYSQL_TYPE_LONG, &ipriority, GNUNET_YES,
1087 MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES,
1088 MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES,
1089 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1090 MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2,
1091 MYSQL_TYPE_BLOB, data, lsize, &lsize,
1093 return GNUNET_SYSERR;
1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1096 "Inserted value `%s' with size %u into gn090 table\n",
1098 (unsigned int) size);
1101 plugin->env->duc (plugin->env->cls,
1108 * Update the priority for a particular key in the datastore. If
1109 * the expiration time in value is different than the time found in
1110 * the datastore, the higher value should be kept. For the
1111 * anonymity level, the lower value is to be used. The specified
1112 * priority should be added to the existing priority, ignoring the
1113 * priority in value.
1115 * Note that it is possible for multiple values to match this put.
1116 * In that case, all of the respective values are updated.
1118 * @param cls our "struct Plugin*"
1119 * @param uid unique identifier of the datum
1120 * @param delta by how much should the priority
1121 * change? If priority + delta < 0 the
1122 * priority should be set to 0 (never go
1124 * @param expire new expiration time should be the
1125 * MAX of any existing expiration time and
1127 * @param msg set to error message
1128 * @return GNUNET_OK on success
1131 mysql_plugin_update (void *cls,
1134 struct GNUNET_TIME_Absolute expire,
1137 struct Plugin *plugin = cls;
1138 unsigned long long vkey = uid;
1139 unsigned long long lexpire = expire.abs_value;
1143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1144 "Updating value %llu adding %d to priority and maxing exp at %llu\n",
1149 ret = prepared_statement_run (plugin,
1150 plugin->update_entry,
1152 MYSQL_TYPE_LONG, &delta, GNUNET_NO,
1153 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
1154 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
1155 MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES,
1157 if (ret != GNUNET_OK)
1159 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1160 "Failed to update value %llu\n",
1169 GNUNET_HashCode key;
1170 GNUNET_HashCode vhash;
1173 unsigned int anonymity;
1174 unsigned long long expiration;
1175 unsigned long long vkey;
1176 unsigned long long total;
1184 get_statement_prepare (void *cls,
1185 struct NextRequestClosure *nrc)
1187 struct GetContext *gc = cls;
1188 struct Plugin *plugin;
1190 unsigned long hashSize;
1197 if (gc->count == gc->total)
1199 plugin = nrc->plugin;
1200 hashSize = sizeof (GNUNET_HashCode);
1201 if (++gc->off >= gc->total)
1204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1205 "Obtaining result number %d/%lld at offset %u for GET `%s'\n",
1209 GNUNET_h2s (&gc->key));
1215 ret = prepared_statement_run_select (plugin,
1216 plugin->select_entry_by_hash_vhash_and_type,
1219 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize,
1220 MYSQL_TYPE_BLOB, &gc->vhash, hashSize, &hashSize,
1221 MYSQL_TYPE_LONG, &nrc->type, GNUNET_YES,
1222 MYSQL_TYPE_LONG, &gc->off, GNUNET_YES,
1228 prepared_statement_run_select (plugin,
1229 plugin->select_entry_by_hash_and_type,
1232 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize,
1233 MYSQL_TYPE_LONG, &nrc->type, GNUNET_YES,
1234 MYSQL_TYPE_LONG, &gc->off, GNUNET_YES,
1243 prepared_statement_run_select (plugin,
1244 plugin->select_entry_by_hash_and_vhash,
1247 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize,
1248 MYSQL_TYPE_BLOB, &gc->vhash, hashSize, &hashSize,
1249 MYSQL_TYPE_LONG, &gc->off, GNUNET_YES,
1255 prepared_statement_run_select (plugin,
1256 plugin->select_entry_by_hash,
1259 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize,
1260 MYSQL_TYPE_LONG, &gc->off, GNUNET_YES,
1270 * Iterate over the results for a particular key in the datastore.
1272 * @param cls closure
1273 * @param key maybe NULL (to match all entries)
1274 * @param vhash hash of the value, maybe NULL (to
1275 * match all values that have the right key).
1276 * Note that for DBlocks there is no difference
1277 * betwen key and vhash, but for other blocks
1279 * @param type entries of which type are relevant?
1280 * Use 0 for any type.
1281 * @param iter function to call on each matching value;
1282 * will be called once with a NULL value at the end
1283 * @param iter_cls closure for iter
1286 mysql_plugin_get (void *cls,
1287 const GNUNET_HashCode *key,
1288 const GNUNET_HashCode *vhash,
1289 enum GNUNET_BLOCK_Type type,
1290 PluginIterator iter, void *iter_cls)
1292 struct Plugin *plugin = cls;
1293 unsigned int itype = type;
1295 MYSQL_BIND cbind[1];
1296 struct GetContext *gc;
1297 struct NextRequestClosure *nrc;
1299 unsigned long hashSize;
1301 GNUNET_assert (key != NULL);
1304 hashSize = sizeof (GNUNET_HashCode);
1305 memset (cbind, 0, sizeof (cbind));
1307 cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
1308 cbind[0].buffer = &total;
1309 cbind[0].is_unsigned = GNUNET_NO;
1315 prepared_statement_run_select (plugin,
1316 plugin->count_entry_by_hash_vhash_and_type,
1319 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1320 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
1321 MYSQL_TYPE_LONG, &itype, GNUNET_YES,
1327 prepared_statement_run_select (plugin,
1328 plugin->count_entry_by_hash_and_type,
1331 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1332 MYSQL_TYPE_LONG, &itype, GNUNET_YES,
1341 prepared_statement_run_select (plugin,
1342 plugin->count_entry_by_hash_and_vhash,
1345 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1346 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
1353 prepared_statement_run_select (plugin,
1354 plugin->count_entry_by_hash,
1357 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1361 if ((ret != GNUNET_OK) || (0 >= total))
1364 NULL, NULL, 0, NULL, 0, 0, 0,
1365 GNUNET_TIME_UNIT_ZERO_ABS, 0);
1369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1370 "Iterating over %lld results for GET `%s'\n",
1374 gc = GNUNET_malloc (sizeof (struct GetContext));
1378 gc->have_vhash = GNUNET_YES;
1382 gc->off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, total);
1385 nrc = GNUNET_malloc (sizeof (struct NextRequestClosure));
1386 nrc->plugin = plugin;
1389 nrc->dviter_cls = iter_cls;
1390 nrc->prep = &get_statement_prepare;
1392 mysql_plugin_next_request (nrc, GNUNET_NO);
1397 * Run the prepared statement to get the next data item ready.
1399 * @param cls not used
1400 * @param nrc closure for the next request iterator
1401 * @return GNUNET_OK on success, GNUNET_NO if there is no additional item
1404 iterator_zero_prepare (void *cls,
1405 struct NextRequestClosure *nrc)
1407 struct Plugin *plugin;
1412 plugin = nrc->plugin;
1413 ret = prepared_statement_run_select (plugin,
1417 MYSQL_TYPE_LONG, &nrc->count, GNUNET_YES,
1425 * Select a subset of the items in the datastore and call
1426 * the given iterator for each of them.
1428 * @param cls our "struct Plugin*"
1429 * @param type entries of which type should be considered?
1430 * Use 0 for any type.
1431 * @param iter function to call on each matching value;
1432 * will be called once with a NULL value at the end
1433 * @param iter_cls closure for iter
1436 mysql_plugin_iter_zero_anonymity (void *cls,
1437 enum GNUNET_BLOCK_Type type,
1438 PluginIterator iter,
1441 struct Plugin *plugin = cls;
1442 struct NextRequestClosure *nrc;
1444 nrc = GNUNET_malloc (sizeof (struct NextRequestClosure));
1445 nrc->plugin = plugin;
1448 nrc->dviter_cls = iter_cls;
1449 nrc->prep = &iterator_zero_prepare;
1450 mysql_plugin_next_request (nrc, GNUNET_NO);
1455 * Run the SELECT statement for the replication function.
1457 * @param cls the 'struct Plugin'
1458 * @param nrc the context (not used)
1461 replication_prepare (void *cls,
1462 struct NextRequestClosure *nrc)
1464 struct Plugin *plugin = cls;
1465 unsigned long long nt;
1467 nt = (unsigned long long) nrc->now.abs_value;
1468 return prepared_statement_run_select (plugin,
1469 plugin->select_replication,
1472 MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES,
1478 * Get a random item for replication. Returns a single, not expired, random item
1479 * from those with the highest replication counters. The item's
1480 * replication counter is decremented by one IF it was positive before.
1481 * Call 'iter' with all values ZERO or NULL if the datastore is empty.
1483 * @param cls closure
1484 * @param iter function to call the value (once only).
1485 * @param iter_cls closure for iter
1488 mysql_plugin_replication_get (void *cls,
1489 PluginIterator iter, void *iter_cls)
1491 struct Plugin *plugin = cls;
1492 struct NextRequestClosure nrc;
1494 memset (&nrc, 0, sizeof (nrc));
1495 nrc.plugin = plugin;
1496 nrc.now = GNUNET_TIME_absolute_get ();
1497 nrc.prep = &replication_prepare;
1498 nrc.prep_cls = plugin;
1501 nrc.dviter_cls = iter_cls;
1502 nrc.end_it = GNUNET_NO;
1503 mysql_next_request_cont (&nrc, NULL);
1508 * Run the SELECT statement for the expiration function.
1510 * @param cls the 'struct Plugin'
1511 * @param nrc the context (not used)
1514 expiration_prepare (void *cls,
1515 struct NextRequestClosure *nrc)
1517 struct Plugin *plugin = cls;
1520 nt = (long long) nrc->now.abs_value;
1521 return prepared_statement_run_select
1523 plugin->select_expiration,
1526 MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES,
1532 * Get a random item for expiration.
1533 * Call 'iter' with all values ZERO or NULL if the datastore is empty.
1535 * @param cls closure
1536 * @param iter function to call the value (once only).
1537 * @param iter_cls closure for iter
1540 mysql_plugin_expiration_get (void *cls,
1541 PluginIterator iter, void *iter_cls)
1543 struct Plugin *plugin = cls;
1544 struct NextRequestClosure nrc;
1546 memset (&nrc, 0, sizeof (nrc));
1547 nrc.plugin = plugin;
1548 nrc.now = GNUNET_TIME_absolute_get ();
1549 nrc.prep = &expiration_prepare;
1550 nrc.prep_cls = plugin;
1553 nrc.dviter_cls = iter_cls;
1554 nrc.end_it = GNUNET_NO;
1555 mysql_next_request_cont (&nrc, NULL);
1562 * @param cls the "struct Plugin*"
1565 mysql_plugin_drop (void *cls)
1567 struct Plugin *plugin = cls;
1569 if ((GNUNET_OK != run_statement (plugin,
1570 "DROP TABLE gn090")) ||
1571 (GNUNET_OK != run_statement (plugin,
1572 "DROP TABLE gn072")))
1574 plugin->env->duc (plugin->env->cls, 0);
1579 * Entry point for the plugin.
1581 * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
1582 * @return our "struct Plugin*"
1585 libgnunet_plugin_datastore_mysql_init (void *cls)
1587 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
1588 struct GNUNET_DATASTORE_PluginFunctions *api;
1589 struct Plugin *plugin;
1591 plugin = GNUNET_malloc (sizeof (struct Plugin));
1593 plugin->cnffile = get_my_cnf_path (env->cfg);
1594 if (GNUNET_OK != iopen (plugin))
1597 GNUNET_free_non_null (plugin->cnffile);
1598 GNUNET_free (plugin);
1601 #define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) )
1602 #define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b)))
1603 if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 ("
1604 " repl INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1605 " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1606 " prio INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1607 " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1608 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0,"
1609 " hash BINARY(64) NOT NULL DEFAULT '',"
1610 " vhash BINARY(64) NOT NULL DEFAULT '',"
1611 " value BLOB NOT NULL DEFAULT ''"
1612 " uid BIGINT NOT NULL AUTO_INCREMENT"
1613 " PRIMARY KEY (uid)"
1614 " INDEX idx_hash (hash(64)),"
1615 " INDEX idx_hash_uid (hash(64),uid),"
1616 " INDEX idx_hash_vhash (hash(64),vhash(64)),"
1617 " INDEX idx_hash_type_uid (hash(64),type,uid),"
1618 " INDEX idx_prio (prio),"
1619 " INDEX idx_repl (repl),"
1620 " INDEX idx_expire_prio (expire,prio),"
1621 " INDEX idx_anonLevel_uid (anonLevel,uid)"
1622 ") ENGINE=InnoDB") ||
1623 MRUNS ("SET AUTOCOMMIT = 1") ||
1624 PINIT (plugin->insert_entry, INSERT_ENTRY) ||
1625 PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
1626 PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
1627 PINIT (plugin->select_entry_by_hash_and_vhash, SELECT_ENTRY_BY_HASH_AND_VHASH)
1628 || PINIT (plugin->select_entry_by_hash_and_type, SELECT_ENTRY_BY_HASH_AND_TYPE)
1629 || PINIT (plugin->select_entry_by_hash_vhash_and_type,
1630 SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE)
1631 || PINIT (plugin->count_entry_by_hash, COUNT_ENTRY_BY_HASH)
1632 || PINIT (plugin->get_size, SELECT_SIZE)
1633 || PINIT (plugin->count_entry_by_hash_and_vhash, COUNT_ENTRY_BY_HASH_AND_VHASH)
1634 || PINIT (plugin->count_entry_by_hash_and_type, COUNT_ENTRY_BY_HASH_AND_TYPE)
1635 || PINIT (plugin->count_entry_by_hash_vhash_and_type,
1636 COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE)
1637 || PINIT (plugin->update_entry, UPDATE_ENTRY)
1638 || PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS)
1639 || PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION)
1640 || PINIT (plugin->select_replication, SELECT_IT_REPLICATION) )
1643 GNUNET_free_non_null (plugin->cnffile);
1644 GNUNET_free (plugin);
1650 api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
1652 api->get_size = &mysql_plugin_get_size;
1653 api->put = &mysql_plugin_put;
1654 api->next_request = &mysql_plugin_next_request;
1655 api->get = &mysql_plugin_get;
1656 api->replication_get = &mysql_plugin_replication_get;
1657 api->expiration_get = &mysql_plugin_expiration_get;
1658 api->update = &mysql_plugin_update;
1659 api->iter_zero_anonymity = &mysql_plugin_iter_zero_anonymity;
1660 api->drop = &mysql_plugin_drop;
1661 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
1662 "mysql", _("Mysql database running\n"));
1668 * Exit point from the plugin.
1669 * @param cls our "struct Plugin*"
1670 * @return always NULL
1673 libgnunet_plugin_datastore_mysql_done (void *cls)
1675 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1676 struct Plugin *plugin = api->cls;
1679 if (plugin->next_task != GNUNET_SCHEDULER_NO_TASK)
1681 GNUNET_SCHEDULER_cancel (plugin->next_task);
1682 plugin->next_task = GNUNET_SCHEDULER_NO_TASK;
1683 plugin->next_task_nc->prep (plugin->next_task_nc->prep_cls, NULL);
1684 GNUNET_free (plugin->next_task_nc);
1685 plugin->next_task_nc = NULL;
1687 GNUNET_free_non_null (plugin->cnffile);
1688 GNUNET_free (plugin);
1690 mysql_library_end ();
1694 /* end of plugin_datastore_mysql.c */