GNUnet 0.21.1
gnunet-set-ibf-profiler.c File Reference

tool for profiling the invertible bloom filter implementation More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "ibf.h"
Include dependency graph for gnunet-set-ibf-profiler.c:

Go to the source code of this file.

Functions

static void register_hashcode (struct GNUNET_HashCode *hash)
 
static void iter_hashcodes (struct IBF_Key key, GNUNET_CONTAINER_MultiHashMapIteratorCallback iter, void *cls)
 
static int insert_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static int remove_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 
int main (int argc, char **argv)
 

Variables

static unsigned int asize = 10
 
static unsigned int bsize = 10
 
static unsigned int csize = 10
 
static unsigned int hash_num = 4
 
static unsigned int ibf_size = 80
 
static enum GNUNET_CRYPTO_Quality random_quality = GNUNET_CRYPTO_QUALITY_WEAK
 
static struct GNUNET_CONTAINER_MultiHashMapset_a
 
static struct GNUNET_CONTAINER_MultiHashMapset_b
 
static struct GNUNET_CONTAINER_MultiHashMapset_c
 
static struct GNUNET_CONTAINER_MultiHashMapkey_to_hashcode
 
static struct InvertibleBloomFilteribf_a
 
static struct InvertibleBloomFilteribf_b
 

Detailed Description

tool for profiling the invertible bloom filter implementation

Author
Florian Dold

Definition in file gnunet-set-ibf-profiler.c.

Function Documentation

◆ register_hashcode()

static void register_hashcode ( struct GNUNET_HashCode hash)
static

Definition at line 53 of file gnunet-set-ibf-profiler.c.

54{
55 struct GNUNET_HashCode replicated;
56 struct IBF_Key key;
57
59 ibf_hashcode_from_key (key, &replicated);
62 &replicated,
63 GNUNET_memdup (hash, sizeof *hash),
65}
struct IBF_Key ibf_key_from_hashcode(const struct GNUNET_HashCode *hash)
Create a key from a hashcode.
Definition: ibf.c:44
void ibf_hashcode_from_key(struct IBF_Key key, struct GNUNET_HashCode *dst)
Create a hashcode from a key, by replicating the key until the hascode is filled.
Definition: ibf.c:58
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_CONTAINER_MultiHashMap * key_to_hashcode
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
A 512-bit hashcode.
Keys that can be inserted into and removed from an IBF.
Definition: ibf.h:46

References GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_memdup, ibf_hashcode_from_key(), ibf_key_from_hashcode(), key, and key_to_hashcode.

Referenced by run().

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

◆ iter_hashcodes()

static void iter_hashcodes ( struct IBF_Key  key,
GNUNET_CONTAINER_MultiHashMapIteratorCallback  iter,
void *  cls 
)
static

Definition at line 69 of file gnunet-set-ibf-profiler.c.

72{
73 struct GNUNET_HashCode replicated;
74
75 ibf_hashcode_from_key (key, &replicated);
77 &replicated,
78 iter,
79 cls);
80}
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.

References GNUNET_CONTAINER_multihashmap_get_multiple(), ibf_hashcode_from_key(), key, and key_to_hashcode.

Referenced by run().

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

◆ insert_iterator()

static int insert_iterator ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 84 of file gnunet-set-ibf-profiler.c.

85{
86 struct InvertibleBloomFilter *ibf = cls;
87
89 return GNUNET_YES;
90}
void ibf_insert(struct InvertibleBloomFilter *ibf, struct IBF_Key key)
Insert a key into an IBF.
Definition: ibf.c:168
@ GNUNET_YES
Invertible bloom filter (IBF).
Definition: ibf.h:83

References GNUNET_YES, ibf_insert(), ibf_key_from_hashcode(), and key.

Referenced by run().

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

◆ remove_iterator()

static int remove_iterator ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 94 of file gnunet-set-ibf-profiler.c.

95{
96 struct GNUNET_CONTAINER_MultiHashMap *hashmap = cls;
97
98 /* if remove fails, there just was a collision with another key */
99 (void) GNUNET_CONTAINER_multihashmap_remove (hashmap, value, NULL);
100 return GNUNET_YES;
101}
static char * value
Value of the record to add/remove.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
Internal representation of the hash map.

References GNUNET_CONTAINER_multihashmap_remove(), GNUNET_YES, and value.

Referenced by run().

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

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Definition at line 105 of file gnunet-set-ibf-profiler.c.

109{
110 struct GNUNET_HashCode id;
111 struct IBF_Key ibf_key;
112 int i;
113 int side;
114 int res;
116 struct GNUNET_TIME_Relative delta_time;
117
118 set_a =
120 GNUNET_NO);
121 set_b =
123 GNUNET_NO);
125 GNUNET_NO);
126
129 ? 1
130 : (asize + bsize + csize)),
131 GNUNET_NO);
132
133 printf ("hash-num=%u, size=%u, #(A-B)=%u, #(B-A)=%u, #(A&B)=%u\n",
134 hash_num,
135 ibf_size,
136 asize,
137 bsize,
138 csize);
139
140 i = 0;
141 while (i < asize)
142 {
145 continue;
148 set_a,
149 &id,
150 NULL,
152 register_hashcode (&id);
153 i++;
154 }
155 i = 0;
156 while (i < bsize)
157 {
160 continue;
162 continue;
165 set_b,
166 &id,
167 NULL,
169 register_hashcode (&id);
170 i++;
171 }
172 i = 0;
173 while (i < csize)
174 {
177 continue;
179 continue;
181 continue;
184 set_c,
185 &id,
186 NULL,
188 register_hashcode (&id);
189 i++;
190 }
191
194 if ((NULL == ibf_a) || (NULL == ibf_b))
195 {
196 /* insufficient memory */
197 GNUNET_break (0);
199 return;
200 }
201
202
203 printf ("generated sets\n");
204
206
211
213
214 printf ("encoded in: %s\n",
216
218
219
221
222 for (i = 0; i <= asize + bsize; i++)
223 {
224 res = ibf_decode (ibf_a, &side, &ibf_key);
225 if (GNUNET_SYSERR == res)
226 {
227 printf ("decode failed, %u/%u elements left\n",
230 asize + bsize);
231 return;
232 }
233 if (GNUNET_NO == res)
234 {
237 {
239 printf ("decoded successfully in: %s\n",
241 }
242 else
243 {
244 printf ("decode missed elements (should never happen)\n");
245 }
246 return;
247 }
248
249 if (side == 1)
251 if (side == -1)
253 }
254 printf ("cyclic IBF, %u/%u elements left\n",
257 asize + bsize);
258}
void ibf_subtract(struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFilter *ibf2)
Subtract ibf2 from ibf1, storing the result in ibf1.
Definition: ibf.c:357
int ibf_decode(struct InvertibleBloomFilter *ibf, int *ret_side, struct IBF_Key *ret_id)
Decode and remove an element from the IBF, if possible.
Definition: ibf.c:229
struct InvertibleBloomFilter * ibf_create(uint32_t size, uint8_t hash_num)
Create an invertible bloom filter.
Definition: ibf.c:80
static struct GNUNET_TIME_Absolute start_time
Start time of the current round; used to determine how long one iteration takes (which influences how...
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static int remove_iterator(void *cls, const struct GNUNET_HashCode *key, void *value)
static struct GNUNET_CONTAINER_MultiHashMap * set_a
static void iter_hashcodes(struct IBF_Key key, GNUNET_CONTAINER_MultiHashMapIteratorCallback iter, void *cls)
static enum GNUNET_CRYPTO_Quality random_quality
static unsigned int hash_num
static struct GNUNET_CONTAINER_MultiHashMap * set_c
static struct InvertibleBloomFilter * ibf_a
static void register_hashcode(struct GNUNET_HashCode *hash)
static struct InvertibleBloomFilter * ibf_b
static unsigned int csize
static unsigned int asize
static unsigned int bsize
static unsigned int ibf_size
static struct GNUNET_CONTAINER_MultiHashMap * set_b
static int insert_iterator(void *cls, const struct GNUNET_HashCode *key, void *value)
void GNUNET_CRYPTO_hash_create_random(enum GNUNET_CRYPTO_Quality mode, struct GNUNET_HashCode *result)
Create a random hash code.
Definition: crypto_hash.c:100
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:436
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.

References asize, bsize, csize, GNUNET_break, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_hash_create_random(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_shutdown(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, hash_num, ibf_a, ibf_b, ibf_create(), ibf_decode(), ibf_size, ibf_subtract(), id, insert_iterator(), iter_hashcodes(), key_to_hashcode, random_quality, register_hashcode(), remove_iterator(), res, set_a, set_b, set_c, and start_time.

Referenced by main().

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 262 of file gnunet-set-ibf-profiler.c.

263{
266 "asize",
267 NULL,
268 gettext_noop ("number of element in set A-B"),
269 &asize),
270
272 "bsize",
273 NULL,
274 gettext_noop ("number of element in set B-A"),
275 &bsize),
276
278 "csize",
279 NULL,
281 "number of common elements in A and B"),
282 &csize),
283
285 "hash-num",
286 NULL,
287 gettext_noop ("hash num"),
288 &hash_num),
289
291 "ibf-size",
292 NULL,
293 gettext_noop ("ibf size"),
294 &ibf_size),
295
297 };
298
300 argv,
301 "gnunet-consensus-ibf",
302 "help",
303 options,
304 &run,
305 NULL,
306 GNUNET_YES);
307 return 0;
308}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run2(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls, int run_without_scheduler)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:132
Definition of a command line option.

References asize, bsize, csize, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_uint(), GNUNET_PROGRAM_run2(), GNUNET_YES, hash_num, ibf_size, options, and run().

Here is the call graph for this function:

Variable Documentation

◆ asize

unsigned int asize = 10
static

Definition at line 32 of file gnunet-set-ibf-profiler.c.

Referenced by main(), and run().

◆ bsize

◆ csize

unsigned int csize = 10
static

Definition at line 34 of file gnunet-set-ibf-profiler.c.

Referenced by main(), and run().

◆ hash_num

unsigned int hash_num = 4
static

Definition at line 35 of file gnunet-set-ibf-profiler.c.

Referenced by ibf_create(), main(), and run().

◆ ibf_size

unsigned int ibf_size = 80
static

Definition at line 36 of file gnunet-set-ibf-profiler.c.

Referenced by main(), run(), send_ibf(), and strata_estimator_create().

◆ random_quality

enum GNUNET_CRYPTO_Quality random_quality = GNUNET_CRYPTO_QUALITY_WEAK
static

Definition at line 39 of file gnunet-set-ibf-profiler.c.

Referenced by run().

◆ set_a

struct GNUNET_CONTAINER_MultiHashMap* set_a
static

Definition at line 41 of file gnunet-set-ibf-profiler.c.

Referenced by run().

◆ set_b

struct GNUNET_CONTAINER_MultiHashMap* set_b
static

Definition at line 42 of file gnunet-set-ibf-profiler.c.

Referenced by run().

◆ set_c

struct GNUNET_CONTAINER_MultiHashMap* set_c
static

Definition at line 44 of file gnunet-set-ibf-profiler.c.

Referenced by run().

◆ key_to_hashcode

struct GNUNET_CONTAINER_MultiHashMap* key_to_hashcode
static

Definition at line 46 of file gnunet-set-ibf-profiler.c.

Referenced by iter_hashcodes(), register_hashcode(), and run().

◆ ibf_a

struct InvertibleBloomFilter* ibf_a
static

Definition at line 48 of file gnunet-set-ibf-profiler.c.

Referenced by run().

◆ ibf_b

struct InvertibleBloomFilter* ibf_b
static

Definition at line 49 of file gnunet-set-ibf-profiler.c.

Referenced by run().