event notifications via Postgres More...
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 enum GNUNET_GenericReturnValue | do_notify (void *cls, const struct GNUNET_ShortHashCode *sh, void *value) |
Function called on every event handler that needs to be triggered. More... | |
void | GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db) |
Poll for events right now. More... | |
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 enum GNUNET_GenericReturnValue | 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_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. More... | |
void | GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh) |
Stop notifications. More... | |
char * | GNUNET_PQ_get_event_notify_channel (const struct GNUNET_DB_EventHeaderP *es) |
Compute the channel that one should notify upon for the given event specification. 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... | |
event notifications via Postgres
Definition in file pq_event.c.
|
static |
Convert es to a short hash.
es | spec to hash to an identifier | |
[out] | sh | short hash to set |
Definition at line 69 of file pq_event.c.
References GNUNET_CRYPTO_hash(), GNUNET_static_assert, sh, and GNUNET_DB_EventHeaderP::size.
Referenced by es_to_channel(), and GNUNET_PQ_event_listen().
|
static |
Convert sh to a Postgres identifier.
sh | short hash to convert to an identifier | |
[out] | identifier | by default, Postgres supports NAMEDATALEN=64 character identifiers |
Definition at line 93 of file pq_event.c.
References end, GNUNET_assert, GNUNET_STRINGS_data_to_string(), and sh.
Referenced by es_to_channel(), and manage_subscribe().
|
static |
Convert sh to a Postgres identifier.
identifier | to convert | |
[out] | sh | set to short hash |
Definition at line 116 of file pq_event.c.
References GNUNET_STRINGS_string_to_data(), and sh.
Referenced by GNUNET_PQ_event_do_poll().
|
static |
Convert es to a Postgres identifier.
es | spec to hash to an identifier | |
[out] | identifier | by default, Postgres supports NAMEDATALEN=64 character identifiers |
Definition at line 135 of file pq_event.c.
References es_to_sh(), sh, and sh_to_channel().
Referenced by GNUNET_PQ_event_notify(), and GNUNET_PQ_get_event_notify_channel().
|
static |
Function called on every event handler that needs to be triggered.
cls | a struct NotifyContext |
sh | channel name |
value | a struct GNUNET_DB_EventHandler |
Definition at line 174 of file pq_event.c.
References GNUNET_DB_EventHandler::cb, GNUNET_DB_EventHandler::cb_cls, ctx, GNUNET_OK, and value.
Referenced by GNUNET_PQ_event_do_poll().
void GNUNET_PQ_event_do_poll | ( | struct GNUNET_PQ_Context * | db | ) |
Poll for events right now.
Useful if we may have triggered an event for ourselves. Not needed when using GNUNET_PQ_event_notify(), but useful when stored procedures may have triggered events. Does nothing if there are no events.
[in,out] | db | database to check for events |
Definition at line 189 of file pq_event.c.
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_PQ_reconnect(), GNUNET_STRINGS_string_to_data_alloc(), and sh.
Referenced by do_scheduler_notify(), and GNUNET_PQ_event_notify().
|
static |
The GNUnet scheduler notifies us that we need to trigger the DB event poller.
cls | a struct GNUNET_PQ_Context * |
Definition at line 272 of file pq_event.c.
References db, do_scheduler_notify(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_PQ_event_do_poll(), GNUNET_PQ_reconnect(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_read_net(), GNUNET_TIME_relative_max(), GNUNET_TIME_STD_BACKOFF, GNUNET_TIME_UNIT_FOREVER_REL, and GNUNET_TIME_UNIT_SECONDS.
Referenced by do_scheduler_notify(), and scheduler_fd_cb().
|
static |
Function called when the Postgres FD changes and we need to update the scheduler event loop task.
cls | a struct GNUNET_PQ_Context * |
fd | the file descriptor, possibly -1 |
Definition at line 313 of file pq_event.c.
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_().
|
static |
Helper function to trigger an SQL cmd on db.
db | database to send command to |
cmd | prefix of the command to send |
eh | details about the event |
Definition at line 351 of file pq_event.c.
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().
|
static |
Re-subscribe to notifications after disconnect.
cls | the DB context |
sh | the short hash of the channel |
value | the event handler |
Definition at line 397 of file pq_event.c.
References db, GNUNET_OK, manage_subscribe(), and value.
Referenced by 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.
db | the DB handle |
fd | socket to listen on |
Definition at line 412 of file pq_event.c.
References db, GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, register_notify(), and scheduler_fd_cb().
Referenced by GNUNET_PQ_reconnect().
|
static |
Function run on timeout for an event.
Triggers the notification, but does NOT clear the handler.
cls | a struct GNUNET_DB_EventHandler * |
Definition at line 433 of file pq_event.c.
References GNUNET_DB_EventHandler::cb, GNUNET_DB_EventHandler::cb_cls, and GNUNET_DB_EventHandler::timeout_task.
Referenced by 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.
db | database context to use |
es | specification of the event to listen for |
timeout | when to trigger cb based on timeout |
cb | function to call when the event happens, possibly multiple times (until GNUNET_PQ_event_listen_cancel() is invoked), including on timeout |
cb_cls | closure for cb |
Definition at line 445 of file pq_event.c.
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_get(), 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.
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.
eh | handle to unregister. |
Definition at line 487 of file pq_event.c.
References db, GNUNET_DB_EventHandler::db, GNUNET_assert, GNUNET_CONTAINER_multishortmap_get(), 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.
char * GNUNET_PQ_get_event_notify_channel | ( | const struct GNUNET_DB_EventHeaderP * | es | ) |
Compute the channel that one should notify upon for the given event specification.
es | event specification |
Definition at line 522 of file pq_event.c.
References end, GNUNET_PQ_Context::es, es_to_channel(), GNUNET_assert, and GNUNET_strdup.
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.
db | database context to use |
es | specification of the event to generate |
extra | additional event data provided |
extra_size | number of bytes in extra |
Definition at line 537 of file pq_event.c.
References db, end, GNUNET_PQ_Context::es, es_to_channel(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_log_from, GNUNET_PQ_event_do_poll(), GNUNET_STRINGS_data_to_string(), and result.