GNUnet 0.21.1
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"
34#include "gnunet_testing_lib.h"
35
36
37/* ************* Basic functions for starting/stopping/connecting *********** */
38
43
48
49
54{
59
64
69
74
79
84
89
94
98 char *hello;
99
104
109
114
119
124
129
134
139
144
148 void *cb_cls;
149
154
158 unsigned int no;
159};
160
161
166{
171
176
181
186
191
196
201
205 void *cb_cls;
206
211
215 int p1_c;
216
220 int p2_c;
221
226};
227
228
233{
238
243
248
253
258};
259
260
268
269
275void
277
278
296 const char *cfgname,
297 int peer_id,
301 void *cb_cls,
303 void *start_cb_cls);
304
305
311void
314
315
324int
328 void *restart_cb_cls);
329
330
348 void *cls);
349
350
358void
361
362
370 void *cls,
372
373
382void
387 void *cb_cls);
388
389
390/* ********************** high-level process functions *************** */
391
392
402 void *cls,
403 unsigned int num_peers,
405
406
411
416
417
420{
425
430};
431
433{
438
443
448};
449
451
452
462 void *cls,
464 const struct GNUNET_PeerIdentity *sender,
465 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message);
466
467
477 void *cls,
479 const struct GNUNET_PeerIdentity *other);
480
481
491 void *cls,
493 const struct GNUNET_PeerIdentity *other);
494
495
501{
506
511
516 const char *config_file;
517
522
527
532
536 void *cls;
537
542
547
555
560
565
570
571 /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */
572
576 unsigned int num_peers;
577
581 char **cfg_files;
582
587
591 const char *test_plugin;
592
596 const char *test_name;
597
602
607
613
620 uint32_t send_num_gen;
621
622 /* ******* internal state, clients should not mess with this **** */
623
628
633
637 unsigned int started;
638
643
648
653};
654
655
666 const struct GNUNET_PeerIdentity *peer);
667
668
685int
687 void *cls,
689 const char *test_plugin_,
690 const char *test_name_,
691 unsigned int num_peers,
692 char *cfg_files[]);
693
694
708 void *cls,
710 const char *test_plugin_,
711 const char *test_name_,
712 unsigned int num_peers,
713 char *cfg_files[]);
714
715
726int
727GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
728 const char *filename,
729 unsigned int num_peers,
731 void *check_cls);
732
733
742#define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \
743 GNUNET_TRANSPORT_TESTING_main_ (argv[0], \
744 __FILE__, \
745 num_peers, \
746 check, \
747 check_cls)
748
749/* ***************** Convenience functions for sending ********* */
750
768int
772 uint16_t mtype,
773 uint16_t msize,
774 uint32_t num,
776 void *cont_cls);
777
778
782#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345
783
787#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346
788
792#define GNUNET_TRANSPORT_TESTING_SIMPLE_PERFORMANCE_MTYPE 12347
793
800{
805
811 size_t (*get_size_cb) (unsigned int n);
812
817 unsigned int num_messages;
818
823
827 void *cont_cls;
828};
829
830
839void
841
847#define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600
848
857void
859
860
861/* ********************** log-only convenience functions ************* */
862
863
871void
873 void *cls,
875 const struct GNUNET_PeerIdentity *other);
876
877
885void
887 void *cls,
889 const struct GNUNET_PeerIdentity *other);
890
891
892/* ********************** low-level filename functions *************** */
893
894
902char *
904
905
914char *
915GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count);
916
917
924char *
926 const char *testname);
927
928
936char *
938
939#endif
940/* end of transport_testing.h */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
static char * filename
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
static struct GNUNET_NotificationContext * nc
Notification context for broadcasting to monitors.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
static unsigned int num_peers
Number of peers.
API to the peerstore service.
Convenience API for writing testcases for GNUnet.
Bandwidth allocation API for applications to interact with.
API of the transport service towards the CORE service (TNG version)
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 *(* 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.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
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:330
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:46
Context for a iterate request.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:136
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:195
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:122
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for relative time used by GNUnet, in microseconds.
Handle to the TRANSPORT subsystem for application management.
Handle for TRANSPORT address suggestion requests.
Handle for the transport service (includes all of the state for the transport service).
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
GNUNET_TRANSPORT_TESTING_NotifyConnect nc
Notify connect argument to give for peers we start.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration object for the testcase.
unsigned int num_peers
Number of peers involved in the test.
void * shutdown_task_cls
Closure for shutdown_task.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
int global_ret
Result from the main function, set to GNUNET_OK on success.
GNUNET_SCHEDULER_TaskCallback shutdown_task
Custom task to run on shutdown.
void * pre_connect_task_cls
Closure for shutdown_task.
GNUNET_TRANSPORT_TESTING_ReceiveCallback rec
Receiver argument to give for peers we start.
GNUNET_SCHEDULER_TaskCallback connect_continuation
How should we continue after the connect?
const char * config_file
Which configuration file should we pass to the GNUNET_PROGRAM_run() of the testcase?
struct GNUNET_TRANSPORT_TESTING_InternalPeerContext * ip
Array with num_peers entries.
GNUNET_TRANSPORT_TESTING_NotifyDisconnect nd
Notify disconnect argument to give for peers we start.
char ** cfg_files
Configuration files we have, array with num_peers entries.
const char * test_name
Name of the testcase.
GNUNET_SCHEDULER_TaskCallback pre_connect_task
Custom task to run after peers were started but before we try to connect them.
void * connect_continuation_cls
Closure for connect_continuation.
void * cls
Closure for rec, nc and nd.
struct GNUNET_SCHEDULER_Task * connect_task
Task run to connect peers.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_head
DLL of active connect requests.
int bi_directional
Should we try to create connections in both directions?
unsigned int started
Number of peers that have been started.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Main testing handle.
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
struct GNUNET_TIME_Relative timeout
When should the testcase time out?
uint32_t send_num_gen
Generator for the num field in test messages.
const char * test_plugin
Name of the plugin.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_tail
DLL of active connect requests.
Handle for a request to connect two peers.
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.
int p2_c
Set if peer2 says the connection is up to peer1.
struct GNUNET_TRANSPORT_ApplicationSuggestHandle * ah_sh
Handle by which we ask TNG to facilitate the connection.
GNUNET_SCHEDULER_TaskCallback cb
Function to call upon completion.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p2
Peer we want to connect.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p1
Peer we want to connect.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * next
Kept in a DLL.
struct GNUNET_SCHEDULER_Task * tct
Task by which we accomplish the connection.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * prev
Kept in a DLL.
int p1_c
Set if peer1 says the connection is up to peer2.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_head
head DLL of peers
struct GNUNET_TESTING_System * tl_system
Testing library system handle.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_tail
tail DLL of peers
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_head
head DLL of connect contexts
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_tail
head DLL of connect contexts
struct GNUNET_CONFIGURATION_Handle * cfg
Peer's configuration.
void * cb_cls
Closure for the nc and nd callbacks.
struct GNUNET_PEERSTORE_Handle * ph
Peer's PEERSTORE Handle.
struct GNUNET_SCHEDULER_Task * rh_task
Hello get task.
struct GNUNET_MQ_MessageHandler * handlers
Receive callback.
struct GNUNET_PEERSTORE_IterateContext * pic
Peer's transport get hello handle to retrieve peer's HELLO message.
GNUNET_SCHEDULER_TaskCallback start_cb
Startup completed callback.
struct GNUNET_TESTING_Peer * peer
Peer's testing handle.
unsigned int no
An unique number to identify the peer.
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Application handle.
GNUNET_TRANSPORT_NotifyConnect nc
Notify connect callback.
struct GNUNET_PeerIdentity id
Peer identity.
struct GNUNET_TRANSPORT_CoreHandle * th
Peer's transport service handle.
struct GNUNET_TRANSPORT_TESTING_PeerContext * prev
Previous element in the DLL.
struct GNUNET_TRANSPORT_TESTING_PeerContext * next
Next element in the DLL.
struct GNUNET_OS_Process * arm_proc
Handle for the peer's ARM process.
void * start_cb_cls
Closure for start_cb.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Transport testing handle this peer belongs to.
GNUNET_TRANSPORT_NotifyDisconnect nd
Notify disconnect callback.
uint32_t num
Monotonically increasing counter throughout the test.
struct GNUNET_TIME_AbsoluteNBO time_send
Time this message was send via transport api.
struct GNUNET_MessageHeader header
Type is (usually) GNUNET_TRANSPORT_TESTING_SIMPLE_PERFORMANCE_MTYPE.
Type of the closure argument to pass to GNUNET_TRANSPORT_TESTING_simple_send() and GNUNET_TRANSPORT_T...
unsigned int num_messages
Number of messages to be transmitted in a loop.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Context for the transmission.
GNUNET_SCHEDULER_TaskCallback cont
Function to call after all transmissions, can be NULL.
size_t(* get_size_cb)(unsigned int n)
Function that returns the desired message size.
uint32_t num
Monotonically increasing counter throughout the test.
struct GNUNET_MessageHeader header
Type is (usually) GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
static void start_cb(void *cls)
Function called once we have successfully launched a peer.
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_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.
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.
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.
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...
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.
void GNUNET_TRANSPORT_TESTING_large_send(void *cls)
Task that sends a large test message from the first peer to the second peer.
void GNUNET_TRANSPORT_TESTING_log_disconnect(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other)
Log a disconnect event.
char * GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file)
Extracts the filename from an absolute file name and removes the extension.
void GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
Task that sends a minimalistic test message from the first peer to the second peer.
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_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init(void)
Initialize the transport testing.
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.
void GNUNET_TRANSPORT_TESTING_log_connect(void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other)
Log a connect event.
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.
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 GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *pc)
Shutdown the given peer.
char * GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count)
This function takes the filename (e.g.
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.
void(* GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Function called on matching connect requests.
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.
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.
char * GNUNET_TRANSPORT_TESTING_get_test_name(const char *file)
Extracts the test filename from an absolute file name and removes the extension.
void GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
Clean up the transport testing.
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Cancel the request to connect two peers.