GNUnet  0.19.2
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 "platform.h"
29 #include "gnunet_gnsrecord_lib.h"
30 #include "gnunet_pq_lib.h"
31 #include "namestore.h"
32 
33 
34 #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-postgres", __VA_ARGS__)
35 
36 
40 struct Plugin
41 {
45  const struct GNUNET_CONFIGURATION_Handle *cfg;
46 
50  struct GNUNET_PQ_Context *dbh;
51 
55  bool ready;
56 };
57 
58 
66 static enum GNUNET_GenericReturnValue
68 {
69  struct Plugin *plugin = cls;
70  struct GNUNET_PQ_Context *dbh;
71 
73  "namestore-postgres",
74  "namestore-",
75  NULL,
76  NULL);
77  if (NULL == dbh)
78  return GNUNET_SYSERR;
80  return GNUNET_OK;
81 }
82 
83 
90 static enum GNUNET_GenericReturnValue
92 {
93  struct Plugin *plugin = cls;
94  struct GNUNET_PQ_Context *dbh;
96 
98  "namestore-postgres",
99  NULL,
100  NULL,
101  NULL);
102  if (NULL == dbh)
103  {
105  "Failed to connect to database\n");
106  return GNUNET_SYSERR;
107  }
108  ret = GNUNET_PQ_exec_sql (dbh,
109  "namestore-drop");
110  GNUNET_PQ_disconnect (dbh);
111  return ret;
112 }
113 
114 
115 static enum GNUNET_GenericReturnValue
117 {
119 
120  if (plugin->ready)
121  return GNUNET_OK;
122  {
123  struct GNUNET_PQ_PreparedStatement ps[] = {
124  GNUNET_PQ_make_prepare ("store_records",
125  "INSERT INTO namestore.ns098records"
126  " (zone_private_key, pkey, rvalue, record_count, record_data, label)"
127  " VALUES ($1, $2, $3, $4, $5, $6)"
128  " ON CONFLICT ON CONSTRAINT zl"
129  " DO UPDATE"
130  " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5"
131  " WHERE ns098records.zone_private_key = $1"
132  " AND ns098records.label = $6"),
133  GNUNET_PQ_make_prepare ("delete_records",
134  "DELETE FROM namestore.ns098records "
135  "WHERE zone_private_key=$1 AND label=$2"),
136  GNUNET_PQ_make_prepare ("zone_to_name",
137  "SELECT seq,record_count,record_data,label FROM namestore.ns098records"
138  " WHERE zone_private_key=$1 AND pkey=$2"),
139  GNUNET_PQ_make_prepare ("iterate_zone",
140  "SELECT seq,record_count,record_data,label FROM namestore.ns098records "
141  "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3"),
142  GNUNET_PQ_make_prepare ("iterate_all_zones",
143  "SELECT seq,record_count,record_data,label,zone_private_key"
144  " FROM namestore.ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2"),
145  GNUNET_PQ_make_prepare ("lookup_label",
146  "SELECT seq,record_count,record_data,label "
147  "FROM namestore.ns098records WHERE zone_private_key=$1 AND label=$2"),
148  GNUNET_PQ_make_prepare ("edit_set",
149  "SELECT seq,record_count,record_data,label "
150  "FROM namestore.ns098records WHERE zone_private_key=$1 AND label=$2 FOR UPDATE NOWAIT"),
152  };
153 
155  ps);
156  }
157  if (GNUNET_OK != ret)
158  return ret;
159  plugin->ready = true;
160  return GNUNET_OK;
161 }
162 
163 
172 static enum GNUNET_GenericReturnValue
174 {
175  struct GNUNET_PQ_ExecuteStatement ess[] = {
176  GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"),
178  };
179  struct GNUNET_PQ_ExecuteStatement *es;
180 
181  if (GNUNET_YES ==
183  "namestore-postgres",
184  "ASYNC_COMMIT"))
185  es = &ess[0];
186  else
187  es = &ess[1];
188 
189  if (GNUNET_YES ==
191  "namestore-postgres",
192  "INIT_ON_CONNECT"))
193  {
194  if (GNUNET_OK !=
196  {
198  "Failed to create tables\n");
199  return GNUNET_SYSERR;
200  }
201  }
203  "namestore-postgres",
204  NULL,
205  es,
206  NULL);
207  if (NULL == plugin->dbh)
208  return GNUNET_SYSERR;
209  return GNUNET_OK;
210 }
211 
212 
224 static enum GNUNET_GenericReturnValue
226  const struct
228  const char *label,
229  unsigned int rd_count,
230  const struct GNUNET_GNSRECORD_Data *rd)
231 {
232  struct Plugin *plugin = cls;
234  uint64_t rvalue;
235  uint32_t rd_count32 = (uint32_t) rd_count;
236  ssize_t data_size;
237 
239  memset (&pkey,
240  0,
241  sizeof(pkey));
242  for (unsigned int i = 0; i < rd_count; i++)
243  if (GNUNET_YES ==
244  GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
245  {
248  rd[i].data_size,
249  rd[i].record_type,
250  &pkey));
251  break;
252  }
254  UINT64_MAX);
256  rd);
257  if (data_size < 0)
258  {
259  GNUNET_break (0);
260  return GNUNET_SYSERR;
261  }
262  if (data_size >= UINT16_MAX)
263  {
264  GNUNET_break (0);
265  return GNUNET_SYSERR;
266  }
267  /* if record set is empty, delete existing records */
268  if (0 == rd_count)
269  {
270  struct GNUNET_PQ_QueryParam params[] = {
274  };
276 
278  "delete_records",
279  params);
282  {
283  GNUNET_break (0);
284  return GNUNET_SYSERR;
285  }
287  "postgres",
288  "Record deleted\n");
289  return GNUNET_OK;
290  }
291  /* otherwise, UPSERT (i.e. UPDATE if exists, otherwise INSERT) */
292  {
293  char data[data_size];
294  struct GNUNET_PQ_QueryParam params[] = {
298  GNUNET_PQ_query_param_uint32 (&rd_count32),
302  };
304  ssize_t ret;
305 
307  rd,
308  data_size,
309  data);
310  if ((ret < 0) ||
311  (data_size != ret))
312  {
313  GNUNET_break (0);
314  return GNUNET_SYSERR;
315  }
316 
318  "store_records",
319  params);
321  return GNUNET_SYSERR;
322  }
323  return GNUNET_OK;
324 }
325 
326 
331 {
336 
340  void *iter_cls;
341 
346 
351  uint64_t limit;
352 };
353 
354 
363 static void
365  PGresult *res,
366  unsigned int num_results)
367 {
368  struct ParserContext *pc = cls;
369 
370  if (NULL == pc->iter)
371  return; /* no need to do more work */
373  "Got %d results from PQ.\n", num_results);
374  for (unsigned int i = 0; i < num_results; i++)
375  {
376  uint64_t serial;
377  void *data;
378  size_t data_size;
379  uint32_t record_count;
380  char *label;
381  struct GNUNET_IDENTITY_PrivateKey zk;
382  struct GNUNET_PQ_ResultSpec rs_with_zone[] = {
383  GNUNET_PQ_result_spec_uint64 ("seq", &serial),
384  GNUNET_PQ_result_spec_uint32 ("record_count", &record_count),
386  GNUNET_PQ_result_spec_string ("label", &label),
387  GNUNET_PQ_result_spec_auto_from_type ("zone_private_key", &zk),
389  };
390  struct GNUNET_PQ_ResultSpec rs_without_zone[] = {
391  GNUNET_PQ_result_spec_uint64 ("seq", &serial),
392  GNUNET_PQ_result_spec_uint32 ("record_count", &record_count),
394  GNUNET_PQ_result_spec_string ("label", &label),
396  };
397  struct GNUNET_PQ_ResultSpec *rs;
398 
399  rs = (NULL == pc->zone_key) ? rs_with_zone : rs_without_zone;
400  if (GNUNET_YES !=
402  rs,
403  i))
404  {
405  GNUNET_break (0);
406  return;
407  }
408 
409  if (record_count > 64 * 1024)
410  {
411  /* sanity check, don't stack allocate far too much just
412  because database might contain a large value here */
413  GNUNET_break (0);
415  return;
416  }
417 
418  {
420 
421  GNUNET_assert (0 != serial);
422  if (GNUNET_OK !=
424  data,
425  record_count,
426  rd))
427  {
428  GNUNET_break (0);
430  return;
431  }
432  pc->iter (pc->iter_cls,
433  serial,
434  (NULL == pc->zone_key) ? &zk : pc->zone_key,
435  label,
436  record_count,
437  rd);
438  }
440  }
441  pc->limit -= num_results;
442 }
443 
444 
456 static enum GNUNET_GenericReturnValue
457 lookup_records (void *cls,
458  const struct
460  const char *label,
462  void *iter_cls,
463  const char*method)
464 {
465  struct Plugin *plugin = cls;
467  struct GNUNET_PQ_QueryParam params[] = {
471  };
472  struct ParserContext pc;
474 
475  if (NULL == zone)
476  {
477  GNUNET_break (0);
478  return GNUNET_SYSERR;
479  }
480  pc.iter = iter;
481  pc.iter_cls = iter_cls;
482  pc.zone_key = zone;
484  method,
485  params,
487  &pc);
488  if (res < 0)
489  return GNUNET_SYSERR;
491  return GNUNET_NO;
492  return GNUNET_OK;
493 }
494 
495 
506 static enum GNUNET_GenericReturnValue
508  const struct
510  const char *label,
512  void *iter_cls)
513 {
514  return lookup_records (cls, zone, label, iter, iter_cls, "lookup_label");
515 }
516 
517 
528 static int
530  const struct
532  const char *label,
534  void *iter_cls)
535 {
536  return lookup_records (cls, zone, label, iter, iter_cls, "edit_set");
537 }
538 
539 
552 static enum GNUNET_GenericReturnValue
554  const struct
556  uint64_t serial,
557  uint64_t limit,
559  void *iter_cls)
560 {
561  struct Plugin *plugin = cls;
563  struct ParserContext pc;
564 
566  pc.iter = iter;
567  pc.iter_cls = iter_cls;
568  pc.zone_key = zone;
569  pc.limit = limit;
570  if (NULL == zone)
571  {
572  struct GNUNET_PQ_QueryParam params_without_zone[] = {
576  };
577 
579  "iterate_all_zones",
580  params_without_zone,
582  &pc);
583  }
584  else
585  {
586  struct GNUNET_PQ_QueryParam params_with_zone[] = {
591  };
592 
594  "iterate_zone",
595  params_with_zone,
597  &pc);
598  }
599  if (res < 0)
600  return GNUNET_SYSERR;
601 
603  (pc.limit > 0))
604  return GNUNET_NO;
605  return GNUNET_OK;
606 }
607 
608 
620 static enum GNUNET_GenericReturnValue
622  const struct
624  const struct
625  GNUNET_IDENTITY_PublicKey *value_zone,
627  void *iter_cls)
628 {
629  struct Plugin *plugin = cls;
631  struct GNUNET_PQ_QueryParam params[] = {
635  };
637  struct ParserContext pc;
638 
639  pc.iter = iter;
640  pc.iter_cls = iter_cls;
641  pc.zone_key = zone;
643  "zone_to_name",
644  params,
646  &pc);
647  if (res < 0)
648  return GNUNET_SYSERR;
649  return GNUNET_OK;
650 }
651 
652 
660 static enum GNUNET_GenericReturnValue
662  char **emsg)
663 {
664  struct Plugin *plugin = cls;
666  struct GNUNET_PQ_ExecuteStatement es[] = {
667  GNUNET_PQ_make_execute ("BEGIN"),
669  };
670 
671  return GNUNET_PQ_exec_statements (plugin->dbh, es);
672 }
673 
674 
683 static enum GNUNET_GenericReturnValue
685  char **emsg)
686 {
687  struct Plugin *plugin = cls;
689  struct GNUNET_PQ_ExecuteStatement es[] = {
690  GNUNET_PQ_make_execute ("ROLLBACK"),
692  };
693 
694  return GNUNET_PQ_exec_statements (plugin->dbh, es);
695 }
696 
697 
706 static enum GNUNET_GenericReturnValue
708  char **emsg)
709 {
710  struct Plugin *plugin = cls;
712  struct GNUNET_PQ_ExecuteStatement es[] = {
713  GNUNET_PQ_make_execute ("COMMIT"),
715  };
716 
717  return GNUNET_PQ_exec_statements (plugin->dbh, es);
718 }
719 
720 
727 static void
729 {
731  plugin->dbh = NULL;
732 }
733 
734 
741 void *
743 {
744  struct Plugin *plugin;
745  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
747 
748  plugin = GNUNET_new (struct Plugin);
749  plugin->cfg = cfg;
751  {
754  return NULL;
755  }
757  api->cls = plugin;
769  "Postgres namestore plugin running\n");
770  return api;
771 }
772 
773 
780 void *
782 {
784  struct Plugin *plugin = api->cls;
785 
787  plugin->cfg = NULL;
789  GNUNET_free (api);
791  "Postgres namestore plugin is finished\n");
792  return NULL;
793 }
794 
795 
796 /* end of plugin_namestore_postgres.c */
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static int res
struct TestcasePlugin * plugin
The process handle to the testbed service.
static uint64_t record_count
Record count.
uint32_t data
The data value.
static char * pkey
Public key of the zone to look in, in ASCII.
static char * zone
Name of the zone being managed.
static const struct GNUNET_IDENTITY_PrivateKey * zone_key
Private key of the zone.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
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.
API that can be used to store naming information on a GNUnet node;.
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 uint16_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:209
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_execute(const char *sql)
Create a struct GNUNET_PQ_ExecuteStatement where errors are fatal.
Definition: pq_exec.c:36
#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:67
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:542
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:477
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:55
#define GNUNET_PQ_query_param_end
End of query parameter specification.
Definition: gnunet_pq_lib.h:98
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:122
#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:132
#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:164
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:143
#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).
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_identity_from_data(const char *data, size_t data_size, uint32_t type, struct GNUNET_IDENTITY_PublicKey *key)
Build a #GNUNET_GNSRECORD_PublicKey from zone delegation resource record data.
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.
GNUNET_NETWORK_STRUCT_END 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 struct GNUNET_IDENTITY_PrivateKey *private_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called for each matching record.
common internal definitions for namestore service
void * libgnunet_plugin_namestore_postgres_init(void *cls)
Entry point for the plugin.
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.
static enum GNUNET_GenericReturnValue namestore_postgres_transaction_begin(void *cls, char **emsg)
Begin a transaction for a client.
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.
static enum GNUNET_GenericReturnValue database_prepare(struct Plugin *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_transaction_rollback(void *cls, char **emsg)
Commit a transaction for a client.
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 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.
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 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.
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.
void * libgnunet_plugin_namestore_postgres_done(void *cls)
Exit point from the plugin.
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.
static enum GNUNET_GenericReturnValue database_connect(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
static enum GNUNET_GenericReturnValue namestore_postgres_transaction_commit(void *cls, char **emsg)
Roll back a transaction for a client.
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(* create_tables)(void *cls)
Setup the database.
enum GNUNET_GenericReturnValue(* store_records)(void *cls, const struct GNUNET_IDENTITY_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.
enum GNUNET_GenericReturnValue(* 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.
enum GNUNET_GenericReturnValue(* transaction_begin)(void *cls, char **emsg)
Transaction-based API draft.
enum GNUNET_GenericReturnValue(* 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 zone in the datastore.
enum GNUNET_GenericReturnValue(* 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.
enum GNUNET_GenericReturnValue(* drop_tables)(void *cls)
Drop existing tables.
enum GNUNET_GenericReturnValue(* transaction_commit)(void *cls, char **emsg)
Commit a transaction in the database.
void * cls
Closure to pass to all plugin functions.
enum GNUNET_GenericReturnValue(* transaction_rollback)(void *cls, char **emsg)
Abort and roll back a transaction in the database.
enum GNUNET_GenericReturnValue(* 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.
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:66
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.
const struct GNUNET_IDENTITY_PrivateKey * zone_key
Zone key, NULL if part of record.
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.