From b0cd5f3c9bf3f87d89fc2f50221cd245b0498b8f Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Fri, 24 Aug 2012 13:51:06 +0000 Subject: [PATCH] peer create fowarding with tests --- src/testbed/gnunet-service-testbed.c | 49 ++++++++----- src/testbed/test_testbed_api_controllerlink.c | 70 ++++++++++++++++--- 2 files changed, 94 insertions(+), 25 deletions(-) diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 72a2f8fda..8a022c18f 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -433,7 +433,7 @@ struct OverlayConnectContext /** - * Context information for operations forward to subcontrollers + * Context information for operations forwarded to subcontrollers */ struct ForwardedOperationContext { @@ -447,6 +447,11 @@ struct ForwardedOperationContext */ struct GNUNET_SERVER_Client *client; + /** + * Closure pointer + */ + void *cls; + /** * Task ID for the timeout task */ @@ -457,10 +462,6 @@ struct ForwardedOperationContext */ uint64_t operation_id; - /** - * The ID of the peer we are going to create - */ - uint32_t peer_id; }; @@ -1533,7 +1534,7 @@ peer_create_forward_timeout (void *cls, /* send error msg to client */ send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id, - "Timedout"); + "Timedout"); GNUNET_SERVER_client_drop (fo_ctxt->client); GNUNET_TESTBED_forward_operation_msg_cancel_ (fo_ctxt->opc); GNUNET_free (fo_ctxt); @@ -1552,13 +1553,24 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) { struct ForwardedOperationContext *fo_ctxt = cls; - struct GNUNET_MessageHeader *dup_msg; + const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *success_msg; + struct GNUNET_MessageHeader *dup_msg; + struct Peer *peer; uint16_t msize; - GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task); - GNUNET_assert (ntohs (msg->type) == - GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS); - msize = ntohs (msg->size); + GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task); + if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS) + { + success_msg + = (const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *) msg; + peer = GNUNET_malloc (sizeof (struct Peer)); + peer->is_remote = GNUNET_YES; + peer->id = ntohl (success_msg->peer_id); + GNUNET_assert (NULL != fo_ctxt->cls); + peer->details.remote.controller = fo_ctxt->cls; + peer_list_add (peer); + } + msize = ntohs (msg->size); dup_msg = GNUNET_malloc (msize); (void) memcpy (dup_msg, msg, msize); queue_message (fo_ctxt->client, dup_msg); @@ -1677,8 +1689,8 @@ handle_peer_create (void *cls, fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); GNUNET_SERVER_client_keep (client); fo_ctxt->client = client; - fo_ctxt->peer_id = ntohl (msg->peer_id); - fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); + fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); + fo_ctxt->cls = slave_list[route->dest]->controller; fo_ctxt->opc = GNUNET_TESTBED_forward_operation_msg_ (slave_list[route->dest]->controller, fo_ctxt->operation_id, @@ -1714,8 +1726,8 @@ handle_peer_destroy (void *cls, peer_id, GNUNET_ntohll (msg->operation_id)); if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id])) { - GNUNET_break (0); - /* FIXME: Reply with failure event message or forward to slave controller */ + LOG (GNUNET_ERROR_TYPE_ERROR, + "Asked for destroy when peer not created at us\n"); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } @@ -2242,8 +2254,11 @@ shutdown_task (void *cls, for (id = 0; id < peer_list_size; id++) if (NULL != peer_list[id]) { - GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer); - GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg); + if (GNUNET_NO == peer_list[id]->is_remote) + { + GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer); + GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg); + } GNUNET_free (peer_list[id]); } GNUNET_free_non_null (peer_list); diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c index 70f6fa846..5236ada4a 100644 --- a/src/testbed/test_testbed_api_controllerlink.c +++ b/src/testbed/test_testbed_api_controllerlink.c @@ -75,8 +75,17 @@ enum Stage /** * Link from slave 1 to slave 2 has been successfully created. */ - SUCCESS + SLAVE2_LINK_SUCCESS, + + /** + * Peer create on slave 1 successful + */ + SLAVE1_PEER_CREATE_SUCCESS, + /** + * Test is successful + */ + SUCCESS }; /** @@ -124,6 +133,16 @@ static GNUNET_SCHEDULER_TaskIdentifier abort_task; */ static struct GNUNET_TESTBED_Operation *op; +/** + * Handle to peer started at slave 1 + */ +static struct GNUNET_TESTBED_Peer *slave1_peer; + +/** + * Handle to peer started at slave 2 + */ +static struct GNUNET_TESTBED_Peer *slave2_peer; + /** * Event mask */ @@ -179,6 +198,43 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) } +/** + * Functions of this signature are called when a peer has been successfully + * created + * + * @param cls the closure from GNUNET_TESTBED_peer_create() + * @param peer the handle for the created peer; NULL on any error during + * creation + * @param emsg NULL if peer is not NULL; else MAY contain the error description + */ +static void +peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) +{ + switch (result) + { + case SLAVE2_LINK_SUCCESS: + GNUNET_assert (NULL != peer); + GNUNET_assert (NULL == emsg); + result = SLAVE1_PEER_CREATE_SUCCESS; + slave1_peer = peer; + GNUNET_TESTBED_operation_done (op); + op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL); + GNUNET_assert (NULL != op); + break; + case SLAVE1_PEER_CREATE_SUCCESS: + GNUNET_assert (NULL != peer); + GNUNET_assert (NULL == emsg); + result = SUCCESS; + slave2_peer = peer; + GNUNET_TESTBED_operation_done (op); + GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + break; + default: + GNUNET_assert (0); + } +} + + /** * Signature of the event handler function called by the * respective event controller. @@ -218,9 +274,10 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 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; + result = SLAVE2_LINK_SUCCESS; + op = GNUNET_TESTBED_peer_create (mc, slave, cfg, peer_create_cb, NULL); + GNUNET_assert (NULL != op); + break; default: GNUNET_assert (0); } @@ -256,10 +313,7 @@ registration_cont (void *cls, const char *emsg) op = GNUNET_TESTBED_controller_link (mc, slave, NULL, cfg, GNUNET_YES); GNUNET_assert (NULL != op); break; - case INIT: - case SUCCESS: - case SLAVE2_REGISTERED: - case SLAVE1_LINK_SUCCESS: + default: GNUNET_assert (0); } } -- 2.25.1