summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-02-08 16:51:20 +0000
committerNathan S. Evans <evans@in.tum.de>2010-02-08 16:51:20 +0000
commitcb01deba9af1ccd46b7d5bd0a9efc5a900ee0e64 (patch)
treeb5a59675768ed8a72585afd513c1972ef4de7b21
parent19b13a33872cef3616e188daade61fc8b662ea35 (diff)
testing changes, beginning of topology stuff
-rw-r--r--src/testing/Makefile.am12
-rw-r--r--src/testing/test_testing.c41
-rw-r--r--src/testing/test_testing_connect.c73
-rw-r--r--src/testing/test_testing_group.c24
-rw-r--r--src/testing/testing.c789
-rw-r--r--src/testing/testing_group.c354
-rw-r--r--src/testing/testing_testbed.c23
7 files changed, 698 insertions, 618 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 18144c514..4ddcc2b97 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -23,12 +23,14 @@ libgnunettesting_la_LIBADD = $(XLIB) \
check_PROGRAMS = \
test_testing \
test_testing_connect \
- test_testing_group
+ test_testing_group \
+ test_testing_topology_clique
TESTS = \
test_testing \
test_testing_connect \
- test_testing_group
+ test_testing_group \
+ test_testing_topology_clique
#$(check_PROGRAMS)
test_testing_SOURCES = \
@@ -48,6 +50,12 @@ test_testing_group_SOURCES = \
test_testing_group_LDADD = \
$(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/util/libgnunetutil.la
+
+test_testing_topology_clique_SOURCES = \
+ test_testing_topology_clique.c
+test_testing_topology_clique_LDADD = \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/util/libgnunetutil.la
EXTRA_DIST = \
test_testing_data.conf \
diff --git a/src/testing/test_testing.c b/src/testing/test_testing.c
index 1a52f3681..15b7e10ec 100644
--- a/src/testing/test_testing.c
+++ b/src/testing/test_testing.c
@@ -28,28 +28,26 @@
static int ok;
-static void end_cb(void *cls,
- const char *emsg)
+static void
+end_cb (void *cls, const char *emsg)
{
- GNUNET_assert (emsg == NULL);
+ GNUNET_assert (emsg == NULL);
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemon terminated, will now exit.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon terminated, will now exit.\n");
#endif
- ok = 0;
+ ok = 0;
}
-static void my_cb(void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d,
- const char *emsg)
+static void
+my_cb (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
GNUNET_assert (id != NULL);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemon `%s' started, will now stop it.\n",
- GNUNET_i2s (id));
+ "Daemon `%s' started, will now stop it.\n", GNUNET_i2s (id));
#endif
GNUNET_TESTING_daemon_stop (d, &end_cb, NULL);
}
@@ -59,21 +57,15 @@ static void
run (void *cls,
struct GNUNET_SCHEDULER_Handle *sched,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_TESTING_Daemon *d;
ok = 1;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting daemon.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
#endif
- d = GNUNET_TESTING_daemon_start (sched,
- cfg,
- NULL,
- &my_cb,
- NULL);
+ d = GNUNET_TESTING_daemon_start (sched, cfg, NULL, &my_cb, NULL);
GNUNET_assert (d != NULL);
}
@@ -92,8 +84,7 @@ check ()
GNUNET_GETOPT_OPTION_END
};
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-testing", "nohelp",
- options, &run, &ok);
+ argv, "test-testing", "nohelp", options, &run, &ok);
return ok;
}
@@ -110,7 +101,7 @@ main (int argc, char *argv[])
#endif
NULL);
ret = check ();
- sleep (1); /* FIXME: make this unnecessary */
+ sleep (1); /* FIXME: make this unnecessary */
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
return ret;
}
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c
index c243cb1d7..ca08eaad3 100644
--- a/src/testing/test_testing_connect.c
+++ b/src/testing/test_testing_connect.c
@@ -45,71 +45,62 @@ static struct GNUNET_CONFIGURATION_Handle *c2;
static struct GNUNET_SCHEDULER_Handle *sched;
-static void end2_cb(void *cls,
- const char *emsg)
+static void
+end2_cb (void *cls, const char *emsg)
{
- GNUNET_assert (emsg == NULL);
+ GNUNET_assert (emsg == NULL);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Both daemons terminated, will now exit.\n");
+ "Both daemons terminated, will now exit.\n");
#endif
- ok = 0;
+ ok = 0;
}
-static void end1_cb(void *cls,
- const char *emsg)
+static void
+end1_cb (void *cls, const char *emsg)
{
- GNUNET_assert (emsg == NULL);
+ GNUNET_assert (emsg == NULL);
GNUNET_TESTING_daemon_stop (d2, &end2_cb, NULL);
d2 = NULL;
}
static void
-my_connect_complete (void *cls,
- const char *emsg)
+my_connect_complete (void *cls, const char *emsg)
{
GNUNET_TESTING_daemon_stop (d1, &end1_cb, NULL);
d1 = NULL;
}
-static void my_cb2(void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d,
- const char *emsg)
+static void
+my_cb2 (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
GNUNET_assert (id != NULL);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemon `%s' started.\n",
- GNUNET_i2s (id));
+ "Daemon `%s' started.\n", GNUNET_i2s (id));
#endif
GNUNET_TESTING_daemons_connect (d1, d2,
- TIMEOUT,
- &my_connect_complete,
- NULL);
+ TIMEOUT, &my_connect_complete, NULL);
}
-static void my_cb1(void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d,
- const char *emsg)
+static void
+my_cb1 (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
GNUNET_assert (id != NULL);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Daemon `%s' started.\n",
- GNUNET_i2s (id));
+ "Daemon `%s' started.\n", GNUNET_i2s (id));
#endif
- d2 = GNUNET_TESTING_daemon_start (sched,
- c2,
- NULL,
- &my_cb2,
- NULL);
+ d2 = GNUNET_TESTING_daemon_start (sched, c2, NULL, &my_cb2, NULL);
GNUNET_assert (d2 != NULL);
}
@@ -119,26 +110,18 @@ static void
run (void *cls,
struct GNUNET_SCHEDULER_Handle *s,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
sched = s;
ok = 1;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting daemon.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
#endif
c1 = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_parse (c1,
- "test_testing_connect_peer1.conf");
+ GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf");
c2 = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_parse (c2,
- "test_testing_connect_peer2.conf");
- d1 = GNUNET_TESTING_daemon_start (sched,
- c1,
- NULL,
- &my_cb1,
- NULL);
+ GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf");
+ d1 = GNUNET_TESTING_daemon_start (sched, c1, NULL, &my_cb1, NULL);
GNUNET_assert (d1 != NULL);
}
diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c
index 1d38ef5ec..2b6df732e 100644
--- a/src/testing/test_testing_group.c
+++ b/src/testing/test_testing_group.c
@@ -42,11 +42,11 @@ static struct GNUNET_TESTING_PeerGroup *pg;
static struct GNUNET_SCHEDULER_Handle *sched;
-static void my_cb(void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d,
- const char *emsg)
+static void
+my_cb (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
GNUNET_assert (id != NULL);
peers_left--;
@@ -62,19 +62,17 @@ static void
run (void *cls,
struct GNUNET_SCHEDULER_Handle *s,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
sched = s;
ok = 1;
#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting daemons.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
#endif
- peers_left = 4;
- pg = GNUNET_TESTING_daemons_start (sched, cfg,
- peers_left,
- &my_cb, NULL, NULL);
+ peers_left = 8;
+ pg = GNUNET_TESTING_daemons_start (sched, cfg,
+ peers_left,
+ &my_cb, NULL, NULL, NULL, NULL);
GNUNET_assert (pg != NULL);
}
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 628856b21..8ceaace75 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -58,40 +58,40 @@
* Phases of starting GNUnet on a system.
*/
enum StartPhase
- {
+{
/**
* Copy the configuration file to the target system.
*/
- SP_COPYING,
+ SP_COPYING,
/**
* Configuration file has been copied, start ARM on target system.
*/
- SP_COPIED,
+ SP_COPIED,
/**
* ARM has been started, check that it has properly daemonized and
* then try to connect to the CORE service (which should be
* auto-started by ARM).
*/
- SP_START_ARMING,
+ SP_START_ARMING,
/**
* We're waiting for CORE to start.
*/
- SP_START_CORE,
+ SP_START_CORE,
/**
* Core has notified us that we've established a connection to the service.
* The main FSM halts here and waits to be moved to UPDATE or CLEANUP.
*/
- SP_START_DONE,
+ SP_START_DONE,
/**
* We've been asked to terminate the instance and are now waiting for
* the remote command to delete the configuration file to complete.
*/
- SP_CLEANUP,
+ SP_CLEANUP,
/**
* We've received a configuration update and are currently waiting for
@@ -99,8 +99,8 @@ enum StartPhase
* return to "SP_START_DONE" (and rely on ARM to restart all affected
* services).
*/
- SP_CONFIG_UPDATE
- };
+ SP_CONFIG_UPDATE
+};
/**
@@ -125,6 +125,9 @@ struct GNUNET_TESTING_Daemon
*/
char *hostname;
+ /* Result of GNUNET_i2s of this peer, for printing */
+ char *shortname;
+
/**
* Username we are using.
*/
@@ -201,8 +204,8 @@ struct GNUNET_TESTING_Daemon
/**
* Handle to the server.
- */
- struct GNUNET_CORE_Handle * server;
+ */
+ struct GNUNET_CORE_Handle *server;
};
@@ -220,12 +223,9 @@ struct GNUNET_TESTING_Daemon
*/
static void
testing_init (void *cls,
- struct GNUNET_CORE_Handle * server,
- const struct GNUNET_PeerIdentity *
- my_identity,
- const struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
- publicKey)
+ struct GNUNET_CORE_Handle *server,
+ const struct GNUNET_PeerIdentity *my_identity,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
{
struct GNUNET_TESTING_Daemon *d = cls;
GNUNET_TESTING_NotifyDaemonRunning cb;
@@ -238,18 +238,18 @@ testing_init (void *cls,
{
d->server = NULL;
if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
+ GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
else if (NULL != cb)
- cb (d->cb_cls, NULL, d->cfg, d,
- _("Failed to connect to core service\n"));
+ cb (d->cb_cls, NULL, d->cfg, d,
+ _("Failed to connect to core service\n"));
return;
}
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully started peer `%4s'.\n",
- GNUNET_i2s(my_identity));
+ "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity));
#endif
d->id = *my_identity;
+ d->shortname = strdup (GNUNET_i2s (my_identity));
d->server = server;
if (GNUNET_YES == d->dead)
GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
@@ -265,179 +265,150 @@ testing_init (void *cls,
* @param tc unused
*/
static void
-start_fsm (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- static struct GNUNET_CORE_MessageHandler no_handlers[] =
- { { NULL, 0, 0 } };
- struct GNUNET_TESTING_Daemon * d = cls;
+ static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
+ struct GNUNET_TESTING_Daemon *d = cls;
GNUNET_TESTING_NotifyDaemonRunning cb;
enum GNUNET_OS_ProcessStatusType type;
unsigned long code;
char *dst;
-
+
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer FSM is in phase %u.\n",
- d->phase);
+ "Peer FSM is in phase %u.\n", d->phase);
#endif
d->task = GNUNET_SCHEDULER_NO_TASK;
switch (d->phase)
{
case SP_COPYING:
/* confirm copying complete */
- if (GNUNET_OK !=
- GNUNET_OS_process_status (d->pid,
- &type,
- &code))
- {
- d->wait_runs++;
- if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- _("`scp' does not seem to terminate.\n"));
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm,
- d);
- return;
- }
- if ( (type != GNUNET_OS_PROCESS_EXITED) ||
- (code != 0) )
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- _("`scp' did not complete cleanly.\n"));
- return;
- }
+ if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
+ {
+ d->wait_runs++;
+ if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg, d, _("`scp' does not seem to terminate.\n"));
+ return;
+ }
+ /* wait some more */
+ d->task
+ = GNUNET_SCHEDULER_add_delayed (d->sched,
+ GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
+ if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL, d->cfg, d, _("`scp' did not complete cleanly.\n"));
+ return;
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully copied configuration file.\n");
+ "Successfully copied configuration file.\n");
#endif
d->phase = SP_COPIED;
/* fall-through */
case SP_COPIED:
/* start GNUnet on remote host */
- if (NULL == d->hostname)
- {
- d->pid = GNUNET_OS_start_process ("gnunet-service-arm",
- "gnunet-service-arm",
- "-c",
- d->cfgfile,
+ if (NULL == d->hostname)
+ {
+ d->pid = GNUNET_OS_start_process ("gnunet-service-arm",
+ "gnunet-service-arm",
+ "-c", d->cfgfile,
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-d",
- NULL);
- }
+ "-d", NULL);
+ }
else
- {
- if (d->username != NULL)
- GNUNET_asprintf (&dst,
- "%s@%s",
- d->username,
- d->hostname);
- else
- dst = GNUNET_strdup (d->hostname);
- d->pid = GNUNET_OS_start_process ("ssh",
- "ssh",
- dst,
- "gnunet-service-arm",
- "-c",
- d->cfgfile,
- "-d",
- NULL);
- GNUNET_free (dst);
- }
+ {
+ if (d->username != NULL)
+ GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
+ else
+ dst = GNUNET_strdup (d->hostname);
+ d->pid = GNUNET_OS_start_process ("ssh",
+ "ssh",
+ dst,
+ "gnunet-service-arm",
+ "-c", d->cfgfile, "-d", NULL);
+ GNUNET_free (dst);
+ }
if (-1 == d->pid)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start `%s' process to start GNUnet.\n"),
- (NULL == d->hostname) ? "gnunet-service-arm" : "ssh");
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- (NULL == d->hostname)
- ? _("Failed to start `gnunet-service-arm' process.\n")
- : _("Failed to start `ssh' process.\n"));
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not start `%s' process to start GNUnet.\n"),
+ (NULL == d->hostname) ? "gnunet-service-arm" : "ssh");
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg,
+ d,
+ (NULL == d->hostname)
+ ? _("Failed to start `gnunet-service-arm' process.\n")
+ : _("Failed to start `ssh' process.\n"));
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Started `%s', waiting for `%s' to be up.\n",
- "gnunet-service-arm",
- "gnunet-service-core");
+ "Started `%s', waiting for `%s' to be up.\n",
+ "gnunet-service-arm", "gnunet-service-core");
#endif
d->phase = SP_START_ARMING;
d->wait_runs = 0;
d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm,
- d);
- break;
+ = GNUNET_SCHEDULER_add_delayed (d->sched,
+ GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ break;
case SP_START_ARMING:
- if (GNUNET_OK !=
- GNUNET_OS_process_status (d->pid,
- &type,
- &code))
- {
- d->wait_runs++;
- if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- (NULL == d->hostname)
- ? _("`gnunet-service-arm' does not seem to terminate.\n")
- : _("`ssh' does not seem to terminate.\n"));
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm,
- d);
- return;
- }
+ if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
+ {
+ d->wait_runs++;
+ if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg,
+ d,
+ (NULL == d->hostname)
+ ? _("`gnunet-service-arm' does not seem to terminate.\n")
+ : _("`ssh' does not seem to terminate.\n"));
+ return;
+ }
+ /* wait some more */
+ d->task
+ = GNUNET_SCHEDULER_add_delayed (d->sched,
+ GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully started `%s'.\n",
- "gnunet-service-arm");
+ "Successfully started `%s'.\n", "gnunet-service-arm");
#endif
d->phase = SP_START_CORE;
d->server = GNUNET_CORE_connect (d->sched,
- d->cfg,
- ARM_START_WAIT,
- d,
- &testing_init,
- NULL, NULL, NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- no_handlers);
+ d->cfg,
+ ARM_START_WAIT,
+ d,
+ &testing_init,
+ NULL, NULL, NULL,
+ NULL, GNUNET_NO,
+ NULL, GNUNET_NO, no_handlers);
break;
case SP_START_CORE:
GNUNET_break (0);
@@ -447,95 +418,82 @@ start_fsm (void *cls,
break;
case SP_CLEANUP:
/* confirm copying complete */
- if (GNUNET_OK !=
- GNUNET_OS_process_status (d->pid,
- &type,
- &code))
- {
- d->wait_runs++;
- if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
- {
- d->dead_cb (d->dead_cb_cls,
- _("`ssh' does not seem to terminate.\n"));
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free (d);
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm,
- d);
- return;
- }
- if ( (type != GNUNET_OS_PROCESS_EXITED) ||
- (code != 0) )
- {
- if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls,
- _("`ssh' did not complete cleanly.\n"));
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free (d);
- return;
- }
+ if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
+ {
+ d->wait_runs++;
+ if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+ {
+ d->dead_cb (d->dead_cb_cls,
+ _("`ssh' does not seem to terminate.\n"));
+ GNUNET_free (d->cfgfile);
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
+ GNUNET_free (d);
+ return;
+ }
+ /* wait some more */
+ d->task
+ = GNUNET_SCHEDULER_add_delayed (d->sched,
+ GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
+ if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ {
+ if (NULL != d->dead_cb)
+ d->dead_cb (d->dead_cb_cls,
+ _("`ssh' did not complete cleanly.\n"));
+ GNUNET_free (d->cfgfile);
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
+ GNUNET_free (d);
+ return;
+ }
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer shutdown complete.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
#endif
GNUNET_free (d->cfgfile);
GNUNET_free_non_null (d->hostname);
GNUNET_free_non_null (d->username);
if (NULL != d->dead_cb)
- d->dead_cb (d->dead_cb_cls, NULL);
+ d->dead_cb (d->dead_cb_cls, NULL);
GNUNET_free (d);
break;
case SP_CONFIG_UPDATE:
/* confirm copying complete */
- if (GNUNET_OK !=
- GNUNET_OS_process_status (d->pid,
- &type,
- &code))
- {
- d->wait_runs++;
- if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
- {
- cb = d->cb;
- d->cb = NULL;
- if (NULL != cb)
- cb (d->cb_cls,
- NULL,
- d->cfg,
- d,
- _("`scp' does not seem to terminate.\n"));
- return;
- }
- /* wait some more */
- d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm,
- d);
- return;
- }
- if ( (type != GNUNET_OS_PROCESS_EXITED) ||
- (code != 0) )
- {
- if (NULL != d->update_cb)
- d->update_cb (d->update_cb_cls,
- _("`scp' did not complete cleanly.\n"));
- return;
- }
+ if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
+ {
+ d->wait_runs++;
+ if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+ {
+ cb = d->cb;
+ d->cb = NULL;
+ if (NULL != cb)
+ cb (d->cb_cls,
+ NULL,
+ d->cfg, d, _("`scp' does not seem to terminate.\n"));
+ return;
+ }
+ /* wait some more */
+ d->task
+ = GNUNET_SCHEDULER_add_delayed (d->sched,
+ GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
+ return;
+ }
+ if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
+ {
+ if (NULL != d->update_cb)
+ d->update_cb (d->update_cb_cls,
+ _("`scp' did not complete cleanly.\n"));
+ return;
+ }
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully copied configuration file.\n");
+ "Successfully copied configuration file.\n");
#endif
- if (NULL != d->update_cb)
- d->update_cb (d->update_cb_cls, NULL);
+ if (NULL != d->update_cb)
+ d->update_cb (d->update_cb_cls, NULL);
d->phase = SP_START_DONE;
break;
}
@@ -558,26 +516,26 @@ start_fsm (void *cls,
*/
struct GNUNET_TESTING_Daemon *
GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *hostname,
- GNUNET_TESTING_NotifyDaemonRunning cb,
- void *cb_cls)
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *hostname,
+ GNUNET_TESTING_NotifyDaemonRunning cb,
+ void *cb_cls)
{
- struct GNUNET_TESTING_Daemon * ret;
+ struct GNUNET_TESTING_Daemon *ret;
char *arg;
char *username;
- ret = GNUNET_malloc (sizeof(struct GNUNET_TESTING_Daemon));
+ ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
ret->sched = sched;
ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Setting up peer with configuration file `%s'.\n",
- ret->cfgfile);
+ "Setting up peer with configuration file `%s'.\n",
+ ret->cfgfile);
#endif
if (NULL == ret->cfgfile)
- {
+ {
GNUNET_free_non_null (ret->hostname);
GNUNET_free (ret);
return NULL;
@@ -586,18 +544,14 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
ret->cb_cls = cb_cls;
ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
GNUNET_CONFIGURATION_set_value_string (ret->cfg,
- "PATHS",
- "DEFAULTCONFIG",
- ret->cfgfile);
+ "PATHS",
+ "DEFAULTCONFIG", ret->cfgfile);
/* 1) write configuration to temporary file */
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_write (ret->cfg,
- ret->cfgfile))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
{
if (0 != UNLINK (ret->cfgfile))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- ret->cfgfile);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", ret->cfgfile);
GNUNET_CONFIGURATION_destroy (ret->cfg);
GNUNET_free_non_null (ret->hostname);
GNUNET_free (ret->cfgfile);
@@ -606,75 +560,62 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "TESTING",
- "USERNAME",
- &username))
+ "TESTING",
+ "USERNAME", &username))
{
if (NULL != getenv ("USER"))
- username = GNUNET_strdup (getenv("USER"));
+ username = GNUNET_strdup (getenv ("USER"));
else
- username = NULL;
+ username = NULL;
}
ret->username = username;
- /* 2) copy file to remote host */
- if (NULL != hostname)
+ /* 2) copy file to remote host */
+ if (NULL != hostname)
{
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Copying configuration file to host `%s'.\n",
- hostname);
+ "Copying configuration file to host `%s'.\n", hostname);
#endif
ret->phase = SP_COPYING;
if (NULL != username)
- GNUNET_asprintf (&arg,
- "%s@%s:%s",
- username,
- hostname,
- ret->cfgfile);
+ GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile);
else
- GNUNET_asprintf (&arg,
- "%s:%s",
- hostname,
- ret->cfgfile);
+ GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
ret->pid = GNUNET_OS_start_process ("scp",
- "scp",
- ret->cfgfile,
- arg,
- NULL);
+ "scp", ret->cfgfile, arg, NULL);
GNUNET_free (arg);
if (-1 == ret->pid)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start `%s' process to copy configuration file.\n"),
- "scp");
- if (0 != UNLINK (ret->cfgfile))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- ret->cfgfile);
- GNUNET_CONFIGURATION_destroy (ret->cfg);
- GNUNET_free_non_null (ret->hostname);
- GNUNET_free_non_null (ret->username);
- GNUNET_free (ret->cfgfile);
- GNUNET_free (ret);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Could not start `%s' process to copy configuration file.\n"),
+ "scp");
+ if (0 != UNLINK (ret->cfgfile))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", ret->cfgfile);
+ GNUNET_CONFIGURATION_destroy (ret->cfg);
+ GNUNET_free_non_null (ret->hostname);
+ GNUNET_free_non_null (ret->username);
+ GNUNET_free (ret->cfgfile);
+ GNUNET_free (ret);
+ return NULL;
+ }
ret->task
- = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm,
- ret);
+ = GNUNET_SCHEDULER_add_delayed (sched,
+ GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, ret);
return ret;
}
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No need to copy configuration file since we are running locally.\n");
+ "No need to copy configuration file since we are running locally.\n");
#endif
ret->phase = SP_COPIED;
GNUNET_SCHEDULER_add_continuation (sched,
- &start_fsm,
- ret,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ &start_fsm,
+ ret,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
return ret;
}
@@ -686,9 +627,9 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
* @param cb function called once the daemon was stopped
* @param cb_cls closure for cb
*/
-void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
- GNUNET_TESTING_NotifyCompletion cb,
- void * cb_cls)
+void
+GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
+ GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
{
struct GNUNET_CLIENT_Connection *cc;
char *dst;
@@ -702,8 +643,7 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
}
if (d->phase == SP_CONFIG_UPDATE)
{
- GNUNET_SCHEDULER_cancel (d->sched,
- d->task);
+ GNUNET_SCHEDULER_cancel (d->sched, d->task);
d->phase = SP_START_DONE;
}
if (d->server != NULL)
@@ -714,60 +654,49 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
/* shutdown ARM process (will also terminate others) */
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Terminating peer `%4s'\n"),
- GNUNET_i2s(&d->id));
+ _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
#endif
- cc = GNUNET_CLIENT_connect (d->sched,
- "arm",
- d->cfg);
+ cc = GNUNET_CLIENT_connect (d->sched, "arm", d->cfg);
GNUNET_CLIENT_service_shutdown (cc);
-
+
/* state clean up and notifications */
if (0 != UNLINK (d->cfgfile))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- d->cfgfile);
+ "unlink", d->cfgfile);
if (d->hostname != NULL)
{
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing configuration file on remote host `%s'.\n",
- d->hostname);
+ "Removing configuration file on remote host `%s'.\n",
+ d->hostname);
#endif
if (NULL != d->username)
- GNUNET_asprintf (&dst,
- "%s@%s",
- d->username,
- d->hostname);
+ GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
else
- dst = GNUNET_strdup (d->hostname);
+ dst = GNUNET_strdup (d->hostname);
d->pid = GNUNET_OS_start_process ("ssh",
- "ssh",
- dst,
- "rm",
- d->cfgfile,
- NULL);
+ "ssh", dst, "rm", d->cfgfile, NULL);
GNUNET_free (dst);
if (-1 == d->pid)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start `%s' process to delete configuration file.\n"),
- "ssh");
- GNUNET_free (d->cfgfile);
- GNUNET_free_non_null (d->hostname);
- GNUNET_free_non_null (d->username);
- GNUNET_free (d);
- cb (cb_cls, _("Error cleaning up configuration file.\n"));
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Could not start `%s' process to delete configuration file.\n"),
+ "ssh");
+ GNUNET_free (d->cfgfile);
+ GNUNET_free_non_null (d->hostname);
+ GNUNET_free_non_null (d->username);
+ GNUNET_free (d);
+ cb (cb_cls, _("Error cleaning up configuration file.\n"));
+ return;
+ }
d->phase = SP_CLEANUP;
d->dead_cb = cb;
d->dead_cb_cls = cb_cls;
d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm,
- d);
+ = GNUNET_SCHEDULER_add_delayed (d->sched,
+ GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
return;
}
GNUNET_CONFIGURATION_destroy (d->cfg);
@@ -788,81 +717,68 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
* @param cb function called once the configuration was changed
* @param cb_cls closure for cb
*/
-void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
- struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_TESTING_NotifyCompletion cb,
- void * cb_cls)
+void
+GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
+ struct GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_TESTING_NotifyCompletion cb,
+ void *cb_cls)
{
char *arg;
if (d->phase != SP_START_DONE)
{
if (NULL != cb)
- cb (cb_cls,
- _("Peer not yet running, can not change configuration at this point."));
- return;
+ cb (cb_cls,
+ _
+ ("Peer not yet running, can not change configuration at this point."));
+ return;
}
/* 1) write configuration to temporary file */
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_write (cfg,
- d->cfgfile))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile))
{
if (NULL != cb)
- cb (cb_cls,
- _("Failed to write new configuration to disk."));
+ cb (cb_cls, _("Failed to write new configuration to disk."));
return;
}
- /* 2) copy file to remote host (if necessary) */
+ /* 2) copy file to remote host (if necessary) */
if (NULL == d->hostname)
{
/* signal success */
if (NULL != cb)
- cb (cb_cls, NULL);
+ cb (cb_cls, NULL);
return;
}
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Copying updated configuration file to remote host `%s'.\n",
- d->hostname);
+ "Copying updated configuration file to remote host `%s'.\n",
+ d->hostname);
#endif
d->phase = SP_CONFIG_UPDATE;
if (NULL != d->username)
- GNUNET_asprintf (&arg,
- "%s@%s:%s",
- d->username,
- d->hostname,
- d->cfgfile);
+ GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile);
else
- GNUNET_asprintf (&arg,
- "%s:%s",
- d->hostname,
- d->cfgfile);
- d->pid = GNUNET_OS_start_process ("scp",
- "scp",
- d->cfgfile,
- arg,
- NULL);
+ GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile);
+ d->pid = GNUNET_OS_start_process ("scp", "scp", d->cfgfile, arg, NULL);
GNUNET_free (arg);
if (-1 == d->pid)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start `%s' process to copy configuration file.\n"),
- "scp");
+ _
+ ("Could not start `%s' process to copy configuration file.\n"),
+ "scp");
if (NULL != cb)
- cb (cb_cls,
- _("Failed to copy new configuration to remote machine."));
+ cb (cb_cls, _("Failed to copy new configuration to remote machine."));
d->phase = SP_START_DONE;
return;
}
d->update_cb = cb;
d->update_cb_cls = cb_cls;
d->task
- = GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_CONSTANTS_EXEC_WAIT,
- &start_fsm,
- d);
+ = GNUNET_SCHEDULER_add_delayed (d->sched,
+ GNUNET_CONSTANTS_EXEC_WAIT,
+ &start_fsm, d);
}
@@ -895,7 +811,7 @@ struct ConnectContext
/**
* Function to call once we are done (or have timed out).
*/
- GNUNET_TESTING_NotifyCompletion cb;
+ GNUNET_TESTING_NotifyConnection cb;
/**
* Closure for "nb".
@@ -926,16 +842,19 @@ struct ConnectContext
*/
static void
notify_connect_result (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ConnectContext *ctx = cls;
if (ctx->cb != NULL)
{
if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
- ctx->cb (ctx->cb_cls, _("Peers failed to connect"));
+ ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
+ ctx->d2->cfg, ctx->d1, ctx->d2,
+ _("Peers failed to connect"));
else
- ctx->cb (ctx->cb_cls, NULL);
+ ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
+ ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
}
GNUNET_free (ctx);
}
@@ -964,28 +883,24 @@ transmit_ready (void *cls, size_t size, void *buf)
GNUNET_TRANSPORT_disconnect (ctx->d2th);
ctx->d2th = NULL;
GNUNET_SCHEDULER_add_continuation (ctx->d1->sched,
- &notify_connect_result,
- ctx,
- (buf == NULL) ?
- GNUNET_SCHEDULER_REASON_TIMEOUT :
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ &notify_connect_result,
+ ctx,
+ (buf == NULL) ?
+ GNUNET_SCHEDULER_REASON_TIMEOUT :
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
return 0;
}
#if 0
static void
-timeout_hello_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th,
- &process_hello,
- ctx);
+ GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, &process_hello, ctx);
GNUNET_TRANSPORT_disconnect (ctx->d1th);
GNUNET_TRANSPORT_disconnect (ctx->d2th);
if (NULL != ctx->cb)
- ctx->cb (ctx->cb_cls,
- _("Failed to receive `HELLO' from peer\n"));
+ ctx->cb (ctx->cb_cls, _("Failed to receive `HELLO' from peer\n"));
GNUNET_free (ctx);
}
#endif
@@ -999,31 +914,38 @@ timeout_hello_task (void *cls,
* @param message HELLO message of peer
*/
static void
-process_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct ConnectContext *ctx = cls;
/* first of all, stop the notification stuff */
- GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th,
- &process_hello,
- ctx);
+ GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, &process_hello, ctx);
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' from transport service of `%4s'\n",
- "HELLO", GNUNET_i2s (peer));
+ "HELLO", GNUNET_i2s (&ctx->d1->id));
#endif
GNUNET_assert (message != NULL);
GNUNET_TRANSPORT_offer_hello (ctx->d2th, message);
- ctx->ntr
+ ctx->ntr
= GNUNET_CORE_notify_transmit_ready (ctx->d2->server,
- 0,
- GNUNET_TIME_absolute_get_remaining (ctx->timeout),
- &ctx->d1->id,
- sizeof (struct GNUNET_MessageHeader),
- &transmit_ready, ctx);
+ 0,
+ GNUNET_TIME_absolute_get_remaining
+ (ctx->timeout), &ctx->d1->id,
+ sizeof (struct GNUNET_MessageHeader),
+ &transmit_ready, ctx);
}
+/*
+ * Accessor function since we have hidden what GNUNET_TESTING_Daemon is
+ *
+ * FIXME: Either expose members or figure out a better way!
+ */
+char *
+GNUNET_TESTING_daemon_get_shortname (struct GNUNET_TESTING_Daemon *d)
+{
+ return d->shortname;
+}
/**
* Establish a connection between two GNUnet daemons.
@@ -1035,55 +957,72 @@ process_hello (void *cls,
* @param cb function to call at the end
* @param cb_cls closure for cb
*/
-void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
- struct GNUNET_TESTING_Daemon *d2,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TESTING_NotifyCompletion cb,
- void *cb_cls)
+void
+GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
+ struct GNUNET_TESTING_Daemon *d2,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TESTING_NotifyConnection cb,
+ void *cb_cls)
{
struct ConnectContext *ctx;
- if ( (d1->server == NULL) ||
- (d2->server == NULL) )
+ if ((d1->server == NULL) || (d2->server == NULL))
{
if (NULL != cb)
- cb (cb_cls, _("Peers are not fully running yet, can not connect!\n"));
+ cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
+ _("Peers are not fully running yet, can not connect!\n"));
return;
}
- ctx = GNUNET_malloc (sizeof(struct ConnectContext));
+ ctx = GNUNET_malloc (sizeof (struct ConnectContext));
ctx->d1 = d1;
ctx->d2 = d2;
ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
ctx->cb = cb;
ctx->cb_cls = cb_cls;
+#if DEBUG_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asked to connect peer %s to peer %s\n",
+ d1->shortname, d2->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting to transport service of peer %s\n", d1->shortname);
+#endif
ctx->d1th = GNUNET_TRANSPORT_connect (d1->sched,
- d1->cfg,
- d1,
- NULL, NULL, NULL);
+ d1->cfg, d1, NULL, NULL, NULL);
if (ctx->d1th == NULL)
{
GNUNET_free (ctx);
if (NULL != cb)
- cb (cb_cls, _("Failed to connect to transport service!\n"));
+ cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
+ _("Failed to connect to transport service!\n"));
return;
}
+#if DEBUG_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asked to connect peer %s to peer %s\n",
+ d1->shortname, d2->shortname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting to transport service of peer %s\n", d2->shortname);
+
+#endif
ctx->d2th = GNUNET_TRANSPORT_connect (d2->sched,
- d2->cfg,
- d2,
- NULL, NULL, NULL);
+ d2->cfg, d2, NULL, NULL, NULL);
if (ctx->d2th == NULL)
{
GNUNET_TRANSPORT_disconnect (ctx->d1th);
GNUNET_free (ctx);
if (NULL != cb)
- cb (cb_cls, _("Failed to connect to transport service!\n"));
+ cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
+ _("Failed to connect to transport service!\n"));
return;
- }
+ }
+
+#if DEBUG_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking for hello from peer %s\n", GNUNET_i2s (&d1->id));
+#endif
/* FIXME: need to handle timeout: start timeout task
as well here! (use 'timeout_hello_task') */
- GNUNET_TRANSPORT_get_hello (ctx->d1th,
- &process_hello,
- ctx);
+ GNUNET_TRANSPORT_get_hello (ctx->d1th, &process_hello, ctx);
}
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index b87507364..424dada34 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -27,6 +27,8 @@
#include "gnunet_arm_service.h"
#include "gnunet_testing_lib.h"
+#define VERBOSE_TESTING GNUNET_YES
+
/**
* Lowest port used for GNUnet testing. Should be high enough to not
* conflict with other applications running on the hosts but be low
@@ -42,6 +44,8 @@
*/
#define HIGH_PORT 32000
+#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
/**
* Data we keep per peer.
*/
@@ -54,7 +58,7 @@ struct PeerData
* updates).
*/
struct GNUNET_CONFIGURATION_Handle *cfg;
-
+
/**
* Handle for controlling the daemon.
*/
@@ -71,7 +75,7 @@ struct HostData
* Name of the host.
*/
char *hostname;
-
+
/**
* Lowest port that we have not yet used
* for GNUnet.
@@ -87,7 +91,7 @@ struct GNUNET_TESTING_PeerGroup
{
/**
* Our scheduler.
- */
+ */
struct GNUNET_SCHEDULER_Handle *sched;
/**
@@ -97,7 +101,7 @@ struct GNUNET_TESTING_PeerGroup
/**
* Function to call on each started daemon.
- */
+ */
GNUNET_TESTING_NotifyDaemonRunning cb;
/**
@@ -105,6 +109,16 @@ struct GNUNET_TESTING_PeerGroup
*/
void *cb_cls;
+ /*
+ * Function to call on each topology connection created
+ */
+ GNUNET_TESTING_NotifyConnection notify_connection;
+
+ /*
+ * Callback for notify_connection
+ */
+ void *notify_connection_cls;
+
/**
* NULL-terminated array of information about
* hosts.
@@ -118,13 +132,13 @@ struct GNUNET_TESTING_PeerGroup
/**
* Number of peers in this group.
- */
+ */
unsigned int total;
};
-struct UpdateContext
+struct UpdateContext
{
struct GNUNET_CONFIGURATION_Handle *ret;
unsigned int nport;
@@ -140,29 +154,20 @@ struct UpdateContext
* @param option name of the option
* @param value value of the option
*/
-static void
-update_config(void *cls,
- const char *section,
- const char *option,
- const char *value)
+static void
+update_config (void *cls,
+ const char *section, const char *option, const char *value)
{
struct UpdateContext *ctx = cls;
unsigned int ival;
char cval[12];
- if ( (0 == strcmp (option, "PORT")) &&
- (1 == sscanf (value, "%u", &ival)) )
+ if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
{
- GNUNET_snprintf (cval,
- sizeof(cval),
- "%u",
- ctx->nport++);
+ GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++);
value = cval;
- }
- GNUNET_CONFIGURATION_set_value_string (ctx->ret,
- section,
- option,
- value);
+ }
+ GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, option, value);
}
@@ -177,9 +182,8 @@ update_config(void *cls,
* port numbers that were used
* @return new configuration, NULL on error
*/
-static struct GNUNET_CONFIGURATION_Handle*
-make_config (const struct GNUNET_CONFIGURATION_Handle*cfg,
- uint16_t *port)
+static struct GNUNET_CONFIGURATION_Handle *
+make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t * port)
{
struct UpdateContext uc;
uint16_t orig;
@@ -187,9 +191,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle*cfg,
orig = *port;
uc.nport = *port;
uc.ret = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_iterate (cfg,
- &update_config,
- &uc);
+ GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
if (uc.nport >= HIGH_PORT)
{
*port = orig;
@@ -200,6 +202,143 @@ make_config (const struct GNUNET_CONFIGURATION_Handle*cfg,
return uc.ret;
}
+static int
+create_clique (struct GNUNET_TESTING_PeerGroup *pg)
+{
+ unsigned int outer_count;
+ unsigned int inner_count;
+ int connect_attempts;
+
+ connect_attempts = 0;
+
+ for (outer_count = 0; outer_count < pg->total - 1; outer_count++)
+ {
+ for (inner_count = outer_count + 1; inner_count < pg->total;
+ inner_count++)
+ {
+#if VERBOSE_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting peer %d to peer %d\n",
+ outer_count, inner_count);
+#endif
+ GNUNET_TESTING_daemons_connect (pg->peers[outer_count].daemon,
+ pg->peers[inner_count].daemon,
+ CONNECT_TIMEOUT,
+ pg->notify_connection,
+ pg->notify_connection_cls);
+ connect_attempts++;
+ }
+ }
+
+ return connect_attempts;
+}
+
+
+/*
+ * Takes a peer group and attempts to create a topology based on the
+ * one specified in the configuration file. Returns the number of connections
+ * that will attempt to be created, but this will happen asynchronously(?) so
+ * the caller will have to keep track (via the callback) of whether or not
+ * the connection actually happened.
+ *
+ * @param pg the peer group struct representing the running peers
+ *
+ */
+int
+GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg)
+{
+ /* Put stuff at home in here... */
+ unsigned long long topology_num;
+ int ret;
+
+ GNUNET_assert (pg->notify_connection != NULL);
+ ret = 0;
+ if (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_number (pg->cfg, "testing", "topology",
+ &topology_num))
+ {
+ switch (topology_num)
+ {
+ case GNUNET_TESTING_TOPOLOGY_CLIQUE:
+#if VERBOSE_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Creating clique topology (may take a bit!)\n"));
+ ret = create_clique (pg);
+ break;
+ case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Creating small world topology (may take a bit!)\n"));
+#endif
+ ret = GNUNET_SYSERR;
+/* ret =
+ GNUNET_REMOTE_connect_small_world_ring (&totalConnections,
+ number_of_daemons,
+ list_as_array, dotOutFile,
+ percentage, logNModifier);
+ */
+ break;
+ case GNUNET_TESTING_TOPOLOGY_RING:
+#if VERBOSE_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Creating ring topology (may take a bit!)\n"));
+#endif
+ /*
+ ret = GNUNET_REMOTE_connect_ring (&totalConnections, head, dotOutFile);
+ */
+ ret = GNUNET_SYSERR;
+ break;
+ case GNUNET_TESTING_TOPOLOGY_2D_TORUS:
+#if VERBOSE_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Creating 2d torus topology (may take a bit!)\n"));
+#endif
+ /*
+ ret =
+ GNUNET_REMOTE_connect_2d_torus (&totalConnections, number_of_daemons,
+ list_as_array, dotOutFile);
+ */
+ ret = GNUNET_SYSERR;
+ break;
+ case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI:
+#if VERBOSE_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Creating Erdos-Renyi topology (may take a bit!)\n"));
+#endif
+ /* ret =
+ GNUNET_REMOTE_connect_erdos_renyi (&totalConnections, percentage,
+ head, dotOutFile);
+ */
+ ret = GNUNET_SYSERR;
+ break;
+ case GNUNET_TESTING_TOPOLOGY_INTERNAT:
+#if VERBOSE_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Creating InterNAT topology (may take a bit!)\n"));
+#endif
+ /*
+ ret =
+ GNUNET_REMOTE_connect_nated_internet (&totalConnections, percentage,
+ number_of_daemons, head,
+ dotOutFile);
+ */
+ ret = GNUNET_SYSERR;
+ break;
+ case GNUNET_TESTING_TOPOLOGY_NONE:
+ ret = 0;
+ break;
+ default:
+ ret = GNUNET_SYSERR;
+ break;
+ }
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("No topology specified, was one intended?\n"));
+ }
+
+ return ret;
+}
/**
* Start count gnunetd processes with the same set of transports and
@@ -212,85 +351,93 @@ make_config (const struct GNUNET_CONFIGURATION_Handle*cfg,
* @param total number of daemons to start
* @param cb function to call on each daemon that was started
* @param cb_cls closure for cb
+ * @param connect_callback function to call each time two hosts are connected
+ * @param connect_callback_cls closure for connect_callback
* @param hostnames space-separated list of hostnames to use; can be NULL (to run
* everything on localhost).
* @return NULL on error, otherwise handle to control peer group
*/
struct GNUNET_TESTING_PeerGroup *
GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int total,
- GNUNET_TESTING_NotifyDaemonRunning cb,
- void *cb_cls,
- const char *hostnames)
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned int total,
+ GNUNET_TESTING_NotifyDaemonRunning cb,
+ void *cb_cls,
+ GNUNET_TESTING_NotifyConnection
+ connect_callback, void *connect_callback_cls,
+ const char *hostnames)
{
struct GNUNET_TESTING_PeerGroup *pg;
const char *rpos;
char *pos;
char *start;
const char *hostname;
+ char *baseservicehome;
+ char *newservicehome;
struct GNUNET_CONFIGURATION_Handle *pcfg;
unsigned int off;
unsigned int hostcnt;
uint16_t minport;
+ int tempsize;
if (0 == total)
{
GNUNET_break (0);
return NULL;
}
- pg = GNUNET_malloc (sizeof(struct GNUNET_TESTING_PeerGroup));
+ pg = GNUNET_malloc (sizeof (struct GNUNET_TESTING_PeerGroup));
pg->sched = sched;
pg->cfg = cfg;
pg->cb = cb;
pg->cb_cls = cb_cls;
+ pg->notify_connection = connect_callback;
+ pg->notify_connection_cls = connect_callback_cls;
pg->total = total;
- pg->peers = GNUNET_malloc (total * sizeof(struct PeerData));
+ pg->peers = GNUNET_malloc (total * sizeof (struct PeerData));
if (NULL != hostnames)
{
off = 2;
/* skip leading spaces */
- while ( (0 != *hostnames) &&
- (isspace(*hostnames)))
- hostnames++;
+ while ((0 != *hostnames) && (isspace (*hostnames)))
+ hostnames++;
rpos = hostnames;
while ('\0' != *rpos)
- {
- if (isspace (*rpos))
- off++;
- rpos++;
- }
+ {
+ if (isspace (*rpos))
+ off++;
+ rpos++;
+ }
pg->hosts = GNUNET_malloc (off * sizeof (struct HostData));
off = 0;
start = GNUNET_strdup (hostnames);
pos = start;
while ('\0' != *pos)
- {
- if (isspace (*pos))
- {
- *pos = '\0';
- if (strlen(start) > 0)
- {
- pg->hosts[off].minport = LOW_PORT;
- pg->hosts[off++].hostname = start;
- }
- start = pos+1;
- }
- pos++;
- }
- if (strlen(start) > 0)
- {
- pg->hosts[off].minport = LOW_PORT;
- pg->hosts[off++].hostname = start;
- }
+ {
+ if (isspace (*pos))
+ {
+ *pos = '\0';
+ if (strlen (start) > 0)
+ {
+ pg->hosts[off].minport = LOW_PORT;
+ pg->hosts[off++].hostname = start;
+ }
+ start = pos + 1;
+ }
+ pos++;
+ }
+ if (strlen (start) > 0)
+ {
+ pg->hosts[off].minport = LOW_PORT;
+ pg->hosts[off++].hostname = start;
+ }
if (off == 0)
- {
- GNUNET_free (start);
- GNUNET_free (pg->hosts);
- pg->hosts = NULL;
- }
+ {
+ GNUNET_free (start);
+ GNUNET_free (pg->hosts);
+ pg->hosts = NULL;
+ }
hostcnt = off;
- minport = 0; /* make gcc happy */
+ minport = 0; /* make gcc happy */
}
else
{
@@ -300,33 +447,51 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
for (off = 0; off < total; off++)
{
if (hostcnt > 0)
- {
- hostname = pg->hosts[off % hostcnt].hostname;
- pcfg = make_config (cfg, &pg->hosts[off % hostcnt].minport);
- }
+ {
+ hostname = pg->hosts[off % hostcnt].hostname;
+ pcfg = make_config (cfg, &pg->hosts[off % hostcnt].minport);
+ }
else
- {
- hostname = NULL;
- pcfg = make_config (cfg, &minport);
- }
+ {
+ hostname = NULL;
+ pcfg = make_config (cfg, &minport);
+ }
if (NULL == pcfg)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not create configuration for peer number %u on `%s'!\n"),
- off,
- hostname == NULL ? "localhost" : hostname);
- continue;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Could not create configuration for peer number %u on `%s'!\n"),
+ off, hostname == NULL ? "localhost" : hostname);
+ continue;
+ }
+
+ if (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", "SERVICEHOME",
+ &baseservicehome))
+ {
+ tempsize = snprintf (NULL, 0, "%s/%d/", baseservicehome, off) + 1;
+ newservicehome = GNUNET_malloc (tempsize);
+ snprintf (newservicehome, tempsize, "%s/%d/", baseservicehome, off);
+ }
+ else
+ {
+ tempsize = snprintf (NULL, 0, "%s/%d/", "/tmp/gnunet-testing-test-test", off) + 1; /* FIXME: set a default path, or read the TMPDIR variable or something */
+ newservicehome = GNUNET_malloc (tempsize);
+ snprintf (newservicehome, tempsize, "%s/%d/",
+ "/tmp/gnunet-testing-test-test", off);
+ }
+ GNUNET_CONFIGURATION_set_value_string (pcfg,
+ "PATHS",
+ "SERVICEHOME", newservicehome);
+
pg->peers[off].cfg = pcfg;
pg->peers[off].daemon = GNUNET_TESTING_daemon_start (sched,
- pcfg,
- hostname,
- cb,
- cb_cls);
+ pcfg,
+ hostname,
+ cb, cb_cls);
if (NULL == pg->peers[off].daemon)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not start peer number %u!\n"),
- off);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not start peer number %u!\n"), off);
}
return pg;
}
@@ -345,14 +510,13 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg)
for (off = 0; off < pg->total; off++)
{
/* FIXME: should we wait for our
- continuations to be called here? This
- would require us to take a continuation
- as well... */
+ continuations to be called here? This
+ would require us to take a continuation
+ as well... */
if (NULL != pg->peers[off].daemon)
- GNUNET_TESTING_daemon_stop (pg->peers[off].daemon,
- NULL, NULL);
+ GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, NULL, NULL);
if (NULL != pg->peers[off].cfg)
- GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg);
+ GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg);
}
GNUNET_free (pg->peers);
if (NULL != pg->hosts)
diff --git a/src/testing/testing_testbed.c b/src/testing/testing_testbed.c
index a3b2c93eb..3d973da77 100644
--- a/src/testing/testing_testbed.c
+++ b/src/testing/testing_testbed.c
@@ -59,13 +59,11 @@ struct GNUNET_TESTING_Testbed
*/
struct GNUNET_TESTING_Testbed *
GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int count,
- enum GNUNET_TESTING_Topology topology,
- GNUNET_TESTING_NotifyDaemonRunning cb,
- void *cb_cls,
- const char *hostname,
- ...)
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned int count,
+ enum GNUNET_TESTING_Topology topology,
+ GNUNET_TESTING_NotifyDaemonRunning cb,
+ void *cb_cls, const char *hostname, ...)
{
GNUNET_break (0);
return NULL;
@@ -81,8 +79,7 @@ GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
*/
void
GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
- GNUNET_TESTING_NotifyCompletion cb,
- void *cb_cls)
+ GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
{
GNUNET_break (0);
}
@@ -110,10 +107,10 @@ GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
*/
void
GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb,
- unsigned int voff,
- unsigned int von,
- GNUNET_TESTING_NotifyCompletion cb,
- void *cb_cls)
+ unsigned int voff,
+ unsigned int von,
+ GNUNET_TESTING_NotifyCompletion cb,
+ void *cb_cls)
{
GNUNET_break (0);
}