diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-11-07 18:13:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-11-07 18:13:30 +0000 |
commit | aa6bebab28149dc9440749afadc279f134ea3f5c (patch) | |
tree | aeac2470ed066a45c1f808933d0a93af4b279b39 /src/set | |
parent | 91b9ba2fc36c1919e11d515d790bae68860653db (diff) | |
download | gnunet-aa6bebab28149dc9440749afadc279f134ea3f5c.tar.gz gnunet-aa6bebab28149dc9440749afadc279f134ea3f5c.zip |
make set testcase fail to highlight issue #3490
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/gnunet-service-set_intersection.c | 123 | ||||
-rw-r--r-- | src/set/test_set_intersection_result_full.c | 119 |
2 files changed, 140 insertions, 102 deletions
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c index 6b2473e26..27110077e 100644 --- a/src/set/gnunet-service-set_intersection.c +++ b/src/set/gnunet-service-set_intersection.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2013, 2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -171,7 +171,9 @@ send_client_element (struct Operation *op, | |||
171 | struct GNUNET_MQ_Envelope *ev; | 171 | struct GNUNET_MQ_Envelope *ev; |
172 | struct GNUNET_SET_ResultMessage *rm; | 172 | struct GNUNET_SET_ResultMessage *rm; |
173 | 173 | ||
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending removed element (size %u) to client\n", element->size); | 174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "sending removed element (size %u) to client\n", | ||
176 | element->size); | ||
175 | GNUNET_assert (0 != op->spec->client_request_id); | 177 | GNUNET_assert (0 != op->spec->client_request_id); |
176 | ev = GNUNET_MQ_msg_extra (rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT); | 178 | ev = GNUNET_MQ_msg_extra (rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT); |
177 | if (NULL == ev) | 179 | if (NULL == ev) |
@@ -305,8 +307,9 @@ iterator_bf_reduce (void *cls, | |||
305 | return GNUNET_YES; | 307 | return GNUNET_YES; |
306 | } | 308 | } |
307 | 309 | ||
310 | |||
308 | /** | 311 | /** |
309 | * create a bloomfilter based on the elements given | 312 | * Create a bloomfilter based on the elements given |
310 | * | 313 | * |
311 | * @param cls closure | 314 | * @param cls closure |
312 | * @param key current key code | 315 | * @param key current key code |
@@ -317,20 +320,22 @@ iterator_bf_reduce (void *cls, | |||
317 | */ | 320 | */ |
318 | static int | 321 | static int |
319 | iterator_bf_create (void *cls, | 322 | iterator_bf_create (void *cls, |
320 | const struct GNUNET_HashCode *key, | 323 | const struct GNUNET_HashCode *key, |
321 | void *value) | 324 | void *value) |
322 | { | 325 | { |
323 | struct ElementEntry *ee = value; | 326 | struct ElementEntry *ee = value; |
324 | struct Operation *op = cls; | 327 | struct Operation *op = cls; |
325 | struct GNUNET_HashCode mutated_hash; | 328 | struct GNUNET_HashCode mutated_hash; |
326 | 329 | ||
327 | GNUNET_BLOCK_mingle_hash(&ee->element_hash, op->spec->salt, &mutated_hash); | 330 | GNUNET_BLOCK_mingle_hash (&ee->element_hash, |
328 | 331 | op->spec->salt, | |
332 | &mutated_hash); | ||
329 | GNUNET_CONTAINER_bloomfilter_add (op->state->local_bf, | 333 | GNUNET_CONTAINER_bloomfilter_add (op->state->local_bf, |
330 | &mutated_hash); | 334 | &mutated_hash); |
331 | return GNUNET_YES; | 335 | return GNUNET_YES; |
332 | } | 336 | } |
333 | 337 | ||
338 | |||
334 | /** | 339 | /** |
335 | * Inform the client that the union operation has failed, | 340 | * Inform the client that the union operation has failed, |
336 | * and proceed to destroy the evaluate operation. | 341 | * and proceed to destroy the evaluate operation. |
@@ -343,11 +348,13 @@ fail_intersection_operation (struct Operation *op) | |||
343 | struct GNUNET_MQ_Envelope *ev; | 348 | struct GNUNET_MQ_Envelope *ev; |
344 | struct GNUNET_SET_ResultMessage *msg; | 349 | struct GNUNET_SET_ResultMessage *msg; |
345 | 350 | ||
346 | if (op->state->my_elements){ | 351 | if (op->state->my_elements) |
352 | { | ||
347 | GNUNET_CONTAINER_multihashmap_destroy(op->state->my_elements); | 353 | GNUNET_CONTAINER_multihashmap_destroy(op->state->my_elements); |
348 | op->state->my_elements = NULL; | 354 | op->state->my_elements = NULL; |
349 | } | 355 | } |
350 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "intersection operation failed\n"); | 356 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
357 | "intersection operation failed\n"); | ||
351 | 358 | ||
352 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_RESULT); | 359 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_RESULT); |
353 | msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); | 360 | msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); |
@@ -387,9 +394,11 @@ send_operation_request (struct Operation *op) | |||
387 | GNUNET_MQ_send (op->mq, ev); | 394 | GNUNET_MQ_send (op->mq, ev); |
388 | 395 | ||
389 | if (NULL != op->spec->context_msg) | 396 | if (NULL != op->spec->context_msg) |
390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sent op request with context message\n"); | 397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
398 | "sent op request with context message\n"); | ||
391 | else | 399 | else |
392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sent op request without context message\n"); | 400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
401 | "sent op request without context message\n"); | ||
393 | 402 | ||
394 | if (NULL != op->spec->context_msg) | 403 | if (NULL != op->spec->context_msg) |
395 | { | 404 | { |
@@ -398,8 +407,10 @@ send_operation_request (struct Operation *op) | |||
398 | } | 407 | } |
399 | } | 408 | } |
400 | 409 | ||
410 | |||
401 | static void | 411 | static void |
402 | send_bloomfilter_multipart (struct Operation *op, uint32_t offset) | 412 | send_bloomfilter_multipart (struct Operation *op, |
413 | uint32_t offset) | ||
403 | { | 414 | { |
404 | struct GNUNET_MQ_Envelope *ev; | 415 | struct GNUNET_MQ_Envelope *ev; |
405 | struct BFPart *msg; | 416 | struct BFPart *msg; |
@@ -409,7 +420,9 @@ send_bloomfilter_multipart (struct Operation *op, uint32_t offset) | |||
409 | if (todo_size < chunk_size) | 420 | if (todo_size < chunk_size) |
410 | chunk_size = todo_size; | 421 | chunk_size = todo_size; |
411 | 422 | ||
412 | ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF_PART); | 423 | ev = GNUNET_MQ_msg_extra (msg, |
424 | chunk_size, | ||
425 | GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF_PART); | ||
413 | 426 | ||
414 | msg->chunk_length = htonl (chunk_size); | 427 | msg->chunk_length = htonl (chunk_size); |
415 | msg->chunk_offset = htonl (offset); | 428 | msg->chunk_offset = htonl (offset); |
@@ -424,10 +437,10 @@ send_bloomfilter_multipart (struct Operation *op, uint32_t offset) | |||
424 | op->state->bf_data = NULL; | 437 | op->state->bf_data = NULL; |
425 | return; | 438 | return; |
426 | } | 439 | } |
427 | |||
428 | send_bloomfilter_multipart (op, offset + chunk_size); | 440 | send_bloomfilter_multipart (op, offset + chunk_size); |
429 | } | 441 | } |
430 | 442 | ||
443 | |||
431 | /** | 444 | /** |
432 | * Send a bloomfilter to our peer. | 445 | * Send a bloomfilter to our peer. |
433 | * that the operation is over. | 446 | * that the operation is over. |
@@ -446,7 +459,8 @@ send_bloomfilter (struct Operation *op) | |||
446 | uint32_t chunk_size; | 459 | uint32_t chunk_size; |
447 | struct GNUNET_CONTAINER_BloomFilter * local_bf; | 460 | struct GNUNET_CONTAINER_BloomFilter * local_bf; |
448 | 461 | ||
449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending bf of size %u\n"); | 462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
463 | "sending bf of size %u\n"); | ||
450 | 464 | ||
451 | CALCULATE_BF_SIZE(op->state->my_element_count, | 465 | CALCULATE_BF_SIZE(op->state->my_element_count, |
452 | op->spec->remote_element_count, | 466 | op->spec->remote_element_count, |
@@ -463,7 +477,8 @@ send_bloomfilter (struct Operation *op) | |||
463 | op); | 477 | op); |
464 | 478 | ||
465 | // send our bloomfilter | 479 | // send our bloomfilter |
466 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE > bf_size + sizeof (struct BFMessage)) { | 480 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE > bf_size + sizeof (struct BFMessage)) |
481 | { | ||
467 | // singlepart | 482 | // singlepart |
468 | chunk_size = bf_size; | 483 | chunk_size = bf_size; |
469 | ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); | 484 | ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); |
@@ -472,7 +487,8 @@ send_bloomfilter (struct Operation *op) | |||
472 | (char*)&msg[1], | 487 | (char*)&msg[1], |
473 | bf_size)); | 488 | bf_size)); |
474 | } | 489 | } |
475 | else { | 490 | else |
491 | { | ||
476 | //multipart | 492 | //multipart |
477 | chunk_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct BFMessage); | 493 | chunk_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct BFMessage); |
478 | ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); | 494 | ev = GNUNET_MQ_msg_extra (msg, chunk_size, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF); |
@@ -535,15 +551,21 @@ send_remaining_elements (void *cls) | |||
535 | struct GNUNET_SET_Element *element; | 551 | struct GNUNET_SET_Element *element; |
536 | int res; | 552 | int res; |
537 | 553 | ||
538 | res = GNUNET_CONTAINER_multihashmap_iterator_next (op->state->full_result_iter, NULL, (const void **) &remaining); | 554 | res = GNUNET_CONTAINER_multihashmap_iterator_next (op->state->full_result_iter, |
539 | if (GNUNET_NO == res) { | 555 | NULL, |
540 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending done and destroy because iterator ran out\n"); | 556 | (const void **) &remaining); |
557 | if (GNUNET_NO == res) | ||
558 | { | ||
559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
560 | "sending done and destroy because iterator ran out\n"); | ||
541 | send_client_done_and_destroy (op); | 561 | send_client_done_and_destroy (op); |
542 | return; | 562 | return; |
543 | } | 563 | } |
544 | 564 | ||
545 | element = &remaining->element; | 565 | element = &remaining->element; |
546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending element (size %u) to client (full set)\n", element->size); | 566 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
567 | "sending element (size %u) to client (full set)\n", | ||
568 | element->size); | ||
547 | GNUNET_assert (0 != op->spec->client_request_id); | 569 | GNUNET_assert (0 != op->spec->client_request_id); |
548 | 570 | ||
549 | ev = GNUNET_MQ_msg_extra (rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT); | 571 | ev = GNUNET_MQ_msg_extra (rm, element->size, GNUNET_MESSAGE_TYPE_SET_RESULT); |
@@ -570,7 +592,8 @@ send_peer_done (struct Operation *op) | |||
570 | struct GNUNET_MQ_Envelope *ev; | 592 | struct GNUNET_MQ_Envelope *ev; |
571 | 593 | ||
572 | op->state->phase = PHASE_FINISHED; | 594 | op->state->phase = PHASE_FINISHED; |
573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Intersection succeeded, sending DONE\n"); | 595 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
596 | "Intersection succeeded, sending DONE\n"); | ||
574 | GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf); | 597 | GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf); |
575 | op->state->local_bf = NULL; | 598 | op->state->local_bf = NULL; |
576 | 599 | ||
@@ -585,7 +608,8 @@ send_peer_done (struct Operation *op) | |||
585 | * @param op the intersection operation | 608 | * @param op the intersection operation |
586 | */ | 609 | */ |
587 | static void | 610 | static void |
588 | process_bf (struct Operation *op){ | 611 | process_bf (struct Operation *op) |
612 | { | ||
589 | uint32_t old_elements; | 613 | uint32_t old_elements; |
590 | uint32_t peer_elements; | 614 | uint32_t peer_elements; |
591 | 615 | ||
@@ -623,7 +647,8 @@ process_bf (struct Operation *op){ | |||
623 | if ((0 == op->state->my_element_count) // fully disjoint | 647 | if ((0 == op->state->my_element_count) // fully disjoint |
624 | || ((op->state->phase == PHASE_MAYBE_FINISHED) // we agree on a shared set of elements | 648 | || ((op->state->phase == PHASE_MAYBE_FINISHED) // we agree on a shared set of elements |
625 | && (old_elements == op->state->my_element_count) | 649 | && (old_elements == op->state->my_element_count) |
626 | && (op->state->my_element_count == peer_elements))) { | 650 | && (op->state->my_element_count == peer_elements))) |
651 | { | ||
627 | // In the last round we though we were finished, we now know this is correct | 652 | // In the last round we though we were finished, we now know this is correct |
628 | send_peer_done (op); | 653 | send_peer_done (op); |
629 | return; | 654 | return; |
@@ -657,7 +682,8 @@ handle_p2p_bf_part (void *cls, const struct GNUNET_MessageHeader *mh) | |||
657 | chunk_offset = ntohl(msg->chunk_offset); | 682 | chunk_offset = ntohl(msg->chunk_offset); |
658 | 683 | ||
659 | if ((NULL == op->state->bf_data) | 684 | if ((NULL == op->state->bf_data) |
660 | || (op->state->bf_data_size < chunk_size + chunk_offset)){ | 685 | || (op->state->bf_data_size < chunk_size + chunk_offset)) |
686 | { | ||
661 | // unexpected multipart chunk | 687 | // unexpected multipart chunk |
662 | GNUNET_break_op (0); | 688 | GNUNET_break_op (0); |
663 | fail_intersection_operation(op); | 689 | fail_intersection_operation(op); |
@@ -688,7 +714,8 @@ handle_p2p_bf_part (void *cls, const struct GNUNET_MessageHeader *mh) | |||
688 | * @param mh the header of the message | 714 | * @param mh the header of the message |
689 | */ | 715 | */ |
690 | static void | 716 | static void |
691 | handle_p2p_bf (void *cls, const struct GNUNET_MessageHeader *mh) | 717 | handle_p2p_bf (void *cls, |
718 | const struct GNUNET_MessageHeader *mh) | ||
692 | { | 719 | { |
693 | struct Operation *op = cls; | 720 | struct Operation *op = cls; |
694 | const struct BFMessage *msg = (const struct BFMessage *) mh; | 721 | const struct BFMessage *msg = (const struct BFMessage *) mh; |
@@ -701,14 +728,16 @@ handle_p2p_bf (void *cls, const struct GNUNET_MessageHeader *mh) | |||
701 | case PHASE_INITIAL: | 728 | case PHASE_INITIAL: |
702 | case PHASE_BF_EXCHANGE: | 729 | case PHASE_BF_EXCHANGE: |
703 | case PHASE_MAYBE_FINISHED: | 730 | case PHASE_MAYBE_FINISHED: |
704 | if (NULL == op->state->bf_data) { | 731 | if (NULL == op->state->bf_data) |
732 | { | ||
705 | // no colliding multipart transaction going on currently | 733 | // no colliding multipart transaction going on currently |
706 | op->spec->salt = ntohl (msg->sender_mutator); | 734 | op->spec->salt = ntohl (msg->sender_mutator); |
707 | bf_size = ntohl (msg->bloomfilter_total_length); | 735 | bf_size = ntohl (msg->bloomfilter_total_length); |
708 | bf_bits_per_element = ntohl (msg->bits_per_element); | 736 | bf_bits_per_element = ntohl (msg->bits_per_element); |
709 | chunk_size = ntohl (msg->bloomfilter_length); | 737 | chunk_size = ntohl (msg->bloomfilter_length); |
710 | op->spec->remote_element_count = ntohl(msg->sender_element_count); | 738 | op->spec->remote_element_count = ntohl(msg->sender_element_count); |
711 | if (bf_size == chunk_size) { | 739 | if (bf_size == chunk_size) |
740 | { | ||
712 | // single part, done here | 741 | // single part, done here |
713 | op->state->remote_bf = GNUNET_CONTAINER_bloomfilter_init ((const char*) &msg[1], | 742 | op->state->remote_bf = GNUNET_CONTAINER_bloomfilter_init ((const char*) &msg[1], |
714 | bf_size, | 743 | bf_size, |
@@ -738,16 +767,18 @@ handle_p2p_bf (void *cls, const struct GNUNET_MessageHeader *mh) | |||
738 | * @param mh the header of the message | 767 | * @param mh the header of the message |
739 | */ | 768 | */ |
740 | static void | 769 | static void |
741 | handle_p2p_element_info (void *cls, const struct GNUNET_MessageHeader *mh) | 770 | handle_p2p_element_info (void *cls, |
771 | const struct GNUNET_MessageHeader *mh) | ||
742 | { | 772 | { |
743 | struct Operation *op = cls; | 773 | struct Operation *op = cls; |
744 | struct BFMessage *msg = (struct BFMessage *) mh; | 774 | const struct BFMessage *msg = (const struct BFMessage *) mh; |
745 | 775 | ||
746 | op->spec->remote_element_count = ntohl(msg->sender_element_count); | 776 | op->spec->remote_element_count = ntohl(msg->sender_element_count); |
747 | if ((op->state->phase != PHASE_INITIAL) | 777 | if ((op->state->phase != PHASE_INITIAL) |
748 | || (op->state->my_element_count > op->spec->remote_element_count) | 778 | || (op->state->my_element_count > op->spec->remote_element_count) |
749 | || (0 == op->state->my_element_count) | 779 | || (0 == op->state->my_element_count) |
750 | || (0 == op->spec->remote_element_count)){ | 780 | || (0 == op->spec->remote_element_count)) |
781 | { | ||
751 | GNUNET_break_op (0); | 782 | GNUNET_break_op (0); |
752 | fail_intersection_operation(op); | 783 | fail_intersection_operation(op); |
753 | return; | 784 | return; |
@@ -762,7 +793,7 @@ handle_p2p_element_info (void *cls, const struct GNUNET_MessageHeader *mh) | |||
762 | 793 | ||
763 | GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf); | 794 | GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf); |
764 | op->state->remote_bf = NULL; | 795 | op->state->remote_bf = NULL; |
765 | 796 | ||
766 | if (op->state->my_element_count == ntohl (msg->sender_element_count)) | 797 | if (op->state->my_element_count == ntohl (msg->sender_element_count)) |
767 | op->state->phase = PHASE_MAYBE_FINISHED; | 798 | op->state->phase = PHASE_MAYBE_FINISHED; |
768 | 799 | ||
@@ -781,7 +812,8 @@ send_element_count (struct Operation *op) | |||
781 | struct GNUNET_MQ_Envelope *ev; | 812 | struct GNUNET_MQ_Envelope *ev; |
782 | struct BFMessage *msg; | 813 | struct BFMessage *msg; |
783 | 814 | ||
784 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending element count (bf_msg)\n"); | 815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
816 | "sending element count (bf_msg)\n"); | ||
785 | 817 | ||
786 | // just send our element count, as the other peer must start | 818 | // just send our element count, as the other peer must start |
787 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO); | 819 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO); |
@@ -808,7 +840,8 @@ finish_and_destroy (struct Operation *op) | |||
808 | 840 | ||
809 | if (GNUNET_SET_RESULT_FULL == op->spec->result_mode) | 841 | if (GNUNET_SET_RESULT_FULL == op->spec->result_mode) |
810 | { | 842 | { |
811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending full result set\n"); | 843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
844 | "sending full result set\n"); | ||
812 | op->state->full_result_iter = | 845 | op->state->full_result_iter = |
813 | GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements); | 846 | GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements); |
814 | send_remaining_elements (op); | 847 | send_remaining_elements (op); |
@@ -830,8 +863,11 @@ handle_p2p_done (void *cls, | |||
830 | { | 863 | { |
831 | struct Operation *op = cls; | 864 | struct Operation *op = cls; |
832 | 865 | ||
833 | if ((op->state->phase = PHASE_FINISHED) || (op->state->phase = PHASE_MAYBE_FINISHED)){ | 866 | if ( (op->state->phase = PHASE_FINISHED) || |
834 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got final DONE\n"); | 867 | (op->state->phase = PHASE_MAYBE_FINISHED) ) |
868 | { | ||
869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
870 | "got final DONE\n"); | ||
835 | 871 | ||
836 | finish_and_destroy (op); | 872 | finish_and_destroy (op); |
837 | return; | 873 | return; |
@@ -872,7 +908,8 @@ intersection_evaluate (struct Operation *op) | |||
872 | static void | 908 | static void |
873 | intersection_accept (struct Operation *op) | 909 | intersection_accept (struct Operation *op) |
874 | { | 910 | { |
875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "accepting set union operation\n"); | 911 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
912 | "accepting set union operation\n"); | ||
876 | op->state = GNUNET_new (struct OperationState); | 913 | op->state = GNUNET_new (struct OperationState); |
877 | op->state->my_elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES); | 914 | op->state->my_elements = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_YES); |
878 | op->state->my_element_count = op->spec->set->state->current_set_element_count; | 915 | op->state->my_element_count = op->spec->set->state->current_set_element_count; |
@@ -967,7 +1004,8 @@ static int | |||
967 | intersection_handle_p2p_message (struct Operation *op, | 1004 | intersection_handle_p2p_message (struct Operation *op, |
968 | const struct GNUNET_MessageHeader *mh) | 1005 | const struct GNUNET_MessageHeader *mh) |
969 | { | 1006 | { |
970 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received p2p message (t: %u, s: %u)\n", | 1007 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1008 | "received p2p message (t: %u, s: %u)\n", | ||
971 | ntohs (mh->type), ntohs (mh->size)); | 1009 | ntohs (mh->type), ntohs (mh->size)); |
972 | switch (ntohs (mh->type)) | 1010 | switch (ntohs (mh->type)) |
973 | { | 1011 | { |
@@ -1012,12 +1050,14 @@ intersection_peer_disconnect (struct Operation *op) | |||
1012 | msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); | 1050 | msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); |
1013 | msg->element_type = htons (0); | 1051 | msg->element_type = htons (0); |
1014 | GNUNET_MQ_send (op->spec->set->client_mq, ev); | 1052 | GNUNET_MQ_send (op->spec->set->client_mq, ev); |
1015 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "other peer disconnected prematurely\n"); | 1053 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1054 | "other peer disconnected prematurely\n"); | ||
1016 | _GSS_operation_destroy (op); | 1055 | _GSS_operation_destroy (op); |
1017 | return; | 1056 | return; |
1018 | } | 1057 | } |
1019 | // else: the session has already been concluded | 1058 | // else: the session has already been concluded |
1020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "other peer disconnected (finished)\n"); | 1059 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1060 | "other peer disconnected (finished)\n"); | ||
1021 | if (GNUNET_NO == op->state->client_done_sent) | 1061 | if (GNUNET_NO == op->state->client_done_sent) |
1022 | finish_and_destroy (op); | 1062 | finish_and_destroy (op); |
1023 | } | 1063 | } |
@@ -1031,7 +1071,8 @@ intersection_peer_disconnect (struct Operation *op) | |||
1031 | static void | 1071 | static void |
1032 | intersection_op_cancel (struct Operation *op) | 1072 | intersection_op_cancel (struct Operation *op) |
1033 | { | 1073 | { |
1034 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying intersection op\n"); | 1074 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1075 | "destroying intersection op\n"); | ||
1035 | /* check if the op was canceled twice */ | 1076 | /* check if the op was canceled twice */ |
1036 | GNUNET_assert (NULL != op->state); | 1077 | GNUNET_assert (NULL != op->state); |
1037 | if (NULL != op->state->remote_bf) | 1078 | if (NULL != op->state->remote_bf) |
diff --git a/src/set/test_set_intersection_result_full.c b/src/set/test_set_intersection_result_full.c index b5140b101..c59624459 100644 --- a/src/set/test_set_intersection_result_full.c +++ b/src/set/test_set_intersection_result_full.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2012 Christian Grothoff (and other contributing authors) | 3 | (C) 2012-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -21,6 +21,8 @@ | |||
21 | /** | 21 | /** |
22 | * @file set/test_set_intersection_result_full.c | 22 | * @file set/test_set_intersection_result_full.c |
23 | * @brief testcase for full result mode of the intersection set operation | 23 | * @brief testcase for full result mode of the intersection set operation |
24 | * @author Christian Fuchs | ||
25 | * @author Christian Grothoff | ||
24 | */ | 26 | */ |
25 | #include "platform.h" | 27 | #include "platform.h" |
26 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
@@ -33,56 +35,63 @@ static int ret; | |||
33 | static struct GNUNET_PeerIdentity local_id; | 35 | static struct GNUNET_PeerIdentity local_id; |
34 | 36 | ||
35 | static struct GNUNET_HashCode app_id; | 37 | static struct GNUNET_HashCode app_id; |
38 | |||
36 | static struct GNUNET_SET_Handle *set1; | 39 | static struct GNUNET_SET_Handle *set1; |
40 | |||
37 | static struct GNUNET_SET_Handle *set2; | 41 | static struct GNUNET_SET_Handle *set2; |
42 | |||
38 | static struct GNUNET_SET_ListenHandle *listen_handle; | 43 | static struct GNUNET_SET_ListenHandle *listen_handle; |
39 | const static struct GNUNET_CONFIGURATION_Handle *config; | 44 | |
45 | static const struct GNUNET_CONFIGURATION_Handle *config; | ||
40 | 46 | ||
41 | static int iter_count; | 47 | static int iter_count; |
42 | 48 | ||
43 | 49 | ||
44 | static void | 50 | static void |
45 | result_cb_set1 (void *cls, const struct GNUNET_SET_Element *element, | 51 | result_cb_set1 (void *cls, |
52 | const struct GNUNET_SET_Element *element, | ||
46 | enum GNUNET_SET_Status status) | 53 | enum GNUNET_SET_Status status) |
47 | { | 54 | { |
55 | static int count; | ||
48 | switch (status) | 56 | switch (status) |
49 | { | 57 | { |
50 | case GNUNET_SET_STATUS_OK: | 58 | case GNUNET_SET_STATUS_OK: |
51 | printf ("set 1: got element\n"); | 59 | count++; |
52 | break; | 60 | break; |
53 | case GNUNET_SET_STATUS_FAILURE: | 61 | case GNUNET_SET_STATUS_FAILURE: |
54 | printf ("set 1: failure\n"); | 62 | ret = 1; |
55 | ret = 1; | 63 | break; |
56 | break; | 64 | case GNUNET_SET_STATUS_DONE: |
57 | case GNUNET_SET_STATUS_DONE: | 65 | GNUNET_assert (1 == count); |
58 | printf ("set 1: done\n"); | 66 | GNUNET_SET_destroy (set1); |
59 | GNUNET_SET_destroy (set1); | 67 | break; |
60 | break; | 68 | default: |
61 | default: | 69 | GNUNET_assert (0); |
62 | GNUNET_assert (0); | ||
63 | } | 70 | } |
64 | } | 71 | } |
65 | 72 | ||
66 | 73 | ||
67 | static void | 74 | static void |
68 | result_cb_set2 (void *cls, const struct GNUNET_SET_Element *element, | 75 | result_cb_set2 (void *cls, |
69 | enum GNUNET_SET_Status status) | 76 | const struct GNUNET_SET_Element *element, |
77 | enum GNUNET_SET_Status status) | ||
70 | { | 78 | { |
79 | static int count; | ||
80 | |||
71 | switch (status) | 81 | switch (status) |
72 | { | 82 | { |
73 | case GNUNET_SET_STATUS_OK: | 83 | case GNUNET_SET_STATUS_OK: |
74 | printf ("set 2: got element\n"); | 84 | count++; |
75 | break; | 85 | break; |
76 | case GNUNET_SET_STATUS_FAILURE: | 86 | case GNUNET_SET_STATUS_FAILURE: |
77 | printf ("set 2: failure\n"); | 87 | ret = 1; |
78 | ret = 1; | 88 | break; |
79 | break; | 89 | case GNUNET_SET_STATUS_DONE: |
80 | case GNUNET_SET_STATUS_DONE: | 90 | GNUNET_assert (1 == count); |
81 | printf ("set 2: done\n"); | 91 | GNUNET_SET_destroy (set2); |
82 | GNUNET_SET_destroy (set2); | 92 | break; |
83 | break; | 93 | default: |
84 | default: | 94 | GNUNET_assert (0); |
85 | GNUNET_assert (0); | ||
86 | } | 95 | } |
87 | } | 96 | } |
88 | 97 | ||
@@ -96,13 +105,11 @@ listen_cb (void *cls, | |||
96 | struct GNUNET_SET_OperationHandle *oh; | 105 | struct GNUNET_SET_OperationHandle *oh; |
97 | 106 | ||
98 | GNUNET_assert (NULL != context_msg); | 107 | GNUNET_assert (NULL != context_msg); |
99 | |||
100 | GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST); | 108 | GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST); |
101 | |||
102 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "listen cb called\n"); | ||
103 | GNUNET_SET_listen_cancel (listen_handle); | 109 | GNUNET_SET_listen_cancel (listen_handle); |
104 | 110 | oh = GNUNET_SET_accept (request, | |
105 | oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_FULL, result_cb_set2, NULL); | 111 | GNUNET_SET_RESULT_FULL, |
112 | &result_cb_set2, NULL); | ||
106 | GNUNET_SET_commit (oh, set2); | 113 | GNUNET_SET_commit (oh, set2); |
107 | } | 114 | } |
108 | 115 | ||
@@ -120,12 +127,15 @@ start (void *cls) | |||
120 | 127 | ||
121 | context_msg.size = htons (sizeof context_msg); | 128 | context_msg.size = htons (sizeof context_msg); |
122 | context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST); | 129 | context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST); |
123 | 130 | listen_handle = GNUNET_SET_listen (config, | |
124 | listen_handle = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_INTERSECTION, | 131 | GNUNET_SET_OPERATION_INTERSECTION, |
125 | &app_id, listen_cb, NULL); | 132 | &app_id, |
126 | oh = GNUNET_SET_prepare (&local_id, &app_id, &context_msg, 42, | 133 | &listen_cb, NULL); |
134 | oh = GNUNET_SET_prepare (&local_id, | ||
135 | &app_id, | ||
136 | &context_msg, 42, | ||
127 | GNUNET_SET_RESULT_FULL, | 137 | GNUNET_SET_RESULT_FULL, |
128 | result_cb_set1, NULL); | 138 | &result_cb_set1, NULL); |
129 | GNUNET_SET_commit (oh, set1); | 139 | GNUNET_SET_commit (oh, set1); |
130 | } | 140 | } |
131 | 141 | ||
@@ -140,10 +150,9 @@ init_set2 (void *cls) | |||
140 | { | 150 | { |
141 | struct GNUNET_SET_Element element; | 151 | struct GNUNET_SET_Element element; |
142 | 152 | ||
143 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
144 | 154 | "initializing set 2\n"); | |
145 | element.type = 0; | 155 | element.type = 0; |
146 | |||
147 | element.data = "hello"; | 156 | element.data = "hello"; |
148 | element.size = strlen(element.data); | 157 | element.size = strlen(element.data); |
149 | GNUNET_SET_add_element (set2, &element, NULL, NULL); | 158 | GNUNET_SET_add_element (set2, &element, NULL, NULL); |
@@ -152,7 +161,7 @@ init_set2 (void *cls) | |||
152 | GNUNET_SET_add_element (set2, &element, NULL, NULL); | 161 | GNUNET_SET_add_element (set2, &element, NULL, NULL); |
153 | element.data = "baz"; | 162 | element.data = "baz"; |
154 | element.size = strlen(element.data); | 163 | element.size = strlen(element.data); |
155 | GNUNET_SET_add_element (set2, &element, start, NULL); | 164 | GNUNET_SET_add_element (set2, &element, &start, NULL); |
156 | } | 165 | } |
157 | 166 | ||
158 | 167 | ||
@@ -165,15 +174,12 @@ init_set1 (void) | |||
165 | struct GNUNET_SET_Element element; | 174 | struct GNUNET_SET_Element element; |
166 | 175 | ||
167 | element.type = 0; | 176 | element.type = 0; |
168 | |||
169 | element.data = "hello"; | 177 | element.data = "hello"; |
170 | element.size = strlen(element.data); | 178 | element.size = strlen(element.data); |
171 | GNUNET_SET_add_element (set1, &element, NULL, NULL); | 179 | GNUNET_SET_add_element (set1, &element, NULL, NULL); |
172 | element.data = "bar"; | 180 | element.data = "bar"; |
173 | element.size = strlen(element.data); | 181 | element.size = strlen(element.data); |
174 | GNUNET_SET_add_element (set1, &element, init_set2, NULL); | 182 | GNUNET_SET_add_element (set1, &element, &init_set2, NULL); |
175 | |||
176 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n"); | ||
177 | } | 183 | } |
178 | 184 | ||
179 | 185 | ||
@@ -187,7 +193,6 @@ iter_cb (void *cls, | |||
187 | GNUNET_SET_destroy (cls); | 193 | GNUNET_SET_destroy (cls); |
188 | return GNUNET_YES; | 194 | return GNUNET_YES; |
189 | } | 195 | } |
190 | printf ("iter: got element\n"); | ||
191 | iter_count++; | 196 | iter_count++; |
192 | return GNUNET_YES; | 197 | return GNUNET_YES; |
193 | } | 198 | } |
@@ -200,9 +205,7 @@ test_iter () | |||
200 | struct GNUNET_SET_Handle *iter_set; | 205 | struct GNUNET_SET_Handle *iter_set; |
201 | 206 | ||
202 | iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_INTERSECTION); | 207 | iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_INTERSECTION); |
203 | |||
204 | element.type = 0; | 208 | element.type = 0; |
205 | |||
206 | element.data = "hello"; | 209 | element.data = "hello"; |
207 | element.size = strlen(element.data); | 210 | element.size = strlen(element.data); |
208 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); | 211 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); |
@@ -212,8 +215,7 @@ test_iter () | |||
212 | element.data = "quux"; | 215 | element.data = "quux"; |
213 | element.size = strlen(element.data); | 216 | element.size = strlen(element.data); |
214 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); | 217 | GNUNET_SET_add_element (iter_set, &element, NULL, NULL); |
215 | 218 | GNUNET_SET_iterate (iter_set, &iter_cb, iter_set); | |
216 | GNUNET_SET_iterate (iter_set, iter_cb, iter_set); | ||
217 | } | 219 | } |
218 | 220 | ||
219 | 221 | ||
@@ -231,11 +233,7 @@ run (void *cls, | |||
231 | struct GNUNET_TESTING_Peer *peer) | 233 | struct GNUNET_TESTING_Peer *peer) |
232 | { | 234 | { |
233 | config = cfg; | 235 | config = cfg; |
234 | GNUNET_CRYPTO_get_peer_identity (cfg, &local_id); | ||
235 | printf ("my id (from CRYPTO): %s\n", GNUNET_i2s (&local_id)); | ||
236 | GNUNET_TESTING_peer_get_identity (peer, &local_id); | 236 | GNUNET_TESTING_peer_get_identity (peer, &local_id); |
237 | printf ("my id (from TESTING): %s\n", GNUNET_i2s (&local_id)); | ||
238 | |||
239 | test_iter (); | 237 | test_iter (); |
240 | 238 | ||
241 | set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); | 239 | set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); |
@@ -246,15 +244,14 @@ run (void *cls, | |||
246 | init_set1 (); | 244 | init_set1 (); |
247 | } | 245 | } |
248 | 246 | ||
247 | |||
249 | int | 248 | int |
250 | main (int argc, char **argv) | 249 | main (int argc, char **argv) |
251 | { | 250 | { |
252 | if (0 != GNUNET_TESTING_peer_run ("test_set_api", | 251 | if (0 != GNUNET_TESTING_peer_run ("test_set_api", |
253 | "test_set.conf", | 252 | "test_set.conf", |
254 | &run, NULL)) | 253 | &run, NULL)) |
255 | { | 254 | return 1; |
256 | return 0; | ||
257 | } | ||
258 | return ret; | 255 | return ret; |
259 | } | 256 | } |
260 | 257 | ||