GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-service-datastore.c File Reference

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

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_statistics_service.h"
#include "gnunet_datastore_plugin.h"
#include "datastore.h"
Include dependency graph for gnunet-service-datastore.c:

Go to the source code of this file.

Data Structures

struct  DatastorePlugin
 Our datastore plugin. More...
 
struct  ReservationList
 Linked list of active reservations. More...
 

Macros

#define MAX_PENDING   1024
 How many messages do we queue at most per client? More...
 
#define MAX_BF_SIZE   ((uint32_t)(1LL << 31))
 Limit size of bloom filter to 2 GB. More...
 
#define MAX_EXPIRE_DELAY   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15)
 How long are we at most keeping "expired" content past the expiration date in the database? More...
 
#define MIN_EXPIRE_DELAY   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
 How fast are we allowed to query the database for deleting expired content? (1 item per second). More...
 
#define MAX_STAT_SYNC_LAG   50
 After how many payload-changing operations do we sync our statistics? More...
 

Functions

static void sync_stats ()
 Synchronize our utilization statistics with the statistics service. More...
 
static void delete_expired (void *cls)
 Task that is used to remove expired entries from the datastore. More...
 
static int expired_processor (void *cls, const struct GNUNET_HashCode *key, uint32_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)
 Iterate over the expired items stored in the datastore. More...
 
static int quota_processor (void *cls, const struct GNUNET_HashCode *key, uint32_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)
 An iterator over a set of items stored in the datastore that deletes until we're happy with respect to our quota. More...
 
static void manage_space (unsigned long long need)
 Manage available disk space by running tasks that will discard content if necessary. More...
 
static void transmit_status (struct GNUNET_SERVICE_Client *client, int code, const char *msg)
 Transmit a status code to the client. More...
 
static int transmit_item (void *cls, const struct GNUNET_HashCode *key, uint32_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)
 Function that will transmit the given datastore entry to the client. More...
 
static void handle_reserve (void *cls, const struct ReserveMessage *msg)
 Handle RESERVE-message. More...
 
static void handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg)
 Handle RELEASE_RESERVE-message. More...
 
static int check_data (const struct DataMessage *dm)
 Check that the given message is a valid data message. More...
 
static void put_continuation (void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
 Put continuation. More...
 
static int check_put (void *cls, const struct DataMessage *dm)
 Verify PUT-message. More...
 
static void handle_put (void *cls, const struct DataMessage *dm)
 Handle PUT-message. More...
 
static void handle_get (void *cls, const struct GetMessage *msg)
 Handle GNUNET_MESSAGE_TYPE_DATASTORE_GET-message. More...
 
static void handle_get_key (void *cls, const struct GetKeyMessage *msg)
 Handle GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY-message. More...
 
static void handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message)
 Handle GET_REPLICATION-message. More...
 
static void handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg)
 Handle GET_ZERO_ANONYMITY-message. More...
 
static void remove_continuation (void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
 Remove continuation. More...
 
static int check_remove (void *cls, const struct DataMessage *dm)
 Verify REMOVE-message. More...
 
static void handle_remove (void *cls, const struct DataMessage *dm)
 Handle REMOVE-message. More...
 
static void handle_drop (void *cls, const struct GNUNET_MessageHeader *message)
 Handle DROP-message. More...
 
static void disk_utilization_change_cb (void *cls, int delta)
 Function called by plugins to notify us about a change in their disk utilization. More...
 
static int process_stat_in (void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
 Callback function to process statistic values. More...
 
static struct DatastorePluginload_plugin ()
 Load the datastore plugin. More...
 
static void unload_plugin (struct DatastorePlugin *plug)
 Function called when the service shuts down. More...
 
static void begin_service ()
 Initialization complete, start operating the service. More...
 
static void add_key_to_bloomfilter (void *cls, const struct GNUNET_HashCode *key, unsigned int count)
 Adds a given key to the bloomfilter in cls count times. More...
 
static void process_stat_done (void *cls, int success)
 We finished receiving the statistic. More...
 
static void stat_timeout (void *cls)
 Fetching stats took to long, run without. More...
 
static void cleaning_task (void *cls)
 Task run during shutdown. More...
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 Add a client to our list of active clients. More...
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
 Called whenever a client is disconnected. More...
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *serv)
 Process datastore requests. More...
 
 GNUNET_SERVICE_MAIN ("datastore", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(reserve, GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, struct ReserveMessage, NULL), GNUNET_MQ_hd_fixed_size(release_reserve, GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, struct ReleaseReserveMessage, NULL), GNUNET_MQ_hd_var_size(put, GNUNET_MESSAGE_TYPE_DATASTORE_PUT, struct DataMessage, NULL), GNUNET_MQ_hd_fixed_size(get, GNUNET_MESSAGE_TYPE_DATASTORE_GET, struct GetMessage, NULL), GNUNET_MQ_hd_fixed_size(get_key, GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, struct GetKeyMessage, NULL), GNUNET_MQ_hd_fixed_size(get_replication, GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_fixed_size(get_zero_anonymity, GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, struct GetZeroAnonymityMessage, NULL), GNUNET_MQ_hd_var_size(remove, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, struct DataMessage, NULL), GNUNET_MQ_hd_fixed_size(drop, GNUNET_MESSAGE_TYPE_DATASTORE_DROP, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

static char * quota_stat_name
 Name under which we store current space consumption. More...
 
static struct GNUNET_SCHEDULER_Taskstat_timeout_task
 Task to timeout stat GET. More...
 
static struct DatastorePluginplugin
 Our datastore plugin (NULL if not available). More...
 
static struct ReservationListreservations
 Linked list of space reservations made by clients. More...
 
static struct GNUNET_CONTAINER_BloomFilterfilter
 Bloomfilter to quickly tell if we don't have the content. More...
 
static char * plugin_name
 Name of our plugin. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
static struct GNUNET_STATISTICS_Handlestats
 Handle for reporting statistics. More...
 
static unsigned long long cache_size
 How much space are we using for the cache? (space available for insertions that will be instantly reclaimed by discarding less important content — or possibly whatever we just inserted into the "cache"). More...
 
static unsigned long long reserved
 How much space have we currently reserved? More...
 
static unsigned long long payload
 How much data are we currently storing in the database? More...
 
static struct GNUNET_SCHEDULER_Taskexpired_kill_task
 Identity of the task that is used to delete expired content. More...
 
static struct GNUNET_TIME_Absolute min_expiration
 Minimum time that content should have to not be discarded instantly (time stamp of any content that we've been discarding recently to stay below the quota). More...
 
static unsigned long long quota
 How much space are we allowed to use? More...
 
static int do_drop
 Should the database be dropped on exit? More...
 
static int refresh_bf
 Should we refresh the BF when the DB is loaded? More...
 
static unsigned int last_sync
 Number of updates that were made to the payload value since we last synchronized it with the statistics service. More...
 
static int stats_worked
 Did we get an answer from statistics? More...
 
static int cleaning_done
 Have we already cleaned up the TCCs and are hence no longer willing (or able) to transmit anything to anyone? More...
 
static struct GNUNET_STATISTICS_GetHandlestat_get
 Handle for pending get request. More...
 
static struct GNUNET_SERVICE_Handleservice
 Handle to our server. More...
 

Detailed Description

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

Author
Christian Grothoff

Definition in file gnunet-service-datastore.c.

Macro Definition Documentation

◆ MAX_PENDING

#define MAX_PENDING   1024

How many messages do we queue at most per client?

Definition at line 37 of file gnunet-service-datastore.c.

◆ MAX_BF_SIZE

#define MAX_BF_SIZE   ((uint32_t)(1LL << 31))

Limit size of bloom filter to 2 GB.

Definition at line 42 of file gnunet-service-datastore.c.

Referenced by run().

◆ MAX_EXPIRE_DELAY

#define MAX_EXPIRE_DELAY   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15)

How long are we at most keeping "expired" content past the expiration date in the database?

Definition at line 48 of file gnunet-service-datastore.c.

Referenced by expired_processor().

◆ MIN_EXPIRE_DELAY

#define MIN_EXPIRE_DELAY   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)

How fast are we allowed to query the database for deleting expired content? (1 item per second).

Definition at line 55 of file gnunet-service-datastore.c.

Referenced by expired_processor().

◆ MAX_STAT_SYNC_LAG

#define MAX_STAT_SYNC_LAG   50

After how many payload-changing operations do we sync our statistics?

Definition at line 72 of file gnunet-service-datastore.c.

Referenced by disk_utilization_change_cb().

Function Documentation

◆ sync_stats()

static void sync_stats ( )
static

Synchronize our utilization statistics with the statistics service.

Definition at line 230 of file gnunet-service-datastore.c.

References GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_YES, last_sync, payload, and quota_stat_name.

Referenced by cleaning_task(), and disk_utilization_change_cb().

231 {
234  "# utilization by current datastore",
235  payload,
236  GNUNET_NO);
237  last_sync = 0;
238 }
#define GNUNET_NO
Definition: gnunet_common.h:78
static char * quota_stat_name
Name under which we store current space consumption.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static unsigned int last_sync
Number of updates that were made to the payload value since we last synchronized it with the statisti...
static unsigned long long payload
How much data are we currently storing in the database?
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_expired()

static void delete_expired ( void *  cls)
static

Task that is used to remove expired entries from the datastore.

This task will schedule itself again automatically to always delete all expired content quickly.

Parameters
clsnot used

Definition at line 355 of file gnunet-service-datastore.c.

References DatastorePlugin::api, GNUNET_DATASTORE_PluginFunctions::cls, expired_processor(), and GNUNET_DATASTORE_PluginFunctions::get_expiration.

Referenced by begin_service(), and expired_processor().

356 {
357  expired_kill_task = NULL;
359 }
PluginGetRandom get_expiration
Function to get a random expired item or, if none are expired, either the oldest entry or one with a ...
static struct GNUNET_SCHEDULER_Task * expired_kill_task
Identity of the task that is used to delete expired content.
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static int expired_processor(void *cls, const struct GNUNET_HashCode *key, uint32_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)
Iterate over the expired items stored in the datastore.
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ expired_processor()

static int expired_processor ( void *  cls,
const struct GNUNET_HashCode key,
uint32_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 
)
static

Iterate over the expired items stored in the datastore.

Delete all expired items; once we have processed all expired items, re-schedule the "delete_expired" task.

Parameters
clsnot used
keykey for the content
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationreplication-level for the content
expirationexpiration time for the content
uidunique identifier for the datum; maybe 0 if no unique identifier is available
Returns
GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue (continue on call to "next", of course), GNUNET_NO to delete the item and continue (if supported)

Definition at line 291 of file gnunet-service-datastore.c.

References GNUNET_TIME_Absolute::abs_value_us, delete_expired(), gettext_noop, GNUNET_CONTAINER_bloomfilter_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_difference(), GNUNET_YES, MAX_EXPIRE_DELAY, min_expiration, and MIN_EXPIRE_DELAY.

Referenced by delete_expired().

301 {
302  struct GNUNET_TIME_Absolute now;
303 
304  if (NULL == key)
305  {
310  NULL);
311  return GNUNET_SYSERR;
312  }
313  now = GNUNET_TIME_absolute_get();
314  if (expiration.abs_value_us > now.abs_value_us)
315  {
316  /* finished processing */
321  NULL);
322  return GNUNET_SYSERR;
323  }
325  "Deleting content `%s' of type %u that expired %s ago\n",
326  GNUNET_h2s(key),
327  type,
329  GNUNET_TIME_absolute_get_difference(expiration, now),
330  GNUNET_YES));
331  min_expiration = now;
333  gettext_noop("# bytes expired"),
334  size,
335  GNUNET_YES);
341  NULL);
342  return GNUNET_NO;
343 }
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...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1169
#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.
uint64_t abs_value_us
The actual value.
#define MAX_EXPIRE_DELAY
How long are we at most keeping "expired" content past the expiration date in the database...
void GNUNET_CONTAINER_bloomfilter_remove(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Remove an element from the filter.
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
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don&#39;t have the content.
static struct GNUNET_SCHEDULER_Task * expired_kill_task
Identity of the task that is used to delete expired content.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
Run when otherwise idle.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:353
#define MIN_EXPIRE_DELAY
How fast are we allowed to query the database for deleting expired content? (1 item per second)...
static void delete_expired(void *cls)
Task that is used to remove expired entries from the datastore.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ quota_processor()

static int quota_processor ( void *  cls,
const struct GNUNET_HashCode key,
uint32_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 
)
static

An iterator over a set of items stored in the datastore that deletes until we're happy with respect to our quota.

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
replicationreplication-level for the content
expirationexpiration time for the content
uidunique identifier for the datum; maybe 0 if no unique identifier is available
Returns
GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue (continue on call to "next", of course), GNUNET_NO to delete the item and continue (if supported)

Definition at line 382 of file gnunet-service-datastore.c.

References expiration, gettext_noop, GNUNET_CONTAINER_bloomfilter_remove(), GNUNET_DATASTORE_ENTRY_OVERHEAD, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_YES, and min_expiration.

Referenced by manage_space().

392 {
393  unsigned long long *need = cls;
394 
395  if (NULL == key)
396  return GNUNET_SYSERR;
397  GNUNET_log(
399  "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n",
400  (unsigned long long)(size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
401  (unsigned int)priority,
402  GNUNET_h2s(key),
403  type,
405  expiration),
406  GNUNET_YES),
407  *need);
409  *need = 0;
410  else
412  if (priority > 0)
414  else
417  gettext_noop("# bytes purged (low-priority)"),
418  size,
419  GNUNET_YES);
421  return GNUNET_NO;
422 }
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...
static char * expiration
Credential TTL.
#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.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
void GNUNET_CONTAINER_bloomfilter_remove(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Remove an element from the filter.
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
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don&#39;t have the content.
#define GNUNET_DATASTORE_ENTRY_OVERHEAD
How many bytes of overhead will we assume per entry in any DB (for reservations)? ...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_log(kind,...)
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
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ manage_space()

static void manage_space ( unsigned long long  need)
static

Manage available disk space by running tasks that will discard content if necessary.

This function will be run whenever a request for "need" bytes of storage could only be satisfied by eating into the "cache" (and we want our cache space back).

Parameters
neednumber of bytes of content that were placed into the "cache" (and hence the number of bytes that should be removed).

Definition at line 438 of file gnunet-service-datastore.c.

References DatastorePlugin::api, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::get_expiration, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and quota_processor().

Referenced by put_continuation().

439 {
440  unsigned long long last;
441 
443  "Asked to free up %llu bytes of cache space\n",
444  need);
445  last = 0;
446  while ((need > 0) && (last != need))
447  {
448  last = need;
450  }
451 }
static int quota_processor(void *cls, const struct GNUNET_HashCode *key, uint32_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)
An iterator over a set of items stored in the datastore that deletes until we&#39;re happy with respect t...
PluginGetRandom get_expiration
Function to get a random expired item or, if none are expired, either the oldest entry or one with a ...
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_status()

static void transmit_status ( struct GNUNET_SERVICE_Client client,
int  code,
const char *  msg 
)
static

Transmit a status code to the client.

Parameters
clientreceiver of the response
codestatus code
msgoptional error message (can be NULL)

Definition at line 462 of file gnunet-service-datastore.c.

References DatastorePlugin::env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_SERVICE_client_get_mq(), GNUNET_TIME_absolute_hton(), StatusMessage::min_expiration, min_expiration, and StatusMessage::status.

Referenced by handle_release_reserve(), handle_reserve(), put_continuation(), and remove_continuation().

465 {
466  struct GNUNET_MQ_Envelope *env;
467  struct StatusMessage *sm;
468  size_t slen;
469 
471  "Transmitting `%s' message with value %d and message `%s'\n",
472  "STATUS",
473  code,
474  msg != NULL ? msg : "(none)");
475  slen = (msg == NULL) ? 0 : strlen(msg) + 1;
477  sm->status = htonl(code);
479  GNUNET_memcpy(&sm[1], msg, slen);
481 }
#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_TIME_Absolute min_expiration
Minimum time that content should have to not be discarded instantly (time stamp of any content that w...
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2424
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_TIME_AbsoluteNBO min_expiration
Minimum expiration time required for content to be stored by the datacache at this time...
Definition: datastore.h:78
#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
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log(kind,...)
Message from datastore service informing client about the success or failure of a requested operation...
Definition: datastore.h:63
int32_t status
Status code, -1 for errors.
Definition: datastore.h:72
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
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:655
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_item()

static int transmit_item ( void *  cls,
const struct GNUNET_HashCode key,
uint32_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 
)
static

Function that will transmit the given datastore entry to the client.

Parameters
clsclosure, pointer to the client (of type struct GNUNET_SERVICE_Client).
keykey for the content
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationreplication-level for the content
expirationexpiration time for the content
uidunique identifier for the datum; maybe 0 if no unique identifier is available
Returns
GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue, GNUNET_NO to delete the item and continue (if supported)

Definition at line 503 of file gnunet-service-datastore.c.

References DataMessage::anonymity, end, DatastorePlugin::env, DataMessage::expiration, gettext_noop, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_htonll(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DATASTORE_DATA, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END, GNUNET_MQ_msg, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_SERVICE_client_get_mq(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_hton(), GNUNET_YES, key, DataMessage::key, DataMessage::priority, DataMessage::replication, DataMessage::rid, DataMessage::size, DataMessage::type, and DataMessage::uid.

Referenced by handle_get(), handle_get_key(), handle_get_replication(), and handle_get_zero_anonymity().

513 {
514  struct GNUNET_SERVICE_Client *client = cls;
515  struct GNUNET_MQ_Envelope *env;
516  struct GNUNET_MessageHeader *end;
517  struct DataMessage *dm;
518 
519  if (NULL == key)
520  {
521  /* transmit 'DATA_END' */
522  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n");
525  return GNUNET_OK;
526  }
529  dm->rid = htonl(0);
530  dm->size = htonl(size);
531  dm->type = htonl(type);
532  dm->priority = htonl(priority);
533  dm->anonymity = htonl(anonymity);
534  dm->replication = htonl(replication);
535  dm->expiration = GNUNET_TIME_absolute_hton(expiration);
536  dm->uid = GNUNET_htonll(uid);
537  dm->key = *key;
538  GNUNET_memcpy(&dm[1], data, size);
539  GNUNET_log(
541  "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n",
542  GNUNET_h2s(key),
543  type,
546  expiration),
547  GNUNET_YES));
549  gettext_noop("# results found"),
550  1,
551  GNUNET_NO);
553  return GNUNET_OK;
554 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
struct GNUNET_TIME_AbsoluteNBO expiration
Expiration time (NBO); zero for remove.
Definition: datastore.h:240
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2424
uint32_t type
Type of the item (NBO), zero for remove, (actually an enum GNUNET_BLOCK_Type)
Definition: datastore.h:207
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int replication
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#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
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
Handle to a client that is connected to a service.
Definition: service.c:246
#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
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 GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END
Message sent by datastore to client signaling end of matching data.
uint32_t replication
Desired replication level.
Definition: datastore.h:222
uint32_t rid
Reservation ID to use; use zero for none.
Definition: datastore.h:197
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
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
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
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
uint64_t uid
Unique ID for the content (can be used for UPDATE); can be zero for remove (which indicates that the ...
Definition: datastore.h:235
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
#define GNUNET_log(kind,...)
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
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:77
static unsigned int anonymity
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
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:741
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 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:

◆ handle_reserve()

static void handle_reserve ( void *  cls,
const struct ReserveMessage msg 
)
static

Handle RESERVE-message.

Parameters
clsidentification of the client
messagethe actual message

Static counter to produce reservation identifiers.

Definition at line 564 of file gnunet-service-datastore.c.

References _, ReserveMessage::amount, ReservationList::amount, cache_size, ReservationList::client, e, ReserveMessage::entries, entries, ReservationList::entries, gettext_noop, GNUNET_DATASTORE_ENTRY_OVERHEAD, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_ntohll(), GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_set(), ReservationList::next, payload, quota, reservations, reserved, ReservationList::rid, and transmit_status().

565 {
569  static int reservation_gen;
570  struct GNUNET_SERVICE_Client *client = cls;
571  struct ReservationList *e;
572  unsigned long long used;
573  unsigned long long req;
574  uint64_t amount;
575  uint32_t entries;
576 
577  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n");
578  amount = GNUNET_ntohll(msg->amount);
579  entries = ntohl(msg->entries);
580  used = payload + reserved;
581  req =
582  amount + ((unsigned long long)GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
583  if (used + req > quota)
584  {
585  if (quota < used)
586  used =
587  quota; /* cheat a bit for error message (to avoid negative numbers) */
588  GNUNET_log(
590  _(
591  "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"),
592  quota - used,
593  req);
594  if (cache_size < req)
595  {
596  /* TODO: document this in the FAQ; essentially, if this
597  * message happens, the insertion request could be blocked
598  * by less-important content from migration because it is
599  * larger than 1/8th of the overall available space, and
600  * we only reserve 1/8th for "fresh" insertions */
601  GNUNET_log(
603  _(
604  "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
605  req,
606  cache_size);
608  0,
609  gettext_noop(
610  "Insufficient space to satisfy request and "
611  "requested amount is larger than cache size"));
612  }
613  else
614  {
616  0,
617  gettext_noop("Insufficient space to satisfy request"));
618  }
620  return;
621  }
622  reserved += req;
624  gettext_noop("# reserved"),
625  reserved,
626  GNUNET_NO);
627  e = GNUNET_new(struct ReservationList);
628  e->next = reservations;
629  reservations = e;
630  e->client = client;
631  e->amount = amount;
632  e->entries = entries;
633  e->rid = ++reservation_gen;
634  if (reservation_gen < 0)
635  reservation_gen = 0; /* wrap around */
636  transmit_status(client, e->rid, NULL);
638 }
uint32_t entries
Number of items to reserve.
Definition: datastore.h:48
uint64_t amount
Number of bytes (still) reserved.
static struct Experiment * e
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
Handle to a client that is connected to a service.
Definition: service.c:246
static struct ReservationList * reservations
Linked list of space reservations made by clients.
struct ListEntry * entries
List of peers in the list.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
#define GNUNET_DATASTORE_ENTRY_OVERHEAD
How many bytes of overhead will we assume per entry in any DB (for reservations)? ...
static unsigned long long payload
How much data are we currently storing in the database?
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
static unsigned long long quota
How much space are we allowed to use?
static unsigned long long cache_size
How much space are we using for the cache? (space available for insertions that will be instantly rec...
#define GNUNET_log(kind,...)
static void transmit_status(struct GNUNET_SERVICE_Client *client, int code, const char *msg)
Transmit a status code to the client.
static unsigned long long reserved
How much space have we currently reserved?
struct GNUNET_SERVICE_Client * client
Client that made the reservation.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
Linked list of active reservations.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#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:

◆ handle_release_reserve()

static void handle_release_reserve ( void *  cls,
const struct ReleaseReserveMessage msg 
)
static

Handle RELEASE_RESERVE-message.

Parameters
clsidentification of the client
messagethe actual message

Definition at line 648 of file gnunet-service-datastore.c.

References ReservationList::amount, ReservationList::entries, gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_DATASTORE_ENTRY_OVERHEAD, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_set(), GNUNET_SYSERR, ReservationList::next, reservations, reserved, ReleaseReserveMessage::rid, ReservationList::rid, and transmit_status().

649 {
650  struct GNUNET_SERVICE_Client *client = cls;
651  struct ReservationList *pos;
652  struct ReservationList *prev;
653  struct ReservationList *next;
654  int rid = ntohl(msg->rid);
655  unsigned long long rem;
656 
657  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n");
658  next = reservations;
659  prev = NULL;
660  while (NULL != (pos = next))
661  {
662  next = pos->next;
663  if (rid == pos->rid)
664  {
665  if (prev == NULL)
666  reservations = next;
667  else
668  prev->next = next;
669  rem =
670  pos->amount +
671  ((unsigned long long)GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
672  GNUNET_assert(reserved >= rem);
673  reserved -= rem;
675  gettext_noop("# reserved"),
676  reserved,
677  GNUNET_NO);
679  "Returning %llu remaining reserved bytes to storage pool\n",
680  rem);
681  GNUNET_free(pos);
682  transmit_status(client, GNUNET_OK, NULL);
684  return;
685  }
686  prev = pos;
687  }
688  GNUNET_break(0);
689  transmit_status(client,
691  gettext_noop("Could not find matching reservation"));
693 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t amount
Number of bytes (still) reserved.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle to a client that is connected to a service.
Definition: service.c:246
int32_t rid
Reservation identifier.
static struct ReservationList * reservations
Linked list of space reservations made by clients.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
#define GNUNET_DATASTORE_ENTRY_OVERHEAD
How many bytes of overhead will we assume per entry in any DB (for reservations)? ...
struct ReservationList * next
This is a linked list.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint64_t entries
Number of items (still) reserved.
int32_t rid
Reservation id.
Definition: datastore.h:96
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_log(kind,...)
static void transmit_status(struct GNUNET_SERVICE_Client *client, int code, const char *msg)
Transmit a status code to the client.
static unsigned long long reserved
How much space have we currently reserved?
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
Linked list of active reservations.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ check_data()

static int check_data ( const struct DataMessage dm)
static

Check that the given message is a valid data message.

Parameters
dmmessage to check
Returns
GNUNET_SYSERR is not well-formed, otherwise GNUNET_OK

Definition at line 703 of file gnunet-service-datastore.c.

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

Referenced by check_put(), and check_remove().

704 {
705  uint16_t size;
706  uint32_t dsize;
707 
708  size = ntohs(dm->header.size);
709  dsize = ntohl(dm->size);
710  if (size != dsize + sizeof(struct DataMessage))
711  {
712  GNUNET_break(0);
713  return GNUNET_SYSERR;
714  }
715  return GNUNET_OK;
716 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Message transmitting content from or to the datastore service.
Definition: datastore.h:185
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
uint32_t size
Number of bytes in the item (NBO).
Definition: datastore.h:202
struct GNUNET_MessageHeader header
Type is either GNUNET_MESSAGE_TYPE_DATASTORE_PUT, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE or GNUNET_MESS...
Definition: datastore.h:192
Here is the caller graph for this function:

◆ put_continuation()

static void put_continuation ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  size,
int  status,
const char *  msg 
)
static

Put continuation.

Parameters
clsclosure
keykey for the item stored
sizesize of the item stored
statusGNUNET_OK if inserted, GNUNET_NO if updated, or #GNUNET_SYSERROR if error
msgerror message on error

Definition at line 730 of file gnunet-service-datastore.c.

References _, cache_size, gettext_noop, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_DATASTORE_ENTRY_OVERHEAD, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_h2s(), GNUNET_log, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, manage_space(), payload, quota, reserved, and transmit_status().

Referenced by handle_put().

735 {
736  struct GNUNET_SERVICE_Client *client = cls;
737 
738  if (GNUNET_OK == status)
739  {
741  gettext_noop("# bytes stored"),
742  size,
743  GNUNET_YES);
746  "Successfully stored %u bytes under key `%s'\n",
747  size,
748  GNUNET_h2s(key));
749  }
750  transmit_status(client,
752  msg);
753  if (quota - reserved - cache_size < payload)
754  {
756  _("Need %llu bytes more space (%llu allowed, using %llu)\n"),
757  (unsigned long long)size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
758  (unsigned long long)(quota - reserved - cache_size),
759  (unsigned long long)payload);
761  }
762 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
static void manage_space(unsigned long long need)
Manage available disk space by running tasks that will discard content if necessary.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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 _(String)
GNU gettext support macro.
Definition: platform.h:181
Handle to a client that is connected to a service.
Definition: service.c:246
uint16_t status
See PRISM_STATUS_*-constants.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don&#39;t have the content.
#define GNUNET_DATASTORE_ENTRY_OVERHEAD
How many bytes of overhead will we assume per entry in any DB (for reservations)? ...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
static unsigned long long payload
How much data are we currently storing in the database?
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
static unsigned long long quota
How much space are we allowed to use?
static unsigned long long cache_size
How much space are we using for the cache? (space available for insertions that will be instantly rec...
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static void transmit_status(struct GNUNET_SERVICE_Client *client, int code, const char *msg)
Transmit a status code to the client.
static unsigned long long reserved
How much space have we currently reserved?
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_put()

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

Verify PUT-message.

Parameters
clsidentification of the client
messagethe actual message
Returns
GNUNET_OK if dm is well-formed

Definition at line 773 of file gnunet-service-datastore.c.

References check_data(), GNUNET_break, GNUNET_OK, and GNUNET_SYSERR.

774 {
775  if (GNUNET_OK != check_data(dm))
776  {
777  GNUNET_break(0);
778  return GNUNET_SYSERR;
779  }
780  return GNUNET_OK;
781 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int check_data(const struct DataMessage *dm)
Check that the given message is a valid data message.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Here is the call graph for this function:

◆ handle_put()

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

Handle PUT-message.

Parameters
clsidentification of the client
messagethe actual message

Definition at line 791 of file gnunet-service-datastore.c.

References ReservationList::amount, DataMessage::anonymity, DatastorePlugin::api, GNUNET_DATASTORE_PluginFunctions::cls, ReservationList::entries, DataMessage::expiration, gettext_noop, GNUNET_break, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_DATASTORE_ENTRY_OVERHEAD, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_set(), GNUNET_TIME_absolute_ntoh(), DataMessage::key, ReservationList::next, DataMessage::priority, GNUNET_DATASTORE_PluginFunctions::put, put_continuation(), DataMessage::replication, reservations, reserved, ReservationList::rid, DataMessage::rid, size, DataMessage::size, and DataMessage::type.

792 {
793  struct GNUNET_SERVICE_Client *client = cls;
794  int rid;
795  struct ReservationList *pos;
796  uint32_t size;
797 
799  "Processing PUT request for `%s' of type %u\n",
800  GNUNET_h2s(&dm->key),
801  (uint32_t)ntohl(dm->type));
802  rid = ntohl(dm->rid);
803  size = ntohl(dm->size);
804  if (rid > 0)
805  {
806  pos = reservations;
807  while ((NULL != pos) && (rid != pos->rid))
808  pos = pos->next;
809  GNUNET_break(pos != NULL);
810  if (NULL != pos)
811  {
812  GNUNET_break(pos->entries > 0);
813  GNUNET_break(pos->amount >= size);
814  pos->entries--;
815  pos->amount -= size;
818  gettext_noop("# reserved"),
819  reserved,
820  GNUNET_NO);
821  }
822  }
823  bool absent =
825  plugin->api->put(plugin->api->cls,
826  &dm->key,
827  absent,
828  ntohl(dm->size),
829  &dm[1],
830  ntohl(dm->type),
831  ntohl(dm->priority),
832  ntohl(dm->anonymity),
833  ntohl(dm->replication),
836  client);
838 }
PluginPut put
Function to store an item in the datastore.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:671
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
uint64_t amount
Number of bytes (still) reserved.
#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_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle to a client that is connected to a service.
Definition: service.c:246
int32_t rid
Reservation identifier.
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
static struct ReservationList * reservations
Linked list of space reservations made by clients.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don&#39;t have the content.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
#define GNUNET_DATASTORE_ENTRY_OVERHEAD
How many bytes of overhead will we assume per entry in any DB (for reservations)? ...
uint32_t replication
Desired replication level.
Definition: datastore.h:222
uint32_t rid
Reservation ID to use; use zero for none.
Definition: datastore.h:197
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
struct ReservationList * next
This is a linked list.
static unsigned int size
Size of the "table".
Definition: peer.c:66
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
uint64_t entries
Number of items (still) reserved.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
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
static void put_continuation(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Put continuation.
#define GNUNET_log(kind,...)
static unsigned long long reserved
How much space have we currently reserved?
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
Linked list of active reservations.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ handle_get()

static void handle_get ( void *  cls,
const struct GetMessage msg 
)
static

Handle GNUNET_MESSAGE_TYPE_DATASTORE_GET-message.

Parameters
clsidentification of the client
msgthe actual message

Definition at line 848 of file gnunet-service-datastore.c.

References DatastorePlugin::api, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::get_key, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_ntohll(), GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), GetMessage::next_uid, GetMessage::random, transmit_item(), and GetMessage::type.

849 {
850  struct GNUNET_SERVICE_Client *client = cls;
851 
853  "Processing GET request of type %u\n",
854  (uint32_t)ntohl(msg->type));
856  gettext_noop("# GET requests received"),
857  1,
858  GNUNET_NO);
860  GNUNET_ntohll(msg->next_uid),
861  msg->random,
862  NULL,
863  ntohl(msg->type),
864  &transmit_item,
865  client);
867 }
static int transmit_item(void *cls, const struct GNUNET_HashCode *key, uint32_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)
Function that will transmit the given datastore entry to the client.
uint32_t random
If true return a random result.
Definition: datastore.h:155
#define GNUNET_NO
Definition: gnunet_common.h:78
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.
Handle to a client that is connected to a service.
Definition: service.c:246
uint32_t type
Desired content type.
Definition: datastore.h:145
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
#define GNUNET_log(kind,...)
PluginGetKey get_key
Get a particular datum matching a given hash from the datastore.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ handle_get_key()

static void handle_get_key ( void *  cls,
const struct GetKeyMessage msg 
)
static

Handle GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY-message.

Parameters
clsclosure
msgthe actual message

Definition at line 877 of file gnunet-service-datastore.c.

References DatastorePlugin::api, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::get_key, gettext_noop, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_ntohll(), GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_YES, GetKeyMessage::key, GetKeyMessage::next_uid, GetKeyMessage::random, transmit_item(), and GetKeyMessage::type.

878 {
879  struct GNUNET_SERVICE_Client *client = cls;
880 
882  "Processing GET request for `%s' of type %u\n",
883  GNUNET_h2s(&msg->key),
884  (uint32_t)ntohl(msg->type));
886  gettext_noop("# GET KEY requests received"),
887  1,
888  GNUNET_NO);
890  {
891  /* don't bother database... */
893  "Empty result set for GET request for `%s' (bloomfilter).\n",
894  GNUNET_h2s(&msg->key));
896  gettext_noop(
897  "# requests filtered by bloomfilter"),
898  1,
899  GNUNET_NO);
900  transmit_item(client,
901  NULL,
902  0,
903  NULL,
904  0,
905  0,
906  0,
907  0,
909  0);
911  return;
912  }
914  GNUNET_ntohll(msg->next_uid),
915  msg->random,
916  &msg->key,
917  ntohl(msg->type),
918  &transmit_item,
919  client);
921 }
uint32_t random
If true return a random result.
Definition: datastore.h:123
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static int transmit_item(void *cls, const struct GNUNET_HashCode *key, uint32_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)
Function that will transmit the given datastore entry to the client.
#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.
Handle to a client that is connected to a service.
Definition: service.c:246
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
uint32_t type
Desired content type.
Definition: datastore.h:113
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don&#39;t have the content.
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
struct GNUNET_HashCode key
Desired key.
Definition: datastore.h:128
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
uint64_t next_uid
UID at which to start the search.
Definition: datastore.h:118
PluginGetKey get_key
Get a particular datum matching a given hash from the datastore.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ handle_get_replication()

static void handle_get_replication ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Handle GET_REPLICATION-message.

Parameters
clsidentification of the client
messagethe actual message

Definition at line 931 of file gnunet-service-datastore.c.

References DatastorePlugin::api, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::get_replication, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), and transmit_item().

932 {
933  struct GNUNET_SERVICE_Client *client = cls;
934 
935  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n");
937  gettext_noop(
938  "# GET REPLICATION requests received"),
939  1,
940  GNUNET_NO);
943 }
static int transmit_item(void *cls, const struct GNUNET_HashCode *key, uint32_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)
Function that will transmit the given datastore entry to the client.
#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.
Handle to a client that is connected to a service.
Definition: service.c:246
PluginGetRandom get_replication
Function to get a random item with high replication score from the database, lowering the item&#39;s repl...
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
#define GNUNET_log(kind,...)
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ handle_get_zero_anonymity()

static void handle_get_zero_anonymity ( void *  cls,
const struct GetZeroAnonymityMessage msg 
)
static

Handle GET_ZERO_ANONYMITY-message.

Parameters
clsclient identification of the client
messagethe actual message

Definition at line 953 of file gnunet-service-datastore.c.

References DatastorePlugin::api, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::get_zero_anonymity, gettext_noop, GNUNET_BLOCK_TYPE_ANY, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_ntohll(), GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_STATISTICS_update(), GetZeroAnonymityMessage::next_uid, transmit_item(), type, and GetZeroAnonymityMessage::type.

954 {
955  struct GNUNET_SERVICE_Client *client = cls;
956  enum GNUNET_BLOCK_Type type;
957 
958  type = (enum GNUNET_BLOCK_Type)ntohl(msg->type);
959  if (type == GNUNET_BLOCK_TYPE_ANY)
960  {
961  GNUNET_break(0);
963  return;
964  }
966  "Processing GET_ZERO_ANONYMITY request\n");
968  gettext_noop(
969  "# GET ZERO ANONYMITY requests received"),
970  1,
971  GNUNET_NO);
973  GNUNET_ntohll(msg->next_uid),
974  type,
975  &transmit_item,
976  client);
978 }
PluginGetType get_zero_anonymity
Get datum (of the specified type) with anonymity level zero.
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 int transmit_item(void *cls, const struct GNUNET_HashCode *key, uint32_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)
Function that will transmit the given datastore entry to the client.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
#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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle to a client that is connected to a service.
Definition: service.c:246
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2315
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
uint64_t next_uid
UID at which to start the search.
Definition: datastore.h:177
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ remove_continuation()

static void remove_continuation ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  size,
int  status,
const char *  msg 
)
static

Remove continuation.

Parameters
clsclosure
keykey for the content
sizenumber of bytes in data
statusGNUNET_OK if removed, GNUNET_NO if not found, or #GNUNET_SYSERROR if error
msgerror message on error

Definition at line 992 of file gnunet-service-datastore.c.

References _, gettext_noop, GNUNET_CONTAINER_bloomfilter_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, and transmit_status().

Referenced by handle_remove().

997 {
998  struct GNUNET_SERVICE_Client *client = cls;
999 
1000  if (GNUNET_SYSERR == status)
1001  {
1002  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg);
1003  transmit_status(client, GNUNET_NO, msg);
1004  return;
1005  }
1006  if (GNUNET_NO == status)
1007  {
1009  "Content not found for REMOVE request.\n");
1010  transmit_status(client, GNUNET_NO, _("Content not found"));
1011  return;
1012  }
1014  "Item matches REMOVE request for key `%s'.\n",
1015  GNUNET_h2s(key));
1017  gettext_noop("# bytes removed (explicit request)"),
1018  size,
1019  GNUNET_YES);
1021  transmit_status(client, GNUNET_OK, NULL);
1022 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
Handle to a client that is connected to a service.
Definition: service.c:246
void GNUNET_CONTAINER_bloomfilter_remove(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Remove an element from the filter.
uint16_t status
See PRISM_STATUS_*-constants.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don&#39;t have the content.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static void transmit_status(struct GNUNET_SERVICE_Client *client, int code, const char *msg)
Transmit a status code to the client.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_remove()

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

Verify REMOVE-message.

Parameters
clsidentification of the client
messagethe actual message
Returns
GNUNET_OK if dm is well-formed

Definition at line 1033 of file gnunet-service-datastore.c.

References check_data(), GNUNET_break, GNUNET_OK, and GNUNET_SYSERR.

1034 {
1035  if (GNUNET_OK != check_data(dm))
1036  {
1037  GNUNET_break(0);
1038  return GNUNET_SYSERR;
1039  }
1040  return GNUNET_OK;
1041 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int check_data(const struct DataMessage *dm)
Check that the given message is a valid data message.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Here is the call graph for this function:

◆ handle_remove()

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

Handle REMOVE-message.

Parameters
clsclosure
clientidentification of the client
messagethe actual message

Definition at line 1052 of file gnunet-service-datastore.c.

References DatastorePlugin::api, GNUNET_DATASTORE_PluginFunctions::cls, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), DataMessage::key, remove_continuation(), GNUNET_DATASTORE_PluginFunctions::remove_key, and DataMessage::size.

1053 {
1054  struct GNUNET_SERVICE_Client *client = cls;
1055 
1057  gettext_noop("# REMOVE requests received"),
1058  1,
1059  GNUNET_NO);
1061  "Processing REMOVE request for `%s'\n",
1062  GNUNET_h2s(&dm->key));
1064  &dm->key,
1065  ntohl(dm->size),
1066  &dm[1],
1068  client);
1070 }
PluginRemoveKey remove_key
Function to remove an item from the database.
static void remove_continuation(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Remove continuation.
#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.
Handle to a client that is connected to a service.
Definition: service.c:246
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
uint32_t size
Number of bytes in the item (NBO).
Definition: datastore.h:202
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
struct GNUNET_HashCode key
Key under which the item can be found.
Definition: datastore.h:245
#define GNUNET_log(kind,...)
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ handle_drop()

static void handle_drop ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Handle DROP-message.

Parameters
clsidentification of the client
messagethe actual message

Definition at line 1080 of file gnunet-service-datastore.c.

References do_drop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SERVICE_client_continue(), and GNUNET_YES.

1081 {
1082  struct GNUNET_SERVICE_Client *client = cls;
1083 
1084  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n");
1085  do_drop = GNUNET_YES;
1087 }
static int do_drop
Should the database be dropped on exit?
Handle to a client that is connected to a service.
Definition: service.c:246
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
Here is the call graph for this function:

◆ disk_utilization_change_cb()

static void disk_utilization_change_cb ( void *  cls,
int  delta 
)
static

Function called by plugins to notify us about a change in their disk utilization.

Parameters
clsclosure (NULL)
deltachange in disk utilization, 0 for "reset to empty"

Definition at line 1099 of file gnunet-service-datastore.c.

References _, DatastorePlugin::api, GNUNET_DATASTORE_PluginFunctions::cls, delta, GNUNET_DATASTORE_PluginFunctions::estimate_size, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, last_sync, MAX_STAT_SYNC_LAG, payload, and sync_stats().

Referenced by load_plugin().

1100 {
1101  if ((delta < 0) && (payload < -delta))
1102  {
1103  GNUNET_log(
1105  _(
1106  "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"),
1107  (long long)payload,
1108  (long long)-delta);
1109  plugin->api->estimate_size(plugin->api->cls, &payload);
1111  _("New payload: %lld\n"),
1112  (long long)payload);
1113  sync_stats();
1114  return;
1115  }
1116  payload += delta;
1117  last_sync++;
1119  sync_stats();
1120 }
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
#define MAX_STAT_SYNC_LAG
After how many payload-changing operations do we sync our statistics?
PluginEstimateSize estimate_size
Calculate the current on-disk size of the SQ store.
static void sync_stats()
Synchronize our utilization statistics with the statistics service.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
static unsigned int last_sync
Number of updates that were made to the payload value since we last synchronized it with the statisti...
static unsigned long long payload
How much data are we currently storing in the database?
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_stat_in()

static int process_stat_in ( void *  cls,
const char *  subsystem,
const char *  name,
uint64_t  value,
int  is_persistent 
)
static

Callback function to process statistic values.

Parameters
clsclosure (struct Plugin*)
subsystemname of subsystem that created the statistic
namethe name of the datum
valuethe current value
is_persistentGNUNET_YES if the value is persistent, GNUNET_NO if not
Returns
GNUNET_OK to continue, GNUNET_SYSERR to abort iteration

Definition at line 1134 of file gnunet-service-datastore.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_YES, payload, stats_worked, and value.

Referenced by run().

1139 {
1142  payload += value;
1143  GNUNET_log(
1145  "Notification from statistics about existing payload (%llu), new payload is %llu\n",
1146  (unsigned long long)value,
1147  (unsigned long long)payload);
1148  return GNUNET_OK;
1149 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * value
Value of the record to add/remove.
static int stats_worked
Did we get an answer from statistics?
static unsigned long long payload
How much data are we currently storing in the database?
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ load_plugin()

static struct DatastorePlugin* load_plugin ( )
static

Load the datastore plugin.

Definition at line 1156 of file gnunet-service-datastore.c.

References _, DatastorePlugin::api, GNUNET_DATASTORE_PluginEnvironment::cfg, cfg, GNUNET_DATASTORE_PluginEnvironment::cls, disk_utilization_change_cb(), GNUNET_DATASTORE_PluginEnvironment::duc, DatastorePlugin::env, GNUNET_asprintf(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_PLUGIN_load(), GNUNET_strdup, DatastorePlugin::lib_name, plugin_name, ret, and DatastorePlugin::short_name.

Referenced by process_stat_done().

1157 {
1158  struct DatastorePlugin *ret;
1159  char *libname;
1160 
1161  ret = GNUNET_new(struct DatastorePlugin);
1162  ret->env.cfg = cfg;
1164  ret->env.cls = NULL;
1166  _("Loading `%s' datastore plugin\n"),
1167  plugin_name);
1168  GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", plugin_name);
1170  ret->lib_name = libname;
1171  ret->api = GNUNET_PLUGIN_load(libname, &ret->env);
1172  if (NULL == ret->api)
1173  {
1175  _("Failed to load datastore plugin for `%s'\n"),
1176  plugin_name);
1177  GNUNET_free(ret->short_name);
1178  GNUNET_free(libname);
1179  GNUNET_free(ret);
1180  return NULL;
1181  }
1182  return ret;
1183 }
GNUNET_DATASTORE_DiskUtilizationChange duc
Function to call on disk utilization change.
static void disk_utilization_change_cb(void *cls, int delta)
Function called by plugins to notify us about a change in their disk utilization. ...
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Our datastore plugin.
char * lib_name
Name of the library (i.e.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * short_name
Short name for the plugin (i.e.
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
struct GNUNET_DATASTORE_PluginEnvironment env
Environment this transport service is using for this plugin.
#define GNUNET_log(kind,...)
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:206
static char * plugin_name
Name of our plugin.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unload_plugin()

static void unload_plugin ( struct DatastorePlugin plug)
static

Function called when the service shuts down.

Unloads our datastore plugin.

Parameters
plugplugin to unload

Definition at line 1193 of file gnunet-service-datastore.c.

References DatastorePlugin::api, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_PLUGIN_unload(), DatastorePlugin::lib_name, and DatastorePlugin::short_name.

Referenced by cleaning_task().

1194 {
1196  "Datastore service is unloading plugin...\n");
1197  GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api));
1198  GNUNET_free(plug->lib_name);
1199  GNUNET_free(plug->short_name);
1200  GNUNET_free(plug);
1201 }
char * lib_name
Name of the library (i.e.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:255
char * short_name
Short name for the plugin (i.e.
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin_service()

static void begin_service ( )
static

Initialization complete, start operating the service.

Definition at line 1208 of file gnunet-service-datastore.c.

References delete_expired(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, and GNUNET_SERVICE_resume().

Referenced by add_key_to_bloomfilter(), and process_stat_done().

1209 {
1213  &delete_expired,
1214  NULL);
1215 }
void GNUNET_SERVICE_resume(struct GNUNET_SERVICE_Handle *sh)
Resume accepting connections from the listen socket.
Definition: service.c:2185
static struct GNUNET_SERVICE_Handle * service
Handle to our server.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1191
static struct GNUNET_SCHEDULER_Task * expired_kill_task
Identity of the task that is used to delete expired content.
Run when otherwise idle.
static void delete_expired(void *cls)
Task that is used to remove expired entries from the datastore.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_key_to_bloomfilter()

static void add_key_to_bloomfilter ( void *  cls,
const struct GNUNET_HashCode key,
unsigned int  count 
)
static

Adds a given key to the bloomfilter in cls count times.

Parameters
clsthe bloomfilter
keykey to add
countnumber of times to add key

Definition at line 1226 of file gnunet-service-datastore.c.

References _, begin_service(), GNUNET_CONTAINER_bloomfilter_add(), GNUNET_ERROR_TYPE_INFO, and GNUNET_log.

Referenced by process_stat_done().

1229 {
1230  struct GNUNET_CONTAINER_BloomFilter *bf = cls;
1231 
1232  if (NULL == key)
1233  {
1235  _("Bloomfilter construction complete.\n"));
1236  begin_service();
1237  return;
1238  }
1239 
1240  while (0 < count--)
1242 }
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static void begin_service()
Initialization complete, start operating the service.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_stat_done()

static void process_stat_done ( void *  cls,
int  success 
)
static

We finished receiving the statistic.

Initialize the plugin; if loading the statistic failed, run the estimator.

Parameters
clsNULL
successGNUNET_NO if we failed to read the stat

Definition at line 1253 of file gnunet-service-datastore.c.

References _, add_key_to_bloomfilter(), DatastorePlugin::api, begin_service(), GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::estimate_size, GNUNET_DATASTORE_PluginFunctions::get_keys, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_YES, load_plugin(), payload, refresh_bf, and stats_worked.

Referenced by run(), and stat_timeout().

1254 {
1255  stat_get = NULL;
1256  if (NULL != stat_timeout_task)
1257  {
1259  stat_timeout_task = NULL;
1260  }
1261  plugin = load_plugin();
1262  if (NULL == plugin)
1263  {
1265  filter = NULL;
1266  if (NULL != stats)
1267  {
1269  stats = NULL;
1270  }
1271  return;
1272  }
1273 
1274  if (GNUNET_NO == stats_worked)
1275  {
1277  "Failed to obtain value from statistics service, recomputing it\n");
1280  _("New payload: %lld\n"),
1281  (long long)payload);
1282  }
1283 
1284  if (GNUNET_YES == refresh_bf)
1285  {
1287  _("Rebuilding bloomfilter. Please be patient.\n"));
1288  if (NULL != plugin->api->get_keys)
1289  {
1291  return;
1292  }
1293  else
1294  {
1296  _(
1297  "Plugin does not support get_keys function. Please fix!\n"));
1298  }
1299  }
1300  begin_service();
1301 }
static void add_key_to_bloomfilter(void *cls, const struct GNUNET_HashCode *key, unsigned int count)
Adds a given key to the bloomfilter in cls count times.
PluginGetKeys get_keys
Iterate over all keys in the database.
PluginEstimateSize estimate_size
Calculate the current on-disk size of the SQ store.
#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).
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct DatastorePlugin * load_plugin()
Load the datastore plugin.
static struct GNUNET_STATISTICS_GetHandle * stat_get
Handle for pending get request.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don&#39;t have the content.
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
static int stats_worked
Did we get an answer from statistics?
static int refresh_bf
Should we refresh the BF when the DB is loaded?
static unsigned long long payload
How much data are we currently storing in the database?
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
static void begin_service()
Initialization complete, start operating the service.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associcated with a filter in memory, flush to drive if needed (do not free the space o...
static struct GNUNET_SCHEDULER_Task * stat_timeout_task
Task to timeout stat GET.
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:

◆ stat_timeout()

static void stat_timeout ( void *  cls)
static

Fetching stats took to long, run without.

Parameters
clsNULL

Definition at line 1310 of file gnunet-service-datastore.c.

References GNUNET_NO, GNUNET_STATISTICS_get_cancel(), and process_stat_done().

Referenced by run().

1311 {
1312  stat_timeout_task = NULL;
1315 }
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.
#define GNUNET_NO
Definition: gnunet_common.h:78
static struct GNUNET_STATISTICS_GetHandle * stat_get
Handle for pending get request.
static void process_stat_done(void *cls, int success)
We finished receiving the statistic.
static struct GNUNET_SCHEDULER_Task * stat_timeout_task
Task to timeout stat GET.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleaning_task()

static void cleaning_task ( void *  cls)
static

Task run during shutdown.

Definition at line 1322 of file gnunet-service-datastore.c.

References DatastorePlugin::api, cleaning_done, GNUNET_DATASTORE_PluginFunctions::cls, do_drop, GNUNET_DATASTORE_PluginFunctions::drop, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_STATISTICS_get_cancel(), GNUNET_YES, last_sync, payload, plugin_name, quota_stat_name, sync_stats(), and unload_plugin().

Referenced by run().

1323 {
1325  if (NULL != expired_kill_task)
1326  {
1328  expired_kill_task = NULL;
1329  }
1330  if (GNUNET_YES == do_drop)
1331  {
1332  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n");
1333  plugin->api->drop(plugin->api->cls);
1334  payload = 0;
1335  last_sync++;
1336  }
1337  if (NULL != plugin)
1338  {
1340  plugin = NULL;
1341  }
1342  if (NULL != filter)
1343  {
1345  filter = NULL;
1346  }
1347  if (NULL != stat_get)
1348  {
1350  stat_get = NULL;
1351  }
1352  if (NULL != stat_timeout_task)
1353  {
1355  stat_timeout_task = NULL;
1356  }
1358  plugin_name = NULL;
1359  if (last_sync > 0)
1360  sync_stats();
1361  if (NULL != stats)
1362  {
1364  stats = NULL;
1365  }
1367  quota_stat_name = NULL;
1368 }
static int cleaning_done
Have we already cleaned up the TCCs and are hence no longer willing (or able) to transmit anything to...
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static int do_drop
Should the database be dropped on exit?
static char * quota_stat_name
Name under which we store current space consumption.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
static void sync_stats()
Synchronize our utilization statistics with the statistics service.
PluginDrop drop
Delete the database.
static void unload_plugin(struct DatastorePlugin *plug)
Function called when the service shuts down.
static struct GNUNET_STATISTICS_GetHandle * stat_get
Handle for pending get request.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don&#39;t have the content.
static struct GNUNET_SCHEDULER_Task * expired_kill_task
Identity of the task that is used to delete expired content.
struct GNUNET_DATASTORE_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
static unsigned int last_sync
Number of updates that were made to the payload value since we last synchronized it with the statisti...
static unsigned long long payload
How much data are we currently storing in the database?
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void * cls
Closure to use for all of the following callbacks (except "next_request").
static struct DatastorePlugin * plugin
Our datastore plugin (NULL if not available).
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associcated with a filter in memory, flush to drive if needed (do not free the space o...
static char * plugin_name
Name of our plugin.
#define GNUNET_free(ptr)
Wrapper around free.
static struct GNUNET_SCHEDULER_Task * stat_timeout_task
Task to timeout stat GET.
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:

◆ client_connect_cb()

static void* client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
struct GNUNET_MQ_Handle mq 
)
static

Add a client to our list of active clients.

Parameters
clsNULL
clientclient to add
mqmessage queue for client
Returns
client

Definition at line 1380 of file gnunet-service-datastore.c.

Referenced by run().

1383 {
1384  return client;
1385 }
Here is the caller graph for this function:

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
void *  app_ctx 
)
static

Called whenever a client is disconnected.

Frees our resources associated with that client.

Parameters
clsclosure
clientidentification of the client
app_ctxmust match client

Definition at line 1397 of file gnunet-service-datastore.c.

References ReservationList::amount, ReservationList::client, ReservationList::entries, gettext_noop, GNUNET_assert, GNUNET_DATASTORE_ENTRY_OVERHEAD, GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_set(), ReservationList::next, reservations, and reserved.

Referenced by run().

1400 {
1401  struct ReservationList *pos;
1402  struct ReservationList *prev;
1403  struct ReservationList *next;
1404 
1405  GNUNET_assert(app_ctx == client);
1406  prev = NULL;
1407  pos = reservations;
1408  while (NULL != pos)
1409  {
1410  next = pos->next;
1411  if (pos->client == client)
1412  {
1413  if (NULL == prev)
1414  reservations = next;
1415  else
1416  prev->next = next;
1418  GNUNET_free(pos);
1419  }
1420  else
1421  {
1422  prev = pos;
1423  }
1424  pos = next;
1425  }
1427  gettext_noop("# reserved"),
1428  reserved,
1429  GNUNET_NO);
1430 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t amount
Number of bytes (still) reserved.
#define GNUNET_NO
Definition: gnunet_common.h:78
static struct ReservationList * reservations
Linked list of space reservations made by clients.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
#define GNUNET_DATASTORE_ENTRY_OVERHEAD
How many bytes of overhead will we assume per entry in any DB (for reservations)? ...
struct ReservationList * next
This is a linked list.
uint64_t entries
Number of items (still) reserved.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
static unsigned long long reserved
How much space have we currently reserved?
struct GNUNET_SERVICE_Client * client
Client that made the reservation.
Linked list of active reservations.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_SERVICE_Handle serv 
)
static

Process datastore requests.

Parameters
clsclosure
servthe initialized service
cconfiguration to use

Definition at line 1441 of file gnunet-service-datastore.c.

References _, cache_size, cleaning_task(), client_connect_cb(), client_disconnect_cb(), fn, gettext_noop, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_size(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CONTAINER_bloomfilter_load(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, GNUNET_log, GNUNET_log_config_missing(), GNUNET_MESSAGE_TYPE_DATASTORE_DROP, GNUNET_MESSAGE_TYPE_DATASTORE_GET, GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, GNUNET_MESSAGE_TYPE_DATASTORE_PUT, GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SERVICE_MAIN(), GNUNET_SERVICE_OPTION_NONE, GNUNET_SERVICE_suspend(), GNUNET_STATISTICS_create(), GNUNET_STATISTICS_destroy(), GNUNET_STATISTICS_get(), GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, MAX_BF_SIZE, plugin_name, process_stat_done(), process_stat_in(), quota, quota_stat_name, refresh_bf, and stat_timeout().

1444 {
1445  char *fn;
1446  char *pfn;
1447  unsigned int bf_size;
1448 
1449  service = serv;
1450  cfg = c;
1452  "DATASTORE",
1453  "DATABASE",
1454  &plugin_name))
1455  {
1457  "DATABASE",
1458  "DATASTORE");
1459  return;
1460  }
1462  _("# bytes used in file-sharing datastore `%s'"),
1463  plugin_name);
1464  if (GNUNET_OK !=
1465  GNUNET_CONFIGURATION_get_value_size(cfg, "DATASTORE", "QUOTA", &quota))
1466  {
1467  GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE");
1468  return;
1469  }
1470  stats = GNUNET_STATISTICS_create("datastore", cfg);
1472  cache_size = quota / 8; /* Or should we make this an option? */
1474  gettext_noop("# cache size"),
1475  cache_size,
1476  GNUNET_NO);
1477  if (quota / (32 * 1024LL) > MAX_BF_SIZE)
1478  bf_size = MAX_BF_SIZE;
1479  else
1480  bf_size =
1481  quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */
1482  fn = NULL;
1484  "DATASTORE",
1485  "BLOOMFILTER",
1486  &fn)) ||
1488  {
1490  _("Could not use specified filename `%s' for bloomfilter.\n"),
1491  NULL != fn ? fn : "");
1493  fn = NULL;
1494  }
1495  if (NULL != fn)
1496  {
1497  GNUNET_asprintf(&pfn, "%s.%s", fn, plugin_name);
1498  if (GNUNET_YES == GNUNET_DISK_file_test(pfn))
1499  {
1500  filter =
1502  bf_size,
1503  5); /* approx. 3% false positives at max use */
1504  if (NULL == filter)
1505  {
1506  /* file exists but not valid, remove and try again, but refresh */
1507  if (0 != unlink(pfn))
1508  {
1509  /* failed to remove, run without file */
1511  _("Failed to remove bogus bloomfilter file `%s'\n"),
1512  pfn);
1513  GNUNET_free(pfn);
1514  pfn = NULL;
1516  NULL,
1517  bf_size,
1518  5); /* approx. 3% false positives at max use */
1520  }
1521  else
1522  {
1523  /* try again after remove */
1525  pfn,
1526  bf_size,
1527  5); /* approx. 3% false positives at max use */
1529  if (NULL == filter)
1530  {
1531  /* failed yet again, give up on using file */
1533  _("Failed to remove bogus bloomfilter file `%s'\n"),
1534  pfn);
1535  GNUNET_free(pfn);
1536  pfn = NULL;
1538  NULL,
1539  bf_size,
1540  5); /* approx. 3% false positives at max use */
1541  }
1542  }
1543  }
1544  else
1545  {
1546  /* normal case: have an existing valid bf file, no need to refresh */
1548  }
1549  }
1550  else
1551  {
1552  filter =
1554  bf_size,
1555  5); /* approx. 3% false positives at max use */
1557  }
1558  GNUNET_free(pfn);
1559  }
1560  else
1561  {
1562  filter =
1564  bf_size,
1565  5); /* approx. 3% false positives at max use */
1567  }
1569  if (NULL == filter)
1570  {
1572  _("Failed to initialize bloomfilter.\n"));
1573  if (NULL != stats)
1574  {
1576  stats = NULL;
1577  }
1578  return;
1579  }
1582  "datastore",
1585  &process_stat_in,
1586  NULL);
1587  if (NULL == stat_get)
1589  else
1591  &stat_timeout,
1592  NULL);
1594 }
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:541
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
static struct GNUNET_SERVICE_Handle * service
Handle to our server.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
#define GNUNET_TIME_UNIT_SECONDS
One second.
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:681
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static char * quota_stat_name
Name under which we store current space consumption.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct GNUNET_STATISTICS_GetHandle * stat_get
Handle for pending get request.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1237
static int process_stat_in(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
Callback function to process statistic values.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static char * fn
Filename of the unique file.
static void process_stat_done(void *cls, int success)
We finished receiving the statistic.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_load(const char *filename, size_t size, unsigned int k)
Load a Bloom filter from a file.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don&#39;t have the content.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
int GNUNET_CONFIGURATION_get_value_size(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *size)
Get a configuration value that should be a size in bytes.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static void stat_timeout(void *cls)
Fetching stats took to long, run without.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static int refresh_bf
Should we refresh the BF when the DB is loaded?
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
static unsigned long long quota
How much space are we allowed to use?
static void cleaning_task(void *cls)
Task run during shutdown.
static unsigned long long cache_size
How much space are we using for the cache? (space available for insertions that will be instantly rec...
struct GNUNET_STATISTICS_GetHandle * GNUNET_STATISTICS_get(struct GNUNET_STATISTICS_Handle *handle, const char *subsystem, const char *name, GNUNET_STATISTICS_Callback cont, GNUNET_STATISTICS_Iterator proc, void *cls)
Get statistic from the peer.
#define GNUNET_log(kind,...)
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
#define MAX_BF_SIZE
Limit size of bloom filter to 2 GB.
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_SERVICE_suspend(struct GNUNET_SERVICE_Handle *sh)
Suspend accepting connections from the listen socket temporarily.
Definition: service.c:2173
static char * plugin_name
Name of our plugin.
#define GNUNET_free(ptr)
Wrapper around free.
static struct GNUNET_SCHEDULER_Task * stat_timeout_task
Task to timeout stat GET.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

Define "main" method using service macro.

Referenced by run().

Here is the caller graph for this function:

Variable Documentation

◆ quota_stat_name

char* quota_stat_name
static

Name under which we store current space consumption.

Definition at line 61 of file gnunet-service-datastore.c.

Referenced by cleaning_task(), run(), and sync_stats().

◆ stat_timeout_task

struct GNUNET_SCHEDULER_Task* stat_timeout_task
static

Task to timeout stat GET.

Definition at line 66 of file gnunet-service-datastore.c.

◆ plugin

struct DatastorePlugin* plugin
static

Our datastore plugin (NULL if not available).

Definition at line 137 of file gnunet-service-datastore.c.

◆ reservations

struct ReservationList* reservations
static

Linked list of space reservations made by clients.

Definition at line 142 of file gnunet-service-datastore.c.

Referenced by client_disconnect_cb(), handle_put(), handle_release_reserve(), and handle_reserve().

◆ filter

struct GNUNET_CONTAINER_BloomFilter* filter
static

Bloomfilter to quickly tell if we don't have the content.

Definition at line 147 of file gnunet-service-datastore.c.

Referenced by api_create_hello(), api_send(), get_audiobin(), and main().

◆ plugin_name

char* plugin_name
static

Name of our plugin.

Definition at line 152 of file gnunet-service-datastore.c.

Referenced by cleaning_task(), load_plugin(), and run().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

Definition at line 157 of file gnunet-service-datastore.c.

Referenced by load_plugin().

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

Handle for reporting statistics.

Definition at line 162 of file gnunet-service-datastore.c.

◆ cache_size

unsigned long long cache_size
static

How much space are we using for the cache? (space available for insertions that will be instantly reclaimed by discarding less important content — or possibly whatever we just inserted into the "cache").

Definition at line 170 of file gnunet-service-datastore.c.

Referenced by handle_reserve(), put_continuation(), and run().

◆ reserved

unsigned long long reserved
static

How much space have we currently reserved?

Definition at line 175 of file gnunet-service-datastore.c.

Referenced by client_disconnect_cb(), handle_put(), handle_release_reserve(), handle_reserve(), and put_continuation().

◆ payload

unsigned long long payload
static

◆ expired_kill_task

struct GNUNET_SCHEDULER_Task* expired_kill_task
static

Identity of the task that is used to delete expired content.

Definition at line 187 of file gnunet-service-datastore.c.

◆ min_expiration

struct GNUNET_TIME_Absolute min_expiration
static

Minimum time that content should have to not be discarded instantly (time stamp of any content that we've been discarding recently to stay below the quota).

FOREVER if we had to expire content with non-zero priority.

Definition at line 195 of file gnunet-service-datastore.c.

Referenced by expired_processor(), quota_processor(), and transmit_status().

◆ quota

unsigned long long quota
static

How much space are we allowed to use?

Definition at line 200 of file gnunet-service-datastore.c.

Referenced by GNUNET_DATACACHE_create(), handle_reserve(), put_continuation(), and run().

◆ do_drop

int do_drop
static

Should the database be dropped on exit?

Definition at line 205 of file gnunet-service-datastore.c.

Referenced by cleaning_task(), and handle_drop().

◆ refresh_bf

int refresh_bf
static

Should we refresh the BF when the DB is loaded?

Definition at line 210 of file gnunet-service-datastore.c.

Referenced by process_stat_done(), and run().

◆ last_sync

unsigned int last_sync
static

Number of updates that were made to the payload value since we last synchronized it with the statistics service.

Definition at line 217 of file gnunet-service-datastore.c.

Referenced by cleaning_task(), disk_utilization_change_cb(), and sync_stats().

◆ stats_worked

int stats_worked
static

Did we get an answer from statistics?

Definition at line 222 of file gnunet-service-datastore.c.

Referenced by process_stat_done(), and process_stat_in().

◆ cleaning_done

int cleaning_done
static

Have we already cleaned up the TCCs and are hence no longer willing (or able) to transmit anything to anyone?

Definition at line 245 of file gnunet-service-datastore.c.

Referenced by cleaning_task().

◆ stat_get

struct GNUNET_STATISTICS_GetHandle* stat_get
static

Handle for pending get request.

Definition at line 250 of file gnunet-service-datastore.c.

◆ service

struct GNUNET_SERVICE_Handle* service
static

Handle to our server.

Definition at line 255 of file gnunet-service-datastore.c.