From 9ae7f13f17e3d04d3ba88862299c8e42541eab47 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 18 Jun 2019 10:30:08 +0200 Subject: Introducing GNUNET_Uuid and matching hash map for 128 bit values. TNG: reducing size of AcknowledgementUUIDPs from 256 bits to 128 bits. --- src/include/gnunet_common.h | 25 + src/include/gnunet_container_lib.h | 1127 ++++++++++++++++++++++++------------ src/transport/gnunet-service-tng.c | 42 +- src/util/Makefile.am | 1 + src/util/common_logging.c | 393 ++++++------- src/util/container_multiuuidmap.c | 1015 ++++++++++++++++++++++++++++++++ 6 files changed, 1979 insertions(+), 624 deletions(-) create mode 100644 src/util/container_multiuuidmap.c diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 0fca53b7f..6b48c81d8 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -272,6 +272,18 @@ struct GNUNET_ShortHashCode }; +/** + * A UUID, a 128 bit random value. + */ +struct GNUNET_Uuid +{ + /** + * 128 random bits. + */ + uint32_t value[4]; +}; + + /** * Header for all communications. */ @@ -653,6 +665,19 @@ const char * GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc); +/** + * @ingroup logging + * Convert a UUID to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param uuid the UUID + * @return string + */ +const char * +GNUNET_uuid2s (const struct GNUNET_Uuid *uuid); + + /** * @ingroup logging * Convert a hash value to a string (for printing debug messages). diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index fee851e1c..fbfbf2d40 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h @@ -84,9 +84,7 @@ GNUNET_try_compression (const char *data, * @return NULL on error, buffer of @a output_size decompressed bytes otherwise */ char * -GNUNET_decompress (const char *input, - size_t input_size, - size_t output_size); +GNUNET_decompress (const char *input, size_t input_size, size_t output_size); #if HAVE_EXTRACTOR_H @@ -101,7 +99,8 @@ GNUNET_decompress (const char *input, * Enumeration defining various sources of keywords. See also * http://dublincore.org/documents/1998/09/dces/ */ -enum EXTRACTOR_MetaType { +enum EXTRACTOR_MetaType +{ EXTRACTOR_METATYPE_RESERVED = 0, EXTRACTOR_METATYPE_MIMETYPE = 1, EXTRACTOR_METATYPE_FILENAME = 2, @@ -131,7 +130,8 @@ enum EXTRACTOR_MetaType { /** * Format in which the extracted meta data is presented. */ -enum EXTRACTOR_MetaFormat { +enum EXTRACTOR_MetaFormat +{ /** * Format is unknown. */ @@ -173,14 +173,13 @@ enum EXTRACTOR_MetaFormat { * @param data_len number of bytes in @a data * @return 0 to continue extracting, 1 to abort */ -typedef int -(*EXTRACTOR_MetaDataProcessor) (void *cls, - const char *plugin_name, - enum EXTRACTOR_MetaType type, - enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, - const char *data, - size_t data_len); +typedef int (*EXTRACTOR_MetaDataProcessor) (void *cls, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_len); #endif @@ -190,9 +189,8 @@ typedef int #endif #ifdef __cplusplus -extern "C" -{ -#if 0 /* keep Emacsens' auto-indent happy */ +extern "C" { +#if 0 /* keep Emacsens' auto-indent happy */ } #endif #endif @@ -216,9 +214,8 @@ struct GNUNET_CONTAINER_BloomFilter; * @return #GNUNET_YES if next was updated * #GNUNET_NO if there are no more entries */ -typedef int -(*GNUNET_CONTAINER_HashCodeIterator) (void *cls, - struct GNUNET_HashCode *next); +typedef int (*GNUNET_CONTAINER_HashCodeIterator) (void *cls, + struct GNUNET_HashCode *next); /** @@ -269,9 +266,10 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, * @return #GNUNET_SYSERR if the data array of the wrong size */ int -GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct GNUNET_CONTAINER_BloomFilter *bf, - char *data, - size_t size); +GNUNET_CONTAINER_bloomfilter_get_raw_data ( + const struct GNUNET_CONTAINER_BloomFilter *bf, + char *data, + size_t size); /** @@ -283,8 +281,9 @@ GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct GNUNET_CONTAINER_BloomFi * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not */ int -GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf, - const struct GNUNET_HashCode *e); +GNUNET_CONTAINER_bloomfilter_test ( + const struct GNUNET_CONTAINER_BloomFilter *bf, + const struct GNUNET_HashCode *e); /** @@ -319,8 +318,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, * @return copy of bf */ struct GNUNET_CONTAINER_BloomFilter * -GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf); - +GNUNET_CONTAINER_bloomfilter_copy ( + const struct GNUNET_CONTAINER_BloomFilter *bf); /** @@ -342,7 +341,8 @@ GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter *bf); * @return addresses set per element in the bf */ size_t -GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter *bf); +GNUNET_CONTAINER_bloomfilter_get_element_addresses ( + const struct GNUNET_CONTAINER_BloomFilter *bf); /** @@ -353,7 +353,8 @@ GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINE * @return number of bytes used for the data of the bloom filter */ size_t -GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter *bf); +GNUNET_CONTAINER_bloomfilter_get_size ( + const struct GNUNET_CONTAINER_BloomFilter *bf); /** @@ -380,7 +381,8 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf); */ int GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, - const char *data, size_t size); + const char *data, + size_t size); /** @@ -394,8 +396,9 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, * @return #GNUNET_OK on success */ int -GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, - const struct GNUNET_CONTAINER_BloomFilter *to_or); +GNUNET_CONTAINER_bloomfilter_or2 ( + struct GNUNET_CONTAINER_BloomFilter *bf, + const struct GNUNET_CONTAINER_BloomFilter *to_or); /** @@ -445,7 +448,8 @@ GNUNET_CONTAINER_meta_data_create (void); * @return duplicate meta-data container */ struct GNUNET_CONTAINER_MetaData * -GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData *md); +GNUNET_CONTAINER_meta_data_duplicate ( + const struct GNUNET_CONTAINER_MetaData *md); /** @@ -470,8 +474,9 @@ GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md); * @return #GNUNET_YES if they are equal */ int -GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData *md1, - const struct GNUNET_CONTAINER_MetaData *md2); +GNUNET_CONTAINER_meta_data_test_equal ( + const struct GNUNET_CONTAINER_MetaData *md1, + const struct GNUNET_CONTAINER_MetaData *md2); /** @@ -551,7 +556,8 @@ GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md); * @param md metadata to modify */ void -GNUNET_CONTAINER_meta_data_add_publication_date (struct GNUNET_CONTAINER_MetaData *md); +GNUNET_CONTAINER_meta_data_add_publication_date ( + struct GNUNET_CONTAINER_MetaData *md); /** @@ -582,8 +588,9 @@ GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md, * @return NULL if no entry was found */ char * -GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData *md, - enum EXTRACTOR_MetaType type); +GNUNET_CONTAINER_meta_data_get_by_type ( + const struct GNUNET_CONTAINER_MetaData *md, + enum EXTRACTOR_MetaType type); /** @@ -599,8 +606,9 @@ GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData * * otherwise client is responsible for freeing the value! */ char * -GNUNET_CONTAINER_meta_data_get_first_by_types (const struct GNUNET_CONTAINER_MetaData *md, - ...); +GNUNET_CONTAINER_meta_data_get_first_by_types ( + const struct GNUNET_CONTAINER_MetaData *md, + ...); /** * @ingroup metadata @@ -613,9 +621,9 @@ GNUNET_CONTAINER_meta_data_get_first_by_types (const struct GNUNET_CONTAINER_Met * @return number of bytes in thumbnail, 0 if not available */ size_t -GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData *md, - unsigned char **thumb); - +GNUNET_CONTAINER_meta_data_get_thumbnail ( + const struct GNUNET_CONTAINER_MetaData *md, + unsigned char **thumb); /** @@ -661,10 +669,11 @@ enum GNUNET_CONTAINER_MetaDataSerializationOptions * space) */ ssize_t -GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData *md, - char **target, - size_t max, - enum GNUNET_CONTAINER_MetaDataSerializationOptions opt); +GNUNET_CONTAINER_meta_data_serialize ( + const struct GNUNET_CONTAINER_MetaData *md, + char **target, + size_t max, + enum GNUNET_CONTAINER_MetaDataSerializationOptions opt); /** @@ -675,7 +684,8 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData *md * @return number of bytes needed for serialization, -1 on error */ ssize_t -GNUNET_CONTAINER_meta_data_get_serialized_size (const struct GNUNET_CONTAINER_MetaData *md); +GNUNET_CONTAINER_meta_data_get_serialized_size ( + const struct GNUNET_CONTAINER_MetaData *md); /** @@ -688,8 +698,7 @@ GNUNET_CONTAINER_meta_data_get_serialized_size (const struct GNUNET_CONTAINER_Me * bad format) */ struct GNUNET_CONTAINER_MetaData * -GNUNET_CONTAINER_meta_data_deserialize (const char *input, - size_t size); +GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size); /* ******************************* HashMap **************************** */ @@ -759,10 +768,10 @@ enum GNUNET_CONTAINER_MultiHashMapOption * iterate, * #GNUNET_NO if not. */ -typedef int -(*GNUNET_CONTAINER_HashMapIterator) (void *cls, - const struct GNUNET_HashCode *key, - void *value); +typedef int (*GNUNET_CONTAINER_HashMapIterator) ( + void *cls, + const struct GNUNET_HashCode *key, + void *value); /** @@ -782,8 +791,7 @@ typedef int * @return NULL on error */ struct GNUNET_CONTAINER_MultiHashMap * -GNUNET_CONTAINER_multihashmap_create (unsigned int len, - int do_not_copy_keys); +GNUNET_CONTAINER_multihashmap_create (unsigned int len, int do_not_copy_keys); /** @@ -794,7 +802,8 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len, * @param map the map */ void -GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map); +GNUNET_CONTAINER_multihashmap_destroy ( + struct GNUNET_CONTAINER_MultiHashMap *map); /** @@ -809,8 +818,9 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map * key-value pairs with value NULL */ void * -GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map, - const struct GNUNET_HashCode *key); +GNUNET_CONTAINER_multihashmap_get ( + const struct GNUNET_CONTAINER_MultiHashMap *map, + const struct GNUNET_HashCode *key); /** @@ -828,7 +838,7 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *m int GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, - const void *value); + const void *value); /** * @ingroup hashmap @@ -840,8 +850,9 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, * @return number of values removed */ int -GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map, - const struct GNUNET_HashCode *key); +GNUNET_CONTAINER_multihashmap_remove_all ( + struct GNUNET_CONTAINER_MultiHashMap *map, + const struct GNUNET_HashCode *key); /** @@ -867,8 +878,9 @@ GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map); * #GNUNET_NO if not */ int -GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashMap *map, - const struct GNUNET_HashCode * key); +GNUNET_CONTAINER_multihashmap_contains ( + const struct GNUNET_CONTAINER_MultiHashMap *map, + const struct GNUNET_HashCode *key); /** @@ -883,9 +895,10 @@ GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashM * #GNUNET_NO if not */ int -GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map, - const struct GNUNET_HashCode *key, - const void *value); +GNUNET_CONTAINER_multihashmap_contains_value ( + const struct GNUNET_CONTAINER_MultiHashMap *map, + const struct GNUNET_HashCode *key, + const void *value); /** @@ -902,11 +915,11 @@ GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_Mult * value already exists */ int -GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, - const struct GNUNET_HashCode *key, - void *value, - enum GNUNET_CONTAINER_MultiHashMapOption - opt); +GNUNET_CONTAINER_multihashmap_put ( + struct GNUNET_CONTAINER_MultiHashMap *map, + const struct GNUNET_HashCode *key, + void *value, + enum GNUNET_CONTAINER_MultiHashMapOption opt); /** * @ingroup hashmap @@ -916,7 +929,8 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, * @return the number of key value pairs */ unsigned int -GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *map); +GNUNET_CONTAINER_multihashmap_size ( + const struct GNUNET_CONTAINER_MultiHashMap *map); /** @@ -930,9 +944,10 @@ GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap * * #GNUNET_SYSERR if it aborted iteration */ int -GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map, - GNUNET_CONTAINER_HashMapIterator it, - void *it_cls); +GNUNET_CONTAINER_multihashmap_iterate ( + struct GNUNET_CONTAINER_MultiHashMap *map, + GNUNET_CONTAINER_HashMapIterator it, + void *it_cls); /** @@ -949,7 +964,8 @@ GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map * @return an iterator over the given multihashmap @a map */ struct GNUNET_CONTAINER_MultiHashMapIterator * -GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap *map); +GNUNET_CONTAINER_multihashmap_iterator_create ( + const struct GNUNET_CONTAINER_MultiHashMap *map); /** @@ -968,9 +984,10 @@ GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_Mul * #GNUNET_NO if we are out of elements */ int -GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter, - struct GNUNET_HashCode *key, - const void **value); +GNUNET_CONTAINER_multihashmap_iterator_next ( + struct GNUNET_CONTAINER_MultiHashMapIterator *iter, + struct GNUNET_HashCode *key, + const void **value); /** @@ -980,7 +997,8 @@ GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMa * @param iter the iterator to destroy */ void -GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter); +GNUNET_CONTAINER_multihashmap_iterator_destroy ( + struct GNUNET_CONTAINER_MultiHashMapIterator *iter); /** @@ -995,10 +1013,11 @@ GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHas * #GNUNET_SYSERR if it aborted iteration */ int -GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap *map, - const struct GNUNET_HashCode *key, - GNUNET_CONTAINER_HashMapIterator it, - void *it_cls); +GNUNET_CONTAINER_multihashmap_get_multiple ( + struct GNUNET_CONTAINER_MultiHashMap *map, + const struct GNUNET_HashCode *key, + GNUNET_CONTAINER_HashMapIterator it, + void *it_cls); /** @@ -1013,9 +1032,10 @@ GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap * @return the number of key value pairs processed, zero or one. */ unsigned int -GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHashMap *map, - GNUNET_CONTAINER_HashMapIterator it, - void *it_cls); +GNUNET_CONTAINER_multihashmap_get_random ( + const struct GNUNET_CONTAINER_MultiHashMap *map, + GNUNET_CONTAINER_HashMapIterator it, + void *it_cls); /* ***************** Version of Multihashmap for peer identities ****************** */ @@ -1031,10 +1051,10 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHas * iterate, * #GNUNET_NO if not. */ -typedef int -(*GNUNET_CONTAINER_PeerMapIterator) (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value); +typedef int (*GNUNET_CONTAINER_PeerMapIterator) ( + void *cls, + const struct GNUNET_PeerIdentity *key, + void *value); /** @@ -1060,8 +1080,7 @@ struct GNUNET_CONTAINER_MultiPeerMap; * @return NULL on error */ struct GNUNET_CONTAINER_MultiPeerMap * -GNUNET_CONTAINER_multipeermap_create (unsigned int len, - int do_not_copy_keys); +GNUNET_CONTAINER_multipeermap_create (unsigned int len, int do_not_copy_keys); /** @@ -1072,7 +1091,8 @@ GNUNET_CONTAINER_multipeermap_create (unsigned int len, * @param map the map */ void -GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map); +GNUNET_CONTAINER_multipeermap_destroy ( + struct GNUNET_CONTAINER_MultiPeerMap *map); /** @@ -1087,8 +1107,9 @@ GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map * key-value pairs with value NULL */ void * -GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map, - const struct GNUNET_PeerIdentity *key); +GNUNET_CONTAINER_multipeermap_get ( + const struct GNUNET_CONTAINER_MultiPeerMap *map, + const struct GNUNET_PeerIdentity *key); /** @@ -1105,8 +1126,8 @@ GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *m */ int GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, - const struct GNUNET_PeerIdentity * key, - const void *value); + const struct GNUNET_PeerIdentity *key, + const void *value); /** * @ingroup hashmap @@ -1118,8 +1139,9 @@ GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, * @return number of values removed */ int -GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map, - const struct GNUNET_PeerIdentity *key); +GNUNET_CONTAINER_multipeermap_remove_all ( + struct GNUNET_CONTAINER_MultiPeerMap *map, + const struct GNUNET_PeerIdentity *key); /** @@ -1133,8 +1155,9 @@ GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap * * #GNUNET_NO if not */ int -GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map, - const struct GNUNET_PeerIdentity *key); +GNUNET_CONTAINER_multipeermap_contains ( + const struct GNUNET_CONTAINER_MultiPeerMap *map, + const struct GNUNET_PeerIdentity *key); /** @@ -1149,9 +1172,10 @@ GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerM * #GNUNET_NO if not */ int -GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map, - const struct GNUNET_PeerIdentity * key, - const void *value); +GNUNET_CONTAINER_multipeermap_contains_value ( + const struct GNUNET_CONTAINER_MultiPeerMap *map, + const struct GNUNET_PeerIdentity *key, + const void *value); /** @@ -1168,10 +1192,11 @@ GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_Mult * value already exists */ int -GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map, - const struct GNUNET_PeerIdentity *key, - void *value, - enum GNUNET_CONTAINER_MultiHashMapOption opt); +GNUNET_CONTAINER_multipeermap_put ( + struct GNUNET_CONTAINER_MultiPeerMap *map, + const struct GNUNET_PeerIdentity *key, + void *value, + enum GNUNET_CONTAINER_MultiHashMapOption opt); /** @@ -1182,7 +1207,8 @@ GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map, * @return the number of key value pairs */ unsigned int -GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map); +GNUNET_CONTAINER_multipeermap_size ( + const struct GNUNET_CONTAINER_MultiPeerMap *map); /** @@ -1196,9 +1222,10 @@ GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap * * #GNUNET_SYSERR if it aborted iteration */ int -GNUNET_CONTAINER_multipeermap_iterate (struct GNUNET_CONTAINER_MultiPeerMap *map, - GNUNET_CONTAINER_PeerMapIterator it, - void *it_cls); +GNUNET_CONTAINER_multipeermap_iterate ( + struct GNUNET_CONTAINER_MultiPeerMap *map, + GNUNET_CONTAINER_PeerMapIterator it, + void *it_cls); struct GNUNET_CONTAINER_MultiPeerMapIterator; @@ -1216,7 +1243,8 @@ struct GNUNET_CONTAINER_MultiPeerMapIterator; * @return an iterator over the given multihashmap @a map */ struct GNUNET_CONTAINER_MultiPeerMapIterator * -GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map); +GNUNET_CONTAINER_multipeermap_iterator_create ( + const struct GNUNET_CONTAINER_MultiPeerMap *map); /** @@ -1235,9 +1263,10 @@ GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_Mul * #GNUNET_NO if we are out of elements */ int -GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter, - struct GNUNET_PeerIdentity *key, - const void **value); +GNUNET_CONTAINER_multipeermap_iterator_next ( + struct GNUNET_CONTAINER_MultiPeerMapIterator *iter, + struct GNUNET_PeerIdentity *key, + const void **value); /** @@ -1247,7 +1276,8 @@ GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMa * @param iter the iterator to destroy */ void -GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter); +GNUNET_CONTAINER_multipeermap_iterator_destroy ( + struct GNUNET_CONTAINER_MultiPeerMapIterator *iter); /** @@ -1262,10 +1292,11 @@ GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPee * #GNUNET_SYSERR if it aborted iteration */ int -GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap *map, - const struct GNUNET_PeerIdentity *key, - GNUNET_CONTAINER_PeerMapIterator it, - void *it_cls); +GNUNET_CONTAINER_multipeermap_get_multiple ( + struct GNUNET_CONTAINER_MultiPeerMap *map, + const struct GNUNET_PeerIdentity *key, + GNUNET_CONTAINER_PeerMapIterator it, + void *it_cls); /** @@ -1280,9 +1311,10 @@ GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap * @return the number of key value pairs processed, zero or one. */ unsigned int -GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPeerMap *map, - GNUNET_CONTAINER_PeerMapIterator it, - void *it_cls); +GNUNET_CONTAINER_multipeermap_get_random ( + const struct GNUNET_CONTAINER_MultiPeerMap *map, + GNUNET_CONTAINER_PeerMapIterator it, + void *it_cls); /* ***************** Version of Multihashmap for short hashes ****************** */ @@ -1298,10 +1330,10 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPee * iterate, * #GNUNET_NO if not. */ -typedef int -(*GNUNET_CONTAINER_ShortmapIterator) (void *cls, - const struct GNUNET_ShortHashCode *key, - void *value); +typedef int (*GNUNET_CONTAINER_ShortmapIterator) ( + void *cls, + const struct GNUNET_ShortHashCode *key, + void *value); /** @@ -1327,8 +1359,7 @@ struct GNUNET_CONTAINER_MultiShortmap; * @return NULL on error */ struct GNUNET_CONTAINER_MultiShortmap * -GNUNET_CONTAINER_multishortmap_create (unsigned int len, - int do_not_copy_keys); +GNUNET_CONTAINER_multishortmap_create (unsigned int len, int do_not_copy_keys); /** @@ -1339,7 +1370,8 @@ GNUNET_CONTAINER_multishortmap_create (unsigned int len, * @param map the map */ void -GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *map); +GNUNET_CONTAINER_multishortmap_destroy ( + struct GNUNET_CONTAINER_MultiShortmap *map); /** @@ -1354,8 +1386,9 @@ GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *m * key-value pairs with value NULL */ void * -GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map, - const struct GNUNET_ShortHashCode *key); +GNUNET_CONTAINER_multishortmap_get ( + const struct GNUNET_CONTAINER_MultiShortmap *map, + const struct GNUNET_ShortHashCode *key); /** @@ -1371,9 +1404,10 @@ GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap * is not in the map */ int -GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map, - const struct GNUNET_ShortHashCode * key, - const void *value); +GNUNET_CONTAINER_multishortmap_remove ( + struct GNUNET_CONTAINER_MultiShortmap *map, + const struct GNUNET_ShortHashCode *key, + const void *value); /** * @ingroup hashmap @@ -1385,8 +1419,9 @@ GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *ma * @return number of values removed */ int -GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map, - const struct GNUNET_ShortHashCode *key); +GNUNET_CONTAINER_multishortmap_remove_all ( + struct GNUNET_CONTAINER_MultiShortmap *map, + const struct GNUNET_ShortHashCode *key); /** @@ -1400,8 +1435,9 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap * #GNUNET_NO if not */ int -GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map, - const struct GNUNET_ShortHashCode *key); +GNUNET_CONTAINER_multishortmap_contains ( + const struct GNUNET_CONTAINER_MultiShortmap *map, + const struct GNUNET_ShortHashCode *key); /** @@ -1416,9 +1452,10 @@ GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShor * #GNUNET_NO if not */ int -GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map, - const struct GNUNET_ShortHashCode * key, - const void *value); +GNUNET_CONTAINER_multishortmap_contains_value ( + const struct GNUNET_CONTAINER_MultiShortmap *map, + const struct GNUNET_ShortHashCode *key, + const void *value); /** @@ -1435,10 +1472,11 @@ GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_Mul * value already exists */ int -GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, - const struct GNUNET_ShortHashCode *key, - void *value, - enum GNUNET_CONTAINER_MultiHashMapOption opt); +GNUNET_CONTAINER_multishortmap_put ( + struct GNUNET_CONTAINER_MultiShortmap *map, + const struct GNUNET_ShortHashCode *key, + void *value, + enum GNUNET_CONTAINER_MultiHashMapOption opt); /** @@ -1449,7 +1487,8 @@ GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map, * @return the number of key value pairs */ unsigned int -GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap *map); +GNUNET_CONTAINER_multishortmap_size ( + const struct GNUNET_CONTAINER_MultiShortmap *map); /** @@ -1463,9 +1502,10 @@ GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap * #GNUNET_SYSERR if it aborted iteration */ int -GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *map, - GNUNET_CONTAINER_ShortmapIterator it, - void *it_cls); +GNUNET_CONTAINER_multishortmap_iterate ( + struct GNUNET_CONTAINER_MultiShortmap *map, + GNUNET_CONTAINER_ShortmapIterator it, + void *it_cls); struct GNUNET_CONTAINER_MultiShortmapIterator; @@ -1485,7 +1525,8 @@ struct GNUNET_CONTAINER_MultiShortmapIterator; * @return an iterator over the given multihashmap @a map */ struct GNUNET_CONTAINER_MultiShortmapIterator * -GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_MultiShortmap *map); +GNUNET_CONTAINER_multishortmap_iterator_create ( + const struct GNUNET_CONTAINER_MultiShortmap *map); /** @@ -1504,9 +1545,10 @@ GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_Mu * #GNUNET_NO if we are out of elements */ int -GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter, - struct GNUNET_ShortHashCode *key, - const void **value); +GNUNET_CONTAINER_multishortmap_iterator_next ( + struct GNUNET_CONTAINER_MultiShortmapIterator *iter, + struct GNUNET_ShortHashCode *key, + const void **value); /** @@ -1516,7 +1558,8 @@ GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShort * @param iter the iterator to destroy */ void -GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiShortmapIterator *iter); +GNUNET_CONTAINER_multishortmap_iterator_destroy ( + struct GNUNET_CONTAINER_MultiShortmapIterator *iter); /** @@ -1531,10 +1574,11 @@ GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiSh * #GNUNET_SYSERR if it aborted iteration */ int -GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortmap *map, - const struct GNUNET_ShortHashCode *key, - GNUNET_CONTAINER_ShortmapIterator it, - void *it_cls); +GNUNET_CONTAINER_multishortmap_get_multiple ( + struct GNUNET_CONTAINER_MultiShortmap *map, + const struct GNUNET_ShortHashCode *key, + GNUNET_CONTAINER_ShortmapIterator it, + void *it_cls); /** @@ -1549,9 +1593,292 @@ GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortm * @return the number of key value pairs processed, zero or one. */ unsigned int -GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiShortmap *map, - GNUNET_CONTAINER_ShortmapIterator it, - void *it_cls); +GNUNET_CONTAINER_multishortmap_get_random ( + const struct GNUNET_CONTAINER_MultiShortmap *map, + GNUNET_CONTAINER_ShortmapIterator it, + void *it_cls); + + +/* ***************** Version of Multihashmap for UUIDs ****************** */ + + +/** + * @ingroup hashmap + * Iterator over uuid map entries. + * + * @param cls closure + * @param key current public key + * @param value value in the hash map + * @return #GNUNET_YES if we should continue to + * iterate, + * #GNUNET_NO if not. + */ +typedef int (*GNUNET_CONTAINER_MultiUuidmapIterator) ( + void *cls, + const struct GNUNET_Uuid *key, + void *value); + + +/** + * Hash map from peer identities to values. + */ +struct GNUNET_CONTAINER_MultiUuidmap; + + +/** + * @ingroup hashmap + * Create a multi peer map (hash map for public keys of peers). + * + * @param len initial size (map will grow as needed) + * @param do_not_copy_keys #GNUNET_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 recipie 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 + * @return NULL on error + */ +struct GNUNET_CONTAINER_MultiUuidmap * +GNUNET_CONTAINER_multiuuidmap_create (unsigned int len, int do_not_copy_keys); + + +/** + * @ingroup hashmap + * Destroy a hash map. Will not free any values + * stored in the hash map! + * + * @param map the map + */ +void +GNUNET_CONTAINER_multiuuidmap_destroy ( + struct GNUNET_CONTAINER_MultiUuidmap *map); + + +/** + * @ingroup hashmap + * Given a key find a value in the map matching the key. + * + * @param map the map + * @param key what to look for + * @return 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 + */ +void * +GNUNET_CONTAINER_multiuuidmap_get ( + const struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key); + + +/** + * @ingroup hashmap + * 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. + * + * @param map the map + * @param key key of the key-value pair + * @param value value of the key-value pair + * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair + * is not in the map + */ +int +GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key, + const void *value); + +/** + * @ingroup hashmap + * Remove all entries for the given key from the map. + * Note that the values would not be "freed". + * + * @param map the map + * @param key identifies values to be removed + * @return number of values removed + */ +int +GNUNET_CONTAINER_multiuuidmap_remove_all ( + struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key); + + +/** + * @ingroup hashmap + * Check if the map contains any value under the given + * key (including values that are NULL). + * + * @param map the map + * @param key the key to test if a value exists for it + * @return #GNUNET_YES if such a value exists, + * #GNUNET_NO if not + */ +int +GNUNET_CONTAINER_multiuuidmap_contains ( + const struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key); + + +/** + * @ingroup hashmap + * Check if the map contains the given value under the given + * key. + * + * @param map the map + * @param key the key to test if a value exists for it + * @param value value to test for + * @return #GNUNET_YES if such a value exists, + * #GNUNET_NO if not + */ +int +GNUNET_CONTAINER_multiuuidmap_contains_value ( + const struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key, + const void *value); + + +/** + * @ingroup hashmap + * Store a key-value pair in the map. + * + * @param map the map + * @param key key to use + * @param value value to use + * @param opt options for put + * @return #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 + */ +int +GNUNET_CONTAINER_multiuuidmap_put ( + struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key, + void *value, + enum GNUNET_CONTAINER_MultiHashMapOption opt); + + +/** + * @ingroup hashmap + * Get the number of key-value pairs in the map. + * + * @param map the map + * @return the number of key value pairs + */ +unsigned int +GNUNET_CONTAINER_multiuuidmap_size ( + const struct GNUNET_CONTAINER_MultiUuidmap *map); + + +/** + * @ingroup hashmap + * Iterate over all entries in the map. + * + * @param map the map + * @param it function to call on each entry + * @param it_cls extra argument to @a it + * @return the number of key value pairs processed, + * #GNUNET_SYSERR if it aborted iteration + */ +int +GNUNET_CONTAINER_multiuuidmap_iterate ( + struct GNUNET_CONTAINER_MultiUuidmap *map, + GNUNET_CONTAINER_MultiUuidmapIterator it, + void *it_cls); + + +struct GNUNET_CONTAINER_MultiUuidmapIterator; + + +/** + * @ingroup hashmap + * 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 @a map after the creation of + * the iterator, or 'map' has been destroyed. Adding elements to @a map may + * result in skipped or repeated elements. + * + * @param map the map to create an iterator for + * @return an iterator over the given multihashmap @a map + */ +struct GNUNET_CONTAINER_MultiUuidmapIterator * +GNUNET_CONTAINER_multiuuidmap_iterator_create ( + const struct GNUNET_CONTAINER_MultiUuidmap *map); + + +/** + * @ingroup hashmap + * Retrieve the next element from the hash map at the iterator's + * position. If there are no elements left, #GNUNET_NO is returned, + * and @a key and @a value are not modified. This operation is only + * allowed if no elements have been removed from the multihashmap + * since the creation of @a iter, and the map has not been destroyed. + * Adding elements may result in repeating or skipping elements. + * + * @param iter the iterator to get the next element from + * @param key pointer to store the key in, can be NULL + * @param value pointer to store the value in, can be NULL + * @return #GNUNET_YES we returned an element, + * #GNUNET_NO if we are out of elements + */ +int +GNUNET_CONTAINER_multiuuidmap_iterator_next ( + struct GNUNET_CONTAINER_MultiUuidmapIterator *iter, + struct GNUNET_Uuid *key, + const void **value); + + +/** + * @ingroup hashmap + * Destroy a multiuuidmap iterator. + * + * @param iter the iterator to destroy + */ +void +GNUNET_CONTAINER_multiuuidmap_iterator_destroy ( + struct GNUNET_CONTAINER_MultiUuidmapIterator *iter); + + +/** + * @ingroup hashmap + * Iterate over all entries in the map that match a particular key. + * + * @param map the map + * @param key public key that the entries must correspond to + * @param it function to call on each entry + * @param it_cls extra argument to @a it + * @return the number of key value pairs processed, + * #GNUNET_SYSERR if it aborted iteration + */ +int +GNUNET_CONTAINER_multiuuidmap_get_multiple ( + struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key, + GNUNET_CONTAINER_MultiUuidmapIterator it, + void *it_cls); + + +/** + * @ingroup hashmap + * Call @a 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). + * + * @param map the map + * @param it function to call on a random entry + * @param it_cls extra argument to @a it + * @return the number of key value pairs processed, zero or one. + */ +unsigned int +GNUNET_CONTAINER_multiuuidmap_get_random ( + const struct GNUNET_CONTAINER_MultiUuidmap *map, + GNUNET_CONTAINER_MultiUuidmapIterator it, + void *it_cls); /* Version of multihashmap with 32 bit keys */ @@ -1582,10 +1909,9 @@ struct GNUNET_CONTAINER_MultiHashMap32Iterator; * iterate, * #GNUNET_NO if not. */ -typedef int -(*GNUNET_CONTAINER_HashMapIterator32) (void *cls, - uint32_t key, - void *value); +typedef int (*GNUNET_CONTAINER_HashMapIterator32) (void *cls, + uint32_t key, + void *value); /** @@ -1607,7 +1933,8 @@ GNUNET_CONTAINER_multihashmap32_create (unsigned int len); * @param map the map */ void -GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32 *map); +GNUNET_CONTAINER_multihashmap32_destroy ( + struct GNUNET_CONTAINER_MultiHashMap32 *map); /** @@ -1618,8 +1945,8 @@ GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32 * @return the number of key value pairs */ unsigned int -GNUNET_CONTAINER_multihashmap32_size (const struct - GNUNET_CONTAINER_MultiHashMap32 *map); +GNUNET_CONTAINER_multihashmap32_size ( + const struct GNUNET_CONTAINER_MultiHashMap32 *map); /** @@ -1634,9 +1961,9 @@ GNUNET_CONTAINER_multihashmap32_size (const struct * key-value pairs with value NULL */ void * -GNUNET_CONTAINER_multihashmap32_get (const struct - GNUNET_CONTAINER_MultiHashMap32 *map, - uint32_t key); +GNUNET_CONTAINER_multihashmap32_get ( + const struct GNUNET_CONTAINER_MultiHashMap32 *map, + uint32_t key); /** @@ -1650,9 +1977,10 @@ GNUNET_CONTAINER_multihashmap32_get (const struct * #GNUNET_SYSERR if it aborted iteration */ int -GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32 *map, - GNUNET_CONTAINER_HashMapIterator32 it, - void *it_cls); +GNUNET_CONTAINER_multihashmap32_iterate ( + struct GNUNET_CONTAINER_MultiHashMap32 *map, + GNUNET_CONTAINER_HashMapIterator32 it, + void *it_cls); /** @@ -1668,9 +1996,10 @@ GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32 * is not in the map */ int -GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map, - uint32_t key, - const void *value); +GNUNET_CONTAINER_multihashmap32_remove ( + struct GNUNET_CONTAINER_MultiHashMap32 *map, + uint32_t key, + const void *value); /** @@ -1683,8 +2012,9 @@ GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 * * @return number of values removed */ int -GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map, - uint32_t key); +GNUNET_CONTAINER_multihashmap32_remove_all ( + struct GNUNET_CONTAINER_MultiHashMap32 *map, + uint32_t key); /** @@ -1698,8 +2028,9 @@ GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap * #GNUNET_NO if not */ int -GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map, - uint32_t key); +GNUNET_CONTAINER_multihashmap32_contains ( + const struct GNUNET_CONTAINER_MultiHashMap32 *map, + uint32_t key); /** @@ -1714,9 +2045,10 @@ GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHas * #GNUNET_NO if not */ int -GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map, - uint32_t key, - const void *value); +GNUNET_CONTAINER_multihashmap32_contains_value ( + const struct GNUNET_CONTAINER_MultiHashMap32 *map, + uint32_t key, + const void *value); /** @@ -1733,10 +2065,11 @@ GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_Mu * value already exists */ int -GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map, - uint32_t key, - void *value, - enum GNUNET_CONTAINER_MultiHashMapOption opt); +GNUNET_CONTAINER_multihashmap32_put ( + struct GNUNET_CONTAINER_MultiHashMap32 *map, + uint32_t key, + void *value, + enum GNUNET_CONTAINER_MultiHashMapOption opt); /** @@ -1751,10 +2084,11 @@ GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map * #GNUNET_SYSERR if it aborted iteration */ int -GNUNET_CONTAINER_multihashmap32_get_multiple (struct GNUNET_CONTAINER_MultiHashMap32 *map, - uint32_t key, - GNUNET_CONTAINER_HashMapIterator32 it, - void *it_cls); +GNUNET_CONTAINER_multihashmap32_get_multiple ( + struct GNUNET_CONTAINER_MultiHashMap32 *map, + uint32_t key, + GNUNET_CONTAINER_HashMapIterator32 it, + void *it_cls); /** @@ -1770,7 +2104,8 @@ GNUNET_CONTAINER_multihashmap32_get_multiple (struct GNUNET_CONTAINER_MultiHashM * @return an iterator over the given multihashmap map */ struct GNUNET_CONTAINER_MultiHashMap32Iterator * -GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap32 *map); +GNUNET_CONTAINER_multihashmap32_iterator_create ( + const struct GNUNET_CONTAINER_MultiHashMap32 *map); /** @@ -1788,9 +2123,10 @@ GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_M * #GNUNET_NO if we are out of elements */ int -GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter, - uint32_t *key, - const void **value); +GNUNET_CONTAINER_multihashmap32_iterator_next ( + struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter, + uint32_t *key, + const void **value); /** @@ -1799,7 +2135,8 @@ GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHash * @param iter the iterator to destroy */ void -GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter); +GNUNET_CONTAINER_multihashmap32_iterator_destroy ( + struct GNUNET_CONTAINER_MultiHashMapIterator *iter); /* ******************** doubly-linked list *************** */ @@ -1814,16 +2151,19 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param tail pointer to the tail of the DLL * @param element element to insert */ -#define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \ - GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \ - GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \ - (element)->next = (head); \ - (element)->prev = NULL; \ - if ((tail) == NULL) \ - (tail) = element; \ - else \ - (head)->prev = element; \ - (head) = (element); } while (0) +#define GNUNET_CONTAINER_DLL_insert(head, tail, element) \ + do \ + { \ + GNUNET_assert (((element)->prev == NULL) && ((head) != (element))); \ + GNUNET_assert (((element)->next == NULL) && ((tail) != (element))); \ + (element)->next = (head); \ + (element)->prev = NULL; \ + if ((tail) == NULL) \ + (tail) = element; \ + else \ + (head)->prev = element; \ + (head) = (element); \ + } while (0) /** @@ -1835,16 +2175,19 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param tail pointer to the tail of the DLL * @param element element to insert */ -#define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \ - GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \ - GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \ - (element)->prev = (tail); \ - (element)->next = NULL; \ - if ((head) == NULL) \ - (head) = element; \ - else \ - (tail)->next = element; \ - (tail) = (element); } while (0) +#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element) \ + do \ + { \ + GNUNET_assert (((element)->prev == NULL) && ((head) != (element))); \ + GNUNET_assert (((element)->next == NULL) && ((tail) != (element))); \ + (element)->prev = (tail); \ + (element)->next = NULL; \ + if ((head) == NULL) \ + (head) = element; \ + else \ + (tail)->next = element; \ + (tail) = (element); \ + } while (0) /** @@ -1857,24 +2200,27 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param other prior element, NULL for insertion at head of DLL * @param element element to insert */ -#define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \ - GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \ - GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \ - (element)->prev = (other); \ - if (NULL == other) \ - { \ - (element)->next = (head); \ - (head) = (element); \ - } \ - else \ - { \ - (element)->next = (other)->next; \ - (other)->next = (element); \ - } \ - if (NULL == (element)->next) \ - (tail) = (element); \ - else \ - (element)->next->prev = (element); } while (0) +#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element) \ + do \ + { \ + GNUNET_assert (((element)->prev == NULL) && ((head) != (element))); \ + GNUNET_assert (((element)->next == NULL) && ((tail) != (element))); \ + (element)->prev = (other); \ + if (NULL == other) \ + { \ + (element)->next = (head); \ + (head) = (element); \ + } \ + else \ + { \ + (element)->next = (other)->next; \ + (other)->next = (element); \ + } \ + if (NULL == (element)->next) \ + (tail) = (element); \ + else \ + (element)->next->prev = (element); \ + } while (0) /** @@ -1887,24 +2233,27 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param other prior element, NULL for insertion at head of DLL * @param element element to insert */ -#define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \ - GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \ - GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \ - (element)->next = (other); \ - if (NULL == other) \ - { \ - (element)->prev = (tail); \ - (tail) = (element); \ - } \ - else \ - { \ - (element)->prev = (other)->prev; \ - (other)->prev = (element); \ - } \ - if (NULL == (element)->prev) \ - (head) = (element); \ - else \ - (element)->prev->next = (element); } while (0) +#define GNUNET_CONTAINER_DLL_insert_before(head, tail, other, element) \ + do \ + { \ + GNUNET_assert (((element)->prev == NULL) && ((head) != (element))); \ + GNUNET_assert (((element)->next == NULL) && ((tail) != (element))); \ + (element)->next = (other); \ + if (NULL == other) \ + { \ + (element)->prev = (tail); \ + (tail) = (element); \ + } \ + else \ + { \ + (element)->prev = (other)->prev; \ + (other)->prev = (element); \ + } \ + if (NULL == (element)->prev) \ + (head) = (element); \ + else \ + (element)->prev->next = (element); \ + } while (0) /** @@ -1921,19 +2270,22 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param tail pointer to the tail of the DLL * @param element element to remove */ -#define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \ - GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \ - GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \ - if ((element)->prev == NULL) \ - (head) = (element)->next; \ - else \ - (element)->prev->next = (element)->next; \ - if ((element)->next == NULL) \ - (tail) = (element)->prev; \ - else \ - (element)->next->prev = (element)->prev; \ - (element)->next = NULL; \ - (element)->prev = NULL; } while (0) +#define GNUNET_CONTAINER_DLL_remove(head, tail, element) \ + do \ + { \ + GNUNET_assert (((element)->prev != NULL) || ((head) == (element))); \ + GNUNET_assert (((element)->next != NULL) || ((tail) == (element))); \ + if ((element)->prev == NULL) \ + (head) = (element)->next; \ + else \ + (element)->prev->next = (element)->next; \ + if ((element)->next == NULL) \ + (tail) = (element)->prev; \ + else \ + (element)->next->prev = (element)->prev; \ + (element)->next = NULL; \ + (element)->prev = NULL; \ + } while (0) /* ************ Multi-DLL interface, allows DLL elements to be @@ -1949,16 +2301,19 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param tail pointer to the tail of the MDLL * @param element element to insert */ -#define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \ - GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ - GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ - (element)->next_##mdll = (head); \ - (element)->prev_##mdll = NULL; \ - if ((tail) == NULL) \ - (tail) = element; \ - else \ - (head)->prev_##mdll = element; \ - (head) = (element); } while (0) +#define GNUNET_CONTAINER_MDLL_insert(mdll, head, tail, element) \ + do \ + { \ + GNUNET_assert (((element)->prev_##mdll == NULL) && ((head) != (element))); \ + GNUNET_assert (((element)->next_##mdll == NULL) && ((tail) != (element))); \ + (element)->next_##mdll = (head); \ + (element)->prev_##mdll = NULL; \ + if ((tail) == NULL) \ + (tail) = element; \ + else \ + (head)->prev_##mdll = element; \ + (head) = (element); \ + } while (0) /** @@ -1971,16 +2326,19 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param tail pointer to the tail of the MDLL * @param element element to insert */ -#define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \ - GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ - GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ - (element)->prev_##mdll = (tail); \ - (element)->next_##mdll = NULL; \ - if ((head) == NULL) \ - (head) = element; \ - else \ - (tail)->next_##mdll = element; \ - (tail) = (element); } while (0) +#define GNUNET_CONTAINER_MDLL_insert_tail(mdll, head, tail, element) \ + do \ + { \ + GNUNET_assert (((element)->prev_##mdll == NULL) && ((head) != (element))); \ + GNUNET_assert (((element)->next_##mdll == NULL) && ((tail) != (element))); \ + (element)->prev_##mdll = (tail); \ + (element)->next_##mdll = NULL; \ + if ((head) == NULL) \ + (head) = element; \ + else \ + (tail)->next_##mdll = element; \ + (tail) = (element); \ + } while (0) /** @@ -1994,24 +2352,27 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param other prior element, NULL for insertion at head of MDLL * @param element element to insert */ -#define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \ - GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ - GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ - (element)->prev_##mdll = (other); \ - if (NULL == other) \ - { \ - (element)->next_##mdll = (head); \ - (head) = (element); \ - } \ - else \ - { \ - (element)->next_##mdll = (other)->next_##mdll; \ - (other)->next_##mdll = (element); \ - } \ - if (NULL == (element)->next_##mdll) \ - (tail) = (element); \ - else \ - (element)->next_##mdll->prev_##mdll = (element); } while (0) +#define GNUNET_CONTAINER_MDLL_insert_after(mdll, head, tail, other, element) \ + do \ + { \ + GNUNET_assert (((element)->prev_##mdll == NULL) && ((head) != (element))); \ + GNUNET_assert (((element)->next_##mdll == NULL) && ((tail) != (element))); \ + (element)->prev_##mdll = (other); \ + if (NULL == other) \ + { \ + (element)->next_##mdll = (head); \ + (head) = (element); \ + } \ + else \ + { \ + (element)->next_##mdll = (other)->next_##mdll; \ + (other)->next_##mdll = (element); \ + } \ + if (NULL == (element)->next_##mdll) \ + (tail) = (element); \ + else \ + (element)->next_##mdll->prev_##mdll = (element); \ + } while (0) /** @@ -2025,24 +2386,27 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param other prior element, NULL for insertion at head of MDLL * @param element element to insert */ -#define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \ - GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ - GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ - (element)->next_##mdll = (other); \ - if (NULL == other) \ - { \ - (element)->prev = (tail); \ - (tail) = (element); \ - } \ - else \ - { \ - (element)->prev_##mdll = (other)->prev_##mdll; \ - (other)->prev_##mdll = (element); \ - } \ - if (NULL == (element)->prev_##mdll) \ - (head) = (element); \ - else \ - (element)->prev_##mdll->next_##mdll = (element); } while (0) +#define GNUNET_CONTAINER_MDLL_insert_before(mdll, head, tail, other, element) \ + do \ + { \ + GNUNET_assert (((element)->prev_##mdll == NULL) && ((head) != (element))); \ + GNUNET_assert (((element)->next_##mdll == NULL) && ((tail) != (element))); \ + (element)->next_##mdll = (other); \ + if (NULL == other) \ + { \ + (element)->prev = (tail); \ + (tail) = (element); \ + } \ + else \ + { \ + (element)->prev_##mdll = (other)->prev_##mdll; \ + (other)->prev_##mdll = (element); \ + } \ + if (NULL == (element)->prev_##mdll) \ + (head) = (element); \ + else \ + (element)->prev_##mdll->next_##mdll = (element); \ + } while (0) /** @@ -2056,20 +2420,22 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param tail pointer to the tail of the MDLL * @param element element to remove */ -#define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \ - GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \ - GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \ - if ((element)->prev_##mdll == NULL) \ - (head) = (element)->next_##mdll; \ - else \ - (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \ - if ((element)->next_##mdll == NULL) \ - (tail) = (element)->prev_##mdll; \ - else \ - (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \ - (element)->next_##mdll = NULL; \ - (element)->prev_##mdll = NULL; } while (0) - +#define GNUNET_CONTAINER_MDLL_remove(mdll, head, tail, element) \ + do \ + { \ + GNUNET_assert (((element)->prev_##mdll != NULL) || ((head) == (element))); \ + GNUNET_assert (((element)->next_##mdll != NULL) || ((tail) == (element))); \ + if ((element)->prev_##mdll == NULL) \ + (head) = (element)->next_##mdll; \ + else \ + (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \ + if ((element)->next_##mdll == NULL) \ + (tail) = (element)->prev_##mdll; \ + else \ + (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \ + (element)->next_##mdll = NULL; \ + (element)->prev_##mdll = NULL; \ + } while (0) /** @@ -2085,44 +2451,36 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH * @param[in,out] tail tail of DLL * @param element element to insert */ -#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE,comparator,comparator_cls,head,tail,element) do { \ - if ( (NULL == head) || \ - (0 < comparator (comparator_cls, \ - element, \ - head)) ) \ - { \ - /* insert at head, element < head */ \ - GNUNET_CONTAINER_DLL_insert (head, \ - tail, \ - element); \ - } \ - else \ - { \ - TYPE *pos; \ - \ - for (pos = head; \ - NULL != pos; \ - pos = pos->next) \ - if (0 < \ - comparator (comparator_cls, \ - element, \ - pos)) \ - break; /* element < pos */ \ - if (NULL == pos) /* => element > tail */ \ - { \ - GNUNET_CONTAINER_DLL_insert_tail (head, \ - tail, \ - element); \ - } \ - else /* prev < element < pos */ \ - { \ - GNUNET_CONTAINER_DLL_insert_after (head, \ - tail, \ - pos->prev, \ - element); \ - } \ - } \ -} while (0) +#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE, \ + comparator, \ + comparator_cls, \ + head, \ + tail, \ + element) \ + do \ + { \ + if ((NULL == head) || (0 < comparator (comparator_cls, element, head))) \ + { \ + /* insert at head, element < head */ \ + GNUNET_CONTAINER_DLL_insert (head, tail, element); \ + } \ + else \ + { \ + TYPE *pos; \ + \ + for (pos = head; NULL != pos; pos = pos->next) \ + if (0 < comparator (comparator_cls, element, pos)) \ + break; /* element < pos */ \ + if (NULL == pos) /* => element > tail */ \ + { \ + GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); \ + } \ + else /* prev < element < pos */ \ + { \ + GNUNET_CONTAINER_DLL_insert_after (head, tail, pos->prev, element); \ + } \ + } \ + } while (0) /* ******************** Heap *************** */ @@ -2236,7 +2594,8 @@ GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap); * @return cost of the node */ GNUNET_CONTAINER_HeapCostType -GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *node); +GNUNET_CONTAINER_heap_node_get_cost ( + const struct GNUNET_CONTAINER_HeapNode *node); /** @@ -2250,11 +2609,11 @@ GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *nod * @return #GNUNET_YES if we should continue to iterate, * #GNUNET_NO if not. */ -typedef int -(*GNUNET_CONTAINER_HeapIterator) (void *cls, - struct GNUNET_CONTAINER_HeapNode *node, - void *element, - GNUNET_CONTAINER_HeapCostType cost); +typedef int (*GNUNET_CONTAINER_HeapIterator) ( + void *cls, + struct GNUNET_CONTAINER_HeapNode *node, + void *element, + GNUNET_CONTAINER_HeapCostType cost); /** @@ -2335,7 +2694,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_HeapNode *node, GNUNET_CONTAINER_HeapCostType new_cost); -#if 0 /* keep Emacsens' auto-indent happy */ +#if 0 /* keep Emacsens' auto-indent happy */ { #endif #ifdef __cplusplus diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index 18a80b3c5..eb3cc2de9 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c @@ -33,8 +33,6 @@ * do NOT forward it to peers _other_ than the origin, as * there is clearly a better path directly from the origin to * whatever else we could reach. - * - AcknowledgementUUIDPs are overkill with 256 bits (128 would do) - * => Need 128 bit hash map though! [BANDWIDTH, MEMORY] * - queue_send_msg by API design has to make a copy * of the payload, and route_message on top of that requires a malloc/free. * Change design to approximate "zero" copy better... [CPU] @@ -345,9 +343,9 @@ struct MessageUUIDP struct AcknowledgementUUIDP { /** - * The UUID value. Not actually a hash, but a random value. + * The UUID value. */ - struct GNUNET_ShortHashCode value; + struct GNUNET_Uuid value; }; @@ -2736,7 +2734,7 @@ static struct GNUNET_CONTAINER_MultiPeerMap *ack_cummulators; * Map of pending acknowledgements, mapping `struct AcknowledgementUUID` to * a `struct PendingAcknowledgement`. */ -static struct GNUNET_CONTAINER_MultiShortmap *pending_acks; +static struct GNUNET_CONTAINER_MultiUuidmap *pending_acks; /** * Map from PIDs to `struct DistanceVector` entries describing @@ -2910,9 +2908,9 @@ free_pending_acknowledgement (struct PendingAcknowledgement *pa) pa->queue = NULL; } GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multishortmap_remove (pending_acks, - &pa->ack_uuid.value, - pa)); + GNUNET_CONTAINER_multiuuidmap_remove (pending_acks, + &pa->ack_uuid.value, + pa)); GNUNET_free (pa); } @@ -5468,7 +5466,7 @@ cummulative_ack (const struct GNUNET_PeerIdentity *pid, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling ACK %s for transmission to %s\n", - GNUNET_sh2s (&ack_uuid->value), + GNUNET_uuid2s (&ack_uuid->value), GNUNET_i2s (pid)); ac = GNUNET_CONTAINER_multipeermap_get (ack_cummulators, pid); if (NULL == ac) @@ -5743,7 +5741,7 @@ handle_reliability_box (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received reliability box from %s with UUID %s of type %u\n", GNUNET_i2s (&cmc->im.sender), - GNUNET_sh2s (&rb->ack_uuid.value), + GNUNET_uuid2s (&rb->ack_uuid.value), (unsigned int) ntohs (inbox->type)); rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we do not really have an RTT for the @@ -5981,13 +5979,13 @@ handle_reliability_ack (void *cls, for (unsigned int i = 0; i < n_acks; i++) { pa = - GNUNET_CONTAINER_multishortmap_get (pending_acks, &ack[i].ack_uuid.value); + GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value); if (NULL == pa) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received ACK from %s with UUID %s which is unknown to us!\n", GNUNET_i2s (&cmc->im.sender), - GNUNET_sh2s (&ack[i].ack_uuid.value)); + GNUNET_uuid2s (&ack[i].ack_uuid.value)); GNUNET_STATISTICS_update ( GST_stats, "# FRAGMENT_ACKS dropped, no matching pending message", @@ -5998,7 +5996,7 @@ handle_reliability_ack (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ACK from %s with UUID %s\n", GNUNET_i2s (&cmc->im.sender), - GNUNET_sh2s (&ack[i].ack_uuid.value)); + GNUNET_uuid2s (&ack[i].ack_uuid.value)); handle_acknowledged (pa, GNUNET_TIME_relative_ntoh (ack[i].ack_delay)); } @@ -8412,7 +8410,7 @@ prepare_pending_acknowledgement (struct Queue *queue, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &pa->ack_uuid, sizeof (pa->ack_uuid)); - } while (GNUNET_YES != GNUNET_CONTAINER_multishortmap_put ( + } while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put ( pending_acks, &pa->ack_uuid.value, pa, @@ -8425,7 +8423,7 @@ prepare_pending_acknowledgement (struct Queue *queue, pa->message_size = pm->bytes_msg; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for ACKnowledgment `%s' for <%llu>\n", - GNUNET_sh2s (&pa->ack_uuid.value), + GNUNET_uuid2s (&pa->ack_uuid.value), pm->logging_uuid); return pa; } @@ -10017,9 +10015,7 @@ free_validation_state_cb (void *cls, * @return #GNUNET_OK (always) */ static int -free_pending_ack_cb (void *cls, - const struct GNUNET_ShortHashCode *key, - void *value) +free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value) { struct PendingAcknowledgement *pa = value; @@ -10085,10 +10081,10 @@ do_shutdown (void *cls) NULL); GNUNET_CONTAINER_multipeermap_destroy (ack_cummulators); ack_cummulators = NULL; - GNUNET_CONTAINER_multishortmap_iterate (pending_acks, - &free_pending_ack_cb, - NULL); - GNUNET_CONTAINER_multishortmap_destroy (pending_acks); + GNUNET_CONTAINER_multiuuidmap_iterate (pending_acks, + &free_pending_ack_cb, + NULL); + GNUNET_CONTAINER_multiuuidmap_destroy (pending_acks); pending_acks = NULL; GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)); GNUNET_CONTAINER_multipeermap_destroy (neighbours); @@ -10142,7 +10138,7 @@ run (void *cls, hello_mono_time = GNUNET_TIME_absolute_get_monotonic (c); GST_cfg = c; backtalkers = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); - pending_acks = GNUNET_CONTAINER_multishortmap_create (32768, GNUNET_YES); + pending_acks = GNUNET_CONTAINER_multiuuidmap_create (32768, GNUNET_YES); ack_cummulators = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES); neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); links = GNUNET_CONTAINER_multipeermap_create (512, GNUNET_YES); diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 8a99197f8..fe5cc6e72 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -78,6 +78,7 @@ libgnunetutil_la_SOURCES = \ container_meta_data.c \ container_multihashmap.c \ container_multishortmap.c \ + container_multiuuidmap.c \ container_multipeermap.c \ container_multihashmap32.c \ crypto_symmetric.c \ diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 5052134f8..b5678e5be 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -107,7 +107,8 @@ static __thread struct GNUNET_AsyncScopeSave current_async_scope; * Note that this message maybe truncated to the first BULK_TRACK_SIZE * characters, in which case it is NOT 0-terminated! */ -static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE] __attribute__ ((nonstring)); +static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE] + __attribute__ ((nonstring)); /** * Type of the last bulk message. @@ -211,7 +212,7 @@ struct LogDef }; -#if !defined(GNUNET_CULL_LOGGING) +#if ! defined(GNUNET_CULL_LOGGING) /** * Dynamic array of logging definitions */ @@ -263,17 +264,17 @@ get_type (const char *log) { if (NULL == log) return GNUNET_ERROR_TYPE_UNSPECIFIED; - if (0 == strcasecmp (log, _("DEBUG"))) + if (0 == strcasecmp (log, _ ("DEBUG"))) return GNUNET_ERROR_TYPE_DEBUG; - if (0 == strcasecmp (log, _("INFO"))) + if (0 == strcasecmp (log, _ ("INFO"))) return GNUNET_ERROR_TYPE_INFO; - if (0 == strcasecmp (log, _("MESSAGE"))) + if (0 == strcasecmp (log, _ ("MESSAGE"))) return GNUNET_ERROR_TYPE_MESSAGE; - if (0 == strcasecmp (log, _("WARNING"))) + if (0 == strcasecmp (log, _ ("WARNING"))) return GNUNET_ERROR_TYPE_WARNING; - if (0 == strcasecmp (log, _("ERROR"))) + if (0 == strcasecmp (log, _ ("ERROR"))) return GNUNET_ERROR_TYPE_ERROR; - if (0 == strcasecmp (log, _("NONE"))) + if (0 == strcasecmp (log, _ ("NONE"))) return GNUNET_ERROR_TYPE_NONE; return GNUNET_ERROR_TYPE_INVALID; } @@ -292,7 +293,7 @@ GNUNET_abort_ () } -#if !defined(GNUNET_CULL_LOGGING) +#if ! defined(GNUNET_CULL_LOGGING) /** * Utility function - reallocates logdefs array to be twice as large. */ @@ -353,7 +354,7 @@ setup_log_file (const struct tm *tm) if (0 == strftime (fn, sizeof (fn), log_file_name, tm)) return GNUNET_SYSERR; leftsquare = strrchr (fn, '['); - if ( (NULL != leftsquare) && (']' == leftsquare[1]) ) + if ((NULL != leftsquare) && (']' == leftsquare[1])) { char *logfile_copy = GNUNET_strdup (fn); @@ -371,8 +372,7 @@ setup_log_file (const struct tm *tm) return GNUNET_OK; /* no change */ log_rotate (last_fn); strcpy (last_fn, fn); - if (GNUNET_SYSERR == - GNUNET_DISK_directory_create_for_file (fn)) + if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (fn)) { fprintf (stderr, "Failed to create directory for `%s': %s\n", @@ -381,14 +381,12 @@ setup_log_file (const struct tm *tm) return GNUNET_SYSERR; } #if WINDOWS - altlog_fd = OPEN (fn, O_APPEND | - O_BINARY | - O_WRONLY | O_CREAT, - _S_IREAD | _S_IWRITE); + altlog_fd = + OPEN (fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE); #else - altlog_fd = OPEN (fn, O_APPEND | - O_WRONLY | O_CREAT, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + altlog_fd = OPEN (fn, + O_APPEND | O_WRONLY | O_CREAT, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); #endif if (-1 != altlog_fd) { @@ -512,7 +510,7 @@ GNUNET_get_log_call_status (int caller_level, /* We have no definitions to override globally configured log level, * so just use it right away. */ - if ( (min_level >= 0) && (GNUNET_NO == gnunet_force_log_present) ) + if ((min_level >= 0) && (GNUNET_NO == gnunet_force_log_present)) return caller_level <= min_level; /* Only look for forced definitions? */ @@ -520,7 +518,7 @@ GNUNET_get_log_call_status (int caller_level, for (i = 0; i < logdefs_len; i++) { ld = &logdefs[i]; - if (( (!force_only) || ld->force) && + if (((! force_only) || ld->force) && (line >= ld->from_line && line <= ld->to_line) && (0 == regexec (&ld->component_regex, comp, 0, NULL, 0)) && (0 == regexec (&ld->file_regex, file, 0, NULL, 0)) && @@ -591,73 +589,79 @@ parse_definitions (const char *constname, int force) { switch (p[0]) { - case ';': /* found a field separator */ + case ';': /* found a field separator */ p[0] = '\0'; switch (state) { - case 0: /* within a component name */ + case 0: /* within a component name */ comp = start; break; - case 1: /* within a file name */ + case 1: /* within a file name */ file = start; break; - case 2: /* within a function name */ + case 2: /* within a function name */ /* after a file name there must be a function name */ function = start; break; - case 3: /* within a from-to line range */ + case 3: /* within a from-to line range */ if (strlen (start) > 0) { errno = 0; from_line = strtol (start, &t, 10); - if ( (0 != errno) || (from_line < 0) ) + if ((0 != errno) || (from_line < 0)) { GNUNET_free (def); return counter; } - if ( (t < p) && ('-' == t[0]) ) + if ((t < p) && ('-' == t[0])) { errno = 0; start = t + 1; to_line = strtol (start, &t, 10); - if ( (0 != errno) || (to_line < 0) || (t != p) ) + if ((0 != errno) || (to_line < 0) || (t != p)) { GNUNET_free (def); return counter; } } - else /* one number means "match this line only" */ + else /* one number means "match this line only" */ to_line = from_line; } - else /* default to 0-max */ + else /* default to 0-max */ { from_line = 0; to_line = INT_MAX; } break; default: - fprintf(stderr, - _("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"), - p); + fprintf ( + stderr, + _ ("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"), + p); break; } start = p + 1; state++; break; - case '\0': /* found EOL */ + case '\0': /* found EOL */ keep_looking = 0; /* fall through to '/' */ - case '/': /* found a definition separator */ + case '/': /* found a definition separator */ switch (state) { - case 4: /* within a log level */ + case 4: /* within a log level */ p[0] = '\0'; state = 0; level = get_type ((const char *) start); - if ( (GNUNET_ERROR_TYPE_INVALID == level) || - (GNUNET_ERROR_TYPE_UNSPECIFIED == level) || - (0 != add_definition (comp, file, function, from_line, to_line, - level, force)) ) + if ((GNUNET_ERROR_TYPE_INVALID == level) || + (GNUNET_ERROR_TYPE_UNSPECIFIED == level) || + (0 != add_definition (comp, + file, + function, + from_line, + to_line, + level, + force))) { GNUNET_free (def); return counter; @@ -666,9 +670,10 @@ parse_definitions (const char *constname, int force) start = p + 1; break; default: - fprintf(stderr, - _("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"), - p); + fprintf ( + stderr, + _ ("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"), + p); break; } default: @@ -688,7 +693,7 @@ parse_all_definitions () { if (GNUNET_NO == gnunet_force_log_parsed) gnunet_force_log_present = - parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO; + parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO; gnunet_force_log_parsed = GNUNET_YES; if (GNUNET_NO == gnunet_log_parsed) @@ -707,14 +712,12 @@ parse_all_definitions () * @return #GNUNET_OK on success */ int -GNUNET_log_setup (const char *comp, - const char *loglevel, - const char *logfile) +GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) { const char *env_logfile; min_level = get_type (loglevel); -#if !defined(GNUNET_CULL_LOGGING) +#if ! defined(GNUNET_CULL_LOGGING) parse_all_definitions (); #endif #ifdef WINDOWS @@ -761,8 +764,7 @@ GNUNET_log_setup (const char *comp, * @param logger_cls closure for @a logger */ void -GNUNET_logger_add (GNUNET_Logger logger, - void *logger_cls) +GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls) { struct CustomLogger *entry; @@ -781,8 +783,7 @@ GNUNET_logger_add (GNUNET_Logger logger, * @param logger_cls closure for @a logger */ void -GNUNET_logger_remove (GNUNET_Logger logger, - void *logger_cls) +GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) { struct CustomLogger *pos; struct CustomLogger *prev; @@ -828,8 +829,7 @@ output_message (enum GNUNET_ErrorType kind, EnterCriticalSection (&output_message_cs); #endif /* only use the standard logger if no custom loggers are present */ - if ( (NULL != GNUNET_stderr) && - (NULL == loggers) ) + if ((NULL != GNUNET_stderr) && (NULL == loggers)) { if (kind == GNUNET_ERROR_TYPE_MESSAGE) { @@ -841,9 +841,7 @@ output_message (enum GNUNET_ErrorType kind, * this way if the output is going to logfiles or robots * instead. */ - FPRINTF (GNUNET_stderr, - "* %s", - msg); + FPRINTF (GNUNET_stderr, "* %s", msg); } else if (GNUNET_YES == current_async_scope.have_scope) { @@ -881,11 +879,7 @@ output_message (enum GNUNET_ErrorType kind, pos = loggers; while (NULL != pos) { - pos->logger (pos->logger_cls, - kind, - comp, - datestr, - msg); + pos->logger (pos->logger_cls, kind, comp, datestr, msg); pos = pos->next; } #if WINDOWS @@ -907,8 +901,7 @@ flush_bulk (const char *datestr) char *last; const char *ft; - if ( (0 == last_bulk_time.abs_value_us) || - (0 == last_bulk_repeat) ) + if ((0 == last_bulk_time.abs_value_us) || (0 == last_bulk_repeat)) return; rev = 0; last = memchr (last_bulk, '\0', BULK_TRACK_SIZE); @@ -921,11 +914,17 @@ flush_bulk (const char *datestr) rev = 1; last[0] = '\0'; } - ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration - (last_bulk_time), GNUNET_YES); - snprintf (msg, sizeof (msg), - _("Message `%.*s' repeated %u times in the last %s\n"), - BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft); + ft = + GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration ( + last_bulk_time), + GNUNET_YES); + snprintf (msg, + sizeof (msg), + _ ("Message `%.*s' repeated %u times in the last %s\n"), + BULK_TRACK_SIZE, + last_bulk, + last_bulk_repeat, + ft); if (rev == 1) last[0] = '\n'; output_message (last_bulk_kind, last_bulk_comp, datestr, msg); @@ -941,8 +940,7 @@ flush_bulk (const char *datestr) * @param check_reset #GNUNET_YES to assert that the log skip counter is currently zero */ void -GNUNET_log_skip (int n, - int check_reset) +GNUNET_log_skip (int n, int check_reset) { int ok; @@ -993,15 +991,10 @@ mylog (enum GNUNET_ErrorType kind, va_list vacp; va_copy (vacp, va); - size = VSNPRINTF (NULL, - 0, - message, - vacp) + 1; + size = VSNPRINTF (NULL, 0, message, vacp) + 1; GNUNET_assert (0 != size); va_end (vacp); - memset (date, - 0, - DATE_STR_SIZE); + memset (date, 0, DATE_STR_SIZE); { char buf[size]; long long offset; @@ -1022,24 +1015,19 @@ mylog (enum GNUNET_ErrorType kind, else { if (0 == - strftime (date2, - DATE_STR_SIZE, - "%b %d %H:%M:%S-%%020llu", - tmptr)) - abort (); - if (0 > - snprintf (date, - sizeof (date), - date2, - (long long) (pc.QuadPart / - (performance_frequency.QuadPart / 1000)))) - abort (); + strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr)) + abort (); + if (0 > snprintf (date, + sizeof (date), + date2, + (long long) (pc.QuadPart / + (performance_frequency.QuadPart / 1000)))) + abort (); } #else struct timeval timeofday; - gettimeofday (&timeofday, - NULL); + gettimeofday (&timeofday, NULL); offset = GNUNET_TIME_get_offset (); if (offset > 0) { @@ -1047,80 +1035,59 @@ mylog (enum GNUNET_ErrorType kind, timeofday.tv_usec += (offset % 1000LL) * 1000LL; if (timeofday.tv_usec > 1000000LL) { - timeofday.tv_usec -= 1000000LL; - timeofday.tv_sec++; + timeofday.tv_usec -= 1000000LL; + timeofday.tv_sec++; } } else { timeofday.tv_sec += offset / 1000LL; - if (timeofday.tv_usec > - (offset % 1000LL) * 1000LL) + if (timeofday.tv_usec > -(offset % 1000LL) * 1000LL) { - timeofday.tv_usec += (offset % 1000LL) * 1000LL; + timeofday.tv_usec += (offset % 1000LL) * 1000LL; } else { - timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL; - timeofday.tv_sec--; + timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL; + timeofday.tv_sec--; } } tmptr = localtime (&timeofday.tv_sec); if (NULL == tmptr) { - strcpy (date, - "localtime error"); + strcpy (date, "localtime error"); } else { - if (0 == - strftime (date2, - DATE_STR_SIZE, - "%b %d %H:%M:%S-%%06u", - tmptr)) - abort (); - if (0 > - snprintf (date, - sizeof (date), - date2, - timeofday.tv_usec)) - abort (); + if (0 == strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr)) + abort (); + if (0 > snprintf (date, sizeof (date), date2, timeofday.tv_usec)) + abort (); } #endif - VSNPRINTF (buf, - size, - message, - va); + VSNPRINTF (buf, size, message, va); #if ! (defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY) if (NULL != tmptr) (void) setup_log_file (tmptr); #endif if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && (0 != last_bulk_time.abs_value_us) && - (0 == strncmp (buf, - last_bulk, - sizeof (last_bulk)))) + (0 == strncmp (buf, last_bulk, sizeof (last_bulk)))) { last_bulk_repeat++; - if ( (GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value_us > - BULK_DELAY_THRESHOLD) || - (last_bulk_repeat > BULK_REPEAT_THRESHOLD) ) + if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value_us > + BULK_DELAY_THRESHOLD) || + (last_bulk_repeat > BULK_REPEAT_THRESHOLD)) flush_bulk (date); return; } flush_bulk (date); - strncpy (last_bulk, - buf, - sizeof (last_bulk)); + strncpy (last_bulk, buf, sizeof (last_bulk)); last_bulk_repeat = 0; last_bulk_kind = kind; last_bulk_time = GNUNET_TIME_absolute_get (); - strncpy (last_bulk_comp, - comp, - COMP_TRACK_SIZE); - output_message (kind, - comp, - date, - buf); + strncpy (last_bulk_comp, comp, COMP_TRACK_SIZE); + output_message (kind, comp, date, buf); } } @@ -1133,8 +1100,7 @@ mylog (enum GNUNET_ErrorType kind, * @param ... arguments for format string */ void -GNUNET_log_nocheck (enum GNUNET_ErrorType kind, - const char *message, ...) +GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...) { va_list va; @@ -1154,8 +1120,10 @@ GNUNET_log_nocheck (enum GNUNET_ErrorType kind, * @param ... arguments for format string */ void -GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, - const char *message, ...) +GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, + const char *comp, + const char *message, + ...) { va_list va; char comp_w_pid[128]; @@ -1180,18 +1148,18 @@ const char * GNUNET_error_type_to_string (enum GNUNET_ErrorType kind) { if ((kind & GNUNET_ERROR_TYPE_ERROR) > 0) - return _("ERROR"); + return _ ("ERROR"); if ((kind & GNUNET_ERROR_TYPE_WARNING) > 0) - return _("WARNING"); + return _ ("WARNING"); if ((kind & GNUNET_ERROR_TYPE_MESSAGE) > 0) - return _("MESSAGE"); + return _ ("MESSAGE"); if ((kind & GNUNET_ERROR_TYPE_INFO) > 0) - return _("INFO"); + return _ ("INFO"); if ((kind & GNUNET_ERROR_TYPE_DEBUG) > 0) - return _("DEBUG"); + return _ ("DEBUG"); if ((kind & ~GNUNET_ERROR_TYPE_BULK) == 0) - return _("NONE"); - return _("INVALID"); + return _ ("NONE"); + return _ ("INVALID"); } @@ -1202,7 +1170,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind) * @return string form; will be overwritten by next call to GNUNET_h2s. */ const char * -GNUNET_h2s (const struct GNUNET_HashCode * hc) +GNUNET_h2s (const struct GNUNET_HashCode *hc) { static GNUNET_THREAD_LOCAL struct GNUNET_CRYPTO_HashAsciiEncoded ret; @@ -1223,7 +1191,7 @@ GNUNET_h2s (const struct GNUNET_HashCode * hc) * @return string form; will be overwritten by next call to GNUNET_h2s. */ const char * -GNUNET_h2s2 (const struct GNUNET_HashCode * hc) +GNUNET_h2s2 (const struct GNUNET_HashCode *hc) { static struct GNUNET_CRYPTO_HashAsciiEncoded ret; @@ -1248,11 +1216,8 @@ GNUNET_p2s (const struct GNUNET_CRYPTO_EddsaPublicKey *p) static struct GNUNET_CRYPTO_HashAsciiEncoded ret; struct GNUNET_HashCode hc; - GNUNET_CRYPTO_hash (p, - sizeof (*p), - &hc); - GNUNET_CRYPTO_hash_to_enc (&hc, - &ret); + GNUNET_CRYPTO_hash (p, sizeof (*p), &hc); + GNUNET_CRYPTO_hash_to_enc (&hc, &ret); ret.encoding[6] = '\0'; return (const char *) ret.encoding; } @@ -1273,11 +1238,8 @@ GNUNET_p2s2 (const struct GNUNET_CRYPTO_EddsaPublicKey *p) static struct GNUNET_CRYPTO_HashAsciiEncoded ret; struct GNUNET_HashCode hc; - GNUNET_CRYPTO_hash (p, - sizeof (*p), - &hc); - GNUNET_CRYPTO_hash_to_enc (&hc, - &ret); + GNUNET_CRYPTO_hash (p, sizeof (*p), &hc); + GNUNET_CRYPTO_hash_to_enc (&hc, &ret); ret.encoding[6] = '\0'; return (const char *) ret.encoding; } @@ -1298,11 +1260,8 @@ GNUNET_e2s (const struct GNUNET_CRYPTO_EcdhePublicKey *p) static struct GNUNET_CRYPTO_HashAsciiEncoded ret; struct GNUNET_HashCode hc; - GNUNET_CRYPTO_hash (p, - sizeof (*p), - &hc); - GNUNET_CRYPTO_hash_to_enc (&hc, - &ret); + GNUNET_CRYPTO_hash (p, sizeof (*p), &hc); + GNUNET_CRYPTO_hash_to_enc (&hc, &ret); ret.encoding[6] = '\0'; return (const char *) ret.encoding; } @@ -1323,11 +1282,8 @@ GNUNET_e2s2 (const struct GNUNET_CRYPTO_EcdhePublicKey *p) static struct GNUNET_CRYPTO_HashAsciiEncoded ret; struct GNUNET_HashCode hc; - GNUNET_CRYPTO_hash (p, - sizeof (*p), - &hc); - GNUNET_CRYPTO_hash_to_enc (&hc, - &ret); + GNUNET_CRYPTO_hash (p, sizeof (*p), &hc); + GNUNET_CRYPTO_hash_to_enc (&hc, &ret); ret.encoding[6] = '\0'; return (const char *) ret.encoding; } @@ -1347,10 +1303,27 @@ GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc) { static char buf[64]; - GNUNET_STRINGS_data_to_string (shc, - sizeof (*shc), - buf, - sizeof (buf)); + GNUNET_STRINGS_data_to_string (shc, sizeof (*shc), buf, sizeof (buf)); + buf[6] = '\0'; + return (const char *) buf; +} + + +/** + * @ingroup logging + * Convert a UUID to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param uuid the UUID + * @return string + */ +const char * +GNUNET_uuid2s (const struct GNUNET_Uuid *uuid) +{ + static char buf[32]; + + GNUNET_STRINGS_data_to_string (uuid, sizeof (*uuid), buf, sizeof (buf)); buf[6] = '\0'; return (const char *) buf; } @@ -1365,7 +1338,7 @@ GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc) * @return string form; will be overwritten by next call to GNUNET_h2s_full. */ const char * -GNUNET_h2s_full (const struct GNUNET_HashCode * hc) +GNUNET_h2s_full (const struct GNUNET_HashCode *hc) { static struct GNUNET_CRYPTO_HashAsciiEncoded ret; @@ -1391,9 +1364,7 @@ GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) if (NULL == pid) return "NULL"; ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); - strncpy (buf, - ret, - sizeof (buf) - 1); + strncpy (buf, ret, sizeof (buf) - 1); GNUNET_free (ret); buf[4] = '\0'; return buf; @@ -1419,9 +1390,7 @@ GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) if (NULL == pid) return "NULL"; ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); - strncpy (buf, - ret, - sizeof (buf) - 1); + strncpy (buf, ret, sizeof (buf) - 1); GNUNET_free (ret); buf[4] = '\0'; return buf; @@ -1459,12 +1428,12 @@ GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid) * will be overwritten by next call to #GNUNET_a2s. */ const char * -GNUNET_a2s (const struct sockaddr *addr, - socklen_t addrlen) +GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen) { #ifndef WINDOWS -#define LEN GNUNET_MAX ((INET6_ADDRSTRLEN + 8), \ - (1 + sizeof (struct sockaddr_un) - sizeof (sa_family_t))) +#define LEN \ + GNUNET_MAX ((INET6_ADDRSTRLEN + 8), \ + (1 + sizeof (struct sockaddr_un) - sizeof (sa_family_t))) #else #define LEN (INET6_ADDRSTRLEN + 8) #endif @@ -1477,24 +1446,18 @@ GNUNET_a2s (const struct sockaddr *addr, unsigned int off; if (addr == NULL) - return _("unknown address"); + return _ ("unknown address"); switch (addr->sa_family) { case AF_INET: if (addrlen != sizeof (struct sockaddr_in)) return ""; v4 = (const struct sockaddr_in *) addr; - inet_ntop (AF_INET, - &v4->sin_addr, - buf, - INET_ADDRSTRLEN); + inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); if (0 == ntohs (v4->sin_port)) return buf; strcat (buf, ":"); - GNUNET_snprintf (b2, - sizeof (b2), - "%u", - ntohs (v4->sin_port)); + GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port)); strcat (buf, b2); return buf; case AF_INET6: @@ -1502,19 +1465,12 @@ GNUNET_a2s (const struct sockaddr *addr, return ""; v6 = (const struct sockaddr_in6 *) addr; buf[0] = '['; - inet_ntop (AF_INET6, - &v6->sin6_addr, - &buf[1], - INET6_ADDRSTRLEN); + inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); if (0 == ntohs (v6->sin6_port)) return &buf[1]; strcat (buf, "]:"); - GNUNET_snprintf (b2, - sizeof (b2), - "%u", - ntohs (v6->sin6_port)); - strcat (buf, - b2); + GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port)); + strcat (buf, b2); return buf; case AF_UNIX: if (addrlen <= sizeof (sa_family_t)) @@ -1532,7 +1488,7 @@ GNUNET_a2s (const struct sockaddr *addr, &un->sun_path[off]); return buf; default: - return _("invalid address"); + return _ ("invalid address"); } } @@ -1546,13 +1502,14 @@ GNUNET_a2s (const struct sockaddr *addr, */ void GNUNET_log_config_missing (enum GNUNET_ErrorType kind, - const char *section, - const char *option) + const char *section, + const char *option) { GNUNET_log (kind, - _("Configuration fails to specify option `%s' in section `%s'!\n"), - option, - section); + _ ( + "Configuration fails to specify option `%s' in section `%s'!\n"), + option, + section); } @@ -1566,13 +1523,17 @@ GNUNET_log_config_missing (enum GNUNET_ErrorType kind, */ void GNUNET_log_config_invalid (enum GNUNET_ErrorType kind, - const char *section, - const char *option, - const char *required) + const char *section, + const char *option, + const char *required) { - GNUNET_log (kind, - _("Configuration specifies invalid value for option `%s' in section `%s': %s\n"), - option, section, required); + GNUNET_log ( + kind, + _ ( + "Configuration specifies invalid value for option `%s' in section `%s': %s\n"), + option, + section, + required); } @@ -1633,15 +1594,14 @@ GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret) /** * Initializer */ -void __attribute__ ((constructor)) -GNUNET_util_cl_init () +void __attribute__ ((constructor)) GNUNET_util_cl_init () { GNUNET_stderr = stderr; #ifdef MINGW GNInitWinEnv (NULL); #endif #if WINDOWS - if (!InitializeCriticalSectionAndSpinCount (&output_message_cs, 0x00000400)) + if (! InitializeCriticalSectionAndSpinCount (&output_message_cs, 0x00000400)) GNUNET_abort_ (); #endif } @@ -1650,8 +1610,7 @@ GNUNET_util_cl_init () /** * Destructor */ -void __attribute__ ((destructor)) -GNUNET_util_cl_fini () +void __attribute__ ((destructor)) GNUNET_util_cl_fini () { #if WINDOWS DeleteCriticalSection (&output_message_cs); diff --git a/src/util/container_multiuuidmap.c b/src/util/container_multiuuidmap.c new file mode 100644 index 000000000..49eb64cfe --- /dev/null +++ b/src/util/container_multiuuidmap.c @@ -0,0 +1,1015 @@ +/* + This file is part of GNUnet. + Copyright (C) 2008, 2012 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later +*/ +/** + * @file util/container_multiuuidmap.c + * @brief hash map for UUIDs where the same key may be present multiple times + * @author Christian Grothoff + */ + +#include "platform.h" +#include "gnunet_util_lib.h" + +#define LOG(kind, ...) \ + GNUNET_log_from (kind, "util-container-multiuuidmap", __VA_ARGS__) + +/** + * Maximum recursion depth for callbacks of + * #GNUNET_CONTAINER_multihashmap_get_multiple() themselve s + * again calling #GNUNET_CONTAINER_multihashmap_get_multiple(). + * Should be totally excessive, but if violated we die. + */ +#define NEXT_CACHE_SIZE 16 + + +/** + * An entry in the hash map with the full key. + */ +struct BigMapEntry +{ + + /** + * Value of the entry. + */ + void *value; + + /** + * If there is a hash collision, we create a linked list. + */ + struct BigMapEntry *next; + + /** + * Key for the entry. + */ + struct GNUNET_Uuid key; +}; + + +/** + * An entry in the hash map with just a pointer to the key. + */ +struct SmallMapEntry +{ + + /** + * Value of the entry. + */ + void *value; + + /** + * If there is a hash collision, we create a linked list. + */ + struct SmallMapEntry *next; + + /** + * Key for the entry. + */ + const struct GNUNET_Uuid *key; +}; + + +/** + * Entry in the map. + */ +union MapEntry +{ + /** + * Variant used if map entries only contain a pointer to the key. + */ + struct SmallMapEntry *sme; + + /** + * Variant used if map entries contain the full key. + */ + struct BigMapEntry *bme; +}; + + +/** + * Internal representation of the hash map. + */ +struct GNUNET_CONTAINER_MultiUuidmap +{ + /** + * All of our buckets. + */ + union MapEntry *map; + + /** + * Number of entries in the map. + */ + unsigned int size; + + /** + * Length of the "map" array. + */ + unsigned int map_length; + + /** + * #GNUNET_NO if the map entries are of type 'struct BigMapEntry', + * #GNUNET_YES if the map entries are of type 'struct SmallMapEntry'. + */ + int use_small_entries; + + /** + * Counts the destructive modifications (grow, remove) + * to the map, so that iterators can check if they are still valid. + */ + unsigned int modification_counter; + + /** + * Map entries indicating iteration positions currently + * in use by #GNUNET_CONTAINER_multihashmap_get_multiple(). + * Only used up to @e next_cache_off. + */ + union MapEntry next_cache[NEXT_CACHE_SIZE]; + + /** + * Offset of @e next_cache entries in use, must be smaller + * than #NEXT_CACHE_SIZE. + */ + unsigned int next_cache_off; +}; + + +/** + * Cursor into a multiuuidmap. + * Allows to enumerate elements asynchronously. + */ +struct GNUNET_CONTAINER_MultiUuidmapIterator +{ + /** + * Position in the bucket 'idx' + */ + union MapEntry me; + + /** + * Current bucket index. + */ + unsigned int idx; + + /** + * Modification counter as observed on the map when the iterator + * was created. + */ + unsigned int modification_counter; + + /** + * Map that we are iterating over. + */ + const struct GNUNET_CONTAINER_MultiUuidmap *map; +}; + + +/** + * Create a multi hash map. + * + * @param len initial size (map will grow as needed) + * @param do_not_copy_keys #GNUNET_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 recipie 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 + * @return NULL on error + */ +struct GNUNET_CONTAINER_MultiUuidmap * +GNUNET_CONTAINER_multiuuidmap_create (unsigned int len, int do_not_copy_keys) +{ + struct GNUNET_CONTAINER_MultiUuidmap *map; + + GNUNET_assert (len > 0); + map = GNUNET_new (struct GNUNET_CONTAINER_MultiUuidmap); + map->map = GNUNET_malloc_large (len * sizeof (union MapEntry)); + if (NULL == map->map) + { + GNUNET_free (map); + return NULL; + } + map->map_length = len; + map->use_small_entries = do_not_copy_keys; + return map; +} + + +/** + * Destroy a hash map. Will not free any values + * stored in the hash map! + * + * @param map the map + */ +void +GNUNET_CONTAINER_multiuuidmap_destroy ( + struct GNUNET_CONTAINER_MultiUuidmap *map) +{ + GNUNET_assert (0 == map->next_cache_off); + for (unsigned int i = 0; i < map->map_length; i++) + { + union MapEntry me; + + me = map->map[i]; + if (map->use_small_entries) + { + struct SmallMapEntry *sme; + struct SmallMapEntry *nxt; + + nxt = me.sme; + while (NULL != (sme = nxt)) + { + nxt = sme->next; + GNUNET_free (sme); + } + me.sme = NULL; + } + else + { + struct BigMapEntry *bme; + struct BigMapEntry *nxt; + + nxt = me.bme; + while (NULL != (bme = nxt)) + { + nxt = bme->next; + GNUNET_free (bme); + } + me.bme = NULL; + } + } + GNUNET_free (map->map); + GNUNET_free (map); +} + + +/** + * Compute the index of the bucket for the given key. + * + * @param map hash map for which to compute the index + * @param key what key should the index be computed for + * @return offset into the "map" array of "map" + */ +static unsigned int +idx_of (const struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key) +{ + unsigned int kx; + + GNUNET_assert (NULL != map); + GNUNET_memcpy (&kx, key, sizeof (kx)); + return kx % map->map_length; +} + + +/** + * Get the number of key-value pairs in the map. + * + * @param map the map + * @return the number of key value pairs + */ +unsigned int +GNUNET_CONTAINER_multiuuidmap_size ( + const struct GNUNET_CONTAINER_MultiUuidmap *map) +{ + return map->size; +} + + +/** + * Given a key find a value in the map matching the key. + * + * @param map the map + * @param key what to look for + * @return 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 + */ +void * +GNUNET_CONTAINER_multiuuidmap_get ( + const struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key) +{ + union MapEntry me; + + me = map->map[idx_of (map, key)]; + if (map->use_small_entries) + { + for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) + if (0 == GNUNET_memcmp (key, sme->key)) + return sme->value; + } + else + { + for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) + if (0 == GNUNET_memcmp (key, &bme->key)) + return bme->value; + } + return NULL; +} + + +/** + * Iterate over all entries in the map. + * + * @param map the map + * @param it function to call on each entry + * @param it_cls extra argument to @a it + * @return the number of key value pairs processed, + * #GNUNET_SYSERR if it aborted iteration + */ +int +GNUNET_CONTAINER_multiuuidmap_iterate ( + struct GNUNET_CONTAINER_MultiUuidmap *map, + GNUNET_CONTAINER_MultiUuidmapIterator it, + void *it_cls) +{ + int count; + union MapEntry me; + union MapEntry *ce; + struct GNUNET_Uuid kc; + + count = 0; + GNUNET_assert (NULL != map); + ce = &map->next_cache[map->next_cache_off]; + GNUNET_assert (++map->next_cache_off < NEXT_CACHE_SIZE); + for (unsigned int i = 0; i < map->map_length; i++) + { + me = map->map[i]; + if (map->use_small_entries) + { + struct SmallMapEntry *sme; + + ce->sme = me.sme; + while (NULL != (sme = ce->sme)) + { + ce->sme = sme->next; + if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value))) + { + GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); + return GNUNET_SYSERR; + } + count++; + } + } + else + { + struct BigMapEntry *bme; + + ce->bme = me.bme; + while (NULL != (bme = ce->bme)) + { + ce->bme = bme->next; + if (NULL != it) + { + kc = bme->key; + if (GNUNET_OK != it (it_cls, &kc, bme->value)) + { + GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); + return GNUNET_SYSERR; + } + } + count++; + } + } + } + GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); + return count; +} + + +/** + * We are about to free() the @a bme, make sure it is not in + * the list of next values for any iterator in the @a map's next_cache. + * + * @param map the map to check + * @param bme the entry that is about to be free'd + */ +static void +update_next_cache_bme (struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct BigMapEntry *bme) +{ + for (unsigned int i = 0; i < map->next_cache_off; i++) + if (map->next_cache[i].bme == bme) + map->next_cache[i].bme = bme->next; +} + + +/** + * We are about to free() the @a sme, make sure it is not in + * the list of next values for any iterator in the @a map's next_cache. + * + * @param map the map to check + * @param sme the entry that is about to be free'd + */ +static void +update_next_cache_sme (struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct SmallMapEntry *sme) +{ + for (unsigned int i = 0; i < map->next_cache_off; i++) + if (map->next_cache[i].sme == sme) + map->next_cache[i].sme = sme->next; +} + + +/** + * 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. + * + * @param map the map + * @param key key of the key-value pair + * @param value value of the key-value pair + * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair + * is not in the map + */ +int +GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key, + const void *value) +{ + union MapEntry me; + unsigned int i; + + map->modification_counter++; + i = idx_of (map, key); + me = map->map[i]; + if (map->use_small_entries) + { + struct SmallMapEntry *p = NULL; + + for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) + { + if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value)) + { + if (NULL == p) + map->map[i].sme = sme->next; + else + p->next = sme->next; + update_next_cache_sme (map, sme); + GNUNET_free (sme); + map->size--; + return GNUNET_YES; + } + p = sme; + } + } + else + { + struct BigMapEntry *p = NULL; + + for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) + { + if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value)) + { + if (NULL == p) + map->map[i].bme = bme->next; + else + p->next = bme->next; + update_next_cache_bme (map, bme); + GNUNET_free (bme); + map->size--; + return GNUNET_YES; + } + p = bme; + } + } + return GNUNET_NO; +} + + +/** + * Remove all entries for the given key from the map. + * Note that the values would not be "freed". + * + * @param map the map + * @param key identifies values to be removed + * @return number of values removed + */ +int +GNUNET_CONTAINER_multiuuidmap_remove_all ( + struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key) +{ + union MapEntry me; + unsigned int i; + int ret; + + map->modification_counter++; + + ret = 0; + i = idx_of (map, key); + me = map->map[i]; + if (map->use_small_entries) + { + struct SmallMapEntry *sme; + struct SmallMapEntry *p; + + p = NULL; + sme = me.sme; + while (NULL != sme) + { + if (0 == GNUNET_memcmp (key, sme->key)) + { + if (NULL == p) + map->map[i].sme = sme->next; + else + p->next = sme->next; + update_next_cache_sme (map, sme); + GNUNET_free (sme); + map->size--; + if (NULL == p) + sme = map->map[i].sme; + else + sme = p->next; + ret++; + } + else + { + p = sme; + sme = sme->next; + } + } + } + else + { + struct BigMapEntry *bme; + struct BigMapEntry *p; + + p = NULL; + bme = me.bme; + while (NULL != bme) + { + if (0 == GNUNET_memcmp (key, &bme->key)) + { + if (NULL == p) + map->map[i].bme = bme->next; + else + p->next = bme->next; + update_next_cache_bme (map, bme); + GNUNET_free (bme); + map->size--; + if (NULL == p) + bme = map->map[i].bme; + else + bme = p->next; + ret++; + } + else + { + p = bme; + bme = bme->next; + } + } + } + return ret; +} + + +/** + * Check if the map contains any value under the given + * key (including values that are NULL). + * + * @param map the map + * @param key the key to test if a value exists for it + * @return #GNUNET_YES if such a value exists, + * #GNUNET_NO if not + */ +int +GNUNET_CONTAINER_multiuuidmap_contains ( + const struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key) +{ + union MapEntry me; + + me = map->map[idx_of (map, key)]; + if (map->use_small_entries) + { + for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) + if (0 == GNUNET_memcmp (key, sme->key)) + return GNUNET_YES; + } + else + { + for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) + if (0 == GNUNET_memcmp (key, &bme->key)) + return GNUNET_YES; + } + return GNUNET_NO; +} + + +/** + * Check if the map contains the given value under the given + * key. + * + * @param map the map + * @param key the key to test if a value exists for it + * @param value value to test for + * @return #GNUNET_YES if such a value exists, + * #GNUNET_NO if not + */ +int +GNUNET_CONTAINER_multiuuidmap_contains_value ( + const struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key, + const void *value) +{ + union MapEntry me; + + me = map->map[idx_of (map, key)]; + if (map->use_small_entries) + { + for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) + if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value)) + return GNUNET_YES; + } + else + { + for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) + if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value)) + return GNUNET_YES; + } + return GNUNET_NO; +} + + +/** + * Grow the given map to a more appropriate size. + * + * @param map the hash map to grow + */ +static void +grow (struct GNUNET_CONTAINER_MultiUuidmap *map) +{ + union MapEntry *old_map; + union MapEntry *new_map; + unsigned int old_len; + unsigned int new_len; + unsigned int idx; + + old_map = map->map; + old_len = map->map_length; + new_len = old_len * 2; + if (0 == new_len) /* 2^31 * 2 == 0 */ + new_len = old_len; /* never use 0 */ + if (new_len == old_len) + return; /* nothing changed */ + new_map = GNUNET_malloc_large (new_len * sizeof (union MapEntry)); + if (NULL == new_map) + return; /* grow not possible */ + map->modification_counter++; + map->map_length = new_len; + map->map = new_map; + for (unsigned int i = 0; i < old_len; i++) + { + if (map->use_small_entries) + { + struct SmallMapEntry *sme; + + while (NULL != (sme = old_map[i].sme)) + { + old_map[i].sme = sme->next; + idx = idx_of (map, sme->key); + sme->next = new_map[idx].sme; + new_map[idx].sme = sme; + } + } + else + { + struct BigMapEntry *bme; + + while (NULL != (bme = old_map[i].bme)) + { + old_map[i].bme = bme->next; + idx = idx_of (map, &bme->key); + bme->next = new_map[idx].bme; + new_map[idx].bme = bme; + } + } + } + GNUNET_free (old_map); +} + + +/** + * Store a key-value pair in the map. + * + * @param map the map + * @param key key to use + * @param value value to use + * @param opt options for put + * @return #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 + */ +int +GNUNET_CONTAINER_multiuuidmap_put (struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key, + void *value, + enum GNUNET_CONTAINER_MultiHashMapOption opt) +{ + union MapEntry me; + unsigned int i; + + i = idx_of (map, key); + if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && + (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) + { + me = map->map[i]; + if (map->use_small_entries) + { + for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) + if (0 == GNUNET_memcmp (key, sme->key)) + { + if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) + return GNUNET_SYSERR; + sme->value = value; + return GNUNET_NO; + } + } + else + { + for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) + if (0 == GNUNET_memcmp (key, &bme->key)) + { + if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) + return GNUNET_SYSERR; + bme->value = value; + return GNUNET_NO; + } + } + } + if (map->size / 3 >= map->map_length / 4) + { + grow (map); + i = idx_of (map, key); + } + if (map->use_small_entries) + { + struct SmallMapEntry *sme; + + sme = GNUNET_new (struct SmallMapEntry); + sme->key = key; + sme->value = value; + sme->next = map->map[i].sme; + map->map[i].sme = sme; + } + else + { + struct BigMapEntry *bme; + + bme = GNUNET_new (struct BigMapEntry); + bme->key = *key; + bme->value = value; + bme->next = map->map[i].bme; + map->map[i].bme = bme; + } + map->size++; + return GNUNET_OK; +} + + +/** + * Iterate over all entries in the map that match a particular key. + * + * @param map the map + * @param key key that the entries must correspond to + * @param it function to call on each entry + * @param it_cls extra argument to @a it + * @return the number of key value pairs processed, + * #GNUNET_SYSERR if it aborted iteration + */ +int +GNUNET_CONTAINER_multiuuidmap_get_multiple ( + struct GNUNET_CONTAINER_MultiUuidmap *map, + const struct GNUNET_Uuid *key, + GNUNET_CONTAINER_MultiUuidmapIterator it, + void *it_cls) +{ + int count; + union MapEntry me; + union MapEntry *ce; + + ce = &map->next_cache[map->next_cache_off]; + GNUNET_assert (++map->next_cache_off < NEXT_CACHE_SIZE); + count = 0; + me = map->map[idx_of (map, key)]; + if (map->use_small_entries) + { + struct SmallMapEntry *sme; + + ce->sme = me.sme; + while (NULL != (sme = ce->sme)) + { + ce->sme = sme->next; + if (0 != GNUNET_memcmp (key, sme->key)) + continue; + if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value))) + { + GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); + return GNUNET_SYSERR; + } + count++; + } + } + else + { + struct BigMapEntry *bme; + + ce->bme = me.bme; + while (NULL != (bme = ce->bme)) + { + ce->bme = bme->next; + if (0 != GNUNET_memcmp (key, &bme->key)) + continue; + if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value))) + { + GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); + return GNUNET_SYSERR; + } + count++; + } + } + GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE); + return count; +} + + +/** + * @ingroup hashmap + * Call @a 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). + * + * @param map the map + * @param it function to call on a random entry + * @param it_cls extra argument to @a it + * @return the number of key value pairs processed, zero or one. + */ +unsigned int +GNUNET_CONTAINER_multiuuidmap_get_random ( + const struct GNUNET_CONTAINER_MultiUuidmap *map, + GNUNET_CONTAINER_MultiUuidmapIterator it, + void *it_cls) +{ + unsigned int off; + union MapEntry me; + + if (0 == map->size) + return 0; + if (NULL == it) + return 1; + off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, map->size); + for (unsigned int idx = 0; idx < map->map_length; idx++) + { + me = map->map[idx]; + if (map->use_small_entries) + { + for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next) + { + if (0 == off) + { + if (GNUNET_OK != it (it_cls, sme->key, sme->value)) + return GNUNET_SYSERR; + return 1; + } + off--; + } + } + else + { + for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next) + { + if (0 == off) + { + if (GNUNET_OK != it (it_cls, &bme->key, bme->value)) + return GNUNET_SYSERR; + return 1; + } + off--; + } + } + } + GNUNET_break (0); + return GNUNET_SYSERR; +} + + +/** + * Create an iterator for a multiuuidmap. + * The iterator can be used to retrieve all the elements in the multiuuidmap + * 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. + * + * @param map the map to create an iterator for + * @return an iterator over the given multiuuidmap 'map' + */ +struct GNUNET_CONTAINER_MultiUuidmapIterator * +GNUNET_CONTAINER_multiuuidmap_iterator_create ( + const struct GNUNET_CONTAINER_MultiUuidmap *map) +{ + struct GNUNET_CONTAINER_MultiUuidmapIterator *iter; + + iter = GNUNET_new (struct GNUNET_CONTAINER_MultiUuidmapIterator); + iter->map = map; + iter->modification_counter = map->modification_counter; + iter->me = map->map[0]; + return iter; +} + + +/** + * 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 + * multiuuidmap since the creation of 'iter', and the map has not been destroyed. + * Adding elements may result in repeating or skipping elements. + * + * @param iter the iterator to get the next element from + * @param key pointer to store the key in, can be NULL + * @param value pointer to store the value in, can be NULL + * @return #GNUNET_YES we returned an element, + * #GNUNET_NO if we are out of elements + */ +int +GNUNET_CONTAINER_multiuuidmap_iterator_next ( + struct GNUNET_CONTAINER_MultiUuidmapIterator *iter, + struct GNUNET_Uuid *key, + const void **value) +{ + /* make sure the map has not been modified */ + GNUNET_assert (iter->modification_counter == iter->map->modification_counter); + + /* look for the next entry, skipping empty buckets */ + while (1) + { + if (iter->idx >= iter->map->map_length) + return GNUNET_NO; + if (GNUNET_YES == iter->map->use_small_entries) + { + if (NULL != iter->me.sme) + { + if (NULL != key) + *key = *iter->me.sme->key; + if (NULL != value) + *value = iter->me.sme->value; + iter->me.sme = iter->me.sme->next; + return GNUNET_YES; + } + } + else + { + if (NULL != iter->me.bme) + { + if (NULL != key) + *key = iter->me.bme->key; + if (NULL != value) + *value = iter->me.bme->value; + iter->me.bme = iter->me.bme->next; + return GNUNET_YES; + } + } + iter->idx += 1; + if (iter->idx < iter->map->map_length) + iter->me = iter->map->map[iter->idx]; + } +} + + +/** + * Destroy a multiuuidmap iterator. + * + * @param iter the iterator to destroy + */ +void +GNUNET_CONTAINER_multiuuidmap_iterator_destroy ( + struct GNUNET_CONTAINER_MultiUuidmapIterator *iter) +{ + GNUNET_free (iter); +} + + +/* end of container_multiuuidmap.c */ -- cgit v1.2.3 From 4cdc3b856356a4eee10534834d84df4159568739 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 18 Jun 2019 10:47:56 +0200 Subject: clean up comments, fixmes, remove dead code --- src/transport/gnunet-service-tng.c | 181 +++++++------------------------------ 1 file changed, 33 insertions(+), 148 deletions(-) diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index eb3cc2de9..803a8e518 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c @@ -27,69 +27,50 @@ * - review retransmission logic, right now there is no smartness there! * => congestion control, etc [PERFORMANCE-BASICS] * - * Optimizations: + * Optimizations-Statistics: + * - Track ACK losses based on ACK-counter [ROUTING] + * - Need to track total bandwidth per VirtualLink and adjust how frequently + * we send FC messages based on bandwidth-delay-product (and relation + * to the window size!). See OPTIMIZE-FC-BDP. + * - Consider more statistics in #check_connection_quality() [FIXME-CONQ-STATISTICS] + * - Adapt available_fc_window_size, using larger values for high-bandwidth + * and high-latency links *if* we have the RAM [GOODPUT / utilization / stalls] + * - Set last_window_consum_limit promise properly based on + * latency and bandwidth of the respective connection [GOODPUT / utilization / stalls] + * + * Optimizations-DV: * - When forwarding DV learn messages, if a peer is reached that * has a *bidirectional* link to the origin beyond 1st hop, * do NOT forward it to peers _other_ than the origin, as * there is clearly a better path directly from the origin to * whatever else we could reach. - * - queue_send_msg by API design has to make a copy - * of the payload, and route_message on top of that requires a malloc/free. - * Change design to approximate "zero" copy better... [CPU] - * - could avoid copying body of message into each fragment and keep - * fragments as just pointers into the original message and only - * fully build fragments just before transmission (optimization, should - * reduce CPU and memory use) [CPU, MEMORY] - * - if messages are below MTU, consider adding ACKs and other stuff - * to the same transmission to avoid tiny messages (requires planning at - * receiver, and additional MST-style demultiplex at receiver!) [PACKET COUNT] * - When we passively learned DV (with unconfirmed freshness), we * right now add the path to our list but with a zero path_valid_until * time and only use it for unconfirmed routes. However, we could consider * triggering an explicit validation mechansim ourselves, specifically routing * a challenge-response message over the path [ROUTING] - * - Track ACK losses based on ACK-counter [ROUTING] - * - Fragments send over a reliable channel could do without the - * AcknowledgementUUIDP altogether, as they won't be acked! [BANDWIDTH] - * (-> have 2nd type of acknowledgment message; low priority, as we - * do not have an MTU-limited *reliable* communicator) - * - Adapt available_fc_window_size, using larger values for high-bandwidth - * and high-latency links *if* we have the RAM [GOODPUT / utilization / stalls] - * - Set last_window_consum_limit promise properly based on - * latency and bandwidth of the respective connection [GOODPUT / utilization / stalls] - * - Need to track total bandwidth per VirtualLink and adjust how frequently - * we send FC messages based on bandwidth-delay-product (and relation - * to the window size!). See OPTIMIZE-FC-BDP. - * - if available, try to confirm unconfirmed DV paths when trying to establish + * = if available, try to confirm unconfirmed DV paths when trying to establish * virtual link for a `struct IncomingRequest`. (i.e. if DVH is * unconfirmed, incoming requests cause us to try to validate a passively * learned path (requires new message type!)) * - * Design realizations / discussion: - * - communicators do flow control by calling MQ "notify sent" - * when 'ready'. They determine flow implicitly (i.e. TCP blocking) - * or explicitly via backchannel FC ACKs. As long as the - * channel is not full, they may 'notify sent' even if the other - * peer has not yet confirmed receipt. The other peer confirming - * is _only_ for FC, not for more reliable transmission; reliable - * transmission (i.e. of fragments) is left to _transport_. - * - ACKs sent back in uni-directional communicators are done via - * the background channel API; here transport _may_ initially - * broadcast (with bounded # hops) if no path is known; - * - transport should _integrate_ DV-routing and build a view of - * the network; then background channel traffic can be - * routed via DV as well as explicit "DV" traffic. - * - background channel is also used for ACKs and NAT traversal support - * - transport service is responsible for AEAD'ing the background - * channel, timestamps and monotonic time are used against replay - * of old messages -> peerstore needs to be supplied with - * "latest timestamps seen" data - * - if transport implements DV, we likely need a 3rd peermap - * in addition to ephemerals and (direct) neighbours - * ==> check if stuff needs to be moved out of "Neighbour" - * - transport should encapsualte core-level messages and do its - * own ACKing for RTT/goodput/loss measurements _and_ fragment - * for retransmission + * Optimizations-Fragmentation: + * - Fragments send over a reliable channel could do without the + * AcknowledgementUUIDP altogether, as they won't be acked! [BANDWIDTH] + * (-> have 2nd type of acknowledgment message; low priority, as we + * do not have an MTU-limited *reliable* communicator) [FIXME-FRAG-REL-UUID] + * - if messages are below MTU, consider adding ACKs and other stuff + * to the same transmission to avoid tiny messages (requires planning at + * receiver, and additional MST-style demultiplex at receiver!) [PACKET COUNT] + * + * Optimizations-internals: + * - queue_send_msg by API design has to make a copy + * of the payload, and route_message on top of that requires a malloc/free. + * Change design to approximate "zero" copy better... [CPU] + * - could avoid copying body of message into each fragment and keep + * fragments as just pointers into the original message and only + * fully build fragments just before transmission (optimization, should + * reduce CPU and memory use) [CPU, MEMORY] */ #include "platform.h" #include "gnunet_util_lib.h" @@ -1308,18 +1289,6 @@ struct VirtualLink */ struct DistanceVector *dv; - /** - * Last challenge we received from @a n. - * FIXME: where do we need this? - */ - struct ChallengeNonceP n_challenge; - - /** - * Last challenge we used with @a n for flow control. - * FIXME: where do we need this? - */ - struct ChallengeNonceP my_challenge; - /** * Sender timestamp of @e n_challenge, used to generate out-of-order * challenges (as sender's timestamps must be monotonically @@ -4223,7 +4192,7 @@ queue_send_msg (struct Queue *queue, GNUNET_ERROR_TYPE_DEBUG, "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n", (unsigned int) payload_size, - pm->logging_uuid, + (NULL == pm) ? 0 : pm->logging_uuid, (unsigned long long) queue->qid, GNUNET_i2s (&queue->neighbour->pid)); env = GNUNET_MQ_msg_extra (smt, @@ -7555,89 +7524,6 @@ check_incoming_msg (void *cls, } -#if 0 -/** - * We received a @a challenge from another peer, check if we can - * increase the flow control window to that peer. - * - * @param vl virtual link - * @param challenge the challenge we received - * @param sender_time when did the peer send the message? - * @param last_window_consum_limit maximum number of kb the sender - * promises to use of the previous window (if any) - */ -static void -update_fc_window (struct VirtualLink *vl, - struct GNUNET_TIME_Absolute sender_time, - uint32_t last_window_consum_limit) -{ - // FIXME: update to new FC logic - if (0 == GNUNET_memcmp (challenge, &vl->n_challenge)) - { - uint32_t avail; - - /* Challenge identical to last one, update - @a last_window_consum_limit (to minimum) */ - vl->last_fc_window_size_remaining = - GNUNET_MIN (last_window_consum_limit, vl->last_fc_window_size_remaining); - /* window could have shrunk! */ - if (vl->available_fc_window_size > vl->last_fc_window_size_remaining) - avail = vl->available_fc_window_size - vl->last_fc_window_size_remaining; - else - avail = 0; - /* guard against integer overflow */ - if (vl->incoming_fc_window_size_used + avail >= - vl->incoming_fc_window_size_used) - vl->incoming_fc_window_size = vl->incoming_fc_window_size_used + avail; - else - vl->incoming_fc_window_size = UINT32_MAX; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Updated window to %u/%u kb (%u used) for virtual link to %s!\n", - vl->incoming_fc_window_size, - vl->available_fc_window_size, - vl->incoming_fc_window_size_used, - GNUNET_i2s (&vl->target)); - return; - } - if (vl->n_challenge_time.abs_value_us >= sender_time.abs_value_us) - { - GNUNET_STATISTICS_update (GST_stats, - "# Challenges ignored: sender time not increasing", - 1, - GNUNET_NO); - return; - } - /* new challenge! */ - if (vl->incoming_fc_window_size_used > last_window_consum_limit) - { - /* lying peer: it already used more than it promised it would ever use! */ - GNUNET_break_op (0); - last_window_consum_limit = vl->incoming_fc_window_size_used; - } - /* What remains is at most the difference between what we already processed - and what the sender promises to limit itself to. */ - vl->last_fc_window_size_remaining = - last_window_consum_limit - vl->incoming_fc_window_size_used; - vl->n_challenge = *challenge; - vl->n_challenge_time = sender_time; - vl->incoming_fc_window_size_used = 0; - /* window could have shrunk! */ - if (vl->available_fc_window_size > vl->last_fc_window_size_remaining) - vl->incoming_fc_window_size = - vl->available_fc_window_size - vl->last_fc_window_size_remaining; - else - vl->incoming_fc_window_size = 0; - GNUNET_log ( - GNUNET_ERROR_TYPE_DEBUG, - "New window at %u/%u kb (%u left on previous) for virtual link to %s!\n", - vl->incoming_fc_window_size, - vl->available_fc_window_size, - vl->last_fc_window_size_remaining, - GNUNET_i2s (&vl->target)); -} -#endif - - /** * Closure for #check_known_address. */ @@ -8153,7 +8039,6 @@ handle_validation_response ( n->vl = vl; vl->core_recv_window = RECV_WINDOW_SIZE; vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; - vl->my_challenge = tvr->challenge; vl->visibility_task = GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl); GNUNET_break (GNUNET_YES == @@ -8747,7 +8632,7 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc, relb = GNUNET_NO; /* if we fragment, we never also reliability box */ if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) { - /* FIXME-OPTIMIZE: we could use an optimized, shorter fragmentation + /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation header without the ACK UUID when using a *reliable* channel! */ } real_overhead = overhead + sizeof (struct TransportFragmentBoxMessage); @@ -9440,7 +9325,7 @@ check_connection_quality (void *cls, ctx->num_queues++; if (0 == ctx->k--) ctx->q = q; - /* OPTIMIZE-FIXME: in the future, add reliability / goodput + /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput statistics and consider those as well here? */ if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us) do_inc = GNUNET_YES; -- cgit v1.2.3 From 136adb0f87a645b392fef587a06fc34d4698f3ed Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 18 Jun 2019 11:00:55 +0200 Subject: fix NPEs, off-by-one, etc --- src/include/gnunet_common.h | 6 ++---- src/transport/gnunet-service-tng.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 6b48c81d8..66d0b8ac3 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -507,7 +507,6 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, #define GNUNET_log_from(kind, comp, ...) \ do \ { \ - int log_line = __LINE__; \ static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ if ((GNUNET_EXTRA_LOGGING > 0) || \ ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ @@ -518,7 +517,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, (comp), \ __FILE__, \ __FUNCTION__, \ - log_line); \ + __LINE__); \ if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ { \ GNUNET_log_skip (-1, GNUNET_NO); \ @@ -534,7 +533,6 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, #define GNUNET_log(kind, ...) \ do \ { \ - int log_line = __LINE__; \ static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ if ((GNUNET_EXTRA_LOGGING > 0) || \ ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ @@ -545,7 +543,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, NULL, \ __FILE__, \ __FUNCTION__, \ - log_line); \ + __LINE__); \ if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ { \ GNUNET_log_skip (-1, GNUNET_NO); \ diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index 803a8e518..bae187e7c 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c @@ -3872,11 +3872,12 @@ client_send_response (struct PendingMessage *pm) { struct TransportClient *tc = pm->client; struct VirtualLink *vl = pm->vl; - struct GNUNET_MQ_Envelope *env; - struct SendOkMessage *som; if (NULL != tc) { + struct GNUNET_MQ_Envelope *env; + struct SendOkMessage *som; + env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); som->peer = vl->target; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -4593,11 +4594,11 @@ encapsulate_for_dv (struct DistanceVector *dv, char *path; path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity)); - for (unsigned int i = 0; i <= num_hops; i++) + for (unsigned int j = 0; j <= num_hops; j++) { char *tmp; - GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[i])); + GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[j])); GNUNET_free (path); path = tmp; } @@ -5938,7 +5939,6 @@ handle_reliability_ack (void *cls, { struct CommunicatorMessageContext *cmc = cls; const struct TransportCummulativeAckPayloadP *ack; - struct PendingAcknowledgement *pa; unsigned int n_acks; uint32_t ack_counter; @@ -5947,7 +5947,7 @@ handle_reliability_ack (void *cls, ack = (const struct TransportCummulativeAckPayloadP *) &ra[1]; for (unsigned int i = 0; i < n_acks; i++) { - pa = + struct PendingAcknowledgement *pa = GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value); if (NULL == pa) { @@ -6886,7 +6886,7 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) if (0 == (bi_history & (1 << i))) break; /* i-th hop not bi-directional, stop learning! */ - if (i == nhops) + if (i == nhops - 1) { path[i + 2] = dvl->initiator; } @@ -8629,7 +8629,6 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc, this queue */) ) { frag = GNUNET_YES; - relb = GNUNET_NO; /* if we fragment, we never also reliability box */ if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) { /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation @@ -8829,8 +8828,9 @@ transmit_on_queue (void *cls) "Fragmentation failed queue %s to %s for <%llu>, trying again\n", queue->address, GNUNET_i2s (&n->pid), - pm->logging_uuid); + sc.best->logging_uuid); schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); + return; } } else if (GNUNET_YES == sc.relb) @@ -8844,7 +8844,7 @@ transmit_on_queue (void *cls) "Reliability boxing failed queue %s to %s for <%llu>, trying again\n", queue->address, GNUNET_i2s (&n->pid), - pm->logging_uuid); + sc.best->logging_uuid); schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); return; } -- cgit v1.2.3 From 6e9bb3405a731442274c6c2fe99983f1d413b1f9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 18 Jun 2019 14:24:51 +0200 Subject: fix memory leak --- src/curl/curl.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/curl/curl.c b/src/curl/curl.c index 749094800..020cdc24f 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c @@ -111,7 +111,6 @@ struct GNUNET_CURL_Job * after the job has finished. */ struct curl_slist *job_headers; - }; @@ -161,7 +160,6 @@ struct GNUNET_CURL_Context * Closure for @e cb. */ void *cb_cls; - }; @@ -213,7 +211,8 @@ GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls) * @param header_name name of the header to send. */ void -GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, const char *header_name) +GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, + const char *header_name) { ctx->async_scope_id_header = header_name; } @@ -279,30 +278,26 @@ download_cb (char *bufptr, size_t size, size_t nitems, void *cls) */ struct GNUNET_CURL_Job * GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, - CURL *eh, - const struct curl_slist *job_headers, - GNUNET_CURL_JobCompletionCallback jcc, - void *jcc_cls) + CURL *eh, + const struct curl_slist *job_headers, + GNUNET_CURL_JobCompletionCallback jcc, + void *jcc_cls) { struct GNUNET_CURL_Job *job; struct curl_slist *all_headers = NULL; - for (const struct curl_slist *curr = job_headers; - curr != NULL; + for (const struct curl_slist *curr = job_headers; curr != NULL; curr = curr->next) { - GNUNET_assert ( - NULL != (all_headers = - curl_slist_append (all_headers, curr->data))); + GNUNET_assert (NULL != + (all_headers = curl_slist_append (all_headers, curr->data))); } - for (const struct curl_slist *curr = ctx->common_headers; - curr != NULL; + for (const struct curl_slist *curr = ctx->common_headers; curr != NULL; curr = curr->next) { - GNUNET_assert ( - NULL != (all_headers = - curl_slist_append (all_headers, curr->data))); + GNUNET_assert (NULL != + (all_headers = curl_slist_append (all_headers, curr->data))); } if (NULL != ctx->async_scope_id_header) @@ -313,8 +308,10 @@ GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, if (GNUNET_YES == scope.have_scope) { char *aid_header = NULL; - aid_header = GNUNET_STRINGS_data_to_string_alloc (&scope.scope_id, - sizeof (struct GNUNET_AsyncScopeId)); + aid_header = + GNUNET_STRINGS_data_to_string_alloc (&scope.scope_id, + sizeof ( + struct GNUNET_AsyncScopeId)); GNUNET_assert (NULL != aid_header); GNUNET_assert (NULL != curl_slist_append (all_headers, aid_header)); GNUNET_free (aid_header); @@ -378,7 +375,9 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, GNUNET_CURL_JobCompletionCallback jcc, void *jcc_cls) { + struct GNUNET_CURL_Job *job; struct curl_slist *job_headers = NULL; + if (GNUNET_YES == add_json) { GNUNET_assert ( @@ -386,7 +385,9 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, curl_slist_append (NULL, "Content-Type: application/json"))); } - return GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls); + job = GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls); + curl_slist_free_all (job_headers); + return job; } -- cgit v1.2.3 From 9d0fb05e46e011ecff520eda6d67800f96e66491 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 18 Jun 2019 17:10:22 +0200 Subject: minimize scopes --- src/curl/curl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/curl/curl.c b/src/curl/curl.c index 020cdc24f..a45d0a154 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c @@ -430,7 +430,7 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job) * the JSON we received was malformed). * @return NULL if downloading a JSON reply failed. */ -void * +static void * download_get_result (struct GNUNET_CURL_DownloadBuffer *db, CURL *eh, long *response_code) @@ -523,15 +523,16 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, GNUNET_CURL_ResponseCleaner rc) { CURLMsg *cmsg; - struct GNUNET_CURL_Job *job; int n_running; int n_completed; - long response_code; - void *response; (void) curl_multi_perform (ctx->multi, &n_running); while (NULL != (cmsg = curl_multi_info_read (ctx->multi, &n_completed))) { + struct GNUNET_CURL_Job *job; + long response_code; + void *response; + /* Only documented return value is CURLMSG_DONE */ GNUNET_break (CURLMSG_DONE == cmsg->msg); GNUNET_assert (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, @@ -620,9 +621,8 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, void GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx) { - GNUNET_CURL_perform2 (ctx, - download_get_result, + &download_get_result, (GNUNET_CURL_ResponseCleaner) &json_decref); } -- cgit v1.2.3 From 3267f8b90815984e4cf4acd269fe832f4dbd975e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 19 Jun 2019 08:56:02 +0200 Subject: clarifications in handbook --- doc/handbook/chapters/installation.texi | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/handbook/chapters/installation.texi b/doc/handbook/chapters/installation.texi index c3b9c6cbc..d02fc7f82 100644 --- a/doc/handbook/chapters/installation.texi +++ b/doc/handbook/chapters/installation.texi @@ -1727,12 +1727,19 @@ $ gnunet-namestore -a -e "1 d" -n "homepage" \ At this point we can start the proxy. Simply execute @example -$ gnunet-gns-proxy +$ gnunet-arm -i gns-proxy +@end example + +To run the proxy at all times in the future, you should +change your configuration as follows: + +@example +$ gnunet-config -s gns-proxy -o AUTOSTART -V YES @end example @noindent -Configure your browser to use this SOCKSv5 proxy on port 7777 and visit -this link. +Configure your browser to use this SOCKSv5 proxy using +@code{localhost} on port 7777. If you use @command{Firefox} (or one of its derivatives/forks such as Icecat) you also have to go to @code{about:config} and set the key @code{network.proxy.socks_remote_dns} to @code{true}. -- cgit v1.2.3 From a31cd73472ac1b4c899a6e1d7e53851c20677f7d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 19 Jun 2019 14:42:41 +0200 Subject: fix ftbfs: --- src/curl/curl.c | 10 +++++----- src/curl/curl_reschedule.c | 29 +++++++++++------------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/curl/curl.c b/src/curl/curl.c index a45d0a154..38a1f5fcd 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c @@ -430,10 +430,10 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job) * the JSON we received was malformed). * @return NULL if downloading a JSON reply failed. */ -static void * -download_get_result (struct GNUNET_CURL_DownloadBuffer *db, - CURL *eh, - long *response_code) +void * +GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, + CURL *eh, + long *response_code) { json_t *json; json_error_t error; @@ -622,7 +622,7 @@ void GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx) { GNUNET_CURL_perform2 (ctx, - &download_get_result, + &GNUNET_CURL_download_get_result_, (GNUNET_CURL_ResponseCleaner) &json_decref); } diff --git a/src/curl/curl_reschedule.c b/src/curl/curl_reschedule.c index 1b0f2e440..354ba13df 100644 --- a/src/curl/curl_reschedule.c +++ b/src/curl/curl_reschedule.c @@ -28,9 +28,9 @@ #include "gnunet_util_lib.h" extern void * -download_get_result (struct GNUNET_CURL_DownloadBuffer *db, - CURL *eh, - long *response_code); +GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, + CURL *eh, + long *response_code); /** * Closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). @@ -105,7 +105,7 @@ GNUNET_CURL_gnunet_rc_create (struct GNUNET_CURL_Context *ctx) rc = GNUNET_new (struct GNUNET_CURL_RescheduleContext); rc->ctx = ctx; - rc->parser = &download_get_result; + rc->parser = &GNUNET_CURL_download_get_result_; rc->cleaner = &clean_result; return rc; } @@ -145,9 +145,7 @@ context_task (void *cls) rc->task = NULL; - GNUNET_CURL_perform2 (rc->ctx, - rc->parser, - rc->cleaner); + GNUNET_CURL_perform2 (rc->ctx, rc->parser, rc->cleaner); max_fd = -1; timeout = -1; FD_ZERO (&read_fd_set); @@ -160,18 +158,14 @@ context_task (void *cls) &max_fd, &timeout); if (timeout >= 0) - delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, - timeout); + delay = + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout); else delay = GNUNET_TIME_UNIT_FOREVER_REL; rs = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_copy_native (rs, - &read_fd_set, - max_fd + 1); + GNUNET_NETWORK_fdset_copy_native (rs, &read_fd_set, max_fd + 1); ws = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_copy_native (ws, - &write_fd_set, - max_fd + 1); + GNUNET_NETWORK_fdset_copy_native (ws, &write_fd_set, max_fd + 1); if (NULL == rc->task) rc->task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, @@ -196,12 +190,11 @@ context_task (void *cls) void GNUNET_CURL_gnunet_scheduler_reschedule (void *cls) { - struct GNUNET_CURL_RescheduleContext *rc = *(void**) cls; + struct GNUNET_CURL_RescheduleContext *rc = *(void **) cls; if (NULL != rc->task) GNUNET_SCHEDULER_cancel (rc->task); - rc->task = GNUNET_SCHEDULER_add_now (&context_task, - rc); + rc->task = GNUNET_SCHEDULER_add_now (&context_task, rc); } /* end of curl_reschedule.c */ -- cgit v1.2.3 From 33e87eb7680148006b7c9fc8f89040ad104597ea Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 19 Jun 2019 21:20:39 +0200 Subject: fix socket cmp, fix compiler warnings about unused args --- src/nse/gnunet-nse.c | 38 ++++--- src/nse/nse_api.c | 43 +++---- src/util/crypto_random.c | 84 ++++++-------- src/util/gnunet-scrypt.c | 213 +++++++++++++++++------------------ src/util/gnunet-uri.c | 84 ++++++++------ src/util/test_common_logging_dummy.c | 59 ++++++---- src/util/tun.c | 163 ++++++++++++++------------- 7 files changed, 343 insertions(+), 341 deletions(-) diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c index bf2fe11c3..c8ffa152e 100644 --- a/src/nse/gnunet-nse.c +++ b/src/nse/gnunet-nse.c @@ -46,6 +46,7 @@ static int status; static void do_shutdown (void *cls) { + (void) cls; if (NULL != nse) { GNUNET_NSE_disconnect (nse); @@ -65,12 +66,14 @@ do_shutdown (void *cls) */ static void handle_estimate (void *cls, - struct GNUNET_TIME_Absolute timestamp, + struct GNUNET_TIME_Absolute timestamp, double estimate, - double std_dev) + double std_dev) { + (void) cls; status = 0; - FPRINTF (stdout, "%llu %f %f %f\n", + FPRINTF (stdout, + "%llu %f %f %f\n", (unsigned long long) timestamp.abs_value_us, GNUNET_NSE_log_estimate_to_n (estimate), estimate, @@ -92,11 +95,11 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { - nse = GNUNET_NSE_connect (cfg, - &handle_estimate, - NULL); - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, - NULL); + (void) cls; + (void) args; + (void) cfgfile; + nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); } @@ -106,22 +109,21 @@ run (void *cls, * @return 0 on success */ int -main (int argc, - char *const *argv) +main (int argc, char *const *argv) { static struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; + GNUNET_GETOPT_OPTION_END}; status = 1; if (GNUNET_OK != GNUNET_PROGRAM_run (argc, - argv, - "gnunet-nse", - gettext_noop - ("Show network size estimates from NSE service."), - options, - &run, NULL)) + argv, + "gnunet-nse", + gettext_noop ( + "Show network size estimates from NSE service."), + options, + &run, + NULL)) return 2; return status; } diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c index e9eaada93..259be75ed 100644 --- a/src/nse/nse_api.c +++ b/src/nse/nse_api.c @@ -32,7 +32,7 @@ #include "gnunet_nse_service.h" #include "nse.h" -#define LOG(kind,...) GNUNET_log_from (kind, "nse-api",__VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "nse-api", __VA_ARGS__) /** * Handle for talking with the NSE service. @@ -68,7 +68,6 @@ struct GNUNET_NSE_Handle * Closure to pass to @e recv_cb callback. */ void *recv_cb_cls; - }; @@ -91,17 +90,15 @@ reconnect (void *cls); * @param error error code */ static void -mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_NSE_Handle *h = cls; + (void) error; GNUNET_MQ_destroy (h->mq); h->mq = NULL; - h->reconnect_task - = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, - &reconnect, - h); + h->reconnect_task = + GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); } @@ -114,8 +111,7 @@ mq_error_handler (void *cls, * @param client_msg message received */ static void -handle_estimate (void *cls, - const struct GNUNET_NSE_ClientMessage *client_msg) +handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) { struct GNUNET_NSE_Handle *h = cls; @@ -123,7 +119,7 @@ handle_estimate (void *cls, h->recv_cb (h->recv_cb_cls, GNUNET_TIME_absolute_ntoh (client_msg->timestamp), GNUNET_ntoh_double (client_msg->size_estimate), - GNUNET_ntoh_double (client_msg->std_deviation)); + GNUNET_ntoh_double (client_msg->std_deviation)); } @@ -136,13 +132,12 @@ static void reconnect (void *cls) { struct GNUNET_NSE_Handle *h = cls; - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (estimate, - GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, - struct GNUNET_NSE_ClientMessage, - h), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_fixed_size (estimate, + GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, + struct GNUNET_NSE_ClientMessage, + h), + GNUNET_MQ_handler_end ()}; struct GNUNET_MessageHeader *msg; struct GNUNET_MQ_Envelope *env; @@ -150,17 +145,11 @@ reconnect (void *cls) LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to network size estimation service.\n"); GNUNET_assert (NULL == h->mq); - h->mq = GNUNET_CLIENT_connect (h->cfg, - "nse", - handlers, - &mq_error_handler, - h); + h->mq = GNUNET_CLIENT_connect (h->cfg, "nse", handlers, &mq_error_handler, h); if (NULL == h->mq) return; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_NSE_START); - GNUNET_MQ_send (h->mq, - env); + env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NSE_START); + GNUNET_MQ_send (h->mq, env); } diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 8bb5f0587..71eaab87a 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c @@ -28,22 +28,23 @@ #include "gnunet_crypto_lib.h" #include -#define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__) -#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-random", syscall) +#define LOG_STRERROR(kind, syscall) \ + GNUNET_log_from_strerror (kind, "util-crypto-random", syscall) /* TODO: ndurner, move this to plibc? */ /* The code is derived from glibc, obviously */ -#if !HAVE_RANDOM || !HAVE_SRANDOM +#if ! HAVE_RANDOM || ! HAVE_SRANDOM #ifdef RANDOM #undef RANDOM #endif #ifdef SRANDOM #undef SRANDOM #endif -#define RANDOM() glibc_weak_rand32() -#define SRANDOM(s) glibc_weak_srand32(s) +#define RANDOM() glibc_weak_rand32 () +#define SRANDOM(s) glibc_weak_srand32 (s) #if defined(RAND_MAX) #undef RAND_MAX #endif @@ -105,17 +106,12 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed) * @param length buffer length */ void -GNUNET_CRYPTO_zero_keys (void *buffer, - size_t length) +GNUNET_CRYPTO_zero_keys (void *buffer, size_t length) { #if HAVE_MEMSET_S - memset_s (buffer, - length, - 0, - length); + memset_s (buffer, length, 0, length); #elif HAVE_EXPLICIT_BZERO - explicit_bzero (buffer, - length); + explicit_bzero (buffer, length); #else volatile unsigned char *p = buffer; while (length--) @@ -175,8 +171,7 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, * @return a random value in the interval [0,i[. */ uint32_t -GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, - uint32_t i) +GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i) { #ifdef gcry_fast_random_poll static unsigned int invokeCount; @@ -197,18 +192,17 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, ul = UINT32_MAX - (UINT32_MAX % i); do { - gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t), + gcry_randomize ((unsigned char *) &ret, + sizeof (uint32_t), GCRY_STRONG_RANDOM); - } - while (ret >= ul); + } while (ret >= ul); return ret % i; case GNUNET_CRYPTO_QUALITY_NONCE: ul = UINT32_MAX - (UINT32_MAX % i); do { gcry_create_nonce (&ret, sizeof (ret)); - } - while (ret >= ul); + } while (ret >= ul); return ret % i; case GNUNET_CRYPTO_QUALITY_WEAK: ret = i * get_weak_random (); @@ -231,8 +225,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, * @return the permutation array (allocated from heap) */ unsigned int * -GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, - unsigned int n) +GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n) { unsigned int *ret; unsigned int i; @@ -262,8 +255,7 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, * @return random 64-bit number */ uint64_t -GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, - uint64_t max) +GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) { uint64_t ret; uint64_t ul; @@ -275,18 +267,17 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, ul = UINT64_MAX - (UINT64_MAX % max); do { - gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t), + gcry_randomize ((unsigned char *) &ret, + sizeof (uint64_t), GCRY_STRONG_RANDOM); - } - while (ret >= ul); + } while (ret >= ul); return ret % max; case GNUNET_CRYPTO_QUALITY_NONCE: ul = UINT64_MAX - (UINT64_MAX % max); do { gcry_create_nonce (&ret, sizeof (ret)); - } - while (ret >= ul); + } while (ret >= ul); return ret % max; case GNUNET_CRYPTO_QUALITY_WEAK: @@ -319,6 +310,7 @@ w_malloc (size_t n) static int w_check (const void *p) { + (void) p; return 0; /* not secure memory */ } @@ -326,50 +318,45 @@ w_check (const void *p) /** * Initialize libgcrypt. */ -void __attribute__ ((constructor)) -GNUNET_CRYPTO_random_init () +void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init () { gcry_error_t rc; if (! gcry_check_version (NEED_LIBGCRYPT_VERSION)) { - FPRINTF (stderr, - _("libgcrypt has not the expected version (version %s is required).\n"), - NEED_LIBGCRYPT_VERSION); + FPRINTF ( + stderr, + _ ("libgcrypt has not the expected version (version %s is required).\n"), + NEED_LIBGCRYPT_VERSION); GNUNET_assert (0); } /* set custom allocators */ - gcry_set_allocation_handler (&w_malloc, - &w_malloc, - &w_check, - &realloc, - &free); + gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free); /* Disable use of secure memory */ if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) FPRINTF (stderr, "Failed to set libgcrypt option %s: %s\n", "DISABLE_SECMEM", - gcry_strerror (rc)); + gcry_strerror (rc)); /* Otherwise gnunet-ecc takes forever to complete, besides we are fine with "just" using GCRY_STRONG_RANDOM */ if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) FPRINTF (stderr, - "Failed to set libgcrypt option %s: %s\n", - "ENABLE_QUICK_RANDOM", - gcry_strerror (rc)); + "Failed to set libgcrypt option %s: %s\n", + "ENABLE_QUICK_RANDOM", + gcry_strerror (rc)); gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); gcry_fast_random_poll (); - GNUNET_CRYPTO_seed_weak_random (time (NULL) ^ - GNUNET_CRYPTO_random_u32 - (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); + GNUNET_CRYPTO_seed_weak_random ( + time (NULL) ^ + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); } /** * Nicely shut down libgcrypt. */ -void __attribute__ ((destructor)) -GNUNET_CRYPTO_random_fini () +void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini () { gcry_set_progress_handler (NULL, NULL); #ifdef GCRYCTL_CLOSE_RANDOM_DEVICE @@ -378,5 +365,4 @@ GNUNET_CRYPTO_random_fini () } - /* end of crypto_random.c */ diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index 5e15eb16a..f4149a398 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c @@ -57,15 +57,13 @@ static char *pwfn; static void shutdown_task (void *cls) { - if (sizeof (proof) != - GNUNET_DISK_fn_write (pwfn, - &proof, - sizeof (proof), - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "write", - pwfn); + (void) cls; + if (sizeof (proof) != GNUNET_DISK_fn_write (pwfn, + &proof, + sizeof (proof), + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", pwfn); } @@ -77,17 +75,18 @@ shutdown_task (void *cls) * @param result where to write the resulting hash */ static void -pow_hash (const void *buf, - size_t buf_len, - struct GNUNET_HashCode *result) +pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result) { - GNUNET_break (0 == - gcry_kdf_derive (buf, buf_len, - GCRY_KDF_SCRYPT, - 1 /* subalgo */, - "gnunet-proof-of-work", strlen ("gnunet-proof-of-work"), - 2 /* iterations; keep cost of individual op small */, - sizeof (struct GNUNET_HashCode), result)); + GNUNET_break ( + 0 == gcry_kdf_derive (buf, + buf_len, + GCRY_KDF_SCRYPT, + 1 /* subalgo */, + "gnunet-proof-of-work", + strlen ("gnunet-proof-of-work"), + 2 /* iterations; keep cost of individual op small */, + sizeof (struct GNUNET_HashCode), + result)); } @@ -118,7 +117,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) static void find_proof (void *cls) { - #define ROUND_SIZE 10 +#define ROUND_SIZE 10 uint64_t counter; char buf[sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + sizeof (uint64_t)] GNUNET_ALIGN; @@ -127,12 +126,14 @@ find_proof (void *cls) struct GNUNET_TIME_Absolute timestamp; struct GNUNET_TIME_Relative elapsed; + (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got Proof of Work %llu\n", - (unsigned long long) proof); + "Got Proof of Work %llu\n", + (unsigned long long) proof); proof_task = NULL; - GNUNET_memcpy (&buf[sizeof (uint64_t)], &pub, - sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); + GNUNET_memcpy (&buf[sizeof (uint64_t)], + &pub, + sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); i = 0; counter = proof; timestamp = GNUNET_TIME_absolute_get (); @@ -143,7 +144,8 @@ find_proof (void *cls) if (nse_work_required <= count_leading_zeroes (&result)) { proof = counter; - FPRINTF (stdout, "Proof of work found: %llu!\n", + FPRINTF (stdout, + "Proof of work found: %llu!\n", (unsigned long long) proof); GNUNET_SCHEDULER_shutdown (); return; @@ -159,7 +161,8 @@ find_proof (void *cls) GNUNET_STRINGS_relative_time_to_string (elapsed, 0)); if (proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing proofs currently at %llu\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Testing proofs currently at %llu\n", (unsigned long long) counter); /* remember progress every 100 rounds */ proof = counter; @@ -171,8 +174,9 @@ find_proof (void *cls) } proof_task = GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, - GNUNET_SCHEDULER_PRIORITY_IDLE, - &find_proof, NULL); + GNUNET_SCHEDULER_PRIORITY_IDLE, + &find_proof, + NULL); } @@ -193,54 +197,46 @@ run (void *cls, struct GNUNET_CRYPTO_EddsaPrivateKey *pk; char *pids; + (void) cls; + (void) args; + (void) cfgfile; cfg = config; /* load proof of work */ if (NULL == pwfn) { - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, - "NSE", - "PROOFFILE", - &pwfn)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, + "NSE", + "PROOFFILE", + &pwfn)) { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "NSE", - "PROOFFILE"); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE"); GNUNET_SCHEDULER_shutdown (); return; } } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Proof of Work file: %s\n", - pwfn); - if ( (GNUNET_YES != GNUNET_DISK_file_test (pwfn)) || - (sizeof (proof) != - GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof)))) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Proof of Work file: %s\n", pwfn); + if ((GNUNET_YES != GNUNET_DISK_file_test (pwfn)) || + (sizeof (proof) != GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof)))) proof = 0; /* load private key */ if (NULL == pkfn) { - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, - "PEER", - "PRIVATE_KEY", - &pkfn)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, + "PEER", + "PRIVATE_KEY", + &pkfn)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "PEER", - "PRIVATE_KEY"); + "PRIVATE_KEY"); return; } } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Private Key file: %s\n", - pkfn); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn); if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn))) { - FPRINTF (stderr, - _("Loading hostkey from `%s' failed.\n"), - pkfn); + FPRINTF (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn); GNUNET_free (pkfn); return; } @@ -248,32 +244,27 @@ run (void *cls, GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub); GNUNET_free (pk); pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Peer ID: %s\n", - pids); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", pids); GNUNET_free (pids); /* get target bit amount */ if (0 == nse_work_required) { - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "NSE", - "WORKBITS", - &nse_work_required)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, + "NSE", + "WORKBITS", + &nse_work_required)) { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "NSE", - "WORKBITS"); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS"); GNUNET_SCHEDULER_shutdown (); return; } if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) { GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - "NSE", - "WORKBITS", - _("Value is too large.\n")); + "NSE", + "WORKBITS", + _ ("Value is too large.\n")); GNUNET_SCHEDULER_shutdown (); return; } @@ -283,19 +274,16 @@ run (void *cls, return; } } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Bits: %llu\n", - nse_work_required); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bits: %llu\n", nse_work_required); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Delay between tries: %s\n", GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1)); proof_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, - &find_proof, - NULL); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); + &find_proof, + NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } @@ -307,46 +295,51 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, - char *const *argv) +main (int argc, char *const *argv) { - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_ulong ('b', - "bits", - "BITS", - gettext_noop ("number of bits to require for the proof of work"), - &nse_work_required), - GNUNET_GETOPT_option_filename ('k', - "keyfile", - "FILE", - gettext_noop ("file with private key, otherwise default is used"), - &pkfn), - GNUNET_GETOPT_option_filename ('o', - "outfile", - "FILE", - gettext_noop ("file with proof of work, otherwise default is used"), - &pwfn), - GNUNET_GETOPT_option_relative_time ('t', - "timeout", - "TIME", - gettext_noop ("time to wait between calculations"), - &proof_find_delay), - GNUNET_GETOPT_OPTION_END - }; + struct GNUNET_GETOPT_CommandLineOption options[] = + {GNUNET_GETOPT_option_ulong ( + 'b', + "bits", + "BITS", + gettext_noop ("number of bits to require for the proof of work"), + &nse_work_required), + GNUNET_GETOPT_option_filename ( + 'k', + "keyfile", + "FILE", + gettext_noop ("file with private key, otherwise default is used"), + &pkfn), + GNUNET_GETOPT_option_filename ( + 'o', + "outfile", + "FILE", + gettext_noop ("file with proof of work, otherwise default is used"), + &pwfn), + GNUNET_GETOPT_option_relative_time ('t', + "timeout", + "TIME", + gettext_noop ( + "time to wait between calculations"), + &proof_find_delay), + GNUNET_GETOPT_OPTION_END}; int ret; - if (GNUNET_OK != - GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; - ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, - "gnunet-scrypt [OPTIONS] prooffile", - gettext_noop ("Manipulate GNUnet proof of work files"), - options, - &run, - NULL)) ? 0 : 1; - GNUNET_free ((void*) argv); + ret = + (GNUNET_OK == + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-scrypt [OPTIONS] prooffile", + gettext_noop ("Manipulate GNUnet proof of work files"), + options, + &run, + NULL)) + ? 0 + : 1; + GNUNET_free ((void *) argv); GNUNET_free_non_null (pwfn); return ret; } diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c index 58f9e331c..33ff7b1e6 100644 --- a/src/util/gnunet-uri.c +++ b/src/util/gnunet-uri.c @@ -53,9 +53,9 @@ maint_child_death (void *cls) { enum GNUNET_OS_ProcessStatusType type; - if ( (GNUNET_OK != - GNUNET_OS_process_status (p, &type, &exit_code)) || - (type != GNUNET_OS_PROCESS_EXITED) ) + (void) cls; + if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) || + (type != GNUNET_OS_PROCESS_EXITED)) GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); GNUNET_OS_process_destroy (p); } @@ -70,56 +70,60 @@ maint_child_death (void *cls) * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { const char *uri; const char *slash; char *subsystem; char *program; - struct GNUNET_SCHEDULER_Task * rt; + struct GNUNET_SCHEDULER_Task *rt; + (void) cls; + (void) cfgfile; if (NULL == (uri = args[0])) { - fprintf (stderr, - _("No URI specified on command line\n")); + fprintf (stderr, _ ("No URI specified on command line\n")); return; } if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) { fprintf (stderr, - _("Invalid URI: does not start with `%s'\n"), - "gnunet://"); + _ ("Invalid URI: does not start with `%s'\n"), + "gnunet://"); return; } uri += strlen ("gnunet://"); if (NULL == (slash = strchr (uri, '/'))) { - fprintf (stderr, _("Invalid URI: fails to specify subsystem\n")); + fprintf (stderr, _ ("Invalid URI: fails to specify subsystem\n")); return; } subsystem = GNUNET_strndup (uri, slash - uri); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "uri", - subsystem, - &program)) + GNUNET_CONFIGURATION_get_value_string (cfg, "uri", subsystem, &program)) { - fprintf (stderr, _("No handler known for subsystem `%s'\n"), subsystem); + fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem); GNUNET_free (subsystem); return; } GNUNET_free (subsystem); - rt = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_DISK_pipe_handle (sigpipe, - GNUNET_DISK_PIPE_END_READ), - &maint_child_death, NULL); - p = GNUNET_OS_start_process (GNUNET_NO, 0, - NULL, NULL, NULL, - program, - program, - args[0], - NULL); + rt = GNUNET_SCHEDULER_add_read_file ( + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), + &maint_child_death, + NULL); + p = GNUNET_OS_start_process (GNUNET_NO, + 0, + NULL, + NULL, + NULL, + program, + program, + args[0], + NULL); GNUNET_free (program); if (NULL == p) GNUNET_SCHEDULER_cancel (rt); @@ -134,13 +138,15 @@ static void sighandler_child_death () { static char c; - int old_errno = errno; /* back-up errno */ - - GNUNET_break (1 == - GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle - (sigpipe, GNUNET_DISK_PIPE_END_WRITE), - &c, sizeof (c))); - errno = old_errno; /* restore errno */ + int old_errno = errno; /* back-up errno */ + + GNUNET_break ( + 1 == + GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, + GNUNET_DISK_PIPE_END_WRITE), + &c, + sizeof (c))); + errno = old_errno; /* restore errno */ } @@ -155,8 +161,7 @@ int main (int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; + GNUNET_GETOPT_OPTION_END}; struct GNUNET_SIGNAL_Context *shc_chld; int ret; @@ -166,9 +171,14 @@ main (int argc, char *const *argv) GNUNET_assert (sigpipe != NULL); shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); - ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-uri URI", - gettext_noop ("Perform default-actions for GNUnet URIs"), - options, &run, NULL); + ret = GNUNET_PROGRAM_run (argc, + argv, + "gnunet-uri URI", + gettext_noop ( + "Perform default-actions for GNUnet URIs"), + options, + &run, + NULL); GNUNET_SIGNAL_handler_uninstall (shc_chld); shc_chld = NULL; GNUNET_DISK_pipe_close (sigpipe); diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c index b8f2bef91..5c3709206 100644 --- a/src/util/test_common_logging_dummy.c +++ b/src/util/test_common_logging_dummy.c @@ -35,12 +35,20 @@ * This must be long enough for us to not to mistake skipped log call * on a slow machine for a non-skipped one. */ -#define OUTPUT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000) +#define OUTPUT_DELAY \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000) static void -my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, - const char *date, const char *msg) +my_log (void *ctx, + enum GNUNET_ErrorType kind, + const char *component, + const char *date, + const char *msg) { + (void) ctx; + (void) kind; + (void) component; + (void) date; if (strncmp ("test-common-logging-dummy", component, 25) != 0) return; FPRINTF (stdout, "%s", msg); @@ -48,7 +56,7 @@ my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, } -#if !defined(GNUNET_CULL_LOGGING) +#if ! defined(GNUNET_CULL_LOGGING) static int expensive_func () { @@ -57,27 +65,36 @@ expensive_func () #endif -#define pr(kind,lvl) {\ - struct GNUNET_TIME_Absolute t1, t2;\ - t1 = GNUNET_TIME_absolute_get ();\ - GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\ - t2 = GNUNET_TIME_absolute_get ();\ - printf ("1%s %llu\n", lvl,\ - (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \ -} +#define pr(kind, lvl) \ + { \ + struct GNUNET_TIME_Absolute t1, t2; \ + t1 = GNUNET_TIME_absolute_get (); \ + GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \ + t2 = GNUNET_TIME_absolute_get (); \ + printf ("1%s %llu\n", \ + lvl, \ + (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \ + .rel_value_us); \ + } + +#define pr2(kind, lvl) \ + { \ + struct GNUNET_TIME_Absolute t1, t2; \ + t1 = GNUNET_TIME_absolute_get (); \ + GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \ + t2 = GNUNET_TIME_absolute_get (); \ + printf ("2%s %llu\n", \ + lvl, \ + (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \ + .rel_value_us); \ + } -#define pr2(kind,lvl) {\ - struct GNUNET_TIME_Absolute t1, t2;\ - t1 = GNUNET_TIME_absolute_get ();\ - GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\ - t2 = GNUNET_TIME_absolute_get ();\ - printf ("2%s %llu\n", lvl,\ - (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \ -} int main (int argc, char *argv[]) { + (void) argc; + (void) argv; /* We set up logging with NULL level - will be overrided by * GNUNET_LOG or GNUNET_FORCE_LOG at runtime. */ @@ -97,6 +114,6 @@ main (int argc, char *argv[]) pr2 (GNUNET_ERROR_TYPE_INFO, "INFO"); pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG"); return 0; -} /* end of main */ +} /* end of main */ /* end of test_common_logging_dummy.c */ diff --git a/src/util/tun.c b/src/util/tun.c index 97fbaa83b..e3643d0c6 100644 --- a/src/util/tun.c +++ b/src/util/tun.c @@ -44,24 +44,27 @@ */ void GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, - uint8_t protocol, - uint16_t payload_length, - const struct in_addr *src, - const struct in_addr *dst) + uint8_t protocol, + uint16_t payload_length, + const struct in_addr *src, + const struct in_addr *dst) { GNUNET_assert (20 == sizeof (struct GNUNET_TUN_IPv4Header)); - GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header)); + GNUNET_assert (payload_length <= + UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header)); memset (ip, 0, sizeof (struct GNUNET_TUN_IPv4Header)); - ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; + ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; ip->version = 4; - ip->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length); - ip->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - 65536); + ip->total_length = + htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length); + ip->identification = + (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 65536); ip->ttl = FRESH_TTL; ip->protocol = protocol; ip->source_address = *src; ip->destination_address = *dst; - ip->checksum = GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header)); + ip->checksum = + GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header)); } @@ -76,13 +79,14 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, */ void GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, - uint8_t protocol, - uint16_t payload_length, - const struct in6_addr *src, - const struct in6_addr *dst) + uint8_t protocol, + uint16_t payload_length, + const struct in6_addr *src, + const struct in6_addr *dst) { GNUNET_assert (40 == sizeof (struct GNUNET_TUN_IPv6Header)); - GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header)); + GNUNET_assert (payload_length <= + UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header)); memset (ip, 0, sizeof (struct GNUNET_TUN_IPv6Header)); ip->version = 6; ip->next_header = protocol; @@ -103,27 +107,29 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, */ void GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, - struct GNUNET_TUN_TcpHeader *tcp, - const void *payload, - uint16_t payload_length) + struct GNUNET_TUN_TcpHeader *tcp, + const void *payload, + uint16_t payload_length) { uint32_t sum; uint16_t tmp; GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); - GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_TcpHeader) == - ntohs (ip->total_length)); + GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + + sizeof (struct GNUNET_TUN_TcpHeader) == + ntohs (ip->total_length)); GNUNET_assert (IPPROTO_TCP == ip->protocol); tcp->crc = 0; sum = GNUNET_CRYPTO_crc16_step (0, - &ip->source_address, - sizeof (struct in_addr) * 2); + &ip->source_address, + sizeof (struct in_addr) * 2); tmp = htons (IPPROTO_TCP); sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); tmp = htons (payload_length + sizeof (struct GNUNET_TUN_TcpHeader)); sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); - sum = GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader)); + sum = + GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader)); sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); } @@ -139,25 +145,27 @@ GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, */ void GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, - struct GNUNET_TUN_TcpHeader *tcp, - const void *payload, - uint16_t payload_length) + struct GNUNET_TUN_TcpHeader *tcp, + const void *payload, + uint16_t payload_length) { uint32_t sum; uint32_t tmp; GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_TcpHeader) == - ntohs (ip->payload_length)); + ntohs (ip->payload_length)); GNUNET_assert (IPPROTO_TCP == ip->next_header); tcp->crc = 0; - sum = GNUNET_CRYPTO_crc16_step (0, &ip->source_address, 2 * sizeof (struct in6_addr)); + sum = GNUNET_CRYPTO_crc16_step (0, + &ip->source_address, + 2 * sizeof (struct in6_addr)); tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length); sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); tmp = htonl (IPPROTO_TCP); sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); - sum = GNUNET_CRYPTO_crc16_step (sum, tcp, - sizeof (struct GNUNET_TUN_TcpHeader)); + sum = + GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader)); sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); } @@ -173,36 +181,31 @@ GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, */ void GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, - struct GNUNET_TUN_UdpHeader *udp, - const void *payload, - uint16_t payload_length) + struct GNUNET_TUN_UdpHeader *udp, + const void *payload, + uint16_t payload_length) { uint32_t sum; uint16_t tmp; GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); - GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_UdpHeader) == - ntohs (ip->total_length)); + GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + + sizeof (struct GNUNET_TUN_UdpHeader) == + ntohs (ip->total_length)); GNUNET_assert (IPPROTO_UDP == ip->protocol); - udp->crc = 0; /* technically optional, but we calculate it anyway, just to be sure */ + udp->crc = + 0; /* technically optional, but we calculate it anyway, just to be sure */ sum = GNUNET_CRYPTO_crc16_step (0, - &ip->source_address, - sizeof (struct in_addr) * 2); + &ip->source_address, + sizeof (struct in_addr) * 2); tmp = htons (IPPROTO_UDP); - sum = GNUNET_CRYPTO_crc16_step (sum, - &tmp, - sizeof (uint16_t)); + sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); - sum = GNUNET_CRYPTO_crc16_step (sum, - &tmp, - sizeof (uint16_t)); - sum = GNUNET_CRYPTO_crc16_step (sum, - udp, - sizeof (struct GNUNET_TUN_UdpHeader)); - sum = GNUNET_CRYPTO_crc16_step (sum, - payload, - payload_length); + sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); + sum = + GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader)); + sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); udp->crc = GNUNET_CRYPTO_crc16_finish (sum); } @@ -217,28 +220,30 @@ GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, */ void GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, - struct GNUNET_TUN_UdpHeader *udp, - const void *payload, - uint16_t payload_length) + struct GNUNET_TUN_UdpHeader *udp, + const void *payload, + uint16_t payload_length) { uint32_t sum; uint32_t tmp; GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == - ntohs (ip->payload_length)); + ntohs (ip->payload_length)); GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == - ntohs (udp->len)); + ntohs (udp->len)); GNUNET_assert (IPPROTO_UDP == ip->next_header); udp->crc = 0; sum = GNUNET_CRYPTO_crc16_step (0, - &ip->source_address, - sizeof (struct in6_addr) * 2); - tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); /* aka udp->len */ + &ip->source_address, + sizeof (struct in6_addr) * 2); + tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + + payload_length); /* aka udp->len */ sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); tmp = htons (ip->next_header); sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); - sum = GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader)); + sum = + GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader)); sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); udp->crc = GNUNET_CRYPTO_crc16_finish (sum); } @@ -253,16 +258,15 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, */ void GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, - const void *payload, - uint16_t payload_length) + const void *payload, + uint16_t payload_length) { uint32_t sum; GNUNET_assert (8 == sizeof (struct GNUNET_TUN_IcmpHeader)); icmp->crc = 0; - sum = GNUNET_CRYPTO_crc16_step (0, - icmp, - sizeof (struct GNUNET_TUN_IcmpHeader)); + sum = + GNUNET_CRYPTO_crc16_step (0, icmp, sizeof (struct GNUNET_TUN_IcmpHeader)); sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); icmp->crc = GNUNET_CRYPTO_crc16_finish (sum); } @@ -286,21 +290,22 @@ GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa, switch (sa->sa_family) { - case AF_INET: - { - const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa; - const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb; - return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr); - } - case AF_INET6: - { - const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa; - const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb; - - return (0 == memcmp(&sa6->sin6_addr, - &sb6->sin6_addr, - sizeof (struct in6_addr))); - } + case AF_INET: { + const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa; + const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb; + if ((include_port) && (sa4->sin_port != sb4->sin_port)) + return GNUNET_NO; + return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr); + } + case AF_INET6: { + const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa; + const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb; + + if ((include_port) && (sa6->sin6_port != sb6->sin6_port)) + return GNUNET_NO; + return ( + 0 == memcmp (&sa6->sin6_addr, &sb6->sin6_addr, sizeof (struct in6_addr))); + } default: GNUNET_break (0); return GNUNET_SYSERR; -- cgit v1.2.3 From 9baf882d7642f8aeac734ffd16c8e94bd409a41b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 19 Jun 2019 21:22:43 +0200 Subject: fix socket cmp, fix compiler warnings about unused args --- src/arm/arm_api.c | 287 +++++++++++++++++----------------------------- src/arm/arm_monitor_api.c | 55 ++++----- src/arm/mockup-service.c | 49 ++++---- 3 files changed, 154 insertions(+), 237 deletions(-) diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index c8103c877..bf0acbcb9 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c @@ -30,7 +30,7 @@ #include "gnunet_protocols.h" #include "arm.h" -#define LOG(kind,...) GNUNET_log_from (kind, "arm-api",__VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "arm-api", __VA_ARGS__) /** @@ -156,7 +156,6 @@ struct GNUNET_ARM_Handle * Have we detected that ARM is up? */ int currently_up; - }; @@ -204,27 +203,19 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h) h->currently_up = GNUNET_NO; GNUNET_assert (NULL == h->reconnect_task); h->reconnect_task = - GNUNET_SCHEDULER_add_delayed (h->retry_backoff, - &reconnect_arm_task, - h); + GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h); while (NULL != (op = h->operation_pending_head)) { if (NULL != op->result_cont) - op->result_cont (op->cont_cls, - GNUNET_ARM_REQUEST_DISCONNECTED, - 0); + op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); if (NULL != op->list_cont) - op->list_cont (op->cont_cls, - GNUNET_ARM_REQUEST_DISCONNECTED, - 0, - NULL); + op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); GNUNET_ARM_operation_cancel (op); } GNUNET_assert (NULL == h->operation_pending_head); h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); if (NULL != h->conn_status) - h->conn_status (h->conn_status_cls, - GNUNET_NO); + h->conn_status (h->conn_status_cls, GNUNET_NO); } @@ -236,12 +227,12 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h) * @return NULL if not found */ static struct GNUNET_ARM_Operation * -find_op_by_id (struct GNUNET_ARM_Handle *h, - uint64_t id) +find_op_by_id (struct GNUNET_ARM_Handle *h, uint64_t id) { struct GNUNET_ARM_Operation *result; - for (result = h->operation_pending_head; NULL != result; result = result->next) + for (result = h->operation_pending_head; NULL != result; + result = result->next) if (id == result->id) return result; return NULL; @@ -255,8 +246,7 @@ find_op_by_id (struct GNUNET_ARM_Handle *h, * @param res the message received from the arm service */ static void -handle_arm_result (void *cls, - const struct GNUNET_ARM_ResultMessage *res) +handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res) { struct GNUNET_ARM_Handle *h = cls; struct GNUNET_ARM_Operation *op; @@ -266,8 +256,7 @@ handle_arm_result (void *cls, void *result_cont_cls; id = GNUNET_ntohll (res->arm_msg.request_id); - op = find_op_by_id (h, - id); + op = find_op_by_id (h, id); if (NULL == op) { LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -277,8 +266,7 @@ handle_arm_result (void *cls, } result = (enum GNUNET_ARM_Result) ntohl (res->result); - if ( (GNUNET_YES == op->is_arm_stop) && - (GNUNET_ARM_RESULT_STOPPING == result) ) + if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result)) { /* special case: if we are stopping 'gnunet-service-arm', we do not just wait for the result message, but also wait for the service to close @@ -289,8 +277,8 @@ handle_arm_result (void *cls, { GNUNET_break (0); op->result_cont (h->thm->cont_cls, - GNUNET_ARM_REQUEST_SENT_OK, - GNUNET_ARM_RESULT_IS_NOT_KNOWN); + GNUNET_ARM_REQUEST_SENT_OK, + GNUNET_ARM_RESULT_IS_NOT_KNOWN); GNUNET_free (h->thm); } GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, @@ -303,9 +291,7 @@ handle_arm_result (void *cls, result_cont_cls = op->cont_cls; GNUNET_ARM_operation_cancel (op); if (NULL != result_cont) - result_cont (result_cont_cls, - GNUNET_ARM_REQUEST_SENT_OK, - result); + result_cont (result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result); } @@ -325,6 +311,7 @@ check_arm_list_result (void *cls, uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres); uint16_t size_check; + (void) cls; size_check = 0; for (unsigned int i = 0; i < rcount; i++) { @@ -361,8 +348,7 @@ handle_arm_list_result (void *cls, uint64_t id; id = GNUNET_ntohll (lres->arm_msg.request_id); - op = find_op_by_id (h, - id); + op = find_op_by_id (h, id); if (NULL == op) { LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -373,9 +359,7 @@ handle_arm_list_result (void *cls, size_check = 0; for (unsigned int i = 0; i < rcount; i++) { - const char *end = memchr (pos, - 0, - msize - size_check); + const char *end = memchr (pos, 0, msize - size_check); /* Assert, as this was already checked in #check_arm_list_result() */ GNUNET_assert (NULL != end); @@ -384,10 +368,7 @@ handle_arm_list_result (void *cls, pos = end + 1; } if (NULL != op->list_cont) - op->list_cont (op->cont_cls, - GNUNET_ARM_REQUEST_SENT_OK, - rcount, - list); + op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list); GNUNET_ARM_operation_cancel (op); } @@ -399,19 +380,17 @@ handle_arm_list_result (void *cls, * @param msg message received */ static void -handle_confirm (void *cls, - const struct GNUNET_MessageHeader *msg) +handle_confirm (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_ARM_Handle *h = cls; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Got confirmation from ARM that we are up!\n"); + (void) msg; + LOG (GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n"); if (GNUNET_NO == h->currently_up) { h->currently_up = GNUNET_YES; if (NULL != h->conn_status) - h->conn_status (h->conn_status_cls, - GNUNET_YES); + h->conn_status (h->conn_status_cls, GNUNET_YES); } } @@ -425,19 +404,19 @@ handle_confirm (void *cls, * @param error error code */ static void -mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_ARM_Handle *h = cls; struct GNUNET_ARM_Operation *op; + (void) error; h->currently_up = GNUNET_NO; if (NULL != (op = h->thm)) { h->thm = NULL; op->result_cont (op->cont_cls, - GNUNET_ARM_REQUEST_SENT_OK, - GNUNET_ARM_RESULT_STOPPED); + GNUNET_ARM_REQUEST_SENT_OK, + GNUNET_ARM_RESULT_STOPPED); GNUNET_free (op); } reconnect_arm_later (h); @@ -453,47 +432,37 @@ mq_error_handler (void *cls, static int reconnect_arm (struct GNUNET_ARM_Handle *h) { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (arm_result, - GNUNET_MESSAGE_TYPE_ARM_RESULT, - struct GNUNET_ARM_ResultMessage, - h), - GNUNET_MQ_hd_var_size (arm_list_result, - GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, - struct GNUNET_ARM_ListResultMessage, - h), - GNUNET_MQ_hd_fixed_size (confirm, - GNUNET_MESSAGE_TYPE_ARM_TEST, - struct GNUNET_MessageHeader, - h), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_fixed_size (arm_result, + GNUNET_MESSAGE_TYPE_ARM_RESULT, + struct GNUNET_ARM_ResultMessage, + h), + GNUNET_MQ_hd_var_size (arm_list_result, + GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, + struct GNUNET_ARM_ListResultMessage, + h), + GNUNET_MQ_hd_fixed_size (confirm, + GNUNET_MESSAGE_TYPE_ARM_TEST, + struct GNUNET_MessageHeader, + h), + GNUNET_MQ_handler_end ()}; struct GNUNET_MessageHeader *test; struct GNUNET_MQ_Envelope *env; if (NULL != h->mq) return GNUNET_OK; GNUNET_assert (GNUNET_NO == h->currently_up); - h->mq = GNUNET_CLIENT_connect (h->cfg, - "arm", - handlers, - &mq_error_handler, - h); + h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); if (NULL == h->mq) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "GNUNET_CLIENT_connect returned NULL\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n"); if (NULL != h->conn_status) - h->conn_status (h->conn_status_cls, - GNUNET_SYSERR); + h->conn_status (h->conn_status_cls, GNUNET_SYSERR); return GNUNET_SYSERR; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending TEST message to ARM\n"); - env = GNUNET_MQ_msg (test, - GNUNET_MESSAGE_TYPE_ARM_TEST); - GNUNET_MQ_send (h->mq, - env); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n"); + env = GNUNET_MQ_msg (test, GNUNET_MESSAGE_TYPE_ARM_TEST); + GNUNET_MQ_send (h->mq, env); return GNUNET_OK; } @@ -512,7 +481,7 @@ reconnect_arm (struct GNUNET_ARM_Handle *h) struct GNUNET_ARM_Handle * GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ARM_ConnectionStatusCallback conn_status, - void *conn_status_cls) + void *conn_status_cls) { struct GNUNET_ARM_Handle *h; @@ -539,22 +508,16 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h) { struct GNUNET_ARM_Operation *op; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting from ARM service\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); while (NULL != (op = h->operation_pending_head)) { GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, h->operation_pending_tail, op); if (NULL != op->result_cont) - op->result_cont (op->cont_cls, - GNUNET_ARM_REQUEST_DISCONNECTED, - 0); + op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); if (NULL != op->list_cont) - op->list_cont (op->cont_cls, - GNUNET_ARM_REQUEST_DISCONNECTED, - 0, - NULL); + op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); if (NULL != op->async) { GNUNET_SCHEDULER_cancel (op->async); @@ -596,60 +559,43 @@ start_arm_service (struct GNUNET_ARM_Handle *h, char *loprefix; char *lopostfix; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (h->cfg, - "arm", - "PREFIX", - &loprefix)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, + "arm", + "PREFIX", + &loprefix)) loprefix = GNUNET_strdup (""); else - loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, - loprefix); - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (h->cfg, - "arm", - "OPTIONS", - &lopostfix)) + loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, + "arm", + "OPTIONS", + &lopostfix)) lopostfix = GNUNET_strdup (""); else - lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, - lopostfix); + lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, lopostfix); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (h->cfg, - "arm", - "BINARY", - &cbinary)) + GNUNET_CONFIGURATION_get_value_string (h->cfg, "arm", "BINARY", &cbinary)) { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, - "arm", - "BINARY"); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); GNUNET_free (loprefix); GNUNET_free (lopostfix); return GNUNET_ARM_RESULT_IS_NOT_KNOWN; } - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (h->cfg, - "arm", - "CONFIG", - &config)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, + "arm", + "CONFIG", + &config)) config = NULL; binary = GNUNET_OS_get_libexec_binary_path (cbinary); - GNUNET_asprintf ("edbinary, - "\"%s\"", - binary); + GNUNET_asprintf ("edbinary, "\"%s\"", binary); GNUNET_free (cbinary); - if ( (GNUNET_YES == - GNUNET_CONFIGURATION_have_value (h->cfg, - "TESTING", - "WEAKRANDOM")) && - (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno (h->cfg, - "TESTING", - "WEAKRANDOM")) && - (GNUNET_NO == - GNUNET_CONFIGURATION_have_value (h->cfg, - "TESTING", - "HOSTFILE"))) + if ((GNUNET_YES == + GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "WEAKRANDOM")) && + (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (h->cfg, + "TESTING", + "WEAKRANDOM")) && + (GNUNET_NO == + GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "HOSTFILE"))) { /* Means we are ONLY running locally */ /* we're clearly running a test, don't daemonize */ @@ -668,7 +614,8 @@ start_arm_service (struct GNUNET_ARM_Handle *h, NULL, loprefix, quotedbinary, - "-c", config, + "-c", + config, /* no daemonization! */ lopostfix, NULL); @@ -683,14 +630,15 @@ start_arm_service (struct GNUNET_ARM_Handle *h, quotedbinary, "-d", /* do daemonize */ lopostfix, - NULL); + NULL); else proc = GNUNET_OS_start_process_s (GNUNET_NO, std_inheritance, NULL, loprefix, quotedbinary, - "-c", config, + "-c", + config, "-d", /* do daemonize */ lopostfix, NULL); @@ -744,7 +692,7 @@ static struct GNUNET_ARM_Operation * change_service (struct GNUNET_ARM_Handle *h, const char *service_name, GNUNET_ARM_ResultCallback cb, - void *cb_cls, + void *cb_cls, uint16_t type) { struct GNUNET_ARM_Operation *op; @@ -753,8 +701,7 @@ change_service (struct GNUNET_ARM_Handle *h, struct GNUNET_ARM_Message *msg; slen = strlen (service_name) + 1; - if (slen + sizeof (struct GNUNET_ARM_Message) >= - GNUNET_MAX_MESSAGE_SIZE) + if (slen + sizeof (struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) { GNUNET_break (0); return NULL; @@ -769,16 +716,11 @@ change_service (struct GNUNET_ARM_Handle *h, GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, h->operation_pending_tail, op); - env = GNUNET_MQ_msg_extra (msg, - slen, - type); + env = GNUNET_MQ_msg_extra (msg, slen, type); msg->reserved = htonl (0); msg->request_id = GNUNET_htonll (op->id); - GNUNET_memcpy (&msg[1], - service_name, - slen); - GNUNET_MQ_send (h->mq, - env); + GNUNET_memcpy (&msg[1], service_name, slen); + GNUNET_MQ_send (h->mq, env); return op; } @@ -802,10 +744,8 @@ notify_running (void *cls) op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, GNUNET_ARM_RESULT_IS_STARTED_ALREADY); - if ( (GNUNET_YES == h->currently_up) && - (NULL != h->conn_status) ) - h->conn_status (h->conn_status_cls, - GNUNET_YES); + if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status)) + h->conn_status (h->conn_status_cls, GNUNET_YES); GNUNET_free (op); } @@ -846,20 +786,18 @@ notify_starting (void *cls) * @return handle for the operation, NULL on error */ struct GNUNET_ARM_Operation * -GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, - const char *service_name, - enum GNUNET_OS_InheritStdioFlags std_inheritance, - GNUNET_ARM_ResultCallback cont, - void *cont_cls) +GNUNET_ARM_request_service_start ( + struct GNUNET_ARM_Handle *h, + const char *service_name, + enum GNUNET_OS_InheritStdioFlags std_inheritance, + GNUNET_ARM_ResultCallback cont, + void *cont_cls) { struct GNUNET_ARM_Operation *op; enum GNUNET_ARM_Result ret; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Starting service `%s'\n", - service_name); - if (0 != strcasecmp ("arm", - service_name)) + LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name); + if (0 != strcasecmp ("arm", service_name)) return change_service (h, service_name, cont, @@ -874,8 +812,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, */ if (GNUNET_YES == h->currently_up) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "ARM is already running\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n"); op = GNUNET_new (struct GNUNET_ARM_Operation); op->h = h; op->result_cont = cont; @@ -883,8 +820,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, h->operation_pending_tail, op); - op->async = GNUNET_SCHEDULER_add_now (¬ify_running, - op); + op->async = GNUNET_SCHEDULER_add_now (¬ify_running, op); return op; } /* This is an inherently uncertain choice, as it is of course @@ -893,10 +829,8 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, are unlikely to hammer 'gnunet-arm -s' on a busy system, the above check should catch 99.99% of the cases where ARM is already running. */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Starting ARM service\n"); - ret = start_arm_service (h, - std_inheritance); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); + ret = start_arm_service (h, std_inheritance); if (GNUNET_ARM_RESULT_STARTING == ret) reconnect_arm (h); op = GNUNET_new (struct GNUNET_ARM_Operation); @@ -907,8 +841,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, h->operation_pending_tail, op); op->starting_ret = ret; - op->async = GNUNET_SCHEDULER_add_now (¬ify_starting, - op); + op->async = GNUNET_SCHEDULER_add_now (¬ify_starting, op); return op; } @@ -929,15 +862,13 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, */ struct GNUNET_ARM_Operation * GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, - const char *service_name, - GNUNET_ARM_ResultCallback cont, - void *cont_cls) + const char *service_name, + GNUNET_ARM_ResultCallback cont, + void *cont_cls) { struct GNUNET_ARM_Operation *op; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Stopping service `%s'\n", - service_name); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name); op = change_service (h, service_name, cont, @@ -947,8 +878,7 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, return NULL; /* If the service is ARM, set a flag as we will use MQ errors to detect that the process is really gone. */ - if (0 == strcasecmp (service_name, - "arm")) + if (0 == strcasecmp (service_name, "arm")) op->is_arm_stop = GNUNET_YES; return op; } @@ -971,8 +901,7 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, struct GNUNET_MQ_Envelope *env; struct GNUNET_ARM_Message *msg; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Requesting LIST from ARM service\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n"); if (0 == h->request_id_counter) h->request_id_counter++; op = GNUNET_new (struct GNUNET_ARM_Operation); @@ -983,12 +912,10 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, h->operation_pending_tail, op); - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_ARM_LIST); + env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_LIST); msg->reserved = htonl (0); msg->request_id = GNUNET_htonll (op->id); - GNUNET_MQ_send (h->mq, - env); + GNUNET_MQ_send (h->mq, env); return op; } diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c index 15f91c036..55b12240f 100644 --- a/src/arm/arm_monitor_api.c +++ b/src/arm/arm_monitor_api.c @@ -32,7 +32,7 @@ #define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) -#define LOG(kind,...) GNUNET_log_from (kind, "arm-monitor-api",__VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__) /** * Handle for interacting with ARM. @@ -69,7 +69,6 @@ struct GNUNET_ARM_MonitorHandle * Closure for @e service_status. */ void *service_status_cls; - }; @@ -115,9 +114,9 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) h->mq = NULL; } GNUNET_assert (NULL == h->reconnect_task); - h->reconnect_task - = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, - &reconnect_arm_monitor_task, h); + h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, + &reconnect_arm_monitor_task, + h); h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); } @@ -130,14 +129,14 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) * @return #GNUNET_OK if the message is well-formed */ static int -check_monitor_notify (void *cls, - const struct GNUNET_ARM_StatusMessage *msg) +check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg) { - size_t sl = ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage); + size_t sl = + ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage); const char *name = (const char *) &msg[1]; - if ( (0 == sl) || - ('\0' != name[sl-1]) ) + (void) cls; + if ((0 == sl) || ('\0' != name[sl - 1])) { GNUNET_break (0); return GNUNET_SYSERR; @@ -153,8 +152,7 @@ check_monitor_notify (void *cls, * @param res the message received from the arm service */ static void -handle_monitor_notify (void *cls, - const struct GNUNET_ARM_StatusMessage *res) +handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res) { struct GNUNET_ARM_MonitorHandle *h = cls; enum GNUNET_ARM_ServiceStatus status; @@ -165,9 +163,7 @@ handle_monitor_notify (void *cls, (const char *) &res[1], (int) status); if (NULL != h->service_status) - h->service_status (h->service_status_cls, - (const char *) &res[1], - status); + h->service_status (h->service_status_cls, (const char *) &res[1], status); } @@ -180,11 +176,11 @@ handle_monitor_notify (void *cls, * @param error error code */ static void -mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_ARM_MonitorHandle *h = cls; + (void) error; reconnect_arm_monitor_later (h); } @@ -198,22 +194,17 @@ mq_error_handler (void *cls, static int reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (monitor_notify, - GNUNET_MESSAGE_TYPE_ARM_STATUS, - struct GNUNET_ARM_StatusMessage, - h), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_var_size (monitor_notify, + GNUNET_MESSAGE_TYPE_ARM_STATUS, + struct GNUNET_ARM_StatusMessage, + h), + GNUNET_MQ_handler_end ()}; struct GNUNET_MessageHeader *msg; struct GNUNET_MQ_Envelope *env; GNUNET_assert (NULL == h->mq); - h->mq = GNUNET_CLIENT_connect (h->cfg, - "arm", - handlers, - &mq_error_handler, - h); + h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); if (NULL == h->mq) { if (NULL != h->service_status) @@ -222,10 +213,8 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) GNUNET_ARM_SERVICE_STOPPED); return GNUNET_SYSERR; } - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_ARM_MONITOR); - GNUNET_MQ_send (h->mq, - env); + env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); + GNUNET_MQ_send (h->mq, env); return GNUNET_OK; } diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c index c9f00b5dd..667556314 100644 --- a/src/arm/mockup-service.c +++ b/src/arm/mockup-service.c @@ -33,13 +33,13 @@ static int special_ret = 0; * @param message the actual message */ static void -handle_stop (void *cls, - const struct GNUNET_MessageHeader *message) +handle_stop (void *cls, const struct GNUNET_MessageHeader *message) { struct GNUNET_SERVICE_Client *client = cls; + (void) message; GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Initiating shutdown as requested by client.\n")); + _ ("Initiating shutdown as requested by client.\n")); GNUNET_SERVICE_client_persist (client); GNUNET_SCHEDULER_shutdown (); /* ARM won't exponentially increase restart delay if we @@ -59,9 +59,11 @@ handle_stop (void *cls, */ static void * client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *c, - struct GNUNET_MQ_Handle *mq) + struct GNUNET_SERVICE_Client *c, + struct GNUNET_MQ_Handle *mq) { + (void) cls; + (void) mq; return c; } @@ -75,9 +77,10 @@ client_connect_cb (void *cls, */ static void client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *c, - void *internal_cls) + struct GNUNET_SERVICE_Client *c, + void *internal_cls) { + (void) cls; GNUNET_assert (c == internal_cls); } @@ -87,6 +90,9 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service) { + (void) cls; + (void) cfg; + (void) service; /* nothing to do */ } @@ -94,25 +100,20 @@ run (void *cls, /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN -("do-nothing", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_fixed_size (stop, - GNUNET_MESSAGE_TYPE_ARM_STOP, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_handler_end ()); +GNUNET_SERVICE_MAIN ("do-nothing", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_fixed_size (stop, + GNUNET_MESSAGE_TYPE_ARM_STOP, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_handler_end ()); /** * MINIMIZE heap size (way below 128k) since this process doesn't need much. */ -void __attribute__ ((destructor)) -GNUNET_mockup_done () -{ - _exit (special_ret); -} +void __attribute__ ((destructor)) GNUNET_mockup_done () { _exit (special_ret); } -- cgit v1.2.3 From 2111b3716776f2a1e6e6b38888c8dea42907c09d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 19 Jun 2019 21:25:50 +0200 Subject: fix compiler warnings about unused args --- src/core/core_api.c | 5 ++- src/core/core_api_monitor_peers.c | 34 +++++++---------- src/core/gnunet-core.c | 80 ++++++++++++++++++++------------------- src/nse/gnunet-service-nse.c | 21 +++++++++- 4 files changed, 78 insertions(+), 62 deletions(-) diff --git a/src/core/core_api.c b/src/core/core_api.c index 6381d9097..223677a5b 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -341,6 +341,7 @@ core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct PeerRecord *pr = impl_state; + (void) mq; GNUNET_assert (NULL != pr->env); GNUNET_MQ_discard (pr->env); pr->env = NULL; @@ -359,7 +360,8 @@ static void core_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { /* struct PeerRecord *pr = cls; */ - + (void) cls; + (void) error; GNUNET_break_op (0); } @@ -530,6 +532,7 @@ check_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm) uint16_t msize; const struct GNUNET_MessageHeader *em; + (void) cls; msize = ntohs (ntm->header.size) - sizeof (struct NotifyTrafficMessage); if (msize < sizeof (struct GNUNET_MessageHeader)) { diff --git a/src/core/core_api_monitor_peers.c b/src/core/core_api_monitor_peers.c index 0ebb94d7b..165f741d2 100644 --- a/src/core/core_api_monitor_peers.c +++ b/src/core/core_api_monitor_peers.c @@ -54,7 +54,6 @@ struct GNUNET_CORE_MonitorHandle * Closure for @e peer_cb. */ void *peer_cb_cls; - }; @@ -77,11 +76,11 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh); * @param error error code */ static void -handle_mq_error (void *cls, - enum GNUNET_MQ_Error error) +handle_mq_error (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_CORE_MonitorHandle *mh = cls; + (void) error; reconnect (mh); } @@ -93,8 +92,7 @@ handle_mq_error (void *cls, * @param mon_message monitor message */ static void -handle_receive_info (void *cls, - const struct MonitorNotifyMessage *mon_message) +handle_receive_info (void *cls, const struct MonitorNotifyMessage *mon_message) { struct GNUNET_CORE_MonitorHandle *mh = cls; @@ -114,24 +112,20 @@ handle_receive_info (void *cls, static void reconnect (struct GNUNET_CORE_MonitorHandle *mh) { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (receive_info, - GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, - struct MonitorNotifyMessage, - mh), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_fixed_size (receive_info, + GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, + struct MonitorNotifyMessage, + mh), + GNUNET_MQ_handler_end ()}; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; if (NULL != mh->mq) GNUNET_MQ_destroy (mh->mq); /* FIXME: use backoff? */ - mh->mq = GNUNET_CLIENT_connect (mh->cfg, - "core", - handlers, - &handle_mq_error, - mh); + mh->mq = + GNUNET_CLIENT_connect (mh->cfg, "core", handlers, &handle_mq_error, mh); if (NULL == mh->mq) return; /* notify callback about reconnect */ @@ -140,10 +134,8 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh) NULL, GNUNET_CORE_KX_CORE_DISCONNECT, GNUNET_TIME_UNIT_FOREVER_ABS); - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS); - GNUNET_MQ_send (mh->mq, - env); + env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS); + GNUNET_MQ_send (mh->mq, env); } diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c index 7180754a9..674da705a 100644 --- a/src/core/gnunet-core.c +++ b/src/core/gnunet-core.c @@ -48,6 +48,7 @@ static struct GNUNET_CORE_MonitorHandle *mh; static void shutdown_task (void *cls) { + (void) cls; if (NULL != mh) { GNUNET_CORE_monitor_stop (mh); @@ -71,13 +72,13 @@ monitor_cb (void *cls, enum GNUNET_CORE_KxState state, struct GNUNET_TIME_Absolute timeout) { - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); const char *now_str; const char *state_str; - if ( ( (NULL == peer) || - (GNUNET_CORE_KX_ITERATION_FINISHED == state) ) && - (GNUNET_NO == monitor_connections) ) + (void) cls; + if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) && + (GNUNET_NO == monitor_connections)) { GNUNET_SCHEDULER_shutdown (); return; @@ -87,42 +88,43 @@ monitor_cb (void *cls, { case GNUNET_CORE_KX_STATE_DOWN: /* should never happen, as we immediately send the key */ - state_str = _("fresh connection"); + state_str = _ ("fresh connection"); break; case GNUNET_CORE_KX_STATE_KEY_SENT: - state_str = _("key sent"); + state_str = _ ("key sent"); break; case GNUNET_CORE_KX_STATE_KEY_RECEIVED: - state_str = _("key received"); + state_str = _ ("key received"); break; case GNUNET_CORE_KX_STATE_UP: - state_str = _("connection established"); + state_str = _ ("connection established"); break; case GNUNET_CORE_KX_STATE_REKEY_SENT: - state_str = _("rekeying"); + state_str = _ ("rekeying"); break; case GNUNET_CORE_KX_PEER_DISCONNECT: - state_str = _("disconnected"); + state_str = _ ("disconnected"); break; case GNUNET_CORE_KX_ITERATION_FINISHED: return; case GNUNET_CORE_KX_CORE_DISCONNECT: FPRINTF (stderr, "%s\n", - _("Connection to CORE service lost (reconnecting)")); + _ ("Connection to CORE service lost (reconnecting)")); return; default: - state_str = _("unknown state"); + state_str = _ ("unknown state"); break; } now_str = GNUNET_STRINGS_absolute_time_to_string (now); FPRINTF (stdout, - _("%24s: %-30s %4s (timeout in %6s)\n"), + _ ("%24s: %-30s %4s (timeout in %6s)\n"), now_str, state_str, GNUNET_i2s (peer), - GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (timeout), - GNUNET_YES)); + GNUNET_STRINGS_relative_time_to_string ( + GNUNET_TIME_absolute_get_remaining (timeout), + GNUNET_YES)); } @@ -135,24 +137,22 @@ monitor_cb (void *cls, * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + (void) cls; + (void) cfgfile; if (NULL != args[0]) { - FPRINTF (stderr, - _("Invalid command line argument `%s'\n"), - args[0]); + FPRINTF (stderr, _ ("Invalid command line argument `%s'\n"), args[0]); return; } - mh = GNUNET_CORE_monitor_start (cfg, - &monitor_cb, - NULL); + mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL); if (NULL == mh) { - FPRINTF (stderr, - "%s", - _("Failed to connect to CORE service!\n")); + FPRINTF (stderr, "%s", _ ("Failed to connect to CORE service!\n")); return; } GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); @@ -167,24 +167,28 @@ run (void *cls, char *const *args, const char *cfgfile, * @return 0 ok, 1 on error */ int -main (int argc, - char *const *argv) +main (int argc, char *const *argv) { int res; - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_flag ('m', - "monitor", - gettext_noop ("provide information about all current connections (continuously)"), - &monitor_connections), - GNUNET_GETOPT_OPTION_END - }; + struct GNUNET_GETOPT_CommandLineOption options[] = + {GNUNET_GETOPT_option_flag ( + 'm', + "monitor", + gettext_noop ( + "provide information about all current connections (continuously)"), + &monitor_connections), + GNUNET_GETOPT_OPTION_END}; if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; - res = GNUNET_PROGRAM_run (argc, argv, "gnunet-core", - gettext_noop - ("Print information about connected peers."), - options, &run, NULL); + res = GNUNET_PROGRAM_run (argc, + argv, + "gnunet-core", + gettext_noop ( + "Print information about connected peers."), + options, + &run, + NULL); GNUNET_free ((void *) argv); if (GNUNET_OK == res) diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 09316dbcf..fd83d2b67 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c @@ -430,6 +430,7 @@ handle_start (void *cls, const struct GNUNET_MessageHeader *message) struct GNUNET_NSE_ClientMessage em; struct GNUNET_MQ_Envelope *env; + (void) message; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); mq = GNUNET_SERVICE_client_get_mq (client); GNUNET_notification_context_add (nc, mq); @@ -717,6 +718,8 @@ schedule_current_round (void *cls, struct NSEPeerEntry *peer_entry = value; struct GNUNET_TIME_Relative delay; + (void) cls; + (void) key; if (NULL != peer_entry->transmit_task) { GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); @@ -749,8 +752,8 @@ static void update_flood_message (void *cls) { struct GNUNET_TIME_Relative offset; - unsigned int i; + (void) cls; flood_task = NULL; offset = GNUNET_TIME_absolute_get_remaining (next_timestamp); if (0 != offset.rel_value_us) @@ -780,7 +783,7 @@ update_flood_message (void *cls) setup_flood_message (estimate_index, current_timestamp); next_message.matching_bits = htonl (0); /* reset for 'next' round */ hop_count_max = 0; - for (i = 0; i < HISTORY_SIZE; i++) + for (unsigned int i = 0; i < HISTORY_SIZE; i++) hop_count_max = GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max); GNUNET_CONTAINER_multipeermap_iterate (peers, &schedule_current_round, NULL); @@ -869,6 +872,7 @@ find_proof (void *cls) struct GNUNET_HashCode result; unsigned int i; + (void) cls; proof_task = NULL; GNUNET_memcpy (&buf[sizeof (uint64_t)], &my_identity, @@ -967,6 +971,7 @@ update_flood_times (void *cls, struct NSEPeerEntry *peer_entry = value; struct GNUNET_TIME_Relative delay; + (void) key; if (peer_entry == exclude) return GNUNET_OK; /* trigger of the update */ if (GNUNET_NO == peer_entry->previous_round) @@ -1178,6 +1183,7 @@ handle_core_connect (void *cls, { struct NSEPeerEntry *peer_entry; + (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected to us\n", GNUNET_i2s (peer)); @@ -1217,6 +1223,7 @@ handle_core_disconnect (void *cls, { struct NSEPeerEntry *pos = internal_cls; + (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected from us\n", GNUNET_i2s (peer)); @@ -1243,6 +1250,8 @@ handle_core_disconnect (void *cls, static void flush_comp_cb (void *cls, size_t size) { + (void) cls; + (void) size; GNUNET_TESTBED_LOGGER_disconnect (lh); lh = NULL; } @@ -1257,6 +1266,7 @@ flush_comp_cb (void *cls, size_t size) static void shutdown_task (void *cls) { + (void) cls; if (NULL != flood_task) { GNUNET_SCHEDULER_cancel (flood_task); @@ -1324,6 +1334,7 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *identity) struct GNUNET_TIME_Absolute now; struct GNUNET_TIME_Absolute prev_time; + (void) cls; if (NULL == identity) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n"); @@ -1365,6 +1376,7 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *identity) static void status_cb (void *cls, int status) { + (void) cls; logger_test = NULL; if (GNUNET_YES != status) { @@ -1402,6 +1414,8 @@ run (void *cls, char *proof; struct GNUNET_CRYPTO_EddsaPrivateKey *pk; + (void) cls; + (void) service; cfg = c; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "NSE", @@ -1524,6 +1538,8 @@ client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq) { + (void) cls; + (void) mq; return c; } @@ -1540,6 +1556,7 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls) { + (void) cls; GNUNET_assert (c == internal_cls); } -- cgit v1.2.3 From 32eec25228bec91318c577d18fe2ce3ff4d45598 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 21 Jun 2019 21:15:58 +0200 Subject: drop sections on planetlab, this is unlikely to even still work anymore, fixes #5628 --- doc/handbook/chapters/developer.texi | 163 ----------------------------------- 1 file changed, 163 deletions(-) diff --git a/doc/handbook/chapters/developer.texi b/doc/handbook/chapters/developer.texi index 228603cda..3225a6359 100644 --- a/doc/handbook/chapters/developer.texi +++ b/doc/handbook/chapters/developer.texi @@ -1876,7 +1876,6 @@ Testbed API can accessed by including the * Hosts file format:: * Topology file format:: * Testbed Barriers:: -* Automatic large-scale deployment in the PlanetLab testbed:: * TESTBED Caveats:: @end menu @@ -2140,168 +2139,6 @@ message from its upward propagation --- the upward propagation is needed for ensuring that the barrier is reached by all the controllers and the downward propagation is for triggering that the barrier is crossed. -@cindex PlanetLab testbed -@node Automatic large-scale deployment in the PlanetLab testbed -@subsection Automatic large-scale deployment in the PlanetLab testbed - -PlanetLab is a testbed for computer networking and distributed systems -research. It was established in 2002 and as of June 2010 was composed of -1090 nodes at 507 sites worldwide. - -To automate the GNUnet we created a set of automation tools to simplify -the large-scale deployment. We provide you a set of scripts you can use -to deploy GNUnet on a set of nodes and manage your installation. - -Please also check @uref{https://old.gnunet.org/installation-fedora8-svn} and -@uref{https://old.gnunet.org/installation-fedora12-svn} to find detailed -instructions how to install GNUnet on a PlanetLab node. - - -@c *********************************************************************** -@menu -* PlanetLab Automation for Fedora8 nodes:: -* Install buildslave on PlanetLab nodes running fedora core 8:: -* Setup a new PlanetLab testbed using GPLMT:: -* Why do i get an ssh error when using the regex profiler?:: -@end menu - -@node PlanetLab Automation for Fedora8 nodes -@subsubsection PlanetLab Automation for Fedora8 nodes - -@c *********************************************************************** -@node Install buildslave on PlanetLab nodes running fedora core 8 -@subsubsection Install buildslave on PlanetLab nodes running fedora core 8 -@c ** Actually this is a subsubsubsection, but must be fixed differently -@c ** as subsubsection is the lowest. - -Since most of the PlanetLab nodes are running the very old Fedora core 8 -image, installing the buildslave software is quite some pain. For our -PlanetLab testbed we figured out how to install the buildslave software -best. - -@c This is a very terrible way to suggest installing software. -@c FIXME: Is there an official, safer way instead of blind-piping a -@c script? -@c FIXME: Use newer pypi URLs below. -Install Distribute for Python: - -@example -curl http://python-distribute.org/distribute_setup.py | sudo python -@end example - -Install Distribute for zope.interface <= 3.8.0 (4.0 and 4.0.1 will not -work): - -@example -export PYPI=@value{PYPI-URL} -wget $PYPI/z/zope.interface/zope.interface-3.8.0.tar.gz -tar xzvf zope.interface-3.8.0.tar.gz -cd zope.interface-3.8.0 -sudo python setup.py install -@end example - -Install the buildslave software (0.8.6 was the latest version): - -@example -export GCODE="http://buildbot.googlecode.com/files" -wget $GCODE/buildbot-slave-0.8.6p1.tar.gz -tar xvfz buildbot-slave-0.8.6p1.tar.gz -cd buildslave-0.8.6p1 -sudo python setup.py install -@end example - -The setup will download the matching twisted package and install it. -It will also try to install the latest version of zope.interface which -will fail to install. Buildslave will work anyway since version 3.8.0 -was installed before! - -@c *********************************************************************** -@node Setup a new PlanetLab testbed using GPLMT -@subsubsection Setup a new PlanetLab testbed using GPLMT - -@itemize @bullet -@item Get a new slice and assign nodes -Ask your PlanetLab PI to give you a new slice and assign the nodes you -need -@item Install a buildmaster -You can stick to the buildbot documentation:@ -@uref{http://buildbot.net/buildbot/docs/current/manual/installation.html} -@item Install the buildslave software on all nodes -To install the buildslave on all nodes assigned to your slice you can use -the tasklist @code{install_buildslave_fc8.xml} provided with GPLMT: - -@example -./gplmt.py -c contrib/tumple_gnunet.conf -t \ -contrib/tasklists/install_buildslave_fc8.xml -a -p -@end example - -@item Create the buildmaster configuration and the slave setup commands - -The master and the and the slaves have need to have credentials and the -master has to have all nodes configured. This can be done with the -@file{create_buildbot_configuration.py} script in the @file{scripts} -directory. - -This scripts takes a list of nodes retrieved directly from PlanetLab or -read from a file and a configuration template and creates: - -@itemize @bullet -@item a tasklist which can be executed with gplmt to setup the slaves -@item a master.cfg file containing a PlanetLab nodes -@end itemize - -A configuration template is included in the , most important is -that the script replaces the following tags in the template: - -%GPLMT_BUILDER_DEFINITION :@ GPLMT_BUILDER_SUMMARY@ GPLMT_SLAVES@ -%GPLMT_SCHEDULER_BUILDERS - -Create configuration for all nodes assigned to a slice: - -@example -./create_buildbot_configuration.py -u \ --p -s -m \ --t