-fix check
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed.c
index 81cf29c5ff2ec24275c4b4fcc183b87fb532f0c6..c9b7c930a43c88f727d35022dec8bbc1aa1a990d 100644 (file)
@@ -1803,10 +1803,11 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
   master_context = GNUNET_malloc (sizeof (struct Context));
+  GNUNET_SERVER_client_keep (client);
   master_context->client = client;
   master_context->host_id = ntohl (msg->host_id);
   master_context->master_ip = GNUNET_strdup (controller_hostname);
-  LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip);
+  LOG_DEBUG ("Our IP: %s\n", master_context->master_ip);
   master_context->system =
       GNUNET_TESTING_system_create ("testbed", master_context->master_ip, hostname);
   host =
@@ -1815,7 +1816,6 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
                                           NULL,
                                           0);
   host_list_add (host);
-  GNUNET_SERVER_client_keep (client);
   LOG_DEBUG ("Created master context with host ID: %u\n",
              master_context->host_id);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -2239,7 +2239,7 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
 /**
  * Function to destroy a peer
  *
- * @param the peer structure to destroy
+ * @param peer the peer structure to destroy
  */
 static void
 destroy_peer (struct Peer *peer)
@@ -3311,31 +3311,18 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
     if ((peer2_host_id >= slave_list_size)
        || (NULL ==slave_list[peer2_host_id]))
     {
-      struct GNUNET_TESTBED_NeedControllerConfig *reply;
-
-      LOG_DEBUG ("Need controller configuration for connecting peers %u and %u\n",
-                p1, p2);
-      reply = GNUNET_malloc (sizeof (struct
-                                     GNUNET_TESTBED_NeedControllerConfig)); 
-      reply->header.size = htons (sizeof (struct
-                                          GNUNET_TESTBED_NeedControllerConfig));
-      reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG);
-      reply->controller_host_id = msg->peer2_host_id;
-      reply->operation_id = msg->operation_id;
-      queue_message (client, &reply->header);      
-      GNUNET_SERVER_receive_done (client, GNUNET_OK);
+      LOG (GNUNET_ERROR_TYPE_WARNING,
+           "Configuration of peer2's controller missing for connecting peers"
+           "%u and %u\n", p1, p2);      
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
       return;
     }
-    else
+    peer2_controller = slave_list[peer2_host_id]->controller;
+    if (NULL == peer2_controller)
     {
-      //occ->peer2_controller = slave_list[peer2_host_id]->controller;
-      peer2_controller = slave_list[peer2_host_id]->controller;
-      if (NULL == peer2_controller)
-      {
-        GNUNET_break (0);       /* What's going on? */
-        GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-        return;
-      }
+      GNUNET_break (0);       /* What's going on? */
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+      return;
     }
   }
   else
@@ -3672,7 +3659,7 @@ reghost_free_iterator (void *cls,
     cleanup_focc (focc);
   }
   if (NULL != rhc->sub_op)
-    GNUNET_TESTBED_operation_cancel (rhc->sub_op);
+    GNUNET_TESTBED_operation_done (rhc->sub_op);
   if (NULL != rhc->client)
   GNUNET_SERVER_client_drop (rhc->client);
   GNUNET_free (value);
@@ -3693,6 +3680,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct OverlayConnectContext *occ;
   struct RequestOverlayConnectContext *rocc;
   struct ForwardedOperationContext *fopc;
+  struct MessageQueue *mq_entry;
   uint32_t id;
 
   shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
@@ -3808,9 +3796,19 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_free_non_null (master_context->master_ip);
     if (NULL != master_context->system)
       GNUNET_TESTING_system_destroy (master_context->system, GNUNET_YES);
+    GNUNET_SERVER_client_drop (master_context->client);
     GNUNET_free (master_context);
     master_context = NULL;
   }
+  if (NULL != transmit_handle)
+    GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle);  
+  while (NULL != (mq_entry = mq_head))
+  {
+    GNUNET_free (mq_entry->msg);
+    GNUNET_SERVER_client_drop (mq_entry->client);
+    GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);    
+    GNUNET_free (mq_entry);
+  }
   GNUNET_free_non_null (hostname);
   GNUNET_CONFIGURATION_destroy (our_config);
 }