GNUnet 0.22.1
plugin_datastore_postgres.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2009-2017, 2022 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"
28#include "gnunet_pq_lib.h"
29
30
41#define BUSY_TIMEOUT GNUNET_TIME_UNIT_SECONDS
42
43
47struct Plugin
48{
53
57 struct GNUNET_PQ_Context *dbh;
58};
59
60
69{
70#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, oid"
73 "SELECT " RESULT_COLUMNS
74 " FROM datastore.gn090"
75 " WHERE oid >= $1::bigint AND"
76 " (rvalue >= $2 OR 0 = $3::smallint) AND"
77 " (hash = $4 OR 0 = $5::smallint) AND"
78 " (type = $6 OR 0 = $7::smallint)"
79 " ORDER BY oid ASC LIMIT 1"),
81 "INSERT INTO datastore.gn090"
82 " (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
83 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)"),
84 GNUNET_PQ_make_prepare ("update",
85 "UPDATE datastore.gn090"
86 " SET prio = prio + $1,"
87 " repl = repl + $2,"
88 " expire = GREATEST(expire, $3)"
89 " WHERE hash = $4 AND vhash = $5"),
90 GNUNET_PQ_make_prepare ("decrepl",
91 "UPDATE datastore.gn090"
92 " SET repl = GREATEST (repl - 1, 0)"
93 " WHERE oid = $1"),
94 GNUNET_PQ_make_prepare ("select_non_anonymous",
95 "SELECT " RESULT_COLUMNS
96 " FROM datastore.gn090"
97 " WHERE anonLevel = 0 AND type = $1 AND oid >= $2::bigint"
98 " ORDER BY oid ASC LIMIT 1"),
99 GNUNET_PQ_make_prepare ("select_expiration_order",
100 "(SELECT " RESULT_COLUMNS
101 " FROM datastore.gn090"
102 " WHERE expire < $1 ORDER BY prio ASC LIMIT 1) "
103 "UNION "
104 "(SELECT " RESULT_COLUMNS
105 " FROM datastore.gn090"
106 " ORDER BY prio ASC LIMIT 1)"
107 " ORDER BY expire ASC LIMIT 1"),
108 GNUNET_PQ_make_prepare ("select_replication_order",
109 "SELECT " RESULT_COLUMNS
110 " FROM datastore.gn090"
111 " ORDER BY repl DESC,RANDOM() LIMIT 1"),
112 GNUNET_PQ_make_prepare ("delrow",
113 "DELETE FROM datastore.gn090"
114 " WHERE oid=$1"),
115 GNUNET_PQ_make_prepare ("remove",
116 "DELETE FROM datastore.gn090"
117 " WHERE hash = $1 AND"
118 " value = $2"),
119 GNUNET_PQ_make_prepare ("get_keys",
120 "SELECT hash"
121 " FROM datastore.gn090"),
122 GNUNET_PQ_make_prepare ("estimate_size",
123 "SELECT CASE WHEN NOT EXISTS"
124 " (SELECT 1 FROM datastore.gn090)"
125 " THEN 0"
126 " ELSE (SELECT SUM(LENGTH(value))+256*COUNT(*)"
127 " FROM datastore.gn090)"
128 "END AS total"),
130 };
131#undef RESULT_COLUMNS
132
133 plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->env->cfg,
134 "datastore-postgres",
135 "datastore-",
136 NULL,
137 ps);
138 if (NULL == plugin->dbh)
139 return GNUNET_SYSERR;
140 return GNUNET_OK;
141}
142
143
151static void
153 unsigned long long *estimate)
154{
155 struct Plugin *plugin = cls;
156 uint64_t total;
157 struct GNUNET_PQ_QueryParam params[] = {
159 };
160 struct GNUNET_PQ_ResultSpec rs[] = {
162 &total),
164 };
166
167 if (NULL == estimate)
168 return;
170 "estimate_size",
171 params,
172 rs);
174 {
175 *estimate = 0LL;
176 return;
177 }
178 *estimate = total;
179}
180
181
198static void
200 const struct GNUNET_HashCode *key,
201 bool absent,
202 uint32_t size,
203 const void *data,
205 uint32_t priority,
206 uint32_t anonymity,
207 uint32_t replication,
209 PluginPutCont cont,
210 void *cont_cls)
211{
212 struct Plugin *plugin = cls;
213 struct GNUNET_HashCode vhash;
215
217 size,
218 &vhash);
219 if (! absent)
220 {
221 struct GNUNET_PQ_QueryParam params[] = {
228 };
230 "update",
231 params);
232 if (0 > ret)
233 {
234 cont (cont_cls,
235 key,
236 size,
238 _ ("Postgresql exec failure"));
239 return;
240 }
241 if (0 != ret)
242 {
243 cont (cont_cls,
244 key,
245 size,
246 GNUNET_NO,
247 NULL);
248 return;
249 }
250 }
251
252 {
253 uint32_t utype = (uint32_t) type;
255 UINT64_MAX);
256 struct GNUNET_PQ_QueryParam params[] = {
267 };
268
270 "put",
271 params);
272 if (0 > ret)
273 {
274 cont (cont_cls,
275 key,
276 size,
278 "Postgresql exec failure");
279 return;
280 }
281 }
282 plugin->env->duc (plugin->env->cls,
285 "datastore-postgres",
286 "Stored %u bytes in database\n",
287 (unsigned int) size);
288 cont (cont_cls,
289 key,
290 size,
291 GNUNET_OK,
292 NULL);
293}
294
295
300{
304 struct Plugin *plugin;
305
310
314 void *proc_cls;
315};
316
317
326static void
327process_result (void *cls,
328 PGresult *res,
329 unsigned int num_results)
330{
331 struct ProcessResultContext *prc = cls;
332 struct Plugin *plugin = prc->plugin;
333
334 if (0 == num_results)
335 {
336 /* no result */
338 "datastore-postgres",
339 "Ending iteration (no more results)\n");
340 prc->proc (prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
342 return;
343 }
344 if (1 != num_results)
345 {
346 GNUNET_break (0);
347 prc->proc (prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
349 return;
350 }
351 /* Technically we don't need the loop here, but nicer in case
352 we ever relax the condition above. */
353 for (unsigned int i = 0; i < num_results; i++)
354 {
355 int iret;
356 uint64_t rowid;
357 uint32_t utype;
358 uint32_t anonymity;
359 uint32_t replication;
360 uint32_t priority;
361 size_t size;
362 void *data;
363 struct GNUNET_TIME_Absolute expiration_time;
364 struct GNUNET_HashCode key;
365 struct GNUNET_PQ_ResultSpec rs[] = {
367 GNUNET_PQ_result_spec_uint32 ("type", &utype),
368 GNUNET_PQ_result_spec_uint32 ("prio", &priority),
370 GNUNET_PQ_result_spec_absolute_time ("expire", &expiration_time),
373 GNUNET_PQ_result_spec_uint64 ("oid", &rowid),
375 };
376
377 if (GNUNET_OK !=
379 rs,
380 i))
381 {
382 GNUNET_break (0);
383 prc->proc (prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
385 return;
386 }
387
389 "datastore-postgres",
390 "Found result of size %u bytes and type %u in database\n",
391 (unsigned int) size,
392 (unsigned int) utype);
393 iret = prc->proc (prc->proc_cls,
394 &key,
395 size,
396 data,
397 (enum GNUNET_BLOCK_Type) utype,
398 priority,
399 anonymity,
401 expiration_time,
402 rowid);
403 if (iret == GNUNET_NO)
404 {
405 struct GNUNET_PQ_QueryParam param[] = {
408 };
409
411 "Processor asked for item %u to be removed.\n",
412 (unsigned int) rowid);
413 if (0 <
415 "delrow",
416 param))
417 {
419 "datastore-postgres",
420 "Deleting %u bytes from database\n",
421 (unsigned int) size);
422 plugin->env->duc (plugin->env->cls,
425 "datastore-postgres",
426 "Deleted %u bytes from database\n",
427 (unsigned int) size);
428 }
429 }
431 } /* for (i) */
432}
433
434
448static void
450 uint64_t next_uid,
451 bool random,
452 const struct GNUNET_HashCode *key,
455 void *proc_cls)
456{
457 struct Plugin *plugin = cls;
458 uint32_t utype = type;
459 uint16_t use_rvalue = random;
460 uint16_t use_key = NULL != key;
461 uint16_t use_type = GNUNET_BLOCK_TYPE_ANY != type;
462 uint64_t rvalue;
463 struct GNUNET_PQ_QueryParam params[] = {
466 GNUNET_PQ_query_param_uint16 (&use_rvalue),
472 };
473 struct ProcessResultContext prc;
475
476 if (random)
477 {
479 UINT64_MAX);
480 next_uid = 0;
481 }
482 else
483 {
484 rvalue = 0;
485 }
486 prc.plugin = plugin;
487 prc.proc = proc;
488 prc.proc_cls = proc_cls;
489
491 "get",
492 params,
494 &prc);
495 if (0 > res)
496 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
498}
499
500
513static void
515 uint64_t next_uid,
518 void *proc_cls)
519{
520 struct Plugin *plugin = cls;
521 uint32_t utype = type;
522 struct GNUNET_PQ_QueryParam params[] = {
526 };
527 struct ProcessResultContext prc;
529
530 prc.plugin = plugin;
531 prc.proc = proc;
532 prc.proc_cls = proc_cls;
534 "select_non_anonymous",
535 params,
537 &prc);
538 if (0 > res)
539 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
541}
542
543
548{
552 struct Plugin *plugin;
553
558
562 void *proc_cls;
563};
564
565
587static int
588repl_proc (void *cls,
589 const struct GNUNET_HashCode *key,
590 uint32_t size,
591 const void *data,
593 uint32_t priority,
594 uint32_t anonymity,
595 uint32_t replication,
597 uint64_t uid)
598{
599 struct ReplCtx *rc = cls;
600 struct Plugin *plugin = rc->plugin;
601 int ret;
602 struct GNUNET_PQ_QueryParam params[] = {
605 };
606 enum GNUNET_DB_QueryStatus qret;
607
608 ret = rc->proc (rc->proc_cls,
609 key,
610 size,
611 data,
612 type,
613 priority,
614 anonymity,
617 uid);
618 if (NULL == key)
619 return ret;
621 "decrepl",
622 params);
623 if (0 > qret)
624 return GNUNET_SYSERR;
625 return ret;
626}
627
628
640static void
643 void *proc_cls)
644{
645 struct Plugin *plugin = cls;
646 struct GNUNET_PQ_QueryParam params[] = {
648 };
649 struct ReplCtx rc;
650 struct ProcessResultContext prc;
652
653 rc.plugin = plugin;
654 rc.proc = proc;
655 rc.proc_cls = proc_cls;
656 prc.plugin = plugin;
657 prc.proc = &repl_proc;
658 prc.proc_cls = &rc;
660 "select_replication_order",
661 params,
663 &prc);
664 if (0 > res)
665 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
667}
668
669
678static void
681 void *proc_cls)
682{
683 struct Plugin *plugin = cls;
684 struct GNUNET_TIME_Absolute now = { 0 };
685 struct GNUNET_PQ_QueryParam params[] = {
688 };
689 struct ProcessResultContext prc;
690
692 prc.plugin = plugin;
693 prc.proc = proc;
694 prc.proc_cls = proc_cls;
696 "select_expiration_order",
697 params,
699 &prc);
700}
701
702
707{
712
716 void *proc_cls;
717};
718
719
728static void
729process_keys (void *cls,
730 PGresult *result,
731 unsigned int num_results)
732{
733 struct ProcessKeysContext *pkc = cls;
734
735 for (unsigned i = 0; i < num_results; i++)
736 {
737 struct GNUNET_HashCode key;
738 struct GNUNET_PQ_ResultSpec rs[] = {
740 &key),
742 };
743
744 if (GNUNET_OK !=
746 rs,
747 i))
748 {
749 GNUNET_break (0);
750 continue;
751 }
752 pkc->proc (pkc->proc_cls,
753 &key,
754 1);
756 }
757}
758
759
767static void
770 void *proc_cls)
771{
772 struct Plugin *plugin = cls;
773 struct GNUNET_PQ_QueryParam params[] = {
775 };
776 struct ProcessKeysContext pkc;
777
778 pkc.proc = proc;
779 pkc.proc_cls = proc_cls;
781 "get_keys",
782 params,
784 &pkc);
785 proc (proc_cls,
786 NULL,
787 0);
788}
789
790
796static void
798{
799 struct Plugin *plugin = cls;
800 struct GNUNET_PQ_ExecuteStatement es[] = {
801 GNUNET_PQ_make_execute ("DROP TABLE gn090"),
803 };
804
805 if (GNUNET_OK !=
807 es))
809 "postgres",
810 _ ("Failed to drop table from database.\n"));
811}
812
813
824static void
826 const struct GNUNET_HashCode *key,
827 uint32_t size,
828 const void *data,
829 PluginRemoveCont cont,
830 void *cont_cls)
831{
832 struct Plugin *plugin = cls;
834 struct GNUNET_PQ_QueryParam params[] = {
838 };
839
841 "remove",
842 params);
843 if (0 > ret)
844 {
845 cont (cont_cls,
846 key,
847 size,
849 _ ("Postgresql exec failure"));
850 return;
851 }
853 {
854 cont (cont_cls,
855 key,
856 size,
857 GNUNET_NO,
858 NULL);
859 return;
860 }
861 plugin->env->duc (plugin->env->cls,
864 "datastore-postgres",
865 "Deleted %u bytes from database\n",
866 (unsigned int) size);
867 cont (cont_cls,
868 key,
869 size,
870 GNUNET_OK,
871 NULL);
872}
873
874
875void *
877
884void *
886{
889 struct Plugin *plugin;
890
891 plugin = GNUNET_new (struct Plugin);
892 plugin->env = env;
894 {
896 return NULL;
897 }
899 api->cls = plugin;
900 api->estimate_size = &postgres_plugin_estimate_size;
901 api->put = &postgres_plugin_put;
903 api->get_replication = &postgres_plugin_get_replication;
904 api->get_expiration = &postgres_plugin_get_expiration;
905 api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity;
906 api->get_keys = &postgres_plugin_get_keys;
907 api->drop = &postgres_plugin_drop;
908 api->remove_key = &postgres_plugin_remove_key;
909 return api;
910}
911
912
913void *
915
922void *
924{
926 struct Plugin *plugin = api->cls;
927
931 return NULL;
932}
933
934
935/* end of plugin_datastore_postgres.c */
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static int ret
Final status code.
Definition: gnunet-arm.c:93
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 unsigned int replication
Desired replication level.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
static unsigned int anonymity
static char * res
Currently read line or NULL on EOF.
static uint32_t type
Type string converted to DNS type value.
static int result
Global testing status.
API for the database backend plugins.
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
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
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_singleton_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params, struct GNUNET_PQ_ResultSpec *rs)
Execute a named prepared statement that is a SELECT statement which must return a single result in co...
Definition: pq_eval.c:199
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:30
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint16(const uint16_t *x)
Generate query parameter for an uint16_t in host byte order.
#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
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64(const char *name, uint64_t *u64)
uint64_t 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_ResultSpec GNUNET_PQ_result_spec_absolute_time(const char *name, struct GNUNET_TIME_Absolute *at)
Absolute time expected.
struct GNUNET_PQ_PreparedStatement GNUNET_PQ_make_prepare(const char *name, const char *sql)
Create a struct GNUNET_PQ_PreparedStatement.
Definition: pq_prepare.c:30
#define GNUNET_PQ_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
#define GNUNET_PQ_result_spec_end
End of result parameter specification.
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(* PluginDatumProcessor)(void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
An processor over a set of items stored in the datastore.
void(* PluginPutCont)(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Put continuation.
#define GNUNET_DATASTORE_ENTRY_OVERHEAD
How many bytes of overhead will we assume per entry in any DB (for reservations)?
void(* PluginKeyProcessor)(void *cls, const struct GNUNET_HashCode *key, unsigned int count)
An processor over a set of keys stored in the datastore.
void(* PluginRemoveCont)(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Remove continuation.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static void postgres_plugin_get_replication(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for replication.
static void postgres_plugin_estimate_size(void *cls, unsigned long long *estimate)
Get an estimate of how much space the database is currently using.
void * libgnunet_plugin_datastore_postgres_done(void *cls)
Exit point from the plugin.
static int repl_proc(void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
Wrapper for the iterator for 'sqlite_plugin_replication_get'.
static void postgres_plugin_drop(void *cls)
Drop database.
static void process_result(void *cls, PGresult *res, unsigned int num_results)
Function invoked to process the result and call the processor of cls.
#define RESULT_COLUMNS
static void postgres_plugin_get_key(void *cls, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
Get one of the results for a particular key in the datastore.
static void postgres_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
Select a subset of the items in the datastore and call the given iterator for each of them.
static enum GNUNET_GenericReturnValue init_connection(struct Plugin *plugin)
Get a database handle.
static void postgres_plugin_remove_key(void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, PluginRemoveCont cont, void *cont_cls)
Remove a particular key in the datastore.
static void postgres_plugin_get_expiration(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for expiration.
void * libgnunet_plugin_datastore_postgres_init(void *cls)
Entry point for the plugin.
static void process_keys(void *cls, PGresult *result, unsigned int num_results)
Function to be called with the results of a SELECT statement that has returned num_results results.
static void postgres_plugin_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls)
Get all of the keys in the datastore.
static void postgres_plugin_put(void *cls, const struct GNUNET_HashCode *key, bool absent, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, void *cont_cls)
Store an item in the datastore.
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
void * cls
Closure for all of the callbacks.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
void * cls
Closure to use for all of the following callbacks (except "next_request").
A 512-bit hashcode.
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.
void * cls
Closure for conv and cleaner.
void * cls
Closure to pass to start_testcase.
Time for absolute times used by GNUnet, in microseconds.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_PQ_Context * dbh
Native Postgres database handle.
Closure for process_keys.
PluginKeyProcessor proc
Function to call for each key.
void * proc_cls
Closure for proc.
Closure for process_result.
struct Plugin * plugin
The plugin handle.
void * proc_cls
Closure for proc.
PluginDatumProcessor proc
Function to call on each result.
Context for #repl_iter() function.
void * proc_cls
Closure for proc.
struct Plugin * plugin
Plugin handle.
PluginDatumProcessor proc
Function to call for the result (or the NULL).