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 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.
16 * @file transport/test_transport_api_manipulation_cfg.c
17 * @brief base test case for transport traffic manipulation implementation
20 * Peer 1 has inbound and outbound delay of 100ms
21 * Peer 2 has no inbound and outbound delay
23 * We send a request from P1 to P2 and expect delay of >= TEST_DELAY us
24 * Then we send response from P2 to P1 and expect delay of >= TEST_DELAY us
27 #include "gnunet_transport_service.h"
28 #include "transport-testing.h"
31 * How long until we give up on transmitting the message?
33 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
36 #define TEST_MESSAGE_SIZE 2600
38 #define TEST_RESPONSE_MESSAGE_TYPE
41 * Test delay, in microseconds.
43 #define TEST_DELAY 100 * 1000LL
46 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
48 static struct GNUNET_TIME_Absolute start_request;
50 static struct GNUNET_TIME_Absolute start_response;
54 sendtask_response_task (void *cls)
58 start_response = GNUNET_TIME_absolute_get();
59 ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
61 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
69 GNUNET_SCHEDULER_shutdown ();
72 GNUNET_assert (GNUNET_SYSERR != ret);
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 struct GNUNET_TIME_Relative duration;
85 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
88 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
91 ntohs (message->header.type),
92 ntohs (message->header.size),
97 switch (ntohs (message->header.type)) {
98 case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE:
99 duration = GNUNET_TIME_absolute_get_difference (start_request,
100 GNUNET_TIME_absolute_get());
101 if (duration.rel_value_us >= TEST_DELAY)
103 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
104 "Request message was delayed for %s\n",
105 GNUNET_STRINGS_relative_time_to_string (duration,
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
111 "Request message was delayed for unexpected duration %s\n",
112 GNUNET_STRINGS_relative_time_to_string (duration,
114 ccc->global_ret = GNUNET_SYSERR;
115 GNUNET_SCHEDULER_shutdown ();
118 GNUNET_SCHEDULER_add_now (&sendtask_response_task,
121 case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2:
122 duration = GNUNET_TIME_absolute_get_difference(start_response,
123 GNUNET_TIME_absolute_get());
124 if (duration.rel_value_us >= TEST_DELAY)
126 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
127 "Response message was delayed for %s\n",
128 GNUNET_STRINGS_relative_time_to_string (duration,
130 ccc->global_ret = GNUNET_OK;
134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
135 "Response message was delayed for unexpected duration %s\n",
136 GNUNET_STRINGS_relative_time_to_string (duration,
138 ccc->global_ret = GNUNET_SYSERR;
140 GNUNET_SCHEDULER_shutdown ();
153 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
156 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
157 .connect_continuation = &GNUNET_TRANSPORT_TESTING_large_send,
158 .connect_continuation_cls = &sc,
159 .config_file = "test_transport_api_data.conf",
160 .rec = ¬ify_receive,
161 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
162 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
169 GNUNET_TRANSPORT_TESTING_main (2,
170 &GNUNET_TRANSPORT_TESTING_connect_check,
177 /* end of test_transport_api_manipulation_cfg.c */