GNUnet 0.28.0-dev.3-20-gf1136b0b8
 
Loading...
Searching...
No Matches
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
64static void
65reconnect_cb (void *cls,
66 struct GNUNET_PQ_Context *db)
67{
70 "namestore-"));
71}
72
73
83{
84 struct Plugin *plugin = cls;
85 struct GNUNET_PQ_Context *dbh;
86
87 dbh = GNUNET_PQ_init (plugin->cfg,
88 "namestore-postgres",
90 NULL);
91 if (NULL == dbh)
92 return GNUNET_SYSERR;
94 return GNUNET_OK;
95}
96
97
106{
107 struct Plugin *plugin = cls;
108 struct GNUNET_PQ_Context *dbh;
110
111 dbh = GNUNET_PQ_init (plugin->cfg,
112 "namestore-postgres",
113 NULL,
114 NULL);
115 if (NULL == dbh)
116 {
118 "Failed to connect to database\n");
119 return GNUNET_SYSERR;
120 }
121 ret = GNUNET_PQ_exec_sql (dbh,
122 "namestore-drop");
124 return ret;
125}
126
127
130{
131 return (plugin->ready) ? GNUNET_OK : GNUNET_SYSERR;
132}
133
134
142static void
144 struct GNUNET_PQ_Context *pq)
145{
146 struct Plugin *plugin = cls;
147 struct GNUNET_PQ_ExecuteStatement ess[] = {
148 GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"),
150 };
152 GNUNET_PQ_make_prepare ("store_records",
153 "INSERT INTO namestore.ns098records"
154 " (zone_private_key, pkey, rvalue, record_count, record_data, label, editor_hint)"
155 " VALUES ($1, $2, $3, $4, $5, $6, '')"
156 " ON CONFLICT ON CONSTRAINT zl"
157 " DO UPDATE"
158 " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5"
159 " WHERE ns098records.zone_private_key = $1"
160 " AND ns098records.label = $6"),
161 GNUNET_PQ_make_prepare ("delete_records",
162 "DELETE FROM namestore.ns098records "
163 "WHERE zone_private_key=$1 AND label=$2"),
164 GNUNET_PQ_make_prepare ("zone_to_name",
165 "SELECT seq,record_count,record_data,label,editor_hint FROM namestore.ns098records"
166 " WHERE zone_private_key=$1 AND pkey=$2"),
167 GNUNET_PQ_make_prepare ("iterate_zone",
168 "SELECT seq,record_count,record_data,label,editor_hint FROM namestore.ns098records "
169 "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3"),
170 GNUNET_PQ_make_prepare ("iterate_all_zones",
171 "SELECT seq,record_count,record_data,label,editor_hint,zone_private_key"
172 " FROM namestore.ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2")
173 ,
174 GNUNET_PQ_make_prepare ("lookup_label",
175 "SELECT seq,record_count,record_data,label,editor_hint "
176 "FROM namestore.ns098records WHERE zone_private_key=$1 AND label=$2"),
177 GNUNET_PQ_make_prepare ("edit_set",
178 "UPDATE namestore.ns098records x"
179 " SET editor_hint=$3"
180 " FROM ("
181 " SELECT * FROM namestore.ns098records"
182 " WHERE ns098records.zone_private_key=$1 AND ns098records.label=$2 FOR UPDATE) y"
183 " WHERE x.zone_private_key = y.zone_private_key AND"
184 " x.label = y.label"
185 " RETURNING x.seq,x.record_count,x.record_data,x.label,y.editor_hint "),
186 GNUNET_PQ_make_prepare ("clear_editor_hint",
187 "UPDATE namestore.ns098records"
188 " SET editor_hint=$4"
189 " WHERE zone_private_key=$1 AND label=$2 AND editor_hint=$3"),
191 };
192
193 if (GNUNET_YES ==
195 "namestore-postgres",
196 "ASYNC_COMMIT"))
197 {
200 ess));
201 }
202
203 if (GNUNET_YES ==
205 "namestore-postgres",
206 "INIT_ON_CONNECT"))
207 {
208 if (GNUNET_OK !=
210 {
212 "Failed to create tables\n");
213 plugin->ready = false;
214 return;
215 }
216 }
217 if (GNUNET_OK !=
219 ps))
220 {
221 plugin->ready = false;
222 return;
223 }
224 plugin->ready = true;
225}
226
227
238{
239 plugin->dbh = GNUNET_PQ_init (plugin->cfg,
240 "namestore-postgres",
242 plugin);
243 if (NULL == plugin->dbh)
244 return GNUNET_SYSERR;
245 if (! plugin->ready)
246 return GNUNET_NO;
247 return GNUNET_OK;
248}
249
250
264 void *cls,
265 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key,
266 const char *label,
267 unsigned int rd_count,
268 const struct GNUNET_GNSRECORD_Data *rd)
269{
270 struct Plugin *plugin = cls;
272 uint64_t rvalue;
273 uint32_t rd_count32 = (uint32_t) rd_count;
274 ssize_t data_size;
275
277 memset (&pkey,
278 0,
279 sizeof(pkey));
280 for (unsigned int i = 0; i < rd_count; i++)
281 if (GNUNET_YES ==
282 GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
283 {
286 rd[i].data_size,
287 rd[i].record_type,
288 &pkey));
289 break;
290 }
291 rvalue = GNUNET_CRYPTO_random_u64 (UINT64_MAX);
293 rd);
294 if (data_size < 0)
295 {
296 GNUNET_break (0);
297 return GNUNET_SYSERR;
298 }
299 if (data_size >= UINT16_MAX)
300 {
301 GNUNET_break (0);
302 return GNUNET_SYSERR;
303 }
304 /* if record set is empty, delete existing records */
305 if (0 == rd_count)
306 {
307 struct GNUNET_PQ_QueryParam params[] = {
311 };
313
315 "delete_records",
316 params);
319 {
320 GNUNET_break (0);
321 return GNUNET_SYSERR;
322 }
324 "postgres",
325 "Record deleted\n");
326 return GNUNET_OK;
327 }
328 /* otherwise, UPSERT (i.e. UPDATE if exists, otherwise INSERT) */
329 {
330 char data[data_size];
331 struct GNUNET_PQ_QueryParam params[] = {
335 GNUNET_PQ_query_param_uint32 (&rd_count32),
339 };
341 ssize_t ret;
342
344 rd,
345 data_size,
346 data);
347 if ((ret < 0) ||
348 (data_size != ret))
349 {
350 GNUNET_break (0);
351 return GNUNET_SYSERR;
352 }
353
355 "store_records",
356 params);
358 return GNUNET_SYSERR;
359 }
360 return GNUNET_OK;
361}
362
363
390
391
400static void
402 PGresult *res,
403 unsigned int num_results)
404{
405 struct ParserContext *pc = cls;
406
407 if (NULL == pc->iter)
408 return; /* no need to do more work */
410 "Got %d results from PQ.\n", num_results);
411 for (unsigned int i = 0; i < num_results; i++)
412 {
413 uint64_t serial;
414 void *data;
415 size_t data_size;
416 uint32_t record_count;
417 char *label;
418 char *editor_hint;
420 struct GNUNET_PQ_ResultSpec rs_with_zone[] = {
421 GNUNET_PQ_result_spec_uint64 ("seq", &serial),
424 GNUNET_PQ_result_spec_string ("label", &label),
425 GNUNET_PQ_result_spec_string ("editor_hint", &editor_hint),
426 GNUNET_PQ_result_spec_auto_from_type ("zone_private_key", &zk),
428 };
429 struct GNUNET_PQ_ResultSpec rs_without_zone[] = {
430 GNUNET_PQ_result_spec_uint64 ("seq", &serial),
433 GNUNET_PQ_result_spec_string ("label", &label),
434 GNUNET_PQ_result_spec_string ("editor_hint", &editor_hint),
436 };
437 struct GNUNET_PQ_ResultSpec *rs;
438
439 rs = (NULL == pc->zone_key) ? rs_with_zone : rs_without_zone;
440 if (GNUNET_YES !=
442 rs,
443 i))
444 {
445 GNUNET_break (0);
446 return;
447 }
448
449 if (record_count > 64 * 1024)
450 {
451 /* sanity check, don't stack allocate far too much just
452 because database might contain a large value here */
453 GNUNET_break (0);
455 return;
456 }
457
458 {
460
461 GNUNET_assert (0 != serial);
462 if (GNUNET_OK !=
464 data,
466 rd))
467 {
468 GNUNET_break (0);
470 return;
471 }
472 pc->iter (pc->iter_cls,
473 serial,
474 editor_hint,
475 (NULL == pc->zone_key) ? &zk : pc->zone_key,
476 label,
478 rd);
479 }
481 }
482 pc->limit -= num_results;
483}
484
485
498 const struct
500 const char *label,
502 void *iter_cls)
503{
504 struct Plugin *plugin = cls;
505 struct GNUNET_PQ_QueryParam params[] = {
509 };
510 struct ParserContext pc;
513
514 if (NULL == zone)
515 {
516 GNUNET_break (0);
517 return GNUNET_SYSERR;
518 }
519 pc.iter = iter;
520 pc.iter_cls = iter_cls;
521 pc.zone_key = zone;
523 "lookup_label",
524 params,
526 &pc);
527 if (res < 0)
528 return GNUNET_SYSERR;
530 return GNUNET_NO;
531 return GNUNET_OK;
532}
533
534
544static int
546 const char *editor_hint,
547 const char *editor_hint_replacement,
548 const struct
550 const char *label)
551{
552
553 struct Plugin *plugin = cls;
555
557 memset (&pkey,
558 0,
559 sizeof(pkey));
560 {
561 struct GNUNET_PQ_QueryParam params[] = {
564 GNUNET_PQ_query_param_string (editor_hint),
565 GNUNET_PQ_query_param_string (editor_hint_replacement),
567 };
569
571 "clear_editor_hint",
572 params);
575 return GNUNET_SYSERR;
576 }
577 return GNUNET_OK;
578}
579
580
591static int
593 const char *editor_hint,
594 const struct
596 const char *label,
598 void *iter_cls)
599{
600 struct Plugin *plugin = cls;
601 struct GNUNET_PQ_QueryParam params[] = {
604 GNUNET_PQ_query_param_string (editor_hint),
606 };
607 struct ParserContext pc;
610
611 if (NULL == zone)
612 {
613 GNUNET_break (0);
614 return GNUNET_SYSERR;
615 }
616 pc.iter = iter;
617 pc.iter_cls = iter_cls;
618 pc.zone_key = zone;
620 "edit_set",
621 params,
623 &pc);
624 if (res < 0)
625 return GNUNET_SYSERR;
627 return GNUNET_NO;
628 return GNUNET_OK;
629}
630
631
646 const struct
648 uint64_t serial,
649 uint64_t limit,
651 void *iter_cls)
652{
653 struct Plugin *plugin = cls;
655 struct ParserContext pc;
656
658 pc.iter = iter;
659 pc.iter_cls = iter_cls;
660 pc.zone_key = zone;
661 pc.limit = limit;
662 if (NULL == zone)
663 {
664 struct GNUNET_PQ_QueryParam params_without_zone[] = {
668 };
669
671 "iterate_all_zones",
672 params_without_zone,
674 &pc);
675 }
676 else
677 {
678 struct GNUNET_PQ_QueryParam params_with_zone[] = {
683 };
684
686 "iterate_zone",
687 params_with_zone,
689 &pc);
690 }
691 if (res < 0)
692 return GNUNET_SYSERR;
693
695 (pc.limit > 0))
696 return GNUNET_NO;
697 return GNUNET_OK;
698}
699
700
714 const struct
716 const struct
719 void *iter_cls)
720{
721 struct Plugin *plugin = cls;
722 struct GNUNET_PQ_QueryParam params[] = {
726 };
728 struct ParserContext pc;
730
731 pc.iter = iter;
732 pc.iter_cls = iter_cls;
733 pc.zone_key = zone;
735 "zone_to_name",
736 params,
738 &pc);
739 if (res < 0)
740 return GNUNET_SYSERR;
741 return GNUNET_OK;
742}
743
744
750static int
752{
753
754 struct Plugin *plugin = cls;
755
756 struct GNUNET_PQ_ExecuteStatement ess[] = {
759 };
761 return GNUNET_PQ_exec_statements (plugin->dbh, ess);
762}
763
764
770static int
772{
773
774 struct Plugin *plugin = cls;
775
776 struct GNUNET_PQ_ExecuteStatement ess[] = {
779 };
781 return GNUNET_PQ_exec_statements (plugin->dbh, ess);
782}
783
784
790static int
792{
793
794 struct Plugin *plugin = cls;
795
796 struct GNUNET_PQ_ExecuteStatement ess[] = {
797 GNUNET_PQ_make_try_execute ("ROLLBACK"),
799 };
801 return GNUNET_PQ_exec_statements (plugin->dbh, ess);
802}
803
804
811static void
813{
815 plugin->dbh = NULL;
816}
817
818
820
827void *
859
860
861void *
863
870void *
872{
874 struct Plugin *plugin = api->cls;
875
877 plugin->cfg = NULL;
881 "Postgres namestore plugin is finished\n");
882 return NULL;
883}
884
885
886/* end of plugin_namestore_postgres.c */
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
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.
static struct GNUNET_FS_DirectoryBuilder * db
shared definitions for transactional databases
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
@ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
The transaction succeeded, and yielded one result.
@ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
The transaction succeeded, but yielded zero results.
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.
#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_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
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:73
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:678
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_Context * GNUNET_PQ_init(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_PQ_ReconnectCallback rc, void *rc_cls)
Connect to a postgres database using the configuration option "CONFIG" in section.
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:142
#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:152
#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:294
#define GNUNET_PQ_result_spec_end
End of result parameter specification.
enum GNUNET_GenericReturnValue GNUNET_PQ_run_sql(struct GNUNET_PQ_Context *db, const char *load_suffix)
Within the db context, run all the SQL files in the load path where the name starts with the load_suf...
Definition pq_connect.c:398
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(uint64_t max)
Generate a random unsigned 64-bit value.
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_BlindablePublicKey *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_BlindablePrivateKey *private_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called for each matching record.
static int namestore_postgres_commit_tx(void *cls)
static enum GNUNET_GenericReturnValue database_prepare(struct Plugin *plugin)
static enum GNUNET_GenericReturnValue namestore_postgres_store_records(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *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 enum GNUNET_GenericReturnValue namestore_postgres_zone_to_name(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const struct GNUNET_CRYPTO_BlindablePublicKey *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_BlindablePrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
static void parse_result_call_iterator(void *cls, PGresult *res, unsigned int num_results)
A statement has been run.
void * libgnunet_plugin_namestore_postgres_init(void *cls)
Entry point for the plugin.
static void reconnect_cb(void *cls, struct GNUNET_PQ_Context *db)
Function called whenever we (re) connect to db.
static int namestore_postgres_edit_records(void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Edit 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_clear_editor_hint(void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_BlindablePrivateKey *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...
static int namestore_postgres_begin_tx(void *cls)
#define LOG(kind,...)
static void reconnect_setup(void *cls, struct GNUNET_PQ_Context *pq)
Function called whenever we reconnect to the DB.
static enum GNUNET_GenericReturnValue namestore_postgres_iterate_records(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *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 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(* lookup_records)(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *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(* create_tables)(void *cls)
Setup the database.
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(* zone_to_name)(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const struct GNUNET_CRYPTO_BlindablePublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Look for an existing PKEY delegation record for a given public key.
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.
enum GNUNET_GenericReturnValue(* store_records)(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *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.
enum GNUNET_GenericReturnValue(* clear_editor_hint)(void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_BlindablePrivateKey *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(* edit_records)(void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Transaction-based API draft.
void * cls
Closure to pass to all plugin functions.
enum GNUNET_GenericReturnValue(* iterate_records)(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *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.
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.
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).
void * iter_cls
Closure for iter.
GNUNET_NAMESTORE_RecordIterator iter
Function to call for each result.
const struct GNUNET_CRYPTO_BlindablePrivateKey * zone_key
Zone key, NULL if part of record.
Handle for a plugin.
Definition block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition block.c:47
bool ready
Set to true if the DB is ready for action.
struct GNUNET_PQ_Context * dbh
Native Postgres database handle.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.