gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r23425 - gnunet/src/testbed
Date: Mon, 27 Aug 2012 11:10:37 +0200

Author: harsha
Date: 2012-08-27 11:10:37 +0200 (Mon, 27 Aug 2012)
New Revision: 23425

Modified:
   gnunet/src/testbed/testbed_api.c
   gnunet/src/testbed/testbed_api.h
   gnunet/src/testbed/testbed_api_services.c
Log:
service connect checkpoint save

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-08-27 08:13:21 UTC (rev 23424)
+++ gnunet/src/testbed/testbed_api.c    2012-08-27 09:10:37 UTC (rev 23425)
@@ -538,6 +538,18 @@
     LOG_DEBUG ("Operation not found\n");
     return GNUNET_YES;
   }
+  if (OP_FORWARDED == opc->type)
+  {
+    struct ForwardedOperationData *fo_data;
+    
+    fo_data = opc->data;
+    if (NULL != fo_data->cc)
+      fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
+    GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
+    GNUNET_free (fo_data);
+    GNUNET_free (opc);    
+    return GNUNET_YES;    
+  }
   data = opc->data;
   GNUNET_assert (NULL != data);
   peer = data->peer;
@@ -571,29 +583,9 @@
     }
     break;
   case GNUNET_TESTBED_PIT_CONFIGURATION:
-    {
-      struct GNUNET_CONFIGURATION_Handle *cfg;
-      char *config;
-      uLong config_size;
-      int ret;
-      uint16_t msize;
-      
-      config_size = (uLong) ntohs (msg->config_size);
-      config = GNUNET_malloc (config_size);
-      msize = ntohs (msg->header.size);
-      msize -= sizeof (struct 
GNUNET_TESTBED_PeerConfigurationInformationMessage);
-      if (Z_OK != (ret = uncompress ((Bytef *) config, &config_size,
-                                    (const Bytef *) &msg[1], (uLong) msize)))
-       GNUNET_assert (0);
-      cfg = GNUNET_CONFIGURATION_create (); /* Freed in oprelease_peer_getinfo 
*/
-      GNUNET_assert (GNUNET_OK == 
-                    GNUNET_CONFIGURATION_deserialize (cfg, config,
-                                                      (size_t) config_size,
-                                                      GNUNET_NO));
-      GNUNET_free (config);
-      response_data->details.cfg = cfg;
-      info.details.operation_finished.op_result.cfg = cfg;
-    }
+    response_data->details.cfg = /* Freed in oprelease_peer_getinfo */
+      GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg);
+    info.details.operation_finished.op_result.cfg = response_data->details.cfg;
     break;
   case GNUNET_TESTBED_PIT_GENERIC:
     GNUNET_assert (0);         /* never reach here */
@@ -602,7 +594,13 @@
   opc->data = response_data;
   GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
   opc->state = OPC_STATE_FINISHED;
-  c->cc (c->cc_cls, &info);  
+  if (0 != ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT)
+            & c->event_mask))
+  {
+    if (NULL != c->cc)
+      c->cc (c->cc_cls, &info);
+  }
+  
   return GNUNET_YES;
 }
 
@@ -1292,6 +1290,8 @@
   if (GNUNET_YES == controller->aux_host)
     GNUNET_TESTBED_host_destroy (controller->host);
   GNUNET_TESTBED_operation_queue_destroy_ 
(controller->opq_parallel_operations);
+  GNUNET_TESTBED_operation_queue_destroy_
+    (controller->opq_parallel_service_connections);
   GNUNET_free (controller);
 }
 
@@ -1622,4 +1622,38 @@
   }
 }
 
+
+/**
+ * Generates configuration by parsing Peer configuration information reply 
message
+ *
+ * @param msg the peer configuration information message
+ * @return handle to the parsed configuration
+ */
+struct GNUNET_CONFIGURATION_Handle *
+GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct
+                                              
GNUNET_TESTBED_PeerConfigurationInformationMessage
+                                              *msg)
+{
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+  char *config;
+  uLong config_size;
+  int ret;
+  uint16_t msize;
+  
+  config_size = (uLong) ntohs (msg->config_size);
+  config = GNUNET_malloc (config_size);
+  msize = ntohs (msg->header.size);
+  msize -= sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
+  if (Z_OK != (ret = uncompress ((Bytef *) config, &config_size,
+                                 (const Bytef *) &msg[1], (uLong) msize)))
+    GNUNET_assert (0);
+  cfg = GNUNET_CONFIGURATION_create ();
+  GNUNET_assert (GNUNET_OK == 
+                 GNUNET_CONFIGURATION_deserialize (cfg, config,
+                                                      (size_t) config_size,
+                                                   GNUNET_NO));
+  GNUNET_free (config);
+  return cfg;
+}
+
 /* end of testbed_api.c */

Modified: gnunet/src/testbed/testbed_api.h
===================================================================
--- gnunet/src/testbed/testbed_api.h    2012-08-27 08:13:21 UTC (rev 23424)
+++ gnunet/src/testbed/testbed_api.h    2012-08-27 09:10:37 UTC (rev 23425)
@@ -28,6 +28,7 @@
 #define TESTBED_API_H
 
 #include "gnunet_testbed_service.h"
+#include "testbed.h"
 
 /**
  * Enumeration of operations
@@ -74,11 +75,6 @@
      */
     OP_LINK_CONTROLLERS,
 
-    /**
-     * Service connect operation
-     */
-    OP_SERVICE_CONNECT
-
   };
 
 
@@ -392,5 +388,16 @@
 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
 
 
+/**
+ * Generates configuration by parsing Peer configuration information reply 
message
+ *
+ * @param msg the peer configuration information message
+ * @return handle to the parsed configuration
+ */
+struct GNUNET_CONFIGURATION_Handle *
+GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct
+                                              
GNUNET_TESTBED_PeerConfigurationInformationMessage
+                                              *msg);
+
 #endif
 /* end of testbed_api.h */

Modified: gnunet/src/testbed/testbed_api_services.c
===================================================================
--- gnunet/src/testbed/testbed_api_services.c   2012-08-27 08:13:21 UTC (rev 
23424)
+++ gnunet/src/testbed/testbed_api_services.c   2012-08-27 09:10:37 UTC (rev 
23425)
@@ -55,6 +55,31 @@
    */
   void *op_cls;
 
+  /**
+   * The operation which created this structure
+   */
+  struct GNUNET_TESTBED_Operation *operation;
+
+  /**
+   * The operation context from GNUNET_TESTBED_forward_operation_msg_()
+   */
+  struct OperationContext *opc;
+
+  /**
+   * The peer handle
+   */
+  struct GNUNET_TESTBED_Peer *peer;
+
+  /**
+   * The acquired configuration of the peer
+   */
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  /**
+   * The op_result pointer from ConnectAdapter
+   */
+  void *op_result;
+  
 };
 
 
@@ -67,7 +92,39 @@
 };
 
 
+/**
+ * Type of a function to call when we receive a message
+ * from the service.
+ *
+ * @param cls ServiceConnectData
+ * @param msg message received, NULL on timeout or fatal error
+ */
+static void 
+configuration_receiver (void *cls,
+                        const struct GNUNET_MessageHeader *msg)
+{
+  struct ServiceConnectData *data = cls;
+  const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg;
+  struct GNUNET_TESTBED_Controller *c;  
+  struct GNUNET_TESTBED_EventInformation info;  
+  
+  imsg = (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)
+    msg;
+  data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg);
+  data->op_result = data->ca (data->cada_cls, data->cfg);
+  info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
+  info.details.operation_finished.operation = data->operation;
+  info.details.operation_finished.op_cls = data->op_cls;
+  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;    
+  if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask))
+      && (NULL != c->cc))
+      c->cc (c->cc_cls, &info);  
+}
 
+
 /**
  * Function called when a service connect operation is ready
  *
@@ -76,7 +133,21 @@
 static void 
 opstart_service_connect (void *cls)
 {
-  GNUNET_break (0);
+  struct ServiceConnectData *data = cls;
+  struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
+  struct GNUNET_TESTBED_Controller *c;  
+  uint64_t op_id;  
+  
+  GNUNET_assert (NULL != data);
+  GNUNET_assert (NULL != data->peer);
+  c = data->peer->controller;  
+  op_id = c->operation_counter++;  
+  msg = GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id,
+                                                    op_id);
+  data->opc =
+    GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header,
+                                           &configuration_receiver, data);
+  
 }
 
 
@@ -120,26 +191,22 @@
                                GNUNET_TESTBED_DisconnectAdapter da,
                                void *cada_cls)
 {
-  struct OperationContext *opc;
   struct ServiceConnectData *data;
 
   data = GNUNET_malloc (sizeof (struct ServiceConnectData));
   data->ca = ca;
   data->da = da;
   data->cada_cls = cada_cls;
-  data->op_cls = op_cls;  
-  opc = GNUNET_malloc (sizeof (struct OperationContext));
-  opc->data = data;
-  opc->c = peer->controller;
-  opc->id = peer->controller->operation_counter++;
-  opc->type = OP_SERVICE_CONNECT;
-  opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_service_connect,
-                                              &oprelease_service_connect);
+  data->op_cls = op_cls;
+  data->peer = peer;  
+  data->operation = 
+    GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect,
+                                      &oprelease_service_connect);
   GNUNET_TESTBED_operation_queue_insert_
-    (opc->c->opq_parallel_service_connections, opc->op);
-  GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
-                                          opc->op);
-  return opc->op;
+    (peer->controller->opq_parallel_service_connections, data->operation);
+  GNUNET_TESTBED_operation_queue_insert_
+    (peer->controller->opq_parallel_operations, data->operation);
+  return data->operation;  
 }
 
 /* end of testbed_api_services.c */




reply via email to

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