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