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.

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 
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 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
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:910
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 incoming MQ-based channels.
Definition: cadet_api.c:970
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
Opaque handle to the service.
Definition: cadet_api.c:39
Opaque handle to a port.
Definition: cadet_api.c:80
Context for a cadet adapter callback.
struct GNUNET_CADET_TEST_Context * ctx
General context.
unsigned int peer
Peer number for the particular peer.
struct GNUNET_CADET_Port ** ports
Port handlers for open ports.
Test context for a CADET Test.

References cfg, GNUNET_CADET_TEST_AdapterContext::ctx, ctx, GNUNET_break, GNUNET_CADET_connect(), GNUNET_CADET_open_port(), GNUNET_new_array, h, GNUNET_CADET_TEST_AdapterContext::peer, and GNUNET_CADET_TEST_AdapterContext::ports.

Referenced by cadet_test_run().

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.

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);
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:775
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port().
Definition: cadet_api.c:808
#define GNUNET_free(ptr)
Wrapper around free.
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.

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

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.

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 }
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_INFO
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531

References ctx, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_shutdown(), and op.

Referenced by cadet_test_run().

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.

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 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:2045

References ctx, GNUNET_assert, GNUNET_free, GNUNET_SCHEDULER_shutdown(), and GNUNET_TESTBED_operation_done().

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

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.

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);
308  peers[i],
309  "cadet",
311  ctx,
314  newctx);
316  "op handle %p\n",
317  ctx->ops[i]);
318  }
319 }
static void cadet_disconnect_adapter(void *cls, void *op_result)
Adapter function called to destroy a connection to the CADET service.
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 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.
static struct CadetPeer * peers
Operation to get peer ids.
static unsigned int num_peers
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.

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

Referenced by GNUNET_CADET_TEST_ruN().

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.

348 {
350 
352  ctx->num_peers = num_peers;
354  struct GNUNET_TESTBED_Operation *);
355  ctx->cadets = GNUNET_new_array (num_peers,
356  struct GNUNET_CADET_Handle *);
357  ctx->app_main = tmain;
358  ctx->app_main_cls = tmain_cls;
359  ctx->connects = connects;
360  ctx->window_changes = window_changes;
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 }
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 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)
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
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:1231
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 'main'.
GNUNET_CADET_WindowSizeEventHandler window_changes
Function called when the transmit window size changes.
const struct GNUNET_HashCode ** ports
Application ports.
Opaque handle to an abstract operation to be executed by the testing framework.

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

Here is the call graph for this function: