return;
}
d->hostkeybuf[103] = '\0';
+
if ((bytes_read < 0) ||
(GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf,
&d->id.hashPubKey)))
if (NULL == d->hostname)
{
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Starting `%s', with command `%s %s %s %s %s %s'.\n",
"gnunet-arm", "gnunet-arm", "-c", d->cfgfile,
"-L", "DEBUG", "-s");
dst = GNUNET_strdup (d->hostname);
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n",
"gnunet-arm", "ssh", dst, "gnunet-arm", "-c",
d->cfgfile, "-L", "DEBUG", "-s", "-q");
return;
}
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Started `%s', waiting for `%s' to be up.\n",
"gnunet-arm", "gnunet-service-core");
#endif
(NULL == d->hostname)
? _("`gnunet-arm' does not seem to terminate.\n")
: _("`ssh' does not seem to terminate.\n"));
+ GNUNET_free(d->proc);
return;
}
/* wait some more */
return;
}
#if DEBUG_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Successfully started `%s'.\n", "gnunet-arm");
#endif
+ GNUNET_free(d->proc);
d->phase = SP_START_CORE;
+#if DEBUG_TESTING
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Calling CORE_connect\n");
+#endif
d->server = GNUNET_CORE_connect (d->cfg, 1,
#if NO_MORE_TIMEOUT_FIXME
ARM_START_WAIT,
GNUNET_free_non_null (d->hostname);
GNUNET_free_non_null (d->username);
GNUNET_free_non_null (d->shortname);
+ GNUNET_free_non_null (d->proc);
+ d->proc = NULL;
GNUNET_free (d);
return;
}
GNUNET_free_non_null (d->hostname);
GNUNET_free_non_null (d->username);
GNUNET_free_non_null (d->shortname);
+ GNUNET_free_non_null (d->proc);
+ d->proc = NULL;
GNUNET_free (d);
return;
}
GNUNET_free_non_null (d->hello);
d->hello = NULL;
GNUNET_free_non_null (d->shortname);
+ GNUNET_free_non_null (d->proc);
+ d->proc = NULL;
d->shortname = NULL;
if (NULL != d->dead_cb)
d->dead_cb (d->dead_cb_cls, NULL);
* (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 pointer to a hostkey to be written to disk (instead of being generated)
* @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 char *hostname,
const char *ssh_username,
uint16_t sshport,
+ const char *hostkey,
GNUNET_TESTING_NotifyHostkeyCreated
hostkey_callback, void *hostkey_cls,
GNUNET_TESTING_NotifyDaemonRunning cb,
struct GNUNET_TESTING_Daemon *ret;
char *arg;
char *username;
+ char *servicehome;
+ char *baseservicehome;
+ char *slash;
+ char *hostkeyfile;
+ char *temp_file_name;
+ struct GNUNET_DISK_FileHandle *fn;
ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
}
else
ret->ssh_port_str = NULL;
- ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
+
+ /* Find service home and base service home directories, create it if it doesn't exist */
+ GNUNET_assert(GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "PATHS",
+ "SERVICEHOME",
+ &servicehome));
+
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome));
+ GNUNET_asprintf(&temp_file_name, "%s/gnunet-testing-config", servicehome);
+ ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name);
+ GNUNET_free(temp_file_name);
#if DEBUG_TESTING
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Setting up peer with configuration file `%s'.\n",
GNUNET_CONFIGURATION_set_value_string (ret->cfg,
"PATHS",
"DEFAULTCONFIG", ret->cfgfile);
- /* 1) write configuration to temporary file */
+
+ /* Write hostkey to file, if we were given one */
+ hostkeyfile = NULL;
+ if (hostkey != NULL)
+ {
+ GNUNET_asprintf(&hostkeyfile, "%s/.hostkey", servicehome);
+ fn =
+ GNUNET_DISK_file_open (hostkeyfile,
+ GNUNET_DISK_OPEN_READWRITE
+ | GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_assert(fn != NULL);
+ GNUNET_assert(HOSTKEYFILESIZE == GNUNET_DISK_file_write(fn, hostkey, HOSTKEYFILESIZE));
+ GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fn));
+ }
+
+ /* write configuration to temporary file */
if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
{
if (0 != UNLINK (ret->cfgfile))
}
ret->username = username;
- /* 2) copy file to remote host */
+ /* copy directory 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 directory to host `%s'.\n", hostname);
#endif
+ baseservicehome = GNUNET_strdup(servicehome);
+ /* Remove trailing /'s */
+ while (baseservicehome[strlen(baseservicehome) - 1] == '/')
+ baseservicehome[strlen(baseservicehome) - 1] = '\0';
+ /* Find next directory /, jump one ahead */
+ slash = strrchr(baseservicehome, '/');
+ if (slash != NULL)
+ *(++slash) = '\0';
+
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, baseservicehome);
else
- GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
+ GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome);
if (ret->ssh_port_str == NULL)
{
- ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
+ ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r",
#if !DEBUG_TESTING
"-q",
#endif
- ret->cfgfile, arg, NULL);
+ servicehome, arg, NULL);
+#if DEBUG_TESTING
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "copying directory with command scp -r %s %s\n", servicehome, arg);
+#endif
}
else
{
ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp",
- "scp", "-P", ret->ssh_port_str,
+ "scp", "-r", "-P", ret->ssh_port_str,
#if !DEBUG_TESTING
"-q",
#endif
- ret->cfgfile, arg, NULL);
+ servicehome, arg, NULL);
}
GNUNET_free (arg);
if (NULL == ret->proc)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
- ("Could not start `%s' process to copy configuration file.\n"),
+ ("Could not start `%s' process to copy configuration directory.\n"),
"scp");
if (0 != UNLINK (ret->cfgfile))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
GNUNET_free_non_null (ret->username);
GNUNET_free (ret->cfgfile);
GNUNET_free (ret);
+ if ((hostkey != NULL) && (0 != UNLINK(hostkeyfile)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink", hostkeyfile);
+ GNUNET_free_non_null(hostkeyfile);
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome));
+ GNUNET_free(servicehome);
return NULL;
}
ret->task
= GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm, ret);
+ GNUNET_free_non_null(hostkeyfile);
+ GNUNET_free(servicehome);
return ret;
}
#if DEBUG_TESTING
GNUNET_SCHEDULER_add_continuation (&start_fsm,
ret,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_free_non_null(hostkeyfile);
+ GNUNET_free(servicehome);
return ret;
}
* Task called once a core connect request has been transmitted.
*
* @param cls struct ConnectContext
- * @param tc context information (why was this task triggered now)
+ * @param success was the request successful?
*/
void
core_connect_request_cont (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ int success)
{
struct ConnectContext *ctx = cls;
- if (tc->reason == GNUNET_SCHEDULER_REASON_PREREQ_DONE)
- ctx->connect_request_handle = NULL;
- return;
+ ctx->connect_request_handle = NULL;
}
static void