diff options
Diffstat (limited to 'src/transport/transport-testing.h')
-rw-r--r-- | src/transport/transport-testing.h | 914 |
1 files changed, 0 insertions, 914 deletions
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h deleted file mode 100644 index c548e59c1..000000000 --- a/src/transport/transport-testing.h +++ /dev/null | |||
@@ -1,914 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2006, 2009, 2015, 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 | /** | ||
22 | * @file transport-testing.h | ||
23 | * @brief testing lib for transport service | ||
24 | * @author Matthias Wachs | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | #ifndef TRANSPORT_TESTING_H | ||
28 | #define TRANSPORT_TESTING_H | ||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_hello_lib.h" | ||
32 | #include "gnunet_transport_service.h" | ||
33 | #include "gnunet_transport_hello_service.h" | ||
34 | #include "gnunet_transport_manipulation_service.h" | ||
35 | #include "gnunet_testing_lib.h" | ||
36 | |||
37 | |||
38 | /* ************* Basic functions for starting/stopping/connecting *********** */ | ||
39 | |||
40 | /** | ||
41 | * Context for a single peer | ||
42 | */ | ||
43 | struct GNUNET_TRANSPORT_TESTING_PeerContext; | ||
44 | |||
45 | /** | ||
46 | * Definition for a transport testing handle | ||
47 | */ | ||
48 | struct GNUNET_TRANSPORT_TESTING_Handle; | ||
49 | |||
50 | |||
51 | /** | ||
52 | * Context for a single peer | ||
53 | */ | ||
54 | struct GNUNET_TRANSPORT_TESTING_PeerContext | ||
55 | { | ||
56 | /** | ||
57 | * Next element in the DLL | ||
58 | */ | ||
59 | struct GNUNET_TRANSPORT_TESTING_PeerContext *next; | ||
60 | |||
61 | /** | ||
62 | * Previous element in the DLL | ||
63 | */ | ||
64 | struct GNUNET_TRANSPORT_TESTING_PeerContext *prev; | ||
65 | |||
66 | /** | ||
67 | * Transport testing handle this peer belongs to | ||
68 | */ | ||
69 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | ||
70 | |||
71 | /** | ||
72 | * Peer's configuration | ||
73 | */ | ||
74 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
75 | |||
76 | /** | ||
77 | * Peer's transport service handle | ||
78 | */ | ||
79 | struct GNUNET_TRANSPORT_CoreHandle *th; | ||
80 | |||
81 | /** | ||
82 | * Peer's transport service manipulation handle | ||
83 | */ | ||
84 | struct GNUNET_TRANSPORT_ManipulationHandle *tmh; | ||
85 | |||
86 | /** | ||
87 | * Peer's ATS handle. | ||
88 | */ | ||
89 | struct GNUNET_ATS_ConnectivityHandle *ats; | ||
90 | |||
91 | /** | ||
92 | * Peer's transport get hello handle to retrieve peer's HELLO message | ||
93 | */ | ||
94 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh; | ||
95 | |||
96 | /** | ||
97 | * Peer's testing handle | ||
98 | */ | ||
99 | struct GNUNET_TESTING_Peer *peer; | ||
100 | |||
101 | /** | ||
102 | * Peer identity | ||
103 | */ | ||
104 | struct GNUNET_PeerIdentity id; | ||
105 | |||
106 | /** | ||
107 | * Handle for the peer's ARM process | ||
108 | */ | ||
109 | struct GNUNET_OS_Process *arm_proc; | ||
110 | |||
111 | /** | ||
112 | * Receive callback | ||
113 | */ | ||
114 | struct GNUNET_MQ_MessageHandler *handlers; | ||
115 | |||
116 | /** | ||
117 | * Notify connect callback | ||
118 | */ | ||
119 | GNUNET_TRANSPORT_NotifyConnect nc; | ||
120 | |||
121 | /** | ||
122 | * Notify disconnect callback | ||
123 | */ | ||
124 | GNUNET_TRANSPORT_NotifyDisconnect nd; | ||
125 | |||
126 | /** | ||
127 | * Startup completed callback | ||
128 | */ | ||
129 | GNUNET_SCHEDULER_TaskCallback start_cb; | ||
130 | |||
131 | /** | ||
132 | * Peers HELLO Message | ||
133 | */ | ||
134 | struct GNUNET_HELLO_Message *hello; | ||
135 | |||
136 | /** | ||
137 | * Closure for the @a nc and @a nd callbacks | ||
138 | */ | ||
139 | void *cb_cls; | ||
140 | |||
141 | /** | ||
142 | * Closure for @e start_cb. | ||
143 | */ | ||
144 | void *start_cb_cls; | ||
145 | |||
146 | /** | ||
147 | * An unique number to identify the peer | ||
148 | */ | ||
149 | unsigned int no; | ||
150 | }; | ||
151 | |||
152 | |||
153 | /** | ||
154 | * Handle for a request to connect two peers. | ||
155 | */ | ||
156 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest | ||
157 | { | ||
158 | /** | ||
159 | * Kept in a DLL. | ||
160 | */ | ||
161 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next; | ||
162 | |||
163 | /** | ||
164 | * Kept in a DLL. | ||
165 | */ | ||
166 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev; | ||
167 | |||
168 | /** | ||
169 | * Peer we want to connect. | ||
170 | */ | ||
171 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
172 | |||
173 | /** | ||
174 | * Peer we want to connect. | ||
175 | */ | ||
176 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
177 | |||
178 | /** | ||
179 | * Task by which we accomplish the connection. | ||
180 | */ | ||
181 | struct GNUNET_SCHEDULER_Task *tct; | ||
182 | |||
183 | /** | ||
184 | * Handle by which we ask ATS to facilitate the connection. | ||
185 | */ | ||
186 | struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | ||
187 | |||
188 | /** | ||
189 | * Handle by which we inform the peer about the HELLO of | ||
190 | * the other peer. | ||
191 | */ | ||
192 | struct GNUNET_TRANSPORT_OfferHelloHandle *oh; | ||
193 | |||
194 | /** | ||
195 | * Function to call upon completion. | ||
196 | */ | ||
197 | GNUNET_SCHEDULER_TaskCallback cb; | ||
198 | |||
199 | /** | ||
200 | * Closure for @e cb. | ||
201 | */ | ||
202 | void *cb_cls; | ||
203 | |||
204 | /** | ||
205 | * Message queue for sending from @a p1 to @a p2. | ||
206 | */ | ||
207 | struct GNUNET_MQ_Handle *mq; | ||
208 | |||
209 | /** | ||
210 | * Set if peer1 says the connection is up to peer2. | ||
211 | */ | ||
212 | int p1_c; | ||
213 | |||
214 | /** | ||
215 | * Set if peer2 says the connection is up to peer1. | ||
216 | */ | ||
217 | int p2_c; | ||
218 | |||
219 | /** | ||
220 | * #GNUNET_YES if both @e p1_c and @e p2_c are #GNUNET_YES. | ||
221 | */ | ||
222 | int connected; | ||
223 | }; | ||
224 | |||
225 | |||
226 | /** | ||
227 | * Handle for a test run. | ||
228 | */ | ||
229 | struct GNUNET_TRANSPORT_TESTING_Handle | ||
230 | { | ||
231 | /** | ||
232 | * Testing library system handle | ||
233 | */ | ||
234 | struct GNUNET_TESTING_System *tl_system; | ||
235 | |||
236 | /** | ||
237 | * head DLL of connect contexts | ||
238 | */ | ||
239 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_head; | ||
240 | |||
241 | /** | ||
242 | * head DLL of connect contexts | ||
243 | */ | ||
244 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail; | ||
245 | |||
246 | /** | ||
247 | * head DLL of peers | ||
248 | */ | ||
249 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p_head; | ||
250 | |||
251 | /** | ||
252 | * tail DLL of peers | ||
253 | */ | ||
254 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p_tail; | ||
255 | }; | ||
256 | |||
257 | |||
258 | /** | ||
259 | * Initialize the transport testing | ||
260 | * | ||
261 | * @return transport testing handle | ||
262 | */ | ||
263 | struct GNUNET_TRANSPORT_TESTING_Handle * | ||
264 | GNUNET_TRANSPORT_TESTING_init (void); | ||
265 | |||
266 | |||
267 | /** | ||
268 | * Clean up the transport testing | ||
269 | * | ||
270 | * @param tth transport testing handle | ||
271 | */ | ||
272 | void | ||
273 | GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth); | ||
274 | |||
275 | |||
276 | /** | ||
277 | * Start a peer with the given configuration | ||
278 | * | ||
279 | * @param tth the testing handle | ||
280 | * @param cfgname configuration file | ||
281 | * @param peer_id the peer_id | ||
282 | * @param handlers functions for receiving messages | ||
283 | * @param nc connect callback | ||
284 | * @param nd disconnect callback | ||
285 | * @param cb_cls closure for @a nc and @a nd callback | ||
286 | * @param start_cb start callback | ||
287 | * @param start_cb_cls closure for @a start_cb | ||
288 | * @return the peer context | ||
289 | */ | ||
290 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | ||
291 | GNUNET_TRANSPORT_TESTING_start_peer ( | ||
292 | struct GNUNET_TRANSPORT_TESTING_Handle *tth, | ||
293 | const char *cfgname, | ||
294 | int peer_id, | ||
295 | const struct GNUNET_MQ_MessageHandler *handlers, | ||
296 | GNUNET_TRANSPORT_NotifyConnect nc, | ||
297 | GNUNET_TRANSPORT_NotifyDisconnect nd, | ||
298 | void *cb_cls, | ||
299 | GNUNET_SCHEDULER_TaskCallback start_cb, | ||
300 | void *start_cb_cls); | ||
301 | |||
302 | |||
303 | /** | ||
304 | * Shutdown the given peer | ||
305 | * | ||
306 | * @param p the peer | ||
307 | */ | ||
308 | void | ||
309 | GNUNET_TRANSPORT_TESTING_stop_peer ( | ||
310 | struct GNUNET_TRANSPORT_TESTING_PeerContext *pc); | ||
311 | |||
312 | |||
313 | /** | ||
314 | * Stops and restarts the given peer, sleeping (!) for 5s in between. | ||
315 | * | ||
316 | * @param p the peer | ||
317 | * @param restart_cb restart callback | ||
318 | * @param restart_cb_cls callback closure | ||
319 | * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR | ||
320 | */ | ||
321 | int | ||
322 | GNUNET_TRANSPORT_TESTING_restart_peer ( | ||
323 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | ||
324 | GNUNET_SCHEDULER_TaskCallback restart_cb, | ||
325 | void *restart_cb_cls); | ||
326 | |||
327 | |||
328 | /** | ||
329 | * Connect the given peers and call the callback when both peers | ||
330 | * report the inbound connection. Remarks: start_peer's notify_connect | ||
331 | * callback can be called before. | ||
332 | * | ||
333 | * @param p1 peer 1 | ||
334 | * @param p2 peer 2 | ||
335 | * @param cb the callback to call when both peers notified that they are | ||
336 | * connected | ||
337 | * @param cls callback cls | ||
338 | * @return a connect request handle | ||
339 | */ | ||
340 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest * | ||
341 | GNUNET_TRANSPORT_TESTING_connect_peers ( | ||
342 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, | ||
343 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, | ||
344 | GNUNET_SCHEDULER_TaskCallback cb, | ||
345 | void *cls); | ||
346 | |||
347 | |||
348 | /** | ||
349 | * Cancel the request to connect two peers. You MUST cancel the | ||
350 | * request if you stop the peers before the peers connected | ||
351 | * successfully. | ||
352 | * | ||
353 | * @param cc a connect request handle | ||
354 | */ | ||
355 | void | ||
356 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel ( | ||
357 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); | ||
358 | |||
359 | |||
360 | /** | ||
361 | * Function called on matching connect requests. | ||
362 | * | ||
363 | * @param cls closure | ||
364 | * @param cc request matching the query | ||
365 | */ | ||
366 | typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback) ( | ||
367 | void *cls, | ||
368 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); | ||
369 | |||
370 | |||
371 | /** | ||
372 | * Find any connecting context matching the given pair of peers. | ||
373 | * | ||
374 | * @param p1 first peer | ||
375 | * @param p2 second peer | ||
376 | * @param cb function to call | ||
377 | * @param cb_cls closure for @a cb | ||
378 | */ | ||
379 | void | ||
380 | GNUNET_TRANSPORT_TESTING_find_connecting_context ( | ||
381 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, | ||
382 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, | ||
383 | GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, | ||
384 | void *cb_cls); | ||
385 | |||
386 | |||
387 | /* ********************** high-level process functions *************** */ | ||
388 | |||
389 | |||
390 | /** | ||
391 | * Function called once the peers have been launched and | ||
392 | * connected by #GNUNET_TRANSPORT_TESTING_connect_check(). | ||
393 | * | ||
394 | * @param cls closure | ||
395 | * @param num_peers size of the @a p array | ||
396 | * @param p the peers that were launched | ||
397 | */ | ||
398 | typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContinuation) ( | ||
399 | void *cls, | ||
400 | unsigned int num_peers, | ||
401 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]); | ||
402 | |||
403 | |||
404 | /** | ||
405 | * Internal data structure. | ||
406 | */ | ||
407 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList; | ||
408 | |||
409 | /** | ||
410 | * Internal data structure. | ||
411 | */ | ||
412 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext; | ||
413 | |||
414 | |||
415 | GNUNET_NETWORK_STRUCT_BEGIN | ||
416 | struct GNUNET_TRANSPORT_TESTING_TestMessage | ||
417 | { | ||
418 | /** | ||
419 | * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE. | ||
420 | */ | ||
421 | struct GNUNET_MessageHeader header; | ||
422 | |||
423 | /** | ||
424 | * Monotonically increasing counter throughout the test. | ||
425 | */ | ||
426 | uint32_t num GNUNET_PACKED; | ||
427 | }; | ||
428 | GNUNET_NETWORK_STRUCT_END | ||
429 | |||
430 | |||
431 | /** | ||
432 | * Function called by the transport for each received message. | ||
433 | * | ||
434 | * @param cls closure | ||
435 | * @param receiver receiver of the message | ||
436 | * @param sender sender of the message | ||
437 | * @param message the message | ||
438 | */ | ||
439 | typedef void (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) ( | ||
440 | void *cls, | ||
441 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | ||
442 | const struct GNUNET_PeerIdentity *sender, | ||
443 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message); | ||
444 | |||
445 | |||
446 | /** | ||
447 | * Function called to notify transport users that another | ||
448 | * peer connected to us. | ||
449 | * | ||
450 | * @param cls closure | ||
451 | * @param me peer experiencing the event | ||
452 | * @param other peer that connected to @a me | ||
453 | */ | ||
454 | typedef void (*GNUNET_TRANSPORT_TESTING_NotifyConnect) ( | ||
455 | void *cls, | ||
456 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
457 | const struct GNUNET_PeerIdentity *other); | ||
458 | |||
459 | |||
460 | /** | ||
461 | * Function called to notify transport users that another | ||
462 | * peer disconnected from us. | ||
463 | * | ||
464 | * @param cls closure | ||
465 | * @param me peer experiencing the event | ||
466 | * @param other peer that disconnected from @a me | ||
467 | */ | ||
468 | typedef void (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) ( | ||
469 | void *cls, | ||
470 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
471 | const struct GNUNET_PeerIdentity *other); | ||
472 | |||
473 | |||
474 | /** | ||
475 | * Closure that must be passed to | ||
476 | * #GNUNET_TRANSPORT_TESTING_connect_check. | ||
477 | */ | ||
478 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext | ||
479 | { | ||
480 | /** | ||
481 | * How should we continue after the connect? | ||
482 | */ | ||
483 | GNUNET_SCHEDULER_TaskCallback connect_continuation; | ||
484 | |||
485 | /** | ||
486 | * Closure for @e connect_continuation. | ||
487 | */ | ||
488 | void *connect_continuation_cls; | ||
489 | |||
490 | /** | ||
491 | * Which configuration file should we pass to the | ||
492 | * #GNUNET_PROGRAM_run() of the testcase? | ||
493 | */ | ||
494 | const char *config_file; | ||
495 | |||
496 | /** | ||
497 | * Receiver argument to give for peers we start. | ||
498 | */ | ||
499 | GNUNET_TRANSPORT_TESTING_ReceiveCallback rec; | ||
500 | |||
501 | /** | ||
502 | * Notify connect argument to give for peers we start. | ||
503 | */ | ||
504 | GNUNET_TRANSPORT_TESTING_NotifyConnect nc; | ||
505 | |||
506 | /** | ||
507 | * Notify disconnect argument to give for peers we start. | ||
508 | */ | ||
509 | GNUNET_TRANSPORT_TESTING_NotifyDisconnect nd; | ||
510 | |||
511 | /** | ||
512 | * Closure for @e rec, @e nc and @e nd. | ||
513 | */ | ||
514 | void *cls; | ||
515 | |||
516 | /** | ||
517 | * Custom task to run on shutdown. | ||
518 | */ | ||
519 | GNUNET_SCHEDULER_TaskCallback shutdown_task; | ||
520 | |||
521 | /** | ||
522 | * Closure for @e shutdown_task. | ||
523 | */ | ||
524 | void *shutdown_task_cls; | ||
525 | |||
526 | /** | ||
527 | * Custom task to run after peers were started but before we try to | ||
528 | * connect them. If this function is set, we wait ONE second after | ||
529 | * running this function until we continue with connecting the | ||
530 | * peers. | ||
531 | */ | ||
532 | GNUNET_SCHEDULER_TaskCallback pre_connect_task; | ||
533 | |||
534 | /** | ||
535 | * Closure for @e shutdown_task. | ||
536 | */ | ||
537 | void *pre_connect_task_cls; | ||
538 | |||
539 | /** | ||
540 | * When should the testcase time out? | ||
541 | */ | ||
542 | struct GNUNET_TIME_Relative timeout; | ||
543 | |||
544 | /** | ||
545 | * Should we try to create connections in both directions? | ||
546 | */ | ||
547 | int bi_directional; | ||
548 | |||
549 | /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */ | ||
550 | |||
551 | /** | ||
552 | * Number of peers involved in the test. | ||
553 | */ | ||
554 | unsigned int num_peers; | ||
555 | |||
556 | /** | ||
557 | * Configuration files we have, array with @e num_peers entries. | ||
558 | */ | ||
559 | char **cfg_files; | ||
560 | |||
561 | /** | ||
562 | * Array with @e num_peers entries. | ||
563 | */ | ||
564 | struct GNUNET_TRANSPORT_TESTING_PeerContext **p; | ||
565 | |||
566 | /** | ||
567 | * Name of the plugin. | ||
568 | */ | ||
569 | const char *test_plugin; | ||
570 | |||
571 | /** | ||
572 | * Name of the testcase. | ||
573 | */ | ||
574 | const char *test_name; | ||
575 | |||
576 | /** | ||
577 | * Configuration object for the testcase. | ||
578 | */ | ||
579 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
580 | |||
581 | /** | ||
582 | * Main testing handle. | ||
583 | */ | ||
584 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | ||
585 | |||
586 | /** | ||
587 | * Result from the main function, set to #GNUNET_OK on success. | ||
588 | * Clients should set to #GNUNET_SYSERR to indicate test failure. | ||
589 | */ | ||
590 | int global_ret; | ||
591 | |||
592 | /** | ||
593 | * Generator for the `num` field in test messages. Incremented each | ||
594 | * time #GNUNET_TRANSPORT_TESTING_simple_send or | ||
595 | * #GNUNET_TRANSPORT_TESTING_large_send are used to transmit a | ||
596 | * message. | ||
597 | */ | ||
598 | uint32_t send_num_gen; | ||
599 | |||
600 | /* ******* internal state, clients should not mess with this **** */ | ||
601 | |||
602 | /** | ||
603 | * Task run on timeout. | ||
604 | */ | ||
605 | struct GNUNET_SCHEDULER_Task *timeout_task; | ||
606 | |||
607 | /** | ||
608 | * Task run to connect peers. | ||
609 | */ | ||
610 | struct GNUNET_SCHEDULER_Task *connect_task; | ||
611 | |||
612 | /** | ||
613 | * Number of peers that have been started. | ||
614 | */ | ||
615 | unsigned int started; | ||
616 | |||
617 | /** | ||
618 | * DLL of active connect requests. | ||
619 | */ | ||
620 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_head; | ||
621 | |||
622 | /** | ||
623 | * DLL of active connect requests. | ||
624 | */ | ||
625 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_tail; | ||
626 | |||
627 | /** | ||
628 | * Array with @e num_peers entries. | ||
629 | */ | ||
630 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip; | ||
631 | }; | ||
632 | |||
633 | |||
634 | /** | ||
635 | * Find peer by peer ID. | ||
636 | * | ||
637 | * @param ccc context to search | ||
638 | * @param peer peer to look for | ||
639 | * @return NULL if @a peer was not found | ||
640 | */ | ||
641 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | ||
642 | GNUNET_TRANSPORT_TESTING_find_peer ( | ||
643 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, | ||
644 | const struct GNUNET_PeerIdentity *peer); | ||
645 | |||
646 | |||
647 | /** | ||
648 | * Common implementation of the #GNUNET_TRANSPORT_TESTING_CheckCallback. | ||
649 | * Starts and connects the two peers, then invokes the | ||
650 | * `connect_continuation` from @a cls. Sets up a timeout to | ||
651 | * abort the test, and a shutdown handler to clean up properly | ||
652 | * on exit. | ||
653 | * | ||
654 | * @param cls closure of type `struct | ||
655 | * GNUNET_TRANSPORT_TESTING_ConnectCheckContext` | ||
656 | * @param tth_ initialized testing handle | ||
657 | * @param test_plugin_ name of the plugin | ||
658 | * @param test_name_ name of the test | ||
659 | * @param num_peers number of entries in the @a cfg_file array | ||
660 | * @param cfg_files array of names of configuration files for the peers | ||
661 | * @return #GNUNET_SYSERR on error | ||
662 | */ | ||
663 | int | ||
664 | GNUNET_TRANSPORT_TESTING_connect_check ( | ||
665 | void *cls, | ||
666 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, | ||
667 | const char *test_plugin_, | ||
668 | const char *test_name_, | ||
669 | unsigned int num_peers, | ||
670 | char *cfg_files[]); | ||
671 | |||
672 | |||
673 | /** | ||
674 | * Main function of a testcase. Called with the initial setup data | ||
675 | * for the test as derived from the source name and the binary name. | ||
676 | * | ||
677 | * @param cls closure | ||
678 | * @param tth_ initialized testing handle | ||
679 | * @param test_plugin_ name of the plugin | ||
680 | * @param test_name_ name of the test | ||
681 | * @param num_peers number of entries in the @a cfg_file array | ||
682 | * @param cfg_files array of names of configuration files for the peers | ||
683 | * @return #GNUNET_SYSERR on error | ||
684 | */ | ||
685 | typedef int (*GNUNET_TRANSPORT_TESTING_CheckCallback) ( | ||
686 | void *cls, | ||
687 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, | ||
688 | const char *test_plugin_, | ||
689 | const char *test_name_, | ||
690 | unsigned int num_peers, | ||
691 | char *cfg_files[]); | ||
692 | |||
693 | |||
694 | /** | ||
695 | * Setup testcase. Calls @a check with the data the test needs. | ||
696 | * | ||
697 | * @param argv0 binary name (argv[0]) | ||
698 | * @param filename source file name (__FILE__) | ||
699 | * @param num_peers number of peers to start | ||
700 | * @param check main function to run | ||
701 | * @param check_cls closure for @a check | ||
702 | * @return #GNUNET_OK on success | ||
703 | */ | ||
704 | int | ||
705 | GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | ||
706 | const char *filename, | ||
707 | unsigned int num_peers, | ||
708 | GNUNET_TRANSPORT_TESTING_CheckCallback check, | ||
709 | void *check_cls); | ||
710 | |||
711 | |||
712 | /** | ||
713 | * Setup testcase. Calls @a check with the data the test needs. | ||
714 | * | ||
715 | * @param num_peers number of peers to start | ||
716 | * @param check main function to run | ||
717 | * @param check_cls closure for @a check | ||
718 | * @return #GNUNET_OK on success | ||
719 | */ | ||
720 | #define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \ | ||
721 | GNUNET_TRANSPORT_TESTING_main_ (argv[0], \ | ||
722 | __FILE__, \ | ||
723 | num_peers, \ | ||
724 | check, \ | ||
725 | check_cls) | ||
726 | |||
727 | /* ***************** Convenience functions for sending ********* */ | ||
728 | |||
729 | /** | ||
730 | * Send a test message of type @a mtype and size @a msize from | ||
731 | * peer @a sender to peer @a receiver. The peers should be | ||
732 | * connected when this function is called. | ||
733 | * | ||
734 | * @param sender the sending peer | ||
735 | * @param receiver the receiving peer | ||
736 | * @param mtype message type to use | ||
737 | * @param msize size of the message, at least `sizeof (struct | ||
738 | * GNUNET_TRANSPORT_TESTING_TestMessage)` | ||
739 | * @param num unique message number | ||
740 | * @param cont continuation to call after transmission | ||
741 | * @param cont_cls closure for @a cont | ||
742 | * @return #GNUNET_OK if message was queued, | ||
743 | * #GNUNET_NO if peers are not connected | ||
744 | * #GNUNET_SYSERR if @a msize is illegal | ||
745 | */ | ||
746 | int | ||
747 | GNUNET_TRANSPORT_TESTING_send ( | ||
748 | struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, | ||
749 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | ||
750 | uint16_t mtype, | ||
751 | uint16_t msize, | ||
752 | uint32_t num, | ||
753 | GNUNET_SCHEDULER_TaskCallback cont, | ||
754 | void *cont_cls); | ||
755 | |||
756 | |||
757 | /** | ||
758 | * Message type used by #GNUNET_TRANSPORT_TESTING_simple_send(). | ||
759 | */ | ||
760 | #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345 | ||
761 | |||
762 | /** | ||
763 | * Alternative message type for tests. | ||
764 | */ | ||
765 | #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346 | ||
766 | |||
767 | |||
768 | /** | ||
769 | * Type of the closure argument to pass to | ||
770 | * #GNUNET_TRANSPORT_TESTING_simple_send() and | ||
771 | * #GNUNET_TRANSPORT_TESTING_large_send(). | ||
772 | */ | ||
773 | struct GNUNET_TRANSPORT_TESTING_SendClosure | ||
774 | { | ||
775 | /** | ||
776 | * Context for the transmission. | ||
777 | */ | ||
778 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | ||
779 | |||
780 | /** | ||
781 | * Function that returns the desired message size. Overrides | ||
782 | * the message size, can be NULL in which case the message | ||
783 | * size is the default. | ||
784 | */ | ||
785 | size_t (*get_size_cb) (unsigned int n); | ||
786 | |||
787 | /** | ||
788 | * Number of messages to be transmitted in a loop. | ||
789 | * Use zero for "forever" (until external shutdown). | ||
790 | */ | ||
791 | unsigned int num_messages; | ||
792 | |||
793 | /** | ||
794 | * Function to call after all transmissions, can be NULL. | ||
795 | */ | ||
796 | GNUNET_SCHEDULER_TaskCallback cont; | ||
797 | |||
798 | /** | ||
799 | * Closure for @e cont. | ||
800 | */ | ||
801 | void *cont_cls; | ||
802 | }; | ||
803 | |||
804 | |||
805 | /** | ||
806 | * Task that sends a minimalistic test message from the | ||
807 | * first peer to the second peer. | ||
808 | * | ||
809 | * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` | ||
810 | * which should contain at least two peers, the first two | ||
811 | * of which should be currently connected | ||
812 | */ | ||
813 | void | ||
814 | GNUNET_TRANSPORT_TESTING_simple_send (void *cls); | ||
815 | |||
816 | /** | ||
817 | * Size of a message sent with | ||
818 | * #GNUNET_TRANSPORT_TESTING_large_send(). Big enough | ||
819 | * to usually force defragmentation. | ||
820 | */ | ||
821 | #define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600 | ||
822 | |||
823 | /** | ||
824 | * Task that sends a large test message from the | ||
825 | * first peer to the second peer. | ||
826 | * | ||
827 | * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` | ||
828 | * which should contain at least two peers, the first two | ||
829 | * of which should be currently connected | ||
830 | */ | ||
831 | void | ||
832 | GNUNET_TRANSPORT_TESTING_large_send (void *cls); | ||
833 | |||
834 | |||
835 | /* ********************** log-only convenience functions ************* */ | ||
836 | |||
837 | |||
838 | /** | ||
839 | * Log a connect event. | ||
840 | * | ||
841 | * @param cls NULL | ||
842 | * @param me peer that had the event | ||
843 | * @param other peer that connected. | ||
844 | */ | ||
845 | void | ||
846 | GNUNET_TRANSPORT_TESTING_log_connect ( | ||
847 | void *cls, | ||
848 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
849 | const struct GNUNET_PeerIdentity *other); | ||
850 | |||
851 | |||
852 | /** | ||
853 | * Log a disconnect event. | ||
854 | * | ||
855 | * @param cls NULL | ||
856 | * @param me peer that had the event | ||
857 | * @param other peer that disconnected. | ||
858 | */ | ||
859 | void | ||
860 | GNUNET_TRANSPORT_TESTING_log_disconnect ( | ||
861 | void *cls, | ||
862 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
863 | const struct GNUNET_PeerIdentity *other); | ||
864 | |||
865 | |||
866 | /* ********************** low-level filename functions *************** */ | ||
867 | |||
868 | |||
869 | /** | ||
870 | * Extracts the test filename from an absolute file name and removes | ||
871 | * the extension. | ||
872 | * | ||
873 | * @param file absolute file name | ||
874 | * @return resulting test name | ||
875 | */ | ||
876 | char * | ||
877 | GNUNET_TRANSPORT_TESTING_get_test_name (const char *file); | ||
878 | |||
879 | |||
880 | /** | ||
881 | * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and | ||
882 | * if existing ".exe"-prefix and adds the peer-number | ||
883 | * | ||
884 | * @param file filename of the test, e.g. argv[0] | ||
885 | * @param count peer number | ||
886 | * @return configuration name to use | ||
887 | */ | ||
888 | char * | ||
889 | GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count); | ||
890 | |||
891 | |||
892 | /** | ||
893 | * Extracts the plugin anme from an absolute file name and the test name | ||
894 | * @param file absolute file name | ||
895 | * @param test test name | ||
896 | * @return the plugin name | ||
897 | */ | ||
898 | char * | ||
899 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable, | ||
900 | const char *testname); | ||
901 | |||
902 | |||
903 | /** | ||
904 | * Extracts the filename from an absolute file name and removes the | ||
905 | * extension | ||
906 | * | ||
907 | * @param file absolute file name | ||
908 | * @return the source name | ||
909 | */ | ||
910 | char * | ||
911 | GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file); | ||
912 | |||
913 | #endif | ||
914 | /* end of transport_testing.h */ | ||