192 unsigned int cnt = 0;
195 "PG poll job active\n");
197 PQconsumeInput (
db->conn))
200 "Failed to read from Postgres: %s\n",
201 PQerrorMessage (
db->conn));
202 if (CONNECTION_BAD != PQstatus (
db->conn))
207 while (NULL != (n = PQnotifies (
db->conn)))
215 if (
'X' != toupper ((
int) n->relname[0]))
218 "Ignoring notification for unsupported channel identifier `%s'\n",
228 "Ignoring notification for unsupported channel identifier `%s'\n",
233 if ( (NULL != n->extra) &&
241 "Ignoring notification for unsupported extra data `%s' on channel `%s'\n",
248 "Received notification %s with extra data `%.*s'\n",
250 (
int)
ctx.extra_size,
251 (
const char *)
ctx.extra);
260 "PG poll job finishes after %u events\n",
276 db->event_task = NULL;
280 if (NULL !=
db->event_task)
286 db->resubscribe_backoff
289 db->resubscribe_backoff
319 "New poll FD is %d\n",
321 if (NULL !=
db->event_task)
324 db->event_task = NULL;
332 "Activating poll job on %d\n",
359 if (NULL ==
db->conn)
366 "Executing PQ command `%s'\n",
370 if (PGRES_COMMAND_OK != PQresultStatus (
result))
374 "Failed to execute `%s': %s/%s/%s/%s/%s",
376 PQresultErrorField (
result,
377 PG_DIAG_MESSAGE_PRIMARY),
378 PQresultErrorField (
result,
379 PG_DIAG_MESSAGE_DETAIL),
380 PQresultErrorMessage (
result),
381 PQresStatus (PQresultStatus (
result)),
382 PQerrorMessage (
db->conn));
416 "Change in PQ event FD to %d\n",
468 if (NULL ==
db->event_task)
471 "Starting event scheduler\n");
473 PQsocket (
db->conn));
504 "Stopping PQ event scheduler job\n");
506 if (NULL !=
db->event_task)
509 db->event_task = NULL;
524 char sql[16 + 64 + 8];
542 char sql[16 + 64 + extra_size * 8 / 5 + 8];
555 sizeof (sql) - (
end - sql) - 1);
561 "Executing command `%s'\n",
565 if (PGRES_COMMAND_OK != PQresultStatus (
result))
569 "Failed to execute `%s': %s/%s/%s/%s/%s",
571 PQresultErrorField (
result,
572 PG_DIAG_MESSAGE_PRIMARY),
573 PQresultErrorField (
result,
574 PG_DIAG_MESSAGE_DETAIL),
575 PQresultErrorMessage (
result),
576 PQresStatus (PQresultStatus (
result)),
577 PQerrorMessage (
db->conn));
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
static int end
Set if we are to shutdown all services (including ARM).
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
static char * value
Value of the record to add/remove.
static int result
Global testing status.
static struct GNUNET_FS_DirectoryBuilder * db
void(* GNUNET_DB_EventCallback)(void *cls, const void *extra, size_t extra_size)
Function called on events received from Postgres.
void GNUNET_PQ_reconnect(struct GNUNET_PQ_Context *db)
Reinitialize the database db.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
enum GNUNET_GenericReturnValue 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.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
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.
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_static_assert(cond)
Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime an...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_box_native(int fd)
Box a native socket (and check that it is a socket).
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...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
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.
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.
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.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the maximum of two relative time values.
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
shared internal data structures of libgnunetpq
void GNUNET_PQ_event_do_poll(struct GNUNET_PQ_Context *db)
Poll for events right now.
static enum GNUNET_GenericReturnValue channel_to_sh(const char *identifier, struct GNUNET_ShortHashCode *sh)
Convert sh to a Postgres identifier.
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.
static void es_to_sh(const struct GNUNET_DB_EventHeaderP *es, struct GNUNET_ShortHashCode *sh)
Convert es to a short hash.
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.
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.
static void event_timeout(void *cls)
Function run on timeout for an event.
static enum GNUNET_GenericReturnValue register_notify(void *cls, const struct GNUNET_ShortHashCode *sh, void *value)
Re-subscribe to notifications after disconnect.
static char * sh_to_channel(struct GNUNET_ShortHashCode *sh, char identifier[64])
Convert sh to a Postgres identifier.
void GNUNET_PQ_event_reconnect_(struct GNUNET_PQ_Context *db, int fd)
Internal API.
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.
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.
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.
static void do_scheduler_notify(void *cls)
The GNUnet scheduler notifies us that we need to trigger the DB event poller.
void GNUNET_PQ_event_listen_cancel(struct GNUNET_DB_EventHandler *eh)
Stop notifications.
static char * es_to_channel(const struct GNUNET_DB_EventHeaderP *es, char identifier[64])
Convert es to a Postgres identifier.
Handle for an active LISTENer to the database.
void * cb_cls
Closure for cb.
struct GNUNET_SCHEDULER_Task * timeout_task
Task to run on timeout.
struct GNUNET_ShortHashCode sh
Channel name.
struct GNUNET_PQ_Context * db
Database context this event handler is with.
GNUNET_DB_EventCallback cb
Function to call on events.
Handle to Postgres database.
struct GNUNET_PQ_ExecuteStatement * es
Statements to execute upon connection.
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.
void * extra
Extra argument of the notification, or NULL.
size_t extra_size
Number of bytes in extra.