sqlite-based namestore backend More...
#include "platform.h"
#include "gnunet_namestore_plugin.h"
#include "gnunet_gnsrecord_lib.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 | 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, "namestore-sqlite", __VA_ARGS__) |
Functions | |
static enum GNUNET_GenericReturnValue | database_prepare (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 enum GNUNET_GenericReturnValue | namestore_sqlite_store_records (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) |
Store a record in the datastore. More... | |
static enum GNUNET_GenericReturnValue | get_records_and_call_iterator (struct Plugin *plugin, sqlite3_stmt *stmt, const struct GNUNET_CRYPTO_PrivateKey *zone_key, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
The given 'sqlite' statement has been prepared to be run. More... | |
static enum GNUNET_GenericReturnValue | lookup_records (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls, const char *editor_hint) |
Lookup records in the datastore for which we are the authority. More... | |
static enum GNUNET_GenericReturnValue | namestore_sqlite_lookup_records (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
Lookup records in the datastore for which we are the authority. More... | |
static enum GNUNET_GenericReturnValue | namestore_sqlite_editor_hint_clear (void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label) |
Clear editor hint. More... | |
static enum GNUNET_GenericReturnValue | namestore_sqlite_edit_records (void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
Lookup records in the datastore for which we are the authority. More... | |
static enum GNUNET_GenericReturnValue | namestore_sqlite_iterate_records (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
Iterate over the results for a particular key and zone in the datastore. More... | |
static enum GNUNET_GenericReturnValue | namestore_sqlite_zone_to_name (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const struct GNUNET_CRYPTO_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
Look for an existing PKEY delegation record for a given public key. More... | |
static enum GNUNET_GenericReturnValue | namestore_sqlite_create_tables (void *cls) |
static enum GNUNET_GenericReturnValue | namestore_sqlite_drop_tables (void *cls) |
static enum GNUNET_GenericReturnValue | namestore_sqlite_begin_tx (void *cls) |
static enum GNUNET_GenericReturnValue | namestore_sqlite_commit_tx (void *cls) |
static enum GNUNET_GenericReturnValue | namestore_sqlite_rollback_tx (void *cls) |
static enum GNUNET_GenericReturnValue | database_connect (struct Plugin *plugin) |
Initialize the database connections and associated data structures (create tables and indices as needed as well). More... | |
void * | libgnunet_plugin_namestore_sqlite_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_namestore_sqlite_done (void *cls) |
Exit point from the plugin. More... | |
sqlite-based namestore backend
Definition in file plugin_namestore_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 43 of file plugin_namestore_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 51 of file plugin_namestore_sqlite.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__) |
Definition at line 61 of file plugin_namestore_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 132 of file plugin_namestore_sqlite.c.
References _, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_prepare(), GNUNET_SQ_make_try_execute(), GNUNET_SQ_prepare(), GNUNET_SQ_PREPARE_END, GNUNET_SYSERR, GNUNET_YES, LOG, plugin, and ps.
Referenced by lookup_records(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_iterate_records(), namestore_sqlite_store_records(), and namestore_sqlite_zone_to_name().
|
static |
Shutdown database connection and associate data structures.
plugin | the plugin context (state for this module) |
Definition at line 218 of file plugin_namestore_sqlite.c.
References _, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, LOG, LOG_SQLITE, plugin, and result.
Referenced by libgnunet_plugin_namestore_sqlite_done().
|
static |
Store a record in the datastore.
Removes any existing record in the same zone with the same name.
cls | closure (internal context for the plugin) |
zone_key | private key of the zone |
label | name that is being mapped (at most 255 characters long) |
rd_count | number of entries in rd array |
rd | array of records with data to store |
Definition at line 283 of file plugin_namestore_sqlite.c.
References data, data_size, database_prepare(), GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_GNSRECORD_identity_from_data(), GNUNET_GNSRECORD_is_zonekey_type(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_GNSRECORD_z2s(), GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_fixed_size(), GNUNET_SQ_query_param_string(), GNUNET_SQ_query_param_uint32(), GNUNET_SQ_query_param_uint64(), GNUNET_SQ_reset(), GNUNET_SYSERR, GNUNET_YES, LOG, LOG_SQLITE, pkey, plugin, rd, rd_count, and ret.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
The given 'sqlite' statement has been prepared to be run.
It will return a record which should be given to the iterator. Runs the statement and parses the returned record.
plugin | plugin context |
stmt | to run (and then clean up) |
zone_key | private key of the zone |
limit | maximum number of results to fetch |
iter | iterator to call with the result |
iter_cls | closure for iter |
Definition at line 440 of file plugin_namestore_sqlite.c.
References data, data_size, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_GNSRECORD_records_deserialize(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SQ_cleanup_result(), GNUNET_SQ_extract_result(), GNUNET_SQ_reset(), GNUNET_SQ_result_spec_auto_from_type, GNUNET_SQ_result_spec_end, GNUNET_SQ_result_spec_string(), GNUNET_SQ_result_spec_uint32(), GNUNET_SQ_result_spec_uint64(), GNUNET_SQ_result_spec_variable_size(), GNUNET_SYSERR, LOG_SQLITE, plugin, rd, record_count, and ret.
Referenced by lookup_records(), namestore_sqlite_iterate_records(), and namestore_sqlite_zone_to_name().
|
static |
Lookup records in the datastore for which we are the authority.
cls | closure (internal context for the plugin) |
zone | private key of the zone |
label | name of the record in the zone |
iter | function to call with the result |
iter_cls | closure for iter |
Definition at line 562 of file plugin_namestore_sqlite.c.
References database_prepare(), get_records_and_call_iterator(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_string(), GNUNET_SQ_reset(), GNUNET_SYSERR, LOG_SQLITE, and plugin.
Referenced by namestore_sqlite_edit_records(), and namestore_sqlite_lookup_records().
|
static |
Lookup records in the datastore for which we are the authority.
cls | closure (internal context for the plugin) |
zone | private key of the zone |
label | name of the record in the zone |
iter | function to call with the result |
iter_cls | closure for iter |
Definition at line 614 of file plugin_namestore_sqlite.c.
References lookup_records().
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Clear editor hint.
cls | closure (internal context for the plugin) |
zone | private key of the zone |
label | name of the record in the zone |
editor_hint | editor hint to clear |
editor_hint_repl | editor hint to replace the old with (optional) |
iter | function to call with the result |
iter_cls | closure for iter |
Definition at line 638 of file plugin_namestore_sqlite.c.
References database_prepare(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_string(), GNUNET_SQ_reset(), GNUNET_SYSERR, LOG_SQLITE, and plugin.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Lookup records in the datastore for which we are the authority.
cls | closure (internal context for the plugin) |
zone | private key of the zone |
label | name of the record in the zone |
iter | function to call with the result |
iter_cls | closure for iter |
Definition at line 709 of file plugin_namestore_sqlite.c.
References lookup_records().
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Iterate over the results for a particular key and zone in the datastore.
Will return at most one result to the iterator.
cls | closure (internal context for the plugin) |
zone | hash of public key of the zone, NULL to iterate over all zones |
serial | serial number to exclude in the list of all matching records |
limit | maximum number of results to return |
iter | function to call with the result |
iter_cls | closure for iter |
Definition at line 734 of file plugin_namestore_sqlite.c.
References database_prepare(), get_records_and_call_iterator(), GNUNET_assert, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_uint64(), GNUNET_SQ_reset(), GNUNET_SYSERR, LOG_SQLITE, and plugin.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Look for an existing PKEY delegation record for a given public key.
Returns at most one result to the iterator.
cls | closure (internal context for the plugin) |
zone | private key of the zone to look up in, never NULL |
value_zone | public key of the target zone (value), never NULL |
iter | function to call with the result |
iter_cls | closure for iter |
Definition at line 802 of file plugin_namestore_sqlite.c.
References database_prepare(), get_records_and_call_iterator(), GNUNET_assert, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_GNSRECORD_z2s(), GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_reset(), GNUNET_SYSERR, LOG, LOG_SQLITE, and plugin.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Definition at line 841 of file plugin_namestore_sqlite.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SQ_make_try_execute(), GNUNET_SYSERR, and plugin.
Referenced by database_connect(), and libgnunet_plugin_namestore_sqlite_init().
|
static |
Definition at line 885 of file plugin_namestore_sqlite.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SYSERR, and plugin.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Definition at line 907 of file plugin_namestore_sqlite.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SYSERR, and plugin.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Definition at line 929 of file plugin_namestore_sqlite.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SYSERR, and plugin.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Definition at line 951 of file plugin_namestore_sqlite.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SYSERR, and plugin.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
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 981 of file plugin_namestore_sqlite.c.
References _, BUSY_TIMEOUT_MS, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, LOG, namestore_sqlite_create_tables(), and plugin.
Referenced by libgnunet_plugin_namestore_sqlite_init().
void * libgnunet_plugin_namestore_sqlite_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | the "struct GNUNET_NAMESTORE_PluginEnvironment*" |
Definition at line 1045 of file plugin_namestore_sqlite.c.
References _, GNUNET_NAMESTORE_PluginFunctions::begin_tx, cfg, GNUNET_NAMESTORE_PluginFunctions::clear_editor_hint, GNUNET_NAMESTORE_PluginFunctions::cls, GNUNET_NAMESTORE_PluginFunctions::commit_tx, GNUNET_NAMESTORE_PluginFunctions::create_tables, database_connect(), GNUNET_NAMESTORE_PluginFunctions::drop_tables, GNUNET_NAMESTORE_PluginFunctions::edit_records, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_NAMESTORE_PluginFunctions::iterate_records, LOG, GNUNET_NAMESTORE_PluginFunctions::lookup_records, namestore_sqlite_begin_tx(), namestore_sqlite_commit_tx(), namestore_sqlite_create_tables(), namestore_sqlite_drop_tables(), namestore_sqlite_edit_records(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_iterate_records(), namestore_sqlite_lookup_records(), namestore_sqlite_rollback_tx(), namestore_sqlite_store_records(), namestore_sqlite_zone_to_name(), plugin, GNUNET_NAMESTORE_PluginFunctions::rollback_tx, GNUNET_NAMESTORE_PluginFunctions::store_records, and GNUNET_NAMESTORE_PluginFunctions::zone_to_name.
void * libgnunet_plugin_namestore_sqlite_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | the plugin context (as returned by "init") |
Definition at line 1088 of file plugin_namestore_sqlite.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_NAMESTORE_PluginFunctions::cls, database_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, LOG, and plugin.