sqlite-based namecache backend More...
#include "platform.h"
#include "gnunet_sq_lib.h"
#include "gnunet_namecache_plugin.h"
#include "gnunet_gnsrecord_lib.h"
#include <sqlite3.h>
Go to the source code of this file.
Data Structures | |
struct | Plugin |
Handle for a plugin. More... | |
Macros | |
#define | BUSY_TIMEOUT_MS 1000 |
After how many ms "busy" should a DB operation fail for good? A low value makes sure that we are more responsive to requests (especially PUTs). More... | |
#define | LOG_SQLITE(db, level, cmd) |
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'filename' with the message given by strerror(errno). More... | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "namecache-sqlite", __VA_ARGS__) |
Functions | |
static int | database_setup (struct Plugin *plugin) |
Initialize the database connections and associated data structures (create tables and indices as needed as well). More... | |
static void | database_shutdown (struct Plugin *plugin) |
Shutdown database connection and associate data structures. More... | |
static void | namecache_sqlite_expire_blocks (struct Plugin *plugin) |
Removes any expired block. More... | |
static int | namecache_sqlite_cache_block (void *cls, const struct GNUNET_GNSRECORD_Block *block) |
Cache a block in the datastore. More... | |
static int | namecache_sqlite_lookup_block (void *cls, const struct GNUNET_HashCode *query, GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls) |
Get the block for a particular zone and label in the datastore. More... | |
void * | libgnunet_plugin_namecache_sqlite_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_namecache_sqlite_done (void *cls) |
Exit point from the plugin. More... | |
sqlite-based namecache backend
Definition in file plugin_namecache_sqlite.c.
#define BUSY_TIMEOUT_MS 1000 |
After how many ms "busy" should a DB operation fail for good? A low value makes sure that we are more responsive to requests (especially PUTs).
A high value guarantees a higher success rate (SELECTs in iterate can take several seconds despite LIMIT=1).
The default value of 1s should ensure that users do not experience huge latencies while at the same time allowing operations to succeed with reasonable probability.
Definition at line 42 of file plugin_namecache_sqlite.c.
#define LOG_SQLITE | ( | db, | |
level, | |||
cmd | |||
) |
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'filename' with the message given by strerror(errno).
Definition at line 50 of file plugin_namecache_sqlite.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "namecache-sqlite", __VA_ARGS__) |
Definition at line 59 of file plugin_namecache_sqlite.c.
|
static |
Initialize the database connections and associated data structures (create tables and indices as needed as well).
plugin | the plugin context (state for this module) |
Definition at line 110 of file plugin_namecache_sqlite.c.
References _, BUSY_TIMEOUT_MS, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SQ_make_prepare(), GNUNET_SQ_make_try_execute(), GNUNET_SQ_prepare(), GNUNET_SQ_PREPARE_END, GNUNET_SYSERR, LOG, plugin, and ps.
Referenced by libgnunet_plugin_namecache_sqlite_init().
|
static |
Shutdown database connection and associate data structures.
plugin | the plugin context (state for this module) |
Definition at line 217 of file plugin_namecache_sqlite.c.
References _, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_from, LOG, LOG_SQLITE, plugin, and result.
Referenced by libgnunet_plugin_namecache_sqlite_done(), and libgnunet_plugin_namecache_sqlite_init().
|
static |
Removes any expired block.
plugin | the plugin |
Definition at line 271 of file plugin_namecache_sqlite.c.
References GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_absolute_time(), GNUNET_SQ_query_param_end, GNUNET_SQ_reset(), GNUNET_TIME_absolute_get(), LOG_SQLITE, and plugin.
Referenced by namecache_sqlite_cache_block().
|
static |
Cache a block in the datastore.
cls | closure (internal context for the plugin) |
block | block to cache |
Definition at line 325 of file plugin_namecache_sqlite.c.
References expiration, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_GNSRECORD_block_get_expiration(), GNUNET_GNSRECORD_block_get_size(), GNUNET_GNSRECORD_query_from_block(), GNUNET_h2s(), GNUNET_h2s_full(), GNUNET_log, GNUNET_log_from, GNUNET_NO, 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_reset(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_UNIT_HOURS, LOG, LOG_SQLITE, namecache_sqlite_expire_blocks(), and plugin.
Referenced by libgnunet_plugin_namecache_sqlite_init().
|
static |
Get the block for a particular zone and label in the datastore.
Will return at most one result to the iterator.
cls | closure (internal context for the plugin) |
query | hash of public key derived from the zone and the label |
iter | function to call with the result |
iter_cls | closure for iter |
Definition at line 453 of file plugin_namecache_sqlite.c.
References GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s_full(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_cleanup_result(), GNUNET_SQ_extract_result(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_reset(), GNUNET_SQ_result_spec_end, GNUNET_SQ_result_spec_variable_size(), GNUNET_SYSERR, GNUNET_YES, LOG_SQLITE, plugin, and ret.
Referenced by libgnunet_plugin_namecache_sqlite_init().
void * libgnunet_plugin_namecache_sqlite_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | the "struct GNUNET_NAMECACHE_PluginEnvironment*" |
Definition at line 543 of file plugin_namecache_sqlite.c.
References _, GNUNET_NAMECACHE_PluginFunctions::cache_block, cfg, GNUNET_NAMECACHE_PluginFunctions::cls, database_setup(), database_shutdown(), GNUNET_ERROR_TYPE_INFO, GNUNET_new, GNUNET_OK, LOG, GNUNET_NAMECACHE_PluginFunctions::lookup_block, namecache_sqlite_cache_block(), namecache_sqlite_lookup_block(), and plugin.
void * libgnunet_plugin_namecache_sqlite_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | the plugin context (as returned by "init") |
Definition at line 577 of file plugin_namecache_sqlite.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_NAMECACHE_PluginFunctions::cls, database_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, LOG, and plugin.