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_YES
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 ("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 ("ssh",
188 "gnunet-service-arm",
189 "-c", d->cfgfile, "-d", NULL);
194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
195 _("Could not start `%s' process to start GNUnet.\n"),
196 (NULL == d->hostname) ? "gnunet-service-arm" : "ssh");
204 (NULL == d->hostname)
205 ? _("Failed to start `gnunet-service-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-service-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-service-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-service-arm");
249 d->phase = SP_START_CORE;
250 d->server = GNUNET_CORE_connect (d->sched,
257 NULL, GNUNET_NO, no_handlers);
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 _("`ssh' does not seem to terminate.\n"));
274 GNUNET_free (d->cfgfile);
275 GNUNET_free_non_null (d->hostname);
276 GNUNET_free_non_null (d->username);
282 = GNUNET_SCHEDULER_add_delayed (d->sched,
283 GNUNET_CONSTANTS_EXEC_WAIT,
287 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
289 if (NULL != d->dead_cb)
290 d->dead_cb (d->dead_cb_cls,
291 _("`ssh' did not complete cleanly.\n"));
292 GNUNET_free (d->cfgfile);
293 GNUNET_free_non_null (d->hostname);
294 GNUNET_free_non_null (d->username);
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n");
301 GNUNET_free (d->cfgfile);
302 GNUNET_free_non_null (d->hostname);
303 GNUNET_free_non_null (d->username);
304 if (NULL != d->dead_cb)
305 d->dead_cb (d->dead_cb_cls, NULL);
308 case SP_CONFIG_UPDATE:
309 /* confirm copying complete */
310 if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
313 if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
320 d->cfg, d, _("`scp' does not seem to terminate.\n"));
325 = GNUNET_SCHEDULER_add_delayed (d->sched,
326 GNUNET_CONSTANTS_EXEC_WAIT,
330 if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0))
332 if (NULL != d->update_cb)
333 d->update_cb (d->update_cb_cls,
334 _("`scp' did not complete cleanly.\n"));
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
339 "Successfully copied configuration file.\n");
341 if (NULL != d->update_cb)
342 d->update_cb (d->update_cb_cls, NULL);
343 d->phase = SP_START_DONE;
350 * Starts a GNUnet daemon. GNUnet must be installed on the target
351 * system and available in the PATH. The machine must furthermore be
352 * reachable via "ssh" (unless the hostname is "NULL") without the
353 * need to enter a password.
355 * @param sched scheduler to use
356 * @param cfg configuration to use
357 * @param hostname name of the machine where to run GNUnet
358 * (use NULL for localhost).
359 * @param cb function to call with the result
360 * @param cb_cls closure for cb
361 * @return handle to the daemon (actual start will be completed asynchronously)
363 struct GNUNET_TESTING_Daemon *
364 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
365 const struct GNUNET_CONFIGURATION_Handle *cfg,
366 const char *hostname,
367 GNUNET_TESTING_NotifyDaemonRunning cb,
370 struct GNUNET_TESTING_Daemon *ret;
374 ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
376 ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
377 ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
380 "Setting up peer with configuration file `%s'.\n",
383 if (NULL == ret->cfgfile)
385 GNUNET_free_non_null (ret->hostname);
390 ret->cb_cls = cb_cls;
391 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
392 GNUNET_CONFIGURATION_set_value_string (ret->cfg,
394 "DEFAULTCONFIG", ret->cfgfile);
395 /* 1) write configuration to temporary file */
396 if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile))
398 if (0 != UNLINK (ret->cfgfile))
399 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
400 "unlink", ret->cfgfile);
401 GNUNET_CONFIGURATION_destroy (ret->cfg);
402 GNUNET_free_non_null (ret->hostname);
403 GNUNET_free (ret->cfgfile);
408 GNUNET_CONFIGURATION_get_value_string (cfg,
410 "USERNAME", &username))
412 if (NULL != getenv ("USER"))
413 username = GNUNET_strdup (getenv ("USER"));
417 ret->username = username;
419 /* 2) copy file to remote host */
420 if (NULL != hostname)
423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
424 "Copying configuration file to host `%s'.\n", hostname);
426 ret->phase = SP_COPYING;
427 if (NULL != username)
428 GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile);
430 GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
431 ret->pid = GNUNET_OS_start_process ("scp",
432 "scp", ret->cfgfile, arg, NULL);
436 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
438 ("Could not start `%s' process to copy configuration file.\n"),
440 if (0 != UNLINK (ret->cfgfile))
441 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
442 "unlink", ret->cfgfile);
443 GNUNET_CONFIGURATION_destroy (ret->cfg);
444 GNUNET_free_non_null (ret->hostname);
445 GNUNET_free_non_null (ret->username);
446 GNUNET_free (ret->cfgfile);
451 = GNUNET_SCHEDULER_add_delayed (sched,
452 GNUNET_CONSTANTS_EXEC_WAIT,
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
458 "No need to copy configuration file since we are running locally.\n");
460 ret->phase = SP_COPIED;
461 GNUNET_SCHEDULER_add_continuation (sched,
464 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
470 * Stops a GNUnet daemon.
472 * @param d the daemon that should be stopped
473 * @param cb function called once the daemon was stopped
474 * @param cb_cls closure for cb
477 GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
478 GNUNET_TESTING_NotifyCompletion cb, void *cb_cls)
480 struct GNUNET_CLIENT_Connection *cc;
485 d->dead = GNUNET_YES;
487 d->dead_cb_cls = cb_cls;
490 if (d->phase == SP_CONFIG_UPDATE)
492 GNUNET_SCHEDULER_cancel (d->sched, d->task);
493 d->phase = SP_START_DONE;
495 if (d->server != NULL)
497 GNUNET_CORE_disconnect (d->server);
500 /* shutdown ARM process (will also terminate others) */
502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
503 _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
505 cc = GNUNET_CLIENT_connect (d->sched, "arm", d->cfg);
506 GNUNET_CLIENT_service_shutdown (cc);
508 /* state clean up and notifications */
509 if (0 != UNLINK (d->cfgfile))
510 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
511 "unlink", d->cfgfile);
512 if (d->hostname != NULL)
515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
516 "Removing configuration file on remote host `%s'.\n",
519 if (NULL != d->username)
520 GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname);
522 dst = GNUNET_strdup (d->hostname);
523 d->pid = GNUNET_OS_start_process ("ssh",
524 "ssh", dst, "rm", d->cfgfile, NULL);
528 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
530 ("Could not start `%s' process to delete configuration file.\n"),
532 GNUNET_free (d->cfgfile);
533 GNUNET_free_non_null (d->hostname);
534 GNUNET_free_non_null (d->username);
536 cb (cb_cls, _("Error cleaning up configuration file.\n"));
539 d->phase = SP_CLEANUP;
541 d->dead_cb_cls = cb_cls;
543 = GNUNET_SCHEDULER_add_delayed (d->sched,
544 GNUNET_CONSTANTS_EXEC_WAIT,
548 GNUNET_CONFIGURATION_destroy (d->cfg);
549 GNUNET_free (d->cfgfile);
550 GNUNET_free_non_null (d->hostname);
551 GNUNET_free_non_null (d->username);
559 * Changes the configuration of a GNUnet daemon.
561 * @param d the daemon that should be modified
562 * @param cfg the new configuration for the daemon
563 * @param cb function called once the configuration was changed
564 * @param cb_cls closure for cb
567 GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
568 struct GNUNET_CONFIGURATION_Handle *cfg,
569 GNUNET_TESTING_NotifyCompletion cb,
574 if (d->phase != SP_START_DONE)
579 ("Peer not yet running, can not change configuration at this point."));
583 /* 1) write configuration to temporary file */
584 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile))
587 cb (cb_cls, _("Failed to write new configuration to disk."));
591 /* 2) copy file to remote host (if necessary) */
592 if (NULL == d->hostname)
600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
601 "Copying updated configuration file to remote host `%s'.\n",
604 d->phase = SP_CONFIG_UPDATE;
605 if (NULL != d->username)
606 GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile);
608 GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile);
609 d->pid = GNUNET_OS_start_process ("scp", "scp", d->cfgfile, arg, NULL);
613 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
615 ("Could not start `%s' process to copy configuration file.\n"),
618 cb (cb_cls, _("Failed to copy new configuration to remote machine."));
619 d->phase = SP_START_DONE;
623 d->update_cb_cls = cb_cls;
625 = GNUNET_SCHEDULER_add_delayed (d->sched,
626 GNUNET_CONSTANTS_EXEC_WAIT,
632 * Data kept for each pair of peers that we try
635 struct ConnectContext
638 * Testing handle to the first daemon.
640 struct GNUNET_TESTING_Daemon *d1;
643 * Handle to core of first daemon (to check connect)
645 struct GNUNET_CORE_Handle * d1core;
648 * Testing handle to the second daemon.
650 struct GNUNET_TESTING_Daemon *d2;
653 * Handle to core of second daemon (to check connect)
655 struct GNUNET_CORE_Handle * d2core;
658 * Transport handle to the first daemon.
660 struct GNUNET_TRANSPORT_Handle *d1th;
663 * Transport handle to the second daemon.
665 struct GNUNET_TRANSPORT_Handle *d2th;
668 * Function to call once we are done (or have timed out).
670 GNUNET_TESTING_NotifyConnection cb;
678 * Transmit handle for our request for transmission
679 * (as given to d2 asking to talk to d1).
681 struct GNUNET_CORE_TransmitHandle *ntr;
684 * When should this operation be complete (or we must trigger
687 struct GNUNET_TIME_Absolute timeout;
692 GNUNET_SCHEDULER_TaskIdentifier hello_send_task;
695 * Connect timeout task
697 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
700 * When should this operation be complete (or we must trigger
703 struct GNUNET_TIME_Relative timeout_hello;
706 * The current hello message we have (for d1)
708 struct GNUNET_MessageHeader *hello;
711 * Was the connection successful?
718 * Receive the HELLO from one peer, give it to the other
719 * and ask them to connect.
721 * @param cls "struct ConnectContext"
722 * @param message HELLO message of peer
725 process_hello (void *cls, const struct GNUNET_MessageHeader *message)
727 struct ConnectContext *ctx = cls;
730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
731 "Received `%s' from transport service of `%4s'\n",
732 "HELLO", GNUNET_i2s (&ctx->d1->id));
735 GNUNET_assert (message != NULL);
736 GNUNET_free_non_null(ctx->hello);
737 ctx->hello = GNUNET_malloc(ntohs(message->size));
738 memcpy(ctx->hello, message, ntohs(message->size));
744 * Notify callback about success or failure of the attempt
745 * to connect the two peers
747 * @param cls our "struct ConnectContext" (freed)
748 * @param tc reason tells us if we succeeded or failed
751 notify_connect_result (void *cls,
752 const struct GNUNET_SCHEDULER_TaskContext *tc)
754 struct ConnectContext *ctx = cls;
756 GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, &process_hello, ctx);
757 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->hello_send_task);
761 if (ctx->connected == GNUNET_NO)
763 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
764 ctx->d2->cfg, ctx->d1, ctx->d2,
765 _("Peers failed to connect"));
769 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
770 ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
771 GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
776 GNUNET_TRANSPORT_disconnect (ctx->d1th);
778 GNUNET_TRANSPORT_disconnect (ctx->d2th);
780 GNUNET_CORE_disconnect (ctx->d1core);
788 * Success, connection is up. Signal client our success.
790 * @param cls our "struct ConnectContext"
791 * @param size number of bytes available in buf
792 * @param buf where to copy the message, NULL on error
793 * @return number of bytes copied to buf
796 connect_notify (void *cls, const struct GNUNET_PeerIdentity * peer, struct GNUNET_TIME_Relative latency,
799 struct ConnectContext *ctx = cls;
802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
803 "Core notified us about connection to a peer\n");
805 if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0)
808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
809 "Core notified us about connection to peer %s\n", GNUNET_i2s(peer));
812 * If we disconnect here, then the hello may never get sent (if it was delayed!)
813 * However I'm sure there was a reason it was here... so I'm just commenting.
815 ctx->connected = GNUNET_YES;
816 GNUNET_SCHEDULER_add_now (ctx->d1->sched,
817 ¬ify_connect_result,
824 send_hello(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
826 struct ConnectContext *ctx = cls;
828 if (ctx->hello != NULL)
830 GNUNET_TRANSPORT_offer_hello (ctx->d2th, ctx->hello);
831 ctx->timeout_hello = GNUNET_TIME_relative_add(ctx->timeout_hello, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200));
834 ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed(ctx->d1->sched, ctx->timeout_hello, &send_hello, ctx);
840 * Accessor function since we have hidden what GNUNET_TESTING_Daemon is
842 * FIXME: Either expose members or figure out a better way!
845 GNUNET_TESTING_daemon_get_shortname (struct GNUNET_TESTING_Daemon *d)
851 GNUNET_TESTING_daemon_get_hostname (struct GNUNET_TESTING_Daemon *d)
857 GNUNET_TESTING_daemon_get_username (struct GNUNET_TESTING_Daemon *d)
862 struct GNUNET_PeerIdentity *
863 GNUNET_TESTING_daemon_get_peer (struct GNUNET_TESTING_Daemon *d)
868 struct GNUNET_CONFIGURATION_Handle *
869 GNUNET_TESTING_daemon_get_config (struct GNUNET_TESTING_Daemon *d)
877 * Establish a connection between two GNUnet daemons.
879 * @param d1 handle for the first daemon
880 * @param d2 handle for the second daemon
881 * @param timeout how long is the connection attempt
883 * @param cb function to call at the end
884 * @param cb_cls closure for cb
887 GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
888 struct GNUNET_TESTING_Daemon *d2,
889 struct GNUNET_TIME_Relative timeout,
890 GNUNET_TESTING_NotifyConnection cb,
893 struct ConnectContext *ctx;
894 static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} };
896 if ((d1->server == NULL) || (d2->server == NULL))
899 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
900 _("Peers are not fully running yet, can not connect!\n"));
903 ctx = GNUNET_malloc (sizeof (struct ConnectContext));
906 ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
908 ctx->cb_cls = cb_cls;
909 ctx->timeout_hello = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 400);
910 ctx->connected = GNUNET_NO;
912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
913 "Asked to connect peer %s to peer %s\n",
914 d1->shortname, d2->shortname);
915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
916 "Connecting to transport service of peer %s\n", d1->shortname);
919 ctx->d1core = GNUNET_CORE_connect (d1->sched,
924 NULL, &connect_notify, NULL,
926 NULL, GNUNET_NO, no_handlers);
927 if (ctx->d1core == NULL)
931 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
932 _("Failed to connect to core service of first peer!\n"));
936 ctx->d1th = GNUNET_TRANSPORT_connect (d1->sched,
937 d1->cfg, d1, NULL, NULL, NULL);
938 if (ctx->d1th == NULL)
942 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
943 _("Failed to connect to transport service!\n"));
947 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
948 "Asked to connect peer %s to peer %s\n",
949 d1->shortname, d2->shortname);
950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
951 "Connecting to transport service of peer %s\n", d2->shortname);
955 ctx->d2th = GNUNET_TRANSPORT_connect (d2->sched,
956 d2->cfg, d2, NULL, NULL, NULL);
957 if (ctx->d2th == NULL)
959 GNUNET_TRANSPORT_disconnect (ctx->d1th);
962 cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
963 _("Failed to connect to transport service!\n"));
968 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
969 "Asking for hello from peer %s\n", GNUNET_i2s (&d1->id));
972 ctx->timeout_task = GNUNET_SCHEDULER_add_delayed (d1->sched,
974 ¬ify_connect_result, ctx);
976 GNUNET_TRANSPORT_get_hello (ctx->d1th, &process_hello, ctx);
977 ctx->hello_send_task = GNUNET_SCHEDULER_add_delayed(ctx->d1->sched, ctx->timeout_hello, &send_hello, ctx);
981 /* end of testing.c */