gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r23407 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r23407 - gnunet/src/testbed
Date: Fri, 24 Aug 2012 15:51:06 +0200

Author: harsha
Date: 2012-08-24 15:51:06 +0200 (Fri, 24 Aug 2012)
New Revision: 23407

Modified:
   gnunet/src/testbed/gnunet-service-testbed.c
   gnunet/src/testbed/test_testbed_api_controllerlink.c
Log:
peer create fowarding with tests

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-08-24 13:44:13 UTC (rev 
23406)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-08-24 13:51:06 UTC (rev 
23407)
@@ -433,7 +433,7 @@
 
 
 /**
- * Context information for operations forward to subcontrollers
+ * Context information for operations forwarded to subcontrollers
  */
 struct ForwardedOperationContext
 {
@@ -448,6 +448,11 @@
   struct GNUNET_SERVER_Client *client;
 
   /**
+   * Closure pointer
+   */
+  void *cls;  
+
+  /**
    * Task ID for the timeout task
    */
   GNUNET_SCHEDULER_TaskIdentifier timeout_task;
@@ -457,10 +462,6 @@
    */
   uint64_t operation_id;  
 
-  /**
-   * The ID of the peer we are going to create
-   */
-  uint32_t peer_id;
 };
 
 
@@ -1533,7 +1534,7 @@
   
   /* 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);  
@@ -1552,13 +1553,24 @@
                         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);
@@ -1677,8 +1689,8 @@
   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,
@@ -1714,8 +1726,8 @@
              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 for destroy when peer not created at us\n");
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
@@ -2242,8 +2254,11 @@
   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);

Modified: gnunet/src/testbed/test_testbed_api_controllerlink.c
===================================================================
--- gnunet/src/testbed/test_testbed_api_controllerlink.c        2012-08-24 
13:44:13 UTC (rev 23406)
+++ gnunet/src/testbed/test_testbed_api_controllerlink.c        2012-08-24 
13:51:06 UTC (rev 23407)
@@ -75,8 +75,17 @@
     /**
      * Link from slave 1 to slave 2 has been successfully created.
      */
+    SLAVE2_LINK_SUCCESS,
+
+    /**
+     * Peer create on slave 1 successful
+     */
+    SLAVE1_PEER_CREATE_SUCCESS,
+
+    /**
+     * Test is successful
+     */
     SUCCESS
-
   };
 
 /**
@@ -125,6 +134,16 @@
 static struct GNUNET_TESTBED_Operation *op;
 
 /**
+ * Handle to peer started at slave 1
+ */
+static struct GNUNET_TESTBED_Peer *slave1_peer;
+
+/**
+ * Handle to peer started at slave 2
+ */
+static struct GNUNET_TESTBED_Peer *slave2_peer;
+
+/**
  * Event mask
  */
 uint64_t event_mask;
@@ -180,6 +199,43 @@
 
 
 /**
+ * Functions of this signature are called when a peer has been successfully
+ * created
+ *
+ * @param cls the closure from GNUNET_TESTBED_peer_create()
+ * @param peer the handle for the created peer; NULL on any error during
+ *          creation
+ * @param emsg NULL if peer is not NULL; else MAY contain the error description
+ */
+static void 
+peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
+{
+  switch (result)
+  {
+  case SLAVE2_LINK_SUCCESS:
+    GNUNET_assert (NULL != peer);
+    GNUNET_assert (NULL == emsg);
+    result = SLAVE1_PEER_CREATE_SUCCESS;    
+    slave1_peer = peer;
+    GNUNET_TESTBED_operation_done (op);    
+    op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL);
+    GNUNET_assert (NULL != op);
+    break;
+  case SLAVE1_PEER_CREATE_SUCCESS:
+    GNUNET_assert (NULL != peer);
+    GNUNET_assert (NULL == emsg);
+    result = SUCCESS;
+    slave2_peer = peer;    
+    GNUNET_TESTBED_operation_done (op);
+    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+    break;
+  default:
+    GNUNET_assert (0);    
+  }
+}
+
+
+/**
  * Signature of the event handler function called by the
  * respective event controller.
  *
@@ -218,9 +274,10 @@
     GNUNET_assert (NULL == 
event->details.operation_finished.op_result.generic);
     GNUNET_TESTBED_operation_done (op);
     op = NULL;
-    result = SUCCESS;
-    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
-    break;
+    result = SLAVE2_LINK_SUCCESS;
+    op = GNUNET_TESTBED_peer_create (mc, slave, cfg, peer_create_cb, NULL);
+    GNUNET_assert (NULL != op);
+    break;    
   default:
     GNUNET_assert (0);
   }
@@ -256,10 +313,7 @@
     op = GNUNET_TESTBED_controller_link (mc, slave, NULL, cfg, GNUNET_YES);
     GNUNET_assert (NULL != op);
     break;
-  case INIT:
-  case SUCCESS:
-  case SLAVE2_REGISTERED:
-  case SLAVE1_LINK_SUCCESS:
+  default:
     GNUNET_assert (0);
   }
 }




reply via email to

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