GNUnet  0.11.x
Data Structures | Functions
pq_event.c File Reference

event notifications via Postgres More...

#include "platform.h"
#include "pq.h"
#include <pthread.h>
Include dependency graph for pq_event.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_DB_EventHandler
 Handle for an active LISTENer to the database. More...
 
struct  NotifyContext
 Closure for do_notify(). More...
 

Functions

static void es_to_sh (const struct GNUNET_DB_EventHeaderP *es, struct GNUNET_ShortHashCode *sh)
 Convert es to a short hash. More...
 
static char * sh_to_channel (struct GNUNET_ShortHashCode *sh, char identifier[64])
 Convert sh to a Postgres identifier. More...
 
static enum GNUNET_GenericReturnValue channel_to_sh (const char *identifier, struct GNUNET_ShortHashCode *sh)
 Convert sh to a Postgres identifier. More...
 
static char * es_to_channel (const struct GNUNET_DB_EventHeaderP *es, char identifier[64])
 Convert es to a Postgres identifier. More...
 
static int do_notify (void *cls, const struct GNUNET_ShortHashCode *sh, void *value)
 Function called on every event handler that needs to be triggered. More...
 
static void event_do_poll (struct GNUNET_PQ_Context *db)
 
static void do_scheduler_notify (void *cls)
 The GNUnet scheduler notifies us that we need to trigger the DB event poller. More...
 
static void scheduler_fd_cb (void *cls, int fd)
 Function called when the Postgres FD changes and we need to update the scheduler event loop task. More...
 
static void manage_subscribe (struct GNUNET_PQ_Context *db, const char *cmd, struct GNUNET_DB_EventHandler *eh)
 Helper function to trigger an SQL cmd on db. More...
 
static int register_notify (void *cls, const struct GNUNET_ShortHashCode *sh, void *value)
 Re-subscribe to notifications after disconnect. More...
 
void GNUNET_PQ_event_reconnect_ (struct GNUNET_PQ_Context *db, int fd)
 Internal API. More...
 
static void event_timeout (void *cls)
 Function run on timeout for an event. More...
 
struct GNUNET_DB_EventHandlerGNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, const struct GNUNET_DB_EventHeaderP *es, struct GNUNET_TIME_Relative timeout, GNUNET_DB_EventCallback cb, void *cb_cls)
 Register callback to be invoked on events of type es. More...
 
void GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh)
 Stop notifications. More...
 
void GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, const struct GNUNET_DB_EventHeaderP *es, const void *extra, size_t extra_size)
 Notify all that listen on es of an event. More...
 

Detailed Description

event notifications via Postgres

Author
Christian Grothoff

Definition in file pq_event.c.

Function Documentation

◆ es_to_sh()

static void es_to_sh ( const struct GNUNET_DB_EventHeaderP es,
struct GNUNET_ShortHashCode sh 
)
static

Convert es to a short hash.

Parameters
esspec to hash to an identifier
[out]shshort hash to set

Definition at line 69 of file pq_event.c.

71 {
72  struct GNUNET_HashCode h_channel;
73 
75  ntohs (es->size),
76  &h_channel);
77  GNUNET_static_assert (sizeof (*sh) <= sizeof (h_channel));
78  memcpy (sh,
79  &h_channel,
80  sizeof (*sh));
81 }
static struct SolverHandle * sh
#define GNUNET_static_assert(cond)
Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime an...
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
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Definition: gnunet_db_lib.h:96
A 512-bit hashcode.

References GNUNET_CRYPTO_hash(), GNUNET_static_assert, sh, and GNUNET_DB_EventHeaderP::size.

Referenced by es_to_channel(), and GNUNET_PQ_event_listen().

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

◆ sh_to_channel()

static char* sh_to_channel ( struct GNUNET_ShortHashCode sh,
char  identifier[64] 
)
static

Convert sh to a Postgres identifier.

Parameters
shshort hash to convert to an identifier
[out]identifierby default, Postgres supports NAMEDATALEN=64 character identifiers
Returns
end position of the identifier

Definition at line 93 of file pq_event.c.

95 {
96  char *end;
97 
99  sizeof (*sh),
100  identifier,
101  63);
102  GNUNET_assert (NULL != end);
103  *end = '\0';
104  return end;
105 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:695

Referenced by es_to_channel(), and manage_subscribe().

Here is the caller graph for this function:

◆ channel_to_sh()

static enum GNUNET_GenericReturnValue channel_to_sh ( const char *  identifier,
struct GNUNET_ShortHashCode sh 
)
static

Convert sh to a Postgres identifier.

Parameters
identifierto convert
[out]shset to short hash
Returns
GNUNET_OK on success

Definition at line 93 of file pq_event.c.

118 {
119  return GNUNET_STRINGS_string_to_data (identifier,
120  strlen (identifier),
121  sh,
122  sizeof (*sh));
123 }
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:775

References end, GNUNET_assert, GNUNET_STRINGS_data_to_string(), and sh.

Referenced by event_do_poll().

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

◆ es_to_channel()

static char* es_to_channel ( const struct GNUNET_DB_EventHeaderP es,
char  identifier[64] 
)
static

Convert es to a Postgres identifier.

Parameters
esspec to hash to an identifier
[out]identifierby default, Postgres supports NAMEDATALEN=64 character identifiers
Returns
end position of the identifier

Definition at line 135 of file pq_event.c.

137 {
138  struct GNUNET_ShortHashCode sh;
139 
140  es_to_sh (es,
141  &sh);
142  return sh_to_channel (&sh,
143  identifier);
144 }
static void es_to_sh(const struct GNUNET_DB_EventHeaderP *es, struct GNUNET_ShortHashCode *sh)
Convert es to a short hash.
Definition: pq_event.c:69
static char * sh_to_channel(struct GNUNET_ShortHashCode *sh, char identifier[64])
Convert sh to a Postgres identifier.
Definition: pq_event.c:93
A 256-bit hashcode.

References es_to_sh(), sh, and sh_to_channel().

Here is the call graph for this function:

◆ do_notify()

static int do_notify ( void *  cls,
const struct GNUNET_ShortHashCode sh,
void *  value 
)
static

Function called on every event handler that needs to be triggered.

Parameters
clsa struct NotifyContext
shchannel name
valuea struct GNUNET_DB_EventHandler
Returns
GNUNET_OK continue to iterate

Definition at line 174 of file pq_event.c.

177 {
178  struct NotifyContext *ctx = cls;
179  struct GNUNET_DB_EventHandler *eh = value;
180 
181  eh->cb (eh->cb_cls,
182  ctx->extra,
183  ctx->extra_size);
184  return GNUNET_OK;
185 }
static char * value
Value of the record to add/remove.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
@ GNUNET_OK
Definition: gnunet_common.h:95
Handle for an active LISTENer to the database.
Definition: pq_event.c:34
void * cb_cls
Closure for cb.
Definition: pq_event.c:48
GNUNET_DB_EventCallback cb
Function to call on events.
Definition: pq_event.c:43
Closure for do_notify().
Definition: pq_event.c:151

References GNUNET_DB_EventHandler::cb, GNUNET_DB_EventHandler::cb_cls, ctx, GNUNET_OK, and value.

Referenced by event_do_poll().

Here is the caller graph for this function:

◆ event_do_poll()

static void event_do_poll ( struct GNUNET_PQ_Context db)
static

Definition at line 189 of file pq_event.c.

190 {
191  PGnotify *n;
192 
194  "PG poll job active\n");
195  if (1 !=
196  PQconsumeInput (db->conn))
198  "Failed to read from Postgres: %s\n",
199  PQerrorMessage (db->conn));
200  while (NULL != (n = PQnotifies (db->conn)))
201  {
202  struct GNUNET_ShortHashCode sh;
203  struct NotifyContext ctx = {
204  .extra = NULL
205  };
206 
207  if ('X' != toupper ((int) n->relname[0]))
208  {
210  "Ignoring notification for unsupported channel identifier `%s'\n",
211  n->relname);
212  PQfreemem (n);
213  continue;
214  }
215  if (GNUNET_OK !=
216  channel_to_sh (&n->relname[1],
217  &sh))
218  {
220  "Ignoring notification for unsupported channel identifier `%s'\n",
221  n->relname);
222  PQfreemem (n);
223  continue;
224  }
225  if ( (NULL != n->extra) &&
226  (GNUNET_OK !=
228  strlen (n->extra),
229  &ctx.extra,
230  &ctx.extra_size)))
231  {
233  "Ignoring notification for unsupported extra data `%s' on channel `%s'\n",
234  n->extra,
235  n->relname);
236  PQfreemem (n);
237  continue;
238  }
240  "Received notification %s with extra data `%.*s'\n",
241  n->relname,
242  (int) ctx.extra_size,
243  (const char *) ctx.extra);
245  &sh,
246  &do_notify,
247  &ctx);
248  GNUNET_free (ctx.extra);
249  PQfreemem (n);
250  }
251 }
static struct GNUNET_FS_DirectoryBuilder * db
Definition: gnunet-search.c:41
#define GNUNET_log(kind,...)
int GNUNET_CONTAINER_multishortmap_get_multiple(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data_alloc(const char *enc, size_t enclen, void **out, size_t *out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:841
static enum GNUNET_GenericReturnValue channel_to_sh(const char *identifier, struct GNUNET_ShortHashCode *sh)
Convert sh to a Postgres identifier.
Definition: pq_event.c:116
static int do_notify(void *cls, const struct GNUNET_ShortHashCode *sh, void *value)
Function called on every event handler that needs to be triggered.
Definition: pq_event.c:174

References channel_to_sh(), ctx, db, do_notify(), GNUNET_CONTAINER_multishortmap_get_multiple(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_STRINGS_string_to_data_alloc(), and sh.

Referenced by do_scheduler_notify().

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

◆ do_scheduler_notify()

static void do_scheduler_notify ( void *  cls)
static

The GNUnet scheduler notifies us that we need to trigger the DB event poller.

Parameters
clsa struct GNUNET_PQ_Context *

Definition at line 261 of file pq_event.c.

262 {
263  struct GNUNET_PQ_Context *db = cls;
264 
265  db->event_task = NULL;
266  GNUNET_assert (NULL != db->rfd);
267  event_do_poll (db);
269  "Resubscribing\n");
270  db->event_task
272  db->rfd,
274  db);
275 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void event_do_poll(struct GNUNET_PQ_Context *db)
Definition: pq_event.c:189
static void do_scheduler_notify(void *cls)
The GNUnet scheduler notifies us that we need to trigger the DB event poller.
Definition: pq_event.c:261
Handle to Postgres database.
Definition: pq.h:36

References db, event_do_poll(), GNUNET_assert, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_add_read_net(), and GNUNET_TIME_UNIT_FOREVER_REL.

Referenced by scheduler_fd_cb().

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

◆ scheduler_fd_cb()

static void scheduler_fd_cb ( void *  cls,
int  fd 
)
static

Function called when the Postgres FD changes and we need to update the scheduler event loop task.

Parameters
clsa struct GNUNET_PQ_Context *
fdthe file descriptor, possibly -1

Definition at line 286 of file pq_event.c.

288 {
289  struct GNUNET_PQ_Context *db = cls;
290 
292  "New poll FD is %d\n",
293  fd);
294  if (NULL != db->event_task)
295  {
296  GNUNET_SCHEDULER_cancel (db->event_task);
297  db->event_task = NULL;
298  }
299  GNUNET_free (db->rfd);
300  if (-1 == fd)
301  return;
302  if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map))
303  return;
305  "Activating poll job on %d\n",
306  fd);
308  db->event_task
310  db->rfd,
312  db);
313 }
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_box_native(int fd)
Box a native socket (and check that it is a socket).
Definition: network.c:636
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.

References db, do_scheduler_notify(), GNUNET_CONTAINER_multishortmap_size(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_NETWORK_socket_box_native(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), and GNUNET_TIME_UNIT_ZERO.

Referenced by GNUNET_PQ_event_listen(), and GNUNET_PQ_event_reconnect_().

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

◆ manage_subscribe()

static void manage_subscribe ( struct GNUNET_PQ_Context db,
const char *  cmd,
struct GNUNET_DB_EventHandler eh 
)
static

Helper function to trigger an SQL cmd on db.

Parameters
dbdatabase to send command to
cmdprefix of the command to send
ehdetails about the event

Definition at line 324 of file pq_event.c.

327 {
328  char sql[16 + 64];
329  char *end;
330  PGresult *result;
331 
332  end = stpcpy (sql,
333  cmd);
334  end = sh_to_channel (&eh->sh,
335  end);
337  "Executing PQ command `%s'\n",
338  sql);
339  result = PQexec (db->conn,
340  sql);
341  if (PGRES_COMMAND_OK != PQresultStatus (result))
342  {
344  "pq",
345  "Failed to execute `%s': %s/%s/%s/%s/%s",
346  sql,
347  PQresultErrorField (result,
348  PG_DIAG_MESSAGE_PRIMARY),
349  PQresultErrorField (result,
350  PG_DIAG_MESSAGE_DETAIL),
351  PQresultErrorMessage (result),
352  PQresStatus (PQresultStatus (result)),
353  PQerrorMessage (db->conn));
354  }
355  PQclear (result);
356 }
static int result
Global testing status.
#define GNUNET_log_from(kind, comp,...)
struct GNUNET_ShortHashCode sh
Channel name.
Definition: pq_event.c:38

References db, end, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_log_from, result, GNUNET_DB_EventHandler::sh, and sh_to_channel().

Referenced by GNUNET_PQ_event_listen(), GNUNET_PQ_event_listen_cancel(), and register_notify().

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

◆ register_notify()

static int register_notify ( void *  cls,
const struct GNUNET_ShortHashCode sh,
void *  value 
)
static

Re-subscribe to notifications after disconnect.

Parameters
clsthe DB context
shthe short hash of the channel
ehthe event handler
Returns
GNUNET_OK to continue to iterate

Definition at line 368 of file pq_event.c.

371 {
372  struct GNUNET_PQ_Context *db = cls;
373  struct GNUNET_DB_EventHandler *eh = value;
374 
376  "LISTEN X",
377  eh);
378  return GNUNET_OK;
379 }
static void manage_subscribe(struct GNUNET_PQ_Context *db, const char *cmd, struct GNUNET_DB_EventHandler *eh)
Helper function to trigger an SQL cmd on db.
Definition: pq_event.c:324

References db, GNUNET_OK, manage_subscribe(), and value.

Referenced by GNUNET_PQ_event_reconnect_().

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

◆ GNUNET_PQ_event_reconnect_()

void GNUNET_PQ_event_reconnect_ ( struct GNUNET_PQ_Context db,
int  fd 
)

Internal API.

Reconnect should re-register notifications after a disconnect.

Parameters
dbthe DB handle
fdsocket to listen on

Definition at line 383 of file pq_event.c.

385 {
387  "Change in PQ event FD to %d\n",
388  fd);
390  fd);
393  db);
394 }
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
static int register_notify(void *cls, const struct GNUNET_ShortHashCode *sh, void *value)
Re-subscribe to notifications after disconnect.
Definition: pq_event.c:368
static void scheduler_fd_cb(void *cls, int fd)
Function called when the Postgres FD changes and we need to update the scheduler event loop task.
Definition: pq_event.c:286

References db, GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, register_notify(), and scheduler_fd_cb().

Referenced by GNUNET_PQ_reconnect().

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

◆ event_timeout()

static void event_timeout ( void *  cls)
static

Function run on timeout for an event.

Triggers the notification, but does NOT clear the handler.

Parameters
clsa struct GNUNET_DB_EventHandler *

Definition at line 404 of file pq_event.c.

405 {
406  struct GNUNET_DB_EventHandler *eh = cls;
407 
408  eh->timeout_task = NULL;
409  eh->cb (eh->cb_cls,
410  NULL,
411  0);
412 }
struct GNUNET_SCHEDULER_Task * timeout_task
Task to run on timeout.
Definition: pq_event.c:58

References GNUNET_DB_EventHandler::cb, GNUNET_DB_EventHandler::cb_cls, and GNUNET_DB_EventHandler::timeout_task.

Referenced by GNUNET_PQ_event_listen().

Here is the caller graph for this function:

◆ GNUNET_PQ_event_listen()

struct GNUNET_DB_EventHandler* GNUNET_PQ_event_listen ( struct GNUNET_PQ_Context db,
const struct GNUNET_DB_EventHeaderP es,
struct GNUNET_TIME_Relative  timeout,
GNUNET_DB_EventCallback  cb,
void *  cb_cls 
)

Register callback to be invoked on events of type es.

Unlike many other calls, this function is thread-safe and may be called from threads that are different from the one that setup db. However, the cb will always be called from the thread that runs #GNUNET_PQ_event_do_poll() or the GNUnet scheduler.

Parameters
dbdatabase context to use
esspecification of the event to listen for
timeoutwhen to trigger cb based on timeout
cbfunction to call when the event happens, possibly multiple times (until GNUNET_PQ_event_listen_cancel() is invoked), including on timeout
cb_clsclosure for cb
Returns
handle useful to cancel the listener

Definition at line 416 of file pq_event.c.

421 {
422  struct GNUNET_DB_EventHandler *eh;
423 
424  eh = GNUNET_new (struct GNUNET_DB_EventHandler);
425  eh->db = db;
426  es_to_sh (es,
427  &eh->sh);
428  eh->cb = cb;
429  eh->cb_cls = cb_cls;
432  &eh->sh,
433  eh,
435  if (NULL == db->event_task)
436  {
438  "Starting event scheduler\n");
440  PQsocket (db->conn));
441  }
443  "LISTEN X",
444  eh);
446  &event_timeout,
447  eh);
448  return eh;
449 }
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
int GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
static void event_timeout(void *cls)
Function run on timeout for an event.
Definition: pq_event.c:404
struct GNUNET_PQ_Context * db
Database context this event handler is with.
Definition: pq_event.c:53

References GNUNET_DB_EventHandler::cb, GNUNET_DB_EventHandler::cb_cls, db, GNUNET_DB_EventHandler::db, es_to_sh(), event_timeout(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_put(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), manage_subscribe(), scheduler_fd_cb(), GNUNET_DB_EventHandler::sh, timeout, and GNUNET_DB_EventHandler::timeout_task.

Here is the call graph for this function:

◆ GNUNET_PQ_event_listen_cancel()

void GNUNET_PQ_event_listen_cancel ( struct GNUNET_DB_EventHandler eh)

Stop notifications.

Unlike many other calls, this function is thread-safe and may be called from threads that are different from the one that setup db. However, the cb will always be called from the thread that runs #GNUNET_PQ_event_do_poll() or the GNUnet scheduler.

Parameters
ehhandle to unregister.

Definition at line 453 of file pq_event.c.

454 {
455  struct GNUNET_PQ_Context *db = eh->db;
456 
459  &eh->sh,
460  eh));
462  "UNLISTEN X",
463  eh);
464  if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map))
465  {
467  "Stopping PQ event scheduler job\n");
468  GNUNET_free (db->rfd);
469  if (NULL != db->event_task)
470  {
471  GNUNET_SCHEDULER_cancel (db->event_task);
472  db->event_task = NULL;
473  }
474  }
475  if (NULL != eh->timeout_task)
476  {
478  eh->timeout_task = NULL;
479  }
480  GNUNET_free (eh);
481 }
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.

References db, GNUNET_DB_EventHandler::db, GNUNET_assert, GNUNET_CONTAINER_multishortmap_remove(), GNUNET_CONTAINER_multishortmap_size(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_cancel(), manage_subscribe(), GNUNET_DB_EventHandler::sh, and GNUNET_DB_EventHandler::timeout_task.

Here is the call graph for this function:

◆ GNUNET_PQ_event_notify()

void GNUNET_PQ_event_notify ( struct GNUNET_PQ_Context db,
const struct GNUNET_DB_EventHeaderP es,
const void *  extra,
size_t  extra_size 
)

Notify all that listen on es of an event.

Unlike many other calls, this function is thread-safe and may be called from threads that are different from the one that setup db. However, the cb will always be called from the thread that runs #GNUNET_PQ_event_do_poll() or the GNUnet scheduler.

Parameters
dbdatabase context to use
esspecification of the event to generate
extraadditional event data provided
extra_sizenumber of bytes in extra

Definition at line 485 of file pq_event.c.

489 {
490  char sql[16 + 64 + extra_size * 8 / 5 + 8];
491  char *end;
492  PGresult *result;
493 
494  end = stpcpy (sql,
495  "NOTIFY X");
496  end = es_to_channel (es,
497  end);
498  end = stpcpy (end,
499  ", '");
501  extra_size,
502  end,
503  sizeof (sql) - (end - sql) - 1);
504  GNUNET_assert (NULL != end);
505  *end = '\0';
506  end = stpcpy (end,
507  "'");
509  "Executing command `%s'\n",
510  sql);
511  result = PQexec (db->conn,
512  sql);
513  if (PGRES_COMMAND_OK != PQresultStatus (result))
514  {
516  "pq",
517  "Failed to execute `%s': %s/%s/%s/%s/%s",
518  sql,
519  PQresultErrorField (result,
520  PG_DIAG_MESSAGE_PRIMARY),
521  PQresultErrorField (result,
522  PG_DIAG_MESSAGE_DETAIL),
523  PQresultErrorMessage (result),
524  PQresStatus (PQresultStatus (result)),
525  PQerrorMessage (db->conn));
526  }
527  PQclear (result);
528  event_do_poll (db);
529 }
static char * es_to_channel(const struct GNUNET_DB_EventHeaderP *es, char identifier[64])
Convert es to a Postgres identifier.
Definition: pq_event.c:135