aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c113
1 files changed, 41 insertions, 72 deletions
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 */
416static void 408static void
417cb_channel_destruction (void *cls, 409cb_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 */
502static int 484static void
503handle_bobs_cryptodata_message (void *cls, 485handle_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 &copy_element_cb, 612 &copy_element_cb,
@@ -843,6 +812,13 @@ cb_intersection_request_alice (void *cls,
843static void 812static void
844client_request_complete_alice (struct AliceServiceSession *s) 813client_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 */
900static int 879static int
901check_alice_client_message_multipart (void *cls, 880check_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 */
930static void 909static void
931handle_alice_client_message_multipart (void *cls, 910handle_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 */
985static int 964static int
986check_alice_client_message (void *cls, 965check_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 */
1023static void 1002static void
1024handle_alice_client_message (void *cls, 1003handle_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 */