diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-05-08 10:32:51 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-05-08 10:32:51 +0000 |
commit | 632c58424511edcd2cf00d89a249e939baeb6a39 (patch) | |
tree | 49665e980957cb1c6758ed14e2a56ba40e2f970a /src/scalarproduct | |
parent | 0662fe7c87b12dcbbac17d523526468e80eb59d8 (diff) | |
download | gnunet-632c58424511edcd2cf00d89a249e939baeb6a39.tar.gz gnunet-632c58424511edcd2cf00d89a249e939baeb6a39.zip |
- added proper error reporting to the service
- some refactoring
- bugfixing
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 1123 |
1 files changed, 577 insertions, 546 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index e3a2d5513..21cbafe5b 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -88,6 +88,11 @@ struct SortedValue | |||
88 | struct ServiceSession | 88 | struct ServiceSession |
89 | { | 89 | { |
90 | /** | 90 | /** |
91 | * Is this session active(GNUNET_YES), Concluded(GNUNET_NO), (GNUNET_SYSERR) | ||
92 | */ | ||
93 | int32_t active; | ||
94 | |||
95 | /** | ||
91 | * the role this peer has | 96 | * the role this peer has |
92 | */ | 97 | */ |
93 | enum PeerRole role; | 98 | enum PeerRole role; |
@@ -128,11 +133,6 @@ struct ServiceSession | |||
128 | uint32_t total; | 133 | uint32_t total; |
129 | 134 | ||
130 | /** | 135 | /** |
131 | * how many elements we used for intersection | ||
132 | */ | ||
133 | uint32_t intersected_elements_count; | ||
134 | |||
135 | /** | ||
136 | * all non-0-value'd elements transmitted to us | 136 | * all non-0-value'd elements transmitted to us |
137 | */ | 137 | */ |
138 | struct GNUNET_CONTAINER_MultiHashMap * intersected_elements; | 138 | struct GNUNET_CONTAINER_MultiHashMap * intersected_elements; |
@@ -140,7 +140,7 @@ struct ServiceSession | |||
140 | /** | 140 | /** |
141 | * how many elements actually are used for the scalar product | 141 | * how many elements actually are used for the scalar product |
142 | */ | 142 | */ |
143 | uint32_t used_elements_count; | 143 | uint32_t used_element_count; |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * already transferred elements (sent/received) for multipart messages, less or equal than used_element_count for | 146 | * already transferred elements (sent/received) for multipart messages, less or equal than used_element_count for |
@@ -367,6 +367,76 @@ compute_square_sum (gcry_mpi_t * vector, uint32_t length) | |||
367 | 367 | ||
368 | 368 | ||
369 | /** | 369 | /** |
370 | * Safely frees ALL memory areas referenced by a session. | ||
371 | * | ||
372 | * @param session - the session to free elements from | ||
373 | */ | ||
374 | static void | ||
375 | free_session_variables (struct ServiceSession * s) | ||
376 | { | ||
377 | while (NULL != s->a_head) { | ||
378 | struct SortedValue * e = s->a_head; | ||
379 | GNUNET_free (e->elem); | ||
380 | gcry_mpi_release (e->val); | ||
381 | GNUNET_CONTAINER_DLL_remove (s->a_head, s->a_tail, e); | ||
382 | GNUNET_free (e); | ||
383 | } | ||
384 | if (s->e_a) { | ||
385 | GNUNET_free (s->e_a); | ||
386 | s->e_a = NULL; | ||
387 | } | ||
388 | if (s->remote_pubkey){ | ||
389 | GNUNET_free(s->remote_pubkey); | ||
390 | s->remote_pubkey=NULL; | ||
391 | } | ||
392 | if (s->sorted_elements) { | ||
393 | GNUNET_free (s->sorted_elements); | ||
394 | s->sorted_elements = NULL; | ||
395 | } | ||
396 | if (s->intersected_elements) { | ||
397 | GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); | ||
398 | //elements are freed independently in session->a_head/tail | ||
399 | s->intersected_elements = NULL; | ||
400 | } | ||
401 | if (s->intersection_listen) { | ||
402 | GNUNET_SET_listen_cancel (s->intersection_listen); | ||
403 | s->intersection_listen = NULL; | ||
404 | } | ||
405 | if (s->intersection_op) { | ||
406 | GNUNET_SET_operation_cancel (s->intersection_op); | ||
407 | s->intersection_op = NULL; | ||
408 | } | ||
409 | if (s->intersection_set) { | ||
410 | GNUNET_SET_destroy (s->intersection_set); | ||
411 | s->intersection_set = NULL; | ||
412 | } | ||
413 | if (s->msg) { | ||
414 | GNUNET_free (s->msg); | ||
415 | s->msg = NULL; | ||
416 | } | ||
417 | if (s->r) { | ||
418 | GNUNET_free (s->r); | ||
419 | s->r = NULL; | ||
420 | } | ||
421 | if (s->r_prime) { | ||
422 | GNUNET_free (s->r_prime); | ||
423 | s->r_prime = NULL; | ||
424 | } | ||
425 | if (s->s) { | ||
426 | GNUNET_free (s->s); | ||
427 | s->s = NULL; | ||
428 | } | ||
429 | if (s->s_prime) { | ||
430 | GNUNET_free (s->s_prime); | ||
431 | s->s_prime = NULL; | ||
432 | } | ||
433 | if (s->product) { | ||
434 | gcry_mpi_release (s->product); | ||
435 | s->product = NULL; | ||
436 | } | ||
437 | } | ||
438 | |||
439 | /** | ||
370 | * Primitive callback for copying over a message, as they | 440 | * Primitive callback for copying over a message, as they |
371 | * usually are too complex to be handled in the callback itself. | 441 | * usually are too complex to be handled in the callback itself. |
372 | * clears a session-callback, if a session was handed over and the transmit handle was stored | 442 | * clears a session-callback, if a session was handed over and the transmit handle was stored |
@@ -377,7 +447,7 @@ compute_square_sum (gcry_mpi_t * vector, uint32_t length) | |||
377 | * @return 0 if we couldn't copy, else the size copied over | 447 | * @return 0 if we couldn't copy, else the size copied over |
378 | */ | 448 | */ |
379 | static size_t | 449 | static size_t |
380 | do_send_message (void *cls, size_t size, void *buf) | 450 | cb_transfer_message (void *cls, size_t size, void *buf) |
381 | { | 451 | { |
382 | struct ServiceSession * s = cls; | 452 | struct ServiceSession * s = cls; |
383 | uint16_t type; | 453 | uint16_t type; |
@@ -401,20 +471,25 @@ do_send_message (void *cls, size_t size, void *buf) | |||
401 | { | 471 | { |
402 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT: | 472 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT: |
403 | s->client_transmit_handle = NULL; | 473 | s->client_transmit_handle = NULL; |
474 | free_session_variables (s); | ||
404 | break; | 475 | break; |
405 | 476 | ||
406 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA: | 477 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA: |
407 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA_MULTIPART: | 478 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA_MULTIPART: |
408 | s->service_transmit_handle = NULL; | 479 | s->service_transmit_handle = NULL; |
409 | if (s->used_elements_count != s->transferred_element_count) | 480 | if (s->used_element_count != s->transferred_element_count) |
410 | prepare_alices_cyrptodata_message_multipart (s); | 481 | prepare_alices_cyrptodata_message_multipart (s); |
482 | else | ||
483 | s->channel = NULL; | ||
411 | break; | 484 | break; |
412 | 485 | ||
413 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA: | 486 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA: |
414 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART: | 487 | case GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART: |
415 | s->service_transmit_handle = NULL; | 488 | s->service_transmit_handle = NULL; |
416 | if (s->used_elements_count != s->transferred_element_count) | 489 | if (s->used_element_count != s->transferred_element_count) |
417 | prepare_bobs_cryptodata_message_multipart (s); | 490 | prepare_bobs_cryptodata_message_multipart (s); |
491 | else | ||
492 | s->channel = NULL; | ||
418 | break; | 493 | break; |
419 | 494 | ||
420 | default: | 495 | default: |
@@ -441,17 +516,17 @@ find_matching_session (struct ServiceSession * tail, | |||
441 | uint32_t element_count, | 516 | uint32_t element_count, |
442 | const struct GNUNET_PeerIdentity * peerid) | 517 | const struct GNUNET_PeerIdentity * peerid) |
443 | { | 518 | { |
444 | struct ServiceSession * curr; | 519 | struct ServiceSession * s; |
445 | 520 | ||
446 | for (curr = tail; NULL != curr; curr = curr->prev) { | 521 | for (s = tail; NULL != s; s = s->prev) { |
447 | // if the key matches, and the element_count is same | 522 | // if the key matches, and the element_count is same |
448 | if ((!memcmp (&curr->session_id, key, sizeof (struct GNUNET_HashCode))) | 523 | if ((!memcmp (&s->session_id, key, sizeof (struct GNUNET_HashCode))) |
449 | && (curr->total == element_count)) { | 524 | && (s->total == element_count)) { |
450 | // if peerid is NULL OR same as the peer Id in the queued request | 525 | // if peerid is NULL OR same as the peer Id in the queued request |
451 | if ((NULL == peerid) | 526 | if ((NULL == peerid) |
452 | || (!memcmp (&curr->peer, peerid, sizeof (struct GNUNET_PeerIdentity)))) | 527 | || (!memcmp (&s->peer, peerid, sizeof (struct GNUNET_PeerIdentity)))) |
453 | // matches and is not an already terminated session | 528 | // matches and is not an already terminated session |
454 | return curr; | 529 | return s; |
455 | } | 530 | } |
456 | } | 531 | } |
457 | 532 | ||
@@ -459,79 +534,6 @@ find_matching_session (struct ServiceSession * tail, | |||
459 | } | 534 | } |
460 | 535 | ||
461 | 536 | ||
462 | /** | ||
463 | * Safely frees ALL memory areas referenced by a session. | ||
464 | * | ||
465 | * @param session - the session to free elements from | ||
466 | */ | ||
467 | static void | ||
468 | free_session_variables (struct ServiceSession * session) | ||
469 | { | ||
470 | while (NULL != session->a_head) { | ||
471 | struct SortedValue * e = session->a_head; | ||
472 | GNUNET_free (e->elem); | ||
473 | gcry_mpi_release (e->val); | ||
474 | GNUNET_CONTAINER_DLL_remove (session->a_head, session->a_tail, e); | ||
475 | GNUNET_free (e); | ||
476 | } | ||
477 | if (session->e_a) { | ||
478 | GNUNET_free (session->e_a); | ||
479 | session->e_a = NULL; | ||
480 | } | ||
481 | if (session->remote_pubkey){ | ||
482 | GNUNET_free(session->remote_pubkey); | ||
483 | session->remote_pubkey=NULL; | ||
484 | } | ||
485 | if (session->sorted_elements) { | ||
486 | GNUNET_free (session->sorted_elements); | ||
487 | session->sorted_elements = NULL; | ||
488 | } | ||
489 | if (session->intersected_elements) { | ||
490 | GNUNET_CONTAINER_multihashmap_destroy (session->intersected_elements); | ||
491 | //elements are freed independently in session->a_head/tail | ||
492 | session->intersected_elements = NULL; | ||
493 | } | ||
494 | if (session->intersection_listen) { | ||
495 | GNUNET_SET_listen_cancel (session->intersection_listen); | ||
496 | session->intersection_listen = NULL; | ||
497 | } | ||
498 | if (session->intersection_op) { | ||
499 | GNUNET_SET_operation_cancel (session->intersection_op); | ||
500 | session->intersection_op = NULL; | ||
501 | } | ||
502 | if (session->intersection_set) { | ||
503 | GNUNET_SET_destroy (session->intersection_set); | ||
504 | session->intersection_set = NULL; | ||
505 | } | ||
506 | if (session->channel){ | ||
507 | GNUNET_CADET_channel_destroy(session->channel); | ||
508 | session->channel = NULL; | ||
509 | } | ||
510 | if (session->msg) { | ||
511 | GNUNET_free (session->msg); | ||
512 | session->msg = NULL; | ||
513 | } | ||
514 | if (session->r) { | ||
515 | GNUNET_free (session->r); | ||
516 | session->r = NULL; | ||
517 | } | ||
518 | if (session->r_prime) { | ||
519 | GNUNET_free (session->r_prime); | ||
520 | session->r_prime = NULL; | ||
521 | } | ||
522 | if (session->s) { | ||
523 | GNUNET_free (session->s); | ||
524 | session->s = NULL; | ||
525 | } | ||
526 | if (session->s_prime) { | ||
527 | GNUNET_free (session->s_prime); | ||
528 | session->s_prime = NULL; | ||
529 | } | ||
530 | if (session->product) { | ||
531 | gcry_mpi_release (session->product); | ||
532 | session->product = NULL; | ||
533 | } | ||
534 | } | ||
535 | /////////////////////////////////////////////////////////////////////////////// | 537 | /////////////////////////////////////////////////////////////////////////////// |
536 | // Event and Message Handlers | 538 | // Event and Message Handlers |
537 | /////////////////////////////////////////////////////////////////////////////// | 539 | /////////////////////////////////////////////////////////////////////////////// |
@@ -548,39 +550,41 @@ free_session_variables (struct ServiceSession * session) | |||
548 | * @param client identification of the client | 550 | * @param client identification of the client |
549 | */ | 551 | */ |
550 | static void | 552 | static void |
551 | handle_client_disconnect (void *cls, | 553 | cb_client_disconnect (void *cls, |
552 | struct GNUNET_SERVER_Client *client) | 554 | struct GNUNET_SERVER_Client *client) |
553 | { | 555 | { |
554 | struct ServiceSession *session; | 556 | struct ServiceSession *s; |
555 | 557 | ||
556 | if (NULL != client) | 558 | if (NULL != client) |
557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
558 | _ ("Client (%p) disconnected from us.\n"), client); | 560 | _ ("Client %p disconnected from us.\n"), client); |
559 | else | 561 | else |
560 | return; | 562 | return; |
561 | 563 | ||
562 | session = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); | 564 | s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); |
563 | if (NULL == session) | 565 | if (NULL == s) |
564 | return; | 566 | return; |
565 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); | 567 | |
568 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, s); | ||
566 | 569 | ||
567 | if (!(session->role == BOB && 0/*//TODO: if session concluded*/)) { | 570 | if (NULL != s->service_transmit_handle){ |
568 | //we MUST terminate any client message underway | 571 | GNUNET_CADET_notify_transmit_ready_cancel (s->service_transmit_handle); |
569 | if (session->service_transmit_handle && session->channel) | 572 | s->service_transmit_handle = NULL; |
570 | GNUNET_CADET_notify_transmit_ready_cancel (session->service_transmit_handle); | ||
571 | if (session->channel && 0/* //TODO: waiting for service response */) | ||
572 | GNUNET_CADET_channel_destroy (session->channel); | ||
573 | } | 573 | } |
574 | if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) { | 574 | if (NULL != s->channel){ |
575 | GNUNET_SCHEDULER_cancel (session->client_notification_task); | 575 | GNUNET_CADET_channel_destroy (s->channel); |
576 | session->client_notification_task = GNUNET_SCHEDULER_NO_TASK; | 576 | s->channel = NULL; |
577 | } | 577 | } |
578 | if (NULL != session->client_transmit_handle) { | 578 | if (GNUNET_SCHEDULER_NO_TASK != s->client_notification_task){ |
579 | GNUNET_SERVER_notify_transmit_ready_cancel (session->client_transmit_handle); | 579 | GNUNET_SCHEDULER_cancel (s->client_notification_task); |
580 | session->client_transmit_handle = NULL; | 580 | s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; |
581 | } | 581 | } |
582 | free_session_variables (session); | 582 | if (NULL != s->client_transmit_handle) { |
583 | GNUNET_free (session); | 583 | GNUNET_SERVER_notify_transmit_ready_cancel (s->client_transmit_handle); |
584 | s->client_transmit_handle = NULL; | ||
585 | } | ||
586 | free_session_variables (s); | ||
587 | GNUNET_free (s); | ||
584 | } | 588 | } |
585 | 589 | ||
586 | 590 | ||
@@ -597,41 +601,40 @@ static void | |||
597 | prepare_client_end_notification (void * cls, | 601 | prepare_client_end_notification (void * cls, |
598 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 602 | const struct GNUNET_SCHEDULER_TaskContext * tc) |
599 | { | 603 | { |
600 | struct ServiceSession * session = cls; | 604 | struct ServiceSession * s = cls; |
601 | struct GNUNET_SCALARPRODUCT_client_response * msg; | 605 | struct GNUNET_SCALARPRODUCT_client_response * msg; |
602 | 606 | ||
603 | session->client_notification_task = GNUNET_SCHEDULER_NO_TASK; | 607 | s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; |
604 | 608 | ||
605 | msg = GNUNET_new (struct GNUNET_SCALARPRODUCT_client_response); | 609 | msg = GNUNET_new (struct GNUNET_SCALARPRODUCT_client_response); |
606 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 610 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
607 | memcpy (&msg->key, &session->session_id, sizeof (struct GNUNET_HashCode)); | 611 | memcpy (&msg->key, &s->session_id, sizeof (struct GNUNET_HashCode)); |
608 | memcpy (&msg->peer, &session->peer, sizeof ( struct GNUNET_PeerIdentity)); | 612 | memcpy (&msg->peer, &s->peer, sizeof ( struct GNUNET_PeerIdentity)); |
609 | msg->header.size = htons (sizeof (struct GNUNET_SCALARPRODUCT_client_response)); | 613 | msg->header.size = htons (sizeof (struct GNUNET_SCALARPRODUCT_client_response)); |
610 | // signal error if not signalized, positive result-range field but zero length. | 614 | // signal error if not signalized, positive result-range field but zero length. |
611 | msg->product_length = htonl (0); | 615 | msg->product_length = htonl (0); |
612 | msg->range = (session /* //TODO: if finalized */) ? 0 : -1; | 616 | msg->status = htonl(s->active); |
613 | 617 | ||
614 | session->msg = &msg->header; | 618 | s->msg = &msg->header; |
615 | 619 | ||
616 | //transmit this message to our client | 620 | //transmit this message to our client |
617 | session->client_transmit_handle = | 621 | s->client_transmit_handle = |
618 | GNUNET_SERVER_notify_transmit_ready (session->client, | 622 | GNUNET_SERVER_notify_transmit_ready (s->client, |
619 | sizeof (struct GNUNET_SCALARPRODUCT_client_response), | 623 | sizeof (struct GNUNET_SCALARPRODUCT_client_response), |
620 | GNUNET_TIME_UNIT_FOREVER_REL, | 624 | GNUNET_TIME_UNIT_FOREVER_REL, |
621 | &do_send_message, | 625 | &cb_transfer_message, |
622 | session); | 626 | s); |
623 | 627 | ||
624 | // if we could not even queue our request, something is wrong | 628 | // if we could not even queue our request, something is wrong |
625 | if (NULL == session->client_transmit_handle) { | 629 | if (NULL == s->client_transmit_handle) { |
626 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not send message to client (%p)!\n"), session->client); | 630 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not send message to client (%p)!\n"), s->client); |
627 | // usually gets freed by do_send_message | 631 | GNUNET_SERVER_client_disconnect(s->client); |
628 | session->msg = NULL; | 632 | free_session_variables(s); |
629 | GNUNET_free (msg); | 633 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, s); |
634 | GNUNET_free(s); | ||
630 | } | 635 | } |
631 | else | 636 | else |
632 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Sending session-end notification to client (%p) for session %s\n"), &session->client, GNUNET_h2s (&session->session_id)); | 637 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Sending session-end notification to client (%p) for session %s\n"), &s->client, GNUNET_h2s (&s->session_id)); |
633 | |||
634 | free_session_variables (session); | ||
635 | } | 638 | } |
636 | 639 | ||
637 | 640 | ||
@@ -643,61 +646,62 @@ prepare_client_end_notification (void * cls, | |||
643 | static void | 646 | static void |
644 | prepare_alices_cyrptodata_message (void *cls) | 647 | prepare_alices_cyrptodata_message (void *cls) |
645 | { | 648 | { |
646 | struct ServiceSession * session = cls; | 649 | struct ServiceSession * s = cls; |
647 | struct GNUNET_SCALARPRODUCT_alices_cryptodata_message * msg; | 650 | struct GNUNET_SCALARPRODUCT_alices_cryptodata_message * msg; |
648 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; | 651 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; |
649 | unsigned int i; | 652 | unsigned int i; |
650 | uint32_t msg_length; | 653 | uint32_t msg_length; |
651 | gcry_mpi_t a; | 654 | gcry_mpi_t a; |
652 | 655 | ||
653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Successfully created new channel to peer (%s)!\n"), GNUNET_i2s (&session->peer)); | 656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Successfully created new channel to peer (%s)!\n"), GNUNET_i2s (&s->peer)); |
654 | 657 | ||
655 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_alices_cryptodata_message) | 658 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_alices_cryptodata_message) |
656 | +session->used_elements_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 659 | +s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); |
657 | 660 | ||
658 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE > msg_length) { | 661 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE > msg_length) { |
659 | session->transferred_element_count = session->used_elements_count; | 662 | s->transferred_element_count = s->used_element_count; |
660 | } | 663 | } |
661 | else { | 664 | else { |
662 | //create a multipart msg, first we calculate a new msg size for the head msg | 665 | //create a multipart msg, first we calculate a new msg size for the head msg |
663 | session->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct GNUNET_SCALARPRODUCT_alices_cryptodata_message)) | 666 | s->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct GNUNET_SCALARPRODUCT_alices_cryptodata_message)) |
664 | / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 667 | / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); |
665 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_alices_cryptodata_message) | 668 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_alices_cryptodata_message) |
666 | +session->transferred_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 669 | +s->transferred_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); |
667 | } | 670 | } |
668 | 671 | ||
669 | msg = GNUNET_malloc (msg_length); | 672 | msg = GNUNET_malloc (msg_length); |
670 | msg->header.size = htons (msg_length); | 673 | msg->header.size = htons (msg_length); |
671 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); | 674 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); |
672 | msg->contained_element_count = htonl (session->transferred_element_count); | 675 | msg->contained_element_count = htonl (s->transferred_element_count); |
673 | 676 | ||
674 | // fill in the payload | 677 | // fill in the payload |
675 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 678 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
676 | 679 | ||
677 | // now copy over the sorted element vector | 680 | // now copy over the sorted element vector |
678 | a = gcry_mpi_new (0); | 681 | a = gcry_mpi_new (0); |
679 | for (i = 0; i < session->transferred_element_count; i++) { | 682 | for (i = 0; i < s->transferred_element_count; i++) { |
680 | gcry_mpi_add (a, session->sorted_elements[i], my_offset); | 683 | gcry_mpi_add (a, s->sorted_elements[i], my_offset); |
681 | GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i]); | 684 | GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i]); |
682 | } | 685 | } |
683 | gcry_mpi_release (a); | 686 | gcry_mpi_release (a); |
684 | 687 | ||
685 | session->msg = (struct GNUNET_MessageHeader *) msg; | 688 | s->msg = (struct GNUNET_MessageHeader *) msg; |
686 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); | 689 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); |
687 | 690 | ||
688 | //transmit via cadet messaging | 691 | //transmit via cadet messaging |
689 | session->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (session->channel, GNUNET_YES, | 692 | s->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (s->channel, GNUNET_YES, |
690 | GNUNET_TIME_UNIT_FOREVER_REL, | 693 | GNUNET_TIME_UNIT_FOREVER_REL, |
691 | msg_length, | 694 | msg_length, |
692 | &do_send_message, | 695 | &cb_transfer_message, |
693 | session); | 696 | s); |
694 | if (NULL == session->service_transmit_handle) { | 697 | if (NULL == s->service_transmit_handle) { |
695 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to channel!\n")); | 698 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to channel!\n")); |
696 | GNUNET_free (msg); | 699 | GNUNET_free (msg); |
697 | session->msg = NULL; | 700 | s->msg = NULL; |
698 | session->client_notification_task = | 701 | s->active = GNUNET_SYSERR; |
702 | s->client_notification_task = | ||
699 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 703 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
700 | session); | 704 | s); |
701 | return; | 705 | return; |
702 | } | 706 | } |
703 | } | 707 | } |
@@ -712,7 +716,7 @@ prepare_alices_cyrptodata_message (void *cls) | |||
712 | static void | 716 | static void |
713 | prepare_bobs_cryptodata_message_multipart (void *cls) | 717 | prepare_bobs_cryptodata_message_multipart (void *cls) |
714 | { | 718 | { |
715 | struct ServiceSession * session = cls; | 719 | struct ServiceSession * s = cls; |
716 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; | 720 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; |
717 | struct GNUNET_SCALARPRODUCT_multipart_message * msg; | 721 | struct GNUNET_SCALARPRODUCT_multipart_message * msg; |
718 | unsigned int i; | 722 | unsigned int i; |
@@ -721,7 +725,7 @@ prepare_bobs_cryptodata_message_multipart (void *cls) | |||
721 | uint32_t todo_count; | 725 | uint32_t todo_count; |
722 | 726 | ||
723 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message); | 727 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message); |
724 | todo_count = session->used_elements_count - session->transferred_element_count; | 728 | todo_count = s->used_element_count - s->transferred_element_count; |
725 | 729 | ||
726 | if (todo_count > MULTIPART_ELEMENT_CAPACITY / 2) | 730 | if (todo_count > MULTIPART_ELEMENT_CAPACITY / 2) |
727 | // send the currently possible maximum chunk, we always transfer both permutations | 731 | // send the currently possible maximum chunk, we always transfer both permutations |
@@ -734,44 +738,43 @@ prepare_bobs_cryptodata_message_multipart (void *cls) | |||
734 | msg->contained_element_count = htonl (todo_count); | 738 | msg->contained_element_count = htonl (todo_count); |
735 | 739 | ||
736 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 740 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
737 | for (i = session->transferred_element_count, j = 0; i < session->transferred_element_count + todo_count; i++) { | 741 | for (i = s->transferred_element_count, j = 0; i < s->transferred_element_count + todo_count; i++) { |
738 | //r[i][p] and r[i][q] | 742 | //r[i][p] and r[i][q] |
739 | memcpy (&payload[j++], &session->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 743 | memcpy (&payload[j++], &s->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
740 | memcpy (&payload[j++], &session->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 744 | memcpy (&payload[j++], &s->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
741 | } | 745 | } |
742 | session->transferred_element_count += todo_count; | 746 | s->transferred_element_count += todo_count; |
743 | session->msg = (struct GNUNET_MessageHeader *) msg; | 747 | s->msg = (struct GNUNET_MessageHeader *) msg; |
744 | session->service_transmit_handle = | 748 | s->service_transmit_handle = |
745 | GNUNET_CADET_notify_transmit_ready (session->channel, | 749 | GNUNET_CADET_notify_transmit_ready (s->channel, |
746 | GNUNET_YES, | 750 | GNUNET_YES, |
747 | GNUNET_TIME_UNIT_FOREVER_REL, | 751 | GNUNET_TIME_UNIT_FOREVER_REL, |
748 | msg_length, | 752 | msg_length, |
749 | &do_send_message, | 753 | &cb_transfer_message, |
750 | session); | 754 | s); |
751 | //disconnect our client | 755 | if (NULL == s->service_transmit_handle) { |
752 | if (NULL == session->service_transmit_handle) { | ||
753 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n")); | 756 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n")); |
754 | 757 | ||
755 | GNUNET_free (msg); | 758 | GNUNET_free (msg); |
756 | session->msg = NULL; | 759 | s->msg = NULL; |
757 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 760 | GNUNET_CADET_channel_destroy(s->channel); |
761 | s->response->active = GNUNET_SYSERR; | ||
758 | 762 | ||
759 | session->response->client_notification_task = | 763 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); |
764 | |||
765 | s->response->client_notification_task = | ||
760 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 766 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
761 | session->response); | 767 | s->response); |
762 | free_session_variables(session); | 768 | free_session_variables(s); |
763 | GNUNET_free(session); | 769 | GNUNET_free(s); |
764 | return; | 770 | return; |
765 | } | 771 | } |
766 | if (session->transferred_element_count != session->used_elements_count) { | 772 | if (s->transferred_element_count == s->used_element_count) { |
767 | // more multiparts | ||
768 | } | ||
769 | else { | ||
770 | // final part | 773 | // final part |
771 | GNUNET_free (session->r_prime); | 774 | GNUNET_free (s->r_prime); |
772 | GNUNET_free (session->r); | 775 | GNUNET_free (s->r); |
773 | session->r_prime = NULL; | 776 | s->r_prime = NULL; |
774 | session->r = NULL; | 777 | s->r = NULL; |
775 | } | 778 | } |
776 | } | 779 | } |
777 | 780 | ||
@@ -792,7 +795,7 @@ prepare_bobs_cryptodata_message (void *cls, | |||
792 | const struct GNUNET_SCHEDULER_TaskContext | 795 | const struct GNUNET_SCHEDULER_TaskContext |
793 | * tc) | 796 | * tc) |
794 | { | 797 | { |
795 | struct ServiceSession * session = (struct ServiceSession *) cls; | 798 | struct ServiceSession * s = (struct ServiceSession *) cls; |
796 | struct GNUNET_SCALARPRODUCT_service_response * msg; | 799 | struct GNUNET_SCALARPRODUCT_service_response * msg; |
797 | uint32_t msg_length = 0; | 800 | uint32_t msg_length = 0; |
798 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; | 801 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; |
@@ -802,70 +805,72 @@ prepare_bobs_cryptodata_message (void *cls, | |||
802 | + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); // s, stick | 805 | + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); // s, stick |
803 | 806 | ||
804 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE > | 807 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE > |
805 | msg_length + 2 * session->used_elements_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) { //r, r' | 808 | msg_length + 2 * s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) { //r, r' |
806 | msg_length += 2 * session->used_elements_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 809 | msg_length += 2 * s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); |
807 | session->transferred_element_count = session->used_elements_count; | 810 | s->transferred_element_count = s->used_element_count; |
808 | } | 811 | } |
809 | else | 812 | else |
810 | session->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - msg_length) / | 813 | s->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - msg_length) / |
811 | (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 2); | 814 | (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 2); |
812 | 815 | ||
813 | msg = GNUNET_malloc (msg_length); | 816 | msg = GNUNET_malloc (msg_length); |
814 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); | 817 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); |
815 | msg->header.size = htons (msg_length); | 818 | msg->header.size = htons (msg_length); |
816 | msg->total_element_count = htonl (session->total); | 819 | msg->total_element_count = htonl (s->total); |
817 | msg->used_element_count = htonl (session->used_elements_count); | 820 | msg->used_element_count = htonl (s->used_element_count); |
818 | msg->contained_element_count = htonl (session->transferred_element_count); | 821 | msg->contained_element_count = htonl (s->transferred_element_count); |
819 | memcpy (&msg->key, &session->session_id, sizeof (struct GNUNET_HashCode)); | 822 | memcpy (&msg->key, &s->session_id, sizeof (struct GNUNET_HashCode)); |
820 | 823 | ||
821 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 824 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
822 | memcpy (&payload[0], session->s, sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 825 | memcpy (&payload[0], s->s, sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
823 | memcpy (&payload[1], session->s_prime, sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 826 | memcpy (&payload[1], s->s_prime, sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
824 | GNUNET_free (session->s_prime); | 827 | GNUNET_free (s->s_prime); |
825 | session->s_prime = NULL; | 828 | s->s_prime = NULL; |
826 | GNUNET_free (session->s); | 829 | GNUNET_free (s->s); |
827 | session->s = NULL; | 830 | s->s = NULL; |
828 | 831 | ||
829 | payload = &payload[2]; | 832 | payload = &payload[2]; |
830 | // convert k[][] | 833 | // convert k[][] |
831 | for (i = 0; i < session->transferred_element_count; i++) { | 834 | for (i = 0; i < s->transferred_element_count; i++) { |
832 | //k[i][p] and k[i][q] | 835 | //k[i][p] and k[i][q] |
833 | memcpy (&payload[i * 2], &session->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 836 | memcpy (&payload[i * 2], &s->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
834 | memcpy (&payload[i * 2 + 1], &session->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 837 | memcpy (&payload[i * 2 + 1], &s->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
835 | } | 838 | } |
836 | 839 | ||
837 | session->msg = (struct GNUNET_MessageHeader *) msg; | 840 | s->msg = (struct GNUNET_MessageHeader *) msg; |
838 | session->service_transmit_handle = | 841 | s->service_transmit_handle = |
839 | GNUNET_CADET_notify_transmit_ready (session->channel, | 842 | GNUNET_CADET_notify_transmit_ready (s->channel, |
840 | GNUNET_YES, | 843 | GNUNET_YES, |
841 | GNUNET_TIME_UNIT_FOREVER_REL, | 844 | GNUNET_TIME_UNIT_FOREVER_REL, |
842 | msg_length, | 845 | msg_length, |
843 | &do_send_message, | 846 | &cb_transfer_message, |
844 | session); | 847 | s); |
845 | //disconnect our client | 848 | if (NULL == s->service_transmit_handle) { |
846 | if (NULL == session->service_transmit_handle) { | 849 | //disconnect our client |
847 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n")); | 850 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n")); |
848 | 851 | ||
849 | GNUNET_free (msg); | 852 | GNUNET_free (msg); |
850 | session->msg = NULL; | 853 | s->msg = NULL; |
851 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 854 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); |
855 | GNUNET_CADET_channel_destroy(s->channel); | ||
856 | s->response->active = GNUNET_SYSERR; | ||
852 | 857 | ||
853 | session->response->client_notification_task = | 858 | s->response->client_notification_task = |
854 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 859 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
855 | session->response); | 860 | s->response); |
856 | free_session_variables(session); | 861 | free_session_variables(s); |
857 | GNUNET_free(session); | 862 | GNUNET_free(s); |
858 | return; | 863 | return; |
859 | } | 864 | } |
860 | if (session->transferred_element_count != session->used_elements_count) { | 865 | if (s->transferred_element_count != s->used_element_count) { |
861 | // multipart | 866 | // multipart |
862 | } | 867 | } |
863 | else { | 868 | else { |
864 | //singlepart | 869 | //singlepart |
865 | GNUNET_free (session->r); | 870 | GNUNET_free (s->r); |
866 | session->r = NULL; | 871 | s->r = NULL; |
867 | GNUNET_free (session->r_prime); | 872 | GNUNET_free (s->r_prime); |
868 | session->r_prime = NULL; | 873 | s->r_prime = NULL; |
869 | } | 874 | } |
870 | } | 875 | } |
871 | 876 | ||
@@ -896,7 +901,7 @@ compute_service_response (struct ServiceSession * session) | |||
896 | struct GNUNET_CRYPTO_PaillierCiphertext * s; | 901 | struct GNUNET_CRYPTO_PaillierCiphertext * s; |
897 | struct GNUNET_CRYPTO_PaillierCiphertext * s_prime; | 902 | struct GNUNET_CRYPTO_PaillierCiphertext * s_prime; |
898 | 903 | ||
899 | count = session->used_elements_count; | 904 | count = session->used_element_count; |
900 | a = session->e_a; | 905 | a = session->e_a; |
901 | b = session->sorted_elements; | 906 | b = session->sorted_elements; |
902 | q = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, count); | 907 | q = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, count); |
@@ -996,7 +1001,7 @@ compute_service_response (struct ServiceSession * session) | |||
996 | GNUNET_free (rand); | 1001 | GNUNET_free (rand); |
997 | 1002 | ||
998 | // copy the r[], r_prime[], S and Stick into a new message, prepare_service_response frees these | 1003 | // copy the r[], r_prime[], S and Stick into a new message, prepare_service_response frees these |
999 | GNUNET_SCHEDULER_add_now (&prepare_bobs_cryptodata_message, session); | 1004 | GNUNET_SCHEDULER_add_now (&prepare_bobs_cryptodata_message, s); |
1000 | } | 1005 | } |
1001 | 1006 | ||
1002 | 1007 | ||
@@ -1015,9 +1020,9 @@ cb_insert_element_sorted (void *cls, | |||
1015 | const struct GNUNET_HashCode *key, | 1020 | const struct GNUNET_HashCode *key, |
1016 | void *value) | 1021 | void *value) |
1017 | { | 1022 | { |
1018 | struct ServiceSession * session = (struct ServiceSession*) cls; | 1023 | struct ServiceSession * s = (struct ServiceSession*) cls; |
1019 | struct SortedValue * e = GNUNET_new (struct SortedValue); | 1024 | struct SortedValue * e = GNUNET_new (struct SortedValue); |
1020 | struct SortedValue * o = session->a_head; | 1025 | struct SortedValue * o = s->a_head; |
1021 | 1026 | ||
1022 | e->elem = value; | 1027 | e->elem = value; |
1023 | e->val = gcry_mpi_new (0); | 1028 | e->val = gcry_mpi_new (0); |
@@ -1027,20 +1032,20 @@ cb_insert_element_sorted (void *cls, | |||
1027 | gcry_mpi_add_ui (e->val, e->val, e->elem->value); | 1032 | gcry_mpi_add_ui (e->val, e->val, e->elem->value); |
1028 | 1033 | ||
1029 | // insert as first element with the lowest key | 1034 | // insert as first element with the lowest key |
1030 | if (NULL == session->a_head | 1035 | if (NULL == s->a_head |
1031 | || (0 <= GNUNET_CRYPTO_hash_cmp (&session->a_head->elem->key, &e->elem->key))) { | 1036 | || (0 <= GNUNET_CRYPTO_hash_cmp (&s->a_head->elem->key, &e->elem->key))) { |
1032 | GNUNET_CONTAINER_DLL_insert (session->a_head, session->a_tail, e); | 1037 | GNUNET_CONTAINER_DLL_insert (s->a_head, s->a_tail, e); |
1033 | return GNUNET_YES; | 1038 | return GNUNET_YES; |
1034 | } | 1039 | } |
1035 | // insert as last element with the highest key | 1040 | // insert as last element with the highest key |
1036 | if (0 >= GNUNET_CRYPTO_hash_cmp (&session->a_tail->elem->key, &e->elem->key)) { | 1041 | if (0 >= GNUNET_CRYPTO_hash_cmp (&s->a_tail->elem->key, &e->elem->key)) { |
1037 | GNUNET_CONTAINER_DLL_insert_tail (session->a_head, session->a_tail, e); | 1042 | GNUNET_CONTAINER_DLL_insert_tail (s->a_head, s->a_tail, e); |
1038 | return GNUNET_YES; | 1043 | return GNUNET_YES; |
1039 | } | 1044 | } |
1040 | // insert before the first higher/equal element | 1045 | // insert before the first higher/equal element |
1041 | do { | 1046 | do { |
1042 | if (0 <= GNUNET_CRYPTO_hash_cmp (&o->elem->key, &e->elem->key)) { | 1047 | if (0 <= GNUNET_CRYPTO_hash_cmp (&o->elem->key, &e->elem->key)) { |
1043 | GNUNET_CONTAINER_DLL_insert_before (session->a_head, session->a_tail, o, e); | 1048 | GNUNET_CONTAINER_DLL_insert_before (s->a_head, s->a_tail, o, e); |
1044 | return GNUNET_YES; | 1049 | return GNUNET_YES; |
1045 | } | 1050 | } |
1046 | o = o->next; | 1051 | o = o->next; |
@@ -1064,7 +1069,7 @@ cb_intersection_element_removed (void *cls, | |||
1064 | const struct GNUNET_SET_Element *element, | 1069 | const struct GNUNET_SET_Element *element, |
1065 | enum GNUNET_SET_Status status) | 1070 | enum GNUNET_SET_Status status) |
1066 | { | 1071 | { |
1067 | struct ServiceSession * session = (struct ServiceSession*) cls; | 1072 | struct ServiceSession * s = (struct ServiceSession*) cls; |
1068 | struct GNUNET_SCALARPRODUCT_Element * se; | 1073 | struct GNUNET_SCALARPRODUCT_Element * se; |
1069 | int i; | 1074 | int i; |
1070 | 1075 | ||
@@ -1072,43 +1077,46 @@ cb_intersection_element_removed (void *cls, | |||
1072 | { | 1077 | { |
1073 | case GNUNET_SET_STATUS_OK: | 1078 | case GNUNET_SET_STATUS_OK: |
1074 | //this element has been removed from the set | 1079 | //this element has been removed from the set |
1075 | se = GNUNET_CONTAINER_multihashmap_get (session->intersected_elements, | 1080 | se = GNUNET_CONTAINER_multihashmap_get (s->intersected_elements, |
1076 | element->data); | 1081 | element->data); |
1077 | 1082 | ||
1078 | GNUNET_CONTAINER_multihashmap_remove (session->intersected_elements, | 1083 | GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, |
1079 | element->data, | 1084 | element->data, |
1080 | se); | 1085 | se); |
1081 | session->used_elements_count--; | 1086 | s->used_element_count--; |
1082 | return; | 1087 | return; |
1083 | 1088 | ||
1084 | case GNUNET_SET_STATUS_DONE: | 1089 | case GNUNET_SET_STATUS_DONE: |
1085 | if (2 > session->used_elements_count) { | 1090 | //stop listening for further requests |
1091 | GNUNET_SET_listen_cancel (s->intersection_listen); | ||
1092 | |||
1093 | if (2 > s->used_element_count) { | ||
1086 | // failed! do not leak information about our single remaining element! | 1094 | // failed! do not leak information about our single remaining element! |
1087 | // continue after the loop | 1095 | // continue after the loop |
1088 | break; | 1096 | break; |
1089 | } | 1097 | } |
1090 | 1098 | ||
1091 | GNUNET_CONTAINER_multihashmap_iterate (session->intersected_elements, | 1099 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
1092 | &cb_insert_element_sorted, | 1100 | &cb_insert_element_sorted, |
1093 | session); | 1101 | s); |
1094 | 1102 | ||
1095 | session->sorted_elements = GNUNET_malloc (session->used_elements_count * sizeof (gcry_mpi_t)); | 1103 | s->sorted_elements = GNUNET_malloc (s->used_element_count * sizeof (gcry_mpi_t)); |
1096 | for (i = 0; NULL != session->a_head; i++) { | 1104 | for (i = 0; NULL != s->a_head; i++) { |
1097 | struct SortedValue* a = session->a_head; | 1105 | struct SortedValue* a = s->a_head; |
1098 | GNUNET_assert (i < session->used_elements_count); | 1106 | GNUNET_assert (i < s->used_element_count); |
1099 | 1107 | ||
1100 | session->sorted_elements[i] = a->val; | 1108 | s->sorted_elements[i] = a->val; |
1101 | GNUNET_CONTAINER_DLL_remove (session->a_head, session->a_tail, a); | 1109 | GNUNET_CONTAINER_DLL_remove (s->a_head, s->a_tail, a); |
1102 | GNUNET_free (a->elem); | 1110 | GNUNET_free (a->elem); |
1103 | } | 1111 | } |
1104 | GNUNET_assert (i == session->used_elements_count); | 1112 | GNUNET_assert (i == s->used_element_count); |
1105 | 1113 | ||
1106 | if (ALICE == session->role) { | 1114 | if (ALICE == s->role) { |
1107 | prepare_alices_cyrptodata_message (session); | 1115 | prepare_alices_cyrptodata_message (s); |
1108 | return; | 1116 | return; |
1109 | } | 1117 | } |
1110 | else if (session->used_elements_count == session->transferred_element_count) { | 1118 | else if (s->used_element_count == s->transferred_element_count) { |
1111 | compute_service_response (session); | 1119 | compute_service_response (s); |
1112 | return; | 1120 | return; |
1113 | } | 1121 | } |
1114 | default: | 1122 | default: |
@@ -1119,18 +1127,20 @@ cb_intersection_element_removed (void *cls, | |||
1119 | GNUNET_break (0); | 1127 | GNUNET_break (0); |
1120 | 1128 | ||
1121 | // and notify our client-session that we could not complete the session | 1129 | // and notify our client-session that we could not complete the session |
1122 | if (ALICE == session->role) { | 1130 | if (ALICE == s->role) { |
1123 | session->client_notification_task = | 1131 | s->active = GNUNET_SYSERR; |
1132 | s->client_notification_task = | ||
1124 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1133 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1125 | session); | 1134 | s); |
1126 | } | 1135 | } |
1127 | else { | 1136 | else { |
1128 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 1137 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); |
1129 | free_session_variables (session); | 1138 | free_session_variables (s); |
1130 | session->response->client_notification_task = | 1139 | s->response->active = GNUNET_SYSERR; |
1140 | s->response->client_notification_task = | ||
1131 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1141 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1132 | session->response); | 1142 | s->response); |
1133 | GNUNET_free(session); | 1143 | GNUNET_free(s); |
1134 | } | 1144 | } |
1135 | } | 1145 | } |
1136 | 1146 | ||
@@ -1156,31 +1166,32 @@ cb_intersection_request_alice (void *cls, | |||
1156 | const struct GNUNET_MessageHeader *context_msg, | 1166 | const struct GNUNET_MessageHeader *context_msg, |
1157 | struct GNUNET_SET_Request *request) | 1167 | struct GNUNET_SET_Request *request) |
1158 | { | 1168 | { |
1159 | struct ServiceSession * session = (struct ServiceSession *) cls; | 1169 | struct ServiceSession * s = (struct ServiceSession *) cls; |
1160 | 1170 | ||
1161 | // check the peer-id, the app-id=session-id is compared by SET | 1171 | // check the peer-id, the app-id=session-id is compared by SET |
1162 | if (0 != memcmp (&session->peer, &other_peer, sizeof (struct GNUNET_PeerIdentity))) | 1172 | if (0 != memcmp (&s->peer, &other_peer, sizeof (struct GNUNET_PeerIdentity))) |
1163 | return; | 1173 | return; |
1164 | 1174 | ||
1165 | session->intersection_op = GNUNET_SET_accept (request, | 1175 | s->intersection_op = GNUNET_SET_accept (request, |
1166 | GNUNET_SET_RESULT_REMOVED, | 1176 | GNUNET_SET_RESULT_REMOVED, |
1167 | cb_intersection_element_removed, | 1177 | cb_intersection_element_removed, |
1168 | session); | 1178 | s); |
1169 | 1179 | if (NULL == s->intersection_op) { | |
1170 | if (NULL == session->intersection_op) { | 1180 | s->active = GNUNET_SYSERR; |
1171 | session->response->client_notification_task = | 1181 | s->client_notification_task = |
1172 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1182 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1173 | session); | 1183 | s); |
1174 | return; | 1184 | return; |
1175 | } | 1185 | } |
1176 | if (GNUNET_OK != GNUNET_SET_commit (session->intersection_op, session->intersection_set)) { | 1186 | if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set)) { |
1177 | session->response->client_notification_task = | 1187 | s->active = GNUNET_SYSERR; |
1188 | s->client_notification_task = | ||
1178 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1189 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1179 | session); | 1190 | s); |
1180 | return; | 1191 | return; |
1181 | } | 1192 | } |
1182 | session->intersection_set = NULL; | 1193 | s->intersection_set = NULL; |
1183 | session->intersection_listen = NULL; | 1194 | s->intersection_listen = NULL; |
1184 | } | 1195 | } |
1185 | 1196 | ||
1186 | 1197 | ||
@@ -1195,7 +1206,7 @@ static void | |||
1195 | prepare_client_response (void *cls, | 1206 | prepare_client_response (void *cls, |
1196 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1207 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1197 | { | 1208 | { |
1198 | struct ServiceSession * session = cls; | 1209 | struct ServiceSession * s = cls; |
1199 | struct GNUNET_SCALARPRODUCT_client_response * msg; | 1210 | struct GNUNET_SCALARPRODUCT_client_response * msg; |
1200 | unsigned char * product_exported = NULL; | 1211 | unsigned char * product_exported = NULL; |
1201 | size_t product_length = 0; | 1212 | size_t product_length = 0; |
@@ -1204,26 +1215,26 @@ prepare_client_response (void *cls, | |||
1204 | gcry_error_t rc; | 1215 | gcry_error_t rc; |
1205 | int sign; | 1216 | int sign; |
1206 | 1217 | ||
1207 | session->client_notification_task = GNUNET_SCHEDULER_NO_TASK; | 1218 | s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; |
1208 | 1219 | ||
1209 | if (session->product) { | 1220 | if (s->product) { |
1210 | gcry_mpi_t value = gcry_mpi_new (0); | 1221 | gcry_mpi_t value = gcry_mpi_new (0); |
1211 | 1222 | ||
1212 | sign = gcry_mpi_cmp_ui (session->product, 0); | 1223 | sign = gcry_mpi_cmp_ui (s->product, 0); |
1213 | // libgcrypt can not handle a print of a negative number | 1224 | // libgcrypt can not handle a print of a negative number |
1214 | // if (a->sign) return gcry_error (GPG_ERR_INTERNAL); /* Can't handle it yet. */ | 1225 | // if (a->sign) return gcry_error (GPG_ERR_INTERNAL); /* Can't handle it yet. */ |
1215 | if (0 > sign) { | 1226 | if (0 > sign) { |
1216 | gcry_mpi_sub (value, value, session->product); | 1227 | gcry_mpi_sub (value, value, s->product); |
1217 | } | 1228 | } |
1218 | else if (0 < sign) { | 1229 | else if (0 < sign) { |
1219 | range = 1; | 1230 | range = 1; |
1220 | gcry_mpi_add (value, value, session->product); | 1231 | gcry_mpi_add (value, value, s->product); |
1221 | } | 1232 | } |
1222 | else | 1233 | else |
1223 | range = 0; | 1234 | range = 0; |
1224 | 1235 | ||
1225 | gcry_mpi_release (session->product); | 1236 | gcry_mpi_release (s->product); |
1226 | session->product = NULL; | 1237 | s->product = NULL; |
1227 | 1238 | ||
1228 | // get representation as string | 1239 | // get representation as string |
1229 | if (range | 1240 | if (range |
@@ -1240,8 +1251,8 @@ prepare_client_response (void *cls, | |||
1240 | 1251 | ||
1241 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_client_response) +product_length; | 1252 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_client_response) +product_length; |
1242 | msg = GNUNET_malloc (msg_length); | 1253 | msg = GNUNET_malloc (msg_length); |
1243 | msg->key = session->session_id; | 1254 | msg->key = s->session_id; |
1244 | msg->peer = session->peer; | 1255 | msg->peer = s->peer; |
1245 | if (product_exported != NULL) { | 1256 | if (product_exported != NULL) { |
1246 | memcpy (&msg[1], product_exported, product_length); | 1257 | memcpy (&msg[1], product_exported, product_length); |
1247 | GNUNET_free (product_exported); | 1258 | GNUNET_free (product_exported); |
@@ -1251,30 +1262,30 @@ prepare_client_response (void *cls, | |||
1251 | msg->range = range; | 1262 | msg->range = range; |
1252 | msg->product_length = htonl (product_length); | 1263 | msg->product_length = htonl (product_length); |
1253 | 1264 | ||
1254 | session->msg = (struct GNUNET_MessageHeader *) msg; | 1265 | s->msg = (struct GNUNET_MessageHeader *) msg; |
1255 | //transmit this message to our client | 1266 | //transmit this message to our client |
1256 | session->client_transmit_handle = | 1267 | s->client_transmit_handle = |
1257 | GNUNET_SERVER_notify_transmit_ready (session->client, | 1268 | GNUNET_SERVER_notify_transmit_ready (s->client, |
1258 | msg_length, | 1269 | msg_length, |
1259 | GNUNET_TIME_UNIT_FOREVER_REL, | 1270 | GNUNET_TIME_UNIT_FOREVER_REL, |
1260 | &do_send_message, | 1271 | &cb_transfer_message, |
1261 | session); | 1272 | s); |
1262 | if (NULL == session->client_transmit_handle) { | 1273 | if (NULL == s->client_transmit_handle) { |
1263 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1274 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1264 | _ ("Could not send message to client (%p)!\n"), | 1275 | _ ("Could not send message to client (%p)!\n"), |
1265 | session->client); | 1276 | s->client); |
1266 | session->client = NULL; | 1277 | GNUNET_SERVER_client_disconnect(s->client); |
1267 | // callback was not called! | 1278 | free_session_variables(s); |
1268 | GNUNET_free (msg); | 1279 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, s); |
1269 | session->msg = NULL; | 1280 | GNUNET_free(s); |
1270 | } | 1281 | } |
1271 | else | 1282 | else |
1272 | // gracefully sent message, just terminate session structure | 1283 | // gracefully sent message, just terminate session structure |
1273 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1284 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1274 | _ ("Sent result to client (%p), this session (%s) has ended!\n"), | 1285 | _ ("Sent result to client (%p), this session (%s) has ended!\n"), |
1275 | session->client, | 1286 | s->client, |
1276 | GNUNET_h2s (&session->session_id)); | 1287 | GNUNET_h2s (&s->session_id)); |
1277 | free_session_variables (session); | 1288 | free_session_variables (s); |
1278 | } | 1289 | } |
1279 | 1290 | ||
1280 | 1291 | ||
@@ -1284,34 +1295,35 @@ prepare_client_response (void *cls, | |||
1284 | * @param session the session associated with this request | 1295 | * @param session the session associated with this request |
1285 | */ | 1296 | */ |
1286 | static void | 1297 | static void |
1287 | prepare_alices_computation_request (struct ServiceSession * session) | 1298 | prepare_alices_computation_request (struct ServiceSession * s) |
1288 | { | 1299 | { |
1289 | struct GNUNET_SCALARPRODUCT_service_request * msg; | 1300 | struct GNUNET_SCALARPRODUCT_service_request * msg; |
1290 | 1301 | ||
1291 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Successfully created new channel to peer (%s)!\n"), GNUNET_i2s (&session->peer)); | 1302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Successfully created new channel to peer (%s)!\n"), GNUNET_i2s (&s->peer)); |
1292 | 1303 | ||
1293 | msg = GNUNET_new (struct GNUNET_SCALARPRODUCT_service_request); | 1304 | msg = GNUNET_new (struct GNUNET_SCALARPRODUCT_service_request); |
1294 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); | 1305 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); |
1295 | msg->total_element_count = htonl (session->used_elements_count); | 1306 | msg->total_element_count = htonl (s->used_element_count); |
1296 | memcpy (&msg->session_id, &session->session_id, sizeof (struct GNUNET_HashCode)); | 1307 | memcpy (&msg->session_id, &s->session_id, sizeof (struct GNUNET_HashCode)); |
1297 | msg->header.size = htons (sizeof (struct GNUNET_SCALARPRODUCT_service_request)); | 1308 | msg->header.size = htons (sizeof (struct GNUNET_SCALARPRODUCT_service_request)); |
1298 | 1309 | ||
1299 | session->msg = (struct GNUNET_MessageHeader *) msg; | 1310 | s->msg = (struct GNUNET_MessageHeader *) msg; |
1300 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); | 1311 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); |
1301 | 1312 | ||
1302 | //transmit via cadet messaging | 1313 | //transmit via cadet messaging |
1303 | session->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (session->channel, GNUNET_YES, | 1314 | s->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (s->channel, GNUNET_YES, |
1304 | GNUNET_TIME_UNIT_FOREVER_REL, | 1315 | GNUNET_TIME_UNIT_FOREVER_REL, |
1305 | sizeof (struct GNUNET_SCALARPRODUCT_service_request), | 1316 | sizeof (struct GNUNET_SCALARPRODUCT_service_request), |
1306 | &do_send_message, | 1317 | &cb_transfer_message, |
1307 | session); | 1318 | s); |
1308 | if (!session->service_transmit_handle) { | 1319 | if (!s->service_transmit_handle) { |
1309 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to channel!\n")); | 1320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to channel!\n")); |
1310 | GNUNET_free (msg); | 1321 | GNUNET_free (msg); |
1311 | session->msg = NULL; | 1322 | s->msg = NULL; |
1312 | session->client_notification_task = | 1323 | s->active = GNUNET_SYSERR; |
1324 | s->client_notification_task = | ||
1313 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1325 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1314 | session); | 1326 | s); |
1315 | return; | 1327 | return; |
1316 | } | 1328 | } |
1317 | } | 1329 | } |
@@ -1329,7 +1341,7 @@ prepare_alices_computation_request (struct ServiceSession * session) | |||
1329 | static void | 1341 | static void |
1330 | prepare_alices_cyrptodata_message_multipart (void *cls) | 1342 | prepare_alices_cyrptodata_message_multipart (void *cls) |
1331 | { | 1343 | { |
1332 | struct ServiceSession * session = cls; | 1344 | struct ServiceSession * s = cls; |
1333 | struct GNUNET_SCALARPRODUCT_multipart_message * msg; | 1345 | struct GNUNET_SCALARPRODUCT_multipart_message * msg; |
1334 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; | 1346 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; |
1335 | unsigned int i; | 1347 | unsigned int i; |
@@ -1338,7 +1350,7 @@ prepare_alices_cyrptodata_message_multipart (void *cls) | |||
1338 | gcry_mpi_t a; | 1350 | gcry_mpi_t a; |
1339 | 1351 | ||
1340 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message); | 1352 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message); |
1341 | todo_count = session->used_elements_count - session->transferred_element_count; | 1353 | todo_count = s->used_element_count - s->transferred_element_count; |
1342 | 1354 | ||
1343 | if (todo_count > MULTIPART_ELEMENT_CAPACITY) | 1355 | if (todo_count > MULTIPART_ELEMENT_CAPACITY) |
1344 | // send the currently possible maximum chunk | 1356 | // send the currently possible maximum chunk |
@@ -1354,29 +1366,30 @@ prepare_alices_cyrptodata_message_multipart (void *cls) | |||
1354 | 1366 | ||
1355 | // now copy over the sorted element vector | 1367 | // now copy over the sorted element vector |
1356 | a = gcry_mpi_new (0); | 1368 | a = gcry_mpi_new (0); |
1357 | for (i = session->transferred_element_count; i < todo_count; i++) { | 1369 | for (i = s->transferred_element_count; i < todo_count; i++) { |
1358 | gcry_mpi_add (a, session->sorted_elements[i], my_offset); | 1370 | gcry_mpi_add (a, s->sorted_elements[i], my_offset); |
1359 | GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - session->transferred_element_count]); | 1371 | GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - s->transferred_element_count]); |
1360 | } | 1372 | } |
1361 | gcry_mpi_release (a); | 1373 | gcry_mpi_release (a); |
1362 | session->transferred_element_count += todo_count; | 1374 | s->transferred_element_count += todo_count; |
1363 | 1375 | ||
1364 | session->msg = (struct GNUNET_MessageHeader *) msg; | 1376 | s->msg = (struct GNUNET_MessageHeader *) msg; |
1365 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); | 1377 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); |
1366 | 1378 | ||
1367 | //transmit via cadet messaging | 1379 | //transmit via cadet messaging |
1368 | session->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (session->channel, GNUNET_YES, | 1380 | s->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (s->channel, GNUNET_YES, |
1369 | GNUNET_TIME_UNIT_FOREVER_REL, | 1381 | GNUNET_TIME_UNIT_FOREVER_REL, |
1370 | msg_length, | 1382 | msg_length, |
1371 | &do_send_message, | 1383 | &cb_transfer_message, |
1372 | session); | 1384 | s); |
1373 | if (!session->service_transmit_handle) { | 1385 | if (!s->service_transmit_handle) { |
1374 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-request multipart message to channel!\n")); | 1386 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-request multipart message to channel!\n")); |
1375 | GNUNET_free (msg); | 1387 | GNUNET_free (msg); |
1376 | session->msg = NULL; | 1388 | s->msg = NULL; |
1377 | session->client_notification_task = | 1389 | s->active = GNUNET_SYSERR; |
1390 | s->client_notification_task = | ||
1378 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1391 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1379 | session); | 1392 | s); |
1380 | return; | 1393 | return; |
1381 | } | 1394 | } |
1382 | } | 1395 | } |
@@ -1390,32 +1403,32 @@ prepare_alices_cyrptodata_message_multipart (void *cls) | |||
1390 | static void | 1403 | static void |
1391 | client_request_complete_bob (struct ServiceSession * client_session) | 1404 | client_request_complete_bob (struct ServiceSession * client_session) |
1392 | { | 1405 | { |
1393 | struct ServiceSession * session; | 1406 | struct ServiceSession * s; |
1394 | 1407 | ||
1395 | //check if service queue contains a matching request | 1408 | //check if service queue contains a matching request |
1396 | session = find_matching_session (from_service_tail, | 1409 | s = find_matching_session (from_service_tail, |
1397 | &client_session->session_id, | 1410 | &client_session->session_id, |
1398 | client_session->total, NULL); | 1411 | client_session->total, NULL); |
1399 | if (NULL != session) { | 1412 | if (NULL != s) { |
1400 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1413 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1401 | _ ("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"), | 1414 | _ ("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"), |
1402 | GNUNET_h2s (&client_session->session_id)); | 1415 | GNUNET_h2s (&client_session->session_id)); |
1403 | 1416 | ||
1404 | session->response = client_session; | 1417 | s->response = client_session; |
1405 | session->intersected_elements = client_session->intersected_elements; | 1418 | s->intersected_elements = client_session->intersected_elements; |
1406 | client_session->intersected_elements = NULL; | 1419 | client_session->intersected_elements = NULL; |
1407 | session->intersection_set = client_session->intersection_set; | 1420 | s->intersection_set = client_session->intersection_set; |
1408 | client_session->intersection_set = NULL; | 1421 | client_session->intersection_set = NULL; |
1409 | 1422 | ||
1410 | session->intersection_op = GNUNET_SET_prepare (&session->peer, | 1423 | s->intersection_op = GNUNET_SET_prepare (&s->peer, |
1411 | &session->session_id, | 1424 | &s->session_id, |
1412 | NULL, | 1425 | NULL, |
1413 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT16_MAX), | 1426 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT16_MAX), |
1414 | GNUNET_SET_RESULT_REMOVED, | 1427 | GNUNET_SET_RESULT_REMOVED, |
1415 | cb_intersection_element_removed, | 1428 | cb_intersection_element_removed, |
1416 | session); | 1429 | s); |
1417 | 1430 | ||
1418 | GNUNET_SET_commit (session->intersection_op, session->intersection_set); | 1431 | GNUNET_SET_commit (s->intersection_op, s->intersection_set); |
1419 | } | 1432 | } |
1420 | else { | 1433 | else { |
1421 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1434 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -1433,33 +1446,35 @@ client_request_complete_bob (struct ServiceSession * client_session) | |||
1433 | * @param session the service session context | 1446 | * @param session the service session context |
1434 | */ | 1447 | */ |
1435 | static void | 1448 | static void |
1436 | client_request_complete_alice (struct ServiceSession * session) | 1449 | client_request_complete_alice (struct ServiceSession * s) |
1437 | { | 1450 | { |
1438 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1451 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1439 | _ ("Creating new channel for session with key %s.\n"), | 1452 | _ ("Creating new channel for session with key %s.\n"), |
1440 | GNUNET_h2s (&session->session_id)); | 1453 | GNUNET_h2s (&s->session_id)); |
1441 | session->channel = GNUNET_CADET_channel_create (my_cadet, session, | 1454 | s->channel = GNUNET_CADET_channel_create (my_cadet, s, |
1442 | &session->peer, | 1455 | &s->peer, |
1443 | GNUNET_APPLICATION_TYPE_SCALARPRODUCT, | 1456 | GNUNET_APPLICATION_TYPE_SCALARPRODUCT, |
1444 | GNUNET_CADET_OPTION_RELIABLE); | 1457 | GNUNET_CADET_OPTION_RELIABLE); |
1445 | if (NULL == session->channel) { | 1458 | if (NULL == s->channel) { |
1446 | session->response->client_notification_task = | 1459 | s->active = GNUNET_SYSERR; |
1460 | s->client_notification_task = | ||
1447 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1461 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1448 | session); | 1462 | s); |
1449 | return; | 1463 | return; |
1450 | } | 1464 | } |
1451 | session->intersection_listen = GNUNET_SET_listen (cfg, | 1465 | s->intersection_listen = GNUNET_SET_listen (cfg, |
1452 | GNUNET_SET_OPERATION_INTERSECTION, | 1466 | GNUNET_SET_OPERATION_INTERSECTION, |
1453 | &session->session_id, | 1467 | &s->session_id, |
1454 | cb_intersection_request_alice, | 1468 | cb_intersection_request_alice, |
1455 | session); | 1469 | s); |
1456 | if (NULL == session->intersection_listen) { | 1470 | if (NULL == s->intersection_listen) { |
1457 | session->response->client_notification_task = | 1471 | s->active = GNUNET_SYSERR; |
1472 | s->client_notification_task = | ||
1458 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1473 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1459 | session); | 1474 | s); |
1460 | return; | 1475 | return; |
1461 | } | 1476 | } |
1462 | prepare_alices_computation_request (session); | 1477 | prepare_alices_computation_request (s); |
1463 | } | 1478 | } |
1464 | 1479 | ||
1465 | 1480 | ||
@@ -1469,14 +1484,14 @@ handle_client_message_multipart (void *cls, | |||
1469 | const struct GNUNET_MessageHeader *message) | 1484 | const struct GNUNET_MessageHeader *message) |
1470 | { | 1485 | { |
1471 | const struct GNUNET_SCALARPRODUCT_computation_message_multipart * msg = (const struct GNUNET_SCALARPRODUCT_computation_message_multipart *) message; | 1486 | const struct GNUNET_SCALARPRODUCT_computation_message_multipart * msg = (const struct GNUNET_SCALARPRODUCT_computation_message_multipart *) message; |
1472 | struct ServiceSession * session; | 1487 | struct ServiceSession * s; |
1473 | uint32_t contained_count; | 1488 | uint32_t contained_count; |
1474 | struct GNUNET_SCALARPRODUCT_Element * elements; | 1489 | struct GNUNET_SCALARPRODUCT_Element * elements; |
1475 | uint32_t i; | 1490 | uint32_t i; |
1476 | 1491 | ||
1477 | // only one concurrent session per client connection allowed, simplifies logics a lot... | 1492 | // only one concurrent session per client connection allowed, simplifies logics a lot... |
1478 | session = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); | 1493 | s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); |
1479 | if (NULL == session) { | 1494 | if (NULL == s) { |
1480 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1495 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1481 | return; | 1496 | return; |
1482 | } | 1497 | } |
@@ -1485,12 +1500,12 @@ handle_client_message_multipart (void *cls, | |||
1485 | 1500 | ||
1486 | //sanity check: is the message as long as the message_count fields suggests? | 1501 | //sanity check: is the message as long as the message_count fields suggests? |
1487 | if ((ntohs (msg->header.size) != (sizeof (struct GNUNET_SCALARPRODUCT_computation_message_multipart) +contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) | 1502 | if ((ntohs (msg->header.size) != (sizeof (struct GNUNET_SCALARPRODUCT_computation_message_multipart) +contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) |
1488 | || (0 == contained_count) || (session->total < session->transferred_element_count + contained_count)) { | 1503 | || (0 == contained_count) || (s->total < s->transferred_element_count + contained_count)) { |
1489 | GNUNET_break_op (0); | 1504 | GNUNET_break_op (0); |
1490 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1505 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1491 | return; | 1506 | return; |
1492 | } | 1507 | } |
1493 | session->transferred_element_count += contained_count; | 1508 | s->transferred_element_count += contained_count; |
1494 | 1509 | ||
1495 | elements = (struct GNUNET_SCALARPRODUCT_Element *) & msg[1]; | 1510 | elements = (struct GNUNET_SCALARPRODUCT_Element *) & msg[1]; |
1496 | for (i = 0; i < contained_count; i++) { | 1511 | for (i = 0; i < contained_count; i++) { |
@@ -1503,7 +1518,7 @@ handle_client_message_multipart (void *cls, | |||
1503 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | 1518 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); |
1504 | memcpy (elem, &elements[i], sizeof (struct GNUNET_SCALARPRODUCT_Element)); | 1519 | memcpy (elem, &elements[i], sizeof (struct GNUNET_SCALARPRODUCT_Element)); |
1505 | 1520 | ||
1506 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (session->intersected_elements, | 1521 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, |
1507 | &elem->key, | 1522 | &elem->key, |
1508 | elem, | 1523 | elem, |
1509 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { | 1524 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { |
@@ -1513,20 +1528,20 @@ handle_client_message_multipart (void *cls, | |||
1513 | set_elem.data = &elements[i].key; | 1528 | set_elem.data = &elements[i].key; |
1514 | set_elem.size = htons (sizeof (elements[i].key)); | 1529 | set_elem.size = htons (sizeof (elements[i].key)); |
1515 | set_elem.type = htons (0); /* do we REALLY need this? */ | 1530 | set_elem.type = htons (0); /* do we REALLY need this? */ |
1516 | GNUNET_SET_add_element (session->intersection_set, &set_elem, NULL, NULL); | 1531 | GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); |
1517 | session->used_elements_count++; | 1532 | s->used_element_count++; |
1518 | } | 1533 | } |
1519 | 1534 | ||
1520 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1535 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1521 | 1536 | ||
1522 | if (session->total != session->transferred_element_count) | 1537 | if (s->total != s->transferred_element_count) |
1523 | // multipart msg | 1538 | // multipart msg |
1524 | return; | 1539 | return; |
1525 | 1540 | ||
1526 | if (ALICE == session->role) | 1541 | if (ALICE == s->role) |
1527 | client_request_complete_alice (session); | 1542 | client_request_complete_alice (s); |
1528 | else | 1543 | else |
1529 | client_request_complete_bob (session); | 1544 | client_request_complete_bob (s); |
1530 | } | 1545 | } |
1531 | 1546 | ||
1532 | 1547 | ||
@@ -1546,7 +1561,7 @@ handle_client_message (void *cls, | |||
1546 | const struct GNUNET_MessageHeader *message) | 1561 | const struct GNUNET_MessageHeader *message) |
1547 | { | 1562 | { |
1548 | const struct GNUNET_SCALARPRODUCT_computation_message * msg = (const struct GNUNET_SCALARPRODUCT_computation_message *) message; | 1563 | const struct GNUNET_SCALARPRODUCT_computation_message * msg = (const struct GNUNET_SCALARPRODUCT_computation_message *) message; |
1549 | struct ServiceSession * session; | 1564 | struct ServiceSession * s; |
1550 | uint32_t contained_count; | 1565 | uint32_t contained_count; |
1551 | uint32_t total_count; | 1566 | uint32_t total_count; |
1552 | uint32_t msg_type; | 1567 | uint32_t msg_type; |
@@ -1554,8 +1569,8 @@ handle_client_message (void *cls, | |||
1554 | uint32_t i; | 1569 | uint32_t i; |
1555 | 1570 | ||
1556 | // only one concurrent session per client connection allowed, simplifies logics a lot... | 1571 | // only one concurrent session per client connection allowed, simplifies logics a lot... |
1557 | session = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); | 1572 | s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); |
1558 | if (NULL != session) { | 1573 | if (NULL != s) { |
1559 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1574 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1560 | return; | 1575 | return; |
1561 | } | 1576 | } |
@@ -1591,17 +1606,17 @@ handle_client_message (void *cls, | |||
1591 | return; | 1606 | return; |
1592 | } | 1607 | } |
1593 | 1608 | ||
1594 | session = GNUNET_new (struct ServiceSession); | 1609 | s = GNUNET_new (struct ServiceSession); |
1595 | session->client_notification_task = GNUNET_SCHEDULER_NO_TASK; | 1610 | s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; |
1596 | session->client = client; | 1611 | s->client = client; |
1597 | session->total = total_count; | 1612 | s->total = total_count; |
1598 | session->transferred_element_count = contained_count; | 1613 | s->transferred_element_count = contained_count; |
1599 | // get our transaction key | 1614 | // get our transaction key |
1600 | memcpy (&session->session_id, &msg->session_key, sizeof (struct GNUNET_HashCode)); | 1615 | memcpy (&s->session_id, &msg->session_key, sizeof (struct GNUNET_HashCode)); |
1601 | 1616 | ||
1602 | elements = (struct GNUNET_SCALARPRODUCT_Element *) & msg[1]; | 1617 | elements = (struct GNUNET_SCALARPRODUCT_Element *) & msg[1]; |
1603 | session->intersected_elements = GNUNET_CONTAINER_multihashmap_create (session->total, GNUNET_NO); | 1618 | s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_NO); |
1604 | session->intersection_set = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); | 1619 | s->intersection_set = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); |
1605 | for (i = 0; i < contained_count; i++) { | 1620 | for (i = 0; i < contained_count; i++) { |
1606 | struct GNUNET_SET_Element set_elem; | 1621 | struct GNUNET_SET_Element set_elem; |
1607 | struct GNUNET_SCALARPRODUCT_Element * elem; | 1622 | struct GNUNET_SCALARPRODUCT_Element * elem; |
@@ -1612,7 +1627,7 @@ handle_client_message (void *cls, | |||
1612 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | 1627 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); |
1613 | memcpy (elem, &elements[i], sizeof (struct GNUNET_SCALARPRODUCT_Element)); | 1628 | memcpy (elem, &elements[i], sizeof (struct GNUNET_SCALARPRODUCT_Element)); |
1614 | 1629 | ||
1615 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (session->intersected_elements, | 1630 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, |
1616 | &elem->key, | 1631 | &elem->key, |
1617 | elem, | 1632 | elem, |
1618 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { | 1633 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { |
@@ -1622,30 +1637,30 @@ handle_client_message (void *cls, | |||
1622 | set_elem.data = &elements[i].key; | 1637 | set_elem.data = &elements[i].key; |
1623 | set_elem.size = htons (sizeof (elements[i].key)); | 1638 | set_elem.size = htons (sizeof (elements[i].key)); |
1624 | set_elem.type = htons (0); /* do we REALLY need this? */ | 1639 | set_elem.type = htons (0); /* do we REALLY need this? */ |
1625 | GNUNET_SET_add_element (session->intersection_set, &set_elem, NULL, NULL); | 1640 | GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); |
1626 | session->used_elements_count++; | 1641 | s->used_element_count++; |
1627 | } | 1642 | } |
1628 | 1643 | ||
1629 | if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) { | 1644 | if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) { |
1630 | session->role = ALICE; | 1645 | s->role = ALICE; |
1631 | memcpy (&session->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); | 1646 | memcpy (&s->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); |
1632 | } | 1647 | } |
1633 | else { | 1648 | else { |
1634 | session->role = BOB; | 1649 | s->role = BOB; |
1635 | } | 1650 | } |
1636 | 1651 | ||
1637 | GNUNET_CONTAINER_DLL_insert (from_client_head, from_client_tail, session); | 1652 | GNUNET_CONTAINER_DLL_insert (from_client_head, from_client_tail, s); |
1638 | GNUNET_SERVER_client_set_user_context (client, session); | 1653 | GNUNET_SERVER_client_set_user_context (client, s); |
1639 | GNUNET_SERVER_receive_done (client, GNUNET_YES); | 1654 | GNUNET_SERVER_receive_done (client, GNUNET_YES); |
1640 | 1655 | ||
1641 | if (session->total != session->transferred_element_count) | 1656 | if (s->total != s->transferred_element_count) |
1642 | // multipart msg | 1657 | // multipart msg |
1643 | return; | 1658 | return; |
1644 | 1659 | ||
1645 | if (ALICE == session->role) | 1660 | if (ALICE == s->role) |
1646 | client_request_complete_alice (session); | 1661 | client_request_complete_alice (s); |
1647 | else | 1662 | else |
1648 | client_request_complete_bob (session); | 1663 | client_request_complete_bob (s); |
1649 | } | 1664 | } |
1650 | 1665 | ||
1651 | 1666 | ||
@@ -1666,16 +1681,17 @@ cb_channel_incoming (void *cls, | |||
1666 | const struct GNUNET_PeerIdentity *initiator, | 1681 | const struct GNUNET_PeerIdentity *initiator, |
1667 | uint32_t port, enum GNUNET_CADET_ChannelOption options) | 1682 | uint32_t port, enum GNUNET_CADET_ChannelOption options) |
1668 | { | 1683 | { |
1669 | struct ServiceSession * c = GNUNET_new (struct ServiceSession); | 1684 | struct ServiceSession * s = GNUNET_new (struct ServiceSession); |
1670 | 1685 | ||
1671 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1686 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1672 | _ ("New incoming channel from peer %s.\n"), | 1687 | _ ("New incoming channel from peer %s.\n"), |
1673 | GNUNET_i2s (initiator)); | 1688 | GNUNET_i2s (initiator)); |
1674 | 1689 | ||
1675 | c->peer = *initiator; | 1690 | s->peer = *initiator; |
1676 | c->channel = channel; | 1691 | s->channel = channel; |
1677 | c->role = BOB; | 1692 | s->role = BOB; |
1678 | return c; | 1693 | s->active = GNUNET_YES; |
1694 | return s; | ||
1679 | } | 1695 | } |
1680 | 1696 | ||
1681 | 1697 | ||
@@ -1695,45 +1711,39 @@ cb_channel_destruction (void *cls, | |||
1695 | const struct GNUNET_CADET_Channel *channel, | 1711 | const struct GNUNET_CADET_Channel *channel, |
1696 | void *channel_ctx) | 1712 | void *channel_ctx) |
1697 | { | 1713 | { |
1698 | struct ServiceSession * session = channel_ctx; | 1714 | struct ServiceSession * s = channel_ctx; |
1699 | struct ServiceSession * client_session; | 1715 | struct ServiceSession * client_session; |
1700 | struct ServiceSession * curr; | ||
1701 | 1716 | ||
1702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1703 | _ ("Peer disconnected, terminating session %s with peer (%s)\n"), | 1718 | _ ("Peer disconnected, terminating session %s with peer (%s)\n"), |
1704 | GNUNET_h2s (&session->session_id), | 1719 | GNUNET_h2s (&s->session_id), |
1705 | GNUNET_i2s (&session->peer)); | 1720 | GNUNET_i2s (&s->peer)); |
1706 | if (ALICE == session->role) { | 1721 | |
1707 | // as we have only one peer connected in each session, just remove the session | 1722 | // as we have only one peer connected in each session, just remove the session |
1708 | 1723 | s->channel = NULL; | |
1709 | if ((0/*//TODO: only for complete session*/) && (!do_shutdown)) { | 1724 | |
1710 | session->channel = NULL; | 1725 | if ((ALICE == s->role) && (GNUNET_NO != s->active) && (!do_shutdown)) { |
1711 | // if this happened before we received the answer, we must terminate the session | 1726 | // if this happened before we received the answer, we must terminate the session |
1712 | session->client_notification_task = | 1727 | s->role = GNUNET_SYSERR; |
1713 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1728 | s->client_notification_task = |
1714 | session); | 1729 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1715 | } | 1730 | s); |
1716 | } | 1731 | } |
1717 | else { //(BOB == session->role) service session | 1732 | else { |
1718 | // remove the session, unless it has already been dequeued, but somehow still active | 1733 | if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) |
1719 | // this could bug without the IF in case the queue is empty and the service session was the only one know to the service | 1734 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); |
1720 | // scenario: disconnect before alice can send her message to bob. | 1735 | |
1721 | for (curr = from_service_head; NULL != curr; curr = curr->next) | ||
1722 | if (curr == session) { | ||
1723 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, curr); | ||
1724 | break; | ||
1725 | } | ||
1726 | // there is a client waiting for this service session, terminate it, too! | 1736 | // there is a client waiting for this service session, terminate it, too! |
1727 | // i assume the tupel of key and element count is unique. if it was not the rest of the code would not work either. | 1737 | // i assume the tupel of key and element count is unique. if it was not the rest of the code would not work either. |
1728 | client_session = find_matching_session (from_client_tail, | 1738 | client_session = s->response; |
1729 | &session->session_id, | 1739 | if ((NULL != s->response ) && (GNUNET_NO == s->active) && (GNUNET_YES == client_session->active)) |
1730 | session->total, NULL); | 1740 | client_session->active = GNUNET_NO; |
1731 | free_session_variables (session); | 1741 | free_session_variables (s); |
1732 | GNUNET_free (session); | 1742 | GNUNET_free (s); |
1733 | 1743 | ||
1734 | // the client has to check if it was waiting for a result | 1744 | // the client has to check if it was waiting for a result |
1735 | // or if it was a responder, no point in adding more statefulness | 1745 | // or if it was a responder, no point in adding more statefulness |
1736 | if (client_session && (!do_shutdown)) { | 1746 | if ((NULL != s->response ) && (!do_shutdown)) { |
1737 | client_session->client_notification_task = | 1747 | client_session->client_notification_task = |
1738 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1748 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1739 | client_session); | 1749 | client_session); |
@@ -1758,13 +1768,13 @@ compute_scalar_product (struct ServiceSession * session) | |||
1758 | gcry_mpi_t p; | 1768 | gcry_mpi_t p; |
1759 | gcry_mpi_t p_prime; | 1769 | gcry_mpi_t p_prime; |
1760 | gcry_mpi_t tmp; | 1770 | gcry_mpi_t tmp; |
1761 | gcry_mpi_t r[session->used_elements_count]; | 1771 | gcry_mpi_t r[session->used_element_count]; |
1762 | gcry_mpi_t r_prime[session->used_elements_count]; | 1772 | gcry_mpi_t r_prime[session->used_element_count]; |
1763 | gcry_mpi_t s; | 1773 | gcry_mpi_t s; |
1764 | gcry_mpi_t s_prime; | 1774 | gcry_mpi_t s_prime; |
1765 | unsigned int i; | 1775 | unsigned int i; |
1766 | 1776 | ||
1767 | count = session->used_elements_count; | 1777 | count = session->used_element_count; |
1768 | // due to the introduced static offset S, we now also have to remove this | 1778 | // due to the introduced static offset S, we now also have to remove this |
1769 | // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each, | 1779 | // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each, |
1770 | // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) | 1780 | // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) |
@@ -1861,17 +1871,17 @@ handle_alices_cyrptodata_message_multipart (void *cls, | |||
1861 | void **channel_ctx, | 1871 | void **channel_ctx, |
1862 | const struct GNUNET_MessageHeader * message) | 1872 | const struct GNUNET_MessageHeader * message) |
1863 | { | 1873 | { |
1864 | struct ServiceSession * session; | 1874 | struct ServiceSession * s; |
1865 | const struct GNUNET_SCALARPRODUCT_multipart_message * msg = (const struct GNUNET_SCALARPRODUCT_multipart_message *) message; | 1875 | const struct GNUNET_SCALARPRODUCT_multipart_message * msg = (const struct GNUNET_SCALARPRODUCT_multipart_message *) message; |
1866 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; | 1876 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; |
1867 | uint32_t contained_elements; | 1877 | uint32_t contained_elements; |
1868 | uint32_t msg_length; | 1878 | uint32_t msg_length; |
1869 | 1879 | ||
1870 | // are we in the correct state? | 1880 | // are we in the correct state? |
1871 | session = (struct ServiceSession *) * channel_ctx; | 1881 | s = (struct ServiceSession *) * channel_ctx; |
1872 | //we are not bob | 1882 | //we are not bob |
1873 | if ((NULL == session->e_a) || //or we did not expect this message yet | 1883 | if ((NULL == s->e_a) || //or we did not expect this message yet |
1874 | (session->used_elements_count == session->transferred_element_count)) { //we are not expecting multipart messages | 1884 | (s->used_element_count == s->transferred_element_count)) { //we are not expecting multipart messages |
1875 | goto except; | 1885 | goto except; |
1876 | } | 1886 | } |
1877 | // shorter than minimum? | 1887 | // shorter than minimum? |
@@ -1883,43 +1893,47 @@ handle_alices_cyrptodata_message_multipart (void *cls, | |||
1883 | +contained_elements * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 1893 | +contained_elements * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); |
1884 | //sanity check | 1894 | //sanity check |
1885 | if ((ntohs (msg->header.size) != msg_length) | 1895 | if ((ntohs (msg->header.size) != msg_length) |
1886 | || (session->used_elements_count < contained_elements + session->transferred_element_count) | 1896 | || (s->used_element_count < contained_elements + s->transferred_element_count) |
1887 | || (0 == contained_elements)) { | 1897 | || (0 == contained_elements)) { |
1888 | goto except; | 1898 | goto except; |
1889 | } | 1899 | } |
1890 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 1900 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
1891 | // Convert each vector element to MPI_value | 1901 | // Convert each vector element to MPI_value |
1892 | memcpy (&session->e_a[session->transferred_element_count], payload, | 1902 | memcpy (&s->e_a[s->transferred_element_count], payload, |
1893 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); | 1903 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); |
1894 | 1904 | ||
1895 | session->transferred_element_count += contained_elements; | 1905 | s->transferred_element_count += contained_elements; |
1896 | 1906 | ||
1897 | if (contained_elements == session->used_elements_count) { | 1907 | if (contained_elements == s->used_element_count) { |
1898 | // single part finished | 1908 | // single part finished |
1899 | if (NULL == session->intersection_op) | 1909 | if (NULL == s->intersection_op) |
1900 | // intersection has already finished, so we can proceed | 1910 | // intersection has already finished, so we can proceed |
1901 | compute_service_response (session); | 1911 | compute_service_response (s); |
1902 | } | 1912 | } |
1903 | 1913 | ||
1904 | return GNUNET_OK; | 1914 | return GNUNET_OK; |
1905 | except: | 1915 | except: |
1906 | session->channel = NULL; | 1916 | s->channel = NULL; |
1907 | // and notify our client-session that we could not complete the session | 1917 | // and notify our client-session that we could not complete the session |
1908 | free_session_variables (session); | 1918 | free_session_variables (s); |
1909 | if (NULL != session->client){ | 1919 | if (NULL != s->client){ |
1910 | //Alice | 1920 | //Alice |
1911 | session->client_notification_task = | 1921 | s->active = GNUNET_SYSERR; |
1922 | s->client_notification_task = | ||
1912 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1923 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1913 | session); | 1924 | s); |
1914 | } | 1925 | } |
1915 | else { | 1926 | else { |
1916 | //Bob | 1927 | //Bob |
1917 | if (NULL != session->response) | 1928 | if (NULL != s->response){ |
1918 | session->response->client_notification_task = | 1929 | s->response->active = GNUNET_SYSERR; |
1919 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1930 | s->response->client_notification_task = |
1920 | session->response); | 1931 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1921 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 1932 | s->response); |
1922 | GNUNET_free(session); | 1933 | } |
1934 | if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) | ||
1935 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); | ||
1936 | GNUNET_free (s); | ||
1923 | } | 1937 | } |
1924 | return GNUNET_SYSERR; | 1938 | return GNUNET_SYSERR; |
1925 | } | 1939 | } |
@@ -1941,22 +1955,22 @@ handle_alices_cyrptodata_message (void *cls, | |||
1941 | void **channel_ctx, | 1955 | void **channel_ctx, |
1942 | const struct GNUNET_MessageHeader * message) | 1956 | const struct GNUNET_MessageHeader * message) |
1943 | { | 1957 | { |
1944 | struct ServiceSession * session; | 1958 | struct ServiceSession * s; |
1945 | const struct GNUNET_SCALARPRODUCT_alices_cryptodata_message * msg = (const struct GNUNET_SCALARPRODUCT_alices_cryptodata_message *) message; | 1959 | const struct GNUNET_SCALARPRODUCT_alices_cryptodata_message * msg = (const struct GNUNET_SCALARPRODUCT_alices_cryptodata_message *) message; |
1946 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; | 1960 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; |
1947 | uint32_t contained_elements = 0; | 1961 | uint32_t contained_elements = 0; |
1948 | uint32_t msg_length; | 1962 | uint32_t msg_length; |
1949 | 1963 | ||
1950 | session = (struct ServiceSession *) * channel_ctx; | 1964 | s = (struct ServiceSession *) * channel_ctx; |
1951 | //we are not bob | 1965 | //we are not bob |
1952 | if ((BOB != session->role) | 1966 | if ((BOB != s->role) |
1953 | //we are expecting multipart messages instead | 1967 | //we are expecting multipart messages instead |
1954 | || (NULL != session->e_a) | 1968 | || (NULL != s->e_a) |
1955 | //or we did not expect this message yet | 1969 | //or we did not expect this message yet |
1956 | || //intersection OP has not yet finished | 1970 | || //intersection OP has not yet finished |
1957 | !((NULL != session->intersection_op) | 1971 | !((NULL != s->intersection_op) |
1958 | //intersection OP done | 1972 | //intersection OP done |
1959 | || (session->response->sorted_elements) | 1973 | || (s->response->sorted_elements) |
1960 | )) { | 1974 | )) { |
1961 | goto invalid_msg; | 1975 | goto invalid_msg; |
1962 | } | 1976 | } |
@@ -1972,42 +1986,46 @@ handle_alices_cyrptodata_message (void *cls, | |||
1972 | 1986 | ||
1973 | //sanity check: is the message as long as the message_count fields suggests? | 1987 | //sanity check: is the message as long as the message_count fields suggests? |
1974 | if ((ntohs (msg->header.size) != msg_length) || | 1988 | if ((ntohs (msg->header.size) != msg_length) || |
1975 | (session->used_elements_count < session->transferred_element_count + contained_elements) || | 1989 | (s->used_element_count < s->transferred_element_count + contained_elements) || |
1976 | (0 == contained_elements)) { | 1990 | (0 == contained_elements)) { |
1977 | goto invalid_msg; | 1991 | goto invalid_msg; |
1978 | } | 1992 | } |
1979 | 1993 | ||
1980 | session->transferred_element_count = contained_elements; | 1994 | s->transferred_element_count = contained_elements; |
1981 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext*) &msg[1]; | 1995 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext*) &msg[1]; |
1982 | 1996 | ||
1983 | session->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * session->used_elements_count); | 1997 | s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count); |
1984 | memcpy (&session->e_a[0], payload, contained_elements * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 1998 | memcpy (&s->e_a[0], payload, contained_elements * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
1985 | if (contained_elements == session->used_elements_count) { | 1999 | if (contained_elements == s->used_element_count) { |
1986 | // single part finished | 2000 | // single part finished |
1987 | if (NULL == session->intersection_op) | 2001 | if (NULL == s->intersection_op) |
1988 | // intersection has already finished, so we can proceed | 2002 | // intersection has already finished, so we can proceed |
1989 | compute_service_response (session); | 2003 | compute_service_response (s); |
1990 | } | 2004 | } |
1991 | return GNUNET_OK; | 2005 | return GNUNET_OK; |
1992 | invalid_msg: | 2006 | invalid_msg: |
1993 | GNUNET_break_op (0); | 2007 | GNUNET_break_op (0); |
1994 | session->channel = NULL; | 2008 | s->channel = NULL; |
1995 | // and notify our client-session that we could not complete the session | 2009 | // and notify our client-session that we could not complete the session |
1996 | free_session_variables (session); | 2010 | free_session_variables (s); |
1997 | if (NULL != session->client){ | 2011 | if (NULL != s->client){ |
1998 | //Alice | 2012 | //Alice |
1999 | session->client_notification_task = | 2013 | s->active = GNUNET_SYSERR; |
2014 | s->client_notification_task = | ||
2000 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 2015 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2001 | session); | 2016 | s); |
2002 | } | 2017 | } |
2003 | else { | 2018 | else { |
2004 | //Bob | 2019 | //Bob |
2005 | if (NULL != session->response) | 2020 | if (NULL != s->response) { |
2006 | session->response->client_notification_task = | 2021 | s->response->active = GNUNET_SYSERR; |
2007 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 2022 | s->response->client_notification_task = |
2008 | session->response); | 2023 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2009 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 2024 | s->response); |
2010 | GNUNET_free(session); | 2025 | } |
2026 | if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) | ||
2027 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); | ||
2028 | GNUNET_free(s); | ||
2011 | } | 2029 | } |
2012 | return GNUNET_SYSERR; | 2030 | return GNUNET_SYSERR; |
2013 | } | 2031 | } |
@@ -2029,25 +2047,25 @@ handle_alices_computation_request (void *cls, | |||
2029 | void **channel_ctx, | 2047 | void **channel_ctx, |
2030 | const struct GNUNET_MessageHeader * message) | 2048 | const struct GNUNET_MessageHeader * message) |
2031 | { | 2049 | { |
2032 | struct ServiceSession * session; | 2050 | struct ServiceSession * s; |
2033 | struct ServiceSession * client_session; | 2051 | struct ServiceSession * client_session; |
2034 | const struct GNUNET_SCALARPRODUCT_service_request * msg = (const struct GNUNET_SCALARPRODUCT_service_request *) message; | 2052 | const struct GNUNET_SCALARPRODUCT_service_request * msg = (const struct GNUNET_SCALARPRODUCT_service_request *) message; |
2035 | uint32_t total_elements; | 2053 | uint32_t total_elements; |
2036 | 2054 | ||
2037 | session = (struct ServiceSession *) * channel_ctx; | 2055 | s = (struct ServiceSession *) * channel_ctx; |
2038 | if (session->total != 0) { | 2056 | if ((BOB != s->role) && (s->total != 0)) { |
2039 | // must be a fresh session | 2057 | // must be a fresh session |
2040 | goto invalid_msg; | 2058 | goto invalid_msg; |
2041 | } | 2059 | } |
2042 | // Check if message was sent by me, which would be bad! | 2060 | // Check if message was sent by me, which would be bad! |
2043 | if (!memcmp (&session->peer, &me, sizeof (struct GNUNET_PeerIdentity))) { | 2061 | if (!memcmp (&s->peer, &me, sizeof (struct GNUNET_PeerIdentity))) { |
2044 | GNUNET_free (session); | 2062 | GNUNET_free (s); |
2045 | GNUNET_break (0); | 2063 | GNUNET_break (0); |
2046 | return GNUNET_SYSERR; | 2064 | return GNUNET_SYSERR; |
2047 | } | 2065 | } |
2048 | // shorter than expected? | 2066 | // shorter than expected? |
2049 | if (ntohs (msg->header.size) != sizeof (struct GNUNET_SCALARPRODUCT_service_request)) { | 2067 | if (ntohs (msg->header.size) != sizeof (struct GNUNET_SCALARPRODUCT_service_request)) { |
2050 | GNUNET_free (session); | 2068 | GNUNET_free (s); |
2051 | GNUNET_break_op (0); | 2069 | GNUNET_break_op (0); |
2052 | return GNUNET_SYSERR; | 2070 | return GNUNET_SYSERR; |
2053 | } | 2071 | } |
@@ -2055,7 +2073,7 @@ handle_alices_computation_request (void *cls, | |||
2055 | 2073 | ||
2056 | //sanity check: is the message as long as the message_count fields suggests? | 2074 | //sanity check: is the message as long as the message_count fields suggests? |
2057 | if (1 > total_elements) { | 2075 | if (1 > total_elements) { |
2058 | GNUNET_free (session); | 2076 | GNUNET_free (s); |
2059 | GNUNET_break_op (0); | 2077 | GNUNET_break_op (0); |
2060 | return GNUNET_SYSERR; | 2078 | return GNUNET_SYSERR; |
2061 | } | 2079 | } |
@@ -2066,72 +2084,76 @@ handle_alices_computation_request (void *cls, | |||
2066 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2084 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2067 | _ ("Got message with duplicate session key (`%s'), ignoring service request.\n"), | 2085 | _ ("Got message with duplicate session key (`%s'), ignoring service request.\n"), |
2068 | (const char *) &(msg->session_id)); | 2086 | (const char *) &(msg->session_id)); |
2069 | GNUNET_free (session); | 2087 | GNUNET_free (s); |
2070 | return GNUNET_SYSERR; | 2088 | return GNUNET_SYSERR; |
2071 | } | 2089 | } |
2072 | 2090 | ||
2073 | session->total = total_elements; | 2091 | s->total = total_elements; |
2074 | session->channel = channel; | 2092 | s->channel = channel; |
2075 | 2093 | ||
2076 | // session key | 2094 | // session key |
2077 | memcpy (&session->session_id, &msg->session_id, sizeof (struct GNUNET_HashCode)); | 2095 | memcpy (&s->session_id, &msg->session_id, sizeof (struct GNUNET_HashCode)); |
2078 | 2096 | ||
2079 | // public key | 2097 | // public key |
2080 | session->remote_pubkey = GNUNET_new (struct GNUNET_CRYPTO_PaillierPublicKey); | 2098 | s->remote_pubkey = GNUNET_new (struct GNUNET_CRYPTO_PaillierPublicKey); |
2081 | memcpy (session->remote_pubkey, &msg->public_key, sizeof (struct GNUNET_CRYPTO_PaillierPublicKey)); | 2099 | memcpy (s->remote_pubkey, &msg->public_key, sizeof (struct GNUNET_CRYPTO_PaillierPublicKey)); |
2082 | 2100 | ||
2083 | //check if service queue contains a matching request | 2101 | //check if service queue contains a matching request |
2084 | client_session = find_matching_session (from_client_tail, | 2102 | client_session = find_matching_session (from_client_tail, |
2085 | &session->session_id, | 2103 | &s->session_id, |
2086 | session->total, NULL); | 2104 | s->total, NULL); |
2087 | 2105 | ||
2088 | GNUNET_CONTAINER_DLL_insert (from_service_head, from_service_tail, session); | 2106 | GNUNET_CONTAINER_DLL_insert (from_service_head, from_service_tail, s); |
2089 | 2107 | ||
2090 | if ((NULL != client_session) | 2108 | if ((NULL != client_session) |
2091 | && (client_session->transferred_element_count == client_session->total)) { | 2109 | && (client_session->transferred_element_count == client_session->total)) { |
2092 | 2110 | ||
2093 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->session_id)); | 2111 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&s->session_id)); |
2094 | 2112 | ||
2095 | session->response = client_session; | 2113 | s->response = client_session; |
2096 | session->intersected_elements = client_session->intersected_elements; | 2114 | s->intersected_elements = client_session->intersected_elements; |
2097 | client_session->intersected_elements = NULL; | 2115 | client_session->intersected_elements = NULL; |
2098 | session->intersection_set = client_session->intersection_set; | 2116 | s->intersection_set = client_session->intersection_set; |
2099 | client_session->intersection_set = NULL; | 2117 | client_session->intersection_set = NULL; |
2100 | 2118 | ||
2101 | session->intersection_op = GNUNET_SET_prepare (&session->peer, | 2119 | s->intersection_op = GNUNET_SET_prepare (&s->peer, |
2102 | &session->session_id, | 2120 | &s->session_id, |
2103 | NULL, | 2121 | NULL, |
2104 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT16_MAX), | 2122 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT16_MAX), |
2105 | GNUNET_SET_RESULT_REMOVED, | 2123 | GNUNET_SET_RESULT_REMOVED, |
2106 | cb_intersection_element_removed, | 2124 | cb_intersection_element_removed, |
2107 | session); | 2125 | s); |
2108 | 2126 | ||
2109 | GNUNET_SET_commit (session->intersection_op, session->intersection_set); | 2127 | GNUNET_SET_commit (s->intersection_op, s->intersection_set); |
2110 | } | 2128 | } |
2111 | else { | 2129 | else { |
2112 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s without a matching element set, queueing.\n"), GNUNET_h2s (&session->session_id)); | 2130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s without a matching element set, queueing.\n"), GNUNET_h2s (&s->session_id)); |
2113 | } | 2131 | } |
2114 | 2132 | ||
2115 | return GNUNET_OK; | 2133 | return GNUNET_OK; |
2116 | invalid_msg: | 2134 | invalid_msg: |
2117 | GNUNET_break_op (0); | 2135 | GNUNET_break_op (0); |
2118 | session->channel = NULL; | 2136 | s->channel = NULL; |
2119 | // and notify our client-session that we could not complete the session | 2137 | // and notify our client-session that we could not complete the session |
2120 | free_session_variables (session); | 2138 | free_session_variables (s); |
2121 | if (NULL != session->client){ | 2139 | if (NULL != s->client){ |
2122 | //Alice | 2140 | //Alice |
2123 | session->client_notification_task = | 2141 | s->active = GNUNET_SYSERR; |
2142 | s->client_notification_task = | ||
2124 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 2143 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2125 | session); | 2144 | s); |
2126 | } | 2145 | } |
2127 | else { | 2146 | else { |
2128 | //Bob | 2147 | //Bob |
2129 | if (NULL != session->response) | 2148 | if (NULL != s->response) { |
2130 | session->response->client_notification_task = | 2149 | s->response->active = GNUNET_SYSERR; |
2131 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 2150 | s->response->client_notification_task = |
2132 | session->response); | 2151 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2133 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 2152 | s->response); |
2134 | GNUNET_free(session); | 2153 | } |
2154 | if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) | ||
2155 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); | ||
2156 | GNUNET_free(s); | ||
2135 | } | 2157 | } |
2136 | return GNUNET_SYSERR; | 2158 | return GNUNET_SYSERR; |
2137 | } | 2159 | } |
@@ -2153,7 +2175,7 @@ handle_bobs_cryptodata_multipart (void *cls, | |||
2153 | void **channel_ctx, | 2175 | void **channel_ctx, |
2154 | const struct GNUNET_MessageHeader * message) | 2176 | const struct GNUNET_MessageHeader * message) |
2155 | { | 2177 | { |
2156 | struct ServiceSession * session; | 2178 | struct ServiceSession * s; |
2157 | const struct GNUNET_SCALARPRODUCT_multipart_message * msg = (const struct GNUNET_SCALARPRODUCT_multipart_message *) message; | 2179 | const struct GNUNET_SCALARPRODUCT_multipart_message * msg = (const struct GNUNET_SCALARPRODUCT_multipart_message *) message; |
2158 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; | 2180 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; |
2159 | size_t i; | 2181 | size_t i; |
@@ -2163,8 +2185,8 @@ handle_bobs_cryptodata_multipart (void *cls, | |||
2163 | 2185 | ||
2164 | GNUNET_assert (NULL != message); | 2186 | GNUNET_assert (NULL != message); |
2165 | // are we in the correct state? | 2187 | // are we in the correct state? |
2166 | session = (struct ServiceSession *) * channel_ctx; | 2188 | s = (struct ServiceSession *) * channel_ctx; |
2167 | if ((ALICE != session->role) || (NULL == session->sorted_elements)) { | 2189 | if ((ALICE != s->role) || (NULL == s->sorted_elements)) { |
2168 | goto invalid_msg; | 2190 | goto invalid_msg; |
2169 | } | 2191 | } |
2170 | msg_size = ntohs (msg->header.size); | 2192 | msg_size = ntohs (msg->header.size); |
@@ -2178,39 +2200,42 @@ handle_bobs_cryptodata_multipart (void *cls, | |||
2178 | required_size = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message) | 2200 | required_size = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message) |
2179 | + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 2201 | + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); |
2180 | //sanity check: is the message as long as the message_count fields suggests? | 2202 | //sanity check: is the message as long as the message_count fields suggests? |
2181 | if ((required_size != msg_size) || (session->used_elements_count < session->transferred_element_count + contained)) { | 2203 | if ((required_size != msg_size) || (s->used_element_count < s->transferred_element_count + contained)) { |
2182 | goto invalid_msg; | 2204 | goto invalid_msg; |
2183 | } | 2205 | } |
2184 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 2206 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
2185 | // Convert each k[][perm] to its MPI_value | 2207 | // Convert each k[][perm] to its MPI_value |
2186 | for (i = 0; i < contained; i++) { | 2208 | for (i = 0; i < contained; i++) { |
2187 | memcpy (&session->r[session->transferred_element_count + i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 2209 | memcpy (&s->r[s->transferred_element_count + i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
2188 | memcpy (&session->r_prime[session->transferred_element_count + i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 2210 | memcpy (&s->r_prime[s->transferred_element_count + i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
2189 | } | 2211 | } |
2190 | session->transferred_element_count += contained; | 2212 | s->transferred_element_count += contained; |
2191 | if (session->transferred_element_count != session->used_elements_count) | 2213 | if (s->transferred_element_count != s->used_element_count) |
2192 | return GNUNET_OK; | 2214 | return GNUNET_OK; |
2193 | session->product = compute_scalar_product (session); //never NULL | 2215 | s->product = compute_scalar_product (s); //never NULL |
2194 | 2216 | ||
2195 | invalid_msg: | 2217 | invalid_msg: |
2196 | GNUNET_break_op (NULL != session->product); | 2218 | GNUNET_break_op (NULL != s->product); |
2197 | session->channel = NULL; | 2219 | s->channel = NULL; |
2198 | // send message with product to client | 2220 | // send message with product to client |
2199 | if (NULL != session->client){ | 2221 | if (NULL != s->client){ |
2200 | //Alice | 2222 | //Alice |
2201 | session->client_notification_task = | 2223 | s->client_notification_task = |
2202 | GNUNET_SCHEDULER_add_now (&prepare_client_response, | 2224 | GNUNET_SCHEDULER_add_now (&prepare_client_response, |
2203 | session); | 2225 | s); |
2204 | } | 2226 | } |
2205 | else { | 2227 | else { |
2206 | //Bob | 2228 | //Bob |
2207 | if (NULL != session->response) | 2229 | if (NULL != s->response){ |
2208 | session->response->client_notification_task = | 2230 | s->response->active = GNUNET_SYSERR; |
2209 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 2231 | s->response->client_notification_task = |
2210 | session->response); | 2232 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2211 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 2233 | s->response); |
2212 | free_session_variables (session); | 2234 | } |
2213 | GNUNET_free(session); | 2235 | if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) |
2236 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); | ||
2237 | free_session_variables (s); | ||
2238 | GNUNET_free(s); | ||
2214 | } | 2239 | } |
2215 | // the channel has done its job, terminate our connection and the channel | 2240 | // the channel has done its job, terminate our connection and the channel |
2216 | // the peer will be notified that the channel was destroyed via channel_destruction_handler | 2241 | // the peer will be notified that the channel was destroyed via channel_destruction_handler |
@@ -2235,7 +2260,7 @@ handle_bobs_cryptodata_message (void *cls, | |||
2235 | void **channel_ctx, | 2260 | void **channel_ctx, |
2236 | const struct GNUNET_MessageHeader * message) | 2261 | const struct GNUNET_MessageHeader * message) |
2237 | { | 2262 | { |
2238 | struct ServiceSession * session; | 2263 | struct ServiceSession * s; |
2239 | const struct GNUNET_SCALARPRODUCT_service_response * msg = (const struct GNUNET_SCALARPRODUCT_service_response *) message; | 2264 | const struct GNUNET_SCALARPRODUCT_service_response * msg = (const struct GNUNET_SCALARPRODUCT_service_response *) message; |
2240 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; | 2265 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; |
2241 | size_t i; | 2266 | size_t i; |
@@ -2244,9 +2269,11 @@ handle_bobs_cryptodata_message (void *cls, | |||
2244 | size_t required_size; | 2269 | size_t required_size; |
2245 | 2270 | ||
2246 | GNUNET_assert (NULL != message); | 2271 | GNUNET_assert (NULL != message); |
2247 | session = (struct ServiceSession *) * channel_ctx; | 2272 | s = (struct ServiceSession *) * channel_ctx; |
2248 | // are we in the correct state? | 2273 | // are we in the correct state? |
2249 | if (0 /*//TODO: correct state*/) { | 2274 | if (NULL == s->sorted_elements |
2275 | || NULL != s->msg | ||
2276 | || s->used_element_count != s->transferred_element_count) { | ||
2250 | goto invalid_msg; | 2277 | goto invalid_msg; |
2251 | } | 2278 | } |
2252 | //we need at least a full message without elements attached | 2279 | //we need at least a full message without elements attached |
@@ -2261,49 +2288,53 @@ handle_bobs_cryptodata_message (void *cls, | |||
2261 | + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) | 2288 | + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) |
2262 | + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 2289 | + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); |
2263 | //sanity check: is the message as long as the message_count fields suggests? | 2290 | //sanity check: is the message as long as the message_count fields suggests? |
2264 | if ((msg_size != required_size) || (session->used_elements_count < contained)) { | 2291 | if ((msg_size != required_size) || (s->used_element_count < contained)) { |
2265 | goto invalid_msg; | 2292 | goto invalid_msg; |
2266 | } | 2293 | } |
2267 | session->transferred_element_count = contained; | 2294 | s->transferred_element_count = contained; |
2268 | //convert s | 2295 | //convert s |
2269 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 2296 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
2270 | 2297 | ||
2271 | session->s = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 2298 | s->s = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
2272 | session->s_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 2299 | s->s_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
2273 | memcpy (session->s, &payload[0], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 2300 | memcpy (s->s, &payload[0], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
2274 | memcpy (session->s_prime, &payload[1], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 2301 | memcpy (s->s_prime, &payload[1], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
2275 | 2302 | ||
2276 | session->r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * session->used_elements_count); | 2303 | s->r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count); |
2277 | session->r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * session->used_elements_count); | 2304 | s->r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count); |
2278 | 2305 | ||
2306 | payload = &payload[2]; | ||
2279 | // Convert each k[][perm] to its MPI_value | 2307 | // Convert each k[][perm] to its MPI_value |
2280 | for (i = 0; i < contained; i++) { | 2308 | for (i = 0; i < contained; i++) { |
2281 | memcpy (&session->r[i], &payload[2 + 2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 2309 | memcpy (&s->r[i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
2282 | memcpy (&session->r_prime[i], &payload[3 + 2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 2310 | memcpy (&s->r_prime[i], &payload[2 * i + 1], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
2283 | } | 2311 | } |
2284 | if (session->transferred_element_count != session->used_elements_count) | 2312 | if (s->transferred_element_count != s->used_element_count) |
2285 | return GNUNET_OK; //wait for the other multipart chunks | 2313 | return GNUNET_OK; //wait for the other multipart chunks |
2286 | session->product = compute_scalar_product (session); //never NULL | 2314 | s->product = compute_scalar_product (s); //never NULL |
2287 | 2315 | ||
2288 | invalid_msg: | 2316 | invalid_msg: |
2289 | GNUNET_break_op (NULL != session->product); | 2317 | GNUNET_break_op (NULL != s->product); |
2290 | session->channel = NULL; | 2318 | s->channel = NULL; |
2291 | // send message with product to client | 2319 | // send message with product to client |
2292 | if (NULL != session->client){ | 2320 | if (NULL != s->client){ |
2293 | //Alice | 2321 | //Alice |
2294 | session->client_notification_task = | 2322 | s->client_notification_task = |
2295 | GNUNET_SCHEDULER_add_now (&prepare_client_response, | 2323 | GNUNET_SCHEDULER_add_now (&prepare_client_response, |
2296 | session); | 2324 | s); |
2297 | } | 2325 | } |
2298 | else { | 2326 | else { |
2299 | //Bob | 2327 | //Bob |
2300 | if (NULL != session->response) | 2328 | if (NULL != s->response) { |
2301 | session->response->client_notification_task = | 2329 | s->response->active = GNUNET_SYSERR; |
2302 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 2330 | s->response->client_notification_task = |
2303 | session->response); | 2331 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
2304 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session); | 2332 | s->response); |
2305 | free_session_variables (session); | 2333 | } |
2306 | GNUNET_free(session); | 2334 | if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) |
2335 | GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); | ||
2336 | free_session_variables (s); | ||
2337 | GNUNET_free(s); | ||
2307 | } | 2338 | } |
2308 | // the channel has done its job, terminate our connection and the channel | 2339 | // the channel has done its job, terminate our connection and the channel |
2309 | // the peer will be notified that the channel was destroyed via channel_destruction_handler | 2340 | // the peer will be notified that the channel was destroyed via channel_destruction_handler |
@@ -2322,30 +2353,30 @@ static void | |||
2322 | shutdown_task (void *cls, | 2353 | shutdown_task (void *cls, |
2323 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 2354 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
2324 | { | 2355 | { |
2325 | struct ServiceSession * session; | 2356 | struct ServiceSession * s; |
2326 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Shutting down, initiating cleanup.\n")); | 2357 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Shutting down, initiating cleanup.\n")); |
2327 | 2358 | ||
2328 | do_shutdown = GNUNET_YES; | 2359 | do_shutdown = GNUNET_YES; |
2329 | 2360 | ||
2330 | // terminate all owned open channels. | 2361 | // terminate all owned open channels. |
2331 | for (session = from_client_head; NULL != session; session = session->next) { | 2362 | for (s = from_client_head; NULL != s; s = s->next) { |
2332 | if ((0/*//TODO: not finalized*/) && (NULL != session->channel)) { | 2363 | if ((0/*//TODO: not finalized*/) && (NULL != s->channel)) { |
2333 | GNUNET_CADET_channel_destroy (session->channel); | 2364 | GNUNET_CADET_channel_destroy (s->channel); |
2334 | session->channel = NULL; | 2365 | s->channel = NULL; |
2335 | } | 2366 | } |
2336 | if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) { | 2367 | if (GNUNET_SCHEDULER_NO_TASK != s->client_notification_task) { |
2337 | GNUNET_SCHEDULER_cancel (session->client_notification_task); | 2368 | GNUNET_SCHEDULER_cancel (s->client_notification_task); |
2338 | session->client_notification_task = GNUNET_SCHEDULER_NO_TASK; | 2369 | s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; |
2339 | } | 2370 | } |
2340 | if (NULL != session->client) { | 2371 | if (NULL != s->client) { |
2341 | GNUNET_SERVER_client_disconnect (session->client); | 2372 | GNUNET_SERVER_client_disconnect (s->client); |
2342 | session->client = NULL; | 2373 | s->client = NULL; |
2343 | } | 2374 | } |
2344 | } | 2375 | } |
2345 | for (session = from_service_head; NULL != session; session = session->next) | 2376 | for (s = from_service_head; NULL != s; s = s->next) |
2346 | if (NULL != session->channel) { | 2377 | if (NULL != s->channel) { |
2347 | GNUNET_CADET_channel_destroy (session->channel); | 2378 | GNUNET_CADET_channel_destroy (s->channel); |
2348 | session->channel = NULL; | 2379 | s->channel = NULL; |
2349 | } | 2380 | } |
2350 | 2381 | ||
2351 | if (my_cadet) { | 2382 | if (my_cadet) { |
@@ -2397,7 +2428,7 @@ run (void *cls, | |||
2397 | // register server callbacks and disconnect handler | 2428 | // register server callbacks and disconnect handler |
2398 | GNUNET_SERVER_add_handlers (server, server_handlers); | 2429 | GNUNET_SERVER_add_handlers (server, server_handlers); |
2399 | GNUNET_SERVER_disconnect_notify (server, | 2430 | GNUNET_SERVER_disconnect_notify (server, |
2400 | &handle_client_disconnect, | 2431 | &cb_client_disconnect, |
2401 | NULL); | 2432 | NULL); |
2402 | GNUNET_break (GNUNET_OK == | 2433 | GNUNET_break (GNUNET_OK == |
2403 | GNUNET_CRYPTO_get_peer_identity (c, | 2434 | GNUNET_CRYPTO_get_peer_identity (c, |