2 This file is part of GNUnet.
3 (C) 2009, 2010 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.
21 * @file transport/test_transport_api.c
22 * @brief base test case for transport implementations
24 * This test case serves as a base for tcp, udp, and udp-nat
25 * transport test cases. Based on the executable being run
26 * the correct test case will be performed. Conservation of
30 #include "gnunet_common.h"
31 #include "gnunet_hello_lib.h"
32 #include "gnunet_getopt_lib.h"
33 #include "gnunet_os_lib.h"
34 #include "gnunet_program_lib.h"
35 #include "gnunet_scheduler_lib.h"
36 #include "gnunet_transport_service.h"
37 #include "transport.h"
38 #include "transport-testing.h"
40 #define VERBOSE GNUNET_NO
42 #define VERBOSE_ARM GNUNET_NO
44 #define START_ARM GNUNET_YES
47 * How long until we give up on transmitting the message?
49 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
51 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
53 static struct PeerContext *p1;
54 static struct PeerContext *p2;
56 static int connected = GNUNET_NO;
63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
65 if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
66 GNUNET_SCHEDULER_cancel (timeout_task);
68 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
69 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
75 timeout_task = GNUNET_SCHEDULER_NO_TASK;
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
78 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
79 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
85 testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
87 char *p1_c = strdup (GNUNET_i2s (&p1->id));
89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers connected: %s <-> %s\n", p1_c,
90 GNUNET_i2s (&p2->id));
96 notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
97 const struct GNUNET_TRANSPORT_ATS_Information *ats,
100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
106 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n",
113 notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
114 const struct GNUNET_MessageHeader *message,
115 const struct GNUNET_TRANSPORT_ATS_Information *ats,
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n");
123 run (void *cls, char *const *args, const char *cfgfile,
124 const struct GNUNET_CONFIGURATION_Handle *cfg)
127 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL);
129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
130 p1 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer1.conf",
131 ¬ify_receive, ¬ify_connect,
132 ¬ify_disconnect, p1);
134 p2 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer2.conf",
135 ¬ify_receive, ¬ify_connect,
136 ¬ify_disconnect, p2);
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was successfully started\n");
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
142 "Peer1 was not started successfully\n");
143 GNUNET_assert (p1 != NULL);
144 GNUNET_assert (p1->th != NULL);
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was successfully started\n");
149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
150 "Peer2 was not started successfully\n");
151 GNUNET_assert (p2 != NULL);
152 GNUNET_assert (p2->th != NULL);
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peers\n");
156 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
160 main (int argc, char *argv[])
162 GNUNET_log_setup ("test_transport_testing",
170 char *const argv_1[] = { "test_transport_testing",
172 "test_transport_api_data.conf",
179 struct GNUNET_GETOPT_CommandLineOption options[] = {
180 GNUNET_GETOPT_OPTION_END
183 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1,
184 "test_transport_testing", "nohelp", options, &run, &ret);
189 /* end of test_transport_api.c */