diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/transport/test_transport_address_switch.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/transport/test_transport_address_switch.c')
-rw-r--r-- | src/transport/test_transport_address_switch.c | 406 |
1 files changed, 202 insertions, 204 deletions
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index 4cc63766e..ffb6baefe 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 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, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | */ |
@@ -51,7 +51,7 @@ | |||
51 | /** | 51 | /** |
52 | * Testcase timeout (set aggressively as we know this test doesn't work right now) | 52 | * Testcase timeout (set aggressively as we know this test doesn't work right now) |
53 | */ | 53 | */ |
54 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 54 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) |
55 | 55 | ||
56 | 56 | ||
57 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 57 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
@@ -62,8 +62,7 @@ static struct GNUNET_SCHEDULER_Task *measure_task; | |||
62 | /** | 62 | /** |
63 | * Statistics we track per peer. | 63 | * Statistics we track per peer. |
64 | */ | 64 | */ |
65 | struct PeerStats | 65 | struct PeerStats { |
66 | { | ||
67 | struct GNUNET_STATISTICS_Handle *stat; | 66 | struct GNUNET_STATISTICS_Handle *stat; |
68 | 67 | ||
69 | unsigned int addresses_avail; | 68 | unsigned int addresses_avail; |
@@ -84,16 +83,16 @@ static unsigned long long bytes_recv_after_switch; | |||
84 | 83 | ||
85 | 84 | ||
86 | static int | 85 | static int |
87 | stat_start_attempt_cb (void *cls, | 86 | stat_start_attempt_cb(void *cls, |
88 | const char *subsystem, | 87 | const char *subsystem, |
89 | const char *name, | 88 | const char *name, |
90 | uint64_t value, | 89 | uint64_t value, |
91 | int is_persistent) | 90 | int is_persistent) |
92 | { | 91 | { |
93 | struct PeerStats *stat = cls; | 92 | struct PeerStats *stat = cls; |
94 | 93 | ||
95 | stat->switch_attempts++; | 94 | stat->switch_attempts++; |
96 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat); | 95 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat); |
97 | bytes_recv_after_switch = 0; | 96 | bytes_recv_after_switch = 0; |
98 | bytes_sent_after_switch = 0; | 97 | bytes_sent_after_switch = 0; |
99 | 98 | ||
@@ -102,26 +101,26 @@ stat_start_attempt_cb (void *cls, | |||
102 | 101 | ||
103 | 102 | ||
104 | static int | 103 | static int |
105 | stat_success_attempt_cb (void *cls, | 104 | stat_success_attempt_cb(void *cls, |
106 | const char *subsystem, | 105 | const char *subsystem, |
107 | const char *name, | 106 | const char *name, |
108 | uint64_t value, | 107 | uint64_t value, |
109 | int is_persistent) | 108 | int is_persistent) |
110 | { | 109 | { |
111 | struct PeerStats *stat = cls; | 110 | struct PeerStats *stat = cls; |
112 | 111 | ||
113 | stat->switch_success++; | 112 | stat->switch_success++; |
114 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat); | 113 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat); |
115 | return GNUNET_OK; | 114 | return GNUNET_OK; |
116 | } | 115 | } |
117 | 116 | ||
118 | 117 | ||
119 | static int | 118 | static int |
120 | stat_fail_attempt_cb (void *cls, | 119 | stat_fail_attempt_cb(void *cls, |
121 | const char *subsystem, | 120 | const char *subsystem, |
122 | const char *name, | 121 | const char *name, |
123 | uint64_t value, | 122 | uint64_t value, |
124 | int is_persistent) | 123 | int is_persistent) |
125 | { | 124 | { |
126 | struct PeerStats *stat = cls; | 125 | struct PeerStats *stat = cls; |
127 | 126 | ||
@@ -129,17 +128,17 @@ stat_fail_attempt_cb (void *cls, | |||
129 | return GNUNET_OK; | 128 | return GNUNET_OK; |
130 | 129 | ||
131 | stat->switch_fail++; | 130 | stat->switch_fail++; |
132 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat); | 131 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat); |
133 | return GNUNET_OK; | 132 | return GNUNET_OK; |
134 | } | 133 | } |
135 | 134 | ||
136 | 135 | ||
137 | static int | 136 | static int |
138 | stat_addresses_available (void *cls, | 137 | stat_addresses_available(void *cls, |
139 | const char *subsystem, | 138 | const char *subsystem, |
140 | const char *name, | 139 | const char *name, |
141 | uint64_t value, | 140 | uint64_t value, |
142 | int is_persistent) | 141 | int is_persistent) |
143 | { | 142 | { |
144 | struct PeerStats *stat = cls; | 143 | struct PeerStats *stat = cls; |
145 | 144 | ||
@@ -151,9 +150,7 @@ stat_addresses_available (void *cls, | |||
151 | /** | 150 | /** |
152 | * List of statistics entries we care about. | 151 | * List of statistics entries we care about. |
153 | */ | 152 | */ |
154 | static struct WatchEntry | 153 | static struct WatchEntry { |
155 | { | ||
156 | |||
157 | /** | 154 | /** |
158 | * Name of the statistic we watch. | 155 | * Name of the statistic we watch. |
159 | */ | 156 | */ |
@@ -164,115 +161,115 @@ static struct WatchEntry | |||
164 | */ | 161 | */ |
165 | GNUNET_STATISTICS_Iterator stat_handler; | 162 | GNUNET_STATISTICS_Iterator stat_handler; |
166 | } watches[] = | 163 | } watches[] = |
167 | {{"# Attempts to switch addresses", &stat_start_attempt_cb}, | 164 | { { "# Attempts to switch addresses", &stat_start_attempt_cb }, |
168 | {"# Successful attempts to switch addresses", &stat_success_attempt_cb}, | 165 | { "# Successful attempts to switch addresses", &stat_success_attempt_cb }, |
169 | {"# Failed attempts to switch addresses (failed to send CONNECT CONT)", | 166 | { "# Failed attempts to switch addresses (failed to send CONNECT CONT)", |
170 | &stat_fail_attempt_cb}, | 167 | &stat_fail_attempt_cb }, |
171 | {"# Failed attempts to switch addresses (failed to send CONNECT)", | 168 | { "# Failed attempts to switch addresses (failed to send CONNECT)", |
172 | &stat_fail_attempt_cb}, | 169 | &stat_fail_attempt_cb }, |
173 | {"# Failed attempts to switch addresses (no response)", | 170 | { "# Failed attempts to switch addresses (no response)", |
174 | &stat_fail_attempt_cb}, | 171 | &stat_fail_attempt_cb }, |
175 | {"# transport addresses", &stat_addresses_available}, | 172 | { "# transport addresses", &stat_addresses_available }, |
176 | {NULL, NULL}}; | 173 | { NULL, NULL } }; |
177 | 174 | ||
178 | 175 | ||
179 | static void | 176 | static void |
180 | custom_shutdown (void *cls) | 177 | custom_shutdown(void *cls) |
181 | { | 178 | { |
182 | int result; | 179 | int result; |
183 | 180 | ||
184 | if (NULL != measure_task) | 181 | if (NULL != measure_task) |
185 | { | 182 | { |
186 | GNUNET_SCHEDULER_cancel (measure_task); | 183 | GNUNET_SCHEDULER_cancel(measure_task); |
187 | measure_task = NULL; | 184 | measure_task = NULL; |
188 | } | 185 | } |
189 | if (0 == stats[0].switch_attempts + stats[1].switch_attempts) | 186 | if (0 == stats[0].switch_attempts + stats[1].switch_attempts) |
190 | { | 187 | { |
191 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 188 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
192 | "Test did not work, as peers didn't switch (flawed testcase)!\n"); | 189 | "Test did not work, as peers didn't switch (flawed testcase)!\n"); |
193 | ccc->global_ret = 77; | 190 | ccc->global_ret = 77; |
194 | } | 191 | } |
195 | else | 192 | else |
196 | { | 193 | { |
197 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 194 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
198 | "Fail (timeout)! No transmission after switch! Stopping peers\n"); | 195 | "Fail (timeout)! No transmission after switch! Stopping peers\n"); |
199 | ccc->global_ret = 77; /* GNUNET_SYSERR; */ | 196 | ccc->global_ret = 77; /* GNUNET_SYSERR; */ |
200 | } | 197 | } |
201 | 198 | ||
202 | /* stop statistics */ | 199 | /* stop statistics */ |
203 | for (unsigned int i = 0; i < 2; i++) | 200 | for (unsigned int i = 0; i < 2; i++) |
204 | { | ||
205 | if (NULL != stats[i].stat) | ||
206 | { | 201 | { |
207 | for (unsigned int j = 0; NULL != watches[j].stat_name; j++) | 202 | if (NULL != stats[i].stat) |
208 | GNUNET_assert (GNUNET_OK == | 203 | { |
209 | GNUNET_STATISTICS_watch_cancel (stats[i].stat, | 204 | for (unsigned int j = 0; NULL != watches[j].stat_name; j++) |
210 | "transport", | 205 | GNUNET_assert(GNUNET_OK == |
211 | watches[j].stat_name, | 206 | GNUNET_STATISTICS_watch_cancel(stats[i].stat, |
212 | watches[j].stat_handler, | 207 | "transport", |
213 | &stats[i])); | 208 | watches[j].stat_name, |
214 | GNUNET_STATISTICS_destroy (stats[i].stat, GNUNET_NO); | 209 | watches[j].stat_handler, |
215 | stats[i].stat = NULL; | 210 | &stats[i])); |
211 | GNUNET_STATISTICS_destroy(stats[i].stat, GNUNET_NO); | ||
212 | stats[i].stat = NULL; | ||
213 | } | ||
216 | } | 214 | } |
217 | } | ||
218 | 215 | ||
219 | result = 0; | 216 | result = 0; |
220 | fprintf (stderr, "\n"); | 217 | fprintf(stderr, "\n"); |
221 | if (stats[0].switch_attempts > 0) | 218 | if (stats[0].switch_attempts > 0) |
222 | { | ||
223 | fprintf ( | ||
224 | stderr, | ||
225 | "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", | ||
226 | stats[0].switch_attempts, | ||
227 | stats[0].switch_success, | ||
228 | stats[0].switch_fail); | ||
229 | if (stats[0].switch_success != stats[0].switch_attempts) | ||
230 | { | 219 | { |
231 | GNUNET_break (0); | 220 | fprintf( |
232 | result++; | 221 | stderr, |
222 | "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", | ||
223 | stats[0].switch_attempts, | ||
224 | stats[0].switch_success, | ||
225 | stats[0].switch_fail); | ||
226 | if (stats[0].switch_success != stats[0].switch_attempts) | ||
227 | { | ||
228 | GNUNET_break(0); | ||
229 | result++; | ||
230 | } | ||
233 | } | 231 | } |
234 | } | ||
235 | else if (stats[0].addresses_avail > 1) | 232 | else if (stats[0].addresses_avail > 1) |
236 | { | 233 | { |
237 | fprintf (stderr, | 234 | fprintf(stderr, |
238 | "Peer 1 had %u addresses available, but did not try to switch\n", | 235 | "Peer 1 had %u addresses available, but did not try to switch\n", |
239 | stats[0].addresses_avail); | 236 | stats[0].addresses_avail); |
240 | } | 237 | } |
241 | if (stats[1].switch_attempts > 0) | 238 | if (stats[1].switch_attempts > 0) |
242 | { | ||
243 | fprintf ( | ||
244 | stderr, | ||
245 | "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", | ||
246 | stats[1].switch_attempts, | ||
247 | stats[1].switch_success, | ||
248 | stats[1].switch_fail); | ||
249 | if (stats[1].switch_success != stats[1].switch_attempts) | ||
250 | { | 239 | { |
251 | GNUNET_break (0); | 240 | fprintf( |
252 | result++; | 241 | stderr, |
242 | "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", | ||
243 | stats[1].switch_attempts, | ||
244 | stats[1].switch_success, | ||
245 | stats[1].switch_fail); | ||
246 | if (stats[1].switch_success != stats[1].switch_attempts) | ||
247 | { | ||
248 | GNUNET_break(0); | ||
249 | result++; | ||
250 | } | ||
253 | } | 251 | } |
254 | } | ||
255 | else if (stats[1].addresses_avail > 1) | 252 | else if (stats[1].addresses_avail > 1) |
256 | { | 253 | { |
257 | fprintf (stderr, | 254 | fprintf(stderr, |
258 | "Peer 2 had %u addresses available, but did not try to switch\n", | 255 | "Peer 2 had %u addresses available, but did not try to switch\n", |
259 | stats[1].addresses_avail); | 256 | stats[1].addresses_avail); |
260 | } | 257 | } |
261 | 258 | ||
262 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && | 259 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && |
263 | (bytes_sent_after_switch == 0)) | 260 | (bytes_sent_after_switch == 0)) |
264 | { | 261 | { |
265 | fprintf (stderr, "No data sent after switching!\n"); | 262 | fprintf(stderr, "No data sent after switching!\n"); |
266 | GNUNET_break (0); | 263 | GNUNET_break(0); |
267 | result++; | 264 | result++; |
268 | } | 265 | } |
269 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && | 266 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && |
270 | (bytes_recv_after_switch == 0)) | 267 | (bytes_recv_after_switch == 0)) |
271 | { | 268 | { |
272 | fprintf (stderr, "No data received after switching!\n"); | 269 | fprintf(stderr, "No data received after switching!\n"); |
273 | GNUNET_break (0); | 270 | GNUNET_break(0); |
274 | result++; | 271 | result++; |
275 | } | 272 | } |
276 | #if 0 | 273 | #if 0 |
277 | /* This test is not really expected to pass right now... */ | 274 | /* This test is not really expected to pass right now... */ |
278 | if (0 != result) | 275 | if (0 != result) |
@@ -282,146 +279,147 @@ custom_shutdown (void *cls) | |||
282 | 279 | ||
283 | 280 | ||
284 | static void | 281 | static void |
285 | notify_receive (void *cls, | 282 | notify_receive(void *cls, |
286 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 283 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
287 | const struct GNUNET_PeerIdentity *sender, | 284 | const struct GNUNET_PeerIdentity *sender, |
288 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) | 285 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) |
289 | { | 286 | { |
290 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) | 287 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type)) |
291 | return; | 288 | return; |
292 | 289 | ||
293 | { | 290 | { |
294 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 291 | char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); |
295 | 292 | ||
296 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 293 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
297 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", | 294 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", |
298 | receiver->no, | 295 | receiver->no, |
299 | ps, | 296 | ps, |
300 | (uint32_t) ntohl (hdr->num), | 297 | (uint32_t)ntohl(hdr->num), |
301 | ntohs (hdr->header.size), | 298 | ntohs(hdr->header.size), |
302 | GNUNET_i2s (sender)); | 299 | GNUNET_i2s(sender)); |
303 | GNUNET_free (ps); | 300 | GNUNET_free(ps); |
304 | } | 301 | } |
305 | if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && | 302 | if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && |
306 | (stats[0].switch_attempts == | 303 | (stats[0].switch_attempts == |
307 | stats[0].switch_fail + stats[0].switch_success) && | 304 | stats[0].switch_fail + stats[0].switch_success) && |
308 | (stats[1].switch_attempts == | 305 | (stats[1].switch_attempts == |
309 | stats[1].switch_fail + stats[1].switch_success)) | 306 | stats[1].switch_fail + stats[1].switch_success)) |
310 | { | ||
311 | bytes_recv_after_switch += ntohs (hdr->header.size); | ||
312 | if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0)) | ||
313 | { | 307 | { |
314 | /* A peer switched addresses and sent and received data after the | 308 | bytes_recv_after_switch += ntohs(hdr->header.size); |
315 | * switch operations */ | 309 | if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0)) |
316 | GNUNET_SCHEDULER_shutdown (); | 310 | { |
311 | /* A peer switched addresses and sent and received data after the | ||
312 | * switch operations */ | ||
313 | GNUNET_SCHEDULER_shutdown(); | ||
314 | } | ||
317 | } | 315 | } |
318 | } | ||
319 | } | 316 | } |
320 | 317 | ||
321 | 318 | ||
322 | static void | 319 | static void |
323 | notify_send (void *cls) | 320 | notify_send(void *cls) |
324 | { | 321 | { |
325 | static uint32_t cnt; | 322 | static uint32_t cnt; |
326 | 323 | ||
327 | GNUNET_assert ( | 324 | GNUNET_assert( |
328 | GNUNET_OK == | 325 | GNUNET_OK == |
329 | GNUNET_TRANSPORT_TESTING_send (ccc->p[1], | 326 | GNUNET_TRANSPORT_TESTING_send(ccc->p[1], |
330 | ccc->p[0], | 327 | ccc->p[0], |
331 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | 328 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, |
332 | GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, | 329 | GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, |
333 | ++cnt, | 330 | ++cnt, |
334 | ¬ify_send, | 331 | ¬ify_send, |
335 | NULL)); | 332 | NULL)); |
336 | if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && | 333 | if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && |
337 | (stats[0].switch_attempts == | 334 | (stats[0].switch_attempts == |
338 | stats[0].switch_fail + stats[0].switch_success) && | 335 | stats[0].switch_fail + stats[0].switch_success) && |
339 | (stats[1].switch_attempts == | 336 | (stats[1].switch_attempts == |
340 | stats[1].switch_fail + stats[1].switch_success)) | 337 | stats[1].switch_fail + stats[1].switch_success)) |
341 | { | 338 | { |
342 | bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE; | 339 | bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE; |
343 | } | 340 | } |
344 | } | 341 | } |
345 | 342 | ||
346 | 343 | ||
347 | static void | 344 | static void |
348 | progress_indicator (void *cls) | 345 | progress_indicator(void *cls) |
349 | { | 346 | { |
350 | static int counter; | 347 | static int counter; |
351 | 348 | ||
352 | measure_task = NULL; | 349 | measure_task = NULL; |
353 | counter++; | 350 | counter++; |
354 | if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter) | 351 | if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter) |
355 | { | 352 | { |
356 | fprintf (stderr, "%s", ".\n"); | 353 | fprintf(stderr, "%s", ".\n"); |
357 | } | 354 | } |
358 | else | 355 | else |
359 | { | 356 | { |
360 | fprintf (stderr, "%s", "."); | 357 | fprintf(stderr, "%s", "."); |
361 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 358 | measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
362 | &progress_indicator, | 359 | &progress_indicator, |
363 | NULL); | 360 | NULL); |
364 | } | 361 | } |
365 | } | 362 | } |
366 | 363 | ||
367 | 364 | ||
368 | static void | 365 | static void |
369 | connected_cb (void *cls) | 366 | connected_cb(void *cls) |
370 | { | 367 | { |
371 | for (unsigned int i = 0; i < 2; i++) | 368 | for (unsigned int i = 0; i < 2; i++) |
372 | { | ||
373 | stats[i].stat = GNUNET_STATISTICS_create ("transport", ccc->p[i]->cfg); | ||
374 | if (NULL == stats[i].stat) | ||
375 | { | 369 | { |
376 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 370 | stats[i].stat = GNUNET_STATISTICS_create("transport", ccc->p[i]->cfg); |
377 | "Fail! Could not create statistics for peers!\n"); | 371 | if (NULL == stats[i].stat) |
378 | ccc->global_ret = GNUNET_SYSERR; | 372 | { |
379 | GNUNET_SCHEDULER_shutdown (); | 373 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
380 | return; | 374 | "Fail! Could not create statistics for peers!\n"); |
381 | } | 375 | ccc->global_ret = GNUNET_SYSERR; |
382 | for (unsigned int j = 0; NULL != watches[j].stat_name; j++) | 376 | GNUNET_SCHEDULER_shutdown(); |
383 | { | 377 | return; |
384 | GNUNET_STATISTICS_watch (stats[i].stat, | 378 | } |
385 | "transport", | 379 | for (unsigned int j = 0; NULL != watches[j].stat_name; j++) |
386 | watches[j].stat_name, | 380 | { |
387 | watches[j].stat_handler, | 381 | GNUNET_STATISTICS_watch(stats[i].stat, |
388 | &stats[i]); | 382 | "transport", |
383 | watches[j].stat_name, | ||
384 | watches[j].stat_handler, | ||
385 | &stats[i]); | ||
386 | } | ||
389 | } | 387 | } |
390 | } | ||
391 | /* Show progress */ | 388 | /* Show progress */ |
392 | ccc->global_ret = GNUNET_OK; | 389 | ccc->global_ret = GNUNET_OK; |
393 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 390 | measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
394 | &progress_indicator, | 391 | &progress_indicator, |
395 | NULL); | 392 | NULL); |
396 | /* Peers are connected, start transmit test messages */ | 393 | /* Peers are connected, start transmit test messages */ |
397 | GNUNET_assert ( | 394 | GNUNET_assert( |
398 | GNUNET_OK == | 395 | GNUNET_OK == |
399 | GNUNET_TRANSPORT_TESTING_send (ccc->p[1], | 396 | GNUNET_TRANSPORT_TESTING_send(ccc->p[1], |
400 | ccc->p[0], | 397 | ccc->p[0], |
401 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | 398 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, |
402 | GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, | 399 | GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, |
403 | 0, | 400 | 0, |
404 | ¬ify_send, | 401 | ¬ify_send, |
405 | NULL)); | 402 | NULL)); |
406 | } | 403 | } |
407 | 404 | ||
408 | 405 | ||
409 | int | 406 | int |
410 | main (int argc, char *argv[]) | 407 | main(int argc, char *argv[]) |
411 | { | 408 | { |
412 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = | 409 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = |
413 | {.connect_continuation = &connected_cb, | 410 | { .connect_continuation = &connected_cb, |
414 | .config_file = "test_transport_api_data.conf", | 411 | .config_file = "test_transport_api_data.conf", |
415 | .rec = ¬ify_receive, | 412 | .rec = ¬ify_receive, |
416 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 413 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
417 | .shutdown_task = &custom_shutdown, | 414 | .shutdown_task = &custom_shutdown, |
418 | .timeout = TIMEOUT}; | 415 | .timeout = TIMEOUT }; |
416 | |||
419 | ccc = &my_ccc; | 417 | ccc = &my_ccc; |
420 | int ret; | 418 | int ret; |
421 | 419 | ||
422 | ret = GNUNET_TRANSPORT_TESTING_main (2, | 420 | ret = GNUNET_TRANSPORT_TESTING_main(2, |
423 | &GNUNET_TRANSPORT_TESTING_connect_check, | 421 | &GNUNET_TRANSPORT_TESTING_connect_check, |
424 | ccc); | 422 | ccc); |
425 | if (77 == ret) | 423 | if (77 == ret) |
426 | return 77; | 424 | return 77; |
427 | if (GNUNET_OK != ret) | 425 | if (GNUNET_OK != ret) |