GNUnet 0.21.1
plugin_namestore_postgres.c
Go to the documentation of this file.
1/*
2 * This file is part of GNUnet
3 * Copyright (C) 2009-2013, 2016-2018 GNUnet e.V.
4 *
5 * GNUnet is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License,
8 * or (at your option) any later version.
9 *
10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "gnunet_db_lib.h"
29#include "gnunet_pq_lib.h"
30
31
32#define LOG(kind, ...) GNUNET_log_from (kind, "namestore-postgres", __VA_ARGS__)
33
34
38struct Plugin
39{
43 const struct GNUNET_CONFIGURATION_Handle *cfg;
44
48 struct GNUNET_PQ_Context *dbh;
49
53 bool ready;
54};
55
56
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}
80
81
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}
111
112
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"
148 " SET editor_hint=$3"
149 " FROM namestore.ns098records AS old_ns098records"
150 " WHERE ns098records.zone_private_key=$1 AND ns098records.label=$2"
151 " RETURNING ns098records.seq,ns098records.record_count,ns098records.record_data,ns098records.label,old_ns098records.editor_hint "),
152 GNUNET_PQ_make_prepare ("clear_editor_hint",
153 "UPDATE namestore.ns098records"
154 " SET editor_hint=$4"
155 " WHERE zone_private_key=$1 AND label=$2 AND editor_hint=$3"),
157 };
158
160 ps);
161 }
162 if (GNUNET_OK != ret)
163 return ret;
164 plugin->ready = true;
165 return GNUNET_OK;
166}
167
168
179{
180 struct GNUNET_PQ_ExecuteStatement ess[] = {
181 GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"),
183 };
185
186 if (GNUNET_YES ==
188 "namestore-postgres",
189 "ASYNC_COMMIT"))
190 es = &ess[0];
191 else
192 es = &ess[1];
193
194 if (GNUNET_YES ==
196 "namestore-postgres",
197 "INIT_ON_CONNECT"))
198 {
199 if (GNUNET_OK !=
201 {
203 "Failed to create tables\n");
204 return GNUNET_SYSERR;
205 }
206 }
208 "namestore-postgres",
209 NULL,
210 es,
211 NULL);
212 if (NULL == plugin->dbh)
213 return GNUNET_SYSERR;
214 return GNUNET_OK;
215}
216
217
231 const struct
232 GNUNET_CRYPTO_PrivateKey *zone_key,
233 const char *label,
234 unsigned int rd_count,
235 const struct GNUNET_GNSRECORD_Data *rd)
236{
237 struct Plugin *plugin = cls;
239 uint64_t rvalue;
240 uint32_t rd_count32 = (uint32_t) rd_count;
241 ssize_t data_size;
242
244 memset (&pkey,
245 0,
246 sizeof(pkey));
247 for (unsigned int i = 0; i < rd_count; i++)
248 if (GNUNET_YES ==
249 GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
250 {
253 rd[i].data_size,
254 rd[i].record_type,
255 &pkey));
256 break;
257 }
259 UINT64_MAX);
261 rd);
262 if (data_size < 0)
263 {
264 GNUNET_break (0);
265 return GNUNET_SYSERR;
266 }
267 if (data_size >= UINT16_MAX)
268 {
269 GNUNET_break (0);
270 return GNUNET_SYSERR;
271 }
272 /* if record set is empty, delete existing records */
273 if (0 == rd_count)
274 {
275 struct GNUNET_PQ_QueryParam params[] = {
279 };
281
283 "delete_records",
284 params);
287 {
288 GNUNET_break (0);
289 return GNUNET_SYSERR;
290 }
292 "postgres",
293 "Record deleted\n");
294 return GNUNET_OK;
295 }
296 /* otherwise, UPSERT (i.e. UPDATE if exists, otherwise INSERT) */
297 {
298 char data[data_size];
299 struct GNUNET_PQ_QueryParam params[] = {
303 GNUNET_PQ_query_param_uint32 (&rd_count32),
307 };
309 ssize_t ret;
310
312 rd,
313 data_size,
314 data);
315 if ((ret < 0) ||
316 (data_size != ret))
317 {
318 GNUNET_break (0);
319 return GNUNET_SYSERR;
320 }
321
323 "store_records",
324 params);
326 return GNUNET_SYSERR;
327 }
328 return GNUNET_OK;
329}
330
331
336{
341
345 void *iter_cls;
346
351
356 uint64_t limit;
357};
358
359
368static void
370 PGresult *res,
371 unsigned int num_results)
372{
373 struct ParserContext *pc = cls;
374
375 if (NULL == pc->iter)
376 return; /* no need to do more work */
378 "Got %d results from PQ.\n", num_results);
379 for (unsigned int i = 0; i < num_results; i++)
380 {
381 uint64_t serial;
382 void *data;
383 size_t data_size;
384 uint32_t record_count;
385 char *label;
386 char *editor_hint;
387 struct GNUNET_CRYPTO_PrivateKey zk;
388 struct GNUNET_PQ_ResultSpec rs_with_zone[] = {
389 GNUNET_PQ_result_spec_uint64 ("seq", &serial),
392 GNUNET_PQ_result_spec_string ("label", &label),
393 GNUNET_PQ_result_spec_string ("editor_hint", &editor_hint),
394 GNUNET_PQ_result_spec_auto_from_type ("zone_private_key", &zk),
396 };
397 struct GNUNET_PQ_ResultSpec rs_without_zone[] = {
398 GNUNET_PQ_result_spec_uint64 ("seq", &serial),
401 GNUNET_PQ_result_spec_string ("label", &label),
402 GNUNET_PQ_result_spec_string ("editor_hint", &editor_hint),
404 };
405 struct GNUNET_PQ_ResultSpec *rs;
406
407 rs = (NULL == pc->zone_key) ? rs_with_zone : rs_without_zone;
408 if (GNUNET_YES !=
410 rs,
411 i))
412 {
413 GNUNET_break (0);
414 return;
415 }
416
417 if (record_count > 64 * 1024)
418 {
419 /* sanity check, don't stack allocate far too much just
420 because database might contain a large value here */
421 GNUNET_break (0);
423 return;
424 }
425
426 {
428
429 GNUNET_assert (0 != serial);
430 if (GNUNET_OK !=
432 data,
434 rd))
435 {
436 GNUNET_break (0);
438 return;
439 }
440 pc->iter (pc->iter_cls,
441 serial,
442 editor_hint,
443 (NULL == pc->zone_key) ? &zk : pc->zone_key,
444 label,
446 rd);
447 }
449 }
450 pc->limit -= num_results;
451}
452
453
466 const struct
468 const char *label,
470 void *iter_cls)
471{
472 struct Plugin *plugin = cls;
474 struct GNUNET_PQ_QueryParam params[] = {
478 };
479 struct ParserContext pc;
481
482 if (NULL == zone)
483 {
484 GNUNET_break (0);
485 return GNUNET_SYSERR;
486 }
487 pc.iter = iter;
488 pc.iter_cls = iter_cls;
489 pc.zone_key = zone;
491 "lookup_label",
492 params,
494 &pc);
495 if (res < 0)
496 return GNUNET_SYSERR;
498 return GNUNET_NO;
499 return GNUNET_OK;
500}
501
502
512static int
514 const char *editor_hint,
515 const char *editor_hint_replacement,
516 const struct
518 const char *label)
519{
520
521 struct Plugin *plugin = cls;
523
525 memset (&pkey,
526 0,
527 sizeof(pkey));
528 {
529 struct GNUNET_PQ_QueryParam params[] = {
532 GNUNET_PQ_query_param_string (editor_hint),
533 GNUNET_PQ_query_param_string (editor_hint_replacement),
535 };
537
539 "clear_editor_hint",
540 params);
543 return GNUNET_SYSERR;
544 }
545 return GNUNET_OK;
546}
547
548
559static int
561 const char *editor_hint,
562 const struct
564 const char *label,
566 void *iter_cls)
567{
568 struct Plugin *plugin = cls;
570 struct GNUNET_PQ_QueryParam params[] = {
573 GNUNET_PQ_query_param_string (editor_hint),
575 };
576 struct ParserContext pc;
578
579 if (NULL == zone)
580 {
581 GNUNET_break (0);
582 return GNUNET_SYSERR;
583 }
584 pc.iter = iter;
585 pc.iter_cls = iter_cls;
586 pc.zone_key = zone;
588 "edit_set",
589 params,
591 &pc);
592 if (res < 0)
593 return GNUNET_SYSERR;
595 return GNUNET_NO;
596 return GNUNET_OK;
597}
598
599
614 const struct
616 uint64_t serial,
617 uint64_t limit,
619 void *iter_cls)
620{
621 struct Plugin *plugin = cls;
623 struct ParserContext pc;
624
626 pc.iter = iter;
627 pc.iter_cls = iter_cls;
628 pc.zone_key = zone;
629 pc.limit = limit;
630 if (NULL == zone)
631 {
632 struct GNUNET_PQ_QueryParam params_without_zone[] = {
636 };
637
639 "iterate_all_zones",
640 params_without_zone,
642 &pc);
643 }
644 else
645 {
646 struct GNUNET_PQ_QueryParam params_with_zone[] = {
651 };
652
654 "iterate_zone",
655 params_with_zone,
657 &pc);
658 }
659 if (res < 0)
660 return GNUNET_SYSERR;
661
663 (pc.limit > 0))
664 return GNUNET_NO;
665 return GNUNET_OK;
666}
667
668
682 const struct
684 const struct
685 GNUNET_CRYPTO_PublicKey *value_zone,
687 void *iter_cls)
688{
689 struct Plugin *plugin = cls;
691 struct GNUNET_PQ_QueryParam params[] = {
695 };
697 struct ParserContext pc;
698
699 pc.iter = iter;
700 pc.iter_cls = iter_cls;
701 pc.zone_key = zone;
703 "zone_to_name",
704 params,
706 &pc);
707 if (res < 0)
708 return GNUNET_SYSERR;
709 return GNUNET_OK;
710}
711
712
719static void
721{
723 plugin->dbh = NULL;
724}
725
726
733void *
735{
736 struct Plugin *plugin;
737 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
739
740 plugin = GNUNET_new (struct Plugin);
741 plugin->cfg = cfg;
743 {
746 return NULL;
747 }
749 api->cls = plugin;
759 "Postgres namestore plugin running\n");
760 return api;
761}
762
763
770void *
772{
774 struct Plugin *plugin = api->cls;
775
777 plugin->cfg = NULL;
781 "Postgres namestore plugin is finished\n");
782 return NULL;
783}
784
785
786/* end of plugin_namestore_postgres.c */
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
struct TestcasePlugin * plugin
The process handle to the testbed service.
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
static uint64_t record_count
Record count.
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.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
shared definitions for transactional databases
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
API that can be used to manipulate GNS record data.
Plugin API for the namestore database backend.
helper functions for Postgres DB interactions
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.
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
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
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:619
#define GNUNET_PQ_result_spec_auto_from_type(name, dst)
We expect a fixed-size result, with size determined by the type of * dst
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_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.
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:684
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
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_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.
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
#define GNUNET_PQ_PREPARED_STATEMENT_END
Terminator for prepared statement list.
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_EXECUTE_STATEMENT_END
Terminator for executable statement list.
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.
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:144
#define GNUNET_PQ_result_spec_end
End of result parameter specification.
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".
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).
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.
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(kind,...)
#define GNUNET_log_from(kind, comp,...)
#define GNUNET_NZL(l)
Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#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_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void(* GNUNET_NAMESTORE_RecordIterator)(void *cls, uint64_t serial, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *private_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called for each matching record.
static enum GNUNET_GenericReturnValue database_prepare(struct Plugin *plugin)
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.
void * libgnunet_plugin_namestore_postgres_done(void *cls)
Exit point from the plugin.
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_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.
void * libgnunet_plugin_namestore_postgres_init(void *cls)
Entry point for the plugin.
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 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 enum GNUNET_GenericReturnValue namestore_postgres_create_tables(void *cls)
Initialize the database connections and associated data structures (create tables and indices as need...
#define LOG(kind,...)
static enum GNUNET_GenericReturnValue database_connect(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
void * cls
Closure for all of the callbacks.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
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(* 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(* 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.
Handle to Postgres database.
Definition: pq.h:36
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements().
Description of a DB query parameter.
Definition: gnunet_pq_lib.h:83
Description of a DB result cell.
Closure for parse_result_call_iterator.
uint64_t limit
Number of results still to return (counted down by number of results given to iterator).
const struct GNUNET_CRYPTO_PrivateKey * zone_key
Zone key, NULL if part of record.
void * iter_cls
Closure for iter.
GNUNET_NAMESTORE_RecordIterator iter
Function to call for each result.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
bool ready
Database is prepared and ready.
struct GNUNET_PQ_Context * dbh
Native Postgres database handle.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.