testing lib for transport service More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_hello_lib.h"
#include "gnunet_transport_service.h"
#include "gnunet_transport_hello_service.h"
#include "gnunet_transport_manipulation_service.h"
#include "gnunet_testing_lib.h"
Go to the source code of this file.
Data Structures | |
struct | GNUNET_TRANSPORT_TESTING_PeerContext |
Context for a single peer. More... | |
struct | GNUNET_TRANSPORT_TESTING_ConnectRequest |
Handle for a request to connect two peers. More... | |
struct | GNUNET_TRANSPORT_TESTING_Handle |
Handle for a test run. More... | |
struct | GNUNET_TRANSPORT_TESTING_TestMessage |
struct | GNUNET_TRANSPORT_TESTING_ConnectCheckContext |
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check. More... | |
struct | GNUNET_TRANSPORT_TESTING_SendClosure |
Type of the closure argument to pass to GNUNET_TRANSPORT_TESTING_simple_send() and GNUNET_TRANSPORT_TESTING_large_send(). More... | |
Macros | |
#define | GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) |
Setup testcase. More... | |
#define | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345 |
Message type used by GNUNET_TRANSPORT_TESTING_simple_send(). More... | |
#define | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346 |
Alternative message type for tests. More... | |
#define | GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600 |
Size of a message sent with GNUNET_TRANSPORT_TESTING_large_send(). More... | |
Typedefs | |
typedef void(* | GNUNET_TRANSPORT_TESTING_ConnectContextCallback) (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc) |
Function called on matching connect requests. More... | |
typedef 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_check(). More... | |
typedef 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. More... | |
typedef 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. More... | |
typedef 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. More... | |
Functions | |
struct GNUNET_TRANSPORT_TESTING_Handle * | GNUNET_TRANSPORT_TESTING_init (void) |
Initialize the transport testing. More... | |
void | GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth) |
Clean up the transport testing. More... | |
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. More... | |
void | GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *pc) |
Shutdown the given peer. More... | |
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. More... | |
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. More... | |
void | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc) |
Cancel the request to connect two peers. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | GNUNET_TRANSPORT_TESTING_simple_send (void *cls) |
Task that sends a minimalistic test message from the first peer to the second peer. More... | |
void | GNUNET_TRANSPORT_TESTING_large_send (void *cls) |
Task that sends a large test message from the first peer to the second peer. More... | |
void | GNUNET_TRANSPORT_TESTING_log_connect (void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other) |
Log a connect event. More... | |
void | GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other) |
Log a disconnect event. More... | |
char * | GNUNET_TRANSPORT_TESTING_get_test_name (const char *file) |
Extracts the test filename from an absolute file name and removes the extension. More... | |
char * | GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count) |
This function takes the filename (e.g. More... | |
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. More... | |
char * | GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file) |
Extracts the filename from an absolute file name and removes the extension. More... | |
Variables | |
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. More... | |
testing lib for transport service
Definition in file transport-testing.h.
#define GNUNET_TRANSPORT_TESTING_main | ( | num_peers, | |
check, | |||
check_cls | |||
) |
Setup testcase.
Calls check with the data the test needs.
num_peers | number of peers to start |
check | main function to run |
check_cls | closure for check |
Definition at line 720 of file transport-testing.h.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345 |
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().
Definition at line 760 of file transport-testing.h.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346 |
Alternative message type for tests.
Definition at line 765 of file transport-testing.h.
#define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600 |
Size of a message sent with GNUNET_TRANSPORT_TESTING_large_send().
Big enough to usually force defragmentation.
Definition at line 821 of file transport-testing.h.
typedef void(* GNUNET_TRANSPORT_TESTING_ConnectContextCallback) (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc) |
Function called on matching connect requests.
cls | closure |
cc | request matching the query |
Definition at line 366 of file transport-testing.h.
typedef 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_check().
cls | closure |
num_peers | size of the p array |
p | the peers that were launched |
Definition at line 398 of file transport-testing.h.
typedef 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.
cls | closure |
me | peer experiencing the event |
other | peer that connected to me |
Definition at line 454 of file transport-testing.h.
typedef 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.
cls | closure |
me | peer experiencing the event |
other | peer that disconnected from me |
Definition at line 468 of file transport-testing.h.
typedef 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.
Called with the initial setup data for the test as derived from the source name and the binary name.
cls | closure |
tth_ | initialized testing handle |
test_plugin_ | name of the plugin |
test_name_ | name of the test |
num_peers | number of entries in the cfg_file array |
cfg_files | array of names of configuration files for the peers |
Definition at line 685 of file transport-testing.h.
struct GNUNET_TRANSPORT_TESTING_Handle* GNUNET_TRANSPORT_TESTING_init | ( | void | ) |
Initialize the transport testing.
Definition at line 912 of file transport-testing.c.
void GNUNET_TRANSPORT_TESTING_done | ( | struct GNUNET_TRANSPORT_TESTING_Handle * | tth | ) |
Clean up the transport testing.
tth | transport testing handle |
Definition at line 872 of file transport-testing.c.
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.
tth | the testing handle |
cfgname | configuration file |
peer_id | the peer_id |
handlers | functions for receiving messages |
nc | connect callback |
nd | disconnect callback |
cb_cls | closure for nc and nd callback |
start_cb | start callback |
start_cb_cls | closure for start_cb |
tth | the testing handle |
cfgname | configuration file |
peer_id | a unique number to identify the peer |
handlers | functions for receiving messages |
nc | connect callback |
nd | disconnect callback |
cb_cls | closure for callback |
start_cb | start callback |
start_cb_cls | closure for callback |
Definition at line 382 of file transport-testing.c.
void GNUNET_TRANSPORT_TESTING_stop_peer | ( | struct GNUNET_TRANSPORT_TESTING_PeerContext * | p | ) |
Shutdown the given peer.
p | the peer |
Definition at line 638 of file transport-testing.c.
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.
p | the peer |
restart_cb | restart callback |
restart_cb_cls | callback closure |
p | the peer |
restart_cb | callback to call when restarted |
restart_cb_cls | callback closure |
Definition at line 544 of file transport-testing.c.
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.
Remarks: start_peer's notify_connect callback can be called before.
p1 | peer 1 |
p2 | peer 2 |
cb | the callback to call when both peers notified that they are connected |
cls | callback cls |
Connect the given peers and call the callback when both peers report the inbound connection.
Remarks: start_peer's notify_connect callback can be called before.
tth | transport testing handle |
p1 | peer 1 |
p2 | peer 2 |
cb | the callback to call when both peers notified that they are connected |
cls | callback cls |
Definition at line 777 of file transport-testing.c.
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel | ( | struct GNUNET_TRANSPORT_TESTING_ConnectRequest * | cc | ) |
Cancel the request to connect two peers.
You MUST cancel the request if you stop the peers before the peers connected successfully.
cc | a connect request handle |
Cancel the request to connect two peers.
tth | transport testing handle |
cc | a connect request handle |
Definition at line 836 of file transport-testing.c.
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.
p1 | first peer |
p2 | second peer |
cb | function to call |
cb_cls | closure for cb |
Definition at line 57 of file transport-testing.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.
ccc | context to search |
peer | peer to look for |
Definition at line 209 of file transport-testing-main.c.
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.
Starts and connects the two peers, then invokes the connect_continuation
from cls. Sets up a timeout to abort the test, and a shutdown handler to clean up properly on exit.
cls | closure of type struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext |
tth_ | initialized testing handle |
test_plugin_ | name of the plugin |
test_name_ | name of the test |
num_peers | number of entries in the cfg_file array |
cfg_files | array of names of configuration files for the peers |
Definition at line 508 of file transport-testing-main.c.
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.
Calls check with the data the test needs.
argv0 | binary name (argv[0]) |
filename | source file name (FILE) |
num_peers | number of peers to start |
check | main function to run |
check_cls | closure for check |
Definition at line 566 of file transport-testing-main.c.
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.
The peers should be connected when this function is called.
sender | the sending peer |
receiver | the receiving peer |
mtype | message type to use |
msize | size of the message, at least sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) |
num | unique message number |
cont | continuation to call after transmission |
cont_cls | closure for cont |
Definition at line 67 of file transport-testing-send.c.
void GNUNET_TRANSPORT_TESTING_simple_send | ( | void * | cls | ) |
Task that sends a minimalistic test message from the first peer to the second peer.
cls | the struct GNUNET_TRANSPORT_TESTING_SendClosure which should contain at least two peers, the first two of which should be currently connected |
cls | the struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext which should contain at least two peers, the first two of which should be currently connected |
Definition at line 178 of file transport-testing-send.c.
void GNUNET_TRANSPORT_TESTING_large_send | ( | void * | cls | ) |
Task that sends a large test message from the first peer to the second peer.
cls | the struct GNUNET_TRANSPORT_TESTING_SendClosure which should contain at least two peers, the first two of which should be currently connected |
cls | the struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext which should contain at least two peers, the first two of which should be currently connected |
Definition at line 214 of file transport-testing-send.c.
void GNUNET_TRANSPORT_TESTING_log_connect | ( | void * | cls, |
struct GNUNET_TRANSPORT_TESTING_PeerContext * | me, | ||
const struct GNUNET_PeerIdentity * | other | ||
) |
Log a connect event.
cls | NULL |
me | peer that had the event |
other | peer that connected. |
Definition at line 37 of file transport-testing-loggers.c.
void GNUNET_TRANSPORT_TESTING_log_disconnect | ( | void * | cls, |
struct GNUNET_TRANSPORT_TESTING_PeerContext * | me, | ||
const struct GNUNET_PeerIdentity * | other | ||
) |
Log a disconnect event.
cls | NULL |
me | peer that had the event |
other | peer that disconnected. |
Definition at line 62 of file transport-testing-loggers.c.
char* GNUNET_TRANSPORT_TESTING_get_test_name | ( | const char * | file | ) |
Extracts the test filename from an absolute file name and removes the extension.
file | absolute file name |
file | absolute file name |
Definition at line 66 of file transport-testing-filenames.c.
char* GNUNET_TRANSPORT_TESTING_get_config_name | ( | const char * | file, |
int | count | ||
) |
This function takes the filename (e.g.
argv[0), removes a "lt-"-prefix and if existing ".exe"-prefix and adds the peer-number
file | filename of the test, e.g. argv[0] |
count | peer number |
argv[0), removes a "lt-"-prefix and if existing ".exe"-prefix and adds the peer-number
file | filename of the test, e.g. argv[0] |
count | peer number |
Definition at line 146 of file transport-testing-filenames.c.
char* GNUNET_TRANSPORT_TESTING_get_test_plugin_name | ( | const char * | file, |
const char * | test | ||
) |
Extracts the plugin anme from an absolute file name and the test name.
file | absolute file name |
test | test name |
Extracts the plugin anme from an absolute file name and the test name.
file | absolute file name |
test | test name |
Definition at line 107 of file transport-testing-filenames.c.
char* GNUNET_TRANSPORT_TESTING_get_test_source_name | ( | const char * | file | ) |
Extracts the filename from an absolute file name and removes the extension.
file | absolute file name |
file | absolute file name |
Definition at line 94 of file transport-testing-filenames.c.
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) | ( | 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.
cls | closure |
receiver | receiver of the message |
sender | sender of the message |
message | the message |
Definition at line 439 of file transport-testing.h.