GNUnet  0.11.x
Data Structures | Functions
transport-testing-main.c File Reference

convenience main function for tests More...

#include "transport-testing.h"
Include dependency graph for transport-testing-main.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_TRANSPORT_TESTING_ConnectRequestList
 Closure for connect_cb. More...
 
struct  GNUNET_TRANSPORT_TESTING_InternalPeerContext
 Internal data structure. More...
 
struct  ConnectPairInfo
 Information tracked per connected peer. More...
 

Functions

static void do_shutdown (void *cls)
 Shutdown function for the test. More...
 
static void do_timeout (void *cls)
 Testcase hit timeout, shut it down with error. More...
 
static void connect_cb (void *cls)
 Function called when we connected two 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...
 
static void * my_nc (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 Wrapper around peers connecting. More...
 
static void my_nd (void *cls, const struct GNUNET_PeerIdentity *peer, void *custom_cls)
 Wrapper around peers disconnecting. More...
 
static int check_test (void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 Wrapper around receiving data. More...
 
static void handle_test (void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 Wrapper around receiving data. More...
 
static int check_test2 (void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 Wrapper around receiving data. More...
 
static void handle_test2 (void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
 Wrapper around receiving data. More...
 
static void do_connect (void *cls)
 Connect the peers as a clique. More...
 
static void start_cb (void *cls)
 Function called once we have successfully launched a peer. More...
 
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. 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...
 

Detailed Description

convenience main function for tests

Author
Christian Grothoff

Definition in file transport-testing-main.c.

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown function for the test.

Stops all peers.

Parameters
clsour struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *

Definition at line 71 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cls, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::connect_task, GNUNET_TRANSPORT_TESTING_ConnectRequestList::cr, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::crl_head, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::crl_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_TESTING_connect_peers_cancel(), GNUNET_TRANSPORT_TESTING_stop_peer(), GNUNET_TRANSPORT_TESTING_ConnectCheckContext::num_peers, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::shutdown_task, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::shutdown_task_cls, and GNUNET_TRANSPORT_TESTING_ConnectCheckContext::timeout_task.

Referenced by connect_check_run().

72 {
75 
77  "Testcase shutting down\n");
78  if (NULL != ccc->shutdown_task)
79  ccc->shutdown_task (ccc->shutdown_task_cls);
80  if (NULL != ccc->timeout_task)
81  {
83  ccc->timeout_task = NULL;
84  }
85  if (NULL != ccc->connect_task)
86  {
88  ccc->connect_task = NULL;
89  }
90  while (NULL != (crl = ccc->crl_head))
91  {
93  ccc->crl_tail,
94  crl);
96  GNUNET_free (crl);
97  }
98  for (unsigned int i = 0; i < ccc->num_peers; i++)
99  {
100  if (NULL != ccc->p[i])
101  {
103  ccc->p[i] = NULL;
104  }
105  }
106 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_SCHEDULER_Task * connect_task
Task run to connect peers.
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
unsigned int num_peers
Number of peers involved in the test.
void * cls
Closure for rec, nc and nd.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_tail
DLL of active connect requests.
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Cancel the request to connect two peers Tou MUST cancel the request if you stop the peers before the ...
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cr
Connect request this is about.
#define GNUNET_log(kind,...)
GNUNET_SCHEDULER_TaskCallback shutdown_task
Custom task to run on shutdown.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
void GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
Shutdown the given peer.
void * shutdown_task_cls
Closure for shutdown_task.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_head
DLL of active connect requests.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_timeout()

static void do_timeout ( void *  cls)
static

Testcase hit timeout, shut it down with error.

Parameters
clsour struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *

Definition at line 115 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cls, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::global_ret, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, and GNUNET_TRANSPORT_TESTING_ConnectCheckContext::timeout_task.

Referenced by connect_check_run().

116 {
118 
119  ccc->timeout_task = NULL;
121  "Testcase timed out\n");
122  ccc->global_ret = GNUNET_SYSERR;
124 }
int global_ret
Result from the main function, set to GNUNET_OK on success.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
void * cls
Closure for rec, nc and nd.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_log(kind,...)
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_cb()

static void connect_cb ( void *  cls)
static

Function called when we connected two peers.

Once we have gotten to the clique, launch test-specific logic.

Parameters
clsour struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *

Definition at line 170 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::connect_continuation, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::connect_continuation_cls, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::crl_head, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::crl_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_TRANSPORT_TESTING_PeerContext::id, GNUNET_TRANSPORT_TESTING_PeerContext::no, GNUNET_TRANSPORT_TESTING_ConnectRequestList::p1, and GNUNET_TRANSPORT_TESTING_ConnectRequestList::p2.

Referenced by do_connect().

171 {
174 
176  ccc->crl_tail,
177  crl);
178  {
179  char *p1_c = GNUNET_strdup (GNUNET_i2s (&crl->p1->id));
180 
182  "Peers connected: %u (%s) <-> %u (%s)\n",
183  crl->p1->no,
184  p1_c,
185  crl->p2->no,
186  GNUNET_i2s (&crl->p2->id));
187  GNUNET_free (p1_c);
188  GNUNET_free (crl);
189  }
190  if (NULL == ccc->crl_head)
191  {
193  "All connections UP, launching custom test logic.\n");
196  }
197 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
GNUNET_SCHEDULER_TaskCallback connect_continuation
How should we continue after the connect?
struct GNUNET_PeerIdentity id
Peer identity.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
unsigned int no
An unique number to identify the peer.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p1
Peer being connected.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_tail
DLL of active connect requests.
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:1280
void * connect_continuation_cls
Closure for connect_continuation.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p2
Peer being connected.
#define GNUNET_log(kind,...)
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Overall context we are in.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_head
DLL of active connect requests.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
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 208 of file transport-testing-main.c.

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

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

◆ my_nc()

static void* my_nc ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Wrapper around peers connecting.

Calls client's nc function.

Parameters
clsour struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *
peerpeer we got connected to
mqmessage queue for transmissions to peer
Returns
closure for message handlers

Definition at line 232 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, GNUNET_TRANSPORT_TESTING_InternalPeerContext::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cls, GNUNET_new, ConnectPairInfo::ipi, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::nc, GNUNET_TRANSPORT_TESTING_InternalPeerContext::off, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, peer, and ConnectPairInfo::sender.

Referenced by connect_check_run().

235 {
238  struct ConnectPairInfo *cpi;
239 
240  if (NULL != ccc->nc)
241  ccc->nc (ccc->cls,
242  ccc->p[ipi->off],
243  peer);
244  cpi = GNUNET_new (struct ConnectPairInfo);
245  cpi->ipi = ipi;
246  cpi->sender = peer; /* valid until disconnect */
247  return cpi;
248 }
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
const struct GNUNET_PeerIdentity * sender
Peer this is about.
unsigned int off
Offset of the peer this is about.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Overall context of the callback.
void * cls
Closure for rec, nc and nd.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_TRANSPORT_TESTING_InternalPeerContext * ipi
Information about the receiving peer.
Information tracked per connected peer.
GNUNET_TRANSPORT_TESTING_NotifyConnect nc
Notify connect argument to give for peers we start.
Here is the caller graph for this function:

◆ my_nd()

static void my_nd ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  custom_cls 
)
static

Wrapper around peers disconnecting.

Calls client's nd function.

Parameters
clsour struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *
peerpeer we got disconnected from
custom_clsreturn value from

Definition at line 259 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, GNUNET_TRANSPORT_TESTING_InternalPeerContext::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cls, GNUNET_free, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::nd, GNUNET_TRANSPORT_TESTING_InternalPeerContext::off, and GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p.

Referenced by connect_check_run().

262 {
265  struct ConnectPairInfo *cpi = custom_cls;
266 
267  if (NULL != ccc->nd)
268  ccc->nd (ccc->cls,
269  ccc->p[ipi->off],
270  peer);
271  GNUNET_free (cpi);
272 }
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
unsigned int off
Offset of the peer this is about.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Overall context of the callback.
void * cls
Closure for rec, nc and nd.
GNUNET_TRANSPORT_TESTING_NotifyDisconnect nd
Notify disconnect argument to give for peers we start.
Information tracked per connected peer.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ check_test()

static int check_test ( void *  cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage message 
)
static

Wrapper around receiving data.

Calls client's rec function.

Parameters
clsour struct ConnectPairInfo *
messagemessage we received
Returns
GNUNET_OK (all messages are fine)

Definition at line 283 of file transport-testing-main.c.

References GNUNET_OK.

285 {
286  return GNUNET_OK;
287 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_test()

static void handle_test ( void *  cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage message 
)
static

Wrapper around receiving data.

Calls client's rec function.

Parameters
clsour struct ConnectPairInfo *
messagemessage we received

Definition at line 297 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, GNUNET_TRANSPORT_TESTING_InternalPeerContext::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cls, ConnectPairInfo::ipi, GNUNET_TRANSPORT_TESTING_InternalPeerContext::off, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::rec, and ConnectPairInfo::sender.

299 {
300  struct ConnectPairInfo *cpi = cls;
303 
304  if (NULL != ccc->rec)
305  ccc->rec (ccc->cls,
306  ccc->p[ipi->off],
307  cpi->sender,
308  message);
309 }
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
const struct GNUNET_PeerIdentity * sender
Peer this is about.
unsigned int off
Offset of the peer this is about.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Overall context of the callback.
void * cls
Closure for rec, nc and nd.
struct GNUNET_TRANSPORT_TESTING_InternalPeerContext * ipi
Information about the receiving peer.
Information tracked per connected peer.
GNUNET_TRANSPORT_TESTING_ReceiveCallback rec
Receiver argument to give for peers we start.

◆ check_test2()

static int check_test2 ( void *  cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage message 
)
static

Wrapper around receiving data.

Calls client's rec function.

Parameters
clsour struct ConnectPairInfo *
messagemessage we received
Returns
GNUNET_OK (all messages are fine)

Definition at line 320 of file transport-testing-main.c.

References GNUNET_OK.

322 {
323  return GNUNET_OK;
324 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_test2()

static void handle_test2 ( void *  cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage message 
)
static

Wrapper around receiving data.

Calls client's rec function.

Parameters
clsour struct ConnectPairInfo *
messagemessage we received

Definition at line 334 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, GNUNET_TRANSPORT_TESTING_InternalPeerContext::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cls, ConnectPairInfo::ipi, GNUNET_TRANSPORT_TESTING_InternalPeerContext::off, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::rec, and ConnectPairInfo::sender.

336 {
337  struct ConnectPairInfo *cpi = cls;
340 
341  if (NULL != ccc->rec)
342  ccc->rec (ccc->cls,
343  ccc->p[ipi->off],
344  cpi->sender,
345  message);
346 }
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
const struct GNUNET_PeerIdentity * sender
Peer this is about.
unsigned int off
Offset of the peer this is about.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Overall context of the callback.
void * cls
Closure for rec, nc and nd.
struct GNUNET_TRANSPORT_TESTING_InternalPeerContext * ipi
Information about the receiving peer.
Information tracked per connected peer.
GNUNET_TRANSPORT_TESTING_ReceiveCallback rec
Receiver argument to give for peers we start.

◆ do_connect()

static void do_connect ( void *  cls)
static

Connect the peers as a clique.

Parameters
clsour struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext

Definition at line 355 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectCheckContext::bi_directional, GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cls, connect_cb(), GNUNET_TRANSPORT_TESTING_ConnectCheckContext::connect_task, GNUNET_TRANSPORT_TESTING_ConnectRequestList::cr, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::crl_head, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::crl_tail, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_strdup, GNUNET_TRANSPORT_TESTING_connect_peers(), GNUNET_TRANSPORT_TESTING_PeerContext::id, GNUNET_TRANSPORT_TESTING_PeerContext::no, num_peers, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::num_peers, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, GNUNET_TRANSPORT_TESTING_ConnectRequestList::p1, and GNUNET_TRANSPORT_TESTING_ConnectRequestList::p2.

Referenced by start_cb().

356 {
358 
359  ccc->connect_task = NULL;
360  for (unsigned int i = 0; i < ccc->num_peers; i++)
361  for (unsigned int j = (ccc->bi_directional ? 0 : i + 1); j < ccc->num_peers;
362  j++)
363  {
365 
366  if (i == j)
367  continue;
370  ccc->crl_tail,
371  crl);
372  crl->ccc = ccc;
373  crl->p1 = ccc->p[i];
374  crl->p2 = ccc->p[j];
375  {
376  char *sender_c = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
377 
379  "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
380  ccc->p[0]->no,
381  sender_c,
382  ccc->p[1]->no,
383  GNUNET_i2s (&ccc->p[1]->id));
384  GNUNET_free (sender_c);
385  }
387  ccc->p[j],
388  &connect_cb,
389  crl);
390  }
391 }
struct GNUNET_SCHEDULER_Task * connect_task
Task run to connect peers.
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_PeerIdentity id
Peer identity.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
unsigned int num_peers
Number of peers involved in the test.
static void connect_cb(void *cls)
Function called when we connected two peers.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
unsigned int no
An unique number to identify the peer.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p1
Peer being connected.
void * cls
Closure for rec, nc and nd.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_tail
DLL of active connect requests.
int bi_directional
Should we try to create connections in both directions?
static unsigned int num_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)
Initiate a connection from p1 to p2 by offering p1 p2&#39;s HELLO message.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p2
Peer being connected.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cr
Connect request this is about.
#define GNUNET_log(kind,...)
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Overall context we are in.
struct GNUNET_TRANSPORT_TESTING_ConnectRequestList * crl_head
DLL of active connect requests.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_cb()

static void start_cb ( void *  cls)
static

Function called once we have successfully launched a peer.

Once all peers have been launched, we connect all of them in a clique.

Parameters
clsour struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *

Definition at line 402 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, GNUNET_TRANSPORT_TESTING_InternalPeerContext::ccc, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::connect_task, do_connect(), GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_UNIT_SECONDS, GNUNET_TRANSPORT_TESTING_PeerContext::id, GNUNET_TRANSPORT_TESTING_PeerContext::no, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::num_peers, GNUNET_TRANSPORT_TESTING_InternalPeerContext::off, p, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::pre_connect_task, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::pre_connect_task_cls, and GNUNET_TRANSPORT_TESTING_ConnectCheckContext::started.

Referenced by connect_check_run(), and GNUNET_TRANSPORT_TESTING_start_peer().

403 {
406  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off];
407 
408  ccc->started++;
410  "Peer %u (`%s') started\n",
411  p->no,
412  GNUNET_i2s (&p->id));
413  if (ccc->started != ccc->num_peers)
414  return;
415  if (NULL != ccc->pre_connect_task)
416  {
417  /* Run the custom per-connect job, then give it a second to
418  go into effect before we continue connecting peers. */
421  &do_connect,
422  ccc);
423  }
424  else
425  {
426  do_connect (ccc);
427  }
428 }
struct GNUNET_SCHEDULER_Task * connect_task
Task run to connect peers.
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
struct GNUNET_PeerIdentity id
Peer identity.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
#define GNUNET_TIME_UNIT_SECONDS
One second.
unsigned int num_peers
Number of peers involved in the test.
Context for a single peer.
unsigned int off
Offset of the peer this is about.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Overall context of the callback.
unsigned int no
An unique number to identify the peer.
static void do_connect(void *cls)
Connect the peers as a clique.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
void * pre_connect_task_cls
Closure for shutdown_task.
#define GNUNET_log(kind,...)
GNUNET_SCHEDULER_TaskCallback pre_connect_task
Custom task to run after peers were started but before we try to connect them.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
unsigned int started
Number of peers that have been started.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_check_run()

static void connect_check_run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Function run from GNUNET_TRANSPORT_TESTING_connect_check once the scheduler is up.

Should launch the peers and then in the continuations try to connect them.

Parameters
clsour struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *
argsignored
cfgfileignored
cfgconfiguration

Definition at line 442 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, cfg, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cfg, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cfg_files, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::cls, do_shutdown(), do_timeout(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_ConnectCheckContext::ip, my_nc(), my_nd(), GNUNET_TRANSPORT_TESTING_ConnectCheckContext::num_peers, ok, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, start_cb(), GNUNET_TRANSPORT_TESTING_ConnectCheckContext::timeout, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::timeout_task, and GNUNET_TRANSPORT_TESTING_ConnectCheckContext::tth.

Referenced by GNUNET_TRANSPORT_TESTING_connect_check().

446 {
448  int ok;
449 
450  ccc->cfg = cfg;
452  &do_timeout,
453  ccc);
455  ccc);
456  ok = GNUNET_OK;
457  for (unsigned int i = 0; i < ccc->num_peers; i++)
458  {
460  GNUNET_MQ_hd_var_size (test,
463  NULL),
464  GNUNET_MQ_hd_var_size (test2,
467  NULL),
469  };
470  ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth,
471  ccc->cfg_files[i],
472  i + 1,
473  handlers,
474  &my_nc,
475  &my_nd,
476  &ccc->ip[i],
477  &start_cb,
478  &ccc->ip[i]);
479  if (NULL == ccc->p[i])
480  ok = GNUNET_SYSERR;
481  }
482  if (GNUNET_OK != ok)
483  {
485  "Fail! Could not start peers!\n");
487  }
488 }
static void my_nd(void *cls, const struct GNUNET_PeerIdentity *peer, void *custom_cls)
Wrapper around peers disconnecting.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
unsigned int num_peers
Number of peers involved in the test.
static void do_shutdown(void *cls)
Shutdown function for the test.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Main testing handle.
static int ok
Return value from &#39;main&#39; (0 == success)
char ** cfg_files
Configuration files we have, array with num_peers entries.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration object for the testcase.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void * cls
Closure for rec, nc and nd.
static void do_timeout(void *cls)
Testcase hit timeout, shut it down with error.
Message handler for a specific message type.
struct GNUNET_TRANSPORT_TESTING_InternalPeerContext * ip
Array with num_peers entries.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
Alternative message type for tests.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_TIME_Relative timeout
When should the testcase time out?
static void * my_nc(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Wrapper around peers connecting.
#define GNUNET_log(kind,...)
static void start_cb(void *cls)
Function called once we have successfully launched a peer.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout.
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.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 507 of file transport-testing-main.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequestList::ccc, 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, p, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::test_name, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::test_plugin, and GNUNET_TRANSPORT_TESTING_ConnectCheckContext::tth.

514 {
515  static struct GNUNET_GETOPT_CommandLineOption options[] = {
517  };
521  char *argv[] = {
522  (char *) test_name_,
523  "-c",
524  (char *) ccc->config_file,
525  NULL
526  };
527 
528  ccc->num_peers = num_peers;
529  ccc->cfg_files = cfg_files;
530  ccc->test_plugin = test_plugin_;
531  ccc->test_name = test_name_;
532  ccc->tth = tth_;
533  ccc->global_ret = GNUNET_OK;
534  ccc->p = p;
535  ccc->ip = ip;
536  for (unsigned int i = 0; i < num_peers; i++)
537  {
538  ip[i].off = i;
539  ip[i].ccc = ccc;
540  }
541  if (GNUNET_OK !=
542  GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
543  argv,
544  test_name_,
545  "nohelp",
546  options,
548  ccc))
549  return GNUNET_SYSERR;
550  return ccc->global_ret;
551 }
int global_ret
Result from the main function, set to GNUNET_OK on success.
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
const char * test_name
Name of the testcase.
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
unsigned int num_peers
Number of peers involved in the test.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Main testing handle.
Context for a single peer.
char ** cfg_files
Configuration files we have, array with num_peers entries.
unsigned int off
Offset of the peer this is about.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Overall context of the callback.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
void * cls
Closure for rec, nc and nd.
const char * config_file
Which configuration file should we pass to the GNUNET_PROGRAM_run() of the testcase?
const char * test_plugin
Name of the plugin.
struct GNUNET_TRANSPORT_TESTING_InternalPeerContext * ip
Array with num_peers entries.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int num_peers
int 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, parse options).
Definition: program.c:367
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.
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 565 of file transport-testing-main.c.

References GNUNET_free, GNUNET_free_non_null, 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.

570 {
572  char *test_name;
573  char *test_source;
574  char *test_plugin;
575  char *cfg_names[num_peers];
576  int ret;
577 
578  ret = GNUNET_OK;
579  test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0);
580  GNUNET_log_setup (test_name,
581  "WARNING",
582  NULL);
585  test_source);
586  for (unsigned int i = 0; i < num_peers; i++)
587  cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name (argv0,
588  i + 1);
590  if (NULL == tth)
591  {
592  ret = GNUNET_SYSERR;
593  }
594  else
595  {
596  ret = check (check_cls,
597  tth,
598  test_plugin,
599  test_name,
600  num_peers,
601  cfg_names);
603  }
604  for (unsigned int i = 0; i < num_peers; i++)
605  GNUNET_free (cfg_names[i]);
606  GNUNET_free (test_source);
607  GNUNET_free_non_null (test_plugin);
608  GNUNET_free (test_name);
609  return ret;
610 }
struct GNUNET_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init()
Initialize the transport testing.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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.
static char * filename
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int num_peers
char * GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file)
Extracts the filename from an absolute file name and removes the extension.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count)
This function takes the filename (e.g.
Here is the call graph for this function: