* 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
* return to "SP_START_DONE" (and rely on ARM to restart all affected
* services).
*/
- SP_CONFIG_UPDATE
- };
+ SP_CONFIG_UPDATE
+};
/**
*/
char *hostname;
+ /* Result of GNUNET_i2s of this peer, for printing */
+ char *shortname;
+
/**
* Username we are using.
*/
/**
* Handle to the server.
- */
- struct GNUNET_CORE_Handle * server;
+ */
+ struct GNUNET_CORE_Handle *server;
};
*/
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;
{
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);
* @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);
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;
}
*/
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;
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);
}
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;
}
* @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;
}
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)
/* 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);
* @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);
}
/**
* Function to call once we are done (or have timed out).
*/
- GNUNET_TESTING_NotifyCompletion cb;
+ GNUNET_TESTING_NotifyConnection cb;
/**
* Closure for "nb".
*/
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);
}
GNUNET_TRANSPORT_disconnect (ctx->d2th);
ctx->d2th = NULL;
GNUNET_SCHEDULER_add_continuation (ctx->d1->sched,
- ¬ify_connect_result,
- ctx,
- (buf == NULL) ?
- GNUNET_SCHEDULER_REASON_TIMEOUT :
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ ¬ify_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
* @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.
* @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);
}
#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
*/
#define HIGH_PORT 32000
+#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
/**
* Data we keep per peer.
*/
* updates).
*/
struct GNUNET_CONFIGURATION_Handle *cfg;
-
+
/**
* Handle for controlling the daemon.
*/
* Name of the host.
*/
char *hostname;
-
+
/**
* Lowest port that we have not yet used
* for GNUnet.
{
/**
* Our scheduler.
- */
+ */
struct GNUNET_SCHEDULER_Handle *sched;
/**
/**
* Function to call on each started daemon.
- */
+ */
GNUNET_TESTING_NotifyDaemonRunning cb;
/**
*/
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.
/**
* Number of peers in this group.
- */
+ */
unsigned int total;
};
-struct UpdateContext
+struct UpdateContext
{
struct GNUNET_CONFIGURATION_Handle *ret;
unsigned int nport;
* @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);
}
* 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;
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;
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
* @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
{
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;
}
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)