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>
7 /* Number of peers we want to start */
10 struct GNUNET_TESTBED_Operation *dht_op;
12 struct GNUNET_DHT_Handle *dht_handle;
14 GNUNET_SCHEDULER_TaskIdentifier shutdown_tid;
24 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
26 shutdown_tid = GNUNET_SCHEDULER_NO_TASK;
29 GNUNET_TESTBED_operation_done (dht_op); /* calls the dht_da() for closing
30 down the connection */
34 GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
39 service_connect_comp (void *cls,
40 struct GNUNET_TESTBED_Operation *op,
44 /* Service to DHT successful; do something */
46 GNUNET_SCHEDULER_cancel (shutdown_tid);
47 GNUNET_SCHEDULER_add_delayed
48 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
49 &shutdown_task, NULL);
54 dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
56 struct MyContext *ctxt = cls;
58 /* Use the provided configuration to connect to service */
59 dht_handle = GNUNET_DHT_connect (cfg, ctxt->ht_len);
65 dht_da (void *cls, void *op_result)
67 struct MyContext *ctxt = cls;
69 /* Disconnect from DHT service */
70 GNUNET_DHT_disconnect ((struct GNUNET_DHT_Handle *) op_result);
76 test_master (void *cls, unsigned int num_peers,
77 struct GNUNET_TESTBED_Peer **peers,
78 unsigned int links_succeeeded,
79 unsigned int links_failed)
81 /* Testbed is ready with peers running and connected in a pre-defined overlay
87 /* connect to a peers service */
88 dht_op = GNUNET_TESTBED_service_connect
89 (NULL, /* Closure for operation */
90 peers[0], /* The peer whose service to connect to */
91 "dht", /* The name of the service */
92 service_connect_comp, /* callback to call after a handle to service
94 NULL, /* closure for the above callback */
95 dht_ca, /* callback to call with peer's configuration;
96 this should open the needed service connection */
97 dht_da, /* callback to be called when closing the
98 opened service connection */
99 &ctxt); /* closure for the above two callbacks */
100 shutdown_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
101 &shutdown_task, NULL);
106 main (int argc, char **argv)
110 result = GNUNET_SYSERR;
111 ret = GNUNET_TESTBED_test_run
112 ("awesome-test", /* test case name */
113 "template.conf", /* template configuration */
114 NUM_PEERS, /* number of peers to start */
115 0LL, /* Event mask - set to 0 for no event notifications */
116 NULL, /* Controller event callback */
117 NULL, /* Closure for controller event callback */
118 &test_master, /* continuation callback to be called when testbed setup is
120 NULL); /* Closure for the test_master callback */
121 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )