-more SP fixes and todos
authorChristian Grothoff <christian@grothoff.org>
Sun, 7 Dec 2014 01:07:07 +0000 (01:07 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 7 Dec 2014 01:07:07 +0000 (01:07 +0000)
src/include/gnunet_scalarproduct_service.h
src/scalarproduct/gnunet-scalarproduct.c
src/scalarproduct/gnunet-service-scalarproduct_alice.c
src/scalarproduct/gnunet-service-scalarproduct_bob.c
src/scalarproduct/test_scalarproduct.sh

index c96c280c4a850e160d0554520a3684c497312320..9585fbe558c050fb07416501201202e3f65c04e4 100644 (file)
@@ -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;
 };
index c6ed365f85e71c53c9fc1de695a4283571c013e1..f6e7d6af27cff5478c7fce2313e238e7c525d549 100644 (file)
@@ -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;
   }
index b5ab8a88fed88b773fabb96b798003e4c680fc24..e75915f9aa516b589bc1d68f548623561b81fbcd 100644 (file)
@@ -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);
   }
index 23bfcda0e3d5d2c25a7a49443d7ba07c6963a5fa..879e6abbd327e6d4bf24eeab7bd8327e23f0caef 100644 (file)
@@ -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,
                                          &copy_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,
index 8a34c2473c76b129a6f0cfc4374147ada7e5d9fe..562a4f68f0f2350f17453c335d2d90328ee713b1 100755 (executable)
@@ -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