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 enum GNUNET_GenericReturnValue | 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, uint32_t xor_distance, const struct GNUNET_DATACACHE_Block *block) |
Store an item in the datastore. More... | |
static enum GNUNET_GenericReturnValue | 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 enum GNUNET_GenericReturnValue | heap_plugin_del (void *cls) |
Delete the entry with the lowest expiration value from the datacache right now. More... | |
static enum GNUNET_GenericReturnValue | 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, enum GNUNET_BLOCK_Type type, 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.
#define LOG_STRERROR_FILE | ( | kind, | |
op, | |||
fn | |||
) |
Definition at line 32 of file plugin_datacache_heap.c.
#define NUM_HEAPS 24 |
Definition at line 36 of file plugin_datacache_heap.c.
#define OVERHEAD (sizeof(struct Value) + 64) |
Definition at line 88 of file plugin_datacache_heap.c.
|
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 118 of file plugin_datacache_heap.c.
References GNUNET_TIME_Absolute::abs_value_us, Value::block, PutContext::block, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DATACACHE_Block::expiration_time, PutContext::found, GNUNET_CONTAINER_heap_update_cost(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_memdup, GNUNET_NO, GNUNET_TIME_absolute_max(), GNUNET_YES, Value::hn, key, GNUNET_DATACACHE_Block::put_path, Value::put_path, GNUNET_DATACACHE_Block::put_path_length, GNUNET_DATACACHE_Block::type, and value.
Referenced by heap_plugin_put().
|
static |
Store an item in the datastore.
cls | closure (our struct Plugin ) |
xor_distance | how close is key to our PID? |
block | data to store |
Definition at line 165 of file plugin_datacache_heap.c.
References GNUNET_TIME_Absolute::abs_value_us, Value::block, PutContext::block, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, Value::distance, GNUNET_DATACACHE_Block::expiration_time, PutContext::found, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_memdup, GNUNET_YES, Value::hn, GNUNET_DATACACHE_Block::key, NUM_HEAPS, OVERHEAD, plugin, put_cb(), GNUNET_DATACACHE_Block::put_path, Value::put_path, and GNUNET_DATACACHE_Block::put_path_length.
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 255 of file plugin_datacache_heap.c.
References Value::block, GetContext::cnt, GNUNET_DATACACHE_Block::expiration_time, GNUNET_BLOCK_TYPE_ANY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_OK, GNUNET_TIME_absolute_is_past(), GNUNET_YES, GetContext::iter, GetContext::iter_cls, key, ret, GNUNET_DATACACHE_Block::type, GetContext::type, and value.
Referenced by heap_plugin_get().
|
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 304 of file plugin_datacache_heap.c.
References GetContext::cnt, get_cb(), GNUNET_CONTAINER_multihashmap_get_multiple(), GetContext::iter, GetContext::iter_cls, key, 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 333 of file plugin_datacache_heap.c.
References Value::block, GNUNET_TESTING_PluginFunctions::cls, GNUNET_DATACACHE_Block::data_size, GNUNET_assert, GNUNET_CONTAINER_heap_remove_root(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_DATACACHE_Block::key, NUM_HEAPS, OVERHEAD, plugin, and Value::put_path.
Referenced by libgnunet_plugin_datacache_heap_init().
|
static |
Definition at line 376 of file plugin_datacache_heap.c.
References Value::block, GNUNET_BLOCK_TYPE_ANY, GNUNET_CRYPTO_hash_cmp(), GNUNET_OK, key, GNUNET_DATACACHE_Block::key, GetClosestContext::key, GetClosestContext::num_results, GNUNET_DATACACHE_Block::type, GetClosestContext::type, 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 |
type | desired block type for the replies |
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 428 of file plugin_datacache_heap.c.
References find_closest(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_SYSERR, key, LOG, GetClosestContext::num_results, plugin, 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 474 of file plugin_datacache_heap.c.
References _, Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATACACHE_PluginEnvironment::cls, 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_put(), LOG, NUM_HEAPS, and plugin.
void * libgnunet_plugin_datacache_heap_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | closure (our "struct Plugin") |
Definition at line 508 of file plugin_datacache_heap.c.
References Plugin::api, Value::block, 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, GNUNET_DATACACHE_Block::key, NUM_HEAPS, plugin, and Value::put_path.