diff options
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct_bob.c')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_bob.c | 97 |
1 files changed, 50 insertions, 47 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c index 879e6abbd..cd2a9ee6e 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c | |||
@@ -145,23 +145,34 @@ struct BobServiceSession | |||
145 | gcry_mpi_t product; | 145 | gcry_mpi_t product; |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * How many elements we were supplied with from the client | 148 | * How many elements will be supplied in total from the client. |
149 | */ | 149 | */ |
150 | uint32_t total; | 150 | uint32_t total; |
151 | 151 | ||
152 | /** | 152 | /** |
153 | * how many elements actually are used for the scalar product. | 153 | * Already transferred elements (received) for multipart |
154 | * Size of the arrays in @e r and @e r_prime. | 154 | * messages from client. Always less than @e total. |
155 | */ | ||
156 | uint32_t client_received_element_count; | ||
157 | |||
158 | /** | ||
159 | * How many elements actually are used for the scalar product. | ||
160 | * Size of the arrays in @e r and @e r_prime. Also sometimes | ||
161 | * used as an index into the arrays during construction. | ||
155 | */ | 162 | */ |
156 | uint32_t used_element_count; | 163 | uint32_t used_element_count; |
157 | 164 | ||
158 | /** | 165 | /** |
159 | * Already transferred elements (sent/received) for multipart | 166 | * Counts the number of values received from Alice by us. |
160 | * messages. First used to count values received from client (less | 167 | * Always less than @e used_element_count. |
161 | * than @e total), then used to count values transmitted from Alice | ||
162 | * (less than @e used_element_count)! FIXME: maybe separate this. | ||
163 | */ | 168 | */ |
164 | uint32_t transferred_element_count; | 169 | uint32_t cadet_received_element_count; |
170 | |||
171 | /** | ||
172 | * Counts the number of values transmitted from us to Alice. | ||
173 | * Always less than @e used_element_count. | ||
174 | */ | ||
175 | uint32_t cadet_transmitted_element_count; | ||
165 | 176 | ||
166 | /** | 177 | /** |
167 | * Is this session active (#GNUNET_YES), Concluded (#GNUNET_NO), or had an error (#GNUNET_SYSERR) | 178 | * Is this session active (#GNUNET_YES), Concluded (#GNUNET_NO), or had an error (#GNUNET_SYSERR) |
@@ -262,12 +273,6 @@ static struct GNUNET_CONTAINER_MultiHashMap *cadet_sessions; | |||
262 | */ | 273 | */ |
263 | static struct GNUNET_CADET_Handle *my_cadet; | 274 | static struct GNUNET_CADET_Handle *my_cadet; |
264 | 275 | ||
265 | /** | ||
266 | * Certain events (callbacks for server & cadet operations) must not | ||
267 | * be queued after shutdown. | ||
268 | */ | ||
269 | static int do_shutdown; | ||
270 | |||
271 | 276 | ||
272 | 277 | ||
273 | /** | 278 | /** |
@@ -527,9 +532,9 @@ transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) | |||
527 | unsigned int j; | 532 | unsigned int j; |
528 | uint32_t todo_count; | 533 | uint32_t todo_count; |
529 | 534 | ||
530 | while (s->transferred_element_count != s->used_element_count) | 535 | while (s->cadet_transmitted_element_count != s->used_element_count) |
531 | { | 536 | { |
532 | todo_count = s->used_element_count - s->transferred_element_count; | 537 | todo_count = s->used_element_count - s->cadet_transmitted_element_count; |
533 | if (todo_count > ELEMENT_CAPACITY / 2) | 538 | if (todo_count > ELEMENT_CAPACITY / 2) |
534 | todo_count = ELEMENT_CAPACITY / 2; | 539 | todo_count = ELEMENT_CAPACITY / 2; |
535 | 540 | ||
@@ -541,7 +546,7 @@ transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) | |||
541 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART); | 546 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART); |
542 | msg->contained_element_count = htonl (todo_count); | 547 | msg->contained_element_count = htonl (todo_count); |
543 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 548 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
544 | for (i = s->transferred_element_count, j = 0; i < s->transferred_element_count + todo_count; i++) | 549 | for (i = s->cadet_transmitted_element_count, j = 0; i < s->cadet_transmitted_element_count + todo_count; i++) |
545 | { | 550 | { |
546 | //r[i][p] and r[i][q] | 551 | //r[i][p] and r[i][q] |
547 | memcpy (&payload[j++], | 552 | memcpy (&payload[j++], |
@@ -551,8 +556,8 @@ transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) | |||
551 | &s->r_prime[i], | 556 | &s->r_prime[i], |
552 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 557 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
553 | } | 558 | } |
554 | s->transferred_element_count += todo_count; | 559 | s->cadet_transmitted_element_count += todo_count; |
555 | if (s->transferred_element_count == s->used_element_count) | 560 | if (s->cadet_transmitted_element_count == s->used_element_count) |
556 | GNUNET_MQ_notify_sent (e, | 561 | GNUNET_MQ_notify_sent (e, |
557 | &bob_cadet_done_cb, | 562 | &bob_cadet_done_cb, |
558 | s); | 563 | s); |
@@ -581,25 +586,24 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
581 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; | 586 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; |
582 | unsigned int i; | 587 | unsigned int i; |
583 | 588 | ||
584 | s->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct ServiceResponseMessage)) / | 589 | s->cadet_transmitted_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct ServiceResponseMessage)) / |
585 | (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 2) - 2; | 590 | (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 2) - 2; |
586 | if (s->transferred_element_count > s->used_element_count) | 591 | if (s->cadet_transmitted_element_count > s->used_element_count) |
587 | s->transferred_element_count = s->used_element_count; | 592 | s->cadet_transmitted_element_count = s->used_element_count; |
588 | 593 | ||
589 | e = GNUNET_MQ_msg_extra (msg, | 594 | e = GNUNET_MQ_msg_extra (msg, |
590 | (2 + s->transferred_element_count * 2) | 595 | (2 + s->cadet_transmitted_element_count * 2) |
591 | * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), | 596 | * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), |
592 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); | 597 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); |
593 | // FIXME: 'total' maybe confusing here, and should already be known to Alice | 598 | msg->reserved = htonl (0); |
594 | msg->total_element_count = htonl (s->used_element_count); | 599 | msg->intersection_element_count = htonl (s->used_element_count); |
595 | // FIXME: redundant! | 600 | msg->contained_element_count = htonl (s->cadet_transmitted_element_count); |
596 | msg->used_element_count = htonl (s->transferred_element_count); | ||
597 | msg->contained_element_count = htonl (s->transferred_element_count); | ||
598 | msg->key = s->session_id; | 601 | msg->key = s->session_id; |
599 | 602 | ||
600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 603 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
601 | "Sending %u crypto values to Alice\n", | 604 | "Sending %u/%u crypto values to Alice\n", |
602 | (unsigned int) s->transferred_element_count); | 605 | (unsigned int) s->cadet_transmitted_element_count, |
606 | (unsigned int) s->used_element_count); | ||
603 | 607 | ||
604 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 608 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
605 | memcpy (&payload[0], | 609 | memcpy (&payload[0], |
@@ -611,7 +615,7 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
611 | 615 | ||
612 | payload = &payload[2]; | 616 | payload = &payload[2]; |
613 | // convert k[][] | 617 | // convert k[][] |
614 | for (i = 0; i < s->transferred_element_count; i++) | 618 | for (i = 0; i < s->cadet_transmitted_element_count; i++) |
615 | { | 619 | { |
616 | //k[i][p] and k[i][q] | 620 | //k[i][p] and k[i][q] |
617 | memcpy (&payload[i * 2], | 621 | memcpy (&payload[i * 2], |
@@ -621,7 +625,7 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
621 | &s->r_prime[i], | 625 | &s->r_prime[i], |
622 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 626 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); |
623 | } | 627 | } |
624 | if (s->transferred_element_count == s->used_element_count) | 628 | if (s->cadet_transmitted_element_count == s->used_element_count) |
625 | GNUNET_MQ_notify_sent (e, | 629 | GNUNET_MQ_notify_sent (e, |
626 | &bob_cadet_done_cb, | 630 | &bob_cadet_done_cb, |
627 | s); | 631 | s); |
@@ -917,7 +921,7 @@ handle_alices_cryptodata_message (void *cls, | |||
917 | if ( (msize != msg_length) || | 921 | if ( (msize != msg_length) || |
918 | (0 == contained_elements) || | 922 | (0 == contained_elements) || |
919 | (contained_elements > UINT16_MAX) || | 923 | (contained_elements > UINT16_MAX) || |
920 | (max < contained_elements + s->transferred_element_count) ) | 924 | (max < contained_elements + s->cadet_received_element_count) ) |
921 | { | 925 | { |
922 | GNUNET_break_op (0); | 926 | GNUNET_break_op (0); |
923 | return GNUNET_SYSERR; | 927 | return GNUNET_SYSERR; |
@@ -930,12 +934,12 @@ handle_alices_cryptodata_message (void *cls, | |||
930 | if (NULL == s->e_a) | 934 | if (NULL == s->e_a) |
931 | s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * | 935 | s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * |
932 | max); | 936 | max); |
933 | memcpy (&s->e_a[s->transferred_element_count], | 937 | memcpy (&s->e_a[s->cadet_received_element_count], |
934 | payload, | 938 | payload, |
935 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); | 939 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); |
936 | s->transferred_element_count += contained_elements; | 940 | s->cadet_received_element_count += contained_elements; |
937 | 941 | ||
938 | if ( (s->transferred_element_count == max) && | 942 | if ( (s->cadet_received_element_count == max) && |
939 | (NULL == s->intersection_op) ) | 943 | (NULL == s->intersection_op) ) |
940 | { | 944 | { |
941 | /* intersection has finished also on our side, and | 945 | /* intersection has finished also on our side, and |
@@ -986,7 +990,7 @@ cb_intersection_element_removed (void *cls, | |||
986 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 990 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
987 | "Finished intersection, %d items remain\n", | 991 | "Finished intersection, %d items remain\n", |
988 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); | 992 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); |
989 | if (s->transferred_element_count == | 993 | if (s->client_received_element_count == |
990 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)) | 994 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)) |
991 | { | 995 | { |
992 | /* CADET transmission from Alice is also already done, | 996 | /* CADET transmission from Alice is also already done, |
@@ -1026,7 +1030,7 @@ start_intersection (struct BobServiceSession *s) | |||
1026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1027 | "Got session with key %s and %u elements, starting intersection.\n", | 1031 | "Got session with key %s and %u elements, starting intersection.\n", |
1028 | GNUNET_h2s (&s->session_id), | 1032 | GNUNET_h2s (&s->session_id), |
1029 | (unsigned int) s->transferred_element_count); | 1033 | (unsigned int) s->total); |
1030 | 1034 | ||
1031 | s->intersection_op | 1035 | s->intersection_op |
1032 | = GNUNET_SET_prepare (&s->cadet->peer, | 1036 | = GNUNET_SET_prepare (&s->cadet->peer, |
@@ -1094,7 +1098,7 @@ handle_alices_computation_request (void *cls, | |||
1094 | /* pair them up */ | 1098 | /* pair them up */ |
1095 | in->s = s; | 1099 | in->s = s; |
1096 | s->cadet = in; | 1100 | s->cadet = in; |
1097 | if (s->transferred_element_count == s->total) | 1101 | if (s->client_received_element_count == s->total) |
1098 | start_intersection (s); | 1102 | start_intersection (s); |
1099 | return GNUNET_OK; | 1103 | return GNUNET_OK; |
1100 | } | 1104 | } |
@@ -1178,8 +1182,8 @@ GSS_handle_bob_client_message_multipart (void *cls, | |||
1178 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || | 1182 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || |
1179 | (0 == contained_count) || | 1183 | (0 == contained_count) || |
1180 | (UINT16_MAX < contained_count) || | 1184 | (UINT16_MAX < contained_count) || |
1181 | (s->total == s->transferred_element_count) || | 1185 | (s->total == s->client_received_element_count) || |
1182 | (s->total < s->transferred_element_count + contained_count) ) | 1186 | (s->total < s->client_received_element_count + contained_count) ) |
1183 | { | 1187 | { |
1184 | GNUNET_break_op (0); | 1188 | GNUNET_break_op (0); |
1185 | GNUNET_SERVER_receive_done (client, | 1189 | GNUNET_SERVER_receive_done (client, |
@@ -1212,10 +1216,10 @@ GSS_handle_bob_client_message_multipart (void *cls, | |||
1212 | &set_elem, | 1216 | &set_elem, |
1213 | NULL, NULL); | 1217 | NULL, NULL); |
1214 | } | 1218 | } |
1215 | s->transferred_element_count += contained_count; | 1219 | s->client_received_element_count += contained_count; |
1216 | GNUNET_SERVER_receive_done (client, | 1220 | GNUNET_SERVER_receive_done (client, |
1217 | GNUNET_OK); | 1221 | GNUNET_OK); |
1218 | if (s->total != s->transferred_element_count) | 1222 | if (s->total != s->client_received_element_count) |
1219 | { | 1223 | { |
1220 | /* more to come */ | 1224 | /* more to come */ |
1221 | return; | 1225 | return; |
@@ -1300,7 +1304,7 @@ GSS_handle_bob_client_message (void *cls, | |||
1300 | s->client = client; | 1304 | s->client = client; |
1301 | s->client_mq = GNUNET_MQ_queue_for_server_client (client); | 1305 | s->client_mq = GNUNET_MQ_queue_for_server_client (client); |
1302 | s->total = total_count; | 1306 | s->total = total_count; |
1303 | s->transferred_element_count = contained_count; | 1307 | s->client_received_element_count = contained_count; |
1304 | s->session_id = msg->session_key; | 1308 | s->session_id = msg->session_key; |
1305 | GNUNET_break (GNUNET_YES == | 1309 | GNUNET_break (GNUNET_YES == |
1306 | GNUNET_CONTAINER_multihashmap_put (client_sessions, | 1310 | GNUNET_CONTAINER_multihashmap_put (client_sessions, |
@@ -1342,7 +1346,7 @@ GSS_handle_bob_client_message (void *cls, | |||
1342 | s); | 1346 | s); |
1343 | GNUNET_SERVER_receive_done (client, | 1347 | GNUNET_SERVER_receive_done (client, |
1344 | GNUNET_YES); | 1348 | GNUNET_YES); |
1345 | if (s->total != s->transferred_element_count) | 1349 | if (s->total != s->client_received_element_count) |
1346 | { | 1350 | { |
1347 | /* multipart msg */ | 1351 | /* multipart msg */ |
1348 | return; | 1352 | return; |
@@ -1373,8 +1377,7 @@ shutdown_task (void *cls, | |||
1373 | { | 1377 | { |
1374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1375 | "Shutting down, initiating cleanup.\n"); | 1379 | "Shutting down, initiating cleanup.\n"); |
1376 | do_shutdown = GNUNET_YES; | 1380 | // FIXME: do we have to cut our connections to CADET first? |
1377 | // FIXME: is there a need to shutdown active sessions? | ||
1378 | if (NULL != my_cadet) | 1381 | if (NULL != my_cadet) |
1379 | { | 1382 | { |
1380 | GNUNET_CADET_disconnect (my_cadet); | 1383 | GNUNET_CADET_disconnect (my_cadet); |