diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-22 21:35:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-22 21:35:51 +0000 |
commit | 8d0883a3f695261cfd8651ed53734f2f4fb30417 (patch) | |
tree | 389c86b7c6ec9777498ae54e4650c9dbc69b94fc /src/transport/test_transport_api_manipulation_cfg.c | |
parent | b77b2502d587f576baff39120e6f37235c5b5b90 (diff) | |
download | gnunet-8d0883a3f695261cfd8651ed53734f2f4fb30417.tar.gz gnunet-8d0883a3f695261cfd8651ed53734f2f4fb30417.zip |
migrate more tests to new transmission API
Diffstat (limited to 'src/transport/test_transport_api_manipulation_cfg.c')
-rw-r--r-- | src/transport/test_transport_api_manipulation_cfg.c | 212 |
1 files changed, 36 insertions, 176 deletions
diff --git a/src/transport/test_transport_api_manipulation_cfg.c b/src/transport/test_transport_api_manipulation_cfg.c index 19823e0b3..84824ad8b 100644 --- a/src/transport/test_transport_api_manipulation_cfg.c +++ b/src/transport/test_transport_api_manipulation_cfg.c | |||
@@ -20,7 +20,7 @@ | |||
20 | /** | 20 | /** |
21 | * @file transport/test_transport_api_manipulation_cfg.c | 21 | * @file transport/test_transport_api_manipulation_cfg.c |
22 | * @brief base test case for transport traffic manipulation implementation | 22 | * @brief base test case for transport traffic manipulation implementation |
23 | * based onf cfg | 23 | * based on cfg |
24 | * | 24 | * |
25 | * Peer 1 has inbound and outbound delay of 100ms | 25 | * Peer 1 has inbound and outbound delay of 100ms |
26 | * Peer 2 has no inbound and outbound delay | 26 | * Peer 2 has no inbound and outbound delay |
@@ -37,15 +37,9 @@ | |||
37 | */ | 37 | */ |
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
39 | 39 | ||
40 | /** | ||
41 | * How long until we give up on transmitting the message? | ||
42 | */ | ||
43 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
44 | 40 | ||
45 | #define TEST_MESSAGE_SIZE 2600 | 41 | #define TEST_MESSAGE_SIZE 2600 |
46 | 42 | ||
47 | #define TEST_REQUEST_MESSAGE_TYPE 12345 | ||
48 | |||
49 | #define TEST_RESPONSE_MESSAGE_TYPE 12346 | 43 | #define TEST_RESPONSE_MESSAGE_TYPE 12346 |
50 | 44 | ||
51 | /** | 45 | /** |
@@ -56,157 +50,31 @@ | |||
56 | 50 | ||
57 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 51 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
58 | 52 | ||
59 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
60 | |||
61 | static struct GNUNET_SCHEDULER_Task *send_task; | ||
62 | |||
63 | static struct GNUNET_TIME_Absolute start_request; | 53 | static struct GNUNET_TIME_Absolute start_request; |
64 | 54 | ||
65 | static struct GNUNET_TIME_Absolute start_response; | 55 | static struct GNUNET_TIME_Absolute start_response; |
66 | 56 | ||
67 | 57 | ||
68 | static void | 58 | static void |
69 | custom_shutdown (void *cls) | ||
70 | { | ||
71 | if (NULL != th) | ||
72 | { | ||
73 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
74 | th = NULL; | ||
75 | } | ||
76 | if (NULL != send_task) | ||
77 | { | ||
78 | GNUNET_SCHEDULER_cancel (send_task); | ||
79 | send_task = NULL; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | |||
84 | static size_t | ||
85 | notify_request_ready (void *cls, size_t size, void *buf) | ||
86 | { | ||
87 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
88 | struct GNUNET_MessageHeader *hdr; | ||
89 | |||
90 | th = NULL; | ||
91 | if (NULL == buf) | ||
92 | { | ||
93 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
94 | "Timeout occurred while waiting for transmit_ready\n"); | ||
95 | GNUNET_SCHEDULER_shutdown (); | ||
96 | ccc->global_ret = 42; | ||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | GNUNET_assert (size >= TEST_MESSAGE_SIZE); | ||
101 | memset (buf, '\0', TEST_MESSAGE_SIZE); | ||
102 | hdr = buf; | ||
103 | hdr->size = htons (TEST_MESSAGE_SIZE); | ||
104 | hdr->type = htons (TEST_REQUEST_MESSAGE_TYPE); | ||
105 | |||
106 | { | ||
107 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | ||
108 | |||
109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
110 | "Sending request message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n", | ||
111 | ccc->p[0]->no, ps, | ||
112 | ntohs (hdr->type), | ||
113 | ntohs (hdr->size), | ||
114 | p->no, | ||
115 | GNUNET_i2s (&p->id)); | ||
116 | GNUNET_free (ps); | ||
117 | } | ||
118 | |||
119 | return TEST_MESSAGE_SIZE; | ||
120 | } | ||
121 | |||
122 | |||
123 | static void | ||
124 | sendtask_request_task (void *cls) | ||
125 | { | ||
126 | send_task = NULL; | ||
127 | { | ||
128 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); | ||
129 | |||
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
131 | "Sending message from peer %u (`%s') -> peer %u (`%s') !\n", | ||
132 | ccc->p[0]->no, | ||
133 | GNUNET_i2s (&ccc->p[0]->id), | ||
134 | ccc->p[1]->no, | ||
135 | receiver_s); | ||
136 | GNUNET_free (receiver_s); | ||
137 | } | ||
138 | |||
139 | start_request = GNUNET_TIME_absolute_get(); | ||
140 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[0]->th, | ||
141 | &ccc->p[1]->id, | ||
142 | TEST_MESSAGE_SIZE, | ||
143 | TIMEOUT_TRANSMIT, | ||
144 | ¬ify_request_ready, | ||
145 | ccc->p[1]); | ||
146 | } | ||
147 | |||
148 | |||
149 | static size_t | ||
150 | notify_response_ready (void *cls, size_t size, void *buf) | ||
151 | { | ||
152 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
153 | struct GNUNET_MessageHeader *hdr; | ||
154 | |||
155 | th = NULL; | ||
156 | if (NULL == buf) | ||
157 | { | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
159 | "Timeout occurred while waiting for transmit_ready\n"); | ||
160 | GNUNET_SCHEDULER_shutdown (); | ||
161 | ccc->global_ret = 42; | ||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | GNUNET_assert (size >= TEST_MESSAGE_SIZE); | ||
166 | memset (buf, '\0', TEST_MESSAGE_SIZE); | ||
167 | hdr = buf; | ||
168 | hdr->size = htons (TEST_MESSAGE_SIZE); | ||
169 | hdr->type = htons (TEST_RESPONSE_MESSAGE_TYPE); | ||
170 | |||
171 | { | ||
172 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | ||
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
174 | "Sending response message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n", | ||
175 | ccc->p[0]->no, | ||
176 | ps, | ||
177 | ntohs (hdr->type), | ||
178 | ntohs (hdr->size), | ||
179 | p->no, | ||
180 | GNUNET_i2s (&p->id)); | ||
181 | GNUNET_free (ps); | ||
182 | } | ||
183 | |||
184 | return TEST_MESSAGE_SIZE; | ||
185 | } | ||
186 | |||
187 | |||
188 | static void | ||
189 | sendtask_response_task (void *cls) | 59 | sendtask_response_task (void *cls) |
190 | { | 60 | { |
191 | send_task = NULL; | 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 | TEST_RESPONSE_MESSAGE_TYPE, | ||
67 | TEST_MESSAGE_SIZE, | ||
68 | 1, | ||
69 | NULL, | ||
70 | NULL); | ||
71 | if (GNUNET_NO == ret) | ||
192 | { | 72 | { |
193 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | 73 | GNUNET_break (0); |
194 | 74 | GNUNET_SCHEDULER_shutdown (); | |
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 75 | return; |
196 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
197 | ccc->p[1]->no, | ||
198 | GNUNET_i2s (&ccc->p[1]->id), | ||
199 | ccc->p[0]->no, | ||
200 | receiver_s); | ||
201 | GNUNET_free (receiver_s); | ||
202 | } | 76 | } |
203 | start_response = GNUNET_TIME_absolute_get(); | 77 | GNUNET_assert (GNUNET_SYSERR != ret); |
204 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | ||
205 | &ccc->p[0]->id, | ||
206 | TEST_MESSAGE_SIZE, | ||
207 | TIMEOUT_TRANSMIT, | ||
208 | ¬ify_response_ready, | ||
209 | ccc->p[0]); | ||
210 | } | 78 | } |
211 | 79 | ||
212 | 80 | ||
@@ -232,14 +100,16 @@ notify_receive (void *cls, | |||
232 | } | 100 | } |
233 | 101 | ||
234 | switch (ntohs (message->type)) { | 102 | switch (ntohs (message->type)) { |
235 | case TEST_REQUEST_MESSAGE_TYPE: | 103 | case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE: |
236 | duration = GNUNET_TIME_absolute_get_difference(start_request, | 104 | duration = GNUNET_TIME_absolute_get_difference (start_request, |
237 | GNUNET_TIME_absolute_get()); | 105 | GNUNET_TIME_absolute_get()); |
238 | if (duration.rel_value_us >= TEST_DELAY) | 106 | if (duration.rel_value_us >= TEST_DELAY) |
107 | { | ||
239 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 108 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
240 | "Request message was delayed for %s\n", | 109 | "Request message was delayed for %s\n", |
241 | GNUNET_STRINGS_relative_time_to_string (duration, | 110 | GNUNET_STRINGS_relative_time_to_string (duration, |
242 | GNUNET_YES)); | 111 | GNUNET_YES)); |
112 | } | ||
243 | else | 113 | else |
244 | { | 114 | { |
245 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -250,17 +120,20 @@ notify_receive (void *cls, | |||
250 | GNUNET_SCHEDULER_shutdown (); | 120 | GNUNET_SCHEDULER_shutdown (); |
251 | } | 121 | } |
252 | /* Send response */ | 122 | /* Send response */ |
253 | send_task = GNUNET_SCHEDULER_add_now (&sendtask_response_task, | 123 | GNUNET_SCHEDULER_add_now (&sendtask_response_task, |
254 | NULL); | 124 | NULL); |
255 | return; | 125 | return; |
256 | case TEST_RESPONSE_MESSAGE_TYPE: | 126 | case TEST_RESPONSE_MESSAGE_TYPE: |
257 | duration = GNUNET_TIME_absolute_get_difference(start_response, | 127 | duration = GNUNET_TIME_absolute_get_difference(start_response, |
258 | GNUNET_TIME_absolute_get()); | 128 | GNUNET_TIME_absolute_get()); |
259 | if (duration.rel_value_us >= TEST_DELAY) | 129 | if (duration.rel_value_us >= TEST_DELAY) |
130 | { | ||
260 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 131 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
261 | "Response message was delayed for %s\n", | 132 | "Response message was delayed for %s\n", |
262 | GNUNET_STRINGS_relative_time_to_string (duration, | 133 | GNUNET_STRINGS_relative_time_to_string (duration, |
263 | GNUNET_YES)); | 134 | GNUNET_YES)); |
135 | ccc->global_ret = GNUNET_OK; | ||
136 | } | ||
264 | else | 137 | else |
265 | { | 138 | { |
266 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -268,48 +141,35 @@ notify_receive (void *cls, | |||
268 | GNUNET_STRINGS_relative_time_to_string (duration, | 141 | GNUNET_STRINGS_relative_time_to_string (duration, |
269 | GNUNET_YES)); | 142 | GNUNET_YES)); |
270 | ccc->global_ret = GNUNET_SYSERR; | 143 | ccc->global_ret = GNUNET_SYSERR; |
271 | GNUNET_SCHEDULER_shutdown (); | ||
272 | break; | ||
273 | } | 144 | } |
274 | ccc->global_ret = GNUNET_OK; | ||
275 | GNUNET_SCHEDULER_shutdown (); | 145 | GNUNET_SCHEDULER_shutdown (); |
276 | break; | 146 | break; |
277 | default: | 147 | default: |
148 | GNUNET_break (0); | ||
278 | break; | 149 | break; |
279 | } | 150 | } |
280 | } | 151 | } |
281 | 152 | ||
282 | 153 | ||
283 | static void | ||
284 | notify_disconnect (void *cls, | ||
285 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
286 | const struct GNUNET_PeerIdentity *other) | ||
287 | { | ||
288 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, | ||
289 | me, | ||
290 | other); | ||
291 | if (NULL != th) | ||
292 | { | ||
293 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
294 | th = NULL; | ||
295 | } | ||
296 | } | ||
297 | |||
298 | |||
299 | int | 154 | int |
300 | main (int argc, char *argv[]) | 155 | main (int argc, |
156 | char *argv[]) | ||
301 | { | 157 | { |
158 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | ||
159 | .num_messages = 1 | ||
160 | }; | ||
302 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 161 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
303 | .connect_continuation = &sendtask_request_task, | 162 | .connect_continuation = &GNUNET_TRANSPORT_TESTING_large_send, |
163 | .connect_continuation_cls = &sc, | ||
304 | .config_file = "test_transport_api_data.conf", | 164 | .config_file = "test_transport_api_data.conf", |
305 | .rec = ¬ify_receive, | 165 | .rec = ¬ify_receive, |
306 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 166 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
307 | .nd = ¬ify_disconnect, | 167 | .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect, |
308 | .shutdown_task = &custom_shutdown, | ||
309 | .timeout = TIMEOUT | 168 | .timeout = TIMEOUT |
310 | }; | 169 | }; |
311 | 170 | ||
312 | ccc = &my_ccc; | 171 | ccc = &my_ccc; |
172 | sc.ccc = ccc; | ||
313 | if (GNUNET_OK != | 173 | if (GNUNET_OK != |
314 | GNUNET_TRANSPORT_TESTING_main (2, | 174 | GNUNET_TRANSPORT_TESTING_main (2, |
315 | &GNUNET_TRANSPORT_TESTING_connect_check, | 175 | &GNUNET_TRANSPORT_TESTING_connect_check, |