* gnunet-service-testbed. This binary also receives configuration
* from the remove controller which is put in a temporary location
* with ports and paths fixed so that gnunet-service-testbed runs
- * without any hurdels. This binary also kills the testbed service
+ * without any hurdles. This binary also kills the testbed service
* should the connection from the remote controller is dropped
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
*/
+
+
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib-new.h"
static void
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ LOG_DEBUG ("Shutting down\n");
if (GNUNET_SCHEDULER_NO_TASK != read_task_id)
{
GNUNET_SCHEDULER_cancel (read_task_id);
(void) GNUNET_DISK_file_close (stdin_fd);
GNUNET_SERVER_mst_destroy (tokenizer);
tokenizer = NULL;
+ if (NULL != testbed)
+ {
+ (void) GNUNET_OS_process_kill (testbed, SIGTERM);
+ GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (testbed));
+ GNUNET_OS_process_destroy (testbed);
+ testbed = NULL;
+ }
+ if (NULL != pipe_in)
+ {
+ (void) GNUNET_DISK_pipe_close (pipe_in);
+ pipe_in = NULL;
+ }
+ if (NULL != pipe_out)
+ {
+ (void) GNUNET_DISK_pipe_close (pipe_out);
+ pipe_out = NULL;
+ }
if (NULL != test_system)
{
GNUNET_TESTING_system_destroy (test_system, GNUNET_YES);
GNUNET_assert (NULL != test_system);
GNUNET_assert (GNUNET_OK == GNUNET_TESTING_configuration_create
(test_system, cfg));
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
+ (cfg, "PATHS", "DEFAULTCONFIG", &config));
pipe_in = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
pipe_out = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_YES);
if ((NULL == pipe_in) || (NULL == pipe_out))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
GNUNET_free (config);
goto error;
- }
+ }
+ if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Unable to write config file: %s -- exiting\n", config);
+ GNUNET_free (config);
+ goto error;
+ }
+ LOG_DEBUG ("Staring testbed with config: %s\n", config);
testbed = GNUNET_OS_start_process
(GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR /*verbose? */, pipe_in, pipe_out,
"gnunet-service-testbed", "gnunet-service-testbed", "-c", config, NULL);
+ GNUNET_free (config);
if (NULL == testbed)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Unable to deserialize config -- exiting\n");
+ "Error staring gnunet-service-testbed -- exiting\n");
goto error;
}
GNUNET_DISK_pipe_close_end (pipe_out, GNUNET_DISK_PIPE_END_WRITE);
#include "platform.h"
#include "gnunet_util_lib.h"
+#include "gnunet_testbed_service.h"
+
+#include "testbed_api.h"
#include "testbed_helper.h"
/**
/**
* Message to helper
*/
-static struct GNUNET_TESTBED_HelperInit msg;
+static struct GNUNET_TESTBED_HelperInit *msg;
/**
* Message send handle
*/
static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
+/**
+ * Configuratin handler
+ */
+static struct GNUNET_CONFIGURATION_Handle *cfg;
+
/**
* Shutdown nicely
{
if (GNUNET_SCHEDULER_NO_TASK != abort_task)
GNUNET_SCHEDULER_cancel (abort_task);
- GNUNET_HELPER_stop (helper);
+ GNUNET_HELPER_stop (helper);
+ GNUNET_free_non_null (msg);
+ if (NULL != cfg)
+ GNUNET_CONFIGURATION_destroy (cfg);
}
GNUNET_assert (GNUNET_OK == result);
if (GNUNET_SCHEDULER_NO_TASK == shutdown_task)
shutdown_task = GNUNET_SCHEDULER_add_delayed
- (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
+ (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
&do_shutdown, NULL);
}
*/
static void
run (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle * cfg)
+ const struct GNUNET_CONFIGURATION_Handle * cfg2)
{
static char * const binary_argv[] = {
"gnunet-testbed-helper",
NULL
};
+ char *config;
+ char *xconfig;
+ const char *hostname = "127.0.0.1";
+ size_t config_size;
+ size_t xconfig_size;
+ uint16_t hostname_len;
+ uint16_t msg_size;
+
helper = GNUNET_HELPER_start ("gnunet-testbed-helper",
binary_argv,
NULL, NULL);
GNUNET_assert (NULL != helper);
- msg.header.size = htons (sizeof (struct GNUNET_TESTBED_HelperInit));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT);
- msg.cname_size = htons (0);
- msg.config_size = htons (0);
+ cfg = GNUNET_CONFIGURATION_dup (cfg2);
+ config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
+ GNUNET_assert (NULL != config);
+ xconfig_size =
+ GNUNET_TESTBED_compress_config (config, config_size, &xconfig);
+ GNUNET_free (config);
+ hostname_len = strlen (hostname);
+ msg_size = xconfig_size + hostname_len + 1 +
+ sizeof (struct GNUNET_TESTBED_HelperInit);
+ msg = GNUNET_realloc (xconfig, msg_size);
+ (void) memmove ( ((void *) &msg[1]) + hostname_len + 1, msg, xconfig_size);
+ msg->header.size = htons (msg_size);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT);
+ msg->cname_size = htons (hostname_len);
+ msg->config_size = htons (config_size);
+ (void) strcpy ((char *) &msg[1], hostname);
shandle = GNUNET_HELPER_send (helper,
- &msg.header,
+ &msg->header,
GNUNET_NO, &cont_cb, NULL);
GNUNET_assert (NULL != shandle);
abort_task = GNUNET_SCHEDULER_add_delayed