GNUnet 0.22.2
testbed_test.c
Go to the documentation of this file.
1#include "platform.h"
2#include <unistd.h>
3#include <gnunet/platform.h>
4#include <gnunet/gnunet_util_lib.h>
5#include <gnunet/gnunet_testbed_service.h>
6#include <gnunet/gnunet_dht_service.h>
7
8#define NUM_PEERS 20
9
10static struct GNUNET_TESTBED_Operation *dht_op;
11
13
14
16{
17 int ht_len;
19
20
21static int result;
22
23
24static void
25shutdown_task (void *cls)
26{
27 if (NULL != dht_op)
28 {
29 GNUNET_TESTBED_operation_done (dht_op);
30 dht_op = NULL;
31 dht_handle = NULL;
32 }
34}
35
36
37static void
39 struct GNUNET_TESTBED_Operation *op,
40 void *ca_result,
41 const char *emsg)
42{
44 dht_handle = ca_result;
45 // Do work here...
47}
48
49
50static void *
51dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
52{
53 struct MyContext *ctxt = cls;
54
56 return dht_handle;
57}
58
59
60static void
61dht_da (void *cls, void *op_result)
62{
63 struct MyContext *ctxt = cls;
64
65 GNUNET_DHT_disconnect ((struct GNUNET_DHT_Handle *) op_result);
66 dht_handle = NULL;
67}
68
69
70static void
71test_master (void *cls,
72 struct GNUNET_TESTBED_RunHandle *h,
73 unsigned int num_peers,
74 struct GNUNET_TESTBED_Peer **peers,
75 unsigned int links_succeeded,
76 unsigned int links_failed)
77{
78 ctxt.ht_len = 10;
79 dht_op = GNUNET_TESTBED_service_connect
80 (NULL, peers[0], "dht",
82 &dht_ca, &dht_da, &ctxt);
84}
85
86
87int
88main (int argc, char **argv)
89{
90 int ret;
91
93 ret = GNUNET_TESTBED_test_run
94 ("awesome-test", "template.conf",
95 NUM_PEERS, 0LL,
96 NULL, NULL, &test_master, NULL);
97 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
98 return 1;
99 return 0;
100}
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:143
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
static unsigned int num_peers
Number of peers.
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:1030
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:1053
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
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,...
Definition: scheduler.c:1339
Connection to the DHT service.
Definition: dht_api.c:235
struct MyContext ctxt
#define NUM_PEERS
Definition: testbed_test.c:8
int main(int argc, char **argv)
Definition: testbed_test.c:88
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:71
static void shutdown_task(void *cls)
Definition: testbed_test.c:25
static struct GNUNET_DHT_Handle * dht_handle
Definition: testbed_test.c:12
static int result
Definition: testbed_test.c:21
static void dht_da(void *cls, void *op_result)
Definition: testbed_test.c:61
static void * dht_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Definition: testbed_test.c:51
static void service_connect_comp(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Definition: testbed_test.c:38
static struct GNUNET_TESTBED_Operation * dht_op
Definition: testbed_test.c:10