From fbb36b18c6d58e14a8fe1af922a72bb58fb6a4f7 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Mon, 9 Jul 2012 11:35:19 +0000 Subject: [PATCH] -peer create bug fixes and test case --- src/testbed/gnunet-service-testbed.c | 17 +++-- src/testbed/test_testbed_api.c | 99 +++++++++++++++++++++------- src/testbed/test_testbed_api.conf | 2 +- src/testbed/testbed_api.c | 2 + src/testbed/testbed_api_peers.c | 2 +- 5 files changed, 91 insertions(+), 31 deletions(-) diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index e05e1d71f..756d49209 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -1085,8 +1085,9 @@ handle_peer_create (void *cls, struct GNUNET_CONFIGURATION_Handle *cfg; char *config; size_t dest_size; + int ret; + uint32_t config_size; uint16_t msize; - uint16_t config_size; msize = ntohs (message->size); @@ -1097,23 +1098,24 @@ handle_peer_create (void *cls, return; } msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message; - if (ntohs (msg->host_id) == master_context->host_id) + if (ntohl (msg->host_id) == master_context->host_id) { struct Peer *peer; char *emsg; - /* We are responsidble for this peer */ + /* We are responsible for this peer */ msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage); config_size = ntohl (msg->config_size); - config = GNUNET_malloc (msg->config_size); - if (Z_OK != uncompress ((Bytef *) config, (uLongf *) &dest_size, - (const Bytef *) &msg[1], (uLong) msize)) + config = GNUNET_malloc (config_size); + dest_size = config_size; + if (Z_OK != (ret = uncompress ((Bytef *) config, (uLongf *) &dest_size, + (const Bytef *) &msg[1], (uLong) msize))) { GNUNET_break (0); /* uncompression error */ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - if (config_size == dest_size) + if (config_size != dest_size) { GNUNET_break (0);/* Uncompressed config size mismatch */ GNUNET_free (config); @@ -1133,6 +1135,7 @@ handle_peer_create (void *cls, peer = GNUNET_malloc (sizeof (struct Peer)); peer->cfg = cfg; peer->id = ntohl (msg->peer_id); + LOG_DEBUG ("Creating peer with id: %u\n", peer->id); peer->peer = GNUNET_TESTING_peer_configure (test_system, peer->cfg, peer->id, NULL /* Peer id */, diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index 612b30347..2ed3e1fa8 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c @@ -36,6 +36,11 @@ #define LOG(kind,...) \ GNUNET_log (kind, __VA_ARGS__) +/** + * Relative time seconds shorthand + */ +#define TIME_REL_SECS(sec) \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) /** * Our localhost @@ -45,7 +50,7 @@ static struct GNUNET_TESTBED_Host *host; /** * The controller handle */ -static struct GNUNET_TESTBED_Controller *c; +static struct GNUNET_TESTBED_Controller *controller; /** * A neighbouring host @@ -57,10 +62,30 @@ static struct GNUNET_TESTBED_Host *neighbour; */ static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle; +/** + * Handle for a peer + */ +static struct GNUNET_TESTBED_Peer *peer; + +/** + * Handle to configuration + */ +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +/** + * Handle to operation + */ +static struct GNUNET_TESTBED_Operation *operation; + /** * Abort task identifier */ -static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; +static GNUNET_SCHEDULER_TaskIdentifier abort_task; + +/** + * Peer destroy task identifier + */ +static GNUNET_SCHEDULER_TaskIdentifier peer_destroy_task; /** * The testing result @@ -77,11 +102,11 @@ static int result; static void do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) { - if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) - GNUNET_SCHEDULER_cancel (abort_task_id); + if (GNUNET_SCHEDULER_NO_TASK != abort_task) + GNUNET_SCHEDULER_cancel (abort_task); if (NULL != reg_handle) GNUNET_TESTBED_cancel_registration (reg_handle); - GNUNET_TESTBED_controller_disconnect (c); + GNUNET_TESTBED_controller_disconnect (controller); GNUNET_TESTBED_host_destroy (neighbour); GNUNET_TESTBED_host_destroy (host); } @@ -97,7 +122,9 @@ static void do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) { LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); - abort_task_id = GNUNET_SCHEDULER_NO_TASK; + abort_task = GNUNET_SCHEDULER_NO_TASK; + if (GNUNET_SCHEDULER_NO_TASK != peer_destroy_task) + GNUNET_SCHEDULER_cancel (peer_destroy_task); do_shutdown (cls, tc); } @@ -112,7 +139,31 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) static void controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) { - GNUNET_break (0); + GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); + GNUNET_assert (event->details.operation_finished.operation == operation); + 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); + result = GNUNET_YES; + GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); +} + + +/** + * Task for destroying the peer + * + * @param cls NULL + * @param tc the task context + */ +static void +do_peer_destroy (void *cls, + const const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + peer_destroy_task = GNUNET_SCHEDULER_NO_TASK; + operation = GNUNET_TESTBED_peer_destroy (peer); + GNUNET_assert (NULL != operation); } @@ -126,9 +177,11 @@ static void registration_comp (void *cls, const char *emsg) { GNUNET_assert (cls == neighbour); - reg_handle = NULL; - result = GNUNET_YES; - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + reg_handle = NULL; + peer = GNUNET_TESTBED_peer_create (controller, host, cfg); + GNUNET_assert (NULL != peer); + peer_destroy_task = + GNUNET_SCHEDULER_add_now (&do_peer_destroy, NULL); } @@ -137,27 +190,29 @@ registration_comp (void *cls, const char *emsg) */ static void run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_TESTING_Peer *peer) { uint64_t event_mask; + cfg = config; host = GNUNET_TESTBED_host_create (NULL, NULL, 0); GNUNET_assert (NULL != host); event_mask ^= event_mask; /* NULL out */ event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); - c = GNUNET_TESTBED_controller_connect (cfg, host, event_mask, - &controller_cb, NULL); - GNUNET_assert (NULL != c); + event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); + controller = GNUNET_TESTBED_controller_connect (config, host, event_mask, + &controller_cb, NULL); + GNUNET_assert (NULL != controller); neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, 0); GNUNET_assert (NULL != neighbour); reg_handle = - GNUNET_TESTBED_register_host (c, neighbour, ®istration_comp, neighbour); - GNUNET_assert (NULL != reg_handle); - - abort_task_id = GNUNET_SCHEDULER_add_delayed + GNUNET_TESTBED_register_host (controller, neighbour, ®istration_comp, + neighbour); + GNUNET_assert (NULL != reg_handle); + abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30), &do_abort, NULL); } @@ -168,10 +223,10 @@ run (void *cls, int main (int argc, char **argv) { result = GNUNET_SYSERR; - if (0 != GNUNET_TESTING_service_run ("test_testbed_api", - "testbed", - "test_testbed_api.conf", - &run, NULL)) + if (0 != GNUNET_TESTING_peer_run ("test_testbed_api", + // "arm", + "test_testbed_api.conf", + &run, NULL)) return 1; else return (GNUNET_OK == result) ? 0 : 1; } diff --git a/src/testbed/test_testbed_api.conf b/src/testbed/test_testbed_api.conf index bf6c414b8..bbb521475 100644 --- a/src/testbed/test_testbed_api.conf +++ b/src/testbed/test_testbed_api.conf @@ -40,7 +40,7 @@ WAN_QUOTA_IN = 3932160 PORT = 12092 [arm] -DEFAULTSERVICES = +DEFAULTSERVICES = core testbed PORT = 12366 DEBUG = NO diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 621121678..2615711fe 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -277,6 +277,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c, { if (NULL != c->cc) c->cc (c->cc_cls, event); + GNUNET_free (event); } GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); GNUNET_free (op); @@ -316,6 +317,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) handle_opsuccess (c, (const struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *) msg); + break; default: GNUNET_break (0); } diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 88c97ebf0..16dc57d23 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c @@ -97,7 +97,7 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id, GNUNET_free (config); msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage); msg = GNUNET_realloc (xconfig, msize); - memmove (&msg[1], msg, sizeof (struct GNUNET_TESTBED_PeerCreateMessage)); + memmove (&msg[1], msg, xc_size); /* Move the compressed config */ msg->header.size = htons (msize); msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER); msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host)); -- 2.25.1