GNUnet  0.10.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 249 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 366 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().

367 {
368  struct GNUNET_DATASTORE_Handle *h;
369 
371  "Establishing DATASTORE connection!\n");
373  h->cfg = cfg;
374  try_reconnect(h);
375  if (NULL == h->mq)
376  {
377  GNUNET_free(h);
378  return NULL;
379  }
380  h->stats = GNUNET_STATISTICS_create("datastore-api",
381  cfg);
382  return h;
383 }
struct GNUNET_MQ_Handle * mq
Current connection to the datastore service.
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:94
#define LOG(kind,...)
Definition: datastore_api.c:34
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
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 431 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().

433 {
435 
437  "Datastore disconnect\n");
438  if (NULL != h->mq)
439  {
440  GNUNET_MQ_destroy(h->mq);
441  h->mq = NULL;
442  }
443  if (NULL != h->reconnect_task)
444  {
446  h->reconnect_task = NULL;
447  }
448  while (NULL != (qe = h->queue_head))
449  {
450  switch (qe->response_type)
451  {
453  if (NULL != qe->qc.sc.cont)
454  qe->qc.sc.cont(qe->qc.sc.cont_cls,
457  _("Disconnected from DATASTORE"));
458  break;
459 
461  if (NULL != qe->qc.rc.proc)
462  qe->qc.rc.proc(qe->qc.rc.proc_cls,
463  NULL,
464  0,
465  NULL,
466  0,
467  0,
468  0,
469  0,
471  0);
472  break;
473 
474  default:
475  GNUNET_break(0);
476  }
477  free_queue_entry(qe);
478  }
479  if (GNUNET_YES == drop)
480  {
482  "Re-connecting to issue DROP!\n");
483  GNUNET_assert(NULL == h->mq);
484  h->mq = GNUNET_CLIENT_connect(h->cfg,
485  "datastore",
486  NULL,
488  h);
489  if (NULL != h->mq)
490  {
491  struct GNUNET_MessageHeader *hdr;
492  struct GNUNET_MQ_Envelope *env;
493 
494  env = GNUNET_MQ_msg(hdr,
498  h);
499  GNUNET_MQ_send(h->mq,
500  env);
501  return;
502  }
503  GNUNET_break(0);
504  }
506  GNUNET_NO);
507  h->stats = NULL;
508  GNUNET_free(h);
509 }
#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:900
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:79
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:87
GNUNET_DATASTORE_DatumProcessor proc
Function to call with the result.
Definition: datastore_api.c:74
struct ResultContext rc
Definition: datastore_api.c:89
static void free_queue_entry(struct GNUNET_DATASTORE_QueueEntry *qe)
Free a queue entry.
Entry in our priority queue.
Definition: datastore_api.c:96
#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:772
GNUNET_DATASTORE_ContinuationWithStatus cont
Continuation to call with the status.
Definition: datastore_api.c:58
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:821
#define GNUNET_YES
Definition: gnunet_common.h:77
void * cont_cls
Closure for cont.
Definition: datastore_api.c:63
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:351
#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:956
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 1049 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().

1054 {
1056  struct GNUNET_MQ_Envelope *env;
1057  struct ReserveMessage *rm;
1058  union QueueContext qc;
1059 
1060  if (NULL == cont)
1061  cont = &drop_status_cont;
1063  "Asked to reserve %llu bytes of data and %u entries\n",
1064  (unsigned long long)amount,
1065  (unsigned int)entries);
1066  env = GNUNET_MQ_msg(rm,
1068  rm->entries = htonl(entries);
1069  rm->amount = GNUNET_htonll(amount);
1070 
1071  qc.sc.cont = cont;
1072  qc.sc.cont_cls = cont_cls;
1073  qe = make_queue_entry(h,
1074  env,
1075  UINT_MAX,
1076  UINT_MAX,
1078  &qc);
1079  if (NULL == qe)
1080  {
1082  "Could not create queue entry to reserve\n");
1083  return NULL;
1084  }
1086  gettext_noop("# RESERVE requests executed"),
1087  1,
1088  GNUNET_NO);
1089  process_queue(h);
1090  return qe;
1091 }
#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:48
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:96
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:86
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:53
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 964 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().

978 {
980  struct GNUNET_MQ_Envelope *env;
981  struct DataMessage *dm;
982  union QueueContext qc;
983 
984  if (size + sizeof(*dm) >= GNUNET_MAX_MESSAGE_SIZE)
985  {
986  GNUNET_break(0);
987  return NULL;
988  }
989 
991  "Asked to put %u bytes of data under key `%s' for %s\n",
992  size,
993  GNUNET_h2s(key),
995  GNUNET_YES));
996  env = GNUNET_MQ_msg_extra(dm,
997  size,
999  dm->rid = htonl(rid);
1000  dm->size = htonl((uint32_t)size);
1001  dm->type = htonl(type);
1002  dm->priority = htonl(priority);
1003  dm->anonymity = htonl(anonymity);
1004  dm->replication = htonl(replication);
1005  dm->expiration = GNUNET_TIME_absolute_hton(expiration);
1006  dm->key = *key;
1007  GNUNET_memcpy(&dm[1],
1008  data,
1009  size);
1010  qc.sc.cont = cont;
1011  qc.sc.cont_cls = cont_cls;
1012  qe = make_queue_entry(h,
1013  env,
1014  queue_priority,
1015  max_queue_size,
1017  &qc);
1018  if (NULL == qe)
1019  {
1021  "Could not create queue entry for PUT\n");
1022  return NULL;
1023  }
1025  gettext_noop("# PUT requests executed"),
1026  1,
1027  GNUNET_NO);
1028  process_queue(h);
1029  return qe;
1030 }
#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:240
uint32_t type
Type of the item (NBO), zero for remove, (actually an enum GNUNET_BLOCK_Type)
Definition: datastore.h:207
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:96
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:686
#define LOG(kind,...)
Definition: datastore_api.c:34
uint32_t replication
Desired replication level.
Definition: datastore.h:222
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:197
Message transmitting content from or to the datastore service.
Definition: datastore.h:185
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:66
Context for a queue operation.
Definition: datastore_api.c:86
uint32_t size
Number of bytes in the item (NBO).
Definition: datastore.h:202
uint32_t anonymity
Desired anonymity level (NBO), zero for remove.
Definition: datastore.h:217
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:245
uint32_t priority
Priority of the item (NBO), zero for remove.
Definition: datastore.h:212
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:655
#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 1115 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().

1121 {
1123  struct GNUNET_MQ_Envelope *env;
1124  struct ReleaseReserveMessage *rrm;
1125  union QueueContext qc;
1126 
1127  if (NULL == cont)
1128  cont = &drop_status_cont;
1130  "Asked to release reserve %d\n",
1131  rid);
1132  env = GNUNET_MQ_msg(rrm,
1134  rrm->rid = htonl(rid);
1135  qc.sc.cont = cont;
1136  qc.sc.cont_cls = cont_cls;
1137  qe = make_queue_entry(h,
1138  env,
1139  queue_priority,
1140  max_queue_size,
1142  &qc);
1143  if (NULL == qe)
1144  {
1146  "Could not create queue entry to release reserve\n");
1147  return NULL;
1148  }
1150  gettext_noop
1151  ("# RELEASE RESERVE requests executed"), 1,
1152  GNUNET_NO);
1153  process_queue(h);
1154  return qe;
1155 }
#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:87
#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:96
#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:86
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
int32_t rid
Reservation id.
Definition: datastore.h:96
#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 1179 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().

1187 {
1189  struct DataMessage *dm;
1190  struct GNUNET_MQ_Envelope *env;
1191  union QueueContext qc;
1192 
1193  if (sizeof(*dm) + size >= GNUNET_MAX_MESSAGE_SIZE)
1194  {
1195  GNUNET_break(0);
1196  return NULL;
1197  }
1198  if (NULL == cont)
1199  cont = &drop_status_cont;
1201  "Asked to remove %u bytes under key `%s'\n",
1202  size,
1203  GNUNET_h2s(key));
1204  env = GNUNET_MQ_msg_extra(dm,
1205  size,
1207  dm->size = htonl(size);
1208  dm->key = *key;
1209  GNUNET_memcpy(&dm[1],
1210  data,
1211  size);
1212 
1213  qc.sc.cont = cont;
1214  qc.sc.cont_cls = cont_cls;
1215 
1216  qe = make_queue_entry(h,
1217  env,
1218  queue_priority,
1219  max_queue_size,
1221  &qc);
1222  if (NULL == qe)
1223  {
1225  "Could not create queue entry for REMOVE\n");
1226  return NULL;
1227  }
1229  gettext_noop("# REMOVE requests executed"),
1230  1,
1231  GNUNET_NO);
1232  process_queue(h);
1233  return qe;
1234 }
#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:96
#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:185
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:66
Context for a queue operation.
Definition: datastore_api.c:86
uint32_t size
Number of bytes in the item (NBO).
Definition: datastore.h:202
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:245
#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 1377 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().

1386 {
1388  struct GNUNET_MQ_Envelope *env;
1389  struct GetKeyMessage *gkm;
1390  struct GetMessage *gm;
1391  union QueueContext qc;
1392 
1393  GNUNET_assert(NULL != proc);
1395  "Asked to look for data of type %u under key `%s'\n",
1396  (unsigned int)type,
1397  GNUNET_h2s(key));
1398  if (NULL == key)
1399  {
1400  env = GNUNET_MQ_msg(gm,
1402  gm->type = htonl(type);
1403  gm->next_uid = GNUNET_htonll(next_uid);
1404  gm->random = random;
1405  }
1406  else
1407  {
1408  env = GNUNET_MQ_msg(gkm,
1410  gkm->type = htonl(type);
1411  gkm->next_uid = GNUNET_htonll(next_uid);
1412  gkm->random = random;
1413  gkm->key = *key;
1414  }
1415  qc.rc.proc = proc;
1416  qc.rc.proc_cls = proc_cls;
1417  qe = make_queue_entry(h,
1418  env,
1419  queue_priority,
1420  max_queue_size,
1422  &qc);
1423  if (NULL == qe)
1424  {
1426  "Could not queue request for `%s'\n",
1427  GNUNET_h2s(key));
1428  return NULL;
1429  }
1430 #if INSANE_STATISTICS
1432  gettext_noop("# GET requests executed"),
1433  1,
1434  GNUNET_NO);
1435 #endif
1436  process_queue(h);
1437  return qe;
1438 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
uint32_t random
If true return a random result.
Definition: datastore.h:123
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:155
#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:104
#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:150
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:96
Message to the datastore service asking about specific content.
Definition: datastore.h:136
uint32_t type
Desired content type.
Definition: datastore.h:113
uint32_t type
Desired content type.
Definition: datastore.h:145
#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:128
struct GNUNET_HashCode key
The key used in the DHT.
Context for a queue operation.
Definition: datastore_api.c:86
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:118
#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 1313 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().

1320 {
1322  struct GNUNET_MQ_Envelope *env;
1323  struct GetZeroAnonymityMessage *m;
1324  union QueueContext qc;
1325 
1326  GNUNET_assert(NULL != proc);
1329  "Asked to get a zero-anonymity entry of type %d\n",
1330  type);
1331  env = GNUNET_MQ_msg(m,
1333  m->type = htonl((uint32_t)type);
1334  m->next_uid = GNUNET_htonll(next_uid);
1335  qc.rc.proc = proc;
1336  qc.rc.proc_cls = proc_cls;
1337  qe = make_queue_entry(h,
1338  env,
1339  queue_priority,
1340  max_queue_size,
1342  &qc);
1343  if (NULL == qe)
1344  {
1346  "Could not create queue entry for zero-anonymity procation\n");
1347  return NULL;
1348  }
1350  gettext_noop
1351  ("# GET ZERO ANONYMITY requests executed"), 1,
1352  GNUNET_NO);
1353  process_queue(h);
1354  return qe;
1355 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
uint32_t type
Desired content type (actually an enum GNUNET_BLOCK_Type)
Definition: datastore.h:172
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:163
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:99
Entry in our priority queue.
Definition: datastore_api.c:96
#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:86
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
uint64_t next_uid
UID at which to start the search.
Definition: datastore.h:177
#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 1257 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().

1262 {
1264  struct GNUNET_MQ_Envelope *env;
1265  struct GNUNET_MessageHeader *m;
1266  union QueueContext qc;
1267 
1268  GNUNET_assert(NULL != proc);
1270  "Asked to get replication entry\n");
1271  env = GNUNET_MQ_msg(m,
1273  qc.rc.proc = proc;
1274  qc.rc.proc_cls = proc_cls;
1275  qe = make_queue_entry(h,
1276  env,
1277  queue_priority,
1278  max_queue_size,
1280  &qc);
1281  if (NULL == qe)
1282  {
1284  "Could not create queue entry for GET REPLICATION\n");
1285  return NULL;
1286  }
1288  gettext_noop
1289  ("# GET REPLICATION requests executed"), 1,
1290  GNUNET_NO);
1291  process_queue(h);
1292  return qe;
1293 }
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:99
Entry in our priority queue.
Definition: datastore_api.c:96
#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:86
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 1448 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().

1449 {
1450  struct GNUNET_DATASTORE_Handle *h = qe->h;
1451 
1453  "Pending DATASTORE request %p cancelled (%d, %d)\n",
1454  qe,
1455  NULL == qe->env,
1456  h->queue_head == qe);
1457  if (NULL == qe->env)
1458  {
1459  free_queue_entry(qe);
1460  h->skip_next_messages++;
1461  return;
1462  }
1463  free_queue_entry(qe);
1464  process_queue(h);
1465 }
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:94
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: