From 4e508bb9f251f0b1d261bb4178fb8a2b0009635d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 7 Dec 2014 01:07:07 +0000 Subject: -more SP fixes and todos --- src/include/gnunet_scalarproduct_service.h | 2 +- src/scalarproduct/gnunet-scalarproduct.c | 3 +- .../gnunet-service-scalarproduct_alice.c | 37 ++++++++++++++++------ .../gnunet-service-scalarproduct_bob.c | 34 +++++++++++++++----- src/scalarproduct/test_scalarproduct.sh | 2 +- 5 files changed, 57 insertions(+), 21 deletions(-) (limited to 'src') 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 struct GNUNET_HashCode key; /** - * Value to multiply in scalar product. + * Value to multiply in scalar product, in NBO. */ int64_t value GNUNET_PACKED; }; 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, LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not convert `%s' to int64_t.\n"), begin); - GNUNET_free(elements); + GNUNET_free (elements); return; } + element.value = GNUNET_htonll (element.value); elements[i] = element; begin = end + 1; } 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 gcry_mpi_t product; /** - * how many elements we were supplied with from the client + * How many elements we were supplied with from the client (total + * count before intersection). */ uint32_t total; /** - * how many elements actually are used for the scalar product. - * Size of the arrays in @e r and @e r_prime. + * How many elements actually are used for the scalar product. + * Size of the arrays in @e r and @e r_prime. Sometimes also + * reset to 0 and used as a counter! */ uint32_t used_element_count; /** - * already transferred elements (sent/received) for multipart messages, less or equal than @e used_element_count for + * Already transferred elements from client to us. + * Less or equal than @e total. */ uint32_t transferred_element_count; @@ -665,6 +668,11 @@ handle_bobs_cryptodata_multipart (void *cls, GNUNET_break (0); return GNUNET_SYSERR; } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received %u additional crypto values from Bob\n", + (unsigned int) contained); + payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; /* Convert each k[][perm] to its MPI_value */ for (i = 0; i < contained; i++) @@ -741,6 +749,11 @@ handle_bobs_cryptodata_message (void *cls, GNUNET_break_op (0); return GNUNET_SYSERR; } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received %u crypto values from Bob\n", + (unsigned int) contained); + payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; memcpy (&s->s, &payload[0], @@ -847,6 +860,7 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) unsigned int i; uint32_t todo_count; gcry_mpi_t a; + uint32_t off; s->sorted_elements = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * @@ -862,12 +876,15 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) s->used_element_count, sizeof (struct MpiElement), &element_cmp); - - while (s->transferred_element_count < s->used_element_count) + off = 0; + while (off < s->used_element_count) { - todo_count = s->used_element_count - s->transferred_element_count; + todo_count = s->used_element_count - off; if (todo_count > ELEMENT_CAPACITY) todo_count = ELEMENT_CAPACITY; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending %u crypto values to Bob\n", + (unsigned int) todo_count); e = GNUNET_MQ_msg_extra (msg, todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), @@ -875,7 +892,7 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) msg->contained_element_count = htonl (todo_count); payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; a = gcry_mpi_new (0); - for (i = s->transferred_element_count; i < todo_count; i++) + for (i = off; i < todo_count; i++) { gcry_mpi_add (a, s->sorted_elements[i].value, @@ -883,10 +900,10 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, - &payload[i - s->transferred_element_count]); + &payload[i - off]); } gcry_mpi_release (a); - s->transferred_element_count += todo_count; + off += todo_count; GNUNET_MQ_send (s->cadet_mq, e); } 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 uint32_t used_element_count; /** - * already transferred elements (sent/received) for multipart messages, less or equal than @e used_element_count for + * Already transferred elements (sent/received) for multipart + * messages. First used to count values received from client (less + * than @e total), then used to count values transmitted from Alice + * (less than @e used_element_count)! FIXME: maybe separate this. */ uint32_t transferred_element_count; @@ -530,6 +533,9 @@ transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) if (todo_count > ELEMENT_CAPACITY / 2) todo_count = ELEMENT_CAPACITY / 2; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending %u additional crypto values to Alice\n", + (unsigned int) todo_count); e = GNUNET_MQ_msg_extra (msg, todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 2, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART); @@ -584,11 +590,17 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) (2 + s->transferred_element_count * 2) * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); - msg->total_element_count = htonl (s->total); - msg->used_element_count = htonl (s->used_element_count); + // FIXME: 'total' maybe confusing here, and should already be known to Alice + msg->total_element_count = htonl (s->used_element_count); + // FIXME: redundant! + msg->used_element_count = htonl (s->transferred_element_count); msg->contained_element_count = htonl (s->transferred_element_count); msg->key = s->session_id; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending %u crypto values to Alice\n", + (unsigned int) s->transferred_element_count); + payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; memcpy (&payload[0], &s->s, @@ -834,6 +846,8 @@ static void transmit_cryptographic_reply (struct BobServiceSession *s) { /* TODO: code duplication with Alice! */ + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received everything, building reply for Alice\n"); s->sorted_elements = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * sizeof (struct MpiElement)); @@ -841,9 +855,6 @@ transmit_cryptographic_reply (struct BobServiceSession *s) GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, ©_element_cb, s); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Finished intersection, %d items remain\n", - s->used_element_count); qsort (s->sorted_elements, s->used_element_count, sizeof (struct MpiElement), @@ -911,6 +922,9 @@ handle_alices_cryptodata_message (void *cls, GNUNET_break_op (0); return GNUNET_SYSERR; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received %u crypto values from Alice\n", + (unsigned int) contained_elements); payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; if (NULL == s->e_a) @@ -969,6 +983,9 @@ cb_intersection_element_removed (void *cls, case GNUNET_SET_STATUS_DONE: s->intersection_op = NULL; s->intersection_set = NULL; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Finished intersection, %d items remain\n", + GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); if (s->transferred_element_count == GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)) { @@ -1007,8 +1024,9 @@ static void start_intersection (struct BobServiceSession *s) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got session with key %s and a matching element set, processing.\n", - GNUNET_h2s (&s->session_id)); + "Got session with key %s and %u elements, starting intersection.\n", + GNUNET_h2s (&s->session_id), + (unsigned int) s->transferred_element_count); s->intersection_op = 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" # interactive mode would terminate the test immediately # because the rest of the script is already in stdin, # thus redirecting stdin does not suffice) -GNUNET_LOG='scalarproduct*;;;;DEBUG' +GNUNET_FORCE_LOG='scalarproduct*;;;;DEBUG' GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 & PID=$! # sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe -- cgit v1.2.3