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. | |
| Functions | |
| static enum GNUNET_GenericReturnValue | init_connection (struct Plugin *plugin) | 
| Get a database handle. | |
| static ssize_t | postgres_plugin_put (void *cls, uint32_t prox, const struct GNUNET_DATACACHE_Block *block) | 
| Store an item in the datastore. | |
| 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. | |
| 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. | |
| static enum GNUNET_GenericReturnValue | postgres_plugin_del (void *cls) | 
| Delete the entry with the lowest expiration value from the datacache right now. | |
| 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. | |
| static unsigned int | postgres_plugin_get_closest (void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, 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. | |
| void * | libgnunet_plugin_datacache_postgres_init (void *cls) | 
| Entry point for the plugin. | |
| void * | libgnunet_plugin_datacache_postgres_done (void *cls) | 
| Exit point from the plugin. | |
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.
| #define OVERHEAD (sizeof(struct GNUNET_HashCode) + 24) | 
Per-entry overhead estimate.
Definition at line 36 of file plugin_datacache_postgres.c.
| 
 | static | 
Get a database handle.
| plugin | global context | 
Definition at line 67 of file plugin_datacache_postgres.c.
References GNUNET_OK, GNUNET_PQ_connect_with_cfg(), GNUNET_PQ_make_prepare(), GNUNET_PQ_PREPARED_STATEMENT_END, GNUNET_SYSERR, plugin, and ps.
Referenced by libgnunet_plugin_datacache_postgres_init().
| 
 | static | 
Store an item in the datastore.
| cls | closure (our struct Plugin) | 
| prox | proximity of key to my PID | 
| block | data to store | 
Definition at line 133 of file plugin_datacache_postgres.c.
References GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DATACACHE_Block::expiration_time, 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_null(), GNUNET_PQ_query_param_uint32(), GNUNET_DATACACHE_Block::key, OVERHEAD, plugin, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, ret, GNUNET_DATACACHE_Block::trunc_peer, and GNUNET_DATACACHE_Block::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.
Parse the result and call the callback given in cls
| cls | closure of type struct HandleResultContext | 
| result | the postgres result | 
| num_results | the number of results in result | 
Definition at line 201 of file plugin_datacache_postgres.c.
References data, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DATACACHE_Block::expiration_time, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_PQ_cleanup_result(), GNUNET_PQ_extract_result(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_allow_null(), 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, HandleResultContext::iter, HandleResultContext::iter_cls, GNUNET_DATACACHE_Block::key, HandleResultContext::key, LOG, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, result, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, and GNUNET_DATACACHE_Block::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 287 of file plugin_datacache_postgres.c.
References 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(), HandleResultContext::iter, HandleResultContext::iter_cls, key, HandleResultContext::key, plugin, res, and type.
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 333 of file plugin_datacache_postgres.c.
References GNUNET_TESTING_PluginFunctions::cls, 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_uint64(), GNUNET_PQ_result_spec_auto_from_type, GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_uint64(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), key, LOG, oid, OVERHEAD, plugin, res, and size.
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_results | the number of results in result | 
Definition at line 429 of file plugin_datacache_postgres.c.
References data, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DATACACHE_Block::expiration_time, 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, GNUNET_DATACACHE_Block::key, LOG, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, result, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, and GNUNET_DATACACHE_Block::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 | 
| type | desired block type for the replies | 
| 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 518 of file plugin_datacache_postgres.c.
References 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(), ExtractResultContext::iter, ExtractResultContext::iter_cls, key, LOG, plugin, res, and type.
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 576 of file plugin_datacache_postgres.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATACACHE_PluginEnvironment::cls, env, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_new, GNUNET_OK, init_connection(), LOG, plugin, postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), and postgres_plugin_put().
| void * libgnunet_plugin_datacache_postgres_done | ( | void * | cls | ) | 
Exit point from the plugin.
| cls | closure (our struct Plugin) | 
Definition at line 613 of file plugin_datacache_postgres.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_break, GNUNET_free, GNUNET_OK, GNUNET_PQ_disconnect(), GNUNET_PQ_exec_sql(), and plugin.