2 This file is part of GNUnet
3 (C) 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testing/testing.c
23 * @brief convenience API for writing testcases for GNUnet
24 * Many testcases need to start and stop gnunetd,
25 * and this library is supposed to make that easier
26 * for TESTCASES. Normal programs should always
27 * use functions from gnunet_{util,arm}_lib.h. This API is
28 * ONLY for writing testcases!
29 * @author Christian Grothoff
33 #include "gnunet_arm_service.h"
34 #include "gnunet_core_service.h"
35 #include "gnunet_constants.h"
36 #include "gnunet_testing_lib.h"
37 #include "gnunet_transport_service.h"
38 #include "gnunet_hello_lib.h"
40 #define DEBUG_TESTING GNUNET_NO
42 #define DEBUG_TESTING_RECONNECT GNUNET_NO
44 #define WAIT_FOR_HELLO GNUNET_NO
47 * Hack to deal with initial HELLO's being often devoid of addresses.
48 * This hack causes 'process_hello' to ignore HELLOs without addresses.
49 * The correct implementation would continue with 'process_hello' until
50 * the connection could be established...
52 #define EMPTY_HACK GNUNET_YES
55 * How long do we wait after starting gnunet-service-arm
56 * for the core service to be alive?
58 #define ARM_START_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
61 * How many times are we willing to try to wait for "scp" or
62 * "gnunet-service-arm" to complete (waitpid) before giving up?
64 #define MAX_EXEC_WAIT_RUNS 250
66 static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
70 test_address (void *cls,
72 struct GNUNET_TIME_Absolute expiration,
73 const void *addr, uint16_t addrlen)
83 * Receive the HELLO from one peer, give it to the other
84 * and ask them to connect.
86 * @param cls "struct ConnectContext"
87 * @param message HELLO message of peer
90 process_hello (void *cls, const struct GNUNET_MessageHeader *message)
92 struct GNUNET_TESTING_Daemon *daemon = cls;
96 GNUNET_TESTING_NotifyDaemonRunning cb;
102 GNUNET_assert (message != NULL);
103 GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *) message,
104 GNUNET_NO, &test_address, &empty);
105 if (GNUNET_YES == empty)
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping empty HELLO address\n");
116 GNUNET_assert (daemon->phase == SP_GET_HELLO ||
117 daemon->phase == SP_START_DONE);
122 if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */
123 GNUNET_SCHEDULER_cancel (daemon->task);
125 if (daemon->server != NULL)
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
129 "Received `%s' from transport service of `%4s', disconnecting core!\n",
130 "HELLO", GNUNET_i2s (&daemon->id));
132 GNUNET_CORE_disconnect (daemon->server);
133 daemon->server = NULL;
136 msize = ntohs (message->size);
141 if (daemon->th != NULL)
143 GNUNET_TRANSPORT_get_hello_cancel (daemon->th, &process_hello, daemon);
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Received `%s' from transport service of `%4s'\n",
148 "HELLO", GNUNET_i2s (&daemon->id));
151 GNUNET_free_non_null (daemon->hello);
152 daemon->hello = GNUNET_malloc (msize);
153 memcpy (daemon->hello, message, msize);
155 if (daemon->th != NULL)
157 GNUNET_TRANSPORT_disconnect (daemon->th);
160 daemon->phase = SP_START_DONE;
163 if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */
164 cb (daemon->cb_cls, &daemon->id, daemon->cfg, daemon, NULL);
169 start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
173 * Function called after GNUNET_CORE_connect has succeeded
174 * (or failed for good). Note that the private key of the
175 * peer is intentionally not exposed here; if you need it,
176 * your process should try to read the private key file
177 * directly (which should work if you are authorized...).
180 * @param server handle to the server, NULL if we failed
181 * @param my_identity ID of this peer, NULL if we failed
182 * @param publicKey public key of this peer, NULL if we failed
185 testing_init (void *cls,
186 struct GNUNET_CORE_Handle *server,
187 const struct GNUNET_PeerIdentity *my_identity,
188 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
190 struct GNUNET_TESTING_Daemon *d = cls;
192 GNUNET_assert (d->phase == SP_START_CORE);
193 d->phase = SP_GET_HELLO;
198 if (GNUNET_YES == d->dead)
199 GNUNET_TESTING_daemon_stop (d,
200 GNUNET_TIME_absolute_get_remaining
201 (d->max_timeout), d->dead_cb,
202 d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
203 else if (NULL != d->cb)
204 d->cb (d->cb_cls, NULL, d->cfg, d,
205 _("Failed to connect to core service\n"));
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity));
212 d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */
213 if (d->shortname == NULL)
214 d->shortname = strdup (GNUNET_i2s (my_identity));
216 d->running = GNUNET_YES;
218 if (GNUNET_NO == d->running)
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "Peer is dead (d->running == GNUNET_NO)\n");
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Successfully started peer `%4s', connecting to transport service.\n",
229 GNUNET_i2s (my_identity));
232 d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
235 if (GNUNET_YES == d->dead)
236 GNUNET_TESTING_daemon_stop (d,
237 GNUNET_TIME_absolute_get_remaining
238 (d->max_timeout), d->dead_cb,
239 d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
240 else if (NULL != d->cb)
241 d->cb (d->cb_cls, &d->id, d->cfg, d,
242 _("Failed to connect to transport service!\n"));
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "Connected to transport service `%s', getting HELLO\n",
248 GNUNET_i2s (my_identity));
251 GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
253 if (d->task != GNUNET_SCHEDULER_NO_TASK)
254 GNUNET_SCHEDULER_cancel (d->task);
256 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
263 * Notify of a peer being up and running. Scheduled as a task
264 * so that variables which may need to be set are set before
265 * the connect callback can set up new operations.
267 * @param cls the testing daemon
268 * @param tc task scheduler context
271 notify_daemon_started (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
273 struct GNUNET_TESTING_Daemon *d = cls;
274 GNUNET_TESTING_NotifyDaemonRunning cb;
279 cb (d->cb_cls, &d->id, d->cfg, d, NULL);
284 * Finite-state machine for starting GNUnet.
286 * @param cls our "struct GNUNET_TESTING_Daemon"
290 start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
292 struct GNUNET_TESTING_Daemon *d = cls;
293 GNUNET_TESTING_NotifyDaemonRunning cb;
294 enum GNUNET_OS_ProcessStatusType type;
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer FSM is in phase %u.\n", d->phase);
303 d->task = GNUNET_SCHEDULER_NO_TASK;
307 /* confirm copying complete */
308 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
310 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
319 ("`scp' does not seem to terminate (timeout copying config).\n"));
324 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
328 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
333 cb (d->cb_cls, NULL, d->cfg, d, _("`scp' did not complete cleanly.\n"));
336 GNUNET_OS_process_close (d->proc);
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
339 "Successfully copied configuration file.\n");
341 d->phase = SP_COPIED;
344 /* Start create hostkey process if we don't already know the peer identity! */
345 if (GNUNET_NO == d->have_hostkey)
347 d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES);
348 if (d->pipe_stdout == NULL)
357 (NULL == d->hostname)
358 ? _("Failed to create pipe for `gnunet-peerinfo' process.\n")
359 : _("Failed to create pipe for `ssh' process.\n"));
362 if (NULL == d->hostname)
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
366 "Starting `%s', with command `%s %s %s %s'.\n",
367 "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile,
371 GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo",
372 "gnunet-peerinfo", "-c", d->cfgfile,
374 GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
378 if (d->username != NULL)
379 GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
381 dst = GNUNET_strdup (d->hostname);
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
385 "Starting `%s', with command `%s %s %s %s %s %s'.\n",
386 "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c",
389 if (d->ssh_port_str == NULL)
391 d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", "ssh",
397 "-c", d->cfgfile, "-sq", NULL);
401 d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
402 "ssh", "-p", d->ssh_port_str,
408 "-c", d->cfgfile, "-sq", NULL);
410 GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
415 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
416 _("Could not start `%s' process to create hostkey.\n"),
417 (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh");
425 (NULL == d->hostname)
426 ? _("Failed to start `gnunet-peerinfo' process.\n")
427 : _("Failed to start `ssh' process.\n"));
428 GNUNET_DISK_pipe_close (d->pipe_stdout);
432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
433 "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo");
435 d->phase = SP_HOSTKEY_CREATE;
438 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
440 GNUNET_DISK_pipe_handle
442 GNUNET_DISK_PIPE_END_READ),
445 else /* Already have a hostkey! */
447 if (d->hostkey_callback != NULL)
449 d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL);
450 d->hostkey_callback = NULL;
451 d->phase = SP_HOSTKEY_CREATED;
454 d->phase = SP_TOPOLOGY_SETUP;
457 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
460 case SP_HOSTKEY_CREATE:
462 GNUNET_DISK_file_read (GNUNET_DISK_pipe_handle
463 (d->pipe_stdout, GNUNET_DISK_PIPE_END_READ),
464 &d->hostkeybuf[d->hostkeybufpos],
465 sizeof (d->hostkeybuf) - d->hostkeybufpos);
467 d->hostkeybufpos += bytes_read;
469 if ((d->hostkeybufpos < 104) && (bytes_read > 0))
474 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
476 GNUNET_DISK_pipe_handle
478 GNUNET_DISK_PIPE_END_READ),
482 d->hostkeybuf[103] = '\0';
484 if ((bytes_read < 0) ||
485 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf,
490 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
491 _("Error reading from gnunet-peerinfo: %s\n"),
494 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
495 _("Malformed output from gnunet-peerinfo!\n"));
498 GNUNET_DISK_pipe_close (d->pipe_stdout);
499 d->pipe_stdout = NULL;
500 (void) GNUNET_OS_process_kill (d->proc, SIGKILL);
501 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc));
502 GNUNET_OS_process_close (d->proc);
505 cb (d->cb_cls, NULL, d->cfg, d, _("`Failed to get hostkey!\n"));
508 d->shortname = GNUNET_strdup (GNUNET_i2s (&d->id));
509 GNUNET_DISK_pipe_close (d->pipe_stdout);
510 d->pipe_stdout = NULL;
511 (void) GNUNET_OS_process_kill (d->proc, SIGKILL);
512 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc));
513 GNUNET_OS_process_close (d->proc);
515 d->have_hostkey = GNUNET_YES;
516 if (d->hostkey_callback != NULL)
518 d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL);
519 d->hostkey_callback = NULL;
520 d->phase = SP_HOSTKEY_CREATED;
524 d->phase = SP_TOPOLOGY_SETUP;
527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n");
530 case SP_HOSTKEY_CREATED:
531 /* wait for topology finished */
532 if ((GNUNET_YES == d->dead)
533 || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0))
539 NULL, d->cfg, d, _("`Failed while waiting for topology setup!\n"));
544 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
547 case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */
548 /* start GNUnet on remote host */
549 if (NULL == d->hostname)
552 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
553 "Starting `%s', with command `%s %s %s %s %s %s'.\n",
554 "gnunet-arm", "gnunet-arm", "-c", d->cfgfile,
555 "-L", "DEBUG", "-s");
557 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
558 "gnunet-arm", "-c", d->cfgfile,
563 GNUNET_TIME_relative_to_string
564 (GNUNET_TIME_absolute_get_remaining
565 (d->max_timeout)), NULL);
569 if (d->username != NULL)
570 GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
572 dst = GNUNET_strdup (d->hostname);
575 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
576 "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n",
577 "gnunet-arm", "ssh", dst, "gnunet-arm", "-c",
578 d->cfgfile, "-L", "DEBUG", "-s", "-q");
580 if (d->ssh_port_str == NULL)
582 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
590 "-c", d->cfgfile, "-s", "-q",
592 GNUNET_TIME_relative_to_string
593 (GNUNET_TIME_absolute_get_remaining
594 (d->max_timeout)), NULL);
599 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh",
600 "ssh", "-p", d->ssh_port_str,
608 "-c", d->cfgfile, "-s", "-q",
610 GNUNET_TIME_relative_to_string
611 (GNUNET_TIME_absolute_get_remaining
612 (d->max_timeout)), NULL);
618 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
619 _("Could not start `%s' process to start GNUnet.\n"),
620 (NULL == d->hostname) ? "gnunet-arm" : "ssh");
628 (NULL == d->hostname)
629 ? _("Failed to start `gnunet-arm' process.\n")
630 : _("Failed to start `ssh' process.\n"));
634 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
635 "Started `%s', waiting for `%s' to be up.\n",
636 "gnunet-arm", "gnunet-service-core");
638 d->phase = SP_START_ARMING;
640 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
643 case SP_START_ARMING:
644 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
646 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
655 (NULL == d->hostname)
656 ? _("`gnunet-arm' does not seem to terminate.\n")
657 : _("`ssh' does not seem to terminate.\n"));
658 GNUNET_CONFIGURATION_destroy (d->cfg);
659 GNUNET_free (d->cfgfile);
660 GNUNET_free_non_null (d->hostname);
661 GNUNET_free_non_null (d->username);
662 GNUNET_free (d->proc);
668 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
673 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
674 "Successfully started `%s'.\n", "gnunet-arm");
676 GNUNET_free (d->proc);
677 d->phase = SP_START_CORE;
679 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Calling CORE_connect\n");
683 if (d->server != NULL)
684 GNUNET_CORE_disconnect (d->server);
687 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
694 d->cfg, d, _("Unable to connect to CORE service for peer!\n"));
695 GNUNET_CONFIGURATION_destroy (d->cfg);
696 GNUNET_free (d->cfgfile);
697 GNUNET_free_non_null (d->hostname);
698 GNUNET_free_non_null (d->username);
702 d->server = GNUNET_CORE_connect (d->cfg, 1,
707 NULL, GNUNET_NO, no_handlers);
710 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
711 (GNUNET_CONSTANTS_SERVICE_RETRY, 2),
714 d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
717 if (GNUNET_YES == d->dead)
718 GNUNET_TESTING_daemon_stop (d,
719 GNUNET_TIME_absolute_get_remaining
720 (d->max_timeout), d->dead_cb,
721 d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
722 else if (NULL != d->cb)
723 d->cb (d->cb_cls, &d->id, d->cfg, d,
724 _("Failed to connect to transport service!\n"));
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
729 "Connected to transport service `%s', getting HELLO\n",
730 GNUNET_i2s (&d->id));
733 GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
734 GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d);
738 * cb (d->cb_cls, &d->id, d->cfg, d, NULL); */
739 d->running = GNUNET_YES;
740 d->phase = SP_GET_HELLO;
744 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
746 if (d->server != NULL)
747 GNUNET_CORE_disconnect (d->server);
749 GNUNET_TRANSPORT_disconnect (d->th);
753 cb (d->cb_cls, NULL, d->cfg, d, _("Unable to get HELLO for peer!\n"));
754 GNUNET_CONFIGURATION_destroy (d->cfg);
755 GNUNET_free (d->cfgfile);
756 GNUNET_free_non_null (d->hostname);
757 GNUNET_free_non_null (d->username);
761 if (d->hello != NULL)
763 GNUNET_assert (d->task == GNUNET_SCHEDULER_NO_TASK);
766 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
767 (GNUNET_CONSTANTS_SERVICE_RETRY, 2),
773 case SP_SERVICE_START:
774 /* confirm gnunet-arm exited */
775 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
777 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
786 (NULL == d->hostname)
787 ? _("`gnunet-arm' does not seem to terminate.\n")
788 : _("`ssh' does not seem to terminate.\n"));
793 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
798 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
807 (NULL == d->hostname)
810 ("`gnunet-arm' terminated with non-zero exit status (or timed out)!\n")
811 : _("`ssh' does not seem to terminate.\n"));
816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n");
820 d->phase = SP_START_DONE;
822 cb (d->cb_cls, &d->id, d->cfg, d, NULL);
824 case SP_SERVICE_SHUTDOWN_START:
825 /* confirm copying complete */
826 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
828 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
830 if (NULL != d->dead_cb)
831 d->dead_cb (d->dead_cb_cls,
833 ("either `gnunet-arm' or `ssh' does not seem to terminate.\n"));
838 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
843 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
845 if (NULL != d->dead_cb)
846 d->dead_cb (d->dead_cb_cls,
848 ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n"));
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
855 if (NULL != d->dead_cb)
856 d->dead_cb (d->dead_cb_cls, NULL);
858 case SP_SHUTDOWN_START:
859 /* confirm copying complete */
860 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
862 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0)
864 if (NULL != d->dead_cb)
865 d->dead_cb (d->dead_cb_cls,
867 ("either `gnunet-arm' or `ssh' does not seem to terminate.\n"));
870 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
871 GNUNET_TRANSPORT_disconnect (d->th);
874 GNUNET_CONFIGURATION_destroy (d->cfg);
875 GNUNET_free (d->cfgfile);
876 GNUNET_free_non_null (d->hello);
877 GNUNET_free_non_null (d->hostname);
878 GNUNET_free_non_null (d->username);
879 GNUNET_free_non_null (d->shortname);
880 GNUNET_free_non_null (d->proc);
887 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
891 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
893 if (NULL != d->dead_cb)
894 d->dead_cb (d->dead_cb_cls,
896 ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n"));
899 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
900 GNUNET_TRANSPORT_disconnect (d->th);
903 if (d->server != NULL)
905 GNUNET_CORE_disconnect (d->server);
908 GNUNET_CONFIGURATION_destroy (d->cfg);
909 GNUNET_free (d->cfgfile);
910 GNUNET_free_non_null (d->hello);
911 GNUNET_free_non_null (d->hostname);
912 GNUNET_free_non_null (d->username);
913 GNUNET_free_non_null (d->shortname);
914 GNUNET_free_non_null (d->proc);
920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
922 if (d->server != NULL)
924 GNUNET_CORE_disconnect (d->server);
930 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
931 GNUNET_TRANSPORT_disconnect (d->th);
935 if (NULL != d->dead_cb)
936 d->dead_cb (d->dead_cb_cls, NULL);
938 /* state clean up and notifications */
939 if (d->churn == GNUNET_NO)
941 GNUNET_CONFIGURATION_destroy (d->cfg);
942 GNUNET_free (d->cfgfile);
943 GNUNET_free_non_null (d->hostname);
944 GNUNET_free_non_null (d->username);
947 GNUNET_free_non_null (d->hello);
949 GNUNET_free_non_null (d->shortname);
950 GNUNET_free_non_null (d->proc);
953 if (d->churn == GNUNET_NO)
957 case SP_CONFIG_UPDATE:
958 /* confirm copying complete */
959 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
961 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) /* FIXME: config update should take timeout parameter! */
967 NULL, d->cfg, d, _("`scp' does not seem to terminate.\n"));
972 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
976 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
978 if (NULL != d->update_cb)
979 d->update_cb (d->update_cb_cls, _("`scp' did not complete cleanly.\n"));
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
984 "Successfully copied configuration file.\n");
986 if (NULL != d->update_cb)
987 d->update_cb (d->update_cb_cls, NULL);
988 d->phase = SP_START_DONE;
994 * Continues GNUnet daemon startup when user wanted to be notified
995 * once a hostkey was generated (for creating friends files, blacklists,
998 * @param daemon the daemon to finish starting
1001 GNUNET_TESTING_daemon_continue_startup (struct GNUNET_TESTING_Daemon *daemon)
1003 GNUNET_assert (daemon->phase == SP_HOSTKEY_CREATED);
1004 daemon->phase = SP_TOPOLOGY_SETUP;
1008 * Check whether the given daemon is running.
1010 * @param daemon the daemon to check
1012 * @return GNUNET_YES if the daemon is up, GNUNET_NO if the
1013 * daemon is down, GNUNET_SYSERR on error.
1016 GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon)
1019 return GNUNET_SYSERR;
1021 if (daemon->running == GNUNET_YES)
1028 * Starts a GNUnet daemon service which has been previously stopped.
1030 * @param d the daemon for which the service should be started
1031 * @param service the name of the service to start
1032 * @param timeout how long to wait for process for shutdown to complete
1033 * @param cb function called once the service starts
1034 * @param cb_cls closure for cb
1037 GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d,
1039 struct GNUNET_TIME_Relative
1041 GNUNET_TESTING_NotifyDaemonRunning
1049 GNUNET_assert (d->running == GNUNET_YES);
1051 if (d->phase == SP_CONFIG_UPDATE)
1053 GNUNET_SCHEDULER_cancel (d->task);
1054 d->phase = SP_START_DONE;
1057 if (d->churned_services == NULL)
1059 d->cb (d->cb_cls, &d->id, d->cfg, d,
1060 "No service has been churned off yet!!");
1063 d->phase = SP_SERVICE_START;
1064 GNUNET_free (d->churned_services);
1065 d->churned_services = NULL;
1066 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1067 /* Check if this is a local or remote process */
1068 if (NULL != d->hostname)
1071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1072 "Starting gnunet-arm with config `%s' on host `%s'.\n",
1073 d->cfgfile, d->hostname);
1076 if (d->username != NULL)
1077 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1079 arg = GNUNET_strdup (d->hostname);
1081 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1089 "-c", d->cfgfile, "-i", service, "-q",
1091 GNUNET_TIME_relative_to_string (timeout),
1093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1094 "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n",
1095 arg, "gnunet-arm", d->cfgfile, service);
1101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1102 "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile);
1104 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
1108 "-c", d->cfgfile, "-i", service, "-q",
1110 GNUNET_TIME_relative_to_string (timeout),
1114 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1115 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
1119 * Starts a GNUnet daemon's service.
1121 * @param d the daemon for which the service should be started
1122 * @param service the name of the service to start
1123 * @param timeout how long to wait for process for startup
1124 * @param cb function called once gnunet-arm returns
1125 * @param cb_cls closure for cb
1128 GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d,
1130 struct GNUNET_TIME_Relative timeout,
1131 GNUNET_TESTING_NotifyDaemonRunning cb,
1139 GNUNET_assert (service != NULL);
1140 GNUNET_assert (d->running == GNUNET_YES);
1141 GNUNET_assert (d->phase == SP_START_DONE);
1144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1145 _("Starting service %s for peer `%4s'\n"), service,
1146 GNUNET_i2s (&d->id));
1149 d->phase = SP_SERVICE_START;
1150 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1151 /* Check if this is a local or remote process */
1152 if (NULL != d->hostname)
1155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1156 "Starting gnunet-arm with config `%s' on host `%s'.\n",
1157 d->cfgfile, d->hostname);
1160 if (d->username != NULL)
1161 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1163 arg = GNUNET_strdup (d->hostname);
1165 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1173 "-c", d->cfgfile, "-i", service, "-q",
1175 GNUNET_TIME_relative_to_string (timeout),
1177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1178 "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q -T %s\n",
1179 arg, "gnunet-arm", d->cfgfile, service,
1180 GNUNET_TIME_relative_to_string (timeout));
1186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1187 "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile);
1189 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
1193 "-c", d->cfgfile, "-i", service, "-q",
1195 GNUNET_TIME_relative_to_string (timeout),
1197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1198 "Starting gnunet-arm with command %s -c %s -i %s -q -T %s\n",
1199 "gnunet-arm", d->cfgfile, service,
1200 GNUNET_TIME_relative_to_string (timeout));
1203 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1204 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
1208 * Start a peer that has previously been stopped using the daemon_stop
1209 * call (and files weren't deleted and the allow restart flag)
1211 * @param daemon the daemon to start (has been previously stopped)
1212 * @param timeout how long to wait for restart
1213 * @param cb the callback for notification when the peer is running
1214 * @param cb_cls closure for the callback
1217 GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
1218 struct GNUNET_TIME_Relative timeout,
1219 GNUNET_TESTING_NotifyDaemonRunning cb,
1222 if (daemon->running == GNUNET_YES)
1224 cb (cb_cls, &daemon->id, daemon->cfg, daemon,
1225 "Daemon already running, can't restart!");
1230 daemon->cb_cls = cb_cls;
1231 daemon->phase = SP_TOPOLOGY_SETUP;
1232 daemon->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1234 GNUNET_SCHEDULER_add_continuation (&start_fsm,
1236 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1240 * Starts a GNUnet daemon. GNUnet must be installed on the target
1241 * system and available in the PATH. The machine must furthermore be
1242 * reachable via "ssh" (unless the hostname is "NULL") without the
1243 * need to enter a password.
1245 * @param cfg configuration to use
1246 * @param timeout how long to wait starting up peers
1247 * @param pretend GNUNET_YES to set up files but not start peer GNUNET_NO
1248 * to really start the peer (default)
1249 * @param hostname name of the machine where to run GNUnet
1250 * (use NULL for localhost).
1251 * @param ssh_username ssh username to use when connecting to hostname
1252 * @param sshport port to pass to ssh process when connecting to hostname
1253 * @param hostkey pointer to a hostkey to be written to disk (instead of being generated)
1254 * @param hostkey_callback function to call once the hostkey has been
1255 * generated for this peer, but it hasn't yet been started
1256 * (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
1257 * @param hostkey_cls closure for hostkey callback
1258 * @param cb function to call once peer is up, or failed to start
1259 * @param cb_cls closure for cb
1260 * @return handle to the daemon (actual start will be completed asynchronously)
1262 struct GNUNET_TESTING_Daemon *
1263 GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1264 struct GNUNET_TIME_Relative timeout,
1266 const char *hostname,
1267 const char *ssh_username,
1269 const char *hostkey,
1270 GNUNET_TESTING_NotifyHostkeyCreated
1271 hostkey_callback, void *hostkey_cls,
1272 GNUNET_TESTING_NotifyDaemonRunning cb,
1275 struct GNUNET_TESTING_Daemon *ret;
1279 char *baseservicehome;
1282 char *temp_file_name;
1283 struct GNUNET_DISK_FileHandle *fn;
1284 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
1285 struct GNUNET_CRYPTO_RsaPrivateKey *private_key;
1287 ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
1288 ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
1291 GNUNET_asprintf (&ret->ssh_port_str, "%d", sshport);
1294 ret->ssh_port_str = NULL;
1296 /* Find service home and base service home directories, create it if it doesn't exist */
1297 GNUNET_assert (GNUNET_OK ==
1298 GNUNET_CONFIGURATION_get_value_string (cfg,
1303 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome));
1304 GNUNET_asprintf (&temp_file_name, "%s/gnunet-testing-config", servicehome);
1305 ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name);
1306 GNUNET_free (temp_file_name);
1308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1309 "Setting up peer with configuration file `%s'.\n", ret->cfgfile);
1311 if (NULL == ret->cfgfile)
1313 GNUNET_free_non_null (ret->ssh_port_str);
1314 GNUNET_free_non_null (ret->hostname);
1318 ret->hostkey_callback = hostkey_callback;
1319 ret->hostkey_cls = hostkey_cls;
1321 ret->cb_cls = cb_cls;
1322 ret->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1323 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
1324 GNUNET_CONFIGURATION_set_value_string (ret->cfg,
1326 "DEFAULTCONFIG", ret->cfgfile);
1328 if (hostkey != NULL) /* Get the peer identity from the hostkey */
1330 private_key = GNUNET_CRYPTO_rsa_decode_key (hostkey, HOSTKEYFILESIZE);
1331 GNUNET_assert (private_key != NULL);
1332 GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key);
1333 GNUNET_CRYPTO_hash (&public_key,
1334 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1335 &ret->id.hashPubKey);
1336 ret->shortname = GNUNET_strdup (GNUNET_i2s (&ret->id));
1337 ret->have_hostkey = GNUNET_YES;
1338 GNUNET_CRYPTO_rsa_key_free (private_key);
1341 /* Write hostkey to file, if we were given one */
1343 if (hostkey != NULL)
1345 GNUNET_asprintf (&hostkeyfile, "%s/.hostkey", servicehome);
1346 fn = GNUNET_DISK_file_open (hostkeyfile,
1347 GNUNET_DISK_OPEN_READWRITE
1348 | GNUNET_DISK_OPEN_CREATE,
1349 GNUNET_DISK_PERM_USER_READ |
1350 GNUNET_DISK_PERM_USER_WRITE);
1351 GNUNET_assert (fn != NULL);
1352 GNUNET_assert (HOSTKEYFILESIZE ==
1353 GNUNET_DISK_file_write (fn, hostkey, HOSTKEYFILESIZE));
1354 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fn));
1357 /* write configuration to temporary file */
1358 if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
1360 if (0 != UNLINK (ret->cfgfile))
1361 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1362 "unlink", ret->cfgfile);
1363 GNUNET_CONFIGURATION_destroy (ret->cfg);
1364 GNUNET_free_non_null (ret->hostname);
1365 GNUNET_free (ret->cfgfile);
1369 if (ssh_username != NULL)
1370 username = GNUNET_strdup (ssh_username);
1371 if ((ssh_username == NULL) && (GNUNET_OK !=
1372 GNUNET_CONFIGURATION_get_value_string (cfg,
1377 if (NULL != getenv ("USER"))
1378 username = GNUNET_strdup (getenv ("USER"));
1382 ret->username = username;
1384 if (GNUNET_NO == pretend) /* Copy files, enter finite state machine */
1386 /* copy directory to remote host */
1387 if (NULL != hostname)
1390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1391 "Copying configuration directory to host `%s'.\n", hostname);
1393 baseservicehome = GNUNET_strdup (servicehome);
1394 /* Remove trailing /'s */
1395 while (baseservicehome[strlen (baseservicehome) - 1] == '/')
1396 baseservicehome[strlen (baseservicehome) - 1] = '\0';
1397 /* Find next directory /, jump one ahead */
1398 slash = strrchr (baseservicehome, '/');
1402 ret->phase = SP_COPYING;
1403 if (NULL != username)
1404 GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, baseservicehome);
1406 GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome);
1407 GNUNET_free (baseservicehome);
1408 if (ret->ssh_port_str == NULL)
1410 ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r",
1414 servicehome, arg, NULL);
1416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1417 "copying directory with command scp -r %s %s\n",
1423 ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp",
1429 servicehome, arg, NULL);
1432 if (NULL == ret->proc)
1434 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1436 ("Could not start `%s' process to copy configuration directory.\n"),
1438 if (0 != UNLINK (ret->cfgfile))
1439 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1440 "unlink", ret->cfgfile);
1441 GNUNET_CONFIGURATION_destroy (ret->cfg);
1442 GNUNET_free_non_null (ret->hostname);
1443 GNUNET_free_non_null (ret->username);
1444 GNUNET_free (ret->cfgfile);
1446 if ((hostkey != NULL) && (0 != UNLINK (hostkeyfile)))
1447 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1448 "unlink", hostkeyfile);
1449 GNUNET_free_non_null (hostkeyfile);
1450 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome));
1451 GNUNET_free (servicehome);
1456 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
1458 GNUNET_free_non_null (hostkeyfile);
1459 GNUNET_free (servicehome);
1463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1464 "No need to copy configuration file since we are running locally.\n");
1466 ret->phase = SP_COPIED;
1467 GNUNET_SCHEDULER_add_continuation (&start_fsm,
1469 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1471 GNUNET_free_non_null (hostkeyfile);
1472 GNUNET_free (servicehome);
1478 * Restart (stop and start) a GNUnet daemon.
1480 * @param d the daemon that should be restarted
1481 * @param cb function called once the daemon is (re)started
1482 * @param cb_cls closure for cb
1485 GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
1486 GNUNET_TESTING_NotifyDaemonRunning cb,
1495 d->dead = GNUNET_YES;
1502 if (d->phase == SP_CONFIG_UPDATE)
1504 GNUNET_SCHEDULER_cancel (d->task);
1505 d->phase = SP_START_DONE;
1507 if (d->server != NULL)
1509 GNUNET_CORE_disconnect (d->server);
1515 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
1516 GNUNET_TRANSPORT_disconnect (d->th);
1519 /* state clean up and notifications */
1520 GNUNET_free_non_null (d->hello);
1523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1524 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
1527 d->phase = SP_START_ARMING;
1529 /* Check if this is a local or remote process */
1530 if (NULL != d->hostname)
1533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1534 "Stopping gnunet-arm with config `%s' on host `%s'.\n",
1535 d->cfgfile, d->hostname);
1538 if (d->username != NULL)
1539 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1541 arg = GNUNET_strdup (d->hostname);
1543 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1551 "-c", d->cfgfile, "-e", "-r", NULL);
1552 /* Use -r to restart arm and all services */
1559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1560 "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile);
1562 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
1566 "-c", d->cfgfile, "-e", "-r", NULL);
1569 GNUNET_free_non_null (del_arg);
1571 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
1578 * Stops a GNUnet daemon.
1580 * @param d the daemon that should be stopped
1581 * @param service the name of the service to stop
1582 * @param timeout how long to wait for process for shutdown to complete
1583 * @param cb function called once the daemon was stopped
1584 * @param cb_cls closure for cb
1585 * @param delete_files GNUNET_YES to remove files, GNUNET_NO
1587 * @param allow_restart GNUNET_YES to restart peer later (using this API)
1588 * GNUNET_NO to kill off and clean up for good
1591 GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
1593 struct GNUNET_TIME_Relative timeout,
1594 GNUNET_TESTING_NotifyCompletion cb,
1600 d->dead_cb_cls = cb_cls;
1602 GNUNET_assert (d->running == GNUNET_YES);
1604 if (d->phase == SP_CONFIG_UPDATE)
1606 GNUNET_SCHEDULER_cancel (d->task);
1607 d->phase = SP_START_DONE;
1611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1612 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
1614 if (d->churned_services != NULL)
1616 d->dead_cb (d->dead_cb_cls, "A service has already been turned off!!");
1619 d->phase = SP_SERVICE_SHUTDOWN_START;
1620 d->churned_services = GNUNET_strdup (service);
1621 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1622 /* Check if this is a local or remote process */
1623 if (NULL != d->hostname)
1626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1627 "Stopping gnunet-arm with config `%s' on host `%s'.\n",
1628 d->cfgfile, d->hostname);
1631 if (d->username != NULL)
1632 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1634 arg = GNUNET_strdup (d->hostname);
1636 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1644 "-c", d->cfgfile, "-k", service, "-q",
1646 GNUNET_TIME_relative_to_string (timeout),
1648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1649 "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k %s -q\n",
1650 arg, "gnunet-arm", d->cfgfile, service);
1656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1657 "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile);
1659 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
1663 "-c", d->cfgfile, "-k", service, "-q",
1665 GNUNET_TIME_relative_to_string (timeout),
1669 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1670 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
1675 * Stops a GNUnet daemon.
1677 * @param d the daemon that should be stopped
1678 * @param timeout how long to wait for process for shutdown to complete
1679 * @param cb function called once the daemon was stopped
1680 * @param cb_cls closure for cb
1681 * @param delete_files GNUNET_YES to remove files, GNUNET_NO
1683 * @param allow_restart GNUNET_YES to restart peer later (using this API)
1684 * GNUNET_NO to kill off and clean up for good
1687 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
1688 struct GNUNET_TIME_Relative timeout,
1689 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
1690 int delete_files, int allow_restart)
1696 d->dead_cb_cls = cb_cls;
1701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1702 _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id));
1704 d->dead = GNUNET_YES;
1708 if ((d->running == GNUNET_NO) && (d->churn == GNUNET_YES)) /* Peer has already been stopped in churn context! */
1710 /* Free what was left from churning! */
1711 GNUNET_assert (d->cfg != NULL);
1712 GNUNET_CONFIGURATION_destroy (d->cfg);
1713 if (delete_files == GNUNET_YES)
1715 if (0 != UNLINK (d->cfgfile))
1717 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "unlink");
1720 GNUNET_free (d->cfgfile);
1721 GNUNET_free_non_null (d->hostname);
1722 GNUNET_free_non_null (d->username);
1723 if (NULL != d->dead_cb)
1724 d->dead_cb (d->dead_cb_cls, NULL);
1730 if (delete_files == GNUNET_YES)
1732 GNUNET_asprintf (&del_arg, "-d");
1735 if (d->phase == SP_CONFIG_UPDATE)
1737 GNUNET_SCHEDULER_cancel (d->task);
1738 d->phase = SP_START_DONE;
1740 /** Move this call to scheduled shutdown as fix for CORE_connect calling daemon_stop?
1741 if (d->server != NULL)
1743 GNUNET_CORE_disconnect (d->server);
1747 /* shutdown ARM process (will terminate others) */
1749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1750 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
1752 d->phase = SP_SHUTDOWN_START;
1753 d->running = GNUNET_NO;
1754 if (allow_restart == GNUNET_YES)
1755 d->churn = GNUNET_YES;
1758 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
1759 GNUNET_TRANSPORT_disconnect (d->th);
1762 /* Check if this is a local or remote process */
1763 if (NULL != d->hostname)
1766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1767 "Stopping gnunet-arm with config `%s' on host `%s'.\n",
1768 d->cfgfile, d->hostname);
1771 if (d->username != NULL)
1772 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1774 arg = GNUNET_strdup (d->hostname);
1776 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1784 "-c", d->cfgfile, "-e", "-q",
1786 GNUNET_TIME_relative_to_string (timeout),
1788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1789 "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e -q %s\n",
1790 arg, "gnunet-arm", d->cfgfile, del_arg);
1791 /* Use -e to end arm, and -d to remove temp files */
1797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1798 "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile);
1800 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm",
1804 "-c", d->cfgfile, "-e", "-q",
1806 GNUNET_TIME_relative_to_string (timeout),
1810 GNUNET_free_non_null (del_arg);
1811 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1812 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
1817 * Changes the configuration of a GNUnet daemon.
1819 * @param d the daemon that should be modified
1820 * @param cfg the new configuration for the daemon
1821 * @param cb function called once the configuration was changed
1822 * @param cb_cls closure for cb
1825 GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
1826 struct GNUNET_CONFIGURATION_Handle *cfg,
1827 GNUNET_TESTING_NotifyCompletion cb,
1832 if (d->phase != SP_START_DONE)
1837 ("Peer not yet running, can not change configuration at this point."));
1841 /* 1) write configuration to temporary file */
1842 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile))
1845 cb (cb_cls, _("Failed to write new configuration to disk."));
1849 /* 2) copy file to remote host (if necessary) */
1850 if (NULL == d->hostname)
1852 /* signal success */
1858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1859 "Copying updated configuration file to remote host `%s'.\n",
1862 d->phase = SP_CONFIG_UPDATE;
1863 if (NULL != d->username)
1864 GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile);
1866 GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile);
1867 d->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
1871 d->cfgfile, arg, NULL);
1873 if (NULL == d->proc)
1875 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1877 ("Could not start `%s' process to copy configuration file.\n"),
1880 cb (cb_cls, _("Failed to copy new configuration to remote machine."));
1881 d->phase = SP_START_DONE;
1885 d->update_cb_cls = cb_cls;
1887 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
1893 * Data kept for each pair of peers that we try
1896 struct ConnectContext
1899 * Testing handle to the first daemon.
1901 struct GNUNET_TESTING_Daemon *d1;
1904 * Handle to core of first daemon (to check connect)
1906 struct GNUNET_CORE_Handle *d1core;
1909 * Have we actually connected to the core of the first daemon yet?
1914 * Testing handle to the second daemon.
1916 struct GNUNET_TESTING_Daemon *d2;
1919 * Handler for the request to core to connect to this peer.
1921 struct GNUNET_CORE_PeerRequestHandle *connect_request_handle;
1924 * Transport handle to the first daemon (to offer the HELLO of the second daemon to).
1926 struct GNUNET_TRANSPORT_Handle *d1th;
1929 * Function to call once we are done (or have timed out).
1931 GNUNET_TESTING_NotifyConnection cb;
1939 * The relative timeout from whence this connect attempt was
1940 * started. Allows for reconnect attempts.
1942 struct GNUNET_TIME_Relative relative_timeout;
1945 * Maximum number of connect attempts, will retry connection
1946 * this number of times on failures.
1948 unsigned int connect_attempts;
1951 * Hello timeout task
1953 GNUNET_SCHEDULER_TaskIdentifier hello_send_task;
1956 * Connect timeout task
1958 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
1961 * When should this operation be complete (or we must trigger
1964 struct GNUNET_TIME_Relative timeout_hello;
1967 * Was the connection attempt successful?
1972 * When connecting, do we need to send the HELLO?
1977 * The distance between the two connected peers
1983 /** Forward declaration **/
1985 reattempt_daemons_connect (void *cls,
1986 const struct GNUNET_SCHEDULER_TaskContext *tc);
1990 * Notify callback about success or failure of the attempt
1991 * to connect the two peers
1993 * @param cls our "struct ConnectContext" (freed)
1994 * @param tc reason tells us if we succeeded or failed
1997 notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1999 struct ConnectContext *ctx = cls;
2001 ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2002 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
2004 GNUNET_SCHEDULER_cancel (ctx->hello_send_task);
2005 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
2008 if (ctx->connect_request_handle != NULL)
2010 GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle);
2011 ctx->connect_request_handle = NULL;
2014 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
2016 if (ctx->d1th != NULL)
2017 GNUNET_TRANSPORT_disconnect (ctx->d1th);
2019 if (ctx->d1core != NULL)
2020 GNUNET_CORE_disconnect (ctx->d1core);
2022 if (ctx->d2core != NULL)
2023 GNUNET_CORE_disconnect (ctx->d2core);
2031 if (ctx->d1th != NULL)
2032 GNUNET_TRANSPORT_disconnect (ctx->d1th);
2034 if (ctx->d1core != NULL)
2035 GNUNET_CORE_disconnect (ctx->d1core);
2038 if (ctx->connected == GNUNET_YES)
2040 if (ctx->cb != NULL)
2042 ctx->cb (ctx->cb_cls,
2046 ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
2049 else if (ctx->connect_attempts > 0)
2051 ctx->d1core_ready = GNUNET_NO;
2053 if (ctx->d2core != NULL)
2055 GNUNET_CORE_disconnect (ctx->d2core);
2059 GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx);
2064 if (ctx->cb != NULL)
2066 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2067 ctx->d2->cfg, ctx->d1, ctx->d2, _("Peers failed to connect"));
2076 * Success, connection is up. Signal client our success.
2078 * @param cls our "struct ConnectContext"
2079 * @param peer identity of the peer that has connected
2080 * @param atsi performance information
2084 connect_notify (void *cls,
2085 const struct GNUNET_PeerIdentity *peer,
2086 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2088 struct ConnectContext *ctx = cls;
2091 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2092 "Connected peer %s to peer %s\n",
2093 ctx->d1->shortname, GNUNET_i2s (peer));
2096 if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))
2099 ctx->connected = GNUNET_YES;
2100 ctx->distance = 0; /* FIXME: distance */
2101 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
2103 GNUNET_SCHEDULER_cancel (ctx->hello_send_task);
2104 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
2106 GNUNET_SCHEDULER_cancel (ctx->timeout_task);
2107 ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
2113 * Success, connection is up. Signal client our success.
2115 * @param cls our "struct ConnectContext"
2116 * @param peer identity of the peer that has connected
2117 * @param atsi performance information
2121 connect_notify_core2 (void *cls,
2122 const struct GNUNET_PeerIdentity *peer,
2123 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2125 struct ConnectContext *ctx = cls;
2127 if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0)
2129 ctx->connected = GNUNET_YES;
2130 ctx->distance = 0; /* FIXME: distance */
2131 GNUNET_SCHEDULER_cancel (ctx->timeout_task);
2132 ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx);
2139 * Task called once a core connect request has been transmitted.
2141 * @param cls struct ConnectContext
2142 * @param success was the request successful?
2145 core_connect_request_cont (void *cls, int success)
2147 struct ConnectContext *ctx = cls;
2149 ctx->connect_request_handle = NULL;
2153 send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2155 struct ConnectContext *ctx = cls;
2156 struct GNUNET_MessageHeader *hello;
2158 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
2159 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
2161 if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL)
2162 && (NULL != GNUNET_HELLO_get_header (ctx->d2->hello))
2163 && (ctx->d1->phase == SP_START_DONE) && (ctx->d2->phase == SP_START_DONE))
2165 hello = GNUNET_HELLO_get_header (ctx->d2->hello);
2166 GNUNET_assert (hello != NULL);
2168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Offering hello of %s to %s\n",
2169 ctx->d2->shortname, ctx->d1->shortname);
2171 GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL);
2172 GNUNET_assert (ctx->d1core != NULL);
2173 ctx->connect_request_handle =
2174 GNUNET_CORE_peer_request_connect (ctx->d1core,
2176 &core_connect_request_cont, ctx);
2179 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2180 "Sending connect request to CORE of %s for peer %s\n",
2181 GNUNET_i2s (&ctx->d1->id),
2182 GNUNET_h2s (&ctx->d2->id.hashPubKey));
2184 ctx->timeout_hello =
2185 GNUNET_TIME_relative_add (ctx->timeout_hello,
2186 GNUNET_TIME_relative_multiply
2187 (GNUNET_TIME_UNIT_MILLISECONDS, 500));
2189 ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello,
2194 * Notify of a successful connection to the core service.
2196 * @param cls a ConnectContext
2197 * @param server handle to the core service
2198 * @param my_identity the peer identity of this peer
2199 * @param publicKey the public key of the peer
2202 core_init_notify (void *cls,
2203 struct GNUNET_CORE_Handle *server,
2204 const struct GNUNET_PeerIdentity *my_identity,
2206 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
2208 struct ConnectContext *connect_ctx = cls;
2210 connect_ctx->d1core_ready = GNUNET_YES;
2212 if (connect_ctx->send_hello == GNUNET_NO)
2214 connect_ctx->connect_request_handle =
2215 GNUNET_CORE_peer_request_connect (connect_ctx->d1core,
2216 &connect_ctx->d2->id,
2217 &core_connect_request_cont,
2219 GNUNET_assert (connect_ctx->connect_request_handle != NULL);
2221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2222 "Sending connect request to CORE of %s for peer %s\n",
2223 connect_ctx->d1->shortname, connect_ctx->d2->shortname);
2231 reattempt_daemons_connect (void *cls,
2232 const struct GNUNET_SCHEDULER_TaskContext *tc)
2234 struct ConnectContext *ctx = cls;
2236 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
2241 #if DEBUG_TESTING_RECONNECT
2242 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2243 "re-attempting connect of peer %s to peer %s\n",
2244 ctx->d1->shortname, ctx->d2->shortname);
2246 ctx->connect_attempts--;
2247 GNUNET_assert (ctx->d1core == NULL);
2248 ctx->d1core_ready = GNUNET_NO;
2249 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
2252 &connect_notify, NULL, NULL,
2254 NULL, GNUNET_NO, no_handlers);
2255 if (ctx->d1core == NULL)
2257 if (NULL != ctx->cb)
2258 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2259 ctx->d2->cfg, ctx->d1, ctx->d2,
2260 _("Failed to connect to core service of first peer!\n"));
2265 /* Don't know reason for initial connect failure, update the HELLO for the second peer */
2266 if (NULL != ctx->d2->hello)
2268 GNUNET_free (ctx->d2->hello);
2269 ctx->d2->hello = NULL;
2270 if (NULL != ctx->d2->th)
2272 GNUNET_TRANSPORT_get_hello_cancel (ctx->d2->th, &process_hello, ctx->d2);
2273 GNUNET_TRANSPORT_disconnect (ctx->d2->th);
2276 GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL,
2278 GNUNET_assert (ctx->d2->th != NULL);
2279 GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
2282 if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL))
2285 GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL,
2287 if (ctx->d2->th == NULL)
2289 GNUNET_CORE_disconnect (ctx->d1core);
2291 if (NULL != ctx->cb)
2292 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2293 ctx->d2->cfg, ctx->d1, ctx->d2,
2294 _("Failed to connect to transport service!\n"));
2297 GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
2300 if (ctx->send_hello == GNUNET_YES)
2302 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
2304 ctx->d1, NULL, NULL, NULL);
2305 if (ctx->d1th == NULL)
2307 GNUNET_CORE_disconnect (ctx->d1core);
2309 if (NULL != ctx->cb)
2310 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2311 ctx->d2->cfg, ctx->d1, ctx->d2,
2312 _("Failed to connect to transport service!\n"));
2315 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
2319 ctx->connect_request_handle =
2320 GNUNET_CORE_peer_request_connect (ctx->d1core,
2322 &core_connect_request_cont, ctx);
2325 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
2326 ¬ify_connect_result, ctx);
2330 * Iterator for currently known peers, to ensure
2331 * that we don't try to send duplicate connect
2334 * @param cls our "struct ConnectContext"
2335 * @param peer identity of the peer that has connected,
2336 * NULL when iteration has finished
2337 * @param atsi performance information
2341 core_initial_iteration (void *cls,
2342 const struct GNUNET_PeerIdentity *peer,
2343 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2345 struct ConnectContext *ctx = cls;
2347 if ((peer != NULL) &&
2348 (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))))
2350 ctx->connected = GNUNET_YES;
2351 ctx->distance = 0; /* FIXME: distance */
2354 else if (peer == NULL) /* End of iteration over peers */
2356 if (ctx->connected == GNUNET_YES)
2358 ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result,
2363 /* Peer not already connected, need to schedule connect request! */
2364 if (ctx->d1core == NULL)
2367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2368 "Peers are NOT connected, connecting to core!\n");
2370 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
2373 &connect_notify, NULL, NULL,
2375 NULL, GNUNET_NO, no_handlers);
2378 if (ctx->d1core == NULL)
2381 if (NULL != ctx->cb)
2382 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2383 ctx->d2->cfg, ctx->d1, ctx->d2,
2384 _("Failed to connect to core service of first peer!\n"));
2388 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 */
2391 GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL,
2393 if (ctx->d2->th == NULL)
2395 GNUNET_CORE_disconnect (ctx->d1core);
2397 if (NULL != ctx->cb)
2398 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2399 ctx->d2->cfg, ctx->d1, ctx->d2,
2400 _("Failed to connect to transport service!\n"));
2403 GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
2406 if (ctx->send_hello == GNUNET_YES)
2408 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
2409 &ctx->d1->id, ctx->d1, NULL, NULL,
2411 if (ctx->d1th == NULL)
2413 GNUNET_CORE_disconnect (ctx->d1core);
2415 if (NULL != ctx->cb)
2416 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2417 ctx->d2->cfg, ctx->d1, ctx->d2,
2418 _("Failed to connect to transport service!\n"));
2421 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
2425 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
2426 ¬ify_connect_result, ctx);
2432 * Establish a connection between two GNUnet daemons.
2434 * @param d1 handle for the first daemon
2435 * @param d2 handle for the second daemon
2436 * @param timeout how long is the connection attempt
2438 * @param max_connect_attempts how many times should we try to reconnect
2440 * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume
2441 * the HELLO has already been exchanged
2442 * @param cb function to call at the end
2443 * @param cb_cls closure for cb
2446 GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
2447 struct GNUNET_TESTING_Daemon *d2,
2448 struct GNUNET_TIME_Relative timeout,
2449 unsigned int max_connect_attempts,
2451 GNUNET_TESTING_NotifyConnection cb,
2454 struct ConnectContext *ctx;
2456 if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO))
2459 cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2,
2460 _("Peers are not fully running yet, can not connect!\n"));
2461 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n");
2465 ctx = GNUNET_malloc (sizeof (struct ConnectContext));
2468 ctx->timeout_hello =
2469 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500);
2470 ctx->relative_timeout =
2471 GNUNET_TIME_relative_divide (timeout, max_connect_attempts);
2473 ctx->cb_cls = cb_cls;
2474 ctx->connect_attempts = max_connect_attempts;
2475 ctx->connected = GNUNET_NO;
2476 ctx->send_hello = send_hello;
2478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2479 "Asked to connect peer %s to peer %s\n",
2480 d1->shortname, d2->shortname);
2483 /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */
2484 GNUNET_assert (GNUNET_OK ==
2485 GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id,
2486 &core_initial_iteration, ctx));
2487 /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg, &core_initial_iteration, ctx)); */
2490 /* end of testing.c */