GNUnet  0.11.x
transport-testing.h
Go to the documentation of this file.
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 
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"
35 #include "gnunet_testing_lib.h"
36 
37 
38 /* ************* Basic functions for starting/stopping/connecting *********** */
39 
44 
49 
50 
55 {
60 
65 
70 
75 
80 
85 
90 
95 
100 
105 
110 
115 
120 
125 
130 
135 
139  void *cb_cls;
140 
145 
149  unsigned int no;
150 };
151 
152 
157 {
162 
167 
172 
177 
182 
187 
193 
198 
202  void *cb_cls;
203 
208 
212  int p1_c;
213 
217  int p2_c;
218 
223 };
224 
225 
230 {
235 
240 
245 
250 
255 };
256 
257 
265 
266 
272 void
274 
275 
293  const char *cfgname,
294  int peer_id,
295  const struct GNUNET_MQ_MessageHandler *handlers,
298  void *cb_cls,
300  void *start_cb_cls);
301 
302 
308 void
311 
312 
321 int
325  void *restart_cb_cls);
326 
327 
345  void *cls);
346 
347 
355 void
358 
359 
367  void *cls,
369 
370 
379 void
384  void *cb_cls);
385 
386 
387 /* ********************** high-level process functions *************** */
388 
389 
399  void *cls,
400  unsigned int num_peers,
402 
403 
408 
413 
414 
417 {
421  struct GNUNET_MessageHeader header;
422 
426  uint32_t num GNUNET_PACKED;
427 };
429 
430 
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 
455  void *cls,
457  const struct GNUNET_PeerIdentity *other);
458 
459 
469  void *cls,
471  const struct GNUNET_PeerIdentity *other);
472 
473 
479 {
484 
489 
494  const char *config_file;
495 
500 
505 
510 
514  void *cls;
515 
520 
525 
533 
538 
543 
548 
549  /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */
550 
554  unsigned int num_peers;
555 
559  char **cfg_files;
560 
565 
569  const char *test_plugin;
570 
574  const char *test_name;
575 
580 
585 
591 
598  uint32_t send_num_gen;
599 
600  /* ******* internal state, clients should not mess with this **** */
601 
606 
611 
615  unsigned int started;
616 
621 
626 
631 };
632 
633 
644  const struct GNUNET_PeerIdentity *peer);
645 
646 
663 int
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 
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 
704 int
705 GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
706  const char *filename,
707  unsigned int num_peers,
709  void *check_cls);
710 
711 
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 
746 int
749  struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
750  uint16_t mtype,
751  uint16_t msize,
752  uint32_t num,
754  void *cont_cls);
755 
756 
760 #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345
761 
765 #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346
766 
767 
774 {
779 
785  size_t (*get_size_cb) (unsigned int n);
786 
791  unsigned int num_messages;
792 
797 
801  void *cont_cls;
802 };
803 
804 
813 void
815 
821 #define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600
822 
831 void
833 
834 
835 /* ********************** log-only convenience functions ************* */
836 
837 
845 void
847  void *cls,
849  const struct GNUNET_PeerIdentity *other);
850 
851 
859 void
861  void *cls,
863  const struct GNUNET_PeerIdentity *other);
864 
865 
866 /* ********************** low-level filename functions *************** */
867 
868 
876 char *
877 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file);
878 
879 
888 char *
889 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count);
890 
891 
898 char *
899 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
900  const char *testname);
901 
902 
910 char *
912 
913 #endif
914 /* end of transport_testing.h */
void GNUNET_TRANSPORT_TESTING_find_connecting_context(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, void *cb_cls)
Find any connecting context matching the given pair of peers.
struct GNUNET_TRANSPORT_TESTING_PeerContext * GNUNET_TRANSPORT_TESTING_find_peer(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, const struct GNUNET_PeerIdentity *peer)
Find peer by peer ID.
struct GNUNET_SCHEDULER_Task * connect_task
Task run to connect peers.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
Handle for a request to connect two peers.
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Cancel the request to connect two peers.
GNUNET_SCHEDULER_TaskCallback connect_continuation
How should we continue after the connect?
int(* GNUNET_TRANSPORT_TESTING_CheckCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_Handle *tth_, const char *test_plugin_, const char *test_name_, unsigned int num_peers, char *cfg_files[])
Main function of a testcase.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * next
Kept in a DLL.
A HELLO message is used to exchange information about transports with other peers.
int global_ret
Result from the main function, set to GNUNET_OK on success.
Entry in linked list for all offer-HELLO requests.
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Transport testing handle this peer belongs to.
void GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
Clean up the transport testing.
char * GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *executable, const char *testname)
Extracts the plugin anme from an absolute file name and the test name.
struct GNUNET_CONFIGURATION_Handle * cfg
Peer&#39;s configuration.
struct GNUNET_TRANSPORT_TESTING_PeerContext * GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth, const char *cfgname, int peer_id, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, void *cb_cls, GNUNET_SCHEDULER_TaskCallback start_cb, void *start_cb_cls)
Start a peer with the given configuration.
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:170
struct GNUNET_PeerIdentity id
Peer identity.
struct GNUNET_TRANSPORT_OfferHelloHandle * oh
Handle by which we inform the peer about the HELLO of the other peer.
void(* GNUNET_TRANSPORT_TESTING_NotifyDisconnect)(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other)
Function called to notify transport users that another peer disconnected from us. ...
const char * test_name
Name of the testcase.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
void GNUNET_TRANSPORT_TESTING_log_connect(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other)
Log a connect event.
unsigned int num_peers
Number of peers involved in the test.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Main testing handle.
Context for a single peer.
GNUNET_TRANSPORT_NotifyDisconnect nd
Notify disconnect callback.
GNUNET_NETWORK_STRUCT_END typedef void(* GNUNET_TRANSPORT_TESTING_ReceiveCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
Function called by the transport for each received message.
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
char ** cfg_files
Configuration files we have, array with num_peers entries.
void *(* GNUNET_TRANSPORT_NotifyConnect)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Function called to notify transport users that another peer connected to us.
struct GNUNET_ATS_ConnectivitySuggestHandle * ats_sh
Handle by which we ask ATS to faciliate the connection.
struct GNUNET_MQ_MessageHandler * handlers
Receive callback.
unsigned int no
An unique number to identify the peer.
struct GNUNET_TRANSPORT_TESTING_PeerContext * next
Next element in the DLL.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_head
head DLL of connect contexts
Handle for the transport service (includes all of the state for the transport service).
struct GNUNET_TESTING_System * tl_system
Testing library system handle.
void(* GNUNET_TRANSPORT_TESTING_ConnectContinuation)(void *cls, unsigned int num_peers, struct GNUNET_TRANSPORT_TESTING_PeerContext *p[])
Function called once the peers have been launched and connected by GNUNET_TRANSPORT_TESTING_connect_c...
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
int GNUNET_TRANSPORT_TESTING_connect_check(void *cls, struct GNUNET_TRANSPORT_TESTING_Handle *tth_, const char *test_plugin_, const char *test_name_, unsigned int num_peers, char *cfg_files[])
Common implementation of the GNUNET_TRANSPORT_TESTING_CheckCallback.
GNUNET_SCHEDULER_TaskCallback start_cb
Startup completed callback.
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration object for the testcase.
struct GNUNET_OS_Process * arm_proc
Handle for the peer&#39;s ARM process.
void(* GNUNET_TRANSPORT_NotifyDisconnect)(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
Function called to notify transport users that another peer disconnected from us. ...
struct GNUNET_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init(void)
Initialize the transport testing.
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
int GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, uint16_t mtype, uint16_t msize, uint32_t num, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Send a test message of type mtype and size msize from peer sender to peer receiver.
void * cls
Closure for rec, nc and nd.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_tail
DLL of active connect requests.
void GNUNET_TRANSPORT_TESTING_large_send(void *cls)
Task that sends a large test message from the first peer to the second peer.
unsigned int num_messages
Number of messages to be transmitted in a loop.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, GNUNET_SCHEDULER_TaskCallback cb, void *cls)
Connect the given peers and call the callback when both peers report the inbound connection.
const char * config_file
Which configuration file should we pass to the GNUNET_PROGRAM_run() of the testcase?
void * connect_continuation_cls
Closure for connect_continuation.
char * GNUNET_TRANSPORT_TESTING_get_test_name(const char *file)
Extracts the test filename from an absolute file name and removes the extension.
static char * filename
int p1_c
Set if peer1 says the connection is up to peer2.
Handle for ATS address suggestion requests.
void(* GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Function called on matching connect requests.
void GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *pc)
Shutdown the given peer.
struct GNUNET_TRANSPORT_ManipulationHandle * tmh
Peer&#39;s transport service manipulation handle.
const char * test_plugin
Name of the plugin.
void * pre_connect_task_cls
Closure for shutdown_task.
struct GNUNET_TRANSPORT_CoreHandle * th
Peer&#39;s transport service handle.
char * GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file)
Extracts the filename from an absolute file name and removes the extenstion.
Message handler for a specific message type.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_head
head DLL of peers
struct GNUNET_TRANSPORT_TESTING_InternalPeerContext * ip
Array with num_peers entries.
struct GNUNET_ATS_ConnectivityHandle * ats
Peer&#39;s ATS handle.
struct GNUNET_TESTING_Peer * peer
Peer&#39;s testing handle.
void(* GNUNET_TRANSPORT_TESTING_NotifyConnect)(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other)
Function called to notify transport users that another peer connected to us.
void GNUNET_TRANSPORT_TESTING_log_disconnect(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other)
Log a disconnect event.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p2
Peer we want to connect.
int bi_directional
Should we try to create connections in both directions?
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:97
GNUNET_SCHEDULER_TaskCallback cont
Function to call after all transmissions, can be NULL.
GNUNET_SCHEDULER_TaskCallback cb
Function to call upon completion.
static unsigned int num_peers
GNUNET_TRANSPORT_NotifyConnect nc
Notify connect callback.
Handle to a message queue.
Definition: mq.c:85
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
The identity of the host (wraps the signing key of the peer).
void GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
Task that sends a minimalistic test message from the first peer to the second peer.
struct GNUNET_HELLO_Message * hello
Peers HELLO Message.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * prev
Kept in a DLL.
#define GNUNET_PACKED
gcc-ism to get packed structs.
struct GNUNET_TRANSPORT_TESTING_PeerContext * prev
Previous element in the DLL.
configuration data
Definition: configuration.c:85
int GNUNET_TRANSPORT_TESTING_main_(const char *argv0, const char *filename, unsigned int num_peers, GNUNET_TRANSPORT_TESTING_CheckCallback check, void *check_cls)
Setup testcase.
Entry in list of pending tasks.
Definition: scheduler.c:134
struct GNUNET_TRANSPORT_TESTING_PeerContext * p1
Peer we want to connect.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Context for the transmission.
char * GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count)
This function takes the filename (e.g.
int GNUNET_TRANSPORT_TESTING_restart_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p, GNUNET_SCHEDULER_TaskCallback restart_cb, void *restart_cb_cls)
Stops and restarts the given peer, sleeping (!) for 5s in between.
GNUNET_SCHEDULER_TaskCallback shutdown_task
Custom task to run on shutdown.
GNUNET_SCHEDULER_TaskCallback pre_connect_task
Custom task to run after peers were started but before we try to connect them.
Functions to call with this peer&#39;s HELLO.
Header for all communications.
Type of the closure argument to pass to GNUNET_TRANSPORT_TESTING_simple_send() and GNUNET_TRANSPORT_T...
GNUNET_TRANSPORT_TESTING_NotifyDisconnect nd
Notify disconnect argument to give for peers we start.
void * cb_cls
Closure for the nc and nd callbacks.
uint32_t send_num_gen
Generator for the num field in test messages.
struct GNUNET_SCHEDULER_Task * tct
Task by which we accomplish the connection.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
int p2_c
Set if peer2 says the connection is up to peer1.
void * shutdown_task_cls
Closure for shutdown_task.
struct GNUNET_TRANSPORT_HelloGetHandle * ghh
Peer&#39;s transport get hello handle to retrieve peer&#39;s HELLO message.
Handle for the transport service (includes all of the state for the transport service).
Handle to the ATS subsystem for connectivity management.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_head
DLL of active connect requests.
void * start_cb_cls
Closure for start_cb.
GNUNET_TRANSPORT_TESTING_ReceiveCallback rec
Receiver argument to give for peers we start.
unsigned int started
Number of peers that have been started.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_tail
head DLL of connect contexts
GNUNET_TRANSPORT_TESTING_NotifyConnect nc
Notify connect argument to give for peers we start.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_tail
tail DLL of peers