GNUnet  0.11.x
testbed_test.c
Go to the documentation of this file.
1 #include <unistd.h>
2 #include <gnunet/platform.h>
3 #include <gnunet/gnunet_util_lib.h>
4 #include <gnunet/gnunet_testbed_service.h>
5 #include <gnunet/gnunet_dht_service.h>
6 
7 #define NUM_PEERS 20
8 
10 
12 
13 
14 struct MyContext
15 {
16  int ht_len;
17 } ctxt;
18 
19 
20 static int result;
21 
22 
23 static void
24 shutdown_task (void *cls)
25 {
26  if (NULL != dht_op)
27  {
29  dht_op = NULL;
30  dht_handle = NULL;
31  }
32  result = GNUNET_OK;
33 }
34 
35 
36 static void
39  void *ca_result,
40  const char *emsg)
41 {
42  GNUNET_assert (op == dht_op);
43  dht_handle = ca_result;
44  // Do work here...
46 }
47 
48 
49 static void *
50 dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
51 {
52  struct MyContext *ctxt = cls;
53 
54  dht_handle = GNUNET_DHT_connect (cfg, ctxt->ht_len);
55  return dht_handle;
56 }
57 
58 
59 static void
60 dht_da (void *cls, void *op_result)
61 {
62  struct MyContext *ctxt = cls;
63 
64  GNUNET_DHT_disconnect ((struct GNUNET_DHT_Handle *) op_result);
65  dht_handle = NULL;
66 }
67 
68 
69 static void
70 test_master (void *cls,
72  unsigned int num_peers,
73  struct GNUNET_TESTBED_Peer **peers,
74  unsigned int links_succeeded,
75  unsigned int links_failed)
76 {
77  ctxt.ht_len = 10;
79  (NULL, peers[0], "dht",
80  &service_connect_comp, NULL,
81  &dht_ca, &dht_da, &ctxt);
83 }
84 
85 
86 int
87 main (int argc, char **argv)
88 {
89  int ret;
90 
93  ("awesome-test", "template.conf",
94  NUM_PEERS, 0LL,
95  NULL, NULL, &test_master, NULL);
96  if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
97  return 1;
98  return 0;
99 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_TESTBED_Operation * dht_op
Definition: testbed_test.c:9
static void * dht_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Definition: testbed_test.c:50
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
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;...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void test_master(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: testbed_test.c:70
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
struct MyContext ctxt
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
static void service_connect_comp(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Definition: testbed_test.c:37
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Connection to the DHT service.
Definition: dht_api.c:201
Opaque handle to an abstract operation to be executed by the testing framework.
int main(int argc, char **argv)
Definition: testbed_test.c:87
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.
static struct GNUNET_DHT_Handle * dht_handle
Definition: testbed_test.c:11
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
static void dht_da(void *cls, void *op_result)
Definition: testbed_test.c:60
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static void shutdown_task(void *cls)
Definition: testbed_test.c:24
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:890
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:918
static unsigned int num_peers
configuration data
Definition: configuration.c:85
#define NUM_PEERS
Definition: testbed_test.c:7
static struct CadetPeer * peers
Operation to get peer ids.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static int result
Definition: testbed_test.c:20
A peer controlled by the testing framework.