towards handling suboperations during overlay connect
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed.c
index b5282cffc39d66964b56ca183e7b26f51561a17e..05d296fee451ef07d68dd7175a5608ce56a30b8c 100644 (file)
@@ -79,7 +79,7 @@ struct Context
    * The TESTING system handle for starting peers locally
    */
   struct GNUNET_TESTING_System *system;
-
+  
   /**
    * Event mask of event to be responded in this context
    */
@@ -180,8 +180,7 @@ struct Slave
   struct GNUNET_TESTBED_Controller *controller;
 
   /**
-   * The configuration of the slave. Will be NULL for slave which we didn't
-   * directly start
+   * The configuration of the slave. Cannot be NULL
    */
   struct GNUNET_CONFIGURATION_Handle *cfg;
 
@@ -296,7 +295,7 @@ struct LCFContextQueue
 
 
 /**
- * A locally started peer
+ * A peer
  */
 struct Peer
 {
@@ -598,7 +597,7 @@ static struct Route **route_list;
 static struct Slave **slave_list;
 
 /**
- * A list of peers we own locally
+ * A list of peers we know about
  */
 static struct Peer **peer_list;
 
@@ -1546,7 +1545,7 @@ handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
           GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
                                              master_context->event_mask,
                                              &slave_event_callback, slave);
-      GNUNET_CONFIGURATION_destroy (cfg);
+      slave->cfg = cfg;
       if (NULL != slave->controller)
         send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
       else
@@ -2042,8 +2041,20 @@ handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
   peer = peer_list[peer_id];
   if (GNUNET_YES == peer->is_remote)
   {
-    /* FIXME: forward to sub controller */
-    GNUNET_break (0);
+    struct ForwardedOperationContext *fopc;
+    
+    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;
   }
@@ -2453,7 +2464,7 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
   occ->peer_id = p1;
   occ->other_peer_id = p2;
   occ->peer = peer_list[p1];
-  occ->op_id = GNUNET_ntohll (msg->operation_id);
+  occ->op_id = GNUNET_ntohll (msg->operation_id);  
   if ((p2 >= peer_list_size) || (NULL == peer_list[p2]))
   {
     uint32_t peer2_host_id;
@@ -2462,21 +2473,32 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
     if ((peer2_host_id >= slave_list_size)
        || (NULL ==slave_list[peer2_host_id]))
     {
-      GNUNET_break (0);
-      GNUNET_SERVER_client_drop (client);
+      struct GNUNET_TESTBED_NeedControllerConfig *reply;
+
       GNUNET_free (occ);
-      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+      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);
       return;
     }
-    occ->peer2_controller = slave_list[peer2_host_id]->controller;
-    if (NULL == occ->peer2_controller)
+    else
     {
-      GNUNET_break (0);
-      GNUNET_SERVER_client_drop (client);
-      GNUNET_free (occ);
-      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-      return;
-    }   
+      occ->peer2_controller = slave_list[peer2_host_id]->controller;
+      if (NULL == occ->peer2_controller)
+      {
+        GNUNET_break (0);       /* What's going on? */
+        GNUNET_SERVER_client_drop (client);
+        GNUNET_free (occ);
+        GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+        return;
+      }
+    }
   }
   else
   {
@@ -2656,10 +2678,14 @@ handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-  if (GNUNET_NO != peer->is_remote)
+  if (GNUNET_YES == peer->is_remote)
   {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    struct GNUNET_MessageHeader *msg2;
+    
+    msg2 = GNUNET_malloc (msize);
+    (void) memcpy (msg2, message, msize);
+    GNUNET_TESTBED_queue_message_ (peer->details.remote.controller, msg2);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
   rocc = GNUNET_malloc (sizeof (struct RequestOverlayConnectContext));
@@ -2676,8 +2702,6 @@ handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
           sizeof (struct GNUNET_PeerIdentity));
   rocc->hello = GNUNET_malloc (hsize);
   memcpy (rocc->hello, msg->hello, hsize);
-  /* GNUNET_TRANSPORT_offer_hello (th, msg->hello, NULL, NULL); */
-  /* GNUNET_TRANSPORT_try_connect (th, &msg->peer_identity); */
   rocc->attempt_connect_task_id =
       GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc);
   rocc->timeout_rocc_task_id =