respect new CADET limit
[oweals/gnunet.git] / src / scalarproduct / gnunet-service-scalarproduct_bob.c
index 414e2c603c415d75ca4671a6d2404b366c507b33..2c6d607e58d45164a1f4fd20f547c4c2237bbefe 100644 (file)
@@ -307,6 +307,25 @@ find_matching_cadet_session (const struct GNUNET_HashCode *key)
 }
 
 
+/**
+ * Callback used to free the elements in the map.
+ *
+ * @param cls NULL
+ * @param key key of the element
+ * @param value the value to free
+ */
+static int
+free_element_cb (void *cls,
+                 const struct GNUNET_HashCode *key,
+                 void *value)
+{
+  struct GNUNET_SCALARPRODUCT_Element *element = value;
+
+  GNUNET_free (element);
+  return GNUNET_OK;
+}
+
+
 /**
  * Destroy session state, we are done with it.
  *
@@ -351,7 +370,9 @@ destroy_service_session (struct BobServiceSession *s)
                                                        s));
   if (NULL != s->intersected_elements)
   {
-    /* FIXME: free elements */
+    GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
+                                           &free_element_cb,
+                                           NULL);
     GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements);
     s->intersected_elements = NULL;
   }
@@ -521,7 +542,7 @@ bob_cadet_done_cb (void *cls)
 /**
  * Maximum count of elements we can put into a multipart message
  */
-#define ELEMENT_CAPACITY ((GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct BobCryptodataMultipartMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
+#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - sizeof (struct BobCryptodataMultipartMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
 
 
 /**
@@ -758,6 +779,7 @@ compute_service_response (struct BobServiceSession *session)
                                                         &a[q[i]],
                                                         &r_prime[i]));
   }
+  gcry_mpi_release (tmp);
 
   // Calculate S' =  E(SUM( r_i^2 ))
   tmp = compute_square_sum (rand, count);
@@ -765,6 +787,7 @@ compute_service_response (struct BobServiceSession *session)
                                   tmp,
                                   1,
                                   &session->s_prime);
+  gcry_mpi_release (tmp);
 
   // Calculate S = E(SUM( (r_i + b_i)^2 ))
   for (i = 0; i < count; i++)
@@ -774,6 +797,7 @@ compute_service_response (struct BobServiceSession *session)
                                   tmp,
                                   1,
                                   &session->s);
+  gcry_mpi_release (tmp);
 
   session->r = r;
   session->r_prime = r_prime;
@@ -781,7 +805,6 @@ compute_service_response (struct BobServiceSession *session)
   // release rand, b and a
   for (i = 0; i < count; i++)
     gcry_mpi_release (rand[i]);
-  gcry_mpi_release (tmp);
   GNUNET_free (session->e_a);
   session->e_a = NULL;
   GNUNET_free (p);
@@ -992,7 +1015,7 @@ cb_intersection_element_removed (void *cls,
     return;
   case GNUNET_SET_STATUS_DONE:
     s->intersection_op = NULL;
-    s->intersection_set = NULL;
+    GNUNET_break (NULL == s->intersection_set);
     GNUNET_CADET_receive_done (s->cadet->channel);
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Finished intersection, %d items remain\n",
@@ -1014,7 +1037,11 @@ cb_intersection_element_removed (void *cls,
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Set intersection failed!\n");
     s->intersection_op = NULL;
-    s->intersection_set = NULL;
+    if (NULL != s->intersection_set)
+    {
+      GNUNET_SET_destroy (s->intersection_set);
+      s->intersection_set = NULL;
+    }
     s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
     prepare_client_end_notification (s);
     return;
@@ -1046,8 +1073,17 @@ start_intersection (struct BobServiceSession *s)
                           GNUNET_SET_RESULT_REMOVED,
                           &cb_intersection_element_removed,
                           s);
-  GNUNET_SET_commit (s->intersection_op,
-                     s->intersection_set);
+  if (GNUNET_OK !=
+      GNUNET_SET_commit (s->intersection_op,
+                         s->intersection_set))
+  {
+    GNUNET_break (0);
+    s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
+    prepare_client_end_notification (s);
+    return;
+  }
+  GNUNET_SET_destroy (s->intersection_set);
+  s->intersection_set = NULL;
 }
 
 
@@ -1138,7 +1174,7 @@ cb_channel_incoming (void *cls,
   in = GNUNET_new (struct CadetIncomingSession);
   in->peer = *initiator;
   in->channel = channel;
-  // in->cadet_mq = GNUNET_CADET_mq_create (in->channel);
+  in->cadet_mq = GNUNET_CADET_mq_create (in->channel);
   return in;
 }