aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_manipulation_recv_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_api_manipulation_recv_tcp.c')
-rw-r--r--src/transport/test_transport_api_manipulation_recv_tcp.c180
1 files changed, 90 insertions, 90 deletions
diff --git a/src/transport/test_transport_api_manipulation_recv_tcp.c b/src/transport/test_transport_api_manipulation_recv_tcp.c
index bf7eb1666..080d245ca 100644
--- a/src/transport/test_transport_api_manipulation_recv_tcp.c
+++ b/src/transport/test_transport_api_manipulation_recv_tcp.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_manipulation_recv_tcp.c 21 * @file transport/test_transport_api_manipulation_recv_tcp.c
22 * @brief base test case for transport traffic manipulation implementation 22 * @brief base test case for transport traffic manipulation implementation
@@ -34,7 +34,7 @@
34/** 34/**
35 * How long until we give up on transmitting the message? 35 * How long until we give up on transmitting the message?
36 */ 36 */
37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 37#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120)
38 38
39 39
40static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 40static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
@@ -51,133 +51,133 @@ static struct GNUNET_TIME_Relative dur_delayed;
51 51
52 52
53static void 53static void
54do_free (void *cls) 54do_free(void *cls)
55{ 55{
56 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 56 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
57 57
58 GNUNET_free (sc); 58 GNUNET_free(sc);
59} 59}
60 60
61 61
62static void 62static void
63delayed_transmit (void *cls) 63delayed_transmit(void *cls)
64{ 64{
65 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 65 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
66 66
67 start_delayed = GNUNET_TIME_absolute_get (); 67 start_delayed = GNUNET_TIME_absolute_get();
68 GNUNET_TRANSPORT_TESTING_large_send (sc); 68 GNUNET_TRANSPORT_TESTING_large_send(sc);
69} 69}
70 70
71 71
72static void 72static void
73sendtask (void *cls) 73sendtask(void *cls)
74{ 74{
75 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc; 75 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc;
76 struct GNUNET_ATS_Properties prop; 76 struct GNUNET_ATS_Properties prop;
77 struct GNUNET_TIME_Relative delay; 77 struct GNUNET_TIME_Relative delay;
78 78
79 sc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_SendClosure); 79 sc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_SendClosure);
80 sc->num_messages = 1; 80 sc->num_messages = 1;
81 sc->ccc = ccc; 81 sc->ccc = ccc;
82 sc->cont = &do_free; 82 sc->cont = &do_free;
83 sc->cont_cls = sc; 83 sc->cont_cls = sc;
84 if (0 == messages_recv) 84 if (0 == messages_recv)
85 { 85 {
86 start_normal = GNUNET_TIME_absolute_get(); 86 start_normal = GNUNET_TIME_absolute_get();
87 } 87 }
88 if (0 < messages_recv) 88 if (0 < messages_recv)
89 {
90 memset (&prop,
91 0,
92 sizeof (prop));
93 delay = GNUNET_TIME_UNIT_SECONDS;
94 GNUNET_TRANSPORT_manipulation_set (ccc->p[1]->tmh,
95 &ccc->p[0]->id,
96 &prop,
97 delay,
98 GNUNET_TIME_UNIT_ZERO);
99 /* wait 1s to allow manipulation to go into effect */
100 if (1 == messages_recv)
101 { 89 {
102 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 90 memset(&prop,
103 &delayed_transmit, 91 0,
104 sc); 92 sizeof(prop));
105 return; 93 delay = GNUNET_TIME_UNIT_SECONDS;
94 GNUNET_TRANSPORT_manipulation_set(ccc->p[1]->tmh,
95 &ccc->p[0]->id,
96 &prop,
97 delay,
98 GNUNET_TIME_UNIT_ZERO);
99 /* wait 1s to allow manipulation to go into effect */
100 if (1 == messages_recv)
101 {
102 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
103 &delayed_transmit,
104 sc);
105 return;
106 }
106 } 107 }
107 } 108 GNUNET_TRANSPORT_TESTING_large_send(sc);
108 GNUNET_TRANSPORT_TESTING_large_send (sc);
109} 109}
110 110
111 111
112static void 112static void
113notify_receive (void *cls, 113notify_receive(void *cls,
114 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 114 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
115 const struct GNUNET_PeerIdentity *sender, 115 const struct GNUNET_PeerIdentity *sender,
116 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 116 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
117{ 117{
118 { 118 {
119 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 119 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id));
120 120
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 121 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
122 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", 122 "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n",
123 receiver->no, 123 receiver->no,
124 ps, 124 ps,
125 ntohs (message->header.type), 125 ntohs(message->header.type),
126 ntohs (message->header.size), 126 ntohs(message->header.size),
127 GNUNET_i2s (sender)); 127 GNUNET_i2s(sender));
128 GNUNET_free (ps); 128 GNUNET_free(ps);
129 }
130 if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) ||
131 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->header.size)) )
132 {
133 GNUNET_break (0);
134 ccc->global_ret = GNUNET_SYSERR;
135 GNUNET_SCHEDULER_shutdown ();
136 return;
137 } 129 }
130 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(message->header.type)) ||
131 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs(message->header.size)))
132 {
133 GNUNET_break(0);
134 ccc->global_ret = GNUNET_SYSERR;
135 GNUNET_SCHEDULER_shutdown();
136 return;
137 }
138 138
139 if (messages_recv <= 2) 139 if (messages_recv <= 2)
140 { 140 {
141 /* Received non-delayed message */ 141 /* Received non-delayed message */
142 dur_normal = GNUNET_TIME_absolute_get_duration (start_normal); 142 dur_normal = GNUNET_TIME_absolute_get_duration(start_normal);
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 143 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
144 "Received non-delayed message %u after %s\n", 144 "Received non-delayed message %u after %s\n",
145 messages_recv, 145 messages_recv,
146 GNUNET_STRINGS_relative_time_to_string (dur_normal, 146 GNUNET_STRINGS_relative_time_to_string(dur_normal,
147 GNUNET_YES)); 147 GNUNET_YES));
148 GNUNET_SCHEDULER_add_now (&sendtask, 148 GNUNET_SCHEDULER_add_now(&sendtask,
149 NULL); 149 NULL);
150 messages_recv++; 150 messages_recv++;
151 return; 151 return;
152 } 152 }
153 /* Received manipulated message */ 153 /* Received manipulated message */
154 dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); 154 dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed);
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 155 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
156 "Received delayed message %u after %s\n", 156 "Received delayed message %u after %s\n",
157 messages_recv, 157 messages_recv,
158 GNUNET_STRINGS_relative_time_to_string (dur_delayed, 158 GNUNET_STRINGS_relative_time_to_string(dur_delayed,
159 GNUNET_YES)); 159 GNUNET_YES));
160 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) 160 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us)
161 { 161 {
162 GNUNET_break (0); 162 GNUNET_break(0);
163 ccc->global_ret = GNUNET_SYSERR; 163 ccc->global_ret = GNUNET_SYSERR;
164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 164 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
165 "Delayed message was not delayed correctly: took only %s\n", 165 "Delayed message was not delayed correctly: took only %s\n",
166 GNUNET_STRINGS_relative_time_to_string (dur_delayed, 166 GNUNET_STRINGS_relative_time_to_string(dur_delayed,
167 GNUNET_YES)); 167 GNUNET_YES));
168 } 168 }
169 else 169 else
170 { 170 {
171 ccc->global_ret = GNUNET_OK; 171 ccc->global_ret = GNUNET_OK;
172 } 172 }
173 /* shutdown */ 173 /* shutdown */
174 GNUNET_SCHEDULER_shutdown (); 174 GNUNET_SCHEDULER_shutdown();
175} 175}
176 176
177 177
178int 178int
179main (int argc, 179main(int argc,
180 char *argv[]) 180 char *argv[])
181{ 181{
182 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 182 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
183 .connect_continuation = &sendtask, 183 .connect_continuation = &sendtask,
@@ -191,9 +191,9 @@ main (int argc,
191 191
192 ccc = &my_ccc; 192 ccc = &my_ccc;
193 if (GNUNET_OK != 193 if (GNUNET_OK !=
194 GNUNET_TRANSPORT_TESTING_main (2, 194 GNUNET_TRANSPORT_TESTING_main(2,
195 &GNUNET_TRANSPORT_TESTING_connect_check, 195 &GNUNET_TRANSPORT_TESTING_connect_check,
196 ccc)) 196 ccc))
197 return 1; 197 return 1;
198 return 0; 198 return 0;
199} 199}