peers_left--;
if (peers_left == 0)
{
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
ok = 0;
}
else if (peers_failed == peers_left)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n");
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ //GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
}
}
char *buf;
char *data;
int count;
+ int ret;
sched = s;
ok = 1;
#if VERBOSE
while (count < frstat.st_size)
{
count++;
- if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))
+ if (count >= frstat.st_size)
+ break;
+
+ /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))*/
+ if (((data[count] == '\n')) && (buf != &data[count]))
{
data[count] = '\0';
temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
- temphost->hostname = buf;
+ ret = sscanf(buf, "%a[a-zA-Z0-9]@%a[a-zA-Z0-9.]:%hd", &temphost->username, &temphost->hostname, &temphost->port);
+ if (3 == ret)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Successfully read host %s, port %d and user %s from file\n", temphost->hostname, temphost->port, temphost->username);
+ }
+ else
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Error reading line `%s' in hostfile\n", buf);
+ GNUNET_free(temphost);
+ buf = &data[count + 1];
+ continue;
+ }
+ /* temphost->hostname = buf; */
temphost->next = hosts;
hosts = temphost;
buf = &data[count + 1];
while (hostpos != NULL)
{
temphost = hostpos->next;
+ GNUNET_free(hostpos->hostname);
+ GNUNET_free(hostpos->username);
GNUNET_free(hostpos);
hostpos = temphost;
}
GNUNET_free_non_null(data);
GNUNET_assert (pg != NULL);
+
}
static int
"gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", d->cfgfile,
"-sq");
#endif
- d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
- "ssh",
+ if (d->ssh_port_str == NULL)
+ {
+ d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
+ "ssh",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- dst,
- "gnunet-peerinfo",
- "-c", d->cfgfile, "-sq", NULL);
+ dst,
+ "gnunet-peerinfo",
+ "-c", d->cfgfile, "-sq", NULL);
+ }
+ else
+ {
+ d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
+ "ssh", "-p", d->ssh_port_str,
+#if !DEBUG_TESTING
+ "-q",
+#endif
+ dst,
+ "gnunet-peerinfo",
+ "-c", d->cfgfile, "-sq", NULL);
+ }
GNUNET_DISK_pipe_close_end(d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_free (dst);
}
"gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile,
"-L", "DEBUG", "-s", "-q");
#endif
- d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
- "ssh",
+ if (d->ssh_port_str == NULL)
+ {
+ d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
+ "ssh",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- dst,
- "gnunet-arm",
+ dst,
+ "gnunet-arm",
#if DEBUG_TESTING
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", d->cfgfile, "-s", "-q", NULL);
+ "-c", d->cfgfile, "-s", "-q", NULL);
+ }
+ else
+ {
+
+ d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
+ "ssh", "-p", d->ssh_port_str,
+#if !DEBUG_TESTING
+ "-q",
+#endif
+ dst,
+ "gnunet-arm",
+#if DEBUG_TESTING
+ "-L", "DEBUG",
+#endif
+ "-c", d->cfgfile, "-s", "-q", NULL);
+ }
GNUNET_free (dst);
}
if (-1 == d->pid)
* @param timeout how long to wait starting up peers
* @param hostname name of the machine where to run GNUnet
* (use NULL for localhost).
+ * @param ssh_username ssh username to use when connecting to hostname
+ * @param sshport port to pass to ssh process when connecting to hostname
* @param hostkey_callback function to call once the hostkey has been
* generated for this peer, but it hasn't yet been started
* (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TIME_Relative timeout,
const char *hostname,
+ const char *ssh_username,
+ uint16_t sshport,
GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
void *hostkey_cls,
GNUNET_TESTING_NotifyDaemonRunning cb,
ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
ret->sched = sched;
ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
+ if (sshport != 0)
+ {
+ GNUNET_asprintf(&ret->ssh_port_str, "%d", sshport);
+ }
+ else
+ ret->ssh_port_str = NULL;
ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_free (ret);
return NULL;
}
- if (GNUNET_OK !=
+ if (ssh_username != NULL)
+ username = GNUNET_strdup(ssh_username);
+ if ((ssh_username == NULL) && (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"TESTING",
- "USERNAME", &username))
+ "USERNAME", &username)))
{
if (NULL != getenv ("USER"))
username = GNUNET_strdup (getenv ("USER"));
GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile);
else
GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
- ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
- "scp",
+
+ if (ret->ssh_port_str == NULL)
+ {
+ ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
+ "scp",
#if !DEBUG_TESTING
- "-q",
+ "-q",
#endif
- ret->cfgfile, arg, NULL);
+ ret->cfgfile, arg, NULL);
+ }
+ else
+ {
+ ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
+ "scp", "-P", ret->ssh_port_str,
+#if !DEBUG_TESTING
+ "-q",
+#endif
+ ret->cfgfile, arg, NULL);
+ }
GNUNET_free (arg);
if (-1 == ret->pid)
{
GNUNET_free_non_null (d->username);
if (NULL != d->dead_cb)
d->dead_cb (d->dead_cb_cls, NULL);
+ GNUNET_free(d);
return;
}
* Hostname, where to start the peer
*/
const char *hostname;
+
+ /**
+ * Username to use when connecting to the
+ * host via ssh.
+ */
+ const char *username;
+
+ /**
+ * Port to use for ssh.
+ */
+ uint16_t sshport;
+
};
/**
*/
char *hostname;
+ /**
+ * SSH username to use when connecting to this host.
+ */
+ char *username;
+
+ /**
+ * SSH port to use when connecting to this host.
+ */
+ uint16_t sshport;
+
/**
* Lowest port that we have not yet used
* for GNUnet.
value = uval;
}
GNUNET_free(single_variable);
+ GNUNET_free(per_host_variable);
}
GNUNET_CONFIGURATION_set_value_string(uc.ret, "transport-udp", "BINDTO", "127.0.0.1");
}
+
*port = (uint16_t) uc.nport;
*upnum = uc.upnum;
uc.fdnum++;
internal_context->peer->cfg,
internal_context->timeout,
internal_context->hostname,
+ internal_context->username,
+ internal_context->sshport,
&internal_hostkey_callback,
internal_context,
&internal_startup_callback,
char *start;
#endif
const char *hostname;
+ const char *username;
char *baseservicehome;
char *newservicehome;
char *tmpdir;
unsigned int off;
unsigned int hostcnt;
uint16_t minport;
+ uint16_t sshport;
uint32_t upnum;
uint32_t fdnum;
while (hostpos != NULL)
{
pg->hosts[off].minport = LOW_PORT;
- pg->hosts[off++].hostname = GNUNET_strdup(hostpos->hostname);
+ off++;
+ pg->hosts[off].hostname = GNUNET_strdup(hostpos->hostname);
+ if (hostpos->username != NULL)
+ pg->hosts[off].username = GNUNET_strdup(hostpos->username);
+ pg->hosts[off].sshport = hostpos->port;
hostpos = hostpos->next;
}
if (hostcnt > 0)
{
hostname = pg->hosts[off % hostcnt].hostname;
+ username = pg->hosts[off % hostcnt].username;
+ sshport = pg->hosts[off % hostcnt].sshport;
pcfg = make_config (cfg,
&pg->hosts[off % hostcnt].minport,
&upnum,
else
{
hostname = NULL;
+ username = NULL;
+ sshport = 0;
pcfg = make_config (cfg,
&minport,
&upnum,
pg->peers[off].internal_context.peer = &pg->peers[off];
pg->peers[off].internal_context.timeout = timeout;
pg->peers[off].internal_context.hostname = hostname;
+ pg->peers[off].internal_context.username = username;
+ pg->peers[off].internal_context.sshport = sshport;
pg->peers[off].internal_context.hostkey_callback = hostkey_callback;
pg->peers[off].internal_context.hostkey_cls = hostkey_cls;
pg->peers[off].internal_context.start_cb = cb;
}
}
+/**
+ * Count the number of running peers.
+ *
+ * @param pg handle for the peer group
+ *
+ * @return the number of currently running peers in the peer group
+ */
+unsigned int
+GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg)
+{
+ unsigned int i;
+ unsigned int running = 0;
+ for (i = 0; i < pg->total; i++)
+ {
+ if (pg->peers[i].daemon->running == GNUNET_YES)
+ {
+ GNUNET_assert(running != -1);
+ running++;
+ }
+ }
+ return running;
+}
/**
* Simulate churn by stopping some peers (and possibly