![]() |
GNUnet
0.11.x
|
postgres for an implementation of a database backend for the datacache More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_pq_lib.h"
#include "gnunet_datacache_plugin.h"
Go to the source code of this file.
Data Structures | |
struct | Plugin |
Handle for a plugin. More... | |
struct | HandleResultContext |
Closure for handle_results. More... | |
struct | ExtractResultContext |
Closure for extract_result_cb. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "datacache-postgres", __VA_ARGS__) |
#define | OVERHEAD (sizeof(struct GNUNET_HashCode) + 24) |
Per-entry overhead estimate. More... | |
Functions | |
static int | init_connection (struct Plugin *plugin) |
Get a database handle. More... | |
static ssize_t | postgres_plugin_put (void *cls, const struct GNUNET_HashCode *key, uint32_t prox, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time, unsigned int path_info_len, const struct GNUNET_PeerIdentity *path_info) |
Store an item in the datastore. More... | |
static void | handle_results (void *cls, PGresult *result, unsigned int num_results) |
Function to be called with the results of a SELECT statement that has returned num_results results. More... | |
static unsigned int | postgres_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 int | postgres_plugin_del (void *cls) |
Delete the entry with the lowest expiration value from the datacache right now. More... | |
static unsigned int | postgres_plugin_get_random (void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls) |
Obtain a random key-value pair from the datacache. More... | |
static void | extract_result_cb (void *cls, PGresult *result, unsigned int num_results) |
Function to be called with the results of a SELECT statement that has returned num_results results. More... | |
static unsigned int | postgres_plugin_get_closest (void *cls, const struct GNUNET_HashCode *key, 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_postgres_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_datacache_postgres_done (void *cls) |
Exit point from the plugin. More... | |
postgres for an implementation of a database backend for the datacache
Definition in file plugin_datacache_postgres.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "datacache-postgres", __VA_ARGS__) |
Definition at line 31 of file plugin_datacache_postgres.c.
Referenced by extract_result_cb(), handle_results(), libgnunet_plugin_datacache_postgres_init(), postgres_plugin_del(), postgres_plugin_get_closest(), and postgres_plugin_get_random().
#define OVERHEAD (sizeof(struct GNUNET_HashCode) + 24) |
Per-entry overhead estimate.
Definition at line 36 of file plugin_datacache_postgres.c.
Referenced by postgres_plugin_del(), and postgres_plugin_put().
|
static |
Get a database handle.
plugin | global context |
Definition at line 67 of file plugin_datacache_postgres.c.
References GNUNET_DATACACHE_PluginEnvironment::cfg, Plugin::dbh, Plugin::env, GNUNET_OK, GNUNET_PQ_connect_with_cfg(), GNUNET_PQ_EXECUTE_STATEMENT_END, GNUNET_PQ_make_execute(), GNUNET_PQ_make_prepare(), GNUNET_PQ_make_try_execute(), GNUNET_PQ_PREPARED_STATEMENT_END, and GNUNET_SYSERR.
Referenced by libgnunet_plugin_datacache_postgres_init().
|
static |
Store an item in the datastore.
cls | closure (our struct Plugin ) |
key | key to store data under |
prox | proximity of key to my PID |
data_size | number of bytes in data |
data | data to store |
type | type of the value |
discard_time | when to discard the value in any case |
path_info_len | number of entries in path_info |
path_info | a path through the network |
Definition at line 155 of file plugin_datacache_postgres.c.
References Plugin::dbh, GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_fixed_size(), GNUNET_PQ_query_param_uint32(), Plugin::num_items, OVERHEAD, plugin, and ret.
Referenced by libgnunet_plugin_datacache_postgres_init().
|
static |
Function to be called with the results of a SELECT statement that has returned num_results results.
Parse the result and call the callback given in cls
cls | closure of type struct HandleResultContext |
result | the postgres result |
num_result | the number of results in result |
Definition at line 222 of file plugin_datacache_postgres.c.
References data, data_size, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_PQ_cleanup_result(), GNUNET_PQ_extract_result(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_variable_size(), GNUNET_SYSERR, GNUNET_YES, HandleResultContext::iter, HandleResultContext::iter_cls, HandleResultContext::key, LOG, and type.
Referenced by postgres_plugin_get().
|
static |
Iterate over the results for a particular key in the datastore.
cls | closure (our struct Plugin ) |
key | key to look for |
type | entries of which type are relevant? |
iter | maybe NULL (to just count) |
iter_cls | closure for iter |
Definition at line 301 of file plugin_datacache_postgres.c.
References Plugin::dbh, GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint32(), GNUNET_TIME_absolute_get(), handle_results(), Plugin::iter, HandleResultContext::iter, Plugin::iter_cls, HandleResultContext::iter_cls, Plugin::key, HandleResultContext::key, plugin, and res.
Referenced by libgnunet_plugin_datacache_postgres_init().
|
static |
Delete the entry with the lowest expiration value from the datacache right now.
cls | closure (our struct Plugin ) |
Definition at line 347 of file plugin_datacache_postgres.c.
References GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::dbh, GNUNET_DATACACHE_PluginEnvironment::delete_notify, Plugin::env, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, GNUNET_PQ_cleanup_result(), GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_eval_prepared_singleton_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint32(), GNUNET_PQ_result_spec_auto_from_type, GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), LOG, Plugin::num_items, OVERHEAD, plugin, res, and Plugin::size.
Referenced by libgnunet_plugin_datacache_postgres_init().
|
static |
Obtain a random key-value pair from the datacache.
cls | closure (our struct Plugin ) |
iter | maybe NULL (to just count) |
iter_cls | closure for iter |
Definition at line 421 of file plugin_datacache_postgres.c.
References data, data_size, Plugin::dbh, GNUNET_break, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_PQ_cleanup_result(), GNUNET_PQ_eval_prepared_singleton_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint32(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_auto_from_type, GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_variable_size(), GNUNET_TIME_absolute_get(), LOG, Plugin::num_items, plugin, res, and type.
Referenced by libgnunet_plugin_datacache_postgres_init().
|
static |
Function to be called with the results of a SELECT statement that has returned num_results results.
Calls the iter
from cls for each result.
cls | closure with the struct ExtractResultContext |
result | the postgres result |
num_result | the number of results in result |
Definition at line 529 of file plugin_datacache_postgres.c.
References data, data_size, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_PQ_cleanup_result(), GNUNET_PQ_extract_result(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_auto_from_type, GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_variable_size(), GNUNET_SYSERR, GNUNET_YES, ExtractResultContext::iter, ExtractResultContext::iter_cls, LOG, and type.
Referenced by postgres_plugin_get_closest().
|
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 |
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 614 of file plugin_datacache_postgres.c.
References Plugin::dbh, extract_result_cb(), GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_ERROR_TYPE_DEBUG, GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint32(), GNUNET_TIME_absolute_get(), Plugin::iter, ExtractResultContext::iter, Plugin::iter_cls, ExtractResultContext::iter_cls, LOG, plugin, and res.
Referenced by libgnunet_plugin_datacache_postgres_init().
void* libgnunet_plugin_datacache_postgres_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | closure (the struct GNUNET_DATACACHE_PluginEnvironmnet ) |
struct Plugin
) Definition at line 664 of file plugin_datacache_postgres.c.
References Plugin::api, GNUNET_DATACACHE_PluginEnvironment::cls, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::del, Plugin::env, GNUNET_DATACACHE_PluginFunctions::get, GNUNET_DATACACHE_PluginFunctions::get_closest, GNUNET_DATACACHE_PluginFunctions::get_random, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_new, GNUNET_OK, init_connection(), LOG, plugin, postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_random(), postgres_plugin_put(), and GNUNET_DATACACHE_PluginFunctions::put.
void* libgnunet_plugin_datacache_postgres_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | closure (our struct Plugin ) |
Definition at line 699 of file plugin_datacache_postgres.c.
References Plugin::api, GNUNET_DATACACHE_PluginFunctions::cls, Plugin::dbh, GNUNET_free, GNUNET_PQ_disconnect(), and plugin.