GNUnet  0.10.x
Data Structures | Functions
dht_test_lib.c File Reference

library for writing DHT tests More...

#include "platform.h"
#include "dht_test_lib.h"
Include dependency graph for dht_test_lib.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_DHT_TEST_Context
 Test context for a DHT Test. More...
 

Functions

static void * dht_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Adapter function called to establish a connection to the DHT service. More...
 
static void dht_disconnect_adapter (void *cls, void *op_result)
 Adapter function called to destroy a connection to the DHT service. More...
 
static void dht_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_DHT_TEST_cleanup (struct GNUNET_DHT_TEST_Context *ctx)
 Clean up the testbed. More...
 
static void dht_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)
 
void GNUNET_DHT_TEST_run (const char *testname, const char *cfgname, unsigned int num_peers, GNUNET_DHT_TEST_AppMain tmain, void *tmain_cls)
 Run a test using the given name, configuration file and number of peers. More...
 

Detailed Description

library for writing DHT tests

Author
Christian Grothoff

Definition in file dht_test_lib.c.

Function Documentation

◆ dht_connect_adapter()

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

Adapter function called to establish a connection to the DHT 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 75 of file dht_test_lib.c.

References GNUNET_DHT_connect().

Referenced by dht_test_run().

77 {
78  return GNUNET_DHT_connect(cfg, 16);
79 }
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
Definition: dht_api.c:885
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dht_disconnect_adapter()

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

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

Parameters
clsclosure
op_resultservice handle returned from the connect adapter

Definition at line 90 of file dht_test_lib.c.

References dht, GNUNET_DHT_disconnect(), and op_result().

Referenced by dht_test_run().

92 {
94 
96 }
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
Connection to the DHT service.
Definition: dht_api.c:198
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:913
static struct GNUNET_DHT_Handle * dht
Handle to the DHT.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dht_connect_cb()

static void dht_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()
emsgerror message in case the operation has failed; will be NULL if operation has executed successfully.

Definition at line 109 of file dht_test_lib.c.

References GNUNET_DHT_TEST_Context::app_main, GNUNET_DHT_TEST_Context::app_main_cls, ctx, GNUNET_DHT_TEST_Context::dhts, GNUNET_SCHEDULER_shutdown(), GNUNET_DHT_TEST_Context::num_peers, GNUNET_DHT_TEST_Context::ops, and GNUNET_DHT_TEST_Context::peers.

Referenced by dht_test_run().

113 {
114  struct GNUNET_DHT_TEST_Context *ctx = cls;
115 
116  if (NULL != emsg)
117  {
118  fprintf(stderr,
119  "Failed to connect to DHT service: %s\n",
120  emsg);
122  return;
123  }
124  for (unsigned int i = 0; i < ctx->num_peers; i++)
125  if (op == ctx->ops[i])
126  ctx->dhts[i] = ca_result;
127  for (unsigned int i = 0; i < ctx->num_peers; i++)
128  if (NULL == ctx->dhts[i])
129  return;
130  /* still some DHT connections missing */
131  /* all DHT connections ready! */
132  ctx->app_main(ctx->app_main_cls,
133  ctx,
134  ctx->num_peers,
135  ctx->peers,
136  ctx->dhts);
137 }
unsigned int num_peers
Number of peers running, size of the arrays above.
Definition: dht_test_lib.c:60
Test context for a DHT Test.
Definition: dht_test_lib.c:31
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.
struct GNUNET_TESTBED_Peer ** peers
Array of running peers.
Definition: dht_test_lib.c:35
struct GNUNET_DHT_Handle ** dhts
Array of handles to the DHT for each peer.
Definition: dht_test_lib.c:40
void * app_main_cls
Closure for &#39;app_main&#39;.
Definition: dht_test_lib.c:55
struct GNUNET_TESTBED_Operation ** ops
Operation associated with the connection to the DHT.
Definition: dht_test_lib.c:45
GNUNET_DHT_TEST_AppMain app_main
Main function of the test to run once all DHTs are available.
Definition: dht_test_lib.c:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DHT_TEST_cleanup()

void GNUNET_DHT_TEST_cleanup ( struct GNUNET_DHT_TEST_Context ctx)

Clean up the testbed.

Parameters
ctxhandle for the testbed

Definition at line 146 of file dht_test_lib.c.

References GNUNET_DHT_TEST_Context::dhts, GNUNET_free, GNUNET_SCHEDULER_shutdown(), GNUNET_TESTBED_operation_done(), GNUNET_DHT_TEST_Context::num_peers, and GNUNET_DHT_TEST_Context::ops.

147 {
148  for (unsigned int i = 0; i < ctx->num_peers; i++)
150  GNUNET_free(ctx->ops);
151  GNUNET_free(ctx->dhts);
152  GNUNET_free(ctx);
154 }
unsigned int num_peers
Number of peers running, size of the arrays above.
Definition: dht_test_lib.c:60
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
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
struct GNUNET_DHT_Handle ** dhts
Array of handles to the DHT for each peer.
Definition: dht_test_lib.c:40
struct GNUNET_TESTBED_Operation ** ops
Operation associated with the connection to the DHT.
Definition: dht_test_lib.c:45
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ dht_test_run()

static void dht_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

Definition at line 158 of file dht_test_lib.c.

References ctx, dht_connect_adapter(), dht_connect_cb(), dht_disconnect_adapter(), GNUNET_assert, GNUNET_TESTBED_service_connect(), GNUNET_DHT_TEST_Context::num_peers, GNUNET_DHT_TEST_Context::ops, and GNUNET_DHT_TEST_Context::peers.

Referenced by GNUNET_DHT_TEST_run().

164 {
165  struct GNUNET_DHT_TEST_Context *ctx = cls;
166 
168  ctx->peers = peers;
169  for (unsigned int i = 0; i < num_peers; i++)
170  ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx,
171  peers[i],
172  "dht",
174  ctx,
177  ctx);
178 }
unsigned int num_peers
Number of peers running, size of the arrays above.
Definition: dht_test_lib.c:60
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Test context for a DHT Test.
Definition: dht_test_lib.c:31
static void dht_disconnect_adapter(void *cls, void *op_result)
Adapter function called to destroy a connection to the DHT service.
Definition: dht_test_lib.c:90
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static void * dht_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to the DHT service.
Definition: dht_test_lib.c:75
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.
struct GNUNET_TESTBED_Peer ** peers
Array of running peers.
Definition: dht_test_lib.c:35
static unsigned int num_peers
static void dht_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.
Definition: dht_test_lib.c:109
static struct CadetPeer * peers
Operation to get peer ids.
struct GNUNET_TESTBED_Operation ** ops
Operation associated with the connection to the DHT.
Definition: dht_test_lib.c:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DHT_TEST_run()

void GNUNET_DHT_TEST_run ( const char *  testname,
const char *  cfgname,
unsigned int  num_peers,
GNUNET_DHT_TEST_AppMain  tmain,
void *  tmain_cls 
)

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

Parameters
testnamename of the test (for logging)
cfgnamename of the configuration file
num_peersnumber of peers to start
tmainmain function to run once the testbed is ready
tmain_clsclosure for 'tmain'

Definition at line 192 of file dht_test_lib.c.

References GNUNET_DHT_TEST_Context::app_main, GNUNET_DHT_TEST_Context::app_main_cls, ctx, dht_test_run(), GNUNET_DHT_TEST_Context::dhts, GNUNET_new, GNUNET_new_array, GNUNET_TESTBED_test_run(), GNUNET_DHT_TEST_Context::num_peers, GNUNET_DHT_TEST_Context::ops, and tmain().

197 {
199 
200  ctx = GNUNET_new(struct GNUNET_DHT_TEST_Context);
201  ctx->num_peers = num_peers;
203  struct GNUNET_TESTBED_Operation *);
205  struct GNUNET_DHT_Handle *);
206  ctx->app_main = tmain;
207  ctx->app_main_cls = tmain_cls;
208  (void)GNUNET_TESTBED_test_run(testname,
209  cfgname,
210  num_peers,
211  0LL, NULL, NULL,
212  &dht_test_run, ctx);
213 }
static void dht_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)
Definition: dht_test_lib.c:158
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;...
unsigned int num_peers
Number of peers running, size of the arrays above.
Definition: dht_test_lib.c:60
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Test context for a DHT Test.
Definition: dht_test_lib.c:31
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
Connection to the DHT service.
Definition: dht_api.c:198
Opaque handle to an abstract operation to be executed by the testing framework.
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
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
static unsigned int num_peers
struct GNUNET_DHT_Handle ** dhts
Array of handles to the DHT for each peer.
Definition: dht_test_lib.c:40
void * app_main_cls
Closure for &#39;app_main&#39;.
Definition: dht_test_lib.c:55
struct GNUNET_TESTBED_Operation ** ops
Operation associated with the connection to the DHT.
Definition: dht_test_lib.c:45
GNUNET_DHT_TEST_AppMain app_main
Main function of the test to run once all DHTs are available.
Definition: dht_test_lib.c:50
Here is the call graph for this function: