diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/secretsharing/gnunet-secretsharing-profiler.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/secretsharing/gnunet-secretsharing-profiler.c')
-rw-r--r-- | src/secretsharing/gnunet-secretsharing-profiler.c | 518 |
1 files changed, 268 insertions, 250 deletions
diff --git a/src/secretsharing/gnunet-secretsharing-profiler.c b/src/secretsharing/gnunet-secretsharing-profiler.c index 0bd2cc6a9..38163e2c2 100644 --- a/src/secretsharing/gnunet-secretsharing-profiler.c +++ b/src/secretsharing/gnunet-secretsharing-profiler.c | |||
@@ -122,10 +122,10 @@ static int in_shutdown; | |||
122 | * @param event information about the event | 122 | * @param event information about the event |
123 | */ | 123 | */ |
124 | static void | 124 | static void |
125 | controller_cb(void *cls, | 125 | controller_cb (void *cls, |
126 | const struct GNUNET_TESTBED_EventInformation *event) | 126 | const struct GNUNET_TESTBED_EventInformation *event) |
127 | { | 127 | { |
128 | GNUNET_assert(0); | 128 | GNUNET_assert (0); |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
@@ -139,29 +139,29 @@ controller_cb(void *cls, | |||
139 | * operation has executed successfully. | 139 | * operation has executed successfully. |
140 | */ | 140 | */ |
141 | static void | 141 | static void |
142 | session_connect_complete(void *cls, | 142 | session_connect_complete (void *cls, |
143 | struct GNUNET_TESTBED_Operation *op, | 143 | struct GNUNET_TESTBED_Operation *op, |
144 | void *ca_result, | 144 | void *ca_result, |
145 | const char *emsg) | 145 | const char *emsg) |
146 | { | 146 | { |
147 | if (NULL != emsg) | 147 | if (NULL != emsg) |
148 | { | 148 | { |
149 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 149 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
150 | "testbed connect emsg: %s\n", | 150 | "testbed connect emsg: %s\n", |
151 | emsg); | 151 | emsg); |
152 | GNUNET_assert(0); | 152 | GNUNET_assert (0); |
153 | } | 153 | } |
154 | 154 | ||
155 | num_connected_sessions++; | 155 | num_connected_sessions++; |
156 | 156 | ||
157 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 157 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
158 | "dkg: session connect complete\n"); | 158 | "dkg: session connect complete\n"); |
159 | 159 | ||
160 | if (num_connected_sessions == num_peers) | 160 | if (num_connected_sessions == num_peers) |
161 | { | 161 | { |
162 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
163 | "dkg: all peers connected\n"); | 163 | "dkg: all peers connected\n"); |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
@@ -175,29 +175,29 @@ session_connect_complete(void *cls, | |||
175 | * operation has executed successfully. | 175 | * operation has executed successfully. |
176 | */ | 176 | */ |
177 | static void | 177 | static void |
178 | decrypt_connect_complete(void *cls, | 178 | decrypt_connect_complete (void *cls, |
179 | struct GNUNET_TESTBED_Operation *op, | 179 | struct GNUNET_TESTBED_Operation *op, |
180 | void *ca_result, | 180 | void *ca_result, |
181 | const char *emsg) | 181 | const char *emsg) |
182 | { | 182 | { |
183 | if (NULL != emsg) | 183 | if (NULL != emsg) |
184 | { | 184 | { |
185 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 185 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
186 | "testbed connect emsg: %s\n", | 186 | "testbed connect emsg: %s\n", |
187 | emsg); | 187 | emsg); |
188 | GNUNET_assert(0); | 188 | GNUNET_assert (0); |
189 | } | 189 | } |
190 | 190 | ||
191 | num_connected_decrypt++; | 191 | num_connected_decrypt++; |
192 | 192 | ||
193 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 193 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
194 | "decrypt: session connect complete\n"); | 194 | "decrypt: session connect complete\n"); |
195 | 195 | ||
196 | if (num_connected_decrypt == num_peers) | 196 | if (num_connected_decrypt == num_peers) |
197 | { | 197 | { |
198 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 198 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
199 | "decrypt: all peers connected\n"); | 199 | "decrypt: all peers connected\n"); |
200 | } | 200 | } |
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
@@ -207,8 +207,8 @@ decrypt_connect_complete(void *cls, | |||
207 | * @param cls Plaintext | 207 | * @param cls Plaintext |
208 | * @param plaintext Plaintext | 208 | * @param plaintext Plaintext |
209 | */ | 209 | */ |
210 | static void decrypt_cb(void *cls, | 210 | static void decrypt_cb (void *cls, |
211 | const struct GNUNET_SECRETSHARING_Plaintext *plaintext) | 211 | const struct GNUNET_SECRETSHARING_Plaintext *plaintext) |
212 | { | 212 | { |
213 | struct GNUNET_SECRETSHARING_DecryptionHandle **dhp = cls; | 213 | struct GNUNET_SECRETSHARING_DecryptionHandle **dhp = cls; |
214 | unsigned int n = dhp - decrypt_handles; | 214 | unsigned int n = dhp - decrypt_handles; |
@@ -218,25 +218,27 @@ static void decrypt_cb(void *cls, | |||
218 | *dhp = NULL; | 218 | *dhp = NULL; |
219 | 219 | ||
220 | // we should still be connected if this is called | 220 | // we should still be connected if this is called |
221 | GNUNET_assert(NULL != connect_ops[n]); | 221 | GNUNET_assert (NULL != connect_ops[n]); |
222 | 222 | ||
223 | GNUNET_TESTBED_operation_done(connect_ops[n]); | 223 | GNUNET_TESTBED_operation_done (connect_ops[n]); |
224 | 224 | ||
225 | if (NULL == plaintext) | 225 | if (NULL == plaintext) |
226 | { | 226 | { |
227 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "decrypt failed for peer %u\n", n); | 227 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decrypt failed for peer %u\n", n); |
228 | return; | 228 | return; |
229 | } | 229 | } |
230 | else if (0 == GNUNET_memcmp(&reference_plaintext, plaintext)) | 230 | else if (0 == GNUNET_memcmp (&reference_plaintext, plaintext)) |
231 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "decrypt got correct result for peer %u\n", n); | 231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
232 | "decrypt got correct result for peer %u\n", n); | ||
232 | else | 233 | else |
233 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "decrypt got wrong result for peer %u\n", n); | 234 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
235 | "decrypt got wrong result for peer %u\n", n); | ||
234 | 236 | ||
235 | if (num_decrypted == num_peers) | 237 | if (num_decrypted == num_peers) |
236 | { | 238 | { |
237 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "every peer decrypted\n"); | 239 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "every peer decrypted\n"); |
238 | GNUNET_SCHEDULER_shutdown(); | 240 | GNUNET_SCHEDULER_shutdown (); |
239 | } | 241 | } |
240 | 242 | ||
241 | *dhp = NULL; | 243 | *dhp = NULL; |
242 | } | 244 | } |
@@ -254,19 +256,19 @@ static void decrypt_cb(void *cls, | |||
254 | * @return service handle to return in 'op_result', NULL on error | 256 | * @return service handle to return in 'op_result', NULL on error |
255 | */ | 257 | */ |
256 | static void * | 258 | static void * |
257 | decrypt_connect_adapter(void *cls, | 259 | decrypt_connect_adapter (void *cls, |
258 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 260 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
259 | { | 261 | { |
260 | struct GNUNET_SECRETSHARING_DecryptionHandle **hp = cls; | 262 | struct GNUNET_SECRETSHARING_DecryptionHandle **hp = cls; |
261 | unsigned int n = hp - decrypt_handles; | 263 | unsigned int n = hp - decrypt_handles; |
262 | 264 | ||
263 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 265 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
264 | "decrypt connect adapter, %d peers\n", | 266 | "decrypt connect adapter, %d peers\n", |
265 | num_peers); | 267 | num_peers); |
266 | *hp = GNUNET_SECRETSHARING_decrypt(cfg, shares[n], &ciphertext, | 268 | *hp = GNUNET_SECRETSHARING_decrypt (cfg, shares[n], &ciphertext, |
267 | decrypt_start, decrypt_deadline, | 269 | decrypt_start, decrypt_deadline, |
268 | decrypt_cb, | 270 | decrypt_cb, |
269 | hp); | 271 | hp); |
270 | 272 | ||
271 | return *hp; | 273 | return *hp; |
272 | } | 274 | } |
@@ -280,30 +282,30 @@ decrypt_connect_adapter(void *cls, | |||
280 | * @param op_result service handle returned from the connect adapter | 282 | * @param op_result service handle returned from the connect adapter |
281 | */ | 283 | */ |
282 | static void | 284 | static void |
283 | decrypt_disconnect_adapter(void *cls, void *op_result) | 285 | decrypt_disconnect_adapter (void *cls, void *op_result) |
284 | { | 286 | { |
285 | struct GNUNET_SECRETSHARING_DecryptionHandle **dh = cls; | 287 | struct GNUNET_SECRETSHARING_DecryptionHandle **dh = cls; |
286 | unsigned int n = dh - decrypt_handles; | 288 | unsigned int n = dh - decrypt_handles; |
287 | 289 | ||
288 | GNUNET_assert(*dh == decrypt_handles[n]); | 290 | GNUNET_assert (*dh == decrypt_handles[n]); |
289 | 291 | ||
290 | if (NULL != *dh) | 292 | if (NULL != *dh) |
291 | { | 293 | { |
292 | GNUNET_SECRETSHARING_decrypt_cancel(*dh); | 294 | GNUNET_SECRETSHARING_decrypt_cancel (*dh); |
293 | *dh = NULL; | 295 | *dh = NULL; |
294 | } | 296 | } |
295 | 297 | ||
296 | GNUNET_assert(NULL != connect_ops[n]); | 298 | GNUNET_assert (NULL != connect_ops[n]); |
297 | connect_ops[n] = NULL; | 299 | connect_ops[n] = NULL; |
298 | } | 300 | } |
299 | 301 | ||
300 | 302 | ||
301 | static void | 303 | static void |
302 | secret_ready_cb(void *cls, | 304 | secret_ready_cb (void *cls, |
303 | struct GNUNET_SECRETSHARING_Share *my_share, | 305 | struct GNUNET_SECRETSHARING_Share *my_share, |
304 | struct GNUNET_SECRETSHARING_PublicKey *public_key, | 306 | struct GNUNET_SECRETSHARING_PublicKey *public_key, |
305 | unsigned int num_ready_peers, | 307 | unsigned int num_ready_peers, |
306 | const struct GNUNET_PeerIdentity *ready_peers) | 308 | const struct GNUNET_PeerIdentity *ready_peers) |
307 | { | 309 | { |
308 | struct GNUNET_SECRETSHARING_Session **sp = cls; | 310 | struct GNUNET_SECRETSHARING_Session **sp = cls; |
309 | unsigned int n = sp - session_handles; | 311 | unsigned int n = sp - session_handles; |
@@ -314,35 +316,39 @@ secret_ready_cb(void *cls, | |||
314 | *sp = NULL; | 316 | *sp = NULL; |
315 | shares[n] = my_share; | 317 | shares[n] = my_share; |
316 | if (NULL == my_share) | 318 | if (NULL == my_share) |
319 | { | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "key generation failed for peer #%u\n", | ||
321 | n); | ||
322 | } | ||
323 | else | ||
324 | { | ||
325 | ret = GNUNET_STRINGS_data_to_string (public_key, sizeof *public_key, | ||
326 | pubkey_str, 1024); | ||
327 | GNUNET_assert (NULL != ret); | ||
328 | *ret = '\0'; | ||
329 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
330 | "key generation successful for peer #%u, pubkey %s\n", n, | ||
331 | pubkey_str); | ||
332 | |||
333 | /* we're the first to get the key -> store it */ | ||
334 | if (num_generated == 1) | ||
317 | { | 335 | { |
318 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "key generation failed for peer #%u\n", n); | 336 | common_pubkey = *public_key; |
319 | } | 337 | } |
320 | else | 338 | else if (0 != GNUNET_memcmp (public_key, &common_pubkey)) |
321 | { | 339 | { |
322 | ret = GNUNET_STRINGS_data_to_string(public_key, sizeof *public_key, pubkey_str, 1024); | 340 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
323 | GNUNET_assert(NULL != ret); | 341 | "generated public keys do not match\n"); |
324 | *ret = '\0'; | 342 | GNUNET_SCHEDULER_shutdown (); |
325 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "key generation successful for peer #%u, pubkey %s\n", n, | 343 | return; |
326 | pubkey_str); | ||
327 | |||
328 | /* we're the first to get the key -> store it */ | ||
329 | if (num_generated == 1) | ||
330 | { | ||
331 | common_pubkey = *public_key; | ||
332 | } | ||
333 | else if (0 != GNUNET_memcmp(public_key, &common_pubkey)) | ||
334 | { | ||
335 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "generated public keys do not match\n"); | ||
336 | GNUNET_SCHEDULER_shutdown(); | ||
337 | return; | ||
338 | } | ||
339 | } | 344 | } |
345 | } | ||
340 | 346 | ||
341 | // we should still be connected | 347 | // we should still be connected |
342 | GNUNET_assert(NULL != connect_ops[n]); | 348 | GNUNET_assert (NULL != connect_ops[n]); |
343 | 349 | ||
344 | // disconnect from the service, will call the disconnect callback | 350 | // disconnect from the service, will call the disconnect callback |
345 | GNUNET_TESTBED_operation_done(connect_ops[n]); | 351 | GNUNET_TESTBED_operation_done (connect_ops[n]); |
346 | } | 352 | } |
347 | 353 | ||
348 | 354 | ||
@@ -357,22 +363,22 @@ secret_ready_cb(void *cls, | |||
357 | * @return service handle to return in 'op_result', NULL on error | 363 | * @return service handle to return in 'op_result', NULL on error |
358 | */ | 364 | */ |
359 | static void * | 365 | static void * |
360 | session_connect_adapter(void *cls, | 366 | session_connect_adapter (void *cls, |
361 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 367 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
362 | { | 368 | { |
363 | struct GNUNET_SECRETSHARING_Session **sp = cls; | 369 | struct GNUNET_SECRETSHARING_Session **sp = cls; |
364 | 370 | ||
365 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 371 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
366 | "connect adapter, %d peers\n", | 372 | "connect adapter, %d peers\n", |
367 | num_peers); | 373 | num_peers); |
368 | *sp = GNUNET_SECRETSHARING_create_session(cfg, | 374 | *sp = GNUNET_SECRETSHARING_create_session (cfg, |
369 | num_peers, | 375 | num_peers, |
370 | peer_ids, | 376 | peer_ids, |
371 | &session_id, | 377 | &session_id, |
372 | dkg_start, | 378 | dkg_start, |
373 | dkg_deadline, | 379 | dkg_deadline, |
374 | threshold, | 380 | threshold, |
375 | &secret_ready_cb, sp); | 381 | &secret_ready_cb, sp); |
376 | return *sp; | 382 | return *sp; |
377 | } | 383 | } |
378 | 384 | ||
@@ -386,20 +392,20 @@ session_connect_adapter(void *cls, | |||
386 | * @param op_result service handle returned from the connect adapter | 392 | * @param op_result service handle returned from the connect adapter |
387 | */ | 393 | */ |
388 | static void | 394 | static void |
389 | session_disconnect_adapter(void *cls, void *op_result) | 395 | session_disconnect_adapter (void *cls, void *op_result) |
390 | { | 396 | { |
391 | struct GNUNET_SECRETSHARING_Session **sp = cls; | 397 | struct GNUNET_SECRETSHARING_Session **sp = cls; |
392 | unsigned int n = (sp - session_handles); | 398 | unsigned int n = (sp - session_handles); |
393 | 399 | ||
394 | GNUNET_assert(*sp == session_handles[n]); | 400 | GNUNET_assert (*sp == session_handles[n]); |
395 | 401 | ||
396 | if (NULL != *sp) | 402 | if (NULL != *sp) |
397 | { | 403 | { |
398 | GNUNET_SECRETSHARING_session_destroy(*sp); | 404 | GNUNET_SECRETSHARING_session_destroy (*sp); |
399 | *sp = NULL; | 405 | *sp = NULL; |
400 | } | 406 | } |
401 | 407 | ||
402 | GNUNET_assert(NULL != connect_ops[n]); | 408 | GNUNET_assert (NULL != connect_ops[n]); |
403 | connect_ops[n] = NULL; | 409 | connect_ops[n] = NULL; |
404 | 410 | ||
405 | if (GNUNET_YES == in_shutdown) | 411 | if (GNUNET_YES == in_shutdown) |
@@ -407,29 +413,34 @@ session_disconnect_adapter(void *cls, void *op_result) | |||
407 | 413 | ||
408 | // all peers received their secret | 414 | // all peers received their secret |
409 | if (num_generated == num_peers) | 415 | if (num_generated == num_peers) |
410 | { | 416 | { |
411 | int i; | 417 | int i; |
412 | |||
413 | // only do decryption if requested by the user | ||
414 | if (GNUNET_NO == decrypt) | ||
415 | { | ||
416 | GNUNET_SCHEDULER_shutdown(); | ||
417 | return; | ||
418 | } | ||
419 | |||
420 | decrypt_start = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); | ||
421 | decrypt_deadline = GNUNET_TIME_absolute_add(decrypt_start, timeout); | ||
422 | |||
423 | // compute g^42 as the plaintext which we will decrypt and then | ||
424 | // cooperatively decrypt | ||
425 | GNUNET_SECRETSHARING_plaintext_generate_i(&reference_plaintext, 42); | ||
426 | GNUNET_SECRETSHARING_encrypt(&common_pubkey, &reference_plaintext, &ciphertext); | ||
427 | 418 | ||
428 | for (i = 0; i < num_peers; i++) | 419 | // only do decryption if requested by the user |
429 | connect_ops[i] = | 420 | if (GNUNET_NO == decrypt) |
430 | GNUNET_TESTBED_service_connect(NULL, peers[i], "secretsharing", &decrypt_connect_complete, NULL, | 421 | { |
431 | &decrypt_connect_adapter, &decrypt_disconnect_adapter, &decrypt_handles[i]); | 422 | GNUNET_SCHEDULER_shutdown (); |
423 | return; | ||
432 | } | 424 | } |
425 | |||
426 | decrypt_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | ||
427 | delay); | ||
428 | decrypt_deadline = GNUNET_TIME_absolute_add (decrypt_start, timeout); | ||
429 | |||
430 | // compute g^42 as the plaintext which we will decrypt and then | ||
431 | // cooperatively decrypt | ||
432 | GNUNET_SECRETSHARING_plaintext_generate_i (&reference_plaintext, 42); | ||
433 | GNUNET_SECRETSHARING_encrypt (&common_pubkey, &reference_plaintext, | ||
434 | &ciphertext); | ||
435 | |||
436 | for (i = 0; i < num_peers; i++) | ||
437 | connect_ops[i] = | ||
438 | GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", | ||
439 | &decrypt_connect_complete, NULL, | ||
440 | &decrypt_connect_adapter, | ||
441 | &decrypt_disconnect_adapter, | ||
442 | &decrypt_handles[i]); | ||
443 | } | ||
433 | } | 444 | } |
434 | 445 | ||
435 | 446 | ||
@@ -443,34 +454,37 @@ session_disconnect_adapter(void *cls, void *op_result) | |||
443 | * operation is successfull | 454 | * operation is successfull |
444 | */ | 455 | */ |
445 | static void | 456 | static void |
446 | peer_info_cb(void *cb_cls, | 457 | peer_info_cb (void *cb_cls, |
447 | struct GNUNET_TESTBED_Operation *op, | 458 | struct GNUNET_TESTBED_Operation *op, |
448 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 459 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
449 | const char *emsg) | 460 | const char *emsg) |
450 | { | 461 | { |
451 | struct GNUNET_PeerIdentity *p; | 462 | struct GNUNET_PeerIdentity *p; |
452 | int i; | 463 | int i; |
453 | 464 | ||
454 | GNUNET_assert(NULL == emsg); | 465 | GNUNET_assert (NULL == emsg); |
455 | 466 | ||
456 | p = (struct GNUNET_PeerIdentity *)cb_cls; | 467 | p = (struct GNUNET_PeerIdentity *) cb_cls; |
457 | 468 | ||
458 | if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY) | 469 | if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY) |
459 | { | 470 | { |
460 | *p = *pinfo->result.id; | 471 | *p = *pinfo->result.id; |
461 | num_retrieved_peer_ids++; | 472 | num_retrieved_peer_ids++; |
462 | if (num_retrieved_peer_ids == num_peers) | 473 | if (num_retrieved_peer_ids == num_peers) |
463 | for (i = 0; i < num_peers; i++) | 474 | for (i = 0; i < num_peers; i++) |
464 | connect_ops[i] = | 475 | connect_ops[i] = |
465 | GNUNET_TESTBED_service_connect(NULL, peers[i], "secretsharing", session_connect_complete, NULL, | 476 | GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", |
466 | session_connect_adapter, session_disconnect_adapter, &session_handles[i]); | 477 | session_connect_complete, NULL, |
467 | } | 478 | session_connect_adapter, |
479 | session_disconnect_adapter, | ||
480 | &session_handles[i]); | ||
481 | } | ||
468 | else | 482 | else |
469 | { | 483 | { |
470 | GNUNET_assert(0); | 484 | GNUNET_assert (0); |
471 | } | 485 | } |
472 | 486 | ||
473 | GNUNET_TESTBED_operation_done(op); | 487 | GNUNET_TESTBED_operation_done (op); |
474 | } | 488 | } |
475 | 489 | ||
476 | 490 | ||
@@ -480,21 +494,21 @@ peer_info_cb(void *cb_cls, | |||
480 | * @param cls closure | 494 | * @param cls closure |
481 | */ | 495 | */ |
482 | static void | 496 | static void |
483 | handle_shutdown(void *cls) | 497 | handle_shutdown (void *cls) |
484 | { | 498 | { |
485 | in_shutdown = GNUNET_YES; | 499 | in_shutdown = GNUNET_YES; |
486 | 500 | ||
487 | if (NULL != connect_ops) | 501 | if (NULL != connect_ops) |
488 | { | 502 | { |
489 | unsigned int i; | 503 | unsigned int i; |
490 | for (i = 0; i < num_peers; i++) | 504 | for (i = 0; i < num_peers; i++) |
491 | if (NULL != connect_ops[i]) | 505 | if (NULL != connect_ops[i]) |
492 | { | 506 | { |
493 | // the disconnect callback will set the op to NULL | 507 | // the disconnect callback will set the op to NULL |
494 | GNUNET_TESTBED_operation_done(connect_ops[i]); | 508 | GNUNET_TESTBED_operation_done (connect_ops[i]); |
495 | } | 509 | } |
496 | GNUNET_free(connect_ops); | 510 | GNUNET_free (connect_ops); |
497 | } | 511 | } |
498 | 512 | ||
499 | // killing the testbed operation will take care of remaining | 513 | // killing the testbed operation will take care of remaining |
500 | // service handles in the disconnect callback | 514 | // service handles in the disconnect callback |
@@ -515,131 +529,135 @@ handle_shutdown(void *cls) | |||
515 | * failed | 529 | * failed |
516 | */ | 530 | */ |
517 | static void | 531 | static void |
518 | test_master(void *cls, | 532 | test_master (void *cls, |
519 | struct GNUNET_TESTBED_RunHandle *h, | 533 | struct GNUNET_TESTBED_RunHandle *h, |
520 | unsigned int num_peers, | 534 | unsigned int num_peers, |
521 | struct GNUNET_TESTBED_Peer **started_peers, | 535 | struct GNUNET_TESTBED_Peer **started_peers, |
522 | unsigned int links_succeeded, | 536 | unsigned int links_succeeded, |
523 | unsigned int links_failed) | 537 | unsigned int links_failed) |
524 | { | 538 | { |
525 | int i; | 539 | int i; |
526 | 540 | ||
527 | GNUNET_log_setup("gnunet-secretsharing-profiler", "INFO", NULL); | 541 | GNUNET_log_setup ("gnunet-secretsharing-profiler", "INFO", NULL); |
528 | 542 | ||
529 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "test master\n"); | 543 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n"); |
530 | 544 | ||
531 | GNUNET_SCHEDULER_add_shutdown(&handle_shutdown, NULL); | 545 | GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL); |
532 | 546 | ||
533 | peers = started_peers; | 547 | peers = started_peers; |
534 | 548 | ||
535 | peer_ids = GNUNET_malloc(num_peers * sizeof(struct GNUNET_PeerIdentity)); | 549 | peer_ids = GNUNET_malloc (num_peers * sizeof(struct GNUNET_PeerIdentity)); |
536 | 550 | ||
537 | session_handles = GNUNET_new_array(num_peers, struct GNUNET_SECRETSHARING_Session *); | 551 | session_handles = GNUNET_new_array (num_peers, struct |
538 | decrypt_handles = GNUNET_new_array(num_peers, struct GNUNET_SECRETSHARING_DecryptionHandle *); | 552 | GNUNET_SECRETSHARING_Session *); |
539 | connect_ops = GNUNET_new_array(num_peers, struct GNUNET_TESTBED_Operation *); | 553 | decrypt_handles = GNUNET_new_array (num_peers, struct |
540 | shares = GNUNET_new_array(num_peers, struct GNUNET_SECRETSHARING_Share *); | 554 | GNUNET_SECRETSHARING_DecryptionHandle *); |
555 | connect_ops = GNUNET_new_array (num_peers, struct GNUNET_TESTBED_Operation *); | ||
556 | shares = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Share *); | ||
541 | 557 | ||
542 | for (i = 0; i < num_peers; i++) | 558 | for (i = 0; i < num_peers; i++) |
543 | { | 559 | { |
544 | // we do not store the returned operation, as peer_info_cb | 560 | // we do not store the returned operation, as peer_info_cb |
545 | // will receive it as a parameter and call GNUNET_TESTBED_operation_done. | 561 | // will receive it as a parameter and call GNUNET_TESTBED_operation_done. |
546 | GNUNET_TESTBED_peer_get_information(peers[i], | 562 | GNUNET_TESTBED_peer_get_information (peers[i], |
547 | GNUNET_TESTBED_PIT_IDENTITY, | 563 | GNUNET_TESTBED_PIT_IDENTITY, |
548 | peer_info_cb, | 564 | peer_info_cb, |
549 | &peer_ids[i]); | 565 | &peer_ids[i]); |
550 | } | 566 | } |
551 | } | 567 | } |
552 | 568 | ||
553 | 569 | ||
554 | static void | 570 | static void |
555 | run(void *cls, char *const *args, const char *cfgfile, | 571 | run (void *cls, char *const *args, const char *cfgfile, |
556 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 572 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
557 | { | 573 | { |
558 | static char *session_str = "gnunet-secretsharing/test"; | 574 | static char *session_str = "gnunet-secretsharing/test"; |
559 | char *topology; | 575 | char *topology; |
560 | int topology_cmp_result; | 576 | int topology_cmp_result; |
561 | 577 | ||
562 | dkg_start = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); | 578 | dkg_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay); |
563 | dkg_deadline = GNUNET_TIME_absolute_add(dkg_start, timeout); | 579 | dkg_deadline = GNUNET_TIME_absolute_add (dkg_start, timeout); |
564 | 580 | ||
565 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "testbed", "OVERLAY_TOPOLOGY", &topology)) | 581 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", |
566 | { | 582 | "OVERLAY_TOPOLOGY", |
567 | fprintf(stderr, | 583 | &topology)) |
568 | "'OVERLAY_TOPOLOGY' not found in 'testbed' config section, " | 584 | { |
569 | "seems like you passed the wrong configuration file\n"); | 585 | fprintf (stderr, |
570 | return; | 586 | "'OVERLAY_TOPOLOGY' not found in 'testbed' config section, " |
571 | } | 587 | "seems like you passed the wrong configuration file\n"); |
588 | return; | ||
589 | } | ||
572 | 590 | ||
573 | topology_cmp_result = strcasecmp(topology, "NONE"); | 591 | topology_cmp_result = strcasecmp (topology, "NONE"); |
574 | GNUNET_free(topology); | 592 | GNUNET_free (topology); |
575 | 593 | ||
576 | if (0 == topology_cmp_result) | 594 | if (0 == topology_cmp_result) |
577 | { | 595 | { |
578 | fprintf(stderr, | 596 | fprintf (stderr, |
579 | "'OVERLAY_TOPOLOGY' set to 'NONE', " | 597 | "'OVERLAY_TOPOLOGY' set to 'NONE', " |
580 | "seems like you passed the wrong configuration file\n"); | 598 | "seems like you passed the wrong configuration file\n"); |
581 | return; | 599 | return; |
582 | } | 600 | } |
583 | 601 | ||
584 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 602 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
585 | "running gnunet-secretsharing-profiler\n"); | 603 | "running gnunet-secretsharing-profiler\n"); |
586 | 604 | ||
587 | GNUNET_CRYPTO_hash(session_str, strlen(session_str), &session_id); | 605 | GNUNET_CRYPTO_hash (session_str, strlen (session_str), &session_id); |
588 | 606 | ||
589 | (void)GNUNET_TESTBED_test_run("gnunet-secretsharing-profiler", | 607 | (void) GNUNET_TESTBED_test_run ("gnunet-secretsharing-profiler", |
590 | cfgfile, | 608 | cfgfile, |
591 | num_peers, | 609 | num_peers, |
592 | 0, | 610 | 0, |
593 | controller_cb, | 611 | controller_cb, |
594 | NULL, | 612 | NULL, |
595 | test_master, | 613 | test_master, |
596 | NULL); | 614 | NULL); |
597 | } | 615 | } |
598 | 616 | ||
599 | 617 | ||
600 | int | 618 | int |
601 | main(int argc, char **argv) | 619 | main (int argc, char **argv) |
602 | { | 620 | { |
603 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 621 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
604 | GNUNET_GETOPT_option_uint('n', | 622 | GNUNET_GETOPT_option_uint ('n', |
605 | "num-peers", | 623 | "num-peers", |
606 | NULL, | 624 | NULL, |
607 | gettext_noop("number of peers in consensus"), | 625 | gettext_noop ("number of peers in consensus"), |
608 | &num_peers), | 626 | &num_peers), |
609 | 627 | ||
610 | GNUNET_GETOPT_option_relative_time('D', | 628 | GNUNET_GETOPT_option_relative_time ('D', |
611 | "delay", | 629 | "delay", |
612 | NULL, | 630 | NULL, |
613 | gettext_noop("dkg start delay"), | 631 | gettext_noop ("dkg start delay"), |
614 | &delay), | 632 | &delay), |
615 | 633 | ||
616 | GNUNET_GETOPT_option_relative_time('t', | 634 | GNUNET_GETOPT_option_relative_time ('t', |
617 | "timeout", | 635 | "timeout", |
618 | NULL, | 636 | NULL, |
619 | gettext_noop("dkg timeout"), | 637 | gettext_noop ("dkg timeout"), |
620 | &timeout), | 638 | &timeout), |
621 | 639 | ||
622 | GNUNET_GETOPT_option_uint('k', | 640 | GNUNET_GETOPT_option_uint ('k', |
623 | "threshold", | 641 | "threshold", |
624 | NULL, | 642 | NULL, |
625 | gettext_noop("threshold"), | 643 | gettext_noop ("threshold"), |
626 | &threshold), | 644 | &threshold), |
627 | 645 | ||
628 | GNUNET_GETOPT_option_flag('d', | 646 | GNUNET_GETOPT_option_flag ('d', |
629 | "descrypt", | 647 | "descrypt", |
630 | gettext_noop("also profile decryption"), | 648 | gettext_noop ("also profile decryption"), |
631 | &decrypt), | 649 | &decrypt), |
632 | 650 | ||
633 | 651 | ||
634 | GNUNET_GETOPT_option_verbose(&verbose), | 652 | GNUNET_GETOPT_option_verbose (&verbose), |
635 | 653 | ||
636 | GNUNET_GETOPT_OPTION_END | 654 | GNUNET_GETOPT_OPTION_END |
637 | }; | 655 | }; |
638 | 656 | ||
639 | delay = GNUNET_TIME_UNIT_ZERO; | 657 | delay = GNUNET_TIME_UNIT_ZERO; |
640 | timeout = GNUNET_TIME_UNIT_MINUTES; | 658 | timeout = GNUNET_TIME_UNIT_MINUTES; |
641 | GNUNET_PROGRAM_run2(argc, argv, "gnunet-secretsharing-profiler", | 659 | GNUNET_PROGRAM_run2 (argc, argv, "gnunet-secretsharing-profiler", |
642 | "help", | 660 | "help", |
643 | options, &run, NULL, GNUNET_YES); | 661 | options, &run, NULL, GNUNET_YES); |
644 | return 0; | 662 | return 0; |
645 | } | 663 | } |