[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r23288 - in gnunet/src: include testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r23288 - in gnunet/src: include testbed |
Date: |
Fri, 17 Aug 2012 16:54:29 +0200 |
Author: harsha
Date: 2012-08-17 16:54:29 +0200 (Fri, 17 Aug 2012)
New Revision: 23288
Modified:
gnunet/src/include/gnunet_testbed_service.h
gnunet/src/testbed/gnunet-service-testbed.c
gnunet/src/testbed/test_testbed_api_controllerlink.c
gnunet/src/testbed/testbed.h
gnunet/src/testbed/testbed_api.c
gnunet/src/testbed/testbed_api.h
gnunet/src/testbed/testbed_api_peers.c
Log:
controller link as operation
Modified: gnunet/src/include/gnunet_testbed_service.h
===================================================================
--- gnunet/src/include/gnunet_testbed_service.h 2012-08-17 12:44:46 UTC (rev
23287)
+++ gnunet/src/include/gnunet_testbed_service.h 2012-08-17 14:54:29 UTC (rev
23288)
@@ -574,8 +574,9 @@
* @param is_subordinate GNUNET_YES if the controller at delegated_host should
* be started by the master controller; GNUNET_NO if we are just
* allowed to use the slave via TCP/IP
+ * @return the operation handle
*/
-void
+struct GNUNET_TESTBED_Operation *
GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
struct GNUNET_TESTBED_Host *delegated_host,
struct GNUNET_TESTBED_Host *slave_host,
@@ -597,8 +598,9 @@
* @param is_subordinate GNUNET_YES if the controller at delegated_host should
* be started by the master controller; GNUNET_NO if we are just
* allowed to use the slave via TCP/IP
+ * @return the operation handle
*/
-void
+struct GNUNET_TESTBED_Operation *
GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
struct GNUNET_TESTBED_Host *delegated_host,
struct GNUNET_TESTBED_Host *slave_host,
Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-08-17 12:44:46 UTC (rev
23287)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-08-17 14:54:29 UTC (rev
23288)
@@ -470,6 +470,29 @@
/**
+ * Context information used while linking controllers
+ */
+struct LinkControllersContext
+{
+ /**
+ * The client which initiated the link controller operation
+ */
+ struct GNUNET_SERVER_Client *client;
+
+ /**
+ * The ID of the operation
+ */
+ uint64_t operation_id;
+
+ /**
+ * Pointer to the slave handle if we are directly starting/connecting to the
controller
+ */
+ struct Slave *slave;
+};
+
+
+
+/**
* The master context; generated with the first INIT message
*/
static struct Context *master_context;
@@ -978,6 +1001,29 @@
/**
+ * Function to send generic operation success message to given client
+ *
+ * @param client the client to send the message to
+ * @param operation_id the id of the operation which was successful
+ */
+static void
+send_operation_success_msg (struct GNUNET_SERVER_Client *client,
+ uint64_t operation_id)
+{
+ struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
+ uint16_t msize;
+
+ msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
+ msg = GNUNET_malloc (msize);
+ msg->header.size = htons (msize);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
+ msg->operation_id = GNUNET_htonll (operation_id);
+ msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
+ queue_message (client, &msg->header);
+}
+
+
+/**
* Callback to signal successfull startup of the controller process
*
* @param cls the closure from GNUNET_TESTBED_controller_start()
@@ -991,20 +1037,27 @@
const struct GNUNET_CONFIGURATION_Handle *cfg,
int status)
{
- struct Slave *slave = cls;
+ struct LinkControllersContext *lcc = cls;
if (GNUNET_SYSERR == status)
{
- slave->controller_proc = NULL;
+ lcc->slave->controller_proc = NULL;
LOG (GNUNET_ERROR_TYPE_WARNING,
"Unexpected slave shutdown\n");
GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
return;
}
- slave->controller =
- GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
+ lcc->slave->controller =
+ GNUNET_TESTBED_controller_connect (cfg, host_list[lcc->slave->host_id],
master_context->event_mask,
- &slave_event_callback, slave);
+ &slave_event_callback, lcc->slave);
+ if (NULL != lcc->slave->controller)
+ send_operation_success_msg (lcc->client, lcc->operation_id);
+ else
+ send_operation_fail_msg (lcc->client, lcc->operation_id,
+ "Could not connect to delegated controller");
+ GNUNET_SERVER_client_drop (lcc->client);
+ GNUNET_free (lcc);
}
@@ -1299,7 +1352,6 @@
if (slave_host_id == master_context->host_id) /* Link from us */
{
struct Slave *slave;
-
if ((delegated_host_id < slave_list_size) &&
(NULL != slave_list[delegated_host_id])) /* We have already added */
{
@@ -1344,20 +1396,32 @@
}
slave = GNUNET_malloc (sizeof (struct Slave));
slave->host_id = delegated_host_id;
- slave_list_add (slave);
+ slave_list_add (slave);
+
if (1 == msg->is_subordinate)
{
+ struct LinkControllersContext *lcc;
+ lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
+ lcc->operation_id = GNUNET_ntohll (msg->operation_id);
+ GNUNET_SERVER_client_keep (client);
+ lcc->client = client;
+ lcc->slave = slave;
slave->controller_proc =
GNUNET_TESTBED_controller_start (master_context->master_ip,
host_list[slave->host_id],
cfg, &slave_status_callback,
- slave);
+ lcc);
}
else {
slave->controller =
GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
master_context->event_mask,
&slave_event_callback, slave);
+ if (NULL != slave->controller)
+ send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
+ else
+ send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
+ "Could not connect to delegated controller");
}
GNUNET_CONFIGURATION_destroy (cfg);
new_route = GNUNET_malloc (sizeof (struct Route));
@@ -1594,10 +1658,8 @@
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
- struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *reply;
struct Peer *peer;
uint32_t peer_id;
- uint16_t reply_size;
msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
peer_id = ntohl (msg->peer_id);
@@ -1622,14 +1684,7 @@
GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
peer_list_remove (peer);
GNUNET_free (peer);
- reply_size =
- sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
- reply = GNUNET_malloc (reply_size);
- reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
- reply->header.size = htons (reply_size);
- reply->operation_id = msg->operation_id;
- reply->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
- queue_message (client, &reply->header);
+ send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
Modified: gnunet/src/testbed/test_testbed_api_controllerlink.c
===================================================================
--- gnunet/src/testbed/test_testbed_api_controllerlink.c 2012-08-17
12:44:46 UTC (rev 23287)
+++ gnunet/src/testbed/test_testbed_api_controllerlink.c 2012-08-17
14:54:29 UTC (rev 23288)
@@ -105,6 +105,11 @@
static GNUNET_SCHEDULER_TaskIdentifier abort_task;
/**
+ * Operation handle for linking controllers
+ */
+static struct GNUNET_TESTBED_Operation *op;
+
+/**
* Event mask
*/
uint64_t event_mask;
@@ -167,7 +172,25 @@
static void
controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
{
- GNUNET_assert (0);
+ switch (result)
+ {
+ case SLAVE1_REGISTERED:
+ GNUNET_assert (NULL != event);
+ GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
+ GNUNET_assert (event->details.operation_finished.operation == op);
+ 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);
+ GNUNET_TESTBED_operation_done (op);
+ op = NULL;
+ result = SUCCESS;
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
}
@@ -188,11 +211,8 @@
GNUNET_assert (NULL != mc);
result = SLAVE1_REGISTERED;
GNUNET_assert (NULL != cfg);
- GNUNET_TESTBED_controller_link (mc, slave, NULL, cfg, GNUNET_YES);
- result = SUCCESS;
- GNUNET_SCHEDULER_add_delayed
- (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
- &do_shutdown, NULL);
+ op = GNUNET_TESTBED_controller_link (mc, slave, NULL, cfg, GNUNET_YES);
+ GNUNET_assert (NULL != op);
break;
case INIT:
case SUCCESS:
@@ -256,7 +276,7 @@
cp =
GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb, NULL);
abort_task = GNUNET_SCHEDULER_add_delayed
- (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30),
+ (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5),
&do_abort, NULL);
}
Modified: gnunet/src/testbed/testbed.h
===================================================================
--- gnunet/src/testbed/testbed.h 2012-08-17 12:44:46 UTC (rev 23287)
+++ gnunet/src/testbed/testbed.h 2012-08-17 14:54:29 UTC (rev 23288)
@@ -166,6 +166,11 @@
uint32_t delegated_host_id GNUNET_PACKED;
/**
+ * The id of the operation which created this message
+ */
+ uint64_t operation_id GNUNET_PACKED;
+
+ /**
* Which host is responsible for managing the delegation? NBO
*/
uint32_t slave_host_id GNUNET_PACKED;
Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c 2012-08-17 12:44:46 UTC (rev 23287)
+++ gnunet/src/testbed/testbed_api.c 2012-08-17 14:54:29 UTC (rev 23288)
@@ -285,25 +285,26 @@
{
case OP_PEER_DESTROY:
{
- struct GNUNET_TESTBED_Peer *peer;
-
- if (NULL != event)
- {
- event->details.operation_finished.operation = opc->op;
- event->details.operation_finished.op_cls = NULL;
- event->details.operation_finished.emsg = NULL;
- event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC;
- event->details.operation_finished.op_result.generic = NULL;
- }
+ struct GNUNET_TESTBED_Peer *peer;
peer = opc->data;
GNUNET_free (peer);
opc->data = NULL;
//PEERDESTROYDATA
}
break;
+ case OP_LINK_CONTROLLERS:
+ break;
default:
GNUNET_assert (0);
}
+ if (NULL != event)
+ {
+ event->details.operation_finished.operation = opc->op;
+ event->details.operation_finished.op_cls = NULL;
+ event->details.operation_finished.emsg = NULL;
+ event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC;
+ event->details.operation_finished.op_result.generic = NULL;
+ }
GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
opc->state = OPC_STATE_FINISHED;
if (NULL != event)
@@ -953,6 +954,45 @@
/**
+ * Function to call to start a link-controllers type operation once all queues
+ * the operation is part of declare that the operation can be activated.
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+opstart_link_controllers (void *cls)
+{
+ struct OperationContext *opc = cls;
+ struct GNUNET_TESTBED_ControllerLinkMessage *msg;
+
+ GNUNET_assert (NULL != opc->data);
+ msg = opc->data;
+ opc->data = NULL;
+ opc->state = OPC_STATE_STARTED;
+ GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
+ GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
+}
+
+
+/**
+ * Callback which will be called when link-controllers type operation is
released
+ *
+ * @param cls the closure from GNUNET_TESTBED_operation_create_()
+ */
+static void
+oprelease_link_controllers (void *cls)
+{
+ struct OperationContext *opc = cls;
+
+ if (OPC_STATE_INIT == opc->state)
+ GNUNET_free (opc->data);
+ if (OPC_STATE_STARTED == opc->state)
+ GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+ GNUNET_free (opc);
+}
+
+
+/**
* Starts a controller process at the host. FIXME: add controller start
callback
* with the configuration with which the controller is started
*
@@ -1320,7 +1360,7 @@
* be started by the master controller; GNUNET_NO if we are just
* allowed to use the slave via TCP/IP
*/
-void
+struct GNUNET_TESTBED_Operation *
GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
struct GNUNET_TESTBED_Host *delegated_host,
struct GNUNET_TESTBED_Host *slave_host,
@@ -1329,6 +1369,7 @@
size_t scfg_size,
int is_subordinate)
{
+ struct OperationContext *opc;
struct GNUNET_TESTBED_ControllerLinkMessage *msg;
uint16_t msg_size;
@@ -1347,7 +1388,17 @@
msg->config_size = htons ((uint16_t) scfg_size);
msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0;
memcpy (&msg[1], sxcfg, sxcfg_size);
- GNUNET_TESTBED_queue_message_ (master, (struct GNUNET_MessageHeader *) msg);
+ opc = GNUNET_malloc (sizeof (struct OperationContext));
+ opc->c = master;
+ opc->data = msg;
+ opc->type = OP_LINK_CONTROLLERS;
+ opc->id = master->operation_counter++;
+ opc->state = OPC_STATE_INIT;
+ msg->operation_id = GNUNET_htonll (opc->id);
+ opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_link_controllers,
+ &oprelease_link_controllers);
+ GNUNET_TESTBED_operation_queue_insert_ (master->opq_peer_create, opc->op);
+ return opc->op;
}
@@ -1395,23 +1446,25 @@
* @param is_subordinate GNUNET_YES if the slave should be started (and
stopped)
* by the master controller; GNUNET_NO if we are just
* allowed to use the slave via TCP/IP
+ * @return the operation handle
*/
-void
+struct GNUNET_TESTBED_Operation *
GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
struct GNUNET_TESTBED_Host *delegated_host,
struct GNUNET_TESTBED_Host *slave_host,
const struct GNUNET_CONFIGURATION_Handle
*slave_cfg,
int is_subordinate)
{
+ struct GNUNET_TESTBED_Operation *op;
char *config;
char *cconfig;
size_t cc_size;
size_t config_size;
- GNUNET_assert (GNUNET_YES ==
+ GNUNET_assert (GNUNET_YES ==
GNUNET_TESTBED_is_host_registered_ (delegated_host, master));
if ((NULL != slave_host) && (0 != GNUNET_TESTBED_host_get_id_ (slave_host)))
- GNUNET_assert (GNUNET_YES ==
+ GNUNET_assert (GNUNET_YES ==
GNUNET_TESTBED_is_host_registered_ (slave_host, master));
config = GNUNET_CONFIGURATION_serialize (slave_cfg, &config_size);
cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig);
@@ -1419,10 +1472,11 @@
GNUNET_assert ((UINT16_MAX -
sizeof (struct GNUNET_TESTBED_ControllerLinkMessage))
>= cc_size); /* Configuration doesn't fit in 1 message */
- GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host,
+ op = GNUNET_TESTBED_controller_link_2 (master, delegated_host, slave_host,
(const char *) cconfig,
cc_size, config_size, is_subordinate);
GNUNET_free (cconfig);
+ return op;
}
@@ -1495,9 +1549,6 @@
void
GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation)
{
- GNUNET_CONTAINER_DLL_remove (operation->controller->op_head,
- operation->controller->op_tail,
- operation);
GNUNET_TESTBED_operation_done (operation);
}
@@ -1522,6 +1573,7 @@
case OP_PEER_STOP:
case OP_PEER_INFO:
case OP_OVERLAY_CONNECT:
+ case OP_LINK_CONTROLLERS:
GNUNET_TESTBED_operation_release_ (operation);
return;
default:
Modified: gnunet/src/testbed/testbed_api.h
===================================================================
--- gnunet/src/testbed/testbed_api.h 2012-08-17 12:44:46 UTC (rev 23287)
+++ gnunet/src/testbed/testbed_api.h 2012-08-17 14:54:29 UTC (rev 23288)
@@ -66,8 +66,13 @@
/**
* Forwarded operation
*/
- OP_FORWARDED
+ OP_FORWARDED,
+ /**
+ * Link controllers operation
+ */
+ OP_LINK_CONTROLLERS,
+
};
@@ -260,16 +265,6 @@
struct GNUNET_TESTBED_HostRegistrationHandle *rh;
/**
- * The head of the operation queue (FIXME: Remove, use ocq)
- */
- struct GNUNET_TESTBED_Operation *op_head;
-
- /**
- * The tail of the operation queue (FIXME: Remove, use ocq)
- */
- struct GNUNET_TESTBED_Operation *op_tail;
-
- /**
* The head of the opeartion context queue
*/
struct OperationContext *ocq_head;
Modified: gnunet/src/testbed/testbed_api_peers.c
===================================================================
--- gnunet/src/testbed/testbed_api_peers.c 2012-08-17 12:44:46 UTC (rev
23287)
+++ gnunet/src/testbed/testbed_api_peers.c 2012-08-17 14:54:29 UTC (rev
23288)
@@ -69,10 +69,8 @@
msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host));
msg->peer_id = htonl (data->peer->unique_id);
msg->config_size = htonl (c_size);
- GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head,
- opc->c->ocq_tail, opc);
- GNUNET_TESTBED_queue_message_ (opc->c,
- (struct GNUNET_MessageHeader *) msg);
+ GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
+ GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r23288 - in gnunet/src: include testbed,
gnunet <=