postgres-based namestore backend More...
#include "platform.h"
#include "gnunet_namestore_plugin.h"
#include "gnunet_namestore_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_pq_lib.h"
#include "namestore.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). More... | |
static enum GNUNET_GenericReturnValue | namestore_postgres_drop_tables (void *cls) |
Drop existing namestore tables. More... | |
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). More... | |
static enum GNUNET_GenericReturnValue | namestore_postgres_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 void | parse_result_call_iterator (void *cls, PGresult *res, unsigned int num_results) |
A statement has been run. More... | |
static enum GNUNET_GenericReturnValue | lookup_records (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls, const char *method) |
Lookup records in the datastore for which we are the authority. More... | |
static enum GNUNET_GenericReturnValue | namestore_postgres_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 int | namestore_postgres_edit_records (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
Edit records in the datastore for which we are the authority. More... | |
static enum GNUNET_GenericReturnValue | namestore_postgres_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_postgres_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_postgres_transaction_begin (void *cls, char **emsg) |
Begin a transaction for a client. More... | |
static enum GNUNET_GenericReturnValue | namestore_postgres_transaction_rollback (void *cls, char **emsg) |
Commit a transaction for a client. More... | |
static enum GNUNET_GenericReturnValue | namestore_postgres_transaction_commit (void *cls, char **emsg) |
Roll back a transaction for a client. More... | |
static void | database_shutdown (struct Plugin *plugin) |
Shutdown database connection and associate data structures. More... | |
void * | libgnunet_plugin_namestore_postgres_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_namestore_postgres_done (void *cls) |
Exit point from the plugin. More... | |
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 34 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 1 of file plugin_namestore_postgres.c.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
Drop existing namestore tables.
cls | the plugin context (state for this module) |
Definition at line 1 of file plugin_namestore_postgres.c.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
Definition at line 1 of file plugin_namestore_postgres.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_postgres.c.
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 1 of file plugin_namestore_postgres.c.
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 364 of file plugin_namestore_postgres.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 |
method | the method to use "lookup_record" or "edit_set" |
Definition at line 364 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().
|
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 364 of file plugin_namestore_postgres.c.
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 529 of file plugin_namestore_postgres.c.
References ParserContext::iter, ParserContext::iter_cls, lookup_records(), and zone.
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 529 of file plugin_namestore_postgres.c.
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 529 of file plugin_namestore_postgres.c.
Referenced by libgnunet_plugin_namestore_postgres_init().
|
static |
Begin a transaction for a client.
cls | closure (internal context for the plugin) |
emsg | error message set of return code is GNUNET_SYSERR |
Definition at line 529 of file plugin_namestore_postgres.c.
Referenced by libgnunet_plugin_namestore_postgres_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 529 of file plugin_namestore_postgres.c.
Referenced by libgnunet_plugin_namestore_postgres_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 529 of file plugin_namestore_postgres.c.
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 728 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 742 of file plugin_namestore_postgres.c.
References cfg, GNUNET_NAMESTORE_PluginFunctions::cls, 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_create_tables(), namestore_postgres_drop_tables(), namestore_postgres_edit_records(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), namestore_postgres_store_records(), namestore_postgres_transaction_begin(), namestore_postgres_transaction_commit(), namestore_postgres_transaction_rollback(), namestore_postgres_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_postgres_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | the plugin context (as returned by "init") |
Definition at line 781 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.