diff options
Diffstat (limited to 'src/set/gnunet-set-profiler.c')
-rw-r--r-- | src/set/gnunet-set-profiler.c | 540 |
1 files changed, 278 insertions, 262 deletions
diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c index 4fabc8388..81263966a 100644 --- a/src/set/gnunet-set-profiler.c +++ b/src/set/gnunet-set-profiler.c | |||
@@ -40,7 +40,8 @@ static char *op_str = "union"; | |||
40 | 40 | ||
41 | const static struct GNUNET_CONFIGURATION_Handle *config; | 41 | const static struct GNUNET_CONFIGURATION_Handle *config; |
42 | 42 | ||
43 | struct SetInfo { | 43 | struct SetInfo |
44 | { | ||
44 | char *id; | 45 | char *id; |
45 | struct GNUNET_SET_Handle *set; | 46 | struct GNUNET_SET_Handle *set; |
46 | struct GNUNET_SET_OperationHandle *oh; | 47 | struct GNUNET_SET_OperationHandle *oh; |
@@ -81,18 +82,18 @@ static FILE *statistics_file; | |||
81 | 82 | ||
82 | 83 | ||
83 | static int | 84 | static int |
84 | map_remove_iterator(void *cls, | 85 | map_remove_iterator (void *cls, |
85 | const struct GNUNET_HashCode *key, | 86 | const struct GNUNET_HashCode *key, |
86 | void *value) | 87 | void *value) |
87 | { | 88 | { |
88 | struct GNUNET_CONTAINER_MultiHashMap *m = cls; | 89 | struct GNUNET_CONTAINER_MultiHashMap *m = cls; |
89 | int ret; | 90 | int ret; |
90 | 91 | ||
91 | GNUNET_assert(NULL != key); | 92 | GNUNET_assert (NULL != key); |
92 | 93 | ||
93 | ret = GNUNET_CONTAINER_multihashmap_remove_all(m, key); | 94 | ret = GNUNET_CONTAINER_multihashmap_remove_all (m, key); |
94 | if (GNUNET_OK != ret) | 95 | if (GNUNET_OK != ret) |
95 | printf("spurious element\n"); | 96 | printf ("spurious element\n"); |
96 | return GNUNET_YES; | 97 | return GNUNET_YES; |
97 | } | 98 | } |
98 | 99 | ||
@@ -108,162 +109,170 @@ map_remove_iterator(void *cls, | |||
108 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 109 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
109 | */ | 110 | */ |
110 | static int | 111 | static int |
111 | statistics_result(void *cls, | 112 | statistics_result (void *cls, |
112 | const char *subsystem, | 113 | const char *subsystem, |
113 | const char *name, | 114 | const char *name, |
114 | uint64_t value, | 115 | uint64_t value, |
115 | int is_persistent) | 116 | int is_persistent) |
116 | { | 117 | { |
117 | if (NULL != statistics_file) | 118 | if (NULL != statistics_file) |
118 | { | 119 | { |
119 | fprintf(statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned long)value); | 120 | fprintf (statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned |
120 | } | 121 | long) value); |
122 | } | ||
121 | return GNUNET_OK; | 123 | return GNUNET_OK; |
122 | } | 124 | } |
123 | 125 | ||
124 | 126 | ||
125 | static void | 127 | static void |
126 | statistics_done(void *cls, | 128 | statistics_done (void *cls, |
127 | int success) | 129 | int success) |
128 | { | 130 | { |
129 | GNUNET_assert(GNUNET_YES == success); | 131 | GNUNET_assert (GNUNET_YES == success); |
130 | if (NULL != statistics_file) | 132 | if (NULL != statistics_file) |
131 | fclose(statistics_file); | 133 | fclose (statistics_file); |
132 | GNUNET_SCHEDULER_shutdown(); | 134 | GNUNET_SCHEDULER_shutdown (); |
133 | } | 135 | } |
134 | 136 | ||
135 | 137 | ||
136 | static void | 138 | static void |
137 | check_all_done(void) | 139 | check_all_done (void) |
138 | { | 140 | { |
139 | if (info1.done == GNUNET_NO || info2.done == GNUNET_NO) | 141 | if ((info1.done == GNUNET_NO)||(info2.done == GNUNET_NO)) |
140 | return; | 142 | return; |
141 | 143 | ||
142 | GNUNET_CONTAINER_multihashmap_iterate(info1.received, map_remove_iterator, info2.sent); | 144 | GNUNET_CONTAINER_multihashmap_iterate (info1.received, map_remove_iterator, |
143 | GNUNET_CONTAINER_multihashmap_iterate(info2.received, map_remove_iterator, info1.sent); | 145 | info2.sent); |
146 | GNUNET_CONTAINER_multihashmap_iterate (info2.received, map_remove_iterator, | ||
147 | info1.sent); | ||
144 | 148 | ||
145 | printf("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size(info1.sent)); | 149 | printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size ( |
146 | printf("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size(info2.sent)); | 150 | info1.sent)); |
151 | printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size ( | ||
152 | info2.sent)); | ||
147 | 153 | ||
148 | if (NULL == statistics_filename) | 154 | if (NULL == statistics_filename) |
149 | { | 155 | { |
150 | GNUNET_SCHEDULER_shutdown(); | 156 | GNUNET_SCHEDULER_shutdown (); |
151 | return; | 157 | return; |
152 | } | 158 | } |
153 | 159 | ||
154 | statistics_file = fopen(statistics_filename, "w"); | 160 | statistics_file = fopen (statistics_filename, "w"); |
155 | GNUNET_STATISTICS_get(statistics, NULL, NULL, | 161 | GNUNET_STATISTICS_get (statistics, NULL, NULL, |
156 | &statistics_done, | 162 | &statistics_done, |
157 | &statistics_result, NULL); | 163 | &statistics_result, NULL); |
158 | } | 164 | } |
159 | 165 | ||
160 | 166 | ||
161 | static void | 167 | static void |
162 | set_result_cb(void *cls, | 168 | set_result_cb (void *cls, |
163 | const struct GNUNET_SET_Element *element, | 169 | const struct GNUNET_SET_Element *element, |
164 | uint64_t current_size, | 170 | uint64_t current_size, |
165 | enum GNUNET_SET_Status status) | 171 | enum GNUNET_SET_Status status) |
166 | { | 172 | { |
167 | struct SetInfo *info = cls; | 173 | struct SetInfo *info = cls; |
168 | struct GNUNET_HashCode hash; | 174 | struct GNUNET_HashCode hash; |
169 | 175 | ||
170 | GNUNET_assert(GNUNET_NO == info->done); | 176 | GNUNET_assert (GNUNET_NO == info->done); |
171 | switch (status) | 177 | switch (status) |
172 | { | 178 | { |
173 | case GNUNET_SET_STATUS_DONE: | 179 | case GNUNET_SET_STATUS_DONE: |
174 | case GNUNET_SET_STATUS_HALF_DONE: | 180 | case GNUNET_SET_STATUS_HALF_DONE: |
175 | info->done = GNUNET_YES; | 181 | info->done = GNUNET_YES; |
176 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id); | 182 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id); |
177 | check_all_done(); | 183 | check_all_done (); |
178 | info->oh = NULL; | 184 | info->oh = NULL; |
179 | return; | 185 | return; |
180 | 186 | ||
181 | case GNUNET_SET_STATUS_FAILURE: | 187 | case GNUNET_SET_STATUS_FAILURE: |
182 | info->oh = NULL; | 188 | info->oh = NULL; |
183 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "failure\n"); | 189 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failure\n"); |
184 | GNUNET_SCHEDULER_shutdown(); | 190 | GNUNET_SCHEDULER_shutdown (); |
185 | return; | 191 | return; |
186 | 192 | ||
187 | case GNUNET_SET_STATUS_ADD_LOCAL: | 193 | case GNUNET_SET_STATUS_ADD_LOCAL: |
188 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id); | 194 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: local element\n", info->id); |
189 | break; | 195 | break; |
190 | 196 | ||
191 | case GNUNET_SET_STATUS_ADD_REMOTE: | 197 | case GNUNET_SET_STATUS_ADD_REMOTE: |
192 | GNUNET_CRYPTO_hash(element->data, element->size, &hash); | 198 | GNUNET_CRYPTO_hash (element->data, element->size, &hash); |
193 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: remote element %s\n", info->id, | 199 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: remote element %s\n", info->id, |
194 | GNUNET_h2s(&hash)); | 200 | GNUNET_h2s (&hash)); |
195 | // XXX: record and check | 201 | // XXX: record and check |
196 | return; | 202 | return; |
197 | 203 | ||
198 | default: | 204 | default: |
199 | GNUNET_assert(0); | 205 | GNUNET_assert (0); |
200 | } | 206 | } |
201 | 207 | ||
202 | if (element->size != element_size) | 208 | if (element->size != element_size) |
203 | { | 209 | { |
204 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
205 | "wrong element size: %u, expected %u\n", | 211 | "wrong element size: %u, expected %u\n", |
206 | element->size, | 212 | element->size, |
207 | (unsigned int)sizeof(struct GNUNET_HashCode)); | 213 | (unsigned int) sizeof(struct GNUNET_HashCode)); |
208 | GNUNET_assert(0); | 214 | GNUNET_assert (0); |
209 | } | 215 | } |
210 | 216 | ||
211 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n", | 217 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n", |
212 | info->id, GNUNET_h2s(element->data)); | 218 | info->id, GNUNET_h2s (element->data)); |
213 | GNUNET_assert(NULL != element->data); | 219 | GNUNET_assert (NULL != element->data); |
214 | struct GNUNET_HashCode data_hash; | 220 | struct GNUNET_HashCode data_hash; |
215 | GNUNET_CRYPTO_hash(element->data, element_size, &data_hash); | 221 | GNUNET_CRYPTO_hash (element->data, element_size, &data_hash); |
216 | GNUNET_CONTAINER_multihashmap_put(info->received, | 222 | GNUNET_CONTAINER_multihashmap_put (info->received, |
217 | &data_hash, NULL, | 223 | &data_hash, NULL, |
218 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 224 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
219 | } | 225 | } |
220 | 226 | ||
221 | 227 | ||
222 | static void | 228 | static void |
223 | set_listen_cb(void *cls, | 229 | set_listen_cb (void *cls, |
224 | const struct GNUNET_PeerIdentity *other_peer, | 230 | const struct GNUNET_PeerIdentity *other_peer, |
225 | const struct GNUNET_MessageHeader *context_msg, | 231 | const struct GNUNET_MessageHeader *context_msg, |
226 | struct GNUNET_SET_Request *request) | 232 | struct GNUNET_SET_Request *request) |
227 | { | 233 | { |
228 | /* max. 2 options plus terminator */ | 234 | /* max. 2 options plus terminator */ |
229 | struct GNUNET_SET_Option opts[3] = { { 0 } }; | 235 | struct GNUNET_SET_Option opts[3] = { { 0 } }; |
230 | unsigned int n_opts = 0; | 236 | unsigned int n_opts = 0; |
231 | 237 | ||
232 | if (NULL == request) | 238 | if (NULL == request) |
233 | { | 239 | { |
234 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
235 | "listener failed\n"); | 241 | "listener failed\n"); |
236 | return; | 242 | return; |
237 | } | 243 | } |
238 | GNUNET_assert(NULL == info2.oh); | 244 | GNUNET_assert (NULL == info2.oh); |
239 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
240 | "set listen cb called\n"); | 246 | "set listen cb called\n"); |
241 | if (byzantine) | 247 | if (byzantine) |
242 | { | 248 | { |
243 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; | 249 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = |
244 | } | 250 | GNUNET_SET_OPTION_BYZANTINE }; |
245 | GNUNET_assert(!(force_full && force_delta)); | 251 | } |
252 | GNUNET_assert (! (force_full && force_delta)); | ||
246 | if (force_full) | 253 | if (force_full) |
247 | { | 254 | { |
248 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; | 255 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = |
249 | } | 256 | GNUNET_SET_OPTION_FORCE_FULL }; |
257 | } | ||
250 | if (force_delta) | 258 | if (force_delta) |
251 | { | 259 | { |
252 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; | 260 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = |
253 | } | 261 | GNUNET_SET_OPTION_FORCE_DELTA }; |
262 | } | ||
254 | 263 | ||
255 | opts[n_opts].type = 0; | 264 | opts[n_opts].type = 0; |
256 | info2.oh = GNUNET_SET_accept(request, GNUNET_SET_RESULT_SYMMETRIC, | 265 | info2.oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_SYMMETRIC, |
257 | opts, | 266 | opts, |
258 | set_result_cb, &info2); | 267 | set_result_cb, &info2); |
259 | GNUNET_SET_commit(info2.oh, info2.set); | 268 | GNUNET_SET_commit (info2.oh, info2.set); |
260 | } | 269 | } |
261 | 270 | ||
262 | 271 | ||
263 | static int | 272 | static int |
264 | set_insert_iterator(void *cls, | 273 | set_insert_iterator (void *cls, |
265 | const struct GNUNET_HashCode *key, | 274 | const struct GNUNET_HashCode *key, |
266 | void *value) | 275 | void *value) |
267 | { | 276 | { |
268 | struct GNUNET_SET_Handle *set = cls; | 277 | struct GNUNET_SET_Handle *set = cls; |
269 | struct GNUNET_SET_Element el; | 278 | struct GNUNET_SET_Element el; |
@@ -271,49 +280,49 @@ set_insert_iterator(void *cls, | |||
271 | el.element_type = 0; | 280 | el.element_type = 0; |
272 | el.data = value; | 281 | el.data = value; |
273 | el.size = element_size; | 282 | el.size = element_size; |
274 | GNUNET_SET_add_element(set, &el, NULL, NULL); | 283 | GNUNET_SET_add_element (set, &el, NULL, NULL); |
275 | return GNUNET_YES; | 284 | return GNUNET_YES; |
276 | } | 285 | } |
277 | 286 | ||
278 | 287 | ||
279 | static void | 288 | static void |
280 | handle_shutdown(void *cls) | 289 | handle_shutdown (void *cls) |
281 | { | 290 | { |
282 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 291 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
283 | "Shutting down set profiler\n"); | 292 | "Shutting down set profiler\n"); |
284 | if (NULL != set_listener) | 293 | if (NULL != set_listener) |
285 | { | 294 | { |
286 | GNUNET_SET_listen_cancel(set_listener); | 295 | GNUNET_SET_listen_cancel (set_listener); |
287 | set_listener = NULL; | 296 | set_listener = NULL; |
288 | } | 297 | } |
289 | if (NULL != info1.oh) | 298 | if (NULL != info1.oh) |
290 | { | 299 | { |
291 | GNUNET_SET_operation_cancel(info1.oh); | 300 | GNUNET_SET_operation_cancel (info1.oh); |
292 | info1.oh = NULL; | 301 | info1.oh = NULL; |
293 | } | 302 | } |
294 | if (NULL != info2.oh) | 303 | if (NULL != info2.oh) |
295 | { | 304 | { |
296 | GNUNET_SET_operation_cancel(info2.oh); | 305 | GNUNET_SET_operation_cancel (info2.oh); |
297 | info2.oh = NULL; | 306 | info2.oh = NULL; |
298 | } | 307 | } |
299 | if (NULL != info1.set) | 308 | if (NULL != info1.set) |
300 | { | 309 | { |
301 | GNUNET_SET_destroy(info1.set); | 310 | GNUNET_SET_destroy (info1.set); |
302 | info1.set = NULL; | 311 | info1.set = NULL; |
303 | } | 312 | } |
304 | if (NULL != info2.set) | 313 | if (NULL != info2.set) |
305 | { | 314 | { |
306 | GNUNET_SET_destroy(info2.set); | 315 | GNUNET_SET_destroy (info2.set); |
307 | info2.set = NULL; | 316 | info2.set = NULL; |
308 | } | 317 | } |
309 | GNUNET_STATISTICS_destroy(statistics, GNUNET_NO); | 318 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); |
310 | } | 319 | } |
311 | 320 | ||
312 | 321 | ||
313 | static void | 322 | static void |
314 | run(void *cls, | 323 | run (void *cls, |
315 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 324 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
316 | struct GNUNET_TESTING_Peer *peer) | 325 | struct GNUNET_TESTING_Peer *peer) |
317 | { | 326 | { |
318 | unsigned int i; | 327 | unsigned int i; |
319 | struct GNUNET_HashCode hash; | 328 | struct GNUNET_HashCode hash; |
@@ -323,170 +332,177 @@ run(void *cls, | |||
323 | 332 | ||
324 | config = cfg; | 333 | config = cfg; |
325 | 334 | ||
326 | GNUNET_assert(element_size > 0); | 335 | GNUNET_assert (element_size > 0); |
327 | 336 | ||
328 | if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity(cfg, &local_peer)) | 337 | if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &local_peer)) |
329 | { | 338 | { |
330 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); | 339 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); |
331 | ret = 0; | 340 | ret = 0; |
332 | return; | 341 | return; |
333 | } | 342 | } |
334 | 343 | ||
335 | statistics = GNUNET_STATISTICS_create("set-profiler", cfg); | 344 | statistics = GNUNET_STATISTICS_create ("set-profiler", cfg); |
336 | 345 | ||
337 | GNUNET_SCHEDULER_add_shutdown(&handle_shutdown, NULL); | 346 | GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL); |
338 | 347 | ||
339 | info1.id = "a"; | 348 | info1.id = "a"; |
340 | info2.id = "b"; | 349 | info2.id = "b"; |
341 | 350 | ||
342 | info1.sent = GNUNET_CONTAINER_multihashmap_create(num_a + 1, GNUNET_NO); | 351 | info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO); |
343 | info2.sent = GNUNET_CONTAINER_multihashmap_create(num_b + 1, GNUNET_NO); | 352 | info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO); |
344 | common_sent = GNUNET_CONTAINER_multihashmap_create(num_c + 1, GNUNET_NO); | 353 | common_sent = GNUNET_CONTAINER_multihashmap_create (num_c + 1, GNUNET_NO); |
345 | 354 | ||
346 | info1.received = GNUNET_CONTAINER_multihashmap_create(num_a + 1, GNUNET_NO); | 355 | info1.received = GNUNET_CONTAINER_multihashmap_create (num_a + 1, GNUNET_NO); |
347 | info2.received = GNUNET_CONTAINER_multihashmap_create(num_b + 1, GNUNET_NO); | 356 | info2.received = GNUNET_CONTAINER_multihashmap_create (num_b + 1, GNUNET_NO); |
348 | 357 | ||
349 | for (i = 0; i < num_a; i++) | 358 | for (i = 0; i < num_a; i++) |
350 | { | 359 | { |
351 | char *data = GNUNET_malloc(element_size); | 360 | char *data = GNUNET_malloc (element_size); |
352 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); | 361 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); |
353 | GNUNET_CRYPTO_hash(data, element_size, &hash); | 362 | GNUNET_CRYPTO_hash (data, element_size, &hash); |
354 | GNUNET_CONTAINER_multihashmap_put(info1.sent, &hash, data, | 363 | GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, data, |
355 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 364 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
356 | } | 365 | } |
357 | 366 | ||
358 | for (i = 0; i < num_b; i++) | 367 | for (i = 0; i < num_b; i++) |
359 | { | 368 | { |
360 | char *data = GNUNET_malloc(element_size); | 369 | char *data = GNUNET_malloc (element_size); |
361 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); | 370 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); |
362 | GNUNET_CRYPTO_hash(data, element_size, &hash); | 371 | GNUNET_CRYPTO_hash (data, element_size, &hash); |
363 | GNUNET_CONTAINER_multihashmap_put(info2.sent, &hash, data, | 372 | GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, data, |
364 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 373 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
365 | } | 374 | } |
366 | 375 | ||
367 | for (i = 0; i < num_c; i++) | 376 | for (i = 0; i < num_c; i++) |
368 | { | 377 | { |
369 | char *data = GNUNET_malloc(element_size); | 378 | char *data = GNUNET_malloc (element_size); |
370 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); | 379 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, data, element_size); |
371 | GNUNET_CRYPTO_hash(data, element_size, &hash); | 380 | GNUNET_CRYPTO_hash (data, element_size, &hash); |
372 | GNUNET_CONTAINER_multihashmap_put(common_sent, &hash, data, | 381 | GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, data, |
373 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 382 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
374 | } | 383 | } |
375 | 384 | ||
376 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_STRONG, &app_id); | 385 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &app_id); |
377 | 386 | ||
378 | /* FIXME: also implement intersection etc. */ | 387 | /* FIXME: also implement intersection etc. */ |
379 | info1.set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); | 388 | info1.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); |
380 | info2.set = GNUNET_SET_create(config, GNUNET_SET_OPERATION_UNION); | 389 | info2.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); |
381 | 390 | ||
382 | GNUNET_CONTAINER_multihashmap_iterate(info1.sent, set_insert_iterator, info1.set); | 391 | GNUNET_CONTAINER_multihashmap_iterate (info1.sent, set_insert_iterator, |
383 | GNUNET_CONTAINER_multihashmap_iterate(info2.sent, set_insert_iterator, info2.set); | 392 | info1.set); |
384 | GNUNET_CONTAINER_multihashmap_iterate(common_sent, set_insert_iterator, info1.set); | 393 | GNUNET_CONTAINER_multihashmap_iterate (info2.sent, set_insert_iterator, |
385 | GNUNET_CONTAINER_multihashmap_iterate(common_sent, set_insert_iterator, info2.set); | 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); | ||
386 | 399 | ||
387 | set_listener = GNUNET_SET_listen(config, GNUNET_SET_OPERATION_UNION, | 400 | set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, |
388 | &app_id, set_listen_cb, NULL); | 401 | &app_id, set_listen_cb, NULL); |
389 | 402 | ||
390 | 403 | ||
391 | if (byzantine) | 404 | if (byzantine) |
392 | { | 405 | { |
393 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_BYZANTINE }; | 406 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = |
394 | } | 407 | GNUNET_SET_OPTION_BYZANTINE }; |
395 | GNUNET_assert(!(force_full && force_delta)); | 408 | } |
409 | GNUNET_assert (! (force_full && force_delta)); | ||
396 | if (force_full) | 410 | if (force_full) |
397 | { | 411 | { |
398 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_FULL }; | 412 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = |
399 | } | 413 | GNUNET_SET_OPTION_FORCE_FULL }; |
414 | } | ||
400 | if (force_delta) | 415 | if (force_delta) |
401 | { | 416 | { |
402 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = GNUNET_SET_OPTION_FORCE_DELTA }; | 417 | opts[n_opts++] = (struct GNUNET_SET_Option) { .type = |
403 | } | 418 | GNUNET_SET_OPTION_FORCE_DELTA }; |
419 | } | ||
404 | 420 | ||
405 | opts[n_opts].type = 0; | 421 | opts[n_opts].type = 0; |
406 | 422 | ||
407 | info1.oh = GNUNET_SET_prepare(&local_peer, &app_id, NULL, | 423 | info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL, |
408 | GNUNET_SET_RESULT_SYMMETRIC, | 424 | GNUNET_SET_RESULT_SYMMETRIC, |
409 | opts, | 425 | opts, |
410 | set_result_cb, &info1); | 426 | set_result_cb, &info1); |
411 | GNUNET_SET_commit(info1.oh, info1.set); | 427 | GNUNET_SET_commit (info1.oh, info1.set); |
412 | GNUNET_SET_destroy(info1.set); | 428 | GNUNET_SET_destroy (info1.set); |
413 | info1.set = NULL; | 429 | info1.set = NULL; |
414 | } | 430 | } |
415 | 431 | ||
416 | 432 | ||
417 | static void | 433 | static void |
418 | pre_run(void *cls, char *const *args, const char *cfgfile, | 434 | pre_run (void *cls, char *const *args, const char *cfgfile, |
419 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 435 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
420 | { | 436 | { |
421 | if (0 != GNUNET_TESTING_peer_run("set-profiler", | 437 | if (0 != GNUNET_TESTING_peer_run ("set-profiler", |
422 | cfgfile, | 438 | cfgfile, |
423 | &run, NULL)) | 439 | &run, NULL)) |
424 | ret = 2; | 440 | ret = 2; |
425 | } | 441 | } |
426 | 442 | ||
427 | 443 | ||
428 | int | 444 | int |
429 | main(int argc, char **argv) | 445 | main (int argc, char **argv) |
430 | { | 446 | { |
431 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 447 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
432 | GNUNET_GETOPT_option_uint('A', | 448 | GNUNET_GETOPT_option_uint ('A', |
433 | "num-first", | 449 | "num-first", |
434 | NULL, | 450 | NULL, |
435 | gettext_noop("number of values"), | 451 | gettext_noop ("number of values"), |
436 | &num_a), | 452 | &num_a), |
437 | 453 | ||
438 | GNUNET_GETOPT_option_uint('B', | 454 | GNUNET_GETOPT_option_uint ('B', |
439 | "num-second", | 455 | "num-second", |
440 | NULL, | 456 | NULL, |
441 | gettext_noop("number of values"), | 457 | gettext_noop ("number of values"), |
442 | &num_b), | 458 | &num_b), |
443 | 459 | ||
444 | GNUNET_GETOPT_option_flag('b', | 460 | GNUNET_GETOPT_option_flag ('b', |
445 | "byzantine", | 461 | "byzantine", |
446 | gettext_noop("use byzantine mode"), | 462 | gettext_noop ("use byzantine mode"), |
447 | &byzantine), | 463 | &byzantine), |
448 | 464 | ||
449 | GNUNET_GETOPT_option_uint('f', | 465 | GNUNET_GETOPT_option_uint ('f', |
450 | "force-full", | 466 | "force-full", |
451 | NULL, | 467 | NULL, |
452 | gettext_noop("force sending full set"), | 468 | gettext_noop ("force sending full set"), |
453 | &force_full), | 469 | &force_full), |
454 | 470 | ||
455 | GNUNET_GETOPT_option_uint('d', | 471 | GNUNET_GETOPT_option_uint ('d', |
456 | "force-delta", | 472 | "force-delta", |
457 | NULL, | 473 | NULL, |
458 | gettext_noop("number delta operation"), | 474 | gettext_noop ("number delta operation"), |
459 | &force_delta), | 475 | &force_delta), |
460 | 476 | ||
461 | GNUNET_GETOPT_option_uint('C', | 477 | GNUNET_GETOPT_option_uint ('C', |
462 | "num-common", | 478 | "num-common", |
463 | NULL, | 479 | NULL, |
464 | gettext_noop("number of values"), | 480 | gettext_noop ("number of values"), |
465 | &num_c), | 481 | &num_c), |
466 | 482 | ||
467 | GNUNET_GETOPT_option_string('x', | 483 | GNUNET_GETOPT_option_string ('x', |
468 | "operation", | 484 | "operation", |
469 | NULL, | 485 | NULL, |
470 | gettext_noop("operation to execute"), | 486 | gettext_noop ("operation to execute"), |
471 | &op_str), | 487 | &op_str), |
472 | 488 | ||
473 | GNUNET_GETOPT_option_uint('w', | 489 | GNUNET_GETOPT_option_uint ('w', |
474 | "element-size", | 490 | "element-size", |
475 | NULL, | 491 | NULL, |
476 | gettext_noop("element size"), | 492 | gettext_noop ("element size"), |
477 | &element_size), | 493 | &element_size), |
478 | 494 | ||
479 | GNUNET_GETOPT_option_filename('s', | 495 | GNUNET_GETOPT_option_filename ('s', |
480 | "statistics", | 496 | "statistics", |
481 | "FILENAME", | 497 | "FILENAME", |
482 | gettext_noop("write statistics to file"), | 498 | gettext_noop ("write statistics to file"), |
483 | &statistics_filename), | 499 | &statistics_filename), |
484 | 500 | ||
485 | GNUNET_GETOPT_OPTION_END | 501 | GNUNET_GETOPT_OPTION_END |
486 | }; | 502 | }; |
487 | 503 | ||
488 | GNUNET_PROGRAM_run2(argc, argv, "gnunet-set-profiler", | 504 | GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler", |
489 | "help", | 505 | "help", |
490 | options, &pre_run, NULL, GNUNET_YES); | 506 | options, &pre_run, NULL, GNUNET_YES); |
491 | return ret; | 507 | return ret; |
492 | } | 508 | } |