postgres-based namestore backend More...
#include "gnunet_db_lib.h"#include "gnunet_namestore_plugin.h"#include "gnunet_gnsrecord_lib.h"#include "gnunet_pq_lib.h"Go to the source code of this file.
Data Structures | |
| struct | Plugin |
| Handle for a plugin. More... | |
| struct | ParserContext |
| Closure for parse_result_call_iterator. More... | |
Macros | |
| #define | LOG(kind, ...) GNUNET_log_from (kind, "namestore-postgres", __VA_ARGS__) |
Functions | |
| static enum GNUNET_GenericReturnValue | namestore_postgres_create_tables (void *cls) |
| Initialize the database connections and associated data structures (create tables and indices as needed as well). | |
| static enum GNUNET_GenericReturnValue | namestore_postgres_drop_tables (void *cls) |
| Drop existing namestore tables. | |
| static enum GNUNET_GenericReturnValue | database_prepare (struct Plugin *plugin) |
| 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). | |
| static enum GNUNET_GenericReturnValue | namestore_postgres_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. | |
| static void | parse_result_call_iterator (void *cls, PGresult *res, unsigned int num_results) |
| A statement has been run. | |
| static enum GNUNET_GenericReturnValue | namestore_postgres_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. | |
| static int | namestore_postgres_clear_editor_hint (void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label) |
| static int | namestore_postgres_edit_records (void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
| Edit records in the datastore for which we are the authority. | |
| static enum GNUNET_GenericReturnValue | namestore_postgres_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. | |
| static enum GNUNET_GenericReturnValue | namestore_postgres_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. | |
| static int | namestore_postgres_begin_tx (void *cls) |
| static int | namestore_postgres_commit_tx (void *cls) |
| static int | namestore_postgres_rollback_tx (void *cls) |
| static void | database_shutdown (struct Plugin *plugin) |
| Shutdown database connection and associate data structures. | |
| void * | libgnunet_plugin_namestore_postgres_init (void *cls) |
| Entry point for the plugin. | |
| void * | libgnunet_plugin_namestore_postgres_done (void *cls) |
| Exit point from the plugin. | |
postgres-based namestore backend
Definition in file plugin_namestore_postgres.c.
| #define LOG | ( | kind, | |
| ... | |||
| ) | GNUNET_log_from (kind, "namestore-postgres", __VA_ARGS__) |
Definition at line 32 of file plugin_namestore_postgres.c.
|
static |
Initialize the database connections and associated data structures (create tables and indices as needed as well).
| cls | the plugin context (state for this module) |
Definition at line 65 of file plugin_namestore_postgres.c.
References GNUNET_OK, GNUNET_PQ_connect_with_cfg(), GNUNET_PQ_disconnect(), GNUNET_SYSERR, and plugin.
Referenced by database_connect(), and libgnunet_plugin_namestore_postgres_init().
|
static |
Drop existing namestore tables.
| cls | the plugin context (state for this module) |
Definition at line 89 of file plugin_namestore_postgres.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_PQ_connect_with_cfg(), GNUNET_PQ_disconnect(), GNUNET_PQ_exec_sql(), GNUNET_SYSERR, plugin, and ret.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
Definition at line 114 of file plugin_namestore_postgres.c.
References GNUNET_OK, GNUNET_PQ_make_prepare(), GNUNET_PQ_prepare_statements(), GNUNET_PQ_PREPARED_STATEMENT_END, plugin, ps, and ret.
Referenced by namestore_postgres_begin_tx(), namestore_postgres_clear_editor_hint(), namestore_postgres_commit_tx(), namestore_postgres_edit_records(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), namestore_postgres_rollback_tx(), namestore_postgres_store_records(), and namestore_postgres_zone_to_name().
|
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 181 of file plugin_namestore_postgres.c.
References GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_PQ_connect_with_cfg(), GNUNET_PQ_EXECUTE_STATEMENT_END, GNUNET_PQ_make_try_execute(), GNUNET_SYSERR, GNUNET_YES, namestore_postgres_create_tables(), and plugin.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
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 233 of file plugin_namestore_postgres.c.
References data, data_size, database_prepare(), GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_identity_from_data(), GNUNET_GNSRECORD_is_zonekey_type(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_log_from, GNUNET_OK, GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_fixed_size(), GNUNET_PQ_query_param_string(), GNUNET_PQ_query_param_uint32(), GNUNET_PQ_query_param_uint64(), GNUNET_SYSERR, GNUNET_YES, pkey, plugin, rd, rd_count, res, and ret.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
A statement has been run.
We should evaluate the result, and if possible call the iter in cls with the result.
| cls | closure of type struct ParserContext * |
| res | the postgres result |
| num_results | the number of results in result |
Definition at line 372 of file plugin_namestore_postgres.c.
References data, data_size, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_records_deserialize(), GNUNET_NZL, GNUNET_OK, GNUNET_PQ_cleanup_result(), GNUNET_PQ_extract_result(), GNUNET_PQ_result_spec_auto_from_type, GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_string(), GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_uint64(), GNUNET_PQ_result_spec_variable_size(), GNUNET_YES, LOG, pc, rd, record_count, and res.
Referenced by namestore_postgres_edit_records(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), and namestore_postgres_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 468 of file plugin_namestore_postgres.c.
References database_prepare(), GNUNET_assert, GNUNET_break, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_NO, GNUNET_OK, GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_string(), GNUNET_SYSERR, ParserContext::iter, ParserContext::iter_cls, parse_result_call_iterator(), pc, plugin, and res.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
| 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 516 of file plugin_namestore_postgres.c.
References database_prepare(), GNUNET_assert, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, GNUNET_OK, GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_string(), GNUNET_SYSERR, pkey, plugin, and res.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
Edit 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 563 of file plugin_namestore_postgres.c.
References database_prepare(), GNUNET_assert, GNUNET_break, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_NO, GNUNET_OK, GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_string(), GNUNET_SYSERR, ParserContext::iter, ParserContext::iter_cls, parse_result_call_iterator(), pc, plugin, and res.
Referenced by libgnunet_plugin_namestore_postgres_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 fetch |
| iter | function to call with the result |
| iter_cls | closure for iter |
Definition at line 616 of file plugin_namestore_postgres.c.
References database_prepare(), GNUNET_assert, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_NO, GNUNET_OK, GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint64(), GNUNET_SYSERR, ParserContext::iter, ParserContext::iter_cls, ParserContext::limit, parse_result_call_iterator(), pc, plugin, and res.
Referenced by libgnunet_plugin_namestore_postgres_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 684 of file plugin_namestore_postgres.c.
References database_prepare(), GNUNET_assert, GNUNET_OK, GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_SYSERR, ParserContext::iter, ParserContext::iter_cls, parse_result_call_iterator(), pc, plugin, and res.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
| cls | closure (internal context for the plugin) |
Definition at line 722 of file plugin_namestore_postgres.c.
References database_prepare(), GNUNET_assert, GNUNET_OK, GNUNET_PQ_exec_statements(), GNUNET_PQ_EXECUTE_STATEMENT_END, GNUNET_PQ_make_try_execute(), and plugin.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
| cls | closure (internal context for the plugin) |
Definition at line 742 of file plugin_namestore_postgres.c.
References database_prepare(), GNUNET_assert, GNUNET_OK, GNUNET_PQ_exec_statements(), GNUNET_PQ_EXECUTE_STATEMENT_END, GNUNET_PQ_make_try_execute(), and plugin.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
| cls | closure (internal context for the plugin) |
Definition at line 762 of file plugin_namestore_postgres.c.
References database_prepare(), GNUNET_assert, GNUNET_OK, GNUNET_PQ_exec_statements(), GNUNET_PQ_EXECUTE_STATEMENT_END, GNUNET_PQ_make_try_execute(), and plugin.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
Shutdown database connection and associate data structures.
| plugin | the plugin context (state for this module) |
Definition at line 783 of file plugin_namestore_postgres.c.
References GNUNET_PQ_disconnect(), and plugin.
Referenced by libgnunet_plugin_namestore_postgres_done(), and libgnunet_plugin_namestore_postgres_init().
| void * libgnunet_plugin_namestore_postgres_init | ( | void * | cls | ) |
Entry point for the plugin.
| cls | the struct GNUNET_NAMESTORE_PluginEnvironment* |
Definition at line 799 of file plugin_namestore_postgres.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(), database_shutdown(), GNUNET_NAMESTORE_PluginFunctions::drop_tables, GNUNET_NAMESTORE_PluginFunctions::edit_records, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_NAMESTORE_PluginFunctions::iterate_records, LOG, GNUNET_NAMESTORE_PluginFunctions::lookup_records, namestore_postgres_begin_tx(), namestore_postgres_clear_editor_hint(), namestore_postgres_commit_tx(), namestore_postgres_create_tables(), namestore_postgres_drop_tables(), namestore_postgres_edit_records(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), namestore_postgres_rollback_tx(), namestore_postgres_store_records(), namestore_postgres_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_postgres_done | ( | void * | cls | ) |
Exit point from the plugin.
| cls | the plugin context (as returned by "init") |
Definition at line 842 of file plugin_namestore_postgres.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_NAMESTORE_PluginFunctions::cls, database_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, LOG, and plugin.