GNUnet  0.11.x
Data Structures | Macros | Functions
plugin_datacache_heap.c File Reference

heap-only implementation of a database backend for the datacache More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_datacache_plugin.h"
Include dependency graph for plugin_datacache_heap.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  Value
 Entry in the hash map. More...
 
struct  PutContext
 Closure for put_cb(). More...
 
struct  GetContext
 Closure for get_cb(). More...
 
struct  GetClosestContext
 Closure for find_closest(). More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "datacache-heap", __VA_ARGS__)
 
#define LOG_STRERROR_FILE(kind, op, fn)
 
#define NUM_HEAPS   24
 
#define OVERHEAD   (sizeof(struct Value) + 64)
 

Functions

static int put_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
 Function called during PUT to detect if an equivalent block already exists. More...
 
static ssize_t heap_plugin_put (void *cls, const struct GNUNET_HashCode *key, uint32_t xor_distance, size_t size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time, unsigned int path_info_len, const struct GNUNET_PeerIdentity *path_info)
 Store an item in the datastore. More...
 
static int get_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
 Function called during GET to find matching blocks. More...
 
static unsigned int heap_plugin_get (void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
 Iterate over the results for a particular key in the datastore. More...
 
static int heap_plugin_del (void *cls)
 Delete the entry with the lowest expiration value from the datacache right now. More...
 
static unsigned int heap_plugin_get_random (void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
 Return a random value from the datastore. More...
 
static int find_closest (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static unsigned int heap_plugin_get_closest (void *cls, const struct GNUNET_HashCode *key, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
 Iterate over the results that are "close" to a particular key in the datacache. More...
 
void * libgnunet_plugin_datacache_heap_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_datacache_heap_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

heap-only implementation of a database backend for the datacache

Author
Christian Grothoff

Definition in file plugin_datacache_heap.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "datacache-heap", __VA_ARGS__)

Definition at line 30 of file plugin_datacache_heap.c.

◆ LOG_STRERROR_FILE

#define LOG_STRERROR_FILE (   kind,
  op,
  fn 
)
Value:
"datacache-heap", \
op, fn)
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
#define GNUNET_log_from_strerror_file(level, component, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...

Definition at line 32 of file plugin_datacache_heap.c.

◆ NUM_HEAPS

#define NUM_HEAPS   24

Definition at line 36 of file plugin_datacache_heap.c.

◆ OVERHEAD

#define OVERHEAD   (sizeof(struct Value) + 64)

Definition at line 107 of file plugin_datacache_heap.c.

Function Documentation

◆ put_cb()

static int put_cb ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Function called during PUT to detect if an equivalent block already exists.

Parameters
clsthe struct PutContext
keythe key for the value(s)
valuean existing value
Returns
GNUNET_YES if not found (to continue to iterate)

Definition at line 162 of file plugin_datacache_heap.c.

165 {
166  struct PutContext *put_ctx = cls;
167  struct Value *val = value;
168 
169  if ((val->size == put_ctx->size) &&
170  (val->type == put_ctx->type) &&
171  (0 == memcmp (&val[1],
172  put_ctx->data,
173  put_ctx->size)))
174  {
175  put_ctx->found = GNUNET_YES;
177  put_ctx->discard_time);
178  /* replace old path with new path */
180  val->path_info_len,
181  put_ctx->path_info_len);
182  GNUNET_memcpy (val->path_info,
183  put_ctx->path_info,
184  put_ctx->path_info_len * sizeof(struct GNUNET_PeerIdentity));
188  "Got same value for key %s and type %d (size %u vs %u)\n",
189  GNUNET_h2s (key),
190  val->type,
191  (unsigned int) val->size,
192  (unsigned int) put_ctx->size);
193  return GNUNET_NO;
194  }
195  return GNUNET_YES;
196 }
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ 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.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
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
The identity of the host (wraps the signing key of the peer).
uint64_t abs_value_us
The actual value.
Closure for put_cb().
unsigned int path_info_len
Number of entries in path_info.
enum GNUNET_BLOCK_Type type
Type of the node.
int found
Value to set to GNUNET_YES if an equivalent block was found.
struct GNUNET_TIME_Absolute discard_time
Expiration time for the new value.
size_t size
Number of bytes in data.
const struct GNUNET_PeerIdentity * path_info
Path information.
const char * data
Data for the new value.
Entry in the hash map.
struct GNUNET_PeerIdentity * path_info
Path information.
size_t size
Payload (actual payload follows this struct)
struct GNUNET_CONTAINER_HeapNode * hn
Corresponding node in the heap.
enum GNUNET_BLOCK_Type type
Type of the block.
struct GNUNET_TIME_Absolute discard_time
Expiration time.
unsigned int path_info_len
Number of entries in path_info.

References GNUNET_TIME_Absolute::abs_value_us, PutContext::data, Value::discard_time, PutContext::discard_time, PutContext::found, GNUNET_array_grow, GNUNET_CONTAINER_heap_update_cost(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_TIME_absolute_max(), GNUNET_YES, Value::hn, key, Value::path_info, PutContext::path_info, Value::path_info_len, PutContext::path_info_len, Value::size, PutContext::size, Value::type, PutContext::type, and value.

Referenced by GNUNET_DHT_monitor_start(), and heap_plugin_put().

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

◆ heap_plugin_put()

static ssize_t heap_plugin_put ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  xor_distance,
size_t  size,
const char *  data,
enum GNUNET_BLOCK_Type  type,
struct GNUNET_TIME_Absolute  discard_time,
unsigned int  path_info_len,
const struct GNUNET_PeerIdentity path_info 
)
static

Store an item in the datastore.

Parameters
clsclosure (our struct Plugin)
keykey to store data under
xor_distancehow close is key to our PID?
sizenumber of bytes in data
datadata to store
typetype of the value
discard_timewhen to discard the value in any case
path_info_lennumber of entries in path_info
path_infoa path through the network
Returns
0 if duplicate, -1 on error, number of bytes used otherwise

Definition at line 214 of file plugin_datacache_heap.c.

223 {
224  struct Plugin *plugin = cls;
225  struct Value *val;
226  struct PutContext put_ctx;
227 
228  put_ctx.found = GNUNET_NO;
229  put_ctx.data = data;
230  put_ctx.size = size;
231  put_ctx.path_info = path_info;
232  put_ctx.path_info_len = path_info_len;
233  put_ctx.discard_time = discard_time;
234  put_ctx.type = type;
236  key,
237  &put_cb,
238  &put_ctx);
239  if (GNUNET_YES == put_ctx.found)
240  return 0;
241  val = GNUNET_malloc (sizeof(struct Value) + size);
242  GNUNET_memcpy (&val[1],
243  data,
244  size);
245  val->key = *key;
246  val->type = type;
247  val->discard_time = discard_time;
248  val->size = size;
249  if (xor_distance >= NUM_HEAPS)
250  val->distance = NUM_HEAPS - 1;
251  else
252  val->distance = xor_distance;
254  val->path_info_len,
255  path_info_len);
256  GNUNET_memcpy (val->path_info,
257  path_info,
258  path_info_len * sizeof(struct GNUNET_PeerIdentity));
260  &val->key,
261  val,
264  val,
266  return size + OVERHEAD;
267 }
struct Plugin * plugin
The process handle to the testbed service.
uint32_t data
The data value.
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_malloc(size)
Wrapper around malloc.
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define OVERHEAD
static int put_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
Function called during PUT to detect if an equivalent block already exists.
#define NUM_HEAPS
Handle for a plugin.
Definition: block.c:38
struct GNUNET_CONTAINER_MultiHashMap * map
Our hash map.
struct GNUNET_CONTAINER_Heap * heaps[24]
Heaps sorted by distance.
struct GNUNET_HashCode key
Key for the entry.
uint32_t distance
How close is the hash to us? Determines which heap we are in!
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References GNUNET_TIME_Absolute::abs_value_us, PutContext::data, data, Value::discard_time, PutContext::discard_time, Value::distance, PutContext::found, GNUNET_array_grow, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_YES, Plugin::heaps, Value::hn, Value::key, key, Plugin::map, NUM_HEAPS, OVERHEAD, Value::path_info, PutContext::path_info, Value::path_info_len, PutContext::path_info_len, plugin, put_cb(), Value::size, PutContext::size, size, Value::type, PutContext::type, and type.

Referenced by libgnunet_plugin_datacache_heap_init().

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

◆ get_cb()

static int get_cb ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Function called during GET to find matching blocks.

Only matches by type.

Parameters
clsthe struct GetContext
keythe key for the value(s)
valuean existing value
Returns
GNUNET_YES to continue to iterate

Definition at line 307 of file plugin_datacache_heap.c.

310 {
311  struct GetContext *get_ctx = cls;
312  struct Value *val = value;
313  int ret;
314 
315  if ((get_ctx->type != val->type) &&
316  (GNUNET_BLOCK_TYPE_ANY != get_ctx->type))
317  return GNUNET_OK;
318  if (0 ==
320  return GNUNET_OK;
321  if (NULL != get_ctx->iter)
322  ret = get_ctx->iter (get_ctx->iter_cls,
323  key,
324  val->size,
325  (const char *) &val[1],
326  val->type,
327  val->discard_time,
328  val->path_info_len,
329  val->path_info);
330  else
331  ret = GNUNET_YES;
332  get_ctx->cnt++;
333  return ret;
334 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_BLOCK_TYPE_ANY
Any type of block, used as a wildcard when searching.
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:232
uint64_t rel_value_us
The actual value.
Closure for get_cb().
void * iter_cls
Closure for iter.
enum GNUNET_BLOCK_Type type
Block type requested.
GNUNET_DATACACHE_Iterator iter
Function to call for each result.
unsigned int cnt
Number of results found.

References GetContext::cnt, Value::discard_time, GNUNET_BLOCK_TYPE_ANY, GNUNET_OK, GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, GetContext::iter, GetContext::iter_cls, key, Value::path_info, Value::path_info_len, GNUNET_TIME_Relative::rel_value_us, ret, Value::size, Value::type, GetContext::type, and value.

Referenced by GNUNET_DHT_monitor_start(), heap_plugin_get(), and heap_plugin_get_random().

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

◆ heap_plugin_get()

static unsigned int heap_plugin_get ( void *  cls,
const struct GNUNET_HashCode key,
enum GNUNET_BLOCK_Type  type,
GNUNET_DATACACHE_Iterator  iter,
void *  iter_cls 
)
static

Iterate over the results for a particular key in the datastore.

Parameters
clsclosure (our struct Plugin)
key
typeentries of which type are relevant?
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found

Definition at line 349 of file plugin_datacache_heap.c.

354 {
355  struct Plugin *plugin = cls;
356  struct GetContext get_ctx;
357 
358  get_ctx.type = type;
359  get_ctx.iter = iter;
360  get_ctx.iter_cls = iter_cls;
361  get_ctx.cnt = 0;
363  key,
364  &get_cb,
365  &get_ctx);
366  return get_ctx.cnt;
367 }
static int get_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
Function called during GET to find matching blocks.

References GetContext::cnt, get_cb(), GNUNET_CONTAINER_multihashmap_get_multiple(), GetContext::iter, GetContext::iter_cls, key, Plugin::map, plugin, GetContext::type, and type.

Referenced by libgnunet_plugin_datacache_heap_init().

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

◆ heap_plugin_del()

static int heap_plugin_del ( void *  cls)
static

Delete the entry with the lowest expiration value from the datacache right now.

Parameters
clsclosure (our struct Plugin)
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 378 of file plugin_datacache_heap.c.

379 {
380  struct Plugin *plugin = cls;
381  struct Value *val;
382 
383  for (unsigned int i = 0; i < NUM_HEAPS; i++)
384  {
386  if (NULL != val)
387  break;
388  }
389  if (NULL == val)
390  return GNUNET_SYSERR;
393  &val->key,
394  val));
396  &val->key,
397  val->size + OVERHEAD);
398  GNUNET_free (val->path_info);
399  GNUNET_free (val);
400  return GNUNET_OK;
401 }
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
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_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_DATACACHE_DeleteNotifyCallback delete_notify
Function to call whenever the plugin needs to discard content that it was asked to store.
void * cls
Closure to use for callbacks.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.

References GNUNET_DATACACHE_PluginEnvironment::cls, GNUNET_DATACACHE_PluginEnvironment::delete_notify, Plugin::env, GNUNET_assert, GNUNET_CONTAINER_heap_remove_root(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, Plugin::heaps, Value::key, Plugin::map, NUM_HEAPS, OVERHEAD, Value::path_info, plugin, and Value::size.

Referenced by libgnunet_plugin_datacache_heap_init().

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

◆ heap_plugin_get_random()

static unsigned int heap_plugin_get_random ( void *  cls,
GNUNET_DATACACHE_Iterator  iter,
void *  iter_cls 
)
static

Return a random value from the datastore.

Parameters
clsclosure (our struct Plugin)
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found

Definition at line 413 of file plugin_datacache_heap.c.

416 {
417  struct Plugin *plugin = cls;
418  struct GetContext get_ctx;
419 
420  get_ctx.type = GNUNET_BLOCK_TYPE_ANY;
421  get_ctx.iter = iter;
422  get_ctx.iter_cls = iter_cls;
423  get_ctx.cnt = 0;
425  &get_cb,
426  &get_ctx);
427  return get_ctx.cnt;
428 }
unsigned int GNUNET_CONTAINER_multihashmap_get_random(const struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Call it on a random value from the map, or not at all if the map is empty.

References GetContext::cnt, get_cb(), GNUNET_BLOCK_TYPE_ANY, GNUNET_CONTAINER_multihashmap_get_random(), GetContext::iter, GetContext::iter_cls, Plugin::map, plugin, and GetContext::type.

Referenced by libgnunet_plugin_datacache_heap_init().

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

◆ find_closest()

static int find_closest ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 445 of file plugin_datacache_heap.c.

448 {
449  struct GetClosestContext *gcc = cls;
450  struct Value *val = value;
451  unsigned int j;
452 
453  if (1 != GNUNET_CRYPTO_hash_cmp (key,
454  gcc->key))
455  return GNUNET_OK; /* useless */
456  j = gcc->num_results;
457  for (unsigned int i = 0; i < gcc->num_results; i++)
458  {
459  if (NULL == gcc->values[i])
460  {
461  j = i;
462  break;
463  }
464  if (1 == GNUNET_CRYPTO_hash_cmp (&gcc->values[i]->key,
465  key))
466  {
467  j = i;
468  break;
469  }
470  }
471  if (j == gcc->num_results)
472  return GNUNET_OK;
473  gcc->values[j] = val;
474  return GNUNET_OK;
475 }
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:201
Closure for find_closest().
const struct GNUNET_HashCode * key

References GNUNET_CRYPTO_hash_cmp(), GNUNET_OK, Value::key, GetClosestContext::key, key, GetClosestContext::num_results, value, and GetClosestContext::values.

Referenced by heap_plugin_get_closest().

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

◆ heap_plugin_get_closest()

static unsigned int heap_plugin_get_closest ( void *  cls,
const struct GNUNET_HashCode key,
unsigned int  num_results,
GNUNET_DATACACHE_Iterator  iter,
void *  iter_cls 
)
static

Iterate over the results that are "close" to a particular key in the datacache.

"close" is defined as numerically larger than key (when interpreted as a circular address space), with small distance.

Parameters
clsclosure (internal context for the plugin)
keyarea of the keyspace to look into
num_resultsnumber of results that should be returned to iter
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found

Definition at line 492 of file plugin_datacache_heap.c.

497 {
498  struct Plugin *plugin = cls;
499  struct Value *values[num_results];
500  struct GetClosestContext gcc = {
501  .values = values,
502  .num_results = num_results,
503  .key = key
504  };
505 
507  &find_closest,
508  &gcc);
509  for (unsigned int i = 0; i < num_results; i++)
510  {
511  if (NULL == values[i])
512  return i;
513  iter (iter_cls,
514  &values[i]->key,
515  values[i]->size,
516  (void *) &values[i][1],
517  values[i]->type,
518  values[i]->discard_time,
519  values[i]->path_info_len,
520  values[i]->path_info);
521  }
522  return num_results;
523 }
static struct GNUNET_CONTAINER_MultiHashMap * values
Collection of all values (represented with ValueSet).
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
static int find_closest(void *cls, const struct GNUNET_HashCode *key, void *value)

References find_closest(), GNUNET_CONTAINER_multihashmap_iterate(), key, Plugin::map, GetClosestContext::num_results, plugin, size, type, GetClosestContext::values, and values.

Referenced by libgnunet_plugin_datacache_heap_init().

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

◆ libgnunet_plugin_datacache_heap_init()

void* libgnunet_plugin_datacache_heap_init ( void *  cls)

Entry point for the plugin.

Parameters
clsclosure (the struct GNUNET_DATACACHE_PluginEnvironmnet)
Returns
the plugin's closure (our struct Plugin)

Definition at line 533 of file plugin_datacache_heap.c.

534 {
537  struct Plugin *plugin;
538 
539  plugin = GNUNET_new (struct Plugin);
540  plugin->map = GNUNET_CONTAINER_multihashmap_create (1024, /* FIXME: base on quota! */
541  GNUNET_YES);
542  for (unsigned int i = 0; i < NUM_HEAPS; i++)
545  plugin->env = env;
547  api->cls = plugin;
548  api->get = &heap_plugin_get;
549  api->put = &heap_plugin_put;
550  api->del = &heap_plugin_del;
551  api->get_random = &heap_plugin_get_random;
552  api->get_closest = &heap_plugin_get_closest;
554  _ ("Heap datacache running\n"));
555  return api;
556 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
static ssize_t heap_plugin_put(void *cls, const struct GNUNET_HashCode *key, uint32_t xor_distance, size_t size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time, unsigned int path_info_len, const struct GNUNET_PeerIdentity *path_info)
Store an item in the datastore.
static unsigned int heap_plugin_get(void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results for a particular key in the datastore.
static unsigned int heap_plugin_get_closest(void *cls, const struct GNUNET_HashCode *key, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results that are "close" to a particular key in the datacache.
#define LOG(kind,...)
static unsigned int heap_plugin_get_random(void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Return a random value from the datastore.
static int heap_plugin_del(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
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 ...
struct returned by the initialization function of the plugin
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References _, Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATACACHE_PluginEnvironment::cls, env, Plugin::env, GNUNET_CONTAINER_heap_create(), GNUNET_CONTAINER_HEAP_ORDER_MIN, GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_INFO, GNUNET_new, GNUNET_YES, heap_plugin_del(), heap_plugin_get(), heap_plugin_get_closest(), heap_plugin_get_random(), heap_plugin_put(), Plugin::heaps, LOG, Plugin::map, NUM_HEAPS, and plugin.

Here is the call graph for this function:

◆ libgnunet_plugin_datacache_heap_done()

void* libgnunet_plugin_datacache_heap_done ( void *  cls)

Exit point from the plugin.

Parameters
clsclosure (our "struct Plugin")
Returns
NULL

Definition at line 566 of file plugin_datacache_heap.c.

567 {
569  struct Plugin *plugin = api->cls;
570  struct Value *val;
571 
572  for (unsigned int i = 0; i < NUM_HEAPS; i++)
573  {
574  while (NULL != (val = GNUNET_CONTAINER_heap_remove_root (plugin->heaps[i])))
575  {
578  &val->key,
579  val));
580  GNUNET_free (val->path_info);
581  GNUNET_free (val);
582  }
584  }
587  GNUNET_free (api);
588  return NULL;
589 }
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.
void * cls
Closure to pass to all plugin functions.

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_assert, GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_heap_remove_root(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_YES, Plugin::heaps, Value::key, Plugin::map, NUM_HEAPS, Value::path_info, and plugin.

Here is the call graph for this function: