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 /src/scalarproduct/gnunet-service-scalarproduct_bob.c | |
parent | 5afc3372aec888e2db988ad30a889c4bc842e5ac (diff) | |
download | gnunet-8a946bb7c2bc6bb863980ecf16607c57c2b077ec.tar.gz gnunet-8a946bb7c2bc6bb863980ecf16607c57c2b077ec.zip |
towards converting SP to new CADET API; still fails tests though
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct_bob.c')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_bob.c | 419 |
1 files changed, 104 insertions, 315 deletions
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) |