diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-19 01:44:37 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-19 01:44:37 +0100 |
commit | 8a946bb7c2bc6bb863980ecf16607c57c2b077ec (patch) | |
tree | aba71ee23c34ef55778eb7e2f6811e0fb837309b | |
parent | 5afc3372aec888e2db988ad30a889c4bc842e5ac (diff) | |
download | gnunet-8a946bb7c2bc6bb863980ecf16607c57c2b077ec.tar.gz gnunet-8a946bb7c2bc6bb863980ecf16607c57c2b077ec.zip |
towards converting SP to new CADET API; still fails tests though
-rw-r--r-- | src/scalarproduct/.gitignore | 1 | ||||
-rw-r--r-- | src/scalarproduct/Makefile.am | 8 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | 113 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | 439 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_alice.c | 213 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_bob.c | 419 |
6 files changed, 363 insertions, 830 deletions
diff --git a/src/scalarproduct/.gitignore b/src/scalarproduct/.gitignore index e244f1108..19909a3f9 100644 --- a/src/scalarproduct/.gitignore +++ b/src/scalarproduct/.gitignore | |||
@@ -3,3 +3,4 @@ gnunet-scalarproduct | |||
3 | gnunet-service-scalarproduct-alice | 3 | gnunet-service-scalarproduct-alice |
4 | gnunet-service-scalarproduct-bob | 4 | gnunet-service-scalarproduct-bob |
5 | gnunet-service-scalarproduct-ecc-alice | 5 | gnunet-service-scalarproduct-ecc-alice |
6 | test_ecc_scalarproduct | ||
diff --git a/src/scalarproduct/Makefile.am b/src/scalarproduct/Makefile.am index 10e04284f..98829408a 100644 --- a/src/scalarproduct/Makefile.am +++ b/src/scalarproduct/Makefile.am | |||
@@ -42,7 +42,7 @@ gnunet_service_scalarproduct_alice_SOURCES = \ | |||
42 | gnunet-service-scalarproduct_alice.c | 42 | gnunet-service-scalarproduct_alice.c |
43 | gnunet_service_scalarproduct_alice_LDADD = \ | 43 | gnunet_service_scalarproduct_alice_LDADD = \ |
44 | $(top_builddir)/src/util/libgnunetutil.la \ | 44 | $(top_builddir)/src/util/libgnunetutil.la \ |
45 | $(top_builddir)/src/cadet/libgnunetcadet.la \ | 45 | $(top_builddir)/src/cadet/libgnunetcadetnew.la \ |
46 | $(top_builddir)/src/set/libgnunetset.la \ | 46 | $(top_builddir)/src/set/libgnunetset.la \ |
47 | $(LIBGCRYPT_LIBS) \ | 47 | $(LIBGCRYPT_LIBS) \ |
48 | -lgcrypt \ | 48 | -lgcrypt \ |
@@ -53,7 +53,7 @@ gnunet_service_scalarproduct_bob_SOURCES = \ | |||
53 | gnunet-service-scalarproduct_bob.c | 53 | gnunet-service-scalarproduct_bob.c |
54 | gnunet_service_scalarproduct_bob_LDADD = \ | 54 | gnunet_service_scalarproduct_bob_LDADD = \ |
55 | $(top_builddir)/src/util/libgnunetutil.la \ | 55 | $(top_builddir)/src/util/libgnunetutil.la \ |
56 | $(top_builddir)/src/cadet/libgnunetcadet.la \ | 56 | $(top_builddir)/src/cadet/libgnunetcadetnew.la \ |
57 | $(top_builddir)/src/set/libgnunetset.la \ | 57 | $(top_builddir)/src/set/libgnunetset.la \ |
58 | $(LIBGCRYPT_LIBS) \ | 58 | $(LIBGCRYPT_LIBS) \ |
59 | -lgcrypt \ | 59 | -lgcrypt \ |
@@ -64,7 +64,7 @@ gnunet_service_scalarproduct_ecc_alice_SOURCES = \ | |||
64 | gnunet-service-scalarproduct-ecc_alice.c | 64 | gnunet-service-scalarproduct-ecc_alice.c |
65 | gnunet_service_scalarproduct_ecc_alice_LDADD = \ | 65 | gnunet_service_scalarproduct_ecc_alice_LDADD = \ |
66 | $(top_builddir)/src/util/libgnunetutil.la \ | 66 | $(top_builddir)/src/util/libgnunetutil.la \ |
67 | $(top_builddir)/src/cadet/libgnunetcadet.la \ | 67 | $(top_builddir)/src/cadet/libgnunetcadetnew.la \ |
68 | $(top_builddir)/src/set/libgnunetset.la \ | 68 | $(top_builddir)/src/set/libgnunetset.la \ |
69 | $(LIBGCRYPT_LIBS) \ | 69 | $(LIBGCRYPT_LIBS) \ |
70 | -lgcrypt \ | 70 | -lgcrypt \ |
@@ -75,7 +75,7 @@ gnunet_service_scalarproduct_ecc_bob_SOURCES = \ | |||
75 | gnunet-service-scalarproduct-ecc_bob.c | 75 | gnunet-service-scalarproduct-ecc_bob.c |
76 | gnunet_service_scalarproduct_ecc_bob_LDADD = \ | 76 | gnunet_service_scalarproduct_ecc_bob_LDADD = \ |
77 | $(top_builddir)/src/util/libgnunetutil.la \ | 77 | $(top_builddir)/src/util/libgnunetutil.la \ |
78 | $(top_builddir)/src/cadet/libgnunetcadet.la \ | 78 | $(top_builddir)/src/cadet/libgnunetcadetnew.la \ |
79 | $(top_builddir)/src/set/libgnunetset.la \ | 79 | $(top_builddir)/src/set/libgnunetset.la \ |
80 | $(LIBGCRYPT_LIBS) \ | 80 | $(LIBGCRYPT_LIBS) \ |
81 | -lgcrypt \ | 81 | -lgcrypt \ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c index 0b7f24e7e..79a6c6704 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013-2016 GNUnet e.V. | 3 | Copyright (C) 2013-2017 GNUnet e.V. |
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 |
@@ -238,15 +238,10 @@ destroy_service_session (struct AliceServiceSession *s) | |||
238 | if (GNUNET_YES == s->in_destroy) | 238 | if (GNUNET_YES == s->in_destroy) |
239 | return; | 239 | return; |
240 | s->in_destroy = GNUNET_YES; | 240 | s->in_destroy = GNUNET_YES; |
241 | if (NULL != s->cadet_mq) | ||
242 | { | ||
243 | GNUNET_MQ_destroy (s->cadet_mq); | ||
244 | s->cadet_mq = NULL; | ||
245 | } | ||
246 | if (NULL != s->client) | 241 | if (NULL != s->client) |
247 | { | 242 | { |
248 | struct GNUNET_SERVICE_Client *c = s->client; | 243 | struct GNUNET_SERVICE_Client *c = s->client; |
249 | 244 | ||
250 | s->client = NULL; | 245 | s->client = NULL; |
251 | GNUNET_SERVICE_client_drop (c); | 246 | GNUNET_SERVICE_client_drop (c); |
252 | } | 247 | } |
@@ -401,34 +396,25 @@ transmit_client_response (struct AliceServiceSession *s) | |||
401 | } | 396 | } |
402 | 397 | ||
403 | 398 | ||
404 | |||
405 | /** | 399 | /** |
406 | * Function called whenever a channel is destroyed. Should clean up | 400 | * Function called whenever a channel is destroyed. Should clean up |
407 | * any associated state. | 401 | * any associated state. |
408 | * | 402 | * |
409 | * It must NOT call #GNUNET_CADET_channel_destroy() on the channel. | 403 | * It must NOT call #GNUNET_CADET_channel_destroy() on the channel. |
410 | * | 404 | * |
411 | * @param cls closure (set from #GNUNET_CADET_connect()) | 405 | * @param cls the `struct AliceServiceSession` |
412 | * @param channel connection to the other end (henceforth invalid) | 406 | * @param channel connection to the other end (henceforth invalid) |
413 | * @param channel_ctx place where local state associated | ||
414 | * with the channel is stored | ||
415 | */ | 407 | */ |
416 | static void | 408 | static void |
417 | cb_channel_destruction (void *cls, | 409 | cb_channel_destruction (void *cls, |
418 | const struct GNUNET_CADET_Channel *channel, | 410 | const struct GNUNET_CADET_Channel *channel) |
419 | void *channel_ctx) | ||
420 | { | 411 | { |
421 | struct AliceServiceSession *s = channel_ctx; | 412 | struct AliceServiceSession *s = cls; |
422 | 413 | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
424 | "Peer disconnected, terminating session %s with peer %s\n", | 415 | "Peer disconnected, terminating session %s with peer %s\n", |
425 | GNUNET_h2s (&s->session_id), | 416 | GNUNET_h2s (&s->session_id), |
426 | GNUNET_i2s (&s->peer)); | 417 | GNUNET_i2s (&s->peer)); |
427 | if (NULL != s->cadet_mq) | ||
428 | { | ||
429 | GNUNET_MQ_destroy (s->cadet_mq); | ||
430 | s->cadet_mq = NULL; | ||
431 | } | ||
432 | s->channel = NULL; | 418 | s->channel = NULL; |
433 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | 419 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
434 | { | 420 | { |
@@ -492,56 +478,40 @@ compute_scalar_product (struct AliceServiceSession *session, | |||
492 | * Handle a response we got from another service we wanted to | 478 | * Handle a response we got from another service we wanted to |
493 | * calculate a scalarproduct with. | 479 | * calculate a scalarproduct with. |
494 | * | 480 | * |
495 | * @param cls closure (set from #GNUNET_CADET_connect) | 481 | * @param cls the `struct AliceServiceSession *` |
496 | * @param channel connection to the other end | 482 | * @param msg the actual message |
497 | * @param channel_ctx place to store local state associated with the channel | ||
498 | * @param message the actual message | ||
499 | * @return #GNUNET_OK to keep the connection open, | ||
500 | * #GNUNET_SYSERR to close it (we are done) | ||
501 | */ | 483 | */ |
502 | static int | 484 | static void |
503 | handle_bobs_cryptodata_message (void *cls, | 485 | handle_bobs_cryptodata_message (void *cls, |
504 | struct GNUNET_CADET_Channel *channel, | 486 | const struct EccBobCryptodataMessage *msg) |
505 | void **channel_ctx, | ||
506 | const struct GNUNET_MessageHeader *message) | ||
507 | { | 487 | { |
508 | struct AliceServiceSession *s = *channel_ctx; | 488 | struct AliceServiceSession *s = cls; |
509 | const struct EccBobCryptodataMessage *msg; | ||
510 | uint32_t contained; | ||
511 | uint16_t msg_size; | ||
512 | gcry_mpi_point_t prod_g_i_b_i; | 489 | gcry_mpi_point_t prod_g_i_b_i; |
513 | gcry_mpi_point_t prod_h_i_b_i; | 490 | gcry_mpi_point_t prod_h_i_b_i; |
491 | uint32_t contained; | ||
514 | 492 | ||
515 | if (NULL == s) | ||
516 | { | ||
517 | GNUNET_break_op (0); | ||
518 | return GNUNET_SYSERR; | ||
519 | } | ||
520 | msg_size = ntohs (message->size); | ||
521 | if (sizeof (struct EccBobCryptodataMessage) > msg_size) | ||
522 | { | ||
523 | GNUNET_break_op (0); | ||
524 | return GNUNET_SYSERR; | ||
525 | } | ||
526 | msg = (const struct EccBobCryptodataMessage *) message; | ||
527 | contained = ntohl (msg->contained_element_count); | 493 | contained = ntohl (msg->contained_element_count); |
528 | if (2 != contained) | 494 | if (2 != contained) |
529 | { | 495 | { |
530 | GNUNET_break_op (0); | 496 | GNUNET_break_op (0); |
531 | return GNUNET_SYSERR; | 497 | destroy_service_session (s); |
498 | return; | ||
532 | } | 499 | } |
533 | if (NULL == s->sorted_elements) | 500 | if (NULL == s->sorted_elements) |
534 | { | 501 | { |
535 | /* we're not ready yet, how can Bob be? */ | 502 | /* we're not ready yet, how can Bob be? */ |
536 | GNUNET_break_op (0); | 503 | GNUNET_break_op (0); |
537 | return GNUNET_SYSERR; | 504 | destroy_service_session (s); |
505 | return; | ||
538 | } | 506 | } |
539 | if (s->total != s->client_received_element_count) | 507 | if (s->total != s->client_received_element_count) |
540 | { | 508 | { |
541 | /* we're not ready yet, how can Bob be? */ | 509 | /* we're not ready yet, how can Bob be? */ |
542 | GNUNET_break_op (0); | 510 | GNUNET_break_op (0); |
543 | return GNUNET_SYSERR; | 511 | destroy_service_session (s); |
512 | return; | ||
544 | } | 513 | } |
514 | |||
545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 515 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
546 | "Received %u crypto values from Bob\n", | 516 | "Received %u crypto values from Bob\n", |
547 | (unsigned int) contained); | 517 | (unsigned int) contained); |
@@ -556,7 +526,6 @@ handle_bobs_cryptodata_message (void *cls, | |||
556 | gcry_mpi_point_release (prod_g_i_b_i); | 526 | gcry_mpi_point_release (prod_g_i_b_i); |
557 | gcry_mpi_point_release (prod_h_i_b_i); | 527 | gcry_mpi_point_release (prod_h_i_b_i); |
558 | transmit_client_response (s); | 528 | transmit_client_response (s); |
559 | return GNUNET_OK; | ||
560 | } | 529 | } |
561 | 530 | ||
562 | 531 | ||
@@ -636,8 +605,8 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
636 | unsigned int todo_count; | 605 | unsigned int todo_count; |
637 | 606 | ||
638 | s->sorted_elements | 607 | s->sorted_elements |
639 | = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * | 608 | = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements), |
640 | sizeof (struct MpiElement)); | 609 | struct MpiElement); |
641 | s->used_element_count = 0; | 610 | s->used_element_count = 0; |
642 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 611 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
643 | ©_element_cb, | 612 | ©_element_cb, |
@@ -843,6 +812,13 @@ cb_intersection_request_alice (void *cls, | |||
843 | static void | 812 | static void |
844 | client_request_complete_alice (struct AliceServiceSession *s) | 813 | client_request_complete_alice (struct AliceServiceSession *s) |
845 | { | 814 | { |
815 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | ||
816 | GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, | ||
817 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, | ||
818 | struct EccBobCryptodataMessage, | ||
819 | s), | ||
820 | GNUNET_MQ_handler_end () | ||
821 | }; | ||
846 | struct EccServiceRequestMessage *msg; | 822 | struct EccServiceRequestMessage *msg; |
847 | struct GNUNET_MQ_Envelope *e; | 823 | struct GNUNET_MQ_Envelope *e; |
848 | struct GNUNET_HashCode set_sid; | 824 | struct GNUNET_HashCode set_sid; |
@@ -854,18 +830,21 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
854 | "Creating new channel for session with key %s.\n", | 830 | "Creating new channel for session with key %s.\n", |
855 | GNUNET_h2s (&s->session_id)); | 831 | GNUNET_h2s (&s->session_id)); |
856 | s->channel | 832 | s->channel |
857 | = GNUNET_CADET_channel_create (my_cadet, | 833 | = GNUNET_CADET_channel_creatE (my_cadet, |
858 | s, | 834 | s, |
859 | &s->peer, | 835 | &s->peer, |
860 | &s->session_id, | 836 | &s->session_id, |
861 | GNUNET_CADET_OPTION_RELIABLE); | 837 | GNUNET_CADET_OPTION_RELIABLE, |
838 | NULL, | ||
839 | &cb_channel_destruction, | ||
840 | cadet_handlers); | ||
862 | if (NULL == s->channel) | 841 | if (NULL == s->channel) |
863 | { | 842 | { |
864 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 843 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
865 | prepare_client_end_notification (s); | 844 | prepare_client_end_notification (s); |
866 | return; | 845 | return; |
867 | } | 846 | } |
868 | s->cadet_mq = GNUNET_CADET_mq_create (s->channel); | 847 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); |
869 | s->intersection_listen | 848 | s->intersection_listen |
870 | = GNUNET_SET_listen (cfg, | 849 | = GNUNET_SET_listen (cfg, |
871 | GNUNET_SET_OPERATION_INTERSECTION, | 850 | GNUNET_SET_OPERATION_INTERSECTION, |
@@ -890,7 +869,7 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
890 | 869 | ||
891 | 870 | ||
892 | /** | 871 | /** |
893 | * We're receiving additional set data. Check if | 872 | * We're receiving additional set data. Check if |
894 | * @a msg is well-formed. | 873 | * @a msg is well-formed. |
895 | * | 874 | * |
896 | * @param cls client identification of the client | 875 | * @param cls client identification of the client |
@@ -898,7 +877,7 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
898 | * @return #GNUNET_OK if @a msg is well-formed | 877 | * @return #GNUNET_OK if @a msg is well-formed |
899 | */ | 878 | */ |
900 | static int | 879 | static int |
901 | check_alice_client_message_multipart (void *cls, | 880 | check_alice_client_message_multipart (void *cls, |
902 | const struct ComputationBobCryptodataMultipartMessage *msg) | 881 | const struct ComputationBobCryptodataMultipartMessage *msg) |
903 | { | 882 | { |
904 | struct AliceServiceSession *s = cls; | 883 | struct AliceServiceSession *s = cls; |
@@ -928,7 +907,7 @@ check_alice_client_message_multipart (void *cls, | |||
928 | * @param msg the actual message | 907 | * @param msg the actual message |
929 | */ | 908 | */ |
930 | static void | 909 | static void |
931 | handle_alice_client_message_multipart (void *cls, | 910 | handle_alice_client_message_multipart (void *cls, |
932 | const struct ComputationBobCryptodataMultipartMessage *msg) | 911 | const struct ComputationBobCryptodataMultipartMessage *msg) |
933 | { | 912 | { |
934 | struct AliceServiceSession *s = cls; | 913 | struct AliceServiceSession *s = cls; |
@@ -983,7 +962,7 @@ handle_alice_client_message_multipart (void *cls, | |||
983 | * @return #GNUNET_OK if @a msg is well-formed | 962 | * @return #GNUNET_OK if @a msg is well-formed |
984 | */ | 963 | */ |
985 | static int | 964 | static int |
986 | check_alice_client_message (void *cls, | 965 | check_alice_client_message (void *cls, |
987 | const struct AliceComputationMessage *msg) | 966 | const struct AliceComputationMessage *msg) |
988 | { | 967 | { |
989 | struct AliceServiceSession *s = cls; | 968 | struct AliceServiceSession *s = cls; |
@@ -1012,7 +991,7 @@ check_alice_client_message (void *cls, | |||
1012 | return GNUNET_OK; | 991 | return GNUNET_OK; |
1013 | } | 992 | } |
1014 | 993 | ||
1015 | 994 | ||
1016 | /** | 995 | /** |
1017 | * Handler for Alice's client request message. | 996 | * Handler for Alice's client request message. |
1018 | * We are doing request-initiation to compute a scalar product with a peer. | 997 | * We are doing request-initiation to compute a scalar product with a peer. |
@@ -1021,7 +1000,7 @@ check_alice_client_message (void *cls, | |||
1021 | * @param msg the actual message | 1000 | * @param msg the actual message |
1022 | */ | 1001 | */ |
1023 | static void | 1002 | static void |
1024 | handle_alice_client_message (void *cls, | 1003 | handle_alice_client_message (void *cls, |
1025 | const struct AliceComputationMessage *msg) | 1004 | const struct AliceComputationMessage *msg) |
1026 | { | 1005 | { |
1027 | struct AliceServiceSession *s = cls; | 1006 | struct AliceServiceSession *s = cls; |
@@ -1167,13 +1146,6 @@ run (void *cls, | |||
1167 | const struct GNUNET_CONFIGURATION_Handle *c, | 1146 | const struct GNUNET_CONFIGURATION_Handle *c, |
1168 | struct GNUNET_SERVICE_Handle *service) | 1147 | struct GNUNET_SERVICE_Handle *service) |
1169 | { | 1148 | { |
1170 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | ||
1171 | { &handle_bobs_cryptodata_message, | ||
1172 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, | ||
1173 | 0}, | ||
1174 | { NULL, 0, 0} | ||
1175 | }; | ||
1176 | |||
1177 | cfg = c; | 1149 | cfg = c; |
1178 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, | 1150 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, |
1179 | MAX_RAM); | 1151 | MAX_RAM); |
@@ -1181,10 +1153,7 @@ run (void *cls, | |||
1181 | GNUNET_CRYPTO_ecc_rnd_mpi (edc, | 1153 | GNUNET_CRYPTO_ecc_rnd_mpi (edc, |
1182 | &my_privkey, | 1154 | &my_privkey, |
1183 | &my_privkey_inv); | 1155 | &my_privkey_inv); |
1184 | my_cadet = GNUNET_CADET_connect (cfg, | 1156 | my_cadet = GNUNET_CADET_connecT (cfg); |
1185 | NULL, | ||
1186 | &cb_channel_destruction, | ||
1187 | cadet_handlers); | ||
1188 | if (NULL == my_cadet) | 1157 | if (NULL == my_cadet) |
1189 | { | 1158 | { |
1190 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1159 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1216,7 +1185,7 @@ GNUNET_SERVICE_MAIN | |||
1216 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, | 1185 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, |
1217 | struct ComputationBobCryptodataMultipartMessage, | 1186 | struct ComputationBobCryptodataMultipartMessage, |
1218 | NULL), | 1187 | NULL), |
1219 | GNUNET_MQ_handler_end ()); | 1188 | GNUNET_MQ_handler_end ()); |
1220 | 1189 | ||
1221 | 1190 | ||
1222 | /* end of gnunet-service-scalarproduct-ecc_alice.c */ | 1191 | /* end of gnunet-service-scalarproduct-ecc_alice.c */ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c index 06e30706e..26468f9e7 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013-2015 GNUnet e.V. | 3 | Copyright (C) 2013-2017 GNUnet e.V. |
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 |
@@ -59,12 +59,6 @@ struct MpiElement | |||
59 | 59 | ||
60 | 60 | ||
61 | /** | 61 | /** |
62 | * An incoming session from CADET. | ||
63 | */ | ||
64 | struct CadetIncomingSession; | ||
65 | |||
66 | |||
67 | /** | ||
68 | * A scalarproduct session which tracks an offer for a | 62 | * A scalarproduct session which tracks an offer for a |
69 | * multiplication service by a local client. | 63 | * multiplication service by a local client. |
70 | */ | 64 | */ |
@@ -72,11 +66,6 @@ struct BobServiceSession | |||
72 | { | 66 | { |
73 | 67 | ||
74 | /** | 68 | /** |
75 | * (hopefully) unique transaction ID | ||
76 | */ | ||
77 | struct GNUNET_HashCode session_id; | ||
78 | |||
79 | /** | ||
80 | * The client this request is related to. | 69 | * The client this request is related to. |
81 | */ | 70 | */ |
82 | struct GNUNET_SERVICE_Client *client; | 71 | struct GNUNET_SERVICE_Client *client; |
@@ -124,12 +113,6 @@ struct BobServiceSession | |||
124 | gcry_mpi_point_t prod_h_i_b_i; | 113 | gcry_mpi_point_t prod_h_i_b_i; |
125 | 114 | ||
126 | /** | 115 | /** |
127 | * Handle for our associated incoming CADET session, or NULL | ||
128 | * if we have not gotten one yet. | ||
129 | */ | ||
130 | struct CadetIncomingSession *cadet; | ||
131 | |||
132 | /** | ||
133 | * How many elements will be supplied in total from the client. | 116 | * How many elements will be supplied in total from the client. |
134 | */ | 117 | */ |
135 | uint32_t total; | 118 | uint32_t total; |
@@ -166,20 +149,6 @@ struct BobServiceSession | |||
166 | */ | 149 | */ |
167 | int in_destroy; | 150 | int in_destroy; |
168 | 151 | ||
169 | }; | ||
170 | |||
171 | |||
172 | /** | ||
173 | * An incoming session from CADET. | ||
174 | */ | ||
175 | struct CadetIncomingSession | ||
176 | { | ||
177 | |||
178 | /** | ||
179 | * Associated client session, or NULL. | ||
180 | */ | ||
181 | struct BobServiceSession *s; | ||
182 | |||
183 | /** | 152 | /** |
184 | * The CADET channel. | 153 | * The CADET channel. |
185 | */ | 154 | */ |
@@ -200,18 +169,6 @@ struct CadetIncomingSession | |||
200 | */ | 169 | */ |
201 | struct GNUNET_MQ_Handle *cadet_mq; | 170 | struct GNUNET_MQ_Handle *cadet_mq; |
202 | 171 | ||
203 | /** | ||
204 | * Has this CADET session been added to the map yet? | ||
205 | * #GNUNET_YES if so, in which case @e session_id is | ||
206 | * the key. | ||
207 | */ | ||
208 | int in_map; | ||
209 | |||
210 | /** | ||
211 | * Are we already in #destroy_cadet_session()? | ||
212 | */ | ||
213 | int in_destroy; | ||
214 | |||
215 | }; | 172 | }; |
216 | 173 | ||
217 | 174 | ||
@@ -221,16 +178,6 @@ struct CadetIncomingSession | |||
221 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 178 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
222 | 179 | ||
223 | /** | 180 | /** |
224 | * Map of `struct BobServiceSession`, by session keys. | ||
225 | */ | ||
226 | static struct GNUNET_CONTAINER_MultiHashMap *client_sessions; | ||
227 | |||
228 | /** | ||
229 | * Map of `struct CadetIncomingSession`, by session keys. | ||
230 | */ | ||
231 | static struct GNUNET_CONTAINER_MultiHashMap *cadet_sessions; | ||
232 | |||
233 | /** | ||
234 | * Handle to the CADET service. | 181 | * Handle to the CADET service. |
235 | */ | 182 | */ |
236 | static struct GNUNET_CADET_Handle *my_cadet; | 183 | static struct GNUNET_CADET_Handle *my_cadet; |
@@ -242,35 +189,6 @@ static struct GNUNET_CRYPTO_EccDlogContext *edc; | |||
242 | 189 | ||
243 | 190 | ||
244 | /** | 191 | /** |
245 | * Finds a not terminated client session in the respective map based on | ||
246 | * session key. | ||
247 | * | ||
248 | * @param key the session key we want to search for | ||
249 | * @return the matching session, or NULL for none | ||
250 | */ | ||
251 | static struct BobServiceSession * | ||
252 | find_matching_client_session (const struct GNUNET_HashCode *key) | ||
253 | { | ||
254 | return GNUNET_CONTAINER_multihashmap_get (client_sessions, | ||
255 | key); | ||
256 | } | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Finds a CADET session in the respective map based on session key. | ||
261 | * | ||
262 | * @param key the session key we want to search for | ||
263 | * @return the matching session, or NULL for none | ||
264 | */ | ||
265 | static struct CadetIncomingSession * | ||
266 | find_matching_cadet_session (const struct GNUNET_HashCode *key) | ||
267 | { | ||
268 | return GNUNET_CONTAINER_multihashmap_get (cadet_sessions, | ||
269 | key); | ||
270 | } | ||
271 | |||
272 | |||
273 | /** | ||
274 | * Callback used to free the elements in the map. | 192 | * Callback used to free the elements in the map. |
275 | * | 193 | * |
276 | * @param cls NULL | 194 | * @param cls NULL |
@@ -295,39 +213,20 @@ free_element_cb (void *cls, | |||
295 | * @param session the session to free elements from | 213 | * @param session the session to free elements from |
296 | */ | 214 | */ |
297 | static void | 215 | static void |
298 | destroy_cadet_session (struct CadetIncomingSession *s); | ||
299 | |||
300 | |||
301 | /** | ||
302 | * Destroy session state, we are done with it. | ||
303 | * | ||
304 | * @param session the session to free elements from | ||
305 | */ | ||
306 | static void | ||
307 | destroy_service_session (struct BobServiceSession *s) | 216 | destroy_service_session (struct BobServiceSession *s) |
308 | { | 217 | { |
309 | struct CadetIncomingSession *in; | ||
310 | unsigned int i; | 218 | unsigned int i; |
311 | 219 | ||
312 | if (GNUNET_YES == s->in_destroy) | 220 | if (GNUNET_YES == s->in_destroy) |
313 | return; | 221 | return; |
314 | s->in_destroy = GNUNET_YES; | 222 | s->in_destroy = GNUNET_YES; |
315 | if (NULL != (in = s->cadet)) | ||
316 | { | ||
317 | s->cadet = NULL; | ||
318 | destroy_cadet_session (in); | ||
319 | } | ||
320 | if (NULL != s->client) | 223 | if (NULL != s->client) |
321 | { | 224 | { |
322 | struct GNUNET_SERVICE_Client *c = s->client; | 225 | struct GNUNET_SERVICE_Client *c = s->client; |
323 | 226 | ||
324 | s->client = NULL; | 227 | s->client = NULL; |
325 | GNUNET_SERVICE_client_drop (c); | 228 | GNUNET_SERVICE_client_drop (c); |
326 | } | 229 | } |
327 | GNUNET_assert (GNUNET_YES == | ||
328 | GNUNET_CONTAINER_multihashmap_remove (client_sessions, | ||
329 | &s->session_id, | ||
330 | s)); | ||
331 | if (NULL != s->intersected_elements) | 230 | if (NULL != s->intersected_elements) |
332 | { | 231 | { |
333 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 232 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
@@ -363,48 +262,17 @@ destroy_service_session (struct BobServiceSession *s) | |||
363 | gcry_mpi_point_release (s->prod_h_i_b_i); | 262 | gcry_mpi_point_release (s->prod_h_i_b_i); |
364 | s->prod_h_i_b_i = NULL; | 263 | s->prod_h_i_b_i = NULL; |
365 | } | 264 | } |
366 | GNUNET_CADET_close_port (s->port); | 265 | if (NULL != s->port) |
367 | GNUNET_free (s); | ||
368 | } | ||
369 | |||
370 | |||
371 | /** | ||
372 | * Destroy incoming CADET session state, we are done with it. | ||
373 | * | ||
374 | * @param in the session to free elements from | ||
375 | */ | ||
376 | static void | ||
377 | destroy_cadet_session (struct CadetIncomingSession *in) | ||
378 | { | ||
379 | struct BobServiceSession *s; | ||
380 | |||
381 | if (GNUNET_YES == in->in_destroy) | ||
382 | return; | ||
383 | in->in_destroy = GNUNET_YES; | ||
384 | if (NULL != (s = in->s)) | ||
385 | { | ||
386 | in->s = NULL; | ||
387 | destroy_service_session (s); | ||
388 | } | ||
389 | if (GNUNET_YES == in->in_map) | ||
390 | { | ||
391 | GNUNET_assert (GNUNET_YES == | ||
392 | GNUNET_CONTAINER_multihashmap_remove (cadet_sessions, | ||
393 | &in->session_id, | ||
394 | in)); | ||
395 | in->in_map = GNUNET_NO; | ||
396 | } | ||
397 | if (NULL != in->cadet_mq) | ||
398 | { | 266 | { |
399 | GNUNET_MQ_destroy (in->cadet_mq); | 267 | GNUNET_CADET_close_port (s->port); |
400 | in->cadet_mq = NULL; | 268 | s->port = NULL; |
401 | } | 269 | } |
402 | if (NULL != in->channel) | 270 | if (NULL != s->channel) |
403 | { | 271 | { |
404 | GNUNET_CADET_channel_destroy (in->channel); | 272 | GNUNET_CADET_channel_destroy (s->channel); |
405 | in->channel = NULL; | 273 | s->channel = NULL; |
406 | } | 274 | } |
407 | GNUNET_free (in); | 275 | GNUNET_free (s); |
408 | } | 276 | } |
409 | 277 | ||
410 | 278 | ||
@@ -443,38 +311,28 @@ prepare_client_end_notification (struct BobServiceSession *session) | |||
443 | * | 311 | * |
444 | * It must NOT call #GNUNET_CADET_channel_destroy() on the channel. | 312 | * It must NOT call #GNUNET_CADET_channel_destroy() on the channel. |
445 | * | 313 | * |
446 | * @param cls closure (set from #GNUNET_CADET_connect()) | 314 | * @param cls the `struct BobServiceSession` |
447 | * @param channel connection to the other end (henceforth invalid) | 315 | * @param channel connection to the other end (henceforth invalid) |
448 | * @param channel_ctx place where local state associated | 316 | * @param channel_ctx place where local state associated |
449 | * with the channel is stored | 317 | * with the channel is stored |
450 | */ | 318 | */ |
451 | static void | 319 | static void |
452 | cb_channel_destruction (void *cls, | 320 | cb_channel_destruction (void *cls, |
453 | const struct GNUNET_CADET_Channel *channel, | 321 | const struct GNUNET_CADET_Channel *channel) |
454 | void *channel_ctx) | ||
455 | { | 322 | { |
456 | struct CadetIncomingSession *in = channel_ctx; | 323 | struct BobServiceSession *s = cls; |
457 | struct BobServiceSession *s; | ||
458 | 324 | ||
459 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
460 | "Peer disconnected, terminating session %s with peer %s\n", | 326 | "Peer disconnected, terminating session %s with peer %s\n", |
461 | GNUNET_h2s (&in->session_id), | 327 | GNUNET_h2s (&s->session_id), |
462 | GNUNET_i2s (&in->peer)); | 328 | GNUNET_i2s (&s->peer)); |
463 | if (NULL != in->cadet_mq) | 329 | s->channel = NULL; |
464 | { | 330 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
465 | GNUNET_MQ_destroy (in->cadet_mq); | ||
466 | in->cadet_mq = NULL; | ||
467 | } | ||
468 | in->channel = NULL; | ||
469 | if (NULL != (s = in->s)) | ||
470 | { | 331 | { |
471 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | 332 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
472 | { | 333 | prepare_client_end_notification (s); |
473 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
474 | prepare_client_end_notification (s); | ||
475 | } | ||
476 | } | 334 | } |
477 | destroy_cadet_session (in); | 335 | destroy_service_session (s); |
478 | } | 336 | } |
479 | 337 | ||
480 | 338 | ||
@@ -519,7 +377,7 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
519 | GNUNET_MQ_notify_sent (e, | 377 | GNUNET_MQ_notify_sent (e, |
520 | &bob_cadet_done_cb, | 378 | &bob_cadet_done_cb, |
521 | s); | 379 | s); |
522 | GNUNET_MQ_send (s->cadet->cadet_mq, | 380 | GNUNET_MQ_send (s->cadet_mq, |
523 | e); | 381 | e); |
524 | } | 382 | } |
525 | 383 | ||
@@ -577,56 +435,79 @@ element_cmp (const void *a, | |||
577 | 435 | ||
578 | 436 | ||
579 | /** | 437 | /** |
580 | * Handle a multipart-chunk of a request from another service to | 438 | * Check a multipart-chunk of a request from another service to |
581 | * calculate a scalarproduct with us. | 439 | * calculate a scalarproduct with us. |
582 | * | 440 | * |
583 | * @param cls closure (set from #GNUNET_CADET_connect) | 441 | * @param cls closure (set from #GNUNET_CADET_connect) |
584 | * @param channel connection to the other end | 442 | * @param msg the actual message |
585 | * @param channel_ctx place to store local state associated with the @a channel | ||
586 | * @param message the actual message | ||
587 | * @return #GNUNET_OK to keep the connection open, | 443 | * @return #GNUNET_OK to keep the connection open, |
588 | * #GNUNET_SYSERR to close it (signal serious error) | 444 | * #GNUNET_SYSERR to close it (signal serious error) |
589 | */ | 445 | */ |
590 | static int | 446 | static int |
591 | handle_alices_cryptodata_message (void *cls, | 447 | check_alices_cryptodata_message (void *cls, |
592 | struct GNUNET_CADET_Channel *channel, | 448 | const struct EccAliceCryptodataMessage *msg) |
593 | void **channel_ctx, | ||
594 | const struct GNUNET_MessageHeader *message) | ||
595 | { | 449 | { |
596 | struct CadetIncomingSession *in = *channel_ctx; | 450 | struct BobServiceSession *s = cls; |
597 | struct BobServiceSession *s; | ||
598 | const struct EccAliceCryptodataMessage *msg; | ||
599 | const struct GNUNET_CRYPTO_EccPoint *payload; | ||
600 | uint32_t contained_elements; | 451 | uint32_t contained_elements; |
601 | size_t msg_length; | 452 | size_t msg_length; |
602 | uint16_t msize; | 453 | uint16_t msize; |
603 | unsigned int max; | 454 | unsigned int max; |
604 | unsigned int i; | ||
605 | const struct MpiElement *b_i; | ||
606 | gcry_mpi_point_t tmp; | ||
607 | gcry_mpi_point_t g_i; | ||
608 | gcry_mpi_point_t h_i; | ||
609 | gcry_mpi_point_t g_i_b_i; | ||
610 | gcry_mpi_point_t h_i_b_i; | ||
611 | 455 | ||
612 | /* sanity checks */ | 456 | msize = ntohs (msg->header.size); |
613 | if (NULL == in) | 457 | if (msize <= sizeof (struct EccAliceCryptodataMessage)) |
614 | { | 458 | { |
615 | GNUNET_break_op (0); | 459 | GNUNET_break_op (0); |
616 | return GNUNET_SYSERR; | 460 | return GNUNET_SYSERR; |
617 | } | 461 | } |
618 | s = in->s; | 462 | contained_elements = ntohl (msg->contained_element_count); |
619 | if (NULL == s) | 463 | /* Our intersection may still be ongoing, but this is nevertheless |
464 | an upper bound on the required array size */ | ||
465 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); | ||
466 | msg_length = sizeof (struct EccAliceCryptodataMessage) | ||
467 | + contained_elements * sizeof (struct GNUNET_CRYPTO_EccPoint) * 2; | ||
468 | if ( (msize != msg_length) || | ||
469 | (0 == contained_elements) || | ||
470 | (contained_elements > UINT16_MAX) || | ||
471 | (max < contained_elements + s->cadet_received_element_count) ) | ||
620 | { | 472 | { |
621 | GNUNET_break_op (0); | 473 | GNUNET_break_op (0); |
622 | return GNUNET_SYSERR; | 474 | return GNUNET_SYSERR; |
623 | } | 475 | } |
476 | return GNUNET_OK; | ||
477 | } | ||
478 | |||
479 | |||
480 | /** | ||
481 | * Handle a multipart-chunk of a request from another service to | ||
482 | * calculate a scalarproduct with us. | ||
483 | * | ||
484 | * @param cls closure (set from #GNUNET_CADET_connect) | ||
485 | * @param msg the actual message | ||
486 | */ | ||
487 | static void | ||
488 | handle_alices_cryptodata_message (void *cls, | ||
489 | const struct EccAliceCryptodataMessage *msg) | ||
490 | { | ||
491 | struct BobServiceSession *s = cls; | ||
492 | const struct GNUNET_CRYPTO_EccPoint *payload; | ||
493 | uint32_t contained_elements; | ||
494 | unsigned int max; | ||
495 | unsigned int i; | ||
496 | const struct MpiElement *b_i; | ||
497 | gcry_mpi_point_t tmp; | ||
498 | gcry_mpi_point_t g_i; | ||
499 | gcry_mpi_point_t h_i; | ||
500 | gcry_mpi_point_t g_i_b_i; | ||
501 | gcry_mpi_point_t h_i_b_i; | ||
502 | |||
503 | contained_elements = ntohl (msg->contained_element_count); | ||
504 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); | ||
624 | /* sort our vector for the computation */ | 505 | /* sort our vector for the computation */ |
625 | if (NULL == s->sorted_elements) | 506 | if (NULL == s->sorted_elements) |
626 | { | 507 | { |
627 | s->sorted_elements | 508 | s->sorted_elements |
628 | = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * | 509 | = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements), |
629 | sizeof (struct MpiElement)); | 510 | struct MpiElement); |
630 | s->used_element_count = 0; | 511 | s->used_element_count = 0; |
631 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 512 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
632 | ©_element_cb, | 513 | ©_element_cb, |
@@ -637,28 +518,6 @@ handle_alices_cryptodata_message (void *cls, | |||
637 | &element_cmp); | 518 | &element_cmp); |
638 | } | 519 | } |
639 | 520 | ||
640 | /* parse message */ | ||
641 | msize = ntohs (message->size); | ||
642 | if (msize <= sizeof (struct EccAliceCryptodataMessage)) | ||
643 | { | ||
644 | GNUNET_break_op (0); | ||
645 | return GNUNET_SYSERR; | ||
646 | } | ||
647 | msg = (const struct EccAliceCryptodataMessage *) message; | ||
648 | contained_elements = ntohl (msg->contained_element_count); | ||
649 | /* Our intersection may still be ongoing, but this is nevertheless | ||
650 | an upper bound on the required array size */ | ||
651 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); | ||
652 | msg_length = sizeof (struct EccAliceCryptodataMessage) | ||
653 | + contained_elements * sizeof (struct GNUNET_CRYPTO_EccPoint) * 2; | ||
654 | if ( (msize != msg_length) || | ||
655 | (0 == contained_elements) || | ||
656 | (contained_elements > UINT16_MAX) || | ||
657 | (max < contained_elements + s->cadet_received_element_count) ) | ||
658 | { | ||
659 | GNUNET_break_op (0); | ||
660 | return GNUNET_SYSERR; | ||
661 | } | ||
662 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
663 | "Received %u crypto values from Alice\n", | 522 | "Received %u crypto values from Alice\n", |
664 | (unsigned int) contained_elements); | 523 | (unsigned int) contained_elements); |
@@ -711,8 +570,7 @@ handle_alices_cryptodata_message (void *cls, | |||
711 | CADET response(s) */ | 570 | CADET response(s) */ |
712 | transmit_bobs_cryptodata_message (s); | 571 | transmit_bobs_cryptodata_message (s); |
713 | } | 572 | } |
714 | GNUNET_CADET_receive_done (s->cadet->channel); | 573 | GNUNET_CADET_receive_done (s->channel); |
715 | return GNUNET_OK; | ||
716 | } | 574 | } |
717 | 575 | ||
718 | 576 | ||
@@ -752,7 +610,7 @@ cb_intersection_element_removed (void *cls, | |||
752 | case GNUNET_SET_STATUS_DONE: | 610 | case GNUNET_SET_STATUS_DONE: |
753 | s->intersection_op = NULL; | 611 | s->intersection_op = NULL; |
754 | GNUNET_break (NULL == s->intersection_set); | 612 | GNUNET_break (NULL == s->intersection_set); |
755 | GNUNET_CADET_receive_done (s->cadet->channel); | 613 | GNUNET_CADET_receive_done (s->channel); |
756 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 614 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
757 | "Finished intersection, %d items remain\n", | 615 | "Finished intersection, %d items remain\n", |
758 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); | 616 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); |
@@ -808,7 +666,7 @@ start_intersection (struct BobServiceSession *s) | |||
808 | (unsigned int) s->total); | 666 | (unsigned int) s->total); |
809 | 667 | ||
810 | s->intersection_op | 668 | s->intersection_op |
811 | = GNUNET_SET_prepare (&s->cadet->peer, | 669 | = GNUNET_SET_prepare (&s->peer, |
812 | &set_sid, | 670 | &set_sid, |
813 | NULL, | 671 | NULL, |
814 | GNUNET_SET_RESULT_REMOVED, | 672 | GNUNET_SET_RESULT_REMOVED, |
@@ -832,53 +690,17 @@ start_intersection (struct BobServiceSession *s) | |||
832 | * Handle a request from Alice to calculate a scalarproduct with us (Bob). | 690 | * Handle a request from Alice to calculate a scalarproduct with us (Bob). |
833 | * | 691 | * |
834 | * @param cls closure (set from #GNUNET_CADET_connect) | 692 | * @param cls closure (set from #GNUNET_CADET_connect) |
835 | * @param channel connection to the other end | 693 | * @param msg the actual message |
836 | * @param channel_ctx place to store the `struct CadetIncomingSession *` | ||
837 | * @param message the actual message | ||
838 | * @return #GNUNET_OK to keep the connection open, | ||
839 | * #GNUNET_SYSERR to close it (signal serious error) | ||
840 | */ | 694 | */ |
841 | static int | 695 | static void |
842 | handle_alices_computation_request (void *cls, | 696 | handle_alices_computation_request (void *cls, |
843 | struct GNUNET_CADET_Channel *channel, | 697 | const struct EccServiceRequestMessage *msg) |
844 | void **channel_ctx, | ||
845 | const struct GNUNET_MessageHeader *message) | ||
846 | { | 698 | { |
847 | struct CadetIncomingSession *in = *channel_ctx; | 699 | struct BobServiceSession *s = cls; |
848 | struct BobServiceSession *s; | ||
849 | const struct EccServiceRequestMessage *msg; | ||
850 | 700 | ||
851 | msg = (const struct EccServiceRequestMessage *) message; | 701 | s->session_id = msg->session_id; // ?? |
852 | if (GNUNET_YES == in->in_map) | ||
853 | { | ||
854 | GNUNET_break_op (0); | ||
855 | return GNUNET_SYSERR; | ||
856 | } | ||
857 | if (NULL != find_matching_cadet_session (&msg->session_id)) | ||
858 | { | ||
859 | /* not unique, got one like this already */ | ||
860 | GNUNET_break_op (0); | ||
861 | return GNUNET_SYSERR; | ||
862 | } | ||
863 | in->session_id = msg->session_id; | ||
864 | GNUNET_assert (GNUNET_YES == | ||
865 | GNUNET_CONTAINER_multihashmap_put (cadet_sessions, | ||
866 | &in->session_id, | ||
867 | in, | ||
868 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
869 | s = find_matching_client_session (&in->session_id); | ||
870 | if (NULL == s) | ||
871 | { | ||
872 | /* no client waiting for this request, wait for client */ | ||
873 | return GNUNET_OK; | ||
874 | } | ||
875 | GNUNET_assert (NULL == s->cadet); | ||
876 | /* pair them up */ | ||
877 | in->s = s; | ||
878 | s->cadet = in; | ||
879 | if (s->client_received_element_count == s->total) | 702 | if (s->client_received_element_count == s->total) |
880 | start_intersection (s); | 703 | start_intersection (s); |
881 | return GNUNET_OK; | ||
882 | } | 704 | } |
883 | 705 | ||
884 | 706 | ||
@@ -887,30 +709,27 @@ handle_alices_computation_request (void *cls, | |||
887 | * preliminary initialization, more happens after we get Alice's first | 709 | * preliminary initialization, more happens after we get Alice's first |
888 | * message. | 710 | * message. |
889 | * | 711 | * |
890 | * @param cls closure | 712 | * @param cls our `struct BobServiceSession` |
891 | * @param channel new handle to the channel | 713 | * @param channel new handle to the channel |
892 | * @param initiator peer that started the channel | 714 | * @param initiator peer that started the channel |
893 | * @param port unused | ||
894 | * @param options unused | ||
895 | * @return session associated with the channel | 715 | * @return session associated with the channel |
896 | */ | 716 | */ |
897 | static void * | 717 | static void * |
898 | cb_channel_incoming (void *cls, | 718 | cb_channel_incoming (void *cls, |
899 | struct GNUNET_CADET_Channel *channel, | 719 | struct GNUNET_CADET_Channel *channel, |
900 | const struct GNUNET_PeerIdentity *initiator, | 720 | const struct GNUNET_PeerIdentity *initiator) |
901 | const struct GNUNET_HashCode *port, | ||
902 | enum GNUNET_CADET_ChannelOption options) | ||
903 | { | 721 | { |
904 | struct CadetIncomingSession *in; | 722 | struct BobServiceSession *s = cls; |
905 | 723 | ||
906 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 724 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
907 | "New incoming channel from peer %s.\n", | 725 | "New incoming channel from peer %s.\n", |
908 | GNUNET_i2s (initiator)); | 726 | GNUNET_i2s (initiator)); |
909 | in = GNUNET_new (struct CadetIncomingSession); | 727 | GNUNET_CADET_close_port (s->port); |
910 | in->peer = *initiator; | 728 | s->port = NULL; |
911 | in->channel = channel; | 729 | s->peer = *initiator; |
912 | in->cadet_mq = GNUNET_CADET_mq_create (in->channel); | 730 | s->channel = channel; |
913 | return in; | 731 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); |
732 | return s; | ||
914 | } | 733 | } |
915 | 734 | ||
916 | 735 | ||
@@ -994,7 +813,7 @@ handle_bob_client_message_multipart (void *cls, | |||
994 | /* more to come */ | 813 | /* more to come */ |
995 | return; | 814 | return; |
996 | } | 815 | } |
997 | if (NULL == s->cadet) | 816 | if (NULL == s->channel) |
998 | { | 817 | { |
999 | /* no Alice waiting for this request, wait for Alice */ | 818 | /* no Alice waiting for this request, wait for Alice */ |
1000 | return; | 819 | return; |
@@ -1037,11 +856,6 @@ check_bob_client_message (void *cls, | |||
1037 | GNUNET_break_op (0); | 856 | GNUNET_break_op (0); |
1038 | return GNUNET_SYSERR; | 857 | return GNUNET_SYSERR; |
1039 | } | 858 | } |
1040 | if (NULL != find_matching_client_session (&msg->session_key)) | ||
1041 | { | ||
1042 | GNUNET_break (0); | ||
1043 | return GNUNET_SYSERR; | ||
1044 | } | ||
1045 | return GNUNET_OK; | 859 | return GNUNET_OK; |
1046 | } | 860 | } |
1047 | 861 | ||
@@ -1059,7 +873,17 @@ handle_bob_client_message (void *cls, | |||
1059 | const struct BobComputationMessage *msg) | 873 | const struct BobComputationMessage *msg) |
1060 | { | 874 | { |
1061 | struct BobServiceSession *s = cls; | 875 | struct BobServiceSession *s = cls; |
1062 | struct CadetIncomingSession *in; | 876 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
877 | GNUNET_MQ_hd_fixed_size (alices_computation_request, | ||
878 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION, | ||
879 | struct EccServiceRequestMessage, | ||
880 | s), | ||
881 | GNUNET_MQ_hd_var_size (alices_cryptodata_message, | ||
882 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA, | ||
883 | struct EccAliceCryptodataMessage, | ||
884 | s), | ||
885 | GNUNET_MQ_handler_end () | ||
886 | }; | ||
1063 | uint32_t contained_count; | 887 | uint32_t contained_count; |
1064 | uint32_t total_count; | 888 | uint32_t total_count; |
1065 | const struct GNUNET_SCALARPRODUCT_Element *elements; | 889 | const struct GNUNET_SCALARPRODUCT_Element *elements; |
@@ -1073,21 +897,6 @@ handle_bob_client_message (void *cls, | |||
1073 | s->total = total_count; | 897 | s->total = total_count; |
1074 | s->client_received_element_count = contained_count; | 898 | s->client_received_element_count = contained_count; |
1075 | s->session_id = msg->session_key; | 899 | s->session_id = msg->session_key; |
1076 | s->port = GNUNET_CADET_open_port (my_cadet, | ||
1077 | &msg->session_key, | ||
1078 | &cb_channel_incoming, | ||
1079 | s); | ||
1080 | if (NULL == s->port) | ||
1081 | { | ||
1082 | GNUNET_break (0); | ||
1083 | GNUNET_SERVICE_client_drop (s->client); | ||
1084 | return; | ||
1085 | } | ||
1086 | GNUNET_break (GNUNET_YES == | ||
1087 | GNUNET_CONTAINER_multihashmap_put (client_sessions, | ||
1088 | &s->session_id, | ||
1089 | s, | ||
1090 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1091 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 900 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
1092 | s->intersected_elements | 901 | s->intersected_elements |
1093 | = GNUNET_CONTAINER_multihashmap_create (s->total, | 902 | = GNUNET_CONTAINER_multihashmap_create (s->total, |
@@ -1122,22 +931,19 @@ handle_bob_client_message (void *cls, | |||
1122 | s->used_element_count++; | 931 | s->used_element_count++; |
1123 | } | 932 | } |
1124 | GNUNET_SERVICE_client_continue (s->client); | 933 | GNUNET_SERVICE_client_continue (s->client); |
1125 | if (s->total != s->client_received_element_count) | 934 | s->port = GNUNET_CADET_open_porT (my_cadet, |
1126 | { | 935 | &msg->session_key, |
1127 | /* multipart msg */ | 936 | &cb_channel_incoming, |
1128 | return; | 937 | s, |
1129 | } | 938 | NULL, |
1130 | in = find_matching_cadet_session (&s->session_id); | 939 | &cb_channel_destruction, |
1131 | if (NULL == in) | 940 | cadet_handlers); |
941 | if (NULL == s->port) | ||
1132 | { | 942 | { |
1133 | /* nothing yet, wait for Alice */ | 943 | GNUNET_break (0); |
944 | GNUNET_SERVICE_client_drop (s->client); | ||
1134 | return; | 945 | return; |
1135 | } | 946 | } |
1136 | GNUNET_assert (NULL == in->s); | ||
1137 | /* pair them up */ | ||
1138 | in->s = s; | ||
1139 | s->cadet = in; | ||
1140 | start_intersection (s); | ||
1141 | } | 947 | } |
1142 | 948 | ||
1143 | 949 | ||
@@ -1162,10 +968,6 @@ shutdown_task (void *cls) | |||
1162 | GNUNET_CRYPTO_ecc_dlog_release (edc); | 968 | GNUNET_CRYPTO_ecc_dlog_release (edc); |
1163 | edc = NULL; | 969 | edc = NULL; |
1164 | } | 970 | } |
1165 | GNUNET_CONTAINER_multihashmap_destroy (client_sessions); | ||
1166 | client_sessions = NULL; | ||
1167 | GNUNET_CONTAINER_multihashmap_destroy (cadet_sessions); | ||
1168 | cadet_sessions = NULL; | ||
1169 | } | 971 | } |
1170 | 972 | ||
1171 | 973 | ||
@@ -1229,28 +1031,11 @@ run (void *cls, | |||
1229 | const struct GNUNET_CONFIGURATION_Handle *c, | 1031 | const struct GNUNET_CONFIGURATION_Handle *c, |
1230 | struct GNUNET_SERVICE_Handle *service) | 1032 | struct GNUNET_SERVICE_Handle *service) |
1231 | { | 1033 | { |
1232 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | ||
1233 | { &handle_alices_computation_request, | ||
1234 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION, | ||
1235 | sizeof (struct EccServiceRequestMessage) }, | ||
1236 | { &handle_alices_cryptodata_message, | ||
1237 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA, | ||
1238 | 0}, | ||
1239 | { NULL, 0, 0} | ||
1240 | }; | ||
1241 | |||
1242 | cfg = c; | 1034 | cfg = c; |
1243 | /* We don't really do DLOG, so we can setup with very minimal resources */ | 1035 | /* We don't really do DLOG, so we can setup with very minimal resources */ |
1244 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (4 /* max value */, | 1036 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (4 /* max value */, |
1245 | 2 /* RAM */); | 1037 | 2 /* RAM */); |
1246 | client_sessions = GNUNET_CONTAINER_multihashmap_create (128, | 1038 | my_cadet = GNUNET_CADET_connecT (cfg); |
1247 | GNUNET_YES); | ||
1248 | cadet_sessions = GNUNET_CONTAINER_multihashmap_create (128, | ||
1249 | GNUNET_YES); | ||
1250 | my_cadet = GNUNET_CADET_connect (cfg, | ||
1251 | NULL, | ||
1252 | &cb_channel_destruction, | ||
1253 | cadet_handlers); | ||
1254 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 1039 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1255 | NULL); | 1040 | NULL); |
1256 | if (NULL == my_cadet) | 1041 | if (NULL == my_cadet) |
@@ -1277,10 +1062,10 @@ GNUNET_SERVICE_MAIN | |||
1277 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, | 1062 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, |
1278 | struct BobComputationMessage, | 1063 | struct BobComputationMessage, |
1279 | NULL), | 1064 | NULL), |
1280 | GNUNET_MQ_hd_var_size (bob_client_message_multipart, | 1065 | GNUNET_MQ_hd_var_size (bob_client_message_multipart, |
1281 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, | 1066 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, |
1282 | struct ComputationBobCryptodataMultipartMessage, | 1067 | struct ComputationBobCryptodataMultipartMessage, |
1283 | NULL), | 1068 | NULL), |
1284 | GNUNET_MQ_handler_end ()); | 1069 | GNUNET_MQ_handler_end ()); |
1285 | 1070 | ||
1286 | 1071 | ||
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c index 45d1f4e2c..779d84b60 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013, 2014 GNUnet e.V. | 3 | Copyright (C) 2013, 2014, 2017 GNUnet e.V. |
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 |
@@ -248,15 +248,10 @@ destroy_service_session (struct AliceServiceSession *s) | |||
248 | if (GNUNET_YES == s->in_destroy) | 248 | if (GNUNET_YES == s->in_destroy) |
249 | return; | 249 | return; |
250 | s->in_destroy = GNUNET_YES; | 250 | s->in_destroy = GNUNET_YES; |
251 | if (NULL != s->cadet_mq) | ||
252 | { | ||
253 | GNUNET_MQ_destroy (s->cadet_mq); | ||
254 | s->cadet_mq = NULL; | ||
255 | } | ||
256 | if (NULL != s->client) | 251 | if (NULL != s->client) |
257 | { | 252 | { |
258 | struct GNUNET_SERVICE_Client *c = s->client; | 253 | struct GNUNET_SERVICE_Client *c = s->client; |
259 | 254 | ||
260 | s->client = NULL; | 255 | s->client = NULL; |
261 | GNUNET_SERVICE_client_drop (c); | 256 | GNUNET_SERVICE_client_drop (c); |
262 | } | 257 | } |
@@ -428,17 +423,14 @@ transmit_client_response (struct AliceServiceSession *s) | |||
428 | * | 423 | * |
429 | * It must NOT call #GNUNET_CADET_channel_destroy() on the channel. | 424 | * It must NOT call #GNUNET_CADET_channel_destroy() on the channel. |
430 | * | 425 | * |
431 | * @param cls closure (set from #GNUNET_CADET_connect()) | 426 | * @param cls our `struct AliceServiceSession` |
432 | * @param channel connection to the other end (henceforth invalid) | 427 | * @param channel connection to the other end (henceforth invalid) |
433 | * @param channel_ctx place where local state associated | ||
434 | * with the channel is stored | ||
435 | */ | 428 | */ |
436 | static void | 429 | static void |
437 | cb_channel_destruction (void *cls, | 430 | cb_channel_destruction (void *cls, |
438 | const struct GNUNET_CADET_Channel *channel, | 431 | const struct GNUNET_CADET_Channel *channel) |
439 | void *channel_ctx) | ||
440 | { | 432 | { |
441 | struct AliceServiceSession *s = channel_ctx; | 433 | struct AliceServiceSession *s = cls; |
442 | 434 | ||
443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
444 | "Peer disconnected, terminating session %s with peer %s\n", | 436 | "Peer disconnected, terminating session %s with peer %s\n", |
@@ -450,11 +442,6 @@ cb_channel_destruction (void *cls, | |||
450 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 442 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
451 | prepare_client_end_notification (s); | 443 | prepare_client_end_notification (s); |
452 | } | 444 | } |
453 | if (NULL != s->cadet_mq) | ||
454 | { | ||
455 | GNUNET_MQ_destroy (s->cadet_mq); | ||
456 | s->cadet_mq = NULL; | ||
457 | } | ||
458 | s->channel = NULL; | 445 | s->channel = NULL; |
459 | } | 446 | } |
460 | 447 | ||
@@ -633,42 +620,24 @@ compute_scalar_product (struct AliceServiceSession *session) | |||
633 | 620 | ||
634 | 621 | ||
635 | /** | 622 | /** |
636 | * Handle a multipart chunk of a response we got from another service | 623 | * Check a multipart chunk of a response we got from another service |
637 | * we wanted to calculate a scalarproduct with. | 624 | * we wanted to calculate a scalarproduct with. |
638 | * | 625 | * |
639 | * @param cls closure (set from #GNUNET_CADET_connect) | 626 | * @param cls the `struct AliceServiceSession` |
640 | * @param channel connection to the other end | 627 | * @param msg the actual message |
641 | * @param channel_ctx place to store local state associated with the @a channel | ||
642 | * @param message the actual message | ||
643 | * @return #GNUNET_OK to keep the connection open, | 628 | * @return #GNUNET_OK to keep the connection open, |
644 | * #GNUNET_SYSERR to close it (signal serious error) | 629 | * #GNUNET_SYSERR to close it (signal serious error) |
645 | */ | 630 | */ |
646 | static int | 631 | static int |
647 | handle_bobs_cryptodata_multipart (void *cls, | 632 | check_bobs_cryptodata_multipart (void *cls, |
648 | struct GNUNET_CADET_Channel *channel, | 633 | const struct BobCryptodataMultipartMessage *msg) |
649 | void **channel_ctx, | ||
650 | const struct GNUNET_MessageHeader *message) | ||
651 | { | 634 | { |
652 | struct AliceServiceSession *s = *channel_ctx; | 635 | struct AliceServiceSession *s = cls; |
653 | const struct BobCryptodataMultipartMessage *msg; | ||
654 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; | ||
655 | size_t i; | ||
656 | uint32_t contained; | 636 | uint32_t contained; |
657 | size_t msg_size; | 637 | size_t msg_size; |
658 | size_t required_size; | 638 | size_t required_size; |
659 | 639 | ||
660 | if (NULL == s) | 640 | msg_size = ntohs (msg->header.size); |
661 | { | ||
662 | GNUNET_break_op (0); | ||
663 | return GNUNET_SYSERR; | ||
664 | } | ||
665 | msg_size = ntohs (message->size); | ||
666 | if (sizeof (struct BobCryptodataMultipartMessage) > msg_size) | ||
667 | { | ||
668 | GNUNET_break_op (0); | ||
669 | return GNUNET_SYSERR; | ||
670 | } | ||
671 | msg = (const struct BobCryptodataMultipartMessage *) message; | ||
672 | contained = ntohl (msg->contained_element_count); | 641 | contained = ntohl (msg->contained_element_count); |
673 | required_size = sizeof (struct BobCryptodataMultipartMessage) | 642 | required_size = sizeof (struct BobCryptodataMultipartMessage) |
674 | + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 643 | + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); |
@@ -678,7 +647,26 @@ handle_bobs_cryptodata_multipart (void *cls, | |||
678 | GNUNET_break (0); | 647 | GNUNET_break (0); |
679 | return GNUNET_SYSERR; | 648 | return GNUNET_SYSERR; |
680 | } | 649 | } |
650 | return GNUNET_OK; | ||
651 | } | ||
681 | 652 | ||
653 | /** | ||
654 | * Handle a multipart chunk of a response we got from another service | ||
655 | * we wanted to calculate a scalarproduct with. | ||
656 | * | ||
657 | * @param cls the `struct AliceServiceSession` | ||
658 | * @param msg the actual message | ||
659 | */ | ||
660 | static void | ||
661 | handle_bobs_cryptodata_multipart (void *cls, | ||
662 | const struct BobCryptodataMultipartMessage *msg) | ||
663 | { | ||
664 | struct AliceServiceSession *s = cls; | ||
665 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; | ||
666 | size_t i; | ||
667 | uint32_t contained; | ||
668 | |||
669 | contained = ntohl (msg->contained_element_count); | ||
682 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 670 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
683 | "Received %u additional crypto values from Bob\n", | 671 | "Received %u additional crypto values from Bob\n", |
684 | (unsigned int) contained); | 672 | (unsigned int) contained); |
@@ -688,60 +676,41 @@ handle_bobs_cryptodata_multipart (void *cls, | |||
688 | for (i = 0; i < contained; i++) | 676 | for (i = 0; i < contained; i++) |
689 | { | 677 | { |
690 | GNUNET_memcpy (&s->r[s->cadet_received_element_count + i], | 678 | GNUNET_memcpy (&s->r[s->cadet_received_element_count + i], |
691 | &payload[2 * i], | 679 | &payload[2 * i], |
692 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 680 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
693 | GNUNET_memcpy (&s->r_prime[s->cadet_received_element_count + i], | 681 | GNUNET_memcpy (&s->r_prime[s->cadet_received_element_count + i], |
694 | &payload[2 * i], | 682 | &payload[2 * i], |
695 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 683 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
696 | } | 684 | } |
697 | s->cadet_received_element_count += contained; | 685 | s->cadet_received_element_count += contained; |
698 | GNUNET_CADET_receive_done (s->channel); | 686 | GNUNET_CADET_receive_done (s->channel); |
699 | if (s->cadet_received_element_count != s->used_element_count) | 687 | if (s->cadet_received_element_count != s->used_element_count) |
700 | return GNUNET_OK; | 688 | return; /* more to come */ |
701 | 689 | ||
702 | s->product = compute_scalar_product (s); | 690 | s->product = compute_scalar_product (s); |
703 | transmit_client_response (s); | 691 | transmit_client_response (s); |
704 | return GNUNET_OK; | ||
705 | } | 692 | } |
706 | 693 | ||
707 | 694 | ||
708 | /** | 695 | /** |
709 | * Handle a response we got from another service we wanted to | 696 | * Check a response we got from another service we wanted to |
710 | * calculate a scalarproduct with. | 697 | * calculate a scalarproduct with. |
711 | * | 698 | * |
712 | * @param cls closure (set from #GNUNET_CADET_connect) | 699 | * @param cls our `struct AliceServiceSession` |
713 | * @param channel connection to the other end | ||
714 | * @param channel_ctx place to store local state associated with the channel | ||
715 | * @param message the actual message | 700 | * @param message the actual message |
716 | * @return #GNUNET_OK to keep the connection open, | 701 | * @return #GNUNET_OK to keep the connection open, |
717 | * #GNUNET_SYSERR to close it (we are done) | 702 | * #GNUNET_SYSERR to close it (we are done) |
718 | */ | 703 | */ |
719 | static int | 704 | static int |
720 | handle_bobs_cryptodata_message (void *cls, | 705 | check_bobs_cryptodata_message (void *cls, |
721 | struct GNUNET_CADET_Channel *channel, | 706 | const struct BobCryptodataMessage *msg) |
722 | void **channel_ctx, | ||
723 | const struct GNUNET_MessageHeader *message) | ||
724 | { | 707 | { |
725 | struct AliceServiceSession *s = *channel_ctx; | 708 | struct AliceServiceSession *s = cls; |
726 | const struct BobCryptodataMessage *msg; | ||
727 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; | ||
728 | uint32_t i; | ||
729 | uint32_t contained; | 709 | uint32_t contained; |
730 | uint16_t msg_size; | 710 | uint16_t msg_size; |
731 | size_t required_size; | 711 | size_t required_size; |
732 | 712 | ||
733 | if (NULL == s) | 713 | msg_size = ntohs (msg->header.size); |
734 | { | ||
735 | GNUNET_break_op (0); | ||
736 | return GNUNET_SYSERR; | ||
737 | } | ||
738 | msg_size = ntohs (message->size); | ||
739 | if (sizeof (struct BobCryptodataMessage) > msg_size) | ||
740 | { | ||
741 | GNUNET_break_op (0); | ||
742 | return GNUNET_SYSERR; | ||
743 | } | ||
744 | msg = (const struct BobCryptodataMessage *) message; | ||
745 | contained = ntohl (msg->contained_element_count); | 714 | contained = ntohl (msg->contained_element_count); |
746 | required_size = sizeof (struct BobCryptodataMessage) | 715 | required_size = sizeof (struct BobCryptodataMessage) |
747 | + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) | 716 | + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) |
@@ -765,29 +734,51 @@ handle_bobs_cryptodata_message (void *cls, | |||
765 | GNUNET_break_op (0); | 734 | GNUNET_break_op (0); |
766 | return GNUNET_SYSERR; | 735 | return GNUNET_SYSERR; |
767 | } | 736 | } |
737 | return GNUNET_OK; | ||
738 | } | ||
739 | |||
740 | |||
741 | /** | ||
742 | * Handle a response we got from another service we wanted to | ||
743 | * calculate a scalarproduct with. | ||
744 | * | ||
745 | * @param cls our `struct AliceServiceSession` | ||
746 | * @param msg the actual message | ||
747 | */ | ||
748 | static void | ||
749 | handle_bobs_cryptodata_message (void *cls, | ||
750 | const struct BobCryptodataMessage *msg) | ||
751 | { | ||
752 | struct AliceServiceSession *s = cls; | ||
753 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; | ||
754 | uint32_t i; | ||
755 | uint32_t contained; | ||
756 | |||
757 | contained = ntohl (msg->contained_element_count); | ||
768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
769 | "Received %u crypto values from Bob\n", | 759 | "Received %u crypto values from Bob\n", |
770 | (unsigned int) contained); | 760 | (unsigned int) contained); |
771 | |||
772 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 761 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
773 | GNUNET_memcpy (&s->s, | 762 | GNUNET_memcpy (&s->s, |
774 | &payload[0], | 763 | &payload[0], |
775 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 764 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
776 | GNUNET_memcpy (&s->s_prime, | 765 | GNUNET_memcpy (&s->s_prime, |
777 | &payload[1], | 766 | &payload[1], |
778 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 767 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
779 | payload = &payload[2]; | 768 | payload = &payload[2]; |
780 | 769 | ||
781 | s->r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count); | 770 | s->r = GNUNET_new_array (s->used_element_count, |
782 | s->r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count); | 771 | struct GNUNET_CRYPTO_PaillierCiphertext); |
772 | s->r_prime = GNUNET_new_array (s->used_element_count, | ||
773 | struct GNUNET_CRYPTO_PaillierCiphertext); | ||
783 | for (i = 0; i < contained; i++) | 774 | for (i = 0; i < contained; i++) |
784 | { | 775 | { |
785 | GNUNET_memcpy (&s->r[i], | 776 | GNUNET_memcpy (&s->r[i], |
786 | &payload[2 * i], | 777 | &payload[2 * i], |
787 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 778 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
788 | GNUNET_memcpy (&s->r_prime[i], | 779 | GNUNET_memcpy (&s->r_prime[i], |
789 | &payload[2 * i + 1], | 780 | &payload[2 * i + 1], |
790 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 781 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
791 | } | 782 | } |
792 | s->cadet_received_element_count = contained; | 783 | s->cadet_received_element_count = contained; |
793 | GNUNET_CADET_receive_done (s->channel); | 784 | GNUNET_CADET_receive_done (s->channel); |
@@ -795,12 +786,10 @@ handle_bobs_cryptodata_message (void *cls, | |||
795 | if (s->cadet_received_element_count != s->used_element_count) | 786 | if (s->cadet_received_element_count != s->used_element_count) |
796 | { | 787 | { |
797 | /* More to come */ | 788 | /* More to come */ |
798 | return GNUNET_OK; | 789 | return; |
799 | } | 790 | } |
800 | |||
801 | s->product = compute_scalar_product (s); | 791 | s->product = compute_scalar_product (s); |
802 | transmit_client_response (s); | 792 | transmit_client_response (s); |
803 | return GNUNET_OK; | ||
804 | } | 793 | } |
805 | 794 | ||
806 | 795 | ||
@@ -1066,6 +1055,17 @@ cb_intersection_request_alice (void *cls, | |||
1066 | static void | 1055 | static void |
1067 | client_request_complete_alice (struct AliceServiceSession *s) | 1056 | client_request_complete_alice (struct AliceServiceSession *s) |
1068 | { | 1057 | { |
1058 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | ||
1059 | GNUNET_MQ_hd_var_size (bobs_cryptodata_message, | ||
1060 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, | ||
1061 | struct BobCryptodataMessage, | ||
1062 | s), | ||
1063 | GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart, | ||
1064 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, | ||
1065 | struct BobCryptodataMultipartMessage, | ||
1066 | s), | ||
1067 | GNUNET_MQ_handler_end () | ||
1068 | }; | ||
1069 | struct ServiceRequestMessage *msg; | 1069 | struct ServiceRequestMessage *msg; |
1070 | struct GNUNET_MQ_Envelope *e; | 1070 | struct GNUNET_MQ_Envelope *e; |
1071 | 1071 | ||
@@ -1073,18 +1073,21 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
1073 | "Creating new channel for session with key %s.\n", | 1073 | "Creating new channel for session with key %s.\n", |
1074 | GNUNET_h2s (&s->session_id)); | 1074 | GNUNET_h2s (&s->session_id)); |
1075 | s->channel | 1075 | s->channel |
1076 | = GNUNET_CADET_channel_create (my_cadet, | 1076 | = GNUNET_CADET_channel_creatE (my_cadet, |
1077 | s, | 1077 | s, |
1078 | &s->peer, | 1078 | &s->peer, |
1079 | &s->session_id, | 1079 | &s->session_id, |
1080 | GNUNET_CADET_OPTION_RELIABLE); | 1080 | GNUNET_CADET_OPTION_RELIABLE, |
1081 | NULL, | ||
1082 | &cb_channel_destruction, | ||
1083 | cadet_handlers); | ||
1081 | if (NULL == s->channel) | 1084 | if (NULL == s->channel) |
1082 | { | 1085 | { |
1083 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 1086 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
1084 | prepare_client_end_notification (s); | 1087 | prepare_client_end_notification (s); |
1085 | return; | 1088 | return; |
1086 | } | 1089 | } |
1087 | s->cadet_mq = GNUNET_CADET_mq_create (s->channel); | 1090 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); |
1088 | s->intersection_listen | 1091 | s->intersection_listen |
1089 | = GNUNET_SET_listen (cfg, | 1092 | = GNUNET_SET_listen (cfg, |
1090 | GNUNET_SET_OPERATION_INTERSECTION, | 1093 | GNUNET_SET_OPERATION_INTERSECTION, |
@@ -1110,7 +1113,7 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
1110 | 1113 | ||
1111 | 1114 | ||
1112 | /** | 1115 | /** |
1113 | * We're receiving additional set data. Check if | 1116 | * We're receiving additional set data. Check if |
1114 | * @a msg is well-formed. | 1117 | * @a msg is well-formed. |
1115 | * | 1118 | * |
1116 | * @param cls client identification of the client | 1119 | * @param cls client identification of the client |
@@ -1118,7 +1121,7 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
1118 | * @return #GNUNET_OK if @a msg is well-formed | 1121 | * @return #GNUNET_OK if @a msg is well-formed |
1119 | */ | 1122 | */ |
1120 | static int | 1123 | static int |
1121 | check_alice_client_message_multipart (void *cls, | 1124 | check_alice_client_message_multipart (void *cls, |
1122 | const struct ComputationBobCryptodataMultipartMessage *msg) | 1125 | const struct ComputationBobCryptodataMultipartMessage *msg) |
1123 | { | 1126 | { |
1124 | struct AliceServiceSession *s = cls; | 1127 | struct AliceServiceSession *s = cls; |
@@ -1148,7 +1151,7 @@ check_alice_client_message_multipart (void *cls, | |||
1148 | * @param msg the actual message | 1151 | * @param msg the actual message |
1149 | */ | 1152 | */ |
1150 | static void | 1153 | static void |
1151 | handle_alice_client_message_multipart (void *cls, | 1154 | handle_alice_client_message_multipart (void *cls, |
1152 | const struct ComputationBobCryptodataMultipartMessage *msg) | 1155 | const struct ComputationBobCryptodataMultipartMessage *msg) |
1153 | { | 1156 | { |
1154 | struct AliceServiceSession *s = cls; | 1157 | struct AliceServiceSession *s = cls; |
@@ -1203,7 +1206,7 @@ handle_alice_client_message_multipart (void *cls, | |||
1203 | * @return #GNUNET_OK if @a msg is well-formed | 1206 | * @return #GNUNET_OK if @a msg is well-formed |
1204 | */ | 1207 | */ |
1205 | static int | 1208 | static int |
1206 | check_alice_client_message (void *cls, | 1209 | check_alice_client_message (void *cls, |
1207 | const struct AliceComputationMessage *msg) | 1210 | const struct AliceComputationMessage *msg) |
1208 | { | 1211 | { |
1209 | struct AliceServiceSession *s = cls; | 1212 | struct AliceServiceSession *s = cls; |
@@ -1232,7 +1235,7 @@ check_alice_client_message (void *cls, | |||
1232 | return GNUNET_OK; | 1235 | return GNUNET_OK; |
1233 | } | 1236 | } |
1234 | 1237 | ||
1235 | 1238 | ||
1236 | /** | 1239 | /** |
1237 | * Handler for Alice's client request message. | 1240 | * Handler for Alice's client request message. |
1238 | * We are doing request-initiation to compute a scalar product with a peer. | 1241 | * We are doing request-initiation to compute a scalar product with a peer. |
@@ -1241,7 +1244,7 @@ check_alice_client_message (void *cls, | |||
1241 | * @param msg the actual message | 1244 | * @param msg the actual message |
1242 | */ | 1245 | */ |
1243 | static void | 1246 | static void |
1244 | handle_alice_client_message (void *cls, | 1247 | handle_alice_client_message (void *cls, |
1245 | const struct AliceComputationMessage *msg) | 1248 | const struct AliceComputationMessage *msg) |
1246 | { | 1249 | { |
1247 | struct AliceServiceSession *s = cls; | 1250 | struct AliceServiceSession *s = cls; |
@@ -1382,16 +1385,6 @@ run (void *cls, | |||
1382 | const struct GNUNET_CONFIGURATION_Handle *c, | 1385 | const struct GNUNET_CONFIGURATION_Handle *c, |
1383 | struct GNUNET_SERVICE_Handle *service) | 1386 | struct GNUNET_SERVICE_Handle *service) |
1384 | { | 1387 | { |
1385 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | ||
1386 | { &handle_bobs_cryptodata_message, | ||
1387 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, | ||
1388 | 0}, | ||
1389 | { &handle_bobs_cryptodata_multipart, | ||
1390 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, | ||
1391 | 0}, | ||
1392 | { NULL, 0, 0} | ||
1393 | }; | ||
1394 | |||
1395 | cfg = c; | 1388 | cfg = c; |
1396 | /* | 1389 | /* |
1397 | offset has to be sufficiently small to allow computation of: | 1390 | offset has to be sufficiently small to allow computation of: |
@@ -1400,13 +1393,9 @@ run (void *cls, | |||
1400 | my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); | 1393 | my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); |
1401 | gcry_mpi_set_bit (my_offset, | 1394 | gcry_mpi_set_bit (my_offset, |
1402 | GNUNET_CRYPTO_PAILLIER_BITS / 3); | 1395 | GNUNET_CRYPTO_PAILLIER_BITS / 3); |
1403 | |||
1404 | GNUNET_CRYPTO_paillier_create (&my_pubkey, | 1396 | GNUNET_CRYPTO_paillier_create (&my_pubkey, |
1405 | &my_privkey); | 1397 | &my_privkey); |
1406 | my_cadet = GNUNET_CADET_connect (cfg, | 1398 | my_cadet = GNUNET_CADET_connecT (cfg); |
1407 | NULL, | ||
1408 | &cb_channel_destruction, | ||
1409 | cadet_handlers); | ||
1410 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 1399 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1411 | NULL); | 1400 | NULL); |
1412 | if (NULL == my_cadet) | 1401 | if (NULL == my_cadet) |
@@ -1437,7 +1426,7 @@ GNUNET_SERVICE_MAIN | |||
1437 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, | 1426 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, |
1438 | struct ComputationBobCryptodataMultipartMessage, | 1427 | struct ComputationBobCryptodataMultipartMessage, |
1439 | NULL), | 1428 | NULL), |
1440 | GNUNET_MQ_handler_end ()); | 1429 | GNUNET_MQ_handler_end ()); |
1441 | 1430 | ||
1442 | 1431 | ||
1443 | /* end of gnunet-service-scalarproduct_alice.c */ | 1432 | /* end of gnunet-service-scalarproduct_alice.c */ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c index 56cb91fe5..a2bceba43 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c | |||
@@ -59,12 +59,6 @@ struct MpiElement | |||
59 | 59 | ||
60 | 60 | ||
61 | /** | 61 | /** |
62 | * An incoming session from CADET. | ||
63 | */ | ||
64 | struct CadetIncomingSession; | ||
65 | |||
66 | |||
67 | /** | ||
68 | * A scalarproduct session which tracks an offer for a | 62 | * A scalarproduct session which tracks an offer for a |
69 | * multiplication service by a local client. | 63 | * multiplication service by a local client. |
70 | */ | 64 | */ |
@@ -187,20 +181,6 @@ struct BobServiceSession | |||
187 | */ | 181 | */ |
188 | int in_destroy; | 182 | int in_destroy; |
189 | 183 | ||
190 | }; | ||
191 | |||
192 | |||
193 | /** | ||
194 | * An incoming session from CADET. | ||
195 | */ | ||
196 | struct CadetIncomingSession | ||
197 | { | ||
198 | |||
199 | /** | ||
200 | * Associated client session, or NULL. | ||
201 | */ | ||
202 | struct BobServiceSession *s; | ||
203 | |||
204 | /** | 184 | /** |
205 | * The CADET channel. | 185 | * The CADET channel. |
206 | */ | 186 | */ |
@@ -212,11 +192,6 @@ struct CadetIncomingSession | |||
212 | struct GNUNET_PeerIdentity peer; | 192 | struct GNUNET_PeerIdentity peer; |
213 | 193 | ||
214 | /** | 194 | /** |
215 | * (hopefully) unique transaction ID | ||
216 | */ | ||
217 | struct GNUNET_HashCode session_id; | ||
218 | |||
219 | /** | ||
220 | * Public key of the remote service. | 195 | * Public key of the remote service. |
221 | */ | 196 | */ |
222 | struct GNUNET_CRYPTO_PaillierPublicKey remote_pubkey; | 197 | struct GNUNET_CRYPTO_PaillierPublicKey remote_pubkey; |
@@ -226,21 +201,10 @@ struct CadetIncomingSession | |||
226 | */ | 201 | */ |
227 | struct GNUNET_MQ_Handle *cadet_mq; | 202 | struct GNUNET_MQ_Handle *cadet_mq; |
228 | 203 | ||
229 | /** | ||
230 | * Has this CADET session been added to the map yet? | ||
231 | * #GNUNET_YES if so, in which case @e session_id is | ||
232 | * the key. | ||
233 | */ | ||
234 | int in_map; | ||
235 | |||
236 | /** | ||
237 | * Are we already in #destroy_cadet_session()? | ||
238 | */ | ||
239 | int in_destroy; | ||
240 | |||
241 | }; | 204 | }; |
242 | 205 | ||
243 | 206 | ||
207 | |||
244 | /** | 208 | /** |
245 | * GNUnet configuration handle | 209 | * GNUnet configuration handle |
246 | */ | 210 | */ |
@@ -262,51 +226,11 @@ static struct GNUNET_CRYPTO_PaillierPrivateKey my_privkey; | |||
262 | static gcry_mpi_t my_offset; | 226 | static gcry_mpi_t my_offset; |
263 | 227 | ||
264 | /** | 228 | /** |
265 | * Map of `struct BobServiceSession`, by session keys. | ||
266 | */ | ||
267 | static struct GNUNET_CONTAINER_MultiHashMap *client_sessions; | ||
268 | |||
269 | /** | ||
270 | * Map of `struct CadetIncomingSession`, by session keys. | ||
271 | */ | ||
272 | static struct GNUNET_CONTAINER_MultiHashMap *cadet_sessions; | ||
273 | |||
274 | /** | ||
275 | * Handle to the CADET service. | 229 | * Handle to the CADET service. |
276 | */ | 230 | */ |
277 | static struct GNUNET_CADET_Handle *my_cadet; | 231 | static struct GNUNET_CADET_Handle *my_cadet; |
278 | 232 | ||
279 | 233 | ||
280 | |||
281 | /** | ||
282 | * Finds a not terminated client session in the respective map based on | ||
283 | * session key. | ||
284 | * | ||
285 | * @param key the session key we want to search for | ||
286 | * @return the matching session, or NULL for none | ||
287 | */ | ||
288 | static struct BobServiceSession * | ||
289 | find_matching_client_session (const struct GNUNET_HashCode *key) | ||
290 | { | ||
291 | return GNUNET_CONTAINER_multihashmap_get (client_sessions, | ||
292 | key); | ||
293 | } | ||
294 | |||
295 | |||
296 | /** | ||
297 | * Finds a CADET session in the respective map based on session key. | ||
298 | * | ||
299 | * @param key the session key we want to search for | ||
300 | * @return the matching session, or NULL for none | ||
301 | */ | ||
302 | static struct CadetIncomingSession * | ||
303 | find_matching_cadet_session (const struct GNUNET_HashCode *key) | ||
304 | { | ||
305 | return GNUNET_CONTAINER_multihashmap_get (cadet_sessions, | ||
306 | key); | ||
307 | } | ||
308 | |||
309 | |||
310 | /** | 234 | /** |
311 | * Callback used to free the elements in the map. | 235 | * Callback used to free the elements in the map. |
312 | * | 236 | * |
@@ -332,39 +256,20 @@ free_element_cb (void *cls, | |||
332 | * @param session the session to free elements from | 256 | * @param session the session to free elements from |
333 | */ | 257 | */ |
334 | static void | 258 | static void |
335 | destroy_cadet_session (struct CadetIncomingSession *s); | ||
336 | |||
337 | |||
338 | /** | ||
339 | * Destroy session state, we are done with it. | ||
340 | * | ||
341 | * @param session the session to free elements from | ||
342 | */ | ||
343 | static void | ||
344 | destroy_service_session (struct BobServiceSession *s) | 259 | destroy_service_session (struct BobServiceSession *s) |
345 | { | 260 | { |
346 | struct CadetIncomingSession *in; | ||
347 | unsigned int i; | 261 | unsigned int i; |
348 | 262 | ||
349 | if (GNUNET_YES == s->in_destroy) | 263 | if (GNUNET_YES == s->in_destroy) |
350 | return; | 264 | return; |
351 | s->in_destroy = GNUNET_YES; | 265 | s->in_destroy = GNUNET_YES; |
352 | if (NULL != (in = s->cadet)) | ||
353 | { | ||
354 | s->cadet = NULL; | ||
355 | destroy_cadet_session (in); | ||
356 | } | ||
357 | if (NULL != s->client) | 266 | if (NULL != s->client) |
358 | { | 267 | { |
359 | struct GNUNET_SERVICE_Client *c = s->client; | 268 | struct GNUNET_SERVICE_Client *c = s->client; |
360 | 269 | ||
361 | s->client = NULL; | 270 | s->client = NULL; |
362 | GNUNET_SERVICE_client_drop (c); | 271 | GNUNET_SERVICE_client_drop (c); |
363 | } | 272 | } |
364 | GNUNET_assert (GNUNET_YES == | ||
365 | GNUNET_CONTAINER_multihashmap_remove (client_sessions, | ||
366 | &s->session_id, | ||
367 | s)); | ||
368 | if (NULL != s->intersected_elements) | 273 | if (NULL != s->intersected_elements) |
369 | { | 274 | { |
370 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 275 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
@@ -405,48 +310,17 @@ destroy_service_session (struct BobServiceSession *s) | |||
405 | GNUNET_free (s->r_prime); | 310 | GNUNET_free (s->r_prime); |
406 | s->r_prime = NULL; | 311 | s->r_prime = NULL; |
407 | } | 312 | } |
408 | GNUNET_CADET_close_port (s->port); | 313 | if (NULL != s->port) |
409 | GNUNET_free (s); | ||
410 | } | ||
411 | |||
412 | |||
413 | /** | ||
414 | * Destroy incoming CADET session state, we are done with it. | ||
415 | * | ||
416 | * @param in the session to free elements from | ||
417 | */ | ||
418 | static void | ||
419 | destroy_cadet_session (struct CadetIncomingSession *in) | ||
420 | { | ||
421 | struct BobServiceSession *s; | ||
422 | |||
423 | if (GNUNET_YES == in->in_destroy) | ||
424 | return; | ||
425 | in->in_destroy = GNUNET_YES; | ||
426 | if (NULL != (s = in->s)) | ||
427 | { | 314 | { |
428 | in->s = NULL; | 315 | GNUNET_CADET_close_port (s->port); |
429 | destroy_service_session (s); | 316 | s->port = NULL; |
430 | } | 317 | } |
431 | if (GNUNET_YES == in->in_map) | 318 | if (NULL != s->channel) |
432 | { | 319 | { |
433 | GNUNET_assert (GNUNET_YES == | 320 | GNUNET_CADET_channel_destroy (s->channel); |
434 | GNUNET_CONTAINER_multihashmap_remove (cadet_sessions, | 321 | s->channel = NULL; |
435 | &in->session_id, | ||
436 | in)); | ||
437 | in->in_map = GNUNET_NO; | ||
438 | } | 322 | } |
439 | if (NULL != in->cadet_mq) | 323 | GNUNET_free (s); |
440 | { | ||
441 | GNUNET_MQ_destroy (in->cadet_mq); | ||
442 | in->cadet_mq = NULL; | ||
443 | } | ||
444 | if (NULL != in->channel) | ||
445 | { | ||
446 | GNUNET_CADET_channel_destroy (in->channel); | ||
447 | in->channel = NULL; | ||
448 | } | ||
449 | GNUNET_free (in); | ||
450 | } | 324 | } |
451 | 325 | ||
452 | 326 | ||
@@ -485,38 +359,26 @@ prepare_client_end_notification (struct BobServiceSession *session) | |||
485 | * | 359 | * |
486 | * It must NOT call #GNUNET_CADET_channel_destroy() on the channel. | 360 | * It must NOT call #GNUNET_CADET_channel_destroy() on the channel. |
487 | * | 361 | * |
488 | * @param cls closure (set from #GNUNET_CADET_connect()) | 362 | * @param cls the `struct BobServiceSession` |
489 | * @param channel connection to the other end (henceforth invalid) | 363 | * @param channel connection to the other end (henceforth invalid) |
490 | * @param channel_ctx place where local state associated | ||
491 | * with the channel is stored | ||
492 | */ | 364 | */ |
493 | static void | 365 | static void |
494 | cb_channel_destruction (void *cls, | 366 | cb_channel_destruction (void *cls, |
495 | const struct GNUNET_CADET_Channel *channel, | 367 | const struct GNUNET_CADET_Channel *channel) |
496 | void *channel_ctx) | ||
497 | { | 368 | { |
498 | struct CadetIncomingSession *in = channel_ctx; | 369 | struct BobServiceSession *s = cls; |
499 | struct BobServiceSession *s; | ||
500 | 370 | ||
501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
502 | "Peer disconnected, terminating session %s with peer %s\n", | 372 | "Peer disconnected, terminating session %s with peer %s\n", |
503 | GNUNET_h2s (&in->session_id), | 373 | GNUNET_h2s (&s->session_id), |
504 | GNUNET_i2s (&in->peer)); | 374 | GNUNET_i2s (&s->peer)); |
505 | if (NULL != (s = in->s)) | 375 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
506 | { | ||
507 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | ||
508 | { | ||
509 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
510 | prepare_client_end_notification (s); | ||
511 | } | ||
512 | } | ||
513 | if (NULL != in->cadet_mq) | ||
514 | { | 376 | { |
515 | GNUNET_MQ_destroy (in->cadet_mq); | 377 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
516 | in->cadet_mq = NULL; | 378 | prepare_client_end_notification (s); |
517 | } | 379 | } |
518 | in->channel = NULL; | 380 | s->channel = NULL; |
519 | destroy_cadet_session (in); | 381 | destroy_service_session (s); |
520 | } | 382 | } |
521 | 383 | ||
522 | 384 | ||
@@ -585,7 +447,7 @@ transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) | |||
585 | GNUNET_MQ_notify_sent (e, | 447 | GNUNET_MQ_notify_sent (e, |
586 | &bob_cadet_done_cb, | 448 | &bob_cadet_done_cb, |
587 | s); | 449 | s); |
588 | GNUNET_MQ_send (s->cadet->cadet_mq, | 450 | GNUNET_MQ_send (s->cadet_mq, |
589 | e); | 451 | e); |
590 | } | 452 | } |
591 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -653,7 +515,7 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
653 | GNUNET_MQ_notify_sent (e, | 515 | GNUNET_MQ_notify_sent (e, |
654 | &bob_cadet_done_cb, | 516 | &bob_cadet_done_cb, |
655 | s); | 517 | s); |
656 | GNUNET_MQ_send (s->cadet->cadet_mq, | 518 | GNUNET_MQ_send (s->cadet_mq, |
657 | e); | 519 | e); |
658 | transmit_bobs_cryptodata_message_multipart (s); | 520 | transmit_bobs_cryptodata_message_multipart (s); |
659 | } | 521 | } |
@@ -752,14 +614,14 @@ compute_service_response (struct BobServiceSession *session) | |||
752 | gcry_mpi_sub (tmp, my_offset, rand[p[i]]); | 614 | gcry_mpi_sub (tmp, my_offset, rand[p[i]]); |
753 | gcry_mpi_sub (tmp, tmp, b[p[i]].value); | 615 | gcry_mpi_sub (tmp, tmp, b[p[i]].value); |
754 | GNUNET_assert (2 == | 616 | GNUNET_assert (2 == |
755 | GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey, | 617 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, |
756 | tmp, | 618 | tmp, |
757 | 2, | 619 | 2, |
758 | &r[i])); | 620 | &r[i])); |
759 | 621 | ||
760 | // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b) | 622 | // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b) |
761 | if (GNUNET_OK != | 623 | if (GNUNET_OK != |
762 | GNUNET_CRYPTO_paillier_hom_add (&session->cadet->remote_pubkey, | 624 | GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey, |
763 | &r[i], | 625 | &r[i], |
764 | &a[p[i]], | 626 | &a[p[i]], |
765 | &r[i])) | 627 | &r[i])) |
@@ -775,14 +637,14 @@ compute_service_response (struct BobServiceSession *session) | |||
775 | // E(S - r_qi) | 637 | // E(S - r_qi) |
776 | gcry_mpi_sub (tmp, my_offset, rand[q[i]]); | 638 | gcry_mpi_sub (tmp, my_offset, rand[q[i]]); |
777 | GNUNET_assert (2 == | 639 | GNUNET_assert (2 == |
778 | GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey, | 640 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, |
779 | tmp, | 641 | tmp, |
780 | 2, | 642 | 2, |
781 | &r_prime[i])); | 643 | &r_prime[i])); |
782 | 644 | ||
783 | // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) | 645 | // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) |
784 | if (GNUNET_OK != | 646 | if (GNUNET_OK != |
785 | GNUNET_CRYPTO_paillier_hom_add (&session->cadet->remote_pubkey, | 647 | GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey, |
786 | &r_prime[i], | 648 | &r_prime[i], |
787 | &a[q[i]], | 649 | &a[q[i]], |
788 | &r_prime[i])) | 650 | &r_prime[i])) |
@@ -796,7 +658,7 @@ compute_service_response (struct BobServiceSession *session) | |||
796 | // Calculate S' = E(SUM( r_i^2 )) | 658 | // Calculate S' = E(SUM( r_i^2 )) |
797 | tmp = compute_square_sum (rand, count); | 659 | tmp = compute_square_sum (rand, count); |
798 | GNUNET_assert (1 == | 660 | GNUNET_assert (1 == |
799 | GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey, | 661 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, |
800 | tmp, | 662 | tmp, |
801 | 1, | 663 | 1, |
802 | &session->s_prime)); | 664 | &session->s_prime)); |
@@ -807,7 +669,7 @@ compute_service_response (struct BobServiceSession *session) | |||
807 | gcry_mpi_add (rand[i], rand[i], b[i].value); | 669 | gcry_mpi_add (rand[i], rand[i], b[i].value); |
808 | tmp = compute_square_sum (rand, count); | 670 | tmp = compute_square_sum (rand, count); |
809 | GNUNET_assert (1 == | 671 | GNUNET_assert (1 == |
810 | GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey, | 672 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, |
811 | tmp, | 673 | tmp, |
812 | 1, | 674 | 1, |
813 | &session->s)); | 675 | &session->s)); |
@@ -919,8 +781,8 @@ transmit_cryptographic_reply (struct BobServiceSession *s) | |||
919 | if (GNUNET_OK != | 781 | if (GNUNET_OK != |
920 | compute_service_response (s)) | 782 | compute_service_response (s)) |
921 | { | 783 | { |
922 | channel = s->cadet->channel; | 784 | channel = s->channel; |
923 | s->cadet->channel = NULL; | 785 | s->channel = NULL; |
924 | GNUNET_CADET_channel_destroy (channel); | 786 | GNUNET_CADET_channel_destroy (channel); |
925 | return; | 787 | return; |
926 | } | 788 | } |
@@ -929,49 +791,25 @@ transmit_cryptographic_reply (struct BobServiceSession *s) | |||
929 | 791 | ||
930 | 792 | ||
931 | /** | 793 | /** |
932 | * Handle a multipart-chunk of a request from another service to | 794 | * Check a multipart-chunk of a request from another service to |
933 | * calculate a scalarproduct with us. | 795 | * calculate a scalarproduct with us. |
934 | * | 796 | * |
935 | * @param cls closure (set from #GNUNET_CADET_connect) | 797 | * @param cls the `struct BobServiceSession *` |
936 | * @param channel connection to the other end | 798 | * @param msg the actual message |
937 | * @param channel_ctx place to store local state associated with the @a channel | ||
938 | * @param message the actual message | ||
939 | * @return #GNUNET_OK to keep the connection open, | 799 | * @return #GNUNET_OK to keep the connection open, |
940 | * #GNUNET_SYSERR to close it (signal serious error) | 800 | * #GNUNET_SYSERR to close it (signal serious error) |
941 | */ | 801 | */ |
942 | static int | 802 | static int |
943 | handle_alices_cryptodata_message (void *cls, | 803 | check_alices_cryptodata_message (void *cls, |
944 | struct GNUNET_CADET_Channel *channel, | 804 | const struct AliceCryptodataMessage *msg) |
945 | void **channel_ctx, | ||
946 | const struct GNUNET_MessageHeader *message) | ||
947 | { | 805 | { |
948 | struct CadetIncomingSession *in = *channel_ctx; | 806 | struct BobServiceSession *s = cls; |
949 | struct BobServiceSession *s; | ||
950 | const struct AliceCryptodataMessage *msg; | ||
951 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; | ||
952 | uint32_t contained_elements; | 807 | uint32_t contained_elements; |
953 | size_t msg_length; | 808 | size_t msg_length; |
954 | uint16_t msize; | 809 | uint16_t msize; |
955 | unsigned int max; | 810 | unsigned int max; |
956 | 811 | ||
957 | if (NULL == in) | 812 | msize = ntohs (msg->header.size); |
958 | { | ||
959 | GNUNET_break_op (0); | ||
960 | return GNUNET_SYSERR; | ||
961 | } | ||
962 | s = in->s; | ||
963 | if (NULL == s) | ||
964 | { | ||
965 | GNUNET_break_op (0); | ||
966 | return GNUNET_SYSERR; | ||
967 | } | ||
968 | msize = ntohs (message->size); | ||
969 | if (msize <= sizeof (struct AliceCryptodataMessage)) | ||
970 | { | ||
971 | GNUNET_break_op (0); | ||
972 | return GNUNET_SYSERR; | ||
973 | } | ||
974 | msg = (const struct AliceCryptodataMessage *) message; | ||
975 | contained_elements = ntohl (msg->contained_element_count); | 813 | contained_elements = ntohl (msg->contained_element_count); |
976 | /* Our intersection may still be ongoing, but this is nevertheless | 814 | /* Our intersection may still be ongoing, but this is nevertheless |
977 | an upper bound on the required array size */ | 815 | an upper bound on the required array size */ |
@@ -986,14 +824,38 @@ handle_alices_cryptodata_message (void *cls, | |||
986 | GNUNET_break_op (0); | 824 | GNUNET_break_op (0); |
987 | return GNUNET_SYSERR; | 825 | return GNUNET_SYSERR; |
988 | } | 826 | } |
827 | return GNUNET_OK; | ||
828 | } | ||
829 | |||
830 | |||
831 | /** | ||
832 | * Handle a multipart-chunk of a request from another service to | ||
833 | * calculate a scalarproduct with us. | ||
834 | * | ||
835 | * @param cls the `struct BobServiceSession *` | ||
836 | * @param msg the actual message | ||
837 | */ | ||
838 | static void | ||
839 | handle_alices_cryptodata_message (void *cls, | ||
840 | const struct AliceCryptodataMessage *msg) | ||
841 | { | ||
842 | struct BobServiceSession *s = cls; | ||
843 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; | ||
844 | uint32_t contained_elements; | ||
845 | unsigned int max; | ||
846 | |||
847 | contained_elements = ntohl (msg->contained_element_count); | ||
848 | /* Our intersection may still be ongoing, but this is nevertheless | ||
849 | an upper bound on the required array size */ | ||
850 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); | ||
989 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
990 | "Received %u crypto values from Alice\n", | 852 | "Received %u crypto values from Alice\n", |
991 | (unsigned int) contained_elements); | 853 | (unsigned int) contained_elements); |
992 | 854 | ||
993 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 855 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
994 | if (NULL == s->e_a) | 856 | if (NULL == s->e_a) |
995 | s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * | 857 | s->e_a = GNUNET_new_array (max, |
996 | max); | 858 | struct GNUNET_CRYPTO_PaillierCiphertext); |
997 | GNUNET_memcpy (&s->e_a[s->cadet_received_element_count], | 859 | GNUNET_memcpy (&s->e_a[s->cadet_received_element_count], |
998 | payload, | 860 | payload, |
999 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); | 861 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); |
@@ -1007,8 +869,7 @@ handle_alices_cryptodata_message (void *cls, | |||
1007 | CADET response(s) */ | 869 | CADET response(s) */ |
1008 | transmit_cryptographic_reply (s); | 870 | transmit_cryptographic_reply (s); |
1009 | } | 871 | } |
1010 | GNUNET_CADET_receive_done (s->cadet->channel); | 872 | GNUNET_CADET_receive_done (s->channel); |
1011 | return GNUNET_OK; | ||
1012 | } | 873 | } |
1013 | 874 | ||
1014 | 875 | ||
@@ -1048,7 +909,7 @@ cb_intersection_element_removed (void *cls, | |||
1048 | case GNUNET_SET_STATUS_DONE: | 909 | case GNUNET_SET_STATUS_DONE: |
1049 | s->intersection_op = NULL; | 910 | s->intersection_op = NULL; |
1050 | GNUNET_break (NULL == s->intersection_set); | 911 | GNUNET_break (NULL == s->intersection_set); |
1051 | GNUNET_CADET_receive_done (s->cadet->channel); | 912 | GNUNET_CADET_receive_done (s->channel); |
1052 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 913 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1053 | "Finished intersection, %d items remain\n", | 914 | "Finished intersection, %d items remain\n", |
1054 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); | 915 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); |
@@ -1099,7 +960,7 @@ start_intersection (struct BobServiceSession *s) | |||
1099 | (unsigned int) s->total); | 960 | (unsigned int) s->total); |
1100 | 961 | ||
1101 | s->intersection_op | 962 | s->intersection_op |
1102 | = GNUNET_SET_prepare (&s->cadet->peer, | 963 | = GNUNET_SET_prepare (&s->peer, |
1103 | &s->session_id, | 964 | &s->session_id, |
1104 | NULL, | 965 | NULL, |
1105 | GNUNET_SET_RESULT_REMOVED, | 966 | GNUNET_SET_RESULT_REMOVED, |
@@ -1122,55 +983,19 @@ start_intersection (struct BobServiceSession *s) | |||
1122 | /** | 983 | /** |
1123 | * Handle a request from Alice to calculate a scalarproduct with us (Bob). | 984 | * Handle a request from Alice to calculate a scalarproduct with us (Bob). |
1124 | * | 985 | * |
1125 | * @param cls closure (set from #GNUNET_CADET_connect) | 986 | * @param cls the `struct BobServiceSession *` |
1126 | * @param channel connection to the other end | 987 | * @param msg the actual message |
1127 | * @param channel_ctx place to store the `struct CadetIncomingSession *` | ||
1128 | * @param message the actual message | ||
1129 | * @return #GNUNET_OK to keep the connection open, | ||
1130 | * #GNUNET_SYSERR to close it (signal serious error) | ||
1131 | */ | 988 | */ |
1132 | static int | 989 | static void |
1133 | handle_alices_computation_request (void *cls, | 990 | handle_alices_computation_request (void *cls, |
1134 | struct GNUNET_CADET_Channel *channel, | 991 | const struct ServiceRequestMessage *msg) |
1135 | void **channel_ctx, | ||
1136 | const struct GNUNET_MessageHeader *message) | ||
1137 | { | 992 | { |
1138 | struct CadetIncomingSession *in = *channel_ctx; | 993 | struct BobServiceSession *s = cls; |
1139 | struct BobServiceSession *s; | ||
1140 | const struct ServiceRequestMessage *msg; | ||
1141 | 994 | ||
1142 | msg = (const struct ServiceRequestMessage *) message; | 995 | s->session_id = msg->session_id; // ?? |
1143 | if (GNUNET_YES == in->in_map) | 996 | s->remote_pubkey = msg->public_key; |
1144 | { | ||
1145 | GNUNET_break_op (0); | ||
1146 | return GNUNET_SYSERR; | ||
1147 | } | ||
1148 | if (NULL != find_matching_cadet_session (&msg->session_id)) | ||
1149 | { | ||
1150 | /* not unique, got one like this already */ | ||
1151 | GNUNET_break_op (0); | ||
1152 | return GNUNET_SYSERR; | ||
1153 | } | ||
1154 | in->session_id = msg->session_id; | ||
1155 | in->remote_pubkey = msg->public_key; | ||
1156 | GNUNET_assert (GNUNET_YES == | ||
1157 | GNUNET_CONTAINER_multihashmap_put (cadet_sessions, | ||
1158 | &in->session_id, | ||
1159 | in, | ||
1160 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1161 | s = find_matching_client_session (&in->session_id); | ||
1162 | if (NULL == s) | ||
1163 | { | ||
1164 | /* no client waiting for this request, wait for client */ | ||
1165 | return GNUNET_OK; | ||
1166 | } | ||
1167 | GNUNET_assert (NULL == s->cadet); | ||
1168 | /* pair them up */ | ||
1169 | in->s = s; | ||
1170 | s->cadet = in; | ||
1171 | if (s->client_received_element_count == s->total) | 997 | if (s->client_received_element_count == s->total) |
1172 | start_intersection (s); | 998 | start_intersection (s); |
1173 | return GNUNET_OK; | ||
1174 | } | 999 | } |
1175 | 1000 | ||
1176 | 1001 | ||
@@ -1182,31 +1007,27 @@ handle_alices_computation_request (void *cls, | |||
1182 | * @param cls closure with the `struct BobServiceSession` | 1007 | * @param cls closure with the `struct BobServiceSession` |
1183 | * @param channel new handle to the channel | 1008 | * @param channel new handle to the channel |
1184 | * @param initiator peer that started the channel | 1009 | * @param initiator peer that started the channel |
1185 | * @param port unused | ||
1186 | * @param options unused | ||
1187 | * @return session associated with the channel | 1010 | * @return session associated with the channel |
1188 | */ | 1011 | */ |
1189 | static void * | 1012 | static void * |
1190 | cb_channel_incoming (void *cls, | 1013 | cb_channel_incoming (void *cls, |
1191 | struct GNUNET_CADET_Channel *channel, | 1014 | struct GNUNET_CADET_Channel *channel, |
1192 | const struct GNUNET_PeerIdentity *initiator, | 1015 | const struct GNUNET_PeerIdentity *initiator) |
1193 | const struct GNUNET_HashCode *port, | ||
1194 | enum GNUNET_CADET_ChannelOption options) | ||
1195 | { | 1016 | { |
1196 | struct CadetIncomingSession *in; | 1017 | struct BobServiceSession *s = cls; |
1197 | 1018 | ||
1198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1019 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1199 | "New incoming channel from peer %s.\n", | 1020 | "New incoming channel from peer %s.\n", |
1200 | GNUNET_i2s (initiator)); | 1021 | GNUNET_i2s (initiator)); |
1201 | in = GNUNET_new (struct CadetIncomingSession); | 1022 | GNUNET_CADET_close_port (s->port); |
1202 | in->peer = *initiator; | 1023 | s->port = NULL; |
1203 | in->channel = channel; | 1024 | s->channel = channel; |
1204 | in->cadet_mq = GNUNET_CADET_mq_create (in->channel); | 1025 | s->peer = *initiator; |
1205 | return in; | 1026 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); |
1027 | return s; | ||
1206 | } | 1028 | } |
1207 | 1029 | ||
1208 | 1030 | ||
1209 | |||
1210 | /** | 1031 | /** |
1211 | * We're receiving additional set data. Check it is well-formed. | 1032 | * We're receiving additional set data. Check it is well-formed. |
1212 | * | 1033 | * |
@@ -1287,7 +1108,7 @@ handle_bob_client_message_multipart (void *cls, | |||
1287 | /* more to come */ | 1108 | /* more to come */ |
1288 | return; | 1109 | return; |
1289 | } | 1110 | } |
1290 | if (NULL == s->cadet) | 1111 | if (NULL == s->channel) |
1291 | { | 1112 | { |
1292 | /* no Alice waiting for this request, wait for Alice */ | 1113 | /* no Alice waiting for this request, wait for Alice */ |
1293 | return; | 1114 | return; |
@@ -1330,11 +1151,6 @@ check_bob_client_message (void *cls, | |||
1330 | GNUNET_break_op (0); | 1151 | GNUNET_break_op (0); |
1331 | return GNUNET_SYSERR; | 1152 | return GNUNET_SYSERR; |
1332 | } | 1153 | } |
1333 | if (NULL != find_matching_client_session (&msg->session_key)) | ||
1334 | { | ||
1335 | GNUNET_break (0); | ||
1336 | return GNUNET_SYSERR; | ||
1337 | } | ||
1338 | return GNUNET_OK; | 1154 | return GNUNET_OK; |
1339 | } | 1155 | } |
1340 | 1156 | ||
@@ -1352,7 +1168,17 @@ handle_bob_client_message (void *cls, | |||
1352 | const struct BobComputationMessage *msg) | 1168 | const struct BobComputationMessage *msg) |
1353 | { | 1169 | { |
1354 | struct BobServiceSession *s = cls; | 1170 | struct BobServiceSession *s = cls; |
1355 | struct CadetIncomingSession *in; | 1171 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
1172 | GNUNET_MQ_hd_fixed_size (alices_computation_request, | ||
1173 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION, | ||
1174 | struct ServiceRequestMessage, | ||
1175 | s), | ||
1176 | GNUNET_MQ_hd_var_size (alices_cryptodata_message, | ||
1177 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA, | ||
1178 | struct AliceCryptodataMessage, | ||
1179 | s), | ||
1180 | GNUNET_MQ_handler_end () | ||
1181 | }; | ||
1356 | uint32_t contained_count; | 1182 | uint32_t contained_count; |
1357 | uint32_t total_count; | 1183 | uint32_t total_count; |
1358 | const struct GNUNET_SCALARPRODUCT_Element *elements; | 1184 | const struct GNUNET_SCALARPRODUCT_Element *elements; |
@@ -1366,21 +1192,6 @@ handle_bob_client_message (void *cls, | |||
1366 | s->total = total_count; | 1192 | s->total = total_count; |
1367 | s->client_received_element_count = contained_count; | 1193 | s->client_received_element_count = contained_count; |
1368 | s->session_id = msg->session_key; | 1194 | s->session_id = msg->session_key; |
1369 | s->port = GNUNET_CADET_open_port (my_cadet, | ||
1370 | &msg->session_key, | ||
1371 | &cb_channel_incoming, | ||
1372 | s); | ||
1373 | if (NULL == s->port) | ||
1374 | { | ||
1375 | GNUNET_break (0); | ||
1376 | GNUNET_SERVICE_client_drop (s->client); | ||
1377 | return; | ||
1378 | } | ||
1379 | GNUNET_break (GNUNET_YES == | ||
1380 | GNUNET_CONTAINER_multihashmap_put (client_sessions, | ||
1381 | &s->session_id, | ||
1382 | s, | ||
1383 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1384 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 1195 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
1385 | s->intersected_elements | 1196 | s->intersected_elements |
1386 | = GNUNET_CONTAINER_multihashmap_create (s->total, | 1197 | = GNUNET_CONTAINER_multihashmap_create (s->total, |
@@ -1415,22 +1226,20 @@ handle_bob_client_message (void *cls, | |||
1415 | s->used_element_count++; | 1226 | s->used_element_count++; |
1416 | } | 1227 | } |
1417 | GNUNET_SERVICE_client_continue (s->client); | 1228 | GNUNET_SERVICE_client_continue (s->client); |
1418 | if (s->total != s->client_received_element_count) | 1229 | /* We're ready, open the port */ |
1419 | { | 1230 | s->port = GNUNET_CADET_open_porT (my_cadet, |
1420 | /* multipart msg */ | 1231 | &msg->session_key, |
1421 | return; | 1232 | &cb_channel_incoming, |
1422 | } | 1233 | s, |
1423 | in = find_matching_cadet_session (&s->session_id); | 1234 | NULL, |
1424 | if (NULL == in) | 1235 | &cb_channel_destruction, |
1236 | cadet_handlers); | ||
1237 | if (NULL == s->port) | ||
1425 | { | 1238 | { |
1426 | /* nothing yet, wait for Alice */ | 1239 | GNUNET_break (0); |
1240 | GNUNET_SERVICE_client_drop (s->client); | ||
1427 | return; | 1241 | return; |
1428 | } | 1242 | } |
1429 | GNUNET_assert (NULL == in->s); | ||
1430 | /* pair them up */ | ||
1431 | in->s = s; | ||
1432 | s->cadet = in; | ||
1433 | start_intersection (s); | ||
1434 | } | 1243 | } |
1435 | 1244 | ||
1436 | 1245 | ||
@@ -1450,10 +1259,6 @@ shutdown_task (void *cls) | |||
1450 | GNUNET_CADET_disconnect (my_cadet); | 1259 | GNUNET_CADET_disconnect (my_cadet); |
1451 | my_cadet = NULL; | 1260 | my_cadet = NULL; |
1452 | } | 1261 | } |
1453 | GNUNET_CONTAINER_multihashmap_destroy (client_sessions); | ||
1454 | client_sessions = NULL; | ||
1455 | GNUNET_CONTAINER_multihashmap_destroy (cadet_sessions); | ||
1456 | cadet_sessions = NULL; | ||
1457 | } | 1262 | } |
1458 | 1263 | ||
1459 | 1264 | ||
@@ -1517,16 +1322,6 @@ run (void *cls, | |||
1517 | const struct GNUNET_CONFIGURATION_Handle *c, | 1322 | const struct GNUNET_CONFIGURATION_Handle *c, |
1518 | struct GNUNET_SERVICE_Handle *service) | 1323 | struct GNUNET_SERVICE_Handle *service) |
1519 | { | 1324 | { |
1520 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | ||
1521 | { &handle_alices_computation_request, | ||
1522 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION, | ||
1523 | sizeof (struct ServiceRequestMessage) }, | ||
1524 | { &handle_alices_cryptodata_message, | ||
1525 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA, | ||
1526 | 0}, | ||
1527 | { NULL, 0, 0} | ||
1528 | }; | ||
1529 | |||
1530 | cfg = c; | 1325 | cfg = c; |
1531 | /* | 1326 | /* |
1532 | offset has to be sufficiently small to allow computation of: | 1327 | offset has to be sufficiently small to allow computation of: |
@@ -1538,13 +1333,7 @@ run (void *cls, | |||
1538 | 1333 | ||
1539 | GNUNET_CRYPTO_paillier_create (&my_pubkey, | 1334 | GNUNET_CRYPTO_paillier_create (&my_pubkey, |
1540 | &my_privkey); | 1335 | &my_privkey); |
1541 | client_sessions = GNUNET_CONTAINER_multihashmap_create (128, | 1336 | my_cadet = GNUNET_CADET_connecT (cfg); |
1542 | GNUNET_YES); | ||
1543 | cadet_sessions = GNUNET_CONTAINER_multihashmap_create (128, | ||
1544 | GNUNET_YES); | ||
1545 | my_cadet = GNUNET_CADET_connect (cfg, NULL, | ||
1546 | &cb_channel_destruction, | ||
1547 | cadet_handlers); | ||
1548 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 1337 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1549 | NULL); | 1338 | NULL); |
1550 | if (NULL == my_cadet) | 1339 | if (NULL == my_cadet) |