sqlite for an implementation of a database backend for the datacache More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_datacache_plugin.h"
#include "gnunet_sq_lib.h"
#include <sqlite3.h>
Go to the source code of this file.
Data Structures | |
struct | Plugin |
Handle for a plugin. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "datacache-sqlite", __VA_ARGS__) |
#define | LOG_STRERROR_FILE(kind, op, fn) GNUNET_log_from_strerror_file (kind, "datacache-sqlite", op, fn) |
#define | OVERHEAD (sizeof(struct GNUNET_HashCode) + 36) |
How much overhead do we assume per entry in the datacache? More... | |
#define | LOG_SQLITE(db, level, cmd) |
Log an error message at log-level level that indicates a failure of the command cmd with the error from the database db. More... | |
#define | SQLITE3_EXEC(db, cmd) |
Execute SQL statement. More... | |
Functions | |
static int | sq_prepare (sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt) |
Prepare a SQL statement. More... | |
static ssize_t | sqlite_plugin_put (void *cls, uint32_t xor_distance, const struct GNUNET_DATACACHE_Block *block) |
Store an item in the datastore. More... | |
static unsigned int | get_any (void *cls, const struct GNUNET_HashCode *key, GNUNET_DATACACHE_Iterator iter, void *iter_cls) |
Iterate over the results for a particular key in the datastore. More... | |
static unsigned int | get_typed (void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls) |
Iterate over the results for a particular key in the datastore. More... | |
static unsigned int | sqlite_plugin_get (void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls) |
Iterate over the results for a particular key in the datastore. More... | |
static enum GNUNET_GenericReturnValue | sqlite_plugin_del (void *cls) |
Delete the entry with the lowest expiration value from the datacache right now. More... | |
static unsigned int | sqlite_plugin_get_closest (void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls) |
Iterate over the results that are "close" to a particular key in the datacache. More... | |
void * | libgnunet_plugin_datacache_sqlite_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_datacache_sqlite_done (void *cls) |
Exit point from the plugin. More... | |
sqlite for an implementation of a database backend for the datacache
Definition in file plugin_datacache_sqlite.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "datacache-sqlite", __VA_ARGS__) |
Definition at line 32 of file plugin_datacache_sqlite.c.
#define LOG_STRERROR_FILE | ( | kind, | |
op, | |||
fn | |||
) | GNUNET_log_from_strerror_file (kind, "datacache-sqlite", op, fn) |
Definition at line 34 of file plugin_datacache_sqlite.c.
#define OVERHEAD (sizeof(struct GNUNET_HashCode) + 36) |
How much overhead do we assume per entry in the datacache?
Definition at line 42 of file plugin_datacache_sqlite.c.
#define LOG_SQLITE | ( | db, | |
level, | |||
cmd | |||
) |
Log an error message at log-level level that indicates a failure of the command cmd with the error from the database db.
db | database handle |
level | log level |
cmd | failed command |
Definition at line 124 of file plugin_datacache_sqlite.c.
#define SQLITE3_EXEC | ( | db, | |
cmd | |||
) |
Execute SQL statement.
db | database handle |
cmd | SQL command to execute |
Definition at line 142 of file plugin_datacache_sqlite.c.
|
static |
Prepare a SQL statement.
dbh | database handle | |
zSql | SQL statement text | |
[out] | ppStmt | set to the prepared statement |
Definition at line 169 of file plugin_datacache_sqlite.c.
References dummy.
Referenced by libgnunet_plugin_datacache_sqlite_init().
|
static |
Store an item in the datastore.
cls | closure (our struct Plugin ) |
xor_distance | how close is key to our PID? |
block | data to store |
Definition at line 192 of file plugin_datacache_sqlite.c.
References GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DATACACHE_Block::expiration_time, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_absolute_time(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_fixed_size(), GNUNET_SQ_query_param_uint32(), GNUNET_SQ_reset(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, GNUNET_DATACACHE_Block::key, LOG, LOG_SQLITE, OVERHEAD, plugin, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, and GNUNET_DATACACHE_Block::type.
Referenced by libgnunet_plugin_datacache_sqlite_init().
|
static |
Iterate over the results for a particular key in the datastore.
cls | closure (our struct Plugin ) |
key | |
iter | maybe NULL (to just count) |
iter_cls | closure for iter |
Definition at line 261 of file plugin_datacache_sqlite.c.
References data, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DATACACHE_Block::expiration_time, GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_cleanup_result(), GNUNET_SQ_extract_result(), GNUNET_SQ_query_param_absolute_time(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_uint32(), GNUNET_SQ_reset(), GNUNET_SQ_result_spec_absolute_time(), GNUNET_SQ_result_spec_auto_from_type, GNUNET_SQ_result_spec_end, GNUNET_SQ_result_spec_uint32(), GNUNET_SQ_result_spec_variable_size(), GNUNET_TIME_absolute_get(), key, GNUNET_DATACACHE_Block::key, LOG, LOG_SQLITE, plugin, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, and GNUNET_DATACACHE_Block::type.
Referenced by sqlite_plugin_get().
|
static |
Iterate over the results for a particular key in the datastore.
cls | closure (our struct Plugin ) |
key | |
type | entries of which type are relevant? |
iter | maybe NULL (to just count) |
iter_cls | closure for iter |
Definition at line 420 of file plugin_datacache_sqlite.c.
References data, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DATACACHE_Block::expiration_time, GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_cleanup_result(), GNUNET_SQ_extract_result(), GNUNET_SQ_query_param_absolute_time(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_uint32(), GNUNET_SQ_reset(), GNUNET_SQ_result_spec_absolute_time(), GNUNET_SQ_result_spec_auto_from_type, GNUNET_SQ_result_spec_end, GNUNET_SQ_result_spec_uint32(), GNUNET_SQ_result_spec_variable_size(), GNUNET_TIME_absolute_get(), key, GNUNET_DATACACHE_Block::key, LOG, LOG_SQLITE, plugin, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, type, and GNUNET_DATACACHE_Block::type.
Referenced by sqlite_plugin_get().
|
static |
Iterate over the results for a particular key in the datastore.
cls | closure (our struct Plugin ) |
key | |
type | entries of which type are relevant? |
iter | maybe NULL (to just count) |
iter_cls | closure for iter |
Definition at line 582 of file plugin_datacache_sqlite.c.
References get_any(), get_typed(), GNUNET_BLOCK_TYPE_ANY, key, and type.
Referenced by libgnunet_plugin_datacache_sqlite_init().
|
static |
Delete the entry with the lowest expiration value from the datacache right now.
cls | closure (our struct Plugin ) |
Definition at line 609 of file plugin_datacache_sqlite.c.
References GNUNET_TESTING_PluginFunctions::cls, data, data_size, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_cleanup_result(), GNUNET_SQ_extract_result(), GNUNET_SQ_query_param_absolute_time(), GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_uint64(), GNUNET_SQ_reset(), GNUNET_SQ_result_spec_auto_from_type, GNUNET_SQ_result_spec_end, GNUNET_SQ_result_spec_uint64(), GNUNET_SQ_result_spec_variable_size(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), LOG, LOG_SQLITE, OVERHEAD, and plugin.
Referenced by libgnunet_plugin_datacache_sqlite_init().
|
static |
Iterate over the results that are "close" to a particular key in the datacache.
"close" is defined as numerically larger than key (when interpreted as a circular address space), with small distance.
cls | closure (internal context for the plugin) |
key | area of the keyspace to look into |
type | desired block type for the replies |
num_results | number of results that should be returned to iter |
iter | maybe NULL (to just count) |
iter_cls | closure for iter |
Definition at line 724 of file plugin_datacache_sqlite.c.
References data, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DATACACHE_Block::expiration_time, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_cleanup_result(), GNUNET_SQ_extract_result(), GNUNET_SQ_query_param_absolute_time(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_uint32(), GNUNET_SQ_reset(), GNUNET_SQ_result_spec_absolute_time(), GNUNET_SQ_result_spec_auto_from_type, GNUNET_SQ_result_spec_end, GNUNET_SQ_result_spec_uint32(), GNUNET_SQ_result_spec_variable_size(), GNUNET_TIME_absolute_get(), key, GNUNET_DATACACHE_Block::key, LOG, LOG_SQLITE, plugin, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, type, and GNUNET_DATACACHE_Block::type.
Referenced by libgnunet_plugin_datacache_sqlite_init().
void * libgnunet_plugin_datacache_sqlite_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | closure (the struct GNUNET_DATACACHE_PluginEnvironment ) |
struct Plugin
) Definition at line 830 of file plugin_datacache_sqlite.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::dbh, env, Plugin::fn, GNUNET_break, GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_DISK_mktemp(), GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_new, GNUNET_strdup, GNUNET_YES, LOG, LOG_SQLITE, plugin, sq_prepare(), SQLITE3_EXEC, sqlite_plugin_del(), sqlite_plugin_get(), sqlite_plugin_get_closest(), and sqlite_plugin_put().
void * libgnunet_plugin_datacache_sqlite_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | closure (our struct Plugin ) |
Definition at line 1006 of file plugin_datacache_sqlite.c.
References _, Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, LOG, LOG_SQLITE, LOG_STRERROR_FILE, plugin, and result.