remove never working setuid helper code from the build-system.
[oweals/gnunet.git] / src / transport / test_transport_api_manipulation_cfg.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 2010, 2016 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 /**
21  * @file transport/test_transport_api_manipulation_cfg.c
22  * @brief base test case for transport traffic manipulation implementation
23  * based on cfg
24  *
25  * Peer 1 has inbound and outbound delay of 100ms
26  * Peer 2 has no inbound and outbound delay
27  *
28  * We send a request from P1 to P2 and expect delay of >= TEST_DELAY us
29  * Then we send response from P2 to P1 and expect delay of >= TEST_DELAY us
30  */
31 #include "platform.h"
32 #include "gnunet_transport_service.h"
33 #include "transport-testing.h"
34
35 /**
36  * How long until we give up on transmitting the message?
37  */
38 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
39
40
41 #define TEST_MESSAGE_SIZE 2600
42
43 #define TEST_RESPONSE_MESSAGE_TYPE
44
45 /**
46  * Test delay, in microseconds.
47  */
48 #define TEST_DELAY 100 * 1000LL
49
50
51 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
52
53 static struct GNUNET_TIME_Absolute start_request;
54
55 static struct GNUNET_TIME_Absolute start_response;
56
57
58 static void
59 sendtask_response_task (void *cls)
60 {
61   int ret;
62
63   start_response = GNUNET_TIME_absolute_get ();
64   ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
65                                        ccc->p[0],
66                                        GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
67                                        TEST_MESSAGE_SIZE,
68                                        1,
69                                        NULL,
70                                        NULL);
71   if (GNUNET_NO == ret)
72   {
73     GNUNET_break (0);
74     GNUNET_SCHEDULER_shutdown ();
75     return;
76   }
77   GNUNET_assert (GNUNET_SYSERR != ret);
78 }
79
80
81 static void
82 notify_receive (void *cls,
83                 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
84                 const struct GNUNET_PeerIdentity *sender,
85                 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
86 {
87   struct GNUNET_TIME_Relative duration;
88
89   {
90     char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
91
92     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
93                 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
94                 receiver->no,
95                 ps,
96                 ntohs (message->header.type),
97                 ntohs (message->header.size),
98                 GNUNET_i2s (sender));
99     GNUNET_free (ps);
100   }
101
102   switch (ntohs (message->header.type))
103   {
104   case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE:
105     duration = GNUNET_TIME_absolute_get_difference (start_request,
106                                                     GNUNET_TIME_absolute_get ());
107     if (duration.rel_value_us >= TEST_DELAY)
108     {
109       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
110                   "Request message was delayed for %s\n",
111                   GNUNET_STRINGS_relative_time_to_string (duration,
112                                                           GNUNET_YES));
113     }
114     else
115     {
116       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
117                   "Request message was delayed for unexpected duration %s\n",
118                   GNUNET_STRINGS_relative_time_to_string (duration,
119                                                           GNUNET_YES));
120       ccc->global_ret = GNUNET_SYSERR;
121       GNUNET_SCHEDULER_shutdown ();
122     }
123     /* Send response */
124     GNUNET_SCHEDULER_add_now (&sendtask_response_task,
125                               NULL);
126     return;
127
128   case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2:
129     duration = GNUNET_TIME_absolute_get_difference (start_response,
130                                                     GNUNET_TIME_absolute_get ());
131     if (duration.rel_value_us >= TEST_DELAY)
132     {
133       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
134                   "Response message was delayed for %s\n",
135                   GNUNET_STRINGS_relative_time_to_string (duration,
136                                                           GNUNET_YES));
137       ccc->global_ret = GNUNET_OK;
138     }
139     else
140     {
141       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
142                   "Response message was delayed for unexpected duration %s\n",
143                   GNUNET_STRINGS_relative_time_to_string (duration,
144                                                           GNUNET_YES));
145       ccc->global_ret = GNUNET_SYSERR;
146     }
147     GNUNET_SCHEDULER_shutdown ();
148     break;
149
150   default:
151     GNUNET_break (0);
152     break;
153   }
154 }
155
156
157 int
158 main (int argc,
159       char *argv[])
160 {
161   struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
162     .num_messages = 1
163   };
164   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
165     .connect_continuation = &GNUNET_TRANSPORT_TESTING_large_send,
166     .connect_continuation_cls = &sc,
167     .config_file = "test_transport_api_data.conf",
168     .rec = &notify_receive,
169     .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
170     .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
171     .timeout = TIMEOUT
172   };
173
174   ccc = &my_ccc;
175   sc.ccc = ccc;
176   start_request = GNUNET_TIME_absolute_get ();
177   if (GNUNET_OK !=
178       GNUNET_TRANSPORT_TESTING_main (2,
179                                      &GNUNET_TRANSPORT_TESTING_connect_check,
180                                      ccc))
181     return 1;
182   return 0;
183 }
184
185
186 /* end of test_transport_api_manipulation_cfg.c */