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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file transport/test_transport_api_timeout.c
22 * @brief test case for transport plugin implementations complying timeout
26 * This test case serves ensures that no peer disconnect events occurs
27 * while plugins are idle
31 #include "gnunet_transport_service.h"
32 #include "transport-testing.h"
35 * How long until we give up on transmitting the message?
37 #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
39 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
43 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
45 static struct GNUNET_TIME_Relative time_running;
47 static struct GNUNET_SCHEDULER_Task *timer_task;
49 static int shutdown_flag;
51 static unsigned int disconnects;
55 custom_shutdown (void *cls)
57 if (NULL != timer_task)
59 GNUNET_SCHEDULER_cancel (timer_task);
64 ccc->global_ret = GNUNET_OK;
68 ccc->global_ret =- GNUNET_SYSERR;
69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
70 "Fail! Had %u disconnects while waiting %s\n",
72 GNUNET_STRINGS_relative_time_to_string (WAIT,
79 notify_receive (void *cls,
80 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
81 const struct GNUNET_PeerIdentity *sender,
82 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
85 "Received message of type %d from peer %s!\n",
86 ntohs (message->header.type),
92 notify_disconnect (void *cls,
93 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
94 const struct GNUNET_PeerIdentity *other)
96 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
99 if (shutdown_flag != GNUNET_YES)
101 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
102 "FAIL! Peer `%s' disconnected during waiting period!\n",
112 static unsigned int percentage;
116 time_running = GNUNET_TIME_relative_add (time_running,
117 GNUNET_TIME_relative_divide (WAIT,
120 if (time_running.rel_value_us ==
121 GNUNET_TIME_relative_max (time_running, WAIT).rel_value_us)
123 FPRINTF (stderr, "%s", "100%%\n");
124 shutdown_flag = GNUNET_YES;
125 GNUNET_SCHEDULER_shutdown ();
133 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (WAIT, 10),
144 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
145 .connect_continuation = &timer,
146 .config_file = "test_transport_api_data.conf",
147 .rec = ¬ify_receive,
148 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
149 .nd = ¬ify_disconnect,
150 .shutdown_task = &custom_shutdown,
156 GNUNET_TRANSPORT_TESTING_main (2,
157 &GNUNET_TRANSPORT_TESTING_connect_check,
163 /* end of test_transport_api_timeout.c*/