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
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"
39 #define DEBUG_TESTING GNUNET_YES
42 * How long do we wait after starting gnunet-service-arm
43 * for the core service to be alive?
45 #define ARM_START_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
48 * How many times are we willing to try to wait for "scp" or
49 * "gnunet-service-arm" to complete (waitpid) before giving up?
51 #define MAX_EXEC_WAIT_RUNS 50
55 * Function called after GNUNET_CORE_connect has succeeded
56 * (or failed for good). Note that the private key of the
57 * peer is intentionally not exposed here; if you need it,
58 * your process should try to read the private key file
59 * directly (which should work if you are authorized...).
62 * @param server handle to the server, NULL if we failed
63 * @param my_identity ID of this peer, NULL if we failed
64 * @param publicKey public key of this peer, NULL if we failed
67 testing_init (void *cls,
68 struct GNUNET_CORE_Handle *server,
69 const struct GNUNET_PeerIdentity *my_identity,
70 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
72 struct GNUNET_TESTING_Daemon *d = cls;
73 GNUNET_TESTING_NotifyDaemonRunning cb;
75 GNUNET_assert (d->phase == SP_START_CORE);
76 d->phase = SP_START_DONE;
82 if (GNUNET_YES == d->dead)
83 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
85 cb (d->cb_cls, NULL, d->cfg, d,
86 _("Failed to connect to core service\n"));
90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
91 "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity));
94 d->shortname = strdup (GNUNET_i2s (my_identity));
96 if (GNUNET_YES == d->dead)
97 GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
99 cb (d->cb_cls, my_identity, d->cfg, d, NULL);
104 * Finite-state machine for starting GNUnet.
106 * @param cls our "struct GNUNET_TESTING_Daemon"
110 start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
112 static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
113 struct GNUNET_TESTING_Daemon *d = cls;
114 GNUNET_TESTING_NotifyDaemonRunning cb;
115 enum GNUNET_OS_ProcessStatusType type;
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Peer FSM is in phase %u.\n", d->phase);
123 d->task = GNUNET_SCHEDULER_NO_TASK;
127 /* confirm copying complete */
128 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
131 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
138 d->cfg, d, _("`scp' does not seem to terminate.\n"));
143 = GNUNET_SCHEDULER_add_delayed (d->sched,
144 GNUNET_CONSTANTS_EXEC_WAIT,
148 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
154 NULL, d->cfg, d, _("`scp' did not complete cleanly.\n"));
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
159 "Successfully copied configuration file.\n");
161 d->phase = SP_COPIED;
164 /* start GNUnet on remote host */
165 if (NULL == d->hostname)
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
169 "Starting `%s', with command `%s %s %s %s %s %s'.\n",
170 "gnunet-arm", "gnunet-arm", "-c", d->cfgfile,
174 d->pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
184 if (d->username != NULL)
185 GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
187 dst = GNUNET_strdup (d->hostname);
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
191 "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n",
192 "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile,
193 "-L", "DEBUG", "-s");
195 d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
202 "-c", d->cfgfile, "-s", NULL);
207 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
208 _("Could not start `%s' process to start GNUnet.\n"),
209 (NULL == d->hostname) ? "gnunet-arm" : "ssh");
217 (NULL == d->hostname)
218 ? _("Failed to start `gnunet-arm' process.\n")
219 : _("Failed to start `ssh' process.\n"));
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
223 "Started `%s', waiting for `%s' to be up.\n",
224 "gnunet-arm", "gnunet-service-core");
226 d->phase = SP_START_ARMING;
229 = GNUNET_SCHEDULER_add_delayed (d->sched,
230 GNUNET_CONSTANTS_EXEC_WAIT,
233 case SP_START_ARMING:
234 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
237 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
246 (NULL == d->hostname)
247 ? _("`gnunet-arm' does not seem to terminate.\n")
248 : _("`ssh' does not seem to terminate.\n"));
253 = GNUNET_SCHEDULER_add_delayed (d->sched,
254 GNUNET_CONSTANTS_EXEC_WAIT,
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "Successfully started `%s'.\n", "gnunet-arm");
262 d->phase = SP_START_CORE;
263 d->server = GNUNET_CORE_connect (d->sched,
270 NULL, GNUNET_NO, no_handlers);
278 case SP_SHUTDOWN_START:
279 /* confirm copying complete */
280 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
283 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
285 d->dead_cb (d->dead_cb_cls,
286 _("either `gnunet-arm' or `ssh' does not seem to terminate.\n"));
287 GNUNET_CONFIGURATION_destroy (d->cfg);
288 GNUNET_free (d->cfgfile);
289 GNUNET_free_non_null (d->hostname);
290 GNUNET_free_non_null (d->username);
291 GNUNET_free_non_null (d->shortname);
297 = GNUNET_SCHEDULER_add_delayed (d->sched,
298 GNUNET_CONSTANTS_EXEC_WAIT,
302 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
304 if (NULL != d->dead_cb)
305 d->dead_cb (d->dead_cb_cls,
306 _("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n"));
307 GNUNET_CONFIGURATION_destroy (d->cfg);
308 GNUNET_free (d->cfgfile);
309 GNUNET_free_non_null (d->hostname);
310 GNUNET_free_non_null (d->username);
311 GNUNET_free_non_null (d->shortname);
316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
318 /* state clean up and notifications */
319 GNUNET_CONFIGURATION_destroy (d->cfg);
320 GNUNET_free (d->cfgfile);
321 GNUNET_free_non_null (d->hostname);
322 GNUNET_free_non_null (d->username);
323 GNUNET_free_non_null (d->shortname);
324 if (NULL != d->dead_cb)
325 d->dead_cb (d->dead_cb_cls, NULL);
328 case SP_CONFIG_UPDATE:
329 /* confirm copying complete */
330 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
333 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
340 d->cfg, d, _("`scp' does not seem to terminate.\n"));
345 = GNUNET_SCHEDULER_add_delayed (d->sched,
346 GNUNET_CONSTANTS_EXEC_WAIT,
350 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
352 if (NULL != d->update_cb)
353 d->update_cb (d->update_cb_cls,
354 _("`scp' did not complete cleanly.\n"));
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
359 "Successfully copied configuration file.\n");
361 if (NULL != d->update_cb)
362 d->update_cb (d->update_cb_cls, NULL);
363 d->phase = SP_START_DONE;
370 * Starts a GNUnet daemon. GNUnet must be installed on the target
371 * system and available in the PATH. The machine must furthermore be
372 * reachable via "ssh" (unless the hostname is "NULL") without the
373 * need to enter a password.
375 * @param sched scheduler to use
376 * @param cfg configuration to use
377 * @param hostname name of the machine where to run GNUnet
378 * (use NULL for localhost).
379 * @param cb function to call with the result
380 * @param cb_cls closure for cb
381 * @return handle to the daemon (actual start will be completed asynchronously)
383 struct GNUNET_TESTING_Daemon *
384 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
385 const struct GNUNET_CONFIGURATION_Handle *cfg,
386 const char *hostname,
387 GNUNET_TESTING_NotifyDaemonRunning cb,
390 struct GNUNET_TESTING_Daemon *ret;
394 ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
396 ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
397 ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
400 "Setting up peer with configuration file `%s'.\n",
403 if (NULL == ret->cfgfile)
405 GNUNET_free_non_null (ret->hostname);
410 ret->cb_cls = cb_cls;
411 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
412 GNUNET_CONFIGURATION_set_value_string (ret->cfg,
414 "DEFAULTCONFIG", ret->cfgfile);
415 /* 1) write configuration to temporary file */
416 if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
418 if (0 != UNLINK (ret->cfgfile))
419 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
420 "unlink", ret->cfgfile);
421 GNUNET_CONFIGURATION_destroy (ret->cfg);
422 GNUNET_free_non_null (ret->hostname);
423 GNUNET_free (ret->cfgfile);
428 GNUNET_CONFIGURATION_get_value_string (cfg,
430 "USERNAME", &username))
432 if (NULL != getenv ("USER"))
433 username = GNUNET_strdup (getenv ("USER"));
437 ret->username = username;
439 /* 2) copy file to remote host */
440 if (NULL != hostname)
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
444 "Copying configuration file to host `%s'.\n", hostname);
446 ret->phase = SP_COPYING;
447 if (NULL != username)
448 GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile);
450 GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
451 ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
452 "scp", ret->cfgfile, arg, NULL);
456 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
458 ("Could not start `%s' process to copy configuration file.\n"),
460 if (0 != UNLINK (ret->cfgfile))
461 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
462 "unlink", ret->cfgfile);
463 GNUNET_CONFIGURATION_destroy (ret->cfg);
464 GNUNET_free_non_null (ret->hostname);
465 GNUNET_free_non_null (ret->username);
466 GNUNET_free (ret->cfgfile);
471 = GNUNET_SCHEDULER_add_delayed (sched,
472 GNUNET_CONSTANTS_EXEC_WAIT,
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
478 "No need to copy configuration file since we are running locally.\n");
480 ret->phase = SP_COPIED;
481 GNUNET_SCHEDULER_add_continuation (sched,
484 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
490 * Stops a GNUnet daemon.
492 * @param d the daemon that should be stopped
493 * @param cb function called once the daemon was stopped
494 * @param cb_cls closure for cb
497 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
498 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
503 d->dead_cb_cls = cb_cls;
507 d->dead = GNUNET_YES;
510 if (d->phase == SP_CONFIG_UPDATE)
512 GNUNET_SCHEDULER_cancel (d->sched, d->task);
513 d->phase = SP_START_DONE;
515 if (d->server != NULL)
517 GNUNET_CORE_disconnect (d->server);
520 /* shutdown ARM process (will terminate others) */
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
524 /* sleep(15); Manual check for running */
527 d->phase = SP_SHUTDOWN_START;
529 /* Check if this is a local or remote process */
530 if (NULL != d->hostname)
533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
534 "Stopping gnunet-arm with config `%s' on host `%s'.\n", d->cfgfile, d->hostname);
537 if (d->username != NULL)
538 GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname);
540 arg = GNUNET_strdup (d->hostname);
542 d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh",
547 "-c", d->cfgfile, "-e", "-d", NULL);
548 /* Use -e to end arm, and -d to remove temp files */
555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
556 "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile);
558 d->pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm",
563 "-c", d->cfgfile, "-e", "-d", NULL);
568 = GNUNET_SCHEDULER_add_delayed (d->sched,
569 GNUNET_CONSTANTS_EXEC_WAIT,
576 * Changes the configuration of a GNUnet daemon.
578 * @param d the daemon that should be modified
579 * @param cfg the new configuration for the daemon
580 * @param cb function called once the configuration was changed
581 * @param cb_cls closure for cb
584 GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
585 struct GNUNET_CONFIGURATION_Handle *cfg,
586 GNUNET_TESTING_NotifyCompletion cb,
591 if (d->phase != SP_START_DONE)
596 ("Peer not yet running, can not change configuration at this point."));
600 /* 1) write configuration to temporary file */
601 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile))
604 cb (cb_cls, _("Failed to write new configuration to disk."));
608 /* 2) copy file to remote host (if necessary) */
609 if (NULL == d->hostname)
617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
618 "Copying updated configuration file to remote host `%s'.\n",
621 d->phase = SP_CONFIG_UPDATE;
622 if (NULL != d->username)
623 GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile);
625 GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile);
626 d->pid = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", d->cfgfile, arg, NULL);
630 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
632 ("Could not start `%s' process to copy configuration file.\n"),
635 cb (cb_cls, _("Failed to copy new configuration to remote machine."));
636 d->phase = SP_START_DONE;
640 d->update_cb_cls = cb_cls;
642 = GNUNET_SCHEDULER_add_delayed (d->sched,
643 GNUNET_CONSTANTS_EXEC_WAIT,
649 * Data kept for each pair of peers that we try
652 struct ConnectContext
655 * Testing handle to the first daemon.
657 struct GNUNET_TESTING_Daemon *d1;
660 * Handle to core of first daemon (to check connect)
662 struct GNUNET_CORE_Handle * d1core;
665 * Testing handle to the second daemon.
667 struct GNUNET_TESTING_Daemon *d2;
670 * Handle to core of second daemon (to check connect)
672 struct GNUNET_CORE_Handle * d2core;
675 * Transport handle to the first daemon.
677 struct GNUNET_TRANSPORT_Handle *d1th;
680 * Transport handle to the second daemon.
682 struct GNUNET_TRANSPORT_Handle *d2th;
685 * Function to call once we are done (or have timed out).
687 GNUNET_TESTING_NotifyConnection cb;
695 * Transmit handle for our request for transmission
696 * (as given to d2 asking to talk to d1).
698 struct GNUNET_CORE_TransmitHandle *ntr;
701 * When should this operation be complete (or we must trigger
704 struct GNUNET_TIME_Absolute timeout;
709 GNUNET_SCHEDULER_TaskIdentifier hello_send_task;
712 * Connect timeout task
714 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
717 * When should this operation be complete (or we must trigger
720 struct GNUNET_TIME_Relative timeout_hello;
723 * The current hello message we have (for d1)
725 struct GNUNET_MessageHeader *hello;
728 * Was the connection successful?
735 * Receive the HELLO from one peer, give it to the other
736 * and ask them to connect.
738 * @param cls "struct ConnectContext"
739 * @param message HELLO message of peer
742 process_hello (void *cls, const struct GNUNET_MessageHeader *message)
744 struct ConnectContext *ctx = cls;
747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
748 "Received `%s' from transport service of `%4s'\n",
749 "HELLO", GNUNET_i2s (&ctx->d1->id));
752 GNUNET_assert (message != NULL);
753 GNUNET_free_non_null(ctx->hello);
754 ctx->hello = GNUNET_malloc(ntohs(message->size));
755 memcpy(ctx->hello, message, ntohs(message->size));
761 * Notify callback about success or failure of the attempt
762 * to connect the two peers
764 * @param cls our "struct ConnectContext" (freed)
765 * @param tc reason tells us if we succeeded or failed
768 notify_connect_result (void *cls,
769 const struct GNUNET_SCHEDULER_TaskContext *tc)
771 struct ConnectContext *ctx = cls;
773 GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, &process_hello, ctx);
774 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->hello_send_task);
778 if (ctx->connected == GNUNET_NO)
780 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
781 ctx->d2->cfg, ctx->d1, ctx->d2,
782 _("Peers failed to connect"));
786 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
787 ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
788 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
793 GNUNET_TRANSPORT_disconnect (ctx->d1th);
795 GNUNET_TRANSPORT_disconnect (ctx->d2th);
797 GNUNET_CORE_disconnect (ctx->d1core);
799 GNUNET_free_non_null (ctx->hello);
805 * Success, connection is up. Signal client our success.
807 * @param cls our "struct ConnectContext"
808 * @param peer identity of the peer that has connected
809 * @param latency the round trip latency of the connection to this peer
810 * @param distance distance the transport level distance to this peer
814 connect_notify (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNET_TIME_Relative latency,
817 struct ConnectContext *ctx = cls;
820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
821 "Core notified us about connection to a peer\n");
823 if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0)
826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
827 "Core notified us about connection to peer %s\n", GNUNET_i2s(peer));
830 * If we disconnect here, then the hello may never get sent (if it was delayed!)
831 * However I'm sure there was a reason it was here... so I'm just commenting.
833 ctx->connected = GNUNET_YES;
834 GNUNET_SCHEDULER_add_now (ctx->d1->sched,
835 ¬ify_connect_result,
842 send_hello(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
844 struct ConnectContext *ctx = cls;
846 if (ctx->hello != NULL)
848 GNUNET_TRANSPORT_offer_hello (ctx->d2th, ctx->hello);
849 ctx->timeout_hello = GNUNET_TIME_relative_add(ctx->timeout_hello,
850 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
853 ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed(ctx->d1->sched,
860 * Establish a connection between two GNUnet daemons.
862 * @param d1 handle for the first daemon
863 * @param d2 handle for the second daemon
864 * @param timeout how long is the connection attempt
866 * @param cb function to call at the end
867 * @param cb_cls closure for cb
870 GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
871 struct GNUNET_TESTING_Daemon *d2,
872 struct GNUNET_TIME_Relative timeout,
873 GNUNET_TESTING_NotifyConnection cb,
876 struct ConnectContext *ctx;
877 static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
879 if ((d1->server == NULL) || (d2->server == NULL))
882 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
883 _("Peers are not fully running yet, can not connect!\n"));
886 ctx = GNUNET_malloc (sizeof (struct ConnectContext));
889 ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
891 ctx->cb_cls = cb_cls;
892 ctx->timeout_hello = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 400);
893 ctx->connected = GNUNET_NO;
895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
896 "Asked to connect peer %s to peer %s\n",
897 d1->shortname, d2->shortname);
898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
899 "Connecting to transport service of peer %s\n", d1->shortname);
902 ctx->d1core = GNUNET_CORE_connect (d1->sched,
907 NULL, &connect_notify, NULL,
909 NULL, GNUNET_NO, no_handlers);
910 if (ctx->d1core == NULL)
914 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
915 _("Failed to connect to core service of first peer!\n"));
919 ctx->d1th = GNUNET_TRANSPORT_connect (d1->sched,
920 d1->cfg, d1, NULL, NULL, NULL);
921 if (ctx->d1th == NULL)
925 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
926 _("Failed to connect to transport service!\n"));
930 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
931 "Asked to connect peer %s to peer %s\n",
932 d1->shortname, d2->shortname);
933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
934 "Connecting to transport service of peer %s\n", d2->shortname);
938 ctx->d2th = GNUNET_TRANSPORT_connect (d2->sched,
939 d2->cfg, d2, NULL, NULL, NULL);
940 if (ctx->d2th == NULL)
942 GNUNET_TRANSPORT_disconnect (ctx->d1th);
945 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
946 _("Failed to connect to transport service!\n"));
951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
952 "Asking for HELLO from peer %s\n", GNUNET_i2s (&d1->id));
955 ctx->timeout_task = GNUNET_SCHEDULER_add_delayed (d1->sched,
957 ¬ify_connect_result, ctx);
959 GNUNET_TRANSPORT_get_hello (ctx->d1th, &process_hello, ctx);
960 ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed(ctx->d1->sched, ctx->timeout_hello,
965 /* end of testing.c */