#define GNUNET_TESTBED_SERVICE_H
#include "gnunet_util_lib.h"
+#include "gnunet_testing_lib-new.h"
#ifdef __cplusplus
extern "C"
$(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) \
*/
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
}
+/**
+ * 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
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],
{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)
#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
*/
/**
* Handle to configuration
*/
-static const struct GNUNET_CONFIGURATION_Handle *cfg;
+static struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Handle to operation
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);
}
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);
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);
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);
}
}
}
+
/**
* 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
};
+/**
+ * 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;