aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing.h')
-rw-r--r--src/transport/transport-testing.h201
1 files changed, 106 insertions, 95 deletions
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 4629d6125..83bbf277b 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -11,7 +11,7 @@
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
@@ -30,7 +30,6 @@
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_hello_lib.h" 31#include "gnunet_hello_lib.h"
32#include "gnunet_transport_service.h" 32#include "gnunet_transport_service.h"
33#include "gnunet_transport_core_service.h"
34#include "gnunet_transport_hello_service.h" 33#include "gnunet_transport_hello_service.h"
35#include "gnunet_transport_manipulation_service.h" 34#include "gnunet_transport_manipulation_service.h"
36#include "gnunet_testing_lib.h" 35#include "gnunet_testing_lib.h"
@@ -143,7 +142,7 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext
143 * Closure for @e start_cb. 142 * Closure for @e start_cb.
144 */ 143 */
145 void *start_cb_cls; 144 void *start_cb_cls;
146 145
147 /** 146 /**
148 * An unique number to identify the peer 147 * An unique number to identify the peer
149 */ 148 */
@@ -207,12 +206,12 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest
207 */ 206 */
208 struct GNUNET_MQ_Handle *mq; 207 struct GNUNET_MQ_Handle *mq;
209 208
210 /** 209 /**
211 * Set if peer1 says the connection is up to peer2. 210 * Set if peer1 says the connection is up to peer2.
212 */ 211 */
213 int p1_c; 212 int p1_c;
214 213
215 /** 214 /**
216 * Set if peer2 says the connection is up to peer1. 215 * Set if peer2 says the connection is up to peer1.
217 */ 216 */
218 int p2_c; 217 int p2_c;
@@ -289,15 +288,16 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth);
289 * @return the peer context 288 * @return the peer context
290 */ 289 */
291struct GNUNET_TRANSPORT_TESTING_PeerContext * 290struct GNUNET_TRANSPORT_TESTING_PeerContext *
292GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth, 291GNUNET_TRANSPORT_TESTING_start_peer (
293 const char *cfgname, 292 struct GNUNET_TRANSPORT_TESTING_Handle *tth,
294 int peer_id, 293 const char *cfgname,
295 const struct GNUNET_MQ_MessageHandler *handlers, 294 int peer_id,
296 GNUNET_TRANSPORT_NotifyConnect nc, 295 const struct GNUNET_MQ_MessageHandler *handlers,
297 GNUNET_TRANSPORT_NotifyDisconnect nd, 296 GNUNET_TRANSPORT_NotifyConnect nc,
298 void *cb_cls, 297 GNUNET_TRANSPORT_NotifyDisconnect nd,
299 GNUNET_SCHEDULER_TaskCallback start_cb, 298 void *cb_cls,
300 void *start_cb_cls); 299 GNUNET_SCHEDULER_TaskCallback start_cb,
300 void *start_cb_cls);
301 301
302 302
303/** 303/**
@@ -306,7 +306,8 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
306 * @param p the peer 306 * @param p the peer
307 */ 307 */
308void 308void
309GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *pc); 309GNUNET_TRANSPORT_TESTING_stop_peer (
310 struct GNUNET_TRANSPORT_TESTING_PeerContext *pc);
310 311
311 312
312/** 313/**
@@ -318,10 +319,10 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext
318 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR 319 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
319 */ 320 */
320int 321int
321GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, 322GNUNET_TRANSPORT_TESTING_restart_peer (
322 GNUNET_SCHEDULER_TaskCallback restart_cb, 323 struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
323 void *restart_cb_cls); 324 GNUNET_SCHEDULER_TaskCallback restart_cb,
324 325 void *restart_cb_cls);
325 326
326 327
327/** 328/**
@@ -331,15 +332,17 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte
331 * 332 *
332 * @param p1 peer 1 333 * @param p1 peer 1
333 * @param p2 peer 2 334 * @param p2 peer 2
334 * @param cb the callback to call when both peers notified that they are connected 335 * @param cb the callback to call when both peers notified that they are
336 * connected
335 * @param cls callback cls 337 * @param cls callback cls
336 * @return a connect request handle 338 * @return a connect request handle
337 */ 339 */
338struct GNUNET_TRANSPORT_TESTING_ConnectRequest * 340struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
339GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 341GNUNET_TRANSPORT_TESTING_connect_peers (
340 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 342 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
341 GNUNET_SCHEDULER_TaskCallback cb, 343 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
342 void *cls); 344 GNUNET_SCHEDULER_TaskCallback cb,
345 void *cls);
343 346
344 347
345/** 348/**
@@ -350,7 +353,8 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont
350 * @param cc a connect request handle 353 * @param cc a connect request handle
351 */ 354 */
352void 355void
353GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); 356GNUNET_TRANSPORT_TESTING_connect_peers_cancel (
357 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
354 358
355 359
356/** 360/**
@@ -359,9 +363,9 @@ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_C
359 * @param cls closure 363 * @param cls closure
360 * @param cc request matching the query 364 * @param cc request matching the query
361 */ 365 */
362typedef void 366typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback) (
363(*GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, 367 void *cls,
364 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); 368 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
365 369
366 370
367/** 371/**
@@ -369,14 +373,15 @@ typedef void
369 * 373 *
370 * @param p1 first peer 374 * @param p1 first peer
371 * @param p2 second peer 375 * @param p2 second peer
372 * @param cb function to call 376 * @param cb function to call
373 * @param cb_cls closure for @a cb 377 * @param cb_cls closure for @a cb
374 */ 378 */
375void 379void
376GNUNET_TRANSPORT_TESTING_find_connecting_context (struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 380GNUNET_TRANSPORT_TESTING_find_connecting_context (
377 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 381 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
378 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, 382 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
379 void *cb_cls); 383 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb,
384 void *cb_cls);
380 385
381 386
382/* ********************** high-level process functions *************** */ 387/* ********************** high-level process functions *************** */
@@ -390,10 +395,10 @@ GNUNET_TRANSPORT_TESTING_find_connecting_context (struct GNUNET_TRANSPORT_TESTIN
390 * @param num_peers size of the @a p array 395 * @param num_peers size of the @a p array
391 * @param p the peers that were launched 396 * @param p the peers that were launched
392 */ 397 */
393typedef void 398typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContinuation) (
394(*GNUNET_TRANSPORT_TESTING_ConnectContinuation)(void *cls, 399 void *cls,
395 unsigned int num_peers, 400 unsigned int num_peers,
396 struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]); 401 struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]);
397 402
398 403
399/** 404/**
@@ -423,7 +428,6 @@ struct GNUNET_TRANSPORT_TESTING_TestMessage
423GNUNET_NETWORK_STRUCT_END 428GNUNET_NETWORK_STRUCT_END
424 429
425 430
426
427/** 431/**
428 * Function called by the transport for each received message. 432 * Function called by the transport for each received message.
429 * 433 *
@@ -432,11 +436,11 @@ GNUNET_NETWORK_STRUCT_END
432 * @param sender sender of the message 436 * @param sender sender of the message
433 * @param message the message 437 * @param message the message
434 */ 438 */
435typedef void 439typedef void (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (
436(*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (void *cls, 440 void *cls,
437 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 441 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
438 const struct GNUNET_PeerIdentity *sender, 442 const struct GNUNET_PeerIdentity *sender,
439 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message); 443 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message);
440 444
441 445
442/** 446/**
@@ -447,10 +451,10 @@ typedef void
447 * @param me peer experiencing the event 451 * @param me peer experiencing the event
448 * @param other peer that connected to @a me 452 * @param other peer that connected to @a me
449 */ 453 */
450typedef void 454typedef void (*GNUNET_TRANSPORT_TESTING_NotifyConnect) (
451(*GNUNET_TRANSPORT_TESTING_NotifyConnect) (void *cls, 455 void *cls,
452 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 456 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
453 const struct GNUNET_PeerIdentity *other); 457 const struct GNUNET_PeerIdentity *other);
454 458
455 459
456/** 460/**
@@ -461,10 +465,10 @@ typedef void
461 * @param me peer experiencing the event 465 * @param me peer experiencing the event
462 * @param other peer that disconnected from @a me 466 * @param other peer that disconnected from @a me
463 */ 467 */
464typedef void 468typedef void (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (
465(*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (void *cls, 469 void *cls,
466 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 470 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
467 const struct GNUNET_PeerIdentity *other); 471 const struct GNUNET_PeerIdentity *other);
468 472
469 473
470/** 474/**
@@ -593,7 +597,7 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
593 * message. 597 * message.
594 */ 598 */
595 uint32_t send_num_gen; 599 uint32_t send_num_gen;
596 600
597 /* ******* internal state, clients should not mess with this **** */ 601 /* ******* internal state, clients should not mess with this **** */
598 602
599 /** 603 /**
@@ -625,7 +629,6 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
625 * Array with @e num_peers entries. 629 * Array with @e num_peers entries.
626 */ 630 */
627 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip; 631 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip;
628
629}; 632};
630 633
631 634
@@ -637,8 +640,9 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
637 * @return NULL if @a peer was not found 640 * @return NULL if @a peer was not found
638 */ 641 */
639struct GNUNET_TRANSPORT_TESTING_PeerContext * 642struct GNUNET_TRANSPORT_TESTING_PeerContext *
640GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 643GNUNET_TRANSPORT_TESTING_find_peer (
641 const struct GNUNET_PeerIdentity *peer); 644 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
645 const struct GNUNET_PeerIdentity *peer);
642 646
643 647
644/** 648/**
@@ -648,7 +652,8 @@ GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheck
648 * abort the test, and a shutdown handler to clean up properly 652 * abort the test, and a shutdown handler to clean up properly
649 * on exit. 653 * on exit.
650 * 654 *
651 * @param cls closure of type `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` 655 * @param cls closure of type `struct
656 * GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
652 * @param tth_ initialized testing handle 657 * @param tth_ initialized testing handle
653 * @param test_plugin_ name of the plugin 658 * @param test_plugin_ name of the plugin
654 * @param test_name_ name of the test 659 * @param test_name_ name of the test
@@ -657,12 +662,13 @@ GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheck
657 * @return #GNUNET_SYSERR on error 662 * @return #GNUNET_SYSERR on error
658 */ 663 */
659int 664int
660GNUNET_TRANSPORT_TESTING_connect_check (void *cls, 665GNUNET_TRANSPORT_TESTING_connect_check (
661 struct GNUNET_TRANSPORT_TESTING_Handle *tth_, 666 void *cls,
662 const char *test_plugin_, 667 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
663 const char *test_name_, 668 const char *test_plugin_,
664 unsigned int num_peers, 669 const char *test_name_,
665 char *cfg_files[]); 670 unsigned int num_peers,
671 char *cfg_files[]);
666 672
667 673
668/** 674/**
@@ -677,13 +683,13 @@ GNUNET_TRANSPORT_TESTING_connect_check (void *cls,
677 * @param cfg_files array of names of configuration files for the peers 683 * @param cfg_files array of names of configuration files for the peers
678 * @return #GNUNET_SYSERR on error 684 * @return #GNUNET_SYSERR on error
679 */ 685 */
680typedef int 686typedef int (*GNUNET_TRANSPORT_TESTING_CheckCallback) (
681(*GNUNET_TRANSPORT_TESTING_CheckCallback)(void *cls, 687 void *cls,
682 struct GNUNET_TRANSPORT_TESTING_Handle *tth_, 688 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
683 const char *test_plugin_, 689 const char *test_plugin_,
684 const char *test_name_, 690 const char *test_name_,
685 unsigned int num_peers, 691 unsigned int num_peers,
686 char *cfg_files[]); 692 char *cfg_files[]);
687 693
688 694
689/** 695/**
@@ -712,8 +718,12 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
712 * @param check_cls closure for @a check 718 * @param check_cls closure for @a check
713 * @return #GNUNET_OK on success 719 * @return #GNUNET_OK on success
714 */ 720 */
715#define GNUNET_TRANSPORT_TESTING_main(num_peers,check,check_cls) \ 721#define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \
716 GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls) 722 GNUNET_TRANSPORT_TESTING_main_ (argv[0], \
723 __FILE__, \
724 num_peers, \
725 check, \
726 check_cls)
717 727
718/* ***************** Convenience functions for sending ********* */ 728/* ***************** Convenience functions for sending ********* */
719 729
@@ -725,7 +735,8 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
725 * @param sender the sending peer 735 * @param sender the sending peer
726 * @param receiver the receiving peer 736 * @param receiver the receiving peer
727 * @param mtype message type to use 737 * @param mtype message type to use
728 * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)` 738 * @param msize size of the message, at least `sizeof (struct
739 * GNUNET_TRANSPORT_TESTING_TestMessage)`
729 * @param num unique message number 740 * @param num unique message number
730 * @param cont continuation to call after transmission 741 * @param cont continuation to call after transmission
731 * @param cont_cls closure for @a cont 742 * @param cont_cls closure for @a cont
@@ -734,13 +745,14 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
734 * #GNUNET_SYSERR if @a msize is illegal 745 * #GNUNET_SYSERR if @a msize is illegal
735 */ 746 */
736int 747int
737GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, 748GNUNET_TRANSPORT_TESTING_send (
738 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 749 struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
739 uint16_t mtype, 750 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
740 uint16_t msize, 751 uint16_t mtype,
741 uint32_t num, 752 uint16_t msize,
742 GNUNET_SCHEDULER_TaskCallback cont, 753 uint32_t num,
743 void *cont_cls); 754 GNUNET_SCHEDULER_TaskCallback cont,
755 void *cont_cls);
744 756
745 757
746/** 758/**
@@ -771,14 +783,14 @@ struct GNUNET_TRANSPORT_TESTING_SendClosure
771 * the message size, can be NULL in which case the message 783 * the message size, can be NULL in which case the message
772 * size is the default. 784 * size is the default.
773 */ 785 */
774 size_t (*get_size_cb)(unsigned int n); 786 size_t (*get_size_cb) (unsigned int n);
775 787
776 /** 788 /**
777 * Number of messages to be transmitted in a loop. 789 * Number of messages to be transmitted in a loop.
778 * Use zero for "forever" (until external shutdown). 790 * Use zero for "forever" (until external shutdown).
779 */ 791 */
780 unsigned int num_messages; 792 unsigned int num_messages;
781 793
782 /** 794 /**
783 * Function to call after all transmissions, can be NULL. 795 * Function to call after all transmissions, can be NULL.
784 */ 796 */
@@ -788,12 +800,11 @@ struct GNUNET_TRANSPORT_TESTING_SendClosure
788 * Closure for @e cont. 800 * Closure for @e cont.
789 */ 801 */
790 void *cont_cls; 802 void *cont_cls;
791
792}; 803};
793 804
794 805
795/** 806/**
796 * Task that sends a minimalistic test message from the 807 * Task that sends a minimalistic test message from the
797 * first peer to the second peer. 808 * first peer to the second peer.
798 * 809 *
799 * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` 810 * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
@@ -804,14 +815,14 @@ void
804GNUNET_TRANSPORT_TESTING_simple_send (void *cls); 815GNUNET_TRANSPORT_TESTING_simple_send (void *cls);
805 816
806/** 817/**
807 * Size of a message sent with 818 * Size of a message sent with
808 * #GNUNET_TRANSPORT_TESTING_large_send(). Big enough 819 * #GNUNET_TRANSPORT_TESTING_large_send(). Big enough
809 * to usually force defragmentation. 820 * to usually force defragmentation.
810 */ 821 */
811#define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600 822#define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600
812 823
813/** 824/**
814 * Task that sends a large test message from the 825 * Task that sends a large test message from the
815 * first peer to the second peer. 826 * first peer to the second peer.
816 * 827 *
817 * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` 828 * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
@@ -833,9 +844,10 @@ GNUNET_TRANSPORT_TESTING_large_send (void *cls);
833 * @param other peer that connected. 844 * @param other peer that connected.
834 */ 845 */
835void 846void
836GNUNET_TRANSPORT_TESTING_log_connect (void *cls, 847GNUNET_TRANSPORT_TESTING_log_connect (
837 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 848 void *cls,
838 const struct GNUNET_PeerIdentity *other); 849 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
850 const struct GNUNET_PeerIdentity *other);
839 851
840 852
841/** 853/**
@@ -846,10 +858,10 @@ GNUNET_TRANSPORT_TESTING_log_connect (void *cls,
846 * @param other peer that disconnected. 858 * @param other peer that disconnected.
847 */ 859 */
848void 860void
849GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls, 861GNUNET_TRANSPORT_TESTING_log_disconnect (
850 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 862 void *cls,
851 const struct GNUNET_PeerIdentity *other); 863 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
852 864 const struct GNUNET_PeerIdentity *other);
853 865
854 866
855/* ********************** low-level filename functions *************** */ 867/* ********************** low-level filename functions *************** */
@@ -875,8 +887,7 @@ GNUNET_TRANSPORT_TESTING_get_test_name (const char *file);
875 * @return configuration name to use 887 * @return configuration name to use
876 */ 888 */
877char * 889char *
878GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, 890GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count);
879 int count);
880 891
881 892
882/** 893/**