GNUnet  0.11.x
Data Structures | Macros | Functions
plugin_datacache_postgres.c File Reference

postgres for an implementation of a database backend for the datacache More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_pq_lib.h"
#include "gnunet_datacache_plugin.h"
Include dependency graph for plugin_datacache_postgres.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  HandleResultContext
 Closure for handle_results. More...
 
struct  ExtractResultContext
 Closure for extract_result_cb. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "datacache-postgres", __VA_ARGS__)
 
#define OVERHEAD   (sizeof(struct GNUNET_HashCode) + 24)
 Per-entry overhead estimate. More...
 

Functions

static int init_connection (struct Plugin *plugin)
 Get a database handle. More...
 
static ssize_t postgres_plugin_put (void *cls, const struct GNUNET_HashCode *key, uint32_t prox, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time, unsigned int path_info_len, const struct GNUNET_DHT_PathElement *path_info)
 Store an item in the datastore. More...
 
static void handle_results (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. More...
 
static unsigned int postgres_plugin_get (void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
 Iterate over the results for a particular key in the datastore. More...
 
static int postgres_plugin_del (void *cls)
 Delete the entry with the lowest expiration value from the datacache right now. More...
 
static void extract_result_cb (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. More...
 
static unsigned int postgres_plugin_get_closest (void *cls, const struct GNUNET_HashCode *key, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
 Iterate over the results that are "close" to a particular key in the datacache. More...
 
void * libgnunet_plugin_datacache_postgres_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_datacache_postgres_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

postgres for an implementation of a database backend for the datacache

Author
Christian Grothoff

Definition in file plugin_datacache_postgres.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "datacache-postgres", __VA_ARGS__)

Definition at line 31 of file plugin_datacache_postgres.c.

◆ OVERHEAD

#define OVERHEAD   (sizeof(struct GNUNET_HashCode) + 24)

Per-entry overhead estimate.

Definition at line 36 of file plugin_datacache_postgres.c.

Function Documentation

◆ init_connection()

static int init_connection ( struct Plugin plugin)
static

Get a database handle.

Parameters
pluginglobal context
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 67 of file plugin_datacache_postgres.c.

68 {
69  struct GNUNET_PQ_ExecuteStatement es[] = {
71  "CREATE TEMPORARY SEQUENCE IF NOT EXISTS gn011dc_oid_seq"),
72  GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS gn011dc ("
73  " oid OID NOT NULL DEFAULT nextval('gn011dc_oid_seq'),"
74  " type INTEGER NOT NULL,"
75  " prox INTEGER NOT NULL,"
76  " discard_time BIGINT NOT NULL,"
77  " key BYTEA NOT NULL,"
78  " value BYTEA NOT NULL,"
79  " path BYTEA DEFAULT NULL)"),
81  "ALTER SEQUENCE gnu011dc_oid_seq OWNED BY gn011dc.oid"),
83  "CREATE INDEX IF NOT EXISTS idx_oid ON gn011dc (oid)"),
85  "CREATE INDEX IF NOT EXISTS idx_key ON gn011dc (key)"),
87  "CREATE INDEX IF NOT EXISTS idx_dt ON gn011dc (discard_time)"),
89  "ALTER TABLE gn011dc ALTER value SET STORAGE EXTERNAL"),
90  GNUNET_PQ_make_execute ("ALTER TABLE gn011dc ALTER key SET STORAGE PLAIN"),
92  };
93  struct GNUNET_PQ_PreparedStatement ps[] = {
94  GNUNET_PQ_make_prepare ("getkt",
95  "SELECT discard_time,type,value,path FROM gn011dc "
96  "WHERE key=$1 AND type=$2 AND discard_time >= $3",
97  3),
98  GNUNET_PQ_make_prepare ("getk",
99  "SELECT discard_time,type,value,path FROM gn011dc "
100  "WHERE key=$1 AND discard_time >= $2",
101  2),
102  GNUNET_PQ_make_prepare ("getex",
103  "SELECT length(value) AS len,oid,key FROM gn011dc"
104  " WHERE discard_time < $1"
105  " ORDER BY discard_time ASC LIMIT 1",
106  1),
107  GNUNET_PQ_make_prepare ("getm",
108  "SELECT length(value) AS len,oid,key FROM gn011dc"
109  " ORDER BY prox ASC, discard_time ASC LIMIT 1",
110  0),
111  GNUNET_PQ_make_prepare ("get_closest",
112  "SELECT discard_time,type,value,path,key FROM gn011dc "
113  "WHERE key>=$1 AND discard_time >= $2 ORDER BY key ASC LIMIT $3",
114  3),
115  GNUNET_PQ_make_prepare ("delrow",
116  "DELETE FROM gn011dc WHERE oid=$1",
117  1),
118  GNUNET_PQ_make_prepare ("put",
119  "INSERT INTO gn011dc (type, prox, discard_time, key, value, path) "
120  "VALUES ($1, $2, $3, $4, $5, $6)",
121  6),
123  };
124 
126  "datacache-postgres",
127  NULL,
128  es,
129  ps);
130  if (NULL == plugin->dbh)
131  return GNUNET_SYSERR;
132  return GNUNET_OK;
133 }
struct Plugin * plugin
The process handle to the testbed service.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
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
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:450
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_PREPARED_STATEMENT_END
Terminator for prepared statement list.
#define GNUNET_PQ_EXECUTE_STATEMENT_END
Terminator for executable statement list.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
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().
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_PQ_Context * dbh
Native Postgres database handle.

References GNUNET_DATACACHE_PluginEnvironment::cfg, Plugin::dbh, Plugin::env, GNUNET_OK, GNUNET_PQ_connect_with_cfg(), GNUNET_PQ_EXECUTE_STATEMENT_END, GNUNET_PQ_make_execute(), GNUNET_PQ_make_prepare(), GNUNET_PQ_make_try_execute(), GNUNET_PQ_PREPARED_STATEMENT_END, GNUNET_SYSERR, and plugin.

Referenced by libgnunet_plugin_datacache_postgres_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ postgres_plugin_put()

static ssize_t postgres_plugin_put ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  prox,
size_t  data_size,
const char *  data,
enum GNUNET_BLOCK_Type  type,
struct GNUNET_TIME_Absolute  discard_time,
unsigned int  path_info_len,
const struct GNUNET_DHT_PathElement path_info 
)
static

Store an item in the datastore.

Parameters
clsclosure (our struct Plugin)
keykey to store data under
proxproximity of key to my PID
data_sizenumber of bytes in data
datadata to store
typetype of the value
discard_timewhen to discard the value in any case
path_info_lennumber of entries in path_info
path_infoa path through the network
Returns
0 if duplicate, -1 on error, number of bytes used otherwise

Definition at line 151 of file plugin_datacache_postgres.c.

160 {
161  struct Plugin *plugin = cls;
162  uint32_t type32 = (uint32_t) type;
163  struct GNUNET_PQ_QueryParam params[] = {
166  GNUNET_PQ_query_param_absolute_time (&discard_time),
170  path_info_len * sizeof(struct
173  };
175 
177  "put",
178  params);
179  if (0 > ret)
180  return -1;
181  plugin->num_items++;
182  return data_size + OVERHEAD;
183 }
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
struct GNUNET_HashCode key
The key used in the DHT.
uint32_t data
The data value.
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
Definition: gnunet_db_lib.h:36
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.
#define GNUNET_PQ_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
#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.
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
#define OVERHEAD
Per-entry overhead estimate.
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
Description of a DB query parameter.
Definition: gnunet_pq_lib.h:65
Handle for a plugin.
Definition: block.c:38
unsigned int num_items
Number of key-value pairs in the database.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References data, data_size, Plugin::dbh, GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_fixed_size(), GNUNET_PQ_query_param_uint32(), key, Plugin::num_items, OVERHEAD, plugin, ret, and type.

Referenced by libgnunet_plugin_datacache_postgres_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_results()

static void handle_results ( void *  cls,
PGresult *  result,
unsigned int  num_results 
)
static

Function to be called with the results of a SELECT statement that has returned num_results results.

Parse the result and call the callback given in cls

Parameters
clsclosure of type struct HandleResultContext
resultthe postgres result
num_resultthe number of results in result

Definition at line 218 of file plugin_datacache_postgres.c.

221 {
222  struct HandleResultContext *hrc = cls;
223 
224  for (unsigned int i = 0; i < num_results; i++)
225  {
226  struct GNUNET_TIME_Absolute expiration_time;
227  uint32_t type;
228  void *data;
229  size_t data_size;
230  struct GNUNET_DHT_PathElement *path;
231  size_t path_len;
232  struct GNUNET_PQ_ResultSpec rs[] = {
233  GNUNET_PQ_result_spec_absolute_time ("discard_time",
234  &expiration_time),
236  &type),
238  &data,
239  &data_size),
241  (void **) &path,
242  &path_len),
244  };
245 
246  if (GNUNET_YES !=
248  rs,
249  i))
250  {
251  GNUNET_break (0);
252  return;
253  }
254  if (0 != (path_len % sizeof(struct GNUNET_DHT_PathElement)))
255  {
256  GNUNET_break (0);
257  path_len = 0;
258  }
259  path_len %= sizeof(struct GNUNET_DHT_PathElement);
261  "Found result of size %u bytes and type %u in database\n",
262  (unsigned int) data_size,
263  (unsigned int) type);
264  if ((NULL != hrc->iter) &&
265  (GNUNET_SYSERR ==
266  hrc->iter (hrc->iter_cls,
267  hrc->key,
268  data_size,
269  data,
270  (enum GNUNET_BLOCK_Type) type,
271  expiration_time,
272  path_len,
273  path)))
274  {
276  "Ending iteration (client error)\n");
278  return;
279  }
281  }
282 }
static int result
Global testing status.
@ GNUNET_YES
Definition: gnunet_common.h:97
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time(const char *name, struct GNUNET_TIME_Absolute *at)
Absolute time expected.
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
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_result_spec_end
End of result parameter specification.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
#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
#define LOG(kind,...)
Description of a DB result cell.
Time for absolute times used by GNUnet, in microseconds.
Closure for handle_results.
void * iter_cls
Closure for iter.
const struct GNUNET_HashCode * key
Key used.
GNUNET_DATACACHE_Iterator iter
Function to call on each result, may be NULL.

References data, data_size, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_PQ_cleanup_result(), GNUNET_PQ_extract_result(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_variable_size(), GNUNET_SYSERR, GNUNET_YES, HandleResultContext::iter, HandleResultContext::iter_cls, HandleResultContext::key, LOG, result, and type.

Referenced by postgres_plugin_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ postgres_plugin_get()

static unsigned int postgres_plugin_get ( void *  cls,
const struct GNUNET_HashCode key,
enum GNUNET_BLOCK_Type  type,
GNUNET_DATACACHE_Iterator  iter,
void *  iter_cls 
)
static

Iterate over the results for a particular key in the datastore.

Parameters
clsclosure (our struct Plugin)
keykey to look for
typeentries of which type are relevant?
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found

Definition at line 297 of file plugin_datacache_postgres.c.

302 {
303  struct Plugin *plugin = cls;
304  uint32_t type32 = (uint32_t) type;
305  struct GNUNET_TIME_Absolute now = { 0 };
306  struct GNUNET_PQ_QueryParam paramk[] = {
310  };
311  struct GNUNET_PQ_QueryParam paramkt[] = {
316  };
318  struct HandleResultContext hr_ctx;
319 
320  now = GNUNET_TIME_absolute_get ();
321  hr_ctx.iter = iter;
322  hr_ctx.iter_cls = iter_cls;
323  hr_ctx.key = key;
325  (0 == type) ? "getk" : "getkt",
326  (0 == type) ? paramk : paramkt,
328  &hr_ctx);
329  if (res < 0)
330  return 0;
331  return res;
332 }
static int res
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_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:94
static void handle_results(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.

References Plugin::dbh, GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint32(), GNUNET_TIME_absolute_get(), handle_results(), HandleResultContext::iter, HandleResultContext::iter_cls, HandleResultContext::key, key, plugin, res, and type.

Referenced by libgnunet_plugin_datacache_postgres_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ postgres_plugin_del()

static int postgres_plugin_del ( void *  cls)
static

Delete the entry with the lowest expiration value from the datacache right now.

Parameters
clsclosure (our struct Plugin)
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 343 of file plugin_datacache_postgres.c.

344 {
345  struct Plugin *plugin = cls;
346  struct GNUNET_PQ_QueryParam pempty[] = {
348  };
349  uint32_t size;
350  uint32_t oid;
351  struct GNUNET_HashCode key;
352  struct GNUNET_PQ_ResultSpec rs[] = {
354  &size),
356  &oid),
358  &key),
360  };
362  struct GNUNET_PQ_QueryParam dparam[] = {
365  };
366  struct GNUNET_TIME_Absolute now;
367  struct GNUNET_PQ_QueryParam xparam[] = {
370  };
371 
372  now = GNUNET_TIME_absolute_get ();
374  "getex",
375  xparam,
376  rs);
377  if (0 >= res)
379  "getm",
380  pempty,
381  rs);
382  if (0 > res)
383  return GNUNET_SYSERR;
385  {
386  /* no result */
388  "Ending iteration (no more results)\n");
389  return 0;
390  }
392  "delrow",
393  dparam);
394  if (0 > res)
395  {
397  return GNUNET_SYSERR;
398  }
399  plugin->num_items--;
401  &key,
402  size + OVERHEAD);
404  return GNUNET_OK;
405 }
@ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
The transaction succeeded, but yielded zero results.
Definition: gnunet_db_lib.h:54
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:258
#define GNUNET_PQ_result_spec_auto_from_type(name, dst)
We expect a fixed-size result, with size determined by the type of * dst
static unsigned int size
Size of the "table".
Definition: peer.c:67
GNUNET_DATACACHE_DeleteNotifyCallback delete_notify
Function to call whenever the plugin needs to discard content that it was asked to store.
void * cls
Closure to use for callbacks.
A 512-bit hashcode.

References GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::dbh, GNUNET_DATACACHE_PluginEnvironment::delete_notify, Plugin::env, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, GNUNET_PQ_cleanup_result(), GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_eval_prepared_singleton_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint32(), GNUNET_PQ_result_spec_auto_from_type, GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), key, LOG, Plugin::num_items, OVERHEAD, plugin, res, and size.

Referenced by libgnunet_plugin_datacache_postgres_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_result_cb()

static void extract_result_cb ( void *  cls,
PGresult *  result,
unsigned int  num_results 
)
static

Function to be called with the results of a SELECT statement that has returned num_results results.

Calls the iter from cls for each result.

Parameters
clsclosure with the struct ExtractResultContext
resultthe postgres result
num_resultthe number of results in result

Definition at line 435 of file plugin_datacache_postgres.c.

438 {
439  struct ExtractResultContext *erc = cls;
440 
441  if (NULL == erc->iter)
442  return;
443  for (unsigned int i = 0; i < num_results; i++)
444  {
445  struct GNUNET_TIME_Absolute expiration_time;
446  uint32_t type;
447  void *data;
448  size_t data_size;
449  struct GNUNET_DHT_PathElement *path;
450  size_t path_len;
451  struct GNUNET_HashCode key;
452  struct GNUNET_PQ_ResultSpec rs[] = {
454  &expiration_time),
456  &type),
458  &data,
459  &data_size),
461  (void **) &path,
462  &path_len),
464  &key),
466  };
467 
468  if (GNUNET_YES !=
470  rs,
471  i))
472  {
473  GNUNET_break (0);
474  return;
475  }
476  if (0 != (path_len % sizeof(struct GNUNET_DHT_PathElement)))
477  {
478  GNUNET_break (0);
479  path_len = 0;
480  }
481  path_len %= sizeof(struct GNUNET_DHT_PathElement);
483  "Found result of size %u bytes and type %u in database\n",
484  (unsigned int) data_size,
485  (unsigned int) type);
486  if (GNUNET_SYSERR ==
487  erc->iter (erc->iter_cls,
488  &key,
489  data_size,
490  data,
491  (enum GNUNET_BLOCK_Type) type,
492  expiration_time,
493  path_len,
494  path))
495  {
497  "Ending iteration (client error)\n");
499  break;
500  }
502  }
503 }
Closure for extract_result_cb.
void * iter_cls
Closure for iter.
GNUNET_DATACACHE_Iterator iter
Function to call for each result found.

References data, data_size, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_PQ_cleanup_result(), GNUNET_PQ_extract_result(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_auto_from_type, GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_variable_size(), GNUNET_SYSERR, GNUNET_YES, ExtractResultContext::iter, ExtractResultContext::iter_cls, key, LOG, result, and type.

Referenced by postgres_plugin_get_closest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ postgres_plugin_get_closest()

static unsigned int postgres_plugin_get_closest ( void *  cls,
const struct GNUNET_HashCode key,
unsigned int  num_results,
GNUNET_DATACACHE_Iterator  iter,
void *  iter_cls 
)
static

Iterate over the results that are "close" to a particular key in the datacache.

"close" is defined as numerically larger than key (when interpreted as a circular address space), with small distance.

Parameters
clsclosure (internal context for the plugin)
keyarea of the keyspace to look into
num_resultsnumber of results that should be returned to iter
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found

Definition at line 520 of file plugin_datacache_postgres.c.

525 {
526  struct Plugin *plugin = cls;
527  uint32_t num_results32 = (uint32_t) num_results;
528  struct GNUNET_TIME_Absolute now;
529  struct GNUNET_PQ_QueryParam params[] = {
532  GNUNET_PQ_query_param_uint32 (&num_results32),
534  };
536  struct ExtractResultContext erc;
537 
538  erc.iter = iter;
539  erc.iter_cls = iter_cls;
540  now = GNUNET_TIME_absolute_get ();
542  "get_closest",
543  params,
545  &erc);
546  if (0 > res)
547  {
549  "Ending iteration (postgres error)\n");
550  return 0;
551  }
553  {
554  /* no result */
556  "Ending iteration (no more results)\n");
557  return 0;
558  }
559  return res;
560 }
static void extract_result_cb(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.

References Plugin::dbh, extract_result_cb(), GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_ERROR_TYPE_DEBUG, GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint32(), GNUNET_TIME_absolute_get(), ExtractResultContext::iter, ExtractResultContext::iter_cls, key, LOG, plugin, and res.

Referenced by libgnunet_plugin_datacache_postgres_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_datacache_postgres_init()

void* libgnunet_plugin_datacache_postgres_init ( void *  cls)

Entry point for the plugin.

Parameters
clsclosure (the struct GNUNET_DATACACHE_PluginEnvironmnet)
Returns
the plugin's closure (our struct Plugin)

Definition at line 570 of file plugin_datacache_postgres.c.

571 {
574  struct Plugin *plugin;
575 
576  plugin = GNUNET_new (struct Plugin);
577  plugin->env = env;
578 
580  {
582  return NULL;
583  }
584 
586  api->cls = plugin;
587  api->get = &postgres_plugin_get;
588  api->put = &postgres_plugin_put;
589  api->del = &postgres_plugin_del;
590  api->get_closest = &postgres_plugin_get_closest;
592  "Postgres datacache running\n");
593  return api;
594 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
static unsigned int postgres_plugin_get_closest(void *cls, const struct GNUNET_HashCode *key, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results that are "close" to a particular key in the datacache.
static int init_connection(struct Plugin *plugin)
Get a database handle.
static unsigned int postgres_plugin_get(void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results for a particular key in the datastore.
static ssize_t postgres_plugin_put(void *cls, const struct GNUNET_HashCode *key, uint32_t prox, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time, unsigned int path_info_len, const struct GNUNET_DHT_PathElement *path_info)
Store an item in the datastore.
static int postgres_plugin_del(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
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 ...
struct returned by the initialization function of the plugin
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATACACHE_PluginEnvironment::cls, env, Plugin::env, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_new, GNUNET_OK, init_connection(), LOG, plugin, postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), and postgres_plugin_put().

Here is the call graph for this function:

◆ libgnunet_plugin_datacache_postgres_done()

void* libgnunet_plugin_datacache_postgres_done ( void *  cls)

Exit point from the plugin.

Parameters
clsclosure (our struct Plugin)
Returns
NULL

Definition at line 604 of file plugin_datacache_postgres.c.

605 {
607  struct Plugin *plugin = api->cls;
608 
611  GNUNET_free (api);
612  return NULL;
613 }
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:509
void * cls
Closure to pass to all plugin functions.

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::cls, Plugin::dbh, GNUNET_free, GNUNET_PQ_disconnect(), and plugin.

Here is the call graph for this function: