![]() |
GNUnet
0.11.x
|
heap-only implementation of a database backend for the datacache More...
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... | |
heap-only implementation of a database backend for the datacache
Definition in file plugin_datacache_heap.c.
#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().
Definition at line 32 of file plugin_datacache_heap.c.
#define NUM_HEAPS 24 |
Definition at line 36 of file plugin_datacache_heap.c.
Referenced by heap_plugin_del(), heap_plugin_put(), libgnunet_plugin_datacache_heap_done(), and libgnunet_plugin_datacache_heap_init().
#define OVERHEAD (sizeof(struct Value) + 64) |
Definition at line 107 of file plugin_datacache_heap.c.
Referenced by heap_plugin_del(), and heap_plugin_put().
|
static |
Function called during PUT to detect if an equivalent block already exists.
cls | the struct PutContext |
key | the key for the value(s) |
value | an existing value |
Definition at line 162 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().
|
static |
Store an item in the datastore.
cls | closure (our struct Plugin ) |
key | key to store data under |
xor_distance | how close is key to our PID? |
size | number of bytes in data |
data | data to store |
type | type of the value |
discard_time | when to discard the value in any case |
path_info_len | number of entries in path_info |
path_info | a path through the network |
Definition at line 214 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().
|
static |
Function called during GET to find matching blocks.
Only matches by type.
cls | the struct GetContext |
key | the key for the value(s) |
value | an existing value |
Definition at line 307 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().
|
static |
Iterate over the results for a particular key in the datastore.
cls | closure (our struct Plugin ) |
key | |
type | entries of which type are relevant? |
iter | maybe NULL (to just count) |
iter_cls | closure for iter |
Definition at line 349 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().
|
static |
Delete the entry with the lowest expiration value from the datacache right now.
cls | closure (our struct Plugin ) |
Definition at line 378 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_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().
|
static |
Return a random value from the datastore.
cls | closure (our struct Plugin ) |
iter | maybe NULL (to just count) |
iter_cls | closure for iter |
Definition at line 413 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().
|
static |
Definition at line 445 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().
|
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.
cls | closure (internal context for the plugin) |
key | area of the keyspace to look into |
num_results | number of results that should be returned to iter |
iter | maybe NULL (to just count) |
iter_cls | closure for iter |
Definition at line 492 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().
void* libgnunet_plugin_datacache_heap_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | closure (the struct GNUNET_DATACACHE_PluginEnvironmnet ) |
struct Plugin
) Definition at line 533 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.
void* libgnunet_plugin_datacache_heap_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | closure (our "struct Plugin") |
Definition at line 566 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_YES, Plugin::heaps, Value::key, Plugin::map, NUM_HEAPS, Value::path_info, and plugin.