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-ecc_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-ecc_bob.c')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | 439 |
1 files changed, 112 insertions, 327 deletions
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 | ||