gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r23076 - gnunet/src/testbed
Date: Sat, 4 Aug 2012 00:34:45 +0200

Author: harsha
Date: 2012-08-04 00:34:45 +0200 (Sat, 04 Aug 2012)
New Revision: 23076

Modified:
   gnunet/src/testbed/gnunet-service-testbed.c
   gnunet/src/testbed/test_testbed_api_2peers.c
   gnunet/src/testbed/testbed.h
   gnunet/src/testbed/testbed_api.c
   gnunet/src/testbed/testbed_api_peers.c
   gnunet/src/testbed/testbed_api_peers.h
Log:
refined overlay connect and extended test case

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-08-03 20:18:58 UTC (rev 
23075)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-08-03 22:34:45 UTC (rev 
23076)
@@ -324,6 +324,11 @@
 struct OverlayConnectContext
 {
   /**
+   * The client which has requested for overlay connection
+   */
+  struct GNUNET_SERVER_Client *client;
+
+  /**
    * peer 1 and peer2
    */
   struct Peer * peers[2];
@@ -349,6 +354,11 @@
   struct GNUNET_PeerIdentity peers_identity[2];
 
   /**
+   * The id of the operation responsible for creating this context
+   */
+  uint64_t op_id;
+
+  /**
    * State information for determining whose HELLOs have been successfully
    * exchanged
    */
@@ -1528,27 +1538,6 @@
 
 
 /**
- * Task to be executed when HELLO has been sent
- *
- * @param cls overlay connect context wrapper
- * @param tc the task context from scheduler
- */
-static void
-overlay_connect_finalize (void *cls, 
-                         const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct OverlayConnectContextWrapper *occw = cls;
-  struct OverlayConnectContext *occ;
-  unsigned int peer;
-  
-  peer = occw->peer;
-  occ = occw->occ;
-  GNUNET_free (occw);
-  GNUNET_free (occ->peers_hello[peer ^ 1]);
-}
-
-
-/**
  * Exchanges HELLO of peers among them
  *
  * @param occ the OverlayConnectContext to look into for HELLO messages
@@ -1556,7 +1545,6 @@
 static void
 exchange_hellos (struct OverlayConnectContext *occ)
 {
-  struct OverlayConnectContextWrapper *occw;
   unsigned int peer;
 
   GNUNET_assert (NULL != occ->peers_hello[0]);
@@ -1564,12 +1552,12 @@
   LOG_DEBUG ("Exchanging hellos\n");
   for (peer = 0; peer < 2; peer++)
   {
-    occw = GNUNET_malloc (sizeof (struct OverlayConnectContextWrapper));
-    occw->occ = occ;
-    occw->peer = peer;
     GNUNET_TRANSPORT_offer_hello (occ->peers_transport[peer], 
                                  occ->peers_hello[peer ^ 1],
-                                 &overlay_connect_finalize, occw);
+                                 NULL, NULL);
+    GNUNET_TRANSPORT_try_connect (occ->peers_transport[peer],
+                                  &occ->peers_identity[peer ^ 1]);
+    GNUNET_free (occ->peers_hello[peer ^ 1]);
   }
 }
 
@@ -1607,17 +1595,51 @@
  * peer connected to us.
  *
  * @param cls closure
- * @param peer the peer that connected
+ * @param new_peer the peer that connected
  * @param ats performance data
  * @param ats_count number of entries in ats (excluding 0-termination)
  */
 static void 
 overlay_connect_notify (void *cls,
-                       const struct GNUNET_PeerIdentity * peer,
+                       const struct GNUNET_PeerIdentity * new_peer,
                        const struct GNUNET_ATS_Information * ats,
                        uint32_t ats_count)
 {
-  GNUNET_break (0);            /* To be implemented */
+  struct OverlayConnectContextWrapper *occw = cls;
+  struct OverlayConnectContext *occ;
+  struct GNUNET_TESTBED_ConnectionEventMessage *msg;
+  unsigned int peer;
+
+  peer = occw->peer;
+  occ = occw->occ;
+  if (0 != memcmp (new_peer, &occ->peers_identity[peer ^ 1],
+                   sizeof (struct GNUNET_PeerIdentity)))
+  {
+    LOG_DEBUG ("Unexpected peer %4s connected to peer %4s\n",
+               GNUNET_i2s (new_peer), 
+               GNUNET_i2s (&occ->peers_identity[peer ^ 1]));
+    return;
+  }
+  GNUNET_free (occw);
+  LOG_DEBUG ("Peer %4s connected to peer %4s\n", GNUNET_i2s (new_peer),
+             GNUNET_i2s (&occ->peers_identity[peer ^ 1]));
+  GNUNET_TRANSPORT_disconnect (occ->peers_transport[peer]);
+  occ->peers_transport[peer] = NULL;
+  if (NULL != occ->peers_transport[peer ^ 1])
+    return;
+  /* Peers are connected - now send overlay connect success message */
+  LOG_DEBUG ("Peers connected - Sending overlay connect success\n");
+  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
+  msg->header.size = htons (sizeof (struct
+                                    GNUNET_TESTBED_ConnectionEventMessage));
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT);
+  msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT);
+  msg->peer1 = occ->peers[0]->id;
+  msg->peer2 = occ->peers[1]->id;
+  msg->operation_id = GNUNET_htonll (occ->op_id);
+  queue_message (occ->client, &msg->header);  
+  GNUNET_SERVER_client_drop (occ->client);
+  GNUNET_free (occ);  
 }
 
 
@@ -1648,9 +1670,12 @@
   GNUNET_assert (p2 < peer_list_size);
   GNUNET_assert (NULL != peer_list[p2]);
   occ = GNUNET_malloc (sizeof (struct OverlayConnectContext));
+  GNUNET_SERVER_client_keep (client);
+  occ->client = client;
   occ->state = OCC_STATE_INIT;
   occ->peers[0] = peer_list[p1];
-  occ->peers[1] = peer_list[p2];  
+  occ->peers[1] = peer_list[p2];
+  occ->op_id = GNUNET_ntohll (msg->operation_id);
   for (peer = 0; peer < 2; peer++)
   {
     occw = GNUNET_malloc (sizeof (struct OverlayConnectContextWrapper));
@@ -1666,6 +1691,7 @@
       GNUNET_TRANSPORT_get_hello (occ->peers_transport[peer], 
                                  &hello_update_cb, occw);
   }
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 

Modified: gnunet/src/testbed/test_testbed_api_2peers.c
===================================================================
--- gnunet/src/testbed/test_testbed_api_2peers.c        2012-08-03 20:18:58 UTC 
(rev 23075)
+++ gnunet/src/testbed/test_testbed_api_2peers.c        2012-08-03 22:34:45 UTC 
(rev 23076)
@@ -43,7 +43,29 @@
 #define TIME_REL_SECS(sec) \
   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
 
+
 /**
+ * Peer context
+ */
+struct PeerContext
+{
+  /**
+   * The peer handle
+   */ 
+  struct GNUNET_TESTBED_Peer *peer;
+  
+  /**
+   * Operations involving this peer
+   */
+  struct GNUNET_TESTBED_Operation *operation;
+
+  /**
+   * set to GNUNET_YES when peer is started
+   */
+  int is_running;
+};
+
+/**
  * Our localhost
  */
 static struct GNUNET_TESTBED_Host *host;
@@ -69,19 +91,24 @@
 static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
 
 /**
- * Handle for a peer
+ * peer 1
  */
-static struct GNUNET_TESTBED_Peer *peer;
+static struct PeerContext peer1;
 
 /**
+ * peer2
+ */
+static struct PeerContext peer2;
+
+/**
  * Handle to configuration
  */
 static struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
- * Handle to operation
+ * Handle to operations involving both peers
  */
-static struct GNUNET_TESTBED_Operation *operation;
+static struct GNUNET_TESTBED_Operation *common_operation;
 
 /**
  * Abort task identifier
@@ -89,9 +116,46 @@
 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
 
 /**
+ * Different stages in testing
+ */
+enum Stage
+  {
+
+    /**
+     * Initial stage
+     */
+    INIT,
+    
+    /**
+     * peers are created
+     */
+    PEERS_CREATED,
+    
+    /**
+     * peers are started
+     */
+    PEERS_STARTED,
+    
+    /**
+     * peers are connected
+     */
+    PEERS_CONNECTED,
+
+    /**
+     * peers are stopped
+     */
+    PEERS_STOPPED,
+
+    /**
+     * Final success stage
+     */
+    SUCCESS
+  };
+
+/**
  * The testing result
  */
-static int result;
+static enum Stage result;
 
 
 /**
@@ -141,15 +205,92 @@
 static void 
 controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
 {
-  GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
-  GNUNET_assert (event->details.operation_finished.operation == operation);
-  GNUNET_assert (NULL == event->details.operation_finished.op_cls);
-  GNUNET_assert (NULL == event->details.operation_finished.emsg);
-  GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC ==
-                 event->details.operation_finished.pit);
-  GNUNET_assert (NULL == event->details.operation_finished.op_result.generic);
-  result = GNUNET_YES;  
-  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ switch (event->type)
+ {
+ case GNUNET_TESTBED_ET_OPERATION_FINISHED:
+   GNUNET_assert (PEERS_STOPPED == result);
+   GNUNET_assert (NULL == event->details.operation_finished.op_cls);
+   GNUNET_assert (NULL == event->details.operation_finished.emsg);
+   GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC ==
+                  event->details.operation_finished.pit);
+   GNUNET_assert (NULL ==
+                  event->details.operation_finished.op_result.generic);
+   if (event->details.operation_finished.operation == peer1.operation)
+   {
+     GNUNET_TESTBED_operation_done (peer1.operation);
+     peer1.operation = NULL;
+     peer1.peer = NULL;
+   }
+   else if (event->details.operation_finished.operation == peer2.operation)
+   {
+     GNUNET_TESTBED_operation_done (peer2.operation);
+     peer2.operation = NULL;
+     peer2.peer = NULL;
+   }
+   else
+     GNUNET_assert (0);
+   result = GNUNET_YES;  
+   GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+   break;
+ case GNUNET_TESTBED_ET_PEER_START:
+   GNUNET_assert (INIT == result);
+   GNUNET_assert (event->details.peer_start.host == host);
+   if (event->details.peer_start.peer == peer1.peer)
+   {
+     peer1.is_running = GNUNET_YES;
+     GNUNET_TESTBED_operation_done (peer1.operation);
+     peer1.operation = NULL;
+   }
+   else if (event->details.peer_start.peer == peer2.peer)
+   {
+     peer2.is_running = GNUNET_YES;
+     GNUNET_TESTBED_operation_done (peer2.operation);
+     peer2.operation = NULL;
+   }
+   else
+     GNUNET_assert (0);
+   if ((GNUNET_YES == peer1.is_running) && (GNUNET_YES == peer2.is_running))
+   {
+     result = PEERS_STARTED;
+     common_operation =
+       GNUNET_TESTBED_overlay_connect (NULL, peer1.peer, peer2.peer);
+   }
+   break;
+ case GNUNET_TESTBED_ET_PEER_STOP:
+   GNUNET_assert (PEERS_CONNECTED == result);
+   if (event->details.peer_stop.peer == peer1.peer)
+   {
+     peer1.is_running = GNUNET_NO;
+     GNUNET_TESTBED_operation_done (peer1.operation);
+     peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
+   }
+   else if (event->details.peer_stop.peer == peer2.peer)
+   {
+     peer2.is_running = GNUNET_NO;
+     GNUNET_TESTBED_operation_done (peer2.operation);
+     peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
+   }
+   else
+     GNUNET_assert (0);
+   if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running))
+     result = PEERS_STOPPED;
+   break;
+ case GNUNET_TESTBED_ET_CONNECT:
+   GNUNET_assert (PEERS_STARTED == result);
+   GNUNET_assert (NULL == peer1.operation);
+   GNUNET_assert (NULL == peer2.operation);
+   GNUNET_assert (NULL != common_operation);
+   GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) 
+                  && (event->details.peer_connect.peer2 == peer2.peer));
+   GNUNET_TESTBED_operation_done (common_operation);
+   common_operation = NULL;
+   result = PEERS_CONNECTED;
+   peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer);
+   peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer);  
+   break;
+ default:
+   GNUNET_assert (0);
+ };
 }
 
 
@@ -166,14 +307,14 @@
 peer_create_cb (void *cls,
                struct GNUNET_TESTBED_Peer *peer, const char *emsg)
 {
-  struct GNUNET_TESTBED_Peer **peer_ptr;
-  
-  peer_ptr = cls;
+  struct PeerContext *pc = cls;
+
+  GNUNET_assert (NULL != pc->operation);
   GNUNET_assert (NULL != peer);
-  GNUNET_assert (NULL != peer_ptr);
-  *peer_ptr = peer;
-  operation = GNUNET_TESTBED_peer_destroy (peer);
-  GNUNET_assert (NULL != operation);
+  GNUNET_assert (NULL == pc->peer);
+  pc->peer = peer;
+  GNUNET_TESTBED_operation_done (pc->operation);
+  pc->operation = GNUNET_TESTBED_peer_start (pc->peer);
 }
 
 
@@ -188,8 +329,12 @@
 {
   GNUNET_assert (cls == neighbour);
   reg_handle = NULL;  
-  operation = GNUNET_TESTBED_peer_create (controller, host, cfg, 
&peer_create_cb, &peer);
-  GNUNET_assert (NULL != operation);
+  peer1.operation = GNUNET_TESTBED_peer_create (controller, host, cfg,
+                                                &peer_create_cb, &peer1);
+  peer2.operation = GNUNET_TESTBED_peer_create (controller, host, cfg,
+                                                &peer_create_cb, &peer2);
+  GNUNET_assert (NULL != peer1.operation);
+  GNUNET_assert (NULL != peer2.operation);
 }
 
 
@@ -262,11 +407,11 @@
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
-  result = GNUNET_SYSERR;
+  result = INIT;
   ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
                            "test_testbed_api", "nohelp", options, &run,
                            NULL);
-  if ((GNUNET_OK != ret) || (GNUNET_OK != result))
+  if ((GNUNET_OK != ret) || (SUCCESS != result))
     return 1;
   return 0;
 }

Modified: gnunet/src/testbed/testbed.h
===================================================================
--- gnunet/src/testbed/testbed.h        2012-08-03 20:18:58 UTC (rev 23075)
+++ gnunet/src/testbed/testbed.h        2012-08-03 22:34:45 UTC (rev 23076)
@@ -441,7 +441,7 @@
 
   /**
    * 'enum GNUNET_TESTBED_EventType' (in NBO);
-   * either GNUNET_TESTBED_ET_PEER_CONNECT or 
GNUNET_TESTBED_ET_PEER_DISCONNECT.
+   * either GNUNET_TESTBED_ET_CONNECT or GNUNET_TESTBED_ET_DISCONNECT.
    */
   int32_t event_type GNUNET_PACKED;
   

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-08-03 20:18:58 UTC (rev 23075)
+++ gnunet/src/testbed/testbed_api.c    2012-08-03 22:34:45 UTC (rev 23076)
@@ -401,6 +401,61 @@
 
 
 /**
+ * Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT message from
+ * controller (testbed service)
+ *
+ * @param c the controller handler
+ * @param msg message received
+ * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
+ *           not
+ */
+static int
+handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
+                      const struct GNUNET_TESTBED_ConnectionEventMessage *msg)
+{
+  struct OperationContext *opc;
+  struct OverlayConnectData *data;
+  struct GNUNET_TESTBED_EventInformation event;
+  uint64_t op_id;
+
+  op_id = GNUNET_ntohll (msg->operation_id);
+  if (NULL == (opc = find_opc (c, op_id)))
+  {
+    LOG_DEBUG ("Operation not found\n");
+    return GNUNET_YES;
+  }
+  data = opc->data;
+  GNUNET_assert (NULL != data);
+  GNUNET_assert ((ntohl (msg->peer1) == data->p1->unique_id)
+                  && (ntohl (msg->peer2) == data->p2->unique_id));             
  
+  event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
+  switch (event.type)
+  {
+  case GNUNET_TESTBED_ET_CONNECT:
+    event.details.peer_connect.peer1 = data->p1;
+    event.details.peer_connect.peer2 = data->p2;
+    break;
+  case GNUNET_TESTBED_ET_DISCONNECT:
+    GNUNET_assert (0);          /* FIXME: implement */
+    break;
+  default:
+    GNUNET_assert (0);          /* Should never reach here */
+    break;
+  }
+  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  opc->state = OPC_STATE_FINISHED;
+  GNUNET_free (data);
+  if (0 != ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT)
+            & c->event_mask))
+  {
+    if (NULL != c->cc)
+      c->cc (c->cc_cls, &event);
+  }
+  return GNUNET_YES;
+}
+
+
+/**
  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG message from
  * controller (testbed service)
  *
@@ -554,6 +609,12 @@
       (c, (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)
   msg);
     break;
+  case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT:
+    GNUNET_assert (msize ==
+                   sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
+    status = 
+      handle_peer_conevent (c, (const struct
+                                GNUNET_TESTBED_ConnectionEventMessage *) msg);
   default:
     GNUNET_break (0);
   }
@@ -1356,13 +1417,13 @@
   case OP_PEER_START:
   case OP_PEER_STOP:
   case OP_PEER_INFO:
+  case OP_OVERLAY_CONNECT:
     GNUNET_TESTBED_operation_release_ (operation);
     return;
-  case OP_OVERLAY_CONNECT:
-    GNUNET_free_non_null (operation->data);
+  default:
+    GNUNET_assert (0);
     break;
   }
-  GNUNET_free (operation);
 }
 
 

Modified: gnunet/src/testbed/testbed_api_peers.c
===================================================================
--- gnunet/src/testbed/testbed_api_peers.c      2012-08-03 20:18:58 UTC (rev 
23075)
+++ gnunet/src/testbed/testbed_api_peers.c      2012-08-03 22:34:45 UTC (rev 
23076)
@@ -23,7 +23,9 @@
  * @brief management of the knowledge about peers in this library
  *        (we know the peer ID, its host, pending operations, etc.)
  * @author Christian Grothoff
+ * @author Sree Harsha Totakura
  */
+
 #include "platform.h"
 #include "testbed_api_peers.h"
 #include "testbed_api.h"
@@ -321,7 +323,14 @@
 static void 
 oprelease_overlay_connect (void *cls)
 {
-  GNUNET_break (0);
+  struct OperationContext *opc = cls;
+  
+  if (OPC_STATE_FINISHED != opc->state)
+  {
+    GNUNET_free (opc->data);
+    GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  }
+  GNUNET_free (opc);  
 }
 
 
@@ -631,6 +640,8 @@
   opc->type = OP_OVERLAY_CONNECT;
   opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect,
                                               &oprelease_overlay_connect);
+  GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create,
+                                          opc->op);
   return opc->op;
 }
 

Modified: gnunet/src/testbed/testbed_api_peers.h
===================================================================
--- gnunet/src/testbed/testbed_api_peers.h      2012-08-03 20:18:58 UTC (rev 
23075)
+++ gnunet/src/testbed/testbed_api_peers.h      2012-08-03 22:34:45 UTC (rev 
23076)
@@ -22,7 +22,9 @@
  * @file testbed/testbed_api_peers.h
  * @brief internal API to access the 'peers' subsystem
  * @author Christian Grothoff
+ * @author Sree Harsha Totakura
  */
+
 #ifndef NEW_TESTING_API_PEERS_H
 #define NEW_TESTING_API_PEERS_H
 




reply via email to

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