diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-07 01:07:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-07 01:07:07 +0000 |
commit | 4e508bb9f251f0b1d261bb4178fb8a2b0009635d (patch) | |
tree | 7eccde4f1e915a6762f523330633557e7e5987c2 /src | |
parent | 4ede109b9167fde6558b4281b023e1010c260522 (diff) | |
download | gnunet-4e508bb9f251f0b1d261bb4178fb8a2b0009635d.tar.gz gnunet-4e508bb9f251f0b1d261bb4178fb8a2b0009635d.zip |
-more SP fixes and todos
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_scalarproduct_service.h | 2 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-scalarproduct.c | 3 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_alice.c | 37 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_bob.c | 34 | ||||
-rwxr-xr-x | src/scalarproduct/test_scalarproduct.sh | 2 |
5 files changed, 57 insertions, 21 deletions
diff --git a/src/include/gnunet_scalarproduct_service.h b/src/include/gnunet_scalarproduct_service.h index c96c280c4..9585fbe55 100644 --- a/src/include/gnunet_scalarproduct_service.h +++ b/src/include/gnunet_scalarproduct_service.h | |||
@@ -87,7 +87,7 @@ struct GNUNET_SCALARPRODUCT_Element | |||
87 | struct GNUNET_HashCode key; | 87 | struct GNUNET_HashCode key; |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Value to multiply in scalar product. | 90 | * Value to multiply in scalar product, in NBO. |
91 | */ | 91 | */ |
92 | int64_t value GNUNET_PACKED; | 92 | int64_t value GNUNET_PACKED; |
93 | }; | 93 | }; |
diff --git a/src/scalarproduct/gnunet-scalarproduct.c b/src/scalarproduct/gnunet-scalarproduct.c index c6ed365f8..f6e7d6af2 100644 --- a/src/scalarproduct/gnunet-scalarproduct.c +++ b/src/scalarproduct/gnunet-scalarproduct.c | |||
@@ -289,9 +289,10 @@ run (void *cls, | |||
289 | LOG (GNUNET_ERROR_TYPE_ERROR, | 289 | LOG (GNUNET_ERROR_TYPE_ERROR, |
290 | _("Could not convert `%s' to int64_t.\n"), | 290 | _("Could not convert `%s' to int64_t.\n"), |
291 | begin); | 291 | begin); |
292 | GNUNET_free(elements); | 292 | GNUNET_free (elements); |
293 | return; | 293 | return; |
294 | } | 294 | } |
295 | element.value = GNUNET_htonll (element.value); | ||
295 | elements[i] = element; | 296 | elements[i] = element; |
296 | begin = end + 1; | 297 | begin = end + 1; |
297 | } | 298 | } |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c index b5ab8a88f..e75915f9a 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c | |||
@@ -148,18 +148,21 @@ struct AliceServiceSession | |||
148 | gcry_mpi_t product; | 148 | gcry_mpi_t product; |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * how many elements we were supplied with from the client | 151 | * How many elements we were supplied with from the client (total |
152 | * count before intersection). | ||
152 | */ | 153 | */ |
153 | uint32_t total; | 154 | uint32_t total; |
154 | 155 | ||
155 | /** | 156 | /** |
156 | * how many elements actually are used for the scalar product. | 157 | * How many elements actually are used for the scalar product. |
157 | * Size of the arrays in @e r and @e r_prime. | 158 | * Size of the arrays in @e r and @e r_prime. Sometimes also |
159 | * reset to 0 and used as a counter! | ||
158 | */ | 160 | */ |
159 | uint32_t used_element_count; | 161 | uint32_t used_element_count; |
160 | 162 | ||
161 | /** | 163 | /** |
162 | * already transferred elements (sent/received) for multipart messages, less or equal than @e used_element_count for | 164 | * Already transferred elements from client to us. |
165 | * Less or equal than @e total. | ||
163 | */ | 166 | */ |
164 | uint32_t transferred_element_count; | 167 | uint32_t transferred_element_count; |
165 | 168 | ||
@@ -665,6 +668,11 @@ handle_bobs_cryptodata_multipart (void *cls, | |||
665 | GNUNET_break (0); | 668 | GNUNET_break (0); |
666 | return GNUNET_SYSERR; | 669 | return GNUNET_SYSERR; |
667 | } | 670 | } |
671 | |||
672 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
673 | "Received %u additional crypto values from Bob\n", | ||
674 | (unsigned int) contained); | ||
675 | |||
668 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 676 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
669 | /* Convert each k[][perm] to its MPI_value */ | 677 | /* Convert each k[][perm] to its MPI_value */ |
670 | for (i = 0; i < contained; i++) | 678 | for (i = 0; i < contained; i++) |
@@ -741,6 +749,11 @@ handle_bobs_cryptodata_message (void *cls, | |||
741 | GNUNET_break_op (0); | 749 | GNUNET_break_op (0); |
742 | return GNUNET_SYSERR; | 750 | return GNUNET_SYSERR; |
743 | } | 751 | } |
752 | |||
753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
754 | "Received %u crypto values from Bob\n", | ||
755 | (unsigned int) contained); | ||
756 | |||
744 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 757 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
745 | memcpy (&s->s, | 758 | memcpy (&s->s, |
746 | &payload[0], | 759 | &payload[0], |
@@ -847,6 +860,7 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
847 | unsigned int i; | 860 | unsigned int i; |
848 | uint32_t todo_count; | 861 | uint32_t todo_count; |
849 | gcry_mpi_t a; | 862 | gcry_mpi_t a; |
863 | uint32_t off; | ||
850 | 864 | ||
851 | s->sorted_elements | 865 | s->sorted_elements |
852 | = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * | 866 | = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * |
@@ -862,12 +876,15 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
862 | s->used_element_count, | 876 | s->used_element_count, |
863 | sizeof (struct MpiElement), | 877 | sizeof (struct MpiElement), |
864 | &element_cmp); | 878 | &element_cmp); |
865 | 879 | off = 0; | |
866 | while (s->transferred_element_count < s->used_element_count) | 880 | while (off < s->used_element_count) |
867 | { | 881 | { |
868 | todo_count = s->used_element_count - s->transferred_element_count; | 882 | todo_count = s->used_element_count - off; |
869 | if (todo_count > ELEMENT_CAPACITY) | 883 | if (todo_count > ELEMENT_CAPACITY) |
870 | todo_count = ELEMENT_CAPACITY; | 884 | todo_count = ELEMENT_CAPACITY; |
885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
886 | "Sending %u crypto values to Bob\n", | ||
887 | (unsigned int) todo_count); | ||
871 | 888 | ||
872 | e = GNUNET_MQ_msg_extra (msg, | 889 | e = GNUNET_MQ_msg_extra (msg, |
873 | todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), | 890 | todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), |
@@ -875,7 +892,7 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
875 | msg->contained_element_count = htonl (todo_count); | 892 | msg->contained_element_count = htonl (todo_count); |
876 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 893 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
877 | a = gcry_mpi_new (0); | 894 | a = gcry_mpi_new (0); |
878 | for (i = s->transferred_element_count; i < todo_count; i++) | 895 | for (i = off; i < todo_count; i++) |
879 | { | 896 | { |
880 | gcry_mpi_add (a, | 897 | gcry_mpi_add (a, |
881 | s->sorted_elements[i].value, | 898 | s->sorted_elements[i].value, |
@@ -883,10 +900,10 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
883 | GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, | 900 | GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, |
884 | a, | 901 | a, |
885 | 3, | 902 | 3, |
886 | &payload[i - s->transferred_element_count]); | 903 | &payload[i - off]); |
887 | } | 904 | } |
888 | gcry_mpi_release (a); | 905 | gcry_mpi_release (a); |
889 | s->transferred_element_count += todo_count; | 906 | off += todo_count; |
890 | GNUNET_MQ_send (s->cadet_mq, | 907 | GNUNET_MQ_send (s->cadet_mq, |
891 | e); | 908 | e); |
892 | } | 909 | } |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c index 23bfcda0e..879e6abbd 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c | |||
@@ -156,7 +156,10 @@ struct BobServiceSession | |||
156 | uint32_t used_element_count; | 156 | uint32_t used_element_count; |
157 | 157 | ||
158 | /** | 158 | /** |
159 | * already transferred elements (sent/received) for multipart messages, less or equal than @e used_element_count for | 159 | * Already transferred elements (sent/received) for multipart |
160 | * messages. First used to count values received from client (less | ||
161 | * than @e total), then used to count values transmitted from Alice | ||
162 | * (less than @e used_element_count)! FIXME: maybe separate this. | ||
160 | */ | 163 | */ |
161 | uint32_t transferred_element_count; | 164 | uint32_t transferred_element_count; |
162 | 165 | ||
@@ -530,6 +533,9 @@ transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) | |||
530 | if (todo_count > ELEMENT_CAPACITY / 2) | 533 | if (todo_count > ELEMENT_CAPACITY / 2) |
531 | todo_count = ELEMENT_CAPACITY / 2; | 534 | todo_count = ELEMENT_CAPACITY / 2; |
532 | 535 | ||
536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
537 | "Sending %u additional crypto values to Alice\n", | ||
538 | (unsigned int) todo_count); | ||
533 | e = GNUNET_MQ_msg_extra (msg, | 539 | e = GNUNET_MQ_msg_extra (msg, |
534 | todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 2, | 540 | todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 2, |
535 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART); | 541 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART); |
@@ -584,11 +590,17 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
584 | (2 + s->transferred_element_count * 2) | 590 | (2 + s->transferred_element_count * 2) |
585 | * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), | 591 | * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), |
586 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); | 592 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); |
587 | msg->total_element_count = htonl (s->total); | 593 | // FIXME: 'total' maybe confusing here, and should already be known to Alice |
588 | msg->used_element_count = htonl (s->used_element_count); | 594 | msg->total_element_count = htonl (s->used_element_count); |
595 | // FIXME: redundant! | ||
596 | msg->used_element_count = htonl (s->transferred_element_count); | ||
589 | msg->contained_element_count = htonl (s->transferred_element_count); | 597 | msg->contained_element_count = htonl (s->transferred_element_count); |
590 | msg->key = s->session_id; | 598 | msg->key = s->session_id; |
591 | 599 | ||
600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
601 | "Sending %u crypto values to Alice\n", | ||
602 | (unsigned int) s->transferred_element_count); | ||
603 | |||
592 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 604 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
593 | memcpy (&payload[0], | 605 | memcpy (&payload[0], |
594 | &s->s, | 606 | &s->s, |
@@ -834,6 +846,8 @@ static void | |||
834 | transmit_cryptographic_reply (struct BobServiceSession *s) | 846 | transmit_cryptographic_reply (struct BobServiceSession *s) |
835 | { | 847 | { |
836 | /* TODO: code duplication with Alice! */ | 848 | /* TODO: code duplication with Alice! */ |
849 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
850 | "Received everything, building reply for Alice\n"); | ||
837 | s->sorted_elements | 851 | s->sorted_elements |
838 | = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * | 852 | = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * |
839 | sizeof (struct MpiElement)); | 853 | sizeof (struct MpiElement)); |
@@ -841,9 +855,6 @@ transmit_cryptographic_reply (struct BobServiceSession *s) | |||
841 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 855 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
842 | ©_element_cb, | 856 | ©_element_cb, |
843 | s); | 857 | s); |
844 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
845 | "Finished intersection, %d items remain\n", | ||
846 | s->used_element_count); | ||
847 | qsort (s->sorted_elements, | 858 | qsort (s->sorted_elements, |
848 | s->used_element_count, | 859 | s->used_element_count, |
849 | sizeof (struct MpiElement), | 860 | sizeof (struct MpiElement), |
@@ -911,6 +922,9 @@ handle_alices_cryptodata_message (void *cls, | |||
911 | GNUNET_break_op (0); | 922 | GNUNET_break_op (0); |
912 | return GNUNET_SYSERR; | 923 | return GNUNET_SYSERR; |
913 | } | 924 | } |
925 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
926 | "Received %u crypto values from Alice\n", | ||
927 | (unsigned int) contained_elements); | ||
914 | 928 | ||
915 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 929 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
916 | if (NULL == s->e_a) | 930 | if (NULL == s->e_a) |
@@ -969,6 +983,9 @@ cb_intersection_element_removed (void *cls, | |||
969 | case GNUNET_SET_STATUS_DONE: | 983 | case GNUNET_SET_STATUS_DONE: |
970 | s->intersection_op = NULL; | 984 | s->intersection_op = NULL; |
971 | s->intersection_set = NULL; | 985 | s->intersection_set = NULL; |
986 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
987 | "Finished intersection, %d items remain\n", | ||
988 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); | ||
972 | if (s->transferred_element_count == | 989 | if (s->transferred_element_count == |
973 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)) | 990 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)) |
974 | { | 991 | { |
@@ -1007,8 +1024,9 @@ static void | |||
1007 | start_intersection (struct BobServiceSession *s) | 1024 | start_intersection (struct BobServiceSession *s) |
1008 | { | 1025 | { |
1009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1010 | "Got session with key %s and a matching element set, processing.\n", | 1027 | "Got session with key %s and %u elements, starting intersection.\n", |
1011 | GNUNET_h2s (&s->session_id)); | 1028 | GNUNET_h2s (&s->session_id), |
1029 | (unsigned int) s->transferred_element_count); | ||
1012 | 1030 | ||
1013 | s->intersection_op | 1031 | s->intersection_op |
1014 | = GNUNET_SET_prepare (&s->cadet->peer, | 1032 | = GNUNET_SET_prepare (&s->cadet->peer, |
diff --git a/src/scalarproduct/test_scalarproduct.sh b/src/scalarproduct/test_scalarproduct.sh index 8a34c2473..562a4f68f 100755 --- a/src/scalarproduct/test_scalarproduct.sh +++ b/src/scalarproduct/test_scalarproduct.sh | |||
@@ -17,7 +17,7 @@ CFGBOB="-c $PREFIX/1/config" | |||
17 | # interactive mode would terminate the test immediately | 17 | # interactive mode would terminate the test immediately |
18 | # because the rest of the script is already in stdin, | 18 | # because the rest of the script is already in stdin, |
19 | # thus redirecting stdin does not suffice) | 19 | # thus redirecting stdin does not suffice) |
20 | GNUNET_LOG='scalarproduct*;;;;DEBUG' | 20 | GNUNET_FORCE_LOG='scalarproduct*;;;;DEBUG' |
21 | GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 & | 21 | GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 & |
22 | PID=$! | 22 | PID=$! |
23 | # sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe | 23 | # sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe |