34#define LOG(kind, ...) GNUNET_log_from (kind, "datastore-api", __VA_ARGS__)
36#define DELAY_WARN_TIMEOUT GNUNET_TIME_UNIT_MINUTES
41#define INSANE_STATISTICS GNUNET_NO
49#define MAX_EXCESS_RESULTS 8
246 h->skip_next_messages = 0;
290 "Request %p of type %u at head of datastore queue for more than %s\n",
315 "MQ error, reconnecting to DATASTORE\n");
331 "Failed to receive response from database.\n");
340 _ (
"DATASTORE disconnected"));
376 "Establishing DATASTORE connection!\n");
403 "Drop sent, disconnecting\n");
422 "Failed to ask datastore to drop tables\n");
442 "Datastore disconnect\n");
453 while (NULL != (
qe =
h->queue_head))
462 _ (
"Disconnected from DATASTORE"));
487 "Re-connecting to issue DROP!\n");
535 unsigned int queue_priority,
536 unsigned int max_queue_size,
537 uint16_t expected_type,
544 if ((NULL !=
h->queue_tail) &&
545 (
h->queue_tail->priority >= queue_priority))
555 while ((NULL != pos) &&
556 (c < max_queue_size) &&
562 if (c >= max_queue_size)
589 (NULL ==
h->queue_head->env))
619 if (NULL == (
qe =
h->queue_head))
630 "Head request already transmitted\n");
663 if (
h->skip_next_messages > 0)
665 h->skip_next_messages--;
703 uint16_t msize = ntohs (sm->
header.
size) -
sizeof(*sm);
708 const char *emsg = (
const char *) &sm[1];
710 if (
'\0' != emsg[msize - 1])
748 emsg = (
const char *) &sm[1];
752 "Received status %d/%s\n",
779 uint16_t msize = ntohs (dm->
header.
size) -
sizeof(*dm);
781 if (msize != ntohl (dm->
size))
815 "Received result %llu with type %u and size %u with key %s\n",
860 "Received end of result set, new queue size is %u\n",
917 "# datastore connections (re)created"),
921 "Reconnected to DATASTORE\n");
955 unsigned int queue_priority,
956 unsigned int max_queue_size,
972 "Asked to put %lu bytes of data under key `%s' for %s\n",
973 (
unsigned long)
size,
981 dm->
rid = htonl (rid);
1003 "Could not create queue entry for PUT\n");
1045 "Asked to reserve %llu bytes of data and %u entries\n",
1046 (
unsigned long long) amount,
1047 (
unsigned int) entries);
1050 rm->
entries = htonl (entries);
1064 "Could not create queue entry to reserve\n");
1079 unsigned int queue_priority,
1080 unsigned int max_queue_size,
1092 "Asked to release reserve %d\n",
1096 rrm->
rid = htonl (rid);
1108 "Could not create queue entry to release reserve\n");
1113 (
"# RELEASE RESERVE requests executed"), 1,
1125 unsigned int queue_priority,
1126 unsigned int max_queue_size,
1143 "Asked to remove %lu bytes under key `%s'\n",
1144 (
unsigned long)
size,
1167 "Could not create queue entry for REMOVE\n");
1199 unsigned int queue_priority,
1200 unsigned int max_queue_size,
1211 "Asked to get replication entry\n");
1225 "Could not create queue entry for GET REPLICATION\n");
1230 (
"# GET REPLICATION requests executed"), 1,
1240 unsigned int queue_priority,
1241 unsigned int max_queue_size,
1254 "Asked to get a zero-anonymity entry of type %d\n",
1258 m->type = htonl ((uint32_t)
type);
1271 "Could not create queue entry for zero-anonymity procation\n");
1276 (
"# GET ZERO ANONYMITY requests executed"), 1,
1307 unsigned int queue_priority,
1308 unsigned int max_queue_size,
1320 "Asked to look for data of type %u under key `%s'\n",
1321 (
unsigned int)
type,
1351 "Could not queue request for `%s'\n",
1355#if INSANE_STATISTICS
1378 "Pending DATASTORE request %p cancelled (%d, %d)\n",
1381 h->queue_head ==
qe);
1382 if (NULL ==
qe->
env)
1385 h->skip_next_messages++;
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
structs for communication between datastore service and API
static int check_status(void *cls, const struct StatusMessage *sm)
Function called to check status message from the service.
static void process_queue(struct GNUNET_DATASTORE_Handle *h)
Process entries in the queue (or do nothing if we are already doing so).
static void disconnect_after_drop(void *cls)
Task used by to disconnect from the datastore after we send the GNUNET_MESSAGE_TYPE_DATASTORE_DROP me...
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 entries if the queue is getting...
static void disconnect_on_mq_error(void *cls, enum GNUNET_MQ_Error error)
Handle error in sending drop request to datastore.
static void try_reconnect(void *cls)
Try reconnecting to the datastore service.
#define DELAY_WARN_TIMEOUT
static void delay_warning(void *cls)
Task that logs an error after some time.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Handle error in sending drop request to datastore.
static void do_disconnect(struct GNUNET_DATASTORE_Handle *h)
Disconnect from the service and then try reconnecting to the datastore service after some delay.
static void 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).
static void free_queue_entry(struct GNUNET_DATASTORE_QueueEntry *qe)
Free a queue entry.
static int check_data(void *cls, const struct DataMessage *dm)
Check data message we received from the service.
static void handle_status(void *cls, const struct StatusMessage *sm)
Function called to handle status message from the service.
static void handle_data_end(void *cls, const struct GNUNET_MessageHeader *msg)
Type of a function to call when we receive a GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END message from the ...
static void handle_data(void *cls, const struct DataMessage *dm)
Handle data message we got from the service.
static struct GNUNET_DATASTORE_QueueEntry * get_queue_head(struct GNUNET_DATASTORE_Handle *h, uint16_t response_type)
Get the entry at the head of the message queue.
#define gettext_noop(String)
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
static unsigned int replication
Desired replication level.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
static unsigned int anonymity
static uint32_t type
Type string converted to DNS type value.
static int status
The program status; 0 for success.
static int result
Global testing status.
static struct GNUNET_TIME_Absolute min_expiration
Minimum time that content should have to not be discarded instantly (time stamp of any content that w...
API to create, modify and access statistics.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
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.
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.
void GNUNET_DATASTORE_disconnect(struct GNUNET_DATASTORE_Handle *h, int drop)
Disconnect from the datastore service (and free associated resources).
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.
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
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.
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.
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...
struct GNUNET_DATASTORE_Handle * GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the datastore service.
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.
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.
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.
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.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
void * cls
Closure for mv and cb.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
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.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
#define GNUNET_MESSAGE_TYPE_DATASTORE_DROP
Message sent by datastore client to drop the database.
#define GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE
Message sent by datastore client on join.
#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END
Message sent by datastore to client signaling end of matching data.
#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY
Message sent by datastore client to get data by key.
#define GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE
Message sent by datastore client on join.
#define GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE
Message sent by datastore client to remove data.
#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 GNUNET_MESSAGE_TYPE_DATASTORE_PUT
Message sent by datastore client to store data.
#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION
Message sent by datastore client to get random data.
#define GNUNET_MESSAGE_TYPE_DATASTORE_STATUS
Message sent by datastore to client informing about status processing a request (in response to RESER...
#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY
Message sent by datastore client to get random data.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
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?
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static unsigned int size
Size of the "table".
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
Message transmitting content from or to the datastore service.
uint32_t priority
Priority of the item (NBO), zero for remove.
struct GNUNET_HashCode key
Key under which the item can be found.
uint64_t uid
Unique ID for the content (can be used for UPDATE); can be zero for remove (which indicates that the ...
struct GNUNET_TIME_AbsoluteNBO expiration
Expiration time (NBO); zero for remove.
struct GNUNET_MessageHeader header
Type is either GNUNET_MESSAGE_TYPE_DATASTORE_PUT, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE or GNUNET_MESS...
uint32_t type
Type of the item (NBO), zero for remove, (actually an enum GNUNET_BLOCK_Type)
uint32_t size
Number of bytes in the item (NBO).
uint32_t replication
Desired replication level.
uint32_t anonymity
Desired anonymity level (NBO), zero for remove.
uint32_t rid
Reservation ID to use; use zero for none.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Handle to the datastore service.
unsigned int queue_size
Number of entries in the queue.
unsigned int skip_next_messages
We should ignore the next message(s) from the service.
struct GNUNET_TIME_Relative retry_time
How quickly should we retry? Used for exponential back-off on connect-errors.
struct GNUNET_DATASTORE_QueueEntry * queue_head
Current head of priority queue.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for trying to reconnect.
unsigned int result_count
Number of results we're receiving for the current query after application stopped to care.
struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_MQ_Handle * mq
Current connection to the datastore service.
struct GNUNET_DATASTORE_QueueEntry * queue_tail
Current tail of priority queue.
Entry in our priority queue.
union QueueContext qc
Context for the operation.
struct GNUNET_DATASTORE_QueueEntry * prev
This is a linked list.
uint16_t response_type
Expected response type.
unsigned int priority
Priority in the queue.
struct GNUNET_DATASTORE_Handle * h
Handle to the master context.
unsigned int max_queue
Maximum allowed length of queue (otherwise this request should be discarded).
struct GNUNET_MQ_Envelope * env
Envelope of the request to transmit, NULL after transmission.
struct GNUNET_DATASTORE_QueueEntry * next
This is a linked list.
GNUNET_DATASTORE_ContinuationWithStatus cont
Function to call after transmission of the request.
void * cont_cls
Closure for cont.
struct GNUNET_SCHEDULER_Task * delay_warn_task
Task we run if this entry stalls the queue and we need to warn the user.
Handle to a message queue.
Message handler for a specific message type.
Entry in list of pending tasks.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Message to the datastore service asking about specific content.
uint32_t type
Desired content type.
uint64_t next_uid
UID at which to start the search.
struct GNUNET_HashCode key
Desired key.
uint32_t random
If true return a random result.
Message to the datastore service asking about specific content.
uint32_t random
If true return a random result.
uint32_t type
Desired content type.
uint64_t next_uid
UID at which to start the search.
Message to the datastore service asking about zero anonymity content.
Message from datastore client informing service that the remainder of the reserved bytes can now be r...
int32_t rid
Reservation id.
Message from datastore service informing client about the current size of the datastore.
uint32_t entries
Number of items to reserve.
uint64_t amount
Number of bytes to reserve.
Context for processing result messages.
GNUNET_DATASTORE_DatumProcessor proc
Function to call with the result.
void * proc_cls
Closure for proc.
Context for processing status messages.
void * cont_cls
Closure for cont.
GNUNET_DATASTORE_ContinuationWithStatus cont
Continuation to call with the status.
Message from datastore service informing client about the success or failure of a requested operation...
struct GNUNET_TIME_AbsoluteNBO min_expiration
Minimum expiration time required for content to be stored by the datacache at this time,...
int32_t status
Status code, -1 for errors.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_DATASTORE_STATUS.
Context for a queue operation.