GNUnet  0.11.x
transport-testing2.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"
36 #include "gnunet_testing_lib.h"
37 
38 
39 /* ************* Basic functions for starting/stopping/connecting *********** */
40 
45 
50 
51 
56 {
61 
66 
71 
76 
81 
86 
91 
96 
101 
106 
110  char *hello;
111 
115  size_t hello_size;
116 
120  struct GNUNET_TESTING_Peer *peer;
121 
125  struct GNUNET_PeerIdentity id;
126 
130  struct GNUNET_OS_Process *arm_proc;
131 
136 
141 
146 
151 
155  void *cb_cls;
156 
160  void *start_cb_cls;
161 
165  unsigned int no;
166 };
167 
168 
173 {
178 
183 
188 
193 
197  struct GNUNET_SCHEDULER_Task *tct;
198 
203 
208 
212  void *cb_cls;
213 
217  struct GNUNET_MQ_Handle *mq;
218 
222  int p1_c;
223 
227  int p2_c;
228 
232  int connected;
233 };
234 
235 
240 {
244  struct GNUNET_TESTING_System *tl_system;
245 
250 
255 
260 
265 };
266 
267 
275 
276 
282 void
284 
285 
303  const char *cfgname,
304  int peer_id,
305  const struct GNUNET_MQ_MessageHandler *handlers,
308  void *cb_cls,
310  void *start_cb_cls);
311 
312 
318 void
321 
322 
331 int
335  void *restart_cb_cls);
336 
337 
355  void *cls);
356 
357 
365 void
368 
369 
377  void *cls,
379 
380 
389 void
394  void *cb_cls);
395 
396 
397 /* ********************** high-level process functions *************** */
398 
399 
409  void *cls,
410  unsigned int num_peers,
412 
413 
418 
423 
424 
427 {
431  struct GNUNET_MessageHeader header;
432 
436  uint32_t num GNUNET_PACKED;
437 };
439 
440 
450  void *cls,
452  const struct GNUNET_PeerIdentity *sender,
453  const struct GNUNET_TRANSPORT_TESTING_TestMessage *message);
454 
455 
465  void *cls,
467  const struct GNUNET_PeerIdentity *other);
468 
469 
479  void *cls,
481  const struct GNUNET_PeerIdentity *other);
482 
483 
489 {
493  GNUNET_SCHEDULER_TaskCallback connect_continuation;
494 
498  void *connect_continuation_cls;
499 
504  const char *config_file;
505 
510 
515 
520 
524  void *cls;
525 
530 
534  void *shutdown_task_cls;
535 
542  GNUNET_SCHEDULER_TaskCallback pre_connect_task;
543 
547  void *pre_connect_task_cls;
548 
552  struct GNUNET_TIME_Relative timeout;
553 
557  int bi_directional;
558 
559  /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */
560 
564  unsigned int num_peers;
565 
569  char **cfg_files;
570 
575 
579  const char *test_plugin;
580 
584  const char *test_name;
585 
589  const struct GNUNET_CONFIGURATION_Handle *cfg;
590 
595 
600  int global_ret;
601 
608  uint32_t send_num_gen;
609 
610  /* ******* internal state, clients should not mess with this **** */
611 
616 
621 
625  unsigned int started;
626 
631 
636 
641 };
642 
643 
654  const struct GNUNET_PeerIdentity *peer);
655 
656 
673 int
675  void *cls,
676  struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
677  const char *test_plugin_,
678  const char *test_name_,
679  unsigned int num_peers,
680  char *cfg_files[]);
681 
682 
696  void *cls,
697  struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
698  const char *test_plugin_,
699  const char *test_name_,
700  unsigned int num_peers,
701  char *cfg_files[]);
702 
703 
714 int
715 GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
716  const char *filename,
717  unsigned int num_peers,
719  void *check_cls);
720 
721 
730 #define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \
731  GNUNET_TRANSPORT_TESTING_main_ (argv[0], \
732  __FILE__, \
733  num_peers, \
734  check, \
735  check_cls)
736 
737 /* ***************** Convenience functions for sending ********* */
738 
756 int
759  struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
760  uint16_t mtype,
761  uint16_t msize,
762  uint32_t num,
764  void *cont_cls);
765 
766 
770 #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345
771 
775 #define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346
776 
777 
784 {
789 
795  size_t (*get_size_cb) (unsigned int n);
796 
801  unsigned int num_messages;
802 
807 
811  void *cont_cls;
812 };
813 
814 
823 void
825 
831 #define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600
832 
841 void
843 
844 
845 /* ********************** log-only convenience functions ************* */
846 
847 
855 void
857  void *cls,
859  const struct GNUNET_PeerIdentity *other);
860 
861 
869 void
871  void *cls,
873  const struct GNUNET_PeerIdentity *other);
874 
875 
876 /* ********************** low-level filename functions *************** */
877 
878 
886 char *
887 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file);
888 
889 
898 char *
899 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count);
900 
901 
908 char *
909 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
910  const char *testname);
911 
912 
920 char *
922 
923 #endif
924 /* 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.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
char * GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file)
Extracts the filename from an absolute file name and removes the extenstion.
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Cancel the request to connect two peers.
Handle for a request to connect two peers.
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Application handle.
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.
void * start_cb_cls
Closure for start_cb.
struct GNUNET_ATS_ConnectivityHandle * ats
Peer&#39;s ATS handle.
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.
struct GNUNET_PEERSTORE_Handle * ph
Peer&#39;s PEERSTORE Handle.
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.
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:164
struct GNUNET_PeerIdentity id
Peer identity.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
struct GNUNET_MQ_MessageHandler * handlers
Receive callback.
void GNUNET_TRANSPORT_TESTING_large_send(void *cls)
Task that sends a large test message from the first peer to the second peer.
Bandwidth allocation API for applications to interact with.
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:84
static void connect_task(void *cls)
Connect to the VPN service and start again to transmit our requests.
Definition: vpn_api.c:317
Context for a single peer.
GNUNET_TRANSPORT_NotifyDisconnect nd
Notify disconnect callback.
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
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_SCHEDULER_Task * shutdown_task
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.
char * GNUNET_TRANSPORT_TESTING_get_test_name(const char *file)
Extracts the test filename from an absolute file name and removes the extension.
void * cb_cls
Closure for the nc and nd callbacks.
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.
unsigned int no
An unique number to identify the peer.
Handle for the transport service (includes all of the state for the transport service).
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.
GNUNET_SCHEDULER_TaskCallback start_cb
Startup completed callback.
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_CoreHandle * th
Peer&#39;s transport service handle.
struct GNUNET_PEERSTORE_IterateContext * pic
Peer&#39;s transport get hello handle to retrieve peer&#39;s HELLO message.
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. ...
void * cls
Closure for rec, nc and nd.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
void GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
Clean up the transport testing.
void GNUNET_TRANSPORT_TESTING_log_disconnect(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other)
Log a disconnect event.
static char * filename
struct GNUNET_OS_Process * arm_proc
Handle for the peer&#39;s ARM process.
Handle for ATS address suggestion requests.
static struct GNUNET_ATS_ConnectivitySuggestHandle * ats_sh
Handle for address suggestion request.
Definition: gnunet-ats.c:126
struct GNUNET_TRANSPORT_TESTING_PeerContext * next
Next element in the DLL.
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.
struct GNUNET_CONFIGURATION_Handle * cfg
Peer&#39;s configuration.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Transport testing handle this peer belongs to.
Message handler for a specific message type.
struct GNUNET_TRANSPORT_TESTING_PeerContext * prev
Previous element in the DLL.
void GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
Task that sends a minimalistic test message from the first peer to the second peer.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:91
char * GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count)
This function takes the filename (e.g.
static struct GNUNET_SCHEDULER_Task * timeout_task
Task to be run on timeout.
Definition: gnunet-arm.c:124
struct GNUNET_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init(void)
Initialize the transport testing.
void receiver(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback to read from the SOCKS5 proxy.
Definition: socks.c:329
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;.
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 struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TESTING_Peer * peer
Peer&#39;s testing handle.
#define GNUNET_PACKED
gcc-ism to get packed structs.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p2
Peer we want to connect.
configuration data
Definition: configuration.c:84
void GNUNET_TRANSPORT_TESTING_log_connect(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other)
Log a connect event.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
Entry in list of pending tasks.
Definition: scheduler.c:134
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.
struct GNUNET_TRANSPORT_ManipulationHandle * tmh
Peer&#39;s transport service manipulation handle.
Header for all communications.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p1
Peer we want to connect.
Type of the closure argument to pass to GNUNET_TRANSPORT_TESTING_simple_send() and GNUNET_TRANSPORT_T...
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.
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. ...
Handle for the transport service (includes all of the state for the transport service).
Handle to the ATS subsystem for connectivity management.
void GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *pc)
Shutdown the given peer.
Handle to the TRANSPORT subsystem for application management.
static int global_ret
Return value from main.
Context for a iterate request.
void(* GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Function called on matching connect requests.
Time for relative time used by GNUnet, in microseconds.
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.