gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r23448 - gnunet/src/testbed
Date: Mon, 27 Aug 2012 19:36:44 +0200

Author: harsha
Date: 2012-08-27 19:36:43 +0200 (Mon, 27 Aug 2012)
New Revision: 23448

Modified:
   gnunet/src/testbed/Makefile.am
   gnunet/src/testbed/test_testbed_api.c
   gnunet/src/testbed/testbed_api_services.c
Log:
peer service connect and its test case

Modified: gnunet/src/testbed/Makefile.am
===================================================================
--- gnunet/src/testbed/Makefile.am      2012-08-27 15:50:25 UTC (rev 23447)
+++ gnunet/src/testbed/Makefile.am      2012-08-27 17:36:43 UTC (rev 23448)
@@ -96,6 +96,7 @@
 test_testbed_api_LDADD = \
  $(top_builddir)/src/util/libgnunetutil.la \
  $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/dht/libgnunetdht.la \
  libgnunettestbed.la
 
 test_testbed_api_2peers_SOURCES = \

Modified: gnunet/src/testbed/test_testbed_api.c
===================================================================
--- gnunet/src/testbed/test_testbed_api.c       2012-08-27 15:50:25 UTC (rev 
23447)
+++ gnunet/src/testbed/test_testbed_api.c       2012-08-27 17:36:43 UTC (rev 
23448)
@@ -26,10 +26,10 @@
 
 #include "platform.h"
 #include "gnunet_util_lib.h"
+#include "gnunet_dht_service.h"
 #include "gnunet_testing_lib-new.h"
 #include "gnunet_testbed_service.h"
 
-
 /**
  * Generic logging shortcut
  */
@@ -83,6 +83,11 @@
 static struct GNUNET_TESTBED_Operation *operation;
 
 /**
+ * Handle to peer's DHT service
+ */
+static struct GNUNET_DHT_Handle *dht_handle;
+
+/**
  * Abort task identifier
  */
 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
@@ -109,6 +114,11 @@
     PEER_GETCONFIG,
 
     /**
+     * Test where we connect to a service running on the peer
+     */
+    PEER_SERVICE_CONNECT,
+
+    /**
      * Test where we get a peer's identity from controller
      */
     PEER_DESTROY,
@@ -158,6 +168,49 @@
 
 
 /**
+ * Adapter function called to establish a connection to
+ * a service.
+ * 
+ * @param cls closure
+ * @param cfg configuration of the peer to connect to; will be available until
+ *          GNUNET_TESTBED_operation_done() is called on the operation returned
+ *          from GNUNET_TESTBED_service_connect()
+ * @return service handle to return in 'op_result', NULL on error
+ */
+static void *
+dht_connect_adapter (void *cls,
+                     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  GNUNET_assert (NULL == cls);
+  GNUNET_assert (OTHER == sub_test);
+  sub_test = PEER_SERVICE_CONNECT;
+  dht_handle = GNUNET_DHT_connect (cfg, 10);
+  return dht_handle;
+}
+
+
+/**
+ * Adapter function called to destroy a connection to
+ * a service.
+ * 
+ * @param cls closure
+ * @param op_result service handle returned from the connect adapter
+ */
+static void 
+dht_disconnect_adapter (void *cls,
+                        void *op_result)
+{
+  if (NULL != op_result)
+    GNUNET_DHT_disconnect (op_result);
+  GNUNET_assert (PEER_SERVICE_CONNECT == sub_test);
+  GNUNET_assert (NULL != operation);
+  operation = GNUNET_TESTBED_peer_stop (peer);
+  GNUNET_assert (NULL != operation);
+}
+
+
+
+/**
  * Signature of the event handler function called by the
  * respective event controller.
  *
@@ -194,6 +247,18 @@
       GNUNET_TESTBED_operation_done (operation);
       GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
       break;
+    case PEER_SERVICE_CONNECT:
+      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 != dht_handle);
+      GNUNET_assert (event->details.operation_finished.op_result.generic
+                     == dht_handle);
+      GNUNET_TESTBED_operation_done (operation); /* This results in call to
+                                                  * disconnect adapter */
+      break;
     case OTHER:
       GNUNET_assert (0);
       break;
@@ -202,11 +267,17 @@
   case GNUNET_TESTBED_ET_PEER_START:
     GNUNET_assert (event->details.peer_start.host == host);
     GNUNET_assert (event->details.peer_start.peer == peer);
+    GNUNET_assert (OTHER == sub_test);
     GNUNET_TESTBED_operation_done (operation);
-    operation = GNUNET_TESTBED_peer_stop (peer);
+    operation = GNUNET_TESTBED_service_connect (NULL, peer, "dht",
+                                                &dht_connect_adapter,
+                                                &dht_disconnect_adapter,
+                                                NULL);
+    GNUNET_assert (NULL != operation);
     break;
   case GNUNET_TESTBED_ET_PEER_STOP:
-    GNUNET_assert (event->details.peer_stop.peer == peer);    
+    GNUNET_assert (event->details.peer_stop.peer == peer);
+    GNUNET_assert (PEER_SERVICE_CONNECT == sub_test);
     result = GNUNET_YES;
     sub_test = PEER_GETCONFIG;
     GNUNET_TESTBED_operation_done (operation);

Modified: gnunet/src/testbed/testbed_api_services.c
===================================================================
--- gnunet/src/testbed/testbed_api_services.c   2012-08-27 15:50:25 UTC (rev 
23447)
+++ gnunet/src/testbed/testbed_api_services.c   2012-08-27 17:36:43 UTC (rev 
23448)
@@ -28,6 +28,36 @@
 #include "testbed_api_peers.h"
 #include "testbed_api_operations.h"
 
+
+/**
+ * States for Service connect operations
+ */
+enum State
+  {
+    /**
+     * Initial state
+     */
+    INIT,
+
+    /**
+     * The configuration request has been sent
+     */
+    CFG_REQUEST_QUEUED,
+
+    /**
+     * connected to service
+     */
+    SERVICE_CONNECTED,
+
+    /**
+     * 
+     */
+  };
+
+
+/**
+ * Data accessed during service connections
+ */
 struct ServiceConnectData
 {
   /**
@@ -79,15 +109,11 @@
    * The op_result pointer from ConnectAdapter
    */
   void *op_result;
-  
-};
 
-
-/**
- * Context information for forwarded operation used in service connect
- */
-struct SCFOContext
-{
+  /**
+   * State information
+   */
+  enum State state;
   
 };
 
@@ -118,10 +144,11 @@
   info.details.operation_finished.emsg = NULL;
   info.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC;
   info.details.operation_finished.op_result.generic = data->op_result;
-  c = data->peer->controller;    
+  c = data->peer->controller;
+  data->state = SERVICE_CONNECTED;
   if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask))
       && (NULL != c->cc))
-      c->cc (c->cc_cls, &info);  
+      c->cc (c->cc_cls, &info);
 }
 
 
@@ -147,7 +174,8 @@
   data->opc =
     GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header,
                                            &configuration_receiver, data);
-  
+  GNUNET_free (msg);
+  data->state = CFG_REQUEST_QUEUED;
 }
 
 
@@ -160,7 +188,24 @@
 static void 
 oprelease_service_connect (void *cls)
 {
-  GNUNET_break (0); 
+  struct ServiceConnectData *data = cls;
+
+  switch (data->state)
+  {
+  case INIT:
+    break;
+  case CFG_REQUEST_QUEUED:
+    GNUNET_assert (NULL != data->opc);
+    GNUNET_TESTBED_forward_operation_msg_cancel_ (data->opc);
+    break;
+  case SERVICE_CONNECTED:
+    GNUNET_assert (NULL != data->cfg);
+    GNUNET_CONFIGURATION_destroy (data->cfg);
+    if (NULL != data->da)
+      data->da (data->cada_cls, data->op_result);
+    break;
+  }
+  GNUNET_free (data);
 }
 
 
@@ -198,7 +243,8 @@
   data->da = da;
   data->cada_cls = cada_cls;
   data->op_cls = op_cls;
-  data->peer = peer;  
+  data->peer = peer;
+  data->state = INIT;
   data->operation = 
     GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect,
                                       &oprelease_service_connect);




reply via email to

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