From: Sree Harsha Totakura Date: Wed, 11 Jul 2012 15:06:03 +0000 (+0000) Subject: fixes for controller_start() API changes X-Git-Tag: initial-import-from-subversion-38251~12541 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=66cf4e437affd0ba540cb2f660986752582ee5b4;p=oweals%2Fgnunet.git fixes for controller_start() API changes --- diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h index 46be98b79..736a0c03c 100644 --- a/src/include/gnunet_testbed_service.h +++ b/src/include/gnunet_testbed_service.h @@ -29,6 +29,7 @@ #define GNUNET_TESTBED_SERVICE_H #include "gnunet_util_lib.h" +#include "gnunet_testing_lib-new.h" #ifdef __cplusplus extern "C" diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index a4e1b2a01..b6e42276e 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am @@ -46,6 +46,7 @@ libgnunettestbed_la_LIBADD = $(XLIB) \ $(top_builddir)/src/hello/libgnunethello.la \ -lm \ $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/testing/libgnunettesting.la \ $(LTLIBINTL) libgnunettestbed_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) \ diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 9ba145abe..0619a67cb 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -385,6 +385,11 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id; */ static struct GNUNET_TESTING_System *test_system; +/** + * Our configuration; we also use this as template for starting other controllers + */ +static struct GNUNET_CONFIGURATION_Handle *config; + /** * Function called to notify a client about the connection begin ready to queue @@ -692,6 +697,27 @@ slave_event_callback(void *cls, } +/** + * Callback for unexpected slave shutdowns + * + * @param cls closure + * @param emsg error message if available; can be NULL, which does NOT mean + * that there was no error + */ +static void +slave_shutdown_handler (void *cls, const char *emsg) +{ + struct Slave *slave; + + slave = (struct Slave *) cls; + slave->controller_proc = NULL; + LOG (GNUNET_ERROR_TYPE_WARNING, + "Unexpected slave shutdown\n"); + if (NULL != emsg) + LOG (GNUNET_ERROR_TYPE_WARNING, "Error: %s\n", emsg); + GNUNET_SCHEDULER_shutdown (); /* We too shutdown */ +} + /** * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages @@ -1011,7 +1037,10 @@ handle_link_controllers (void *cls, if (1 == msg->is_subordinate) { slave->controller_proc = - GNUNET_TESTBED_controller_start (host_list[delegated_host_id]); + GNUNET_TESTBED_controller_start (test_system, + host_list[delegated_host_id], + cfg, &slave_shutdown_handler, + slave); } slave->controller = GNUNET_TESTBED_controller_connect (cfg, host_list[delegated_host_id], @@ -1378,13 +1407,14 @@ testbed_run (void *cls, {NULL} }; + config = GNUNET_CONFIGURATION_dup (cfg); GNUNET_SERVER_add_handlers (server, message_handlers); GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); ss_map = GNUNET_CONTAINER_multihashmap_create (5); - test_system = GNUNET_TESTING_system_create ("testbed_peers", NULL); + test_system = GNUNET_TESTING_system_create ("testbed", NULL); fh = GNUNET_DISK_get_handle_from_native (stdin); if (NULL == fh) diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index 1fdb7169a..849f5ddd4 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c @@ -42,6 +42,11 @@ #define TIME_REL_SECS(sec) \ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) +/** + * The testing system we work with + */ +struct GNUNET_TESTING_System *test_system; + /** * Our localhost */ @@ -75,7 +80,7 @@ static struct GNUNET_TESTBED_Peer *peer; /** * Handle to configuration */ -static const struct GNUNET_CONFIGURATION_Handle *cfg; +static struct GNUNET_CONFIGURATION_Handle *cfg; /** * Handle to operation @@ -107,10 +112,12 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) if (NULL != reg_handle) GNUNET_TESTBED_cancel_registration (reg_handle); GNUNET_TESTBED_controller_disconnect (controller); + GNUNET_CONFIGURATION_destroy (cfg); if (NULL != cp) GNUNET_TESTBED_controller_stop (cp); GNUNET_TESTBED_host_destroy (neighbour); GNUNET_TESTBED_host_destroy (host); + GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); } @@ -182,19 +189,19 @@ run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config) { uint64_t event_mask; - struct GNUNET_CONFIGURATION_Handle *cdup; - cfg = config; + test_system = GNUNET_TESTING_system_create ("test_testbed", + "127.0.0.1"); host = GNUNET_TESTBED_host_create (NULL, NULL, 0); GNUNET_assert (NULL != host); - cdup = GNUNET_CONFIGURATION_dup (config); - cp = GNUNET_TESTBED_controller_start (system, host, cdup, NULL, NULL); + cfg = GNUNET_CONFIGURATION_dup (config); + cp = GNUNET_TESTBED_controller_start (test_system, host, cfg, NULL, NULL); event_mask = 0; event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); - controller = GNUNET_TESTBED_controller_connect (config, host, event_mask, + controller = GNUNET_TESTBED_controller_connect (cfg, host, event_mask, &controller_cb, NULL); GNUNET_assert (NULL != controller); neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, 0); diff --git a/src/testbed/test_testbed_api_hosts.c b/src/testbed/test_testbed_api_hosts.c index 2528e7aff..340e2491a 100644 --- a/src/testbed/test_testbed_api_hosts.c +++ b/src/testbed/test_testbed_api_hosts.c @@ -70,7 +70,8 @@ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { - char *const binary_args[] = {NULL}; + char *const binary_args[] = {"gnunet-service-testbed", + NULL}; host = GNUNET_TESTBED_host_create ("localhost", NULL, 0); GNUNET_assert (NULL != host); @@ -82,7 +83,7 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0)); helper_handle = GNUNET_TESTBED_host_run_ (host, binary_args); GNUNET_assert (NULL != helper_handle); - GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (2), &do_shutdown, NULL); + GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (1), &do_shutdown, NULL); } diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index dfec11f94..5070d4f29 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -329,6 +329,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) } } + /** * Function called to notify a client about the connection begin ready to queue * more data. "buf" will be NULL and "size" zero if the connection was closed @@ -432,26 +433,86 @@ struct GNUNET_TESTBED_ControllerProc }; +/** + * Context to use while starting a controller + */ +struct ControllerStartContext +{ + /** + * The error callback + */ + GNUNET_TESTBED_ControllerErrorCallback cec; + + /** + * Closure for the above callback + */ + void *cec_cls; + + /** + * error message if any + */ + char *emsg; +}; + + /** * Starts a controller process at the host * + * @param system used for reserving ports if host is NULL and to determine + * which 'host' to set as TRUSTED ('controller') when starting testbed remotely * @param host the host where the controller has to be started; NULL for localhost - * @return the controller process handle + * @param cfg template configuration to use for the remote controller; will + * be modified to contain the actual host/port/unixpath used for + * the testbed service + * @param cec function called if the contoller dies unexpectedly; will not be + * invoked after GNUNET_TESTBED_controller_stop, if 'cec' was called, + * GNUNET_TESTBED_controller_stop must no longer be called; will + * never be called in the same task as 'GNUNET_TESTBED_controller_start' + * (synchronous errors will be signalled by returning NULL) + * @param cec_cls closure for 'cec' + * @return the controller process handle, NULL on errors */ struct GNUNET_TESTBED_ControllerProc * -GNUNET_TESTBED_controller_start (struct GNUNET_TESTBED_Host *host) +GNUNET_TESTBED_controller_start (struct GNUNET_TESTING_System *system, + struct GNUNET_TESTBED_Host *host, + struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_TESTBED_ControllerErrorCallback cec, + void *cec_cls) { struct GNUNET_TESTBED_ControllerProc *cproc; - char * const binary_argv[] = { - "gnunet-service-testbed", - NULL - }; - - cproc = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); - cproc->helper = GNUNET_TESTBED_host_run_ (host, binary_argv); - if (NULL == cproc->helper) + //struct ControllerStartContext *csc; + char *cfg_filename; + + if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host))) + { + if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg)) + return NULL; + GNUNET_assert + (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "DEFAULTCONFIG", + &cfg_filename)); + if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, cfg_filename)) + { + GNUNET_break (0); + return NULL; + } + char * const binary_argv[] = { + "gnunet-service-testbed", + "-c", cfg_filename, + NULL + }; + cproc = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc)); + cproc->helper = GNUNET_TESTBED_host_run_ (host, binary_argv); + GNUNET_free (cfg_filename); + if (NULL == cproc->helper) + { + GNUNET_free (cproc); + return NULL; + } + } + else { - GNUNET_free (cproc); + GNUNET_break (0); return NULL; } return cproc;