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
59 * Function called after GNUNET_CORE_connect has succeeded
60 * (or failed for good). Note that the private key of the
61 * peer is intentionally not exposed here; if you need it,
62 * your process should try to read the private key file
63 * directly (which should work if you are authorized...).
66 * @param server handle to the server, NULL if we failed
67 * @param my_identity ID of this peer, NULL if we failed
68 * @param publicKey public key of this peer, NULL if we failed
71 testing_init (void *cls,
72 struct GNUNET_CORE_Handle *server,
73 const struct GNUNET_PeerIdentity *my_identity,
74 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
76 struct GNUNET_TESTING_Daemon *d = cls;
77 GNUNET_TESTING_NotifyDaemonRunning cb;
79 GNUNET_assert (d->phase == SP_START_CORE);
80 d->phase = SP_START_DONE;
86 if (GNUNET_YES == d->dead)
87 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
89 cb (d->cb_cls, NULL, d->cfg, d,
90 _("Failed to connect to core service\n"));
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
95 "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity));
98 d->shortname = strdup (GNUNET_i2s (my_identity));
100 if (GNUNET_YES == d->dead)
101 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
103 cb (d->cb_cls, my_identity, d->cfg, d, NULL);
108 * Finite-state machine for starting GNUnet.
110 * @param cls our "struct GNUNET_TESTING_Daemon"
114 start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
116 static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
117 struct GNUNET_TESTING_Daemon *d = cls;
118 GNUNET_TESTING_NotifyDaemonRunning cb;
119 enum GNUNET_OS_ProcessStatusType type;
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
125 "Peer FSM is in phase %u.\n", d->phase);
127 d->task = GNUNET_SCHEDULER_NO_TASK;
131 /* confirm copying complete */
132 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
135 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
142 d->cfg, d, _("`scp' does not seem to terminate.\n"));
147 = GNUNET_SCHEDULER_add_delayed (d->sched,
148 GNUNET_CONSTANTS_EXEC_WAIT,
152 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
158 NULL, d->cfg, d, _("`scp' did not complete cleanly.\n"));
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "Successfully copied configuration file.\n");
165 d->phase = SP_COPIED;
168 /* start GNUnet on remote host */
169 if (NULL == d->hostname)
171 d->pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
172 "gnunet-service-arm",
181 if (d->username != NULL)
182 GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
184 dst = GNUNET_strdup (d->hostname);
185 d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
189 "-c", d->cfgfile, "-s", NULL);
194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
195 _("Could not start `%s' process to start GNUnet.\n"),
196 (NULL == d->hostname) ? "gnunet-arm" : "ssh");
204 (NULL == d->hostname)
205 ? _("Failed to start `gnunet-arm' process.\n")
206 : _("Failed to start `ssh' process.\n"));
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Started `%s', waiting for `%s' to be up.\n",
211 "gnunet-arm", "gnunet-service-core");
213 d->phase = SP_START_ARMING;
216 = GNUNET_SCHEDULER_add_delayed (d->sched,
217 GNUNET_CONSTANTS_EXEC_WAIT,
220 case SP_START_ARMING:
221 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
224 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
233 (NULL == d->hostname)
234 ? _("`gnunet-arm' does not seem to terminate.\n")
235 : _("`ssh' does not seem to terminate.\n"));
240 = GNUNET_SCHEDULER_add_delayed (d->sched,
241 GNUNET_CONSTANTS_EXEC_WAIT,
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "Successfully started `%s'.\n", "gnunet-arm");
249 d->phase = SP_START_CORE;
250 d->server = GNUNET_CORE_connect (d->sched,
257 NULL, GNUNET_NO, no_handlers);
265 case SP_SHUTDOWN_START:
266 /* confirm copying complete */
267 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
270 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
272 d->dead_cb (d->dead_cb_cls,
273 _("either `gnunet-arm' or `ssh' does not seem to terminate.\n"));
274 GNUNET_CONFIGURATION_destroy (d->cfg);
275 GNUNET_free (d->cfgfile);
276 GNUNET_free_non_null (d->hostname);
277 GNUNET_free_non_null (d->username);
278 GNUNET_free_non_null (d->shortname);
284 = GNUNET_SCHEDULER_add_delayed (d->sched,
285 GNUNET_CONSTANTS_EXEC_WAIT,
289 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
291 if (NULL != d->dead_cb)
292 d->dead_cb (d->dead_cb_cls,
293 _("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n"));
294 GNUNET_CONFIGURATION_destroy (d->cfg);
295 GNUNET_free (d->cfgfile);
296 GNUNET_free_non_null (d->hostname);
297 GNUNET_free_non_null (d->username);
298 GNUNET_free_non_null (d->shortname);
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
305 /* state clean up and notifications */
306 GNUNET_CONFIGURATION_destroy (d->cfg);
307 GNUNET_free (d->cfgfile);
308 GNUNET_free_non_null (d->hostname);
309 GNUNET_free_non_null (d->username);
310 GNUNET_free_non_null (d->shortname);
311 if (NULL != d->dead_cb)
312 d->dead_cb (d->dead_cb_cls, NULL);
315 case SP_CONFIG_UPDATE:
316 /* confirm copying complete */
317 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
320 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
327 d->cfg, d, _("`scp' does not seem to terminate.\n"));
332 = GNUNET_SCHEDULER_add_delayed (d->sched,
333 GNUNET_CONSTANTS_EXEC_WAIT,
337 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
339 if (NULL != d->update_cb)
340 d->update_cb (d->update_cb_cls,
341 _("`scp' did not complete cleanly.\n"));
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
346 "Successfully copied configuration file.\n");
348 if (NULL != d->update_cb)
349 d->update_cb (d->update_cb_cls, NULL);
350 d->phase = SP_START_DONE;
357 * Starts a GNUnet daemon. GNUnet must be installed on the target
358 * system and available in the PATH. The machine must furthermore be
359 * reachable via "ssh" (unless the hostname is "NULL") without the
360 * need to enter a password.
362 * @param sched scheduler to use
363 * @param cfg configuration to use
364 * @param hostname name of the machine where to run GNUnet
365 * (use NULL for localhost).
366 * @param cb function to call with the result
367 * @param cb_cls closure for cb
368 * @return handle to the daemon (actual start will be completed asynchronously)
370 struct GNUNET_TESTING_Daemon *
371 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
372 const struct GNUNET_CONFIGURATION_Handle *cfg,
373 const char *hostname,
374 GNUNET_TESTING_NotifyDaemonRunning cb,
377 struct GNUNET_TESTING_Daemon *ret;
381 ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
383 ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
384 ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
387 "Setting up peer with configuration file `%s'.\n",
390 if (NULL == ret->cfgfile)
392 GNUNET_free_non_null (ret->hostname);
397 ret->cb_cls = cb_cls;
398 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
399 GNUNET_CONFIGURATION_set_value_string (ret->cfg,
401 "DEFAULTCONFIG", ret->cfgfile);
402 /* 1) write configuration to temporary file */
403 if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
405 if (0 != UNLINK (ret->cfgfile))
406 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
407 "unlink", ret->cfgfile);
408 GNUNET_CONFIGURATION_destroy (ret->cfg);
409 GNUNET_free_non_null (ret->hostname);
410 GNUNET_free (ret->cfgfile);
415 GNUNET_CONFIGURATION_get_value_string (cfg,
417 "USERNAME", &username))
419 if (NULL != getenv ("USER"))
420 username = GNUNET_strdup (getenv ("USER"));
424 ret->username = username;
426 /* 2) copy file to remote host */
427 if (NULL != hostname)
430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431 "Copying configuration file to host `%s'.\n", hostname);
433 ret->phase = SP_COPYING;
434 if (NULL != username)
435 GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile);
437 GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
438 ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
439 "scp", ret->cfgfile, arg, NULL);
443 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
445 ("Could not start `%s' process to copy configuration file.\n"),
447 if (0 != UNLINK (ret->cfgfile))
448 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
449 "unlink", ret->cfgfile);
450 GNUNET_CONFIGURATION_destroy (ret->cfg);
451 GNUNET_free_non_null (ret->hostname);
452 GNUNET_free_non_null (ret->username);
453 GNUNET_free (ret->cfgfile);
458 = GNUNET_SCHEDULER_add_delayed (sched,
459 GNUNET_CONSTANTS_EXEC_WAIT,
464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
465 "No need to copy configuration file since we are running locally.\n");
467 ret->phase = SP_COPIED;
468 GNUNET_SCHEDULER_add_continuation (sched,
471 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
477 * Stops a GNUnet daemon.
479 * @param d the daemon that should be stopped
480 * @param cb function called once the daemon was stopped
481 * @param cb_cls closure for cb
484 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
485 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
490 d->dead_cb_cls = cb_cls;
494 d->dead = GNUNET_YES;
497 if (d->phase == SP_CONFIG_UPDATE)
499 GNUNET_SCHEDULER_cancel (d->sched, d->task);
500 d->phase = SP_START_DONE;
502 if (d->server != NULL)
504 GNUNET_CORE_disconnect (d->server);
507 /* shutdown ARM process (will terminate others) */
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
511 /* sleep(15); Manual check for running */
514 d->phase = SP_SHUTDOWN_START;
516 /* Check if this is a local or remote process */
517 if (NULL != d->hostname)
520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
521 "Stopping gnunet-arm on with config `%s' on host `%s'.\n", d->cfgfile, d->hostname);
524 if (d->username != NULL)
525 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
527 arg = GNUNET_strdup (d->hostname);
529 d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
531 "-c", d->cfgfile, "-e", "-d", NULL);
532 /* Use -e to end arm, and -d to remove temp files */
539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
540 "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile);
542 d->pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
544 "-c", d->cfgfile, "-e", NULL);
549 = GNUNET_SCHEDULER_add_delayed (d->sched,
550 GNUNET_CONSTANTS_EXEC_WAIT,
557 * Changes the configuration of a GNUnet daemon.
559 * @param d the daemon that should be modified
560 * @param cfg the new configuration for the daemon
561 * @param cb function called once the configuration was changed
562 * @param cb_cls closure for cb
565 GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
566 struct GNUNET_CONFIGURATION_Handle *cfg,
567 GNUNET_TESTING_NotifyCompletion cb,
572 if (d->phase != SP_START_DONE)
577 ("Peer not yet running, can not change configuration at this point."));
581 /* 1) write configuration to temporary file */
582 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile))
585 cb (cb_cls, _("Failed to write new configuration to disk."));
589 /* 2) copy file to remote host (if necessary) */
590 if (NULL == d->hostname)
598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
599 "Copying updated configuration file to remote host `%s'.\n",
602 d->phase = SP_CONFIG_UPDATE;
603 if (NULL != d->username)
604 GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile);
606 GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile);
607 d->pid = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", d->cfgfile, arg, NULL);
611 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
613 ("Could not start `%s' process to copy configuration file.\n"),
616 cb (cb_cls, _("Failed to copy new configuration to remote machine."));
617 d->phase = SP_START_DONE;
621 d->update_cb_cls = cb_cls;
623 = GNUNET_SCHEDULER_add_delayed (d->sched,
624 GNUNET_CONSTANTS_EXEC_WAIT,
630 * Data kept for each pair of peers that we try
633 struct ConnectContext
636 * Testing handle to the first daemon.
638 struct GNUNET_TESTING_Daemon *d1;
641 * Handle to core of first daemon (to check connect)
643 struct GNUNET_CORE_Handle * d1core;
646 * Testing handle to the second daemon.
648 struct GNUNET_TESTING_Daemon *d2;
651 * Handle to core of second daemon (to check connect)
653 struct GNUNET_CORE_Handle * d2core;
656 * Transport handle to the first daemon.
658 struct GNUNET_TRANSPORT_Handle *d1th;
661 * Transport handle to the second daemon.
663 struct GNUNET_TRANSPORT_Handle *d2th;
666 * Function to call once we are done (or have timed out).
668 GNUNET_TESTING_NotifyConnection cb;
676 * Transmit handle for our request for transmission
677 * (as given to d2 asking to talk to d1).
679 struct GNUNET_CORE_TransmitHandle *ntr;
682 * When should this operation be complete (or we must trigger
685 struct GNUNET_TIME_Absolute timeout;
690 GNUNET_SCHEDULER_TaskIdentifier hello_send_task;
693 * Connect timeout task
695 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
698 * When should this operation be complete (or we must trigger
701 struct GNUNET_TIME_Relative timeout_hello;
704 * The current hello message we have (for d1)
706 struct GNUNET_MessageHeader *hello;
709 * Was the connection successful?
716 * Receive the HELLO from one peer, give it to the other
717 * and ask them to connect.
719 * @param cls "struct ConnectContext"
720 * @param message HELLO message of peer
723 process_hello (void *cls, const struct GNUNET_MessageHeader *message)
725 struct ConnectContext *ctx = cls;
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
729 "Received `%s' from transport service of `%4s'\n",
730 "HELLO", GNUNET_i2s (&ctx->d1->id));
733 GNUNET_assert (message != NULL);
734 GNUNET_free_non_null(ctx->hello);
735 ctx->hello = GNUNET_malloc(ntohs(message->size));
736 memcpy(ctx->hello, message, ntohs(message->size));
742 * Notify callback about success or failure of the attempt
743 * to connect the two peers
745 * @param cls our "struct ConnectContext" (freed)
746 * @param tc reason tells us if we succeeded or failed
749 notify_connect_result (void *cls,
750 const struct GNUNET_SCHEDULER_TaskContext *tc)
752 struct ConnectContext *ctx = cls;
754 GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, &process_hello, ctx);
755 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->hello_send_task);
759 if (ctx->connected == GNUNET_NO)
761 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
762 ctx->d2->cfg, ctx->d1, ctx->d2,
763 _("Peers failed to connect"));
767 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
768 ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
769 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
774 GNUNET_TRANSPORT_disconnect (ctx->d1th);
776 GNUNET_TRANSPORT_disconnect (ctx->d2th);
778 GNUNET_CORE_disconnect (ctx->d1core);
780 GNUNET_free_non_null (ctx->hello);
786 * Success, connection is up. Signal client our success.
788 * @param cls our "struct ConnectContext"
789 * @param peer identity of the peer that has connected
790 * @param latency the round trip latency of the connection to this peer
791 * @param distance distance the transport level distance to this peer
795 connect_notify (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNET_TIME_Relative latency,
798 struct ConnectContext *ctx = cls;
801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
802 "Core notified us about connection to a peer\n");
804 if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0)
807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
808 "Core notified us about connection to peer %s\n", GNUNET_i2s(peer));
811 * If we disconnect here, then the hello may never get sent (if it was delayed!)
812 * However I'm sure there was a reason it was here... so I'm just commenting.
814 ctx->connected = GNUNET_YES;
815 GNUNET_SCHEDULER_add_now (ctx->d1->sched,
816 ¬ify_connect_result,
823 send_hello(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
825 struct ConnectContext *ctx = cls;
827 if (ctx->hello != NULL)
829 GNUNET_TRANSPORT_offer_hello (ctx->d2th, ctx->hello);
830 ctx->timeout_hello = GNUNET_TIME_relative_add(ctx->timeout_hello,
831 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
834 ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed(ctx->d1->sched,
841 * Establish a connection between two GNUnet daemons.
843 * @param d1 handle for the first daemon
844 * @param d2 handle for the second daemon
845 * @param timeout how long is the connection attempt
847 * @param cb function to call at the end
848 * @param cb_cls closure for cb
851 GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
852 struct GNUNET_TESTING_Daemon *d2,
853 struct GNUNET_TIME_Relative timeout,
854 GNUNET_TESTING_NotifyConnection cb,
857 struct ConnectContext *ctx;
858 static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
860 if ((d1->server == NULL) || (d2->server == NULL))
863 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
864 _("Peers are not fully running yet, can not connect!\n"));
867 ctx = GNUNET_malloc (sizeof (struct ConnectContext));
870 ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
872 ctx->cb_cls = cb_cls;
873 ctx->timeout_hello = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 400);
874 ctx->connected = GNUNET_NO;
876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
877 "Asked to connect peer %s to peer %s\n",
878 d1->shortname, d2->shortname);
879 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
880 "Connecting to transport service of peer %s\n", d1->shortname);
883 ctx->d1core = GNUNET_CORE_connect (d1->sched,
888 NULL, &connect_notify, NULL,
890 NULL, GNUNET_NO, no_handlers);
891 if (ctx->d1core == NULL)
895 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
896 _("Failed to connect to core service of first peer!\n"));
900 ctx->d1th = GNUNET_TRANSPORT_connect (d1->sched,
901 d1->cfg, d1, NULL, NULL, NULL);
902 if (ctx->d1th == NULL)
906 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
907 _("Failed to connect to transport service!\n"));
911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
912 "Asked to connect peer %s to peer %s\n",
913 d1->shortname, d2->shortname);
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
915 "Connecting to transport service of peer %s\n", d2->shortname);
919 ctx->d2th = GNUNET_TRANSPORT_connect (d2->sched,
920 d2->cfg, d2, NULL, NULL, NULL);
921 if (ctx->d2th == NULL)
923 GNUNET_TRANSPORT_disconnect (ctx->d1th);
926 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
927 _("Failed to connect to transport service!\n"));
932 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
933 "Asking for HELLO from peer %s\n", GNUNET_i2s (&d1->id));
936 ctx->timeout_task = GNUNET_SCHEDULER_add_delayed (d1->sched,
938 ¬ify_connect_result, ctx);
940 GNUNET_TRANSPORT_get_hello (ctx->d1th, &process_hello, ctx);
941 ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed(ctx->d1->sched, ctx->timeout_hello,
946 /* end of testing.c */