GNUnet  0.10.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 129 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().

131 {
132  struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
133  struct GNUNET_CADET_TEST_Context *ctx = actx->ctx;
134  struct GNUNET_CADET_Handle *h;
135 
136  h = GNUNET_CADET_connect(cfg);
137  if (NULL == h)
138  {
139  GNUNET_break(0);
140  return NULL;
141  }
142  if (NULL == ctx->ports)
143  return h;
144  actx->ports = GNUNET_new_array(ctx->port_count,
145  struct GNUNET_CADET_Port *);
146  for (unsigned int i = 0; i < ctx->port_count; i++)
147  {
148  actx->ports[i] = GNUNET_CADET_open_port(h,
149  ctx->ports[i],
150  ctx->connects,
151  (void *)(long)actx->peer,
152  ctx->window_changes,
153  ctx->disconnects,
154  ctx->handlers);
155  }
156  return h;
157 }
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:94
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:973
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:1007
#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:143
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 168 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().

170 {
172  struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
173 
174  if (NULL != actx->ports)
175  {
176  for (unsigned int i = 0; i < actx->ctx->port_count; i++)
177  {
178  GNUNET_CADET_close_port(actx->ports[i]);
179  actx->ports[i] = NULL;
180  }
181  GNUNET_free(actx->ports);
182  }
183  GNUNET_free(actx);
185 }
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:838
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:243
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:871
#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 199 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().

203 {
204  struct GNUNET_CADET_TEST_Context *ctx = cls;
205 
206  if (NULL != emsg)
207  {
208  fprintf(stderr,
209  "Failed to connect to CADET service: %s\n",
210  emsg);
212  return;
213  }
214  for (unsigned int i = 0; i < ctx->num_peers; i++)
215  if (op == ctx->ops[i])
216  {
217  ctx->cadets[i] = ca_result;
219  "...cadet %u connected\n",
220  i);
221  }
222  for (unsigned int i = 0; i < ctx->num_peers; i++)
223  if (NULL == ctx->cadets[i])
224  return;
225  /* still some CADET connections missing */
226  /* all CADET connections ready! */
227  ctx->app_main(ctx->app_main_cls,
228  ctx,
229  ctx->num_peers,
230  ctx->peers,
231  ctx->cadets);
232 }
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:517
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 236 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().

237 {
238  for (unsigned int i = 0; i < ctx->num_peers; i++)
239  {
240  GNUNET_assert(NULL != ctx->ops[i]);
242  ctx->ops[i] = NULL;
243  }
244  GNUNET_free(ctx->ops);
245  GNUNET_free(ctx->cadets);
246  GNUNET_free(ctx->handlers);
247  GNUNET_free(ctx);
249 }
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:517
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:2037
#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 266 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().

272 {
273  struct GNUNET_CADET_TEST_Context *ctx = cls;
274 
275  if (0 != links_failed)
276  {
278  "Some links failed (%u), ending\n",
279  links_failed);
280  exit(77);
281  }
282  if (num_peers != ctx->num_peers)
283  {
285  "Peers started %u/%u, ending\n",
286  num_peers,
287  ctx->num_peers);
288  exit(1);
289  }
291  "Testbed up, %u peers and %u links\n",
292  num_peers,
293  links_succeeded);
294  ctx->peers = peers;
295  for (unsigned int i = 0; i < num_peers; i++)
296  {
297  struct GNUNET_CADET_TEST_AdapterContext *newctx;
298 
300  newctx->peer = i;
301  newctx->ctx = ctx;
303  "Connecting to cadet %u\n",
304  i);
305  ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx,
306  peers[i],
307  "cadet",
309  ctx,
312  newctx);
314  "op handle %p\n",
315  ctx->ops[i]);
316  }
317 }
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 336 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.

346 {
348 
350  ctx->num_peers = num_peers;
352  struct GNUNET_TESTBED_Operation *);
354  struct GNUNET_CADET_Handle *);
355  ctx->app_main = tmain;
356  ctx->app_main_cls = tmain_cls;
357  ctx->connects = connects;
359  ctx->disconnects = disconnects;
360  ctx->handlers = GNUNET_MQ_copy_handlers(handlers);
361  ctx->ports = ports;
362  ctx->port_count = 0;
363  while (NULL != ctx->ports[ctx->port_count])
364  ctx->port_count++;
365  GNUNET_TESTBED_test_run(testname,
366  cfgfile,
367  num_peers,
368  0LL, NULL, NULL,
370  ctx);
371 }
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:1211
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: