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
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_transport_service.h"
31 #include "transport-testing.h"
34 * How long until we give up on transmitting the message?
36 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
39 * How long until we give up on transmitting the message?
41 #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
43 #define TEST_MESSAGE_SIZE 2600
45 #define TEST_MESSAGE_TYPE 12345
48 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
50 static struct GNUNET_TRANSPORT_TransmitHandle *th;
54 custom_shutdown (void *cls)
58 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
62 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
63 "Peers were not ready to send data\n");
68 notify_receive (void *cls,
69 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
70 const struct GNUNET_PeerIdentity *sender,
71 const struct GNUNET_MessageHeader *message)
74 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
76 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
77 "Peer %u (`%4s') received message of type %d and size %u size from peer %s!\n",
80 ntohs (message->type),
81 ntohs (message->size),
86 if ((TEST_MESSAGE_TYPE == ntohs (message->type)) &&
87 (TEST_MESSAGE_SIZE == ntohs (message->size)))
89 ccc->global_ret = GNUNET_OK;
90 GNUNET_SCHEDULER_shutdown ();
95 ccc->global_ret = GNUNET_SYSERR;
96 GNUNET_SCHEDULER_shutdown ();
102 notify_ready (void *cls,
106 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
107 struct GNUNET_MessageHeader *hdr;
112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
113 "Timeout occurred while waiting for transmit_ready\n");
114 GNUNET_SCHEDULER_shutdown ();
115 ccc->global_ret = 42;
119 GNUNET_assert (size >= TEST_MESSAGE_SIZE);
122 memset (buf, '\0', TEST_MESSAGE_SIZE);
124 hdr->size = htons (TEST_MESSAGE_SIZE);
125 hdr->type = htons (TEST_MESSAGE_TYPE);
129 char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id));
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
131 "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
137 GNUNET_i2s (&p->id));
140 return TEST_MESSAGE_SIZE;
148 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
150 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
151 "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
153 GNUNET_i2s (&ccc->p[1]->id),
156 GNUNET_free (receiver_s);
158 ccc->global_ret = GNUNET_SYSERR;
159 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
169 notify_disconnect (void *cls,
170 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
171 const struct GNUNET_PeerIdentity *other)
173 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
178 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
188 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
189 .connect_continuation = &sendtask,
190 .config_file = "test_transport_api_data.conf",
191 .rec = ¬ify_receive,
192 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
193 .nd = ¬ify_disconnect,
194 .shutdown_task = &custom_shutdown,
200 GNUNET_TRANSPORT_TESTING_main (2,
201 &GNUNET_TRANSPORT_TESTING_connect_check,
207 /* end of test_transport_api.c */