GNUnet  0.17.6
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 };
52 
53 
62 static int
64 {
65  struct GNUNET_PQ_ExecuteStatement es_temporary =
67  "CREATE TEMPORARY TABLE IF NOT EXISTS ns098records ("
68  " seq BIGSERIAL PRIMARY KEY,"
69  " zone_private_key BYTEA NOT NULL DEFAULT '',"
70  " pkey BYTEA DEFAULT '',"
71  " rvalue BYTEA NOT NULL DEFAULT '',"
72  " record_count INTEGER NOT NULL DEFAULT 0,"
73  " record_data BYTEA NOT NULL DEFAULT '',"
74  " label TEXT NOT NULL DEFAULT '',"
75  " CONSTRAINT zl UNIQUE (zone_private_key,label)"
76  ")");
77  struct GNUNET_PQ_ExecuteStatement es_default =
78  GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
79  " seq BIGSERIAL PRIMARY KEY,"
80  " zone_private_key BYTEA NOT NULL DEFAULT '',"
81  " pkey BYTEA DEFAULT '',"
82  " rvalue BYTEA NOT NULL DEFAULT '',"
83  " record_count INTEGER NOT NULL DEFAULT 0,"
84  " record_data BYTEA NOT NULL DEFAULT '',"
85  " label TEXT NOT NULL DEFAULT '',"
86  " CONSTRAINT zl UNIQUE (zone_private_key,label)"
87  ")");
88  const struct GNUNET_PQ_ExecuteStatement *cr;
90 
91  if (GNUNET_YES ==
93  "namestore-postgres",
94  "TEMPORARY_TABLE"))
95  {
96  cr = &es_temporary;
97  }
98  else
99  {
100  cr = &es_default;
101  }
102 
103  if (GNUNET_YES ==
105  "namestore-postgres",
106  "ASYNC_COMMIT"))
107  sc = GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off");
108 
109  {
110  struct GNUNET_PQ_ExecuteStatement es[] = {
111  *cr,
112  GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
113  "ON ns098records (zone_private_key,pkey)"),
114  GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
115  "ON ns098records (zone_private_key,seq)"),
116  GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_label "
117  "ON ns098records (label)"),
118  GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS zone_label "
119  "ON ns098records (zone_private_key,label)"),
120  sc,
122  };
123  struct GNUNET_PQ_PreparedStatement ps[] = {
124  GNUNET_PQ_make_prepare ("store_records",
125  "INSERT INTO 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  6),
134  GNUNET_PQ_make_prepare ("delete_records",
135  "DELETE FROM ns098records "
136  "WHERE zone_private_key=$1 AND label=$2",
137  2),
138  GNUNET_PQ_make_prepare ("zone_to_name",
139  "SELECT seq,record_count,record_data,label FROM ns098records"
140  " WHERE zone_private_key=$1 AND pkey=$2",
141  2),
142  GNUNET_PQ_make_prepare ("iterate_zone",
143  "SELECT seq,record_count,record_data,label FROM ns098records "
144  "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3",
145  3),
146  GNUNET_PQ_make_prepare ("iterate_all_zones",
147  "SELECT seq,record_count,record_data,label,zone_private_key"
148  " FROM ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2",
149  2),
150  GNUNET_PQ_make_prepare ("lookup_label",
151  "SELECT seq,record_count,record_data,label "
152  "FROM ns098records WHERE zone_private_key=$1 AND label=$2",
153  2),
154  GNUNET_PQ_make_prepare ("edit_set",
155  "SELECT seq,record_count,record_data,label "
156  "FROM ns098records WHERE zone_private_key=$1 AND label=$2 FOR UPDATE NOWAIT",
157  2),
159  };
160 
162  "namestore-postgres",
163  NULL,
164  es,
165  ps);
166  }
167  if (NULL == plugin->dbh)
168  return GNUNET_SYSERR;
169  return GNUNET_OK;
170 }
171 
172 
184 static int
186  const struct
188  const char *label,
189  unsigned int rd_count,
190  const struct GNUNET_GNSRECORD_Data *rd)
191 {
192  struct Plugin *plugin = cls;
194  uint64_t rvalue;
195  uint32_t rd_count32 = (uint32_t) rd_count;
196  ssize_t data_size;
197 
198  memset (&pkey,
199  0,
200  sizeof(pkey));
201  for (unsigned int i = 0; i < rd_count; i++)
202  if (GNUNET_YES ==
203  GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
204  {
207  rd[i].data_size,
208  rd[i].record_type,
209  &pkey));
210  break;
211  }
213  UINT64_MAX);
215  rd);
216  if (data_size < 0)
217  {
218  GNUNET_break (0);
219  return GNUNET_SYSERR;
220  }
221  if (data_size >= UINT16_MAX)
222  {
223  GNUNET_break (0);
224  return GNUNET_SYSERR;
225  }
226  /* if record set is empty, delete existing records */
227  if (0 == rd_count)
228  {
229  struct GNUNET_PQ_QueryParam params[] = {
233  };
235 
237  "delete_records",
238  params);
241  {
242  GNUNET_break (0);
243  return GNUNET_SYSERR;
244  }
246  "postgres",
247  "Record deleted\n");
248  return GNUNET_OK;
249  }
250  /* otherwise, UPSERT (i.e. UPDATE if exists, otherwise INSERT) */
251  {
252  char data[data_size];
253  struct GNUNET_PQ_QueryParam params[] = {
257  GNUNET_PQ_query_param_uint32 (&rd_count32),
261  };
263  ssize_t ret;
264 
266  rd,
267  data_size,
268  data);
269  if ((ret < 0) ||
270  (data_size != ret))
271  {
272  GNUNET_break (0);
273  return GNUNET_SYSERR;
274  }
275 
277  "store_records",
278  params);
280  return GNUNET_SYSERR;
281  }
282  return GNUNET_OK;
283 }
284 
285 
290 {
295 
299  void *iter_cls;
300 
305 
310  uint64_t limit;
311 };
312 
313 
322 static void
324  PGresult *res,
325  unsigned int num_results)
326 {
327  struct ParserContext *pc = cls;
328 
329  if (NULL == pc->iter)
330  return; /* no need to do more work */
332  "Got %d results from PQ.\n", num_results);
333  for (unsigned int i = 0; i < num_results; i++)
334  {
335  uint64_t serial;
336  void *data;
337  size_t data_size;
338  uint32_t record_count;
339  char *label;
340  struct GNUNET_IDENTITY_PrivateKey zk;
341  struct GNUNET_PQ_ResultSpec rs_with_zone[] = {
342  GNUNET_PQ_result_spec_uint64 ("seq", &serial),
343  GNUNET_PQ_result_spec_uint32 ("record_count", &record_count),
345  GNUNET_PQ_result_spec_string ("label", &label),
346  GNUNET_PQ_result_spec_auto_from_type ("zone_private_key", &zk),
348  };
349  struct GNUNET_PQ_ResultSpec rs_without_zone[] = {
350  GNUNET_PQ_result_spec_uint64 ("seq", &serial),
351  GNUNET_PQ_result_spec_uint32 ("record_count", &record_count),
353  GNUNET_PQ_result_spec_string ("label", &label),
355  };
356  struct GNUNET_PQ_ResultSpec *rs;
357 
358  rs = (NULL == pc->zone_key) ? rs_with_zone : rs_without_zone;
359  if (GNUNET_YES !=
361  rs,
362  i))
363  {
364  GNUNET_break (0);
365  return;
366  }
367 
368  if (record_count > 64 * 1024)
369  {
370  /* sanity check, don't stack allocate far too much just
371  because database might contain a large value here */
372  GNUNET_break (0);
374  return;
375  }
376 
377  {
379 
380  GNUNET_assert (0 != serial);
381  if (GNUNET_OK !=
383  data,
384  record_count,
385  rd))
386  {
387  GNUNET_break (0);
389  return;
390  }
391  pc->iter (pc->iter_cls,
392  serial,
393  (NULL == pc->zone_key) ? &zk : pc->zone_key,
394  label,
395  record_count,
396  rd);
397  }
399  }
400  pc->limit -= num_results;
401 }
402 
403 
415 static int
416 lookup_records (void *cls,
417  const struct
419  const char *label,
421  void *iter_cls,
422  const char*method)
423 {
424  struct Plugin *plugin = cls;
425  struct GNUNET_PQ_QueryParam params[] = {
429  };
430  struct ParserContext pc;
432 
433  if (NULL == zone)
434  {
435  GNUNET_break (0);
436  return GNUNET_SYSERR;
437  }
438  pc.iter = iter;
439  pc.iter_cls = iter_cls;
440  pc.zone_key = zone;
442  method,
443  params,
445  &pc);
446  if (res < 0)
447  return GNUNET_SYSERR;
449  return GNUNET_NO;
450  return GNUNET_OK;
451 }
452 
463 static int
465  const struct
467  const char *label,
469  void *iter_cls)
470 {
471  return lookup_records (cls, zone, label, iter, iter_cls, "lookup_label");
472 }
473 
484 static int
486  const struct
488  const char *label,
490  void *iter_cls)
491 {
492  return lookup_records (cls, zone, label, iter, iter_cls, "edit_set");
493 }
494 
495 
508 static int
510  const struct
512  uint64_t serial,
513  uint64_t limit,
515  void *iter_cls)
516 {
517  struct Plugin *plugin = cls;
519  struct ParserContext pc;
520 
521  pc.iter = iter;
522  pc.iter_cls = iter_cls;
523  pc.zone_key = zone;
524  pc.limit = limit;
525  if (NULL == zone)
526  {
527  struct GNUNET_PQ_QueryParam params_without_zone[] = {
531  };
532 
534  "iterate_all_zones",
535  params_without_zone,
537  &pc);
538  }
539  else
540  {
541  struct GNUNET_PQ_QueryParam params_with_zone[] = {
546  };
547 
549  "iterate_zone",
550  params_with_zone,
552  &pc);
553  }
554  if (res < 0)
555  return GNUNET_SYSERR;
556 
558  (pc.limit > 0))
559  return GNUNET_NO;
560  return GNUNET_OK;
561 }
562 
563 
575 static int
577  const struct
579  const struct
580  GNUNET_IDENTITY_PublicKey *value_zone,
582  void *iter_cls)
583 {
584  struct Plugin *plugin = cls;
585  struct GNUNET_PQ_QueryParam params[] = {
589  };
591  struct ParserContext pc;
592 
593  pc.iter = iter;
594  pc.iter_cls = iter_cls;
595  pc.zone_key = zone;
597  "zone_to_name",
598  params,
600  &pc);
601  if (res < 0)
602  return GNUNET_SYSERR;
603  return GNUNET_OK;
604 }
605 
613 static enum GNUNET_GenericReturnValue
615  char **emsg)
616 {
617  struct Plugin *plugin = cls;
618  struct GNUNET_PQ_ExecuteStatement es[] = {
619  GNUNET_PQ_make_execute ("BEGIN"),
621  };
622 
623  return GNUNET_PQ_exec_statements (plugin->dbh, es);
624 }
625 
634 static enum GNUNET_GenericReturnValue
636  char **emsg)
637 {
638  struct Plugin *plugin = cls;
639  struct GNUNET_PQ_ExecuteStatement es[] = {
640  GNUNET_PQ_make_execute ("ROLLBACK"),
642  };
643 
644  return GNUNET_PQ_exec_statements (plugin->dbh, es);
645 }
646 
655 static enum GNUNET_GenericReturnValue
657  char **emsg)
658 {
659  struct Plugin *plugin = cls;
660  struct GNUNET_PQ_ExecuteStatement es[] = {
661  GNUNET_PQ_make_execute ("COMMIT"),
663  };
664 
665  return GNUNET_PQ_exec_statements (plugin->dbh, es);
666 }
667 
668 
675 static void
677 {
679  plugin->dbh = NULL;
680 }
681 
682 
689 void *
691 {
692  struct Plugin *plugin;
693  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
695 
696  plugin = GNUNET_new (struct Plugin);
697  plugin->cfg = cfg;
699  {
702  return NULL;
703  }
705  api->cls = plugin;
715  "Postgres namestore plugin running\n");
716  return api;
717 }
718 
719 
726 void *
728 {
730  struct Plugin *plugin = api->cls;
731 
733  plugin->cfg = NULL;
735  GNUNET_free (api);
737  "Postgres namestore plugin is finished\n");
738  return NULL;
739 }
740 
741 
742 /* 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 Plugin * 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 struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:84
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
Definition: gnunet_db_lib.h:36
@ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
The transaction succeeded, and yielded one result.
Definition: gnunet_db_lib.h:59
@ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
The transaction succeeded, but yielded zero results.
Definition: gnunet_db_lib.h:54
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_PreparedStatement GNUNET_PQ_make_prepare(const char *name, const char *sql, unsigned int num_args)
Create a struct GNUNET_PQ_PreparedStatement.
Definition: pq_prepare.c:38
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:76
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:526
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:461
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:97
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.
#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_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.
Definition: gnunet_common.h:96
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#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
@ 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_transaction_begin(void *cls, char **emsg)
Begin a transaction for a client.
static int 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 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 void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
static int 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 int database_setup(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
static int 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.
#define LOG(kind,...)
static int 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 int 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 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
int(* 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.
int(* 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.
int(* 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(* transaction_begin)(void *cls, char **emsg)
Transaction-based API draft.
int(* 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(* 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.
int(* 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:65
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
struct GNUNET_PQ_Context * dbh
Native Postgres database handle.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.