GNUnet  0.20.0
datastore_api.c File Reference

Management for the datastore for files stored on a GNUnet node. More...

Include dependency graph for datastore_api.c:

Go to the source code of this file.

Data Structures

struct  StatusContext
 Context for processing status messages. More...
 
struct  ResultContext
 Context for processing result messages. More...
 
union  QueueContext
 Context for a queue operation. More...
 
struct  GNUNET_DATASTORE_QueueEntry
 Entry in our priority queue. More...
 
struct  GNUNET_DATASTORE_Handle
 Handle to the datastore service. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "datastore-api", __VA_ARGS__)
 
#define DELAY_WARN_TIMEOUT   GNUNET_TIME_UNIT_MINUTES
 
#define INSANE_STATISTICS   GNUNET_NO
 Collect an instance number of statistics? May cause excessive IPC. More...
 
#define MAX_EXCESS_RESULTS   8
 If a client stopped asking for more results, how many more do we receive from the DB before killing the connection? Trade-off between re-doing TCP handshakes and (needlessly) receiving useless results. More...
 

Functions

static void try_reconnect (void *cls)
 Try reconnecting to the datastore service. More...
 
static void do_disconnect (struct GNUNET_DATASTORE_Handle *h)
 Disconnect from the service and then try reconnecting to the datastore service after some delay. More...
 
static void free_queue_entry (struct GNUNET_DATASTORE_QueueEntry *qe)
 Free a queue entry. More...
 
static void delay_warning (void *cls)
 Task that logs an error after some time. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Handle error in sending drop request to datastore. More...
 
struct GNUNET_DATASTORE_HandleGNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Connect to the datastore service. More...
 
static void disconnect_after_drop (void *cls)
 Task used by to disconnect from the datastore after we send the GNUNET_MESSAGE_TYPE_DATASTORE_DROP message. More...
 
static void disconnect_on_mq_error (void *cls, enum GNUNET_MQ_Error error)
 Handle error in sending drop request to datastore. More...
 
void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, int drop)
 Disconnect from the datastore service (and free associated resources). More...
 
static struct GNUNET_DATASTORE_QueueEntrymake_queue_entry (struct GNUNET_DATASTORE_Handle *h, struct GNUNET_MQ_Envelope *env, unsigned int queue_priority, unsigned int max_queue_size, uint16_t expected_type, const union QueueContext *qc)
 Create a new entry for our priority queue (and possibly discard other entries if the queue is getting too long). More...
 
static void process_queue (struct GNUNET_DATASTORE_Handle *h)
 Process entries in the queue (or do nothing if we are already doing so). More...
 
static struct GNUNET_DATASTORE_QueueEntryget_queue_head (struct GNUNET_DATASTORE_Handle *h, uint16_t response_type)
 Get the entry at the head of the message queue. More...
 
static int check_status (void *cls, const struct StatusMessage *sm)
 Function called to check status message from the service. More...
 
static void handle_status (void *cls, const struct StatusMessage *sm)
 Function called to handle status message from the service. More...
 
static int check_data (void *cls, const struct DataMessage *dm)
 Check data message we received from the service. More...
 
static void handle_data (void *cls, const struct DataMessage *dm)
 Handle data message we got from the service. More...
 
static void handle_data_end (void *cls, const struct GNUNET_MessageHeader *msg)
 Type of a function to call when we receive a GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END message from the service. More...
 
static void drop_status_cont (void *cls, int32_t result, struct GNUNET_TIME_Absolute min_expiration, const char *emsg)
 Dummy continuation used to do nothing (but be non-zero). More...
 
struct GNUNET_DATASTORE_QueueEntryGNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, uint32_t rid, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
 Store an item in the datastore. More...
 
struct GNUNET_DATASTORE_QueueEntryGNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, uint64_t amount, uint32_t entries, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
 Reserve space in the datastore. More...
 
struct GNUNET_DATASTORE_QueueEntryGNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, uint32_t rid, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
 Signal that all of the data for which a reservation was made has been stored and that whatever excess space might have been reserved can now be released. More...
 
struct GNUNET_DATASTORE_QueueEntryGNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, const struct GNUNET_HashCode *key, size_t size, const void *data, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
 Explicitly remove some content from the database. More...
 
struct GNUNET_DATASTORE_QueueEntryGNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
 Get a random value from the datastore for content replication. More...
 
struct GNUNET_DATASTORE_QueueEntryGNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, uint64_t next_uid, unsigned int queue_priority, unsigned int max_queue_size, enum GNUNET_BLOCK_Type type, GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
 Get a single zero-anonymity value from the datastore. More...
 
struct GNUNET_DATASTORE_QueueEntryGNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
 Get a result for a particular key from the datastore. More...
 
void GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe)
 Cancel a datastore operation. More...
 

Detailed Description

Management for the datastore for files stored on a GNUnet node.

Implements a priority queue for requests

Author
Christian Grothoff

Definition in file datastore_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "datastore-api", __VA_ARGS__)

Definition at line 34 of file datastore_api.c.

◆ DELAY_WARN_TIMEOUT

#define DELAY_WARN_TIMEOUT   GNUNET_TIME_UNIT_MINUTES

Definition at line 36 of file datastore_api.c.

◆ INSANE_STATISTICS

#define INSANE_STATISTICS   GNUNET_NO

Collect an instance number of statistics? May cause excessive IPC.

Definition at line 41 of file datastore_api.c.

◆ MAX_EXCESS_RESULTS

#define MAX_EXCESS_RESULTS   8

If a client stopped asking for more results, how many more do we receive from the DB before killing the connection? Trade-off between re-doing TCP handshakes and (needlessly) receiving useless results.

Definition at line 49 of file datastore_api.c.

Function Documentation

◆ try_reconnect()

static void try_reconnect ( void *  cls)
static

Try reconnecting to the datastore service.

Parameters
clsthe struct GNUNET_DATASTORE_Handle

Definition at line 886 of file datastore_api.c.

887 {
888  struct GNUNET_DATASTORE_Handle *h = cls;
892  struct StatusMessage,
893  h),
896  struct DataMessage,
897  h),
898  GNUNET_MQ_hd_fixed_size (data_end,
900  struct GNUNET_MessageHeader,
901  h),
903  };
904 
905  h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time);
906  h->reconnect_task = NULL;
907  GNUNET_assert (NULL == h->mq);
909  "datastore",
910  handlers,
912  h);
913  if (NULL == h->mq)
914  return;
915  GNUNET_STATISTICS_update (h->stats,
916  gettext_noop (
917  "# datastore connections (re)created"),
918  1,
919  GNUNET_NO);
921  "Reconnected to DATASTORE\n");
922  process_queue (h);
923 }
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Handle error in sending drop request to datastore.
#define LOG(kind,...)
Definition: datastore_api.c:34
#define gettext_noop(String)
Definition: gettext.h:70
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
uint32_t data
The data value.
uint16_t status
See PRISM_STATUS_*-constants.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END
Message sent by datastore to client signaling end of matching data.
#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA
Message sent by datastore to client providing requested data (in response to GET or GET_RANDOM reques...
#define GNUNET_MESSAGE_TYPE_DATASTORE_STATUS
Message sent by datastore to client informing about status processing a request (in response to RESER...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Message transmitting content from or to the datastore service.
Definition: datastore.h:192
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
Handle to the datastore service.
Message handler for a specific message type.
Header for all communications.
Message from datastore service informing client about the success or failure of a requested operation...
Definition: datastore.h:65

References GNUNET_ARM_Handle::cfg, data, gettext_noop, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_STD_BACKOFF, h, handlers, LOG, GNUNET_ARM_Handle::mq, mq_error_handler(), process_queue(), GNUNET_ARM_Handle::reconnect_task, and status.

Referenced by do_disconnect(), and GNUNET_DATASTORE_connect().

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

◆ do_disconnect()

static void do_disconnect ( struct GNUNET_DATASTORE_Handle h)
static

Disconnect from the service and then try reconnecting to the datastore service after some delay.

Parameters
hhandle to datastore to disconnect and reconnect

Definition at line 237 of file datastore_api.c.

238 {
239  if (NULL == h->mq)
240  {
241  GNUNET_break (0);
242  return;
243  }
245  h->mq = NULL;
246  h->skip_next_messages = 0;
248  = GNUNET_SCHEDULER_add_delayed (h->retry_time,
249  &try_reconnect,
250  h);
251 }
static void try_reconnect(void *cls)
Try reconnecting to the datastore service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
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:1272

References GNUNET_break, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), h, GNUNET_ARM_Handle::mq, GNUNET_ARM_Handle::reconnect_task, and try_reconnect().

Referenced by get_queue_head(), and mq_error_handler().

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

◆ free_queue_entry()

static void free_queue_entry ( struct GNUNET_DATASTORE_QueueEntry qe)
static

Free a queue entry.

Removes the given entry from the queue and releases associated resources. Does NOT call the callback.

Parameters
qeentry to free.

Definition at line 262 of file datastore_api.c.

263 {
264  struct GNUNET_DATASTORE_Handle *h = qe->h;
265 
266  GNUNET_CONTAINER_DLL_remove (h->queue_head,
267  h->queue_tail,
268  qe);
269  h->queue_size--;
270  if (NULL != qe->env)
272  if (NULL != qe->delay_warn_task)
274  GNUNET_free (qe);
275 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct GNUNET_DATASTORE_Handle * h
Handle to the master context.
struct GNUNET_MQ_Envelope * env
Envelope of the request to transmit, NULL after transmission.
struct GNUNET_SCHEDULER_Task * delay_warn_task
Task we run if this entry stalls the queue and we need to warn the user.

References GNUNET_DATASTORE_QueueEntry::delay_warn_task, GNUNET_DATASTORE_QueueEntry::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_discard(), GNUNET_SCHEDULER_cancel(), h, GNUNET_DATASTORE_QueueEntry::h, and qe.

Referenced by GNUNET_DATASTORE_cancel(), GNUNET_DATASTORE_disconnect(), handle_data(), handle_data_end(), handle_status(), and mq_error_handler().

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

◆ delay_warning()

static void delay_warning ( void *  cls)
static

Task that logs an error after some time.

Parameters
clsstruct GNUNET_DATASTORE_QueueEntry about which the error is

Definition at line 284 of file datastore_api.c.

285 {
286  struct GNUNET_DATASTORE_QueueEntry *qe = cls;
287 
288  qe->delay_warn_task = NULL;
290  "Request %p of type %u at head of datastore queue for more than %s\n",
291  qe,
292  (unsigned int) qe->response_type,
294  GNUNET_YES));
296  &delay_warning,
297  qe);
298 }
#define DELAY_WARN_TIMEOUT
Definition: datastore_api.c:36
static void delay_warning(void *cls)
Task that logs an error after some time.
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_ERROR
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:569
Entry in our priority queue.
uint16_t response_type
Expected response type.

References GNUNET_DATASTORE_QueueEntry::delay_warn_task, DELAY_WARN_TIMEOUT, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, qe, and GNUNET_DATASTORE_QueueEntry::response_type.

Referenced by process_queue().

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

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Handle error in sending drop request to datastore.

Parameters
clsclosure with the datastore handle
errorerror code

Definition at line 308 of file datastore_api.c.

310 {
311  struct GNUNET_DATASTORE_Handle *h = cls;
313 
315  "MQ error, reconnecting to DATASTORE\n");
316  do_disconnect (h);
317  qe = h->queue_head;
318  if (NULL == qe)
319  return;
320  if (NULL != qe->delay_warn_task)
321  {
323  qe->delay_warn_task = NULL;
324  }
325  if (NULL == qe->env)
326  {
327  union QueueContext qc = qe->qc;
328  uint16_t rt = qe->response_type;
329 
331  "Failed to receive response from database.\n");
333  switch (rt)
334  {
336  if (NULL != qc.sc.cont)
337  qc.sc.cont (qc.sc.cont_cls,
340  _ ("DATASTORE disconnected"));
341  break;
342 
344  if (NULL != qc.rc.proc)
345  qc.rc.proc (qc.rc.proc_cls,
346  NULL,
347  0,
348  NULL,
349  0,
350  0,
351  0,
352  0,
354  0);
355  break;
356 
357  default:
358  GNUNET_break (0);
359  }
360  }
361 }
static void do_disconnect(struct GNUNET_DATASTORE_Handle *h)
Disconnect from the service and then try reconnecting to the datastore service after some delay.
static void free_queue_entry(struct GNUNET_DATASTORE_QueueEntry *qe)
Free a queue entry.
@ GNUNET_SYSERR
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
union QueueContext qc
Context for the operation.
GNUNET_DATASTORE_DatumProcessor proc
Function to call with the result.
Definition: datastore_api.c:76
void * proc_cls
Closure for proc.
Definition: datastore_api.c:81
void * cont_cls
Closure for cont.
Definition: datastore_api.c:64
GNUNET_DATASTORE_ContinuationWithStatus cont
Continuation to call with the status.
Definition: datastore_api.c:59
Context for a queue operation.
Definition: datastore_api.c:89
struct ResultContext rc
Definition: datastore_api.c:92
struct StatusContext sc
Definition: datastore_api.c:90

References _, StatusContext::cont, StatusContext::cont_cls, GNUNET_DATASTORE_QueueEntry::delay_warn_task, do_disconnect(), GNUNET_DATASTORE_QueueEntry::env, free_queue_entry(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, h, LOG, ResultContext::proc, ResultContext::proc_cls, GNUNET_DATASTORE_QueueEntry::qc, qe, QueueContext::rc, GNUNET_DATASTORE_QueueEntry::response_type, and QueueContext::sc.

Referenced by try_reconnect().

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

◆ disconnect_after_drop()

static void disconnect_after_drop ( void *  cls)
static

Task used by to disconnect from the datastore after we send the GNUNET_MESSAGE_TYPE_DATASTORE_DROP message.

Parameters
clsthe datastore handle

Definition at line 398 of file datastore_api.c.

399 {
400  struct GNUNET_DATASTORE_Handle *h = cls;
401 
403  "Drop sent, disconnecting\n");
405  GNUNET_NO);
406 }
void GNUNET_DATASTORE_disconnect(struct GNUNET_DATASTORE_Handle *h, int drop)
Disconnect from the datastore service (and free associated resources).

References GNUNET_DATASTORE_disconnect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, h, and LOG.

Referenced by GNUNET_DATASTORE_disconnect().

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

◆ disconnect_on_mq_error()

static void disconnect_on_mq_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Handle error in sending drop request to datastore.

Parameters
clsclosure with the datastore handle
errorerror code

Definition at line 416 of file datastore_api.c.

418 {
419  struct GNUNET_DATASTORE_Handle *h = cls;
420 
422  "Failed to ask datastore to drop tables\n");
424  GNUNET_NO);
425 }

References GNUNET_DATASTORE_disconnect(), GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, h, and LOG.

Referenced by GNUNET_DATASTORE_disconnect().

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

◆ make_queue_entry()

static struct GNUNET_DATASTORE_QueueEntry* make_queue_entry ( struct GNUNET_DATASTORE_Handle h,
struct GNUNET_MQ_Envelope env,
unsigned int  queue_priority,
unsigned int  max_queue_size,
uint16_t  expected_type,
const union QueueContext qc 
)
static

Create a new entry for our priority queue (and possibly discard other entries if the queue is getting too long).

Parameters
hhandle to the datastore
envenvelope with the message to queue
queue_prioritypriority of the entry
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
expected_typewhich type of response do we expect, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS or GNUNET_MESSAGE_TYPE_DATASTORE_DATA
qcclient context (NOT a closure for response_proc)
Returns
NULL if the queue is full

Definition at line 533 of file datastore_api.c.

539 {
541  struct GNUNET_DATASTORE_QueueEntry *pos;
542  unsigned int c;
543 
544  if ((NULL != h->queue_tail) &&
545  (h->queue_tail->priority >= queue_priority))
546  {
547  c = h->queue_size;
548  pos = NULL;
549  }
550  else
551  {
552  c = 0;
553  pos = h->queue_head;
554  }
555  while ((NULL != pos) &&
556  (c < max_queue_size) &&
557  (pos->priority >= queue_priority))
558  {
559  c++;
560  pos = pos->next;
561  }
562  if (c >= max_queue_size)
563  {
564  GNUNET_STATISTICS_update (h->stats,
565  gettext_noop ("# queue overflows"),
566  1,
567  GNUNET_NO);
569  return NULL;
570  }
572  qe->h = h;
573  qe->env = env;
574  qe->response_type = expected_type;
575  qe->qc = *qc;
576  qe->priority = queue_priority;
577  qe->max_queue = max_queue_size;
578  if (NULL == pos)
579  {
580  /* append at the tail */
581  pos = h->queue_tail;
582  }
583  else
584  {
585  pos = pos->prev;
586  /* do not insert at HEAD if HEAD query was already
587  * transmitted and we are still receiving replies! */
588  if ((NULL == pos) &&
589  (NULL == h->queue_head->env))
590  pos = h->queue_head;
591  }
592  c++;
593 #if INSANE_STATISTICS
594  GNUNET_STATISTICS_update (h->stats,
595  gettext_noop ("# queue entries created"),
596  1,
597  GNUNET_NO);
598 #endif
600  h->queue_tail,
601  pos,
602  qe);
603  h->queue_size++;
604  return qe;
605 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_DATASTORE_QueueEntry * prev
This is a linked list.
unsigned int priority
Priority in the queue.
unsigned int max_queue
Maximum allowed length of queue (otherwise this request should be discarded).
struct GNUNET_DATASTORE_QueueEntry * next
This is a linked list.

References env, GNUNET_DATASTORE_QueueEntry::env, gettext_noop, GNUNET_CONTAINER_DLL_insert_after, GNUNET_MQ_discard(), GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), h, GNUNET_DATASTORE_QueueEntry::h, GNUNET_DATASTORE_QueueEntry::max_queue, GNUNET_DATASTORE_QueueEntry::next, GNUNET_DATASTORE_QueueEntry::prev, GNUNET_DATASTORE_QueueEntry::priority, GNUNET_DATASTORE_QueueEntry::qc, qe, and GNUNET_DATASTORE_QueueEntry::response_type.

Referenced by GNUNET_DATASTORE_get_for_replication(), GNUNET_DATASTORE_get_key(), GNUNET_DATASTORE_get_zero_anonymity(), GNUNET_DATASTORE_put(), GNUNET_DATASTORE_release_reserve(), GNUNET_DATASTORE_remove(), and GNUNET_DATASTORE_reserve().

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

◆ process_queue()

static void process_queue ( struct GNUNET_DATASTORE_Handle h)
static

Process entries in the queue (or do nothing if we are already doing so).

Parameters
hhandle to the datastore

Definition at line 615 of file datastore_api.c.

616 {
618 
619  if (NULL == (qe = h->queue_head))
620  {
621  /* no entry in queue */
623  "Queue empty\n");
624  return;
625  }
626  if (NULL == qe->env)
627  {
628  /* waiting for replies */
630  "Head request already transmitted\n");
631  return;
632  }
633  if (NULL == h->mq)
634  {
635  /* waiting for reconnect */
637  "Not connected\n");
638  return;
639  }
640  GNUNET_assert (NULL == qe->delay_warn_task);
642  &delay_warning,
643  qe);
644  GNUNET_MQ_send (h->mq,
645  qe->env);
646  qe->env = NULL;
647 }
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304

References GNUNET_DATASTORE_QueueEntry::delay_warn_task, DELAY_WARN_TIMEOUT, delay_warning(), GNUNET_DATASTORE_QueueEntry::env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_send(), GNUNET_SCHEDULER_add_delayed(), h, LOG, GNUNET_ARM_Handle::mq, and qe.

Referenced by get_queue_head(), GNUNET_DATASTORE_cancel(), GNUNET_DATASTORE_get_for_replication(), GNUNET_DATASTORE_get_key(), GNUNET_DATASTORE_get_zero_anonymity(), GNUNET_DATASTORE_put(), GNUNET_DATASTORE_release_reserve(), GNUNET_DATASTORE_remove(), GNUNET_DATASTORE_reserve(), handle_data(), handle_data_end(), handle_status(), and try_reconnect().

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

◆ get_queue_head()

static struct GNUNET_DATASTORE_QueueEntry* get_queue_head ( struct GNUNET_DATASTORE_Handle h,
uint16_t  response_type 
)
static

Get the entry at the head of the message queue.

Parameters
hhandle to the datastore
response_typethe expected response type
Returns
the queue entry

Definition at line 658 of file datastore_api.c.

660 {
662 
663  if (h->skip_next_messages > 0)
664  {
665  h->skip_next_messages--;
666  process_queue (h);
667  return NULL;
668  }
669  qe = h->queue_head;
670  if (NULL == qe)
671  {
672  GNUNET_break (0);
673  do_disconnect (h);
674  return NULL;
675  }
676  if (NULL != qe->env)
677  {
678  GNUNET_break (0);
679  do_disconnect (h);
680  return NULL;
681  }
683  {
684  GNUNET_break (0);
685  do_disconnect (h);
686  return NULL;
687  }
688  return qe;
689 }

References do_disconnect(), GNUNET_DATASTORE_QueueEntry::env, GNUNET_break, h, process_queue(), qe, and GNUNET_DATASTORE_QueueEntry::response_type.

Referenced by handle_data(), handle_data_end(), and handle_status().

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

◆ check_status()

static int check_status ( void *  cls,
const struct StatusMessage sm 
)
static

Function called to check status message from the service.

Parameters
clsclosure
smstatus message received
Returns
GNUNET_OK if the message is well-formed

Definition at line 700 of file datastore_api.c.

702 {
703  uint16_t msize = ntohs (sm->header.size) - sizeof(*sm);
704  int32_t status = ntohl (sm->status);
705 
706  if (msize > 0)
707  {
708  const char *emsg = (const char *) &sm[1];
709 
710  if ('\0' != emsg[msize - 1])
711  {
712  GNUNET_break (0);
713  return GNUNET_SYSERR;
714  }
715  }
716  else if (GNUNET_SYSERR == status)
717  {
718  GNUNET_break (0);
719  return GNUNET_SYSERR;
720  }
721  return GNUNET_OK;
722 }
@ GNUNET_OK
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
int32_t status
Status code, -1 for errors.
Definition: datastore.h:74
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_DATASTORE_STATUS.
Definition: datastore.h:69

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, StatusMessage::header, GNUNET_MessageHeader::size, StatusMessage::status, and status.

◆ handle_status()

static void handle_status ( void *  cls,
const struct StatusMessage sm 
)
static

Function called to handle status message from the service.

Parameters
clsclosure
smstatus message received

Definition at line 732 of file datastore_api.c.

734 {
735  struct GNUNET_DATASTORE_Handle *h = cls;
737  struct StatusContext rc;
738  const char *emsg;
739  int32_t status = ntohl (sm->status);
740 
741  qe = get_queue_head (h,
743  if (NULL == qe)
744  return;
745  rc = qe->qc.sc;
747  if (ntohs (sm->header.size) > sizeof(struct StatusMessage))
748  emsg = (const char *) &sm[1];
749  else
750  emsg = NULL;
752  "Received status %d/%s\n",
753  (int) status,
754  emsg);
755  GNUNET_STATISTICS_update (h->stats,
756  gettext_noop ("# status messages received"),
757  1,
758  GNUNET_NO);
759  h->retry_time = GNUNET_TIME_UNIT_ZERO;
760  process_queue (h);
761  if (NULL != rc.cont)
762  rc.cont (rc.cont_cls,
763  status,
765  emsg);
766 }
static struct GNUNET_DATASTORE_QueueEntry * get_queue_head(struct GNUNET_DATASTORE_Handle *h, uint16_t response_type)
Get the entry at the head of the message queue.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Context for processing status messages.
Definition: datastore_api.c:55
struct GNUNET_TIME_AbsoluteNBO min_expiration
Minimum expiration time required for content to be stored by the datacache at this time,...
Definition: datastore.h:80

References StatusContext::cont, StatusContext::cont_cls, free_queue_entry(), get_queue_head(), gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_ZERO, h, StatusMessage::header, LOG, StatusMessage::min_expiration, process_queue(), GNUNET_DATASTORE_QueueEntry::qc, qe, QueueContext::sc, GNUNET_MessageHeader::size, StatusMessage::status, and status.

Here is the call graph for this function:

◆ check_data()

static int check_data ( void *  cls,
const struct DataMessage dm 
)
static

Check data message we received from the service.

Parameters
clsclosure with the struct GNUNET_DATASTORE_Handle *
dmmessage received

Definition at line 776 of file datastore_api.c.

778 {
779  uint16_t msize = ntohs (dm->header.size) - sizeof(*dm);
780 
781  if (msize != ntohl (dm->size))
782  {
783  GNUNET_break (0);
784  return GNUNET_SYSERR;
785  }
786  return GNUNET_OK;
787 }
struct GNUNET_MessageHeader header
Type is either GNUNET_MESSAGE_TYPE_DATASTORE_PUT, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE or GNUNET_MESS...
Definition: datastore.h:199
uint32_t size
Number of bytes in the item (NBO).
Definition: datastore.h:209

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, DataMessage::header, DataMessage::size, and GNUNET_MessageHeader::size.

◆ handle_data()

static void handle_data ( void *  cls,
const struct DataMessage dm 
)
static

Handle data message we got from the service.

Parameters
clsclosure with the struct GNUNET_DATASTORE_Handle *
dmmessage received

Definition at line 797 of file datastore_api.c.

799 {
800  struct GNUNET_DATASTORE_Handle *h = cls;
802  struct ResultContext rc;
803 
804  qe = get_queue_head (h,
806  if (NULL == qe)
807  return;
808 #if INSANE_STATISTICS
809  GNUNET_STATISTICS_update (h->stats,
810  gettext_noop ("# Results received"),
811  1,
812  GNUNET_NO);
813 #endif
815  "Received result %llu with type %u and size %u with key %s\n",
816  (unsigned long long) GNUNET_ntohll (dm->uid),
817  ntohl (dm->type),
818  ntohl (dm->size),
819  GNUNET_h2s (&dm->key));
820  rc = qe->qc.rc;
822  h->retry_time = GNUNET_TIME_UNIT_ZERO;
823  process_queue (h);
824  if (NULL != rc.proc)
825  rc.proc (rc.proc_cls,
826  &dm->key,
827  ntohl (dm->size),
828  &dm[1],
829  ntohl (dm->type),
830  ntohl (dm->priority),
831  ntohl (dm->anonymity),
832  ntohl (dm->replication),
834  GNUNET_ntohll (dm->uid));
835 }
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
uint32_t priority
Priority of the item (NBO), zero for remove.
Definition: datastore.h:219
struct GNUNET_HashCode key
Key under which the item can be found.
Definition: datastore.h:252
uint64_t uid
Unique ID for the content (can be used for UPDATE); can be zero for remove (which indicates that the ...
Definition: datastore.h:242
struct GNUNET_TIME_AbsoluteNBO expiration
Expiration time (NBO); zero for remove.
Definition: datastore.h:247
uint32_t type
Type of the item (NBO), zero for remove, (actually an enum GNUNET_BLOCK_Type)
Definition: datastore.h:214
uint32_t replication
Desired replication level.
Definition: datastore.h:229
uint32_t anonymity
Desired anonymity level (NBO), zero for remove.
Definition: datastore.h:224
Context for processing result messages.
Definition: datastore_api.c:72

References DataMessage::anonymity, DataMessage::expiration, free_queue_entry(), get_queue_head(), gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_NO, GNUNET_ntohll(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_ZERO, h, DataMessage::key, LOG, DataMessage::priority, ResultContext::proc, ResultContext::proc_cls, process_queue(), GNUNET_DATASTORE_QueueEntry::qc, qe, QueueContext::rc, DataMessage::replication, DataMessage::size, DataMessage::type, and DataMessage::uid.

Here is the call graph for this function:

◆ handle_data_end()

static void handle_data_end ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Type of a function to call when we receive a GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END message from the service.

Parameters
clsclosure with the struct GNUNET_DATASTORE_Handle *
msgmessage received

Definition at line 846 of file datastore_api.c.

848 {
849  struct GNUNET_DATASTORE_Handle *h = cls;
851  struct ResultContext rc;
852 
853  qe = get_queue_head (h,
855  if (NULL == qe)
856  return;
857  rc = qe->qc.rc;
860  "Received end of result set, new queue size is %u\n",
861  h->queue_size);
862  h->retry_time = GNUNET_TIME_UNIT_ZERO;
863  h->result_count = 0;
864  process_queue (h);
865  /* signal end of iteration */
866  if (NULL != rc.proc)
867  rc.proc (rc.proc_cls,
868  NULL,
869  0,
870  NULL,
871  0,
872  0,
873  0,
874  0,
876  0);
877 }

References free_queue_entry(), get_queue_head(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_UNIT_ZERO_ABS, h, LOG, ResultContext::proc, ResultContext::proc_cls, process_queue(), GNUNET_DATASTORE_QueueEntry::qc, qe, and QueueContext::rc.

Here is the call graph for this function:

◆ drop_status_cont()

static void drop_status_cont ( void *  cls,
int32_t  result,
struct GNUNET_TIME_Absolute  min_expiration,
const char *  emsg 
)
static

Dummy continuation used to do nothing (but be non-zero).

Parameters
clsclosure
resultresult
min_expirationexpiration time
emsgerror message

Definition at line 935 of file datastore_api.c.

939 {
940  /* do nothing */
941 }

Referenced by GNUNET_DATASTORE_release_reserve(), GNUNET_DATASTORE_remove(), and GNUNET_DATASTORE_reserve().

Here is the caller graph for this function: