diff options
-rw-r--r-- | doc/gnunet-c-tutorial.pdf | bin | 404530 -> 408828 bytes | |||
-rw-r--r-- | doc/testbed_test.c | 80 |
2 files changed, 71 insertions, 9 deletions
diff --git a/doc/gnunet-c-tutorial.pdf b/doc/gnunet-c-tutorial.pdf index a5a4a3de8..1b7749ff6 100644 --- a/doc/gnunet-c-tutorial.pdf +++ b/doc/gnunet-c-tutorial.pdf | |||
Binary files differ | |||
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 | ||
10 | struct GNUNET_TESTBED_Operation *dht_op; | 10 | static struct GNUNET_TESTBED_Operation *dht_op; |
11 | 11 | ||
12 | struct GNUNET_DHT_Handle *dht_handle; | 12 | static struct GNUNET_DHT_Handle *dht_handle; |
13 | 13 | ||
14 | GNUNET_SCHEDULER_TaskIdentifier shutdown_tid; | 14 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_tid; |
15 | 15 | ||
16 | |||
17 | /** | ||
18 | * Closure to 'dht_ca' and 'dht_da' DHT adapters. | ||
19 | */ | ||
16 | struct MyContext | 20 | struct 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 | */ | ||
21 | static int result; | 32 | static int result; |
22 | 33 | ||
34 | |||
35 | /** | ||
36 | * Function run on CTRL-C or shutdown (i.e. success/timeout/etc.). | ||
37 | * Cleans up. | ||
38 | */ | ||
23 | static void | 39 | static void |
24 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 40 | shutdown_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 | */ | ||
38 | static void | 66 | static void |
39 | service_connect_comp (void *cls, | 67 | service_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 | */ | ||
53 | static void * | 99 | static void * |
54 | dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 100 | dht_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 | */ | ||
64 | static void | 116 | static void |
65 | dht_da (void *cls, void *op_result) | 117 | dht_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 | */ | ||
75 | static void | 137 | static void |
76 | test_master (void *cls, unsigned int num_peers, | 138 | test_master (void *cls, unsigned int num_peers, |
77 | struct GNUNET_TESTBED_Peer **peers, | 139 | struct GNUNET_TESTBED_Peer **peers, |