From 86559fb594b8a9c9c99575d4915caa4937b14311 Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Mon, 14 Mar 2011 18:30:08 +0000 Subject: [PATCH] code not to be used by anyone, ever --- src/include/gnunet_testing_lib.h | 3 + src/testing/test_testing.c | 2 +- src/testing/test_testing_connect.c | 4 +- src/testing/test_testing_reconnect.c | 6 +- src/testing/testing.c | 189 ++++++++++++------- src/testing/testing_group.c | 262 +++++++++++++++++++-------- 6 files changed, 319 insertions(+), 147 deletions(-) diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index 0de51af78..f08dd9d20 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h @@ -418,6 +418,8 @@ typedef void (*GNUNET_TESTING_NotifyTopology)(void *cls, * * @param cfg configuration to use * @param timeout how long to wait starting up peers + * @param pretend GNUNET_YES to set up files but not start peer GNUNET_NO + * to really start the peer (default) * @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 @@ -434,6 +436,7 @@ typedef void (*GNUNET_TESTING_NotifyTopology)(void *cls, struct GNUNET_TESTING_Daemon * GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TIME_Relative timeout, + int pretend, const char *hostname, const char *ssh_username, uint16_t sshport, diff --git a/src/testing/test_testing.c b/src/testing/test_testing.c index 30ad9b13d..7045ee6b1 100644 --- a/src/testing/test_testing.c +++ b/src/testing/test_testing.c @@ -86,7 +86,7 @@ run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); #endif d = - GNUNET_TESTING_daemon_start (cfg, TIMEOUT, NULL, NULL, 0, NULL, NULL, NULL, + GNUNET_TESTING_daemon_start (cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, &my_cb, NULL); GNUNET_assert (d != NULL); } diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c index 6c6507737..631b224f5 100644 --- a/src/testing/test_testing_connect.c +++ b/src/testing/test_testing_connect.c @@ -134,7 +134,7 @@ my_cb1 (void *cls, "Daemon `%s' started.\n", GNUNET_i2s (id)); #endif d2 = - GNUNET_TESTING_daemon_start (c2, TIMEOUT, NULL, NULL, 0, NULL, NULL, NULL, + GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, &my_cb2, NULL); GNUNET_assert (d2 != NULL); @@ -155,7 +155,7 @@ run (void *cls, c2 = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf"); d1 = - GNUNET_TESTING_daemon_start (c1, TIMEOUT, NULL, NULL, 0, NULL, NULL, NULL, + GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, &my_cb1, NULL); GNUNET_assert (d1 != NULL); } diff --git a/src/testing/test_testing_reconnect.c b/src/testing/test_testing_reconnect.c index 46b7934f1..7cec78f98 100644 --- a/src/testing/test_testing_reconnect.c +++ b/src/testing/test_testing_reconnect.c @@ -24,7 +24,7 @@ #include "platform.h" #include "gnunet_testing_lib.h" -#define VERBOSE GNUNET_NO +#define VERBOSE GNUNET_YES /** * How long until we give up on connecting the peers? @@ -164,7 +164,7 @@ my_cb1 (void *cls, "Daemon `%s' started.\n", GNUNET_i2s (id)); #endif d2 = - GNUNET_TESTING_daemon_start (c2, TIMEOUT, NULL, NULL, 0, NULL, NULL, NULL, + GNUNET_TESTING_daemon_start (c2, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, &my_cb2, NULL); GNUNET_assert (d2 != NULL); } @@ -191,7 +191,7 @@ run_phase () { phase++; d1 = - GNUNET_TESTING_daemon_start (c1, TIMEOUT, NULL, NULL, 0, NULL, NULL, NULL, + GNUNET_TESTING_daemon_start (c1, TIMEOUT, GNUNET_NO, NULL, NULL, 0, NULL, NULL, NULL, &my_cb1, NULL); GNUNET_assert (d1 != NULL); } diff --git a/src/testing/testing.c b/src/testing/testing.c index 1bd88ddc0..024be6ff5 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -72,7 +72,7 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) if (daemon == NULL) return; - GNUNET_assert (daemon->phase == SP_GET_HELLO); + GNUNET_assert (daemon->phase == SP_GET_HELLO || daemon->phase == SP_START_DONE); cb = daemon->cb; daemon->cb = NULL; @@ -514,7 +514,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d); break; - case SP_TOPOLOGY_SETUP: + case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */ /* start GNUnet on remote host */ if (NULL == d->hostname) { @@ -950,6 +950,8 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, * * @param cfg configuration to use * @param timeout how long to wait starting up peers + * @param pretend GNUNET_YES to set up files but not start peer GNUNET_NO + * to really start the peer (default) * @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 @@ -966,6 +968,7 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, struct GNUNET_TESTING_Daemon * GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TIME_Relative timeout, + int pretend, const char *hostname, const char *ssh_username, uint16_t sshport, @@ -1084,88 +1087,91 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, } ret->username = username; - /* copy directory to remote host */ - if (NULL != hostname) + if (GNUNET_NO == pretend) /* Copy files, enter finite state machine */ { + /* copy directory to remote host */ + if (NULL != hostname) + { #if DEBUG_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Copying configuration directory to host `%s'.\n", hostname); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "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, baseservicehome); - else - GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome); + 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, baseservicehome); + else + GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome); - if (ret->ssh_port_str == NULL) - { - ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", + if (ret->ssh_port_str == NULL) + { + ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", #if !DEBUG_TESTING - "-q", + "-q", #endif - servicehome, 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); + 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", "-r", "-P", ret->ssh_port_str, -#if !DEBUG_TESTING - "-q", -#endif - servicehome, arg, NULL); - } - GNUNET_free (arg); - if (NULL == ret->proc) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ - ("Could not start `%s' process to copy configuration directory.\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); - if ((hostkey != NULL) && (0 != UNLINK(hostkeyfile))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "unlink", hostkeyfile); + } + else + { + ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", + "scp", "-r", "-P", ret->ssh_port_str, + #if !DEBUG_TESTING + "-q", + #endif + servicehome, arg, NULL); + } + GNUNET_free (arg); + if (NULL == ret->proc) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ + ("Could not start `%s' process to copy configuration directory.\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); + 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_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome)); + GNUNET_free(baseservicehome); GNUNET_free(servicehome); - return NULL; + return ret; } - - ret->task - = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, - &start_fsm, ret); - GNUNET_free_non_null(hostkeyfile); - GNUNET_free(baseservicehome); - GNUNET_free(servicehome); - return ret; - } #if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No need to copy configuration file since we are running locally.\n"); #endif - ret->phase = SP_COPIED; - GNUNET_SCHEDULER_add_continuation (&start_fsm, - ret, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); + ret->phase = SP_COPIED; + GNUNET_SCHEDULER_add_continuation (&start_fsm, + ret, + GNUNET_SCHEDULER_REASON_PREREQ_DONE); + } GNUNET_free_non_null(hostkeyfile); GNUNET_free(servicehome); return ret; @@ -1867,6 +1873,36 @@ reattempt_daemons_connect (void *cls, return; } + /* Don't know reason for initial connect failure, update the HELLO for the second peer */ + if (NULL != ctx->d2->hello) + { + GNUNET_free(ctx->d2->hello); + ctx->d2->hello = NULL; + if (NULL != ctx->d2->th) + { + GNUNET_TRANSPORT_get_hello_cancel(ctx->d2->th, &process_hello, ctx->d2); + GNUNET_TRANSPORT_disconnect(ctx->d2->th); + } + ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); + GNUNET_assert(ctx->d2->th != NULL); + GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); + } + + if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) + { + ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); + if (ctx->d2->th == NULL) + { + GNUNET_CORE_disconnect (ctx->d1core); + GNUNET_free (ctx); + if (NULL != ctx->cb) + ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, + _("Failed to connect to transport service!\n")); + return; + } + GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); + } + if (ctx->send_hello == GNUNET_YES) { ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, @@ -1955,6 +1991,21 @@ core_initial_iteration (void *cls, return; } + if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet have the second peer's hello, set up a task to get it */ + { + ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); + if (ctx->d2->th == NULL) + { + GNUNET_CORE_disconnect (ctx->d1core); + GNUNET_free (ctx); + if (NULL != ctx->cb) + ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, + _("Failed to connect to transport service!\n")); + return; + } + GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); + } + if (ctx->send_hello == GNUNET_YES) { ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 14bf31bbc..083e67750 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -36,8 +36,11 @@ #define DEBUG_CHURN GNUNET_NO +#define USE_START_HELPER GNUNET_YES + #define OLD 1 +/* Before connecting peers, send all of the HELLOs */ #define USE_SEND_HELLOS GNUNET_NO #define TOPOLOGY_HACK GNUNET_YES @@ -3474,12 +3477,9 @@ static void schedule_send_hellos (void *cls, const struct GNUNET_SCHEDULER_TaskC if (send_hello_context->peer->daemon->th == NULL) { pg->outstanding_connects++; /* Actual TRANSPORT, CORE connections! */ - send_hello_context->peer->daemon->th = GNUNET_TRANSPORT_connect(send_hello_context->peer->cfg, - NULL, - send_hello_context, - NULL, - NULL, - NULL); + send_hello_context->peer->daemon->th + = GNUNET_TRANSPORT_connect (send_hello_context->peer->cfg, NULL, + send_hello_context, NULL, NULL, NULL); } #if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -3606,7 +3606,7 @@ schedule_connect(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) connect_context->ct_ctx->connect_timeout, connect_context->ct_ctx->connect_attempts, #if USE_SEND_HELLOS - GNUNET_NO, + GNUNET_NO, #else GNUNET_YES, #endif @@ -3741,7 +3741,7 @@ connect_topology(struct GNUNET_TESTING_PeerGroup *pg, struct PeerConnection *connection_iter; #endif #if USE_SEND_HELLOS - struct SendHelloContext *send_hello_context + struct SendHelloContext *send_hello_context; #endif total = 0; @@ -5532,6 +5532,7 @@ schedule_churn_restart(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } } + static void internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -5556,6 +5557,7 @@ internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) internal_context->peer->daemon = GNUNET_TESTING_daemon_start (internal_context->peer->cfg, internal_context->timeout, + GNUNET_NO, internal_context->hostname, internal_context->username, internal_context->sshport, @@ -5574,6 +5576,66 @@ internal_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) &internal_start, internal_context); } } +#if USE_START_HELPER + +struct PeerStartHelperContext +{ + struct GNUNET_TESTING_PeerGroup *pg; + + struct HostData *host; +}; + +static void +start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct PeerStartHelperContext *helper = cls; + char *baseservicehome; + char *tempdir; + struct GNUNET_OS_Process *proc; + unsigned int i; + char *arg; + GNUNET_TESTING_NotifyDaemonRunning cb; + /* ssh user@host peerStartHelper /path/to/basedirectory */ + + GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (helper->pg->cfg, "PATHS", "SERVICEHOME", + &baseservicehome)); + GNUNET_asprintf(&tempdir, "%s/%s/", baseservicehome, helper->host->hostname); + if (NULL != helper->host->username) + GNUNET_asprintf (&arg, "%s@%s", helper->host->username, helper->host->hostname); + else + GNUNET_asprintf (&arg, "%s", helper->host->hostname); + + /* FIXME: Doesn't support ssh_port option! */ + proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, + "peerStartHelper.pl", tempdir, NULL); + + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "starting peers with cmd ssh %s %s %s\n", arg, "peerStartHelper.pl", tempdir); + + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close(proc); + GNUNET_free (tempdir); + GNUNET_free (baseservicehome); + GNUNET_free (arg); + + helper->pg->starting--; + if (helper->pg->starting == 0) /* All peers have finished starting! */ + { + /* Call the peer started callback for each peer, set proper FSM state (?) */ + for (i = 0; i < helper->pg->total; i++) + { + cb = helper->pg->peers[i].daemon->cb; + helper->pg->peers[i].daemon->cb = NULL; + if (NULL != cb) + cb (helper->pg->peers[i].daemon->cb_cls, + &helper->pg->peers[i].daemon->id, + helper->pg->peers[i].daemon->cfg, helper->pg->peers[i].daemon, + NULL); + + } + } + +} +#endif /** * Function which continues a peer group starting up @@ -5587,14 +5649,57 @@ GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg) { unsigned int i; +#if USE_START_HELPER + if ((pg->num_hosts > 0) && (pg->hostkey_data != NULL)) + { + struct PeerStartHelperContext *helper; + pg->starting = pg->num_hosts; + for (i = 0; i < pg->num_hosts; i++) + { + helper = GNUNET_malloc(sizeof(struct PeerStartHelperContext)); + helper->pg = pg; + helper->host = &pg->hosts[i]; + GNUNET_SCHEDULER_add_now(&start_peer_helper, helper); + } + } + else + { + pg->starting = 0; + for (i = 0; i < pg->total; i++) + { + GNUNET_SCHEDULER_add_now (&internal_continue_startup, + &pg->peers[i].internal_context); + } + } +#else pg->starting = 0; for (i = 0; i < pg->total; i++) { GNUNET_SCHEDULER_add_now (&internal_continue_startup, &pg->peers[i].internal_context); - //GNUNET_TESTING_daemon_continue_startup(pg->peers[i].daemon); } +#endif +} + +#if USE_START_HELPER +static void +call_hostkey_callbacks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_TESTING_PeerGroup *pg = cls; + unsigned int i; + for (i = 0; i < pg->total; i++) + { + if (pg->peers[i].internal_context.hostkey_callback != NULL) + pg->peers[i].internal_context.hostkey_callback (pg->peers[i].internal_context.hostkey_cls, + &pg->peers[i].daemon->id, + pg->peers[i].daemon, + NULL); + } + + if (pg->peers[0].internal_context.hostkey_callback == NULL) + GNUNET_TESTING_daemons_continue_startup (pg); } +#endif /** * Start count gnunet instances with the same set of transports and @@ -5624,8 +5729,7 @@ GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg) * @return NULL on error, otherwise handle to control peer group */ struct GNUNET_TESTING_PeerGroup * -GNUNET_TESTING_daemons_start( - const struct GNUNET_CONFIGURATION_Handle *cfg, +GNUNET_TESTING_daemons_start(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int total, unsigned int max_concurrent_connections, unsigned int max_concurrent_ssh, @@ -5640,11 +5744,6 @@ GNUNET_TESTING_daemons_start( { struct GNUNET_TESTING_PeerGroup *pg; const struct GNUNET_TESTING_Host *hostpos; -#if 0 - char *pos; - const char *rpos; - char *start; -#endif const char *hostname; const char *username; char *baseservicehome; @@ -5715,51 +5814,6 @@ GNUNET_TESTING_daemons_start( hostcnt = off; minport = 0; pg->num_hosts = off; - -#if NO_LL - off = 2; - /* skip leading spaces */ - while ((0 != *hostnames) && (isspace ((unsigned char) *hostnames))) - hostnames++; - rpos = hostnames; - while ('\0' != *rpos) - { - if (isspace ((unsigned char) *rpos)) - off++; - rpos++; - } - pg->hosts = GNUNET_malloc (off * sizeof (struct HostData)); - off = 0; - start = GNUNET_strdup (hostnames); - pos = start; - while ('\0' != *pos) - { - if (isspace ((unsigned char) *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; - } - hostcnt = off; - minport = 0; /* make gcc happy */ -#endif } else { @@ -5885,7 +5939,9 @@ GNUNET_TESTING_daemons_start( GNUNET_asprintf (&newservicehome, "%s/%s/%d/", baseservicehome, hostname, off); else GNUNET_asprintf (&newservicehome, "%s/%d/", baseservicehome, off); +#if !USE_START_HELPER GNUNET_free (baseservicehome); +#endif } else { @@ -5902,16 +5958,6 @@ GNUNET_TESTING_daemons_start( newservicehome); GNUNET_free (newservicehome); pg->peers[off].cfg = pcfg; -#if DEFER - /* Can we do this later? */ - pg->peers[off].allowed_peers = - GNUNET_CONTAINER_multihashmap_create (total); - pg->peers[off].connect_peers = - GNUNET_CONTAINER_multihashmap_create (total); - pg->peers[off].blacklisted_peers = - GNUNET_CONTAINER_multihashmap_create (total); - -#endif pg->peers[off].pg = pg; pg->peers[off].internal_context.peer = &pg->peers[off]; pg->peers[off].internal_context.timeout = timeout; @@ -5925,11 +5971,83 @@ GNUNET_TESTING_daemons_start( pg->peers[off].internal_context.hostkey_cls = hostkey_cls; pg->peers[off].internal_context.start_cb = cb; pg->peers[off].internal_context.start_cb_cls = cb_cls; - +#if !USE_START_HELPER GNUNET_SCHEDULER_add_now (&internal_start, &pg->peers[off].internal_context); +#else + if ((pg->hostkey_data != NULL) && (hostcnt > 0)) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Have hostkey data and running on remote hosts!\n"); + GNUNET_TESTING_daemon_start (pcfg, + timeout, + GNUNET_YES, + hostname, + username, + sshport, + pg->peers[off].internal_context.hostkey, + &internal_hostkey_callback, + &pg->peers[off].internal_context, + &internal_startup_callback, + &pg->peers[off].internal_context); + /** + * At this point, given that we had a hostkeyfile, + * we can call the hostkey callback! + * But first, we should copy (rsync) all of the configs + * and hostkeys to the remote peers. Then let topology + * creation happen, then call the peer start helper processes, + * then set pg->whatever_phase for each peer and let them + * enter the fsm to get the HELLO's for peers and start connecting. + */ + } + else + { + GNUNET_SCHEDULER_add_now (&internal_start, + &pg->peers[off].internal_context); + } + +#endif + } + +#if USE_START_HELPER /* Now the peergroup has been set up, hostkeys and configs written to files. */ + if ((pg->hostkey_data != NULL) && (hostcnt > 0)) + { + for (off = 0; off < hostcnt; off++) + { + GNUNET_asprintf(&newservicehome, "%s/%s/", baseservicehome, pg->hosts[off].hostname); + + if (NULL != username) + GNUNET_asprintf (&arg, "%s@%s:%s", username, pg->hosts[off].hostname, newservicehome); + else + GNUNET_asprintf (&arg, "%s:%s", pg->hosts[off].hostname, newservicehome); + + /* FIXME: Doesn't support ssh_port option! */ + proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", +#if !DEBUG_TESTING + "-q", +#endif + newservicehome, arg, NULL); + + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "copying directory with command scp -r %s %s\n", newservicehome, arg); + + GNUNET_free (arg); + if (NULL == proc) + { + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + _ + ("Could not start `%s' process to copy configuration directory.\n"), + "scp"); + GNUNET_assert(0); + } + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + } + /* Now all the configuration files and hostkeys are copied to the remote host. Call the hostkey callback for each peer! */ + GNUNET_SCHEDULER_add_now(&call_hostkey_callbacks, pg); } + GNUNET_free (baseservicehome); +#endif return pg; } -- 2.25.1