2 This file is part of GNUnet.x
3 Copyright (C) 2009, 2010, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file transport/test_transport_api_timeout.c
20 * @brief test case for transport plugin implementations complying timeout
24 * This test case serves ensures that no peer disconnect events occurs
25 * while plugins are idle
29 #include "gnunet_transport_service.h"
30 #include "transport-testing.h"
33 * How long until we give up on transmitting the message?
35 #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
37 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
41 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
43 static struct GNUNET_TIME_Relative time_running;
45 static struct GNUNET_SCHEDULER_Task *timer_task;
47 static int shutdown_flag;
49 static unsigned int disconnects;
53 custom_shutdown (void *cls)
55 if (NULL != timer_task)
57 GNUNET_SCHEDULER_cancel (timer_task);
62 ccc->global_ret = GNUNET_OK;
66 ccc->global_ret =- GNUNET_SYSERR;
67 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
68 "Fail! Had %u disconnects while waiting %s\n",
70 GNUNET_STRINGS_relative_time_to_string (WAIT,
77 notify_receive (void *cls,
78 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
79 const struct GNUNET_PeerIdentity *sender,
80 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
83 "Received message of type %d from peer %s!\n",
84 ntohs (message->header.type),
90 notify_disconnect (void *cls,
91 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
92 const struct GNUNET_PeerIdentity *other)
94 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
97 if (shutdown_flag != GNUNET_YES)
99 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
100 "FAIL! Peer `%s' disconnected during waiting period!\n",
110 static unsigned int percentage;
114 time_running = GNUNET_TIME_relative_add (time_running,
115 GNUNET_TIME_relative_divide (WAIT,
118 if (time_running.rel_value_us ==
119 GNUNET_TIME_relative_max (time_running, WAIT).rel_value_us)
121 FPRINTF (stderr, "%s", "100%%\n");
122 shutdown_flag = GNUNET_YES;
123 GNUNET_SCHEDULER_shutdown ();
131 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (WAIT, 10),
142 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
143 .connect_continuation = &timer,
144 .config_file = "test_transport_api_data.conf",
145 .rec = ¬ify_receive,
146 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
147 .nd = ¬ify_disconnect,
148 .shutdown_task = &custom_shutdown,
154 GNUNET_TRANSPORT_TESTING_main (2,
155 &GNUNET_TRANSPORT_TESTING_connect_check,
161 /* end of test_transport_api_timeout.c*/