aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-08 00:17:15 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-08 00:17:15 +0000
commit4d8d62298e1926c6f8bd26ad5a34b966ffeb188c (patch)
treef3bfc90e07d1af8bdc15b69663f03b3a07857e71 /src
parenta3c0efd4c0b4f30f4956e2e44d59bfb003b80c6f (diff)
downloadgnunet-4d8d62298e1926c6f8bd26ad5a34b966ffeb188c.tar.gz
gnunet-4d8d62298e1926c6f8bd26ad5a34b966ffeb188c.zip
-fix shutdown
Diffstat (limited to 'src')
-rw-r--r--src/scalarproduct/gnunet-scalarproduct.c6
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c60
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_bob.c23
3 files changed, 64 insertions, 25 deletions
diff --git a/src/scalarproduct/gnunet-scalarproduct.c b/src/scalarproduct/gnunet-scalarproduct.c
index e812ff444..6f8d03bf3 100644
--- a/src/scalarproduct/gnunet-scalarproduct.c
+++ b/src/scalarproduct/gnunet-scalarproduct.c
@@ -137,7 +137,11 @@ requester_callback (void *cls,
137 if (0 == (rc = gcry_mpi_aprint (GCRYMPI_FMT_HEX, &buf, NULL, result))) 137 if (0 == (rc = gcry_mpi_aprint (GCRYMPI_FMT_HEX, &buf, NULL, result)))
138 { 138 {
139 ret = 0; 139 ret = 0;
140 printf ("%s", buf); 140 fprintf (stdout,
141 "%s%s\n",
142 (0 > gcry_mpi_cmp_ui (result, 0)) ? "-" : "",
143 buf);
144 fflush (stdout);
141 } 145 }
142 else 146 else
143 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, 147 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index 99d1f73d7..f34da64f9 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
@@ -164,7 +164,13 @@ struct AliceServiceSession
164 * Already transferred elements from client to us. 164 * Already transferred elements from client to us.
165 * Less or equal than @e total. 165 * Less or equal than @e total.
166 */ 166 */
167 uint32_t transferred_element_count; 167 uint32_t client_received_element_count;
168
169 /**
170 * Already transferred elements from Bob to us.
171 * Less or equal than @e total.
172 */
173 uint32_t cadet_received_element_count;
168 174
169 /** 175 /**
170 * State of this session. In 176 * State of this session. In
@@ -400,6 +406,7 @@ transmit_client_response (struct AliceServiceSession *s)
400 e = GNUNET_MQ_msg_extra (msg, 406 e = GNUNET_MQ_msg_extra (msg,
401 product_length, 407 product_length,
402 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 408 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
409 msg->status = htonl (GNUNET_SCALARPRODUCT_STATUS_SUCCESS);
403 msg->range = htonl (range); 410 msg->range = htonl (range);
404 msg->product_length = htonl (product_length); 411 msg->product_length = htonl (product_length);
405 if (NULL != product_exported) 412 if (NULL != product_exported)
@@ -669,7 +676,7 @@ handle_bobs_cryptodata_multipart (void *cls,
669 required_size = sizeof (struct BobCryptodataMultipartMessage) 676 required_size = sizeof (struct BobCryptodataMultipartMessage)
670 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 677 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
671 if ( (required_size != msg_size) || 678 if ( (required_size != msg_size) ||
672 (s->transferred_element_count + contained > s->used_element_count) ) 679 (s->cadet_received_element_count + contained > s->used_element_count) )
673 { 680 {
674 GNUNET_break (0); 681 GNUNET_break (0);
675 return GNUNET_SYSERR; 682 return GNUNET_SYSERR;
@@ -683,16 +690,16 @@ handle_bobs_cryptodata_multipart (void *cls,
683 /* Convert each k[][perm] to its MPI_value */ 690 /* Convert each k[][perm] to its MPI_value */
684 for (i = 0; i < contained; i++) 691 for (i = 0; i < contained; i++)
685 { 692 {
686 memcpy (&s->r[s->transferred_element_count + i], 693 memcpy (&s->r[s->cadet_received_element_count + i],
687 &payload[2 * i], 694 &payload[2 * i],
688 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 695 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
689 memcpy (&s->r_prime[s->transferred_element_count + i], 696 memcpy (&s->r_prime[s->cadet_received_element_count + i],
690 &payload[2 * i], 697 &payload[2 * i],
691 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 698 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
692 } 699 }
693 s->transferred_element_count += contained; 700 s->cadet_received_element_count += contained;
694 GNUNET_CADET_receive_done (s->channel); 701 GNUNET_CADET_receive_done (s->channel);
695 if (s->transferred_element_count != s->used_element_count) 702 if (s->cadet_received_element_count != s->used_element_count)
696 return GNUNET_OK; 703 return GNUNET_OK;
697 704
698 s->product = compute_scalar_product (s); 705 s->product = compute_scalar_product (s);
@@ -749,14 +756,18 @@ handle_bobs_cryptodata_message (void *cls,
749 GNUNET_break_op (0); 756 GNUNET_break_op (0);
750 return GNUNET_SYSERR; 757 return GNUNET_SYSERR;
751 } 758 }
752 if ( (NULL == s->sorted_elements) || 759 if (NULL == s->sorted_elements)
753 (s->used_element_count != s->transferred_element_count) ) 760 {
761 /* we're not ready yet, how can Bob be? */
762 GNUNET_break_op (0);
763 return GNUNET_SYSERR;
764 }
765 if (s->total != s->client_received_element_count)
754 { 766 {
755 /* we're not ready yet, how can Bob be? */ 767 /* we're not ready yet, how can Bob be? */
756 GNUNET_break_op (0); 768 GNUNET_break_op (0);
757 return GNUNET_SYSERR; 769 return GNUNET_SYSERR;
758 } 770 }
759
760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
761 "Received %u crypto values from Bob\n", 772 "Received %u crypto values from Bob\n",
762 (unsigned int) contained); 773 (unsigned int) contained);
@@ -781,10 +792,10 @@ handle_bobs_cryptodata_message (void *cls,
781 &payload[2 * i + 1], 792 &payload[2 * i + 1],
782 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 793 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
783 } 794 }
784 s->transferred_element_count = contained; 795 s->cadet_received_element_count = contained;
785 GNUNET_CADET_receive_done (s->channel); 796 GNUNET_CADET_receive_done (s->channel);
786 797
787 if (s->transferred_element_count != s->used_element_count) 798 if (s->cadet_received_element_count != s->used_element_count)
788 { 799 {
789 /* More to come */ 800 /* More to come */
790 return GNUNET_OK; 801 return GNUNET_OK;
@@ -954,7 +965,11 @@ cb_intersection_element_removed (void *cls,
954 return; 965 return;
955 case GNUNET_SET_STATUS_DONE: 966 case GNUNET_SET_STATUS_DONE:
956 s->intersection_op = NULL; 967 s->intersection_op = NULL;
957 s->intersection_set = NULL; 968 if (NULL != s->intersection_set)
969 {
970 GNUNET_SET_destroy (s->intersection_set);
971 s->intersection_set = NULL;
972 }
958 send_alices_cryptodata_message (s); 973 send_alices_cryptodata_message (s);
959 return; 974 return;
960 case GNUNET_SET_STATUS_HALF_DONE: 975 case GNUNET_SET_STATUS_HALF_DONE:
@@ -971,7 +986,11 @@ cb_intersection_element_removed (void *cls,
971 s->intersection_listen = NULL; 986 s->intersection_listen = NULL;
972 } 987 }
973 s->intersection_op = NULL; 988 s->intersection_op = NULL;
974 s->intersection_set = NULL; 989 if (NULL != s->intersection_set)
990 {
991 GNUNET_SET_destroy (s->intersection_set);
992 s->intersection_set = NULL;
993 }
975 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 994 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
976 prepare_client_end_notification (s); 995 prepare_client_end_notification (s);
977 return; 996 return;
@@ -1028,11 +1047,14 @@ cb_intersection_request_alice (void *cls,
1028 GNUNET_SET_commit (s->intersection_op, 1047 GNUNET_SET_commit (s->intersection_op,
1029 s->intersection_set)) 1048 s->intersection_set))
1030 { 1049 {
1050 GNUNET_break (0);
1031 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1051 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1032 prepare_client_end_notification (s); 1052 prepare_client_end_notification (s);
1033 return; 1053 return;
1034 } 1054 }
1055 GNUNET_SET_destroy (s->intersection_set);
1035 s->intersection_set = NULL; 1056 s->intersection_set = NULL;
1057 GNUNET_SET_listen_cancel (s->intersection_listen);
1036 s->intersection_listen = NULL; 1058 s->intersection_listen = NULL;
1037} 1059}
1038 1060
@@ -1134,15 +1156,15 @@ GSS_handle_alice_client_message_multipart (void *cls,
1134 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 1156 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) +
1135 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 1157 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
1136 (0 == contained_count) || 1158 (0 == contained_count) ||
1137 (s->total == s->transferred_element_count) || 1159 (s->total == s->client_received_element_count) ||
1138 (s->total < s->transferred_element_count + contained_count) ) 1160 (s->total < s->client_received_element_count + contained_count) )
1139 { 1161 {
1140 GNUNET_break_op (0); 1162 GNUNET_break_op (0);
1141 GNUNET_SERVER_receive_done (client, 1163 GNUNET_SERVER_receive_done (client,
1142 GNUNET_SYSERR); 1164 GNUNET_SYSERR);
1143 return; 1165 return;
1144 } 1166 }
1145 s->transferred_element_count += contained_count; 1167 s->client_received_element_count += contained_count;
1146 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 1168 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1147 for (i = 0; i < contained_count; i++) 1169 for (i = 0; i < contained_count; i++)
1148 { 1170 {
@@ -1172,7 +1194,7 @@ GSS_handle_alice_client_message_multipart (void *cls,
1172 } 1194 }
1173 GNUNET_SERVER_receive_done (client, 1195 GNUNET_SERVER_receive_done (client,
1174 GNUNET_OK); 1196 GNUNET_OK);
1175 if (s->total != s->transferred_element_count) 1197 if (s->total != s->client_received_element_count)
1176 { 1198 {
1177 /* more to come */ 1199 /* more to come */
1178 return; 1200 return;
@@ -1240,7 +1262,7 @@ GSS_handle_alice_client_message (void *cls,
1240 s->client = client; 1262 s->client = client;
1241 s->client_mq = GNUNET_MQ_queue_for_server_client (client); 1263 s->client_mq = GNUNET_MQ_queue_for_server_client (client);
1242 s->total = total_count; 1264 s->total = total_count;
1243 s->transferred_element_count = contained_count; 1265 s->client_received_element_count = contained_count;
1244 s->session_id = msg->session_key; 1266 s->session_id = msg->session_key;
1245 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 1267 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1246 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 1268 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total,
@@ -1278,7 +1300,7 @@ GSS_handle_alice_client_message (void *cls,
1278 s); 1300 s);
1279 GNUNET_SERVER_receive_done (client, 1301 GNUNET_SERVER_receive_done (client,
1280 GNUNET_OK); 1302 GNUNET_OK);
1281 if (s->total != s->transferred_element_count) 1303 if (s->total != s->client_received_element_count)
1282 { 1304 {
1283 /* wait for multipart msg */ 1305 /* wait for multipart msg */
1284 return; 1306 return;
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
index 414e2c603..38fc65f37 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
@@ -992,7 +992,7 @@ cb_intersection_element_removed (void *cls,
992 return; 992 return;
993 case GNUNET_SET_STATUS_DONE: 993 case GNUNET_SET_STATUS_DONE:
994 s->intersection_op = NULL; 994 s->intersection_op = NULL;
995 s->intersection_set = NULL; 995 GNUNET_break (NULL == s->intersection_set);
996 GNUNET_CADET_receive_done (s->cadet->channel); 996 GNUNET_CADET_receive_done (s->cadet->channel);
997 LOG (GNUNET_ERROR_TYPE_DEBUG, 997 LOG (GNUNET_ERROR_TYPE_DEBUG,
998 "Finished intersection, %d items remain\n", 998 "Finished intersection, %d items remain\n",
@@ -1014,7 +1014,11 @@ cb_intersection_element_removed (void *cls,
1014 LOG (GNUNET_ERROR_TYPE_DEBUG, 1014 LOG (GNUNET_ERROR_TYPE_DEBUG,
1015 "Set intersection failed!\n"); 1015 "Set intersection failed!\n");
1016 s->intersection_op = NULL; 1016 s->intersection_op = NULL;
1017 s->intersection_set = NULL; 1017 if (NULL != s->intersection_set)
1018 {
1019 GNUNET_SET_destroy (s->intersection_set);
1020 s->intersection_set = NULL;
1021 }
1018 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1022 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1019 prepare_client_end_notification (s); 1023 prepare_client_end_notification (s);
1020 return; 1024 return;
@@ -1046,8 +1050,17 @@ start_intersection (struct BobServiceSession *s)
1046 GNUNET_SET_RESULT_REMOVED, 1050 GNUNET_SET_RESULT_REMOVED,
1047 &cb_intersection_element_removed, 1051 &cb_intersection_element_removed,
1048 s); 1052 s);
1049 GNUNET_SET_commit (s->intersection_op, 1053 if (GNUNET_OK !=
1050 s->intersection_set); 1054 GNUNET_SET_commit (s->intersection_op,
1055 s->intersection_set))
1056 {
1057 GNUNET_break (0);
1058 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1059 prepare_client_end_notification (s);
1060 return;
1061 }
1062 GNUNET_SET_destroy (s->intersection_set);
1063 s->intersection_set = NULL;
1051} 1064}
1052 1065
1053 1066
@@ -1138,7 +1151,7 @@ cb_channel_incoming (void *cls,
1138 in = GNUNET_new (struct CadetIncomingSession); 1151 in = GNUNET_new (struct CadetIncomingSession);
1139 in->peer = *initiator; 1152 in->peer = *initiator;
1140 in->channel = channel; 1153 in->channel = channel;
1141 // in->cadet_mq = GNUNET_CADET_mq_create (in->channel); 1154 in->cadet_mq = GNUNET_CADET_mq_create (in->channel);
1142 return in; 1155 return in;
1143} 1156}
1144 1157