gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated: towards converting SP to ne


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: towards converting SP to new CADET API; still fails tests though
Date: Sun, 19 Feb 2017 01:44:40 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 8a946bb7c towards converting SP to new CADET API; still fails tests 
though
8a946bb7c is described below

commit 8a946bb7c2bc6bb863980ecf16607c57c2b077ec
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Feb 19 01:44:37 2017 +0100

    towards converting SP to new CADET API; still fails tests though
---
 src/scalarproduct/.gitignore                       |   1 +
 src/scalarproduct/Makefile.am                      |   8 +-
 .../gnunet-service-scalarproduct-ecc_alice.c       | 113 ++----
 .../gnunet-service-scalarproduct-ecc_bob.c         | 439 ++++++---------------
 .../gnunet-service-scalarproduct_alice.c           | 213 +++++-----
 .../gnunet-service-scalarproduct_bob.c             | 419 +++++---------------
 6 files changed, 363 insertions(+), 830 deletions(-)

diff --git a/src/scalarproduct/.gitignore b/src/scalarproduct/.gitignore
index e244f1108..19909a3f9 100644
--- a/src/scalarproduct/.gitignore
+++ b/src/scalarproduct/.gitignore
@@ -3,3 +3,4 @@ gnunet-scalarproduct
 gnunet-service-scalarproduct-alice
 gnunet-service-scalarproduct-bob
 gnunet-service-scalarproduct-ecc-alice
+test_ecc_scalarproduct
diff --git a/src/scalarproduct/Makefile.am b/src/scalarproduct/Makefile.am
index 10e04284f..98829408a 100644
--- a/src/scalarproduct/Makefile.am
+++ b/src/scalarproduct/Makefile.am
@@ -42,7 +42,7 @@ gnunet_service_scalarproduct_alice_SOURCES = \
   gnunet-service-scalarproduct_alice.c
 gnunet_service_scalarproduct_alice_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/cadet/libgnunetcadet.la \
+  $(top_builddir)/src/cadet/libgnunetcadetnew.la \
   $(top_builddir)/src/set/libgnunetset.la \
   $(LIBGCRYPT_LIBS) \
   -lgcrypt \
@@ -53,7 +53,7 @@ gnunet_service_scalarproduct_bob_SOURCES = \
   gnunet-service-scalarproduct_bob.c
 gnunet_service_scalarproduct_bob_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/cadet/libgnunetcadet.la \
+  $(top_builddir)/src/cadet/libgnunetcadetnew.la \
   $(top_builddir)/src/set/libgnunetset.la \
   $(LIBGCRYPT_LIBS) \
   -lgcrypt \
@@ -64,7 +64,7 @@ gnunet_service_scalarproduct_ecc_alice_SOURCES = \
   gnunet-service-scalarproduct-ecc_alice.c
 gnunet_service_scalarproduct_ecc_alice_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/cadet/libgnunetcadet.la \
+  $(top_builddir)/src/cadet/libgnunetcadetnew.la \
   $(top_builddir)/src/set/libgnunetset.la \
   $(LIBGCRYPT_LIBS) \
   -lgcrypt \
@@ -75,7 +75,7 @@ gnunet_service_scalarproduct_ecc_bob_SOURCES = \
   gnunet-service-scalarproduct-ecc_bob.c
 gnunet_service_scalarproduct_ecc_bob_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/cadet/libgnunetcadet.la \
+  $(top_builddir)/src/cadet/libgnunetcadetnew.la \
   $(top_builddir)/src/set/libgnunetset.la \
   $(LIBGCRYPT_LIBS) \
   -lgcrypt \
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c 
b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
index 0b7f24e7e..79a6c6704 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2013-2016 GNUnet e.V.
+     Copyright (C) 2013-2017 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -238,15 +238,10 @@ destroy_service_session (struct AliceServiceSession *s)
   if (GNUNET_YES == s->in_destroy)
     return;
   s->in_destroy = GNUNET_YES;
-  if (NULL != s->cadet_mq)
-  {
-    GNUNET_MQ_destroy (s->cadet_mq);
-    s->cadet_mq = NULL;
-  }
   if (NULL != s->client)
   {
     struct GNUNET_SERVICE_Client *c = s->client;
-    
+
     s->client = NULL;
     GNUNET_SERVICE_client_drop (c);
   }
@@ -401,34 +396,25 @@ transmit_client_response (struct AliceServiceSession *s)
 }
 
 
-
 /**
  * Function called whenever a channel is destroyed.  Should clean up
  * any associated state.
  *
  * It must NOT call #GNUNET_CADET_channel_destroy() on the channel.
  *
- * @param cls closure (set from #GNUNET_CADET_connect())
+ * @param cls the `struct AliceServiceSession`
  * @param channel connection to the other end (henceforth invalid)
- * @param channel_ctx place where local state associated
- *                   with the channel is stored
  */
 static void
 cb_channel_destruction (void *cls,
-                        const struct GNUNET_CADET_Channel *channel,
-                        void *channel_ctx)
+                        const struct GNUNET_CADET_Channel *channel)
 {
-  struct AliceServiceSession *s = channel_ctx;
+  struct AliceServiceSession *s = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Peer disconnected, terminating session %s with peer %s\n",
               GNUNET_h2s (&s->session_id),
               GNUNET_i2s (&s->peer));
-  if (NULL != s->cadet_mq)
-  {
-    GNUNET_MQ_destroy (s->cadet_mq);
-    s->cadet_mq = NULL;
-  }
   s->channel = NULL;
   if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status)
   {
@@ -492,56 +478,40 @@ compute_scalar_product (struct AliceServiceSession 
*session,
  * Handle a response we got from another service we wanted to
  * calculate a scalarproduct with.
  *
- * @param cls closure (set from #GNUNET_CADET_connect)
- * @param channel connection to the other end
- * @param channel_ctx place to store local state associated with the channel
- * @param message the actual message
- * @return #GNUNET_OK to keep the connection open,
- *         #GNUNET_SYSERR to close it (we are done)
+ * @param cls the `struct AliceServiceSession *`
+ * @param msg the actual message
  */
-static int
+static void
 handle_bobs_cryptodata_message (void *cls,
-                                struct GNUNET_CADET_Channel *channel,
-                                void **channel_ctx,
-                                const struct GNUNET_MessageHeader *message)
+                                const struct EccBobCryptodataMessage *msg)
 {
-  struct AliceServiceSession *s = *channel_ctx;
-  const struct EccBobCryptodataMessage *msg;
-  uint32_t contained;
-  uint16_t msg_size;
+  struct AliceServiceSession *s = cls;
   gcry_mpi_point_t prod_g_i_b_i;
   gcry_mpi_point_t prod_h_i_b_i;
+  uint32_t contained;
 
-  if (NULL == s)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  msg_size = ntohs (message->size);
-  if (sizeof (struct EccBobCryptodataMessage) > msg_size)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  msg = (const struct EccBobCryptodataMessage *) message;
   contained = ntohl (msg->contained_element_count);
   if (2 != contained)
   {
     GNUNET_break_op (0);
-    return GNUNET_SYSERR;
+    destroy_service_session (s);
+    return;
   }
   if (NULL == s->sorted_elements)
   {
     /* we're not ready yet, how can Bob be? */
     GNUNET_break_op (0);
-    return GNUNET_SYSERR;
+    destroy_service_session (s);
+    return;
   }
   if (s->total != s->client_received_element_count)
   {
     /* we're not ready yet, how can Bob be? */
     GNUNET_break_op (0);
-    return GNUNET_SYSERR;
+    destroy_service_session (s);
+    return;
   }
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received %u crypto values from Bob\n",
               (unsigned int) contained);
@@ -556,7 +526,6 @@ handle_bobs_cryptodata_message (void *cls,
   gcry_mpi_point_release (prod_g_i_b_i);
   gcry_mpi_point_release (prod_h_i_b_i);
   transmit_client_response (s);
-  return GNUNET_OK;
 }
 
 
@@ -636,8 +605,8 @@ send_alices_cryptodata_message (struct AliceServiceSession 
*s)
   unsigned int todo_count;
 
   s->sorted_elements
-    = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size 
(s->intersected_elements) *
-                     sizeof (struct MpiElement));
+    = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size 
(s->intersected_elements),
+                        struct MpiElement);
   s->used_element_count = 0;
   GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
                                          &copy_element_cb,
@@ -843,6 +812,13 @@ cb_intersection_request_alice (void *cls,
 static void
 client_request_complete_alice (struct AliceServiceSession *s)
 {
+  struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
+    GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message,
+                             
GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA,
+                             struct EccBobCryptodataMessage,
+                             s),
+    GNUNET_MQ_handler_end ()
+  };
   struct EccServiceRequestMessage *msg;
   struct GNUNET_MQ_Envelope *e;
   struct GNUNET_HashCode set_sid;
@@ -854,18 +830,21 @@ client_request_complete_alice (struct AliceServiceSession 
*s)
               "Creating new channel for session with key %s.\n",
               GNUNET_h2s (&s->session_id));
   s->channel
-    = GNUNET_CADET_channel_create (my_cadet,
+    = GNUNET_CADET_channel_creatE (my_cadet,
                                    s,
                                    &s->peer,
                                    &s->session_id,
-                                   GNUNET_CADET_OPTION_RELIABLE);
+                                   GNUNET_CADET_OPTION_RELIABLE,
+                                   NULL,
+                                   &cb_channel_destruction,
+                                   cadet_handlers);
   if (NULL == s->channel)
   {
     s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
     prepare_client_end_notification (s);
     return;
   }
-  s->cadet_mq = GNUNET_CADET_mq_create (s->channel);
+  s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
   s->intersection_listen
     = GNUNET_SET_listen (cfg,
                          GNUNET_SET_OPERATION_INTERSECTION,
@@ -890,7 +869,7 @@ client_request_complete_alice (struct AliceServiceSession 
*s)
 
 
 /**
- * We're receiving additional set data. Check if 
+ * We're receiving additional set data. Check if
  * @a msg is well-formed.
  *
  * @param cls client identification of the client
@@ -898,7 +877,7 @@ client_request_complete_alice (struct AliceServiceSession 
*s)
  * @return #GNUNET_OK if @a msg is well-formed
  */
 static int
-check_alice_client_message_multipart (void *cls,                               
       
+check_alice_client_message_multipart (void *cls,
                                      const struct 
ComputationBobCryptodataMultipartMessage *msg)
 {
   struct AliceServiceSession *s = cls;
@@ -928,7 +907,7 @@ check_alice_client_message_multipart (void *cls,
  * @param msg the actual message
  */
 static void
-handle_alice_client_message_multipart (void *cls,                              
       
+handle_alice_client_message_multipart (void *cls,
                                       const struct 
ComputationBobCryptodataMultipartMessage *msg)
 {
   struct AliceServiceSession *s = cls;
@@ -983,7 +962,7 @@ handle_alice_client_message_multipart (void *cls,
  * @return #GNUNET_OK if @a msg is well-formed
  */
 static int
-check_alice_client_message (void *cls,                      
+check_alice_client_message (void *cls,
                            const struct AliceComputationMessage *msg)
 {
   struct AliceServiceSession *s = cls;
@@ -1012,7 +991,7 @@ check_alice_client_message (void *cls,
   return GNUNET_OK;
 }
 
-  
+
 /**
  * Handler for Alice's client request message.
  * We are doing request-initiation to compute a scalar product with a peer.
@@ -1021,7 +1000,7 @@ check_alice_client_message (void *cls,
  * @param msg the actual message
  */
 static void
-handle_alice_client_message (void *cls,                             
+handle_alice_client_message (void *cls,
                             const struct AliceComputationMessage *msg)
 {
   struct AliceServiceSession *s = cls;
@@ -1167,13 +1146,6 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *c,
      struct GNUNET_SERVICE_Handle *service)
 {
-  static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
-    { &handle_bobs_cryptodata_message,
-      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA,
-      0},
-    { NULL, 0, 0}
-  };
-
   cfg = c;
   edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT,
                                         MAX_RAM);
@@ -1181,10 +1153,7 @@ run (void *cls,
   GNUNET_CRYPTO_ecc_rnd_mpi (edc,
                              &my_privkey,
                              &my_privkey_inv);
-  my_cadet = GNUNET_CADET_connect (cfg,
-                                  NULL,
-                                   &cb_channel_destruction,
-                                   cadet_handlers);
+  my_cadet = GNUNET_CADET_connecT (cfg);
   if (NULL == my_cadet)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1216,7 +1185,7 @@ GNUNET_SERVICE_MAIN
                        
GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
                        struct ComputationBobCryptodataMultipartMessage,
                        NULL),
-  GNUNET_MQ_handler_end ());
+ GNUNET_MQ_handler_end ());
 
 
 /* end of gnunet-service-scalarproduct-ecc_alice.c */
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c 
b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
index 06e30706e..26468f9e7 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2013-2015 GNUnet e.V.
+     Copyright (C) 2013-2017 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -59,12 +59,6 @@ struct MpiElement
 
 
 /**
- * An incoming session from CADET.
- */
-struct CadetIncomingSession;
-
-
-/**
  * A scalarproduct session which tracks an offer for a
  * multiplication service by a local client.
  */
@@ -72,11 +66,6 @@ struct BobServiceSession
 {
 
   /**
-   * (hopefully) unique transaction ID
-   */
-  struct GNUNET_HashCode session_id;
-
-  /**
    * The client this request is related to.
    */
   struct GNUNET_SERVICE_Client *client;
@@ -124,12 +113,6 @@ struct BobServiceSession
   gcry_mpi_point_t prod_h_i_b_i;
 
   /**
-   * Handle for our associated incoming CADET session, or NULL
-   * if we have not gotten one yet.
-   */
-  struct CadetIncomingSession *cadet;
-
-  /**
    * How many elements will be supplied in total from the client.
    */
   uint32_t total;
@@ -166,20 +149,6 @@ struct BobServiceSession
    */
   int in_destroy;
 
-};
-
-
-/**
- * An incoming session from CADET.
- */
-struct CadetIncomingSession
-{
-
-  /**
-   * Associated client session, or NULL.
-   */
-  struct BobServiceSession *s;
-
   /**
    * The CADET channel.
    */
@@ -200,18 +169,6 @@ struct CadetIncomingSession
    */
   struct GNUNET_MQ_Handle *cadet_mq;
 
-  /**
-   * Has this CADET session been added to the map yet?
-   * #GNUNET_YES if so, in which case @e session_id is
-   * the key.
-   */
-  int in_map;
-
-  /**
-   * Are we already in #destroy_cadet_session()?
-   */
-  int in_destroy;
-
 };
 
 
@@ -221,16 +178,6 @@ struct CadetIncomingSession
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
- * Map of `struct BobServiceSession`, by session keys.
- */
-static struct GNUNET_CONTAINER_MultiHashMap *client_sessions;
-
-/**
- * Map of `struct CadetIncomingSession`, by session keys.
- */
-static struct GNUNET_CONTAINER_MultiHashMap *cadet_sessions;
-
-/**
  * Handle to the CADET service.
  */
 static struct GNUNET_CADET_Handle *my_cadet;
@@ -242,35 +189,6 @@ static struct GNUNET_CRYPTO_EccDlogContext *edc;
 
 
 /**
- * Finds a not terminated client session in the respective map based on
- * session key.
- *
- * @param key the session key we want to search for
- * @return the matching session, or NULL for none
- */
-static struct BobServiceSession *
-find_matching_client_session (const struct GNUNET_HashCode *key)
-{
-  return GNUNET_CONTAINER_multihashmap_get (client_sessions,
-                                            key);
-}
-
-
-/**
- * Finds a CADET session in the respective map based on session key.
- *
- * @param key the session key we want to search for
- * @return the matching session, or NULL for none
- */
-static struct CadetIncomingSession *
-find_matching_cadet_session (const struct GNUNET_HashCode *key)
-{
-  return GNUNET_CONTAINER_multihashmap_get (cadet_sessions,
-                                            key);
-}
-
-
-/**
  * Callback used to free the elements in the map.
  *
  * @param cls NULL
@@ -295,39 +213,20 @@ free_element_cb (void *cls,
  * @param session the session to free elements from
  */
 static void
-destroy_cadet_session (struct CadetIncomingSession *s);
-
-
-/**
- * Destroy session state, we are done with it.
- *
- * @param session the session to free elements from
- */
-static void
 destroy_service_session (struct BobServiceSession *s)
 {
-  struct CadetIncomingSession *in;
   unsigned int i;
 
   if (GNUNET_YES == s->in_destroy)
     return;
   s->in_destroy = GNUNET_YES;
-  if (NULL != (in = s->cadet))
-  {
-    s->cadet = NULL;
-    destroy_cadet_session (in);
-  }
   if (NULL != s->client)
   {
     struct GNUNET_SERVICE_Client *c = s->client;
-    
+
     s->client = NULL;
     GNUNET_SERVICE_client_drop (c);
   }
-  GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multihashmap_remove (client_sessions,
-                                                       &s->session_id,
-                                                       s));
   if (NULL != s->intersected_elements)
   {
     GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
@@ -363,48 +262,17 @@ destroy_service_session (struct BobServiceSession *s)
     gcry_mpi_point_release (s->prod_h_i_b_i);
     s->prod_h_i_b_i = NULL;
   }
-  GNUNET_CADET_close_port (s->port);
-  GNUNET_free (s);
-}
-
-
-/**
- * Destroy incoming CADET session state, we are done with it.
- *
- * @param in the session to free elements from
- */
-static void
-destroy_cadet_session (struct CadetIncomingSession *in)
-{
-  struct BobServiceSession *s;
-
-  if (GNUNET_YES == in->in_destroy)
-    return;
-  in->in_destroy = GNUNET_YES;
-  if (NULL != (s = in->s))
-  {
-    in->s = NULL;
-    destroy_service_session (s);
-  }
-  if (GNUNET_YES == in->in_map)
-  {
-    GNUNET_assert (GNUNET_YES ==
-                   GNUNET_CONTAINER_multihashmap_remove (cadet_sessions,
-                                                         &in->session_id,
-                                                         in));
-    in->in_map = GNUNET_NO;
-  }
-  if (NULL != in->cadet_mq)
+  if (NULL != s->port)
   {
-    GNUNET_MQ_destroy (in->cadet_mq);
-    in->cadet_mq = NULL;
+    GNUNET_CADET_close_port (s->port);
+    s->port = NULL;
   }
-  if (NULL != in->channel)
+  if (NULL != s->channel)
   {
-    GNUNET_CADET_channel_destroy (in->channel);
-    in->channel = NULL;
+    GNUNET_CADET_channel_destroy (s->channel);
+    s->channel = NULL;
   }
-  GNUNET_free (in);
+  GNUNET_free (s);
 }
 
 
@@ -443,38 +311,28 @@ prepare_client_end_notification (struct BobServiceSession 
*session)
  *
  * It must NOT call #GNUNET_CADET_channel_destroy() on the channel.
  *
- * @param cls closure (set from #GNUNET_CADET_connect())
+ * @param cls the `struct BobServiceSession`
  * @param channel connection to the other end (henceforth invalid)
  * @param channel_ctx place where local state associated
  *                   with the channel is stored
  */
 static void
 cb_channel_destruction (void *cls,
-                        const struct GNUNET_CADET_Channel *channel,
-                        void *channel_ctx)
+                        const struct GNUNET_CADET_Channel *channel)
 {
-  struct CadetIncomingSession *in = channel_ctx;
-  struct BobServiceSession *s;
+  struct BobServiceSession *s = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Peer disconnected, terminating session %s with peer %s\n",
-              GNUNET_h2s (&in->session_id),
-              GNUNET_i2s (&in->peer));
-  if (NULL != in->cadet_mq)
-  {
-    GNUNET_MQ_destroy (in->cadet_mq);
-    in->cadet_mq = NULL;
-  }
-  in->channel = NULL;
-  if (NULL != (s = in->s))
+              GNUNET_h2s (&s->session_id),
+              GNUNET_i2s (&s->peer));
+  s->channel = NULL;
+  if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status)
   {
-    if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status)
-    {
-      s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
-      prepare_client_end_notification (s);
-    }
+    s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
+    prepare_client_end_notification (s);
   }
-  destroy_cadet_session (in);
+  destroy_service_session (s);
 }
 
 
@@ -519,7 +377,7 @@ transmit_bobs_cryptodata_message (struct BobServiceSession 
*s)
   GNUNET_MQ_notify_sent (e,
                          &bob_cadet_done_cb,
                          s);
-  GNUNET_MQ_send (s->cadet->cadet_mq,
+  GNUNET_MQ_send (s->cadet_mq,
                   e);
 }
 
@@ -577,56 +435,79 @@ element_cmp (const void *a,
 
 
 /**
- * Handle a multipart-chunk of a request from another service to
+ * Check a multipart-chunk of a request from another service to
  * calculate a scalarproduct with us.
  *
  * @param cls closure (set from #GNUNET_CADET_connect)
- * @param channel connection to the other end
- * @param channel_ctx place to store local state associated with the @a channel
- * @param message the actual message
+ * @param msg the actual message
  * @return #GNUNET_OK to keep the connection open,
  *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-handle_alices_cryptodata_message (void *cls,
-                                  struct GNUNET_CADET_Channel *channel,
-                                  void **channel_ctx,
-                                  const struct GNUNET_MessageHeader *message)
+check_alices_cryptodata_message (void *cls,
+                                 const struct EccAliceCryptodataMessage *msg)
 {
-  struct CadetIncomingSession *in = *channel_ctx;
-  struct BobServiceSession *s;
-  const struct EccAliceCryptodataMessage *msg;
-  const struct GNUNET_CRYPTO_EccPoint *payload;
+  struct BobServiceSession *s = cls;
   uint32_t contained_elements;
   size_t msg_length;
   uint16_t msize;
   unsigned int max;
-  unsigned int i;
-  const struct MpiElement *b_i;
-  gcry_mpi_point_t tmp;
-  gcry_mpi_point_t g_i;
-  gcry_mpi_point_t h_i;
-  gcry_mpi_point_t g_i_b_i;
-  gcry_mpi_point_t h_i_b_i;
 
-  /* sanity checks */
-  if (NULL == in)
+  msize = ntohs (msg->header.size);
+  if (msize <= sizeof (struct EccAliceCryptodataMessage))
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  s = in->s;
-  if (NULL == s)
+  contained_elements = ntohl (msg->contained_element_count);
+  /* Our intersection may still be ongoing, but this is nevertheless
+     an upper bound on the required array size */
+  max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements);
+  msg_length = sizeof (struct EccAliceCryptodataMessage)
+    + contained_elements * sizeof (struct GNUNET_CRYPTO_EccPoint) * 2;
+  if ( (msize != msg_length) ||
+       (0 == contained_elements) ||
+       (contained_elements > UINT16_MAX) ||
+       (max < contained_elements + s->cadet_received_element_count) )
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
+  return GNUNET_OK;
+}
+
+
+/**
+ * Handle a multipart-chunk of a request from another service to
+ * calculate a scalarproduct with us.
+ *
+ * @param cls closure (set from #GNUNET_CADET_connect)
+ * @param msg the actual message
+ */
+static void
+handle_alices_cryptodata_message (void *cls,
+                                  const struct EccAliceCryptodataMessage *msg)
+{
+  struct BobServiceSession *s = cls;
+  const struct GNUNET_CRYPTO_EccPoint *payload;
+  uint32_t contained_elements;
+  unsigned int max;
+  unsigned int i;
+  const struct MpiElement *b_i;
+  gcry_mpi_point_t tmp;
+  gcry_mpi_point_t g_i;
+  gcry_mpi_point_t h_i;
+  gcry_mpi_point_t g_i_b_i;
+  gcry_mpi_point_t h_i_b_i;
+
+  contained_elements = ntohl (msg->contained_element_count);
+  max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements);
   /* sort our vector for the computation */
   if (NULL == s->sorted_elements)
   {
     s->sorted_elements
-      = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size 
(s->intersected_elements) *
-                       sizeof (struct MpiElement));
+      = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size 
(s->intersected_elements),
+                          struct MpiElement);
     s->used_element_count = 0;
     GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
                                            &copy_element_cb,
@@ -637,28 +518,6 @@ handle_alices_cryptodata_message (void *cls,
            &element_cmp);
   }
 
-  /* parse message */
-  msize = ntohs (message->size);
-  if (msize <= sizeof (struct EccAliceCryptodataMessage))
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  msg = (const struct EccAliceCryptodataMessage *) message;
-  contained_elements = ntohl (msg->contained_element_count);
-  /* Our intersection may still be ongoing, but this is nevertheless
-     an upper bound on the required array size */
-  max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements);
-  msg_length = sizeof (struct EccAliceCryptodataMessage)
-    + contained_elements * sizeof (struct GNUNET_CRYPTO_EccPoint) * 2;
-  if ( (msize != msg_length) ||
-       (0 == contained_elements) ||
-       (contained_elements > UINT16_MAX) ||
-       (max < contained_elements + s->cadet_received_element_count) )
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received %u crypto values from Alice\n",
               (unsigned int) contained_elements);
@@ -711,8 +570,7 @@ handle_alices_cryptodata_message (void *cls,
        CADET response(s) */
     transmit_bobs_cryptodata_message (s);
   }
-  GNUNET_CADET_receive_done (s->cadet->channel);
-  return GNUNET_OK;
+  GNUNET_CADET_receive_done (s->channel);
 }
 
 
@@ -752,7 +610,7 @@ cb_intersection_element_removed (void *cls,
   case GNUNET_SET_STATUS_DONE:
     s->intersection_op = NULL;
     GNUNET_break (NULL == s->intersection_set);
-    GNUNET_CADET_receive_done (s->cadet->channel);
+    GNUNET_CADET_receive_done (s->channel);
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Finished intersection, %d items remain\n",
          GNUNET_CONTAINER_multihashmap_size (s->intersected_elements));
@@ -808,7 +666,7 @@ start_intersection (struct BobServiceSession *s)
               (unsigned int) s->total);
 
   s->intersection_op
-    = GNUNET_SET_prepare (&s->cadet->peer,
+    = GNUNET_SET_prepare (&s->peer,
                           &set_sid,
                           NULL,
                           GNUNET_SET_RESULT_REMOVED,
@@ -832,53 +690,17 @@ start_intersection (struct BobServiceSession *s)
  * Handle a request from Alice to calculate a scalarproduct with us (Bob).
  *
  * @param cls closure (set from #GNUNET_CADET_connect)
- * @param channel connection to the other end
- * @param channel_ctx place to store the `struct CadetIncomingSession *`
- * @param message the actual message
- * @return #GNUNET_OK to keep the connection open,
- *         #GNUNET_SYSERR to close it (signal serious error)
+ * @param msg the actual message
  */
-static int
+static void
 handle_alices_computation_request (void *cls,
-                                   struct GNUNET_CADET_Channel *channel,
-                                   void **channel_ctx,
-                                   const struct GNUNET_MessageHeader *message)
+                                   const struct EccServiceRequestMessage *msg)
 {
-  struct CadetIncomingSession *in = *channel_ctx;
-  struct BobServiceSession *s;
-  const struct EccServiceRequestMessage *msg;
+  struct BobServiceSession *s = cls;
 
-  msg = (const struct EccServiceRequestMessage *) message;
-  if (GNUNET_YES == in->in_map)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  if (NULL != find_matching_cadet_session (&msg->session_id))
-  {
-    /* not unique, got one like this already */
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  in->session_id = msg->session_id;
-  GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multihashmap_put (cadet_sessions,
-                                                    &in->session_id,
-                                                    in,
-                                                    
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-  s = find_matching_client_session (&in->session_id);
-  if (NULL == s)
-  {
-    /* no client waiting for this request, wait for client */
-    return GNUNET_OK;
-  }
-  GNUNET_assert (NULL == s->cadet);
-  /* pair them up */
-  in->s = s;
-  s->cadet = in;
+  s->session_id = msg->session_id; // ??
   if (s->client_received_element_count == s->total)
     start_intersection (s);
-  return GNUNET_OK;
 }
 
 
@@ -887,30 +709,27 @@ handle_alices_computation_request (void *cls,
  * preliminary initialization, more happens after we get Alice's first
  * message.
  *
- * @param cls closure
+ * @param cls our `struct BobServiceSession`
  * @param channel new handle to the channel
  * @param initiator peer that started the channel
- * @param port unused
- * @param options unused
  * @return session associated with the channel
  */
 static void *
 cb_channel_incoming (void *cls,
                      struct GNUNET_CADET_Channel *channel,
-                     const struct GNUNET_PeerIdentity *initiator,
-                     const struct GNUNET_HashCode *port,
-                     enum GNUNET_CADET_ChannelOption options)
+                     const struct GNUNET_PeerIdentity *initiator)
 {
-  struct CadetIncomingSession *in;
+  struct BobServiceSession *s = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "New incoming channel from peer %s.\n",
               GNUNET_i2s (initiator));
-  in = GNUNET_new (struct CadetIncomingSession);
-  in->peer = *initiator;
-  in->channel = channel;
-  in->cadet_mq = GNUNET_CADET_mq_create (in->channel);
-  return in;
+  GNUNET_CADET_close_port (s->port);
+  s->port = NULL;
+  s->peer = *initiator;
+  s->channel = channel;
+  s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
+  return s;
 }
 
 
@@ -994,7 +813,7 @@ handle_bob_client_message_multipart (void *cls,
     /* more to come */
     return;
   }
-  if (NULL == s->cadet)
+  if (NULL == s->channel)
   {
     /* no Alice waiting for this request, wait for Alice */
     return;
@@ -1037,11 +856,6 @@ check_bob_client_message (void *cls,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  if (NULL != find_matching_client_session (&msg->session_key))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
   return GNUNET_OK;
 }
 
@@ -1059,7 +873,17 @@ handle_bob_client_message (void *cls,
                           const struct BobComputationMessage *msg)
 {
   struct BobServiceSession *s = cls;
-  struct CadetIncomingSession *in;
+  struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
+    GNUNET_MQ_hd_fixed_size (alices_computation_request,
+                             
GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION,
+                             struct EccServiceRequestMessage,
+                             s),
+    GNUNET_MQ_hd_var_size (alices_cryptodata_message,
+                           
GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA,
+                           struct EccAliceCryptodataMessage,
+                           s),
+    GNUNET_MQ_handler_end ()
+  };
   uint32_t contained_count;
   uint32_t total_count;
   const struct GNUNET_SCALARPRODUCT_Element *elements;
@@ -1073,21 +897,6 @@ handle_bob_client_message (void *cls,
   s->total = total_count;
   s->client_received_element_count = contained_count;
   s->session_id = msg->session_key;
-  s->port = GNUNET_CADET_open_port (my_cadet,
-                                    &msg->session_key,
-                                    &cb_channel_incoming,
-                                    s);
-  if (NULL == s->port)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (s->client);
-    return;
-  }
-  GNUNET_break (GNUNET_YES ==
-                GNUNET_CONTAINER_multihashmap_put (client_sessions,
-                                                   &s->session_id,
-                                                   s,
-                                                   
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
   s->intersected_elements
     = GNUNET_CONTAINER_multihashmap_create (s->total,
@@ -1122,22 +931,19 @@ handle_bob_client_message (void *cls,
     s->used_element_count++;
   }
   GNUNET_SERVICE_client_continue (s->client);
-  if (s->total != s->client_received_element_count)
-  {
-    /* multipart msg */
-    return;
-  }
-  in = find_matching_cadet_session (&s->session_id);
-  if (NULL == in)
+  s->port = GNUNET_CADET_open_porT (my_cadet,
+                                    &msg->session_key,
+                                    &cb_channel_incoming,
+                                    s,
+                                    NULL,
+                                    &cb_channel_destruction,
+                                    cadet_handlers);
+  if (NULL == s->port)
   {
-    /* nothing yet, wait for Alice */
+    GNUNET_break (0);
+    GNUNET_SERVICE_client_drop (s->client);
     return;
   }
-  GNUNET_assert (NULL == in->s);
-  /* pair them up */
-  in->s = s;
-  s->cadet = in;
-  start_intersection (s);
 }
 
 
@@ -1162,10 +968,6 @@ shutdown_task (void *cls)
     GNUNET_CRYPTO_ecc_dlog_release (edc);
     edc = NULL;
   }
-  GNUNET_CONTAINER_multihashmap_destroy (client_sessions);
-  client_sessions = NULL;
-  GNUNET_CONTAINER_multihashmap_destroy (cadet_sessions);
-  cadet_sessions = NULL;
 }
 
 
@@ -1229,28 +1031,11 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *c,
      struct GNUNET_SERVICE_Handle *service)
 {
-  static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
-    { &handle_alices_computation_request,
-      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION,
-      sizeof (struct EccServiceRequestMessage) },
-    { &handle_alices_cryptodata_message,
-      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA,
-      0},
-    { NULL, 0, 0}
-  };
-
   cfg = c;
   /* We don't really do DLOG, so we can setup with very minimal resources */
   edc = GNUNET_CRYPTO_ecc_dlog_prepare (4 /* max value */,
                                         2 /* RAM */);
-  client_sessions = GNUNET_CONTAINER_multihashmap_create (128,
-                                                          GNUNET_YES);
-  cadet_sessions = GNUNET_CONTAINER_multihashmap_create (128,
-                                                         GNUNET_YES);
-  my_cadet = GNUNET_CADET_connect (cfg, 
-                                  NULL,
-                                   &cb_channel_destruction,
-                                   cadet_handlers);
+  my_cadet = GNUNET_CADET_connecT (cfg);
   GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
                                 NULL);
   if (NULL == my_cadet)
@@ -1277,10 +1062,10 @@ GNUNET_SERVICE_MAIN
                        GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB,
                        struct BobComputationMessage,
                        NULL),
-GNUNET_MQ_hd_var_size (bob_client_message_multipart,
-                      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB,
-                      struct ComputationBobCryptodataMultipartMessage,
-                      NULL),
+ GNUNET_MQ_hd_var_size (bob_client_message_multipart,
+                        GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB,
+                        struct ComputationBobCryptodataMultipartMessage,
+                        NULL),
  GNUNET_MQ_handler_end ());
 
 
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c 
b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index 45d1f4e2c..779d84b60 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2013, 2014 GNUnet e.V.
+     Copyright (C) 2013, 2014, 2017 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -248,15 +248,10 @@ destroy_service_session (struct AliceServiceSession *s)
   if (GNUNET_YES == s->in_destroy)
     return;
   s->in_destroy = GNUNET_YES;
-  if (NULL != s->cadet_mq)
-  {
-    GNUNET_MQ_destroy (s->cadet_mq);
-    s->cadet_mq = NULL;
-  }
   if (NULL != s->client)
   {
     struct GNUNET_SERVICE_Client *c = s->client;
-    
+
     s->client = NULL;
     GNUNET_SERVICE_client_drop (c);
   }
@@ -428,17 +423,14 @@ transmit_client_response (struct AliceServiceSession *s)
  *
  * It must NOT call #GNUNET_CADET_channel_destroy() on the channel.
  *
- * @param cls closure (set from #GNUNET_CADET_connect())
+ * @param cls our `struct AliceServiceSession`
  * @param channel connection to the other end (henceforth invalid)
- * @param channel_ctx place where local state associated
- *                   with the channel is stored
  */
 static void
 cb_channel_destruction (void *cls,
-                        const struct GNUNET_CADET_Channel *channel,
-                        void *channel_ctx)
+                        const struct GNUNET_CADET_Channel *channel)
 {
-  struct AliceServiceSession *s = channel_ctx;
+  struct AliceServiceSession *s = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Peer disconnected, terminating session %s with peer %s\n",
@@ -450,11 +442,6 @@ cb_channel_destruction (void *cls,
     s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
     prepare_client_end_notification (s);
   }
-  if (NULL != s->cadet_mq)
-  {
-    GNUNET_MQ_destroy (s->cadet_mq);
-    s->cadet_mq = NULL;
-  }
   s->channel = NULL;
 }
 
@@ -633,42 +620,24 @@ compute_scalar_product (struct AliceServiceSession 
*session)
 
 
 /**
- * Handle a multipart chunk of a response we got from another service
+ * Check a multipart chunk of a response we got from another service
  * we wanted to calculate a scalarproduct with.
  *
- * @param cls closure (set from #GNUNET_CADET_connect)
- * @param channel connection to the other end
- * @param channel_ctx place to store local state associated with the @a channel
- * @param message the actual message
+ * @param cls the `struct AliceServiceSession`
+ * @param msg the actual message
  * @return #GNUNET_OK to keep the connection open,
  *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-handle_bobs_cryptodata_multipart (void *cls,
-                                  struct GNUNET_CADET_Channel *channel,
-                                  void **channel_ctx,
-                                  const struct GNUNET_MessageHeader *message)
+check_bobs_cryptodata_multipart (void *cls,
+                                 const struct BobCryptodataMultipartMessage 
*msg)
 {
-  struct AliceServiceSession *s = *channel_ctx;
-  const struct BobCryptodataMultipartMessage *msg;
-  const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
-  size_t i;
+  struct AliceServiceSession *s = cls;
   uint32_t contained;
   size_t msg_size;
   size_t required_size;
 
-  if (NULL == s)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  msg_size = ntohs (message->size);
-  if (sizeof (struct BobCryptodataMultipartMessage) > msg_size)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  msg = (const struct BobCryptodataMultipartMessage *) message;
+  msg_size = ntohs (msg->header.size);
   contained = ntohl (msg->contained_element_count);
   required_size = sizeof (struct BobCryptodataMultipartMessage)
     + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
@@ -678,7 +647,26 @@ handle_bobs_cryptodata_multipart (void *cls,
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
+  return GNUNET_OK;
+}
 
+/**
+ * Handle a multipart chunk of a response we got from another service
+ * we wanted to calculate a scalarproduct with.
+ *
+ * @param cls the `struct AliceServiceSession`
+ * @param msg the actual message
+ */
+static void
+handle_bobs_cryptodata_multipart (void *cls,
+                                  const struct BobCryptodataMultipartMessage 
*msg)
+{
+  struct AliceServiceSession *s = cls;
+  const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
+  size_t i;
+  uint32_t contained;
+
+  contained = ntohl (msg->contained_element_count);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received %u additional crypto values from Bob\n",
               (unsigned int) contained);
@@ -688,60 +676,41 @@ handle_bobs_cryptodata_multipart (void *cls,
   for (i = 0; i < contained; i++)
   {
     GNUNET_memcpy (&s->r[s->cadet_received_element_count + i],
-            &payload[2 * i],
-            sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+                   &payload[2 * i],
+                   sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
     GNUNET_memcpy (&s->r_prime[s->cadet_received_element_count + i],
-            &payload[2 * i],
-            sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+                   &payload[2 * i],
+                   sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
   }
   s->cadet_received_element_count += contained;
   GNUNET_CADET_receive_done (s->channel);
   if (s->cadet_received_element_count != s->used_element_count)
-    return GNUNET_OK;
+    return; /* more to come */
 
   s->product = compute_scalar_product (s);
   transmit_client_response (s);
-  return GNUNET_OK;
 }
 
 
 /**
- * Handle a response we got from another service we wanted to
+ * Check a response we got from another service we wanted to
  * calculate a scalarproduct with.
  *
- * @param cls closure (set from #GNUNET_CADET_connect)
- * @param channel connection to the other end
- * @param channel_ctx place to store local state associated with the channel
+ * @param cls our `struct AliceServiceSession`
  * @param message the actual message
  * @return #GNUNET_OK to keep the connection open,
  *         #GNUNET_SYSERR to close it (we are done)
  */
 static int
-handle_bobs_cryptodata_message (void *cls,
-                                struct GNUNET_CADET_Channel *channel,
-                                void **channel_ctx,
-                                const struct GNUNET_MessageHeader *message)
+check_bobs_cryptodata_message (void *cls,
+                               const struct BobCryptodataMessage *msg)
 {
-  struct AliceServiceSession *s = *channel_ctx;
-  const struct BobCryptodataMessage *msg;
-  const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
-  uint32_t i;
+  struct AliceServiceSession *s = cls;
   uint32_t contained;
   uint16_t msg_size;
   size_t required_size;
 
-  if (NULL == s)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  msg_size = ntohs (message->size);
-  if (sizeof (struct BobCryptodataMessage) > msg_size)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  msg = (const struct BobCryptodataMessage *) message;
+  msg_size = ntohs (msg->header.size);
   contained = ntohl (msg->contained_element_count);
   required_size = sizeof (struct BobCryptodataMessage)
     + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)
@@ -765,29 +734,51 @@ handle_bobs_cryptodata_message (void *cls,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
+  return GNUNET_OK;
+}
+
+
+/**
+ * Handle a response we got from another service we wanted to
+ * calculate a scalarproduct with.
+ *
+ * @param cls our `struct AliceServiceSession`
+ * @param msg the actual message
+ */
+static void
+handle_bobs_cryptodata_message (void *cls,
+                                const struct BobCryptodataMessage *msg)
+{
+  struct AliceServiceSession *s = cls;
+  const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
+  uint32_t i;
+  uint32_t contained;
+
+  contained = ntohl (msg->contained_element_count);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received %u crypto values from Bob\n",
               (unsigned int) contained);
-
   payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
   GNUNET_memcpy (&s->s,
-          &payload[0],
-          sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+                 &payload[0],
+                 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
   GNUNET_memcpy (&s->s_prime,
-          &payload[1],
-          sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+                 &payload[1],
+                 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
   payload = &payload[2];
 
-  s->r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 
s->used_element_count);
-  s->r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) 
* s->used_element_count);
+  s->r = GNUNET_new_array (s->used_element_count,
+                           struct GNUNET_CRYPTO_PaillierCiphertext);
+  s->r_prime = GNUNET_new_array (s->used_element_count,
+                                 struct GNUNET_CRYPTO_PaillierCiphertext);
   for (i = 0; i < contained; i++)
   {
     GNUNET_memcpy (&s->r[i],
-            &payload[2 * i],
-            sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+                   &payload[2 * i],
+                   sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
     GNUNET_memcpy (&s->r_prime[i],
-            &payload[2 * i + 1],
-            sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+                   &payload[2 * i + 1],
+                   sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
   }
   s->cadet_received_element_count = contained;
   GNUNET_CADET_receive_done (s->channel);
@@ -795,12 +786,10 @@ handle_bobs_cryptodata_message (void *cls,
   if (s->cadet_received_element_count != s->used_element_count)
   {
     /* More to come */
-    return GNUNET_OK;
+    return;
   }
-
   s->product = compute_scalar_product (s);
   transmit_client_response (s);
-  return GNUNET_OK;
 }
 
 
@@ -1066,6 +1055,17 @@ cb_intersection_request_alice (void *cls,
 static void
 client_request_complete_alice (struct AliceServiceSession *s)
 {
+  struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
+    GNUNET_MQ_hd_var_size (bobs_cryptodata_message,
+                           GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
+                           struct BobCryptodataMessage,
+                           s),
+    GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart,
+                           
GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
+                           struct BobCryptodataMultipartMessage,
+                           s),
+    GNUNET_MQ_handler_end ()
+  };
   struct ServiceRequestMessage *msg;
   struct GNUNET_MQ_Envelope *e;
 
@@ -1073,18 +1073,21 @@ client_request_complete_alice (struct 
AliceServiceSession *s)
               "Creating new channel for session with key %s.\n",
               GNUNET_h2s (&s->session_id));
   s->channel
-    = GNUNET_CADET_channel_create (my_cadet,
+    = GNUNET_CADET_channel_creatE (my_cadet,
                                    s,
                                    &s->peer,
                                    &s->session_id,
-                                   GNUNET_CADET_OPTION_RELIABLE);
+                                   GNUNET_CADET_OPTION_RELIABLE,
+                                   NULL,
+                                   &cb_channel_destruction,
+                                   cadet_handlers);
   if (NULL == s->channel)
   {
     s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
     prepare_client_end_notification (s);
     return;
   }
-  s->cadet_mq = GNUNET_CADET_mq_create (s->channel);
+  s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
   s->intersection_listen
     = GNUNET_SET_listen (cfg,
                          GNUNET_SET_OPERATION_INTERSECTION,
@@ -1110,7 +1113,7 @@ client_request_complete_alice (struct AliceServiceSession 
*s)
 
 
 /**
- * We're receiving additional set data. Check if 
+ * We're receiving additional set data. Check if
  * @a msg is well-formed.
  *
  * @param cls client identification of the client
@@ -1118,7 +1121,7 @@ client_request_complete_alice (struct AliceServiceSession 
*s)
  * @return #GNUNET_OK if @a msg is well-formed
  */
 static int
-check_alice_client_message_multipart (void *cls,                               
       
+check_alice_client_message_multipart (void *cls,
                                      const struct 
ComputationBobCryptodataMultipartMessage *msg)
 {
   struct AliceServiceSession *s = cls;
@@ -1148,7 +1151,7 @@ check_alice_client_message_multipart (void *cls,
  * @param msg the actual message
  */
 static void
-handle_alice_client_message_multipart (void *cls,                              
       
+handle_alice_client_message_multipart (void *cls,
                                       const struct 
ComputationBobCryptodataMultipartMessage *msg)
 {
   struct AliceServiceSession *s = cls;
@@ -1203,7 +1206,7 @@ handle_alice_client_message_multipart (void *cls,
  * @return #GNUNET_OK if @a msg is well-formed
  */
 static int
-check_alice_client_message (void *cls,                      
+check_alice_client_message (void *cls,
                            const struct AliceComputationMessage *msg)
 {
   struct AliceServiceSession *s = cls;
@@ -1232,7 +1235,7 @@ check_alice_client_message (void *cls,
   return GNUNET_OK;
 }
 
-  
+
 /**
  * Handler for Alice's client request message.
  * We are doing request-initiation to compute a scalar product with a peer.
@@ -1241,7 +1244,7 @@ check_alice_client_message (void *cls,
  * @param msg the actual message
  */
 static void
-handle_alice_client_message (void *cls,                             
+handle_alice_client_message (void *cls,
                             const struct AliceComputationMessage *msg)
 {
   struct AliceServiceSession *s = cls;
@@ -1382,16 +1385,6 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *c,
      struct GNUNET_SERVICE_Handle *service)
 {
-  static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
-    { &handle_bobs_cryptodata_message,
-      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
-      0},
-    { &handle_bobs_cryptodata_multipart,
-      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
-      0},
-    { NULL, 0, 0}
-  };
-
   cfg = c;
   /*
     offset has to be sufficiently small to allow computation of:
@@ -1400,13 +1393,9 @@ run (void *cls,
   my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3);
   gcry_mpi_set_bit (my_offset,
                     GNUNET_CRYPTO_PAILLIER_BITS / 3);
-
   GNUNET_CRYPTO_paillier_create (&my_pubkey,
                                  &my_privkey);
-  my_cadet = GNUNET_CADET_connect (cfg,
-                                  NULL,
-                                   &cb_channel_destruction,
-                                   cadet_handlers);
+  my_cadet = GNUNET_CADET_connecT (cfg);
   GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
                                 NULL);
   if (NULL == my_cadet)
@@ -1437,7 +1426,7 @@ GNUNET_SERVICE_MAIN
                        
GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
                        struct ComputationBobCryptodataMultipartMessage,
                        NULL),
-  GNUNET_MQ_handler_end ());
+ GNUNET_MQ_handler_end ());
 
 
 /* end of gnunet-service-scalarproduct_alice.c */
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c 
b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
index 56cb91fe5..a2bceba43 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
@@ -59,12 +59,6 @@ struct MpiElement
 
 
 /**
- * An incoming session from CADET.
- */
-struct CadetIncomingSession;
-
-
-/**
  * A scalarproduct session which tracks an offer for a
  * multiplication service by a local client.
  */
@@ -187,20 +181,6 @@ struct BobServiceSession
    */
   int in_destroy;
 
-};
-
-
-/**
- * An incoming session from CADET.
- */
-struct CadetIncomingSession
-{
-
-  /**
-   * Associated client session, or NULL.
-   */
-  struct BobServiceSession *s;
-
   /**
    * The CADET channel.
    */
@@ -212,11 +192,6 @@ struct CadetIncomingSession
   struct GNUNET_PeerIdentity peer;
 
   /**
-   * (hopefully) unique transaction ID
-   */
-  struct GNUNET_HashCode session_id;
-
-  /**
    * Public key of the remote service.
    */
   struct GNUNET_CRYPTO_PaillierPublicKey remote_pubkey;
@@ -226,21 +201,10 @@ struct CadetIncomingSession
    */
   struct GNUNET_MQ_Handle *cadet_mq;
 
-  /**
-   * Has this CADET session been added to the map yet?
-   * #GNUNET_YES if so, in which case @e session_id is
-   * the key.
-   */
-  int in_map;
-
-  /**
-   * Are we already in #destroy_cadet_session()?
-   */
-  int in_destroy;
-
 };
 
 
+
 /**
  * GNUnet configuration handle
  */
@@ -262,51 +226,11 @@ static struct GNUNET_CRYPTO_PaillierPrivateKey my_privkey;
 static gcry_mpi_t my_offset;
 
 /**
- * Map of `struct BobServiceSession`, by session keys.
- */
-static struct GNUNET_CONTAINER_MultiHashMap *client_sessions;
-
-/**
- * Map of `struct CadetIncomingSession`, by session keys.
- */
-static struct GNUNET_CONTAINER_MultiHashMap *cadet_sessions;
-
-/**
  * Handle to the CADET service.
  */
 static struct GNUNET_CADET_Handle *my_cadet;
 
 
-
-/**
- * Finds a not terminated client session in the respective map based on
- * session key.
- *
- * @param key the session key we want to search for
- * @return the matching session, or NULL for none
- */
-static struct BobServiceSession *
-find_matching_client_session (const struct GNUNET_HashCode *key)
-{
-  return GNUNET_CONTAINER_multihashmap_get (client_sessions,
-                                            key);
-}
-
-
-/**
- * Finds a CADET session in the respective map based on session key.
- *
- * @param key the session key we want to search for
- * @return the matching session, or NULL for none
- */
-static struct CadetIncomingSession *
-find_matching_cadet_session (const struct GNUNET_HashCode *key)
-{
-  return GNUNET_CONTAINER_multihashmap_get (cadet_sessions,
-                                            key);
-}
-
-
 /**
  * Callback used to free the elements in the map.
  *
@@ -332,39 +256,20 @@ free_element_cb (void *cls,
  * @param session the session to free elements from
  */
 static void
-destroy_cadet_session (struct CadetIncomingSession *s);
-
-
-/**
- * Destroy session state, we are done with it.
- *
- * @param session the session to free elements from
- */
-static void
 destroy_service_session (struct BobServiceSession *s)
 {
-  struct CadetIncomingSession *in;
   unsigned int i;
 
   if (GNUNET_YES == s->in_destroy)
     return;
   s->in_destroy = GNUNET_YES;
-  if (NULL != (in = s->cadet))
-  {
-    s->cadet = NULL;
-    destroy_cadet_session (in);
-  }
   if (NULL != s->client)
   {
     struct GNUNET_SERVICE_Client *c = s->client;
-    
+
     s->client = NULL;
     GNUNET_SERVICE_client_drop (c);
   }
-  GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multihashmap_remove (client_sessions,
-                                                       &s->session_id,
-                                                       s));
   if (NULL != s->intersected_elements)
   {
     GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
@@ -405,48 +310,17 @@ destroy_service_session (struct BobServiceSession *s)
     GNUNET_free (s->r_prime);
     s->r_prime = NULL;
   }
-  GNUNET_CADET_close_port (s->port);
-  GNUNET_free (s);
-}
-
-
-/**
- * Destroy incoming CADET session state, we are done with it.
- *
- * @param in the session to free elements from
- */
-static void
-destroy_cadet_session (struct CadetIncomingSession *in)
-{
-  struct BobServiceSession *s;
-
-  if (GNUNET_YES == in->in_destroy)
-    return;
-  in->in_destroy = GNUNET_YES;
-  if (NULL != (s = in->s))
+  if (NULL != s->port)
   {
-    in->s = NULL;
-    destroy_service_session (s);
+    GNUNET_CADET_close_port (s->port);
+    s->port = NULL;
   }
-  if (GNUNET_YES == in->in_map)
+  if (NULL != s->channel)
   {
-    GNUNET_assert (GNUNET_YES ==
-                   GNUNET_CONTAINER_multihashmap_remove (cadet_sessions,
-                                                         &in->session_id,
-                                                         in));
-    in->in_map = GNUNET_NO;
+    GNUNET_CADET_channel_destroy (s->channel);
+    s->channel = NULL;
   }
-  if (NULL != in->cadet_mq)
-  {
-    GNUNET_MQ_destroy (in->cadet_mq);
-    in->cadet_mq = NULL;
-  }
-  if (NULL != in->channel)
-  {
-    GNUNET_CADET_channel_destroy (in->channel);
-    in->channel = NULL;
-  }
-  GNUNET_free (in);
+  GNUNET_free (s);
 }
 
 
@@ -485,38 +359,26 @@ prepare_client_end_notification (struct BobServiceSession 
*session)
  *
  * It must NOT call #GNUNET_CADET_channel_destroy() on the channel.
  *
- * @param cls closure (set from #GNUNET_CADET_connect())
+ * @param cls the `struct BobServiceSession`
  * @param channel connection to the other end (henceforth invalid)
- * @param channel_ctx place where local state associated
- *                   with the channel is stored
  */
 static void
 cb_channel_destruction (void *cls,
-                        const struct GNUNET_CADET_Channel *channel,
-                        void *channel_ctx)
+                        const struct GNUNET_CADET_Channel *channel)
 {
-  struct CadetIncomingSession *in = channel_ctx;
-  struct BobServiceSession *s;
+  struct BobServiceSession *s = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Peer disconnected, terminating session %s with peer %s\n",
-              GNUNET_h2s (&in->session_id),
-              GNUNET_i2s (&in->peer));
-  if (NULL != (s = in->s))
-  {
-    if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status)
-    {
-      s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
-      prepare_client_end_notification (s);
-    }
-  }
-  if (NULL != in->cadet_mq)
+              GNUNET_h2s (&s->session_id),
+              GNUNET_i2s (&s->peer));
+  if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status)
   {
-    GNUNET_MQ_destroy (in->cadet_mq);
-    in->cadet_mq = NULL;
+    s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
+    prepare_client_end_notification (s);
   }
-  in->channel = NULL;
-  destroy_cadet_session (in);
+  s->channel = NULL;
+  destroy_service_session (s);
 }
 
 
@@ -585,7 +447,7 @@ transmit_bobs_cryptodata_message_multipart (struct 
BobServiceSession *s)
       GNUNET_MQ_notify_sent (e,
                              &bob_cadet_done_cb,
                              s);
-    GNUNET_MQ_send (s->cadet->cadet_mq,
+    GNUNET_MQ_send (s->cadet_mq,
                     e);
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -653,7 +515,7 @@ transmit_bobs_cryptodata_message (struct BobServiceSession 
*s)
     GNUNET_MQ_notify_sent (e,
                            &bob_cadet_done_cb,
                            s);
-  GNUNET_MQ_send (s->cadet->cadet_mq,
+  GNUNET_MQ_send (s->cadet_mq,
                   e);
   transmit_bobs_cryptodata_message_multipart (s);
 }
@@ -752,14 +614,14 @@ compute_service_response (struct BobServiceSession 
*session)
     gcry_mpi_sub (tmp, my_offset, rand[p[i]]);
     gcry_mpi_sub (tmp, tmp, b[p[i]].value);
     GNUNET_assert (2 ==
-                   GNUNET_CRYPTO_paillier_encrypt 
(&session->cadet->remote_pubkey,
+                   GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
                                                    tmp,
                                                    2,
                                                    &r[i]));
 
     // E(S - r_pi - b_pi) * E(S + a_pi) ==  E(2*S + a - r - b)
     if (GNUNET_OK !=
-        GNUNET_CRYPTO_paillier_hom_add (&session->cadet->remote_pubkey,
+        GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey,
                                         &r[i],
                                         &a[p[i]],
                                         &r[i]))
@@ -775,14 +637,14 @@ compute_service_response (struct BobServiceSession 
*session)
     // E(S - r_qi)
     gcry_mpi_sub (tmp, my_offset, rand[q[i]]);
     GNUNET_assert (2 ==
-                   GNUNET_CRYPTO_paillier_encrypt 
(&session->cadet->remote_pubkey,
+                   GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
                                                    tmp,
                                                    2,
                                                    &r_prime[i]));
 
     // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi)
     if (GNUNET_OK !=
-        GNUNET_CRYPTO_paillier_hom_add (&session->cadet->remote_pubkey,
+        GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey,
                                         &r_prime[i],
                                         &a[q[i]],
                                         &r_prime[i]))
@@ -796,7 +658,7 @@ compute_service_response (struct BobServiceSession *session)
   // Calculate S' =  E(SUM( r_i^2 ))
   tmp = compute_square_sum (rand, count);
   GNUNET_assert (1 ==
-                 GNUNET_CRYPTO_paillier_encrypt 
(&session->cadet->remote_pubkey,
+                 GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
                                                  tmp,
                                                  1,
                                                  &session->s_prime));
@@ -807,7 +669,7 @@ compute_service_response (struct BobServiceSession *session)
     gcry_mpi_add (rand[i], rand[i], b[i].value);
   tmp = compute_square_sum (rand, count);
   GNUNET_assert (1 ==
-                 GNUNET_CRYPTO_paillier_encrypt 
(&session->cadet->remote_pubkey,
+                 GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
                                                  tmp,
                                                  1,
                                                  &session->s));
@@ -919,8 +781,8 @@ transmit_cryptographic_reply (struct BobServiceSession *s)
   if (GNUNET_OK !=
       compute_service_response (s))
   {
-    channel = s->cadet->channel;
-    s->cadet->channel = NULL;
+    channel = s->channel;
+    s->channel = NULL;
     GNUNET_CADET_channel_destroy (channel);
     return;
   }
@@ -929,49 +791,25 @@ transmit_cryptographic_reply (struct BobServiceSession *s)
 
 
 /**
- * Handle a multipart-chunk of a request from another service to
+ * Check a multipart-chunk of a request from another service to
  * calculate a scalarproduct with us.
  *
- * @param cls closure (set from #GNUNET_CADET_connect)
- * @param channel connection to the other end
- * @param channel_ctx place to store local state associated with the @a channel
- * @param message the actual message
+ * @param cls the `struct BobServiceSession *`
+ * @param msg the actual message
  * @return #GNUNET_OK to keep the connection open,
  *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-handle_alices_cryptodata_message (void *cls,
-                                  struct GNUNET_CADET_Channel *channel,
-                                  void **channel_ctx,
-                                  const struct GNUNET_MessageHeader *message)
+check_alices_cryptodata_message (void *cls,
+                                 const struct AliceCryptodataMessage *msg)
 {
-  struct CadetIncomingSession *in = *channel_ctx;
-  struct BobServiceSession *s;
-  const struct AliceCryptodataMessage *msg;
-  const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
+  struct BobServiceSession *s = cls;
   uint32_t contained_elements;
   size_t msg_length;
   uint16_t msize;
   unsigned int max;
 
-  if (NULL == in)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  s = in->s;
-  if (NULL == s)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  msize = ntohs (message->size);
-  if (msize <= sizeof (struct AliceCryptodataMessage))
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  msg = (const struct AliceCryptodataMessage *) message;
+  msize = ntohs (msg->header.size);
   contained_elements = ntohl (msg->contained_element_count);
   /* Our intersection may still be ongoing, but this is nevertheless
      an upper bound on the required array size */
@@ -986,14 +824,38 @@ handle_alices_cryptodata_message (void *cls,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
+  return GNUNET_OK;
+}
+
+
+/**
+ * Handle a multipart-chunk of a request from another service to
+ * calculate a scalarproduct with us.
+ *
+ * @param cls the `struct BobServiceSession *`
+ * @param msg the actual message
+ */
+static void
+handle_alices_cryptodata_message (void *cls,
+                                  const struct AliceCryptodataMessage *msg)
+{
+  struct BobServiceSession *s = cls;
+  const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
+  uint32_t contained_elements;
+  unsigned int max;
+
+  contained_elements = ntohl (msg->contained_element_count);
+  /* Our intersection may still be ongoing, but this is nevertheless
+     an upper bound on the required array size */
+  max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements);
   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)
-    s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) *
-                            max);
+    s->e_a = GNUNET_new_array (max,
+                               struct GNUNET_CRYPTO_PaillierCiphertext);
   GNUNET_memcpy (&s->e_a[s->cadet_received_element_count],
                 payload,
                 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 
contained_elements);
@@ -1007,8 +869,7 @@ handle_alices_cryptodata_message (void *cls,
        CADET response(s) */
     transmit_cryptographic_reply (s);
   }
-  GNUNET_CADET_receive_done (s->cadet->channel);
-  return GNUNET_OK;
+  GNUNET_CADET_receive_done (s->channel);
 }
 
 
@@ -1048,7 +909,7 @@ cb_intersection_element_removed (void *cls,
   case GNUNET_SET_STATUS_DONE:
     s->intersection_op = NULL;
     GNUNET_break (NULL == s->intersection_set);
-    GNUNET_CADET_receive_done (s->cadet->channel);
+    GNUNET_CADET_receive_done (s->channel);
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Finished intersection, %d items remain\n",
          GNUNET_CONTAINER_multihashmap_size (s->intersected_elements));
@@ -1099,7 +960,7 @@ start_intersection (struct BobServiceSession *s)
               (unsigned int) s->total);
 
   s->intersection_op
-    = GNUNET_SET_prepare (&s->cadet->peer,
+    = GNUNET_SET_prepare (&s->peer,
                           &s->session_id,
                           NULL,
                           GNUNET_SET_RESULT_REMOVED,
@@ -1122,55 +983,19 @@ start_intersection (struct BobServiceSession *s)
 /**
  * Handle a request from Alice to calculate a scalarproduct with us (Bob).
  *
- * @param cls closure (set from #GNUNET_CADET_connect)
- * @param channel connection to the other end
- * @param channel_ctx place to store the `struct CadetIncomingSession *`
- * @param message the actual message
- * @return #GNUNET_OK to keep the connection open,
- *         #GNUNET_SYSERR to close it (signal serious error)
+ * @param cls the `struct BobServiceSession *`
+ * @param msg the actual message
  */
-static int
+static void
 handle_alices_computation_request (void *cls,
-                                   struct GNUNET_CADET_Channel *channel,
-                                   void **channel_ctx,
-                                   const struct GNUNET_MessageHeader *message)
+                                   const struct ServiceRequestMessage *msg)
 {
-  struct CadetIncomingSession *in = *channel_ctx;
-  struct BobServiceSession *s;
-  const struct ServiceRequestMessage *msg;
+  struct BobServiceSession *s = cls;
 
-  msg = (const struct ServiceRequestMessage *) message;
-  if (GNUNET_YES == in->in_map)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  if (NULL != find_matching_cadet_session (&msg->session_id))
-  {
-    /* not unique, got one like this already */
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  in->session_id = msg->session_id;
-  in->remote_pubkey = msg->public_key;
-  GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multihashmap_put (cadet_sessions,
-                                                    &in->session_id,
-                                                    in,
-                                                    
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-  s = find_matching_client_session (&in->session_id);
-  if (NULL == s)
-  {
-    /* no client waiting for this request, wait for client */
-    return GNUNET_OK;
-  }
-  GNUNET_assert (NULL == s->cadet);
-  /* pair them up */
-  in->s = s;
-  s->cadet = in;
+  s->session_id = msg->session_id; // ??
+  s->remote_pubkey = msg->public_key;
   if (s->client_received_element_count == s->total)
     start_intersection (s);
-  return GNUNET_OK;
 }
 
 
@@ -1182,31 +1007,27 @@ handle_alices_computation_request (void *cls,
  * @param cls closure with the `struct BobServiceSession`
  * @param channel new handle to the channel
  * @param initiator peer that started the channel
- * @param port unused
- * @param options unused
  * @return session associated with the channel
  */
 static void *
 cb_channel_incoming (void *cls,
                      struct GNUNET_CADET_Channel *channel,
-                     const struct GNUNET_PeerIdentity *initiator,
-                     const struct GNUNET_HashCode *port,
-                     enum GNUNET_CADET_ChannelOption options)
+                     const struct GNUNET_PeerIdentity *initiator)
 {
-  struct CadetIncomingSession *in;
+  struct BobServiceSession *s = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "New incoming channel from peer %s.\n",
               GNUNET_i2s (initiator));
-  in = GNUNET_new (struct CadetIncomingSession);
-  in->peer = *initiator;
-  in->channel = channel;
-  in->cadet_mq = GNUNET_CADET_mq_create (in->channel);
-  return in;
+  GNUNET_CADET_close_port (s->port);
+  s->port = NULL;
+  s->channel = channel;
+  s->peer = *initiator;
+  s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
+  return s;
 }
 
 
-
 /**
  * We're receiving additional set data. Check it is well-formed.
  *
@@ -1287,7 +1108,7 @@ handle_bob_client_message_multipart (void *cls,
     /* more to come */
     return;
   }
-  if (NULL == s->cadet)
+  if (NULL == s->channel)
   {
     /* no Alice waiting for this request, wait for Alice */
     return;
@@ -1330,11 +1151,6 @@ check_bob_client_message (void *cls,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  if (NULL != find_matching_client_session (&msg->session_key))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
   return GNUNET_OK;
 }
 
@@ -1352,7 +1168,17 @@ handle_bob_client_message (void *cls,
                           const struct BobComputationMessage *msg)
 {
   struct BobServiceSession *s = cls;
-  struct CadetIncomingSession *in;
+  struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
+    GNUNET_MQ_hd_fixed_size (alices_computation_request,
+                             
GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION,
+                             struct ServiceRequestMessage,
+                             s),
+    GNUNET_MQ_hd_var_size (alices_cryptodata_message,
+                           GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA,
+                           struct AliceCryptodataMessage,
+                           s),
+    GNUNET_MQ_handler_end ()
+  };
   uint32_t contained_count;
   uint32_t total_count;
   const struct GNUNET_SCALARPRODUCT_Element *elements;
@@ -1366,21 +1192,6 @@ handle_bob_client_message (void *cls,
   s->total = total_count;
   s->client_received_element_count = contained_count;
   s->session_id = msg->session_key;
-  s->port = GNUNET_CADET_open_port (my_cadet,
-                                    &msg->session_key,
-                                    &cb_channel_incoming,
-                                    s);
-  if (NULL == s->port)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (s->client);
-    return;
-  }
-  GNUNET_break (GNUNET_YES ==
-                GNUNET_CONTAINER_multihashmap_put (client_sessions,
-                                                   &s->session_id,
-                                                   s,
-                                                   
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
   s->intersected_elements
     = GNUNET_CONTAINER_multihashmap_create (s->total,
@@ -1415,22 +1226,20 @@ handle_bob_client_message (void *cls,
     s->used_element_count++;
   }
   GNUNET_SERVICE_client_continue (s->client);
-  if (s->total != s->client_received_element_count)
-  {
-    /* multipart msg */
-    return;
-  }
-  in = find_matching_cadet_session (&s->session_id);
-  if (NULL == in)
+  /* We're ready, open the port */
+  s->port = GNUNET_CADET_open_porT (my_cadet,
+                                    &msg->session_key,
+                                    &cb_channel_incoming,
+                                    s,
+                                    NULL,
+                                    &cb_channel_destruction,
+                                    cadet_handlers);
+  if (NULL == s->port)
   {
-    /* nothing yet, wait for Alice */
+    GNUNET_break (0);
+    GNUNET_SERVICE_client_drop (s->client);
     return;
   }
-  GNUNET_assert (NULL == in->s);
-  /* pair them up */
-  in->s = s;
-  s->cadet = in;
-  start_intersection (s);
 }
 
 
@@ -1450,10 +1259,6 @@ shutdown_task (void *cls)
     GNUNET_CADET_disconnect (my_cadet);
     my_cadet = NULL;
   }
-  GNUNET_CONTAINER_multihashmap_destroy (client_sessions);
-  client_sessions = NULL;
-  GNUNET_CONTAINER_multihashmap_destroy (cadet_sessions);
-  cadet_sessions = NULL;
 }
 
 
@@ -1517,16 +1322,6 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *c,
      struct GNUNET_SERVICE_Handle *service)
 {
-  static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
-    { &handle_alices_computation_request,
-      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION,
-      sizeof (struct ServiceRequestMessage) },
-    { &handle_alices_cryptodata_message,
-      GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA,
-      0},
-    { NULL, 0, 0}
-  };
-
   cfg = c;
   /*
     offset has to be sufficiently small to allow computation of:
@@ -1538,13 +1333,7 @@ run (void *cls,
 
   GNUNET_CRYPTO_paillier_create (&my_pubkey,
                                  &my_privkey);
-  client_sessions = GNUNET_CONTAINER_multihashmap_create (128,
-                                                          GNUNET_YES);
-  cadet_sessions = GNUNET_CONTAINER_multihashmap_create (128,
-                                                         GNUNET_YES);
-  my_cadet = GNUNET_CADET_connect (cfg, NULL,
-                                   &cb_channel_destruction,
-                                   cadet_handlers);
+  my_cadet = GNUNET_CADET_connecT (cfg);
   GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
                                 NULL);
   if (NULL == my_cadet)

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]