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 it
6 under the terms of the GNU 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.
16 * @file transport/test_transport_api_manipulation_recv_tcp.c
17 * @brief base test case for transport traffic manipulation implementation
19 * This test case will setup 2 peers and connect them, the first message
20 * will be sent without manipulation, then a receive delay of 1 second will
21 * be configured and 2 more message will be sent. Time will be measured
23 * In addition the distance on receiver side will be manipulated to be 10
26 #include "gnunet_transport_service.h"
27 #include "transport-testing.h"
30 * How long until we give up on transmitting the message?
32 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
35 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
37 static int messages_recv;
39 static struct GNUNET_TIME_Absolute start_normal;
41 static struct GNUNET_TIME_Relative dur_normal;
43 static struct GNUNET_TIME_Absolute start_delayed;
45 static struct GNUNET_TIME_Relative dur_delayed;
51 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
58 delayed_transmit (void *cls)
60 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
62 start_delayed = GNUNET_TIME_absolute_get ();
63 GNUNET_TRANSPORT_TESTING_large_send (sc);
70 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc;
71 struct GNUNET_ATS_Properties prop;
72 struct GNUNET_TIME_Relative delay;
74 sc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_SendClosure);
79 if (0 == messages_recv)
81 start_normal = GNUNET_TIME_absolute_get();
83 if (0 < messages_recv)
88 delay = GNUNET_TIME_UNIT_SECONDS;
89 GNUNET_TRANSPORT_manipulation_set (ccc->p[1]->tmh,
93 GNUNET_TIME_UNIT_ZERO);
94 /* wait 1s to allow manipulation to go into effect */
95 if (1 == messages_recv)
97 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
103 GNUNET_TRANSPORT_TESTING_large_send (sc);
108 notify_receive (void *cls,
109 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
110 const struct GNUNET_PeerIdentity *sender,
111 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
114 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
117 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
120 ntohs (message->header.type),
121 ntohs (message->header.size),
122 GNUNET_i2s (sender));
125 if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) ||
126 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->header.size)) )
129 ccc->global_ret = GNUNET_SYSERR;
130 GNUNET_SCHEDULER_shutdown ();
134 if (messages_recv <= 2)
136 /* Received non-delayed message */
137 dur_normal = GNUNET_TIME_absolute_get_duration (start_normal);
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
139 "Received non-delayed message %u after %s\n",
141 GNUNET_STRINGS_relative_time_to_string (dur_normal,
143 GNUNET_SCHEDULER_add_now (&sendtask,
148 /* Received manipulated message */
149 dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed);
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
151 "Received delayed message %u after %s\n",
153 GNUNET_STRINGS_relative_time_to_string (dur_delayed,
155 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us)
158 ccc->global_ret = GNUNET_SYSERR;
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "Delayed message was not delayed correctly: took only %s\n",
161 GNUNET_STRINGS_relative_time_to_string (dur_delayed,
166 ccc->global_ret = GNUNET_OK;
169 GNUNET_SCHEDULER_shutdown ();
177 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
178 .connect_continuation = &sendtask,
179 .config_file = "test_transport_api_data.conf",
180 .rec = ¬ify_receive,
181 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
182 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
184 .global_ret = GNUNET_NO
189 GNUNET_TRANSPORT_TESTING_main (2,
190 &GNUNET_TRANSPORT_TESTING_connect_check,
196 /* end of test_transport_api_manipulation_recv_tcp.c */