GNUnet 0.21.1
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 iterator for updating. 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}
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
Handle for a plugin.
Definition: block.c:38

References plugin.

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
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.
@ GNUNET_YES
@ GNUNET_NO
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:367
Closure for iterator for updating.
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];
328 value->expire_heap = GNUNET_CONTAINER_heap_insert (plugin->by_expiration,
329 value,
330 expiration.abs_value_us);
331 value->replication_heap = GNUNET_CONTAINER_heap_insert (
332 plugin->by_replication,
333 value,
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 {
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;
367 &value->key,
368 value,
370 plugin->size += size;
371 cont (cont_cls, key, size, GNUNET_OK, NULL);
372}
static unsigned int replication
Desired replication level.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
static unsigned int anonymity
static uint32_t type
Type string converted to DNS type value.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
@ 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_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
#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:68
static int update_iterator(void *cls, const struct GNUNET_HashCode *key, void *val)
Update the matching value.
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.

References anonymity, ZeroAnonByType::array, ZeroAnonByType::array_pos, ZeroAnonByType::array_size, 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, ZeroAnonByType::next, plugin, UpdateContext::priority, replication, size, type, ZeroAnonByType::type, uc, update_iterator(), 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:

◆ 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 {
408 zabt->array_size,
409 0);
411 plugin->zero_tail,
412 zabt);
413 GNUNET_free (zabt);
414 }
415 }
416 plugin->size -= value->size;
418}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
enum GNUNET_GenericReturnValue 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, ZeroAnonByType::next, plugin, ZeroAnonByType::type, value, and Value::zero_anon_offset.

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
Identifier for any block.
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, value, and GetContext::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 {
515 &gc);
516 }
517 else
518 {
520 key,
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_MultiHashMapIteratorCallback 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, key, Value::key, GetContext::next_uid, plugin, Value::priority, GetContext::random, Value::replication, Value::size, type, GetContext::type, Value::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 (
572 plugin->by_replication,
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 (
580 plugin->by_replication,
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 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
614 value = GNUNET_CONTAINER_heap_peek (plugin->by_expiration);
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 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, type, ZeroAnonByType::type, and value.

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;
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, 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, value, and RemoveContext::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.
uint32_t size
Number of bytes in 'data'.

References data, RemoveContext::data, delete_value(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_NO, GNUNET_OK, key, plugin, remove_iterator(), size, RemoveContext::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;
879 plugin->by_expiration = GNUNET_CONTAINER_heap_create (
881 plugin->by_replication = GNUNET_CONTAINER_heap_create (
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
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.
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_ERROR_TYPE_INFO
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
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

References _, Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginEnvironment::cls, 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(), 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);
936 GNUNET_CONTAINER_heap_destroy (plugin->by_expiration);
937 GNUNET_CONTAINER_heap_destroy (plugin->by_replication);
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, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::cls, free_value(), GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, and plugin.

Here is the call graph for this function: