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/transport-testing-main.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/transport/transport-testing-main.c')
-rw-r--r-- | src/transport/transport-testing-main.c | 460 |
1 files changed, 228 insertions, 232 deletions
diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c index 6cef20ba1..7e7b0df4b 100644 --- a/src/transport/transport-testing-main.c +++ b/src/transport/transport-testing-main.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-testing-main.c | 21 | * @file transport-testing-main.c |
22 | * @brief convenience main function for tests | 22 | * @brief convenience main function for tests |
@@ -28,8 +28,7 @@ | |||
28 | /** | 28 | /** |
29 | * Closure for #connect_cb. | 29 | * Closure for #connect_cb. |
30 | */ | 30 | */ |
31 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList | 31 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList { |
32 | { | ||
33 | /** | 32 | /** |
34 | * Stored in a DLL. | 33 | * Stored in a DLL. |
35 | */ | 34 | */ |
@@ -59,7 +58,6 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequestList | |||
59 | * Peer being connected. | 58 | * Peer being connected. |
60 | */ | 59 | */ |
61 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | 60 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; |
62 | |||
63 | }; | 61 | }; |
64 | 62 | ||
65 | 63 | ||
@@ -69,41 +67,41 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequestList | |||
69 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` | 67 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` |
70 | */ | 68 | */ |
71 | static void | 69 | static void |
72 | do_shutdown (void *cls) | 70 | do_shutdown(void *cls) |
73 | { | 71 | { |
74 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | 72 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; |
75 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; | 73 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; |
76 | 74 | ||
77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 75 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
78 | "Testcase shutting down\n"); | 76 | "Testcase shutting down\n"); |
79 | if (NULL != ccc->shutdown_task) | 77 | if (NULL != ccc->shutdown_task) |
80 | ccc->shutdown_task (ccc->shutdown_task_cls); | 78 | ccc->shutdown_task(ccc->shutdown_task_cls); |
81 | if (NULL != ccc->timeout_task) | 79 | if (NULL != ccc->timeout_task) |
82 | { | 80 | { |
83 | GNUNET_SCHEDULER_cancel (ccc->timeout_task); | 81 | GNUNET_SCHEDULER_cancel(ccc->timeout_task); |
84 | ccc->timeout_task = NULL; | 82 | ccc->timeout_task = NULL; |
85 | } | 83 | } |
86 | if (NULL != ccc->connect_task) | 84 | if (NULL != ccc->connect_task) |
87 | { | 85 | { |
88 | GNUNET_SCHEDULER_cancel (ccc->connect_task); | 86 | GNUNET_SCHEDULER_cancel(ccc->connect_task); |
89 | ccc->connect_task = NULL; | 87 | ccc->connect_task = NULL; |
90 | } | 88 | } |
91 | while (NULL != (crl = ccc->crl_head)) | 89 | while (NULL != (crl = ccc->crl_head)) |
92 | { | ||
93 | GNUNET_CONTAINER_DLL_remove (ccc->crl_head, | ||
94 | ccc->crl_tail, | ||
95 | crl); | ||
96 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (crl->cr); | ||
97 | GNUNET_free (crl); | ||
98 | } | ||
99 | for (unsigned int i=0;i<ccc->num_peers;i++) | ||
100 | { | ||
101 | if (NULL != ccc->p[i]) | ||
102 | { | 90 | { |
103 | GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[i]); | 91 | GNUNET_CONTAINER_DLL_remove(ccc->crl_head, |
104 | ccc->p[i] = NULL; | 92 | ccc->crl_tail, |
93 | crl); | ||
94 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel(crl->cr); | ||
95 | GNUNET_free(crl); | ||
96 | } | ||
97 | for (unsigned int i = 0; i < ccc->num_peers; i++) | ||
98 | { | ||
99 | if (NULL != ccc->p[i]) | ||
100 | { | ||
101 | GNUNET_TRANSPORT_TESTING_stop_peer(ccc->p[i]); | ||
102 | ccc->p[i] = NULL; | ||
103 | } | ||
105 | } | 104 | } |
106 | } | ||
107 | } | 105 | } |
108 | 106 | ||
109 | 107 | ||
@@ -113,15 +111,15 @@ do_shutdown (void *cls) | |||
113 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` | 111 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` |
114 | */ | 112 | */ |
115 | static void | 113 | static void |
116 | do_timeout (void *cls) | 114 | do_timeout(void *cls) |
117 | { | 115 | { |
118 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | 116 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; |
119 | 117 | ||
120 | ccc->timeout_task = NULL; | 118 | ccc->timeout_task = NULL; |
121 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 119 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
122 | "Testcase timed out\n"); | 120 | "Testcase timed out\n"); |
123 | ccc->global_ret = GNUNET_SYSERR; | 121 | ccc->global_ret = GNUNET_SYSERR; |
124 | GNUNET_SCHEDULER_shutdown (); | 122 | GNUNET_SCHEDULER_shutdown(); |
125 | } | 123 | } |
126 | 124 | ||
127 | 125 | ||
@@ -130,8 +128,7 @@ do_timeout (void *cls) | |||
130 | * #connect_cb, #disconnect_cb, #my_nc and #start_cb. | 128 | * #connect_cb, #disconnect_cb, #my_nc and #start_cb. |
131 | * Allows us to identify which peer this is about. | 129 | * Allows us to identify which peer this is about. |
132 | */ | 130 | */ |
133 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext | 131 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext { |
134 | { | ||
135 | /** | 132 | /** |
136 | * Overall context of the callback. | 133 | * Overall context of the callback. |
137 | */ | 134 | */ |
@@ -147,8 +144,7 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext | |||
147 | /** | 144 | /** |
148 | * Information tracked per connected peer. | 145 | * Information tracked per connected peer. |
149 | */ | 146 | */ |
150 | struct ConnectPairInfo | 147 | struct ConnectPairInfo { |
151 | { | ||
152 | /** | 148 | /** |
153 | * Peer this is about. | 149 | * Peer this is about. |
154 | */ | 150 | */ |
@@ -168,33 +164,33 @@ struct ConnectPairInfo | |||
168 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *` | 164 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *` |
169 | */ | 165 | */ |
170 | static void | 166 | static void |
171 | connect_cb (void *cls) | 167 | connect_cb(void *cls) |
172 | { | 168 | { |
173 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl = cls; | 169 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl = cls; |
174 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = crl->ccc; | 170 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = crl->ccc; |
175 | 171 | ||
176 | GNUNET_CONTAINER_DLL_remove (ccc->crl_head, | 172 | GNUNET_CONTAINER_DLL_remove(ccc->crl_head, |
177 | ccc->crl_tail, | 173 | ccc->crl_tail, |
178 | crl); | 174 | crl); |
179 | { | 175 | { |
180 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&crl->p1->id)); | 176 | char *p1_c = GNUNET_strdup(GNUNET_i2s(&crl->p1->id)); |
181 | 177 | ||
182 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 178 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
183 | "Peers connected: %u (%s) <-> %u (%s)\n", | 179 | "Peers connected: %u (%s) <-> %u (%s)\n", |
184 | crl->p1->no, | 180 | crl->p1->no, |
185 | p1_c, | 181 | p1_c, |
186 | crl->p2->no, | 182 | crl->p2->no, |
187 | GNUNET_i2s (&crl->p2->id)); | 183 | GNUNET_i2s(&crl->p2->id)); |
188 | GNUNET_free (p1_c); | 184 | GNUNET_free(p1_c); |
189 | GNUNET_free (crl); | 185 | GNUNET_free(crl); |
190 | } | 186 | } |
191 | if (NULL == ccc->crl_head) | 187 | if (NULL == ccc->crl_head) |
192 | { | 188 | { |
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 189 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
194 | "All connections UP, launching custom test logic.\n"); | 190 | "All connections UP, launching custom test logic.\n"); |
195 | GNUNET_SCHEDULER_add_now (ccc->connect_continuation, | 191 | GNUNET_SCHEDULER_add_now(ccc->connect_continuation, |
196 | ccc->connect_continuation_cls); | 192 | ccc->connect_continuation_cls); |
197 | } | 193 | } |
198 | } | 194 | } |
199 | 195 | ||
200 | 196 | ||
@@ -206,14 +202,14 @@ connect_cb (void *cls) | |||
206 | * @return NULL if @a peer was not found | 202 | * @return NULL if @a peer was not found |
207 | */ | 203 | */ |
208 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | 204 | struct GNUNET_TRANSPORT_TESTING_PeerContext * |
209 | GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, | 205 | GNUNET_TRANSPORT_TESTING_find_peer(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, |
210 | const struct GNUNET_PeerIdentity *peer) | 206 | const struct GNUNET_PeerIdentity *peer) |
211 | { | 207 | { |
212 | for (unsigned int i=0;i<ccc->num_peers;i++) | 208 | for (unsigned int i = 0; i < ccc->num_peers; i++) |
213 | if ( (NULL != ccc->p[i]) && | 209 | if ((NULL != ccc->p[i]) && |
214 | (0 == memcmp (peer, | 210 | (0 == memcmp(peer, |
215 | &ccc->p[i]->id, | 211 | &ccc->p[i]->id, |
216 | sizeof (*peer))) ) | 212 | sizeof(*peer)))) |
217 | return ccc->p[i]; | 213 | return ccc->p[i]; |
218 | return NULL; | 214 | return NULL; |
219 | } | 215 | } |
@@ -228,19 +224,19 @@ GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheck | |||
228 | * @return closure for message handlers | 224 | * @return closure for message handlers |
229 | */ | 225 | */ |
230 | static void * | 226 | static void * |
231 | my_nc (void *cls, | 227 | my_nc(void *cls, |
232 | const struct GNUNET_PeerIdentity *peer, | 228 | const struct GNUNET_PeerIdentity *peer, |
233 | struct GNUNET_MQ_Handle *mq) | 229 | struct GNUNET_MQ_Handle *mq) |
234 | { | 230 | { |
235 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | 231 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; |
236 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | 232 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; |
237 | struct ConnectPairInfo *cpi; | 233 | struct ConnectPairInfo *cpi; |
238 | 234 | ||
239 | if (NULL != ccc->nc) | 235 | if (NULL != ccc->nc) |
240 | ccc->nc (ccc->cls, | 236 | ccc->nc(ccc->cls, |
241 | ccc->p[ipi->off], | 237 | ccc->p[ipi->off], |
242 | peer); | 238 | peer); |
243 | cpi = GNUNET_new (struct ConnectPairInfo); | 239 | cpi = GNUNET_new(struct ConnectPairInfo); |
244 | cpi->ipi = ipi; | 240 | cpi->ipi = ipi; |
245 | cpi->sender = peer; /* valid until disconnect */ | 241 | cpi->sender = peer; /* valid until disconnect */ |
246 | return cpi; | 242 | return cpi; |
@@ -255,19 +251,19 @@ my_nc (void *cls, | |||
255 | * @param custom_cls return value from @my_nc | 251 | * @param custom_cls return value from @my_nc |
256 | */ | 252 | */ |
257 | static void | 253 | static void |
258 | my_nd (void *cls, | 254 | my_nd(void *cls, |
259 | const struct GNUNET_PeerIdentity *peer, | 255 | const struct GNUNET_PeerIdentity *peer, |
260 | void *custom_cls) | 256 | void *custom_cls) |
261 | { | 257 | { |
262 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | 258 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; |
263 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | 259 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; |
264 | struct ConnectPairInfo *cpi = custom_cls; | 260 | struct ConnectPairInfo *cpi = custom_cls; |
265 | 261 | ||
266 | if (NULL != ccc->nd) | 262 | if (NULL != ccc->nd) |
267 | ccc->nd (ccc->cls, | 263 | ccc->nd(ccc->cls, |
268 | ccc->p[ipi->off], | 264 | ccc->p[ipi->off], |
269 | peer); | 265 | peer); |
270 | GNUNET_free (cpi); | 266 | GNUNET_free(cpi); |
271 | } | 267 | } |
272 | 268 | ||
273 | 269 | ||
@@ -279,8 +275,8 @@ my_nd (void *cls, | |||
279 | * @return #GNUNET_OK (all messages are fine) | 275 | * @return #GNUNET_OK (all messages are fine) |
280 | */ | 276 | */ |
281 | static int | 277 | static int |
282 | check_test (void *cls, | 278 | check_test(void *cls, |
283 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 279 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
284 | { | 280 | { |
285 | return GNUNET_OK; | 281 | return GNUNET_OK; |
286 | } | 282 | } |
@@ -293,18 +289,18 @@ check_test (void *cls, | |||
293 | * @param message message we received | 289 | * @param message message we received |
294 | */ | 290 | */ |
295 | static void | 291 | static void |
296 | handle_test (void *cls, | 292 | handle_test(void *cls, |
297 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 293 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
298 | { | 294 | { |
299 | struct ConnectPairInfo *cpi = cls; | 295 | struct ConnectPairInfo *cpi = cls; |
300 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; | 296 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; |
301 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | 297 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; |
302 | 298 | ||
303 | if (NULL != ccc->rec) | 299 | if (NULL != ccc->rec) |
304 | ccc->rec (ccc->cls, | 300 | ccc->rec(ccc->cls, |
305 | ccc->p[ipi->off], | 301 | ccc->p[ipi->off], |
306 | cpi->sender, | 302 | cpi->sender, |
307 | message); | 303 | message); |
308 | } | 304 | } |
309 | 305 | ||
310 | 306 | ||
@@ -316,8 +312,8 @@ handle_test (void *cls, | |||
316 | * @return #GNUNET_OK (all messages are fine) | 312 | * @return #GNUNET_OK (all messages are fine) |
317 | */ | 313 | */ |
318 | static int | 314 | static int |
319 | check_test2 (void *cls, | 315 | check_test2(void *cls, |
320 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 316 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
321 | { | 317 | { |
322 | return GNUNET_OK; | 318 | return GNUNET_OK; |
323 | } | 319 | } |
@@ -330,18 +326,18 @@ check_test2 (void *cls, | |||
330 | * @param message message we received | 326 | * @param message message we received |
331 | */ | 327 | */ |
332 | static void | 328 | static void |
333 | handle_test2 (void *cls, | 329 | handle_test2(void *cls, |
334 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 330 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
335 | { | 331 | { |
336 | struct ConnectPairInfo *cpi = cls; | 332 | struct ConnectPairInfo *cpi = cls; |
337 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; | 333 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; |
338 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | 334 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; |
339 | 335 | ||
340 | if (NULL != ccc->rec) | 336 | if (NULL != ccc->rec) |
341 | ccc->rec (ccc->cls, | 337 | ccc->rec(ccc->cls, |
342 | ccc->p[ipi->off], | 338 | ccc->p[ipi->off], |
343 | cpi->sender, | 339 | cpi->sender, |
344 | message); | 340 | message); |
345 | } | 341 | } |
346 | 342 | ||
347 | 343 | ||
@@ -351,41 +347,41 @@ handle_test2 (void *cls, | |||
351 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` | 347 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` |
352 | */ | 348 | */ |
353 | static void | 349 | static void |
354 | do_connect (void *cls) | 350 | do_connect(void *cls) |
355 | { | 351 | { |
356 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | 352 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; |
357 | 353 | ||
358 | ccc->connect_task = NULL; | 354 | ccc->connect_task = NULL; |
359 | for (unsigned int i=0;i<ccc->num_peers;i++) | 355 | for (unsigned int i = 0; i < ccc->num_peers; i++) |
360 | for (unsigned int j=(ccc->bi_directional ? 0 : i+1);j<ccc->num_peers;j++) | 356 | for (unsigned int j = (ccc->bi_directional ? 0 : i + 1); j < ccc->num_peers; j++) |
361 | { | ||
362 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; | ||
363 | |||
364 | if (i == j) | ||
365 | continue; | ||
366 | crl = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequestList); | ||
367 | GNUNET_CONTAINER_DLL_insert (ccc->crl_head, | ||
368 | ccc->crl_tail, | ||
369 | crl); | ||
370 | crl->ccc = ccc; | ||
371 | crl->p1 = ccc->p[i]; | ||
372 | crl->p2 = ccc->p[j]; | ||
373 | { | 357 | { |
374 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | 358 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; |
375 | 359 | ||
376 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 360 | if (i == j) |
377 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | 361 | continue; |
378 | ccc->p[0]->no, | 362 | crl = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequestList); |
379 | sender_c, | 363 | GNUNET_CONTAINER_DLL_insert(ccc->crl_head, |
380 | ccc->p[1]->no, | 364 | ccc->crl_tail, |
381 | GNUNET_i2s (&ccc->p[1]->id)); | 365 | crl); |
382 | GNUNET_free (sender_c); | 366 | crl->ccc = ccc; |
367 | crl->p1 = ccc->p[i]; | ||
368 | crl->p2 = ccc->p[j]; | ||
369 | { | ||
370 | char *sender_c = GNUNET_strdup(GNUNET_i2s(&ccc->p[0]->id)); | ||
371 | |||
372 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
373 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
374 | ccc->p[0]->no, | ||
375 | sender_c, | ||
376 | ccc->p[1]->no, | ||
377 | GNUNET_i2s(&ccc->p[1]->id)); | ||
378 | GNUNET_free(sender_c); | ||
379 | } | ||
380 | crl->cr = GNUNET_TRANSPORT_TESTING_connect_peers(ccc->p[i], | ||
381 | ccc->p[j], | ||
382 | &connect_cb, | ||
383 | crl); | ||
383 | } | 384 | } |
384 | crl->cr = GNUNET_TRANSPORT_TESTING_connect_peers (ccc->p[i], | ||
385 | ccc->p[j], | ||
386 | &connect_cb, | ||
387 | crl); | ||
388 | } | ||
389 | } | 385 | } |
390 | 386 | ||
391 | 387 | ||
@@ -397,32 +393,32 @@ do_connect (void *cls) | |||
397 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` | 393 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` |
398 | */ | 394 | */ |
399 | static void | 395 | static void |
400 | start_cb (void *cls) | 396 | start_cb(void *cls) |
401 | { | 397 | { |
402 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | 398 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; |
403 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | 399 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; |
404 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off]; | 400 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off]; |
405 | 401 | ||
406 | ccc->started++; | 402 | ccc->started++; |
407 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 403 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
408 | "Peer %u (`%s') started\n", | 404 | "Peer %u (`%s') started\n", |
409 | p->no, | 405 | p->no, |
410 | GNUNET_i2s (&p->id)); | 406 | GNUNET_i2s(&p->id)); |
411 | if (ccc->started != ccc->num_peers) | 407 | if (ccc->started != ccc->num_peers) |
412 | return; | 408 | return; |
413 | if (NULL != ccc->pre_connect_task) | 409 | if (NULL != ccc->pre_connect_task) |
414 | { | 410 | { |
415 | /* Run the custom per-connect job, then give it a second to | 411 | /* Run the custom per-connect job, then give it a second to |
416 | go into effect before we continue connecting peers. */ | 412 | go into effect before we continue connecting peers. */ |
417 | ccc->pre_connect_task (ccc->pre_connect_task_cls); | 413 | ccc->pre_connect_task(ccc->pre_connect_task_cls); |
418 | ccc->connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 414 | ccc->connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
419 | &do_connect, | 415 | &do_connect, |
420 | ccc); | 416 | ccc); |
421 | } | 417 | } |
422 | else | 418 | else |
423 | { | 419 | { |
424 | do_connect (ccc); | 420 | do_connect(ccc); |
425 | } | 421 | } |
426 | } | 422 | } |
427 | 423 | ||
428 | 424 | ||
@@ -437,52 +433,52 @@ start_cb (void *cls) | |||
437 | * @param cfg configuration | 433 | * @param cfg configuration |
438 | */ | 434 | */ |
439 | static void | 435 | static void |
440 | connect_check_run (void *cls, | 436 | connect_check_run(void *cls, |
441 | char *const *args, | 437 | char *const *args, |
442 | const char *cfgfile, | 438 | const char *cfgfile, |
443 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 439 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
444 | { | 440 | { |
445 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | 441 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; |
446 | int ok; | 442 | int ok; |
447 | 443 | ||
448 | ccc->cfg = cfg; | 444 | ccc->cfg = cfg; |
449 | ccc->timeout_task = GNUNET_SCHEDULER_add_delayed (ccc->timeout, | 445 | ccc->timeout_task = GNUNET_SCHEDULER_add_delayed(ccc->timeout, |
450 | &do_timeout, | 446 | &do_timeout, |
451 | ccc); | 447 | ccc); |
452 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 448 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
453 | ccc); | 449 | ccc); |
454 | ok = GNUNET_OK; | 450 | ok = GNUNET_OK; |
455 | for (unsigned int i=0;i<ccc->num_peers;i++) | 451 | for (unsigned int i = 0; i < ccc->num_peers; i++) |
456 | { | 452 | { |
457 | struct GNUNET_MQ_MessageHandler handlers[] = { | 453 | struct GNUNET_MQ_MessageHandler handlers[] = { |
458 | GNUNET_MQ_hd_var_size (test, | 454 | GNUNET_MQ_hd_var_size(test, |
459 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | 455 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, |
460 | struct GNUNET_TRANSPORT_TESTING_TestMessage, | 456 | struct GNUNET_TRANSPORT_TESTING_TestMessage, |
461 | NULL), | 457 | NULL), |
462 | GNUNET_MQ_hd_var_size (test2, | 458 | GNUNET_MQ_hd_var_size(test2, |
463 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, | 459 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, |
464 | struct GNUNET_TRANSPORT_TESTING_TestMessage, | 460 | struct GNUNET_TRANSPORT_TESTING_TestMessage, |
465 | NULL), | 461 | NULL), |
466 | GNUNET_MQ_handler_end() | 462 | GNUNET_MQ_handler_end() |
467 | }; | 463 | }; |
468 | ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth, | 464 | ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer(ccc->tth, |
469 | ccc->cfg_files[i], | 465 | ccc->cfg_files[i], |
470 | i + 1, | 466 | i + 1, |
471 | handlers, | 467 | handlers, |
472 | &my_nc, | 468 | &my_nc, |
473 | &my_nd, | 469 | &my_nd, |
474 | &ccc->ip[i], | 470 | &ccc->ip[i], |
475 | &start_cb, | 471 | &start_cb, |
476 | &ccc->ip[i]); | 472 | &ccc->ip[i]); |
477 | if (NULL == ccc->p[i]) | 473 | if (NULL == ccc->p[i]) |
478 | ok = GNUNET_SYSERR; | 474 | ok = GNUNET_SYSERR; |
479 | } | 475 | } |
480 | if (GNUNET_OK != ok) | 476 | if (GNUNET_OK != ok) |
481 | { | 477 | { |
482 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 478 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
483 | "Fail! Could not start peers!\n"); | 479 | "Fail! Could not start peers!\n"); |
484 | GNUNET_SCHEDULER_shutdown (); | 480 | GNUNET_SCHEDULER_shutdown(); |
485 | } | 481 | } |
486 | } | 482 | } |
487 | 483 | ||
488 | 484 | ||
@@ -502,12 +498,12 @@ connect_check_run (void *cls, | |||
502 | * @return #GNUNET_SYSERR on error | 498 | * @return #GNUNET_SYSERR on error |
503 | */ | 499 | */ |
504 | int | 500 | int |
505 | GNUNET_TRANSPORT_TESTING_connect_check (void *cls, | 501 | GNUNET_TRANSPORT_TESTING_connect_check(void *cls, |
506 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, | 502 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, |
507 | const char *test_plugin_, | 503 | const char *test_plugin_, |
508 | const char *test_name_, | 504 | const char *test_name_, |
509 | unsigned int num_peers, | 505 | unsigned int num_peers, |
510 | char *cfg_files[]) | 506 | char *cfg_files[]) |
511 | { | 507 | { |
512 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 508 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
513 | GNUNET_GETOPT_OPTION_END | 509 | GNUNET_GETOPT_OPTION_END |
@@ -516,9 +512,9 @@ GNUNET_TRANSPORT_TESTING_connect_check (void *cls, | |||
516 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p[num_peers]; | 512 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p[num_peers]; |
517 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext ip[num_peers]; | 513 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext ip[num_peers]; |
518 | char * argv[] = { | 514 | char * argv[] = { |
519 | (char *) test_name_, | 515 | (char *)test_name_, |
520 | "-c", | 516 | "-c", |
521 | (char *) ccc->config_file, | 517 | (char *)ccc->config_file, |
522 | NULL | 518 | NULL |
523 | }; | 519 | }; |
524 | 520 | ||
@@ -530,19 +526,19 @@ GNUNET_TRANSPORT_TESTING_connect_check (void *cls, | |||
530 | ccc->global_ret = GNUNET_OK; | 526 | ccc->global_ret = GNUNET_OK; |
531 | ccc->p = p; | 527 | ccc->p = p; |
532 | ccc->ip = ip; | 528 | ccc->ip = ip; |
533 | for (unsigned int i=0;i<num_peers;i++) | 529 | for (unsigned int i = 0; i < num_peers; i++) |
534 | { | 530 | { |
535 | ip[i].off = i; | 531 | ip[i].off = i; |
536 | ip[i].ccc = ccc; | 532 | ip[i].ccc = ccc; |
537 | } | 533 | } |
538 | if (GNUNET_OK != | 534 | if (GNUNET_OK != |
539 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 535 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
540 | argv, | 536 | argv, |
541 | test_name_, | 537 | test_name_, |
542 | "nohelp", | 538 | "nohelp", |
543 | options, | 539 | options, |
544 | &connect_check_run, | 540 | &connect_check_run, |
545 | ccc)) | 541 | ccc)) |
546 | return GNUNET_SYSERR; | 542 | return GNUNET_SYSERR; |
547 | return ccc->global_ret; | 543 | return ccc->global_ret; |
548 | } | 544 | } |
@@ -559,11 +555,11 @@ GNUNET_TRANSPORT_TESTING_connect_check (void *cls, | |||
559 | * @return #GNUNET_OK on success | 555 | * @return #GNUNET_OK on success |
560 | */ | 556 | */ |
561 | int | 557 | int |
562 | GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | 558 | GNUNET_TRANSPORT_TESTING_main_(const char *argv0, |
563 | const char *filename, | 559 | const char *filename, |
564 | unsigned int num_peers, | 560 | unsigned int num_peers, |
565 | GNUNET_TRANSPORT_TESTING_CheckCallback check, | 561 | GNUNET_TRANSPORT_TESTING_CheckCallback check, |
566 | void *check_cls) | 562 | void *check_cls) |
567 | { | 563 | { |
568 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 564 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; |
569 | char *test_name; | 565 | char *test_name; |
@@ -573,36 +569,36 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | |||
573 | int ret; | 569 | int ret; |
574 | 570 | ||
575 | ret = GNUNET_OK; | 571 | ret = GNUNET_OK; |
576 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0); | 572 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name(argv0); |
577 | GNUNET_log_setup (test_name, | 573 | GNUNET_log_setup(test_name, |
578 | "WARNING", | 574 | "WARNING", |
579 | NULL); | 575 | NULL); |
580 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (filename); | 576 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name(filename); |
581 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv0, | 577 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name(argv0, |
582 | test_source); | 578 | test_source); |
583 | for (unsigned int i=0;i<num_peers;i++) | 579 | for (unsigned int i = 0; i < num_peers; i++) |
584 | cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name (argv0, | 580 | cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name(argv0, |
585 | i+1); | 581 | i + 1); |
586 | tth = GNUNET_TRANSPORT_TESTING_init (); | 582 | tth = GNUNET_TRANSPORT_TESTING_init(); |
587 | if (NULL == tth) | 583 | if (NULL == tth) |
588 | { | 584 | { |
589 | ret = GNUNET_SYSERR; | 585 | ret = GNUNET_SYSERR; |
590 | } | 586 | } |
591 | else | 587 | else |
592 | { | 588 | { |
593 | ret = check (check_cls, | 589 | ret = check(check_cls, |
594 | tth, | 590 | tth, |
595 | test_plugin, | 591 | test_plugin, |
596 | test_name, | 592 | test_name, |
597 | num_peers, | 593 | num_peers, |
598 | cfg_names); | 594 | cfg_names); |
599 | GNUNET_TRANSPORT_TESTING_done (tth); | 595 | GNUNET_TRANSPORT_TESTING_done(tth); |
600 | } | 596 | } |
601 | for (unsigned int i=0;i<num_peers;i++) | 597 | for (unsigned int i = 0; i < num_peers; i++) |
602 | GNUNET_free (cfg_names[i]); | 598 | GNUNET_free(cfg_names[i]); |
603 | GNUNET_free (test_source); | 599 | GNUNET_free(test_source); |
604 | GNUNET_free_non_null (test_plugin); | 600 | GNUNET_free_non_null(test_plugin); |
605 | GNUNET_free (test_name); | 601 | GNUNET_free(test_name); |
606 | return ret; | 602 | return ret; |
607 | } | 603 | } |
608 | 604 | ||