[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26182 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26182 - gnunet/src/testbed |
Date: |
Thu, 21 Feb 2013 18:06:37 +0100 |
Author: harsha
Date: 2013-02-21 18:06:37 +0100 (Thu, 21 Feb 2013)
New Revision: 26182
Modified:
gnunet/src/testbed/gnunet-service-testbed.c
gnunet/src/testbed/gnunet-service-testbed.h
gnunet/src/testbed/testbed.h
gnunet/src/testbed/testbed_api.c
gnunet/src/testbed/testbed_api.h
gnunet/src/testbed/testbed_api_hosts.c
gnunet/src/testbed/testbed_api_hosts.h
Log:
send configurations of newly started slave controllers as part of controller
link operations
Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2013-02-21 17:06:30 UTC (rev
26181)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2013-02-21 17:06:37 UTC (rev
26182)
@@ -475,8 +475,62 @@
/**
- * Callback which will be called to after a host registration succeeded or
failed
+ * Function to send a failure reponse for controller link operation
*
+ * @param client the client to send the message to
+ * @param operation_id the operation ID of the controller link request
+ * @param cfg the configuration with which the delegated controller is started.
+ * Can be NULL if the delegated controller is not started but just
+ * linked to.
+ * @param emsg set to an error message explaining why the controller link
+ * failed. Setting this to NULL signifies success. !This should be
+ * NULL if cfg is set!
+ */
+static void
+send_controller_link_response (struct GNUNET_SERVER_Client *client,
+ uint64_t operation_id,
+ const struct GNUNET_CONFIGURATION_Handle
+ *cfg,
+ const char *emsg)
+{
+ struct GNUNET_TESTBED_ControllerLinkResponse *msg;
+ char *xconfig;
+ size_t config_size;
+ size_t xconfig_size;
+ uint16_t msize;
+
+ GNUNET_assert ((NULL == cfg) || (NULL == emsg));
+ xconfig = NULL;
+ xconfig_size = 0;
+ config_size = 0;
+ msize = sizeof (struct GNUNET_TESTBED_ControllerLinkResponse);
+ if (NULL != cfg)
+ {
+ xconfig = GNUNET_TESTBED_compress_cfg_ (cfg,
+ &config_size,
+ &xconfig_size);
+ msize += xconfig_size;
+ }
+ if (NULL != emsg)
+ msize += strlen (emsg);
+ msg = GNUNET_malloc (msize);
+ msg->header.type = htons
+ (GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT);
+ msg->header.size = htons (msize);
+ if (NULL == emsg)
+ msg->success = htons (GNUNET_YES);
+ msg->operation_id = GNUNET_htonll (operation_id);
+ msg->config_size = htons ((uint16_t) config_size);
+ if (NULL != xconfig)
+ memcpy (&msg[1], xconfig, xconfig_size);
+ if (NULL != emsg)
+ memcpy (&msg[1], emsg, strlen (emsg));
+ GST_queue_message (client, &msg->header);
+}
+
+/**
+ * Callback which will be called after a host registration succeeded or failed
+ *
* @param cls the handle to the slave at which the registration is completed
* @param emsg the error message; NULL if host registration is successful
*/
@@ -704,10 +758,18 @@
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct LCFContext *lcf = cls;
+ struct ForwardedOperationContext *fopc = lcf->fopc;
GNUNET_assert (NULL != lcf->fopc);
lcf->fopc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- GST_forwarded_operation_timeout (lcf->fopc, tc);
+ // GST_forwarded_operation_timeout (lcf->fopc, tc);
+ GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "A forwarded operation as part of controller linking has timed out\n");
+ send_controller_link_response (fopc->client, fopc->operation_id, NULL,
"Timeout");
+ GNUNET_SERVER_client_drop (fopc->client);
+ GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
+ GNUNET_free (fopc);
lcf->fopc = NULL;
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
@@ -867,13 +929,13 @@
slave);
if (NULL != slave->controller)
{
- send_operation_success_msg (lcc->client, lcc->operation_id);
+ send_controller_link_response (lcc->client, lcc->operation_id, cfg, NULL);
slave->cfg = GNUNET_CONFIGURATION_dup (cfg);
}
else
{
- GST_send_operation_fail_msg (lcc->client, lcc->operation_id,
- "Could not connect to delegated controller");
+ send_controller_link_response (lcc->client, lcc->operation_id, NULL,
+ "Could not connect to delegated
controller");
GNUNET_TESTBED_controller_stop (slave->controller_proc);
GST_slave_list[slave->host_id] = NULL;
GNUNET_free (slave);
@@ -1168,7 +1230,7 @@
handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
+ const struct GNUNET_TESTBED_ControllerLinkRequest *msg;
struct GNUNET_CONFIGURATION_Handle *cfg;
struct LCFContextQueue *lcfq;
struct Route *route;
@@ -1187,13 +1249,13 @@
return;
}
msize = ntohs (message->size);
- if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
+ if (sizeof (struct GNUNET_TESTBED_ControllerLinkRequest) >= msize)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
+ msg = (const struct GNUNET_TESTBED_ControllerLinkRequest *) message;
delegated_host_id = ntohl (msg->delegated_host_id);
if (delegated_host_id == GST_context->host_id)
{
@@ -1231,7 +1293,7 @@
struct Slave *slave;
struct LinkControllersContext *lcc;
- msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
+ msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkRequest);
config_size = ntohs (msg->config_size);
if ((delegated_host_id < GST_slave_list_size) && (NULL !=
GST_slave_list[delegated_host_id])) /* We have already added */
{
@@ -1287,10 +1349,15 @@
slave);
slave->cfg = cfg;
if (NULL != slave->controller)
- send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
+ send_controller_link_response (client,
+ GNUNET_ntohll (msg->operation_id),
+ NULL,
+ NULL);
else
- GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
- "Could not connect to delegated
controller");
+ send_controller_link_response (client,
+ GNUNET_ntohll (msg->operation_id),
+ NULL,
+ "Could not connect to delegated
controller");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
Modified: gnunet/src/testbed/gnunet-service-testbed.h
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.h 2013-02-21 17:06:30 UTC (rev
26181)
+++ gnunet/src/testbed/gnunet-service-testbed.h 2013-02-21 17:06:37 UTC (rev
26182)
@@ -509,7 +509,7 @@
/**
* The controller link message that has to be forwarded to
*/
- struct GNUNET_TESTBED_ControllerLinkMessage *msg;
+ struct GNUNET_TESTBED_ControllerLinkRequest *msg;
/**
* The client which has asked to perform this operation
Modified: gnunet/src/testbed/testbed.h
===================================================================
--- gnunet/src/testbed/testbed.h 2013-02-21 17:06:30 UTC (rev 26181)
+++ gnunet/src/testbed/testbed.h 2013-02-21 17:06:37 UTC (rev 26182)
@@ -166,7 +166,7 @@
* requests for a particular client to a particular
* sub-controller.
*/
-struct GNUNET_TESTBED_ControllerLinkMessage
+struct GNUNET_TESTBED_ControllerLinkRequest
{
/**
@@ -207,6 +207,42 @@
/**
+ * Response message for ControllerLinkRequest message
+ */
+struct GNUNET_TESTBED_ControllerLinkResponse
+{
+
+ /**
+ * Type is GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * The size of the compressed configuration. Can be ZERO if the controller is
+ * not started (depends on the ControllerLinkRequest). NBO.
+ */
+ uint16_t config_size GNUNET_PACKED;
+
+ /**
+ * Set to GNUNET_YES to signify SUCCESS; GNUNET_NO to signify failure
+ */
+ uint16_t success GNUNET_PACKED;
+
+ /**
+ * The id of the operation which created this message. NBO
+ */
+ uint64_t operation_id GNUNET_PACKED;
+
+ /* If controller linking is successful and configuration is present, then
here
+ * comes the serialized gzip configuration with which the controller is
+ * running at the delegate host */
+
+ /* In case of failure, here comes the error message (without \0
termination)*/
+
+};
+
+
+/**
* Message sent from client to testing service to
* create (configure, but not start) a peer.
*/
Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c 2013-02-21 17:06:30 UTC (rev 26181)
+++ gnunet/src/testbed/testbed_api.c 2013-02-21 17:06:37 UTC (rev 26182)
@@ -169,8 +169,13 @@
/**
* The controller link message
*/
- struct GNUNET_TESTBED_ControllerLinkMessage *msg;
+ struct GNUNET_TESTBED_ControllerLinkRequest *msg;
+ /**
+ * The id of the host which is hosting the controller to be linked
+ */
+ uint32_t host_id;
+
};
@@ -280,16 +285,6 @@
//PEERDESTROYDATA
}
break;
- case OP_LINK_CONTROLLERS:
- {
- struct ControllerLinkData *data;
-
- data = opc->data;
- GNUNET_assert (NULL != data);
- GNUNET_free (data);
- opc->data = NULL;
- }
- break;
default:
GNUNET_assert (0);
}
@@ -748,6 +743,93 @@
/**
+ * 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_link_controllers_result (struct GNUNET_TESTBED_Controller *c,
+ const struct
+ GNUNET_TESTBED_ControllerLinkResponse *msg)
+{
+ struct OperationContext *opc;
+ struct ControllerLinkData *data;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct GNUNET_TESTBED_Host *host;
+ char *emsg;
+ 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_FORWARDED == opc->type)
+ {
+ handle_forwarded_operation_msg (c, opc,
+ (const struct GNUNET_MessageHeader *) msg);
+ return GNUNET_YES;
+ }
+ if (OP_LINK_CONTROLLERS != opc->type)
+ {
+ GNUNET_break (0);
+ return GNUNET_YES;
+ }
+ data = opc->data;
+ GNUNET_assert (NULL != data);
+ host = GNUNET_TESTBED_host_lookup_by_id_ (data->host_id);
+ GNUNET_assert (NULL != host);
+ GNUNET_free (data);
+ opc->data = NULL;
+ event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
+ event.details.operation_finished.operation = opc->op;
+ event.details.operation_finished.op_cls = opc->op_cls;
+ event.details.operation_finished.emsg = NULL;
+ event.details.operation_finished.generic = NULL;
+ emsg = NULL;
+ cfg = NULL;
+ if (GNUNET_NO == ntohs (msg->success))
+ {
+ emsg = GNUNET_malloc (ntohs (msg->header.size)
+ - sizeof (struct
+ GNUNET_TESTBED_ControllerLinkResponse) +
1);
+ memcpy (emsg, &msg[1], ntohs (msg->header.size)
+ - sizeof (struct
+ GNUNET_TESTBED_ControllerLinkResponse));
+ event.details.operation_finished.emsg = emsg;
+ }
+ else
+ {
+ if (0 != ntohs (msg->config_size))
+ {
+ cfg = GNUNET_TESTBED_extract_config_ ((const struct GNUNET_MessageHeader
*) msg);
+ GNUNET_assert (NULL != cfg);
+ GNUNET_TESTBED_host_replace_cfg_ (host, cfg);
+ }
+ }
+ GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+ opc->state = OPC_STATE_FINISHED;
+ if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
+ {
+ if (NULL != c->cc)
+ c->cc (c->cc_cls, &event);
+ }
+ else
+ LOG_DEBUG ("Not calling callback\n");
+ if (NULL != cfg)
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free_non_null (emsg);
+ return GNUNET_YES;
+}
+
+
+/**
* Handler for messages from controller (testbed service)
*
* @param cls the controller handler
@@ -840,6 +922,13 @@
(const struct GNUNET_TESTBED_SlaveConfiguration *)
msg);
break;
+ case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT:
+ status =
+ handle_link_controllers_result (c,
+ (const struct
+ GNUNET_TESTBED_ControllerLinkResponse
+ *) msg);
+ break;
default:
GNUNET_assert (0);
}
@@ -1010,7 +1099,7 @@
{
struct OperationContext *opc = cls;
struct ControllerLinkData *data;
- struct GNUNET_TESTBED_ControllerLinkMessage *msg;
+ struct GNUNET_TESTBED_ControllerLinkRequest *msg;
GNUNET_assert (NULL != opc->data);
data = opc->data;
@@ -1311,11 +1400,11 @@
int is_subordinate)
{
struct OperationContext *opc;
- struct GNUNET_TESTBED_ControllerLinkMessage *msg;
+ struct GNUNET_TESTBED_ControllerLinkRequest *msg;
struct ControllerLinkData *data;
uint16_t msg_size;
- msg_size = sxcfg_size + sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
+ msg_size = sxcfg_size + sizeof (struct GNUNET_TESTBED_ControllerLinkRequest);
msg = GNUNET_malloc (msg_size);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS);
msg->header.size = htons (msg_size);
@@ -1326,6 +1415,7 @@
memcpy (&msg[1], sxcfg, sxcfg_size);
data = GNUNET_malloc (sizeof (struct ControllerLinkData));
data->msg = msg;
+ data->host_id = delegated_host_id;
opc = GNUNET_malloc (sizeof (struct OperationContext));
opc->c = master;
opc->data = data;
@@ -1416,6 +1506,33 @@
/**
+ * Function to serialize and compress using zlib a configuration through a
+ * configuration handle
+ *
+ * @param cfg the configuration
+ * @param size the size of configuration when serialize. Will be set on
success.
+ * @param xsize the sizeo of the compressed configuration. Will be set on
success.
+ * @return the serialized and compressed configuration
+ */
+char *
+GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ size_t *size, size_t *xsize)
+{
+ char *config;
+ char *xconfig;
+ size_t size_;
+ size_t xsize_;
+
+ config = GNUNET_CONFIGURATION_serialize (cfg, &size_);
+ xsize_ = GNUNET_TESTBED_compress_config_ (config, size_, &xconfig);
+ GNUNET_free (config);
+ *size = size_;
+ *xsize = xsize_;
+ return xconfig;
+}
+
+
+/**
* Same as the GNUNET_TESTBED_controller_link, but with ids for delegated host
* and slave host
*
@@ -1453,7 +1570,7 @@
GNUNET_free (config);
/* Configuration doesn't fit in 1 message */
GNUNET_assert ((UINT16_MAX -
- sizeof (struct GNUNET_TESTBED_ControllerLinkMessage)) >=
+ sizeof (struct GNUNET_TESTBED_ControllerLinkRequest)) >=
cc_size);
op = GNUNET_TESTBED_controller_link_2_ (op_cls, master, delegated_host_id,
slave_host_id, (const char *)
cconfig,
@@ -1697,7 +1814,8 @@
* given message should be of the following types:
* GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION,
* GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION,
- * GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST
+ * GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST,
+ * GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT
*
* @param msg the message containing compressed configuration
* @return handle to the parsed configuration; NULL upon error while parsing
the message
@@ -1752,6 +1870,17 @@
xdata = (const Bytef *) ((const void *) imsg + osize);
}
break;
+ case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT:
+ {
+ const struct GNUNET_TESTBED_ControllerLinkResponse *imsg;
+
+ imsg = (const struct GNUNET_TESTBED_ControllerLinkResponse *) msg;
+ data_len = ntohs (imsg->config_size);
+ xdata_len = ntohs (imsg->header.size) -
+ sizeof (const struct GNUNET_TESTBED_ControllerLinkResponse);
+ xdata = (const Bytef *) &imsg[1];
+ }
+ break;
default:
GNUNET_assert (0);
}
Modified: gnunet/src/testbed/testbed_api.h
===================================================================
--- gnunet/src/testbed/testbed_api.h 2013-02-21 17:06:30 UTC (rev 26181)
+++ gnunet/src/testbed/testbed_api.h 2013-02-21 17:06:37 UTC (rev 26182)
@@ -318,6 +318,20 @@
/**
+ * Function to serialize and compress using zlib a configuration through a
+ * configuration handle
+ *
+ * @param cfg the configuration
+ * @param size the size of configuration when serialize. Will be set on
success.
+ * @param xsize the sizeo of the compressed configuration. Will be set on
success.
+ * @return the serialized and compressed configuration
+ */
+char *
+GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ size_t *size, size_t *xsize);
+
+
+/**
* Adds an operation to the queue of operations
*
* @param op the operation to add
Modified: gnunet/src/testbed/testbed_api_hosts.c
===================================================================
--- gnunet/src/testbed/testbed_api_hosts.c 2013-02-21 17:06:30 UTC (rev
26181)
+++ gnunet/src/testbed/testbed_api_hosts.c 2013-02-21 17:06:37 UTC (rev
26182)
@@ -337,6 +337,21 @@
/**
+ * Function to replace host's configuration
+ *
+ * @param host the host handle
+ * @param new_cfg the new configuration to replace the old one
+ */
+void
+GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host,
+ const struct GNUNET_CONFIGURATION_Handle
*new_cfg)
+{
+ GNUNET_CONFIGURATION_destroy (host->cfg);
+ host->cfg = GNUNET_CONFIGURATION_dup (new_cfg);
+}
+
+
+/**
* Create a host to run peers and controllers on.
*
* @param id global host ID assigned to the host; 0 is
Modified: gnunet/src/testbed/testbed_api_hosts.h
===================================================================
--- gnunet/src/testbed/testbed_api_hosts.h 2013-02-21 17:06:30 UTC (rev
26181)
+++ gnunet/src/testbed/testbed_api_hosts.h 2013-02-21 17:06:37 UTC (rev
26182)
@@ -103,6 +103,17 @@
/**
+ * Function to replace host's configuration
+ *
+ * @param host the host handle
+ * @param new_cfg the new configuration to replace the old one
+ */
+void
+GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host,
+ const struct GNUNET_CONFIGURATION_Handle
*new_cfg);
+
+
+/**
* Marks a host as registered with a controller
*
* @param host the host to mark
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26182 - gnunet/src/testbed,
gnunet <=