first batch of license fixes (boring)
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed_oc.c
index ff5331fe4acd9d0ac0d6d21cd0d183271344f3ae..3f12dd9503a339e47033e6fa34b79f3c3a4306ff 100644 (file)
@@ -1,21 +1,16 @@
 /*
   This file is part of GNUnet.
-  Copyright (C) 2008--2015 Christian Grothoff (and other contributing authors)
+  Copyright (C) 2008--2016 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
-  by the Free Software Foundation; either version 3, or (at your
-  option) any later version.
+  GNUnet is free software: you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published
+  by the Free Software Foundation, either version 3 of the License,
+  or (at your option) any later version.
 
   GNUnet is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with GNUnet; see the file COPYING.  If not, write to the
-  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-  Boston, MA 02110-1301, USA.
+  Affero General Public License for more details.
 */
 
 /**
@@ -26,6 +21,7 @@
 
 #include "gnunet-service-testbed.h"
 #include "gnunet-service-testbed_connectionpool.h"
+#include "gnunet_transport_hello_service.h"
 
 /**
  * Redefine LOG with a changed log component string
@@ -46,7 +42,12 @@ struct ConnectivitySuggestContext
   /**
    * The transport handle obtained from cache. Do NOT close/disconnect.
    */
-  struct GNUNET_TRANSPORT_Handle *th_;
+  struct GNUNET_TRANSPORT_CoreHandle *th_;
+
+  /**
+   * Configuration of the peer from cache. Do not free!
+   */
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
 
   /**
    * The GetCacheHandle for the peer2's transport handle
@@ -162,7 +163,7 @@ struct OverlayConnectContext
    * The client which has requested for overlay connection. This is used to send
    * either a success of failure message
    */
-  struct GNUNET_SERVER_Client *client;
+  struct GNUNET_SERVICE_Client *client;
 
   /**
    * the first peer which is to expect an overlay connection from the second peer.
@@ -173,7 +174,7 @@ struct OverlayConnectContext
    * Transport handle of the first peer obtained from cache to get its HELLO. Do
    * NOT close/disconnect.
    */
-  struct GNUNET_TRANSPORT_Handle *p1th_;
+  struct GNUNET_TRANSPORT_CoreHandle *p1th_;
 
   /**
    * The #GST_ConnectionPool_GetHandle for the peer1's transport handle
@@ -194,7 +195,7 @@ struct OverlayConnectContext
   /**
    * Get GetHelloHandle to acquire a HELLO of the first peer
    */
-  struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
+  struct GNUNET_TRANSPORT_HelloGetHandle *ghh;
 
   /**
    * The error message we send if this overlay connect operation has timed out
@@ -255,7 +256,7 @@ struct OverlayConnectContext
   enum OverlayConnectContextType type;
 
   /**
-   * The id of the second peer which is has to connect to the first peer
+   * The id of the second peer which has to connect to the first peer
    */
   uint32_t other_peer_id;
 };
@@ -352,7 +353,11 @@ static struct RemoteOverlayConnectCtx *roccq_tail;
 void
 GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc)
 {
-  GNUNET_SERVER_client_drop (focc->client);
+  struct RegisteredHostContext *rhc = focc->rhc;
+
+  GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head,
+                               rhc->focc_dll_tail,
+                               focc);
   GNUNET_free_non_null (focc->orig_msg);
   GNUNET_free (focc);
 }
@@ -361,25 +366,23 @@ GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc)
 /**
  * Timeout task for cancelling a forwarded overlay connect connect
  *
- * @param cls the ForwardedOverlayConnectContext
- * @param tc the task context from the scheduler
+ * @param cls the `struct ForwardedOperationContext`
  */
 static void
-forwarded_overlay_connect_timeout (void *cls,
-                                   const struct GNUNET_SCHEDULER_TaskContext
-                                   *tc)
+forwarded_overlay_connect_timeout (void *cls)
 {
   struct ForwardedOperationContext *fopc = cls;
   struct RegisteredHostContext *rhc;
   struct ForwardedOverlayConnectContext *focc;
 
+  fopc->timeout_task = NULL;
   rhc = fopc->cls;
   focc = rhc->focc_dll_head;
-  GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, rhc->focc_dll_tail, focc);
-  LOG_DEBUG ("Overlay linking between peers %u and %u failed\n", focc->peer1,
+  LOG_DEBUG ("Overlay linking between peers %u and %u failed\n",
+             focc->peer1,
              focc->peer2);
   GST_cleanup_focc (focc);
-  GST_forwarded_operation_timeout (fopc, tc);
+  GST_forwarded_operation_timeout (fopc);
   if (NULL != rhc->focc_dll_head)
     GST_process_next_focc (rhc);
 }
@@ -404,7 +407,6 @@ forwarded_overlay_connect_listener (void *cls,
   rhc = fopc->cls;
   GST_forwarded_operation_reply_relay (cls, msg);
   focc = rhc->focc_dll_head;
-  GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, rhc->focc_dll_tail, focc);
   GST_cleanup_focc (focc);
   if (NULL != rhc->focc_dll_head)
     GST_process_next_focc (rhc);
@@ -432,22 +434,24 @@ GST_process_next_focc (struct RegisteredHostContext *rhc)
   GNUNET_assert (GNUNET_YES == peer->is_remote);
   GNUNET_assert (NULL != (slave = peer->details.remote.slave));
   fopc = GNUNET_new (struct ForwardedOperationContext);
-  GNUNET_SERVER_client_keep (focc->client);
   fopc->client = focc->client;
   fopc->operation_id = focc->operation_id;
   fopc->cls = rhc;
   fopc->type = OP_OVERLAY_CONNECT;
   fopc->opc =
       GNUNET_TESTBED_forward_operation_msg_ (slave->controller,
-                                             focc->operation_id, focc->orig_msg,
+                                             focc->operation_id,
+                                             focc->orig_msg,
                                              &forwarded_overlay_connect_listener,
                                              fopc);
   GNUNET_free (focc->orig_msg);
   focc->orig_msg = NULL;
-  fopc->timeout_task =
-      GNUNET_SCHEDULER_add_delayed (GST_timeout, &forwarded_overlay_connect_timeout,
+  fopc->timeout_task = GNUNET_SCHEDULER_add_delayed (GST_timeout,
+                                                     &forwarded_overlay_connect_timeout,
+                                                     fopc);
+  GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
+                                    fopcq_tail,
                                     fopc);
-  GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
 }
 
 
@@ -460,11 +464,25 @@ static void
 cleanup_occ_lp2c (struct LocalPeer2Context *lp2c)
 {
   if (NULL != lp2c->ohh)
+  {
     GNUNET_TRANSPORT_offer_hello_cancel (lp2c->ohh);
-  GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_th);
-  GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_ats);
+    lp2c->ohh = NULL;
+  }
+  if (NULL != lp2c->tcc.cgh_p2_th)
+  {
+    GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_th);
+    lp2c->tcc.cgh_p2_th = NULL;
+  }
+  if (NULL != lp2c->tcc.cgh_p2_ats)
+  {
+    GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_ats);
+    lp2c->tcc.cgh_p2_ats = NULL;
+  }
   if (NULL != lp2c->tcc.csh)
+  {
     GNUNET_ATS_connectivity_suggest_cancel (lp2c->tcc.csh);
+    lp2c->tcc.csh = NULL;
+  }
 }
 
 
@@ -478,11 +496,20 @@ static void
 cleanup_occ_rp2c (struct RemotePeer2Context *rp2c)
 {
   if (NULL != rp2c->opc)
+  {
     GNUNET_TESTBED_forward_operation_msg_cancel_ (rp2c->opc);
+    rp2c->opc = NULL;
+  }
   if (NULL != rp2c->ncn)
+  {
     GST_neighbour_get_connection_cancel (rp2c->ncn);
+    rp2c->ncn = NULL;
+  }
   if ( (NULL != rp2c->p2c) && (NULL != rp2c->p2n) )
+  {
     GST_neighbour_release_connection (rp2c->p2n);
+    rp2c->p2n = NULL;
+  }
 }
 
 /**
@@ -503,10 +530,10 @@ cleanup_occ (struct OverlayConnectContext *occ)
 {
   struct Peer *peer2;
 
-  LOG_DEBUG ("0x%llx: Cleaning up occ\n", occ->op_id);
+  LOG_DEBUG ("0x%llx: Cleaning up occ\n",
+             occ->op_id);
   GNUNET_free_non_null (occ->emsg);
   GNUNET_free_non_null (occ->hello);
-  GNUNET_SERVER_client_drop (occ->client);
   if (NULL != occ->send_hello_task)
     GNUNET_SCHEDULER_cancel (occ->send_hello_task);
   if (NULL != occ->cleanup_task)
@@ -516,7 +543,7 @@ cleanup_occ (struct OverlayConnectContext *occ)
   if (NULL != occ->cgh_ch)
     GST_connection_pool_get_handle_done (occ->cgh_ch);
   if (NULL != occ->ghh)
-    GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
+    GNUNET_TRANSPORT_hello_get_cancel (occ->ghh);
   GST_connection_pool_get_handle_done (occ->cgh_p1th);
   GNUNET_assert (NULL != GST_peer_list);
   GNUNET_assert (occ->peer->reference_cnt > 0);
@@ -549,11 +576,9 @@ cleanup_occ (struct OverlayConnectContext *occ)
  * Task for cleaing up overlay connect context structure
  *
  * @param cls the overlay connect context
- * @param tc the task context
  */
 static void
-do_cleanup_occ (void *cls,
-                const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_cleanup_occ (void *cls)
 {
   struct OverlayConnectContext *occ = cls;
 
@@ -566,11 +591,9 @@ do_cleanup_occ (void *cls,
  * Task which will be run when overlay connect request has been timed out
  *
  * @param cls the OverlayConnectContext
- * @param tc the TaskContext
  */
 static void
-timeout_overlay_connect (void *cls,
-                         const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_overlay_connect (void *cls)
 {
   struct OverlayConnectContext *occ = cls;
 
@@ -579,27 +602,66 @@ timeout_overlay_connect (void *cls,
   /* LOG (GNUNET_ERROR_TYPE_WARNING, */
   /*      "0x%llx: Timeout while connecting peers %u and %u: %s\n", occ->op_id, */
   /*      occ->peer->id, occ->other_peer_id, occ->emsg); */
-  GST_send_operation_fail_msg (occ->client, occ->op_id, occ->emsg);
+  GST_send_operation_fail_msg (occ->client,
+                               occ->op_id,
+                               occ->emsg);
   cleanup_occ (occ);
 }
 
 
+/**
+ * Notify OC subsystem that @a client disconnected.
+ *
+ * @param client the client that disconnected
+ */
+void
+GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client)
+{
+  struct ForwardedOperationContext *fopc;
+  struct ForwardedOperationContext *fopcn;
+  struct OverlayConnectContext *occ;
+  struct OverlayConnectContext *occn;
+
+  for (fopc = fopcq_head; NULL != fopc; fopc = fopcn)
+  {
+    fopcn = fopc->next;
+    if (fopc->client == client)
+    {
+      GNUNET_SCHEDULER_cancel (fopc->timeout_task);
+      GST_forwarded_operation_timeout (fopc);
+    }
+  }
+  for (occ = occq_head; NULL != occ; occ = occn)
+  {
+    occn = occ->next;
+    if (occ->client == client)
+      cleanup_occ (occ);
+  }
+  // FIXME: implement clean up for client_keep replacements!
+}
+
+
+
+
+/**
+ * FIXME.
+ */
 static void
 send_overlay_connect_success_msg (struct OverlayConnectContext *occ)
 {
+  struct GNUNET_MQ_Envelope *env;
   struct GNUNET_TESTBED_ConnectionEventMessage *msg;
 
   LOG_DEBUG ("0x%llx: Peers connected - Sending overlay connect success\n",
              occ->op_id);
-  msg = GNUNET_new (struct GNUNET_TESTBED_ConnectionEventMessage);
-  msg->header.size =
-      htons (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT);
+  env = GNUNET_MQ_msg (msg,
+                       GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT);
   msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT);
   msg->peer1 = htonl (occ->peer->id);
   msg->peer2 = htonl (occ->other_peer_id);
   msg->operation_id = GNUNET_htonll (occ->op_id);
-  GST_queue_message (occ->client, &msg->header);
+  GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (occ->client),
+                  env);
 }
 
 
@@ -651,10 +713,21 @@ overlay_connect_notify (void *cls,
   GNUNET_assert (NULL != occ->timeout_task);
   GNUNET_SCHEDULER_cancel (occ->timeout_task);
   occ->timeout_task = NULL;
+  switch (occ->type)
+  {
+  case OCC_TYPE_LOCAL:
+    cleanup_occ_lp2c (&occ->p2ctx.local);
+    break;
+  case OCC_TYPE_REMOTE_SLAVE:
+  case OCC_TYPE_REMOTE_LATERAL:
+    cleanup_occ_rp2c (&occ->p2ctx.remote);
+    break;
+  }
   GNUNET_free_non_null (occ->emsg);
   occ->emsg = NULL;
   send_overlay_connect_success_msg (occ);
-  occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ, occ);
+  occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ,
+                                                occ);
 }
 
 
@@ -666,13 +739,15 @@ overlay_connect_notify (void *cls,
  * @param th the handle to TRANSPORT. Can be NULL if it is not requested
  * @param ac the handle to ATS. Can be NULL if it is not requested
  * @param my_identity the identity of our peer
+ * @param cfg configuration of the peer
  */
 static void
 occ_cache_get_handle_ats_occ_cb (void *cls,
                                  struct GNUNET_CORE_Handle *ch,
-                                 struct GNUNET_TRANSPORT_Handle *th,
+                                 struct GNUNET_TRANSPORT_CoreHandle *th,
                                  struct GNUNET_ATS_ConnectivityHandle *ac,
-                                 const struct GNUNET_PeerIdentity *my_identity)
+                                 const struct GNUNET_PeerIdentity *my_identity,
+                                 const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct OverlayConnectContext *occ = cls;
   struct LocalPeer2Context *lp2c;
@@ -719,9 +794,10 @@ occ_cache_get_handle_ats_occ_cb (void *cls,
 static void
 occ_cache_get_handle_ats_rocc_cb (void *cls,
                                   struct GNUNET_CORE_Handle *ch,
-                                  struct GNUNET_TRANSPORT_Handle *th,
+                                  struct GNUNET_TRANSPORT_CoreHandle *th,
                                   struct GNUNET_ATS_ConnectivityHandle *ac,
-                                  const struct GNUNET_PeerIdentity *my_identity)
+                                  const struct GNUNET_PeerIdentity *my_identity,
+                                  const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;
 
@@ -737,46 +813,31 @@ occ_cache_get_handle_ats_rocc_cb (void *cls,
  * peer 1.
  *
  * @param cls the OverlayConnectContext
- * @param tc the TaskContext from scheduler
  */
 static void
-send_hello (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc);
+send_hello (void *cls);
 
 
 /**
- * Task that is run when hello has been sent
+ * Task that is run when hello has been sent If tc->reason =
+ * #GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
+ * #GNUNET_SCHEDULER_REASON_READ_READY is succeeded
  *
  * @param cls the overlay connect context
- * @param tc the scheduler task context; if tc->reason =
- *          #GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
- *          #GNUNET_SCHEDULER_REASON_READ_READY is succeeded
  */
 static void
-occ_hello_sent_cb (void *cls,
-                   const struct GNUNET_SCHEDULER_TaskContext *tc)
+occ_hello_sent_cb (void *cls)
 {
   struct OverlayConnectContext *occ = cls;
   struct LocalPeer2Context *lp2c;
   struct Peer *peer2;
 
   GNUNET_assert (OCC_TYPE_LOCAL == occ->type);
+  GNUNET_assert (NULL != occ->timeout_task);
   lp2c = &occ->p2ctx.local;
   lp2c->ohh = NULL;
 
   GNUNET_assert (NULL == occ->send_hello_task);
-  if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
-  {
-    GNUNET_free_non_null (occ->emsg);
-    GNUNET_asprintf (&occ->emsg,
-                     "0x%llx: Timeout while offering HELLO to other peer",
-                     occ->op_id);
-    occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello,
-                                                     occ);
-    return;
-  }
-  if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason)
-    return;
   GNUNET_free_non_null (occ->emsg);
 
   GNUNET_asprintf (&occ->emsg,
@@ -826,7 +887,7 @@ send_hello_thru_rocc (struct OverlayConnectContext *occ)
   msg->peer = htonl (occ->other_peer_id);
   msg->operation_id = GNUNET_htonll (occ->op_id);
   msg->peer_identity = occ->peer_identity;
-  memcpy (msg->hello,
+  GNUNET_memcpy (msg->hello,
           occ->hello,
           hello_size);
   GNUNET_TESTBED_queue_message_ (occ->p2ctx.remote.p2c,
@@ -840,19 +901,16 @@ send_hello_thru_rocc (struct OverlayConnectContext *occ)
  * send_hello_thru_rocc()
  *
  * @param cls the OverlayConnectContext
- * @param tc the TaskContext from scheduler
  */
 static void
-send_hello (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_hello (void *cls)
 {
   struct OverlayConnectContext *occ = cls;
   struct LocalPeer2Context *lp2c;
   char *other_peer_str;
 
   occ->send_hello_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
+  GNUNET_assert (NULL != occ->timeout_task);
   GNUNET_assert (NULL != occ->hello);
   if (OCC_TYPE_LOCAL != occ->type)
   {
@@ -867,10 +925,10 @@ send_hello (void *cls,
              other_peer_str);
   GNUNET_free (other_peer_str);
   lp2c->ohh =
-      GNUNET_TRANSPORT_offer_hello (lp2c->tcc.th_,
-                                    occ->hello,
-                                    occ_hello_sent_cb,
-                                    occ);
+    GNUNET_TRANSPORT_offer_hello (lp2c->tcc.cfg,
+                                 occ->hello,
+                                 &occ_hello_sent_cb,
+                                 occ);
   if (NULL == lp2c->ohh)
   {
     GNUNET_break (0);
@@ -893,13 +951,15 @@ send_hello (void *cls,
  * @param th the handle to TRANSPORT. Can be NULL if it is not requested
  * @param ac the handle to ATS. Can be NULL if it is not requested
  * @param ignore_ peer identity which is ignored in this callback
- */
+ * @param cfg configuration of the peer
+*/
 static void
 p2_transport_connect_cache_callback (void *cls,
                                      struct GNUNET_CORE_Handle *ch,
-                                     struct GNUNET_TRANSPORT_Handle *th,
+                                     struct GNUNET_TRANSPORT_CoreHandle *th,
                                      struct GNUNET_ATS_ConnectivityHandle *ac,
-                                     const struct GNUNET_PeerIdentity *ignore_)
+                                     const struct GNUNET_PeerIdentity *ignore_,
+                                     const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct OverlayConnectContext *occ = cls;
 
@@ -916,6 +976,7 @@ p2_transport_connect_cache_callback (void *cls,
     return;
   }
   occ->p2ctx.local.tcc.th_ = th;
+  occ->p2ctx.local.tcc.cfg = cfg;
   GNUNET_asprintf (&occ->emsg,
                    "0x%llx: Timeout while offering HELLO to %s",
                    occ->op_id,
@@ -935,6 +996,11 @@ p2_transport_connect (struct OverlayConnectContext *occ)
 {
   struct Peer *peer2;
 
+  /* HUH? Why to *obtain* HELLO? Seems we use this to *SEND* the
+     HELLO! */
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Connecting to transport of peer %s to obtain HELLO\n",
+             GNUNET_i2s (&occ->other_peer_identity));
   GNUNET_assert (NULL == occ->emsg);
   GNUNET_assert (NULL != occ->hello);
   GNUNET_assert (NULL == occ->ghh);
@@ -1013,8 +1079,8 @@ hello_update_cb (void *cls,
              GNUNET_i2s (&occ->peer_identity));
   occ->hello = GNUNET_malloc (msize);
   GST_cache_add_hello (occ->peer->id, hello);
-  memcpy (occ->hello, hello, msize);
-  GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
+  GNUNET_memcpy (occ->hello, hello, msize);
+  GNUNET_TRANSPORT_hello_get_cancel (occ->ghh);
   occ->ghh = NULL;
   GST_connection_pool_get_handle_done (occ->cgh_p1th);
   occ->cgh_p1th = NULL;
@@ -1037,9 +1103,10 @@ hello_update_cb (void *cls,
 static void
 p1_transport_connect_cache_callback (void *cls,
                                      struct GNUNET_CORE_Handle *ch,
-                                     struct GNUNET_TRANSPORT_Handle *th,
+                                     struct GNUNET_TRANSPORT_CoreHandle *th,
                                      struct GNUNET_ATS_ConnectivityHandle *ac,
-                                     const struct GNUNET_PeerIdentity *ignore_)
+                                     const struct GNUNET_PeerIdentity *ignore_,
+                                     const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct OverlayConnectContext *occ = cls;
 
@@ -1063,7 +1130,8 @@ p1_transport_connect_cache_callback (void *cls,
                    "0x%llx: Timeout while acquiring HELLO of peer %s",
                    occ->op_id,
                    GNUNET_i2s (&occ->peer_identity));
-  occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p1th_,
+  occ->ghh = GNUNET_TRANSPORT_hello_get (cfg,
+                                        GNUNET_TRANSPORT_AC_ANY,
                                          &hello_update_cb,
                                          occ);
 }
@@ -1081,9 +1149,10 @@ p1_transport_connect_cache_callback (void *cls,
 static void
 occ_cache_get_handle_core_cb (void *cls,
                               struct GNUNET_CORE_Handle *ch,
-                              struct GNUNET_TRANSPORT_Handle *th,
+                              struct GNUNET_TRANSPORT_CoreHandle *th,
                               struct GNUNET_ATS_ConnectivityHandle *ac,
-                              const struct GNUNET_PeerIdentity *my_identity)
+                              const struct GNUNET_PeerIdentity *my_identity,
+                              const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct OverlayConnectContext *occ = cls;
   const struct GNUNET_MessageHeader *hello;
@@ -1103,9 +1172,9 @@ occ_cache_get_handle_core_cb (void *cls,
     return;
   }
   occ->emsg = NULL;
-  if (GNUNET_YES ==
-      GNUNET_CORE_is_peer_connected_sync (ch,
-                                          &occ->other_peer_identity))
+  if (NULL !=
+      GNUNET_CORE_get_mq (ch,
+                          &occ->other_peer_identity))
   {
     LOG_DEBUG ("0x%llx: Target peer already connected\n",
                occ->op_id);
@@ -1284,7 +1353,8 @@ register_host (struct Slave *slave,
   rhc->state = RHC_INIT;
   hash = hash_hosts (rhc->reg_host, rhc->host);
   if ((GNUNET_NO ==
-       GNUNET_CONTAINER_multihashmap_contains (slave->reghost_map, &hash)) ||
+       GNUNET_CONTAINER_multihashmap_contains (slave->reghost_map,
+                                               &hash)) ||
       (GNUNET_SYSERR !=
        GNUNET_CONTAINER_multihashmap_get_multiple (slave->reghost_map,
                                                    &hash,
@@ -1293,10 +1363,14 @@ register_host (struct Slave *slave,
   {
     /* create and add a new registerd host context */
     /* add the focc to its queue */
-    GNUNET_CONTAINER_multihashmap_put (slave->reghost_map, &hash, rhc,
+    GNUNET_CONTAINER_multihashmap_put (slave->reghost_map,
+                                       &hash,
+                                       rhc,
                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-    GST_queue_host_registration (slave, host_registration_comp,
-                                 rhc, rhc->reg_host);
+    GST_queue_host_registration (slave,
+                                 host_registration_comp,
+                                 rhc,
+                                 rhc->reg_host);
   }
   else
   {
@@ -1322,7 +1396,7 @@ register_host (struct Slave *slave,
  */
 static void
 forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg,
-                         struct GNUNET_SERVER_Client *client)
+                         struct GNUNET_SERVICE_Client *client)
 {
   struct ForwardedOperationContext *fopc;
   struct Route *route_to_peer2_host;
@@ -1358,14 +1432,15 @@ forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg,
   {
     LOG_DEBUG ("Queueing forwarding FOCC for connecting peers %u and %u\n", p1, p2);
     focc = GNUNET_new (struct ForwardedOverlayConnectContext);
+    focc->rhc = rhc;
     focc->peer1 = p1;
     focc->peer2 = p2;
     focc->peer2_host_id = peer2_host_id;
     focc->orig_msg = GNUNET_copy_message (&msg->header);
     focc->operation_id = op_id;
     focc->client = client;
-    GNUNET_SERVER_client_keep (client);
-    GNUNET_CONTAINER_DLL_insert_tail (rhc->focc_dll_head, rhc->focc_dll_tail,
+    GNUNET_CONTAINER_DLL_insert_tail (rhc->focc_dll_head,
+                                      rhc->focc_dll_tail,
                                       focc);
     return;
   }
@@ -1373,7 +1448,6 @@ forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg,
  forward:
   LOG_DEBUG ("Forwarding without FOCC for connecting peers %u and %u\n", p1, p2);
   fopc = GNUNET_new (struct ForwardedOperationContext);
-  GNUNET_SERVER_client_keep (client);
   fopc->client = client;
   fopc->operation_id = op_id;
   fopc->type = OP_OVERLAY_CONNECT;
@@ -1420,7 +1494,8 @@ p2_controller_connect_cb (void *cls,
   cmsg.operation_id = GNUNET_htonll (occ->op_id);
   rp2c->opc =
       GNUNET_TESTBED_forward_operation_msg_ (rp2c->p2c,
-                                             occ->op_id, &cmsg.header,
+                                             occ->op_id,
+                                             &cmsg.header,
                                              &overlay_connect_get_config,
                                              occ);
   GNUNET_free_non_null (occ->emsg);
@@ -1433,18 +1508,16 @@ p2_controller_connect_cb (void *cls,
 
 
 /**
- * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
+ * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT messages
  *
- * @param cls NULL
- * @param client identification of the client
- * @param message the actual message
+ * @param cls identification of the client
+ * @param msg the actual message
  */
 void
-GST_handle_overlay_connect (void *cls,
-                            struct GNUNET_SERVER_Client *client,
-                            const struct GNUNET_MessageHeader *message)
+handle_overlay_connect (void *cls,
+                        const struct GNUNET_TESTBED_OverlayConnectMessage *msg)
 {
-  const struct GNUNET_TESTBED_OverlayConnectMessage *msg;
+  struct GNUNET_SERVICE_Client *client = cls;
   struct Peer *peer;
   struct Peer *peer2;
   struct OverlayConnectContext *occ;
@@ -1454,20 +1527,12 @@ GST_handle_overlay_connect (void *cls,
   uint32_t p2;
   uint32_t peer2_host_id;
 
-  if (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage) !=
-      ntohs (message->size))
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-  msg = (const struct GNUNET_TESTBED_OverlayConnectMessage *) message;
   p1 = ntohl (msg->peer1);
   p2 = ntohl (msg->peer2);
-  if (!VALID_PEER_ID (p1))
+  if (! VALID_PEER_ID (p1))
   {
     GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    GNUNET_SERVICE_client_drop (client);
     return;
   }
   peer = GST_peer_list[p1];
@@ -1483,30 +1548,27 @@ GST_handle_overlay_connect (void *cls,
     if (! VALID_HOST_ID (peer2_host_id))
     {
       GNUNET_break (0);
-      GNUNET_SERVER_receive_done (client,
-                                  GNUNET_SYSERR);
+      GNUNET_SERVICE_client_drop (client);
       return;
     }
     forward_overlay_connect (msg, client);
-    GNUNET_SERVER_receive_done (client,
-                                GNUNET_OK);
+    GNUNET_SERVICE_client_continue (client);
     return;
   }
   p2n = NULL;
   occ = GNUNET_new (struct OverlayConnectContext);
   occ->type = OCC_TYPE_LOCAL;
-  if (!VALID_PEER_ID (p2))       /* May be peer2 is on a another controller */
+  if (! VALID_PEER_ID (p2))       /* May be peer2 is on a another controller */
   {
     if (NULL == (p2n = GST_get_neighbour (peer2_host_id)))
     {
-      if (!VALID_HOST_ID (peer2_host_id))
+      if (! VALID_HOST_ID (peer2_host_id))
       {
         GNUNET_break (0);
         LOG (GNUNET_ERROR_TYPE_WARNING,
              "0x%llx: Peer %u's host not in our neighbours list\n",
              operation_id, p2);
-        GNUNET_SERVER_receive_done (client,
-                                    GNUNET_SYSERR);
+        GNUNET_SERVICE_client_drop (client);
         GNUNET_free (occ);
         return;
       }
@@ -1523,7 +1585,6 @@ GST_handle_overlay_connect (void *cls,
   GNUNET_CONTAINER_DLL_insert_tail (occq_head,
                                     occq_tail,
                                     occ);
-  GNUNET_SERVER_client_keep (client);
   occ->client = client;
   occ->other_peer_id = p2;
   GST_peer_list[p1]->reference_cnt++;
@@ -1543,11 +1604,14 @@ GST_handle_overlay_connect (void *cls,
                      occ->op_id,
                      occ->other_peer_id,
                      peer2_host_id);
-    occ->p2ctx.remote.ncn =
-        GST_neighbour_get_connection (p2n, &p2_controller_connect_cb, occ);
+    occ->p2ctx.remote.ncn
+      = GST_neighbour_get_connection (p2n,
+                                      &p2_controller_connect_cb,
+                                      occ);
     break;
   case OCC_TYPE_REMOTE_SLAVE:
-    p2_controller_connect_cb (occ, occ->p2ctx.remote.p2c);
+    p2_controller_connect_cb (occ,
+                              occ->p2ctx.remote.p2c);
     break;
   case OCC_TYPE_LOCAL:
     peer2 = GST_peer_list[occ->other_peer_id];
@@ -1568,7 +1632,7 @@ GST_handle_overlay_connect (void *cls,
                                         &overlay_connect_notify, occ);
     break;
   }
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+  GNUNET_SERVICE_client_continue (client);
 }
 
 
@@ -1610,11 +1674,9 @@ cleanup_rocc (struct RemoteOverlayConnectCtx *rocc)
  * Task to timeout rocc and cleanit up
  *
  * @param cls the RemoteOverlayConnectCtx
- * @param tc the TaskContext from scheduler
  */
 static void
-timeout_rocc_task (void *cls,
-                   const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_rocc_task (void *cls)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;
 
@@ -1656,24 +1718,20 @@ cache_transport_peer_connect_notify (void *cls,
  * whose identity is in RemoteOverlayConnectCtx
  *
  * @param cls the RemoteOverlayConnectCtx
- * @param tc the TaskContext from scheduler
  */
 static void
-attempt_connect_task (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext *tc);
+attempt_connect_task (void *cls);
 
 
 /**
- * Task that is run when hello has been sent
+ * Task that is run when hello has been sent If tc->reason =
+ * #GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
+ * #GNUNET_SCHEDULER_REASON_READ_READY is succeeded
  *
  * @param cls the overlay connect context
- * @param tc the scheduler task context; if tc->reason =
- *          #GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
- *          #GNUNET_SCHEDULER_REASON_READ_READY is succeeded
  */
 static void
-rocc_hello_sent_cb (void *cls,
-                    const struct GNUNET_SCHEDULER_TaskContext *tc)
+rocc_hello_sent_cb (void *cls)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;
 
@@ -1683,27 +1741,12 @@ rocc_hello_sent_cb (void *cls,
              rocc->op_id,
              GNUNET_i2s (&rocc->a_id),
              rocc->peer->id);
-  if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
-  {
-    GNUNET_break (0);
-    rocc->attempt_connect_task_id =
-        GNUNET_SCHEDULER_add_now (&attempt_connect_task,
-                                  rocc);
-    return;
-  }
-  if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason)
-  {
-    GNUNET_break (0);
-    return;
-  }
-
   rocc->tcc.cgh_p2_ats =
     GST_connection_pool_get_handle (rocc->peer->id,
                                     rocc->peer->details.local.cfg,
                                     GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY,
                                     &occ_cache_get_handle_ats_rocc_cb,
                                     rocc, NULL, NULL, NULL);
-
 }
 
 
@@ -1712,11 +1755,9 @@ rocc_hello_sent_cb (void *cls,
  * whose identity is in RemoteOverlayConnectCtx
  *
  * @param cls the RemoteOverlayConnectCtx
- * @param tc the TaskContext from scheduler
  */
 static void
-attempt_connect_task (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext *tc)
+attempt_connect_task (void *cls)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;
 
@@ -1727,9 +1768,10 @@ attempt_connect_task (void *cls,
              GNUNET_i2s (&rocc->a_id),
              rocc->peer->id);
   rocc->ohh =
-      GNUNET_TRANSPORT_offer_hello (rocc->tcc.th_,
+      GNUNET_TRANSPORT_offer_hello (rocc->tcc.cfg,
                                     rocc->hello,
-                                    rocc_hello_sent_cb, rocc);
+                                    &rocc_hello_sent_cb,
+                                    rocc);
   if (NULL == rocc->ohh)
     rocc->attempt_connect_task_id =
         GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
@@ -1753,9 +1795,10 @@ attempt_connect_task (void *cls,
 static void
 rocc_cache_get_handle_transport_cb (void *cls,
                                     struct GNUNET_CORE_Handle *ch,
-                                    struct GNUNET_TRANSPORT_Handle *th,
+                                    struct GNUNET_TRANSPORT_CoreHandle *th,
                                     struct GNUNET_ATS_ConnectivityHandle *ac,
-                                    const struct GNUNET_PeerIdentity *ignore_)
+                                    const struct GNUNET_PeerIdentity *ignore_,
+                                    const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;
 
@@ -1766,9 +1809,10 @@ rocc_cache_get_handle_transport_cb (void *cls,
     return;
   }
   rocc->tcc.th_ = th;
-  if (GNUNET_YES ==
-      GNUNET_TRANSPORT_check_peer_connected (rocc->tcc.th_,
-                                             &rocc->a_id))
+  rocc->tcc.cfg = cfg;
+  if (NULL !=
+      GNUNET_TRANSPORT_core_get_mq (rocc->tcc.th_,
+                                   &rocc->a_id))
   {
     LOG_DEBUG ("0x%llx: Target peer %s already connected to local peer: %u\n",
                rocc->op_id,
@@ -1783,65 +1827,72 @@ rocc_cache_get_handle_transport_cb (void *cls,
 
 
 /**
- * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_REQUEST_CONNECT messages
+ * Check #GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT messages
  *
- * @param cls NULL
- * @param client identification of the client
- * @param message the actual message
+ * @param cls identification of the client
+ * @param msg the actual message
+ * @return #GNUNET_OK if @a msg is well-formed
  */
-void
-GST_handle_remote_overlay_connect (void *cls,
-                                   struct GNUNET_SERVER_Client *client,
-                                   const struct GNUNET_MessageHeader *message)
+int
+check_remote_overlay_connect (void *cls,
+                               const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg)
 {
-  const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg;
-  struct RemoteOverlayConnectCtx *rocc;
-  struct Peer *peer;
-  struct GNUNET_PeerIdentity pid;
-  static char pid_str[16];
   uint32_t peer_id;
   uint16_t msize;
   uint16_t hsize;
 
-  msize = ntohs (message->size);
-  if (sizeof (struct GNUNET_TESTBED_RemoteOverlayConnectMessage) >= msize)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-  msg = (const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *) message;
-  if ((NULL == msg->hello) ||
-      ((GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type))))
+  msize = ntohs (msg->header.size);
+  if (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type))
   {
     GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
+    return GNUNET_SYSERR;
   }
   hsize = ntohs (msg->hello->size);
-  if ((sizeof (struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hsize) !=
-      msize)
+  if ((sizeof (struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hsize) != msize)
   {
     GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
+    return GNUNET_SYSERR;
   }
   peer_id = ntohl (msg->peer);
   if ((peer_id >= GST_peer_list_size) ||
-      (NULL == (peer = GST_peer_list[peer_id])))
+      (NULL == GST_peer_list[peer_id]))
   {
     GNUNET_break_op (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
+    return GNUNET_SYSERR;
   }
+  return GNUNET_OK;
+}
+
+
+/**
+ * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT messages
+ *
+ * @param cls identification of the client
+ * @param msg the actual message
+ */
+void
+handle_remote_overlay_connect (void *cls,
+                               const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg)
+{
+  struct GNUNET_SERVICE_Client *client = cls;
+  struct RemoteOverlayConnectCtx *rocc;
+  struct Peer *peer;
+  struct GNUNET_PeerIdentity pid;
+  static char pid_str[16];
+  uint32_t peer_id;
+  uint16_t hsize;
+
+  hsize = ntohs (msg->hello->size);
+  peer_id = ntohl (msg->peer);
+  peer = GST_peer_list[peer_id];
   if (GNUNET_YES == peer->is_remote)
   {
     struct GNUNET_MessageHeader *msg2;
 
-    msg2 = GNUNET_copy_message (message);
+    msg2 = GNUNET_copy_message (&msg->header);
     GNUNET_TESTBED_queue_message_ (peer->details.remote.slave->controller,
                                    msg2);
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    GNUNET_SERVICE_client_continue (client);
     return;
   }
   rocc = GNUNET_new (struct RemoteOverlayConnectCtx);
@@ -1863,7 +1914,9 @@ GST_handle_remote_overlay_connect (void *cls,
   rocc->peer = peer;
   rocc->peer->reference_cnt++;
   rocc->hello = GNUNET_malloc (hsize);
-  memcpy (rocc->hello, msg->hello, hsize);
+  GNUNET_memcpy (rocc->hello,
+                 msg->hello,
+                 hsize);
   rocc->tcc.cgh_p2_th =
       GST_connection_pool_get_handle (peer_id,
                                       rocc->peer->details.local.cfg,
@@ -1877,8 +1930,7 @@ GST_handle_remote_overlay_connect (void *cls,
       GNUNET_SCHEDULER_add_delayed (GST_timeout,
                                     &timeout_rocc_task,
                                     rocc);
-  GNUNET_SERVER_receive_done (client,
-                              GNUNET_OK);
+  GNUNET_SERVICE_client_continue (client);
 }