sqlite-based namestore backend More...
#include "platform.h"
#include "gnunet_namestore_plugin.h"
#include "gnunet_namestore_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_sq_lib.h"
#include "namestore.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_IDENTITY_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_IDENTITY_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 | namestore_sqlite_lookup_records (void *cls, const struct GNUNET_IDENTITY_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_IDENTITY_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_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_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_transaction_begin (void *cls, char **emsg) |
Begin a transaction for a client. More... | |
static enum GNUNET_GenericReturnValue | namestore_sqlite_transaction_rollback (void *cls, char **emsg) |
Commit a transaction for a client. More... | |
static enum GNUNET_GenericReturnValue | namestore_sqlite_transaction_commit (void *cls, char **emsg) |
Roll back a transaction for a client. 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 | 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 45 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 53 of file plugin_namestore_sqlite.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__) |
Definition at line 63 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 1 of file plugin_namestore_sqlite.c.
|
static |
Shutdown database connection and associate data structures.
plugin | the plugin context (state for this module) |
Definition at line 206 of file plugin_namestore_sqlite.c.
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 206 of file plugin_namestore_sqlite.c.
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 206 of file plugin_namestore_sqlite.c.
|
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 206 of file plugin_namestore_sqlite.c.
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 206 of file plugin_namestore_sqlite.c.
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 206 of file plugin_namestore_sqlite.c.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Begin a transaction for a client.
This locks the database. SQLite is unable to discern between different rows with a specific zone key but the API looks like this anyway. https://www.sqlite.org/lang_transaction.html
cls | closure (internal context for the plugin) |
emsg | error message set of return code is GNUNET_SYSERR |
Definition at line 206 of file plugin_namestore_sqlite.c.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Commit a transaction for a client.
This releases the lock on the database.
cls | closure (internal context for the plugin) |
emsg | error message set of return code is GNUNET_SYSERR |
Definition at line 206 of file plugin_namestore_sqlite.c.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Roll back a transaction for a client.
This releases the lock on the database.
cls | closure (internal context for the plugin) |
emsg | error message set of return code is GNUNET_SYSERR |
Definition at line 206 of file plugin_namestore_sqlite.c.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Definition at line 206 of file plugin_namestore_sqlite.c.
Referenced by libgnunet_plugin_namestore_sqlite_init().
|
static |
Definition at line 206 of file plugin_namestore_sqlite.c.
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 206 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_init().
void* libgnunet_plugin_namestore_sqlite_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | the "struct GNUNET_NAMESTORE_PluginEnvironment*" |
NOTE: Since SQlite does not support SELECT ... FOR UPDATE this is just an alias to lookup_records. The BEGIN IMMEDIATE mechanic currently implicitly ensures this API behaves as it should
Definition at line 923 of file plugin_namestore_sqlite.c.
References _, cfg, GNUNET_NAMESTORE_PluginFunctions::cls, 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_create_tables(), namestore_sqlite_drop_tables(), namestore_sqlite_iterate_records(), namestore_sqlite_lookup_records(), namestore_sqlite_store_records(), namestore_sqlite_transaction_begin(), namestore_sqlite_transaction_commit(), namestore_sqlite_transaction_rollback(), namestore_sqlite_zone_to_name(), plugin, GNUNET_NAMESTORE_PluginFunctions::store_records, GNUNET_NAMESTORE_PluginFunctions::transaction_begin, GNUNET_NAMESTORE_PluginFunctions::transaction_commit, GNUNET_NAMESTORE_PluginFunctions::transaction_rollback, 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 968 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.