GNUNET_TESTBED_run and test cases
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed.c
index 7398ee19cff193b04b87270c881cbae6e12d13d1..57d9bafa98b85a0209285fa20cc870ff06c14dfe 100644 (file)
@@ -213,35 +213,30 @@ enum LCFContextState
  */
 struct LCFContext
 {
-  /**
-   * The serialized and compressed configuration
-   */
-  char *sxcfg;
-
   /**
    * The gateway which will pass the link message to delegated host
    */
   struct Slave *gateway;
 
   /**
-   * The host registration handle while registered hosts in this context
+   * The controller link message that has to be forwarded to
    */
-  struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
+  struct GNUNET_TESTBED_ControllerLinkMessage *msg;
 
   /**
-   * The size of the compressed serialized configuration
+   * The client which has asked to perform this operation
    */
-  size_t sxcfg_size;
+  struct GNUNET_SERVER_Client *client;
 
   /**
-   * The size of the uncompressed configuration
+   * The host registration handle while registered hosts in this context
    */
-  size_t scfg_size;
+  struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
 
   /**
-   * Should the delegated host be started by the slave host?
+   * The id of the operation which created this context
    */
-  int is_subordinate;
+  uint64_t operation_id;
 
   /**
    * The state of this context
@@ -438,7 +433,7 @@ struct OverlayConnectContext
 
 
 /**
- * Context information for operations forward to subcontrollers
+ * Context information for operations forwarded to subcontrollers
  */
 struct ForwardedOperationContext
 {
@@ -452,6 +447,11 @@ struct ForwardedOperationContext
    */
   struct GNUNET_SERVER_Client *client;
 
+  /**
+   * Closure pointer
+   */
+  void *cls;  
+
   /**
    * Task ID for the timeout task
    */
@@ -462,13 +462,32 @@ struct ForwardedOperationContext
    */
   uint64_t operation_id;  
 
+};
+
+
+/**
+ * Context information used while linking controllers
+ */
+struct LinkControllersContext
+{
   /**
-   * The ID of the peer we are going to create
+   * The client which initiated the link controller operation
    */
-  uint32_t peer_id;
+  struct GNUNET_SERVER_Client *client;
+
+  /**
+   * The ID of the operation
+   */
+  uint64_t operation_id;
+  
+  /**
+   * Pointer to the slave handle if we are directly starting/connecting to the controller
+   */
+  struct Slave *slave;
 };
 
 
+
 /**
  * The master context; generated with the first INIT message
  */
@@ -842,6 +861,29 @@ send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
 }
 
 
+/**
+ * Function to send generic operation success message to given client
+ *
+ * @param client the client to send the message to
+ * @param operation_id the id of the operation which was successful
+ */
+static void
+send_operation_success_msg (struct GNUNET_SERVER_Client *client,
+                           uint64_t operation_id)
+{
+  struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
+  uint16_t msize;
+  
+  msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);  
+  msg = GNUNET_malloc (msize);
+  msg->header.size = htons (msize);
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
+  msg->operation_id = GNUNET_htonll (operation_id);
+  msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
+  queue_message (client, &msg->header);  
+}
+
+
 /**
  * The  Link Controller forwarding task
  *
@@ -892,6 +934,51 @@ lcf_proc_cc (void *cls, const char *emsg)
 }
 
 
+/**
+ * Callback to be called when forwarded link controllers operation is
+ * successfull. We have to relay the reply msg back to the client
+ *
+ * @param cls ForwardedOperationContext
+ * @param msg the peer create success message
+ */
+static void
+forwarded_operation_reply_relay (void *cls,
+                                 const struct GNUNET_MessageHeader *msg)
+{
+  struct ForwardedOperationContext *fopc = cls;
+  struct GNUNET_MessageHeader *dup_msg;  
+  uint16_t msize;
+  
+  msize = ntohs (msg->size);
+  dup_msg = GNUNET_malloc (msize);
+  (void) memcpy (dup_msg, msg, msize);  
+  queue_message (fopc->client, dup_msg);
+  GNUNET_SERVER_client_drop (fopc->client);
+  GNUNET_SCHEDULER_cancel (fopc->timeout_task);  
+  GNUNET_free (fopc);
+}
+
+
+/**
+ * Task to free resources when forwarded link controllers has been timedout
+ *
+ * @param cls the ForwardedOperationContext
+ * @param tc the task context from scheduler
+ */
+static void
+forwarded_operation_timeout (void *cls,
+                                   const struct GNUNET_SCHEDULER_TaskContext
+                                   *tc)
+{
+  struct ForwardedOperationContext *fopc = cls;
+  
+  GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
+  send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
+  GNUNET_SERVER_client_drop (fopc->client);
+  GNUNET_free (fopc);  
+}
+
+
 /**
  * The  Link Controller forwarding task
  *
@@ -903,7 +990,8 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct LCFContext *lcf = cls;
   struct LCFContextQueue *lcfq;
-
+  struct ForwardedOperationContext *fopc;
+  
   lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
   switch (lcf->state)
   {
@@ -940,19 +1028,25 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     }
     break;
   case SLAVE_HOST_REGISTERED:
-    GNUNET_TESTBED_controller_link_2 (lcf->gateway->controller,
-                                      host_list[lcf->delegated_host_id],
-                                      host_list[lcf->slave_host_id],
-                                      lcf->sxcfg, lcf->sxcfg_size,
-                                      lcf->scfg_size,
-                                      lcf->is_subordinate);
+    fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
+    fopc->client = lcf->client;
+    fopc->operation_id = lcf->operation_id;
+    fopc->opc = 
+      GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller,
+                                            lcf->operation_id,
+                                            &lcf->msg->header,
+                                            &forwarded_operation_reply_relay,
+                                            fopc);
+    fopc->timeout_task = 
+      GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                   &forwarded_operation_timeout, fopc);    
     lcf->state = FINISHED;
     lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
     break;
   case FINISHED:
     lcfq = lcfq_head;
     GNUNET_assert (lcfq->lcf == lcf);
-    GNUNET_free (lcf->sxcfg);
+    GNUNET_free (lcf->msg);
     GNUNET_free (lcf);
     GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
     GNUNET_free (lcfq);
@@ -970,8 +1064,8 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param event information about the event
  */
 static void 
-slave_event_callback(void *cls,
-                     const struct GNUNET_TESTBED_EventInformation *event)
+slave_event_callback (void *cls,
+                     const struct GNUNET_TESTBED_EventInformation *event)
 {
   GNUNET_break (0);
 }
@@ -991,20 +1085,27 @@ slave_status_callback (void *cls,
                        const struct GNUNET_CONFIGURATION_Handle *cfg,
                        int status)
 {
-  struct Slave *slave = cls;
+  struct LinkControllersContext *lcc = cls;
 
   if (GNUNET_SYSERR == status)
   {
-    slave->controller_proc = NULL;
+    lcc->slave->controller_proc = NULL;
     LOG (GNUNET_ERROR_TYPE_WARNING,
          "Unexpected slave shutdown\n");
     GNUNET_SCHEDULER_shutdown ();      /* We too shutdown */
     return;
   }
-  slave->controller =
-    GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
+  lcc->slave->controller =
+    GNUNET_TESTBED_controller_connect (cfg, host_list[lcc->slave->host_id],
                                        master_context->event_mask,
-                                       &slave_event_callback, slave);
+                                       &slave_event_callback, lcc->slave);
+  if (NULL != lcc->slave->controller)
+    send_operation_success_msg (lcc->client, lcc->operation_id);
+  else
+    send_operation_fail_msg (lcc->client, lcc->operation_id,
+                            "Could not connect to delegated controller");
+  GNUNET_SERVER_client_drop (lcc->client);
+  GNUNET_free (lcc);
 }
 
 
@@ -1108,7 +1209,11 @@ handle_add_host (void *cls,
   LOG_DEBUG ("-------host id: %u\n", host_id);
   if (NULL != hostname) LOG_DEBUG ("-------hostname: %s\n", hostname);
   if (0 != username_length) LOG_DEBUG ("-------username: %s\n", username);
-  else LOG_DEBUG ("-------username: NULL\n");
+  else 
+  {
+    LOG_DEBUG ("-------username: NULL\n");
+    username = NULL;
+  }
   LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
   host = GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
                                              ntohs (msg->ssh_port));
@@ -1288,14 +1393,14 @@ handle_link_controllers (void *cls,
     LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
-  }
-  msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
-  config_size = ntohs (msg->config_size);
+  } 
   
   if (slave_host_id == master_context->host_id) /* Link from us */
   {
     struct Slave *slave;
-
+    
+    msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
+    config_size = ntohs (msg->config_size);
     if ((delegated_host_id < slave_list_size) && 
         (NULL != slave_list[delegated_host_id])) /* We have already added */
     {
@@ -1340,20 +1445,31 @@ handle_link_controllers (void *cls,
     }
     slave = GNUNET_malloc (sizeof (struct Slave));
     slave->host_id = delegated_host_id;    
-    slave_list_add (slave);    
+    slave_list_add (slave);
     if (1 == msg->is_subordinate)
     {
+      struct LinkControllersContext *lcc;
+      lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
+      lcc->operation_id = GNUNET_ntohll (msg->operation_id);
+      GNUNET_SERVER_client_keep (client);
+      lcc->client = client;
+      lcc->slave = slave;      
       slave->controller_proc =
         GNUNET_TESTBED_controller_start (master_context->master_ip,
                                         host_list[slave->host_id],
                                         cfg, &slave_status_callback,
-                                        slave);
+                                        lcc);
     }
     else {
       slave->controller = 
        GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
                                           master_context->event_mask,
                                           &slave_event_callback, slave);
+      if (NULL != slave->controller)
+       send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
+      else
+       send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
+                                "Could not connect to delegated controller");
     }
     GNUNET_CONFIGURATION_destroy (cfg);
     new_route = GNUNET_malloc (sizeof (struct Route));
@@ -1379,22 +1495,23 @@ handle_link_controllers (void *cls,
   GNUNET_assert (NULL != route); /* because we add routes carefully */
   GNUNET_assert (route->dest < slave_list_size);
   GNUNET_assert (NULL != slave_list[route->dest]);  
-  lcfq->lcf->is_subordinate =
-    (1 == msg->is_subordinate) ? GNUNET_YES : GNUNET_NO;
   lcfq->lcf->state = INIT;
+  lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
   lcfq->lcf->gateway = slave_list[route->dest];
-  lcfq->lcf->sxcfg_size = msize;
-  lcfq->lcf->sxcfg = GNUNET_malloc (msize);
-  lcfq->lcf->scfg_size = config_size;
-  (void) memcpy (lcfq->lcf->sxcfg, &msg[1], msize);
+  lcfq->lcf->msg = GNUNET_malloc (msize);
+  (void) memcpy (lcfq->lcf->msg, msg, msize);
+  GNUNET_SERVER_client_keep (client);
+  lcfq->lcf->client = client;
   if (NULL == lcfq_head)
   {
     GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
     GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
-    lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq);
+    lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
   }
   else
     GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
+  /* FIXME: Adding a new route should happen after the controllers are linked
+     successfully */
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
   new_route = GNUNET_malloc (sizeof (struct Route));
   new_route->dest = delegated_host_id;
@@ -1418,7 +1535,7 @@ peer_create_forward_timeout (void *cls,
   
   /* send error msg to client */
   send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id,
-                           "Timedout");  
+                           "Timedout");
   GNUNET_SERVER_client_drop (fo_ctxt->client);
   GNUNET_TESTBED_forward_operation_msg_cancel_ (fo_ctxt->opc);
   GNUNET_free (fo_ctxt);  
@@ -1437,13 +1554,24 @@ peer_create_success_cb (void *cls,
                         const struct GNUNET_MessageHeader *msg)
 {
   struct ForwardedOperationContext *fo_ctxt = cls;
-  struct GNUNET_MessageHeader *dup_msg;  
+  const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *success_msg;
+  struct GNUNET_MessageHeader *dup_msg;
+  struct Peer *peer;
   uint16_t msize;
   
-  GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task);  
-  GNUNET_assert (ntohs (msg->type) == 
-                 GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
-  msize = ntohs (msg->size);  
+  GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task);
+  if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
+  {
+    success_msg 
+      = (const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *) msg;
+    peer = GNUNET_malloc (sizeof (struct Peer));
+    peer->is_remote = GNUNET_YES;
+    peer->id = ntohl (success_msg->peer_id);
+    GNUNET_assert (NULL != fo_ctxt->cls);
+    peer->details.remote.controller = fo_ctxt->cls;
+    peer_list_add (peer);    
+  }
+  msize = ntohs (msg->size);
   dup_msg = GNUNET_malloc (msize);
   (void) memcpy (dup_msg, msg, msize);  
   queue_message (fo_ctxt->client, dup_msg);
@@ -1562,8 +1690,8 @@ handle_peer_create (void *cls,
   fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
   GNUNET_SERVER_client_keep (client);
   fo_ctxt->client = client;
-  fo_ctxt->peer_id = ntohl (msg->peer_id);
-  fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);  
+  fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); 
+  fo_ctxt->cls = slave_list[route->dest]->controller;  
   fo_ctxt->opc = 
     GNUNET_TESTBED_forward_operation_msg_ (slave_list[route->dest]->controller,
                                            fo_ctxt->operation_id,
@@ -1590,10 +1718,9 @@ handle_peer_destroy (void *cls,
                      const struct GNUNET_MessageHeader *message)
 {
   const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
-  struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *reply;
+  struct ForwardedOperationContext *fopc;
   struct Peer *peer;
   uint32_t peer_id;
-  uint16_t reply_size;
   
   msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
   peer_id = ntohl (msg->peer_id);
@@ -1601,8 +1728,8 @@ handle_peer_destroy (void *cls,
              peer_id, GNUNET_ntohll (msg->operation_id));  
   if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id]))
   {
-    GNUNET_break (0);
-    /* FIXME: Reply with failure event message or forward to slave controller */
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         "Asked to destroy a non existent peer with id: %u\n", peer_id);
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
@@ -1610,7 +1737,19 @@ handle_peer_destroy (void *cls,
   if (GNUNET_YES == peer->is_remote)
   {
     /* Forward the destory message to sub controller */
-    GNUNET_break (0);
+    fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
+    GNUNET_SERVER_client_keep (client);    
+    fopc->client = client;
+    fopc->operation_id = GNUNET_ntohll (msg->operation_id);
+    fopc->opc = 
+      GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
+                                             fopc->operation_id,
+                                             &msg->header,
+                                             &forwarded_operation_reply_relay,
+                                             fopc);
+    fopc->timeout_task =
+      GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                    &forwarded_operation_timeout, fopc);    
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
@@ -1618,14 +1757,7 @@ handle_peer_destroy (void *cls,
   GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
   peer_list_remove (peer);
   GNUNET_free (peer);
-  reply_size = 
-    sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
-  reply = GNUNET_malloc (reply_size);
-  reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
-  reply->header.size = htons (reply_size);
-  reply->operation_id = msg->operation_id;
-  reply->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
-  queue_message (client, &reply->header);
+  send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
@@ -1644,6 +1776,8 @@ handle_peer_start (void *cls,
 {
   const struct GNUNET_TESTBED_PeerStartMessage *msg;
   struct GNUNET_TESTBED_PeerEventMessage *reply;
+  struct ForwardedOperationContext *fopc;
+  struct Peer *peer;
   uint32_t peer_id;
 
   msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
@@ -1652,15 +1786,35 @@ handle_peer_start (void *cls,
       || (NULL == peer_list[peer_id]))
   {
     GNUNET_break (0);
-    /* FIXME: reply with failure message or forward to slave controller */
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         "Asked to start a non existent peer with id: %u\n", peer_id);    
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+  peer = peer_list[peer_id];
+  if (GNUNET_YES == peer->is_remote)
+  {
+    fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
+    GNUNET_SERVER_client_keep (client);    
+    fopc->client = client;
+    fopc->operation_id = GNUNET_ntohll (msg->operation_id);
+    fopc->opc = 
+      GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
+                                             fopc->operation_id,
+                                             &msg->header,
+                                             &forwarded_operation_reply_relay,
+                                             fopc);
+    fopc->timeout_task =
+      GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                    &forwarded_operation_timeout, fopc);    
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
   if (GNUNET_OK != 
-      GNUNET_TESTING_peer_start (peer_list[peer_id]->details.local.peer))
+      GNUNET_TESTING_peer_start (peer->details.local.peer))
   {
-    /* FIXME: return FAILURE message */
-    GNUNET_break (0);
+    send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
+                             "Failed to start");
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
@@ -1690,21 +1844,43 @@ handle_peer_stop (void *cls,
 {
   const struct GNUNET_TESTBED_PeerStopMessage *msg;
   struct GNUNET_TESTBED_PeerEventMessage *reply;
+  struct ForwardedOperationContext *fopc;
+  struct Peer *peer;
   uint32_t peer_id;
 
   msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
   peer_id = ntohl (msg->peer_id);
   if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
+  {    
+    send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
+                             "Peer not found");
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+  peer = peer_list[peer_id];
+  if (GNUNET_YES == peer->is_remote)
   {
-    GNUNET_break (0);          /* FIXME: route to slave? */
+    fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
+    GNUNET_SERVER_client_keep (client);    
+    fopc->client = client;
+    fopc->operation_id = GNUNET_ntohll (msg->operation_id);
+    fopc->opc = 
+      GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
+                                             fopc->operation_id,
+                                             &msg->header,
+                                             &forwarded_operation_reply_relay,
+                                             fopc);
+    fopc->timeout_task =
+      GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                    &forwarded_operation_timeout, fopc);    
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
   if (GNUNET_OK != 
-      GNUNET_TESTING_peer_stop (peer_list[peer_id]->details.local.peer))
+      GNUNET_TESTING_peer_stop (peer->details.local.peer))
   {
-    /* FIXME: return FAILURE message */
-    GNUNET_break (0);
+    send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
+                             "Failed to stop peer");
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
@@ -1746,8 +1922,8 @@ handle_peer_get_config (void *cls,
   peer_id = ntohl (msg->peer_id);
   if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
   {
-    /* FIXME: return FAILURE message */
-    GNUNET_break (0);
+    send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
+                             "Peer not found");
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
@@ -1810,8 +1986,8 @@ occ_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 /**
  * Task which will be run when overlay connect request has been timed out
  *
- * @param 
- * @return 
+ * @param cls the OverlayConnectContext
+ * @param tc the TaskContext
  */
 static void
 timeout_overlay_connect (void *cls,
@@ -2127,7 +2303,7 @@ shutdown_task (void *cls,
   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
   for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
   {
-    GNUNET_free (lcfq->lcf->sxcfg);
+    GNUNET_free (lcfq->lcf->msg);
     GNUNET_free (lcfq->lcf);
     GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
     GNUNET_free (lcfq);
@@ -2136,8 +2312,11 @@ shutdown_task (void *cls,
   for (id = 0; id < peer_list_size; id++)
     if (NULL != peer_list[id])
     {
-      GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer);
-      GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg);
+      if (GNUNET_NO == peer_list[id]->is_remote)
+      {        
+        GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer);
+        GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg);
+      }      
       GNUNET_free (peer_list[id]);
     }
   GNUNET_free_non_null (peer_list);
@@ -2249,7 +2428,7 @@ testbed_run (void *cls,
  */
 int main (int argc, char *const *argv)
 {
-  //sleep (30);                        /* Debugging */
+  //sleep (15);                        /* Debugging */
   return
     (GNUNET_OK ==
      GNUNET_SERVICE_run (argc,