aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-05-24 20:09:12 +0000
committerChristian Grothoff <christian@grothoff.org>2014-05-24 20:09:12 +0000
commitd0d8c852a37bffe6be52f5ee48653728ee4ce5f6 (patch)
treebb23c28fc86650820caf5e33a78040b712389af0 /src/scalarproduct
parent31536a9bb75502f4c090472f188e1eec138515f7 (diff)
downloadgnunet-d0d8c852a37bffe6be52f5ee48653728ee4ce5f6.tar.gz
gnunet-d0d8c852a37bffe6be52f5ee48653728ee4ce5f6.zip
-a bit more towards following coding conventions
Diffstat (limited to 'src/scalarproduct')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct.c517
1 files changed, 310 insertions, 207 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c
index 7758d7046..a6f398fbe 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors) 3 (C) 2013, 2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -22,6 +22,7 @@
22 * @file scalarproduct/gnunet-service-scalarproduct.c 22 * @file scalarproduct/gnunet-service-scalarproduct.c
23 * @brief scalarproduct service implementation 23 * @brief scalarproduct service implementation
24 * @author Christian M. Fuchs 24 * @author Christian M. Fuchs
25 * @author Christian Grothoff
25 */ 26 */
26#include "platform.h" 27#include "platform.h"
27#include <limits.h> 28#include <limits.h>
@@ -198,7 +199,7 @@ struct SortedValue
198struct ServiceSession 199struct ServiceSession
199{ 200{
200 /** 201 /**
201 * Is this session active(GNUNET_YES), Concluded(GNUNET_NO), (GNUNET_SYSERR) 202 * Is this session active (#GNUNET_YES), Concluded (#GNUNET_NO), or had an error (#GNUNET_SYSERR)
202 */ 203 */
203 int32_t active; 204 int32_t active;
204 205
@@ -230,12 +231,12 @@ struct ServiceSession
230 /** 231 /**
231 * the client this request is related to 232 * the client this request is related to
232 */ 233 */
233 struct GNUNET_SERVER_Client * client; 234 struct GNUNET_SERVER_Client *client;
234 235
235 /** 236 /**
236 * The message to send 237 * The message to send
237 */ 238 */
238 struct GNUNET_MessageHeader * msg; 239 struct GNUNET_MessageHeader *msg;
239 240
240 /** 241 /**
241 * how many elements we were supplied with from the client 242 * how many elements we were supplied with from the client
@@ -245,7 +246,7 @@ struct ServiceSession
245 /** 246 /**
246 * all non-0-value'd elements transmitted to us 247 * all non-0-value'd elements transmitted to us
247 */ 248 */
248 struct GNUNET_CONTAINER_MultiHashMap * intersected_elements; 249 struct GNUNET_CONTAINER_MultiHashMap *intersected_elements;
249 250
250 /** 251 /**
251 * how many elements actually are used for the scalar product 252 * how many elements actually are used for the scalar product
@@ -253,7 +254,7 @@ struct ServiceSession
253 uint32_t used_element_count; 254 uint32_t used_element_count;
254 255
255 /** 256 /**
256 * already transferred elements (sent/received) for multipart messages, less or equal than used_element_count for 257 * already transferred elements (sent/received) for multipart messages, less or equal than @e used_element_count for
257 */ 258 */
258 uint32_t transferred_element_count; 259 uint32_t transferred_element_count;
259 260
@@ -261,68 +262,68 @@ struct ServiceSession
261 * Set of elements for which will conduction an intersection. 262 * Set of elements for which will conduction an intersection.
262 * the resulting elements are then used for computing the scalar product. 263 * the resulting elements are then used for computing the scalar product.
263 */ 264 */
264 struct GNUNET_SET_Handle * intersection_set; 265 struct GNUNET_SET_Handle *intersection_set;
265 266
266 /** 267 /**
267 * Set of elements for which will conduction an intersection. 268 * Set of elements for which will conduction an intersection.
268 * the resulting elements are then used for computing the scalar product. 269 * the resulting elements are then used for computing the scalar product.
269 */ 270 */
270 struct GNUNET_SET_OperationHandle * intersection_op; 271 struct GNUNET_SET_OperationHandle *intersection_op;
271 272
272 /** 273 /**
273 * Handle to Alice's Intersection operation listening for Bob 274 * Handle to Alice's Intersection operation listening for Bob
274 */ 275 */
275 struct GNUNET_SET_ListenHandle * intersection_listen; 276 struct GNUNET_SET_ListenHandle *intersection_listen;
276 277
277 /** 278 /**
278 * Public key of the remote service, only used by bob 279 * Public key of the remote service, only used by Bob
279 */ 280 */
280 struct GNUNET_CRYPTO_PaillierPublicKey * remote_pubkey; 281 struct GNUNET_CRYPTO_PaillierPublicKey *remote_pubkey;
281 282
282 /** 283 /**
283 * DLL for sorting elements after intersection 284 * DLL for sorting elements after intersection
284 */ 285 */
285 struct SortedValue * a_head; 286 struct SortedValue *a_head;
286 287
287 /** 288 /**
288 * a(Alice) 289 * a(Alice)
289 */ 290 */
290 struct SortedValue * a_tail; 291 struct SortedValue *a_tail;
291 292
292 /** 293 /**
293 * a(Alice) 294 * a(Alice)
294 */ 295 */
295 gcry_mpi_t * sorted_elements; 296 gcry_mpi_t *sorted_elements;
296 297
297 /** 298 /**
298 * E(ai)(Bob) after applying the mask 299 * E(ai)(Bob) after applying the mask
299 */ 300 */
300 struct GNUNET_CRYPTO_PaillierCiphertext * e_a; 301 struct GNUNET_CRYPTO_PaillierCiphertext *e_a;
301 302
302 /** 303 /**
303 * Bob's permutation p of R 304 * Bob's permutation p of R
304 */ 305 */
305 struct GNUNET_CRYPTO_PaillierCiphertext * r; 306 struct GNUNET_CRYPTO_PaillierCiphertext *r;
306 307
307 /** 308 /**
308 * Bob's permutation q of R 309 * Bob's permutation q of R
309 */ 310 */
310 struct GNUNET_CRYPTO_PaillierCiphertext * r_prime; 311 struct GNUNET_CRYPTO_PaillierCiphertext *r_prime;
311 312
312 /** 313 /**
313 * Bob's s 314 * Bob's s
314 */ 315 */
315 struct GNUNET_CRYPTO_PaillierCiphertext * s; 316 struct GNUNET_CRYPTO_PaillierCiphertext *s;
316 317
317 /** 318 /**
318 * Bob's s' 319 * Bob's s'
319 */ 320 */
320 struct GNUNET_CRYPTO_PaillierCiphertext * s_prime; 321 struct GNUNET_CRYPTO_PaillierCiphertext *s_prime;
321 322
322 /** 323 /**
323 * Bobs matching response session from the client 324 * Bob's matching response session from the client
324 */ 325 */
325 struct ServiceSession * response; 326 struct ServiceSession *response;
326 327
327 /** 328 /**
328 * The computed scalar 329 * The computed scalar
@@ -330,19 +331,19 @@ struct ServiceSession
330 gcry_mpi_t product; 331 gcry_mpi_t product;
331 332
332 /** 333 /**
333 * My transmit handle for the current message to a alice/bob 334 * My transmit handle for the current message to a Alice/Bob
334 */ 335 */
335 struct GNUNET_CADET_TransmitHandle * service_transmit_handle; 336 struct GNUNET_CADET_TransmitHandle *service_transmit_handle;
336 337
337 /** 338 /**
338 * My transmit handle for the current message to the client 339 * My transmit handle for the current message to the client
339 */ 340 */
340 struct GNUNET_SERVER_TransmitHandle * client_transmit_handle; 341 struct GNUNET_SERVER_TransmitHandle *client_transmit_handle;
341 342
342 /** 343 /**
343 * channel-handle associated with our cadet handle 344 * channel-handle associated with our cadet handle
344 */ 345 */
345 struct GNUNET_CADET_Channel * channel; 346 struct GNUNET_CADET_Channel *channel;
346 347
347 /** 348 /**
348 * Handle to a task that sends a msg to the our client 349 * Handle to a task that sends a msg to the our client
@@ -350,9 +351,6 @@ struct ServiceSession
350 GNUNET_SCHEDULER_TaskIdentifier client_notification_task; 351 GNUNET_SCHEDULER_TaskIdentifier client_notification_task;
351}; 352};
352 353
353///////////////////////////////////////////////////////////////////////////////
354// Forward Delcarations
355///////////////////////////////////////////////////////////////////////////////
356 354
357/** 355/**
358 * Send a multi part chunk of a service request from alice to bob. 356 * Send a multi part chunk of a service request from alice to bob.
@@ -366,8 +364,9 @@ struct ServiceSession
366static void 364static void
367prepare_alices_cyrptodata_message_multipart (void *cls); 365prepare_alices_cyrptodata_message_multipart (void *cls);
368 366
367
369/** 368/**
370 * Send a multi part chunk of a service response from bob to alice. 369 * Send a multi part chunk of a service response from Bob to Alice.
371 * This element only contains the two permutations of R, R'. 370 * This element only contains the two permutations of R, R'.
372 * 371 *
373 * @param cls the associated service session 372 * @param cls the associated service session
@@ -376,15 +375,11 @@ static void
376prepare_bobs_cryptodata_message_multipart (void *cls); 375prepare_bobs_cryptodata_message_multipart (void *cls);
377 376
378 377
379///////////////////////////////////////////////////////////////////////////////
380// Global Variables
381///////////////////////////////////////////////////////////////////////////////
382
383 378
384/** 379/**
385 * Gnunet configuration handle 380 * GNUnet configuration handle
386 */ 381 */
387const struct GNUNET_CONFIGURATION_Handle * cfg; 382static const struct GNUNET_CONFIGURATION_Handle * cfg;
388 383
389/** 384/**
390 * Handle to the core service (NULL until we've connected to it). 385 * Handle to the core service (NULL until we've connected to it).
@@ -416,37 +411,34 @@ static gcry_mpi_t my_offset;
416 * for all of these elements we calculate a scalar product with a remote peer 411 * for all of these elements we calculate a scalar product with a remote peer
417 * split between service->service and client->service for simplicity 412 * split between service->service and client->service for simplicity
418 */ 413 */
419static struct ServiceSession * from_client_head; 414static struct ServiceSession *from_client_head;
415
420/** 416/**
421 * Tail of our double linked list for client-requests sent to us. 417 * Tail of our double linked list for client-requests sent to us.
422 * for all of these elements we calculate a scalar product with a remote peer 418 * for all of these elements we calculate a scalar product with a remote peer
423 * split between service->service and client->service for simplicity 419 * split between service->service and client->service for simplicity
424 */ 420 */
425static struct ServiceSession * from_client_tail; 421static struct ServiceSession *from_client_tail;
426 422
427/** 423/**
428 * Head of our double linked list for service-requests sent to us. 424 * Head of our double linked list for service-requests sent to us.
429 * for all of these elements we help the requesting service in calculating a scalar product 425 * for all of these elements we help the requesting service in calculating a scalar product
430 * split between service->service and client->service for simplicity 426 * split between service->service and client->service for simplicity
431 */ 427 */
432static struct ServiceSession * from_service_head; 428static struct ServiceSession *from_service_head;
433 429
434/** 430/**
435 * Tail of our double linked list for service-requests sent to us. 431 * Tail of our double linked list for service-requests sent to us.
436 * for all of these elements we help the requesting service in calculating a scalar product 432 * for all of these elements we help the requesting service in calculating a scalar product
437 * split between service->service and client->service for simplicity 433 * split between service->service and client->service for simplicity
438 */ 434 */
439static struct ServiceSession * from_service_tail; 435static struct ServiceSession *from_service_tail;
440 436
441/** 437/**
442 * Certain events (callbacks for server & cadet operations) must not be queued after shutdown. 438 * Certain events (callbacks for server & cadet operations) must not be queued after shutdown.
443 */ 439 */
444static int do_shutdown; 440static int do_shutdown;
445 441
446///////////////////////////////////////////////////////////////////////////////
447// Helper Functions
448///////////////////////////////////////////////////////////////////////////////
449
450 442
451/** 443/**
452 * computes the square sum over a vector of a given length. 444 * computes the square sum over a vector of a given length.
@@ -456,7 +448,8 @@ static int do_shutdown;
456 * @return an MPI value containing the calculated sum, never NULL 448 * @return an MPI value containing the calculated sum, never NULL
457 */ 449 */
458static gcry_mpi_t 450static gcry_mpi_t
459compute_square_sum (gcry_mpi_t * vector, uint32_t length) 451compute_square_sum (gcry_mpi_t *vector,
452 uint32_t length)
460{ 453{
461 gcry_mpi_t elem; 454 gcry_mpi_t elem;
462 gcry_mpi_t sum; 455 gcry_mpi_t sum;
@@ -482,70 +475,86 @@ compute_square_sum (gcry_mpi_t * vector, uint32_t length)
482 * @param session - the session to free elements from 475 * @param session - the session to free elements from
483 */ 476 */
484static void 477static void
485free_session_variables (struct ServiceSession * s) 478free_session_variables (struct ServiceSession *s)
486{ 479{
487 while (NULL != s->a_head) { 480 while (NULL != s->a_head)
481 {
488 struct SortedValue * e = s->a_head; 482 struct SortedValue * e = s->a_head;
483
489 GNUNET_free (e->elem); 484 GNUNET_free (e->elem);
490 gcry_mpi_release (e->val); 485 gcry_mpi_release (e->val);
491 GNUNET_CONTAINER_DLL_remove (s->a_head, s->a_tail, e); 486 GNUNET_CONTAINER_DLL_remove (s->a_head, s->a_tail, e);
492 GNUNET_free (e); 487 GNUNET_free (e);
493 } 488 }
494 if (s->e_a) { 489 if (s->e_a)
490 {
495 GNUNET_free (s->e_a); 491 GNUNET_free (s->e_a);
496 s->e_a = NULL; 492 s->e_a = NULL;
497 } 493 }
498 if (s->remote_pubkey){ 494 if (s->remote_pubkey)
495 {
499 GNUNET_free(s->remote_pubkey); 496 GNUNET_free(s->remote_pubkey);
500 s->remote_pubkey=NULL; 497 s->remote_pubkey=NULL;
501 } 498 }
502 if (s->sorted_elements) { 499 if (s->sorted_elements)
500 {
503 GNUNET_free (s->sorted_elements); 501 GNUNET_free (s->sorted_elements);
504 s->sorted_elements = NULL; 502 s->sorted_elements = NULL;
505 } 503 }
506 if (s->intersected_elements) { 504 if (s->intersected_elements)
505 {
507 GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); 506 GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements);
508 //elements are freed independently in session->a_head/tail 507 //elements are freed independently in session->a_head/tail
509 s->intersected_elements = NULL; 508 s->intersected_elements = NULL;
510 } 509 }
511 if (s->intersection_listen) { 510 if (s->intersection_listen)
511 {
512 GNUNET_SET_listen_cancel (s->intersection_listen); 512 GNUNET_SET_listen_cancel (s->intersection_listen);
513 s->intersection_listen = NULL; 513 s->intersection_listen = NULL;
514 } 514 }
515 if (s->intersection_op) { 515 if (s->intersection_op)
516 {
516 GNUNET_SET_operation_cancel (s->intersection_op); 517 GNUNET_SET_operation_cancel (s->intersection_op);
517 s->intersection_op = NULL; 518 s->intersection_op = NULL;
518 } 519 }
519 if (s->intersection_set) { 520 if (s->intersection_set)
521 {
520 GNUNET_SET_destroy (s->intersection_set); 522 GNUNET_SET_destroy (s->intersection_set);
521 s->intersection_set = NULL; 523 s->intersection_set = NULL;
522 } 524 }
523 if (s->msg) { 525 if (s->msg)
526 {
524 GNUNET_free (s->msg); 527 GNUNET_free (s->msg);
525 s->msg = NULL; 528 s->msg = NULL;
526 } 529 }
527 if (s->r) { 530 if (s->r)
531 {
528 GNUNET_free (s->r); 532 GNUNET_free (s->r);
529 s->r = NULL; 533 s->r = NULL;
530 } 534 }
531 if (s->r_prime) { 535 if (s->r_prime)
536 {
532 GNUNET_free (s->r_prime); 537 GNUNET_free (s->r_prime);
533 s->r_prime = NULL; 538 s->r_prime = NULL;
534 } 539 }
535 if (s->s) { 540 if (s->s)
541 {
536 GNUNET_free (s->s); 542 GNUNET_free (s->s);
537 s->s = NULL; 543 s->s = NULL;
538 } 544 }
539 if (s->s_prime) { 545 if (s->s_prime)
546 {
540 GNUNET_free (s->s_prime); 547 GNUNET_free (s->s_prime);
541 s->s_prime = NULL; 548 s->s_prime = NULL;
542 } 549 }
543 if (s->product) { 550 if (s->product)
551 {
544 gcry_mpi_release (s->product); 552 gcry_mpi_release (s->product);
545 s->product = NULL; 553 s->product = NULL;
546 } 554 }
547} 555}
548 556
557
549/** 558/**
550 * Primitive callback for copying over a message, as they 559 * Primitive callback for copying over a message, as they
551 * usually are too complex to be handled in the callback itself. 560 * usually are too complex to be handled in the callback itself.
@@ -557,14 +566,16 @@ free_session_variables (struct ServiceSession * s)
557 * @return 0 if we couldn't copy, else the size copied over 566 * @return 0 if we couldn't copy, else the size copied over
558 */ 567 */
559static size_t 568static size_t
560cb_transfer_message (void *cls, size_t size, void *buf) 569cb_transfer_message (void *cls,
570 size_t size,
571 void *buf)
561{ 572{
562 struct ServiceSession * s = cls; 573 struct ServiceSession * s = cls;
563 uint16_t type; 574 uint16_t type;
564 575
565 GNUNET_assert (buf); 576 GNUNET_assert (buf);
566 577 if (ntohs (s->msg->size) != size)
567 if (ntohs (s->msg->size) != size) { 578 {
568 GNUNET_break (0); 579 GNUNET_break (0);
569 return 0; 580 return 0;
570 } 581 }
@@ -601,11 +612,9 @@ cb_transfer_message (void *cls, size_t size, void *buf)
601 else 612 else
602 s->channel = NULL; 613 s->channel = NULL;
603 break; 614 break;
604
605 default: 615 default:
606 GNUNET_assert (0); 616 GNUNET_assert (0);
607 } 617 }
608
609 return size; 618 return size;
610} 619}
611 620
@@ -626,9 +635,11 @@ find_matching_session (struct ServiceSession * tail,
626{ 635{
627 struct ServiceSession * s; 636 struct ServiceSession * s;
628 637
629 for (s = tail; NULL != s; s = s->prev) { 638 for (s = tail; NULL != s; s = s->prev)
639 {
630 // if the key matches, and the element_count is same 640 // if the key matches, and the element_count is same
631 if (0 == memcmp (&s->session_id, key, sizeof (struct GNUNET_HashCode))) { 641 if (0 == memcmp (&s->session_id, key, sizeof (struct GNUNET_HashCode)))
642 {
632 // if peerid is NULL OR same as the peer Id in the queued request 643 // if peerid is NULL OR same as the peer Id in the queued request
633 if ((NULL == peerid) 644 if ((NULL == peerid)
634 || (0 == memcmp (&s->peer, peerid, sizeof (struct GNUNET_PeerIdentity)))) 645 || (0 == memcmp (&s->peer, peerid, sizeof (struct GNUNET_PeerIdentity))))
@@ -641,11 +652,6 @@ find_matching_session (struct ServiceSession * tail,
641} 652}
642 653
643 654
644///////////////////////////////////////////////////////////////////////////////
645// Event and Message Handlers
646///////////////////////////////////////////////////////////////////////////////
647
648
649/** 655/**
650 * A client disconnected. 656 * A client disconnected.
651 * 657 *
@@ -658,35 +664,37 @@ find_matching_session (struct ServiceSession * tail,
658 */ 664 */
659static void 665static void
660cb_client_disconnect (void *cls, 666cb_client_disconnect (void *cls,
661 struct GNUNET_SERVER_Client *client) 667 struct GNUNET_SERVER_Client *client)
662{ 668{
663 struct ServiceSession *s; 669 struct ServiceSession *s;
664 670
665 if (NULL != client) 671 if (NULL == client)
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
667 _ ("Client %p disconnected from us.\n"), client);
668 else
669 return; 672 return;
670 673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
674 _ ("Client %p disconnected from us.\n"), client);
671 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); 675 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession);
672 if (NULL == s) 676 if (NULL == s)
673 return; 677 return;
674 678 GNUNET_CONTAINER_DLL_remove (from_client_head,
675 GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, s); 679 from_client_tail,
676 680 s);
677 if (NULL != s->service_transmit_handle){ 681 if (NULL != s->service_transmit_handle)
682 {
678 GNUNET_CADET_notify_transmit_ready_cancel (s->service_transmit_handle); 683 GNUNET_CADET_notify_transmit_ready_cancel (s->service_transmit_handle);
679 s->service_transmit_handle = NULL; 684 s->service_transmit_handle = NULL;
680 } 685 }
681 if (NULL != s->channel){ 686 if (NULL != s->channel)
687 {
682 GNUNET_CADET_channel_destroy (s->channel); 688 GNUNET_CADET_channel_destroy (s->channel);
683 s->channel = NULL; 689 s->channel = NULL;
684 } 690 }
685 if (GNUNET_SCHEDULER_NO_TASK != s->client_notification_task){ 691 if (GNUNET_SCHEDULER_NO_TASK != s->client_notification_task)
692 {
686 GNUNET_SCHEDULER_cancel (s->client_notification_task); 693 GNUNET_SCHEDULER_cancel (s->client_notification_task);
687 s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; 694 s->client_notification_task = GNUNET_SCHEDULER_NO_TASK;
688 } 695 }
689 if (NULL != s->client_transmit_handle) { 696 if (NULL != s->client_transmit_handle)
697 {
690 GNUNET_SERVER_notify_transmit_ready_cancel (s->client_transmit_handle); 698 GNUNET_SERVER_notify_transmit_ready_cancel (s->client_transmit_handle);
691 s->client_transmit_handle = NULL; 699 s->client_transmit_handle = NULL;
692 } 700 }
@@ -709,7 +717,7 @@ prepare_client_end_notification (void * cls,
709 const struct GNUNET_SCHEDULER_TaskContext * tc) 717 const struct GNUNET_SCHEDULER_TaskContext * tc)
710{ 718{
711 struct ServiceSession * s = cls; 719 struct ServiceSession * s = cls;
712 struct ClientResponseMessage * msg; 720 struct ClientResponseMessage *msg;
713 721
714 s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; 722 s->client_notification_task = GNUNET_SCHEDULER_NO_TASK;
715 723
@@ -719,7 +727,6 @@ prepare_client_end_notification (void * cls,
719 // signal error if not signalized, positive result-range field but zero length. 727 // signal error if not signalized, positive result-range field but zero length.
720 msg->product_length = htonl (0); 728 msg->product_length = htonl (0);
721 msg->status = htonl(s->active); 729 msg->status = htonl(s->active);
722
723 s->msg = &msg->header; 730 s->msg = &msg->header;
724 731
725 //transmit this message to our client 732 //transmit this message to our client
@@ -734,17 +741,20 @@ prepare_client_end_notification (void * cls,
734 if (NULL == s->client_transmit_handle) 741 if (NULL == s->client_transmit_handle)
735 { 742 {
736 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 743 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
737 _("Could not send message to client (%p)!\n"), s->client); 744 _("Could not send message to client (%p)!\n"),
738 GNUNET_SERVER_client_disconnect(s->client); 745 s->client);
746 GNUNET_SERVER_client_disconnect (s->client);
739 free_session_variables(s); 747 free_session_variables(s);
740 GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, s); 748 GNUNET_CONTAINER_DLL_remove (from_client_head,
749 from_client_tail,
750 s);
741 GNUNET_free(s); 751 GNUNET_free(s);
752 return;
742 } 753 }
743 else 754 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
744 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 755 _("Sending session-end notification to client (%p) for session %s\n"),
745 _("Sending session-end notification to client (%p) for session %s\n"), 756 s->client,
746 s->client, 757 GNUNET_h2s (&s->session_id));
747 GNUNET_h2s (&s->session_id));
748} 758}
749 759
750 760
@@ -773,7 +783,8 @@ prepare_alices_cyrptodata_message (void *cls)
773 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > msg_length) { 783 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > msg_length) {
774 s->transferred_element_count = s->used_element_count; 784 s->transferred_element_count = s->used_element_count;
775 } 785 }
776 else { 786 else
787 {
777 //create a multipart msg, first we calculate a new msg size for the head msg 788 //create a multipart msg, first we calculate a new msg size for the head msg
778 s->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage)) 789 s->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage))
779 / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 790 / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
@@ -791,23 +802,28 @@ prepare_alices_cyrptodata_message (void *cls)
791 802
792 // now copy over the sorted element vector 803 // now copy over the sorted element vector
793 a = gcry_mpi_new (0); 804 a = gcry_mpi_new (0);
794 for (i = 0; i < s->transferred_element_count; i++) { 805 for (i = 0; i < s->transferred_element_count; i++)
806 {
795 gcry_mpi_add (a, s->sorted_elements[i], my_offset); 807 gcry_mpi_add (a, s->sorted_elements[i], my_offset);
796 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i]); 808 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i]);
797 } 809 }
798 gcry_mpi_release (a); 810 gcry_mpi_release (a);
799 811
800 s->msg = (struct GNUNET_MessageHeader *) msg; 812 s->msg = (struct GNUNET_MessageHeader *) msg;
801 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); 813 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
814 _("Transmitting service request.\n"));
802 815
803 //transmit via cadet messaging 816 //transmit via cadet messaging
804 s->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (s->channel, GNUNET_YES, 817 s->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (s->channel,
805 GNUNET_TIME_UNIT_FOREVER_REL, 818 GNUNET_YES,
806 msg_length, 819 GNUNET_TIME_UNIT_FOREVER_REL,
807 &cb_transfer_message, 820 msg_length,
808 s); 821 &cb_transfer_message,
809 if (NULL == s->service_transmit_handle) { 822 s);
810 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to channel!\n")); 823 if (NULL == s->service_transmit_handle)
824 {
825 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
826 _("Could not send message to channel!\n"));
811 GNUNET_free (msg); 827 GNUNET_free (msg);
812 s->msg = NULL; 828 s->msg = NULL;
813 s->active = GNUNET_SYSERR; 829 s->active = GNUNET_SYSERR;
@@ -850,7 +866,8 @@ prepare_bobs_cryptodata_message_multipart (void *cls)
850 msg->contained_element_count = htonl (todo_count); 866 msg->contained_element_count = htonl (todo_count);
851 867
852 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 868 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
853 for (i = s->transferred_element_count, j = 0; i < s->transferred_element_count + todo_count; i++) { 869 for (i = s->transferred_element_count, j = 0; i < s->transferred_element_count + todo_count; i++)
870 {
854 //r[i][p] and r[i][q] 871 //r[i][p] and r[i][q]
855 memcpy (&payload[j++], &s->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 872 memcpy (&payload[j++], &s->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
856 memcpy (&payload[j++], &s->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 873 memcpy (&payload[j++], &s->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
@@ -864,8 +881,10 @@ prepare_bobs_cryptodata_message_multipart (void *cls)
864 msg_length, 881 msg_length,
865 &cb_transfer_message, 882 &cb_transfer_message,
866 s); 883 s);
867 if (NULL == s->service_transmit_handle) { 884 if (NULL == s->service_transmit_handle)
868 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n")); 885 {
886 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
887 _("Could not send service-response message via cadet!)\n"));
869 888
870 GNUNET_free (msg); 889 GNUNET_free (msg);
871 s->msg = NULL; 890 s->msg = NULL;
@@ -881,7 +900,8 @@ prepare_bobs_cryptodata_message_multipart (void *cls)
881 GNUNET_free(s); 900 GNUNET_free(s);
882 return; 901 return;
883 } 902 }
884 if (s->transferred_element_count == s->used_element_count) { 903 if (s->transferred_element_count == s->used_element_count)
904 {
885 // final part 905 // final part
886 s->active = GNUNET_NO; 906 s->active = GNUNET_NO;
887 GNUNET_free (s->r_prime); 907 GNUNET_free (s->r_prime);
@@ -918,7 +938,8 @@ prepare_bobs_cryptodata_message (void *cls,
918 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); // s, stick 938 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); // s, stick
919 939
920 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > 940 if (GNUNET_SERVER_MAX_MESSAGE_SIZE >
921 msg_length + 2 * s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) { //r, r' 941 msg_length + 2 * s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
942 { //r, r'
922 msg_length += 2 * s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 943 msg_length += 2 * s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
923 s->transferred_element_count = s->used_element_count; 944 s->transferred_element_count = s->used_element_count;
924 } 945 }
@@ -944,7 +965,8 @@ prepare_bobs_cryptodata_message (void *cls,
944 965
945 payload = &payload[2]; 966 payload = &payload[2];
946 // convert k[][] 967 // convert k[][]
947 for (i = 0; i < s->transferred_element_count; i++) { 968 for (i = 0; i < s->transferred_element_count; i++)
969 {
948 //k[i][p] and k[i][q] 970 //k[i][p] and k[i][q]
949 memcpy (&payload[i * 2], &s->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 971 memcpy (&payload[i * 2], &s->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
950 memcpy (&payload[i * 2 + 1], &s->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 972 memcpy (&payload[i * 2 + 1], &s->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
@@ -958,9 +980,11 @@ prepare_bobs_cryptodata_message (void *cls,
958 msg_length, 980 msg_length,
959 &cb_transfer_message, 981 &cb_transfer_message,
960 s); 982 s);
961 if (NULL == s->service_transmit_handle) { 983 if (NULL == s->service_transmit_handle)
984 {
962 //disconnect our client 985 //disconnect our client
963 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n")); 986 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
987 _("Could not send service-response message via cadet!)\n"));
964 988
965 GNUNET_free (msg); 989 GNUNET_free (msg);
966 s->msg = NULL; 990 s->msg = NULL;
@@ -975,10 +999,12 @@ prepare_bobs_cryptodata_message (void *cls,
975 GNUNET_free(s); 999 GNUNET_free(s);
976 return; 1000 return;
977 } 1001 }
978 if (s->transferred_element_count != s->used_element_count) { 1002 if (s->transferred_element_count != s->used_element_count)
1003 {
979 // multipart 1004 // multipart
980 } 1005 }
981 else { 1006 else
1007 {
982 //singlepart 1008 //singlepart
983 s->active = GNUNET_NO; 1009 s->active = GNUNET_NO;
984 GNUNET_free (s->r); 1010 GNUNET_free (s->r);
@@ -1028,7 +1054,8 @@ compute_service_response (struct ServiceSession *session)
1028 s = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 1054 s = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
1029 s_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 1055 s_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
1030 1056
1031 for (i = 0; i < count; i++) { 1057 for (i = 0; i < count; i++)
1058 {
1032 int32_t svalue; 1059 int32_t svalue;
1033 1060
1034 svalue = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 1061 svalue = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
@@ -1149,18 +1176,22 @@ cb_insert_element_sorted (void *cls,
1149 1176
1150 // insert as first element with the lowest key 1177 // insert as first element with the lowest key
1151 if (NULL == s->a_head 1178 if (NULL == s->a_head
1152 || (0 <= GNUNET_CRYPTO_hash_cmp (&s->a_head->elem->key, &e->elem->key))) { 1179 || (0 <= GNUNET_CRYPTO_hash_cmp (&s->a_head->elem->key, &e->elem->key)))
1180 {
1153 GNUNET_CONTAINER_DLL_insert (s->a_head, s->a_tail, e); 1181 GNUNET_CONTAINER_DLL_insert (s->a_head, s->a_tail, e);
1154 return GNUNET_YES; 1182 return GNUNET_YES;
1155 } 1183 }
1156 // insert as last element with the highest key 1184 // insert as last element with the highest key
1157 if (0 >= GNUNET_CRYPTO_hash_cmp (&s->a_tail->elem->key, &e->elem->key)) { 1185 if (0 >= GNUNET_CRYPTO_hash_cmp (&s->a_tail->elem->key, &e->elem->key))
1186 {
1158 GNUNET_CONTAINER_DLL_insert_tail (s->a_head, s->a_tail, e); 1187 GNUNET_CONTAINER_DLL_insert_tail (s->a_head, s->a_tail, e);
1159 return GNUNET_YES; 1188 return GNUNET_YES;
1160 } 1189 }
1161 // insert before the first higher/equal element 1190 // insert before the first higher/equal element
1162 do { 1191 do
1163 if (0 <= GNUNET_CRYPTO_hash_cmp (&o->elem->key, &e->elem->key)) { 1192 {
1193 if (0 <= GNUNET_CRYPTO_hash_cmp (&o->elem->key, &e->elem->key))
1194 {
1164 GNUNET_CONTAINER_DLL_insert_before (s->a_head, s->a_tail, o, e); 1195 GNUNET_CONTAINER_DLL_insert_before (s->a_head, s->a_tail, o, e);
1165 return GNUNET_YES; 1196 return GNUNET_YES;
1166 } 1197 }
@@ -1185,7 +1216,7 @@ cb_intersection_element_removed (void *cls,
1185 const struct GNUNET_SET_Element *element, 1216 const struct GNUNET_SET_Element *element,
1186 enum GNUNET_SET_Status status) 1217 enum GNUNET_SET_Status status)
1187{ 1218{
1188 struct ServiceSession * s = (struct ServiceSession*) cls; 1219 struct ServiceSession * s = cls;
1189 struct GNUNET_SCALARPRODUCT_Element * se; 1220 struct GNUNET_SCALARPRODUCT_Element * se;
1190 int i; 1221 int i;
1191 1222
@@ -1205,7 +1236,8 @@ cb_intersection_element_removed (void *cls,
1205 case GNUNET_SET_STATUS_DONE: 1236 case GNUNET_SET_STATUS_DONE:
1206 s->intersection_op = NULL; 1237 s->intersection_op = NULL;
1207 1238
1208 if (2 > s->used_element_count) { 1239 if (2 > s->used_element_count)
1240 {
1209 // failed! do not leak information about our single remaining element! 1241 // failed! do not leak information about our single remaining element!
1210 // continue after the loop 1242 // continue after the loop
1211 break; 1243 break;
@@ -1216,7 +1248,8 @@ cb_intersection_element_removed (void *cls,
1216 s); 1248 s);
1217 1249
1218 s->sorted_elements = GNUNET_malloc (s->used_element_count * sizeof (gcry_mpi_t)); 1250 s->sorted_elements = GNUNET_malloc (s->used_element_count * sizeof (gcry_mpi_t));
1219 for (i = 0; NULL != s->a_head; i++) { 1251 for (i = 0; NULL != s->a_head; i++)
1252 {
1220 struct SortedValue* a = s->a_head; 1253 struct SortedValue* a = s->a_head;
1221 GNUNET_assert (i < s->used_element_count); 1254 GNUNET_assert (i < s->used_element_count);
1222 1255
@@ -1230,12 +1263,14 @@ cb_intersection_element_removed (void *cls,
1230 prepare_alices_cyrptodata_message (s); 1263 prepare_alices_cyrptodata_message (s);
1231 return; 1264 return;
1232 } 1265 }
1233 else if (s->used_element_count == s->transferred_element_count) { 1266 else if (s->used_element_count == s->transferred_element_count)
1267 {
1234 compute_service_response (s); 1268 compute_service_response (s);
1235 return; 1269 return;
1236 } 1270 }
1237 default: 1271 default:
1238 if (NULL != s->intersection_listen){ 1272 if (NULL != s->intersection_listen)
1273 {
1239 GNUNET_SET_listen_cancel (s->intersection_listen); 1274 GNUNET_SET_listen_cancel (s->intersection_listen);
1240 s->intersection_listen = NULL; 1275 s->intersection_listen = NULL;
1241 } 1276 }
@@ -1255,8 +1290,11 @@ cb_intersection_element_removed (void *cls,
1255 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 1290 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
1256 s); 1291 s);
1257 } 1292 }
1258 else { 1293 else
1259 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 1294 {
1295 GNUNET_CONTAINER_DLL_remove (from_service_head,
1296 from_service_tail,
1297 s);
1260 free_session_variables (s); 1298 free_session_variables (s);
1261 s->response->active = GNUNET_SYSERR; 1299 s->response->active = GNUNET_SYSERR;
1262 s->response->client_notification_task = 1300 s->response->client_notification_task =
@@ -1288,20 +1326,22 @@ cb_intersection_request_alice (void *cls,
1288 const struct GNUNET_MessageHeader *context_msg, 1326 const struct GNUNET_MessageHeader *context_msg,
1289 struct GNUNET_SET_Request *request) 1327 struct GNUNET_SET_Request *request)
1290{ 1328{
1291 struct ServiceSession * s = (struct ServiceSession *) cls; 1329 struct ServiceSession * s = cls;
1292 1330
1293 s->intersection_op = GNUNET_SET_accept (request, 1331 s->intersection_op = GNUNET_SET_accept (request,
1294 GNUNET_SET_RESULT_REMOVED, 1332 GNUNET_SET_RESULT_REMOVED,
1295 cb_intersection_element_removed, 1333 cb_intersection_element_removed,
1296 s); 1334 s);
1297 if (NULL == s->intersection_op) { 1335 if (NULL == s->intersection_op)
1336 {
1298 s->active = GNUNET_SYSERR; 1337 s->active = GNUNET_SYSERR;
1299 s->client_notification_task = 1338 s->client_notification_task =
1300 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 1339 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
1301 s); 1340 s);
1302 return; 1341 return;
1303 } 1342 }
1304 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set)) { 1343 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
1344 {
1305 s->active = GNUNET_SYSERR; 1345 s->active = GNUNET_SYSERR;
1306 s->client_notification_task = 1346 s->client_notification_task =
1307 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 1347 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
@@ -1335,16 +1375,19 @@ prepare_client_response (void *cls,
1335 1375
1336 s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; 1376 s->client_notification_task = GNUNET_SCHEDULER_NO_TASK;
1337 1377
1338 if (s->product) { 1378 if (s->product)
1379 {
1339 gcry_mpi_t value = gcry_mpi_new (0); 1380 gcry_mpi_t value = gcry_mpi_new (0);
1340 1381
1341 sign = gcry_mpi_cmp_ui (s->product, 0); 1382 sign = gcry_mpi_cmp_ui (s->product, 0);
1342 // libgcrypt can not handle a print of a negative number 1383 // libgcrypt can not handle a print of a negative number
1343 // if (a->sign) return gcry_error (GPG_ERR_INTERNAL); /* Can't handle it yet. */ 1384 // if (a->sign) return gcry_error (GPG_ERR_INTERNAL); /* Can't handle it yet. */
1344 if (0 > sign) { 1385 if (0 > sign)
1386 {
1345 gcry_mpi_sub (value, value, s->product); 1387 gcry_mpi_sub (value, value, s->product);
1346 } 1388 }
1347 else if (0 < sign) { 1389 else if (0 < sign)
1390 {
1348 range = 1; 1391 range = 1;
1349 gcry_mpi_add (value, value, s->product); 1392 gcry_mpi_add (value, value, s->product);
1350 } 1393 }
@@ -1359,7 +1402,8 @@ prepare_client_response (void *cls,
1359 && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, 1402 && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD,
1360 &product_exported, 1403 &product_exported,
1361 &product_length, 1404 &product_length,
1362 value)))) { 1405 value))))
1406 {
1363 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 1407 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
1364 product_length = 0; 1408 product_length = 0;
1365 range = -1; // signal error with product-length = 0 and range = -1 1409 range = -1; // signal error with product-length = 0 and range = -1
@@ -1369,7 +1413,8 @@ prepare_client_response (void *cls,
1369 1413
1370 msg_length = sizeof (struct ClientResponseMessage) + product_length; 1414 msg_length = sizeof (struct ClientResponseMessage) + product_length;
1371 msg = GNUNET_malloc (msg_length); 1415 msg = GNUNET_malloc (msg_length);
1372 if (product_exported != NULL) { 1416 if (product_exported != NULL)
1417 {
1373 memcpy (&msg[1], product_exported, product_length); 1418 memcpy (&msg[1], product_exported, product_length);
1374 GNUNET_free (product_exported); 1419 GNUNET_free (product_exported);
1375 } 1420 }
@@ -1422,7 +1467,8 @@ prepare_alices_computation_request (struct ServiceSession * s)
1422 sizeof (struct ServiceRequestMessage), 1467 sizeof (struct ServiceRequestMessage),
1423 &cb_transfer_message, 1468 &cb_transfer_message,
1424 s); 1469 s);
1425 if (!s->service_transmit_handle) { 1470 if (!s->service_transmit_handle)
1471 {
1426 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1472 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1427 _("Could not send message to channel!\n")); 1473 _("Could not send message to channel!\n"));
1428 GNUNET_free (msg); 1474 GNUNET_free (msg);
@@ -1473,7 +1519,8 @@ prepare_alices_cyrptodata_message_multipart (void *cls)
1473 1519
1474 // now copy over the sorted element vector 1520 // now copy over the sorted element vector
1475 a = gcry_mpi_new (0); 1521 a = gcry_mpi_new (0);
1476 for (i = s->transferred_element_count; i < todo_count; i++) { 1522 for (i = s->transferred_element_count; i < todo_count; i++)
1523 {
1477 gcry_mpi_add (a, s->sorted_elements[i], my_offset); 1524 gcry_mpi_add (a, s->sorted_elements[i], my_offset);
1478 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - s->transferred_element_count]); 1525 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - s->transferred_element_count]);
1479 } 1526 }
@@ -1489,7 +1536,8 @@ prepare_alices_cyrptodata_message_multipart (void *cls)
1489 msg_length, 1536 msg_length,
1490 &cb_transfer_message, 1537 &cb_transfer_message,
1491 s); 1538 s);
1492 if (!s->service_transmit_handle) { 1539 if (!s->service_transmit_handle)
1540 {
1493 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1541 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1494 _("Could not send service-request multipart message to channel!\n")); 1542 _("Could not send service-request multipart message to channel!\n"));
1495 GNUNET_free (msg); 1543 GNUNET_free (msg);
@@ -1517,7 +1565,8 @@ client_request_complete_bob (struct ServiceSession * client_session)
1517 s = find_matching_session (from_service_tail, 1565 s = find_matching_session (from_service_tail,
1518 &client_session->session_id, 1566 &client_session->session_id,
1519 NULL); 1567 NULL);
1520 if (NULL != s) { 1568 if (NULL != s)
1569 {
1521 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1570 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1522 _ ("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"), 1571 _ ("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"),
1523 GNUNET_h2s (&client_session->session_id)); 1572 GNUNET_h2s (&client_session->session_id));
@@ -1538,7 +1587,8 @@ client_request_complete_bob (struct ServiceSession * client_session)
1538 1587
1539 GNUNET_SET_commit (s->intersection_op, s->intersection_set); 1588 GNUNET_SET_commit (s->intersection_op, s->intersection_set);
1540 } 1589 }
1541 else { 1590 else
1591 {
1542 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1592 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1543 _ ("Got client-responder-session with key %s but NO matching service-request-session set, queuing element for later use.\n"), 1593 _ ("Got client-responder-session with key %s but NO matching service-request-session set, queuing element for later use.\n"),
1544 GNUNET_h2s (&client_session->session_id)); 1594 GNUNET_h2s (&client_session->session_id));
@@ -1563,7 +1613,8 @@ client_request_complete_alice (struct ServiceSession * s)
1563 &s->peer, 1613 &s->peer,
1564 GNUNET_APPLICATION_TYPE_SCALARPRODUCT, 1614 GNUNET_APPLICATION_TYPE_SCALARPRODUCT,
1565 GNUNET_CADET_OPTION_RELIABLE); 1615 GNUNET_CADET_OPTION_RELIABLE);
1566 if (NULL == s->channel) { 1616 if (NULL == s->channel)
1617 {
1567 s->active = GNUNET_SYSERR; 1618 s->active = GNUNET_SYSERR;
1568 s->client_notification_task = 1619 s->client_notification_task =
1569 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 1620 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
@@ -1571,11 +1622,12 @@ client_request_complete_alice (struct ServiceSession * s)
1571 return; 1622 return;
1572 } 1623 }
1573 s->intersection_listen = GNUNET_SET_listen (cfg, 1624 s->intersection_listen = GNUNET_SET_listen (cfg,
1574 GNUNET_SET_OPERATION_INTERSECTION, 1625 GNUNET_SET_OPERATION_INTERSECTION,
1575 &s->session_id, 1626 &s->session_id,
1576 cb_intersection_request_alice, 1627 cb_intersection_request_alice,
1577 s); 1628 s);
1578 if (NULL == s->intersection_listen) { 1629 if (NULL == s->intersection_listen)
1630 {
1579 s->active = GNUNET_SYSERR; 1631 s->active = GNUNET_SYSERR;
1580 s->client_notification_task = 1632 s->client_notification_task =
1581 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 1633 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
@@ -1592,9 +1644,9 @@ handle_client_message_multipart (void *cls,
1592 const struct GNUNET_MessageHeader *message) 1644 const struct GNUNET_MessageHeader *message)
1593{ 1645{
1594 const struct ComputationMultipartMessage * msg = (const struct ComputationMultipartMessage *) message; 1646 const struct ComputationMultipartMessage * msg = (const struct ComputationMultipartMessage *) message;
1595 struct ServiceSession * s; 1647 struct ServiceSession *s;
1596 uint32_t contained_count; 1648 uint32_t contained_count;
1597 struct GNUNET_SCALARPRODUCT_Element * elements; 1649 struct GNUNET_SCALARPRODUCT_Element *elements;
1598 uint32_t i; 1650 uint32_t i;
1599 1651
1600 // only one concurrent session per client connection allowed, simplifies logics a lot... 1652 // only one concurrent session per client connection allowed, simplifies logics a lot...
@@ -1617,7 +1669,8 @@ handle_client_message_multipart (void *cls,
1617 s->transferred_element_count += contained_count; 1669 s->transferred_element_count += contained_count;
1618 1670
1619 elements = (struct GNUNET_SCALARPRODUCT_Element *) & msg[1]; 1671 elements = (struct GNUNET_SCALARPRODUCT_Element *) & msg[1];
1620 for (i = 0; i < contained_count; i++) { 1672 for (i = 0; i < contained_count; i++)
1673 {
1621 struct GNUNET_SET_Element set_elem; 1674 struct GNUNET_SET_Element set_elem;
1622 struct GNUNET_SCALARPRODUCT_Element * elem; 1675 struct GNUNET_SCALARPRODUCT_Element * elem;
1623 1676
@@ -1630,7 +1683,8 @@ handle_client_message_multipart (void *cls,
1630 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1683 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (s->intersected_elements,
1631 &elem->key, 1684 &elem->key,
1632 elem, 1685 elem,
1633 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { 1686 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1687 {
1634 GNUNET_free (elem); 1688 GNUNET_free (elem);
1635 continue; 1689 continue;
1636 } 1690 }
@@ -1679,7 +1733,8 @@ handle_client_message (void *cls,
1679 1733
1680 // only one concurrent session per client connection allowed, simplifies logics a lot... 1734 // only one concurrent session per client connection allowed, simplifies logics a lot...
1681 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); 1735 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession);
1682 if (NULL != s) { 1736 if (NULL != s)
1737 {
1683 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1738 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1684 return; 1739 return;
1685 } 1740 }
@@ -1784,21 +1839,20 @@ handle_client_message (void *cls,
1784 * @param initiator peer that started the channel 1839 * @param initiator peer that started the channel
1785 * @param port unused 1840 * @param port unused
1786 * @param options unused 1841 * @param options unused
1787 *
1788 * @return session associated with the channel 1842 * @return session associated with the channel
1789 */ 1843 */
1790static void * 1844static void *
1791cb_channel_incoming (void *cls, 1845cb_channel_incoming (void *cls,
1792 struct GNUNET_CADET_Channel *channel, 1846 struct GNUNET_CADET_Channel *channel,
1793 const struct GNUNET_PeerIdentity *initiator, 1847 const struct GNUNET_PeerIdentity *initiator,
1794 uint32_t port, enum GNUNET_CADET_ChannelOption options) 1848 uint32_t port,
1849 enum GNUNET_CADET_ChannelOption options)
1795{ 1850{
1796 struct ServiceSession * s = GNUNET_new (struct ServiceSession); 1851 struct ServiceSession *s = GNUNET_new (struct ServiceSession);
1797 1852
1798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1799 _ ("New incoming channel from peer %s.\n"), 1854 _ ("New incoming channel from peer %s.\n"),
1800 GNUNET_i2s (initiator)); 1855 GNUNET_i2s (initiator));
1801
1802 s->peer = *initiator; 1856 s->peer = *initiator;
1803 s->channel = channel; 1857 s->channel = channel;
1804 s->role = BOB; 1858 s->role = BOB;
@@ -1820,8 +1874,8 @@ cb_channel_incoming (void *cls,
1820 */ 1874 */
1821static void 1875static void
1822cb_channel_destruction (void *cls, 1876cb_channel_destruction (void *cls,
1823 const struct GNUNET_CADET_Channel *channel, 1877 const struct GNUNET_CADET_Channel *channel,
1824 void *channel_ctx) 1878 void *channel_ctx)
1825{ 1879{
1826 struct ServiceSession * s = channel_ctx; 1880 struct ServiceSession * s = channel_ctx;
1827 struct ServiceSession * client_session; 1881 struct ServiceSession * client_session;
@@ -1834,14 +1888,16 @@ cb_channel_destruction (void *cls,
1834 // as we have only one peer connected in each session, just remove the session 1888 // as we have only one peer connected in each session, just remove the session
1835 s->channel = NULL; 1889 s->channel = NULL;
1836 1890
1837 if ((ALICE == s->role) && (GNUNET_NO != s->active) && (!do_shutdown)) { 1891 if ((ALICE == s->role) && (GNUNET_NO != s->active) && (!do_shutdown))
1892 {
1838 // if this happened before we received the answer, we must terminate the session 1893 // if this happened before we received the answer, we must terminate the session
1839 s->role = GNUNET_SYSERR; 1894 s->role = GNUNET_SYSERR;
1840 s->client_notification_task = 1895 s->client_notification_task =
1841 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 1896 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
1842 s); 1897 s);
1843 } 1898 }
1844 else { 1899 else
1900 {
1845 if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) 1901 if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail))))
1846 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 1902 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s);
1847 1903
@@ -1855,7 +1911,8 @@ cb_channel_destruction (void *cls,
1855 1911
1856 // the client has to check if it was waiting for a result 1912 // the client has to check if it was waiting for a result
1857 // or if it was a responder, no point in adding more statefulness 1913 // or if it was a responder, no point in adding more statefulness
1858 if ((NULL != s->response ) && (!do_shutdown)) { 1914 if ((NULL != s->response ) && (!do_shutdown))
1915 {
1859 client_session->client_notification_task = 1916 client_session->client_notification_task =
1860 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 1917 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
1861 client_session); 1918 client_session);
@@ -1871,7 +1928,7 @@ cb_channel_destruction (void *cls,
1871 * @return product as MPI, never NULL 1928 * @return product as MPI, never NULL
1872 */ 1929 */
1873static gcry_mpi_t 1930static gcry_mpi_t
1874compute_scalar_product (struct ServiceSession * session) 1931compute_scalar_product (struct ServiceSession *session)
1875{ 1932{
1876 uint32_t count; 1933 uint32_t count;
1877 gcry_mpi_t t; 1934 gcry_mpi_t t;
@@ -1890,7 +1947,8 @@ compute_scalar_product (struct ServiceSession * session)
1890 // due to the introduced static offset S, we now also have to remove this 1947 // due to the introduced static offset S, we now also have to remove this
1891 // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each, 1948 // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each,
1892 // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) 1949 // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi)
1893 for (i = 0; i < count; i++) { 1950 for (i = 0; i < count; i++)
1951 {
1894 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, 1952 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey,
1895 &session->r[i], r[i]); 1953 &session->r[i], r[i]);
1896 gcry_mpi_sub (r[i], r[i], my_offset); 1954 gcry_mpi_sub (r[i], r[i], my_offset);
@@ -1947,7 +2005,8 @@ compute_scalar_product (struct ServiceSession * session)
1947 gcry_mpi_div (p, NULL, p, tmp, 0); 2005 gcry_mpi_div (p, NULL, p, tmp, 0);
1948 2006
1949 gcry_mpi_release (tmp); 2007 gcry_mpi_release (tmp);
1950 for (i = 0; i < count; i++) { 2008 for (i = 0; i < count; i++)
2009 {
1951 gcry_mpi_release (session->sorted_elements[i]); 2010 gcry_mpi_release (session->sorted_elements[i]);
1952 gcry_mpi_release (r[i]); 2011 gcry_mpi_release (r[i]);
1953 gcry_mpi_release (r_prime[i]); 2012 gcry_mpi_release (r_prime[i]);
@@ -1993,11 +2052,13 @@ handle_alices_cyrptodata_message_multipart (void *cls,
1993 s = (struct ServiceSession *) * channel_ctx; 2052 s = (struct ServiceSession *) * channel_ctx;
1994 //we are not bob 2053 //we are not bob
1995 if ((NULL == s->e_a) || //or we did not expect this message yet 2054 if ((NULL == s->e_a) || //or we did not expect this message yet
1996 (s->used_element_count == s->transferred_element_count)) { //we are not expecting multipart messages 2055 (s->used_element_count == s->transferred_element_count))
2056 { //we are not expecting multipart messages
1997 goto except; 2057 goto except;
1998 } 2058 }
1999 // shorter than minimum? 2059 // shorter than minimum?
2000 if (ntohs (msg->header.size) <= sizeof (struct MultipartMessage)) { 2060 if (ntohs (msg->header.size) <= sizeof (struct MultipartMessage))
2061 {
2001 goto except; 2062 goto except;
2002 } 2063 }
2003 contained_elements = ntohl (msg->contained_element_count); 2064 contained_elements = ntohl (msg->contained_element_count);
@@ -2006,7 +2067,8 @@ handle_alices_cyrptodata_message_multipart (void *cls,
2006 //sanity check 2067 //sanity check
2007 if ((ntohs (msg->header.size) != msg_length) 2068 if ((ntohs (msg->header.size) != msg_length)
2008 || (s->used_element_count < contained_elements + s->transferred_element_count) 2069 || (s->used_element_count < contained_elements + s->transferred_element_count)
2009 || (0 == contained_elements)) { 2070 || (0 == contained_elements))
2071 {
2010 goto except; 2072 goto except;
2011 } 2073 }
2012 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 2074 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
@@ -2016,7 +2078,8 @@ handle_alices_cyrptodata_message_multipart (void *cls,
2016 2078
2017 s->transferred_element_count += contained_elements; 2079 s->transferred_element_count += contained_elements;
2018 2080
2019 if (contained_elements == s->used_element_count) { 2081 if (contained_elements == s->used_element_count)
2082 {
2020 // single part finished 2083 // single part finished
2021 if (NULL == s->intersection_op) 2084 if (NULL == s->intersection_op)
2022 // intersection has already finished, so we can proceed 2085 // intersection has already finished, so we can proceed
@@ -2028,14 +2091,16 @@ except:
2028 s->channel = NULL; 2091 s->channel = NULL;
2029 // and notify our client-session that we could not complete the session 2092 // and notify our client-session that we could not complete the session
2030 free_session_variables (s); 2093 free_session_variables (s);
2031 if (NULL != s->client){ 2094 if (NULL != s->client)
2095 {
2032 //Alice 2096 //Alice
2033 s->active = GNUNET_SYSERR; 2097 s->active = GNUNET_SYSERR;
2034 s->client_notification_task = 2098 s->client_notification_task =
2035 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2099 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
2036 s); 2100 s);
2037 } 2101 }
2038 else { 2102 else
2103 {
2039 //Bob 2104 //Bob
2040 if (NULL != s->response){ 2105 if (NULL != s->response){
2041 s->response->active = GNUNET_SYSERR; 2106 s->response->active = GNUNET_SYSERR;
@@ -2083,7 +2148,8 @@ handle_alices_cyrptodata_message (void *cls,
2083 !((NULL != s->intersection_op) 2148 !((NULL != s->intersection_op)
2084 //intersection OP done 2149 //intersection OP done
2085 || (s->response->sorted_elements) 2150 || (s->response->sorted_elements)
2086 )) { 2151 ))
2152 {
2087 goto invalid_msg; 2153 goto invalid_msg;
2088 } 2154 }
2089 2155
@@ -2100,7 +2166,8 @@ handle_alices_cyrptodata_message (void *cls,
2100 //sanity check: is the message as long as the message_count fields suggests? 2166 //sanity check: is the message as long as the message_count fields suggests?
2101 if ((ntohs (msg->header.size) != msg_length) || 2167 if ((ntohs (msg->header.size) != msg_length) ||
2102 (s->used_element_count < s->transferred_element_count + contained_elements) || 2168 (s->used_element_count < s->transferred_element_count + contained_elements) ||
2103 (0 == contained_elements)) { 2169 (0 == contained_elements))
2170 {
2104 goto invalid_msg; 2171 goto invalid_msg;
2105 } 2172 }
2106 2173
@@ -2109,7 +2176,8 @@ handle_alices_cyrptodata_message (void *cls,
2109 2176
2110 s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count); 2177 s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count);
2111 memcpy (&s->e_a[0], payload, contained_elements * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2178 memcpy (&s->e_a[0], payload, contained_elements * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2112 if (contained_elements == s->used_element_count) { 2179 if (contained_elements == s->used_element_count)
2180 {
2113 // single part finished 2181 // single part finished
2114 if (NULL == s->intersection_op) 2182 if (NULL == s->intersection_op)
2115 // intersection has already finished, so we can proceed 2183 // intersection has already finished, so we can proceed
@@ -2121,16 +2189,19 @@ invalid_msg:
2121 s->channel = NULL; 2189 s->channel = NULL;
2122 // and notify our client-session that we could not complete the session 2190 // and notify our client-session that we could not complete the session
2123 free_session_variables (s); 2191 free_session_variables (s);
2124 if (NULL != s->client){ 2192 if (NULL != s->client)
2193 {
2125 //Alice 2194 //Alice
2126 s->active = GNUNET_SYSERR; 2195 s->active = GNUNET_SYSERR;
2127 s->client_notification_task = 2196 s->client_notification_task =
2128 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2197 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
2129 s); 2198 s);
2130 } 2199 }
2131 else { 2200 else
2201 {
2132 //Bob 2202 //Bob
2133 if (NULL != s->response) { 2203 if (NULL != s->response)
2204 {
2134 s->response->active = GNUNET_SYSERR; 2205 s->response->active = GNUNET_SYSERR;
2135 s->response->client_notification_task = 2206 s->response->client_notification_task =
2136 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2207 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
@@ -2165,18 +2236,21 @@ handle_alices_computation_request (void *cls,
2165 const struct ServiceRequestMessage * msg = (const struct ServiceRequestMessage *) message; 2236 const struct ServiceRequestMessage * msg = (const struct ServiceRequestMessage *) message;
2166 2237
2167 s = (struct ServiceSession *) * channel_ctx; 2238 s = (struct ServiceSession *) * channel_ctx;
2168 if ((BOB != s->role) || (s->total != 0)) { 2239 if ((BOB != s->role) || (s->total != 0))
2240 {
2169 // must be a fresh session 2241 // must be a fresh session
2170 goto invalid_msg; 2242 goto invalid_msg;
2171 } 2243 }
2172 // Check if message was sent by me, which would be bad! 2244 // Check if message was sent by me, which would be bad!
2173 if (!memcmp (&s->peer, &me, sizeof (struct GNUNET_PeerIdentity))) { 2245 if (!memcmp (&s->peer, &me, sizeof (struct GNUNET_PeerIdentity)))
2246 {
2174 GNUNET_free (s); 2247 GNUNET_free (s);
2175 GNUNET_break (0); 2248 GNUNET_break (0);
2176 return GNUNET_SYSERR; 2249 return GNUNET_SYSERR;
2177 } 2250 }
2178 // shorter than expected? 2251 // shorter than expected?
2179 if (ntohs (msg->header.size) != sizeof (struct ServiceRequestMessage)) { 2252 if (ntohs (msg->header.size) != sizeof (struct ServiceRequestMessage))
2253 {
2180 GNUNET_free (s); 2254 GNUNET_free (s);
2181 GNUNET_break_op (0); 2255 GNUNET_break_op (0);
2182 return GNUNET_SYSERR; 2256 return GNUNET_SYSERR;
@@ -2208,9 +2282,12 @@ handle_alices_computation_request (void *cls,
2208 GNUNET_CONTAINER_DLL_insert (from_service_head, from_service_tail, s); 2282 GNUNET_CONTAINER_DLL_insert (from_service_head, from_service_tail, s);
2209 2283
2210 if ((NULL != client_session) 2284 if ((NULL != client_session)
2211 && (client_session->transferred_element_count == client_session->total)) { 2285 && (client_session->transferred_element_count == client_session->total))
2286 {
2212 2287
2213 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&s->session_id)); 2288 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2289 _("Got session with key %s and a matching element set, processing.\n"),
2290 GNUNET_h2s (&s->session_id));
2214 2291
2215 s->response = client_session; 2292 s->response = client_session;
2216 s->intersected_elements = client_session->intersected_elements; 2293 s->intersected_elements = client_session->intersected_elements;
@@ -2228,7 +2305,8 @@ handle_alices_computation_request (void *cls,
2228 2305
2229 GNUNET_SET_commit (s->intersection_op, s->intersection_set); 2306 GNUNET_SET_commit (s->intersection_op, s->intersection_set);
2230 } 2307 }
2231 else { 2308 else
2309 {
2232 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s without a matching element set, queueing.\n"), GNUNET_h2s (&s->session_id)); 2310 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s without a matching element set, queueing.\n"), GNUNET_h2s (&s->session_id));
2233 } 2311 }
2234 2312
@@ -2238,14 +2316,16 @@ invalid_msg:
2238 s->channel = NULL; 2316 s->channel = NULL;
2239 // and notify our client-session that we could not complete the session 2317 // and notify our client-session that we could not complete the session
2240 free_session_variables (s); 2318 free_session_variables (s);
2241 if (NULL != s->client){ 2319 if (NULL != s->client)
2320 {
2242 //Alice 2321 //Alice
2243 s->active = GNUNET_SYSERR; 2322 s->active = GNUNET_SYSERR;
2244 s->client_notification_task = 2323 s->client_notification_task =
2245 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2324 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
2246 s); 2325 s);
2247 } 2326 }
2248 else { 2327 else
2328 {
2249 //Bob 2329 //Bob
2250 if (NULL != s->response) { 2330 if (NULL != s->response) {
2251 s->response->active = GNUNET_SYSERR; 2331 s->response->active = GNUNET_SYSERR;
@@ -2288,21 +2368,24 @@ handle_bobs_cryptodata_multipart (void *cls,
2288 GNUNET_assert (NULL != message); 2368 GNUNET_assert (NULL != message);
2289 // are we in the correct state? 2369 // are we in the correct state?
2290 s = (struct ServiceSession *) * channel_ctx; 2370 s = (struct ServiceSession *) * channel_ctx;
2291 if ((ALICE != s->role) || (NULL == s->sorted_elements)) { 2371 if ((ALICE != s->role) || (NULL == s->sorted_elements))
2372 {
2292 goto invalid_msg; 2373 goto invalid_msg;
2293 } 2374 }
2294 msg_size = ntohs (msg->header.size); 2375 msg_size = ntohs (msg->header.size);
2295 required_size = sizeof (struct MultipartMessage) 2376 required_size = sizeof (struct MultipartMessage)
2296 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 2377 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
2297 // shorter than minimum? 2378 // shorter than minimum?
2298 if (required_size > msg_size) { 2379 if (required_size > msg_size)
2380 {
2299 goto invalid_msg; 2381 goto invalid_msg;
2300 } 2382 }
2301 contained = ntohl (msg->contained_element_count); 2383 contained = ntohl (msg->contained_element_count);
2302 required_size = sizeof (struct MultipartMessage) 2384 required_size = sizeof (struct MultipartMessage)
2303 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 2385 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
2304 //sanity check: is the message as long as the message_count fields suggests? 2386 //sanity check: is the message as long as the message_count fields suggests?
2305 if ((required_size != msg_size) || (s->used_element_count < s->transferred_element_count + contained)) { 2387 if ((required_size != msg_size) || (s->used_element_count < s->transferred_element_count + contained))
2388 {
2306 goto invalid_msg; 2389 goto invalid_msg;
2307 } 2390 }
2308 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 2391 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
@@ -2320,7 +2403,8 @@ invalid_msg:
2320 GNUNET_break_op (NULL != s->product); 2403 GNUNET_break_op (NULL != s->product);
2321 s->channel = NULL; 2404 s->channel = NULL;
2322 // send message with product to client 2405 // send message with product to client
2323 if (NULL != s->client){ 2406 if (NULL != s->client)
2407 {
2324 //Alice 2408 //Alice
2325 if (NULL != s->product) 2409 if (NULL != s->product)
2326 s->active = GNUNET_NO; 2410 s->active = GNUNET_NO;
@@ -2330,7 +2414,8 @@ invalid_msg:
2330 GNUNET_SCHEDULER_add_now (&prepare_client_response, 2414 GNUNET_SCHEDULER_add_now (&prepare_client_response,
2331 s); 2415 s);
2332 } 2416 }
2333 else { 2417 else
2418 {
2334 //Bob 2419 //Bob
2335 if (NULL != s->response){ 2420 if (NULL != s->response){
2336 s->response->active = GNUNET_SYSERR; 2421 s->response->active = GNUNET_SYSERR;
@@ -2379,14 +2464,16 @@ handle_bobs_cryptodata_message (void *cls,
2379 // are we in the correct state? 2464 // are we in the correct state?
2380 if (NULL == s->sorted_elements 2465 if (NULL == s->sorted_elements
2381 || NULL != s->msg 2466 || NULL != s->msg
2382 || s->used_element_count != s->transferred_element_count) { 2467 || s->used_element_count != s->transferred_element_count)
2468 {
2383 goto invalid_msg; 2469 goto invalid_msg;
2384 } 2470 }
2385 //we need at least a full message without elements attached 2471 //we need at least a full message without elements attached
2386 msg_size = ntohs (msg->header.size); 2472 msg_size = ntohs (msg->header.size);
2387 required_size = sizeof (struct ServiceResponseMessage) + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 2473 required_size = sizeof (struct ServiceResponseMessage) + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
2388 2474
2389 if (required_size > msg_size) { 2475 if (required_size > msg_size)
2476 {
2390 goto invalid_msg; 2477 goto invalid_msg;
2391 } 2478 }
2392 contained = ntohl (msg->contained_element_count); 2479 contained = ntohl (msg->contained_element_count);
@@ -2394,7 +2481,8 @@ handle_bobs_cryptodata_message (void *cls,
2394 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) 2481 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)
2395 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 2482 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
2396 //sanity check: is the message as long as the message_count fields suggests? 2483 //sanity check: is the message as long as the message_count fields suggests?
2397 if ((msg_size != required_size) || (s->used_element_count < contained)) { 2484 if ((msg_size != required_size) || (s->used_element_count < contained))
2485 {
2398 goto invalid_msg; 2486 goto invalid_msg;
2399 } 2487 }
2400 s->transferred_element_count = contained; 2488 s->transferred_element_count = contained;
@@ -2411,7 +2499,8 @@ handle_bobs_cryptodata_message (void *cls,
2411 2499
2412 payload = &payload[2]; 2500 payload = &payload[2];
2413 // Convert each k[][perm] to its MPI_value 2501 // Convert each k[][perm] to its MPI_value
2414 for (i = 0; i < contained; i++) { 2502 for (i = 0; i < contained; i++)
2503 {
2415 memcpy (&s->r[i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2504 memcpy (&s->r[i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2416 memcpy (&s->r_prime[i], &payload[2 * i + 1], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2505 memcpy (&s->r_prime[i], &payload[2 * i + 1], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2417 } 2506 }
@@ -2423,15 +2512,18 @@ invalid_msg:
2423 GNUNET_break_op (NULL != s->product); 2512 GNUNET_break_op (NULL != s->product);
2424 s->channel = NULL; 2513 s->channel = NULL;
2425 // send message with product to client 2514 // send message with product to client
2426 if (NULL != s->client){ 2515 if (NULL != s->client)
2516 {
2427 //Alice 2517 //Alice
2428 s->client_notification_task = 2518 s->client_notification_task =
2429 GNUNET_SCHEDULER_add_now (&prepare_client_response, 2519 GNUNET_SCHEDULER_add_now (&prepare_client_response,
2430 s); 2520 s);
2431 } 2521 }
2432 else { 2522 else
2523 {
2433 //Bob 2524 //Bob
2434 if (NULL != s->response) { 2525 if (NULL != s->response)
2526 {
2435 s->response->active = GNUNET_SYSERR; 2527 s->response->active = GNUNET_SYSERR;
2436 s->response->client_notification_task = 2528 s->response->client_notification_task =
2437 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2529 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
@@ -2460,32 +2552,40 @@ shutdown_task (void *cls,
2460 const struct GNUNET_SCHEDULER_TaskContext *tc) 2552 const struct GNUNET_SCHEDULER_TaskContext *tc)
2461{ 2553{
2462 struct ServiceSession * s; 2554 struct ServiceSession * s;
2463 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Shutting down, initiating cleanup.\n")); 2555
2556 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2557 _("Shutting down, initiating cleanup.\n"));
2464 2558
2465 do_shutdown = GNUNET_YES; 2559 do_shutdown = GNUNET_YES;
2466 2560
2467 // terminate all owned open channels. 2561 // terminate all owned open channels.
2468 for (s = from_client_head; NULL != s; s = s->next) { 2562 for (s = from_client_head; NULL != s; s = s->next)
2469 if ((GNUNET_NO != s->active) && (NULL != s->channel)) { 2563 {
2564 if ((GNUNET_NO != s->active) && (NULL != s->channel))
2565 {
2470 GNUNET_CADET_channel_destroy (s->channel); 2566 GNUNET_CADET_channel_destroy (s->channel);
2471 s->channel = NULL; 2567 s->channel = NULL;
2472 } 2568 }
2473 if (GNUNET_SCHEDULER_NO_TASK != s->client_notification_task) { 2569 if (GNUNET_SCHEDULER_NO_TASK != s->client_notification_task)
2570 {
2474 GNUNET_SCHEDULER_cancel (s->client_notification_task); 2571 GNUNET_SCHEDULER_cancel (s->client_notification_task);
2475 s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; 2572 s->client_notification_task = GNUNET_SCHEDULER_NO_TASK;
2476 } 2573 }
2477 if (NULL != s->client) { 2574 if (NULL != s->client)
2575 {
2478 GNUNET_SERVER_client_disconnect (s->client); 2576 GNUNET_SERVER_client_disconnect (s->client);
2479 s->client = NULL; 2577 s->client = NULL;
2480 } 2578 }
2481 } 2579 }
2482 for (s = from_service_head; NULL != s; s = s->next) 2580 for (s = from_service_head; NULL != s; s = s->next)
2483 if (NULL != s->channel) { 2581 if (NULL != s->channel)
2582 {
2484 GNUNET_CADET_channel_destroy (s->channel); 2583 GNUNET_CADET_channel_destroy (s->channel);
2485 s->channel = NULL; 2584 s->channel = NULL;
2486 } 2585 }
2487 2586
2488 if (my_cadet) { 2587 if (my_cadet)
2588 {
2489 GNUNET_CADET_disconnect (my_cadet); 2589 GNUNET_CADET_disconnect (my_cadet);
2490 my_cadet = NULL; 2590 my_cadet = NULL;
2491 } 2591 }
@@ -2545,12 +2645,15 @@ run (void *cls,
2545 &cb_channel_incoming, 2645 &cb_channel_incoming,
2546 &cb_channel_destruction, 2646 &cb_channel_destruction,
2547 cadet_handlers, ports); 2647 cadet_handlers, ports);
2548 if (!my_cadet) { 2648 if (!my_cadet)
2549 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n")); 2649 {
2650 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2651 _("Connect to CADET failed\n"));
2550 GNUNET_SCHEDULER_shutdown (); 2652 GNUNET_SCHEDULER_shutdown ();
2551 return; 2653 return;
2552 } 2654 }
2553 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("CADET initialized\n")); 2655 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2656 _("CADET initialized\n"));
2554 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 2657 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
2555 &shutdown_task, 2658 &shutdown_task,
2556 NULL); 2659 NULL);