aboutsummaryrefslogtreecommitdiff
path: root/doc/testbed_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'doc/testbed_test.c')
-rw-r--r--doc/testbed_test.c80
1 files changed, 71 insertions, 9 deletions
diff --git a/doc/testbed_test.c b/doc/testbed_test.c
index 593c3c703..b1102ef92 100644
--- a/doc/testbed_test.c
+++ b/doc/testbed_test.c
@@ -7,49 +7,95 @@
7/* Number of peers we want to start */ 7/* Number of peers we want to start */
8#define NUM_PEERS 20 8#define NUM_PEERS 20
9 9
10struct GNUNET_TESTBED_Operation *dht_op; 10static struct GNUNET_TESTBED_Operation *dht_op;
11 11
12struct GNUNET_DHT_Handle *dht_handle; 12static struct GNUNET_DHT_Handle *dht_handle;
13 13
14GNUNET_SCHEDULER_TaskIdentifier shutdown_tid; 14static GNUNET_SCHEDULER_TaskIdentifier shutdown_tid;
15 15
16
17/**
18 * Closure to 'dht_ca' and 'dht_da' DHT adapters.
19 */
16struct MyContext 20struct MyContext
17{ 21{
22 /**
23 * Argument we pass to GNUNET_DHT_connect.
24 */
18 int ht_len; 25 int ht_len;
19} ctxt; 26} ctxt;
20 27
28
29/**
30 * Global result for testcase.
31 */
21static int result; 32static int result;
22 33
34
35/**
36 * Function run on CTRL-C or shutdown (i.e. success/timeout/etc.).
37 * Cleans up.
38 */
23static void 39static void
24shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 40shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
25{ 41{
26 shutdown_tid = GNUNET_SCHEDULER_NO_TASK; 42 shutdown_tid = GNUNET_SCHEDULER_NO_TASK;
27 if (NULL != dht_op) 43 if (NULL != dht_op)
28 { 44 {
29 GNUNET_TESTBED_operation_done (dht_op); /* calls the dht_da() for closing 45 GNUNET_TESTBED_operation_done (dht_op); /* indirectly calls the dht_da() for closing
30 down the connection */ 46 down the connection to the DHT */
31 dht_op = NULL; 47 dht_op = NULL;
48 dht_handle = NULL;
32 } 49 }
33 result = GNUNET_OK; 50 result = GNUNET_OK;
34 GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */ 51 GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
35} 52}
36 53
37 54
55/**
56 * This is where the test logic should be, at least that
57 * part of it that uses the DHT of peer "0".
58 *
59 * @param cls closure, for the example: NULL
60 * @param op should be equal to "dht_op"
61 * @param ca_result result of the connect operation, the
62 * connection to the DHT service
63 * @param emsg error message, if testbed somehow failed to
64 * connect to the DHT.
65 */
38static void 66static void
39service_connect_comp (void *cls, 67service_connect_comp (void *cls,
40 struct GNUNET_TESTBED_Operation *op, 68 struct GNUNET_TESTBED_Operation *op,
41 void *ca_result, 69 void *ca_result,
42 const char *emsg) 70 const char *emsg)
43{ 71{
44 /* Service to DHT successful; do something */ 72 GNUNET_assert (op == dht_op);
73 dht_handle = ca_result;
74 /* Service to DHT successful; here we'd usually do something
75 with the DHT (ok, if successful) */
45 76
77 /* for now, just indiscriminately terminate after 10s */
46 GNUNET_SCHEDULER_cancel (shutdown_tid); 78 GNUNET_SCHEDULER_cancel (shutdown_tid);
47 GNUNET_SCHEDULER_add_delayed 79 shutdown_tid = GNUNET_SCHEDULER_add_delayed
48 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 80 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
49 &shutdown_task, NULL); 81 &shutdown_task, NULL);
50} 82}
51 83
52 84
85/**
86 * Testbed has provided us with the configuration to access one
87 * of the peers and it is time to do "some" connect operation to
88 * "some" subsystem of the peer. For this example, we connect
89 * to the DHT subsystem. Testbed doesn't know which subsystem,
90 * so we need these adapters to do the actual connecting (and
91 * possibly pass additional options to the subsystem connect
92 * function, such as the "ht_len" argument for the DHT).
93 *
94 * @param cls closure
95 * @param cfg peer configuration (here: peer[0]
96 * @return NULL on error, otherwise some handle to access the
97 * subsystem
98 */
53static void * 99static void *
54dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 100dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
55{ 101{
@@ -61,6 +107,12 @@ dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
61} 107}
62 108
63 109
110/**
111 * Dual of 'dht_ca' to perform the 'disconnect'/cleanup operation
112 * once we no longer need to access this subsystem.
113 *
114 * @param op_result whatever we returned from 'dht_ca'
115 */
64static void 116static void
65dht_da (void *cls, void *op_result) 117dht_da (void *cls, void *op_result)
66{ 118{
@@ -68,10 +120,20 @@ dht_da (void *cls, void *op_result)
68 120
69 /* Disconnect from DHT service */ 121 /* Disconnect from DHT service */
70 GNUNET_DHT_disconnect ((struct GNUNET_DHT_Handle *) op_result); 122 GNUNET_DHT_disconnect ((struct GNUNET_DHT_Handle *) op_result);
71 ctxt->ht_len = 0;
72 dht_handle = NULL; 123 dht_handle = NULL;
73} 124}
74 125
126
127/**
128 * Main function inovked from TESTBED once all of the
129 * peers are up and running. This one then connects
130 * just to the DHT service of peer 0.
131 *
132 * @param cls closure
133 * @param num_peers size of the 'peers' array
134 * @param links_succeeded number of links between peers that were created
135 * @param links_failed number of links testbed was unable to establish
136 */
75static void 137static void
76test_master (void *cls, unsigned int num_peers, 138test_master (void *cls, unsigned int num_peers,
77 struct GNUNET_TESTBED_Peer **peers, 139 struct GNUNET_TESTBED_Peer **peers,