gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r24156 - in gnunet/src: include testbed


From: gnunet
Subject: [GNUnet-SVN] r24156 - in gnunet/src: include testbed
Date: Mon, 1 Oct 2012 16:59:31 +0200

Author: harsha
Date: 2012-10-01 16:59:31 +0200 (Mon, 01 Oct 2012)
New Revision: 24156

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/include/gnunet_testbed_service.h
   gnunet/src/testbed/testbed.h
   gnunet/src/testbed/testbed_api.c
   gnunet/src/testbed/testbed_api.h
   gnunet/src/testbed/testbed_api_services.c
Log:
slave get config client part

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2012-10-01 11:50:37 UTC (rev 
24155)
+++ gnunet/src/include/gnunet_protocols.h       2012-10-01 14:59:31 UTC (rev 
24156)
@@ -1537,10 +1537,20 @@
 #define GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECTCANCEL 480
 
 /**
+ * Message to request configuration of a slave controller
+ */
+#define GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG 481
+
+/**
+ * Message which contains the configuration of slave controller
+ */
+#define GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG 482
+
+/**
  * Not really a message, but for careful checks on the testbed messages; Should
  * always be the maximum and never be used to send messages with this type
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 481
+#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 483
 
 /**
  * The initialization message towards gnunet-testbed-helper

Modified: gnunet/src/include/gnunet_testbed_service.h
===================================================================
--- gnunet/src/include/gnunet_testbed_service.h 2012-10-01 11:50:37 UTC (rev 
24155)
+++ gnunet/src/include/gnunet_testbed_service.h 2012-10-01 14:59:31 UTC (rev 
24156)
@@ -602,8 +602,11 @@
  *
  * @param op_cls the closure for the operation
  * @param master the handle to master controller
- * @param slave_host the host where the slave controller is running
- * @return the operation handle
+ * @param slave_host the host where the slave controller is running; the handle
+ *          to the slave_host should remain valid until this operation is
+ *          cancelled or marked as finished
+ * @return the operation handle; NULL if the slave_host is not registered at
+ *           master
  */
 struct GNUNET_TESTBED_Operation *
 GNUNET_TESTBED_get_slave_config (void *op_cls,

Modified: gnunet/src/testbed/testbed.h
===================================================================
--- gnunet/src/testbed/testbed.h        2012-10-01 11:50:37 UTC (rev 24155)
+++ gnunet/src/testbed/testbed.h        2012-10-01 14:59:31 UTC (rev 24156)
@@ -29,6 +29,7 @@
 
 #include "gnunet_util_lib.h"
 
+GNUNET_NETWORK_STRUCT_BEGIN
 
 /**
  * Initial message from a client to a testing control service.
@@ -641,12 +642,66 @@
   /**
    * The size of configuration when uncompressed
    */
-  uint16_t config_size;
+  uint16_t config_size GNUNET_PACKED;
 
   /* followed by gzip-compressed configuration of the peer */
 
 };
 
 
+/**
+ * Message to request configuration of a slave controller
+ */
+struct GNUNET_TESTBED_SlaveGetConfigurationMessage
+{
+  /**
+   * Type is GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * The id of the slave host
+   */
+  uint32_t slave_id GNUNET_PACKED;
+
+  /**
+   * Operation ID
+   */
+  uint64_t operation_id GNUNET_PACKED;
+
+};
+
+
+/**
+ * Reply to GETSLAVECONFIG message
+ */
+struct GNUNET_TESTBED_SlaveConfiguration
+{
+  /**
+   * Type is GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * The id of the host where the slave is running
+   */
+  uint32_t slave_id GNUNET_PACKED;
+
+  /**
+   * Operation ID
+   */
+  uint64_t operation_id GNUNET_PACKED;
+
+  /**
+   * The size of the configuration when uncompressed
+   */
+  uint16_t config_size GNUNET_PACKED;
+
+  /* followed by gzip-compressed configuration of the peer */
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
 #endif
 /* end of testbed.h */

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-10-01 11:50:37 UTC (rev 24155)
+++ gnunet/src/testbed/testbed_api.c    2012-10-01 14:59:31 UTC (rev 24156)
@@ -182,6 +182,24 @@
 
 
 /**
+ * Context data for get slave config operations
+ */
+struct GetSlaveConfigData
+{
+  /**
+   * The operation closure
+   */
+  void *op_cls;
+
+  /**
+   * The id of the slave controller
+   */
+  uint32_t slave_id;
+
+};
+
+
+/**
  * Returns the operation context with the given id if found in the Operation
  * context queues of the controller
  *
@@ -589,7 +607,7 @@
     break;
   case GNUNET_TESTBED_PIT_CONFIGURATION:
     pinfo->result.cfg =        /* Freed in oprelease_peer_getinfo */
-       GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg);    
+       GNUNET_TESTBED_get_config_from_peerinfo_msg_ (&msg->header);    
     break;
   case GNUNET_TESTBED_PIT_GENERIC:
     GNUNET_assert (0);          /* never reach here */
@@ -711,6 +729,56 @@
 
 
 /**
+ * Handler for GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG 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_slave_config (struct GNUNET_TESTBED_Controller *c,
+                    const struct GNUNET_TESTBED_SlaveConfiguration * msg)
+{
+  struct OperationContext *opc;
+  void *op_cls;
+  uint64_t op_id;
+  struct GNUNET_TESTBED_EventInformation event;  
+
+  op_id = GNUNET_ntohll (msg->operation_id);
+  if (NULL == (opc = find_opc (c, op_id)))
+  {
+    LOG_DEBUG ("Operation not found\n");
+    return GNUNET_YES;
+  }
+  if (OP_GET_SLAVE_CONFIG != opc->type)
+  {
+    GNUNET_break (0);
+    return GNUNET_YES;
+  }  
+  op_cls = ((struct GetSlaveConfigData *) opc->data)->op_cls;
+  GNUNET_free (opc->data);
+  opc->data = NULL;
+  opc->state = OPC_STATE_FINISHED;
+  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
+      (NULL != c->cc))
+  {
+    opc->data = 
+       GNUNET_TESTBED_get_config_from_peerinfo_msg_ (&msg->header);
+    event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;   
+    event.details.operation_finished.generic = opc->data;
+    event.details.operation_finished.operation = opc->op;
+    event.details.operation_finished.op_cls = op_cls;
+    event.details.operation_finished.emsg = NULL;
+    c->cc (c->cc_cls, &event);
+  }
+  return GNUNET_YES;
+}
+
+
+/**
  * Handler for messages from controller (testbed service)
  *
  * @param cls the controller handler
@@ -797,6 +865,13 @@
                                GNUNET_TESTBED_OperationFailureEventMessage *)
                               msg);
     break;
+  case GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG:
+    GNUNET_assert (msize >
+                  sizeof (struct GNUNET_TESTBED_SlaveConfiguration));
+    status = 
+       handle_slave_config (c, (const struct 
+                                GNUNET_TESTBED_SlaveConfiguration *) msg);
+    break;
   default:
     GNUNET_assert (0);
   }
@@ -1141,6 +1216,60 @@
 
 
 /**
+ * Function to be called when get slave config operation is ready
+ *
+ * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG
+ */
+static void
+opstart_get_slave_config (void *cls)
+{
+  struct OperationContext *opc = cls;
+  struct GetSlaveConfigData *data;
+  struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
+  uint16_t msize;
+  
+  data = opc->data;
+  msize = sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage);
+  msg = GNUNET_malloc (msize);
+  msg->header.size = htons (msize);
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG);
+  msg->operation_id = GNUNET_htonll (opc->id);
+  msg->slave_id = htonl (data->slave_id);
+  GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
+  opc->state = OPC_STATE_STARTED;
+}
+
+
+/**
+ * Function to be called when get slave config operation is cancelled or 
finished
+ *
+ * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG
+ */
+static void
+oprelease_get_slave_config (void *cls)
+{
+  struct OperationContext *opc = cls;
+
+  switch (opc->state)
+  {
+  case OPC_STATE_INIT:
+    GNUNET_free (opc->data);
+    break;
+  case OPC_STATE_STARTED:
+    GNUNET_free (opc->data);
+    GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+    break;
+  case OPC_STATE_FINISHED:
+    if (NULL != opc->data)
+      GNUNET_CONFIGURATION_destroy (opc->data);
+    break;
+  }
+  GNUNET_free (opc);
+}
+
+
+/**
  * Starts a controller process at the host. FIXME: add controller start 
callback
  * with the configuration with which the controller is started
  *
@@ -1651,7 +1780,9 @@
   config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size);
   cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig);
   GNUNET_free (config);
-  GNUNET_assert ((UINT16_MAX - sizeof (struct 
GNUNET_TESTBED_ControllerLinkMessage)) >= cc_size);       /* Configuration 
doesn't fit in 1 message */
+  /* Configuration doesn't fit in 1 message */
+  GNUNET_assert ((UINT16_MAX - 
+                 sizeof (struct GNUNET_TESTBED_ControllerLinkMessage)) >= 
cc_size);
   op = GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host,
                                          (const char *) cconfig, cc_size,
                                          config_size, is_subordinate);
@@ -1669,16 +1800,37 @@
  *
  * @param op_cls the closure for the operation
  * @param master the handle to master controller
- * @param slave_host the host where the slave controller is running
- * @return the operation handle
+ * @param slave_host the host where the slave controller is running; the handle
+ *          to the slave_host should remain valid until this operation is
+ *          cancelled or marked as finished
+ * @return the operation handle; NULL if the slave_host is not registered at
+ *           master
  */
 struct GNUNET_TESTBED_Operation *
 GNUNET_TESTBED_get_slave_config (void *op_cls,
                                  struct GNUNET_TESTBED_Controller *master,
                                  struct GNUNET_TESTBED_Host *slave_host)
 {
-  GNUNET_break (0);
-  return NULL;
+  struct OperationContext *opc;
+  struct GetSlaveConfigData *data;
+
+  if (GNUNET_NO == GNUNET_TESTBED_is_host_registered_ (slave_host, master))
+    return NULL;
+  data = GNUNET_malloc (sizeof (struct GetSlaveConfigData));
+  data->slave_id = GNUNET_TESTBED_host_get_id_ (slave_host);
+  data->op_cls = op_cls;
+  opc = GNUNET_malloc (sizeof (struct OperationContext));
+  opc->state = OPC_STATE_INIT;
+  opc->c = master;
+  opc->id = master->operation_counter++;
+  opc->type = OP_GET_SLAVE_CONFIG;
+  opc->data = data;
+  opc->op =
+      GNUNET_TESTBED_operation_create_ (opc, &opstart_get_slave_config,
+                                        &oprelease_get_slave_config);
+  GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations,
+                                         opc->op); 
+  return opc->op;
 }
 
 
@@ -1790,35 +1942,60 @@
 /**
  * Generates configuration by parsing Peer configuration information reply 
message
  *
- * @param msg the peer configuration information message
+ * @param msg the message containing compressed configuration. This message
+ *          should be of the following types: 
GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
+ *          GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
  * @return handle to the parsed configuration
  */
 struct GNUNET_CONFIGURATION_Handle *
-GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct
-                                              
GNUNET_TESTBED_PeerConfigurationInformationMessage
-                                              *msg)
-{
+GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct 
GNUNET_MessageHeader *msg)
+{  
   struct GNUNET_CONFIGURATION_Handle *cfg;
-  char *config;
-  uLong config_size;
+  Bytef *data;
+  const Bytef *xdata;
+  uLong data_len;
+  uLong xdata_len;
   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);
+  switch (ntohs (msg->type))
+  {
+  case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG:
+    {
+      const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg;
+
+      imsg = (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage 
*)
+         msg;
+      data_len = (uLong) ntohs (imsg->config_size);
+      xdata_len = ntohs (imsg->header.size)
+         - sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
+      xdata = (const Bytef *) &imsg[1];
+    }
+    break;
+  case GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG:
+    {
+      const struct GNUNET_TESTBED_SlaveConfiguration *imsg;
+
+      imsg = (const struct GNUNET_TESTBED_SlaveConfiguration *) msg;
+      data_len = (uLong) ntohs (imsg->config_size);
+      xdata_len =  ntohs (imsg->header.size) 
+         - sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
+      xdata = (const Bytef *) &imsg[1];
+    }
+    break;
+  default:
+    GNUNET_assert (0);
+  }  
+  data = GNUNET_malloc (data_len);
   if (Z_OK !=
       (ret =
-       uncompress ((Bytef *) config, &config_size, (const Bytef *) &msg[1],
-                   (uLong) msize)))
+       uncompress (data, &data_len, xdata, xdata_len)))
     GNUNET_assert (0);
   cfg = GNUNET_CONFIGURATION_create ();
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_deserialize (cfg, config,
-                                                   (size_t) config_size,
+                 GNUNET_CONFIGURATION_deserialize (cfg, (const char *) data,
+                                                   (size_t) data_len,
                                                    GNUNET_NO));
-  GNUNET_free (config);
+  GNUNET_free (data);
   return cfg;
 }
 

Modified: gnunet/src/testbed/testbed_api.h
===================================================================
--- gnunet/src/testbed/testbed_api.h    2012-10-01 11:50:37 UTC (rev 24155)
+++ gnunet/src/testbed/testbed_api.h    2012-10-01 14:59:31 UTC (rev 24156)
@@ -75,6 +75,11 @@
      */
   OP_LINK_CONTROLLERS,
 
+  /**
+   * Get slave config operation
+   */
+  OP_GET_SLAVE_CONFIG
+
 };
 
 
@@ -399,9 +404,8 @@
  * @return handle to the parsed configuration
  */
 struct GNUNET_CONFIGURATION_Handle *
-GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct
-                                              
GNUNET_TESTBED_PeerConfigurationInformationMessage
-                                              *msg);
+GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct 
+                                             GNUNET_MessageHeader *msg);
 
 
 /**

Modified: gnunet/src/testbed/testbed_api_services.c
===================================================================
--- gnunet/src/testbed/testbed_api_services.c   2012-10-01 11:50:37 UTC (rev 
24155)
+++ gnunet/src/testbed/testbed_api_services.c   2012-10-01 14:59:31 UTC (rev 
24156)
@@ -136,7 +136,6 @@
 configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
 {
   struct ServiceConnectData *data = cls;
-  const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg;
   struct GNUNET_TESTBED_Controller *c;
   const char *emsg;
   struct GNUNET_TESTBED_EventInformation info;
@@ -159,9 +158,7 @@
     info.details.operation_finished.generic = NULL;
     goto call_cb;
   }  
-  imsg =
-      (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg;
-  data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg);
+  data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg);
   GNUNET_assert (NULL == data->op_result);
   data->op_result = data->ca (data->cada_cls, data->cfg);  
   info.details.operation_finished.emsg = NULL;




reply via email to

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