GNUnet  0.11.x
Data Structures | Functions
cadet_test_lib.c File Reference

library for writing CADET tests More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "cadet_test_lib.h"
#include "gnunet_cadet_service.h"
Include dependency graph for cadet_test_lib.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CADET_TEST_Context
 Test context for a CADET Test. More...
 
struct  GNUNET_CADET_TEST_AdapterContext
 Context for a cadet adapter callback. More...
 

Functions

static void * cadet_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Adapter function called to establish a connection to the CADET service. More...
 
static void cadet_disconnect_adapter (void *cls, void *op_result)
 Adapter function called to destroy a connection to the CADET service. More...
 
static void cadet_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
 Callback to be called when a service connect operation is completed. More...
 
void GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx)
 Clean up the testbed. More...
 
static void cadet_test_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, unsigned int links_failed)
 Callback run when the testbed is ready (peers running and connected to each other) More...
 
void GNUNET_CADET_TEST_ruN (const char *testname, const char *cfgfile, unsigned int num_peers, GNUNET_CADET_TEST_AppMain tmain, void *tmain_cls, GNUNET_CADET_ConnectEventHandler connects, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_HashCode **ports)
 Run a test using the given name, configuration file and number of peers. More...
 

Detailed Description

library for writing CADET tests

Author
Bartlomiej Polot

Definition in file cadet_test_lib.c.

Function Documentation

◆ cadet_connect_adapter()

static void* cadet_connect_adapter ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Adapter function called to establish a connection to the CADET service.

Parameters
clsclosure
cfgconfiguration of the peer to connect to; will be available until GNUNET_TESTBED_operation_done() is called on the operation returned from GNUNET_TESTBED_service_connect()
Returns
service handle to return in 'op_result', NULL on error

Definition at line 131 of file cadet_test_lib.c.

References GNUNET_CADET_TEST_Context::connects, ctx, GNUNET_CADET_TEST_AdapterContext::ctx, GNUNET_CADET_TEST_Context::disconnects, GNUNET_break, GNUNET_CADET_connect(), GNUNET_CADET_open_port(), GNUNET_new_array, h, GNUNET_CADET_TEST_Context::handlers, GNUNET_CADET_TEST_AdapterContext::peer, GNUNET_CADET_TEST_Context::port_count, GNUNET_CADET_TEST_Context::ports, GNUNET_CADET_TEST_AdapterContext::ports, and GNUNET_CADET_TEST_Context::window_changes.

Referenced by cadet_test_run().

133 {
134  struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
135  struct GNUNET_CADET_TEST_Context *ctx = actx->ctx;
136  struct GNUNET_CADET_Handle *h;
137 
138  h = GNUNET_CADET_connect (cfg);
139  if (NULL == h)
140  {
141  GNUNET_break (0);
142  return NULL;
143  }
144  if (NULL == ctx->ports)
145  return h;
146  actx->ports = GNUNET_new_array (ctx->port_count,
147  struct GNUNET_CADET_Port *);
148  for (unsigned int i = 0; i < ctx->port_count; i++)
149  {
150  actx->ports[i] = GNUNET_CADET_open_port (h,
151  ctx->ports[i],
152  ctx->connects,
153  (void *) (long) actx->peer,
154  ctx->window_changes,
155  ctx->disconnects,
156  ctx->handlers);
157  }
158  return h;
159 }
Context for a cadet adapter callback.
Opaque handle to the service.
Definition: cadet_api.c:38
GNUNET_CADET_ConnectEventHandler connects
Handler for incoming tunnels.
Test context for a CADET Test.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition: cadet_api.c:976
GNUNET_CADET_DisconnectEventHandler disconnects
Cleaner for destroyed incoming tunnels.
struct GNUNET_MQ_MessageHandler * handlers
Message handlers.
GNUNET_CADET_WindowSizeEventHandler window_changes
Function called when the transmit window size changes.
struct GNUNET_CADET_Port * GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *port, GNUNET_CADET_ConnectEventHandler connects, void *connects_cls, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Open a port to receive incomming MQ-based channels.
Definition: cadet_api.c:1010
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
unsigned int peer
Peer number for the particular peer.
const struct GNUNET_HashCode ** ports
Application ports.
unsigned int port_count
Number of ports in ports.
struct GNUNET_CADET_TEST_Context * ctx
General context.
struct GNUNET_CADET_Port ** ports
Port handlers for open ports.
Opaque handle to a port.
Definition: cadet_api.c:145
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadet_disconnect_adapter()

static void cadet_disconnect_adapter ( void *  cls,
void *  op_result 
)
static

Adapter function called to destroy a connection to the CADET service.

Parameters
clsclosure
op_resultservice handle returned from the connect adapter

Definition at line 170 of file cadet_test_lib.c.

References cadet, GNUNET_CADET_TEST_AdapterContext::ctx, GNUNET_CADET_close_port(), GNUNET_CADET_disconnect(), GNUNET_free, op_result(), GNUNET_CADET_TEST_Context::port_count, and GNUNET_CADET_TEST_AdapterContext::ports.

Referenced by cadet_test_run().

172 {
174  struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
175 
176  if (NULL != actx->ports)
177  {
178  for (unsigned int i = 0; i < actx->ctx->port_count; i++)
179  {
180  GNUNET_CADET_close_port (actx->ports[i]);
181  actx->ports[i] = NULL;
182  }
183  GNUNET_free (actx->ports);
184  }
185  GNUNET_free (actx);
186  GNUNET_CADET_disconnect (cadet);
187 }
static struct GNUNET_CADET_Handle * cadet
Handle for cadet.
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:841
Context for a cadet adapter callback.
Opaque handle to the service.
Definition: cadet_api.c:38
static int op_result(struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx, uint8_t cancel)
Remove an operation, and call its result callback (unless it was cancelled).
Definition: op.c:245
unsigned int port_count
Number of ports in ports.
struct GNUNET_CADET_TEST_Context * ctx
General context.
struct GNUNET_CADET_Port ** ports
Port handlers for open ports.
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port().
Definition: cadet_api.c:874
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadet_connect_cb()

static void cadet_connect_cb ( void *  cls,
struct GNUNET_TESTBED_Operation op,
void *  ca_result,
const char *  emsg 
)
static

Callback to be called when a service connect operation is completed.

Parameters
clsThe callback closure from functions generating an operation.
opThe operation that has been finished.
ca_resultThe service handle returned from GNUNET_TESTBED_ConnectAdapter() (cadet handle).
emsgError message in case the operation has failed. NULL if operation has executed successfully.

Definition at line 201 of file cadet_test_lib.c.

References GNUNET_CADET_TEST_Context::app_main, GNUNET_CADET_TEST_Context::app_main_cls, GNUNET_CADET_TEST_Context::cadets, ctx, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_shutdown(), GNUNET_CADET_TEST_Context::num_peers, GNUNET_CADET_TEST_Context::ops, and GNUNET_CADET_TEST_Context::peers.

Referenced by cadet_test_run().

205 {
206  struct GNUNET_CADET_TEST_Context *ctx = cls;
207 
208  if (NULL != emsg)
209  {
210  fprintf (stderr,
211  "Failed to connect to CADET service: %s\n",
212  emsg);
214  return;
215  }
216  for (unsigned int i = 0; i < ctx->num_peers; i++)
217  if (op == ctx->ops[i])
218  {
219  ctx->cadets[i] = ca_result;
221  "...cadet %u connected\n",
222  i);
223  }
224  for (unsigned int i = 0; i < ctx->num_peers; i++)
225  if (NULL == ctx->cadets[i])
226  return;
227  /* still some CADET connections missing */
228  /* all CADET connections ready! */
229  ctx->app_main (ctx->app_main_cls,
230  ctx,
231  ctx->num_peers,
232  ctx->peers,
233  ctx->cadets);
234 }
struct GNUNET_TESTBED_Operation ** ops
Operation associated with the connection to the CADET.
struct GNUNET_TESTBED_Peer ** peers
Array of running peers.
struct GNUNET_CADET_Handle ** cadets
Array of handles to the CADET for each peer.
Test context for a CADET Test.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
unsigned int num_peers
Number of peers running, size of the arrays above.
#define GNUNET_log(kind,...)
void * app_main_cls
Closure for &#39;app_main&#39;.
GNUNET_CADET_TEST_AppMain app_main
Main function of the test to run once all CADETs are available.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CADET_TEST_cleanup()

void GNUNET_CADET_TEST_cleanup ( struct GNUNET_CADET_TEST_Context ctx)

Clean up the testbed.

Parameters
ctxhandle for the testbed

Definition at line 238 of file cadet_test_lib.c.

References GNUNET_CADET_TEST_Context::cadets, GNUNET_assert, GNUNET_free, GNUNET_SCHEDULER_shutdown(), GNUNET_TESTBED_operation_done(), GNUNET_CADET_TEST_Context::handlers, GNUNET_CADET_TEST_Context::num_peers, and GNUNET_CADET_TEST_Context::ops.

Referenced by disconnect_cadet_peers(), start_test(), and warmup().

239 {
240  for (unsigned int i = 0; i < ctx->num_peers; i++)
241  {
242  GNUNET_assert (NULL != ctx->ops[i]);
244  ctx->ops[i] = NULL;
245  }
246  GNUNET_free (ctx->ops);
247  GNUNET_free (ctx->cadets);
248  GNUNET_free (ctx->handlers);
249  GNUNET_free (ctx);
251 }
struct GNUNET_TESTBED_Operation ** ops
Operation associated with the connection to the CADET.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CADET_Handle ** cadets
Array of handles to the CADET for each peer.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
struct GNUNET_MQ_MessageHandler * handlers
Message handlers.
unsigned int num_peers
Number of peers running, size of the arrays above.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2044
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadet_test_run()

static void cadet_test_run ( void *  cls,
struct GNUNET_TESTBED_RunHandle h,
unsigned int  num_peers,
struct GNUNET_TESTBED_Peer **  peers,
unsigned int  links_succeeded,
unsigned int  links_failed 
)
static

Callback run when the testbed is ready (peers running and connected to each other)

Parameters
clsClosure (context).
hthe run handle
num_peersNumber of peers that are running.
peersHandles to each one of the num_peers peers.
links_succeededthe number of overlay link connection attempts that succeeded
links_failedthe number of overlay link connection attempts that failed

Definition at line 268 of file cadet_test_lib.c.

References cadet_connect_adapter(), cadet_connect_cb(), cadet_disconnect_adapter(), ctx, GNUNET_CADET_TEST_AdapterContext::ctx, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_new, GNUNET_TESTBED_service_connect(), GNUNET_CADET_TEST_Context::num_peers, GNUNET_CADET_TEST_Context::ops, GNUNET_CADET_TEST_AdapterContext::peer, and GNUNET_CADET_TEST_Context::peers.

Referenced by GNUNET_CADET_TEST_ruN().

274 {
275  struct GNUNET_CADET_TEST_Context *ctx = cls;
276 
277  if (0 != links_failed)
278  {
280  "Some links failed (%u), ending\n",
281  links_failed);
282  exit (77);
283  }
284  if (num_peers != ctx->num_peers)
285  {
287  "Peers started %u/%u, ending\n",
288  num_peers,
289  ctx->num_peers);
290  exit (1);
291  }
293  "Testbed up, %u peers and %u links\n",
294  num_peers,
295  links_succeeded);
296  ctx->peers = peers;
297  for (unsigned int i = 0; i < num_peers; i++)
298  {
299  struct GNUNET_CADET_TEST_AdapterContext *newctx;
300 
302  newctx->peer = i;
303  newctx->ctx = ctx;
305  "Connecting to cadet %u\n",
306  i);
307  ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx,
308  peers[i],
309  "cadet",
311  ctx,
314  newctx);
316  "op handle %p\n",
317  ctx->ops[i]);
318  }
319 }
static void cadet_connect_cb(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Callback to be called when a service connect operation is completed.
struct GNUNET_TESTBED_Operation ** ops
Operation associated with the connection to the CADET.
struct GNUNET_TESTBED_Peer ** peers
Array of running peers.
Context for a cadet adapter callback.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Test context for a CADET Test.
static void * cadet_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to the CADET service.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_ServiceConnectCompletionCallback cb, void *cb_cls, GNUNET_TESTBED_ConnectAdapter ca, GNUNET_TESTBED_DisconnectAdapter da, void *cada_cls)
Connect to a service offered by the given peer.
unsigned int num_peers
Number of peers running, size of the arrays above.
unsigned int peer
Peer number for the particular peer.
struct GNUNET_CADET_TEST_Context * ctx
General context.
static unsigned int num_peers
static void cadet_disconnect_adapter(void *cls, void *op_result)
Adapter function called to destroy a connection to the CADET service.
static struct CadetPeer * peers
Operation to get peer ids.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CADET_TEST_ruN()

void GNUNET_CADET_TEST_ruN ( const char *  testname,
const char *  cfgfile,
unsigned int  num_peers,
GNUNET_CADET_TEST_AppMain  tmain,
void *  tmain_cls,
GNUNET_CADET_ConnectEventHandler  connects,
GNUNET_CADET_WindowSizeEventHandler  window_changes,
GNUNET_CADET_DisconnectEventHandler  disconnects,
struct GNUNET_MQ_MessageHandler handlers,
const struct GNUNET_HashCode **  ports 
)

Run a test using the given name, configuration file and number of peers.

All cadet callbacks will receive the peer number (long) as the closure.

Parameters
testnameName of the test (for logging).
cfgfileName of the configuration file.
num_peersNumber of peers to start.
tmainMain function to run once the testbed is ready.
tmain_clsClosure for tmain.
connectsHandler for incoming channels.
window_changesHandler for the window size change notification.
disconnectsCleaner for destroyed incoming channels.
handlersMessage handlers.
portsPorts the peers offer, NULL-terminated.

Definition at line 338 of file cadet_test_lib.c.

References GNUNET_CADET_TEST_Context::app_main, GNUNET_CADET_TEST_Context::app_main_cls, cadet_test_run(), GNUNET_CADET_TEST_Context::cadets, GNUNET_CADET_TEST_Context::connects, ctx, GNUNET_CADET_TEST_Context::disconnects, GNUNET_MQ_copy_handlers(), GNUNET_new, GNUNET_new_array, GNUNET_TESTBED_test_run(), GNUNET_CADET_TEST_Context::handlers, GNUNET_CADET_TEST_Context::num_peers, GNUNET_CADET_TEST_Context::ops, GNUNET_CADET_TEST_Context::port_count, GNUNET_CADET_TEST_Context::ports, tmain(), and GNUNET_CADET_TEST_Context::window_changes.

348 {
350 
351  ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context);
352  ctx->num_peers = num_peers;
354  struct GNUNET_TESTBED_Operation *);
356  struct GNUNET_CADET_Handle *);
357  ctx->app_main = tmain;
358  ctx->app_main_cls = tmain_cls;
359  ctx->connects = connects;
361  ctx->disconnects = disconnects;
362  ctx->handlers = GNUNET_MQ_copy_handlers (handlers);
363  ctx->ports = ports;
364  ctx->port_count = 0;
365  while (NULL != ctx->ports[ctx->port_count])
366  ctx->port_count++;
367  GNUNET_TESTBED_test_run (testname,
368  cfgfile,
369  num_peers,
370  0LL, NULL, NULL,
372  ctx);
373 }
struct GNUNET_TESTBED_Operation ** ops
Operation associated with the connection to the CADET.
Opaque handle to the service.
Definition: cadet_api.c:38
int GNUNET_TESTBED_test_run(const char *testname, const char *cfg_filename, unsigned int num_peers, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, GNUNET_TESTBED_TestMaster test_master, void *test_master_cls)
Convenience method for running a "simple" test on the local system with a single call from &#39;main&#39;...
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:1214
struct GNUNET_CADET_Handle ** cadets
Array of handles to the CADET for each peer.
GNUNET_CADET_ConnectEventHandler connects
Handler for incoming tunnels.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Test context for a CADET Test.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
Opaque handle to an abstract operation to be executed by the testing framework.
GNUNET_CADET_DisconnectEventHandler disconnects
Cleaner for destroyed incoming tunnels.
struct GNUNET_MQ_MessageHandler * handlers
Message handlers.
static void tmain(void *cls, struct GNUNET_CADET_TEST_Context *ctx, unsigned int num_peers, struct GNUNET_TESTBED_Peer **testbed_peers, struct GNUNET_CADET_Handle **cadetes)
test main: start test when all peers are connected
GNUNET_CADET_WindowSizeEventHandler window_changes
Function called when the transmit window size changes.
unsigned int num_peers
Number of peers running, size of the arrays above.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
const struct GNUNET_HashCode ** ports
Application ports.
unsigned int port_count
Number of ports in ports.
void * connects(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Definition: 010.c:2
void disconnects(void *cls, const struct GNUNET_PeerIdentity *peer)
Definition: 011.c:2
static unsigned int num_peers
void * app_main_cls
Closure for &#39;app_main&#39;.
static void cadet_test_run(void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, unsigned int links_failed)
Callback run when the testbed is ready (peers running and connected to each other) ...
GNUNET_CADET_TEST_AppMain app_main
Main function of the test to run once all CADETs are available.
Here is the call graph for this function: