2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2016 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file transport/test_transport_api.c
22 * @brief base test case for transport implementations
23 * @author Christian Grothoff
25 * This test case serves as a base for tcp, udp, and udp-nat
26 * transport test cases. Based on the executable being run
27 * the correct test case will be performed. Conservation of
31 #include "gnunet_transport_service.h"
32 #include "transport-testing.h"
35 * How long until we give up on transmitting the message?
37 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
40 * How long until we give up on transmitting the message?
42 #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
44 #define TEST_MESSAGE_SIZE 2600
46 #define TEST_MESSAGE_TYPE 12345
49 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
51 static struct GNUNET_TRANSPORT_TransmitHandle *th;
55 custom_shutdown (void *cls)
59 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
66 notify_receive (void *cls,
67 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
68 const struct GNUNET_PeerIdentity *sender,
69 const struct GNUNET_MessageHeader *message)
72 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
74 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
75 "Peer %u (`%4s') received message of type %d and size %u size from peer %s!\n",
78 ntohs (message->type),
79 ntohs (message->size),
84 if ((TEST_MESSAGE_TYPE == ntohs (message->type)) &&
85 (TEST_MESSAGE_SIZE == ntohs (message->size)))
87 ccc->global_ret = GNUNET_OK;
88 GNUNET_SCHEDULER_shutdown ();
93 ccc->global_ret = GNUNET_SYSERR;
94 GNUNET_SCHEDULER_shutdown ();
100 notify_ready (void *cls,
104 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
105 struct GNUNET_MessageHeader *hdr;
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
111 "Timeout occurred while waiting for transmit_ready\n");
112 GNUNET_SCHEDULER_shutdown ();
113 ccc->global_ret = 42;
117 GNUNET_assert (size >= TEST_MESSAGE_SIZE);
120 memset (buf, '\0', TEST_MESSAGE_SIZE);
122 hdr->size = htons (TEST_MESSAGE_SIZE);
123 hdr->type = htons (TEST_MESSAGE_TYPE);
127 char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id));
128 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
129 "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
135 GNUNET_i2s (&p->id));
138 return TEST_MESSAGE_SIZE;
146 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
148 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
149 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
151 GNUNET_i2s (&ccc->p[1]->id),
154 GNUNET_free (receiver_s);
156 ccc->global_ret = GNUNET_SYSERR;
157 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
163 GNUNET_assert (NULL != th);
168 notify_disconnect (void *cls,
169 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
170 const struct GNUNET_PeerIdentity *other)
172 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
177 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
186 * @param argv the argv argument from main()
187 * @param bi_directional should we try to establish connections
188 * in both directions simultaneously?
194 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
195 .connect_continuation = &sendtask,
196 .config_file = "test_transport_api_data.conf",
197 .rec = ¬ify_receive,
198 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
199 .nd = ¬ify_disconnect,
200 .shutdown_task = &custom_shutdown,
202 .bi_directional = bi_directional
207 GNUNET_TRANSPORT_TESTING_main (2,
208 &GNUNET_TRANSPORT_TESTING_connect_check,
219 if ( (0 != test (argv,
227 /* end of test_transport_api.c */