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 2, 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
32 * - modify configuration to allow 2087-connections from
33 * controlling host (otherwise shutdown won't work)
37 #include "gnunet_arm_service.h"
38 #include "gnunet_core_service.h"
39 #include "gnunet_constants.h"
40 #include "gnunet_testing_lib.h"
41 #include "gnunet_transport_service.h"
43 #define DEBUG_TESTING GNUNET_NO
46 * How long do we wait after starting gnunet-service-arm
47 * for the core service to be alive?
49 #define ARM_START_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
52 * How many times are we willing to try to wait for "scp" or
53 * "gnunet-service-arm" to complete (waitpid) before giving up?
55 #define MAX_EXEC_WAIT_RUNS 50
58 * Phases of starting GNUnet on a system.
63 * Copy the configuration file to the target system.
68 * Configuration file has been copied, start ARM on target system.
73 * ARM has been started, check that it has properly daemonized and
74 * then try to connect to the CORE service (which should be
75 * auto-started by ARM).
80 * We're waiting for CORE to start.
85 * Core has notified us that we've established a connection to the service.
86 * The main FSM halts here and waits to be moved to UPDATE or CLEANUP.
91 * We've been asked to terminate the instance and are now waiting for
92 * the remote command to delete the configuration file to complete.
97 * We've received a configuration update and are currently waiting for
98 * the copy process for the update to complete. Once it is, we will
99 * return to "SP_START_DONE" (and rely on ARM to restart all affected
107 * Handle for a GNUnet daemon (technically a set of
108 * daemons; the handle is really for the master ARM
109 * daemon) started by the testing library.
111 struct GNUNET_TESTING_Daemon
116 struct GNUNET_SCHEDULER_Handle *sched;
121 struct GNUNET_CONFIGURATION_Handle *cfg;
124 * Host to run GNUnet on.
128 /* Result of GNUNET_i2s of this peer, for printing */
132 * Username we are using.
137 * Name of the configuration file
142 * Function to call when the peer is running.
144 GNUNET_TESTING_NotifyDaemonRunning cb;
152 * Arguments from "daemon_stop" call.
154 GNUNET_TESTING_NotifyCompletion dead_cb;
157 * Closure for 'dead_cb'.
162 * Arguments from "daemon_stop" call.
164 GNUNET_TESTING_NotifyCompletion update_cb;
167 * Closure for 'update_cb'.
172 * Identity of this peer (once started).
174 struct GNUNET_PeerIdentity id;
177 * Flag to indicate that we've already been asked
178 * to terminate (but could not because some action
179 * was still pending).
184 * PID of the process that we started last.
189 * How many iterations have we been waiting for
190 * the started process to complete?
192 unsigned int wait_runs;
195 * In which phase are we during the start of
198 enum StartPhase phase;
201 * ID of the current task.
203 GNUNET_SCHEDULER_TaskIdentifier task;
206 * Handle to the server.
208 struct GNUNET_CORE_Handle *server;
213 * Function called after GNUNET_CORE_connect has succeeded
214 * (or failed for good). Note that the private key of the
215 * peer is intentionally not exposed here; if you need it,
216 * your process should try to read the private key file
217 * directly (which should work if you are authorized...).
220 * @param server handle to the server, NULL if we failed
221 * @param my_identity ID of this peer, NULL if we failed
222 * @param publicKey public key of this peer, NULL if we failed
225 testing_init (void *cls,
226 struct GNUNET_CORE_Handle *server,
227 const struct GNUNET_PeerIdentity *my_identity,
228 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
230 struct GNUNET_TESTING_Daemon *d = cls;
231 GNUNET_TESTING_NotifyDaemonRunning cb;
233 GNUNET_assert (d->phase == SP_START_CORE);
234 d->phase = SP_START_DONE;
240 if (GNUNET_YES == d->dead)
241 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
243 cb (d->cb_cls, NULL, d->cfg, d,
244 _("Failed to connect to core service\n"));
248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
249 "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity));
251 d->id = *my_identity;
252 d->shortname = strdup (GNUNET_i2s (my_identity));
254 if (GNUNET_YES == d->dead)
255 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
257 cb (d->cb_cls, my_identity, d->cfg, d, NULL);
262 * Finite-state machine for starting GNUnet.
264 * @param cls our "struct GNUNET_TESTING_Daemon"
268 start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
270 static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
271 struct GNUNET_TESTING_Daemon *d = cls;
272 GNUNET_TESTING_NotifyDaemonRunning cb;
273 enum GNUNET_OS_ProcessStatusType type;
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
279 "Peer FSM is in phase %u.\n", d->phase);
281 d->task = GNUNET_SCHEDULER_NO_TASK;
285 /* confirm copying complete */
286 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
289 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
296 d->cfg, d, _("`scp' does not seem to terminate.\n"));
301 = GNUNET_SCHEDULER_add_delayed (d->sched,
302 GNUNET_CONSTANTS_EXEC_WAIT,
306 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
312 NULL, d->cfg, d, _("`scp' did not complete cleanly.\n"));
316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
317 "Successfully copied configuration file.\n");
319 d->phase = SP_COPIED;
322 /* start GNUnet on remote host */
323 if (NULL == d->hostname)
325 d->pid = GNUNET_OS_start_process ("gnunet-service-arm",
326 "gnunet-service-arm",
335 if (d->username != NULL)
336 GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
338 dst = GNUNET_strdup (d->hostname);
339 d->pid = GNUNET_OS_start_process ("ssh",
342 "gnunet-service-arm",
343 "-c", d->cfgfile, "-d", NULL);
348 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
349 _("Could not start `%s' process to start GNUnet.\n"),
350 (NULL == d->hostname) ? "gnunet-service-arm" : "ssh");
358 (NULL == d->hostname)
359 ? _("Failed to start `gnunet-service-arm' process.\n")
360 : _("Failed to start `ssh' process.\n"));
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
364 "Started `%s', waiting for `%s' to be up.\n",
365 "gnunet-service-arm", "gnunet-service-core");
367 d->phase = SP_START_ARMING;
370 = GNUNET_SCHEDULER_add_delayed (d->sched,
371 GNUNET_CONSTANTS_EXEC_WAIT,
374 case SP_START_ARMING:
375 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
378 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
387 (NULL == d->hostname)
388 ? _("`gnunet-service-arm' does not seem to terminate.\n")
389 : _("`ssh' does not seem to terminate.\n"));
394 = GNUNET_SCHEDULER_add_delayed (d->sched,
395 GNUNET_CONSTANTS_EXEC_WAIT,
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
401 "Successfully started `%s'.\n", "gnunet-service-arm");
403 d->phase = SP_START_CORE;
404 d->server = GNUNET_CORE_connect (d->sched,
411 NULL, GNUNET_NO, no_handlers);
420 /* confirm copying complete */
421 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
424 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
426 d->dead_cb (d->dead_cb_cls,
427 _("`ssh' does not seem to terminate.\n"));
428 GNUNET_free (d->cfgfile);
429 GNUNET_free_non_null (d->hostname);
430 GNUNET_free_non_null (d->username);
436 = GNUNET_SCHEDULER_add_delayed (d->sched,
437 GNUNET_CONSTANTS_EXEC_WAIT,
441 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
443 if (NULL != d->dead_cb)
444 d->dead_cb (d->dead_cb_cls,
445 _("`ssh' did not complete cleanly.\n"));
446 GNUNET_free (d->cfgfile);
447 GNUNET_free_non_null (d->hostname);
448 GNUNET_free_non_null (d->username);
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
455 GNUNET_free (d->cfgfile);
456 GNUNET_free_non_null (d->hostname);
457 GNUNET_free_non_null (d->username);
458 if (NULL != d->dead_cb)
459 d->dead_cb (d->dead_cb_cls, NULL);
462 case SP_CONFIG_UPDATE:
463 /* confirm copying complete */
464 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
467 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
474 d->cfg, d, _("`scp' does not seem to terminate.\n"));
479 = GNUNET_SCHEDULER_add_delayed (d->sched,
480 GNUNET_CONSTANTS_EXEC_WAIT,
484 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
486 if (NULL != d->update_cb)
487 d->update_cb (d->update_cb_cls,
488 _("`scp' did not complete cleanly.\n"));
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
493 "Successfully copied configuration file.\n");
495 if (NULL != d->update_cb)
496 d->update_cb (d->update_cb_cls, NULL);
497 d->phase = SP_START_DONE;
504 * Starts a GNUnet daemon. GNUnet must be installed on the target
505 * system and available in the PATH. The machine must furthermore be
506 * reachable via "ssh" (unless the hostname is "NULL") without the
507 * need to enter a password.
509 * @param sched scheduler to use
510 * @param cfg configuration to use
511 * @param hostname name of the machine where to run GNUnet
512 * (use NULL for localhost).
513 * @param cb function to call with the result
514 * @param cb_cls closure for cb
515 * @return handle to the daemon (actual start will be completed asynchronously)
517 struct GNUNET_TESTING_Daemon *
518 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
519 const struct GNUNET_CONFIGURATION_Handle *cfg,
520 const char *hostname,
521 GNUNET_TESTING_NotifyDaemonRunning cb,
524 struct GNUNET_TESTING_Daemon *ret;
528 ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
530 ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
531 ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
534 "Setting up peer with configuration file `%s'.\n",
537 if (NULL == ret->cfgfile)
539 GNUNET_free_non_null (ret->hostname);
544 ret->cb_cls = cb_cls;
545 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
546 GNUNET_CONFIGURATION_set_value_string (ret->cfg,
548 "DEFAULTCONFIG", ret->cfgfile);
549 /* 1) write configuration to temporary file */
550 if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
552 if (0 != UNLINK (ret->cfgfile))
553 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
554 "unlink", ret->cfgfile);
555 GNUNET_CONFIGURATION_destroy (ret->cfg);
556 GNUNET_free_non_null (ret->hostname);
557 GNUNET_free (ret->cfgfile);
562 GNUNET_CONFIGURATION_get_value_string (cfg,
564 "USERNAME", &username))
566 if (NULL != getenv ("USER"))
567 username = GNUNET_strdup (getenv ("USER"));
571 ret->username = username;
573 /* 2) copy file to remote host */
574 if (NULL != hostname)
577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "Copying configuration file to host `%s'.\n", hostname);
580 ret->phase = SP_COPYING;
581 if (NULL != username)
582 GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile);
584 GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
585 ret->pid = GNUNET_OS_start_process ("scp",
586 "scp", ret->cfgfile, arg, NULL);
590 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
592 ("Could not start `%s' process to copy configuration file.\n"),
594 if (0 != UNLINK (ret->cfgfile))
595 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
596 "unlink", ret->cfgfile);
597 GNUNET_CONFIGURATION_destroy (ret->cfg);
598 GNUNET_free_non_null (ret->hostname);
599 GNUNET_free_non_null (ret->username);
600 GNUNET_free (ret->cfgfile);
605 = GNUNET_SCHEDULER_add_delayed (sched,
606 GNUNET_CONSTANTS_EXEC_WAIT,
611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
612 "No need to copy configuration file since we are running locally.\n");
614 ret->phase = SP_COPIED;
615 GNUNET_SCHEDULER_add_continuation (sched,
618 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
624 * Stops a GNUnet daemon.
626 * @param d the daemon that should be stopped
627 * @param cb function called once the daemon was stopped
628 * @param cb_cls closure for cb
631 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
632 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
634 struct GNUNET_CLIENT_Connection *cc;
639 d->dead = GNUNET_YES;
641 d->dead_cb_cls = cb_cls;
644 if (d->phase == SP_CONFIG_UPDATE)
646 GNUNET_SCHEDULER_cancel (d->sched, d->task);
647 d->phase = SP_START_DONE;
649 if (d->server != NULL)
651 GNUNET_CORE_disconnect (d->server);
654 /* shutdown ARM process (will also terminate others) */
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
659 cc = GNUNET_CLIENT_connect (d->sched, "arm", d->cfg);
660 GNUNET_CLIENT_service_shutdown (cc);
662 /* state clean up and notifications */
663 if (0 != UNLINK (d->cfgfile))
664 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
665 "unlink", d->cfgfile);
666 if (d->hostname != NULL)
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
670 "Removing configuration file on remote host `%s'.\n",
673 if (NULL != d->username)
674 GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
676 dst = GNUNET_strdup (d->hostname);
677 d->pid = GNUNET_OS_start_process ("ssh",
678 "ssh", dst, "rm", d->cfgfile, NULL);
682 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
684 ("Could not start `%s' process to delete configuration file.\n"),
686 GNUNET_free (d->cfgfile);
687 GNUNET_free_non_null (d->hostname);
688 GNUNET_free_non_null (d->username);
690 cb (cb_cls, _("Error cleaning up configuration file.\n"));
693 d->phase = SP_CLEANUP;
695 d->dead_cb_cls = cb_cls;
697 = GNUNET_SCHEDULER_add_delayed (d->sched,
698 GNUNET_CONSTANTS_EXEC_WAIT,
702 GNUNET_CONFIGURATION_destroy (d->cfg);
703 GNUNET_free (d->cfgfile);
704 GNUNET_free_non_null (d->hostname);
705 GNUNET_free_non_null (d->username);
713 * Changes the configuration of a GNUnet daemon.
715 * @param d the daemon that should be modified
716 * @param cfg the new configuration for the daemon
717 * @param cb function called once the configuration was changed
718 * @param cb_cls closure for cb
721 GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
722 struct GNUNET_CONFIGURATION_Handle *cfg,
723 GNUNET_TESTING_NotifyCompletion cb,
728 if (d->phase != SP_START_DONE)
733 ("Peer not yet running, can not change configuration at this point."));
737 /* 1) write configuration to temporary file */
738 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile))
741 cb (cb_cls, _("Failed to write new configuration to disk."));
745 /* 2) copy file to remote host (if necessary) */
746 if (NULL == d->hostname)
754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
755 "Copying updated configuration file to remote host `%s'.\n",
758 d->phase = SP_CONFIG_UPDATE;
759 if (NULL != d->username)
760 GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile);
762 GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile);
763 d->pid = GNUNET_OS_start_process ("scp", "scp", d->cfgfile, arg, NULL);
767 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
769 ("Could not start `%s' process to copy configuration file.\n"),
772 cb (cb_cls, _("Failed to copy new configuration to remote machine."));
773 d->phase = SP_START_DONE;
777 d->update_cb_cls = cb_cls;
779 = GNUNET_SCHEDULER_add_delayed (d->sched,
780 GNUNET_CONSTANTS_EXEC_WAIT,
786 * Data kept for each pair of peers that we try
789 struct ConnectContext
792 * Testing handle to the first daemon.
794 struct GNUNET_TESTING_Daemon *d1;
797 * Testing handle to the second daemon.
799 struct GNUNET_TESTING_Daemon *d2;
802 * Transport handle to the first daemon.
804 struct GNUNET_TRANSPORT_Handle *d1th;
807 * Transport handle to the second daemon.
809 struct GNUNET_TRANSPORT_Handle *d2th;
812 * Function to call once we are done (or have timed out).
814 GNUNET_TESTING_NotifyConnection cb;
822 * Transmit handle for our request for transmission
823 * (as given to d2 asking to talk to d1).
825 struct GNUNET_CORE_TransmitHandle *ntr;
828 * When should this operation be complete (or we must trigger
831 struct GNUNET_TIME_Absolute timeout;
837 * Notify callback about success or failure of the attempt
838 * to connect the two peers
840 * @param cls our "struct ConnectContext" (freed)
841 * @param tc reason tells us if we succeeded or failed
844 notify_connect_result (void *cls,
845 const struct GNUNET_SCHEDULER_TaskContext *tc)
847 struct ConnectContext *ctx = cls;
851 if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
852 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
853 ctx->d2->cfg, ctx->d1, ctx->d2,
854 _("Peers failed to connect"));
856 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
857 ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
864 * Success, connection is up. Signal client our success.
866 * @param cls our "struct ConnectContext"
867 * @param size number of bytes available in buf
868 * @param buf where to copy the message, NULL on error
869 * @return number of bytes copied to buf
872 transmit_ready (void *cls, size_t size, void *buf)
874 struct ConnectContext *ctx = cls;
877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
878 "Core notified us about readiness to transmit message, connection must be up!\n");
881 GNUNET_TRANSPORT_disconnect (ctx->d1th);
883 GNUNET_TRANSPORT_disconnect (ctx->d2th);
885 GNUNET_SCHEDULER_add_continuation (ctx->d1->sched,
886 ¬ify_connect_result,
889 GNUNET_SCHEDULER_REASON_TIMEOUT :
890 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
897 timeout_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
899 GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, &process_hello, ctx);
900 GNUNET_TRANSPORT_disconnect (ctx->d1th);
901 GNUNET_TRANSPORT_disconnect (ctx->d2th);
903 ctx->cb (ctx->cb_cls, _("Failed to receive `HELLO' from peer\n"));
910 * Receive the HELLO from one peer, give it to the other
911 * and ask them to connect.
913 * @param cls "struct ConnectContext"
914 * @param message HELLO message of peer
917 process_hello (void *cls, const struct GNUNET_MessageHeader *message)
919 struct ConnectContext *ctx = cls;
921 /* first of all, stop the notification stuff */
922 GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, &process_hello, ctx);
924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
925 "Received `%s' from transport service of `%4s'\n",
926 "HELLO", GNUNET_i2s (&ctx->d1->id));
928 GNUNET_assert (message != NULL);
929 GNUNET_TRANSPORT_offer_hello (ctx->d2th, message);
931 = GNUNET_CORE_notify_transmit_ready (ctx->d2->server,
933 GNUNET_TIME_absolute_get_remaining
934 (ctx->timeout), &ctx->d1->id,
935 sizeof (struct GNUNET_MessageHeader),
936 &transmit_ready, ctx);
940 * Accessor function since we have hidden what GNUNET_TESTING_Daemon is
942 * FIXME: Either expose members or figure out a better way!
945 GNUNET_TESTING_daemon_get_shortname (struct GNUNET_TESTING_Daemon *d)
951 * Establish a connection between two GNUnet daemons.
953 * @param d1 handle for the first daemon
954 * @param d2 handle for the second daemon
955 * @param timeout how long is the connection attempt
957 * @param cb function to call at the end
958 * @param cb_cls closure for cb
961 GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
962 struct GNUNET_TESTING_Daemon *d2,
963 struct GNUNET_TIME_Relative timeout,
964 GNUNET_TESTING_NotifyConnection cb,
967 struct ConnectContext *ctx;
969 if ((d1->server == NULL) || (d2->server == NULL))
972 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
973 _("Peers are not fully running yet, can not connect!\n"));
976 ctx = GNUNET_malloc (sizeof (struct ConnectContext));
979 ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
981 ctx->cb_cls = cb_cls;
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
984 "Asked to connect peer %s to peer %s\n",
985 d1->shortname, d2->shortname);
986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
987 "Connecting to transport service of peer %s\n", d1->shortname);
989 ctx->d1th = GNUNET_TRANSPORT_connect (d1->sched,
990 d1->cfg, d1, NULL, NULL, NULL);
991 if (ctx->d1th == NULL)
995 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
996 _("Failed to connect to transport service!\n"));
1000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1001 "Asked to connect peer %s to peer %s\n",
1002 d1->shortname, d2->shortname);
1003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1004 "Connecting to transport service of peer %s\n", d2->shortname);
1007 ctx->d2th = GNUNET_TRANSPORT_connect (d2->sched,
1008 d2->cfg, d2, NULL, NULL, NULL);
1009 if (ctx->d2th == NULL)
1011 GNUNET_TRANSPORT_disconnect (ctx->d1th);
1014 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
1015 _("Failed to connect to transport service!\n"));
1020 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1021 "Asking for hello from peer %s\n", GNUNET_i2s (&d1->id));
1023 /* FIXME: need to handle timeout: start timeout task
1024 as well here! (use 'timeout_hello_task') */
1025 GNUNET_TRANSPORT_get_hello (ctx->d1th, &process_hello, ctx);
1029 /* end of testing.c */