Management for the datastore for files stored on a GNUnet node. More...
#include "platform.h"
#include "gnunet_arm_service.h"
#include "gnunet_constants.h"
#include "gnunet_datastore_service.h"
#include "gnunet_statistics_service.h"
#include "datastore.h"
Go to the source code of this file.
Data Structures | |
struct | StatusContext |
Context for processing status messages. More... | |
struct | ResultContext |
Context for processing result messages. More... | |
union | QueueContext |
Context for a queue operation. More... | |
struct | GNUNET_DATASTORE_QueueEntry |
Entry in our priority queue. More... | |
struct | GNUNET_DATASTORE_Handle |
Handle to the datastore service. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "datastore-api", __VA_ARGS__) |
#define | DELAY_WARN_TIMEOUT GNUNET_TIME_UNIT_MINUTES |
#define | INSANE_STATISTICS GNUNET_NO |
Collect an instance number of statistics? May cause excessive IPC. More... | |
#define | MAX_EXCESS_RESULTS 8 |
If a client stopped asking for more results, how many more do we receive from the DB before killing the connection? Trade-off between re-doing TCP handshakes and (needlessly) receiving useless results. More... | |
Functions | |
static void | try_reconnect (void *cls) |
Try reconnecting to the datastore service. More... | |
static void | do_disconnect (struct GNUNET_DATASTORE_Handle *h) |
Disconnect from the service and then try reconnecting to the datastore service after some delay. More... | |
static void | free_queue_entry (struct GNUNET_DATASTORE_QueueEntry *qe) |
Free a queue entry. More... | |
static void | delay_warning (void *cls) |
Task that logs an error after some time. More... | |
static void | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
Handle error in sending drop request to datastore. More... | |
struct GNUNET_DATASTORE_Handle * | GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
Connect to the datastore service. More... | |
static void | disconnect_after_drop (void *cls) |
Task used by to disconnect from the datastore after we send the GNUNET_MESSAGE_TYPE_DATASTORE_DROP message. More... | |
static void | disconnect_on_mq_error (void *cls, enum GNUNET_MQ_Error error) |
Handle error in sending drop request to datastore. More... | |
void | GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, int drop) |
Disconnect from the datastore service (and free associated resources). More... | |
static struct GNUNET_DATASTORE_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 too long). More... | |
static void | process_queue (struct GNUNET_DATASTORE_Handle *h) |
Process entries in the queue (or do nothing if we are already doing so). More... | |
static struct GNUNET_DATASTORE_QueueEntry * | get_queue_head (struct GNUNET_DATASTORE_Handle *h, uint16_t response_type) |
Get the entry at the head of the message queue. More... | |
static int | check_status (void *cls, const struct StatusMessage *sm) |
Function called to check status message from the service. More... | |
static void | handle_status (void *cls, const struct StatusMessage *sm) |
Function called to handle status message from the service. More... | |
static int | check_data (void *cls, const struct DataMessage *dm) |
Check data message we received from the service. More... | |
static void | handle_data (void *cls, const struct DataMessage *dm) |
Handle data message we got from the service. More... | |
static void | handle_data_end (void *cls, const struct GNUNET_MessageHeader *msg) |
Type of a function to call when we receive a GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END message from the service. More... | |
static void | drop_status_cont (void *cls, int32_t result, struct GNUNET_TIME_Absolute min_expiration, const char *emsg) |
Dummy continuation used to do nothing (but be non-zero). More... | |
struct GNUNET_DATASTORE_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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe) |
Cancel a datastore operation. More... | |
Management for the datastore for files stored on a GNUnet node.
Implements a priority queue for requests
Definition in file datastore_api.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "datastore-api", __VA_ARGS__) |
Definition at line 34 of file datastore_api.c.
#define DELAY_WARN_TIMEOUT GNUNET_TIME_UNIT_MINUTES |
Definition at line 36 of file datastore_api.c.
#define INSANE_STATISTICS GNUNET_NO |
Collect an instance number of statistics? May cause excessive IPC.
Definition at line 41 of file datastore_api.c.
#define MAX_EXCESS_RESULTS 8 |
If a client stopped asking for more results, how many more do we receive from the DB before killing the connection? Trade-off between re-doing TCP handshakes and (needlessly) receiving useless results.
Definition at line 49 of file datastore_api.c.
|
static |
Try reconnecting to the datastore service.
cls | the struct GNUNET_DATASTORE_Handle |
Definition at line 886 of file datastore_api.c.
References GNUNET_ARM_Handle::cfg, data, gettext_noop, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_STD_BACKOFF, h, handlers, LOG, GNUNET_ARM_Handle::mq, mq_error_handler(), process_queue(), GNUNET_ARM_Handle::reconnect_task, and status.
Referenced by do_disconnect(), and GNUNET_DATASTORE_connect().
|
static |
Disconnect from the service and then try reconnecting to the datastore service after some delay.
h | handle to datastore to disconnect and reconnect |
Definition at line 237 of file datastore_api.c.
References GNUNET_break, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), h, GNUNET_ARM_Handle::mq, GNUNET_ARM_Handle::reconnect_task, and try_reconnect().
Referenced by get_queue_head(), and mq_error_handler().
|
static |
Free a queue entry.
Removes the given entry from the queue and releases associated resources. Does NOT call the callback.
qe | entry to free. |
Definition at line 262 of file datastore_api.c.
References GNUNET_DATASTORE_QueueEntry::delay_warn_task, GNUNET_DATASTORE_QueueEntry::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_discard(), GNUNET_SCHEDULER_cancel(), h, GNUNET_DATASTORE_QueueEntry::h, and qe.
Referenced by GNUNET_DATASTORE_cancel(), GNUNET_DATASTORE_disconnect(), handle_data(), handle_data_end(), handle_status(), and mq_error_handler().
|
static |
Task that logs an error after some time.
cls | struct GNUNET_DATASTORE_QueueEntry about which the error is |
Definition at line 284 of file datastore_api.c.
References GNUNET_DATASTORE_QueueEntry::delay_warn_task, DELAY_WARN_TIMEOUT, delay_warning(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, qe, and GNUNET_DATASTORE_QueueEntry::response_type.
Referenced by delay_warning(), and process_queue().
|
static |
Handle error in sending drop request to datastore.
cls | closure with the datastore handle |
error | error code |
Definition at line 308 of file datastore_api.c.
References _, StatusContext::cont, StatusContext::cont_cls, GNUNET_DATASTORE_QueueEntry::delay_warn_task, do_disconnect(), GNUNET_DATASTORE_QueueEntry::env, free_queue_entry(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, h, LOG, ResultContext::proc, ResultContext::proc_cls, GNUNET_DATASTORE_QueueEntry::qc, qe, QueueContext::rc, GNUNET_DATASTORE_QueueEntry::response_type, and QueueContext::sc.
Referenced by try_reconnect().
|
static |
Task used by to disconnect from the datastore after we send the GNUNET_MESSAGE_TYPE_DATASTORE_DROP message.
cls | the datastore handle |
Definition at line 398 of file datastore_api.c.
References GNUNET_DATASTORE_disconnect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, h, and LOG.
Referenced by GNUNET_DATASTORE_disconnect().
|
static |
Handle error in sending drop request to datastore.
cls | closure with the datastore handle |
error | error code |
Definition at line 416 of file datastore_api.c.
References GNUNET_DATASTORE_disconnect(), GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, h, and LOG.
Referenced by GNUNET_DATASTORE_disconnect().
|
static |
Create a new entry for our priority queue (and possibly discard other entries if the queue is getting too long).
h | handle to the datastore |
env | envelope with the message to queue |
queue_priority | priority of the entry |
max_queue_size | at what queue size should this request be dropped (if other requests of higher priority are in the queue) |
expected_type | which type of response do we expect, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS or GNUNET_MESSAGE_TYPE_DATASTORE_DATA |
qc | client context (NOT a closure for response_proc) |
Definition at line 533 of file datastore_api.c.
References env, GNUNET_DATASTORE_QueueEntry::env, gettext_noop, GNUNET_CONTAINER_DLL_insert_after, GNUNET_MQ_discard(), GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), h, GNUNET_DATASTORE_QueueEntry::h, GNUNET_DATASTORE_QueueEntry::max_queue, GNUNET_DATASTORE_QueueEntry::next, GNUNET_DATASTORE_QueueEntry::prev, GNUNET_DATASTORE_QueueEntry::priority, GNUNET_DATASTORE_QueueEntry::qc, qe, and GNUNET_DATASTORE_QueueEntry::response_type.
Referenced by GNUNET_DATASTORE_get_for_replication(), GNUNET_DATASTORE_get_key(), GNUNET_DATASTORE_get_zero_anonymity(), GNUNET_DATASTORE_put(), GNUNET_DATASTORE_release_reserve(), GNUNET_DATASTORE_remove(), and GNUNET_DATASTORE_reserve().
|
static |
Process entries in the queue (or do nothing if we are already doing so).
h | handle to the datastore |
Definition at line 615 of file datastore_api.c.
References GNUNET_DATASTORE_QueueEntry::delay_warn_task, DELAY_WARN_TIMEOUT, delay_warning(), GNUNET_DATASTORE_QueueEntry::env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_send(), GNUNET_SCHEDULER_add_delayed(), h, LOG, GNUNET_ARM_Handle::mq, and qe.
Referenced by get_queue_head(), GNUNET_DATASTORE_cancel(), GNUNET_DATASTORE_get_for_replication(), GNUNET_DATASTORE_get_key(), GNUNET_DATASTORE_get_zero_anonymity(), GNUNET_DATASTORE_put(), GNUNET_DATASTORE_release_reserve(), GNUNET_DATASTORE_remove(), GNUNET_DATASTORE_reserve(), handle_data(), handle_data_end(), handle_status(), and try_reconnect().
|
static |
Get the entry at the head of the message queue.
h | handle to the datastore |
response_type | the expected response type |
Definition at line 658 of file datastore_api.c.
References do_disconnect(), GNUNET_DATASTORE_QueueEntry::env, GNUNET_break, h, process_queue(), qe, and GNUNET_DATASTORE_QueueEntry::response_type.
Referenced by handle_data(), handle_data_end(), and handle_status().
|
static |
Function called to check status message from the service.
cls | closure |
sm | status message received |
Definition at line 700 of file datastore_api.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, StatusMessage::header, GNUNET_MessageHeader::size, status, and StatusMessage::status.
|
static |
Function called to handle status message from the service.
cls | closure |
sm | status message received |
Definition at line 732 of file datastore_api.c.
References StatusContext::cont, StatusContext::cont_cls, free_queue_entry(), get_queue_head(), gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_ZERO, h, StatusMessage::header, LOG, StatusMessage::min_expiration, process_queue(), GNUNET_DATASTORE_QueueEntry::qc, qe, QueueContext::sc, GNUNET_MessageHeader::size, status, and StatusMessage::status.
|
static |
Check data message we received from the service.
cls | closure with the struct GNUNET_DATASTORE_Handle * |
dm | message received |
Definition at line 776 of file datastore_api.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, DataMessage::header, GNUNET_MessageHeader::size, and DataMessage::size.
|
static |
Handle data message we got from the service.
cls | closure with the struct GNUNET_DATASTORE_Handle * |
dm | message received |
Definition at line 797 of file datastore_api.c.
References DataMessage::anonymity, DataMessage::expiration, free_queue_entry(), get_queue_head(), gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_NO, GNUNET_ntohll(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_UNIT_ZERO, h, DataMessage::key, LOG, DataMessage::priority, ResultContext::proc, ResultContext::proc_cls, process_queue(), GNUNET_DATASTORE_QueueEntry::qc, qe, QueueContext::rc, DataMessage::replication, DataMessage::size, DataMessage::type, and DataMessage::uid.
|
static |
Type of a function to call when we receive a GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END message from the service.
cls | closure with the struct GNUNET_DATASTORE_Handle * |
msg | message received |
Definition at line 846 of file datastore_api.c.
References free_queue_entry(), get_queue_head(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_UNIT_ZERO_ABS, h, LOG, ResultContext::proc, ResultContext::proc_cls, process_queue(), GNUNET_DATASTORE_QueueEntry::qc, qe, and QueueContext::rc.
|
static |
Dummy continuation used to do nothing (but be non-zero).
cls | closure |
result | result |
min_expiration | expiration time |
emsg | error message |
Definition at line 935 of file datastore_api.c.
Referenced by GNUNET_DATASTORE_release_reserve(), GNUNET_DATASTORE_remove(), and GNUNET_DATASTORE_reserve().