sqlite-based peerstore backend More...
#include "platform.h"
#include "gnunet_peerstore_plugin.h"
#include "gnunet_peerstore_service.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, "peerstore-sqlite", __VA_ARGS__) |
Functions | |
static int | peerstore_sqlite_delete_records (void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key) |
Delete records with the given key. More... | |
static int | peerstore_sqlite_expire_records (void *cls, struct GNUNET_TIME_Absolute now, GNUNET_PEERSTORE_Continuation cont, void *cont_cls) |
Delete expired records (expiry < now) More... | |
static int | peerstore_sqlite_iterate_records (void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, uint64_t serial, uint64_t limit, GNUNET_PEERSTORE_PluginProcessor iter, void *iter_cls) |
Iterate over the records given an optional peer id and/or key. More... | |
static int | peerstore_sqlite_store_record (void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls) |
Store a record in the peerstore. More... | |
static int | sql_exec (sqlite3 *dbh, const char *sql) |
Prepare a SQL statement. More... | |
static int | sql_prepare (sqlite3 *dbh, const char *sql, sqlite3_stmt **stmt) |
Prepare a SQL statement. More... | |
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... | |
void * | libgnunet_plugin_peerstore_sqlite_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_peerstore_sqlite_done (void *cls) |
Exit point from the plugin. More... | |
sqlite-based peerstore backend
Definition in file plugin_peerstore_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_peerstore_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 52 of file plugin_peerstore_sqlite.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "peerstore-sqlite", __VA_ARGS__) |
Definition at line 61 of file plugin_peerstore_sqlite.c.
|
static |
Delete records with the given key.
cls | closure (internal context for the plugin) |
sub_system | name of sub system |
peer | Peer identity (can be NULL) |
key | entry key string (can be NULL) |
Definition at line 132 of file plugin_peerstore_sqlite.c.
References 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, key, LOG_SQLITE, plugin, and ret.
Referenced by peerstore_sqlite_store_record().
|
static |
Delete expired records (expiry < now)
cls | closure (internal context for the plugin) |
now | time to use as reference |
cont | continuation called with the number of records expired |
cont_cls | continuation closure |
Definition at line 187 of file plugin_peerstore_sqlite.c.
References GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_absolute_time(), GNUNET_SQ_query_param_end, GNUNET_SQ_reset(), GNUNET_SYSERR, LOG_SQLITE, and plugin.
Referenced by libgnunet_plugin_peerstore_sqlite_init().
|
static |
Iterate over the records given an optional peer id and/or key.
cls | closure (internal context for the plugin) |
sub_system | name of sub system |
peer | Peer identity (can be NULL) |
key | entry key string (can be NULL) |
iter | function to call asynchronously with the results, terminated by a NULL result |
iter_cls | closure for iter |
Definition at line 242 of file plugin_peerstore_sqlite.c.
References GNUNET_PEERSTORE_Record::expiry, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, 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_query_param_string(), GNUNET_SQ_query_param_uint64(), 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_string(), GNUNET_SQ_result_spec_uint64(), GNUNET_SQ_result_spec_variable_size(), GNUNET_SYSERR, key, GNUNET_PEERSTORE_Record::key, LOG, LOG_SQLITE, GNUNET_PEERSTORE_Record::peer, plugin, ret, GNUNET_PEERSTORE_Record::sub_system, GNUNET_PEERSTORE_Record::value, and GNUNET_PEERSTORE_Record::value_size.
Referenced by libgnunet_plugin_peerstore_sqlite_init().
|
static |
Store a record in the peerstore.
Key is the combination of sub system and peer identity. One key can store multiple values.
cls | closure (internal context for the plugin) |
sub_system | name of the GNUnet sub system responsible |
peer | peer identity |
key | record key string |
value | value to be stored |
size | size of value to be stored |
expiry | absolute time after which the record is (possibly) deleted |
options | options related to the store operation |
cont | continuation called when record is stored |
cont_cls | continuation closure |
Definition at line 406 of file plugin_peerstore_sqlite.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_PEERSTORE_STOREOPTION_REPLACE, 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_string(), GNUNET_SQ_reset(), key, LOG_SQLITE, options, peerstore_sqlite_delete_records(), plugin, size, and value.
Referenced by libgnunet_plugin_peerstore_sqlite_init().
|
static |
Prepare a SQL statement.
dbh | handle to the database |
sql | SQL statement, UTF-8 encoded |
Definition at line 469 of file plugin_peerstore_sqlite.c.
References _, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, LOG, and result.
Referenced by database_setup().
|
static |
Prepare a SQL statement.
dbh | handle to the database |
sql | SQL statement, UTF-8 encoded |
stmt | set to the prepared statement |
Definition at line 501 of file plugin_peerstore_sqlite.c.
References _, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, LOG, and result.
Referenced by database_setup().
|
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 536 of file plugin_peerstore_sqlite.c.
References _, BUSY_TIMEOUT_MS, filename, 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_SYSERR, LOG, plugin, sql_exec(), and sql_prepare().
Referenced by libgnunet_plugin_peerstore_sqlite_init().
|
static |
Shutdown database connection and associate data structures.
plugin | the plugin context (state for this module) |
Definition at line 664 of file plugin_peerstore_sqlite.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, LOG, LOG_SQLITE, plugin, and result.
Referenced by libgnunet_plugin_peerstore_sqlite_done(), and libgnunet_plugin_peerstore_sqlite_init().
void * libgnunet_plugin_peerstore_sqlite_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | The struct GNUNET_CONFIGURATION_Handle. |
Definition at line 696 of file plugin_peerstore_sqlite.c.
References cfg, GNUNET_PEERSTORE_PluginFunctions::cls, database_setup(), database_shutdown(), GNUNET_PEERSTORE_PluginFunctions::expire_records, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_OK, GNUNET_PEERSTORE_PluginFunctions::iterate_records, LOG, peerstore_sqlite_expire_records(), peerstore_sqlite_iterate_records(), peerstore_sqlite_store_record(), plugin, and GNUNET_PEERSTORE_PluginFunctions::store_record.
void * libgnunet_plugin_peerstore_sqlite_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | The plugin context (as returned by "init") |
Definition at line 733 of file plugin_peerstore_sqlite.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_PEERSTORE_PluginFunctions::cls, database_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, LOG, and plugin.