GNUnet 0.22.2
plugin_namestore_postgres.c File Reference

postgres-based namestore backend More...

Include dependency graph for plugin_namestore_postgres.c:

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_CRYPTO_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 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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. 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...
 

Detailed Description

postgres-based namestore backend

Author
Christian Grothoff

Definition in file plugin_namestore_postgres.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "namestore-postgres", __VA_ARGS__)

Definition at line 32 of file plugin_namestore_postgres.c.

Function Documentation

◆ namestore_postgres_create_tables()

static enum GNUNET_GenericReturnValue namestore_postgres_create_tables ( void *  cls)
static

Initialize the database connections and associated data structures (create tables and indices as needed as well).

Parameters
clsthe plugin context (state for this module)
Returns
GNUNET_OK on success

Definition at line 65 of file plugin_namestore_postgres.c.

66{
67 struct Plugin *plugin = cls;
68 struct GNUNET_PQ_Context *dbh;
69
71 "namestore-postgres",
72 "namestore-",
73 NULL,
74 NULL);
75 if (NULL == dbh)
76 return GNUNET_SYSERR;
78 return GNUNET_OK;
79}
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
struct GNUNET_PQ_Context * GNUNET_PQ_connect_with_cfg(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *load_path_suffix, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps)
Connect to a postgres database using the configuration option "CONFIG" in section.
Definition: pq_connect.c:700
void GNUNET_PQ_disconnect(struct GNUNET_PQ_Context *db)
Disconnect from the database, destroying the prepared statements and releasing other associated resou...
Definition: pq_connect.c:765
@ GNUNET_OK
@ GNUNET_SYSERR
Handle to Postgres database.
Definition: pq.h:36
Handle for a plugin.
Definition: block.c:38

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_drop_tables()

static enum GNUNET_GenericReturnValue namestore_postgres_drop_tables ( void *  cls)
static

Drop existing namestore tables.

Parameters
clsthe plugin context (state for this module)
Returns
GNUNET_OK on success

Definition at line 89 of file plugin_namestore_postgres.c.

90{
91 struct Plugin *plugin = cls;
92 struct GNUNET_PQ_Context *dbh;
94
96 "namestore-postgres",
97 NULL,
98 NULL,
99 NULL);
100 if (NULL == dbh)
101 {
103 "Failed to connect to database\n");
104 return GNUNET_SYSERR;
105 }
106 ret = GNUNET_PQ_exec_sql (dbh,
107 "namestore-drop");
109 return ret;
110}
static int ret
Final status code.
Definition: gnunet-arm.c:93
enum GNUNET_GenericReturnValue GNUNET_PQ_exec_sql(struct GNUNET_PQ_Context *db, const char *buf)
Execute SQL statements from buf against db.
Definition: pq_connect.c:318
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_ERROR_TYPE_ERROR

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ database_prepare()

static enum GNUNET_GenericReturnValue database_prepare ( struct Plugin plugin)
static

Definition at line 114 of file plugin_namestore_postgres.c.

115{
117
118 if (plugin->ready)
119 return GNUNET_OK;
120 {
122 GNUNET_PQ_make_prepare ("store_records",
123 "INSERT INTO namestore.ns098records"
124 " (zone_private_key, pkey, rvalue, record_count, record_data, label, editor_hint)"
125 " VALUES ($1, $2, $3, $4, $5, $6, '')"
126 " ON CONFLICT ON CONSTRAINT zl"
127 " DO UPDATE"
128 " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5"
129 " WHERE ns098records.zone_private_key = $1"
130 " AND ns098records.label = $6"),
131 GNUNET_PQ_make_prepare ("delete_records",
132 "DELETE FROM namestore.ns098records "
133 "WHERE zone_private_key=$1 AND label=$2"),
134 GNUNET_PQ_make_prepare ("zone_to_name",
135 "SELECT seq,record_count,record_data,label,editor_hint FROM namestore.ns098records"
136 " WHERE zone_private_key=$1 AND pkey=$2"),
137 GNUNET_PQ_make_prepare ("iterate_zone",
138 "SELECT seq,record_count,record_data,label,editor_hint FROM namestore.ns098records "
139 "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3"),
140 GNUNET_PQ_make_prepare ("iterate_all_zones",
141 "SELECT seq,record_count,record_data,label,editor_hint,zone_private_key"
142 " FROM namestore.ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2"),
143 GNUNET_PQ_make_prepare ("lookup_label",
144 "SELECT seq,record_count,record_data,label,editor_hint "
145 "FROM namestore.ns098records WHERE zone_private_key=$1 AND label=$2"),
146 GNUNET_PQ_make_prepare ("edit_set",
147 "UPDATE namestore.ns098records x"
148 " SET editor_hint=$3"
149 " FROM ("
150 " SELECT * FROM namestore.ns098records"
151 " WHERE ns098records.zone_private_key=$1 AND ns098records.label=$2 FOR UPDATE) y"
152 " WHERE x.zone_private_key = y.zone_private_key AND"
153 " x.label = y.label"
154 " RETURNING x.seq,x.record_count,x.record_data,x.label,y.editor_hint "),
155 GNUNET_PQ_make_prepare ("clear_editor_hint",
156 "UPDATE namestore.ns098records"
157 " SET editor_hint=$4"
158 " WHERE zone_private_key=$1 AND label=$2 AND editor_hint=$3"),
160 };
161
163 ps);
164 }
165 if (GNUNET_OK != ret)
166 return ret;
167 plugin->ready = true;
168 return GNUNET_OK;
169}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
enum GNUNET_GenericReturnValue GNUNET_PQ_prepare_statements(struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_PreparedStatement *ps)
Request creation of prepared statements ps from Postgres.
Definition: pq_prepare.c:88
struct GNUNET_PQ_PreparedStatement GNUNET_PQ_make_prepare(const char *name, const char *sql)
Create a struct GNUNET_PQ_PreparedStatement.
Definition: pq_prepare.c:30
#define GNUNET_PQ_PREPARED_STATEMENT_END
Terminator for prepared statement list.
Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements().

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ database_connect()

static enum GNUNET_GenericReturnValue database_connect ( struct Plugin plugin)
static

Initialize the database connections and associated data structures (create tables and indices as needed as well).

Parameters
pluginthe plugin context (state for this module)
Returns
GNUNET_OK on success

Definition at line 181 of file plugin_namestore_postgres.c.

182{
183 struct GNUNET_PQ_ExecuteStatement ess[] = {
184 GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"),
186 };
188
189 if (GNUNET_YES ==
191 "namestore-postgres",
192 "ASYNC_COMMIT"))
193 es = &ess[0];
194 else
195 es = &ess[1];
196
197 if (GNUNET_YES ==
199 "namestore-postgres",
200 "INIT_ON_CONNECT"))
201 {
202 if (GNUNET_OK !=
204 {
206 "Failed to create tables\n");
207 return GNUNET_SYSERR;
208 }
209 }
211 "namestore-postgres",
212 NULL,
213 es,
214 NULL);
215 if (NULL == plugin->dbh)
216 return GNUNET_SYSERR;
217 return GNUNET_OK;
218}
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_try_execute(const char *sql)
Create a struct GNUNET_PQ_ExecuteStatement where errors should be tolerated.
Definition: pq_exec.c:42
#define GNUNET_PQ_EXECUTE_STATEMENT_END
Terminator for executable statement list.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
@ GNUNET_YES
static enum GNUNET_GenericReturnValue namestore_postgres_create_tables(void *cls)
Initialize the database connections and associated data structures (create tables and indices as need...
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_store_records()

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 
)
static

Store a record in the datastore.

Removes any existing record in the same zone with the same name.

Parameters
clsclosure (internal context for the plugin)
zone_keyprivate key of the zone
labelname that is being mapped (at most 255 characters long)
rd_countnumber of entries in rd array
rdarray of records with data to store
Returns
GNUNET_OK on success, else GNUNET_SYSERR

Definition at line 233 of file plugin_namestore_postgres.c.

239{
240 struct Plugin *plugin = cls;
242 uint64_t rvalue;
243 uint32_t rd_count32 = (uint32_t) rd_count;
244 ssize_t data_size;
245
247 memset (&pkey,
248 0,
249 sizeof(pkey));
250 for (unsigned int i = 0; i < rd_count; i++)
251 if (GNUNET_YES ==
252 GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
253 {
256 rd[i].data_size,
257 rd[i].record_type,
258 &pkey));
259 break;
260 }
262 UINT64_MAX);
264 rd);
265 if (data_size < 0)
266 {
267 GNUNET_break (0);
268 return GNUNET_SYSERR;
269 }
270 if (data_size >= UINT16_MAX)
271 {
272 GNUNET_break (0);
273 return GNUNET_SYSERR;
274 }
275 /* if record set is empty, delete existing records */
276 if (0 == rd_count)
277 {
278 struct GNUNET_PQ_QueryParam params[] = {
282 };
284
286 "delete_records",
287 params);
290 {
291 GNUNET_break (0);
292 return GNUNET_SYSERR;
293 }
295 "postgres",
296 "Record deleted\n");
297 return GNUNET_OK;
298 }
299 /* otherwise, UPSERT (i.e. UPDATE if exists, otherwise INSERT) */
300 {
301 char data[data_size];
302 struct GNUNET_PQ_QueryParam params[] = {
306 GNUNET_PQ_query_param_uint32 (&rd_count32),
310 };
312 ssize_t ret;
313
315 rd,
316 data_size,
317 data);
318 if ((ret < 0) ||
319 (data_size != ret))
320 {
321 GNUNET_break (0);
322 return GNUNET_SYSERR;
323 }
324
326 "store_records",
327 params);
329 return GNUNET_SYSERR;
330 }
331 return GNUNET_OK;
332}
static char * data
The data to insert into the dht.
static char * pkey
Public key of the zone to look in, in ASCII.
static unsigned int rd_count
Number of records for currently parsed set.
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static size_t data_size
Number of bytes in data.
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
Definition: gnunet_db_lib.h:37
@ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
The transaction succeeded, and yielded one result.
Definition: gnunet_db_lib.h:60
@ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
The transaction succeeded, but yielded zero results.
Definition: gnunet_db_lib.h:55
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
#define GNUNET_PQ_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
#define GNUNET_PQ_query_param_end
End of query parameter specification.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_non_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params)
Execute a named prepared statement that is NOT a SELECT statement in connection using the given param...
Definition: pq_eval.c:135
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string(const char *ptr)
Generate query parameter for a string.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_identity_from_data(const char *data, size_t data_size, uint32_t type, struct GNUNET_CRYPTO_PublicKey *key)
Build a #GNUNET_GNSRECORD_PublicKey from zone delegation resource record data.
ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type(uint32_t type)
Check if this type is one of the supported GNS zone types.
#define GNUNET_log_from(kind, comp,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
static enum GNUNET_GenericReturnValue database_prepare(struct Plugin *plugin)
An identity key as per LSD0001.
Description of a DB query parameter.
Definition: gnunet_pq_lib.h:83

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_result_call_iterator()

static void parse_result_call_iterator ( void *  cls,
PGresult *  res,
unsigned int  num_results 
)
static

A statement has been run.

We should evaluate the result, and if possible call the iter in cls with the result.

Parameters
clsclosure of type struct ParserContext *
resthe postgres result
num_resultsthe number of results in result

Definition at line 372 of file plugin_namestore_postgres.c.

375{
376 struct ParserContext *pc = cls;
377
378 if (NULL == pc->iter)
379 return; /* no need to do more work */
381 "Got %d results from PQ.\n", num_results);
382 for (unsigned int i = 0; i < num_results; i++)
383 {
384 uint64_t serial;
385 void *data;
386 size_t data_size;
387 uint32_t record_count;
388 char *label;
389 char *editor_hint;
390 struct GNUNET_CRYPTO_PrivateKey zk;
391 struct GNUNET_PQ_ResultSpec rs_with_zone[] = {
392 GNUNET_PQ_result_spec_uint64 ("seq", &serial),
395 GNUNET_PQ_result_spec_string ("label", &label),
396 GNUNET_PQ_result_spec_string ("editor_hint", &editor_hint),
397 GNUNET_PQ_result_spec_auto_from_type ("zone_private_key", &zk),
399 };
400 struct GNUNET_PQ_ResultSpec rs_without_zone[] = {
401 GNUNET_PQ_result_spec_uint64 ("seq", &serial),
404 GNUNET_PQ_result_spec_string ("label", &label),
405 GNUNET_PQ_result_spec_string ("editor_hint", &editor_hint),
407 };
408 struct GNUNET_PQ_ResultSpec *rs;
409
410 rs = (NULL == pc->zone_key) ? rs_with_zone : rs_without_zone;
411 if (GNUNET_YES !=
413 rs,
414 i))
415 {
416 GNUNET_break (0);
417 return;
418 }
419
420 if (record_count > 64 * 1024)
421 {
422 /* sanity check, don't stack allocate far too much just
423 because database might contain a large value here */
424 GNUNET_break (0);
426 return;
427 }
428
429 {
431
432 GNUNET_assert (0 != serial);
433 if (GNUNET_OK !=
435 data,
437 rd))
438 {
439 GNUNET_break (0);
441 return;
442 }
443 pc->iter (pc->iter_cls,
444 serial,
445 editor_hint,
446 (NULL == pc->zone_key) ? &zk : pc->zone_key,
447 label,
449 rd);
450 }
452 }
453 pc->limit -= num_results;
454}
static uint64_t record_count
Record count.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
#define GNUNET_PQ_result_spec_auto_from_type(name, dst)
We expect a fixed-size result, with size determined by the type of * dst
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64(const char *name, uint64_t *u64)
uint64_t expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string(const char *name, char **dst)
0-terminated string expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size(const char *name, void **dst, size_t *sptr)
Variable-size result expected.
void GNUNET_PQ_cleanup_result(struct GNUNET_PQ_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_PQ_extract_result().
Definition: pq.c:139
enum GNUNET_GenericReturnValue GNUNET_PQ_extract_result(PGresult *result, struct GNUNET_PQ_ResultSpec *rs, int row)
Extract results from a query result according to the given specification.
Definition: pq.c:149
#define GNUNET_PQ_result_spec_end
End of result parameter specification.
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
#define GNUNET_NZL(l)
Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).
#define LOG(kind,...)
A private key for an identity as per LSD0001.
Description of a DB result cell.
Closure for parse_result_call_iterator.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_lookup_records()

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 
)
static

Lookup records in the datastore for which we are the authority.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone
labelname of the record in the zone
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 468 of file plugin_namestore_postgres.c.

474{
475 struct Plugin *plugin = cls;
476 struct GNUNET_PQ_QueryParam params[] = {
480 };
481 struct ParserContext pc;
484
485 if (NULL == zone)
486 {
487 GNUNET_break (0);
488 return GNUNET_SYSERR;
489 }
490 pc.iter = iter;
491 pc.iter_cls = iter_cls;
492 pc.zone_key = zone;
494 "lookup_label",
495 params,
497 &pc);
498 if (res < 0)
499 return GNUNET_SYSERR;
501 return GNUNET_NO;
502 return GNUNET_OK;
503}
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_multi_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params, GNUNET_PQ_PostgresResultHandler rh, void *rh_cls)
Execute a named prepared statement that is a SELECT statement which may return multiple results in co...
Definition: pq_eval.c:165
@ GNUNET_NO
static void parse_result_call_iterator(void *cls, PGresult *res, unsigned int num_results)
A statement has been run.
void * iter_cls
Closure for iter.
GNUNET_NAMESTORE_RecordIterator iter
Function to call for each result.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_clear_editor_hint()

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
Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone
labelname of the record in the zone
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 516 of file plugin_namestore_postgres.c.

522{
523
524 struct Plugin *plugin = cls;
526
528 memset (&pkey,
529 0,
530 sizeof(pkey));
531 {
532 struct GNUNET_PQ_QueryParam params[] = {
535 GNUNET_PQ_query_param_string (editor_hint),
536 GNUNET_PQ_query_param_string (editor_hint_replacement),
538 };
540
542 "clear_editor_hint",
543 params);
546 return GNUNET_SYSERR;
547 }
548 return GNUNET_OK;
549}

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_edit_records()

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 
)
static

Edit records in the datastore for which we are the authority.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone
labelname of the record in the zone
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 563 of file plugin_namestore_postgres.c.

570{
571 struct Plugin *plugin = cls;
572 struct GNUNET_PQ_QueryParam params[] = {
575 GNUNET_PQ_query_param_string (editor_hint),
577 };
578 struct ParserContext pc;
581
582 if (NULL == zone)
583 {
584 GNUNET_break (0);
585 return GNUNET_SYSERR;
586 }
587 pc.iter = iter;
588 pc.iter_cls = iter_cls;
589 pc.zone_key = zone;
591 "edit_set",
592 params,
594 &pc);
595 if (res < 0)
596 return GNUNET_SYSERR;
598 return GNUNET_NO;
599 return GNUNET_OK;
600}

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_iterate_records()

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 
)
static

Iterate over the results for a particular key and zone in the datastore.

Will return at most one result to the iterator.

Parameters
clsclosure (internal context for the plugin)
zonehash of public key of the zone, NULL to iterate over all zones
serialserial number to exclude in the list of all matching records
limitmaximum number of results to fetch
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO if there were no more results, GNUNET_SYSERR on error

Definition at line 616 of file plugin_namestore_postgres.c.

623{
624 struct Plugin *plugin = cls;
626 struct ParserContext pc;
627
629 pc.iter = iter;
630 pc.iter_cls = iter_cls;
631 pc.zone_key = zone;
632 pc.limit = limit;
633 if (NULL == zone)
634 {
635 struct GNUNET_PQ_QueryParam params_without_zone[] = {
639 };
640
642 "iterate_all_zones",
643 params_without_zone,
645 &pc);
646 }
647 else
648 {
649 struct GNUNET_PQ_QueryParam params_with_zone[] = {
654 };
655
657 "iterate_zone",
658 params_with_zone,
660 &pc);
661 }
662 if (res < 0)
663 return GNUNET_SYSERR;
664
666 (pc.limit > 0))
667 return GNUNET_NO;
668 return GNUNET_OK;
669}
uint64_t limit
Number of results still to return (counted down by number of results given to iterator).

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_zone_to_name()

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 
)
static

Look for an existing PKEY delegation record for a given public key.

Returns at most one result to the iterator.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone to look up in, never NULL
value_zonepublic key of the target zone (value), never NULL
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error

Definition at line 684 of file plugin_namestore_postgres.c.

691{
692 struct Plugin *plugin = cls;
693 struct GNUNET_PQ_QueryParam params[] = {
697 };
699 struct ParserContext pc;
701
702 pc.iter = iter;
703 pc.iter_cls = iter_cls;
704 pc.zone_key = zone;
706 "zone_to_name",
707 params,
709 &pc);
710 if (res < 0)
711 return GNUNET_SYSERR;
712 return GNUNET_OK;
713}

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_begin_tx()

static int namestore_postgres_begin_tx ( void *  cls)
static
Parameters
clsclosure (internal context for the plugin)
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 722 of file plugin_namestore_postgres.c.

723{
724
725 struct Plugin *plugin = cls;
726
727 struct GNUNET_PQ_ExecuteStatement ess[] = {
730 };
732 return GNUNET_PQ_exec_statements (plugin->dbh, ess);
733}
enum GNUNET_GenericReturnValue GNUNET_PQ_exec_statements(struct GNUNET_PQ_Context *db, const struct GNUNET_PQ_ExecuteStatement *es)
Request execution of an array of statements es from Postgres.
Definition: pq_exec.c:54

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_commit_tx()

static int namestore_postgres_commit_tx ( void *  cls)
static
Parameters
clsclosure (internal context for the plugin)
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 742 of file plugin_namestore_postgres.c.

743{
744
745 struct Plugin *plugin = cls;
746
747 struct GNUNET_PQ_ExecuteStatement ess[] = {
750 };
752 return GNUNET_PQ_exec_statements (plugin->dbh, ess);
753}

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_postgres_rollback_tx()

static int namestore_postgres_rollback_tx ( void *  cls)
static
Parameters
clsclosure (internal context for the plugin)
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 762 of file plugin_namestore_postgres.c.

763{
764
765 struct Plugin *plugin = cls;
766
767 struct GNUNET_PQ_ExecuteStatement ess[] = {
768 GNUNET_PQ_make_try_execute ("ROLLBACK"),
770 };
772 return GNUNET_PQ_exec_statements (plugin->dbh, ess);
773}

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ database_shutdown()

static void database_shutdown ( struct Plugin plugin)
static

Shutdown database connection and associate data structures.

Parameters
pluginthe plugin context (state for this module)

Definition at line 783 of file plugin_namestore_postgres.c.

784{
786 plugin->dbh = NULL;
787}

References GNUNET_PQ_disconnect(), and plugin.

Referenced by libgnunet_plugin_namestore_postgres_done(), and libgnunet_plugin_namestore_postgres_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_namestore_postgres_init()

void * libgnunet_plugin_namestore_postgres_init ( void *  cls)

Entry point for the plugin.

Parameters
clsthe struct GNUNET_NAMESTORE_PluginEnvironment*
Returns
NULL on error, othrewise the plugin context

Definition at line 799 of file plugin_namestore_postgres.c.

800{
801 struct Plugin *plugin;
802 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
804
805 plugin = GNUNET_new (struct Plugin);
806 plugin->cfg = cfg;
808 {
811 return NULL;
812 }
814 api->cls = plugin;
827 "Postgres namestore plugin running\n");
828 return api;
829}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
static int namestore_postgres_commit_tx(void *cls)
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 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 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_rollback_tx(void *cls)
static enum GNUNET_GenericReturnValue namestore_postgres_drop_tables(void *cls)
Drop existing namestore tables.
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
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 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_begin_tx(void *cls)
static enum GNUNET_GenericReturnValue database_connect(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
struct returned by the initialization function of the plugin
enum GNUNET_GenericReturnValue(* clear_editor_hint)(void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label)
This clears the editor hint, unless it does not match the given editor hint, in which case this is a ...
enum GNUNET_GenericReturnValue(* 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.
enum GNUNET_GenericReturnValue(* create_tables)(void *cls)
Setup the database.
enum GNUNET_GenericReturnValue(* edit_records)(void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Transaction-based API draft.
enum GNUNET_GenericReturnValue(* rollback_tx)(void *cls)
Tell plugin to rollback what we started with begin_tx This may be a NOP (and thus NOT roll anything b...
enum GNUNET_GenericReturnValue(* 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 zone in the datastore.
enum GNUNET_GenericReturnValue(* 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.
enum GNUNET_GenericReturnValue(* begin_tx)(void *cls)
Tell plugin that a set of procedures are coming that are ideally handled within a single TX (BEGIN/CO...
enum GNUNET_GenericReturnValue(* commit_tx)(void *cls)
Tell plugin the we finished what we started with begin_tx.
enum GNUNET_GenericReturnValue(* drop_tables)(void *cls)
Drop existing tables.
void * cls
Closure to pass to all plugin functions.
enum GNUNET_GenericReturnValue(* store_records)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Store a record in the datastore for which we are the authority.

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.

Here is the call graph for this function:

◆ libgnunet_plugin_namestore_postgres_done()

void * libgnunet_plugin_namestore_postgres_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe plugin context (as returned by "init")
Returns
always NULL

Definition at line 842 of file plugin_namestore_postgres.c.

843{
845 struct Plugin *plugin = api->cls;
846
848 plugin->cfg = NULL;
852 "Postgres namestore plugin is finished\n");
853 return NULL;
854}
void * cls
Closure for all of the callbacks.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_NAMESTORE_PluginFunctions::cls, database_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, LOG, and plugin.

Here is the call graph for this function: