![]() |
GNUnet
0.16.x
|
mysql-based datastore backend More...
#include "platform.h"
#include "gnunet_datastore_plugin.h"
#include "gnunet_util_lib.h"
#include "gnunet_mysql_lib.h"
#include "gnunet_my_lib.h"
Go to the source code of this file.
Data Structures | |
struct | Plugin |
Handle for a plugin. More... | |
struct | ReplCtx |
Context for repl_proc() function. More... | |
struct | ExpiCtx |
Context for expi_proc() function. More... | |
Macros | |
#define | MAX_DATUM_SIZE 65536 |
#define | INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)" |
Prepared statements. More... | |
#define | DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" |
#define | DELETE_ENTRY_BY_HASH_VALUE |
#define | RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid" |
#define | SELECT_ENTRY |
#define | SELECT_ENTRY_BY_HASH |
#define | SELECT_ENTRY_BY_HASH_AND_TYPE |
#define | UPDATE_ENTRY |
#define | DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?" |
#define | SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090" |
#define | SELECT_IT_NON_ANONYMOUS |
#define | SELECT_IT_EXPIRATION |
#define | SELECT_IT_PRIORITY |
#define | SELECT_IT_REPLICATION |
#define | SELECT_MAX_REPL "SELECT MAX(repl) FROM gn090" |
#define | GET_ALL_KEYS "SELECT hash from gn090" |
#define | MAX_PARAM 16 |
#define | MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a)) |
#define | PINIT(a, b) |
Functions | |
static int | do_delete_entry (struct Plugin *plugin, unsigned long long uid) |
Delete an entry from the gn090 table. More... | |
static void | mysql_plugin_estimate_size (void *cls, unsigned long long *estimate) |
Get an estimate of how much space the database is currently using. More... | |
static void | mysql_plugin_put (void *cls, const struct GNUNET_HashCode *key, bool absent, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, void *cont_cls) |
Store an item in the datastore. More... | |
static void | execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, PluginDatumProcessor proc, void *proc_cls, struct GNUNET_MY_QueryParam *params_select) |
Run the given select statement and call 'proc' on the resulting values (which must be in particular positions). More... | |
static void | mysql_plugin_get_key (void *cls, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls) |
Get one of the results for a particular key in the datastore. More... | |
static void | mysql_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls) |
Get a zero-anonymity datum from the datastore. More... | |
static int | repl_proc (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
Wrapper for the processor for mysql_plugin_get_replication(). More... | |
static void | mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc, void *proc_cls) |
Get a random item for replication. More... | |
static void | mysql_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls) |
Get all of the keys in the datastore. More... | |
static int | expi_proc (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
Wrapper for the processor for mysql_plugin_get_expiration(). More... | |
static void | mysql_plugin_get_expiration (void *cls, PluginDatumProcessor proc, void *proc_cls) |
Get a random item for expiration. More... | |
static void | mysql_plugin_drop (void *cls) |
Drop database. More... | |
static void | mysql_plugin_remove_key (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, PluginRemoveCont cont, void *cont_cls) |
Remove a particular key in the datastore. More... | |
void * | libgnunet_plugin_datastore_mysql_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_datastore_mysql_done (void *cls) |
Exit point from the plugin. More... | |
mysql-based datastore backend
NOTE: This db module does NOT work with mysql prior to 4.1 since it uses prepared statements. MySQL 5.0.46 promises to fix a bug in MyISAM that is causing us grief. At the time of this writing, that version is yet to be released. In anticipation, the code will use MyISAM with 5.0.46 (and higher). If you run such a version, please run "make check" to verify that the MySQL bug was actually fixed in your version (and if not, change the code below to use MyISAM for gn071).
HIGHLIGHTS
Pros
MANUAL SETUP INSTRUCTIONS
1) in gnunet.conf, set
[datastore] DATABASE = "mysql"
2) Then access mysql as root,
$ mysql -u root -p
and do the following. [You should replace $USER with the username that will be running the gnunetd process].
CREATE DATABASE gnunet; GRANT select,insert,update,delete,create,alter,drop,create temporary tables ON gnunet.* TO $USER@localhost; SET PASSWORD FOR $USER@localhost=PASSWORD('$the_password_you_like'); FLUSH PRIVILEGES;
3) In the $HOME directory of $USER, create a ".my.cnf" file with the following lines
[client] user=$USER password=$the_password_you_like
That's it. Note that .my.cnf file is a security risk unless its on a safe partition etc. The $HOME/.my.cnf can of course be a symbolic link. Even greater security risk can be achieved by setting no password for $USER. Luckily $USER has only privileges to mess up GNUnet's tables, nothing else (unless you give them more, of course).
4) Still, perhaps you should briefly try if the DB connection works. First, login as $USER. Then use,
$ mysql -u $USER -p $the_password_you_like mysql> use gnunet;
If you get the message "Database changed" it probably works.
[If you get "ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" it may be resolvable by "ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock" so there may be some additional trouble depending on your mysql setup.]
REPAIRING TABLES
mysql> REPAIR TABLE gn090;
PROBLEMS?
If you have problems related to the mysql module, your best friend is probably the mysql manual. The first thing to check is that mysql is basically operational, that you can connect to it, create tables, issue queries etc.
Definition in file plugin_datastore_mysql.c.
#define MAX_DATUM_SIZE 65536 |
Definition at line 126 of file plugin_datastore_mysql.c.
#define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)" |
Prepared statements.
Definition at line 147 of file plugin_datastore_mysql.c.
#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" |
Definition at line 151 of file plugin_datastore_mysql.c.
#define DELETE_ENTRY_BY_HASH_VALUE |
Definition at line 154 of file plugin_datastore_mysql.c.
Definition at line 160 of file plugin_datastore_mysql.c.
#define SELECT_ENTRY |
Definition at line 162 of file plugin_datastore_mysql.c.
#define SELECT_ENTRY_BY_HASH |
Definition at line 168 of file plugin_datastore_mysql.c.
#define SELECT_ENTRY_BY_HASH_AND_TYPE |
Definition at line 176 of file plugin_datastore_mysql.c.
#define UPDATE_ENTRY |
Definition at line 185 of file plugin_datastore_mysql.c.
#define DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?" |
Definition at line 192 of file plugin_datastore_mysql.c.
#define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090" |
Definition at line 195 of file plugin_datastore_mysql.c.
#define SELECT_IT_NON_ANONYMOUS |
Definition at line 198 of file plugin_datastore_mysql.c.
#define SELECT_IT_EXPIRATION |
Definition at line 206 of file plugin_datastore_mysql.c.
#define SELECT_IT_PRIORITY |
Definition at line 212 of file plugin_datastore_mysql.c.
#define SELECT_IT_REPLICATION |
Definition at line 217 of file plugin_datastore_mysql.c.
#define SELECT_MAX_REPL "SELECT MAX(repl) FROM gn090" |
Definition at line 226 of file plugin_datastore_mysql.c.
#define GET_ALL_KEYS "SELECT hash from gn090" |
Definition at line 229 of file plugin_datastore_mysql.c.
#define MAX_PARAM 16 |
Definition at line 233 of file plugin_datastore_mysql.c.
#define MRUNS | ( | a | ) | (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a)) |
#define PINIT | ( | a, | |
b | |||
) |
|
static |
Delete an entry from the gn090 table.
plugin | plugin context |
uid | unique ID of the entry to delete |
Definition at line 243 of file plugin_datastore_mysql.c.
References Plugin::delete_entry_by_uid, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint64(), GNUNET_OK, Plugin::mc, plugin, and ret.
Referenced by execute_select().
|
static |
Get an estimate of how much space the database is currently using.
cls | our struct Plugin * |
Definition at line 278 of file plugin_datastore_mysql.c.
References Plugin::get_size, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_query_param_end, GNUNET_MY_result_spec_end, GNUNET_MY_result_spec_uint64(), GNUNET_NO, GNUNET_OK, Plugin::mc, plugin, and ret.
Referenced by libgnunet_plugin_datastore_mysql_init().
|
static |
Store an item in the datastore.
cls | closure |
key | key for the item |
absent | true if the key was not found in the bloom filter |
size | number of bytes in data |
data | content stored |
type | type of the content |
priority | priority of the content |
anonymity | anonymity-level for the content |
replication | replication-level for the content |
expiration | expiration time for the content |
cont | continuation called with success or failure status |
cont_cls | closure for cont |
Definition at line 331 of file plugin_datastore_mysql.c.
References _, anonymity, GNUNET_DATACACHE_PluginEnvironment::cls, data, Plugin::env, expiration, GNUNET_break, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_query_param_auto_from_type, GNUNET_MY_query_param_end, GNUNET_MY_query_param_fixed_size(), GNUNET_MY_query_param_uint32(), GNUNET_MY_query_param_uint64(), GNUNET_MYSQL_statement_get_stmt(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, Plugin::insert_entry, key, MAX_DATUM_SIZE, Plugin::mc, plugin, replication, size, type, and Plugin::update_entry.
Referenced by libgnunet_plugin_datastore_mysql_init().
|
static |
Run the given select statement and call 'proc' on the resulting values (which must be in particular positions).
plugin | the plugin handle |
stmt | select statement to run |
proc | function to call on result |
proc_cls | closure for proc |
params_select | arguments to initialize stmt |
Definition at line 455 of file plugin_datastore_mysql.c.
References anonymity, GNUNET_DATACACHE_PluginEnvironment::cls, do_delete_entry(), Plugin::env, expiration, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MY_cleanup_result(), GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_result_spec_absolute_time(), GNUNET_MY_result_spec_auto_from_type, GNUNET_MY_result_spec_end, GNUNET_MY_result_spec_uint32(), GNUNET_MY_result_spec_uint64(), GNUNET_MY_result_spec_variable_size(), GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_UNIT_ZERO_ABS, key, MAX_DATUM_SIZE, Plugin::mc, plugin, replication, ret, type, and value.
Referenced by expi_proc(), mysql_plugin_get_expiration(), mysql_plugin_get_key(), mysql_plugin_get_replication(), and mysql_plugin_get_zero_anonymity().
|
static |
Get one of the results for a particular key in the datastore.
cls | closure |
next_uid | return the result with lowest uid >= next_uid |
random | if true, return a random result instead of using next_uid |
key | key to match, never NULL |
type | entries of which type are relevant? Use 0 for any type. |
proc | function to call on the matching value, with NULL for if no value matches |
proc_cls | closure for proc |
Definition at line 548 of file plugin_datastore_mysql.c.
References execute_select(), GNUNET_BLOCK_TYPE_ANY, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_MY_query_param_auto_from_type, GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint32(), GNUNET_MY_query_param_uint64(), key, plugin, Plugin::select_entry, Plugin::select_entry_by_hash, Plugin::select_entry_by_hash_and_type, and type.
Referenced by libgnunet_plugin_datastore_mysql_init().
|
static |
Get a zero-anonymity datum from the datastore.
cls | our struct Plugin * |
next_uid | return the result with lowest uid >= next_uid |
type | entries of which type should be considered? Must not be zero (ANY). |
proc | function to call on a matching value; will be called with NULL if no value matches |
proc_cls | closure for proc |
Definition at line 631 of file plugin_datastore_mysql.c.
References execute_select(), GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint32(), GNUNET_MY_query_param_uint64(), plugin, type, and Plugin::zero_iter.
Referenced by libgnunet_plugin_datastore_mysql_init().
|
static |
Wrapper for the processor for mysql_plugin_get_replication().
Decrements the replication counter and calls the original iterator.
cls | closure |
key | key for the content |
size | number of bytes in data |
data | content stored |
type | type of the content |
priority | priority of the content |
anonymity | anonymity-level for the content |
replication | replication-level for the content |
expiration | expiration time for the content |
uid | unique identifier for the datum; maybe 0 if no unique identifier is available |
Definition at line 697 of file plugin_datastore_mysql.c.
References anonymity, data, Plugin::dec_repl, expiration, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint64(), GNUNET_SYSERR, key, Plugin::mc, ReplCtx::plugin, plugin, ReplCtx::proc, ReplCtx::proc_cls, replication, ret, size, and type.
Referenced by mysql_plugin_get_replication().
|
static |
Get a random item for replication.
Returns a single, not expired, random item from those with the highest replication counters. The item's replication counter is decremented by one IF it was positive before. Call proc with all values ZERO or NULL if the datastore is empty.
cls | closure |
proc | function to call the value (once only). |
proc_cls | closure for proc |
Definition at line 756 of file plugin_datastore_mysql.c.
References execute_select(), GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint32(), GNUNET_MY_query_param_uint64(), GNUNET_MY_result_spec_end, GNUNET_MY_result_spec_uint32(), GNUNET_NO, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, Plugin::max_repl, Plugin::mc, ReplCtx::plugin, plugin, ReplCtx::proc, ReplCtx::proc_cls, repl_proc(), and Plugin::select_replication.
Referenced by libgnunet_plugin_datastore_mysql_init().
|
static |
Get all of the keys in the datastore.
cls | closure |
proc | function to call on each key |
proc_cls | closure for proc |
Definition at line 821 of file plugin_datastore_mysql.c.
References _, GET_ALL_KEYS, Plugin::get_all_keys, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memcmp, GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_query_param_end, GNUNET_MY_result_spec_auto_from_type, GNUNET_MY_result_spec_end, GNUNET_MYSQL_statement_get_stmt(), GNUNET_MYSQL_statements_invalidate(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, key, Plugin::mc, plugin, and ret.
Referenced by libgnunet_plugin_datastore_mysql_init().
|
static |
Wrapper for the processor for mysql_plugin_get_expiration().
If no expired value was found, we do a second query for low-priority content.
cls | closure |
key | key for the content |
size | number of bytes in data |
data | content stored |
type | type of the content |
priority | priority of the content |
anonymity | anonymity-level for the content |
replication | replication-level for the content |
expiration | expiration time for the content |
uid | unique identifier for the datum; maybe 0 if no unique identifier is available |
Definition at line 944 of file plugin_datastore_mysql.c.
References anonymity, data, execute_select(), expiration, GNUNET_MY_query_param_end, GNUNET_SYSERR, key, ExpiCtx::plugin, plugin, ExpiCtx::proc, ExpiCtx::proc_cls, replication, Plugin::select_priority, size, and type.
Referenced by mysql_plugin_get_expiration().
|
static |
Get a random item for expiration.
Call proc with all values ZERO or NULL if the datastore is empty.
cls | closure |
proc | function to call the value (once only). |
proc_cls | closure for proc |
Definition at line 992 of file plugin_datastore_mysql.c.
References execute_select(), expi_proc(), GNUNET_MY_query_param_absolute_time(), GNUNET_MY_query_param_end, GNUNET_TIME_absolute_get(), ExpiCtx::plugin, plugin, ExpiCtx::proc, ExpiCtx::proc_cls, and Plugin::select_expiration.
Referenced by libgnunet_plugin_datastore_mysql_init().
|
static |
Drop database.
cls | the struct Plugin * |
Definition at line 1022 of file plugin_datastore_mysql.c.
References GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_MYSQL_statement_run(), GNUNET_OK, Plugin::mc, and plugin.
Referenced by libgnunet_plugin_datastore_mysql_init().
|
static |
Remove a particular key in the datastore.
cls | closure |
key | key for the content |
size | number of bytes in data |
data | content stored |
cont | continuation called with success or failure status |
cont_cls | continuation closure for cont |
Definition at line 1045 of file plugin_datastore_mysql.c.
References _, GNUNET_DATACACHE_PluginEnvironment::cls, data, Plugin::delete_entry_by_hash_value, Plugin::env, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_query_param_auto_from_type, GNUNET_MY_query_param_end, GNUNET_MY_query_param_fixed_size(), GNUNET_MYSQL_statement_get_stmt(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, key, Plugin::mc, plugin, and size.
Referenced by libgnunet_plugin_datastore_mysql_init().
void* libgnunet_plugin_datastore_mysql_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | the struct GNUNET_DATASTORE_PluginEnvironment * |
struct Plugin *
Definition at line 1105 of file plugin_datastore_mysql.c.
References _, Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginEnvironment::cls, DEC_REPL, Plugin::dec_repl, DELETE_ENTRY_BY_HASH_VALUE, Plugin::delete_entry_by_hash_value, DELETE_ENTRY_BY_UID, Plugin::delete_entry_by_uid, env, Plugin::env, GET_ALL_KEYS, Plugin::get_all_keys, GNUNET_BLOCK_PluginFunctions::get_key, Plugin::get_size, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log_from, GNUNET_MYSQL_context_create(), GNUNET_MYSQL_context_destroy(), GNUNET_new, INSERT_ENTRY, Plugin::insert_entry, Plugin::max_repl, Plugin::mc, MRUNS, mysql_plugin_drop(), mysql_plugin_estimate_size(), mysql_plugin_get_expiration(), mysql_plugin_get_key(), mysql_plugin_get_keys(), mysql_plugin_get_replication(), mysql_plugin_get_zero_anonymity(), mysql_plugin_put(), mysql_plugin_remove_key(), PINIT, plugin, SELECT_ENTRY, Plugin::select_entry, SELECT_ENTRY_BY_HASH, Plugin::select_entry_by_hash, SELECT_ENTRY_BY_HASH_AND_TYPE, Plugin::select_entry_by_hash_and_type, Plugin::select_expiration, SELECT_IT_EXPIRATION, SELECT_IT_NON_ANONYMOUS, SELECT_IT_PRIORITY, SELECT_IT_REPLICATION, SELECT_MAX_REPL, Plugin::select_priority, Plugin::select_replication, SELECT_SIZE, UPDATE_ENTRY, Plugin::update_entry, and Plugin::zero_iter.
void* libgnunet_plugin_datastore_mysql_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | our struct Plugin * |
Definition at line 1191 of file plugin_datastore_mysql.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_free, GNUNET_MYSQL_context_destroy(), Plugin::mc, and plugin.