diff options
Diffstat (limited to 'src/dht/dht_test_lib.c')
-rw-r--r-- | src/dht/dht_test_lib.c | 119 |
1 files changed, 60 insertions, 59 deletions
diff --git a/src/dht/dht_test_lib.c b/src/dht/dht_test_lib.c index 8ce3e98ea..e18d2ab24 100644 --- a/src/dht/dht_test_lib.c +++ b/src/dht/dht_test_lib.c | |||
@@ -28,7 +28,8 @@ | |||
28 | /** | 28 | /** |
29 | * Test context for a DHT Test. | 29 | * Test context for a DHT Test. |
30 | */ | 30 | */ |
31 | struct GNUNET_DHT_TEST_Context { | 31 | struct GNUNET_DHT_TEST_Context |
32 | { | ||
32 | /** | 33 | /** |
33 | * Array of running peers. | 34 | * Array of running peers. |
34 | */ | 35 | */ |
@@ -72,10 +73,10 @@ struct GNUNET_DHT_TEST_Context { | |||
72 | * @return service handle to return in 'op_result', NULL on error | 73 | * @return service handle to return in 'op_result', NULL on error |
73 | */ | 74 | */ |
74 | static void * | 75 | static void * |
75 | dht_connect_adapter(void *cls, | 76 | dht_connect_adapter (void *cls, |
76 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 77 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
77 | { | 78 | { |
78 | return GNUNET_DHT_connect(cfg, 16); | 79 | return GNUNET_DHT_connect (cfg, 16); |
79 | } | 80 | } |
80 | 81 | ||
81 | 82 | ||
@@ -87,12 +88,12 @@ dht_connect_adapter(void *cls, | |||
87 | * @param op_result service handle returned from the connect adapter | 88 | * @param op_result service handle returned from the connect adapter |
88 | */ | 89 | */ |
89 | static void | 90 | static void |
90 | dht_disconnect_adapter(void *cls, | 91 | dht_disconnect_adapter (void *cls, |
91 | void *op_result) | 92 | void *op_result) |
92 | { | 93 | { |
93 | struct GNUNET_DHT_Handle *dht = op_result; | 94 | struct GNUNET_DHT_Handle *dht = op_result; |
94 | 95 | ||
95 | GNUNET_DHT_disconnect(dht); | 96 | GNUNET_DHT_disconnect (dht); |
96 | } | 97 | } |
97 | 98 | ||
98 | 99 | ||
@@ -106,21 +107,21 @@ dht_disconnect_adapter(void *cls, | |||
106 | * operation has executed successfully. | 107 | * operation has executed successfully. |
107 | */ | 108 | */ |
108 | static void | 109 | static void |
109 | dht_connect_cb(void *cls, | 110 | dht_connect_cb (void *cls, |
110 | struct GNUNET_TESTBED_Operation *op, | 111 | struct GNUNET_TESTBED_Operation *op, |
111 | void *ca_result, | 112 | void *ca_result, |
112 | const char *emsg) | 113 | const char *emsg) |
113 | { | 114 | { |
114 | struct GNUNET_DHT_TEST_Context *ctx = cls; | 115 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
115 | 116 | ||
116 | if (NULL != emsg) | 117 | if (NULL != emsg) |
117 | { | 118 | { |
118 | fprintf(stderr, | 119 | fprintf (stderr, |
119 | "Failed to connect to DHT service: %s\n", | 120 | "Failed to connect to DHT service: %s\n", |
120 | emsg); | 121 | emsg); |
121 | GNUNET_SCHEDULER_shutdown(); | 122 | GNUNET_SCHEDULER_shutdown (); |
122 | return; | 123 | return; |
123 | } | 124 | } |
124 | for (unsigned int i = 0; i < ctx->num_peers; i++) | 125 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
125 | if (op == ctx->ops[i]) | 126 | if (op == ctx->ops[i]) |
126 | ctx->dhts[i] = ca_result; | 127 | ctx->dhts[i] = ca_result; |
@@ -129,11 +130,11 @@ dht_connect_cb(void *cls, | |||
129 | return; | 130 | return; |
130 | /* still some DHT connections missing */ | 131 | /* still some DHT connections missing */ |
131 | /* all DHT connections ready! */ | 132 | /* all DHT connections ready! */ |
132 | ctx->app_main(ctx->app_main_cls, | 133 | ctx->app_main (ctx->app_main_cls, |
133 | ctx, | 134 | ctx, |
134 | ctx->num_peers, | 135 | ctx->num_peers, |
135 | ctx->peers, | 136 | ctx->peers, |
136 | ctx->dhts); | 137 | ctx->dhts); |
137 | } | 138 | } |
138 | 139 | ||
139 | 140 | ||
@@ -143,38 +144,38 @@ dht_connect_cb(void *cls, | |||
143 | * @param ctx handle for the testbed | 144 | * @param ctx handle for the testbed |
144 | */ | 145 | */ |
145 | void | 146 | void |
146 | GNUNET_DHT_TEST_cleanup(struct GNUNET_DHT_TEST_Context *ctx) | 147 | GNUNET_DHT_TEST_cleanup (struct GNUNET_DHT_TEST_Context *ctx) |
147 | { | 148 | { |
148 | for (unsigned int i = 0; i < ctx->num_peers; i++) | 149 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
149 | GNUNET_TESTBED_operation_done(ctx->ops[i]); | 150 | GNUNET_TESTBED_operation_done (ctx->ops[i]); |
150 | GNUNET_free(ctx->ops); | 151 | GNUNET_free (ctx->ops); |
151 | GNUNET_free(ctx->dhts); | 152 | GNUNET_free (ctx->dhts); |
152 | GNUNET_free(ctx); | 153 | GNUNET_free (ctx); |
153 | GNUNET_SCHEDULER_shutdown(); | 154 | GNUNET_SCHEDULER_shutdown (); |
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
157 | static void | 158 | static void |
158 | dht_test_run(void *cls, | 159 | dht_test_run (void *cls, |
159 | struct GNUNET_TESTBED_RunHandle *h, | 160 | struct GNUNET_TESTBED_RunHandle *h, |
160 | unsigned int num_peers, | 161 | unsigned int num_peers, |
161 | struct GNUNET_TESTBED_Peer **peers, | 162 | struct GNUNET_TESTBED_Peer **peers, |
162 | unsigned int links_succeeded, | 163 | unsigned int links_succeeded, |
163 | unsigned int links_failed) | 164 | unsigned int links_failed) |
164 | { | 165 | { |
165 | struct GNUNET_DHT_TEST_Context *ctx = cls; | 166 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
166 | 167 | ||
167 | GNUNET_assert(num_peers == ctx->num_peers); | 168 | GNUNET_assert (num_peers == ctx->num_peers); |
168 | ctx->peers = peers; | 169 | ctx->peers = peers; |
169 | for (unsigned int i = 0; i < num_peers; i++) | 170 | for (unsigned int i = 0; i < num_peers; i++) |
170 | ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx, | 171 | ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, |
171 | peers[i], | 172 | peers[i], |
172 | "dht", | 173 | "dht", |
173 | &dht_connect_cb, | 174 | &dht_connect_cb, |
174 | ctx, | 175 | ctx, |
175 | &dht_connect_adapter, | 176 | &dht_connect_adapter, |
176 | &dht_disconnect_adapter, | 177 | &dht_disconnect_adapter, |
177 | ctx); | 178 | ctx); |
178 | } | 179 | } |
179 | 180 | ||
180 | 181 | ||
@@ -189,27 +190,27 @@ dht_test_run(void *cls, | |||
189 | * @param tmain_cls closure for 'tmain' | 190 | * @param tmain_cls closure for 'tmain' |
190 | */ | 191 | */ |
191 | void | 192 | void |
192 | GNUNET_DHT_TEST_run(const char *testname, | 193 | GNUNET_DHT_TEST_run (const char *testname, |
193 | const char *cfgname, | 194 | const char *cfgname, |
194 | unsigned int num_peers, | 195 | unsigned int num_peers, |
195 | GNUNET_DHT_TEST_AppMain tmain, | 196 | GNUNET_DHT_TEST_AppMain tmain, |
196 | void *tmain_cls) | 197 | void *tmain_cls) |
197 | { | 198 | { |
198 | struct GNUNET_DHT_TEST_Context *ctx; | 199 | struct GNUNET_DHT_TEST_Context *ctx; |
199 | 200 | ||
200 | ctx = GNUNET_new(struct GNUNET_DHT_TEST_Context); | 201 | ctx = GNUNET_new (struct GNUNET_DHT_TEST_Context); |
201 | ctx->num_peers = num_peers; | 202 | ctx->num_peers = num_peers; |
202 | ctx->ops = GNUNET_new_array(num_peers, | 203 | ctx->ops = GNUNET_new_array (num_peers, |
203 | struct GNUNET_TESTBED_Operation *); | 204 | struct GNUNET_TESTBED_Operation *); |
204 | ctx->dhts = GNUNET_new_array(num_peers, | 205 | ctx->dhts = GNUNET_new_array (num_peers, |
205 | struct GNUNET_DHT_Handle *); | 206 | struct GNUNET_DHT_Handle *); |
206 | ctx->app_main = tmain; | 207 | ctx->app_main = tmain; |
207 | ctx->app_main_cls = tmain_cls; | 208 | ctx->app_main_cls = tmain_cls; |
208 | (void)GNUNET_TESTBED_test_run(testname, | 209 | (void) GNUNET_TESTBED_test_run (testname, |
209 | cfgname, | 210 | cfgname, |
210 | num_peers, | 211 | num_peers, |
211 | 0LL, NULL, NULL, | 212 | 0LL, NULL, NULL, |
212 | &dht_test_run, ctx); | 213 | &dht_test_run, ctx); |
213 | } | 214 | } |
214 | 215 | ||
215 | /* end of dht_test_lib.c */ | 216 | /* end of dht_test_lib.c */ |