30 #define LOG(kind, ...) GNUNET_log_from (kind, "datacache-heap", __VA_ARGS__) 32 #define LOG_STRERROR_FILE(kind, op, fn) GNUNET_log_from_strerror_file (kind, \ 107 #define OVERHEAD (sizeof(struct Value) + 64) 171 (0 == memcmp (&val[1],
188 "Got same value for key %s and type %d (size %u vs %u)\n",
191 (
unsigned int) val->
size,
192 (
unsigned int) put_ctx->
size);
216 uint32_t xor_distance,
321 if (NULL != get_ctx->
iter)
325 (
const char *) &val[1],
383 for (
unsigned int i = 0; i <
NUM_HEAPS; i++)
457 for (
unsigned int i = 0; i < gcc->
num_results; i++)
459 if (NULL == gcc->
values[i])
494 unsigned int num_results,
511 if (NULL == values[i])
516 (
void *) &values[i][1],
518 values[i]->discard_time,
519 values[i]->path_info_len,
520 values[i]->path_info);
542 for (
unsigned int i = 0; i <
NUM_HEAPS; i++)
554 _ (
"Heap datacache running\n"));
572 for (
unsigned int i = 0; i <
NUM_HEAPS; i++)
void * cls
Closure to pass to all plugin functions.
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.
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.
uint64_t rel_value_us
The actual value.
void * libgnunet_plugin_datacache_heap_init(void *cls)
Entry point for the plugin.
Any type of block, used as a wildcard when searching.
static struct GNUNET_CONTAINER_MultiHashMap * values
Collection of all values (represented with ValueSet).
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.
size_t size
Number of bytes in data.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int heap_plugin_del(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
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.
const char * data
Data for the new value.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
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.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * iter_cls
Closure for iter.
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.
static int find_closest(void *cls, const struct GNUNET_HashCode *key, void *value)
const struct GNUNET_HashCode * key
uint64_t abs_value_us
The actual value.
Internal representation of the hash map.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
GNUNET_DATACACHE_DeleteNotifyCallback delete_notify
Function to call whenever the plugin needs to discard content that it was asked to store...
struct GNUNET_TIME_Absolute discard_time
Expiration time for the new value.
unsigned int cnt
Number of results found.
#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.
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.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
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
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.
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
Handle to a node in a heap.
enum GNUNET_BLOCK_Type type
Block type requested.
Heap with the minimum cost at the root.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
static char * plugin
Solver plugin name as string.
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_HashCode key
Key for the entry.
Closure for find_closest().
void * iter_cls
Iterator cls.
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.
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
Allow multiple values with the same key.
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.
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.
unsigned long long size
Size of all values we're storing.
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.
void * libgnunet_plugin_datacache_heap_done(void *cls)
Exit point from the plugin.
struct GNUNET_CONTAINER_HeapNode * hn
Corresponding node in the heap.
#define GNUNET_log(kind,...)
void * GNUNET_CONTAINER_heap_remove_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
int(* GNUNET_DATACACHE_Iterator)(void *cls, const struct GNUNET_HashCode *key, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute exp, unsigned int path_info_len, const struct GNUNET_PeerIdentity *path_info)
An iterator over a set of items stored in the datacache.
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?
void * cls
Closure to use for callbacks.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Time for absolute times used by GNUnet, in microseconds.
unsigned int(* get_random)(void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Return a random value from the datastore.
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.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
uint32_t data
The data value.
struct GNUNET_PeerIdentity * path_info
Path information.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
GNUNET_PEERSTORE_Processor iter
Iterator.
enum GNUNET_BLOCK_Type type
Type of the node.
#define GNUNET_malloc(size)
Wrapper around malloc.
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.
#define GNUNET_free(ptr)
Wrapper around free.