GNUnet  0.18.1
MultiHashMap

Hash map with multiple values per key. More...

Collaboration diagram for MultiHashMap:

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MulitHashMapIteratorCallback) (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over hash map entries. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_PeerMapIterator) (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_ShortmapIterator) (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 Iterator over hash map entries. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiUuidmapIteratorCallback) (void *cls, const struct GNUNET_Uuid *key, void *value)
 Iterator over uuid map entries. More...
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MulitHashMapIterator32Callback) (void *cls, uint32_t key, void *value)
 Iterator over hash map entries. More...
 

Enumerations

enum  GNUNET_CONTAINER_MultiHashMapOption { GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE , GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE , GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY , GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST }
 Options for storing values in the HashMap. More...
 

Functions

struct GNUNET_CONTAINER_MultiHashMapGNUNET_CONTAINER_multihashmap_create (unsigned int len, int do_not_copy_keys)
 Create a multi hash map. More...
 
void GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map)
 Destroy a hash map. More...
 
void * GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
 Given a key find a value in the map matching the key. More...
 
enum GNUNET_GenericReturnValue 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. More...
 
int GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
 Remove all entries for the given key from the map. More...
 
unsigned int GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map)
 Remove all entries from the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
 Check if the map contains the given value under the given key. More...
 
enum GNUNET_GenericReturnValue 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. More...
 
unsigned int GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *map)
 Get the number of key-value pairs in the map. More...
 
int GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
 Iterate over all entries in the map. More...
 
struct GNUNET_CONTAINER_MultiHashMapIteratorGNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap *map)
 Create an iterator for a multihashmap. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter, struct GNUNET_HashCode *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
 Destroy a multihashmap iterator. More...
 
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. More...
 
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. More...
 
struct GNUNET_CONTAINER_MultiPeerMapGNUNET_CONTAINER_multipeermap_create (unsigned int len, int do_not_copy_keys)
 Create a multi peer map (hash map for public keys of peers). More...
 
void GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map)
 Destroy a hash map. More...
 
void * GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
 Given a key find a value in the map matching the key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
 Remove the given key-value pair from the map. More...
 
int GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
 Remove all entries for the given key from the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
 Check if the map contains the given value under the given key. More...
 
int GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
unsigned int GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map)
 Get the number of key-value pairs in the map. More...
 
int GNUNET_CONTAINER_multipeermap_iterate (struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
 Iterate over all entries in the map. More...
 
struct GNUNET_CONTAINER_MultiPeerMapIteratorGNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map)
 Create an iterator for a multihashmap. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter, struct GNUNET_PeerIdentity *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter)
 Destroy a multipeermap iterator. More...
 
int GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
 Iterate over all entries in the map that match a particular key. More...
 
unsigned int GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
 Call it on a random value from the map, or not at all if the map is empty. More...
 
struct GNUNET_CONTAINER_MultiShortmapGNUNET_CONTAINER_multishortmap_create (unsigned int len, int do_not_copy_keys)
 Create a multi peer map (hash map for public keys of peers). More...
 
void GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *map)
 Destroy a hash map. More...
 
void * GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
 Given a key find a value in the map matching the key. More...
 
int GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
 Remove the given key-value pair from the map. More...
 
int GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
 Remove all entries for the given key from the map. More...
 
int GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
int GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
 Check if the map contains the given value under the given key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
unsigned int GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap *map)
 Get the number of key-value pairs in the map. More...
 
int GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
 Iterate over all entries in the map. More...
 
struct GNUNET_CONTAINER_MultiShortmapIteratorGNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_MultiShortmap *map)
 Create an iterator for a multihashmap. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter, struct GNUNET_ShortHashCode *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiShortmapIterator *iter)
 Destroy a multishortmap iterator. More...
 
int GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
 Iterate over all entries in the map that match a particular key. More...
 
unsigned int GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
 Call it on a random value from the map, or not at all if the map is empty. More...
 
struct GNUNET_CONTAINER_MultiUuidmapGNUNET_CONTAINER_multiuuidmap_create (unsigned int len, int do_not_copy_keys)
 Create a multi peer map (hash map for public keys of peers). More...
 
void GNUNET_CONTAINER_multiuuidmap_destroy (struct GNUNET_CONTAINER_MultiUuidmap *map)
 Destroy a hash map. More...
 
void * GNUNET_CONTAINER_multiuuidmap_get (const struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key)
 Given a key find a value in the map matching the key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key, const void *value)
 Remove the given key-value pair from the map. More...
 
int GNUNET_CONTAINER_multiuuidmap_remove_all (struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key)
 Remove all entries for the given key from the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_contains (const struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_contains_value (const struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key, const void *value)
 Check if the map contains the given value under the given key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_put (struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
unsigned int GNUNET_CONTAINER_multiuuidmap_size (const struct GNUNET_CONTAINER_MultiUuidmap *map)
 Get the number of key-value pairs in the map. More...
 
int GNUNET_CONTAINER_multiuuidmap_iterate (struct GNUNET_CONTAINER_MultiUuidmap *map, GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, void *it_cls)
 Iterate over all entries in the map. More...
 
struct GNUNET_CONTAINER_MultiUuidmapIteratorGNUNET_CONTAINER_multiuuidmap_iterator_create (const struct GNUNET_CONTAINER_MultiUuidmap *map)
 Create an iterator for a multihashmap. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_iterator_next (struct GNUNET_CONTAINER_MultiUuidmapIterator *iter, struct GNUNET_Uuid *key, const void **value)
 Retrieve the next element from the hash map at the iterator's position. More...
 
void GNUNET_CONTAINER_multiuuidmap_iterator_destroy (struct GNUNET_CONTAINER_MultiUuidmapIterator *iter)
 Destroy a multiuuidmap iterator. More...
 
int GNUNET_CONTAINER_multiuuidmap_get_multiple (struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key, GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, void *it_cls)
 Iterate over all entries in the map that match a particular key. More...
 
unsigned int GNUNET_CONTAINER_multiuuidmap_get_random (const struct GNUNET_CONTAINER_MultiUuidmap *map, GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, void *it_cls)
 Call it on a random value from the map, or not at all if the map is empty. More...
 
struct GNUNET_CONTAINER_MultiHashMap32GNUNET_CONTAINER_multihashmap32_create (unsigned int len)
 Create a 32-bit key multi hash map. More...
 
void GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32 *map)
 Destroy a 32-bit key hash map. More...
 
unsigned int GNUNET_CONTAINER_multihashmap32_size (const struct GNUNET_CONTAINER_MultiHashMap32 *map)
 Get the number of key-value pairs in the map. More...
 
void * GNUNET_CONTAINER_multihashmap32_get (const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
 Given a key find a value in the map matching the key. More...
 
int GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
 Iterate over all entries in the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
 Remove the given key-value pair from the map. More...
 
int GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
 Remove all entries for the given key from the map. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
 Check if the map contains any value under the given key (including values that are NULL). More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
 Check if the map contains the given value under the given key. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
 Store a key-value pair in the map. More...
 
int GNUNET_CONTAINER_multihashmap32_get_multiple (struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
 Iterate over all entries in the map that match a particular key. More...
 
static int free_iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries. More...
 
static int iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries. More...
 

Detailed Description

Hash map with multiple values per key.

See also
Documentation

Typedef Documentation

◆ GNUNET_CONTAINER_MulitHashMapIteratorCallback

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MulitHashMapIteratorCallback) (void *cls, const struct GNUNET_HashCode *key, void *value)

Iterator over hash map entries.

Parameters
clsclosure
keycurrent key code
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 710 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_PeerMapIterator

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_PeerMapIterator) (void *cls, const struct GNUNET_PeerIdentity *key, void *value)

Iterator over hash map entries.

Parameters
clsclosure
keycurrent public key
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 1045 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_ShortmapIterator

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_ShortmapIterator) (void *cls, const struct GNUNET_ShortHashCode *key, void *value)

Iterator over hash map entries.

Parameters
clsclosure
keycurrent public key
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 1328 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_MultiUuidmapIteratorCallback

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MultiUuidmapIteratorCallback) (void *cls, const struct GNUNET_Uuid *key, void *value)

Iterator over uuid map entries.

Parameters
clsclosure
keycurrent public key
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 1611 of file gnunet_container_lib.h.

◆ GNUNET_CONTAINER_MulitHashMapIterator32Callback

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONTAINER_MulitHashMapIterator32Callback) (void *cls, uint32_t key, void *value)

Iterator over hash map entries.

Parameters
clsclosure
keycurrent key code
valuevalue in the hash map
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 1894 of file gnunet_container_lib.h.

Enumeration Type Documentation

◆ GNUNET_CONTAINER_MultiHashMapOption

Options for storing values in the HashMap.

Enumerator
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE 

If a value with the given key exists, replace it.

Note that the old value would NOT be freed by replace (the application has to make sure that this happens if required).

GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE 

Allow multiple values with the same key.

GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY 

There must only be one value per key; storing a value should fail if a value under the same key already exists.

GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST 

, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY; implemented just like GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE but this option documents better what is intended if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY is what is desired).

Definition at line 732 of file gnunet_container_lib.h.

733 {
741 
747 
754 
765 };
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
If a value with the given key exists, replace it.

Function Documentation

◆ GNUNET_CONTAINER_multihashmap_create()

struct GNUNET_CONTAINER_MultiHashMap* GNUNET_CONTAINER_multihashmap_create ( unsigned int  len,
int  do_not_copy_keys 
)

Create a multi hash map.

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Definition at line 179 of file container_multihashmap.c.

180 {
182 
183  GNUNET_assert (len > 0);
185  if (len * sizeof(union MapEntry) > GNUNET_MAX_MALLOC_CHECKED)
186  {
187  size_t s;
188  /* application *explicitly* requested very large map, hopefully
189  it checks the return value... */
190  s = len * sizeof(union MapEntry);
191  if ((s / sizeof(union MapEntry)) != len)
192  return NULL; /* integer overflow on multiplication */
193  if (NULL == (hm->map = GNUNET_malloc_large (s)))
194  {
195  /* out of memory */
197  "Out of memory allocating large hash map (%u entries)\n",
198  len);
199  GNUNET_free (hm);
200  return NULL;
201  }
202  }
203  else
204  {
205  hm->map = GNUNET_new_array (len, union MapEntry);
206  }
207  hm->map_length = len;
208  hm->use_small_entries = do_not_copy_keys;
209  return hm;
210 }
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
Internal representation of the hash map.
union MapEntry * map
All of our buckets.
unsigned int map_length
Length of the "map" array.
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...
Entry in the map.

References GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc_large, GNUNET_MAX_MALLOC_CHECKED, GNUNET_new, GNUNET_new_array, len, GNUNET_CONTAINER_MultiHashMap::map, GNUNET_CONTAINER_MultiHashMap::map_length, and GNUNET_CONTAINER_MultiHashMap::use_small_entries.

Referenced by check_unique(), create_download_context(), create_handle(), create_member(), create_member_session(), create_response(), create_room(), create_service(), create_srv_handle(), database_setup(), deserialize_download(), deserialize_search(), diff_create(), GDS_CLIENTS_init(), GDS_ROUTING_init(), get_cadet(), get_file_handle(), GNUNET_CADET_connect(), GNUNET_DHT_connect(), GNUNET_FS_indexing_init(), GNUNET_FS_namespace_list_updateable(), GNUNET_FS_search_start_searching_(), GNUNET_FS_share_tree_trim(), GNUNET_IDENTITY_connect(), GNUNET_PEERSTORE_watch(), GNUNET_TESTBED_barrier_init_(), GSF_peer_connect_handler(), GSF_pending_request_init_(), GSF_plan_add_(), GST_barriers_init(), handle_alice_client_message(), handle_bob_client_message(), handle_client_accept(), handle_client_create_set(), handle_client_evaluate(), handle_client_join(), handle_link_controllers(), handle_port_open(), init_contact_store(), init_ego_store(), init_message_store(), init_operation_store(), init_socket(), intersection_accept(), intersection_evaluate(), iterate_forward_members(), iterate_notify_about_members(), libgnunet_plugin_datacache_heap_init(), libgnunet_plugin_datastore_heap_init(), libgnunet_plugin_dhtu_ip_init(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search(), rfn_create(), run(), search_start(), send_full_set(), switch_member_session(), union_accept(), and union_evaluate().

◆ GNUNET_CONTAINER_multihashmap_destroy()

void GNUNET_CONTAINER_multihashmap_destroy ( struct GNUNET_CONTAINER_MultiHashMap map)

Destroy a hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 214 of file container_multihashmap.c.

216 {
218  for (unsigned int i = 0; i < map->map_length; i++)
219  {
220  union MapEntry me;
221 
222  me = map->map[i];
223  if (map->use_small_entries)
224  {
225  struct SmallMapEntry *sme;
226  struct SmallMapEntry *nxt;
227 
228  nxt = me.sme;
229  while (NULL != (sme = nxt))
230  {
231  nxt = sme->next;
232  GNUNET_free (sme);
233  }
234  me.sme = NULL;
235  }
236  else
237  {
238  struct BigMapEntry *bme;
239  struct BigMapEntry *nxt;
240 
241  nxt = me.bme;
242  while (NULL != (bme = nxt))
243  {
244  nxt = bme->next;
245  GNUNET_free (bme);
246  }
247  me.bme = NULL;
248  }
249  }
250  GNUNET_free (map->map);
251  GNUNET_free (map);
252 }
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
An entry in the hash map with the full key.
struct BigMapEntry * next
If there is a hash collision, we create a linked list.
unsigned int next_cache_off
Offset of next_cache entries in use, must be smaller than NEXT_CACHE_SIZE.
unsigned int map_length
Length of the "map" array.
union MapEntry * map
All of our buckets.
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...
An entry in the hash map with just a pointer to the key.
struct SmallMapEntry * next
If there is a hash collision, we create a linked list.

References GNUNET_assert, GNUNET_free, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by _GSS_operation_destroy(), check_key_type(), check_unique(), cleanup(), cleanup_handle(), clear_contact_store(), clear_ego_store(), clear_message_store(), clear_operation_store(), client_disconnect_cb(), close_all_files(), database_shutdown(), destroy_handle(), destroy_member(), destroy_member_session(), destroy_room(), destroy_service(), destroy_service_session(), destroy_srv_handle(), disconnect_cb(), do_shutdown(), fail_intersection_operation(), free_download_context(), free_search_context(), free_update_information_graph(), GNUNET_CADET_disconnect(), GNUNET_DHT_disconnect(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_indexing_done(), GNUNET_FS_search_signal_suspend_(), GNUNET_FS_search_stop(), GNUNET_FS_share_tree_trim(), GNUNET_PEERSTORE_disconnect(), GNUNET_TESTBED_barrier_remove_(), GSF_peer_disconnect_handler(), GSF_plan_notify_peer_disconnect_(), GST_barriers_destroy(), intersection_op_cancel(), iterate_forward_members(), iterate_notify_about_members(), iterate_zones(), kill_slave(), libgnunet_plugin_datacache_heap_done(), libgnunet_plugin_dhtu_ip_done(), libgnunet_plugin_rest_openid_connect_done(), main(), print_finish(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search_cancel(), search_start(), shutdown_rest(), shutdown_task(), and union_op_cancel().

◆ GNUNET_CONTAINER_multihashmap_get()

void* GNUNET_CONTAINER_multihashmap_get ( const struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 280 of file container_multihashmap.c.

283 {
284  union MapEntry me;
285 
286  me = map->map[idx_of (map, key)];
287  if (map->use_small_entries)
288  {
289  struct SmallMapEntry *sme;
290 
291  for (sme = me.sme; NULL != sme; sme = sme->next)
292  if (0 == GNUNET_memcmp (key, sme->key))
293  return sme->value;
294  }
295  else
296  {
297  struct BigMapEntry *bme;
298 
299  for (bme = me.bme; NULL != bme; bme = bme->next)
300  if (0 == GNUNET_memcmp (key, &bme->key))
301  return bme->value;
302  }
303  return NULL;
304 }
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Compute the index of the bucket for the given key.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void * value
Value of the entry.
struct GNUNET_HashCode key
Key for the entry.
void * value
Value of the entry.
const struct GNUNET_HashCode * key
Key for the entry.

References GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_file(), add_to_keyword_counter(), add_to_meta_counter(), callback_ego_lookup(), callback_ego_rename(), cancel_store_operation(), cb_intersection_element_removed(), change_srv_handle_member_id(), check_member_session_history(), close_handle_room(), code_redirect(), collector(), consume_fail(), consume_ticket(), cookie_identity_interpretation(), create_response(), delete_store_ego(), diff_insert(), ego_sign_data(), entry_handle_room_at(), execute_add(), execute_remove(), find_port(), find_target(), GCCH_channel_incoming_new(), GCCH_channel_local_new(), get_file_handle(), get_gns_cont(), get_handle_contact(), get_member_session(), get_redirect_state(), get_room_message(), get_room_sender(), get_service_room(), get_srv_handle_member_id(), get_store_contact(), get_store_contact_raw(), get_store_message(), get_store_message_link(), get_url_parameter_copy(), GNUNET_FS_add_to_index(), GNUNET_FS_handle_on_demand_block(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_open_room(), handle_barrier_cancel(), handle_barrier_status(), handle_barrier_wait(), handle_client_set_add(), handle_delete_message(), handle_identity_update(), handle_member_id(), handle_port_close(), handle_recv_message(), handle_union_p2p_demand(), handle_union_p2p_offer(), handle_watch_record(), is_message_in_message_control_flow(), login_cont(), lookup_diff(), lookup_rfn(), lookup_set(), lookup_task(), mark_as_reachable(), message_token(), namecache_lookup_block(), namestore_flat_lookup_records(), namestore_get(), ns_lookup_result_cb(), open_handle_room(), parse_credentials_basic_auth(), parse_credentials_post_body(), peerinfo_get(), post_data_iter(), queue_destroy(), remove_high_frequency_keywords(), rfn_vote(), route_packet(), token_endpoint(), update_message_control_flow(), update_store_ego(), use_store_operation(), and userinfo_endpoint().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_remove()

enum GNUNET_GenericReturnValue 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.

Note that if the key-value pair is in the map multiple times, only one of the pairs will be removed.

Parameters
mapthe map
keykey of the key-value pair
valuevalue of the key-value pair
Returns
GNUNET_YES on success, GNUNET_NO if the key-value pair is not in the map

Definition at line 405 of file container_multihashmap.c.

408 {
409  union MapEntry me;
410  unsigned int i;
411 
413 
414  i = idx_of (map, key);
415  me = map->map[i];
416  if (map->use_small_entries)
417  {
418  struct SmallMapEntry *p;
419 
420  p = NULL;
421  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
422  {
423  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
424  {
425  if (NULL == p)
426  map->map[i].sme = sme->next;
427  else
428  p->next = sme->next;
429  update_next_cache_sme (map, sme);
430  GNUNET_free (sme);
431  map->size--;
432  return GNUNET_YES;
433  }
434  p = sme;
435  }
436  }
437  else
438  {
439  struct BigMapEntry *p;
440 
441  p = NULL;
442  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
443  {
444  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
445  {
446  if (NULL == p)
447  map->map[i].bme = bme->next;
448  else
449  p->next = bme->next;
450  update_next_cache_bme (map, bme);
451  GNUNET_free (bme);
452  map->size--;
453  return GNUNET_YES;
454  }
455  p = bme;
456  }
457  }
458  return GNUNET_NO;
459 }
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiHashMap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiHashMap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static char * value
Value of the record to add/remove.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:37
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
unsigned int size
Number of entries in the map.
struct SmallMapEntry * sme
Variant used if map entries only contain a pointer to the key.
struct BigMapEntry * bme
Variant used if map entries contain the full key.

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), GNUNET_CONTAINER_MultiPeerMap::use_small_entries, and value.

Referenced by add_file(), bind_loose_channel(), callback_ego_rename(), cancel_store_operation(), cb_intersection_element_removed(), clean_channel(), clean_request(), client_disconnect_it(), client_release_ports(), close_handle_room(), close_service_room(), consume_fail(), consume_ticket(), create_target(), delete_entries(), delete_store_ego(), delete_value(), expire_entries(), expire_oldest_entry(), filter_all(), free_channel_state(), free_destination_entry(), free_ego(), free_pending_request(), free_service_record(), get_store_message(), GNUNET_CADET_close_port(), GNUNET_DHT_get_stop(), GNUNET_FS_indexing_do_unindex(), GNUNET_FS_indexing_done(), GNUNET_PEERSTORE_watch_cancel(), GNUNET_TESTBED_barrier_remove_(), GSC_drop_loose_channel(), GSF_cadet_query_cancel(), GSF_plan_notify_peer_disconnect_(), GSF_plan_notify_request_done_(), handle_delete_message(), handle_identity_update(), handle_port_close(), handle_union_p2p_elements(), handle_watch_cancel(), iterator_bf_reduce(), libgnunet_plugin_datacache_heap_done(), migrate_and_drop_keywords(), migrate_and_drop_metadata(), move_to_pending(), ns_lookup_result_cb(), process_result_with_request(), reconstruct_cb(), reghost_free_iterator(), remove_all(), remove_barrier(), remove_client_query_record(), remove_iterator(), remove_member_session(), remove_store_contact(), setup_state_record(), unbind_store_ego(), and update_store_contact().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_remove_all()

int GNUNET_CONTAINER_multihashmap_remove_all ( struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

Parameters
mapthe map
keyidentifies values to be removed
Returns
number of values removed

Definition at line 463 of file container_multihashmap.c.

466 {
467  union MapEntry me;
468  unsigned int i;
469  int ret;
470 
472 
473  ret = 0;
474  i = idx_of (map, key);
475  me = map->map[i];
476  if (map->use_small_entries)
477  {
478  struct SmallMapEntry *sme;
479  struct SmallMapEntry *p;
480 
481  p = NULL;
482  sme = me.sme;
483  while (NULL != sme)
484  {
485  if (0 == GNUNET_memcmp (key, sme->key))
486  {
487  if (NULL == p)
488  map->map[i].sme = sme->next;
489  else
490  p->next = sme->next;
491  update_next_cache_sme (map, sme);
492  GNUNET_free (sme);
493  map->size--;
494  if (NULL == p)
495  sme = map->map[i].sme;
496  else
497  sme = p->next;
498  ret++;
499  }
500  else
501  {
502  p = sme;
503  sme = sme->next;
504  }
505  }
506  }
507  else
508  {
509  struct BigMapEntry *bme;
510  struct BigMapEntry *p;
511 
512  p = NULL;
513  bme = me.bme;
514  while (NULL != bme)
515  {
516  if (0 == GNUNET_memcmp (key, &bme->key))
517  {
518  if (NULL == p)
519  map->map[i].bme = bme->next;
520  else
521  p->next = bme->next;
522  update_next_cache_bme (map, bme);
523  GNUNET_free (bme);
524  map->size--;
525  if (NULL == p)
526  bme = map->map[i].bme;
527  else
528  bme = p->next;
529  ret++;
530  }
531  else
532  {
533  p = bme;
534  bme = bme->next;
535  }
536  }
537  }
538  return ret;
539 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, ret, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by clear_member_chain_history(), expire_blocks(), map_remove_iterator(), namecache_cache_block(), and namestore_flat_store_records().

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

◆ GNUNET_CONTAINER_multihashmap_clear()

unsigned int GNUNET_CONTAINER_multihashmap_clear ( struct GNUNET_CONTAINER_MultiHashMap map)

Remove all entries from the map.

Note that the values would not be "freed".

Parameters
mapthe map
Returns
number of values removed

Definition at line 570 of file container_multihashmap.c.

571 {
572  unsigned int ret;
573 
574  ret = map->size;
576  return ret;
577 }
static int remove_all(void *cls, const struct GNUNET_HashCode *key, void *value)
Callback used to remove all entries from the map.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.

References GNUNET_CONTAINER_multihashmap_iterate(), map, remove_all(), ret, and GNUNET_CONTAINER_MultiPeerMap::size.

Referenced by check_member_session_completion().

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

◆ GNUNET_CONTAINER_multihashmap_contains()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains ( const struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key 
)

Check if the map contains any value under the given key (including values that are NULL).

Parameters
mapthe map
keythe key to test if a value exists for it
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 581 of file container_multihashmap.c.

584 {
585  union MapEntry me;
586 
587  me = map->map[idx_of (map, key)];
588  if (map->use_small_entries)
589  {
590  struct SmallMapEntry *sme;
591 
592  for (sme = me.sme; NULL != sme; sme = sme->next)
593  if (0 == GNUNET_memcmp (key, sme->key))
594  return GNUNET_YES;
595  }
596  else
597  {
598  struct BigMapEntry *bme;
599 
600  for (bme = me.bme; NULL != bme; bme = bme->next)
601  if (0 == GNUNET_memcmp (key, &bme->key))
602  return GNUNET_YES;
603  }
604  return GNUNET_NO;
605 }

References GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by allocate_v4_address(), allocate_v6_address(), build_authz_response(), check_member_session_history(), code_redirect(), collector(), contains_store_message(), cookie_identity_interpretation(), do_flood(), ego_get_all(), ego_get_response(), ego_sign_data(), forward_about_members(), get_gns_cont(), get_url_parameter_copy(), GNUNET_TESTBED_barrier_init_(), handle_barrier_cancel(), handle_barrier_init(), handle_room_message(), handle_union_p2p_offer(), iterate_save_messages(), load_message_store_entries(), load_message_store_links(), namestore_get(), notify_about_members(), parse_credentials_basic_auth(), parse_credentials_post_body(), peerinfo_get(), regex_next_edge(), register_host(), run(), and userinfo_endpoint().

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

◆ GNUNET_CONTAINER_multihashmap_contains_value()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains_value ( const struct GNUNET_CONTAINER_MultiHashMap map,
const struct GNUNET_HashCode key,
const void *  value 
)

Check if the map contains the given value under the given key.

Parameters
mapthe map
keythe key to test if a value exists for it
valuevalue to test for
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 609 of file container_multihashmap.c.

613 {
614  union MapEntry me;
615 
616  me = map->map[idx_of (map, key)];
617  if (map->use_small_entries)
618  {
619  struct SmallMapEntry *sme;
620 
621  for (sme = me.sme; NULL != sme; sme = sme->next)
622  if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
623  return GNUNET_YES;
624  }
625  else
626  {
627  struct BigMapEntry *bme;
628 
629  for (bme = me.bme; NULL != bme; bme = bme->next)
630  if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
631  return GNUNET_YES;
632  }
633  return GNUNET_NO;
634 }

References GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by bind_store_ego(), plan(), schedule_block_download(), and unbind_store_ego().

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

◆ GNUNET_CONTAINER_multihashmap_put()

enum GNUNET_GenericReturnValue 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.

Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the value already exists
Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if UNIQUE_ONLY was the option and the value already exists

Definition at line 709 of file container_multihashmap.c.

713 {
714  union MapEntry me;
715  unsigned int i;
716 
717  i = idx_of (map, key);
720  {
721  me = map->map[i];
722  if (map->use_small_entries)
723  {
724  struct SmallMapEntry *sme;
725 
726  for (sme = me.sme; NULL != sme; sme = sme->next)
727  if (0 == GNUNET_memcmp (key, sme->key))
728  {
730  return GNUNET_SYSERR;
731  sme->value = value;
732  return GNUNET_NO;
733  }
734  }
735  else
736  {
737  struct BigMapEntry *bme;
738 
739  for (bme = me.bme; NULL != bme; bme = bme->next)
740  if (0 == GNUNET_memcmp (key, &bme->key))
741  {
743  return GNUNET_SYSERR;
744  bme->value = value;
745  return GNUNET_NO;
746  }
747  }
748  }
749  if (map->size / 3 >= map->map_length / 4)
750  {
751  grow (map);
752  i = idx_of (map, key);
753  }
754  if (map->use_small_entries)
755  {
756  struct SmallMapEntry *sme;
757 
758  sme = GNUNET_new (struct SmallMapEntry);
759  sme->key = key;
760  sme->value = value;
761  sme->next = map->map[i].sme;
762  map->map[i].sme = sme;
763  }
764  else
765  {
766  struct BigMapEntry *bme;
767 
768  bme = GNUNET_new (struct BigMapEntry);
769  bme->key = *key;
770  bme->value = value;
771  bme->next = map->map[i].bme;
772  map->map[i].bme = bme;
773  }
774  map->size++;
775  return GNUNET_OK;
776 }
static void grow(struct GNUNET_CONTAINER_MultiHashMap *map)
Grow the given map to a more appropriate size.
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_SYSERR
Definition: gnunet_common.h:97

References MapEntry::bme, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, grow(), idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_link(), add_member_session(), add_to_keyword_counter(), add_to_meta_counter(), bind_store_ego(), callback_ego_rename(), callback_scan_for_operations(), change_srv_handle_member_id(), check_dht_local_get_result_seen(), check_unique(), collector(), create_handle_member_id(), create_randomized_element_iterator(), database_setup(), decode_and_send(), deserialize_search_result(), dht_get_string_handler(), diff_insert(), entry_service_room(), execute_add(), filtered_map_initialization(), find_target(), forward_about_members(), GCCH_channel_incoming_new(), GCCH_channel_local_new(), GDS_ROUTING_add(), get_cb(), get_file_handle(), get_store_contact(), get_store_message(), GNUNET_CADET_open_port(), GNUNET_DHT_get_start(), GNUNET_FS_add_to_index(), GNUNET_FS_namespace_list_updateable(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_open_room(), GNUNET_PEERSTORE_watch(), GNUNET_TESTBED_barrier_init_(), GSF_pending_request_create_(), GSF_plan_add_(), handle_alice_client_message(), handle_alice_client_message_multipart(), handle_barrier_init(), handle_bob_client_message(), handle_bob_client_message_multipart(), handle_client_redirect_to_ip(), handle_client_redirect_to_service(), handle_client_set_add(), handle_identity_update(), handle_p2p_get(), handle_port_open(), handle_room_message(), handle_union_p2p_inquiry(), handle_union_p2p_offer(), handle_watch(), header_iterator(), heap_plugin_put(), init_socket(), initialize_map_unfiltered(), iterate_copy_history(), load_member_session_history(), load_message_store_entries(), load_message_store_links(), load_state(), login_cont(), maint_child_death(), namecache_cache_block(), namestore_flat_store_records(), notify_about_members(), open_service_room(), peerstore_flat_store_record(), post_data_iter(), process_ksk_result(), process_sks_result(), put_diff(), put_rfn(), put_set(), put_store_message(), put_task(), queue(), read_index_list(), regex_find_path(), REGEX_INTERNAL_search(), regex_next_edge(), register_hashcode(), register_host(), rfn_vote(), route_packet(), run(), schedule_block_download(), set_result_cb(), setup_state_record(), store_all_states(), store_service(), token_endpoint(), transmit_pending(), update_member_chain_history(), update_message_control_flow(), update_sre_result_maps(), update_store_contact(), update_store_ego(), url_iterator(), and use_store_operation().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap_size()

◆ GNUNET_CONTAINER_multihashmap_iterate()

int GNUNET_CONTAINER_multihashmap_iterate ( struct GNUNET_CONTAINER_MultiHashMap map,
GNUNET_CONTAINER_MulitHashMapIteratorCallback  it,
void *  it_cls 
)

Iterate over all entries in the map.

Parameters
mapthe map
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 308 of file container_multihashmap.c.

312 {
313  int count;
314  union MapEntry me;
315  union MapEntry *ce;
316  struct GNUNET_HashCode kc;
317 
318  GNUNET_assert (NULL != map);
319  ce = &map->next_cache[map->next_cache_off];
321  count = 0;
322  for (unsigned i = 0; i < map->map_length; i++)
323  {
324  me = map->map[i];
325  if (map->use_small_entries)
326  {
327  struct SmallMapEntry *sme;
328 
329  ce->sme = me.sme;
330  while (NULL != (sme = ce->sme))
331  {
332  ce->sme = sme->next;
333  if (NULL != it)
334  {
335  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
336  {
338  return GNUNET_SYSERR;
339  }
340  }
341  count++;
342  }
343  }
344  else
345  {
346  struct BigMapEntry *bme;
347 
348  ce->bme = me.bme;
349  while (NULL != (bme = ce->bme))
350  {
351  ce->bme = bme->next;
352  if (NULL != it)
353  {
354  kc = bme->key;
355  if (GNUNET_OK != it (it_cls, &kc, bme->value))
356  {
358  return GNUNET_SYSERR;
359  }
360  }
361  count++;
362  }
363  }
364  }
366  return count;
367 }
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
union MapEntry next_cache[16]
Map entries indicating iteration positions currently in use by GNUNET_CONTAINER_multihashmap_get_mult...
A 512-bit hashcode.

References MapEntry::bme, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by begin_bf_exchange(), callback_mq_error(), callback_reconnect(), callback_set_handle_name(), check_all_done(), check_key_type(), cleanup(), cleanup_handle(), clear_contact_store(), clear_ego_store(), clear_message_store(), clear_operation_store(), client_disconnect_cb(), close_all_files(), collect_generation_garbage(), database_shutdown(), destroy_handle(), destroy_member(), destroy_room(), destroy_service(), destroy_service_session(), destroy_srv_handle(), disconnect_cb(), do_reconnect(), do_shutdown(), free_search_context(), get_member_session_of(), get_store_operation_type(), GNUNET_CADET_disconnect(), GNUNET_CONTAINER_multihashmap_clear(), GNUNET_FS_search_continue(), GNUNET_FS_search_pause(), GNUNET_FS_search_signal_suspend_(), GNUNET_FS_search_start_searching_(), GNUNET_FS_search_stop(), GNUNET_MESSENGER_find_rooms(), GNUNET_PEERSTORE_disconnect(), GSF_iterate_pending_requests_(), GSF_peer_disconnect_handler(), GST_barriers_destroy(), GST_link_notify_disconnect(), handle_alices_cryptodata_message(), handle_client_accept(), handle_intersection_p2p_done(), handle_union_p2p_request_full(), handle_union_p2p_send_full(), handle_union_p2p_strata_estimator(), heap_get_keys(), heap_plugin_get_closest(), heap_plugin_get_key(), initialize_key_to_element(), iterate_member_sessions(), iterate_zones(), kill_slave(), libgnunet_plugin_rest_openid_connect_done(), load_member_next_sessions(), main(), maybe_finish(), namecache_expire_blocks(), namestore_flat_iterate_records(), namestore_flat_zone_to_name(), peerstore_flat_delete_records(), peerstore_flat_expire_records(), peerstore_flat_iterate_records(), print_finish(), process_bf(), reconnect(), reconnect_cbk(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_INTERNAL_search_cancel(), reschedule_connect(), reset_cadet(), run(), save_member(), save_member_session_history(), save_message_store(), save_srv_handle_configuration(), save_state(), schedule_transmit_search_request(), send_alices_cryptodata_message(), send_bloomfilter(), send_full_set(), set_srv_handle_ego(), share_tree_trim(), shutdown_task(), signal_search_resume(), switch_member_session(), sync_member_contacts(), transmit_cryptographic_reply(), and try_reconnect().

◆ GNUNET_CONTAINER_multihashmap_iterator_create()

struct GNUNET_CONTAINER_MultiHashMapIterator* GNUNET_CONTAINER_multihashmap_iterator_create ( const struct GNUNET_CONTAINER_MultiHashMap map)

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multihashmap_iterate). Note that the iterator can not be used anymore if elements have been removed from 'map' after the creation of the iterator, or 'map' has been destroyed. Adding elements to 'map' may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Definition at line 907 of file container_multihashmap.c.

909 {
911 
913  iter->map = map;
915  iter->me = map->map[0];
916  return iter;
917 }
const struct GNUNET_CONTAINER_MultiHashMap * map
Map that we are iterating over.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
union MapEntry me
Position in the bucket idx.

References GNUNET_new, map, GNUNET_CONTAINER_MultiHashMapIterator::map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiHashMapIterator::me, GNUNET_CONTAINER_MultiHashMapIterator::modification_counter, and GNUNET_CONTAINER_MultiPeerMap::modification_counter.

Referenced by apply_diff_to_rfn(), handle_client_iterate(), handle_intersection_p2p_done(), process_bf(), task_start_apply_round(), task_start_eval_echo(), and task_start_grade().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_iterator_next()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterator_next ( struct GNUNET_CONTAINER_MultiHashMapIterator iter,
struct GNUNET_HashCode key,
const void **  value 
)

Retrieve the next element from the hash map at the iterator's position.

If there are no elements left, GNUNET_NO is returned, and key and value are not modified. This operation is only allowed if no elements have been removed from the multihashmap since the creation of iter, and the map has not been destroyed. Adding elements may result in repeating or skipping elements.

Parameters
iterthe iterator to get the next element from
keypointer to store the key in, can be NULL
valuepointer to store the value in, can be NULL
Returns
GNUNET_YES we returned an element, GNUNET_NO if we are out of elements

Definition at line 921 of file container_multihashmap.c.

925 {
926  /* make sure the map has not been modified */
928 
929  /* look for the next entry, skipping empty buckets */
930  while (1)
931  {
932  if (iter->idx >= iter->map->map_length)
933  return GNUNET_NO;
934  if (GNUNET_YES == iter->map->use_small_entries)
935  {
936  if (NULL != iter->me.sme)
937  {
938  if (NULL != key)
939  *key = *iter->me.sme->key;
940  if (NULL != value)
941  *value = iter->me.sme->value;
942  iter->me.sme = iter->me.sme->next;
943  return GNUNET_YES;
944  }
945  }
946  else
947  {
948  if (NULL != iter->me.bme)
949  {
950  if (NULL != key)
951  *key = iter->me.bme->key;
952  if (NULL != value)
953  *value = iter->me.bme->value;
954  iter->me.bme = iter->me.bme->next;
955  return GNUNET_YES;
956  }
957  }
958  iter->idx += 1;
959  if (iter->idx < iter->map->map_length)
960  iter->me = iter->map->map[iter->idx];
961  }
962 }
unsigned int idx
Current bucket index.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiHashMapIterator::idx, key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiHashMap::map, GNUNET_CONTAINER_MultiHashMapIterator::map, GNUNET_CONTAINER_MultiHashMap::map_length, GNUNET_CONTAINER_MultiHashMapIterator::me, GNUNET_CONTAINER_MultiHashMap::modification_counter, GNUNET_CONTAINER_MultiHashMapIterator::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiHashMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by apply_diff_to_rfn(), send_client_element(), send_remaining_elements(), task_start_apply_round(), task_start_eval_echo(), and task_start_grade().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_iterator_destroy()

void GNUNET_CONTAINER_multihashmap_iterator_destroy ( struct GNUNET_CONTAINER_MultiHashMapIterator iter)

Destroy a multihashmap iterator.

Parameters
iterthe iterator to destroy

Definition at line 966 of file container_multihashmap.c.

968 {
969  GNUNET_free (iter);
970 }

References GNUNET_free.

Referenced by _GSS_operation_destroy(), apply_diff_to_rfn(), client_disconnect_cb(), handle_client_iter_ack(), intersection_op_cancel(), send_client_element(), send_remaining_elements(), task_start_apply_round(), task_start_eval_echo(), and task_start_grade().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap_get_multiple()

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.

Parameters
mapthe map
keykey that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 780 of file container_multihashmap.c.

785 {
786  int count;
787  union MapEntry *me;
788  union MapEntry *ce;
789 
790  ce = &map->next_cache[map->next_cache_off];
792  count = 0;
793  me = &map->map[idx_of (map, key)];
794  if (map->use_small_entries)
795  {
796  struct SmallMapEntry *sme;
797 
798  ce->sme = me->sme;
799  while (NULL != (sme = ce->sme))
800  {
801  ce->sme = sme->next;
802  if (0 != GNUNET_memcmp (key, sme->key))
803  continue;
804  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
805  {
807  return GNUNET_SYSERR;
808  }
809  count++;
810  }
811  }
812  else
813  {
814  struct BigMapEntry *bme;
815 
816  ce->bme = me->bme;
817  while (NULL != (bme = ce->bme))
818  {
819  ce->bme = bme->next;
820  if (0 != GNUNET_memcmp (key, &bme->key))
821  continue;
822  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
823  {
825  return GNUNET_SYSERR;
826  }
827  count++;
828  }
829  }
831  return count;
832 }

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by callback_ego_create(), check_client_hello(), find_closest(), find_trees(), forward_reply(), GDS_CLIENTS_handle_reply(), GDS_ROUTING_add(), GDS_ROUTING_process(), get_cb(), GNUNET_FS_namespace_list_updateable(), GSF_plan_add_(), handle_dht_local_get_result_seen(), handle_p2p_get(), handle_p2p_put(), handle_port_open(), handle_put(), handle_reply(), heap_plugin_get_key(), heap_plugin_put(), heap_plugin_remove_key(), iter_hashcodes(), process_ksk_result(), process_sks_result(), regex_next_edge(), register_host(), and watch_notifier().

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

◆ GNUNET_CONTAINER_multihashmap_get_random()

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.

Note that this function has linear complexity (in the size of the map).

Parameters
mapthe map
itfunction to call on a random entry
it_clsextra argument to it
Returns
the number of key value pairs processed, zero or one.

Definition at line 847 of file container_multihashmap.c.

851 {
852  unsigned int off;
853  unsigned int idx;
854  union MapEntry me;
855 
856  if (0 == map->size)
857  return 0;
858  if (NULL == it)
859  return 1;
861  for (idx = 0; idx < map->map_length; idx++)
862  {
863  me = map->map[idx];
864  if (map->use_small_entries)
865  {
866  struct SmallMapEntry *sme;
867  struct SmallMapEntry *nxt;
868 
869  nxt = me.sme;
870  while (NULL != (sme = nxt))
871  {
872  nxt = sme->next;
873  if (0 == off)
874  {
875  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
876  return GNUNET_SYSERR;
877  return 1;
878  }
879  off--;
880  }
881  }
882  else
883  {
884  struct BigMapEntry *bme;
885  struct BigMapEntry *nxt;
886 
887  nxt = me.bme;
888  while (NULL != (bme = nxt))
889  {
890  nxt = bme->next;
891  if (0 == off)
892  {
893  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
894  return GNUNET_SYSERR;
895  return 1;
896  }
897  off--;
898  }
899  }
900  }
901  GNUNET_break (0);
902  return GNUNET_SYSERR;
903 }
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multipeermap_create()

struct GNUNET_CONTAINER_MultiPeerMap* GNUNET_CONTAINER_multipeermap_create ( unsigned int  len,
int  do_not_copy_keys 
)

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Definition at line 178 of file container_multipeermap.c.

180 {
182 
183  GNUNET_assert (len > 0);
185  map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
186  if (NULL == map->map)
187  {
188  GNUNET_free (map);
189  return NULL;
190  }
191  map->map_length = len;
192  map->use_small_entries = do_not_copy_keys;
193  return map;
194 }
Internal representation of the hash map.

References GNUNET_assert, GNUNET_free, GNUNET_malloc_large, GNUNET_new, len, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by client_connect_cb(), core_init(), create_srv_room(), CustomPeerMap_create(), GAS_addresses_init(), GAS_connectivity_init(), GAS_preference_init(), GAS_reservations_init(), GNUNET_ATS_connectivity_init(), GNUNET_ATS_solvers_solver_start(), GNUNET_CORE_connect(), GNUNET_CRYPTO_ecc_dlog_prepare(), GNUNET_PEER_intern(), GNUNET_TRANSPORT_application_init(), GNUNET_TRANSPORT_core_connect(), GSC_SESSIONS_init(), GSF_cadet_start_server(), GSF_connected_peer_init_(), GSF_plan_init(), GST_ats_init(), GST_blacklist_add_peer(), GST_manipulation_init(), GST_neighbours_start(), GST_validation_start(), handle_client_send_request(), handle_connection_create(), handle_peer_push(), handle_suggest(), init_socket(), libgnunet_plugin_transport_http_client_init(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_init(), libgnunet_plugin_transport_unix_init(), new_sub(), run(), setup_ac(), update_preference(), View_change_len(), and View_create().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_destroy()

void GNUNET_CONTAINER_multipeermap_destroy ( struct GNUNET_CONTAINER_MultiPeerMap map)

Destroy a hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 198 of file container_multipeermap.c.

200 {
202  for (unsigned int i = 0; i < map->map_length; i++)
203  {
204  union MapEntry me;
205 
206  me = map->map[i];
207  if (map->use_small_entries)
208  {
209  struct SmallMapEntry *sme;
210  struct SmallMapEntry *nxt;
211 
212  nxt = me.sme;
213  while (NULL != (sme = nxt))
214  {
215  nxt = sme->next;
216  GNUNET_free (sme);
217  }
218  me.sme = NULL;
219  }
220  else
221  {
222  struct BigMapEntry *bme;
223  struct BigMapEntry *nxt;
224 
225  nxt = me.bme;
226  while (NULL != (bme = nxt))
227  {
228  nxt = bme->next;
229  GNUNET_free (bme);
230  }
231  me.bme = NULL;
232  }
233  }
234  GNUNET_free (map->map);
235  GNUNET_free (map);
236 }

References GNUNET_assert, GNUNET_free, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by cleaning_task(), cleanup_map(), client_disconnect_cb(), CustomPeerMap_destroy(), destroy_srv_room(), destroy_sub(), do_shutdown(), end(), GAS_addresses_done(), GAS_connectivity_done(), GAS_preference_client_disconnect(), GAS_preference_done(), GAS_reservations_done(), GDS_NEIGHBOURS_done(), GNUNET_ATS_connectivity_done(), GNUNET_ATS_solvers_solver_stop(), GNUNET_CORE_disconnect(), GNUNET_CRYPTO_ecc_dlog_release(), GNUNET_TRANSPORT_application_done(), GNUNET_TRANSPORT_core_disconnect(), GSC_SESSIONS_done(), GSF_cadet_stop_server(), GSF_connected_peer_done_(), GSF_plan_done(), GST_ats_done(), GST_validation_stop(), handle_connection_create(), libgnunet_plugin_transport_http_client_done(), libgnunet_plugin_transport_tcp_done(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_init(), libgnunet_plugin_transport_unix_done(), main(), peers_terminate(), shutdown_rest(), shutdown_task(), View_change_len(), and View_destroy().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multipeermap_get()

void* GNUNET_CONTAINER_multipeermap_get ( const struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 267 of file container_multipeermap.c.

270 {
271  union MapEntry me;
272 
273  me = map->map[idx_of (map, key)];
274  if (map->use_small_entries)
275  {
276  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
277  if (0 == GNUNET_memcmp (key, sme->key))
278  return sme->value;
279  }
280  else
281  {
282  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
283  if (0 == GNUNET_memcmp (key, &bme->key))
284  return bme->value;
285  }
286  return NULL;
287 }
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Compute the index of the bucket for the given key.

References MapEntry::bme, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_host_to_known_hosts(), addr_info_cb(), blacklist_check(), connect_notify(), consider_for_advertising(), cummulative_ack(), CustomPeerMap_get_index_pointer(), CustomPeerMap_remove_peer(), enter_srv_room_at(), find_session(), free_preference(), GAS_preference_get_by_peer(), GAS_reservations_set_bandwidth(), GCP_get(), GDS_NEIGHBOURS_lookup_peer(), GDS_u_connect(), get_cadet(), get_peer_ctx(), get_srv_room_tunnel(), GNUNET_CORE_get_mq(), GNUNET_CRYPTO_ecc_dlog(), GNUNET_PEER_intern(), GNUNET_PEER_search(), GSF_peer_get_(), GSF_plan_add_(), GSF_plan_notify_peer_disconnect_(), GST_manipulation_manipulate_metrics(), GST_manipulation_peer_disconnect(), GST_manipulation_send(), GST_manipulation_set_metric(), handle_client_send(), handle_client_send_request(), handle_connect_notify(), handle_core_connect(), handle_disconnect_notify(), handle_dv_box(), handle_hello(), handle_notify_inbound(), handle_revocation_union_request(), handle_send_ready(), handle_suggest_cancel(), handle_tcp_nat_probe(), incoming_channel(), learn_dv_path(), lookup_neighbour(), lookup_virtual_link(), neighbour_find(), process_peer(), process_peer_monitoring_cb(), profiler_reply_handle(), profiler_reply_handle_info(), rebuild_srv_room_basement_structure(), reservations_reserve(), update_hello(), update_preference(), update_relative_values_for_peer(), View_change_len(), View_clear(), and View_remove_peer().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multipeermap_remove()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove ( struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key,
const void *  value 
)

Remove the given key-value pair from the map.

Note that if the key-value pair is in the map multiple times, only one of the pairs will be removed.

Parameters
mapthe map
keykey of the key-value pair
valuevalue of the key-value pair
Returns
GNUNET_YES on success, GNUNET_NO if the key-value pair is not in the map

Definition at line 388 of file container_multipeermap.c.

391 {
392  union MapEntry me;
393  unsigned int i;
394 
396  i = idx_of (map, key);
397  me = map->map[i];
398  if (map->use_small_entries)
399  {
400  struct SmallMapEntry *p = NULL;
401 
402  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
403  {
404  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
405  {
406  if (NULL == p)
407  map->map[i].sme = sme->next;
408  else
409  p->next = sme->next;
410  update_next_cache_sme (map, sme);
411  GNUNET_free (sme);
412  map->size--;
413  return GNUNET_YES;
414  }
415  p = sme;
416  }
417  }
418  else
419  {
420  struct BigMapEntry *p = NULL;
421 
422  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
423  {
424  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
425  {
426  if (NULL == p)
427  map->map[i].bme = bme->next;
428  else
429  p->next = bme->next;
430  update_next_cache_bme (map, bme);
431  GNUNET_free (bme);
432  map->size--;
433  return GNUNET_YES;
434  }
435  p = bme;
436  }
437  }
438  return GNUNET_NO;
439 }
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), GNUNET_CONTAINER_MultiPeerMap::use_small_entries, and value.

Referenced by ats_perf_mon_cb(), callback_room_connect(), callback_room_disconnect(), cleanup_validation_entry(), client_delete_session(), destroy_ack_cummulator(), destroy_active_client_request(), destroy_ai(), destroy_it(), destroy_peer(), disconnect_and_free_peer_entry(), disconnect_cb(), enforce_del_address(), enter_srv_room_at(), free_addr_it(), free_address(), free_all_it(), free_backtalker(), free_dv_route(), free_iterator(), free_matching_requests(), free_neighbour(), free_peer(), free_preference(), free_tmps(), free_validation_state(), free_virtual_link(), GAS_reservations_set_bandwidth(), GDS_u_disconnect(), GNUNET_PEER_change_rc(), GNUNET_PEER_decrement_rcs(), GNUNET_TRANSPORT_application_suggest_cancel(), GSC_CLIENTS_notify_client_about_neighbour(), GSC_CLIENTS_reject_request(), GSC_SESSIONS_end(), GSF_peer_disconnect_handler(), GSF_plan_notify_peer_disconnect_(), handle_client_send(), handle_core_disconnect(), handle_send_transmit_continuation(), handle_tcp_nat_probe(), iterator(), neighbour_delete(), queue_destroy(), receiver_destroy(), sender_destroy(), server_delete_session(), stop_peer_request(), tcp_plugin_disconnect_session(), udp_disconnect_session(), and unix_plugin_session_disconnect().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multipeermap_remove_all()

int GNUNET_CONTAINER_multipeermap_remove_all ( struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

Parameters
mapthe map
keyidentifies values to be removed
Returns
number of values removed

Definition at line 443 of file container_multipeermap.c.

446 {
447  union MapEntry me;
448  unsigned int i;
449  int ret;
450 
452 
453  ret = 0;
454  i = idx_of (map, key);
455  me = map->map[i];
456  if (map->use_small_entries)
457  {
458  struct SmallMapEntry *sme;
459  struct SmallMapEntry *p;
460 
461  p = NULL;
462  sme = me.sme;
463  while (NULL != sme)
464  {
465  if (0 == GNUNET_memcmp (key, sme->key))
466  {
467  if (NULL == p)
468  map->map[i].sme = sme->next;
469  else
470  p->next = sme->next;
471  update_next_cache_sme (map, sme);
472  GNUNET_free (sme);
473  map->size--;
474  if (NULL == p)
475  sme = map->map[i].sme;
476  else
477  sme = p->next;
478  ret++;
479  }
480  else
481  {
482  p = sme;
483  sme = sme->next;
484  }
485  }
486  }
487  else
488  {
489  struct BigMapEntry *bme;
490  struct BigMapEntry *p;
491 
492  p = NULL;
493  bme = me.bme;
494  while (NULL != bme)
495  {
496  if (0 == GNUNET_memcmp (key, &bme->key))
497  {
498  if (NULL == p)
499  map->map[i].bme = bme->next;
500  else
501  p->next = bme->next;
502  update_next_cache_bme (map, bme);
503  GNUNET_free (bme);
504  map->size--;
505  if (NULL == p)
506  bme = map->map[i].bme;
507  else
508  bme = p->next;
509  ret++;
510  }
511  else
512  {
513  p = bme;
514  bme = bme->next;
515  }
516  }
517  }
518  return ret;
519 }

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, ret, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by add_valid_peer(), core_disconnects(), CustomPeerMap_remove_peer(), destroy_peer(), View_clear(), and View_remove_peer().

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

◆ GNUNET_CONTAINER_multipeermap_contains()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains ( const struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key 
)

Check if the map contains any value under the given key (including values that are NULL).

Parameters
mapthe map
keythe key to test if a value exists for it
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 523 of file container_multipeermap.c.

526 {
527  union MapEntry me;
528 
529  me = map->map[idx_of (map, key)];
530  if (map->use_small_entries)
531  {
532  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
533  if (0 == GNUNET_memcmp (key, sme->key))
534  return GNUNET_YES;
535  }
536  else
537  {
538  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
539  if (0 == GNUNET_memcmp (key, &bme->key))
540  return GNUNET_YES;
541  }
542  return GNUNET_NO;
543 }

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by addr_info_cb(), callback_room_disconnect(), check_access(), check_peer_known(), check_peer_valid(), check_removable(), clean_peer(), compute_rand_delay(), CustomPeerMap_contains_peer(), CustomPeerMap_put(), destroy_peer(), GAS_connectivity_has_peer(), get_peer_ctx(), GSC_CLIENTS_deliver_message(), GSC_CLIENTS_notify_client_about_neighbour(), GSC_CLIENTS_solicit_request(), handle_client_send_request(), handle_dv_learn(), handle_feedback(), handle_peer_pull_request(), handle_peer_push(), mq_notify_sent_cb(), send_pull_request(), send_push(), tcp_plugin_get_session(), View_clear(), and View_contains_peer().

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

◆ GNUNET_CONTAINER_multipeermap_contains_value()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_contains_value ( const struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key,
const void *  value 
)

Check if the map contains the given value under the given key.

Parameters
mapthe map
keythe key to test if a value exists for it
valuevalue to test for
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 547 of file container_multipeermap.c.

551 {
552  union MapEntry me;
553 
554  me = map->map[idx_of (map, key)];
555  if (map->use_small_entries)
556  {
557  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
558  if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
559  return GNUNET_YES;
560  }
561  else
562  {
563  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
564  if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
565  return GNUNET_YES;
566  }
567  return GNUNET_NO;
568 }

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by handle_tcp_data(), set_prop_task(), tcp_plugin_send(), udp_plugin_send(), udp_plugin_update_session_timeout(), unix_plugin_send(), and unix_plugin_update_session_timeout().

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

◆ GNUNET_CONTAINER_multipeermap_put()

int GNUNET_CONTAINER_multipeermap_put ( struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key,
void *  value,
enum GNUNET_CONTAINER_MultiHashMapOption  opt 
)

Store a key-value pair in the map.

Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the value already exists

Definition at line 631 of file container_multipeermap.c.

635 {
636  union MapEntry me;
637  unsigned int i;
638 
639  i = idx_of (map, key);
642  {
643  me = map->map[i];
644  if (map->use_small_entries)
645  {
646  struct SmallMapEntry *sme;
647 
648  for (sme = me.sme; NULL != sme; sme = sme->next)
649  if (0 == GNUNET_memcmp (key, sme->key))
650  {
652  return GNUNET_SYSERR;
653  sme->value = value;
654  return GNUNET_NO;
655  }
656  }
657  else
658  {
659  struct BigMapEntry *bme;
660 
661  for (bme = me.bme; NULL != bme; bme = bme->next)
662  if (0 == GNUNET_memcmp (key, &bme->key))
663  {
665  return GNUNET_SYSERR;
666  bme->value = value;
667  return GNUNET_NO;
668  }
669  }
670  }
671  if (map->size / 3 >= map->map_length / 4)
672  {
673  grow (map);
674  i = idx_of (map, key);
675  }
676  if (map->use_small_entries)
677  {
678  struct SmallMapEntry *sme;
679 
680  sme = GNUNET_new (struct SmallMapEntry);
681  sme->key = key;
682  sme->value = value;
683  sme->next = map->map[i].sme;
684  map->map[i].sme = sme;
685  }
686  else
687  {
688  struct BigMapEntry *bme;
689 
690  bme = GNUNET_new (struct BigMapEntry);
691  bme->key = *key;
692  bme->value = value;
693  bme->next = map->map[i].bme;
694  map->map[i].bme = bme;
695  }
696  map->size++;
697  return GNUNET_OK;
698 }
static void grow(struct GNUNET_CONTAINER_MultiPeerMap *map)
Grow the given map to a more appropriate size.

References MapEntry::bme, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, grow(), idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by activate_core_visible_dv_path(), add_host_to_known_hosts(), add_valid_peer(), addr_info_cb(), ats_perf_mon_cb(), boot_queue(), callback_room_connect(), connect_peer(), core_connects(), create_peer_ctx(), cummulative_ack(), CustomPeerMap_put(), enforce_add_address(), enter_srv_room_at(), find_validation_entry(), GAS_addresses_add(), GAS_handle_request_address(), GAS_reservations_set_bandwidth(), GCP_get(), GDS_u_connect(), get_cadet(), GNUNET_ATS_connectivity_suggest(), GNUNET_CRYPTO_ecc_dlog_prepare(), GNUNET_PEER_intern(), GNUNET_TRANSPORT_application_suggest(), GSC_CLIENTS_notify_client_about_neighbour(), GSC_SESSIONS_create(), GSF_peer_connect_handler(), GSF_plan_add_(), GST_ats_add_address(), GST_ats_add_inbound_address(), GST_blacklist_add_peer(), GST_manipulation_set_metric(), handle_add_queue_message(), handle_client_init(), handle_client_send(), handle_client_send_request(), handle_connect(), handle_connection_create(), handle_core_connect(), handle_dv_box(), handle_flow_control(), handle_suggest(), handle_tcp_nat_probe(), handle_tcp_welcome(), handle_validation_response(), http_client_plugin_get_session(), info_cb(), insert_in_sampler(), learn_dv_path(), make_peer(), mq_init(), new_peer_entry(), peer_id_cb(), process_peer_monitoring_cb(), run(), server_lookup_connection(), setup_ac(), setup_neighbour(), setup_queue(), setup_sender(), start_address_validation(), tcp_plugin_get_session(), udp_plugin_create_session(), unix_plugin_get_session(), update_preference(), View_change_len(), and View_put().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multipeermap_size()

◆ GNUNET_CONTAINER_multipeermap_iterate()

int GNUNET_CONTAINER_multipeermap_iterate ( struct GNUNET_CONTAINER_MultiPeerMap map,
GNUNET_CONTAINER_PeerMapIterator  it,
void *  it_cls 
)

Iterate over all entries in the map.

Parameters
mapthe map
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 291 of file container_multipeermap.c.

295 {
296  int count;
297  union MapEntry me;
298  union MapEntry *ce;
299  struct GNUNET_PeerIdentity kc;
300 
301  count = 0;
302  GNUNET_assert (NULL != map);
303  ce = &map->next_cache[map->next_cache_off];
305  for (unsigned int i = 0; i < map->map_length; i++)
306  {
307  me = map->map[i];
308  if (map->use_small_entries)
309  {
310  struct SmallMapEntry *sme;
311 
312  ce->sme = me.sme;
313  while (NULL != (sme = ce->sme))
314  {
315  ce->sme = sme->next;
316  if (NULL != it)
317  {
318  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
319  {
321  return GNUNET_SYSERR;
322  }
323  }
324  count++;
325  }
326  }
327  else
328  {
329  struct BigMapEntry *bme;
330 
331  ce->bme = me.bme;
332  while (NULL != (bme = ce->bme))
333  {
334  ce->bme = bme->next;
335  if (NULL != it)
336  {
337  kc = bme->key;
338  if (GNUNET_OK != it (it_cls, &kc, bme->value))
339  {
341  return GNUNET_SYSERR;
342  }
343  }
344  count++;
345  }
346  }
347  }
349  return count;
350 }
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
The identity of the host (wraps the signing key of the peer).

References MapEntry::bme, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_peer_task(), ats_perf_mon_cb(), check_proof_of_work(), cleaning_task(), cleanup_map(), client_disconnect_cb(), client_lookup_session(), consider_for_advertising(), cron_flush_respect(), destroy_srv_room(), disconnect(), disconnect_and_schedule_reconnect(), do_shutdown(), end(), forward_srv_room_message(), GAS_addresses_destroy_all(), GAS_addresses_get_peer_info(), GAS_connectivity_done(), GAS_connectivity_remove_client(), GAS_normalization_update_property(), GAS_preference_client_disconnect(), GAS_preference_done(), GAS_reservations_done(), GCP_destroy_all_peers(), GCP_iterate_all(), get_random_peer_from_peermap(), get_valid_peers(), GNUNET_ATS_connectivity_done(), GNUNET_ATS_solvers_solver_stop(), GNUNET_CORE_disconnect(), GNUNET_TRANSPORT_application_done(), GSC_SESSIONS_broadcast_typemap(), GSC_SESSIONS_done(), GSC_SESSIONS_notify_client_about_sessions(), GSF_cadet_stop_server(), GSF_connected_peer_done_(), GSF_handle_local_client_disconnect_(), GSF_iterate_connected_peers_(), GST_ats_done(), GST_neighbours_iterate(), GST_validation_stop(), handle_client_start(), handle_dv_learn(), handle_get_all(), handle_monitor_start(), handle_notify(), handle_p2p_estimate(), http_client_plugin_setup_monitor(), http_server_plugin_setup_monitor(), libgnunet_plugin_transport_http_client_done(), libgnunet_plugin_transport_tcp_done(), libgnunet_plugin_transport_unix_done(), peers_terminate(), preference_aging(), recalculate_relative_preferences(), reconnect(), reconnect_later(), schedule_next_hello(), send_find_peer_message(), send_srv_room_message(), shutdown_task(), start_dv_learn(), store_valid_peers(), tcp_plugin_setup_monitor(), template_plugin_setup_monitor(), udp_plugin_setup_monitor(), unix_plugin_setup_monitor(), update_preference(), and utilization_transmission().

◆ GNUNET_CONTAINER_multipeermap_iterator_create()

struct GNUNET_CONTAINER_MultiPeerMapIterator* GNUNET_CONTAINER_multipeermap_iterator_create ( const struct GNUNET_CONTAINER_MultiPeerMap map)

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multipeermap_iterate). Note that the iterator can not be used anymore if elements have been removed from map after the creation of the iterator, or 'map' has been destroyed. Adding elements to map may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Definition at line 828 of file container_multipeermap.c.

830 {
832 
834  iter->map = map;
836  iter->me = map->map[0];
837  return iter;
838 }
union MapEntry me
Position in the bucket 'idx'.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
const struct GNUNET_CONTAINER_MultiPeerMap * map
Map that we are iterating over.

References GNUNET_new, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMapIterator::map, GNUNET_CONTAINER_MultiPeerMapIterator::me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, and GNUNET_CONTAINER_MultiPeerMapIterator::modification_counter.

◆ GNUNET_CONTAINER_multipeermap_iterator_next()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_iterator_next ( struct GNUNET_CONTAINER_MultiPeerMapIterator iter,
struct GNUNET_PeerIdentity key,
const void **  value 
)

Retrieve the next element from the hash map at the iterator's position.

If there are no elements left, GNUNET_NO is returned, and key and value are not modified.

This operation is only allowed if no elements have been removed from the multihashmap since the creation of iter, and the map has not been destroyed.

Adding elements may result in repeating or skipping elements.

Parameters
iterthe iterator to get the next element from
keypointer to store the key in, can be NULL
valuepointer to store the value in, can be NULL
Returns
GNUNET_YES we returned an element, GNUNET_NO if we are out of elements

Definition at line 842 of file container_multipeermap.c.

846 {
847  /* make sure the map has not been modified */
849 
850  /* look for the next entry, skipping empty buckets */
851  while (1)
852  {
853  if (iter->idx >= iter->map->map_length)
854  return GNUNET_NO;
855  if (GNUNET_YES == iter->map->use_small_entries)
856  {
857  if (NULL != iter->me.sme)
858  {
859  if (NULL != key)
860  *key = *iter->me.sme->key;
861  if (NULL != value)
862  *value = iter->me.sme->value;
863  iter->me.sme = iter->me.sme->next;
864  return GNUNET_YES;
865  }
866  }
867  else
868  {
869  if (NULL != iter->me.bme)
870  {
871  if (NULL != key)
872  *key = iter->me.bme->key;
873  if (NULL != value)
874  *value = iter->me.bme->value;
875  iter->me.bme = iter->me.bme->next;
876  return GNUNET_YES;
877  }
878  }
879  iter->idx += 1;
880  if (iter->idx < iter->map->map_length)
881  iter->me = iter->map->map[iter->idx];
882  }
883 }
unsigned int idx
Current bucket index.

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiPeerMapIterator::idx, key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMapIterator::map, GNUNET_CONTAINER_MultiPeerMap::map_length, GNUNET_CONTAINER_MultiPeerMapIterator::me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, GNUNET_CONTAINER_MultiPeerMapIterator::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

◆ GNUNET_CONTAINER_multipeermap_iterator_destroy()

void GNUNET_CONTAINER_multipeermap_iterator_destroy ( struct GNUNET_CONTAINER_MultiPeerMapIterator iter)

Destroy a multipeermap iterator.

Parameters
iterthe iterator to destroy

Definition at line 887 of file container_multipeermap.c.

889 {
890  GNUNET_free (iter);
891 }

References GNUNET_free.

◆ GNUNET_CONTAINER_multipeermap_get_multiple()

int GNUNET_CONTAINER_multipeermap_get_multiple ( struct GNUNET_CONTAINER_MultiPeerMap map,
const struct GNUNET_PeerIdentity key,
GNUNET_CONTAINER_PeerMapIterator  it,
void *  it_cls 
)

Iterate over all entries in the map that match a particular key.

Parameters
mapthe map
keypublic key that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 702 of file container_multipeermap.c.

707 {
708  int count;
709  union MapEntry me;
710  union MapEntry *ce;
711 
712  ce = &map->next_cache[map->next_cache_off];
714  count = 0;
715  me = map->map[idx_of (map, key)];
716  if (map->use_small_entries)
717  {
718  struct SmallMapEntry *sme;
719 
720  ce->sme = me.sme;
721  while (NULL != (sme = ce->sme))
722  {
723  ce->sme = sme->next;
724  if (0 != GNUNET_memcmp (key, sme->key))
725  continue;
726  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
727  {
729  return GNUNET_SYSERR;
730  }
731  count++;
732  }
733  }
734  else
735  {
736  struct BigMapEntry *bme;
737 
738  ce->bme = me.bme;
739  while (NULL != (bme = ce->bme))
740  {
741  ce->bme = bme->next;
742  if (0 != GNUNET_memcmp (key, &bme->key))
743  continue;
744  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
745  {
747  return GNUNET_SYSERR;
748  }
749  count++;
750  }
751  }
753  return count;
754 }

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by ats_perf_mon_cb(), enc_notify_cb(), find_ai(), find_ai_no_session(), find_exact_address(), find_validation_entry(), GAS_addresses_get_peer_info(), GAS_handle_request_address_cancel(), get_active_address(), get_best_address(), GST_blacklist_test_allowed(), GST_clients_broadcast_disconnect(), GST_validation_get_addresses(), handle_add_queue_message(), handle_get(), handle_validation_response(), http_client_plugin_peer_disconnect(), http_server_plugin_disconnect_peer(), lookup_queue(), lookup_session(), server_lookup_connection(), setup_sender(), start_address_validation(), tcp_plugin_disconnect(), tcp_plugin_get_session(), try_handle_plaintext(), udp_disconnect(), udp_plugin_lookup_session(), unix_plugin_peer_disconnect(), and update_relative_values_for_peer().

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

◆ GNUNET_CONTAINER_multipeermap_get_random()

unsigned int GNUNET_CONTAINER_multipeermap_get_random ( const struct GNUNET_CONTAINER_MultiPeerMap map,
GNUNET_CONTAINER_PeerMapIterator  it,
void *  it_cls 
)

Call it on a random value from the map, or not at all if the map is empty.

Note that this function has linear complexity (in the size of the map).

Parameters
mapthe map
itfunction to call on a random entry
it_clsextra argument to it
Returns
the number of key value pairs processed, zero or one.

Definition at line 769 of file container_multipeermap.c.

773 {
774  unsigned int off;
775  union MapEntry me;
776 
777  if (0 == map->size)
778  return 0;
779  if (NULL == it)
780  return 1;
782  for (unsigned int idx = 0; idx < map->map_length; idx++)
783  {
784  me = map->map[idx];
785  if (map->use_small_entries)
786  {
787  struct SmallMapEntry *sme;
788  struct SmallMapEntry *nxt;
789 
790  nxt = me.sme;
791  while (NULL != (sme = nxt))
792  {
793  nxt = sme->next;
794  if (0 == off)
795  {
796  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
797  return GNUNET_SYSERR;
798  return 1;
799  }
800  off--;
801  }
802  }
803  else
804  {
805  struct BigMapEntry *bme;
806  struct BigMapEntry *nxt;
807 
808  nxt = me.bme;
809  while (NULL != (bme = nxt))
810  {
811  nxt = bme->next;
812  if (0 == off)
813  {
814  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
815  return GNUNET_SYSERR;
816  return 1;
817  }
818  off--;
819  }
820  }
821  }
822  GNUNET_break (0);
823  return GNUNET_SYSERR;
824 }

References GNUNET_break, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multishortmap_create()

struct GNUNET_CONTAINER_MultiShortmap* GNUNET_CONTAINER_multishortmap_create ( unsigned int  len,
int  do_not_copy_keys 
)

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Definition at line 194 of file container_multishortmap.c.

195 {
197 
198  GNUNET_assert (len > 0);
200  map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
201  if (NULL == map->map)
202  {
203  GNUNET_free (map);
204  return NULL;
205  }
206  map->map_length = len;
207  map->use_small_entries = do_not_copy_keys;
208  return map;
209 }
Internal representation of the hash map.

References GNUNET_assert, GNUNET_free, GNUNET_malloc_large, GNUNET_new, len, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by create_room(), GCO_init(), GCP_get(), GNUNET_PQ_connect2(), GNUNET_TESTING_get_topo_from_string(), init_member_store(), and run().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_destroy()

void GNUNET_CONTAINER_multishortmap_destroy ( struct GNUNET_CONTAINER_MultiShortmap map)

Destroy a hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 213 of file container_multishortmap.c.

215 {
217  for (unsigned int i = 0; i < map->map_length; i++)
218  {
219  union MapEntry me;
220 
221  me = map->map[i];
222  if (map->use_small_entries)
223  {
224  struct SmallMapEntry *sme;
225  struct SmallMapEntry *nxt;
226 
227  nxt = me.sme;
228  while (NULL != (sme = nxt))
229  {
230  nxt = sme->next;
231  GNUNET_free (sme);
232  }
233  me.sme = NULL;
234  }
235  else
236  {
237  struct BigMapEntry *bme;
238  struct BigMapEntry *nxt;
239 
240  nxt = me.bme;
241  while (NULL != (bme = nxt))
242  {
243  nxt = bme->next;
244  GNUNET_free (bme);
245  }
246  me.bme = NULL;
247  }
248  }
249  GNUNET_free (map->map);
250  GNUNET_free (map);
251 }

References GNUNET_assert, GNUNET_free, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by clear_member_store(), destroy_peer(), destroy_room(), do_shutdown(), GCO_shutdown(), GNUNET_PQ_connect2(), GNUNET_PQ_disconnect(), GNUNET_TESTING_free_topology(), and shutdown_rest().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_get()

void* GNUNET_CONTAINER_multishortmap_get ( const struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 282 of file container_multishortmap.c.

285 {
286  union MapEntry me;
287 
288  me = map->map[idx_of (map, key)];
289  if (map->use_small_entries)
290  {
291  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
292  if (0 == GNUNET_memcmp (key, sme->key))
293  return sme->value;
294  }
295  else
296  {
297  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
298  if (0 == GNUNET_memcmp (key, &bme->key))
299  return bme->value;
300  }
301  return NULL;
302 }
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Compute the index of the bucket for the given key.

References MapEntry::bme, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by GCC_lookup(), get_node_info(), get_route(), get_store_member(), GNUNET_PQ_event_listen(), GNUNET_PQ_event_listen_cancel(), GNUNET_TESTING_get_topo_from_string(), sock_read(), and start_helper().

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

◆ GNUNET_CONTAINER_multishortmap_remove()

int GNUNET_CONTAINER_multishortmap_remove ( struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key,
const void *  value 
)

Remove the given key-value pair from the map.

Note that if the key-value pair is in the map multiple times, only one of the pairs will be removed.

Parameters
mapthe map
keykey of the key-value pair
valuevalue of the key-value pair
Returns
GNUNET_YES on success, GNUNET_NO if the key-value pair is not in the map

Definition at line 400 of file container_multishortmap.c.

404 {
405  union MapEntry me;
406  unsigned int i;
407 
409  i = idx_of (map, key);
410  me = map->map[i];
411  if (map->use_small_entries)
412  {
413  struct SmallMapEntry *p = NULL;
414 
415  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
416  {
417  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
418  {
419  if (NULL == p)
420  map->map[i].sme = sme->next;
421  else
422  p->next = sme->next;
423  update_next_cache_sme (map, sme);
424  GNUNET_free (sme);
425  map->size--;
426  return GNUNET_YES;
427  }
428  p = sme;
429  }
430  }
431  else
432  {
433  struct BigMapEntry *p = NULL;
434 
435  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
436  {
437  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
438  {
439  if (NULL == p)
440  map->map[i].bme = bme->next;
441  else
442  p->next = bme->next;
443  update_next_cache_bme (map, bme);
444  GNUNET_free (bme);
445  map->size--;
446  return GNUNET_YES;
447  }
448  p = bme;
449  }
450  }
451  return GNUNET_NO;
452 }
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiShortmap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiShortmap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), GNUNET_CONTAINER_MultiPeerMap::use_small_entries, and value.

Referenced by destroy_route(), GCC_destroy(), GCP_remove_connection(), GNUNET_PQ_event_listen_cancel(), handle_id_message(), handle_leave_message(), kce_destroy(), and start_dv_learn().

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

◆ GNUNET_CONTAINER_multishortmap_remove_all()

int GNUNET_CONTAINER_multishortmap_remove_all ( struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

Parameters
mapthe map
keyidentifies values to be removed
Returns
number of values removed

Definition at line 456 of file container_multishortmap.c.

459 {
460  union MapEntry me;
461  unsigned int i;
462  int ret;
463 
465 
466  ret = 0;
467  i = idx_of (map, key);
468  me = map->map[i];
469  if (map->use_small_entries)
470  {
471  struct SmallMapEntry *sme;
472  struct SmallMapEntry *p;
473 
474  p = NULL;
475  sme = me.sme;
476  while (NULL != sme)
477  {
478  if (0 == GNUNET_memcmp (key, sme->key))
479  {
480  if (NULL == p)
481  map->map[i].sme = sme->next;
482  else
483  p->next = sme->next;
484  update_next_cache_sme (map, sme);
485  GNUNET_free (sme);
486  map->size--;
487  if (NULL == p)
488  sme = map->map[i].sme;
489  else
490  sme = p->next;
491  ret++;
492  }
493  else
494  {
495  p = sme;
496  sme = sme->next;
497  }
498  }
499  }
500  else
501  {
502  struct BigMapEntry *bme;
503  struct BigMapEntry *p;
504 
505  p = NULL;
506  bme = me.bme;
507  while (NULL != bme)
508  {
509  if (0 == GNUNET_memcmp (key, &bme->key))
510  {
511  if (NULL == p)
512  map->map[i].bme = bme->next;
513  else
514  p->next = bme->next;
515  update_next_cache_bme (map, bme);
516  GNUNET_free (bme);
517  map->size--;
518  if (NULL == p)
519  bme = map->map[i].bme;
520  else
521  bme = p->next;
522  ret++;
523  }
524  else
525  {
526  p = bme;
527  bme = bme->next;
528  }
529  }
530  }
531  return ret;
532 }

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, ret, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multishortmap_contains()

int GNUNET_CONTAINER_multishortmap_contains ( const struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key 
)

Check if the map contains any value under the given key (including values that are NULL).

Parameters
mapthe map
keythe key to test if a value exists for it
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 536 of file container_multishortmap.c.

539 {
540  union MapEntry me;
541 
542  me = map->map[idx_of (map, key)];
543  if (map->use_small_entries)
544  {
545  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
546  if (0 == GNUNET_memcmp (key, sme->key))
547  return GNUNET_YES;
548  }
549  else
550  {
551  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
552  if (0 == GNUNET_memcmp (key, &bme->key))
553  return GNUNET_YES;
554  }
555  return GNUNET_NO;
556 }

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by generate_free_member_id(), GNUNET_TESTING_get_topo_from_string(), and start_helper().

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

◆ GNUNET_CONTAINER_multishortmap_contains_value()

int GNUNET_CONTAINER_multishortmap_contains_value ( const struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key,
const void *  value 
)

Check if the map contains the given value under the given key.

Parameters
mapthe map
keythe key to test if a value exists for it
valuevalue to test for
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 560 of file container_multishortmap.c.

564 {
565  union MapEntry me;
566 
567  me = map->map[idx_of (map, key)];
568  if (map->use_small_entries)
569  {
570  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
571  if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
572  return GNUNET_YES;
573  }
574  else
575  {
576  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
577  if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
578  return GNUNET_YES;
579  }
580  return GNUNET_NO;
581 }

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by handle_join_message().

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

◆ GNUNET_CONTAINER_multishortmap_put()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put ( struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key,
void *  value,
enum GNUNET_CONTAINER_MultiHashMapOption  opt 
)

Store a key-value pair in the map.

Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the value already exists

Definition at line 643 of file container_multishortmap.c.

648 {
649  union MapEntry me;
650  unsigned int i;
651 
652  i = idx_of (map, key);
655  {
656  me = map->map[i];
657  if (map->use_small_entries)
658  {
659  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
660  if (0 == GNUNET_memcmp (key, sme->key))
661  {
663  return GNUNET_SYSERR;
664  sme->value = value;
665  return GNUNET_NO;
666  }
667  }
668  else
669  {
670  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
671  if (0 == GNUNET_memcmp (key, &bme->key))
672  {
674  return GNUNET_SYSERR;
675  bme->value = value;
676  return GNUNET_NO;
677  }
678  }
679  }
680  if (map->size / 3 >= map->map_length / 4)
681  {
682  grow (map);
683  i = idx_of (map, key);
684  }
685  if (map->use_small_entries)
686  {
687  struct SmallMapEntry *sme;
688 
689  sme = GNUNET_new (struct SmallMapEntry);
690  sme->key = key;
691  sme->value = value;
692  sme->next = map->map[i].sme;
693  map->map[i].sme = sme;
694  }
695  else
696  {
697  struct BigMapEntry *bme;
698 
699  bme = GNUNET_new (struct BigMapEntry);
700  bme->key = *key;
701  bme->value = value;
702  bme->next = map->map[i].bme;
703  map->map[i].bme = bme;
704  }
705  map->size++;
706  return GNUNET_OK;
707 }
static void grow(struct GNUNET_CONTAINER_MultiShortmap *map)
Grow the given map to a more appropriate size.

References MapEntry::bme, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, grow(), idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by add_store_member(), connection_create(), GCP_add_connection(), GNUNET_PQ_event_listen(), GNUNET_TESTING_get_topo_from_string(), handle_connection_create(), handle_id_message(), handle_join_message(), kce_generate(), notify_connect(), and start_dv_learn().

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

◆ GNUNET_CONTAINER_multishortmap_size()

unsigned int GNUNET_CONTAINER_multishortmap_size ( const struct GNUNET_CONTAINER_MultiShortmap map)

Get the number of key-value pairs in the map.

Parameters
mapthe map
Returns
the number of key value pairs

Definition at line 274 of file container_multishortmap.c.

276 {
277  return map->size;
278 }

References map, and GNUNET_CONTAINER_MultiPeerMap::size.

Referenced by consider_peer_activate(), consider_peer_destroy(), destroy_peer(), destroy_route(), GCO_shutdown(), generate_free_member_id(), GNUNET_PQ_disconnect(), GNUNET_PQ_event_listen_cancel(), handle_connection_create(), kce_generate(), scheduler_fd_cb(), secret_destroy(), and start_dv_learn().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_iterate()

int GNUNET_CONTAINER_multishortmap_iterate ( struct GNUNET_CONTAINER_MultiShortmap map,
GNUNET_CONTAINER_ShortmapIterator  it,
void *  it_cls 
)

Iterate over all entries in the map.

Parameters
mapthe map
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 306 of file container_multishortmap.c.

310 {
311  int count;
312  union MapEntry me;
313  union MapEntry *ce;
314  struct GNUNET_ShortHashCode kc;
315 
316  count = 0;
317  GNUNET_assert (NULL != map);
318  ce = &map->next_cache[map->next_cache_off];
320  for (unsigned int i = 0; i < map->map_length; i++)
321  {
322  me = map->map[i];
323  if (map->use_small_entries)
324  {
325  struct SmallMapEntry *sme;
326 
327  ce->sme = me.sme;
328  while (NULL != (sme = ce->sme))
329  {
330  ce->sme = sme->next;
331  if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
332  {
334  return GNUNET_SYSERR;
335  }
336  count++;
337  }
338  }
339  else
340  {
341  struct BigMapEntry *bme;
342 
343  ce->bme = me.bme;
344  while (NULL != (bme = ce->bme))
345  {
346  ce->bme = bme->next;
347  if (NULL != it)
348  {
349  kc = bme->key;
350  if (GNUNET_OK != it (it_cls, &kc, bme->value))
351  {
353  return GNUNET_SYSERR;
354  }
355  }
356  count++;
357  }
358  }
359  }
361  return count;
362 }
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
A 256-bit hashcode.

References MapEntry::bme, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by clear_member_store(), find_room_member(), free_namespaces_cb(), GNUNET_PQ_event_reconnect_(), GNUNET_TESTING_free_topology(), iterate_room_members(), iterate_store_members(), load_member_store(), log_namespaces(), log_topo(), save_member_store(), and send_simple_run().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_iterator_create()

struct GNUNET_CONTAINER_MultiShortmapIterator* GNUNET_CONTAINER_multishortmap_iterator_create ( const struct GNUNET_CONTAINER_MultiShortmap map)

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multishortmap_iterate). Note that the iterator can not be used anymore if elements have been removed from map after the creation of the iterator, or 'map' has been destroyed. Adding elements to map may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Definition at line 837 of file container_multishortmap.c.

839 {
841 
843  iter->map = map;
845  iter->me = map->map[0];
846  return iter;
847 }
union MapEntry me
Position in the bucket 'idx'.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.
const struct GNUNET_CONTAINER_MultiShortmap * map
Map that we are iterating over.

References GNUNET_new, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiShortmapIterator::map, GNUNET_CONTAINER_MultiShortmapIterator::me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, and GNUNET_CONTAINER_MultiShortmapIterator::modification_counter.

Referenced by backchannel_check_run().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_iterator_next()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_iterator_next ( struct GNUNET_CONTAINER_MultiShortmapIterator iter,
struct GNUNET_ShortHashCode key,
const void **  value 
)

Retrieve the next element from the hash map at the iterator's position.

If there are no elements left, GNUNET_NO is returned, and key and value are not modified. This operation is only allowed if no elements have been removed from the multihashmap since the creation of iter, and the map has not been destroyed. Adding elements may result in repeating or skipping elements.

Parameters
iterthe iterator to get the next element from
keypointer to store the key in, can be NULL
valuepointer to store the value in, can be NULL
Returns
GNUNET_YES we returned an element, GNUNET_NO if we are out of elements

Definition at line 851 of file container_multishortmap.c.

855 {
856  /* make sure the map has not been modified */
858 
859  /* look for the next entry, skipping empty buckets */
860  while (1)
861  {
862  if (iter->idx >= iter->map->map_length)
863  return GNUNET_NO;
864  if (GNUNET_YES == iter->map->use_small_entries)
865  {
866  if (NULL != iter->me.sme)
867  {
868  if (NULL != key)
869  *key = *iter->me.sme->key;
870  if (NULL != value)
871  *value = iter->me.sme->value;
872  iter->me.sme = iter->me.sme->next;
873  return GNUNET_YES;
874  }
875  }
876  else
877  {
878  if (NULL != iter->me.bme)
879  {
880  if (NULL != key)
881  *key = iter->me.bme->key;
882  if (NULL != value)
883  *value = iter->me.bme->value;
884  iter->me.bme = iter->me.bme->next;
885  return GNUNET_YES;
886  }
887  }
888  iter->idx += 1;
889  if (iter->idx < iter->map->map_length)
890  iter->me = iter->map->map[iter->idx];
891  }
892 }
unsigned int idx
Current bucket index.
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...
unsigned int map_length
Length of the "map" array.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
union MapEntry * map
All of our buckets.

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiShortmapIterator::idx, key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiShortmap::map, GNUNET_CONTAINER_MultiShortmapIterator::map, GNUNET_CONTAINER_MultiShortmap::map_length, GNUNET_CONTAINER_MultiShortmapIterator::me, GNUNET_CONTAINER_MultiShortmap::modification_counter, GNUNET_CONTAINER_MultiShortmapIterator::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiShortmap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by backchannel_check_run().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multishortmap_iterator_destroy()

void GNUNET_CONTAINER_multishortmap_iterator_destroy ( struct GNUNET_CONTAINER_MultiShortmapIterator iter)

Destroy a multishortmap iterator.

Parameters
iterthe iterator to destroy

Definition at line 896 of file container_multishortmap.c.

898 {
899  GNUNET_free (iter);
900 }

References GNUNET_free.

◆ GNUNET_CONTAINER_multishortmap_get_multiple()

int GNUNET_CONTAINER_multishortmap_get_multiple ( struct GNUNET_CONTAINER_MultiShortmap map,
const struct GNUNET_ShortHashCode key,
GNUNET_CONTAINER_ShortmapIterator  it,
void *  it_cls 
)

Iterate over all entries in the map that match a particular key.

Parameters
mapthe map
keypublic key that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration
Parameters
mapthe map
keykey that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 721 of file container_multishortmap.c.

726 {
727  int count;
728  union MapEntry me;
729  union MapEntry *ce;
730 
731  ce = &map->next_cache[map->next_cache_off];
733  count = 0;
734  me = map->map[idx_of (map, key)];
735  if (map->use_small_entries)
736  {
737  struct SmallMapEntry *sme;
738 
739  ce->sme = me.sme;
740  while (NULL != (sme = ce->sme))
741  {
742  ce->sme = sme->next;
743  if (0 != GNUNET_memcmp (key, sme->key))
744  continue;
745  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
746  {
748  return GNUNET_SYSERR;
749  }
750  count++;
751  }
752  }
753  else
754  {
755  struct BigMapEntry *bme;
756 
757  ce->bme = me.bme;
758  while (NULL != (bme = ce->bme))
759  {
760  ce->bme = bme->next;
761  if (0 != GNUNET_memcmp (key, &bme->key))
762  continue;
763  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
764  {
766  return GNUNET_SYSERR;
767  }
768  count++;
769  }
770  }
772  return count;
773 }

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by event_do_poll().

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

◆ GNUNET_CONTAINER_multishortmap_get_random()

unsigned int GNUNET_CONTAINER_multishortmap_get_random ( const struct GNUNET_CONTAINER_MultiShortmap map,
GNUNET_CONTAINER_ShortmapIterator  it,
void *  it_cls 
)

Call it on a random value from the map, or not at all if the map is empty.

Note that this function has linear complexity (in the size of the map).

Parameters
mapthe map
itfunction to call on a random entry
it_clsextra argument to it
Returns
the number of key value pairs processed, zero or one.

Definition at line 788 of file container_multishortmap.c.

792 {
793  unsigned int off;
794  union MapEntry me;
795 
796  if (0 == map->size)
797  return 0;
798  if (NULL == it)
799  return 1;
801  for (unsigned int idx = 0; idx < map->map_length; idx++)
802  {
803  me = map->map[idx];
804  if (map->use_small_entries)
805  {
806  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
807  {
808  if (0 == off)
809  {
810  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
811  return GNUNET_SYSERR;
812  return 1;
813  }
814  off--;
815  }
816  }
817  else
818  {
819  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
820  {
821  if (0 == off)
822  {
823  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
824  return GNUNET_SYSERR;
825  return 1;
826  }
827  off--;
828  }
829  }
830  }
831  GNUNET_break (0);
832  return GNUNET_SYSERR;
833 }

References MapEntry::bme, GNUNET_break, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_create()

struct GNUNET_CONTAINER_MultiUuidmap* GNUNET_CONTAINER_multiuuidmap_create ( unsigned int  len,
int  do_not_copy_keys 
)

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Create a multi peer map (hash map for public keys of peers).

Parameters
leninitial size (map will grow as needed)
do_not_copy_keysGNUNET_NO is always safe and should be used by default; GNUNET_YES means that on 'put', the 'key' does not have to be copied as the destination of the pointer is guaranteed to be life as long as the value is stored in the hashmap. This can significantly reduce memory consumption, but of course is also a recipe for heap corruption if the assumption is not true. Only use this if (1) memory use is important in this case and (2) you have triple-checked that the invariant holds
Returns
NULL on error

Definition at line 194 of file container_multiuuidmap.c.

195 {
197 
198  GNUNET_assert (len > 0);
200  map->map = GNUNET_malloc_large (len * sizeof(union MapEntry));
201  if (NULL == map->map)
202  {
203  GNUNET_free (map);
204  return NULL;
205  }
206  map->map_length = len;
207  map->use_small_entries = do_not_copy_keys;
208  return map;
209 }
Internal representation of the hash map.

References GNUNET_assert, GNUNET_free, GNUNET_malloc_large, GNUNET_new, len, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by run().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_destroy()

void GNUNET_CONTAINER_multiuuidmap_destroy ( struct GNUNET_CONTAINER_MultiUuidmap map)

Destroy a hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 213 of file container_multiuuidmap.c.

215 {
217  for (unsigned int i = 0; i < map->map_length; i++)
218  {
219  union MapEntry me;
220 
221  me = map->map[i];
222  if (map->use_small_entries)
223  {
224  struct SmallMapEntry *sme;
225  struct SmallMapEntry *nxt;
226 
227  nxt = me.sme;
228  while (NULL != (sme = nxt))
229  {
230  nxt = sme->next;
231  GNUNET_free (sme);
232  }
233  me.sme = NULL;
234  }
235  else
236  {
237  struct BigMapEntry *bme;
238  struct BigMapEntry *nxt;
239 
240  nxt = me.bme;
241  while (NULL != (bme = nxt))
242  {
243  nxt = bme->next;
244  GNUNET_free (bme);
245  }
246  me.bme = NULL;
247  }
248  }
249  GNUNET_free (map->map);
250  GNUNET_free (map);
251 }

References GNUNET_assert, GNUNET_free, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Referenced by do_shutdown().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_get()

void* GNUNET_CONTAINER_multiuuidmap_get ( const struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 282 of file container_multiuuidmap.c.

285 {
286  union MapEntry me;
287 
288  me = map->map[idx_of (map, key)];
289  if (map->use_small_entries)
290  {
291  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
292  if (0 == GNUNET_memcmp (key, sme->key))
293  return sme->value;
294  }
295  else
296  {
297  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
298  if (0 == GNUNET_memcmp (key, &bme->key))
299  return bme->value;
300  }
301  return NULL;
302 }
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiUuidmap *map, const struct GNUNET_Uuid *key)
Compute the index of the bucket for the given key.

References MapEntry::bme, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by handle_reliability_ack().

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

◆ GNUNET_CONTAINER_multiuuidmap_remove()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_remove ( struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key,
const void *  value 
)

Remove the given key-value pair from the map.

Note that if the key-value pair is in the map multiple times, only one of the pairs will be removed.

Parameters
mapthe map
keykey of the key-value pair
valuevalue of the key-value pair
Returns
GNUNET_YES on success, GNUNET_NO if the key-value pair is not in the map

Definition at line 400 of file container_multiuuidmap.c.

403 {
404  union MapEntry me;
405  unsigned int i;
406 
408  i = idx_of (map, key);
409  me = map->map[i];
410  if (map->use_small_entries)
411  {
412  struct SmallMapEntry *p = NULL;
413 
414  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
415  {
416  if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
417  {
418  if (NULL == p)
419  map->map[i].sme = sme->next;
420  else
421  p->next = sme->next;
422  update_next_cache_sme (map, sme);
423  GNUNET_free (sme);
424  map->size--;
425  return GNUNET_YES;
426  }
427  p = sme;
428  }
429  }
430  else
431  {
432  struct BigMapEntry *p = NULL;
433 
434  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
435  {
436  if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
437  {
438  if (NULL == p)
439  map->map[i].bme = bme->next;
440  else
441  p->next = bme->next;
442  update_next_cache_bme (map, bme);
443  GNUNET_free (bme);
444  map->size--;
445  return GNUNET_YES;
446  }
447  p = bme;
448  }
449  }
450  return GNUNET_NO;
451 }
static void update_next_cache_sme(struct GNUNET_CONTAINER_MultiUuidmap *map, const struct SmallMapEntry *sme)
We are about to free() the sme, make sure it is not in the list of next values for any iterator in th...
static void update_next_cache_bme(struct GNUNET_CONTAINER_MultiUuidmap *map, const struct BigMapEntry *bme)
We are about to free() the bme, make sure it is not in the list of next values for any iterator in th...

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), GNUNET_CONTAINER_MultiPeerMap::use_small_entries, and value.

Referenced by free_pending_acknowledgement().

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

◆ GNUNET_CONTAINER_multiuuidmap_remove_all()

int GNUNET_CONTAINER_multiuuidmap_remove_all ( struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key 
)

Remove all entries for the given key from the map.

Note that the values would not be "freed".

Parameters
mapthe map
keyidentifies values to be removed
Returns
number of values removed

Definition at line 455 of file container_multiuuidmap.c.

458 {
459  union MapEntry me;
460  unsigned int i;
461  int ret;
462 
464 
465  ret = 0;
466  i = idx_of (map, key);
467  me = map->map[i];
468  if (map->use_small_entries)
469  {
470  struct SmallMapEntry *sme;
471  struct SmallMapEntry *p;
472 
473  p = NULL;
474  sme = me.sme;
475  while (NULL != sme)
476  {
477  if (0 == GNUNET_memcmp (key, sme->key))
478  {
479  if (NULL == p)
480  map->map[i].sme = sme->next;
481  else
482  p->next = sme->next;
483  update_next_cache_sme (map, sme);
484  GNUNET_free (sme);
485  map->size--;
486  if (NULL == p)
487  sme = map->map[i].sme;
488  else
489  sme = p->next;
490  ret++;
491  }
492  else
493  {
494  p = sme;
495  sme = sme->next;
496  }
497  }
498  }
499  else
500  {
501  struct BigMapEntry *bme;
502  struct BigMapEntry *p;
503 
504  p = NULL;
505  bme = me.bme;
506  while (NULL != bme)
507  {
508  if (0 == GNUNET_memcmp (key, &bme->key))
509  {
510  if (NULL == p)
511  map->map[i].bme = bme->next;
512  else
513  p->next = bme->next;
514  update_next_cache_bme (map, bme);
515  GNUNET_free (bme);
516  map->size--;
517  if (NULL == p)
518  bme = map->map[i].bme;
519  else
520  bme = p->next;
521  ret++;
522  }
523  else
524  {
525  p = bme;
526  bme = bme->next;
527  }
528  }
529  }
530  return ret;
531 }

References MapEntry::bme, GNUNET_free, GNUNET_memcmp, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, BigMapEntry::next, SmallMapEntry::next, p, ret, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, update_next_cache_bme(), update_next_cache_sme(), and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_contains()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_contains ( const struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key 
)

Check if the map contains any value under the given key (including values that are NULL).

Parameters
mapthe map
keythe key to test if a value exists for it
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 535 of file container_multiuuidmap.c.

538 {
539  union MapEntry me;
540 
541  me = map->map[idx_of (map, key)];
542  if (map->use_small_entries)
543  {
544  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
545  if (0 == GNUNET_memcmp (key, sme->key))
546  return GNUNET_YES;
547  }
548  else
549  {
550  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
551  if (0 == GNUNET_memcmp (key, &bme->key))
552  return GNUNET_YES;
553  }
554  return GNUNET_NO;
555 }

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, and GNUNET_CONTAINER_MultiPeerMap::use_small_entries.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_contains_value()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_contains_value ( const struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key,
const void *  value 
)

Check if the map contains the given value under the given key.

Parameters
mapthe map
keythe key to test if a value exists for it
valuevalue to test for
Returns
GNUNET_YES if such a value exists, GNUNET_NO if not

Definition at line 559 of file container_multiuuidmap.c.

563 {
564  union MapEntry me;
565 
566  me = map->map[idx_of (map, key)];
567  if (map->use_small_entries)
568  {
569  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
570  if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
571  return GNUNET_YES;
572  }
573  else
574  {
575  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
576  if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
577  return GNUNET_YES;
578  }
579  return GNUNET_NO;
580 }

References MapEntry::bme, GNUNET_memcmp, GNUNET_NO, GNUNET_YES, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_put()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_put ( struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key,
void *  value,
enum GNUNET_CONTAINER_MultiHashMapOption  opt 
)

Store a key-value pair in the map.

Parameters
mapthe map
keykey to use
valuevalue to use
optoptions for put
Returns
GNUNET_OK on success, GNUNET_NO if a value was replaced (with REPLACE) GNUNET_SYSERR if GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the value already exists

Definition at line 642 of file container_multiuuidmap.c.

646 {
647  union MapEntry me;
648  unsigned int i;
649 
650  i = idx_of (map, key);
653  {
654  me = map->map[i];
655  if (map->use_small_entries)
656  {
657  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
658  if (0 == GNUNET_memcmp (key, sme->key))
659  {
661  return GNUNET_SYSERR;
662  sme->value = value;
663  return GNUNET_NO;
664  }
665  }
666  else
667  {
668  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
669  if (0 == GNUNET_memcmp (key, &bme->key))
670  {
672  return GNUNET_SYSERR;
673  bme->value = value;
674  return GNUNET_NO;
675  }
676  }
677  }
678  if (map->size / 3 >= map->map_length / 4)
679  {
680  grow (map);
681  i = idx_of (map, key);
682  }
683  if (map->use_small_entries)
684  {
685  struct SmallMapEntry *sme;
686 
687  sme = GNUNET_new (struct SmallMapEntry);
688  sme->key = key;
689  sme->value = value;
690  sme->next = map->map[i].sme;
691  map->map[i].sme = sme;
692  }
693  else
694  {
695  struct BigMapEntry *bme;
696 
697  bme = GNUNET_new (struct BigMapEntry);
698  bme->key = *key;
699  bme->value = value;
700  bme->next = map->map[i].bme;
701  map->map[i].bme = bme;
702  }
703  map->size++;
704  return GNUNET_OK;
705 }
static void grow(struct GNUNET_CONTAINER_MultiUuidmap *map)
Grow the given map to a more appropriate size.

References MapEntry::bme, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, grow(), idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

Referenced by prepare_pending_acknowledgement().

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

◆ GNUNET_CONTAINER_multiuuidmap_size()

unsigned int GNUNET_CONTAINER_multiuuidmap_size ( const struct GNUNET_CONTAINER_MultiUuidmap map)

Get the number of key-value pairs in the map.

Parameters
mapthe map
Returns
the number of key value pairs

Definition at line 274 of file container_multiuuidmap.c.

276 {
277  return map->size;
278 }

References map, and GNUNET_CONTAINER_MultiPeerMap::size.

◆ GNUNET_CONTAINER_multiuuidmap_iterate()

int GNUNET_CONTAINER_multiuuidmap_iterate ( struct GNUNET_CONTAINER_MultiUuidmap map,
GNUNET_CONTAINER_MultiUuidmapIteratorCallback  it,
void *  it_cls 
)

Iterate over all entries in the map.

Parameters
mapthe map
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 306 of file container_multiuuidmap.c.

310 {
311  int count;
312  union MapEntry me;
313  union MapEntry *ce;
314  struct GNUNET_Uuid kc;
315 
316  count = 0;
317  GNUNET_assert (NULL != map);
318  ce = &map->next_cache[map->next_cache_off];
320  for (unsigned int i = 0; i < map->map_length; i++)
321  {
322  me = map->map[i];
323  if (map->use_small_entries)
324  {
325  struct SmallMapEntry *sme;
326 
327  ce->sme = me.sme;
328  while (NULL != (sme = ce->sme))
329  {
330  ce->sme = sme->next;
331  if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
332  {
334  return GNUNET_SYSERR;
335  }
336  count++;
337  }
338  }
339  else
340  {
341  struct BigMapEntry *bme;
342 
343  ce->bme = me.bme;
344  while (NULL != (bme = ce->bme))
345  {
346  ce->bme = bme->next;
347  if (NULL != it)
348  {
349  kc = bme->key;
350  if (GNUNET_OK != it (it_cls, &kc, bme->value))
351  {
353  return GNUNET_SYSERR;
354  }
355  }
356  count++;
357  }
358  }
359  }
361  return count;
362 }
#define NEXT_CACHE_SIZE
Maximum recursion depth for callbacks of GNUNET_CONTAINER_multihashmap_get_multiple() themselves s ag...
A UUID, a 128 bit "random" value.

References MapEntry::bme, GNUNET_assert, GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Referenced by do_shutdown().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_iterator_create()

struct GNUNET_CONTAINER_MultiUuidmapIterator* GNUNET_CONTAINER_multiuuidmap_iterator_create ( const struct GNUNET_CONTAINER_MultiUuidmap map)

Create an iterator for a multihashmap.

The iterator can be used to retrieve all the elements in the multihashmap one by one, without having to handle all elements at once (in contrast to GNUNET_CONTAINER_multiuuidmap_iterate). Note that the iterator can not be used anymore if elements have been removed from map after the creation of the iterator, or 'map' has been destroyed. Adding elements to map may result in skipped or repeated elements.

Parameters
mapthe map to create an iterator for
Returns
an iterator over the given multihashmap map

Definition at line 835 of file container_multiuuidmap.c.

837 {
839 
841  iter->map = map;
843  iter->me = map->map[0];
844  return iter;
845 }
const struct GNUNET_CONTAINER_MultiUuidmap * map
Map that we are iterating over.
union MapEntry me
Position in the bucket 'idx'.
unsigned int modification_counter
Modification counter as observed on the map when the iterator was created.

References GNUNET_new, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiUuidmapIterator::map, GNUNET_CONTAINER_MultiUuidmapIterator::me, GNUNET_CONTAINER_MultiPeerMap::modification_counter, and GNUNET_CONTAINER_MultiUuidmapIterator::modification_counter.

◆ GNUNET_CONTAINER_multiuuidmap_iterator_next()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multiuuidmap_iterator_next ( struct GNUNET_CONTAINER_MultiUuidmapIterator iter,
struct GNUNET_Uuid key,
const void **  value 
)

Retrieve the next element from the hash map at the iterator's position.

If there are no elements left, GNUNET_NO is returned, and key and value are not modified. This operation is only allowed if no elements have been removed from the multihashmap since the creation of iter, and the map has not been destroyed. Adding elements may result in repeating or skipping elements.

Parameters
iterthe iterator to get the next element from
keypointer to store the key in, can be NULL
valuepointer to store the value in, can be NULL
Returns
GNUNET_YES we returned an element, GNUNET_NO if we are out of elements

Definition at line 849 of file container_multiuuidmap.c.

853 {
854  /* make sure the map has not been modified */
856 
857  /* look for the next entry, skipping empty buckets */
858  while (1)
859  {
860  if (iter->idx >= iter->map->map_length)
861  return GNUNET_NO;
862  if (GNUNET_YES == iter->map->use_small_entries)
863  {
864  if (NULL != iter->me.sme)
865  {
866  if (NULL != key)
867  *key = *iter->me.sme->key;
868  if (NULL != value)
869  *value = iter->me.sme->value;
870  iter->me.sme = iter->me.sme->next;
871  return GNUNET_YES;
872  }
873  }
874  else
875  {
876  if (NULL != iter->me.bme)
877  {
878  if (NULL != key)
879  *key = iter->me.bme->key;
880  if (NULL != value)
881  *value = iter->me.bme->value;
882  iter->me.bme = iter->me.bme->next;
883  return GNUNET_YES;
884  }
885  }
886  iter->idx += 1;
887  if (iter->idx < iter->map->map_length)
888  iter->me = iter->map->map[iter->idx];
889  }
890 }
unsigned int idx
Current bucket index.
union MapEntry * map
All of our buckets.
unsigned int map_length
Length of the "map" array.
unsigned int modification_counter
Counts the destructive modifications (grow, remove) to the map, so that iterators can check if they a...
int use_small_entries
GNUNET_NO if the map entries are of type 'struct BigMapEntry', GNUNET_YES if the map entries are of t...

References MapEntry::bme, GNUNET_assert, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MultiUuidmapIterator::idx, key, BigMapEntry::key, SmallMapEntry::key, GNUNET_CONTAINER_MultiUuidmap::map, GNUNET_CONTAINER_MultiUuidmapIterator::map, GNUNET_CONTAINER_MultiUuidmap::map_length, GNUNET_CONTAINER_MultiUuidmapIterator::me, GNUNET_CONTAINER_MultiUuidmap::modification_counter, GNUNET_CONTAINER_MultiUuidmapIterator::modification_counter, BigMapEntry::next, SmallMapEntry::next, MapEntry::sme, GNUNET_CONTAINER_MultiUuidmap::use_small_entries, value, BigMapEntry::value, and SmallMapEntry::value.

◆ GNUNET_CONTAINER_multiuuidmap_iterator_destroy()

void GNUNET_CONTAINER_multiuuidmap_iterator_destroy ( struct GNUNET_CONTAINER_MultiUuidmapIterator iter)

Destroy a multiuuidmap iterator.

Parameters
iterthe iterator to destroy

Definition at line 894 of file container_multiuuidmap.c.

896 {
897  GNUNET_free (iter);
898 }

References GNUNET_free.

◆ GNUNET_CONTAINER_multiuuidmap_get_multiple()

int GNUNET_CONTAINER_multiuuidmap_get_multiple ( struct GNUNET_CONTAINER_MultiUuidmap map,
const struct GNUNET_Uuid key,
GNUNET_CONTAINER_MultiUuidmapIteratorCallback  it,
void *  it_cls 
)

Iterate over all entries in the map that match a particular key.

Parameters
mapthe map
keypublic key that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration
Parameters
mapthe map
keykey that the entries must correspond to
itfunction to call on each entry
it_clsextra argument to it
Returns
the number of key value pairs processed, GNUNET_SYSERR if it aborted iteration

Definition at line 719 of file container_multiuuidmap.c.

724 {
725  int count;
726  union MapEntry me;
727  union MapEntry *ce;
728 
729  ce = &map->next_cache[map->next_cache_off];
731  count = 0;
732  me = map->map[idx_of (map, key)];
733  if (map->use_small_entries)
734  {
735  struct SmallMapEntry *sme;
736 
737  ce->sme = me.sme;
738  while (NULL != (sme = ce->sme))
739  {
740  ce->sme = sme->next;
741  if (0 != GNUNET_memcmp (key, sme->key))
742  continue;
743  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
744  {
746  return GNUNET_SYSERR;
747  }
748  count++;
749  }
750  }
751  else
752  {
753  struct BigMapEntry *bme;
754 
755  ce->bme = me.bme;
756  while (NULL != (bme = ce->bme))
757  {
758  ce->bme = bme->next;
759  if (0 != GNUNET_memcmp (key, &bme->key))
760  continue;
761  if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
762  {
764  return GNUNET_SYSERR;
765  }
766  count++;
767  }
768  }
770  return count;
771 }

References MapEntry::bme, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, idx_of(), key, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::next_cache, GNUNET_CONTAINER_MultiPeerMap::next_cache_off, NEXT_CACHE_SIZE, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multiuuidmap_get_random()

unsigned int GNUNET_CONTAINER_multiuuidmap_get_random ( const struct GNUNET_CONTAINER_MultiUuidmap map,
GNUNET_CONTAINER_MultiUuidmapIteratorCallback  it,
void *  it_cls 
)

Call it on a random value from the map, or not at all if the map is empty.

Note that this function has linear complexity (in the size of the map).

Parameters
mapthe map
itfunction to call on a random entry
it_clsextra argument to it
Returns
the number of key value pairs processed, zero or one.

Definition at line 786 of file container_multiuuidmap.c.

790 {
791  unsigned int off;
792  union MapEntry me;
793 
794  if (0 == map->size)
795  return 0;
796  if (NULL == it)
797  return 1;
799  for (unsigned int idx = 0; idx < map->map_length; idx++)
800  {
801  me = map->map[idx];
802  if (map->use_small_entries)
803  {
804  for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
805  {
806  if (0 == off)
807  {
808  if (GNUNET_OK != it (it_cls, sme->key, sme->value))
809  return GNUNET_SYSERR;
810  return 1;
811  }
812  off--;
813  }
814  }
815  else
816  {
817  for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
818  {
819  if (0 == off)
820  {
821  if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
822  return GNUNET_SYSERR;
823  return 1;
824  }
825  off--;
826  }
827  }
828  }
829  GNUNET_break (0);
830  return GNUNET_SYSERR;
831 }

References MapEntry::bme, GNUNET_break, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_OK, GNUNET_SYSERR, BigMapEntry::key, SmallMapEntry::key, map, GNUNET_CONTAINER_MultiPeerMap::map, GNUNET_CONTAINER_MultiPeerMap::map_length, me, BigMapEntry::next, SmallMapEntry::next, GNUNET_CONTAINER_MultiPeerMap::size, MapEntry::sme, GNUNET_CONTAINER_MultiPeerMap::use_small_entries, BigMapEntry::value, and SmallMapEntry::value.

Here is the call graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_create()

struct GNUNET_CONTAINER_MultiHashMap32* GNUNET_CONTAINER_multihashmap32_create ( unsigned int  len)

Create a 32-bit key multi hash map.

Parameters
leninitial size (map will grow as needed)
Returns
NULL on error

Create a 32-bit key multi hash map.

Parameters
leninitial size (map will grow as needed)
Returns
NULL on error

Definition at line 141 of file container_multihashmap32.c.

142 {
144 
145  GNUNET_assert (len > 0);
147  ret->map = GNUNET_malloc_large (len * sizeof(struct MapEntry *));
148  if (NULL == ret->map)
149  {
150  GNUNET_free (ret);
151  return NULL;
152  }
153  ret->map_length = len;
154  return ret;
155 }
Internal representation of the hash map.

References GNUNET_assert, GNUNET_free, GNUNET_malloc_large, GNUNET_new, len, and ret.

Referenced by client_connect_cb(), CustomPeerMap_create(), GCT_create_tunnel(), GNUNET_CADET_connect(), GNUNET_MQ_assoc_add(), GNUNET_TESTBED_insert_opc_(), GNUNET_TESTBED_run(), GNUNET_TRANSPORT_monitor_plugins(), GST_cache_init(), GST_connection_pool_init(), handle_fragment_box(), and initialize_key_to_element().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_destroy()

void GNUNET_CONTAINER_multihashmap32_destroy ( struct GNUNET_CONTAINER_MultiHashMap32 map)

Destroy a 32-bit key hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Destroy a 32-bit key hash map.

Will not free any values stored in the hash map!

Parameters
mapthe map

Definition at line 165 of file container_multihashmap32.c.

167 {
168  struct MapEntry *e;
169 
170  for (unsigned int i = 0; i < map->map_length; i++)
171  {
172  while (NULL != (e = map->map[i]))
173  {
174  map->map[i] = e->next;
175  GNUNET_free (e);
176  }
177  }
178  GNUNET_free (map->map);
179  GNUNET_free (map);
180 }
static struct Experiment * e

References e, GNUNET_free, map, GNUNET_CONTAINER_MultiPeerMap::map, and GNUNET_CONTAINER_MultiPeerMap::map_length.

Referenced by _GSS_operation_destroy(), cleanup(), client_disconnect_cb(), CustomPeerMap_destroy(), destroy_tunnel(), free_virtual_link(), GNUNET_CADET_disconnect(), GNUNET_MQ_destroy(), GNUNET_TESTBED_controller_disconnect(), GNUNET_TRANSPORT_monitor_plugins_cancel(), GST_cache_clear(), GST_connection_pool_destroy(), and union_op_cancel().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_size()

unsigned int GNUNET_CONTAINER_multihashmap32_size ( const struct GNUNET_CONTAINER_MultiHashMap32 map)

Get the number of key-value pairs in the map.

Parameters
mapthe map
Returns
the number of key value pairs

Definition at line 199 of file container_multihashmap32.c.

201 {
202  return map->size;
203 }

References map, and GNUNET_CONTAINER_MultiPeerMap::size.

Referenced by add_entry(), cleanup(), client_disconnect_cb(), CustomPeerMap_put(), CustomPeerMap_remove_peer(), CustomPeerMap_remove_peer_by_index(), CustomPeerMap_size(), GCT_count_channels(), GNUNET_TESTBED_controller_disconnect(), GNUNET_TESTBED_remove_opc_(), GNUNET_TESTBED_shutdown_peers(), GST_cache_clear(), GST_connection_pool_get_handle(), GST_connection_pool_get_handle_done(), handle_client_accept(), handle_client_evaluate(), interrupt(), send_client_done(), send_client_element(), union_accept(), and union_evaluate().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_multihashmap32_get()

void* GNUNET_CONTAINER_multihashmap32_get ( const struct GNUNET_CONTAINER_MultiHashMap32 map,
uint32_t  key 
)

Given a key find a value in the map matching the key.

Parameters
mapthe map
keywhat to look for
Returns
NULL if no value was found; note that this is indistinguishable from values that just happen to be NULL; use "contains" to test for key-value pairs with value NULL

Definition at line 207 of file container_multihashmap32.c.

210 {
211  struct MapEntry *e;
212 
213  e = map->map[idx_of (map, key)];
214  while (NULL != e)
215  {
216  if (key == e->key)
217  return e->value;
218  e = e->next;
219  }
220  return NULL;
221 }
static unsigned int idx_of(const struct GNUNET_CONTAINER_MultiHashMap32 *m, const uint32_t key)
Compute the index of the bucket for the given key.

References e, idx_of(),