GNUnet  0.10.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)   GNUNET_log_from_strerror_file(kind, "datacache-heap", 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.

Referenced by libgnunet_plugin_datacache_heap_init().

◆ LOG_STRERROR_FILE

#define LOG_STRERROR_FILE (   kind,
  op,
  fn 
)    GNUNET_log_from_strerror_file(kind, "datacache-heap", op, fn)

Definition at line 32 of file plugin_datacache_heap.c.

◆ NUM_HEAPS

#define NUM_HEAPS   24

◆ OVERHEAD

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

Definition at line 103 of file plugin_datacache_heap.c.

Referenced by heap_plugin_del(), and heap_plugin_put().

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 157 of file plugin_datacache_heap.c.

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, 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().

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

References GNUNET_TIME_Absolute::abs_value_us, data, PutContext::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, Plugin::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, Plugin::size, Value::type, type, and PutContext::type.

Referenced by libgnunet_plugin_datacache_heap_init().

218 {
219  struct Plugin *plugin = cls;
220  struct Value *val;
221  struct PutContext put_ctx;
222 
223  put_ctx.found = GNUNET_NO;
224  put_ctx.data = data;
225  put_ctx.size = size;
226  put_ctx.path_info = path_info;
227  put_ctx.path_info_len = path_info_len;
228  put_ctx.discard_time = discard_time;
229  put_ctx.type = type;
231  key,
232  &put_cb,
233  &put_ctx);
234  if (GNUNET_YES == put_ctx.found)
235  return 0;
236  val = GNUNET_malloc(sizeof(struct Value) + size);
237  GNUNET_memcpy(&val[1],
238  data,
239  size);
240  val->key = *key;
241  val->type = type;
242  val->discard_time = discard_time;
243  val->size = size;
244  if (xor_distance >= NUM_HEAPS)
245  val->distance = NUM_HEAPS - 1;
246  else
247  val->distance = xor_distance;
249  val->path_info_len,
250  path_info_len);
252  path_info,
253  path_info_len * sizeof(struct GNUNET_PeerIdentity));
255  &val->key,
256  val,
258  val->hn = GNUNET_CONTAINER_heap_insert(plugin->heaps[val->distance],
259  val,
261  return size + OVERHEAD;
262 }
size_t size
Payload (actual payload follows this struct)
unsigned int path_info_len
Number of entries in path_info.
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.
uint32_t distance
How close is the hash to us? Determines which heap we are in!
struct GNUNET_CONTAINER_Heap * heaps[24]
Heaps sorted by distance.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_CONTAINER_MultiHashMap * map
Our hash map.
uint64_t abs_value_us
The actual value.
#define OVERHEAD
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_TIME_Absolute discard_time
Expiration time for the new value.
Closure for put_cb().
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
int found
Value to set to GNUNET_YES if an equivalent block was found.
enum GNUNET_BLOCK_Type type
Type of the block.
#define NUM_HEAPS
struct GNUNET_HashCode key
Key for the entry.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:66
const struct GNUNET_PeerIdentity * path_info
Path information.
unsigned int path_info_len
Number of entries in path_info.
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.
Allow multiple values with the same key.
Entry in the hash map.
The identity of the host (wraps the signing key of the peer).
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.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_CONTAINER_HeapNode * hn
Corresponding node in the heap.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_Absolute discard_time
Expiration time.
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.
uint32_t data
The data value.
struct GNUNET_PeerIdentity * path_info
Path information.
#define GNUNET_malloc(size)
Wrapper around malloc.
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 302 of file plugin_datacache_heap.c.

References GetContext::cnt, Value::discard_time, GNUNET_BLOCK_TYPE_ANY, GNUNET_OK, GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, GetContext::iter, GetContext::iter_cls, 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().

305 {
306  struct GetContext *get_ctx = cls;
307  struct Value *val = value;
308  int ret;
309 
310  if ((get_ctx->type != val->type) &&
311  (GNUNET_BLOCK_TYPE_ANY != get_ctx->type))
312  return GNUNET_OK;
313  if (0 ==
315  return GNUNET_OK;
316  if (NULL != get_ctx->iter)
317  ret = get_ctx->iter(get_ctx->iter_cls,
318  key,
319  val->size,
320  (const char *)&val[1],
321  val->type,
322  val->discard_time,
323  val->path_info_len,
324  val->path_info);
325  else
326  ret = GNUNET_YES;
327  get_ctx->cnt++;
328  return ret;
329 }
size_t size
Payload (actual payload follows this struct)
uint64_t rel_value_us
The actual value.
Any type of block, used as a wildcard when searching.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void * iter_cls
Closure for iter.
static int ret
Final status code.
Definition: gnunet-arm.c:89
unsigned int cnt
Number of results found.
static char * value
Value of the record to add/remove.
GNUNET_DATACACHE_Iterator iter
Function to call for each result.
enum GNUNET_BLOCK_Type type
Type of the block.
enum GNUNET_BLOCK_Type type
Block type requested.
Closure for get_cb().
Entry in the hash map.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_Absolute discard_time
Expiration time.
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 344 of file plugin_datacache_heap.c.

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

Referenced by libgnunet_plugin_datacache_heap_init().

349 {
350  struct Plugin *plugin = cls;
351  struct GetContext get_ctx;
352 
353  get_ctx.type = type;
354  get_ctx.iter = iter;
355  get_ctx.iter_cls = iter_cls;
356  get_ctx.cnt = 0;
358  key,
359  &get_cb,
360  &get_ctx);
361  return get_ctx.cnt;
362 }
static int get_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
Function called during GET to find matching blocks.
struct GNUNET_CONTAINER_MultiHashMap * map
Our hash map.
void * iter_cls
Closure for iter.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
GNUNET_DATACACHE_Iterator iter
Function to call for each result.
enum GNUNET_BLOCK_Type type
Block type requested.
Closure for get_cb().
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.
Handle for a plugin.
Definition: block.c:37
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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 373 of file plugin_datacache_heap.c.

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_free_non_null, 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().

374 {
375  struct Plugin *plugin = cls;
376  struct Value *val;
377 
378  for (unsigned int i = 0; i < NUM_HEAPS; i++)
379  {
380  val = GNUNET_CONTAINER_heap_remove_root(plugin->heaps[i]);
381  if (NULL != val)
382  break;
383  }
384  if (NULL == val)
385  return GNUNET_SYSERR;
388  &val->key,
389  val));
390  plugin->env->delete_notify(plugin->env->cls,
391  &val->key,
392  val->size + OVERHEAD);
394  GNUNET_free(val);
395  return GNUNET_OK;
396 }
size_t size
Payload (actual payload follows this struct)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_Heap * heaps[24]
Heaps sorted by distance.
struct GNUNET_CONTAINER_MultiHashMap * map
Our hash map.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define OVERHEAD
GNUNET_DATACACHE_DeleteNotifyCallback delete_notify
Function to call whenever the plugin needs to discard content that it was asked to store...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
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.
#define NUM_HEAPS
struct GNUNET_HashCode key
Key for the entry.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Entry in the hash map.
Handle for a plugin.
Definition: block.c:37
void * GNUNET_CONTAINER_heap_remove_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_PeerIdentity * path_info
Path information.
#define GNUNET_free(ptr)
Wrapper around free.
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 408 of file plugin_datacache_heap.c.

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

Referenced by libgnunet_plugin_datacache_heap_init().

411 {
412  struct Plugin *plugin = cls;
413  struct GetContext get_ctx;
414 
415  get_ctx.type = GNUNET_BLOCK_TYPE_ANY;
416  get_ctx.iter = iter;
417  get_ctx.iter_cls = iter_cls;
418  get_ctx.cnt = 0;
420  &get_cb,
421  &get_ctx);
422  return get_ctx.cnt;
423 }
Any type of block, used as a wildcard when searching.
static int get_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
Function called during GET to find matching blocks.
struct GNUNET_CONTAINER_MultiHashMap * map
Our hash map.
void * iter_cls
Closure for iter.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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.
GNUNET_DATACACHE_Iterator iter
Function to call for each result.
enum GNUNET_BLOCK_Type type
Block type requested.
Closure for get_cb().
Handle for a plugin.
Definition: block.c:37
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 439 of file plugin_datacache_heap.c.

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

Referenced by heap_plugin_get_closest().

442 {
443  struct GetClosestContext *gcc = cls;
444  struct Value *val = value;
445  unsigned int j;
446 
447  if (1 != GNUNET_CRYPTO_hash_cmp(key,
448  gcc->key))
449  return GNUNET_OK; /* useless */
450  j = gcc->num_results;
451  for (unsigned int i = 0; i < gcc->num_results; i++)
452  {
453  if (NULL == gcc->values[i])
454  {
455  j = i;
456  break;
457  }
458  if (1 == GNUNET_CRYPTO_hash_cmp(&gcc->values[i]->key,
459  key))
460  {
461  j = i;
462  break;
463  }
464  }
465  if (j == gcc->num_results)
466  return GNUNET_OK;
467  gcc->values[j] = val;
468  return GNUNET_OK;
469 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const struct GNUNET_HashCode * key
static char * value
Value of the record to add/remove.
struct GNUNET_HashCode key
Key for the entry.
Closure for find_closest().
Entry in the hash map.
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:278
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 486 of file plugin_datacache_heap.c.

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

Referenced by libgnunet_plugin_datacache_heap_init().

491 {
492  struct Plugin *plugin = cls;
493  struct Value *values[num_results];
494  struct GetClosestContext gcc = {
495  .values = values,
496  .num_results = num_results,
497  .key = key
498  };
499 
501  &find_closest,
502  &gcc);
503  for (unsigned int i = 0; i < num_results; i++)
504  {
505  if (NULL == values[i])
506  return i;
507  iter(iter_cls,
508  &values[i]->key,
509  values[i]->size,
510  (void *)&values[i][1],
511  values[i]->type,
512  values[i]->discard_time,
513  values[i]->path_info_len,
514  values[i]->path_info);
515  }
516  return num_results;
517 }
static struct GNUNET_CONTAINER_MultiHashMap * values
Collection of all values (represented with ValueSet).
struct GNUNET_CONTAINER_MultiHashMap * map
Our hash map.
static int find_closest(void *cls, const struct GNUNET_HashCode *key, void *value)
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Closure for find_closest().
static unsigned int size
Size of the "table".
Definition: peer.c:66
Entry in the hash map.
Handle for a plugin.
Definition: block.c:37
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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 527 of file plugin_datacache_heap.c.

References _, Plugin::api, GNUNET_DATACACHE_PluginEnvironment::cls, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::del, Plugin::env, GNUNET_DATACACHE_PluginFunctions::get, GNUNET_DATACACHE_PluginFunctions::get_closest, GNUNET_DATACACHE_PluginFunctions::get_random, 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, plugin, and GNUNET_DATACACHE_PluginFunctions::put.

528 {
531  struct Plugin *plugin;
532 
533  plugin = GNUNET_new(struct Plugin);
534  plugin->map = GNUNET_CONTAINER_multihashmap_create(1024, /* FIXME: base on quota! */
535  GNUNET_YES);
536  for (unsigned int i = 0; i < NUM_HEAPS; i++)
538  plugin->env = env;
540  api->cls = plugin;
541  api->get = &heap_plugin_get;
542  api->put = &heap_plugin_put;
543  api->del = &heap_plugin_del;
547  _("Heap datacache running\n"));
548  return api;
549 }
void * cls
Closure to pass to all plugin functions.
ssize_t(* 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.
int(* del)(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
static int heap_plugin_del(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
struct GNUNET_CONTAINER_Heap * heaps[24]
Heaps sorted by distance.
struct GNUNET_CONTAINER_MultiHashMap * map
Our hash map.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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 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.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:46
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
unsigned int(* 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.
struct returned by the initialization function of the plugin
Heap with the minimum cost at the root.
#define NUM_HEAPS
static unsigned int heap_plugin_get_random(void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Return a random value from the datastore.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define LOG(kind,...)
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
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.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:77
unsigned int(* get_random)(void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Return a random value from the datastore.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
unsigned int(* 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.
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 559 of file plugin_datacache_heap.c.

References Plugin::api, 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_free_non_null, GNUNET_YES, Plugin::heaps, Value::key, Plugin::map, NUM_HEAPS, Value::path_info, and plugin.

560 {
562  struct Plugin *plugin = api->cls;
563  struct Value *val;
564 
565  for (unsigned int i = 0; i < NUM_HEAPS; i++)
566  {
567  while (NULL != (val = GNUNET_CONTAINER_heap_remove_root(plugin->heaps[i])))
568  {
571  &val->key,
572  val));
574  GNUNET_free(val);
575  }
577  }
579  GNUNET_free(plugin);
580  GNUNET_free(api);
581  return NULL;
582 }
void * cls
Closure to pass to all plugin functions.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_Heap * heaps[24]
Heaps sorted by distance.
struct GNUNET_CONTAINER_MultiHashMap * map
Our hash map.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
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.
struct returned by the initialization function of the plugin
#define NUM_HEAPS
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
struct GNUNET_HashCode key
Key for the entry.
Entry in the hash map.
Handle for a plugin.
Definition: block.c:37
void * GNUNET_CONTAINER_heap_remove_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_PeerIdentity * path_info
Path information.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: