diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-04-14 21:25:56 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-04-14 21:25:56 +0000 |
commit | 10bad9a96003bfe5742a33757f661c762af00384 (patch) | |
tree | 1384494db55496487d524b4361746bd5dcd8ac40 /src/secretsharing | |
parent | 04206bcc8f95670b172c00a8bf803b812908972f (diff) | |
download | gnunet-10bad9a96003bfe5742a33757f661c762af00384.tar.gz gnunet-10bad9a96003bfe5742a33757f661c762af00384.zip |
- call operation_done on testbed operations in profiler
- destroy consensus handles in secretsharing service correctly
Diffstat (limited to 'src/secretsharing')
-rw-r--r-- | src/secretsharing/gnunet-secretsharing-profiler.c | 130 | ||||
-rw-r--r-- | src/secretsharing/gnunet-service-secretsharing.c | 24 | ||||
-rw-r--r-- | src/secretsharing/test_secretsharing.conf | 3 |
3 files changed, 127 insertions, 30 deletions
diff --git a/src/secretsharing/gnunet-secretsharing-profiler.c b/src/secretsharing/gnunet-secretsharing-profiler.c index 7f118c6f0..5dc649178 100644 --- a/src/secretsharing/gnunet-secretsharing-profiler.c +++ b/src/secretsharing/gnunet-secretsharing-profiler.c | |||
@@ -67,15 +67,15 @@ static struct GNUNET_SECRETSHARING_Share **shares; | |||
67 | 67 | ||
68 | static struct GNUNET_SECRETSHARING_PublicKey common_pubkey; | 68 | static struct GNUNET_SECRETSHARING_PublicKey common_pubkey; |
69 | 69 | ||
70 | /** | ||
71 | * ??? | ||
72 | */ | ||
73 | static struct GNUNET_TESTBED_Operation **testbed_operations; | ||
74 | 70 | ||
75 | static unsigned int num_connected_sessions; | 71 | static unsigned int num_connected_sessions; |
76 | 72 | ||
77 | static unsigned int num_connected_decrypt; | 73 | static unsigned int num_connected_decrypt; |
78 | 74 | ||
75 | /** | ||
76 | * Handles to the running peers. | ||
77 | * When peers[i] is NULL, the i-th peer has stopped. | ||
78 | */ | ||
79 | static struct GNUNET_TESTBED_Peer **peers; | 79 | static struct GNUNET_TESTBED_Peer **peers; |
80 | 80 | ||
81 | static struct GNUNET_PeerIdentity *peer_ids; | 81 | static struct GNUNET_PeerIdentity *peer_ids; |
@@ -103,6 +103,16 @@ static struct GNUNET_TIME_Absolute decrypt_start; | |||
103 | 103 | ||
104 | static struct GNUNET_TIME_Absolute decrypt_deadline; | 104 | static struct GNUNET_TIME_Absolute decrypt_deadline; |
105 | 105 | ||
106 | /** | ||
107 | * Connect operations, one for every peer. | ||
108 | */ | ||
109 | static struct GNUNET_TESTBED_Operation **connect_ops; | ||
110 | |||
111 | /** | ||
112 | * Are we performing a shutdown right now? | ||
113 | */ | ||
114 | static int in_shutdown; | ||
115 | |||
106 | 116 | ||
107 | /** | 117 | /** |
108 | * Signature of the event handler function called by the | 118 | * Signature of the event handler function called by the |
@@ -208,6 +218,11 @@ static void decrypt_cb (void *cls, | |||
208 | 218 | ||
209 | *dhp = NULL; | 219 | *dhp = NULL; |
210 | 220 | ||
221 | // we should still be connected if this is called | ||
222 | GNUNET_assert (NULL != connect_ops[n]); | ||
223 | |||
224 | GNUNET_TESTBED_operation_done (connect_ops[n]); | ||
225 | |||
211 | if (NULL == plaintext) | 226 | if (NULL == plaintext) |
212 | { | 227 | { |
213 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decrypt failed for peer %u\n", n); | 228 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decrypt failed for peer %u\n", n); |
@@ -269,11 +284,18 @@ static void | |||
269 | decrypt_disconnect_adapter(void *cls, void *op_result) | 284 | decrypt_disconnect_adapter(void *cls, void *op_result) |
270 | { | 285 | { |
271 | struct GNUNET_SECRETSHARING_DecryptionHandle **dh = cls; | 286 | struct GNUNET_SECRETSHARING_DecryptionHandle **dh = cls; |
287 | unsigned int n = dh - decrypt_handles; | ||
288 | |||
289 | GNUNET_assert (*dh == decrypt_handles[n]); | ||
290 | |||
272 | if (NULL != *dh) | 291 | if (NULL != *dh) |
273 | { | 292 | { |
274 | GNUNET_SECRETSHARING_decrypt_cancel (*dh); | 293 | GNUNET_SECRETSHARING_decrypt_cancel (*dh); |
275 | *dh = NULL; | 294 | *dh = NULL; |
276 | } | 295 | } |
296 | |||
297 | GNUNET_assert (NULL == connect_ops[n]); | ||
298 | connect_ops[n] = NULL; | ||
277 | } | 299 | } |
278 | 300 | ||
279 | 301 | ||
@@ -317,30 +339,12 @@ secret_ready_cb (void *cls, | |||
317 | } | 339 | } |
318 | } | 340 | } |
319 | 341 | ||
320 | // FIXME: destroy testbed operation | 342 | // we should still be connected |
343 | GNUNET_assert (NULL != connect_ops[n]); | ||
321 | 344 | ||
322 | if (num_generated == num_peers) | 345 | // disconnect from the service, will call the disconnect callback |
323 | { | 346 | GNUNET_TESTBED_operation_done (connect_ops[n]); |
324 | int i; | ||
325 | if (GNUNET_NO == decrypt) | ||
326 | { | ||
327 | GNUNET_SCHEDULER_shutdown (); | ||
328 | return; | ||
329 | } | ||
330 | |||
331 | decrypt_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay); | ||
332 | decrypt_deadline = GNUNET_TIME_absolute_add (decrypt_start, timeout); | ||
333 | |||
334 | |||
335 | // compute g^42 | ||
336 | GNUNET_SECRETSHARING_plaintext_generate_i (&reference_plaintext, 42); | ||
337 | GNUNET_SECRETSHARING_encrypt (&common_pubkey, &reference_plaintext, &ciphertext); | ||
338 | 347 | ||
339 | // FIXME: store the ops somewhere! | ||
340 | for (i = 0; i < num_peers; i++) | ||
341 | GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", &decrypt_connect_complete, NULL, | ||
342 | &decrypt_connect_adapter, &decrypt_disconnect_adapter, &decrypt_handles[i]); | ||
343 | } | ||
344 | } | 348 | } |
345 | 349 | ||
346 | 350 | ||
@@ -387,11 +391,47 @@ static void | |||
387 | session_disconnect_adapter (void *cls, void *op_result) | 391 | session_disconnect_adapter (void *cls, void *op_result) |
388 | { | 392 | { |
389 | struct GNUNET_SECRETSHARING_Session **sp = cls; | 393 | struct GNUNET_SECRETSHARING_Session **sp = cls; |
394 | unsigned int n = (sp - session_handles); | ||
395 | |||
396 | GNUNET_assert (*sp == session_handles[n]); | ||
397 | |||
390 | if (NULL != *sp) | 398 | if (NULL != *sp) |
391 | { | 399 | { |
392 | GNUNET_SECRETSHARING_session_destroy (*sp); | 400 | GNUNET_SECRETSHARING_session_destroy (*sp); |
393 | *sp = NULL; | 401 | *sp = NULL; |
394 | } | 402 | } |
403 | |||
404 | GNUNET_assert (NULL != connect_ops[n]); | ||
405 | connect_ops[n] = NULL; | ||
406 | |||
407 | if (GNUNET_YES == in_shutdown) | ||
408 | return; | ||
409 | |||
410 | // all peers received their secret | ||
411 | if (num_generated == num_peers) | ||
412 | { | ||
413 | int i; | ||
414 | |||
415 | // only do decryption if requested by the user | ||
416 | if (GNUNET_NO == decrypt) | ||
417 | { | ||
418 | GNUNET_SCHEDULER_shutdown (); | ||
419 | return; | ||
420 | } | ||
421 | |||
422 | decrypt_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay); | ||
423 | decrypt_deadline = GNUNET_TIME_absolute_add (decrypt_start, timeout); | ||
424 | |||
425 | // compute g^42 as the plaintext which we will decrypt and then | ||
426 | // cooperatively decrypt | ||
427 | GNUNET_SECRETSHARING_plaintext_generate_i (&reference_plaintext, 42); | ||
428 | GNUNET_SECRETSHARING_encrypt (&common_pubkey, &reference_plaintext, &ciphertext); | ||
429 | |||
430 | for (i = 0; i < num_peers; i++) | ||
431 | connect_ops[i] = | ||
432 | GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", &decrypt_connect_complete, NULL, | ||
433 | &decrypt_connect_adapter, &decrypt_disconnect_adapter, &decrypt_handles[i]); | ||
434 | } | ||
395 | } | 435 | } |
396 | 436 | ||
397 | 437 | ||
@@ -423,7 +463,7 @@ peer_info_cb (void *cb_cls, | |||
423 | num_retrieved_peer_ids++; | 463 | num_retrieved_peer_ids++; |
424 | if (num_retrieved_peer_ids == num_peers) | 464 | if (num_retrieved_peer_ids == num_peers) |
425 | for (i = 0; i < num_peers; i++) | 465 | for (i = 0; i < num_peers; i++) |
426 | testbed_operations[i] = | 466 | connect_ops[i] = |
427 | GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", session_connect_complete, NULL, | 467 | GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", session_connect_complete, NULL, |
428 | session_connect_adapter, session_disconnect_adapter, &session_handles[i]); | 468 | session_connect_adapter, session_disconnect_adapter, &session_handles[i]); |
429 | } | 469 | } |
@@ -437,6 +477,32 @@ peer_info_cb (void *cb_cls, | |||
437 | 477 | ||
438 | 478 | ||
439 | /** | 479 | /** |
480 | * Signature of the main function of a task. | ||
481 | * | ||
482 | * @param cls closure | ||
483 | * @param tc context information (why was this task triggered now) | ||
484 | */ | ||
485 | static void | ||
486 | handle_shutdown (void *cls, | ||
487 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
488 | { | ||
489 | in_shutdown = GNUNET_YES; | ||
490 | |||
491 | if (NULL != connect_ops) | ||
492 | { | ||
493 | unsigned int i; | ||
494 | for (i = 0; i < num_peers; i++) | ||
495 | if (NULL != connect_ops[i]) | ||
496 | GNUNET_TESTBED_operation_done (connect_ops[i]); | ||
497 | GNUNET_free (connect_ops); | ||
498 | } | ||
499 | |||
500 | // killing the testbed operation will take care of remaining | ||
501 | // service handles in the disconnect callback | ||
502 | } | ||
503 | |||
504 | |||
505 | /** | ||
440 | * Signature of a main function for a testcase. | 506 | * Signature of a main function for a testcase. |
441 | * | 507 | * |
442 | * @param cls closure | 508 | * @param cls closure |
@@ -463,21 +529,27 @@ test_master (void *cls, | |||
463 | 529 | ||
464 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n"); | 530 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n"); |
465 | 531 | ||
532 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
533 | &handle_shutdown, NULL); | ||
534 | |||
466 | peers = started_peers; | 535 | peers = started_peers; |
467 | 536 | ||
468 | peer_ids = GNUNET_malloc (num_peers * sizeof (struct GNUNET_PeerIdentity)); | 537 | peer_ids = GNUNET_malloc (num_peers * sizeof (struct GNUNET_PeerIdentity)); |
469 | 538 | ||
470 | session_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Session *); | 539 | session_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Session *); |
471 | decrypt_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_DecryptionHandle *); | 540 | decrypt_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_DecryptionHandle *); |
472 | testbed_operations = GNUNET_new_array (num_peers, struct GNUNET_TESTBED_Operation *); | 541 | connect_ops = GNUNET_new_array (num_peers, struct GNUNET_TESTBED_Operation *); |
473 | shares = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Share *); | 542 | shares = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Share *); |
474 | 543 | ||
475 | |||
476 | for (i = 0; i < num_peers; i++) | 544 | for (i = 0; i < num_peers; i++) |
545 | { | ||
546 | // we do not store the returned operation, as peer_info_cb | ||
547 | // will receive it as a parameter and call GNUNET_TESTBED_operation_done. | ||
477 | GNUNET_TESTBED_peer_get_information (peers[i], | 548 | GNUNET_TESTBED_peer_get_information (peers[i], |
478 | GNUNET_TESTBED_PIT_IDENTITY, | 549 | GNUNET_TESTBED_PIT_IDENTITY, |
479 | peer_info_cb, | 550 | peer_info_cb, |
480 | &peer_ids[i]); | 551 | &peer_ids[i]); |
552 | } | ||
481 | } | 553 | } |
482 | 554 | ||
483 | 555 | ||
diff --git a/src/secretsharing/gnunet-service-secretsharing.c b/src/secretsharing/gnunet-service-secretsharing.c index 1778b6ca0..0359fd0d7 100644 --- a/src/secretsharing/gnunet-service-secretsharing.c +++ b/src/secretsharing/gnunet-service-secretsharing.c | |||
@@ -539,6 +539,12 @@ compute_lagrange_coefficient (gcry_mpi_t coeff, unsigned int j, | |||
539 | } | 539 | } |
540 | 540 | ||
541 | 541 | ||
542 | /** | ||
543 | * Destroy a decrypt session, removing it from | ||
544 | * the linked list of decrypt sessions. | ||
545 | * | ||
546 | * @param ds decrypt session to destroy | ||
547 | */ | ||
542 | static void | 548 | static void |
543 | decrypt_session_destroy (struct DecryptSession *ds) | 549 | decrypt_session_destroy (struct DecryptSession *ds) |
544 | { | 550 | { |
@@ -546,6 +552,12 @@ decrypt_session_destroy (struct DecryptSession *ds) | |||
546 | 552 | ||
547 | GNUNET_CONTAINER_DLL_remove (decrypt_sessions_head, decrypt_sessions_tail, ds); | 553 | GNUNET_CONTAINER_DLL_remove (decrypt_sessions_head, decrypt_sessions_tail, ds); |
548 | 554 | ||
555 | if (NULL != ds->consensus) | ||
556 | { | ||
557 | GNUNET_CONSENSUS_destroy (ds->consensus); | ||
558 | ds->consensus = NULL; | ||
559 | } | ||
560 | |||
549 | if (NULL != ds->client_mq) | 561 | if (NULL != ds->client_mq) |
550 | { | 562 | { |
551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying decrypt MQ\n"); | 563 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying decrypt MQ\n"); |
@@ -570,6 +582,12 @@ keygen_session_destroy (struct KeygenSession *ks) | |||
570 | 582 | ||
571 | GNUNET_CONTAINER_DLL_remove (keygen_sessions_head, keygen_sessions_tail, ks); | 583 | GNUNET_CONTAINER_DLL_remove (keygen_sessions_head, keygen_sessions_tail, ks); |
572 | 584 | ||
585 | if (NULL != ks->consensus) | ||
586 | { | ||
587 | GNUNET_CONSENSUS_destroy (ks->consensus); | ||
588 | ks->consensus = NULL; | ||
589 | } | ||
590 | |||
573 | if (NULL != ks->client_mq) | 591 | if (NULL != ks->client_mq) |
574 | { | 592 | { |
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying keygen MQ\n"); | 593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying keygen MQ\n"); |
@@ -734,6 +752,9 @@ keygen_round2_conclude (void *cls) | |||
734 | 752 | ||
735 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "round2 conclude\n"); | 753 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "round2 conclude\n"); |
736 | 754 | ||
755 | GNUNET_CONSENSUS_destroy (ks->consensus); | ||
756 | ks->consensus = NULL; | ||
757 | |||
737 | share = GNUNET_new (struct GNUNET_SECRETSHARING_Share); | 758 | share = GNUNET_new (struct GNUNET_SECRETSHARING_Share); |
738 | 759 | ||
739 | share->num_peers = 0; | 760 | share->num_peers = 0; |
@@ -1289,6 +1310,9 @@ decrypt_conclude (void *cls) | |||
1289 | unsigned int i; | 1310 | unsigned int i; |
1290 | unsigned int j; | 1311 | unsigned int j; |
1291 | 1312 | ||
1313 | GNUNET_CONSENSUS_destroy (ds->consensus); | ||
1314 | ds->consensus = NULL; | ||
1315 | |||
1292 | GNUNET_assert (0 != (lagrange = gcry_mpi_new (0))); | 1316 | GNUNET_assert (0 != (lagrange = gcry_mpi_new (0))); |
1293 | GNUNET_assert (0 != (m = gcry_mpi_new (0))); | 1317 | GNUNET_assert (0 != (m = gcry_mpi_new (0))); |
1294 | GNUNET_assert (0 != (tmp = gcry_mpi_new (0))); | 1318 | GNUNET_assert (0 != (tmp = gcry_mpi_new (0))); |
diff --git a/src/secretsharing/test_secretsharing.conf b/src/secretsharing/test_secretsharing.conf index 44b9adf3d..f0b04052b 100644 --- a/src/secretsharing/test_secretsharing.conf +++ b/src/secretsharing/test_secretsharing.conf | |||
@@ -1,13 +1,14 @@ | |||
1 | [secretsharing] | 1 | [secretsharing] |
2 | AUTOSTART = YES | 2 | AUTOSTART = YES |
3 | #PREFIX = valgrind | 3 | #PREFIX = valgrind |
4 | OPTIONS = -LINFO | 4 | #OPTIONS = -LINFO |
5 | 5 | ||
6 | [consensus] | 6 | [consensus] |
7 | AUTOSTART = YES | 7 | AUTOSTART = YES |
8 | 8 | ||
9 | [transport] | 9 | [transport] |
10 | OPTIONS = -LERROR | 10 | OPTIONS = -LERROR |
11 | PLUGINS = unix | ||
11 | 12 | ||
12 | [arm] | 13 | [arm] |
13 | DEFAULTSERVICES = core consensus set secretsharing | 14 | DEFAULTSERVICES = core consensus set secretsharing |