GNUnet 0.21.1
transport-testing2.h File Reference
Include dependency graph for transport-testing2.h:
This graph shows which files directly or indirectly include this file:

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_PerformanceTestMessage
 
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_SIMPLE_PERFORMANCE_MTYPE   12347
 Message type used by #(). 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_HandleGNUNET_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_PeerContextGNUNET_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_ConnectRequestGNUNET_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_PeerContextGNUNET_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...
 

Macro Definition Documentation

◆ GNUNET_TRANSPORT_TESTING_main

#define GNUNET_TRANSPORT_TESTING_main (   num_peers,
  check,
  check_cls 
)
Value:
__FILE__, \
check, \
check_cls)
static unsigned int num_peers
Number of peers.
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.

Setup testcase.

Calls check with the data the test needs.

Parameters
num_peersnumber of peers to start
checkmain function to run
check_clsclosure for check
Returns
GNUNET_OK on success

Definition at line 742 of file transport-testing2.h.

◆ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE

#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE   12345

Message type used by GNUNET_TRANSPORT_TESTING_simple_send().

Definition at line 782 of file transport-testing2.h.

◆ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2

#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2   12346

Alternative message type for tests.

Definition at line 787 of file transport-testing2.h.

◆ GNUNET_TRANSPORT_TESTING_SIMPLE_PERFORMANCE_MTYPE

#define GNUNET_TRANSPORT_TESTING_SIMPLE_PERFORMANCE_MTYPE   12347

Message type used by #().

Definition at line 792 of file transport-testing2.h.

◆ GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE

#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 847 of file transport-testing2.h.

Typedef Documentation

◆ GNUNET_TRANSPORT_TESTING_ConnectContextCallback

typedef void(* GNUNET_TRANSPORT_TESTING_ConnectContextCallback) (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)

Function called on matching connect requests.

Parameters
clsclosure
ccrequest matching the query

Definition at line 369 of file transport-testing2.h.

◆ GNUNET_TRANSPORT_TESTING_ConnectContinuation

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().

Parameters
clsclosure
num_peerssize of the p array
pthe peers that were launched

Definition at line 401 of file transport-testing2.h.

◆ GNUNET_TRANSPORT_TESTING_NotifyConnect

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.

Parameters
clsclosure
mepeer experiencing the event
otherpeer that connected to me

Definition at line 476 of file transport-testing2.h.

◆ GNUNET_TRANSPORT_TESTING_NotifyDisconnect

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.

Parameters
clsclosure
mepeer experiencing the event
otherpeer that disconnected from me

Definition at line 490 of file transport-testing2.h.

◆ GNUNET_TRANSPORT_TESTING_CheckCallback

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.

Parameters
clsclosure
tth_initialized testing handle
test_plugin_name of the plugin
test_name_name of the test
num_peersnumber of entries in the cfg_file array
cfg_filesarray of names of configuration files for the peers
Returns
GNUNET_SYSERR on error

Definition at line 707 of file transport-testing2.h.

Function Documentation

◆ GNUNET_TRANSPORT_TESTING_init()

struct GNUNET_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init ( void  )

Initialize the transport testing.

Returns
transport testing handle

Definition at line 851 of file transport-testing2.c.

852{
854
856 tth->tl_system = GNUNET_TESTING_system_create ("transport-testing",
857 NULL,
858 NULL,
859 NULL);
860 if (NULL == tth->tl_system)
861 {
863 "Failed to initialize testing library!\n");
864 GNUNET_free (tth);
865 return NULL;
866 }
867 return tth;
868}
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services)
Create a system handle.
Definition: testing.c:477
struct GNUNET_TESTING_System * tl_system
Testing library system handle.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_TESTING_system_create(), and GNUNET_TRANSPORT_TESTING_Handle::tl_system.

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_done()

void GNUNET_TRANSPORT_TESTING_done ( struct GNUNET_TRANSPORT_TESTING_Handle tth)

Clean up the transport testing.

Parameters
tthtransport testing handle

Definition at line 811 of file transport-testing2.c.

812{
817
818 if (NULL == tth)
819 return;
820 cc = tth->cc_head;
821 while (NULL != cc)
822 {
823 ct = cc->next;
825 "Developer forgot to cancel connect request!\n");
827 cc = ct;
828 }
829 p = tth->p_head;
830 while (NULL != p)
831 {
832 t = p->next;
834 "Developer forgot to stop peer!\n");
836 p = t;
837 }
839 GNUNET_YES);
840
842}
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
static struct GNUNET_SCHEDULER_Task * t
Main task.
@ GNUNET_YES
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:557
Handle for a request to connect two peers.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * next
Kept in a DLL.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_head
head DLL of peers
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_head
head DLL of connect contexts
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Transport testing handle this peer belongs to.
void GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
Shutdown the given peer.
#define LOG(kind,...)
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Cancel the request to connect two peers.

References GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_TESTING_system_destroy(), GNUNET_TRANSPORT_TESTING_connect_peers_cancel(), GNUNET_TRANSPORT_TESTING_stop_peer(), GNUNET_YES, LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, p, GNUNET_TRANSPORT_TESTING_Handle::p_head, t, GNUNET_TRANSPORT_TESTING_Handle::tl_system, and GNUNET_TRANSPORT_TESTING_PeerContext::tth.

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_start_peer()

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.

Parameters
tththe testing handle
cfgnameconfiguration file
peer_idan identification number for the peer
handlersfunctions for receiving messages
ncconnect callback
nddisconnect callback
cb_clsclosure for nc and nd callback
start_cbstart callback
start_cb_clsclosure for start_cb
Returns
the peer context

Definition at line 374 of file transport-testing2.c.

385{
386 char *emsg = NULL;
389 unsigned int i;
390
391 if (GNUNET_NO == GNUNET_DISK_file_test (cfgname))
392 {
394 "File not found: `%s'\n",
395 cfgname);
396 return NULL;
397 }
398
400 p->tth = tth;
401 p->nc = nc;
402 p->nd = nd;
403 if (NULL != handlers)
404 {
405 for (i = 0; NULL != handlers[i].cb; i++)
406 ;
407 p->handlers = GNUNET_new_array (i + 1,
409 GNUNET_memcpy (p->handlers,
410 handlers,
411 i * sizeof(struct GNUNET_MQ_MessageHandler));
412 }
413 if (NULL != cb_cls)
414 p->cb_cls = cb_cls;
415 else
416 p->cb_cls = p;
417 p->start_cb = start_cb;
418 if (NULL != start_cb_cls)
419 p->start_cb_cls = start_cb_cls;
420 else
421 p->start_cb_cls = p;
423 tth->p_tail,
424 p);
425
426 /* Create configuration and call testing lib to modify it */
429 GNUNET_CONFIGURATION_load (p->cfg, cfgname));
430 if (GNUNET_SYSERR ==
432 p->cfg))
433 {
435 "Testing library failed to create unique configuration based on `%s'\n",
436 cfgname);
438 GNUNET_free (p);
439 return NULL;
440 }
441
442 p->no = peer_id;
443 /* Configure peer with configuration */
445 p->cfg,
446 p->no,
447 NULL,
448 &emsg);
449 if (NULL == p->peer)
450 {
452 "Testing library failed to create unique configuration based on `%s': `%s'\n",
453 cfgname,
454 emsg);
456 GNUNET_free (emsg);
457 return NULL;
458 }
459
461 {
463 "Testing library failed to create unique configuration based on `%s'\n",
464 cfgname);
466 return NULL;
467 }
468
469 memset (&dummy,
470 '\0',
471 sizeof(dummy));
473 &p->id);
474 if (0 == memcmp (&dummy,
475 &p->id,
476 sizeof(struct GNUNET_PeerIdentity)))
477 {
479 "Testing library failed to obtain peer identity for peer %u\n",
480 p->no);
482 return NULL;
483 }
485 "Peer %u configured with identity `%s'\n",
486 p->no,
487 GNUNET_i2s_full (&p->id));
489 NULL,
490 handlers,
491 p,
494 if (NULL == p->th)
495 {
497 "Failed to connect to transport service for peer `%s': `%s'\n",
498 cfgname,
499 emsg);
501 GNUNET_free (emsg);
502 return NULL;
503 }
505 if (NULL == p->ah)
506 {
508 "Failed to connect to TNG service for peer `%s': `%s'\n",
509 cfgname,
510 emsg);
512 GNUNET_free (emsg);
513 return NULL;
514 }
515 p->ph = GNUNET_PEERSTORE_connect (p->cfg);
516 // FIXME Error handling
518
519 return p;
520}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static struct GNUNET_NotificationContext * nc
Notification context for broadcasting to monitors.
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd)
Connect to the transport service.
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1381
struct GNUNET_TESTING_Peer * GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t key_number, struct GNUNET_PeerIdentity *id, char **emsg)
Configure a GNUnet peer.
Definition: testing.c:1188
int GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testing.c:1167
void GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer, struct GNUNET_PeerIdentity *id)
Obtain the peer identity from a peer handle.
Definition: testing.c:1359
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_tail
tail DLL of peers
static void start_cb(void *cls)
Function called once we have successfully launched a peer.
static void * notify_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
static void retrieve_hello(void *cls)
static void notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)

References dummy, GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_CONTAINER_DLL_insert, GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s_full(), GNUNET_memcpy, GNUNET_new, GNUNET_new_array, GNUNET_NO, GNUNET_OK, GNUNET_PEERSTORE_connect(), GNUNET_SCHEDULER_add_now(), GNUNET_SYSERR, GNUNET_TESTING_configuration_create(), GNUNET_TESTING_peer_configure(), GNUNET_TESTING_peer_get_identity(), GNUNET_TESTING_peer_start(), GNUNET_TRANSPORT_application_init(), GNUNET_TRANSPORT_core_connect(), GNUNET_TRANSPORT_TESTING_stop_peer(), handlers, LOG, nc, notify_connect(), notify_disconnect(), p, GNUNET_TRANSPORT_TESTING_Handle::p_head, GNUNET_TRANSPORT_TESTING_Handle::p_tail, peer_id, retrieve_hello(), start_cb(), and GNUNET_TRANSPORT_TESTING_Handle::tl_system.

Referenced by connect_check_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_stop_peer()

void GNUNET_TRANSPORT_TESTING_stop_peer ( struct GNUNET_TRANSPORT_TESTING_PeerContext p)

Shutdown the given peer.

Parameters
pthe peer

Definition at line 614 of file transport-testing2.c.

616{
617 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
620 /* shutdown */
622 "Stopping peer %u (`%s')\n",
623 p->no,
624 GNUNET_i2s (&p->id));
625
626 for (cc = tth->cc_head; NULL != cc; cc = ccn)
627 {
628 ccn = cc->next;
629 if ((cc->p1 == p) ||
630 (cc->p2 == p))
632 }
633 if (NULL != p->pic)
634 {
636 p->pic = NULL;
637 }
638 if (NULL != p->th)
639 {
641 p->th = NULL;
642 }
643 if (NULL != p->ah)
644 {
646 p->ah = NULL;
647 }
648 if (NULL != p->ph)
649 {
651 "Disconnecting from PEERSTORE service\n");
653 p->ph = NULL;
654 }
655
656 if (NULL != p->peer)
657 {
658 if (GNUNET_OK !=
660 {
662 "Testing lib failed to stop peer %u (`%s')\n",
663 p->no,
664 GNUNET_i2s (&p->id));
665 }
667 p->peer = NULL;
668 }
669 if (NULL != p->hello)
670 {
671 GNUNET_free (p->hello);
672 p->hello = NULL;
673 }
674 if (NULL != p->cfg)
675 {
677 p->cfg = NULL;
678 }
679 if (NULL != p->handlers)
680 {
681 GNUNET_free (p->handlers);
682 p->handlers = NULL;
683 }
685 tth->p_tail,
686 p);
688 "Peer %u (`%s') stopped\n",
689 p->no,
690 GNUNET_i2s (&p->id));
691 if (NULL != p->rh_task)
692 GNUNET_SCHEDULER_cancel (p->rh_task);
693 p->rh_task = NULL;
694 GNUNET_free (p);
695}
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
void GNUNET_PEERSTORE_iteration_stop(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iteration.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1485
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1566
struct GNUNET_TRANSPORT_TESTING_PeerContext * p2
Peer we want to connect.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p1
Peer we want to connect.

References GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_CONFIGURATION_destroy(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_disconnect(), GNUNET_PEERSTORE_iteration_stop(), GNUNET_SCHEDULER_cancel(), GNUNET_TESTING_peer_destroy(), GNUNET_TESTING_peer_stop(), GNUNET_TRANSPORT_application_done(), GNUNET_TRANSPORT_core_disconnect(), GNUNET_TRANSPORT_TESTING_connect_peers_cancel(), LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, p, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2, GNUNET_TRANSPORT_TESTING_Handle::p_head, and GNUNET_TRANSPORT_TESTING_Handle::p_tail.

Referenced by do_shutdown(), GNUNET_TRANSPORT_TESTING_done(), and GNUNET_TRANSPORT_TESTING_start_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_restart_peer()

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.

Parameters
pthe peer
restart_cbrestart callback
restart_cb_clscallback closure
Returns
GNUNET_OK in success otherwise GNUNET_SYSERR

Definition at line 524 of file transport-testing2.c.

528{
531
532 /* shutdown */
534 "Stopping peer %u (`%s')\n",
535 p->no,
536 GNUNET_i2s (&p->id));
537 if (NULL != p->pic)
538 {
540 p->pic = NULL;
541 }
542 if (NULL != p->th)
543 {
545 p->th = NULL;
546 }
547 for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
548 {
549 ccn = cc->next;
550 if ((cc->p1 == p) ||
551 (cc->p2 == p))
553 }
554 if (NULL != p->ah)
555 {
557 p->ah = NULL;
558 }
559 if (GNUNET_SYSERR ==
561 {
563 "Failed to stop peer %u (`%s')\n",
564 p->no,
565 GNUNET_i2s (&p->id));
566 return GNUNET_SYSERR;
567 }
568
569 sleep (5); // YUCK!
570
572 "Restarting peer %u (`%s')\n",
573 p->no,
574 GNUNET_i2s (&p->id));
575 /* restart */
577 {
579 "Failed to restart peer %u (`%s')\n",
580 p->no,
581 GNUNET_i2s (&p->id));
582 return GNUNET_SYSERR;
583 }
584
585 GNUNET_assert (NULL == p->start_cb);
586 p->start_cb = restart_cb;
587 p->start_cb_cls = restart_cb_cls;
588
590 NULL,
591 p->handlers,
592 p,
595 GNUNET_assert (NULL != p->th);
598 "transport",
599 &p->id,
602 p);
603 GNUNET_assert (NULL != p->pic);
604 return GNUNET_OK;
605}
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iteration_start(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over peerstore entries.
#define GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY
Key used for storing HELLOs in the peerstore.
static void hello_iter_cb(void *cb_cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_OK, GNUNET_PEERSTORE_iteration_start(), GNUNET_PEERSTORE_iteration_stop(), GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, GNUNET_SYSERR, GNUNET_TESTING_peer_start(), GNUNET_TESTING_peer_stop(), GNUNET_TRANSPORT_application_done(), GNUNET_TRANSPORT_application_init(), GNUNET_TRANSPORT_core_connect(), GNUNET_TRANSPORT_core_disconnect(), GNUNET_TRANSPORT_TESTING_connect_peers_cancel(), hello_iter_cb(), LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, notify_connect(), notify_disconnect(), p, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, and GNUNET_TRANSPORT_TESTING_ConnectRequest::p2.

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_TESTING_connect_peers()

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.

Parameters
p1peer 1
p2peer 2
cbthe callback to call when both peers notified that they are connected
clscallback cls
Returns
a connect request handle

Connect the given peers and call the callback when both peers report the inbound connection.

FIXME maybe schedule the application_validate somehow Initiate a connection from p1 to p2 by offering p1 p2's HELLO message

Remarks: start_peer's notify_connect callback can be called before.

Parameters
tthtransport testing handle
p1peer 1
p2peer 2
cbthe callback to call when both peers notified that they are connected
clscallback cls
Returns
a connect request handle

Definition at line 729 of file transport-testing2.c.

735{
736 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
739
740 ccn = NULL;
741 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
742 {
743 if ((cc->p1 == p1) &&
744 (cc->p2 == p2))
745 {
746 ccn = cc;
747 break;
748 }
749 }
750
752 cc->p1 = p1;
753 cc->p2 = p2;
754 cc->cb = cb;
755 if (NULL != cls)
756 cc->cb_cls = cls;
757 else
758 cc->cb_cls = cc;
759 if (NULL != ccn)
760 {
761 cc->p1_c = ccn->p1_c;
762 cc->p2_c = ccn->p2_c;
763 cc->connected = ccn->connected;
764 }
766 tth->cc_tail,
767 cc);
769 &p2->id,
773 "New connect request %p\n",
774 cc);
775 return cc;
776}
struct GNUNET_TRANSPORT_ApplicationSuggestHandle * GNUNET_TRANSPORT_application_suggest(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_MQ_PriorityPreferences pk, struct GNUNET_BANDWIDTH_Value32NBO bw)
An application would like TRANSPORT to connect to a peer.
#define GNUNET_BANDWIDTH_ZERO
Convenience definition to use for 0-bandwidth.
@ GNUNET_MQ_PRIO_BEST_EFFORT
Best-effort traffic (e.g.
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.
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.
int p1_c
Set if peer1 says the connection is up to peer2.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_tail
head DLL of connect contexts
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Application handle.
struct GNUNET_PeerIdentity id
Peer identity.

References GNUNET_TRANSPORT_TESTING_PeerContext::ah, GNUNET_TRANSPORT_TESTING_ConnectRequest::ah_sh, GNUNET_TRANSPORT_TESTING_ConnectRequest::cb, GNUNET_TRANSPORT_TESTING_ConnectRequest::cb_cls, GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_TRANSPORT_TESTING_Handle::cc_tail, GNUNET_TRANSPORT_TESTING_ConnectRequest::connected, GNUNET_BANDWIDTH_ZERO, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_PRIO_BEST_EFFORT, GNUNET_new, GNUNET_TRANSPORT_application_suggest(), GNUNET_TRANSPORT_TESTING_PeerContext::id, LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1_c, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2_c, and GNUNET_TRANSPORT_TESTING_PeerContext::tth.

Referenced by do_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_connect_peers_cancel()

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.

Parameters
cca connect request handle

Definition at line 780 of file transport-testing2.c.

783{
784 struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth;
785
787 "Canceling connect request!\n");
788 if (NULL != cc->tct)
789 {
791 cc->tct = NULL;
792 }
793 if (NULL != cc->ah_sh)
794 {
796 cc->ah_sh = NULL;
797 }
799 tth->cc_tail,
800 cc);
801 GNUNET_free (cc);
802}
void GNUNET_TRANSPORT_application_suggest_cancel(struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
We no longer care about being connected to a peer.
struct GNUNET_SCHEDULER_Task * tct
Task by which we accomplish the connection.

References GNUNET_TRANSPORT_TESTING_ConnectRequest::ah_sh, GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_TRANSPORT_TESTING_Handle::cc_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_application_suggest_cancel(), LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::tct, and GNUNET_TRANSPORT_TESTING_PeerContext::tth.

Referenced by do_shutdown(), GNUNET_TRANSPORT_TESTING_done(), GNUNET_TRANSPORT_TESTING_restart_peer(), and GNUNET_TRANSPORT_TESTING_stop_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_find_connecting_context()

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.

Parameters
p1first peer
p2second peer
cbfunction to call
cb_clsclosure for cb

Definition at line 57 of file transport-testing2.c.

66{
67 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
70
71 for (cc = tth->cc_head; NULL != cc; cc = ccn)
72 {
73 ccn = cc->next;
74 if ((cc->p1 == p1) &&
75 (cc->p2 == p2))
76 cb (cb_cls,
77 cc);
78 }
79}

References GNUNET_TRANSPORT_TESTING_ConnectRequest::cb, GNUNET_TRANSPORT_TESTING_ConnectRequest::cb_cls, GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2, and GNUNET_TRANSPORT_TESTING_PeerContext::tth.

Referenced by GNUNET_TRANSPORT_TESTING_send(), notify_connect(), and notify_disconnect().

Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_find_peer()

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.

Parameters
ccccontext to search
peerpeer to look for
Returns
NULL if peer was not found

Definition at line 209 of file transport-testing-main2.c.

213{
214 for (unsigned int i = 0; i < ccc->num_peers; i++)
215 if ((NULL != ccc->p[i]) &&
216 (0 == memcmp (peer,
217 &ccc->p[i]->id,
218 sizeof(*peer))))
219 return ccc->p[i];
220 return NULL;
221}
unsigned int num_peers
Number of peers involved in the test.
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.

References GNUNET_TRANSPORT_TESTING_PeerContext::id, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::num_peers, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, and GNUNET_TRANSPORT_TESTING_PeerContext::peer.

◆ GNUNET_TRANSPORT_TESTING_connect_check()

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.

Parameters
clsclosure of type struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
tth_initialized testing handle
test_plugin_name of the plugin
test_name_name of the test
num_peersnumber of entries in the cfg_file array
cfg_filesarray of names of configuration files for the peers
Returns
GNUNET_SYSERR on error

Definition at line 508 of file transport-testing-main2.c.

515{
516 static struct GNUNET_GETOPT_CommandLineOption options[] = {
518 };
522 char *argv[] = {
523 (char *) test_name_,
524 "-c",
525 (char *) ccc->config_file,
526 NULL
527 };
528
530 ccc->cfg_files = cfg_files;
531 ccc->test_plugin = test_plugin_;
532 ccc->test_name = test_name_;
533 ccc->tth = tth_;
535 ccc->p = p;
536 ccc->ip = ip;
537 for (unsigned int i = 0; i < num_peers; i++)
538 {
539 ip[i].off = i;
540 ip[i].ccc = ccc;
541 }
542 if (GNUNET_OK !=
543 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
544 argv,
545 test_name_,
546 "nohelp",
547 options,
549 ccc))
550 return GNUNET_SYSERR;
551 return ccc->global_ret;
552}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
Definition of a command line option.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
int global_ret
Result from the main function, set to GNUNET_OK on success.
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.
char ** cfg_files
Configuration files we have, array with num_peers entries.
const char * test_name
Name of the testcase.
void * cls
Closure for rec, nc and nd.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Main testing handle.
const char * test_plugin
Name of the plugin.
unsigned int off
Offset of the peer this is about.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Overall context of the callback.
static void connect_check_run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Function run from GNUNET_TRANSPORT_TESTING_connect_check once the scheduler is up.

References GNUNET_TRANSPORT_TESTING_InternalPeerContext::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cfg_files, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cls, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::config_file, connect_check_run(), GNUNET_TRANSPORT_TESTING_ConnectCheckContext::global_ret, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_SYSERR, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::ip, num_peers, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::num_peers, GNUNET_TRANSPORT_TESTING_InternalPeerContext::off, options, p, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::test_name, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::test_plugin, and GNUNET_TRANSPORT_TESTING_ConnectCheckContext::tth.

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_TESTING_main_()

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.

Parameters
argv0binary name (argv[0])
filenamesource file name (FILE)
num_peersnumber of peers to start
checkmain function to run
check_clsclosure for check
Returns
GNUNET_OK on success

Definition at line 566 of file transport-testing-main2.c.

571{
573 char *test_name;
574 char *test_source;
575 char *test_plugin;
576 char *cfg_names[num_peers];
577 int ret;
578
579 ret = GNUNET_OK;
580 test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0);
581 GNUNET_log_setup (test_name,
582 "WARNING",
583 NULL);
586 test_source);
587 for (unsigned int i = 0; i < num_peers; i++)
588 cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name (argv0,
589 i + 1);
591 if (NULL == tth)
592 {
594 }
595 else
596 {
597 ret = check (check_cls,
598 tth,
599 test_plugin,
600 test_name,
601 num_peers,
602 cfg_names);
604 }
605 for (unsigned int i = 0; i < num_peers; i++)
606 GNUNET_free (cfg_names[i]);
607 GNUNET_free (test_source);
608 GNUNET_free (test_plugin);
609 GNUNET_free (test_name);
610 return ret;
611}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static char * filename
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
char * GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *file, const char *test)
Extracts the plugin name from an absolute file name and the test name.
char * GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file)
Extracts the filename from an absolute file name and removes the extension.
char * GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count)
This function takes the filename (e.g.
char * GNUNET_TRANSPORT_TESTING_get_test_name(const char *file)
Extracts the test filename from an absolute file name and removes the extension.
struct GNUNET_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init()
Initialize the transport testing.
void GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
Clean up the transport testing.

References filename, GNUNET_free, GNUNET_log_setup(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TRANSPORT_TESTING_done(), GNUNET_TRANSPORT_TESTING_get_config_name(), GNUNET_TRANSPORT_TESTING_get_test_name(), GNUNET_TRANSPORT_TESTING_get_test_plugin_name(), GNUNET_TRANSPORT_TESTING_get_test_source_name(), GNUNET_TRANSPORT_TESTING_init(), num_peers, and ret.

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_TESTING_send()

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.

Parameters
senderthe sending peer
receiverthe receiving peer
mtypemessage type to use
msizesize of the message, at least sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)
numunique message number
contcontinuation to call after transmission
cont_clsclosure for cont
Returns
GNUNET_OK if message was queued, GNUNET_NO if peers are not connected GNUNET_SYSERR if msize is illegal

Definition at line 67 of file transport-testing-send2.c.

76{
78 struct GNUNET_MQ_Envelope *env;
80
81 if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))
82 {
83 GNUNET_break (0);
84 return GNUNET_SYSERR;
85 }
86 cr = NULL;
89 &find_cr,
90 &cr);
91 if (NULL == cr)
93 sender,
94 &find_cr,
95 &cr);
96 if (NULL == cr)
97 {
98 GNUNET_break (0);
99 return GNUNET_NO;
100 }
101 if (NULL == cr->mq)
102 {
103 GNUNET_break (0);
104 return GNUNET_NO;
105 }
106 {
107 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
108
110 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
111 sender->no,
112 GNUNET_i2s (&sender->id),
113 receiver->no,
114 receiver_s);
115 GNUNET_free (receiver_s);
116 }
117 env = GNUNET_MQ_msg_extra (test,
118 msize - sizeof(*test),
119 mtype);
120 test->num = htonl (num);
121 memset (&test[1],
122 num,
123 msize - sizeof(*test));
125 cont,
126 cont_cls);
127 GNUNET_MQ_send (cr->mq,
128 env);
129 return GNUNET_OK;
130}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:638
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
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.
unsigned int no
An unique number to identify the peer.
uint32_t num
Monotonically increasing counter throughout the test.
static void find_cr(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
Return cx in cls.
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.

References env, find_cr(), GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, GNUNET_TRANSPORT_TESTING_find_connecting_context(), GNUNET_TRANSPORT_TESTING_PeerContext::id, GNUNET_TRANSPORT_TESTING_ConnectRequest::mq, GNUNET_TRANSPORT_TESTING_PeerContext::no, GNUNET_TRANSPORT_TESTING_TestMessage::num, and receiver().

Referenced by do_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_simple_send()

void GNUNET_TRANSPORT_TESTING_simple_send ( void *  cls)

Task that sends a minimalistic test message from the first peer to the second peer.

Parameters
clsthe struct GNUNET_TRANSPORT_TESTING_SendClosure which should contain at least two peers, the first two of which should be currently connected
clsthe 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-send2.c.

179{
181 int done;
182 size_t msize;
183
184 if (0 < sc->num_messages)
185 {
186 sc->num_messages--;
187 done = (0 == sc->num_messages);
188 }
189 else
190 {
191 done = 0; /* infinite loop */
192 }
193 msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage);
194 if (NULL != sc->get_size_cb)
195 msize = sc->get_size_cb (sc->num_messages);
196 /* if this was the last message, call the continuation,
197 otherwise call this function again */
198 do_send (sc->ccc,
199 msize,
201 done ? sc->cont_cls : sc);
202}
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
Type of the closure argument to pass to GNUNET_TRANSPORT_TESTING_simple_send() and GNUNET_TRANSPORT_T...
static void do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, uint16_t size, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Task that sends a test message from the first peer to the second peer.
void GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
Task that sends a minimalistic test message from the first peer to the second peer.

References do_send(), GNUNET_TRANSPORT_TESTING_simple_send(), and sc.

Referenced by GNUNET_TRANSPORT_TESTING_simple_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_large_send()

void GNUNET_TRANSPORT_TESTING_large_send ( void *  cls)

Task that sends a large test message from the first peer to the second peer.

Parameters
clsthe struct GNUNET_TRANSPORT_TESTING_SendClosure which should contain at least two peers, the first two of which should be currently connected
clsthe 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-send2.c.

215{
217 int done;
218 size_t msize;
219
220 if (0 < sc->num_messages)
221 {
222 sc->num_messages--;
223 done = (0 == sc->num_messages);
224 }
225 else
226 {
227 done = 0; /* infinite loop */
228 }
229 msize = 2600;
230 if (NULL != sc->get_size_cb)
231 msize = sc->get_size_cb (sc->num_messages);
232 /* if this was the last message, call the continuation,
233 otherwise call this function again */
234 do_send (sc->ccc,
235 msize,
237 done ? sc->cont_cls : sc);
238}
void GNUNET_TRANSPORT_TESTING_large_send(void *cls)
Task that sends a large test message from the first peer to the second peer.

References do_send(), GNUNET_TRANSPORT_TESTING_large_send(), and sc.

Referenced by GNUNET_TRANSPORT_TESTING_large_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_log_connect()

void GNUNET_TRANSPORT_TESTING_log_connect ( void *  cls,
struct GNUNET_TRANSPORT_TESTING_PeerContext me,
const struct GNUNET_PeerIdentity other 
)

Log a connect event.

Parameters
clsNULL
mepeer that had the event
otherpeer that connected.

Definition at line 37 of file transport-testing-loggers2.c.

41{
42 char *ps;
43
44 ps = GNUNET_strdup (GNUNET_i2s (&me->id));
46 "Peer %s connected to %u (%s)!\n",
47 GNUNET_i2s (other),
48 me->no,
49 ps);
51}
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.

References GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_strdup, me, and ps.

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_TESTING_log_disconnect()

void GNUNET_TRANSPORT_TESTING_log_disconnect ( void *  cls,
struct GNUNET_TRANSPORT_TESTING_PeerContext me,
const struct GNUNET_PeerIdentity other 
)

Log a disconnect event.

Parameters
clsNULL
mepeer that had the event
otherpeer that disconnected.

Definition at line 62 of file transport-testing-loggers2.c.

68{
69 char *ps;
70
71 ps = GNUNET_strdup (GNUNET_i2s (&me->id));
73 "Peer `%s' disconnected from %u (%s)!\n",
74 GNUNET_i2s (other),
75 me->no,
76 ps);
78}

References GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_strdup, me, and ps.

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_TESTING_get_test_name()

char * GNUNET_TRANSPORT_TESTING_get_test_name ( const char *  file)

Extracts the test filename from an absolute file name and removes the extension.

Parameters
fileabsolute file name
Returns
resulting test name
Parameters
fileabsolute file name
Returns
the result

Definition at line 73 of file transport-testing-filenames2.c.

74{
75 char *backup = extract_filename (file);
76 char *filename = backup;
77 char *dotexe;
78 char *ret;
79
80 if (NULL == filename)
81 return NULL;
82
83 /* remove "lt-" */
84 filename = strstr (filename, "test");
85 if (NULL == filename)
86 {
87 GNUNET_free (backup);
88 return NULL;
89 }
90
91 /* remove ".exe" */
92 if (NULL != (dotexe = strstr (filename, ".exe")))
93 dotexe[0] = '\0';
95 GNUNET_free (backup);
96 return ret;
97}
static char * extract_filename(const char *file)
Removes all directory separators from absolute filename.

References extract_filename(), filename, GNUNET_free, GNUNET_strdup, and ret.

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_get_config_name()

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

Parameters
filefilename of the test, e.g. argv[0]
countpeer number
Returns
configuration name to use

argv[0), removes a "lt-"-prefix and if existing ".exe"-prefix and adds the peer-number

Parameters
filefilename of the test, e.g. argv[0]
countpeer number
Returns
the result

Definition at line 174 of file transport-testing-filenames2.c.

176{
177 char *filename = extract_filename (file);
178 char *backup = filename;
179 char *dotexe;
180 char *ret;
181
182 if (NULL == filename)
183 return NULL;
184 /* remove "lt-" */
185 filename = strstr (filename, "test");
186 if (NULL == filename)
187 goto fail;
188 /* remove ".exe" */
189 if (NULL != (dotexe = strstr (filename, ".exe")))
190 dotexe[0] = '\0';
192 "%s_peer%u.conf",
193 filename,
194 count);
195 GNUNET_free (backup);
196 return ret;
197fail:
198 GNUNET_free (backup);
199 return NULL;
200}
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.

References extract_filename(), filename, GNUNET_asprintf(), GNUNET_free, and ret.

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_get_test_plugin_name()

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.

Parameters
fileabsolute file name
testtest name
Returns
the plugin name

Extracts the plugin anme from an absolute file name and the test name.

Parameters
fileabsolute file name
testtest name
Returns
the result

Definition at line 127 of file transport-testing-filenames2.c.

129{
130 char *filename;
131 char *dotexe;
132 char *e = extract_filename (file);
133 char *t = extract_filename (test);
134 char *ret;
135
136 if (NULL == e)
137 goto fail;
138 /* remove "lt-" */
139 filename = strstr (e, "tes");
140 if (NULL == filename)
141 goto fail;
142 /* remove ".exe" */
143 if (NULL != (dotexe = strstr (filename, ".exe")))
144 dotexe[0] = '\0';
145
146 /* find last _ */
147 filename = strstr (filename, t);
148 if (NULL == filename)
149 goto fail;
150 /* copy plugin */
151 filename += strlen (t);
152 if ('\0' != *filename)
153 filename++;
155 goto suc;
156fail:
157 ret = NULL;
158suc:
159 GNUNET_free (t);
160 GNUNET_free (e);
161 return ret;
162}

References extract_filename(), filename, GNUNET_free, GNUNET_strdup, ret, and t.

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_get_test_source_name()

char * GNUNET_TRANSPORT_TESTING_get_test_source_name ( const char *  file)

Extracts the filename from an absolute file name and removes the extension.

Parameters
fileabsolute file name
Returns
the source name
Parameters
fileabsolute file name
Returns
the result

Definition at line 107 of file transport-testing-filenames2.c.

108{
109 char *src = extract_filename (file);
110 char *split;
111
112 split = strstr (src, ".");
113 if (NULL != split)
114 split[0] = '\0';
115 return src;
116}

References extract_filename().

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ GNUNET_TRANSPORT_TESTING_ReceiveCallback

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.

Parameters
clsclosure
receiverreceiver of the message
sendersender of the message
messagethe message

Definition at line 461 of file transport-testing2.h.