GNUnet  0.11.x
Macros | Typedefs | Functions
Data Store service

Data store for files stored on a GNUnet node. More...

Macros

#define GNUNET_DATASTORE_MAX_VALUE_SIZE   65536
 Maximum size of a value that can be stored in the datastore. More...
 

Typedefs

typedef void(* GNUNET_DATASTORE_ContinuationWithStatus) (void *cls, int32_t success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
 Continuation called to notify client about result of the operation. More...
 
typedef void(* GNUNET_DATASTORE_DatumProcessor) (void *cls, 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, uint64_t uid)
 Process a datum that was stored in the datastore. More...
 

Functions

struct GNUNET_DATASTORE_HandleGNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Connect to the datastore service. More...
 
void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, int drop)
 Disconnect from the datastore service (and free associated resources). 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_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_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_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...
 
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_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...
 
void GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe)
 Cancel a datastore operation. More...
 

Detailed Description

Data store for files stored on a GNUnet node.

Provides an API that can be used manage the datastore for files stored on a GNUnet node. Note that the datastore is NOT responsible for on-demand encoding, that is achieved using a special kind of entry.

Macro Definition Documentation

◆ GNUNET_DATASTORE_MAX_VALUE_SIZE

#define GNUNET_DATASTORE_MAX_VALUE_SIZE   65536

Maximum size of a value that can be stored in the datastore.

Definition at line 66 of file gnunet_datastore_service.h.

Typedef Documentation

◆ GNUNET_DATASTORE_ContinuationWithStatus

typedef void(* GNUNET_DATASTORE_ContinuationWithStatus) (void *cls, int32_t success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)

Continuation called to notify client about result of the operation.

Parameters
clsclosure
successGNUNET_SYSERR on failure GNUNET_NO if content was already there GNUNET_YES (or other positive value) on success
min_expirationminimum expiration time required for 0-priority content to be stored by the datacache at this time, zero for unknown, forever if we have no space for 0-priority content
msgNULL on success, otherwise an error message

Definition at line 104 of file gnunet_datastore_service.h.

◆ GNUNET_DATASTORE_DatumProcessor

typedef void(* GNUNET_DATASTORE_DatumProcessor) (void *cls, 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, uint64_t uid)

Process a datum that was stored in the datastore.

Parameters
clsclosure
keykey for the content
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationhow often should the content be replicated to other peers?
expirationexpiration time for the content
uidunique identifier for the datum; maybe 0 if no unique identifier is available

Definition at line 250 of file gnunet_datastore_service.h.

Function Documentation

◆ GNUNET_DATASTORE_connect()

struct GNUNET_DATASTORE_Handle* GNUNET_DATASTORE_connect ( const struct GNUNET_CONFIGURATION_Handle cfg)

Connect to the datastore service.

Parameters
cfgconfiguration to use
Returns
handle to use to access the service

Definition at line 371 of file datastore_api.c.

References cfg, GNUNET_DATASTORE_Handle::cfg, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_new, GNUNET_STATISTICS_create(), h, LOG, GNUNET_DATASTORE_Handle::mq, GNUNET_DATASTORE_Handle::stats, and try_reconnect().

Referenced by deserialize_publish_file(), GNUNET_FS_publish_ksk(), GNUNET_FS_publish_sks(), GNUNET_FS_publish_start(), GNUNET_FS_unindex_do_remove_(), GNUNET_FS_unindex_do_remove_kblocks_(), and run().

372 {
373  struct GNUNET_DATASTORE_Handle *h;
374 
376  "Establishing DATASTORE connection!\n");
377  h = GNUNET_new (struct GNUNET_DATASTORE_Handle);
378  h->cfg = cfg;
379  try_reconnect (h);
380  if (NULL == h->mq)
381  {
382  GNUNET_free (h);
383  return NULL;
384  }
385  h->stats = GNUNET_STATISTICS_create ("datastore-api",
386  cfg);
387  return h;
388 }
struct GNUNET_MQ_Handle * mq
Current connection to the datastore service.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static void try_reconnect(void *cls)
Try reconnecting to the datastore service.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define LOG(kind,...)
Definition: datastore_api.c:34
Handle to the datastore service.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATASTORE_disconnect()

void GNUNET_DATASTORE_disconnect ( struct GNUNET_DATASTORE_Handle h,
int  drop 
)

Disconnect from the datastore service (and free associated resources).

Parameters
hhandle to the datastore
dropset to GNUNET_YES to delete all data in datastore (!)

Definition at line 436 of file datastore_api.c.

References _, GNUNET_DATASTORE_Handle::cfg, StatusContext::cont, StatusContext::cont_cls, disconnect_after_drop(), disconnect_on_mq_error(), env, free_queue_entry(), GNUNET_assert, GNUNET_break, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_MESSAGE_TYPE_DATASTORE_DROP, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_MQ_destroy(), GNUNET_MQ_msg, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_YES, LOG, GNUNET_DATASTORE_Handle::mq, ResultContext::proc, ResultContext::proc_cls, GNUNET_DATASTORE_QueueEntry::qc, qe, GNUNET_DATASTORE_Handle::queue_head, QueueContext::rc, GNUNET_DATASTORE_Handle::reconnect_task, GNUNET_DATASTORE_QueueEntry::response_type, QueueContext::sc, and GNUNET_DATASTORE_Handle::stats.

Referenced by disconnect_after_drop(), disconnect_on_mq_error(), do_shutdown(), GNUNET_FS_publish_ksk_cancel(), GNUNET_FS_publish_sks_cancel(), GNUNET_FS_unindex_do_remove_(), GNUNET_FS_unindex_signal_suspend_(), GNUNET_FS_unindex_stop(), publish_cleanup(), shutdown_task(), suspend_operation(), and unindex_finish().

438 {
440 
442  "Datastore disconnect\n");
443  if (NULL != h->mq)
444  {
445  GNUNET_MQ_destroy (h->mq);
446  h->mq = NULL;
447  }
448  if (NULL != h->reconnect_task)
449  {
451  h->reconnect_task = NULL;
452  }
453  while (NULL != (qe = h->queue_head))
454  {
455  switch (qe->response_type)
456  {
458  if (NULL != qe->qc.sc.cont)
459  qe->qc.sc.cont (qe->qc.sc.cont_cls,
462  _ ("Disconnected from DATASTORE"));
463  break;
464 
466  if (NULL != qe->qc.rc.proc)
467  qe->qc.rc.proc (qe->qc.rc.proc_cls,
468  NULL,
469  0,
470  NULL,
471  0,
472  0,
473  0,
474  0,
476  0);
477  break;
478 
479  default:
480  GNUNET_break (0);
481  }
482  free_queue_entry (qe);
483  }
484  if (GNUNET_YES == drop)
485  {
487  "Re-connecting to issue DROP!\n");
488  GNUNET_assert (NULL == h->mq);
489  h->mq = GNUNET_CLIENT_connect (h->cfg,
490  "datastore",
491  NULL,
493  h);
494  if (NULL != h->mq)
495  {
496  struct GNUNET_MessageHeader *hdr;
497  struct GNUNET_MQ_Envelope *env;
498 
499  env = GNUNET_MQ_msg (hdr,
503  h);
504  GNUNET_MQ_send (h->mq,
505  env);
506  return;
507  }
508  GNUNET_break (0);
509  }
511  GNUNET_NO);
512  h->stats = NULL;
513  GNUNET_free (h);
514 }
#define GNUNET_MESSAGE_TYPE_DATASTORE_STATUS
Message sent by datastore to client informing about status processing a request (in response to RESER...
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
struct GNUNET_MQ_Handle * mq
Current connection to the datastore service.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
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
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * proc_cls
Closure for proc.
Definition: datastore_api.c:81
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for trying to reconnect.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct StatusContext sc
Definition: datastore_api.c:90
GNUNET_DATASTORE_DatumProcessor proc
Function to call with the result.
Definition: datastore_api.c:76
struct ResultContext rc
Definition: datastore_api.c:92
static void free_queue_entry(struct GNUNET_DATASTORE_QueueEntry *qe)
Free a queue entry.
Entry in our priority queue.
Definition: datastore_api.c:99
#define GNUNET_MESSAGE_TYPE_DATASTORE_DROP
Message sent by datastore client to drop the database.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
GNUNET_DATASTORE_ContinuationWithStatus cont
Continuation to call with the status.
Definition: datastore_api.c:59
static void disconnect_after_drop(void *cls)
Task used by to disconnect from the datastore after we send the GNUNET_MESSAGE_TYPE_DATASTORE_DROP me...
#define LOG(kind,...)
Definition: datastore_api.c:34
union QueueContext qc
Context for the operation.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void disconnect_on_mq_error(void *cls, enum GNUNET_MQ_Error error)
Handle error in sending drop request to datastore.
struct GNUNET_DATASTORE_QueueEntry * queue_head
Current head of priority queue.
uint16_t response_type
Expected response type.
Header for all communications.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:77
void * cont_cls
Closure for cont.
Definition: datastore_api.c:64
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:353
#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_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATASTORE_reserve()

struct GNUNET_DATASTORE_QueueEntry* GNUNET_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.

This function should be used to avoid "out of space" failures during a longer sequence of "put" operations (for example, when a file is being inserted).

Parameters
hhandle to the datastore
amounthow much space (in bytes) should be reserved (for content only)
entrieshow many entries will be created (to calculate per-entry overhead)
contcontinuation to call when done; "success" will be set to a positive reservation value if space could be reserved.
cont_clsclosure for cont
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel; note that even if NULL is returned, the callback will be invoked (or rather, will already have been invoked)

Definition at line 1056 of file datastore_api.c.

References ReserveMessage::amount, StatusContext::cont, StatusContext::cont_cls, drop_status_cont(), ReserveMessage::entries, env, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_htonll(), GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_MQ_msg, GNUNET_NO, GNUNET_STATISTICS_update(), LOG, make_queue_entry(), process_queue(), qe, QueueContext::sc, and GNUNET_DATASTORE_Handle::stats.

Referenced by GNUNET_FS_publish_start().

1061 {
1063  struct GNUNET_MQ_Envelope *env;
1064  struct ReserveMessage *rm;
1065  union QueueContext qc;
1066 
1067  if (NULL == cont)
1068  cont = &drop_status_cont;
1070  "Asked to reserve %llu bytes of data and %u entries\n",
1071  (unsigned long long) amount,
1072  (unsigned int) entries);
1073  env = GNUNET_MQ_msg (rm,
1075  rm->entries = htonl (entries);
1076  rm->amount = GNUNET_htonll (amount);
1077 
1078  qc.sc.cont = cont;
1079  qc.sc.cont_cls = cont_cls;
1080  qe = make_queue_entry (h,
1081  env,
1082  UINT_MAX,
1083  UINT_MAX,
1085  &qc);
1086  if (NULL == qe)
1087  {
1089  "Could not create queue entry to reserve\n");
1090  return NULL;
1091  }
1093  gettext_noop ("# RESERVE requests executed"),
1094  1,
1095  GNUNET_NO);
1096  process_queue (h);
1097  return qe;
1098 }
#define GNUNET_MESSAGE_TYPE_DATASTORE_STATUS
Message sent by datastore to client informing about status processing a request (in response to RESER...
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
uint32_t entries
Number of items to reserve.
Definition: datastore.h:49
Message from datastore service informing client about the current size of the datastore.
Definition: datastore.h:39
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE
Message sent by datastore client on join.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
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).
Entry in our priority queue.
Definition: datastore_api.c:99
struct ListEntry * entries
List of peers in the list.
#define LOG(kind,...)
Definition: datastore_api.c:34
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)
Create a new entry for our priority queue (and possibly discard other entires if the queue is getting...
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
Context for a queue operation.
Definition: datastore_api.c:88
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define gettext_noop(String)
Definition: gettext.h:69
uint64_t amount
Number of bytes to reserve.
Definition: datastore.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATASTORE_put()

struct GNUNET_DATASTORE_QueueEntry* GNUNET_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.

If the item is already present, the priorities and replication values are summed up and the higher expiration time and lower anonymity level is used.

Parameters
hhandle to the datastore
ridreservation ID to use (from "reserve"); use 0 if no prior reservation was made
keykey for the value
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationhow often should the content be replicated to other peers?
expirationexpiration time for the content
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
contcontinuation to call when done
cont_clsclosure for cont
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel; note that even if NULL is returned, the callback will be invoked (or rather, will already have been invoked)

If the item is already present, the priorities are summed up and the higher expiration time and lower anonymity level is used.

Parameters
hhandle to the datastore
ridreservation ID to use (from "reserve"); use 0 if no prior reservation was made
keykey for the value
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationhow often should the content be replicated to other peers?
expirationexpiration time for the content
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
contcontinuation to call when done
cont_clsclosure for cont
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel; note that even if NULL is returned, the callback will be invoked (or rather, will already have been invoked)

Definition at line 970 of file datastore_api.c.

References DataMessage::anonymity, StatusContext::cont, StatusContext::cont_cls, env, DataMessage::expiration, gettext_noop, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DATASTORE_PUT, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_MQ_msg_extra, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_hton(), GNUNET_YES, key, DataMessage::key, LOG, make_queue_entry(), DataMessage::priority, process_queue(), qe, DataMessage::replication, DataMessage::rid, QueueContext::sc, DataMessage::size, GNUNET_DATASTORE_Handle::stats, and DataMessage::type.

Referenced by block_proc(), GNUNET_FS_publish_ublock_(), handle_dht_reply(), handle_p2p_put(), and put_cb().

984 {
986  struct GNUNET_MQ_Envelope *env;
987  struct DataMessage *dm;
988  union QueueContext qc;
989 
990  if (size + sizeof(*dm) >= GNUNET_MAX_MESSAGE_SIZE)
991  {
992  GNUNET_break (0);
993  return NULL;
994  }
995 
997  "Asked to put %u bytes of data under key `%s' for %s\n",
998  size,
999  GNUNET_h2s (key),
1002  GNUNET_YES));
1003  env = GNUNET_MQ_msg_extra (dm,
1004  size,
1006  dm->rid = htonl (rid);
1007  dm->size = htonl ((uint32_t) size);
1008  dm->type = htonl (type);
1009  dm->priority = htonl (priority);
1010  dm->anonymity = htonl (anonymity);
1011  dm->replication = htonl (replication);
1012  dm->expiration = GNUNET_TIME_absolute_hton (expiration);
1013  dm->key = *key;
1014  GNUNET_memcpy (&dm[1],
1015  data,
1016  size);
1017  qc.sc.cont = cont;
1018  qc.sc.cont_cls = cont_cls;
1019  qe = make_queue_entry (h,
1020  env,
1021  queue_priority,
1022  max_queue_size,
1024  &qc);
1025  if (NULL == qe)
1026  {
1028  "Could not create queue entry for PUT\n");
1029  return NULL;
1030  }
1032  gettext_noop ("# PUT requests executed"),
1033  1,
1034  GNUNET_NO);
1035  process_queue (h);
1036  return qe;
1037 }
#define GNUNET_MESSAGE_TYPE_DATASTORE_STATUS
Message sent by datastore to client informing about status processing a request (in response to RESER...
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
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
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
static unsigned int replication
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_MESSAGE_TYPE_DATASTORE_PUT
Message sent by datastore client to store data.
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_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
Entry in our priority queue.
Definition: datastore_api.c:99
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:687
#define LOG(kind,...)
Definition: datastore_api.c:34
uint32_t replication
Desired replication level.
Definition: datastore.h:229
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)
Create a new entry for our priority queue (and possibly discard other entires if the queue is getting...
uint32_t rid
Reservation ID to use; use zero for none.
Definition: datastore.h:204
Message transmitting content from or to the datastore service.
Definition: datastore.h:191
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Context for a queue operation.
Definition: datastore_api.c:88
uint32_t size
Number of bytes in the item (NBO).
Definition: datastore.h:209
uint32_t anonymity
Desired anonymity level (NBO), zero for remove.
Definition: datastore.h:224
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_HashCode key
Key under which the item can be found.
Definition: datastore.h:252
uint32_t priority
Priority of the item (NBO), zero for remove.
Definition: datastore.h:219
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:77
static unsigned int anonymity
uint32_t data
The data value.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATASTORE_release_reserve()

struct GNUNET_DATASTORE_QueueEntry* GNUNET_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.

Parameters
hhandle to the datastore
ridreservation ID (value of "success" in original continuation from the "reserve" function).
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
contcontinuation to call when done
cont_clsclosure for cont
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel; note that even if NULL is returned, the callback will be invoked (or rather, will already have been invoked)

Definition at line 1122 of file datastore_api.c.

References StatusContext::cont, StatusContext::cont_cls, drop_status_cont(), env, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_MQ_msg, GNUNET_NO, GNUNET_STATISTICS_update(), LOG, make_queue_entry(), process_queue(), qe, ReleaseReserveMessage::rid, QueueContext::sc, and GNUNET_DATASTORE_Handle::stats.

Referenced by publish_sblocks_cont().

1128 {
1130  struct GNUNET_MQ_Envelope *env;
1131  struct ReleaseReserveMessage *rrm;
1132  union QueueContext qc;
1133 
1134  if (NULL == cont)
1135  cont = &drop_status_cont;
1137  "Asked to release reserve %d\n",
1138  rid);
1139  env = GNUNET_MQ_msg (rrm,
1141  rrm->rid = htonl (rid);
1142  qc.sc.cont = cont;
1143  qc.sc.cont_cls = cont_cls;
1144  qe = make_queue_entry (h,
1145  env,
1146  queue_priority,
1147  max_queue_size,
1149  &qc);
1150  if (NULL == qe)
1151  {
1153  "Could not create queue entry to release reserve\n");
1154  return NULL;
1155  }
1157  gettext_noop
1158  ("# RELEASE RESERVE requests executed"), 1,
1159  GNUNET_NO);
1160  process_queue (h);
1161  return qe;
1162 }
#define GNUNET_MESSAGE_TYPE_DATASTORE_STATUS
Message sent by datastore to client informing about status processing a request (in response to RESER...
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
Message from datastore client informing service that the remainder of the reserved bytes can now be r...
Definition: datastore.h:89
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
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).
#define GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE
Message sent by datastore client on join.
Entry in our priority queue.
Definition: datastore_api.c:99
#define LOG(kind,...)
Definition: datastore_api.c:34
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)
Create a new entry for our priority queue (and possibly discard other entires if the queue is getting...
Context for a queue operation.
Definition: datastore_api.c:88
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
int32_t rid
Reservation id.
Definition: datastore.h:99
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATASTORE_remove()

struct GNUNET_DATASTORE_QueueEntry* GNUNET_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.

cont will be called with status GNUNET_OK if content was removed, GNUNET_NO if no matching entry was found and GNUNET_SYSERR on all other types of errors.

Parameters
hhandle to the datastore
keykey for the value
sizenumber of bytes in data
datacontent stored
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
contcontinuation to call when done
cont_clsclosure for cont
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel; note that even if NULL is returned, the callback will be invoked (or rather, will already have been invoked)

The cont continuation will be called with status GNUNET_OK" if content was removed, GNUNET_NO if no matching entry was found and GNUNET_SYSERR on all other types of errors.

Parameters
hhandle to the datastore
keykey for the value
sizenumber of bytes in data
datacontent stored
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
contcontinuation to call when done
cont_clsclosure for cont
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel; note that even if NULL is returned, the callback will be invoked (or rather, will already have been invoked)

Definition at line 1186 of file datastore_api.c.

References StatusContext::cont, StatusContext::cont_cls, drop_status_cont(), env, gettext_noop, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_MQ_msg_extra, GNUNET_NO, GNUNET_STATISTICS_update(), key, DataMessage::key, LOG, make_queue_entry(), process_queue(), qe, QueueContext::sc, DataMessage::size, and GNUNET_DATASTORE_Handle::stats.

Referenced by GNUNET_FS_handle_on_demand_block(), process_kblock_for_unindex(), process_local_reply(), and unindex_process().

1194 {
1196  struct DataMessage *dm;
1197  struct GNUNET_MQ_Envelope *env;
1198  union QueueContext qc;
1199 
1200  if (sizeof(*dm) + size >= GNUNET_MAX_MESSAGE_SIZE)
1201  {
1202  GNUNET_break (0);
1203  return NULL;
1204  }
1205  if (NULL == cont)
1206  cont = &drop_status_cont;
1208  "Asked to remove %u bytes under key `%s'\n",
1209  size,
1210  GNUNET_h2s (key));
1211  env = GNUNET_MQ_msg_extra (dm,
1212  size,
1214  dm->size = htonl (size);
1215  dm->key = *key;
1216  GNUNET_memcpy (&dm[1],
1217  data,
1218  size);
1219 
1220  qc.sc.cont = cont;
1221  qc.sc.cont_cls = cont_cls;
1222 
1223  qe = make_queue_entry (h,
1224  env,
1225  queue_priority,
1226  max_queue_size,
1228  &qc);
1229  if (NULL == qe)
1230  {
1232  "Could not create queue entry for REMOVE\n");
1233  return NULL;
1234  }
1236  gettext_noop ("# REMOVE requests executed"),
1237  1,
1238  GNUNET_NO);
1239  process_queue (h);
1240  return qe;
1241 }
#define GNUNET_MESSAGE_TYPE_DATASTORE_STATUS
Message sent by datastore to client informing about status processing a request (in response to RESER...
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
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).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
Entry in our priority queue.
Definition: datastore_api.c:99
#define LOG(kind,...)
Definition: datastore_api.c:34
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)
Create a new entry for our priority queue (and possibly discard other entires if the queue is getting...
Message transmitting content from or to the datastore service.
Definition: datastore.h:191
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Context for a queue operation.
Definition: datastore_api.c:88
uint32_t size
Number of bytes in the item (NBO).
Definition: datastore.h:209
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_HashCode key
Key under which the item can be found.
Definition: datastore.h:252
#define GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE
Message sent by datastore client to remove data.
uint32_t data
The data value.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATASTORE_get_key()

struct GNUNET_DATASTORE_QueueEntry* GNUNET_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.

The processor will only be called once.

Parameters
hhandle to the datastore
next_uidreturn the result with lowest uid >= next_uid
randomif true, return a random result instead of using next_uid
keymaybe NULL (to match all entries)
typedesired type, 0 for any
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
procfunction to call on a matching value; or with a NULL value if no datum matches
proc_clsclosure for proc
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel

The processor will only be called once.

Parameters
hhandle to the datastore
next_uidreturn the result with lowest uid >= next_uid
randomif true, return a random result instead of using next_uid
keymaybe NULL (to match all entries)
typedesired type, 0 for any
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
procfunction to call on each matching value; will be called once with a NULL value at the end
proc_clsclosure for proc
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel

Definition at line 1383 of file datastore_api.c.

References env, gettext_noop, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_htonll(), GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_MESSAGE_TYPE_DATASTORE_GET, GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, GNUNET_MQ_msg, GNUNET_NO, GNUNET_STATISTICS_update(), key, GetKeyMessage::key, LOG, make_queue_entry(), GetKeyMessage::next_uid, GetMessage::next_uid, ResultContext::proc, ResultContext::proc_cls, process_queue(), qe, GetKeyMessage::random, GetMessage::random, QueueContext::rc, GNUNET_DATASTORE_Handle::stats, GetKeyMessage::type, and GetMessage::type.

Referenced by do_get(), GNUNET_FS_unindex_do_remove_kblocks_(), handle_request(), process_kblock_for_unindex(), and start_local_query().

1392 {
1394  struct GNUNET_MQ_Envelope *env;
1395  struct GetKeyMessage *gkm;
1396  struct GetMessage *gm;
1397  union QueueContext qc;
1398 
1399  GNUNET_assert (NULL != proc);
1401  "Asked to look for data of type %u under key `%s'\n",
1402  (unsigned int) type,
1403  GNUNET_h2s (key));
1404  if (NULL == key)
1405  {
1406  env = GNUNET_MQ_msg (gm,
1408  gm->type = htonl (type);
1409  gm->next_uid = GNUNET_htonll (next_uid);
1410  gm->random = random;
1411  }
1412  else
1413  {
1414  env = GNUNET_MQ_msg (gkm,
1416  gkm->type = htonl (type);
1417  gkm->next_uid = GNUNET_htonll (next_uid);
1418  gkm->random = random;
1419  gkm->key = *key;
1420  }
1421  qc.rc.proc = proc;
1422  qc.rc.proc_cls = proc_cls;
1423  qe = make_queue_entry (h,
1424  env,
1425  queue_priority,
1426  max_queue_size,
1428  &qc);
1429  if (NULL == qe)
1430  {
1432  "Could not queue request for `%s'\n",
1433  GNUNET_h2s (key));
1434  return NULL;
1435  }
1436 #if INSANE_STATISTICS
1438  gettext_noop ("# GET requests executed"),
1439  1,
1440  GNUNET_NO);
1441 #endif
1442  process_queue (h);
1443  return qe;
1444 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
uint32_t random
If true return a random result.
Definition: datastore.h:127
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t random
If true return a random result.
Definition: datastore.h:160
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Message to the datastore service asking about specific content.
Definition: datastore.h:107
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
uint64_t next_uid
UID at which to start the search.
Definition: datastore.h:155
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
Entry in our priority queue.
Definition: datastore_api.c:99
Message to the datastore service asking about specific content.
Definition: datastore.h:140
uint32_t type
Desired content type.
Definition: datastore.h:117
uint32_t type
Desired content type.
Definition: datastore.h:150
#define LOG(kind,...)
Definition: datastore_api.c:34
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)
Create a new entry for our priority queue (and possibly discard other entires if the queue is getting...
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
struct GNUNET_HashCode key
Desired key.
Definition: datastore.h:132
struct GNUNET_HashCode key
The key used in the DHT.
Context for a queue operation.
Definition: datastore_api.c:88
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY
Message sent by datastore client to get data by key.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint64_t next_uid
UID at which to start the search.
Definition: datastore.h:122
#define GNUNET_MESSAGE_TYPE_DATASTORE_GET
Message sent by datastore client to get 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 gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATASTORE_get_zero_anonymity()

struct GNUNET_DATASTORE_QueueEntry* GNUNET_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.

Parameters
hhandle to the datastore
next_uidreturn the result with lowest uid >= next_uid
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
typeallowed type for the operation (never zero)
procfunction to call on a random value; it will be called once with a value (if available) or with NULL if none value exists.
proc_clsclosure for proc
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel
Parameters
hhandle to the datastore
next_uidreturn the result with lowest uid >= next_uid
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
typeallowed type for the operation (never zero)
procfunction to call on a random value; it will be called once with a value (if available) or with NULL if none value exists.
proc_clsclosure for proc
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel

Definition at line 1319 of file datastore_api.c.

References env, gettext_noop, GNUNET_assert, GNUNET_BLOCK_TYPE_ANY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_htonll(), GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, GNUNET_MQ_msg, GNUNET_NO, GNUNET_STATISTICS_update(), LOG, m, make_queue_entry(), GetZeroAnonymityMessage::next_uid, ResultContext::proc, ResultContext::proc_cls, process_queue(), qe, QueueContext::rc, GNUNET_DATASTORE_Handle::stats, and GetZeroAnonymityMessage::type.

Referenced by gather_dht_put_blocks().

1326 {
1328  struct GNUNET_MQ_Envelope *env;
1329  struct GetZeroAnonymityMessage *m;
1330  union QueueContext qc;
1331 
1332  GNUNET_assert (NULL != proc);
1335  "Asked to get a zero-anonymity entry of type %d\n",
1336  type);
1337  env = GNUNET_MQ_msg (m,
1339  m->type = htonl ((uint32_t) type);
1340  m->next_uid = GNUNET_htonll (next_uid);
1341  qc.rc.proc = proc;
1342  qc.rc.proc_cls = proc_cls;
1343  qe = make_queue_entry (h,
1344  env,
1345  queue_priority,
1346  max_queue_size,
1348  &qc);
1349  if (NULL == qe)
1350  {
1352  "Could not create queue entry for zero-anonymity procation\n");
1353  return NULL;
1354  }
1356  gettext_noop
1357  ("# GET ZERO ANONYMITY requests executed"), 1,
1358  GNUNET_NO);
1359  process_queue (h);
1360  return qe;
1361 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
uint32_t type
Desired content type (actually an enum GNUNET_BLOCK_Type)
Definition: datastore.h:178
Any type of block, used as a wildcard when searching.
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:78
Message to the datastore service asking about zero anonymity content.
Definition: datastore.h:168
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
Entry in our priority queue.
Definition: datastore_api.c:99
#define LOG(kind,...)
Definition: datastore_api.c:34
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)
Create a new entry for our priority queue (and possibly discard other entires if the queue is getting...
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
Context for a queue operation.
Definition: datastore_api.c:88
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
uint64_t next_uid
UID at which to start the search.
Definition: datastore.h:183
#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY
Message sent by datastore client to get random data.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA
Message sent by datastore to client providing requested data (in response to GET or GET_RANDOM reques...
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATASTORE_get_for_replication()

struct GNUNET_DATASTORE_QueueEntry* GNUNET_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.

Returns a single, random value among those with the highest replication score, lowering positive replication scores by one for the chosen value (if only content with a replication score exists, a random value is returned and replication scores are not changed).

Parameters
hhandle to the datastore
queue_priorityranking of this request in the priority queue
max_queue_sizeat what queue size should this request be dropped (if other requests of higher priority are in the queue)
procfunction to call on a random value; it will be called once with a value (if available) and always once with a value of NULL.
proc_clsclosure for proc
Returns
NULL if the entry was not queued, otherwise a handle that can be used to cancel

Definition at line 1263 of file datastore_api.c.

References env, gettext_noop, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, GNUNET_MQ_msg, GNUNET_NO, GNUNET_STATISTICS_update(), LOG, m, make_queue_entry(), ResultContext::proc, ResultContext::proc_cls, process_queue(), qe, QueueContext::rc, and GNUNET_DATASTORE_Handle::stats.

Referenced by gather_migration_blocks().

1268 {
1270  struct GNUNET_MQ_Envelope *env;
1271  struct GNUNET_MessageHeader *m;
1272  union QueueContext qc;
1273 
1274  GNUNET_assert (NULL != proc);
1276  "Asked to get replication entry\n");
1277  env = GNUNET_MQ_msg (m,
1279  qc.rc.proc = proc;
1280  qc.rc.proc_cls = proc_cls;
1281  qe = make_queue_entry (h,
1282  env,
1283  queue_priority,
1284  max_queue_size,
1286  &qc);
1287  if (NULL == qe)
1288  {
1290  "Could not create queue entry for GET REPLICATION\n");
1291  return NULL;
1292  }
1294  gettext_noop
1295  ("# GET REPLICATION requests executed"), 1,
1296  GNUNET_NO);
1297  process_queue (h);
1298  return qe;
1299 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION
Message sent by datastore client to get random data.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
Entry in our priority queue.
Definition: datastore_api.c:99
#define LOG(kind,...)
Definition: datastore_api.c:34
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)
Create a new entry for our priority queue (and possibly discard other entires if the queue is getting...
Context for a queue operation.
Definition: datastore_api.c:88
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Header for all communications.
#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA
Message sent by datastore to client providing requested data (in response to GET or GET_RANDOM reques...
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATASTORE_cancel()

void GNUNET_DATASTORE_cancel ( struct GNUNET_DATASTORE_QueueEntry qe)

Cancel a datastore operation.

The final callback from the operation must not have been done yet.

Parameters
qeoperation to cancel

Definition at line 1454 of file datastore_api.c.

References GNUNET_DATASTORE_QueueEntry::env, free_queue_entry(), GNUNET_ERROR_TYPE_DEBUG, h, GNUNET_DATASTORE_QueueEntry::h, LOG, process_queue(), GNUNET_DATASTORE_Handle::queue_head, and GNUNET_DATASTORE_Handle::skip_next_messages.

Referenced by clean_request(), disconnect_cb(), do_shutdown(), GNUNET_FS_publish_stop(), GNUNET_FS_publish_ublock_cancel_(), GNUNET_FS_unindex_signal_suspend_(), GNUNET_FS_unindex_stop(), GSF_pending_request_cancel_(), GSF_push_done_(), GSF_put_done_(), and suspend_operation().

1455 {
1456  struct GNUNET_DATASTORE_Handle *h = qe->h;
1457 
1459  "Pending DATASTORE request %p cancelled (%d, %d)\n",
1460  qe,
1461  NULL == qe->env,
1462  h->queue_head == qe);
1463  if (NULL == qe->env)
1464  {
1465  free_queue_entry (qe);
1466  h->skip_next_messages++;
1467  return;
1468  }
1469  free_queue_entry (qe);
1470  process_queue (h);
1471 }
struct GNUNET_DATASTORE_Handle * h
Handle to the master context.
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
struct GNUNET_MQ_Envelope * env
Envelope of the request to transmit, NULL after transmission.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static void free_queue_entry(struct GNUNET_DATASTORE_QueueEntry *qe)
Free a queue entry.
unsigned int skip_next_messages
We should ignore the next message(s) from the service.
#define LOG(kind,...)
Definition: datastore_api.c:34
Handle to the datastore service.
struct GNUNET_DATASTORE_QueueEntry * queue_head
Current head of priority queue.
Here is the call graph for this function:
Here is the caller graph for this function: