aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-12-28 08:09:50 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2023-12-28 08:09:50 +0100
commite6902dd5c0e4722f31e2a3717f5e5ed336ae0647 (patch)
treeb5eb39a92467426a468af9f19cb134e23358331d /src
parent02fd299416e715a706cb35140a90d7651a84803f (diff)
downloadgnunet-e6902dd5c0e4722f31e2a3717f5e5ed336ae0647.tar.gz
gnunet-e6902dd5c0e4722f31e2a3717f5e5ed336ae0647.zip
SET: Remove components depending on removed testbed
Diffstat (limited to 'src')
-rw-r--r--src/contrib/service/set/Makefile.am13
-rw-r--r--src/contrib/service/set/gnunet-set-profiler.c508
-rw-r--r--src/service/seti/Makefile.am13
-rw-r--r--src/service/seti/gnunet-seti-profiler.c480
-rw-r--r--src/service/setu/Makefile.am13
-rw-r--r--src/service/setu/gnunet-setu-profiler.c499
6 files changed, 2 insertions, 1524 deletions
diff --git a/src/contrib/service/set/Makefile.am b/src/contrib/service/set/Makefile.am
index 88d4d39ad..d8e19e6d4 100644
--- a/src/contrib/service/set/Makefile.am
+++ b/src/contrib/service/set/Makefile.am
@@ -15,8 +15,7 @@ if USE_COVERAGE
15endif 15endif
16 16
17noinst_PROGRAMS = \ 17noinst_PROGRAMS = \
18 gnunet-set-ibf-profiler \ 18 gnunet-set-ibf-profiler
19 gnunet-set-profiler
20 19
21libexec_PROGRAMS = \ 20libexec_PROGRAMS = \
22 gnunet-service-set 21 gnunet-service-set
@@ -24,16 +23,6 @@ libexec_PROGRAMS = \
24lib_LTLIBRARIES = \ 23lib_LTLIBRARIES = \
25 libgnunetset.la 24 libgnunetset.la
26 25
27gnunet_set_profiler_SOURCES = \
28 gnunet-set-profiler.c
29gnunet_set_profiler_LDADD = \
30 $(top_builddir)/src/lib/util/libgnunetutil.la \
31 $(top_builddir)/src/service/statistics/libgnunetstatistics.la \
32 libgnunetset.la \
33 $(top_builddir)/src/service/testing/libgnunettesting.la \
34 $(GN_LIBINTL)
35
36
37gnunet_set_ibf_profiler_SOURCES = \ 26gnunet_set_ibf_profiler_SOURCES = \
38 gnunet-set-ibf-profiler.c \ 27 gnunet-set-ibf-profiler.c \
39 ibf.c 28 ibf.c
diff --git a/src/contrib/service/set/gnunet-set-profiler.c b/src/contrib/service/set/gnunet-set-profiler.c
deleted file mode 100644
index 3014861a6..000000000
--- a/src/contrib/service/set/gnunet-set-profiler.c
+++ /dev/null
@@ -1,508 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file set/gnunet-set-profiler.c
23 * @brief profiling tool for set
24 * @author Florian Dold
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_statistics_service.h"
29#include "gnunet_set_service.h"
30#include "gnunet_testbed_service.h"
31
32
33static int ret;
34
35static unsigned int num_a = 5;
36static unsigned int num_b = 5;
37static unsigned int num_c = 20;
38
39static char *op_str = "union";
40
41const static struct GNUNET_CONFIGURATION_Handle *config;
42
43struct SetInfo
44{
45 char *id;
46 struct GNUNET_SET_Handle *set;
47 struct GNUNET_SET_OperationHandle *oh;
48 struct GNUNET_CONTAINER_MultiHashMap *sent;
49 struct GNUNET_CONTAINER_MultiHashMap *received;
50 int done;
51} info1, info2;
52
53static struct GNUNET_CONTAINER_MultiHashMap *common_sent;
54
55static struct GNUNET_HashCode app_id;
56
57static struct GNUNET_PeerIdentity local_peer;
58
59static struct GNUNET_SET_ListenHandle *set_listener;
60
61static int byzantine;
62static unsigned int force_delta;
63static unsigned int force_full;
64static unsigned int element_size = 32;
65
66/**
67 * Handle to the statistics service.
68 */
69static struct GNUNET_STATISTICS_Handle *statistics;
70
71/**
72 * The profiler will write statistics
73 * for all peers to the file with this name.
74 */
75static char *statistics_filename;
76
77/**
78 * The profiler will write statistics
79 * for all peers to this file.
80 */
81static FILE *statistics_file;
82
83
84static int
85map_remove_iterator (void *cls,
86 const struct GNUNET_HashCode *key,
87 void *value)
88{
89 struct GNUNET_CONTAINER_MultiHashMap *m = cls;
90 int ret;
91
92 GNUNET_assert (NULL != key);
93
94 ret = GNUNET_CONTAINER_multihashmap_remove_all (m, key);
95 if (GNUNET_OK != ret)
96 printf ("spurious element\n");
97 return GNUNET_YES;
98}
99
100
101/**
102 * Callback function to process statistic values.
103 *
104 * @param cls closure
105 * @param subsystem name of subsystem that created the statistic
106 * @param name the name of the datum
107 * @param value the current value
108 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
109 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
110 */
111static int
112statistics_result (void *cls,
113 const char *subsystem,
114 const char *name,
115 uint64_t value,
116 int is_persistent)
117{
118 if (NULL != statistics_file)
119 {
120 fprintf (statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned
121 long) value);
122 }
123 return GNUNET_OK;
124}
125
126
127static void
128statistics_done (void *cls,
129 int success)
130{
131 GNUNET_assert (GNUNET_YES == success);
132 if (NULL != statistics_file)
133 fclose (statistics_file);
134 GNUNET_SCHEDULER_shutdown ();
135}
136
137
138static void
139check_all_done (void)
140{
141 if ((info1.done == GNUNET_NO) || (info2.done == GNUNET_NO))
142 return;
143
144 GNUNET_CONTAINER_multihashmap_iterate (info1.received, map_remove_iterator,
145 info2.sent);
146 GNUNET_CONTAINER_multihashmap_iterate (info2.received, map_remove_iterator,
147 info1.sent);
148
149 printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (
150 info1.sent));
151 printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (
152 info2.sent));
153
154 if (NULL == statistics_filename)
155 {
156 GNUNET_SCHEDULER_shutdown ();
157 return;
158 }
159
160 statistics_file = fopen (statistics_filename, "w");
161 GNUNET_STATISTICS_get (statistics, NULL, NULL,
162 &statistics_done,
163 &statistics_result, NULL);
164}
165
166
167static void
168set_result_cb (void *cls,
169 const struct GNUNET_SET_Element *element,
170 uint64_t current_size,
171 enum GNUNET_SET_Status status)
172{
173 struct SetInfo *info = cls;
174 struct GNUNET_HashCode hash;
175
176 GNUNET_assert (GNUNET_NO == info->done);
177 switch (status)
178 {
179 case GNUNET_SET_STATUS_DONE:
180 case GNUNET_SET_STATUS_HALF_DONE:
181 info->done = GNUNET_YES;
182 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id);
183 check_all_done ();
184 info->oh = NULL;
185 return;
186
187 case GNUNET_SET_STATUS_FAILURE:
188 info->oh = NULL;
189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failure\n");
190 GNUNET_SCHEDULER_shutdown ();
191 return;
192
193 case GNUNET_SET_STATUS_ADD_LOCAL:
194 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id);
195 break;
196
197 case GNUNET_SET_STATUS_ADD_REMOTE:
198 GNUNET_CRYPTO_hash (element->data, element->size, &hash);
199 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: remote element %s\n", info->id,
200 GNUNET_h2s (&hash));
201 // XXX: record and check
202 return;
203
204 default:
205 GNUNET_assert (0);
206 }
207
208 if (element->size != element_size)
209 {
210 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
211 "wrong element size: %u, expected %u\n",
212 element->size,
213 (unsigned int) sizeof(struct GNUNET_HashCode));
214 GNUNET_assert (0);
215 }
216
217 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n",
218 info->id, GNUNET_h2s (element->data));
219 GNUNET_assert (NULL != element->data);
220 struct GNUNET_HashCode data_hash;
221 GNUNET_CRYPTO_hash (element->data, element_size, &data_hash);
222 GNUNET_CONTAINER_multihashmap_put (info->received,
223 &data_hash, NULL,
224 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
225}
226
227
228static void
229set_listen_cb (void *cls,
230 const struct GNUNET_PeerIdentity *other_peer,
231 const struct GNUNET_MessageHeader *context_msg,
232 struct GNUNET_SET_Request *request)
233{
234 /* max. 2 options plus terminator */
235 struct GNUNET_SET_Option opts[3] = { { 0 } };
236 unsigned int n_opts = 0;
237
238 if (NULL == request)
239 {
240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
241 "listener failed\n");
242 return;
243 }
244 GNUNET_assert (NULL == info2.oh);
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 "set listen cb called\n");
247 if (byzantine)
248 {
249 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
250 GNUNET_SET_OPTION_BYZANTINE };
251 }
252 GNUNET_assert (! (force_full && force_delta));
253 if (force_full)
254 {
255 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
256 GNUNET_SET_OPTION_FORCE_FULL };
257 }
258 if (force_delta)
259 {
260 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
261 GNUNET_SET_OPTION_FORCE_DELTA };
262 }
263
264 opts[n_opts].type = 0;
265 info2.oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_SYMMETRIC,
266 opts,
267 set_result_cb, &info2);
268 GNUNET_SET_commit (info2.oh, info2.set);
269}
270
271
272static int
273set_insert_iterator (void *cls,
274 const struct GNUNET_HashCode *key,
275 void *value)
276{
277 struct GNUNET_SET_Handle *set = cls;
278 struct GNUNET_SET_Element el;
279
280 el.element_type = 0;
281 el.data = value;
282 el.size = element_size;
283 GNUNET_SET_add_element (set, &el, NULL, NULL);
284 return GNUNET_YES;
285}
286
287
288static void
289handle_shutdown (void *cls)
290{
291 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
292 "Shutting down set profiler\n");
293 if (NULL != set_listener)
294 {
295 GNUNET_SET_listen_cancel (set_listener);
296 set_listener = NULL;
297 }
298 if (NULL != info1.oh)
299 {
300 GNUNET_SET_operation_cancel (info1.oh);
301 info1.oh = NULL;
302 }
303 if (NULL != info2.oh)
304 {
305 GNUNET_SET_operation_cancel (info2.oh);
306 info2.oh = NULL;
307 }
308 if (NULL != info1.set)
309 {
310 GNUNET_SET_destroy (info1.set);
311 info1.set = NULL;
312 }
313 if (NULL != info2.set)
314 {
315 GNUNET_SET_destroy (info2.set);
316 info2.set = NULL;
317 }
318 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
319}
320
321
322static void
323run (void *cls,
324 const struct GNUNET_CONFIGURATION_Handle *cfg,
325 struct GNUNET_TESTING_Peer *peer)
326{
327 unsigned int i;
328 struct GNUNET_HashCode hash;
329 /* max. 2 options plus terminator */
330 struct GNUNET_SET_Option opts[3] = { { 0 } };
331 unsigned int n_opts = 0;
332
333 config = cfg;
334
335 GNUNET_assert (element_size > 0);
336
337 if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &local_peer))
338 {
339 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n");
340 ret = 0;
341 return;
342 }
343
344 statistics = GNUNET_STATISTICS_create ("set-profiler", cfg);
345
346 GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
347
348 info1.id = "a";
349 info2.id = "b";
350
351 info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO);
352 info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO);
353 common_sent = GNUNET_CONTAINER_multihashmap_create (num_c + 1, GNUNET_NO);
354
355 info1.received = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO);
356 info2.received = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO);
357
358 for (i = 0; i < num_a; i++)
359 {
360 char *data = GNUNET_malloc (element_size);
361 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
362 GNUNET_CRYPTO_hash (data, element_size, &hash);
363 GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, data,
364 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
365 }
366
367 for (i = 0; i < num_b; i++)
368 {
369 char *data = GNUNET_malloc (element_size);
370 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
371 GNUNET_CRYPTO_hash (data, element_size, &hash);
372 GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, data,
373 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
374 }
375
376 for (i = 0; i < num_c; i++)
377 {
378 char *data = GNUNET_malloc (element_size);
379 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
380 GNUNET_CRYPTO_hash (data, element_size, &hash);
381 GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, data,
382 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
383 }
384
385 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &app_id);
386
387 /* FIXME: also implement intersection etc. */
388 info1.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION);
389 info2.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION);
390
391 GNUNET_CONTAINER_multihashmap_iterate (info1.sent, set_insert_iterator,
392 info1.set);
393 GNUNET_CONTAINER_multihashmap_iterate (info2.sent, set_insert_iterator,
394 info2.set);
395 GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator,
396 info1.set);
397 GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator,
398 info2.set);
399
400 set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION,
401 &app_id, set_listen_cb, NULL);
402
403
404 if (byzantine)
405 {
406 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
407 GNUNET_SET_OPTION_BYZANTINE };
408 }
409 GNUNET_assert (! (force_full && force_delta));
410 if (force_full)
411 {
412 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
413 GNUNET_SET_OPTION_FORCE_FULL };
414 }
415 if (force_delta)
416 {
417 opts[n_opts++] = (struct GNUNET_SET_Option) { .type =
418 GNUNET_SET_OPTION_FORCE_DELTA };
419 }
420
421 opts[n_opts].type = 0;
422
423 info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL,
424 GNUNET_SET_RESULT_SYMMETRIC,
425 opts,
426 set_result_cb, &info1);
427 GNUNET_SET_commit (info1.oh, info1.set);
428 GNUNET_SET_destroy (info1.set);
429 info1.set = NULL;
430}
431
432
433static void
434pre_run (void *cls, char *const *args, const char *cfgfile,
435 const struct GNUNET_CONFIGURATION_Handle *cfg)
436{
437 if (0 != GNUNET_TESTING_peer_run ("set-profiler",
438 cfgfile,
439 &run, NULL))
440 ret = 2;
441}
442
443
444int
445main (int argc, char **argv)
446{
447 struct GNUNET_GETOPT_CommandLineOption options[] = {
448 GNUNET_GETOPT_option_uint ('A',
449 "num-first",
450 NULL,
451 gettext_noop ("number of values"),
452 &num_a),
453
454 GNUNET_GETOPT_option_uint ('B',
455 "num-second",
456 NULL,
457 gettext_noop ("number of values"),
458 &num_b),
459
460 GNUNET_GETOPT_option_flag ('b',
461 "byzantine",
462 gettext_noop ("use byzantine mode"),
463 &byzantine),
464
465 GNUNET_GETOPT_option_uint ('f',
466 "force-full",
467 NULL,
468 gettext_noop ("force sending full set"),
469 &force_full),
470
471 GNUNET_GETOPT_option_uint ('d',
472 "force-delta",
473 NULL,
474 gettext_noop ("number delta operation"),
475 &force_delta),
476
477 GNUNET_GETOPT_option_uint ('C',
478 "num-common",
479 NULL,
480 gettext_noop ("number of values"),
481 &num_c),
482
483 GNUNET_GETOPT_option_string ('x',
484 "operation",
485 NULL,
486 gettext_noop ("operation to execute"),
487 &op_str),
488
489 GNUNET_GETOPT_option_uint ('w',
490 "element-size",
491 NULL,
492 gettext_noop ("element size"),
493 &element_size),
494
495 GNUNET_GETOPT_option_filename ('s',
496 "statistics",
497 "FILENAME",
498 gettext_noop ("write statistics to file"),
499 &statistics_filename),
500
501 GNUNET_GETOPT_OPTION_END
502 };
503
504 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler",
505 "help",
506 options, &pre_run, NULL, GNUNET_YES);
507 return ret;
508}
diff --git a/src/service/seti/Makefile.am b/src/service/seti/Makefile.am
index 00923d56d..3c0c66ed8 100644
--- a/src/service/seti/Makefile.am
+++ b/src/service/seti/Makefile.am
@@ -17,22 +17,9 @@ endif
17libexec_PROGRAMS = \ 17libexec_PROGRAMS = \
18 gnunet-service-seti 18 gnunet-service-seti
19 19
20noinst_PROGRAMS = \
21 gnunet-seti-profiler
22
23lib_LTLIBRARIES = \ 20lib_LTLIBRARIES = \
24 libgnunetseti.la 21 libgnunetseti.la
25 22
26gnunet_seti_profiler_SOURCES = \
27 gnunet-seti-profiler.c
28gnunet_seti_profiler_LDADD = \
29 $(top_builddir)/src/lib/util/libgnunetutil.la \
30 $(top_builddir)/src/service/statistics/libgnunetstatistics.la \
31 libgnunetseti.la \
32 $(top_builddir)/src/service/testing/libgnunettesting.la \
33 $(GN_LIBINTL)
34
35
36gnunet_service_seti_SOURCES = \ 23gnunet_service_seti_SOURCES = \
37 gnunet-service-seti.c \ 24 gnunet-service-seti.c \
38 gnunet-service-seti_protocol.h 25 gnunet-service-seti_protocol.h
diff --git a/src/service/seti/gnunet-seti-profiler.c b/src/service/seti/gnunet-seti-profiler.c
deleted file mode 100644
index b8230bcfc..000000000
--- a/src/service/seti/gnunet-seti-profiler.c
+++ /dev/null
@@ -1,480 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013, 2020 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file set/gnunet-seti-profiler.c
23 * @brief profiling tool for set intersection
24 * @author Florian Dold
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_statistics_service.h"
29#include "gnunet_seti_service.h"
30#include "gnunet_testbed_service.h"
31
32
33static int ret;
34
35static unsigned int num_a = 5;
36static unsigned int num_b = 5;
37static unsigned int num_c = 20;
38
39const static struct GNUNET_CONFIGURATION_Handle *config;
40
41struct SetInfo
42{
43 char *id;
44 struct GNUNET_SETI_Handle *set;
45 struct GNUNET_SETI_OperationHandle *oh;
46 struct GNUNET_CONTAINER_MultiHashMap *sent;
47 struct GNUNET_CONTAINER_MultiHashMap *received;
48 int done;
49} info1, info2;
50
51static struct GNUNET_CONTAINER_MultiHashMap *common_sent;
52
53static struct GNUNET_HashCode app_id;
54
55static struct GNUNET_PeerIdentity local_peer;
56
57static struct GNUNET_SETI_ListenHandle *set_listener;
58
59static unsigned int use_intersection;
60
61static unsigned int element_size = 32;
62
63/**
64 * Handle to the statistics service.
65 */
66static struct GNUNET_STATISTICS_Handle *statistics;
67
68/**
69 * The profiler will write statistics
70 * for all peers to the file with this name.
71 */
72static char *statistics_filename;
73
74/**
75 * The profiler will write statistics
76 * for all peers to this file.
77 */
78static FILE *statistics_file;
79
80
81static int
82map_remove_iterator (void *cls,
83 const struct GNUNET_HashCode *key,
84 void *value)
85{
86 struct GNUNET_CONTAINER_MultiHashMap *m = cls;
87 int ret;
88
89 GNUNET_assert (NULL != key);
90
91 ret = GNUNET_CONTAINER_multihashmap_remove_all (m, key);
92 if (GNUNET_OK != ret)
93 printf ("spurious element\n");
94 return GNUNET_YES;
95}
96
97
98/**
99 * Callback function to process statistic values.
100 *
101 * @param cls closure
102 * @param subsystem name of subsystem that created the statistic
103 * @param name the name of the datum
104 * @param value the current value
105 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
106 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
107 */
108static int
109statistics_result (void *cls,
110 const char *subsystem,
111 const char *name,
112 uint64_t value,
113 int is_persistent)
114{
115 if (NULL != statistics_file)
116 {
117 fprintf (statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned
118 long) value);
119 }
120 return GNUNET_OK;
121}
122
123
124static void
125statistics_done (void *cls,
126 int success)
127{
128 GNUNET_assert (GNUNET_YES == success);
129 if (NULL != statistics_file)
130 fclose (statistics_file);
131 GNUNET_SCHEDULER_shutdown ();
132}
133
134
135static void
136check_all_done (void)
137{
138 if ((info1.done == GNUNET_NO) || (info2.done == GNUNET_NO))
139 return;
140
141 GNUNET_CONTAINER_multihashmap_iterate (info1.received, map_remove_iterator,
142 info2.sent);
143 GNUNET_CONTAINER_multihashmap_iterate (info2.received, map_remove_iterator,
144 info1.sent);
145
146 printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (
147 info1.sent));
148 printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (
149 info2.sent));
150
151 if (NULL == statistics_filename)
152 {
153 GNUNET_SCHEDULER_shutdown ();
154 return;
155 }
156
157 statistics_file = fopen (statistics_filename, "w");
158 GNUNET_STATISTICS_get (statistics, NULL, NULL,
159 &statistics_done,
160 &statistics_result, NULL);
161}
162
163
164static void
165set_result_cb (void *cls,
166 const struct GNUNET_SETI_Element *element,
167 uint64_t current_size,
168 enum GNUNET_SETI_Status status)
169{
170 struct SetInfo *info = cls;
171 struct GNUNET_HashCode hash;
172
173 GNUNET_assert (GNUNET_NO == info->done);
174 switch (status)
175 {
176 case GNUNET_SETI_STATUS_DONE:
177 info->done = GNUNET_YES;
178 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
179 "set intersection done\n");
180 check_all_done ();
181 info->oh = NULL;
182 return;
183 case GNUNET_SETI_STATUS_FAILURE:
184 info->oh = NULL;
185 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
186 "failure\n");
187 GNUNET_SCHEDULER_shutdown ();
188 return;
189 case GNUNET_SETI_STATUS_ADD_LOCAL:
190 GNUNET_CRYPTO_hash (element->data,
191 element->size,
192 &hash);
193 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
194 "set %s: keep element %s\n",
195 info->id,
196 GNUNET_h2s (&hash));
197 break;
198 case GNUNET_SETI_STATUS_DEL_LOCAL:
199 GNUNET_CRYPTO_hash (element->data,
200 element->size,
201 &hash);
202 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
203 "set %s: remove element %s\n",
204 info->id,
205 GNUNET_h2s (&hash));
206 return;
207 default:
208 GNUNET_assert (0);
209 }
210
211 if (element->size != element_size)
212 {
213 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
214 "wrong element size: %u, expected %u\n",
215 element->size,
216 (unsigned int) sizeof(struct GNUNET_HashCode));
217 GNUNET_assert (0);
218 }
219
220 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
221 "set %s: got element (%s)\n",
222 info->id, GNUNET_h2s (element->data));
223 GNUNET_assert (NULL != element->data);
224 {
225 struct GNUNET_HashCode data_hash;
226
227 GNUNET_CRYPTO_hash (element->data,
228 element_size,
229 &data_hash);
230 GNUNET_CONTAINER_multihashmap_put (info->received,
231 &data_hash,
232 NULL,
233 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
234 }
235}
236
237
238static void
239set_listen_cb (void *cls,
240 const struct GNUNET_PeerIdentity *other_peer,
241 const struct GNUNET_MessageHeader *context_msg,
242 struct GNUNET_SETI_Request *request)
243{
244 /* max. 1 option plus terminator */
245 struct GNUNET_SETI_Option opts[2] = { { 0 } };
246 unsigned int n_opts = 0;
247
248 if (NULL == request)
249 {
250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
251 "listener failed\n");
252 return;
253 }
254 GNUNET_assert (NULL == info2.oh);
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
256 "set listen cb called\n");
257 if (use_intersection)
258 {
259 opts[n_opts++] = (struct GNUNET_SETI_Option) { .type =
260 GNUNET_SETI_OPTION_RETURN_INTERSECTION };
261 }
262 opts[n_opts].type = GNUNET_SETI_OPTION_END;
263 info2.oh = GNUNET_SETI_accept (request,
264 opts,
265 &set_result_cb,
266 &info2);
267 GNUNET_SETI_commit (info2.oh,
268 info2.set);
269}
270
271
272static int
273set_insert_iterator (void *cls,
274 const struct GNUNET_HashCode *key,
275 void *value)
276{
277 struct GNUNET_SETI_Handle *set = cls;
278 struct GNUNET_SETI_Element el;
279
280 el.element_type = 0;
281 el.data = value;
282 el.size = element_size;
283 GNUNET_SETI_add_element (set, &el, NULL, NULL);
284 return GNUNET_YES;
285}
286
287
288static void
289handle_shutdown (void *cls)
290{
291 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
292 "Shutting down set profiler\n");
293 if (NULL != set_listener)
294 {
295 GNUNET_SETI_listen_cancel (set_listener);
296 set_listener = NULL;
297 }
298 if (NULL != info1.oh)
299 {
300 GNUNET_SETI_operation_cancel (info1.oh);
301 info1.oh = NULL;
302 }
303 if (NULL != info2.oh)
304 {
305 GNUNET_SETI_operation_cancel (info2.oh);
306 info2.oh = NULL;
307 }
308 if (NULL != info1.set)
309 {
310 GNUNET_SETI_destroy (info1.set);
311 info1.set = NULL;
312 }
313 if (NULL != info2.set)
314 {
315 GNUNET_SETI_destroy (info2.set);
316 info2.set = NULL;
317 }
318 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
319}
320
321
322static void
323run (void *cls,
324 const struct GNUNET_CONFIGURATION_Handle *cfg,
325 struct GNUNET_TESTING_Peer *peer)
326{
327 unsigned int i;
328 struct GNUNET_HashCode hash;
329 /* max. 1 option plus terminator */
330 struct GNUNET_SETI_Option opts[2] = { { 0 } };
331 unsigned int n_opts = 0;
332
333 config = cfg;
334
335 GNUNET_assert (element_size > 0);
336
337 if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &local_peer))
338 {
339 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
340 "could not retrieve host identity\n");
341 ret = 0;
342 return;
343 }
344 statistics = GNUNET_STATISTICS_create ("set-profiler", cfg);
345 GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
346 info1.id = "a";
347 info2.id = "b";
348 info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO);
349 info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO);
350 common_sent = GNUNET_CONTAINER_multihashmap_create (num_c + 1, GNUNET_NO);
351 info1.received = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO);
352 info2.received = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO);
353 for (i = 0; i < num_a; i++)
354 {
355 char *data = GNUNET_malloc (element_size);
356 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
357 GNUNET_CRYPTO_hash (data, element_size, &hash);
358 GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, data,
359 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
360 }
361
362 for (i = 0; i < num_b; i++)
363 {
364 char *data = GNUNET_malloc (element_size);
365 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
366 GNUNET_CRYPTO_hash (data, element_size, &hash);
367 GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, data,
368 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
369 }
370
371 for (i = 0; i < num_c; i++)
372 {
373 char *data = GNUNET_malloc (element_size);
374 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
375 GNUNET_CRYPTO_hash (data, element_size, &hash);
376 GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, data,
377 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
378 }
379
380 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &app_id);
381
382 info1.set = GNUNET_SETI_create (config);
383 info2.set = GNUNET_SETI_create (config);
384 GNUNET_CONTAINER_multihashmap_iterate (info1.sent,
385 &set_insert_iterator,
386 info1.set);
387 GNUNET_CONTAINER_multihashmap_iterate (info2.sent,
388 &set_insert_iterator,
389 info2.set);
390 GNUNET_CONTAINER_multihashmap_iterate (common_sent,
391 &set_insert_iterator,
392 info1.set);
393 GNUNET_CONTAINER_multihashmap_iterate (common_sent,
394 &set_insert_iterator,
395 info2.set);
396
397 set_listener = GNUNET_SETI_listen (config,
398 &app_id,
399 &set_listen_cb,
400 NULL);
401 if (use_intersection)
402 {
403 opts[n_opts++] = (struct GNUNET_SETI_Option) { .type =
404 GNUNET_SETI_OPTION_RETURN_INTERSECTION };
405 }
406 opts[n_opts].type = GNUNET_SETI_OPTION_END;
407
408 info1.oh = GNUNET_SETI_prepare (&local_peer,
409 &app_id,
410 NULL,
411 opts,
412 set_result_cb,
413 &info1);
414 GNUNET_SETI_commit (info1.oh,
415 info1.set);
416 GNUNET_SETI_destroy (info1.set);
417 info1.set = NULL;
418}
419
420
421static void
422pre_run (void *cls,
423 char *const *args,
424 const char *cfgfile,
425 const struct GNUNET_CONFIGURATION_Handle *cfg)
426{
427 if (0 != GNUNET_TESTING_peer_run ("set-profiler",
428 cfgfile,
429 &run, NULL))
430 ret = 2;
431}
432
433
434int
435main (int argc, char **argv)
436{
437 struct GNUNET_GETOPT_CommandLineOption options[] = {
438 GNUNET_GETOPT_option_uint ('A',
439 "num-first",
440 NULL,
441 gettext_noop ("number of values"),
442 &num_a),
443 GNUNET_GETOPT_option_uint ('B',
444 "num-second",
445 NULL,
446 gettext_noop ("number of values"),
447 &num_b),
448 GNUNET_GETOPT_option_uint ('C',
449 "num-common",
450 NULL,
451 gettext_noop ("number of values"),
452 &num_c),
453 GNUNET_GETOPT_option_uint ('i',
454 "use-intersection",
455 NULL,
456 gettext_noop (
457 "return intersection instead of delta"),
458 &use_intersection),
459 GNUNET_GETOPT_option_uint ('w',
460 "element-size",
461 NULL,
462 gettext_noop ("element size"),
463 &element_size),
464 GNUNET_GETOPT_option_filename ('s',
465 "statistics",
466 "FILENAME",
467 gettext_noop ("write statistics to file"),
468 &statistics_filename),
469 GNUNET_GETOPT_OPTION_END
470 };
471
472 GNUNET_PROGRAM_run2 (argc, argv,
473 "gnunet-seti-profiler",
474 "help",
475 options,
476 &pre_run,
477 NULL,
478 GNUNET_YES);
479 return ret;
480}
diff --git a/src/service/setu/Makefile.am b/src/service/setu/Makefile.am
index f0cf9fdbc..bdbc78f44 100644
--- a/src/service/setu/Makefile.am
+++ b/src/service/setu/Makefile.am
@@ -15,8 +15,7 @@ if USE_COVERAGE
15endif 15endif
16 16
17noinst_PROGRAMS = \ 17noinst_PROGRAMS = \
18 gnunet-setu-ibf-profiler \ 18 gnunet-setu-ibf-profiler
19 gnunet-setu-profiler
20 19
21libexec_PROGRAMS = \ 20libexec_PROGRAMS = \
22 gnunet-service-setu 21 gnunet-service-setu
@@ -24,16 +23,6 @@ libexec_PROGRAMS = \
24lib_LTLIBRARIES = \ 23lib_LTLIBRARIES = \
25 libgnunetsetu.la 24 libgnunetsetu.la
26 25
27gnunet_setu_profiler_SOURCES = \
28 gnunet-setu-profiler.c
29gnunet_setu_profiler_LDADD = \
30 $(top_builddir)/src/lib/util/libgnunetutil.la \
31 $(top_builddir)/src/service/statistics/libgnunetstatistics.la \
32 libgnunetsetu.la \
33 $(top_builddir)/src/service/testing/libgnunettesting.la \
34 $(GN_LIBINTL)
35
36
37gnunet_setu_ibf_profiler_SOURCES = \ 26gnunet_setu_ibf_profiler_SOURCES = \
38 gnunet-setu-ibf-profiler.c \ 27 gnunet-setu-ibf-profiler.c \
39 ibf.c 28 ibf.c
diff --git a/src/service/setu/gnunet-setu-profiler.c b/src/service/setu/gnunet-setu-profiler.c
deleted file mode 100644
index 8d6a2dc8c..000000000
--- a/src/service/setu/gnunet-setu-profiler.c
+++ /dev/null
@@ -1,499 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file setu/gnunet-setu-profiler.c
23 * @brief profiling tool for set
24 * @author Florian Dold
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_statistics_service.h"
29#include "gnunet_setu_service.h"
30#include "gnunet_testbed_service.h"
31
32
33static int ret;
34
35static unsigned int num_a = 5;
36static unsigned int num_b = 5;
37static unsigned int num_c = 20;
38
39static char *op_str = "union";
40
41const static struct GNUNET_CONFIGURATION_Handle *config;
42
43struct SetInfo
44{
45 char *id;
46 struct GNUNET_SETU_Handle *set;
47 struct GNUNET_SETU_OperationHandle *oh;
48 struct GNUNET_CONTAINER_MultiHashMap *sent;
49 struct GNUNET_CONTAINER_MultiHashMap *received;
50 int done;
51} info1, info2;
52
53static struct GNUNET_CONTAINER_MultiHashMap *common_sent;
54
55static struct GNUNET_HashCode app_id;
56
57static struct GNUNET_PeerIdentity local_peer;
58
59static struct GNUNET_SETU_ListenHandle *set_listener;
60
61static int byzantine;
62static unsigned int force_delta;
63static unsigned int force_full;
64static unsigned int element_size = 32;
65
66/**
67 * Handle to the statistics service.
68 */
69static struct GNUNET_STATISTICS_Handle *statistics;
70
71/**
72 * The profiler will write statistics
73 * for all peers to the file with this name.
74 */
75static char *statistics_filename;
76
77/**
78 * The profiler will write statistics
79 * for all peers to this file.
80 */
81static FILE *statistics_file;
82
83
84static int
85map_remove_iterator (void *cls,
86 const struct GNUNET_HashCode *key,
87 void *value)
88{
89 struct GNUNET_CONTAINER_MultiHashMap *m = cls;
90 int ret;
91
92 GNUNET_assert (NULL != key);
93
94 ret = GNUNET_CONTAINER_multihashmap_remove_all (m, key);
95 if (GNUNET_OK != ret)
96 printf ("spurious element\n");
97 return GNUNET_YES;
98}
99
100
101/**
102 * Callback function to process statistic values.
103 *
104 * @param cls closure
105 * @param subsystem name of subsystem that created the statistic
106 * @param name the name of the datum
107 * @param value the current value
108 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
109 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
110 */
111static int
112statistics_result (void *cls,
113 const char *subsystem,
114 const char *name,
115 uint64_t value,
116 int is_persistent)
117{
118 if (NULL != statistics_file)
119 {
120 fprintf (statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned
121 long) value);
122 }
123 return GNUNET_OK;
124}
125
126
127static void
128statistics_done (void *cls,
129 int success)
130{
131 GNUNET_assert (GNUNET_YES == success);
132 if (NULL != statistics_file)
133 fclose (statistics_file);
134 GNUNET_SCHEDULER_shutdown ();
135}
136
137
138static void
139check_all_done (void)
140{
141 if ((info1.done == GNUNET_NO) || (info2.done == GNUNET_NO))
142 return;
143
144 GNUNET_CONTAINER_multihashmap_iterate (info1.received, map_remove_iterator,
145 info2.sent);
146 GNUNET_CONTAINER_multihashmap_iterate (info2.received, map_remove_iterator,
147 info1.sent);
148
149 printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (
150 info1.sent));
151 printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (
152 info2.sent));
153
154 if (NULL == statistics_filename)
155 {
156 GNUNET_SCHEDULER_shutdown ();
157 return;
158 }
159
160 statistics_file = fopen (statistics_filename, "w");
161 GNUNET_STATISTICS_get (statistics, NULL, NULL,
162 &statistics_done,
163 &statistics_result, NULL);
164}
165
166
167static void
168set_result_cb (void *cls,
169 const struct GNUNET_SETU_Element *element,
170 uint64_t current_size,
171 enum GNUNET_SETU_Status status)
172{
173 struct SetInfo *info = cls;
174
175 GNUNET_assert (GNUNET_NO == info->done);
176 switch (status)
177 {
178 case GNUNET_SETU_STATUS_DONE:
179 info->done = GNUNET_YES;
180 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id);
181 check_all_done ();
182 info->oh = NULL;
183 return;
184
185 case GNUNET_SETU_STATUS_FAILURE:
186 info->oh = NULL;
187 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failure\n");
188 GNUNET_SCHEDULER_shutdown ();
189 return;
190
191 case GNUNET_SETU_STATUS_ADD_LOCAL:
192 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id);
193 break;
194 default:
195 GNUNET_assert (0);
196 }
197
198 if (element->size != element_size)
199 {
200 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
201 "wrong element size: %u, expected %u\n",
202 element->size,
203 (unsigned int) sizeof(struct GNUNET_HashCode));
204 GNUNET_assert (0);
205 }
206
207 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n",
208 info->id, GNUNET_h2s (element->data));
209 GNUNET_assert (NULL != element->data);
210 struct GNUNET_HashCode data_hash;
211 GNUNET_CRYPTO_hash (element->data, element_size, &data_hash);
212 GNUNET_CONTAINER_multihashmap_put (info->received,
213 &data_hash, NULL,
214 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
215}
216
217
218static void
219set_listen_cb (void *cls,
220 const struct GNUNET_PeerIdentity *other_peer,
221 const struct GNUNET_MessageHeader *context_msg,
222 struct GNUNET_SETU_Request *request)
223{
224 /* max. 2 options plus terminator */
225 struct GNUNET_SETU_Option opts[3] = { { 0 } };
226 unsigned int n_opts = 0;
227
228 if (NULL == request)
229 {
230 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
231 "listener failed\n");
232 return;
233 }
234 GNUNET_assert (NULL == info2.oh);
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
236 "set listen cb called\n");
237 if (byzantine)
238 {
239 opts[n_opts++] = (struct GNUNET_SETU_Option) { .type =
240 GNUNET_SETU_OPTION_BYZANTINE };
241 }
242 GNUNET_assert (! (force_full && force_delta));
243 if (force_full)
244 {
245 opts[n_opts++] = (struct GNUNET_SETU_Option) { .type =
246 GNUNET_SETU_OPTION_FORCE_FULL };
247 }
248 if (force_delta)
249 {
250 opts[n_opts++] = (struct GNUNET_SETU_Option) { .type =
251 GNUNET_SETU_OPTION_FORCE_DELTA };
252 }
253
254 opts[n_opts].type = 0;
255 info2.oh = GNUNET_SETU_accept (request,
256 opts,
257 set_result_cb, &info2);
258 GNUNET_SETU_commit (info2.oh, info2.set);
259}
260
261
262static int
263set_insert_iterator (void *cls,
264 const struct GNUNET_HashCode *key,
265 void *value)
266{
267 struct GNUNET_SETU_Handle *set = cls;
268 struct GNUNET_SETU_Element el;
269
270 el.element_type = 0;
271 el.data = value;
272 el.size = element_size;
273 GNUNET_SETU_add_element (set, &el, NULL, NULL);
274 return GNUNET_YES;
275}
276
277
278static void
279handle_shutdown (void *cls)
280{
281 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
282 "Shutting down set profiler\n");
283 if (NULL != set_listener)
284 {
285 GNUNET_SETU_listen_cancel (set_listener);
286 set_listener = NULL;
287 }
288 if (NULL != info1.oh)
289 {
290 GNUNET_SETU_operation_cancel (info1.oh);
291 info1.oh = NULL;
292 }
293 if (NULL != info2.oh)
294 {
295 GNUNET_SETU_operation_cancel (info2.oh);
296 info2.oh = NULL;
297 }
298 if (NULL != info1.set)
299 {
300 GNUNET_SETU_destroy (info1.set);
301 info1.set = NULL;
302 }
303 if (NULL != info2.set)
304 {
305 GNUNET_SETU_destroy (info2.set);
306 info2.set = NULL;
307 }
308 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
309}
310
311
312static void
313run (void *cls,
314 const struct GNUNET_CONFIGURATION_Handle *cfg,
315 struct GNUNET_TESTING_Peer *peer)
316{
317 unsigned int i;
318 struct GNUNET_HashCode hash;
319 /* max. 2 options plus terminator */
320 struct GNUNET_SETU_Option opts[3] = { { 0 } };
321 unsigned int n_opts = 0;
322
323 config = cfg;
324
325 GNUNET_assert (element_size > 0);
326
327 if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &local_peer))
328 {
329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n");
330 ret = 0;
331 return;
332 }
333
334 statistics = GNUNET_STATISTICS_create ("set-profiler", cfg);
335
336 GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
337
338 info1.id = "a";
339 info2.id = "b";
340
341 info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO);
342 info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO);
343 common_sent = GNUNET_CONTAINER_multihashmap_create (num_c + 1, GNUNET_NO);
344
345 info1.received = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO);
346 info2.received = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO);
347
348 for (i = 0; i < num_a; i++)
349 {
350 char *data = GNUNET_malloc (element_size);
351 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
352 GNUNET_CRYPTO_hash (data, element_size, &hash);
353 GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, data,
354 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
355 }
356
357 for (i = 0; i < num_b; i++)
358 {
359 char *data = GNUNET_malloc (element_size);
360 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
361 GNUNET_CRYPTO_hash (data, element_size, &hash);
362 GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, data,
363 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
364 }
365
366 for (i = 0; i < num_c; i++)
367 {
368 char *data = GNUNET_malloc (element_size);
369 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size);
370 GNUNET_CRYPTO_hash (data, element_size, &hash);
371 GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, data,
372 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
373 }
374
375 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &app_id);
376
377 /* FIXME: also implement intersection etc. */
378 info1.set = GNUNET_SETU_create (config);
379 info2.set = GNUNET_SETU_create (config);
380
381 GNUNET_CONTAINER_multihashmap_iterate (info1.sent, set_insert_iterator,
382 info1.set);
383 GNUNET_CONTAINER_multihashmap_iterate (info2.sent, set_insert_iterator,
384 info2.set);
385 GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator,
386 info1.set);
387 GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator,
388 info2.set);
389
390 set_listener = GNUNET_SETU_listen (config,
391 &app_id,
392 &set_listen_cb,
393 NULL);
394
395
396 if (byzantine)
397 {
398 opts[n_opts++] = (struct GNUNET_SETU_Option) { .type =
399 GNUNET_SETU_OPTION_BYZANTINE };
400 }
401 GNUNET_assert (! (force_full && force_delta));
402 if (force_full)
403 {
404 opts[n_opts++] = (struct GNUNET_SETU_Option) { .type =
405 GNUNET_SETU_OPTION_FORCE_FULL };
406 }
407 if (force_delta)
408 {
409 opts[n_opts++] = (struct GNUNET_SETU_Option) { .type =
410 GNUNET_SETU_OPTION_FORCE_DELTA };
411 }
412
413 opts[n_opts].type = 0;
414
415 info1.oh = GNUNET_SETU_prepare (&local_peer, &app_id, NULL,
416 opts,
417 set_result_cb, &info1);
418 GNUNET_SETU_commit (info1.oh, info1.set);
419 GNUNET_SETU_destroy (info1.set);
420 info1.set = NULL;
421}
422
423
424static void
425pre_run (void *cls, char *const *args, const char *cfgfile,
426 const struct GNUNET_CONFIGURATION_Handle *cfg)
427{
428 if (0 != GNUNET_TESTING_peer_run ("set-profiler",
429 cfgfile,
430 &run, NULL))
431 ret = 2;
432}
433
434
435int
436main (int argc, char **argv)
437{
438 struct GNUNET_GETOPT_CommandLineOption options[] = {
439 GNUNET_GETOPT_option_uint ('A',
440 "num-first",
441 NULL,
442 gettext_noop ("number of values"),
443 &num_a),
444
445 GNUNET_GETOPT_option_uint ('B',
446 "num-second",
447 NULL,
448 gettext_noop ("number of values"),
449 &num_b),
450
451 GNUNET_GETOPT_option_flag ('b',
452 "byzantine",
453 gettext_noop ("use byzantine mode"),
454 &byzantine),
455
456 GNUNET_GETOPT_option_uint ('f',
457 "force-full",
458 NULL,
459 gettext_noop ("force sending full set"),
460 &force_full),
461
462 GNUNET_GETOPT_option_uint ('d',
463 "force-delta",
464 NULL,
465 gettext_noop ("number delta operation"),
466 &force_delta),
467
468 GNUNET_GETOPT_option_uint ('C',
469 "num-common",
470 NULL,
471 gettext_noop ("number of values"),
472 &num_c),
473
474 GNUNET_GETOPT_option_string ('x',
475 "operation",
476 NULL,
477 gettext_noop ("operation to execute"),
478 &op_str),
479
480 GNUNET_GETOPT_option_uint ('w',
481 "element-size",
482 NULL,
483 gettext_noop ("element size"),
484 &element_size),
485
486 GNUNET_GETOPT_option_filename ('s',
487 "statistics",
488 "FILENAME",
489 gettext_noop ("write statistics to file"),
490 &statistics_filename),
491
492 GNUNET_GETOPT_OPTION_END
493 };
494
495 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler",
496 "help",
497 options, &pre_run, NULL, GNUNET_YES);
498 return ret;
499}