GNUnet  0.11.x
Data Structures | Functions
plugin_datastore_heap.c File Reference

heap-based datastore backend; usually we want the datastore to be persistent, and storing data in the heap is obviously NOT going to be persistent; still, this plugin is useful for testing/benchmarking — but never for production! More...

#include "platform.h"
#include "gnunet_datastore_plugin.h"
Include dependency graph for plugin_datastore_heap.c:

Go to the source code of this file.

Data Structures

struct  Value
 Entry in the hash map. More...
 
struct  ZeroAnonByType
 We organize 0-anonymity values in arrays "by type". More...
 
struct  Plugin
 Handle for a plugin. More...
 
struct  UpdateContext
 Closure for update_rel_sum() and update_abs_sum(). More...
 
struct  GetContext
 Closure for get_cb(). More...
 
struct  GetAllContext
 Closure for the 'return_value' function. More...
 
struct  RemoveContext
 Closure for iterator called during 'remove_key'. More...
 

Functions

static void heap_plugin_estimate_size (void *cls, unsigned long long *estimate)
 Get an estimate of how much space the database is currently using. More...
 
static int update_iterator (void *cls, const struct GNUNET_HashCode *key, void *val)
 Update the matching value. More...
 
static void heap_plugin_put (void *cls, const struct GNUNET_HashCode *key, bool absent, 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, PluginPutCont cont, void *cont_cls)
 Store an item in the datastore. More...
 
static void delete_value (struct Plugin *plugin, struct Value *value)
 Delete the given value, removing it from the plugin's data structures. More...
 
static int get_iterator (void *cls, const struct GNUNET_HashCode *key, void *val)
 Obtain the matching value with the lowest uid >= next_uid. More...
 
static void heap_plugin_get_key (void *cls, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
 Get one of the results for a particular key in the datastore. More...
 
static void heap_plugin_get_replication (void *cls, PluginDatumProcessor proc, void *proc_cls)
 Get a random item for replication. More...
 
static void heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc, void *proc_cls)
 Get a random item for expiration. More...
 
static void heap_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
 Call the given processor on an item with zero anonymity. More...
 
static void heap_plugin_drop (void *cls)
 Drop database. More...
 
static int return_value (void *cls, const struct GNUNET_HashCode *key, void *val)
 Callback invoked to call callback on each value. More...
 
static void heap_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls)
 Get all of the keys in the datastore. More...
 
static int remove_iterator (void *cls, const struct GNUNET_HashCode *key, void *val)
 Obtain the matching value with the lowest uid >= next_uid. More...
 
static void heap_plugin_remove_key (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, PluginRemoveCont cont, void *cont_cls)
 Remove a particular key in the datastore. More...
 
void * libgnunet_plugin_datastore_heap_init (void *cls)
 Entry point for the plugin. More...
 
static int free_value (void *cls, const struct GNUNET_HashCode *key, void *val)
 Callback invoked to free all value. More...
 
void * libgnunet_plugin_datastore_heap_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

heap-based datastore backend; usually we want the datastore to be persistent, and storing data in the heap is obviously NOT going to be persistent; still, this plugin is useful for testing/benchmarking — but never for production!

Author
Christian Grothoff

Definition in file plugin_datastore_heap.c.

Function Documentation

◆ heap_plugin_estimate_size()

static void heap_plugin_estimate_size ( void *  cls,
unsigned long long *  estimate 
)
static

Get an estimate of how much space the database is currently using.

Parameters
clsour "struct Plugin*"
Returns
number of bytes used on disk

Definition at line 184 of file plugin_datastore_heap.c.

185 {
186  struct Plugin *plugin = cls;
187 
188  if (NULL != estimate)
189  *estimate = plugin->size;
190 }
struct Plugin * plugin
The process handle to the testbed service.
Handle for a plugin.
Definition: block.c:38
unsigned long long size
Size of all values we're storing.

References plugin, and Plugin::size.

Referenced by libgnunet_plugin_datastore_heap_init().

Here is the caller graph for this function:

◆ update_iterator()

static int update_iterator ( void *  cls,
const struct GNUNET_HashCode key,
void *  val 
)
static

Update the matching value.

Parameters
clsthe 'struct UpdateContext'
keyunused
valthe 'struct Value'
Returns
GNUNET_YES (continue iteration), GNUNET_NO if value was found

Definition at line 239 of file plugin_datastore_heap.c.

242 {
243  struct UpdateContext *uc = cls;
244  struct Value *value = val;
245 
246  if (value->size != uc->size)
247  return GNUNET_YES;
248  if (0 != memcmp (value->data, uc->data, uc->size))
249  return GNUNET_YES;
250  uc->expiration = GNUNET_TIME_absolute_max (value->expiration,
251  uc->expiration);
252  if (value->expiration.abs_value_us != uc->expiration.abs_value_us)
253  {
254  value->expiration = uc->expiration;
256  value->expiration.abs_value_us);
257  }
258  /* Saturating adds, don't overflow */
259  if (value->priority > UINT32_MAX - uc->priority)
260  value->priority = UINT32_MAX;
261  else
262  value->priority += uc->priority;
263  if (value->replication > UINT32_MAX - uc->replication)
264  value->replication = UINT32_MAX;
265  else
266  value->replication += uc->replication;
267  uc->updated = true;
268  return GNUNET_NO;
269 }
static char * value
Value of the record to add/remove.
static struct GNUNET_FS_UnindexContext * uc
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
void GNUNET_CONTAINER_heap_update_cost(struct GNUNET_CONTAINER_HeapNode *node, GNUNET_CONTAINER_HeapCostType new_cost)
Updates the cost of any node in the tree.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the maximum of two absolute time values.
Definition: time.c:224
Closure for update_rel_sum() and update_abs_sum().
Entry in the hash map.

References GNUNET_CONTAINER_heap_update_cost(), GNUNET_NO, GNUNET_TIME_absolute_max(), GNUNET_YES, uc, and value.

Referenced by heap_plugin_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ heap_plugin_put()

static void heap_plugin_put ( void *  cls,
const struct GNUNET_HashCode key,
bool  absent,
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,
PluginPutCont  cont,
void *  cont_cls 
)
static

Store an item in the datastore.

Parameters
clsclosure
keykey for the item
absenttrue if the key was not found in the bloom filter
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
contcontinuation called with success or failure status
cont_clscontinuation closure

Definition at line 289 of file plugin_datastore_heap.c.

301 {
302  struct Plugin *plugin = cls;
303  struct Value *value;
304 
305  if (! absent)
306  {
307  struct UpdateContext uc;
308 
309  uc.size = size;
310  uc.data = data;
311  uc.priority = priority;
312  uc.replication = replication;
313  uc.expiration = expiration;
314  uc.updated = false;
316  key,
318  &uc);
319  if (uc.updated)
320  {
321  cont (cont_cls, key, size, GNUNET_NO, NULL);
322  return;
323  }
324  }
325  value = GNUNET_malloc (sizeof(struct Value) + size);
326  value->key = *key;
327  value->data = &value[1];
329  value,
330  expiration.abs_value_us);
331  value->replication_heap = GNUNET_CONTAINER_heap_insert (
333  value,
334  replication);
335  value->expiration = expiration;
336  if (0 == anonymity)
337  {
338  struct ZeroAnonByType *zabt;
339 
340  for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
341  if (zabt->type == type)
342  break;
343  if (NULL == zabt)
344  {
345  zabt = GNUNET_new (struct ZeroAnonByType);
346  zabt->type = type;
348  plugin->zero_tail,
349  zabt);
350  }
351  if (zabt->array_size == zabt->array_pos)
352  {
353  GNUNET_array_grow (zabt->array,
354  zabt->array_size,
355  zabt->array_size * 2 + 4);
356  }
357  value->zero_anon_offset = zabt->array_pos;
358  zabt->array[zabt->array_pos++] = value;
359  }
360  value->size = size;
361  value->priority = priority;
362  value->anonymity = anonymity;
363  value->replication = replication;
364  value->type = type;
365  GNUNET_memcpy (&value[1], data, size);
367  &value->key,
368  value,
370  plugin->size += size;
371  cont (cont_cls, key, size, GNUNET_OK, NULL);
372 }
static char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
static unsigned int replication
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int anonymity
uint32_t data
The data value.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
static unsigned int size
Size of the "table".
Definition: peer.c:67
static int update_iterator(void *cls, const struct GNUNET_HashCode *key, void *val)
Update the matching value.
struct ZeroAnonByType * zero_head
Head of list of arrays containing zero-anonymity values by type.
struct GNUNET_CONTAINER_Heap * by_replication
Heap organized by maximum replication value.
struct ZeroAnonByType * zero_tail
Tail of list of arrays containing zero-anonymity values by type.
struct GNUNET_CONTAINER_MultiHashMap * keyvalue
Mapping from keys to 'struct Value's.
struct GNUNET_CONTAINER_Heap * by_expiration
Heap organized by minimum expiration time.
uint32_t priority
Priority of the value.
We organize 0-anonymity values in arrays "by type".
unsigned int array_pos
First unused offset in 'array'.
unsigned int array_size
Allocated size of the array.
struct ZeroAnonByType * next
We keep these in a DLL.
enum GNUNET_BLOCK_Type type
Type of all of the values in 'array'.
struct Value ** array
Array of 0-anonymity items of the given type.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References anonymity, ZeroAnonByType::array, ZeroAnonByType::array_pos, ZeroAnonByType::array_size, Plugin::by_expiration, Plugin::by_replication, data, expiration, GNUNET_array_grow, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, key, Plugin::keyvalue, ZeroAnonByType::next, plugin, UpdateContext::priority, replication, Plugin::size, size, ZeroAnonByType::type, type, uc, update_iterator(), value, Plugin::zero_head, and Plugin::zero_tail.

Referenced by libgnunet_plugin_datastore_heap_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_value()

static void delete_value ( struct Plugin plugin,
struct Value value 
)
static

Delete the given value, removing it from the plugin's data structures.

Parameters
pluginthe plugin
valuevalue to delete

Definition at line 383 of file plugin_datastore_heap.c.

385 {
388  &value->key,
389  value));
391  value->expire_heap));
393  value->replication_heap));
394  if (0 == value->anonymity)
395  {
396  struct ZeroAnonByType *zabt;
397 
398  for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
399  if (zabt->type == value->type)
400  break;
401  GNUNET_assert (NULL != zabt);
402  zabt->array[value->zero_anon_offset] = zabt->array[--zabt->array_pos];
403  zabt->array[value->zero_anon_offset]->zero_anon_offset =
404  value->zero_anon_offset;
405  if (0 == zabt->array_pos)
406  {
407  GNUNET_array_grow (zabt->array,
408  zabt->array_size,
409  0);
411  plugin->zero_tail,
412  zabt);
413  GNUNET_free (zabt);
414  }
415  }
416  plugin->size -= value->size;
417  GNUNET_free (value);
418 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.
unsigned int zero_anon_offset
Offset of this value in the array of the 'struct ZeroAnonByType'; only used if anonymity is zero.

References ZeroAnonByType::array, ZeroAnonByType::array_pos, ZeroAnonByType::array_size, GNUNET_array_grow, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_YES, Plugin::keyvalue, ZeroAnonByType::next, plugin, Plugin::size, ZeroAnonByType::type, value, Value::zero_anon_offset, Plugin::zero_head, and Plugin::zero_tail.

Referenced by free_value(), heap_plugin_get_expiration(), and heap_plugin_remove_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_iterator()

static int get_iterator ( void *  cls,
const struct GNUNET_HashCode key,
void *  val 
)
static

Obtain the matching value with the lowest uid >= next_uid.

Parameters
clsthe 'struct GetContext'
keyunused
valthe 'struct Value'
Returns
GNUNET_YES (continue iteration), GNUNET_NO if result was found

Definition at line 457 of file plugin_datastore_heap.c.

460 {
461  struct GetContext *gc = cls;
462  struct Value *value = val;
463 
464  if ((gc->type != GNUNET_BLOCK_TYPE_ANY) &&
465  (gc->type != value->type))
466  return GNUNET_OK;
467  if (gc->random)
468  {
469  gc->value = value;
470  return GNUNET_NO;
471  }
472  if ((uint64_t) (intptr_t) value < gc->next_uid)
473  return GNUNET_OK;
474  if ((NULL != gc->value) &&
475  (value > gc->value))
476  return GNUNET_OK;
477  gc->value = value;
478  return GNUNET_OK;
479 }
@ GNUNET_BLOCK_TYPE_ANY
Any type of block, used as a wildcard when searching.
Closure for get_cb().
enum GNUNET_BLOCK_Type type
Block type requested.
bool random
If true, return a random value.
struct Value * value
Value with lowest uid >= next_uid found so far.

References GNUNET_BLOCK_TYPE_ANY, GNUNET_NO, GNUNET_OK, GetContext::random, GetContext::type, GetContext::value, and value.

Referenced by heap_plugin_get_key().

Here is the caller graph for this function:

◆ heap_plugin_get_key()

static void heap_plugin_get_key ( void *  cls,
uint64_t  next_uid,
bool  random,
const struct GNUNET_HashCode key,
enum GNUNET_BLOCK_Type  type,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get one of the results for a particular key in the datastore.

Parameters
clsclosure
next_uidreturn the result with lowest uid >= next_uid
randomif true, return a random result instead of using next_uid
keymaybe NULL (to match all entries)
typeentries of which type are relevant? Use 0 for any type.
procfunction to call on the matching value; will be called with NULL if nothing matches
proc_clsclosure for proc

Definition at line 496 of file plugin_datastore_heap.c.

503 {
504  struct Plugin *plugin = cls;
505  struct GetContext gc;
506 
507  gc.value = NULL;
508  gc.next_uid = next_uid;
509  gc.random = random;
510  gc.type = type;
511  if (NULL == key)
512  {
514  &get_iterator,
515  &gc);
516  }
517  else
518  {
520  key,
521  &get_iterator,
522  &gc);
523  }
524  if (NULL == gc.value)
525  {
526  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
527  return;
528  }
530  proc (proc_cls,
531  &gc.value->key,
532  gc.value->size,
533  &gc.value[1],
534  gc.value->type,
535  gc.value->priority,
536  gc.value->anonymity,
537  gc.value->replication,
538  gc.value->expiration,
539  (uint64_t) (intptr_t) gc.value));
540 }
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static int get_iterator(void *cls, const struct GNUNET_HashCode *key, void *val)
Obtain the matching value with the lowest uid >= next_uid.
uint64_t next_uid
Lowest uid to consider.

References Value::anonymity, Value::expiration, get_iterator(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, Value::key, key, Plugin::keyvalue, GetContext::next_uid, plugin, Value::priority, GetContext::random, Value::replication, Value::size, Value::type, GetContext::type, type, and GetContext::value.

Referenced by libgnunet_plugin_datastore_heap_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ heap_plugin_get_replication()

static void heap_plugin_get_replication ( void *  cls,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get a random item for replication.

Returns a single, not expired, random item from those with the highest replication counters. The item's replication counter is decremented by one IF it was positive before. Call 'proc' with all values ZERO or NULL if the datastore is empty.

Parameters
clsclosure
procfunction to call the value (once only).
proc_clsclosure for proc

Definition at line 555 of file plugin_datastore_heap.c.

558 {
559  struct Plugin *plugin = cls;
560  struct Value *value;
561 
563  if (NULL == value)
564  {
565  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
566  return;
567  }
568  if (value->replication > 0)
569  {
570  value->replication--;
571  value->replication_heap = GNUNET_CONTAINER_heap_insert (
573  value,
574  value->replication);
575  }
576  else
577  {
578  /* need a better way to pick a random item, replication level is always 0 */
579  value->replication_heap = GNUNET_CONTAINER_heap_insert (
581  value,
582  value->replication);
584  }
586  proc (proc_cls,
587  &value->key,
588  value->size,
589  &value[1],
590  value->type,
591  value->priority,
592  value->anonymity,
593  value->replication,
594  value->expiration,
595  (uint64_t) (intptr_t) value));
596 }
void * GNUNET_CONTAINER_heap_remove_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
void * GNUNET_CONTAINER_heap_walk_get_next(struct GNUNET_CONTAINER_Heap *heap)
Perform a random walk of the tree.

References Plugin::by_replication, GNUNET_assert, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_heap_remove_root(), GNUNET_CONTAINER_heap_walk_get_next(), GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, plugin, and value.

Referenced by libgnunet_plugin_datastore_heap_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ heap_plugin_get_expiration()

static void heap_plugin_get_expiration ( void *  cls,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get a random item for expiration.

Call 'proc' with all values ZERO or NULL if the datastore is empty.

Parameters
clsclosure
procfunction to call the value (once only).
proc_clsclosure for proc

Definition at line 608 of file plugin_datastore_heap.c.

610 {
611  struct Plugin *plugin = cls;
612  struct Value *value;
613 
615  if (NULL == value)
616  {
617  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
618  return;
619  }
620  if (GNUNET_NO ==
621  proc (proc_cls,
622  &value->key,
623  value->size,
624  &value[1],
625  value->type,
626  value->priority,
627  value->anonymity,
628  value->replication,
629  value->expiration,
630  (uint64_t) (intptr_t) value))
632 }
void * GNUNET_CONTAINER_heap_peek(const struct GNUNET_CONTAINER_Heap *heap)
Get element stored at the root of heap.
static void delete_value(struct Plugin *plugin, struct Value *value)
Delete the given value, removing it from the plugin's data structures.

References Plugin::by_expiration, delete_value(), GNUNET_CONTAINER_heap_peek(), GNUNET_NO, GNUNET_TIME_UNIT_ZERO_ABS, plugin, and value.

Referenced by libgnunet_plugin_datastore_heap_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ heap_plugin_get_zero_anonymity()

static void heap_plugin_get_zero_anonymity ( void *  cls,
uint64_t  next_uid,
enum GNUNET_BLOCK_Type  type,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Call the given processor on an item with zero anonymity.

Parameters
clsour "struct Plugin*"
next_uidreturn the result with lowest uid >= next_uid
typeentries of which type should be considered? Must not be zero (ANY).
procfunction to call on each matching value; will be called with NULL if no value matches
proc_clsclosure for proc

Definition at line 647 of file plugin_datastore_heap.c.

650 {
651  struct Plugin *plugin = cls;
652  struct ZeroAnonByType *zabt;
653  struct Value *value = NULL;
654 
655  for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
656  {
657  if ((type != GNUNET_BLOCK_TYPE_ANY) &&
658  (type != zabt->type))
659  continue;
660  for (int i = 0; i < zabt->array_pos; ++i)
661  {
662  if ((uint64_t) (intptr_t) zabt->array[i] < next_uid)
663  continue;
664  if ((NULL != value) &&
665  (zabt->array[i] > value))
666  continue;
667  value = zabt->array[i];
668  }
669  }
670  if (NULL == value)
671  {
672  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
673  return;
674  }
676  proc (proc_cls,
677  &value->key,
678  value->size,
679  &value[1],
680  value->type,
681  value->priority,
682  value->anonymity,
683  value->replication,
684  value->expiration,
685  (uint64_t) (intptr_t) value));
686 }

References ZeroAnonByType::array, ZeroAnonByType::array_pos, GNUNET_assert, GNUNET_BLOCK_TYPE_ANY, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, ZeroAnonByType::next, plugin, ZeroAnonByType::type, type, value, and Plugin::zero_head.

Referenced by libgnunet_plugin_datastore_heap_init().

Here is the caller graph for this function:

◆ heap_plugin_drop()

static void heap_plugin_drop ( void *  cls)
static

Drop database.

Definition at line 693 of file plugin_datastore_heap.c.

694 {
695  /* nothing needs to be done */
696 }

Referenced by libgnunet_plugin_datastore_heap_init().

Here is the caller graph for this function:

◆ return_value()

static int return_value ( void *  cls,
const struct GNUNET_HashCode key,
void *  val 
)
static

Callback invoked to call callback on each value.

Parameters
clsthe plugin
keyunused
valthe value
Returns
GNUNET_OK (continue to iterate)

Definition at line 725 of file plugin_datastore_heap.c.

728 {
729  struct GetAllContext *gac = cls;
730 
731  gac->proc (gac->proc_cls,
732  key,
733  1);
734  return GNUNET_OK;
735 }
Closure for the 'return_value' function.
void * proc_cls
Closure for 'proc'.
PluginKeyProcessor proc
Function to call.

References GNUNET_OK, key, GetAllContext::proc, and GetAllContext::proc_cls.

Referenced by heap_get_keys().

Here is the caller graph for this function:

◆ heap_get_keys()

static void heap_get_keys ( void *  cls,
PluginKeyProcessor  proc,
void *  proc_cls 
)
static

Get all of the keys in the datastore.

Parameters
clsclosure
procfunction to call on each key
proc_clsclosure for proc

Definition at line 746 of file plugin_datastore_heap.c.

749 {
750  struct Plugin *plugin = cls;
751  struct GetAllContext gac;
752 
753  gac.proc = proc;
754  gac.proc_cls = proc_cls;
756  &return_value,
757  &gac);
758  proc (proc_cls, NULL, 0);
759 }
static int return_value(void *cls, const struct GNUNET_HashCode *key, void *val)
Callback invoked to call callback on each value.

References GNUNET_CONTAINER_multihashmap_iterate(), Plugin::keyvalue, plugin, GetAllContext::proc, GetAllContext::proc_cls, and return_value().

Referenced by libgnunet_plugin_datastore_heap_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_iterator()

static int remove_iterator ( void *  cls,
const struct GNUNET_HashCode key,
void *  val 
)
static

Obtain the matching value with the lowest uid >= next_uid.

Parameters
clsthe 'struct GetContext'
keyunused
valthe 'struct Value'
Returns
GNUNET_YES (continue iteration), GNUNET_NO if result was found

Definition at line 793 of file plugin_datastore_heap.c.

796 {
797  struct RemoveContext *rc = cls;
798  struct Value *value = val;
799 
800  if (value->size != rc->size)
801  return GNUNET_YES;
802  if (0 != memcmp (value->data, rc->data, rc->size))
803  return GNUNET_YES;
804  rc->value = value;
805  return GNUNET_NO;
806 }
Closure for iterator called during 'remove_key'.
uint32_t size
Size of data.
const void * data
Data to remove.
struct Value * value
Value found.

References RemoveContext::data, GNUNET_NO, GNUNET_YES, RemoveContext::size, RemoveContext::value, and value.

Referenced by heap_plugin_remove_key().

Here is the caller graph for this function:

◆ heap_plugin_remove_key()

static void heap_plugin_remove_key ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  size,
const void *  data,
PluginRemoveCont  cont,
void *  cont_cls 
)
static

Remove a particular key in the datastore.

Parameters
clsclosure
keykey for the content
sizenumber of bytes in data
datacontent stored
contcontinuation called with success or failure status
cont_clscontinuation closure for cont

Definition at line 820 of file plugin_datastore_heap.c.

826 {
827  struct Plugin *plugin = cls;
828  struct RemoveContext rc;
829 
830  rc.value = NULL;
831  rc.size = size;
832  rc.data = data;
834  key,
836  &rc);
837  if (NULL == rc.value)
838  {
839  cont (cont_cls,
840  key,
841  size,
842  GNUNET_NO,
843  NULL);
844  return;
845  }
847  rc.value);
848  cont (cont_cls,
849  key,
850  size,
851  GNUNET_OK,
852  NULL);
853 }
static int remove_iterator(void *cls, const struct GNUNET_HashCode *key, void *val)
Obtain the matching value with the lowest uid >= next_uid.
size_t size
Payload (actual payload follows this struct)

References RemoveContext::data, data, delete_value(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_NO, GNUNET_OK, key, Plugin::keyvalue, plugin, remove_iterator(), RemoveContext::size, size, and RemoveContext::value.

Referenced by libgnunet_plugin_datastore_heap_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_datastore_heap_init()

void* libgnunet_plugin_datastore_heap_init ( void *  cls)

Entry point for the plugin.

Parameters
clsthe "struct GNUNET_DATASTORE_PluginEnvironment*"
Returns
our "struct Plugin*"

Definition at line 863 of file plugin_datastore_heap.c.

864 {
867  struct Plugin *plugin;
868  unsigned long long esize;
869 
870  if (GNUNET_OK !=
872  "datastore-heap",
873  "HASHMAPSIZE",
874  &esize))
875  esize = 128 * 1024;
876  plugin = GNUNET_new (struct Plugin);
877  plugin->env = env;
884  api->cls = plugin;
885  api->estimate_size = &heap_plugin_estimate_size;
886  api->put = &heap_plugin_put;
888  api->get_replication = &heap_plugin_get_replication;
889  api->get_expiration = &heap_plugin_get_expiration;
890  api->get_zero_anonymity = &heap_plugin_get_zero_anonymity;
891  api->drop = &heap_plugin_drop;
892  api->get_keys = &heap_get_keys;
893  api->remove_key = &heap_plugin_remove_key;
895  _ ("Heap database running\n"));
896  return api;
897 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log_from(kind, comp,...)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
@ GNUNET_CONTAINER_HEAP_ORDER_MIN
Heap with the minimum cost at the root.
@ GNUNET_CONTAINER_HEAP_ORDER_MAX
Heap with the maximum cost at the root.
@ GNUNET_ERROR_TYPE_INFO
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
static void heap_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
Call the given processor on an item with zero anonymity.
static void heap_plugin_get_key(void *cls, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
Get one of the results for a particular key in the datastore.
static void heap_plugin_get_replication(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for replication.
static void heap_plugin_estimate_size(void *cls, unsigned long long *estimate)
Get an estimate of how much space the database is currently using.
static void heap_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls)
Get all of the keys in the datastore.
static void heap_plugin_drop(void *cls)
Drop database.
static void heap_plugin_remove_key(void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, PluginRemoveCont cont, void *cont_cls)
Remove a particular key in the datastore.
static void heap_plugin_put(void *cls, const struct GNUNET_HashCode *key, bool absent, 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, PluginPutCont cont, void *cont_cls)
Store an item in the datastore.
static void heap_plugin_get_expiration(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for expiration.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
void * cls
Closure for all of the callbacks.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.

References _, Plugin::api, Plugin::by_expiration, Plugin::by_replication, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginEnvironment::cls, env, Plugin::env, GNUNET_BLOCK_PluginFunctions::get_key, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONTAINER_heap_create(), GNUNET_CONTAINER_HEAP_ORDER_MAX, GNUNET_CONTAINER_HEAP_ORDER_MIN, GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_INFO, GNUNET_log_from, GNUNET_new, GNUNET_OK, GNUNET_YES, heap_get_keys(), heap_plugin_drop(), heap_plugin_estimate_size(), heap_plugin_get_expiration(), heap_plugin_get_key(), heap_plugin_get_replication(), heap_plugin_get_zero_anonymity(), heap_plugin_put(), heap_plugin_remove_key(), Plugin::keyvalue, and plugin.

Here is the call graph for this function:

◆ free_value()

static int free_value ( void *  cls,
const struct GNUNET_HashCode key,
void *  val 
)
static

Callback invoked to free all value.

Parameters
clsthe plugin
keyunused
valthe value
Returns
GNUNET_OK (continue to iterate)

Definition at line 909 of file plugin_datastore_heap.c.

912 {
913  struct Plugin *plugin = cls;
914  struct Value *value = val;
915 
917  return GNUNET_OK;
918 }

References delete_value(), GNUNET_OK, plugin, and value.

Referenced by libgnunet_plugin_datastore_heap_done().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_datastore_heap_done()

void* libgnunet_plugin_datastore_heap_done ( void *  cls)

Exit point from the plugin.

Parameters
clsour "struct Plugin*"
Returns
always NULL

Definition at line 927 of file plugin_datastore_heap.c.

928 {
930  struct Plugin *plugin = api->cls;
931 
933  &free_value,
934  plugin);
939  GNUNET_free (api);
940  return NULL;
941 }
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
static int free_value(void *cls, const struct GNUNET_HashCode *key, void *val)
Callback invoked to free all value.
void * cls
Closure to use for all of the following callbacks (except "next_request").

References Plugin::api, Plugin::by_expiration, Plugin::by_replication, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::cls, free_value(), GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, Plugin::keyvalue, and plugin.

Here is the call graph for this function: