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,
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,
91 const struct GNUNET_MessageHeader *message)
93 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,
107 if (GNUNET_YES == empty)
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 "Skipping empty HELLO address\n");
119 GNUNET_assert (daemon->phase == SP_GET_HELLO || daemon->phase == SP_START_DONE);
124 if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */
125 GNUNET_SCHEDULER_cancel(daemon->task);
127 if (daemon->server != NULL)
130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
131 "Received `%s' from transport service of `%4s', disconnecting core!\n",
132 "HELLO", GNUNET_i2s (&daemon->id));
134 GNUNET_CORE_disconnect (daemon->server);
135 daemon->server = NULL;
138 msize = ntohs (message->size);
143 if (daemon->th != NULL)
145 GNUNET_TRANSPORT_get_hello_cancel (daemon->th, &process_hello, daemon);
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Received `%s' from transport service of `%4s'\n",
150 "HELLO", GNUNET_i2s (&daemon->id));
153 GNUNET_free_non_null (daemon->hello);
154 daemon->hello = GNUNET_malloc (msize);
155 memcpy (daemon->hello, message, msize);
157 if (daemon->th != NULL)
159 GNUNET_TRANSPORT_disconnect (daemon->th);
162 daemon->phase = SP_START_DONE;
165 if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */
174 start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
178 * Function called after GNUNET_CORE_connect has succeeded
179 * (or failed for good). Note that the private key of the
180 * peer is intentionally not exposed here; if you need it,
181 * your process should try to read the private key file
182 * directly (which should work if you are authorized...).
185 * @param server handle to the server, NULL if we failed
186 * @param my_identity ID of this peer, NULL if we failed
187 * @param publicKey public key of this peer, NULL if we failed
190 testing_init (void *cls,
191 struct GNUNET_CORE_Handle *server,
192 const struct GNUNET_PeerIdentity *my_identity,
193 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
195 struct GNUNET_TESTING_Daemon *d = cls;
197 GNUNET_assert (d->phase == SP_START_CORE);
198 d->phase = SP_GET_HELLO;
203 if (GNUNET_YES == d->dead)
204 GNUNET_TESTING_daemon_stop (d,
205 GNUNET_TIME_absolute_get_remaining
206 (d->max_timeout), d->dead_cb,
207 d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
208 else if (NULL != d->cb)
209 d->cb (d->cb_cls, NULL, d->cfg, d,
210 _("Failed to connect to core service\n"));
214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity));
217 d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */
218 if (d->shortname == NULL)
219 d->shortname = strdup (GNUNET_i2s (my_identity));
221 d->running = GNUNET_YES;
223 if (GNUNET_NO == d->running)
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
227 "Peer is dead (d->running == GNUNET_NO)\n");
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "Successfully started peer `%4s', connecting to transport service.\n",
234 GNUNET_i2s (my_identity));
237 d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
240 if (GNUNET_YES == d->dead)
241 GNUNET_TESTING_daemon_stop (d,
242 GNUNET_TIME_absolute_get_remaining
243 (d->max_timeout), d->dead_cb,
244 d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
245 else if (NULL != d->cb)
246 d->cb (d->cb_cls, &d->id, d->cfg, d,
247 _("Failed to connect to transport service!\n"));
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "Connected to transport service `%s', getting HELLO\n",
253 GNUNET_i2s (my_identity));
256 GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
258 if (d->task != GNUNET_SCHEDULER_NO_TASK)
259 GNUNET_SCHEDULER_cancel(d->task);
261 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
268 * Notify of a peer being up and running. Scheduled as a task
269 * so that variables which may need to be set are set before
270 * the connect callback can set up new operations.
272 * @param cls the testing daemon
273 * @param tc task scheduler context
276 notify_daemon_started (void *cls,
277 const struct GNUNET_SCHEDULER_TaskContext *tc)
279 struct GNUNET_TESTING_Daemon *d = cls;
280 GNUNET_TESTING_NotifyDaemonRunning cb;
285 cb (d->cb_cls, &d->id, d->cfg, d, NULL);
290 * Finite-state machine for starting GNUnet.
292 * @param cls our "struct GNUNET_TESTING_Daemon"
296 start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
298 struct GNUNET_TESTING_Daemon *d = cls;
299 GNUNET_TESTING_NotifyDaemonRunning cb;
300 enum GNUNET_OS_ProcessStatusType type;
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
307 "Peer FSM is in phase %u.\n", d->phase);
310 d->task = GNUNET_SCHEDULER_NO_TASK;
314 /* confirm copying complete */
315 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
317 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
327 ("`scp' does not seem to terminate (timeout copying config).\n"));
332 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
336 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
342 NULL, d->cfg, d, _("`scp' did not complete cleanly.\n"));
345 GNUNET_OS_process_close(d->proc);
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348 "Successfully copied configuration file.\n");
350 d->phase = SP_COPIED;
353 /* Start create hostkey process if we don't already know the peer identity!*/
354 if (GNUNET_NO == d->have_hostkey)
356 d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES);
357 if (d->pipe_stdout == NULL)
366 (NULL == d->hostname)
367 ? _("Failed to create pipe for `gnunet-peerinfo' process.\n")
368 : _("Failed to create pipe for `ssh' process.\n"));
371 if (NULL == d->hostname)
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "Starting `%s', with command `%s %s %s %s'.\n",
376 "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile,
380 GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo",
381 "gnunet-peerinfo", "-c", d->cfgfile,
383 GNUNET_DISK_pipe_close_end (d->pipe_stdout,
384 GNUNET_DISK_PIPE_END_WRITE);
388 if (d->username != NULL)
389 GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
391 dst = GNUNET_strdup (d->hostname);
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
395 "Starting `%s', with command `%s %s %s %s %s %s'.\n",
396 "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c",
399 if (d->ssh_port_str == NULL)
401 d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
408 "-c", d->cfgfile, "-sq",
413 d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
414 "ssh", "-p", d->ssh_port_str,
420 "-c", d->cfgfile, "-sq",
423 GNUNET_DISK_pipe_close_end (d->pipe_stdout,
424 GNUNET_DISK_PIPE_END_WRITE);
429 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
430 _("Could not start `%s' process to create hostkey.\n"),
431 (NULL == d->hostname) ? "gnunet-peerinfo" : "ssh");
439 (NULL == d->hostname)
440 ? _("Failed to start `gnunet-peerinfo' process.\n")
441 : _("Failed to start `ssh' process.\n"));
442 GNUNET_DISK_pipe_close (d->pipe_stdout);
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo");
449 d->phase = SP_HOSTKEY_CREATE;
452 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
454 GNUNET_DISK_pipe_handle
456 GNUNET_DISK_PIPE_END_READ),
459 else /* Already have a hostkey! */
461 if (d->hostkey_callback != NULL)
463 d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL);
464 d->hostkey_callback = NULL;
465 d->phase = SP_HOSTKEY_CREATED;
468 d->phase = SP_TOPOLOGY_SETUP;
472 = GNUNET_SCHEDULER_add_now (&start_fsm, d);
475 case SP_HOSTKEY_CREATE:
477 GNUNET_DISK_file_read (GNUNET_DISK_pipe_handle
478 (d->pipe_stdout, GNUNET_DISK_PIPE_END_READ),
479 &d->hostkeybuf[d->hostkeybufpos],
480 sizeof (d->hostkeybuf) - d->hostkeybufpos);
482 d->hostkeybufpos += bytes_read;
484 if ((d->hostkeybufpos < 104) && (bytes_read > 0))
489 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
491 GNUNET_DISK_pipe_handle
493 GNUNET_DISK_PIPE_END_READ),
497 d->hostkeybuf[103] = '\0';
499 if ((bytes_read < 0) ||
500 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (d->hostkeybuf,
505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
506 _("Error reading from gnunet-peerinfo: %s\n"),
509 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
510 _("Malformed output from gnunet-peerinfo!\n"));
513 GNUNET_DISK_pipe_close (d->pipe_stdout);
514 d->pipe_stdout = NULL;
515 (void) GNUNET_OS_process_kill (d->proc, SIGKILL);
516 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc));
517 GNUNET_OS_process_close (d->proc);
520 cb (d->cb_cls, NULL, d->cfg, d, _("`Failed to get hostkey!\n"));
523 d->shortname = GNUNET_strdup(GNUNET_i2s(&d->id));
524 GNUNET_DISK_pipe_close (d->pipe_stdout);
525 d->pipe_stdout = NULL;
526 (void) GNUNET_OS_process_kill (d->proc, SIGKILL);
527 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc));
528 GNUNET_OS_process_close (d->proc);
530 d->have_hostkey = GNUNET_YES;
531 if (d->hostkey_callback != NULL)
533 d->hostkey_callback (d->hostkey_cls, &d->id, d, NULL);
534 d->hostkey_callback = NULL;
535 d->phase = SP_HOSTKEY_CREATED;
539 d->phase = SP_TOPOLOGY_SETUP;
542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n");
545 case SP_HOSTKEY_CREATED:
546 /* wait for topology finished */
547 if ((GNUNET_YES == d->dead)
548 || (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
556 d->cfg, d, _("`Failed while waiting for topology setup!\n"));
561 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
564 case SP_TOPOLOGY_SETUP: /* Indicates topology setup has completed! */
565 /* start GNUnet on remote host */
566 if (NULL == d->hostname)
569 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
570 "Starting `%s', with command `%s %s %s %s %s %s'.\n",
571 "gnunet-arm", "gnunet-arm", "-c", d->cfgfile,
572 "-L", "DEBUG", "-s");
574 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
575 "gnunet-arm", "-c", d->cfgfile,
579 "-s", "-q", "-T", GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)), NULL);
583 if (d->username != NULL)
584 GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
586 dst = GNUNET_strdup (d->hostname);
589 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
590 "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n",
591 "gnunet-arm", "ssh", dst, "gnunet-arm", "-c",
592 d->cfgfile, "-L", "DEBUG", "-s", "-q");
594 if (d->ssh_port_str == NULL)
596 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
604 "-c", d->cfgfile, "-s", "-q",
605 "-T", GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)),
611 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh",
612 "ssh", "-p", d->ssh_port_str,
620 "-c", d->cfgfile, "-s", "-q",
621 "-T", GNUNET_TIME_relative_to_string(GNUNET_TIME_absolute_get_remaining(d->max_timeout)),
628 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
629 _("Could not start `%s' process to start GNUnet.\n"),
630 (NULL == d->hostname) ? "gnunet-arm" : "ssh");
638 (NULL == d->hostname)
639 ? _("Failed to start `gnunet-arm' process.\n")
640 : _("Failed to start `ssh' process.\n"));
644 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
645 "Started `%s', waiting for `%s' to be up.\n",
646 "gnunet-arm", "gnunet-service-core");
648 d->phase = SP_START_ARMING;
650 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
653 case SP_START_ARMING:
654 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
656 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
666 (NULL == d->hostname)
667 ? _("`gnunet-arm' does not seem to terminate.\n")
668 : _("`ssh' does not seem to terminate.\n"));
669 GNUNET_CONFIGURATION_destroy (d->cfg);
670 GNUNET_free (d->cfgfile);
671 GNUNET_free_non_null (d->hostname);
672 GNUNET_free_non_null (d->username);
673 GNUNET_free(d->proc);
679 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
684 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
685 "Successfully started `%s'.\n", "gnunet-arm");
687 GNUNET_free(d->proc);
688 d->phase = SP_START_CORE;
690 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
691 "Calling CORE_connect\n");
695 if (d->server != NULL)
696 GNUNET_CORE_disconnect(d->server);
699 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
709 _("Unable to connect to CORE service for peer!\n"));
710 GNUNET_CONFIGURATION_destroy (d->cfg);
711 GNUNET_free (d->cfgfile);
712 GNUNET_free_non_null (d->hostname);
713 GNUNET_free_non_null (d->username);
717 d->server = GNUNET_CORE_connect (d->cfg, 1,
722 NULL, GNUNET_NO, no_handlers);
724 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2),
727 d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL);
730 if (GNUNET_YES == d->dead)
731 GNUNET_TESTING_daemon_stop (d,
732 GNUNET_TIME_absolute_get_remaining
733 (d->max_timeout), d->dead_cb,
734 d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
735 else if (NULL != d->cb)
736 d->cb (d->cb_cls, &d->id, d->cfg, d,
737 _("Failed to connect to transport service!\n"));
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
742 "Connected to transport service `%s', getting HELLO\n",
743 GNUNET_i2s (&d->id));
746 GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
747 GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d);
751 cb (d->cb_cls, &d->id, d->cfg, d, NULL);*/
752 d->running = GNUNET_YES;
753 d->phase = SP_GET_HELLO;
757 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
760 if (d->server != NULL)
761 GNUNET_CORE_disconnect(d->server);
763 GNUNET_TRANSPORT_disconnect(d->th);
771 _("Unable to get HELLO for peer!\n"));
772 GNUNET_CONFIGURATION_destroy (d->cfg);
773 GNUNET_free (d->cfgfile);
774 GNUNET_free_non_null (d->hostname);
775 GNUNET_free_non_null (d->username);
779 if (d->hello != NULL)
781 GNUNET_assert(d->task == GNUNET_SCHEDULER_NO_TASK);
783 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2),
789 case SP_SERVICE_START:
790 /* confirm gnunet-arm exited */
791 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
793 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
803 (NULL == d->hostname)
804 ? _("`gnunet-arm' does not seem to terminate.\n")
805 : _("`ssh' does not seem to terminate.\n"));
810 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
815 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
824 (NULL == d->hostname)
825 ? _("`gnunet-arm' terminated with non-zero exit status (or timed out)!\n")
826 : _("`ssh' does not seem to terminate.\n"));
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n");
835 d->phase = SP_START_DONE;
837 cb (d->cb_cls, &d->id, d->cfg, d, NULL);
839 case SP_SERVICE_SHUTDOWN_START:
840 /* confirm copying complete */
841 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
843 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
846 if (NULL != d->dead_cb)
847 d->dead_cb (d->dead_cb_cls,
849 ("either `gnunet-arm' or `ssh' does not seem to terminate.\n"));
854 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
859 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
861 if (NULL != d->dead_cb)
862 d->dead_cb (d->dead_cb_cls,
864 ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n"));
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
871 if (NULL != d->dead_cb)
872 d->dead_cb (d->dead_cb_cls, NULL);
874 case SP_SHUTDOWN_START:
875 /* confirm copying complete */
876 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
878 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
881 if (NULL != d->dead_cb)
882 d->dead_cb (d->dead_cb_cls,
884 ("either `gnunet-arm' or `ssh' does not seem to terminate.\n"));
887 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello,
889 GNUNET_TRANSPORT_disconnect (d->th);
892 GNUNET_CONFIGURATION_destroy (d->cfg);
893 GNUNET_free (d->cfgfile);
894 GNUNET_free_non_null (d->hello);
895 GNUNET_free_non_null (d->hostname);
896 GNUNET_free_non_null (d->username);
897 GNUNET_free_non_null (d->shortname);
898 GNUNET_free_non_null (d->proc);
905 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
909 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
911 if (NULL != d->dead_cb)
912 d->dead_cb (d->dead_cb_cls,
914 ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n"));
917 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
918 GNUNET_TRANSPORT_disconnect (d->th);
921 if (d->server != NULL)
923 GNUNET_CORE_disconnect (d->server);
926 GNUNET_CONFIGURATION_destroy (d->cfg);
927 GNUNET_free (d->cfgfile);
928 GNUNET_free_non_null (d->hello);
929 GNUNET_free_non_null (d->hostname);
930 GNUNET_free_non_null (d->username);
931 GNUNET_free_non_null (d->shortname);
932 GNUNET_free_non_null (d->proc);
938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
940 if (d->server != NULL)
942 GNUNET_CORE_disconnect (d->server);
948 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
949 GNUNET_TRANSPORT_disconnect (d->th);
953 if (NULL != d->dead_cb)
954 d->dead_cb (d->dead_cb_cls, NULL);
956 /* state clean up and notifications */
957 if (d->churn == GNUNET_NO)
959 GNUNET_CONFIGURATION_destroy (d->cfg);
960 GNUNET_free (d->cfgfile);
961 GNUNET_free_non_null (d->hostname);
962 GNUNET_free_non_null (d->username);
965 GNUNET_free_non_null (d->hello);
967 GNUNET_free_non_null (d->shortname);
968 GNUNET_free_non_null (d->proc);
971 if (d->churn == GNUNET_NO)
975 case SP_CONFIG_UPDATE:
976 /* confirm copying complete */
977 if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code))
979 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) /* FIXME: config update should take timeout parameter! */
986 d->cfg, d, _("`scp' does not seem to terminate.\n"));
991 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
995 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
997 if (NULL != d->update_cb)
998 d->update_cb (d->update_cb_cls,
999 _("`scp' did not complete cleanly.\n"));
1003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1004 "Successfully copied configuration file.\n");
1006 if (NULL != d->update_cb)
1007 d->update_cb (d->update_cb_cls, NULL);
1008 d->phase = SP_START_DONE;
1014 * Continues GNUnet daemon startup when user wanted to be notified
1015 * once a hostkey was generated (for creating friends files, blacklists,
1018 * @param daemon the daemon to finish starting
1021 GNUNET_TESTING_daemon_continue_startup (struct GNUNET_TESTING_Daemon *daemon)
1023 GNUNET_assert (daemon->phase == SP_HOSTKEY_CREATED);
1024 daemon->phase = SP_TOPOLOGY_SETUP;
1028 * Check whether the given daemon is running.
1030 * @param daemon the daemon to check
1032 * @return GNUNET_YES if the daemon is up, GNUNET_NO if the
1033 * daemon is down, GNUNET_SYSERR on error.
1036 GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon)
1039 return GNUNET_SYSERR;
1041 if (daemon->running == GNUNET_YES)
1048 * Starts a GNUnet daemon service which has been previously stopped.
1050 * @param d the daemon for which the service should be started
1051 * @param service the name of the service to start
1052 * @param timeout how long to wait for process for shutdown to complete
1053 * @param cb function called once the service starts
1054 * @param cb_cls closure for cb
1057 GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d,
1059 struct GNUNET_TIME_Relative timeout,
1060 GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls)
1066 GNUNET_assert(d->running == GNUNET_YES);
1068 if (d->phase == SP_CONFIG_UPDATE)
1070 GNUNET_SCHEDULER_cancel (d->task);
1071 d->phase = SP_START_DONE;
1074 if (d->churned_services == NULL)
1076 d->cb(d->cb_cls, &d->id, d->cfg, d, "No service has been churned off yet!!");
1079 d->phase = SP_SERVICE_START;
1080 GNUNET_free(d->churned_services);
1081 d->churned_services = NULL;
1083 /* Check if this is a local or remote process */
1084 if (NULL != d->hostname)
1087 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1088 "Starting gnunet-arm with config `%s' on host `%s'.\n",
1089 d->cfgfile, d->hostname);
1092 if (d->username != NULL)
1093 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1095 arg = GNUNET_strdup (d->hostname);
1097 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1105 "-c", d->cfgfile, "-i", service, "-q",
1106 "-T", GNUNET_TIME_relative_to_string(timeout),
1108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1109 "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n",
1110 arg, "gnunet-arm", d->cfgfile, service);
1116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1117 "Starting gnunet-arm with config `%s' locally.\n",
1120 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
1125 "-c", d->cfgfile, "-i", service, "-q",
1126 "-T", GNUNET_TIME_relative_to_string(timeout),
1130 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1131 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
1135 * Starts a GNUnet daemon's service.
1137 * @param d the daemon for which the service should be started
1138 * @param service the name of the service to start
1139 * @param timeout how long to wait for process for startup
1140 * @param cb function called once gnunet-arm returns
1141 * @param cb_cls closure for cb
1144 GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d,
1146 struct GNUNET_TIME_Relative timeout,
1147 GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls)
1153 GNUNET_assert(service != NULL);
1154 GNUNET_assert(d->running == GNUNET_YES);
1155 GNUNET_assert(d->phase == SP_START_DONE);
1158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1159 _("Starting service %s for peer `%4s'\n"), service, GNUNET_i2s (&d->id));
1162 d->phase = SP_SERVICE_START;
1164 /* Check if this is a local or remote process */
1165 if (NULL != d->hostname)
1168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1169 "Starting gnunet-arm with config `%s' on host `%s'.\n",
1170 d->cfgfile, d->hostname);
1173 if (d->username != NULL)
1174 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1176 arg = GNUNET_strdup (d->hostname);
1178 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1186 "-c", d->cfgfile, "-i", service, "-q",
1187 "-T", GNUNET_TIME_relative_to_string(timeout),
1189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1190 "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n",
1191 arg, "gnunet-arm", d->cfgfile, service);
1197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1198 "Starting gnunet-arm with config `%s' locally.\n",
1201 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
1206 "-c", d->cfgfile, "-i", service, "-q",
1207 "-T", GNUNET_TIME_relative_to_string(timeout),
1211 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1212 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
1216 * Start a peer that has previously been stopped using the daemon_stop
1217 * call (and files weren't deleted and the allow restart flag)
1219 * @param daemon the daemon to start (has been previously stopped)
1220 * @param timeout how long to wait for restart
1221 * @param cb the callback for notification when the peer is running
1222 * @param cb_cls closure for the callback
1225 GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
1226 struct GNUNET_TIME_Relative timeout,
1227 GNUNET_TESTING_NotifyDaemonRunning cb,
1230 if (daemon->running == GNUNET_YES)
1232 cb (cb_cls, &daemon->id, daemon->cfg, daemon,
1233 "Daemon already running, can't restart!");
1238 daemon->cb_cls = cb_cls;
1239 daemon->phase = SP_TOPOLOGY_SETUP;
1240 daemon->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1242 GNUNET_SCHEDULER_add_continuation (&start_fsm,
1244 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1248 * Starts a GNUnet daemon. GNUnet must be installed on the target
1249 * system and available in the PATH. The machine must furthermore be
1250 * reachable via "ssh" (unless the hostname is "NULL") without the
1251 * need to enter a password.
1253 * @param cfg configuration to use
1254 * @param timeout how long to wait starting up peers
1255 * @param pretend GNUNET_YES to set up files but not start peer GNUNET_NO
1256 * to really start the peer (default)
1257 * @param hostname name of the machine where to run GNUnet
1258 * (use NULL for localhost).
1259 * @param ssh_username ssh username to use when connecting to hostname
1260 * @param sshport port to pass to ssh process when connecting to hostname
1261 * @param hostkey pointer to a hostkey to be written to disk (instead of being generated)
1262 * @param hostkey_callback function to call once the hostkey has been
1263 * generated for this peer, but it hasn't yet been started
1264 * (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
1265 * @param hostkey_cls closure for hostkey callback
1266 * @param cb function to call once peer is up, or failed to start
1267 * @param cb_cls closure for cb
1268 * @return handle to the daemon (actual start will be completed asynchronously)
1270 struct GNUNET_TESTING_Daemon *
1271 GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
1272 struct GNUNET_TIME_Relative timeout,
1274 const char *hostname,
1275 const char *ssh_username,
1277 const char *hostkey,
1278 GNUNET_TESTING_NotifyHostkeyCreated
1279 hostkey_callback, void *hostkey_cls,
1280 GNUNET_TESTING_NotifyDaemonRunning cb,
1283 struct GNUNET_TESTING_Daemon *ret;
1287 char *baseservicehome;
1290 char *temp_file_name;
1291 struct GNUNET_DISK_FileHandle *fn;
1292 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
1293 struct GNUNET_CRYPTO_RsaPrivateKey *private_key;
1295 ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
1296 ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
1299 GNUNET_asprintf (&ret->ssh_port_str, "%d", sshport);
1302 ret->ssh_port_str = NULL;
1304 /* Find service home and base service home directories, create it if it doesn't exist */
1305 GNUNET_assert(GNUNET_OK ==
1306 GNUNET_CONFIGURATION_get_value_string (cfg,
1311 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_create (servicehome));
1312 GNUNET_asprintf(&temp_file_name, "%s/gnunet-testing-config", servicehome);
1313 ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name);
1314 GNUNET_free(temp_file_name);
1316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1317 "Setting up peer with configuration file `%s'.\n",
1320 if (NULL == ret->cfgfile)
1322 GNUNET_free_non_null (ret->ssh_port_str);
1323 GNUNET_free_non_null (ret->hostname);
1327 ret->hostkey_callback = hostkey_callback;
1328 ret->hostkey_cls = hostkey_cls;
1330 ret->cb_cls = cb_cls;
1331 ret->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1332 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
1333 GNUNET_CONFIGURATION_set_value_string (ret->cfg,
1335 "DEFAULTCONFIG", ret->cfgfile);
1337 if (hostkey != NULL) /* Get the peer identity from the hostkey */
1339 private_key = GNUNET_CRYPTO_rsa_decode_key(hostkey, HOSTKEYFILESIZE);
1340 GNUNET_assert(private_key != NULL);
1341 GNUNET_CRYPTO_rsa_key_get_public (private_key,
1343 GNUNET_CRYPTO_hash(&public_key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &ret->id.hashPubKey);
1344 ret->shortname = GNUNET_strdup(GNUNET_i2s(&ret->id));
1345 ret->have_hostkey = GNUNET_YES;
1346 GNUNET_CRYPTO_rsa_key_free(private_key);
1349 /* Write hostkey to file, if we were given one */
1351 if (hostkey != NULL)
1353 GNUNET_asprintf(&hostkeyfile, "%s/.hostkey", servicehome);
1355 GNUNET_DISK_file_open (hostkeyfile,
1356 GNUNET_DISK_OPEN_READWRITE
1357 | GNUNET_DISK_OPEN_CREATE,
1358 GNUNET_DISK_PERM_USER_READ |
1359 GNUNET_DISK_PERM_USER_WRITE);
1360 GNUNET_assert(fn != NULL);
1361 GNUNET_assert(HOSTKEYFILESIZE == GNUNET_DISK_file_write(fn, hostkey, HOSTKEYFILESIZE));
1362 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fn));
1365 /* write configuration to temporary file */
1366 if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
1368 if (0 != UNLINK (ret->cfgfile))
1369 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1370 "unlink", ret->cfgfile);
1371 GNUNET_CONFIGURATION_destroy (ret->cfg);
1372 GNUNET_free_non_null (ret->hostname);
1373 GNUNET_free (ret->cfgfile);
1377 if (ssh_username != NULL)
1378 username = GNUNET_strdup (ssh_username);
1379 if ((ssh_username == NULL) && (GNUNET_OK !=
1380 GNUNET_CONFIGURATION_get_value_string (cfg,
1385 if (NULL != getenv ("USER"))
1386 username = GNUNET_strdup (getenv ("USER"));
1390 ret->username = username;
1392 if (GNUNET_NO == pretend) /* Copy files, enter finite state machine */
1394 /* copy directory to remote host */
1395 if (NULL != hostname)
1398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1399 "Copying configuration directory to host `%s'.\n", hostname);
1401 baseservicehome = GNUNET_strdup(servicehome);
1402 /* Remove trailing /'s */
1403 while (baseservicehome[strlen(baseservicehome) - 1] == '/')
1404 baseservicehome[strlen(baseservicehome) - 1] = '\0';
1405 /* Find next directory /, jump one ahead */
1406 slash = strrchr(baseservicehome, '/');
1410 ret->phase = SP_COPYING;
1411 if (NULL != username)
1412 GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, baseservicehome);
1414 GNUNET_asprintf (&arg, "%s:%s", hostname, baseservicehome);
1415 GNUNET_free(baseservicehome);
1416 if (ret->ssh_port_str == NULL)
1418 ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r",
1422 servicehome, arg, NULL);
1424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1425 "copying directory with command scp -r %s %s\n",
1432 ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp",
1433 "scp", "-r", "-P", ret->ssh_port_str,
1437 servicehome, arg, NULL);
1440 if (NULL == ret->proc)
1442 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1444 ("Could not start `%s' process to copy configuration directory.\n"),
1446 if (0 != UNLINK (ret->cfgfile))
1447 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1448 "unlink", ret->cfgfile);
1449 GNUNET_CONFIGURATION_destroy (ret->cfg);
1450 GNUNET_free_non_null (ret->hostname);
1451 GNUNET_free_non_null (ret->username);
1452 GNUNET_free (ret->cfgfile);
1454 if ((hostkey != NULL) && (0 != UNLINK(hostkeyfile)))
1455 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1456 "unlink", hostkeyfile);
1457 GNUNET_free_non_null(hostkeyfile);
1458 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (servicehome));
1459 GNUNET_free(servicehome);
1464 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
1466 GNUNET_free_non_null(hostkeyfile);
1467 GNUNET_free(servicehome);
1471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1472 "No need to copy configuration file since we are running locally.\n");
1474 ret->phase = SP_COPIED;
1475 GNUNET_SCHEDULER_add_continuation (&start_fsm,
1477 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1479 GNUNET_free_non_null(hostkeyfile);
1480 GNUNET_free(servicehome);
1486 * Restart (stop and start) a GNUnet daemon.
1488 * @param d the daemon that should be restarted
1489 * @param cb function called once the daemon is (re)started
1490 * @param cb_cls closure for cb
1493 GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
1494 GNUNET_TESTING_NotifyDaemonRunning cb,
1503 d->dead = GNUNET_YES;
1510 if (d->phase == SP_CONFIG_UPDATE)
1512 GNUNET_SCHEDULER_cancel (d->task);
1513 d->phase = SP_START_DONE;
1515 if (d->server != NULL)
1517 GNUNET_CORE_disconnect (d->server);
1523 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
1524 GNUNET_TRANSPORT_disconnect (d->th);
1527 /* state clean up and notifications */
1528 GNUNET_free_non_null (d->hello);
1531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1532 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
1535 d->phase = SP_START_ARMING;
1537 /* Check if this is a local or remote process */
1538 if (NULL != d->hostname)
1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1542 "Stopping gnunet-arm with config `%s' on host `%s'.\n",
1543 d->cfgfile, d->hostname);
1546 if (d->username != NULL)
1547 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1549 arg = GNUNET_strdup (d->hostname);
1551 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1559 "-c", d->cfgfile, "-e", "-r", NULL);
1560 /* Use -r to restart arm and all services */
1567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1568 "Stopping gnunet-arm with config `%s' locally.\n",
1571 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
1576 "-c", d->cfgfile, "-e", "-r", NULL);
1579 GNUNET_free_non_null (del_arg);
1581 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
1588 * Stops a GNUnet daemon.
1590 * @param d the daemon that should be stopped
1591 * @param service the name of the service to stop
1592 * @param timeout how long to wait for process for shutdown to complete
1593 * @param cb function called once the daemon was stopped
1594 * @param cb_cls closure for cb
1595 * @param delete_files GNUNET_YES to remove files, GNUNET_NO
1597 * @param allow_restart GNUNET_YES to restart peer later (using this API)
1598 * GNUNET_NO to kill off and clean up for good
1601 GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d,
1603 struct GNUNET_TIME_Relative timeout,
1604 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
1608 d->dead_cb_cls = cb_cls;
1610 GNUNET_assert(d->running == GNUNET_YES);
1612 if (d->phase == SP_CONFIG_UPDATE)
1614 GNUNET_SCHEDULER_cancel (d->task);
1615 d->phase = SP_START_DONE;
1619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1620 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
1622 if (d->churned_services != NULL)
1624 d->dead_cb(d->dead_cb_cls, "A service has already been turned off!!");
1627 d->phase = SP_SERVICE_SHUTDOWN_START;
1628 d->churned_services = GNUNET_strdup(service);
1630 /* Check if this is a local or remote process */
1631 if (NULL != d->hostname)
1634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1635 "Stopping gnunet-arm with config `%s' on host `%s'.\n",
1636 d->cfgfile, d->hostname);
1639 if (d->username != NULL)
1640 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1642 arg = GNUNET_strdup (d->hostname);
1644 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1652 "-c", d->cfgfile, "-k", service, "-q",
1653 "-T", GNUNET_TIME_relative_to_string(timeout),
1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1656 "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k %s -q\n",
1657 arg, "gnunet-arm", d->cfgfile, service);
1663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1664 "Stopping gnunet-arm with config `%s' locally.\n",
1667 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
1672 "-c", d->cfgfile, "-k", service, "-q",
1673 "-T", GNUNET_TIME_relative_to_string(timeout),
1677 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1678 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
1683 * Stops a GNUnet daemon.
1685 * @param d the daemon that should be stopped
1686 * @param timeout how long to wait for process for shutdown to complete
1687 * @param cb function called once the daemon was stopped
1688 * @param cb_cls closure for cb
1689 * @param delete_files GNUNET_YES to remove files, GNUNET_NO
1691 * @param allow_restart GNUNET_YES to restart peer later (using this API)
1692 * GNUNET_NO to kill off and clean up for good
1695 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
1696 struct GNUNET_TIME_Relative timeout,
1697 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
1698 int delete_files, int allow_restart)
1703 d->dead_cb_cls = cb_cls;
1708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1709 _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id));
1711 d->dead = GNUNET_YES;
1715 if ((d->running == GNUNET_NO) && (d->churn == GNUNET_YES)) /* Peer has already been stopped in churn context! */
1717 /* Free what was left from churning! */
1718 GNUNET_assert (d->cfg != NULL);
1719 GNUNET_CONFIGURATION_destroy (d->cfg);
1720 if (delete_files == GNUNET_YES)
1722 if (0 != UNLINK (d->cfgfile))
1724 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "unlink");
1727 GNUNET_free (d->cfgfile);
1728 GNUNET_free_non_null (d->hostname);
1729 GNUNET_free_non_null (d->username);
1730 if (NULL != d->dead_cb)
1731 d->dead_cb (d->dead_cb_cls, NULL);
1737 if (delete_files == GNUNET_YES)
1739 GNUNET_asprintf (&del_arg, "-d");
1742 if (d->phase == SP_CONFIG_UPDATE)
1744 GNUNET_SCHEDULER_cancel (d->task);
1745 d->phase = SP_START_DONE;
1747 /** Move this call to scheduled shutdown as fix for CORE_connect calling daemon_stop?
1748 if (d->server != NULL)
1750 GNUNET_CORE_disconnect (d->server);
1754 /* shutdown ARM process (will terminate others) */
1756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1757 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
1759 d->phase = SP_SHUTDOWN_START;
1760 d->running = GNUNET_NO;
1761 if (allow_restart == GNUNET_YES)
1762 d->churn = GNUNET_YES;
1765 GNUNET_TRANSPORT_get_hello_cancel (d->th, &process_hello, d);
1766 GNUNET_TRANSPORT_disconnect (d->th);
1769 /* Check if this is a local or remote process */
1770 if (NULL != d->hostname)
1773 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1774 "Stopping gnunet-arm with config `%s' on host `%s'.\n",
1775 d->cfgfile, d->hostname);
1778 if (d->username != NULL)
1779 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
1781 arg = GNUNET_strdup (d->hostname);
1783 d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
1791 "-c", d->cfgfile, "-e", "-q",
1792 "-T", GNUNET_TIME_relative_to_string(timeout),
1794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1795 "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -e -q %s\n",
1796 arg, "gnunet-arm", d->cfgfile, del_arg);
1797 /* Use -e to end arm, and -d to remove temp files */
1803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1804 "Stopping gnunet-arm with config `%s' locally.\n",
1807 d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
1812 "-c", d->cfgfile, "-e", "-q",
1813 "-T", GNUNET_TIME_relative_to_string(timeout),
1817 GNUNET_free_non_null (del_arg);
1818 d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1819 d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d);
1824 * Changes the configuration of a GNUnet daemon.
1826 * @param d the daemon that should be modified
1827 * @param cfg the new configuration for the daemon
1828 * @param cb function called once the configuration was changed
1829 * @param cb_cls closure for cb
1832 GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
1833 struct GNUNET_CONFIGURATION_Handle *cfg,
1834 GNUNET_TESTING_NotifyCompletion cb,
1839 if (d->phase != SP_START_DONE)
1844 ("Peer not yet running, can not change configuration at this point."));
1848 /* 1) write configuration to temporary file */
1849 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile))
1852 cb (cb_cls, _("Failed to write new configuration to disk."));
1856 /* 2) copy file to remote host (if necessary) */
1857 if (NULL == d->hostname)
1859 /* signal success */
1865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1866 "Copying updated configuration file to remote host `%s'.\n",
1869 d->phase = SP_CONFIG_UPDATE;
1870 if (NULL != d->username)
1871 GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile);
1873 GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile);
1874 d->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp",
1878 d->cfgfile, arg, NULL);
1880 if (NULL == d->proc)
1882 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1884 ("Could not start `%s' process to copy configuration file.\n"),
1887 cb (cb_cls, _("Failed to copy new configuration to remote machine."));
1888 d->phase = SP_START_DONE;
1892 d->update_cb_cls = cb_cls;
1894 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
1900 * Data kept for each pair of peers that we try
1903 struct ConnectContext
1906 * Testing handle to the first daemon.
1908 struct GNUNET_TESTING_Daemon *d1;
1911 * Handle to core of first daemon (to check connect)
1913 struct GNUNET_CORE_Handle *d1core;
1916 * Have we actually connected to the core of the first daemon yet?
1921 * Testing handle to the second daemon.
1923 struct GNUNET_TESTING_Daemon *d2;
1926 * Handler for the request to core to connect to this peer.
1928 struct GNUNET_CORE_PeerRequestHandle *connect_request_handle;
1931 * Transport handle to the first daemon (to offer the HELLO of the second daemon to).
1933 struct GNUNET_TRANSPORT_Handle *d1th;
1936 * Function to call once we are done (or have timed out).
1938 GNUNET_TESTING_NotifyConnection cb;
1946 * The relative timeout from whence this connect attempt was
1947 * started. Allows for reconnect attempts.
1949 struct GNUNET_TIME_Relative relative_timeout;
1952 * Maximum number of connect attempts, will retry connection
1953 * this number of times on failures.
1955 unsigned int connect_attempts;
1958 * Hello timeout task
1960 GNUNET_SCHEDULER_TaskIdentifier hello_send_task;
1963 * Connect timeout task
1965 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
1968 * When should this operation be complete (or we must trigger
1971 struct GNUNET_TIME_Relative timeout_hello;
1974 * Was the connection attempt successful?
1979 * When connecting, do we need to send the HELLO?
1984 * The distance between the two connected peers
1990 /** Forward declaration **/
1992 reattempt_daemons_connect (void *cls,
1993 const struct GNUNET_SCHEDULER_TaskContext *tc);
1997 * Notify callback about success or failure of the attempt
1998 * to connect the two peers
2000 * @param cls our "struct ConnectContext" (freed)
2001 * @param tc reason tells us if we succeeded or failed
2004 notify_connect_result (void *cls,
2005 const struct GNUNET_SCHEDULER_TaskContext *tc)
2007 struct ConnectContext *ctx = cls;
2008 ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2009 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
2011 GNUNET_SCHEDULER_cancel (ctx->hello_send_task);
2012 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
2015 if (ctx->connect_request_handle != NULL)
2017 GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle);
2018 ctx->connect_request_handle = NULL;
2021 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
2023 if (ctx->d1th != NULL)
2024 GNUNET_TRANSPORT_disconnect (ctx->d1th);
2026 if (ctx->d1core != NULL)
2027 GNUNET_CORE_disconnect (ctx->d1core);
2029 if (ctx->d2core != NULL)
2030 GNUNET_CORE_disconnect (ctx->d2core);
2038 if (ctx->d1th != NULL)
2039 GNUNET_TRANSPORT_disconnect (ctx->d1th);
2041 if (ctx->d1core != NULL)
2042 GNUNET_CORE_disconnect (ctx->d1core);
2045 if (ctx->connected == GNUNET_YES)
2047 if (ctx->cb != NULL)
2049 ctx->cb (ctx->cb_cls,
2053 ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
2056 else if (ctx->connect_attempts > 0)
2058 ctx->d1core_ready = GNUNET_NO;
2060 if (ctx->d2core != NULL)
2062 GNUNET_CORE_disconnect (ctx->d2core);
2066 GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx);
2071 if (ctx->cb != NULL)
2073 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2074 ctx->d2->cfg, ctx->d1, ctx->d2,
2075 _("Peers failed to connect"));
2084 * Success, connection is up. Signal client our success.
2086 * @param cls our "struct ConnectContext"
2087 * @param peer identity of the peer that has connected
2088 * @param atsi performance information
2092 connect_notify (void *cls,
2093 const struct GNUNET_PeerIdentity *peer,
2094 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2096 struct ConnectContext *ctx = cls;
2099 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2100 "Connected peer %s to peer %s\n",
2101 ctx->d1->shortname, GNUNET_i2s(peer));
2104 if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))
2107 ctx->connected = GNUNET_YES;
2108 ctx->distance = 0; /* FIXME: distance */
2109 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
2111 GNUNET_SCHEDULER_cancel(ctx->hello_send_task);
2112 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
2114 GNUNET_SCHEDULER_cancel (ctx->timeout_task);
2115 ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result,
2122 * Success, connection is up. Signal client our success.
2124 * @param cls our "struct ConnectContext"
2125 * @param peer identity of the peer that has connected
2126 * @param atsi performance information
2130 connect_notify_core2 (void *cls,
2131 const struct GNUNET_PeerIdentity *peer,
2132 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2134 struct ConnectContext *ctx = cls;
2136 if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0)
2138 ctx->connected = GNUNET_YES;
2139 ctx->distance = 0; /* FIXME: distance */
2140 GNUNET_SCHEDULER_cancel (ctx->timeout_task);
2141 ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result,
2149 * Task called once a core connect request has been transmitted.
2151 * @param cls struct ConnectContext
2152 * @param success was the request successful?
2155 core_connect_request_cont (void *cls,
2158 struct ConnectContext *ctx = cls;
2160 ctx->connect_request_handle = NULL;
2164 send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2166 struct ConnectContext *ctx = cls;
2167 struct GNUNET_MessageHeader *hello;
2168 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
2169 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
2171 if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL)
2172 && (NULL != GNUNET_HELLO_get_header (ctx->d2->hello))
2173 && (ctx->d1->phase == SP_START_DONE)
2174 && (ctx->d2->phase == SP_START_DONE))
2176 hello = GNUNET_HELLO_get_header (ctx->d2->hello);
2177 GNUNET_assert (hello != NULL);
2179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Offering hello of %s to %s\n", ctx->d2->shortname, ctx->d1->shortname);
2181 GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL);
2182 GNUNET_assert (ctx->d1core != NULL);
2183 ctx->connect_request_handle =
2184 GNUNET_CORE_peer_request_connect (ctx->d1core,
2186 &core_connect_request_cont, ctx);
2189 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2190 "Sending connect request to CORE of %s for peer %s\n",
2191 GNUNET_i2s (&ctx->d1->id),
2192 GNUNET_h2s (&ctx->d2->id.hashPubKey));
2194 ctx->timeout_hello =
2195 GNUNET_TIME_relative_add (ctx->timeout_hello,
2196 GNUNET_TIME_relative_multiply
2197 (GNUNET_TIME_UNIT_MILLISECONDS, 500));
2199 ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed (ctx->timeout_hello,
2204 * Notify of a successful connection to the core service.
2206 * @param cls a ConnectContext
2207 * @param server handle to the core service
2208 * @param my_identity the peer identity of this peer
2209 * @param publicKey the public key of the peer
2212 core_init_notify (void *cls,
2213 struct GNUNET_CORE_Handle * server,
2214 const struct GNUNET_PeerIdentity *
2217 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
2220 struct ConnectContext *connect_ctx = cls;
2221 connect_ctx->d1core_ready = GNUNET_YES;
2223 if (connect_ctx->send_hello == GNUNET_NO)
2225 connect_ctx->connect_request_handle =
2226 GNUNET_CORE_peer_request_connect (connect_ctx->d1core,
2227 &connect_ctx->d2->id,
2228 &core_connect_request_cont, connect_ctx);
2229 GNUNET_assert(connect_ctx->connect_request_handle != NULL);
2231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2232 "Sending connect request to CORE of %s for peer %s\n",
2233 connect_ctx->d1->shortname,
2234 connect_ctx->d2->shortname);
2242 reattempt_daemons_connect (void *cls,
2243 const struct GNUNET_SCHEDULER_TaskContext *tc)
2245 struct ConnectContext *ctx = cls;
2246 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
2251 #if DEBUG_TESTING_RECONNECT
2252 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2253 "re-attempting connect of peer %s to peer %s\n",
2254 ctx->d1->shortname, ctx->d2->shortname);
2256 ctx->connect_attempts--;
2257 GNUNET_assert (ctx->d1core == NULL);
2258 ctx->d1core_ready = GNUNET_NO;
2259 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
2262 &connect_notify, NULL, NULL,
2264 NULL, GNUNET_NO, no_handlers);
2265 if (ctx->d1core == NULL)
2267 if (NULL != ctx->cb)
2268 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2269 ctx->d2->cfg, ctx->d1, ctx->d2,
2270 _("Failed to connect to core service of first peer!\n"));
2275 /* Don't know reason for initial connect failure, update the HELLO for the second peer */
2276 if (NULL != ctx->d2->hello)
2278 GNUNET_free(ctx->d2->hello);
2279 ctx->d2->hello = NULL;
2280 if (NULL != ctx->d2->th)
2282 GNUNET_TRANSPORT_get_hello_cancel(ctx->d2->th, &process_hello, ctx->d2);
2283 GNUNET_TRANSPORT_disconnect(ctx->d2->th);
2285 ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL);
2286 GNUNET_assert(ctx->d2->th != NULL);
2287 GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
2290 if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL))
2292 ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL);
2293 if (ctx->d2->th == NULL)
2295 GNUNET_CORE_disconnect (ctx->d1core);
2297 if (NULL != ctx->cb)
2298 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
2299 _("Failed to connect to transport service!\n"));
2302 GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
2305 if (ctx->send_hello == GNUNET_YES)
2307 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
2309 ctx->d1, NULL, NULL, NULL);
2310 if (ctx->d1th == NULL)
2312 GNUNET_CORE_disconnect (ctx->d1core);
2314 if (NULL != ctx->cb)
2315 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
2316 ctx->d2->cfg, ctx->d1, ctx->d2,
2317 _("Failed to connect to transport service!\n"));
2320 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
2324 ctx->connect_request_handle =
2325 GNUNET_CORE_peer_request_connect (ctx->d1core,
2327 &core_connect_request_cont, ctx);
2330 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
2331 ¬ify_connect_result, ctx);
2335 * Iterator for currently known peers, to ensure
2336 * that we don't try to send duplicate connect
2339 * @param cls our "struct ConnectContext"
2340 * @param peer identity of the peer that has connected,
2341 * NULL when iteration has finished
2342 * @param atsi performance information
2346 core_initial_iteration (void *cls,
2347 const struct GNUNET_PeerIdentity *peer,
2348 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2350 struct ConnectContext *ctx = cls;
2352 if ((peer != NULL) &&
2353 (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))))
2355 ctx->connected = GNUNET_YES;
2356 ctx->distance = 0; /* FIXME: distance */
2359 else if (peer == NULL) /* End of iteration over peers */
2361 if (ctx->connected == GNUNET_YES)
2363 ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result,
2368 /* Peer not already connected, need to schedule connect request! */
2369 if (ctx->d1core == NULL)
2372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2373 "Peers are NOT connected, connecting to core!\n");
2375 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
2378 &connect_notify, NULL, NULL,
2380 NULL, GNUNET_NO, no_handlers);
2383 if (ctx->d1core == NULL)
2386 if (NULL != ctx->cb)
2387 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
2388 _("Failed to connect to core service of first peer!\n"));
2392 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 */
2394 ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL);
2395 if (ctx->d2->th == NULL)
2397 GNUNET_CORE_disconnect (ctx->d1core);
2399 if (NULL != ctx->cb)
2400 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
2401 _("Failed to connect to transport service!\n"));
2404 GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
2407 if (ctx->send_hello == GNUNET_YES)
2409 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
2410 &ctx->d1->id, ctx->d1, NULL, 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, ctx->d2->cfg, ctx->d1, ctx->d2,
2417 _("Failed to connect to transport service!\n"));
2420 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
2424 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
2425 ¬ify_connect_result, ctx);
2431 * Establish a connection between two GNUnet daemons.
2433 * @param d1 handle for the first daemon
2434 * @param d2 handle for the second daemon
2435 * @param timeout how long is the connection attempt
2437 * @param max_connect_attempts how many times should we try to reconnect
2439 * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume
2440 * the HELLO has already been exchanged
2441 * @param cb function to call at the end
2442 * @param cb_cls closure for cb
2445 GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
2446 struct GNUNET_TESTING_Daemon *d2,
2447 struct GNUNET_TIME_Relative timeout,
2448 unsigned int max_connect_attempts,
2450 GNUNET_TESTING_NotifyConnection cb,
2453 struct ConnectContext *ctx;
2455 if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO))
2458 cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2,
2459 _("Peers are not fully running yet, can not connect!\n"));
2460 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n");
2464 ctx = GNUNET_malloc (sizeof (struct ConnectContext));
2467 ctx->timeout_hello =
2468 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500);
2469 ctx->relative_timeout = GNUNET_TIME_relative_divide(timeout, max_connect_attempts);
2471 ctx->cb_cls = cb_cls;
2472 ctx->connect_attempts = max_connect_attempts;
2473 ctx->connected = GNUNET_NO;
2474 ctx->send_hello = send_hello;
2476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2477 "Asked to connect peer %s to peer %s\n",
2478 d1->shortname, d2->shortname);
2481 /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */
2482 GNUNET_assert(GNUNET_OK == GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, &core_initial_iteration, ctx));
2483 /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg, &core_initial_iteration, ctx));*/
2486 /* end of testing.c */