aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/cadet_test_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/cadet_test_lib.c')
-rw-r--r--src/cadet/cadet_test_lib.c260
1 files changed, 131 insertions, 129 deletions
diff --git a/src/cadet/cadet_test_lib.c b/src/cadet/cadet_test_lib.c
index ae1eb6f00..490e6539b 100644
--- a/src/cadet/cadet_test_lib.c
+++ b/src/cadet/cadet_test_lib.c
@@ -31,7 +31,8 @@
31/** 31/**
32 * Test context for a CADET Test. 32 * Test context for a CADET Test.
33 */ 33 */
34struct GNUNET_CADET_TEST_Context { 34struct GNUNET_CADET_TEST_Context
35{
35 /** 36 /**
36 * Array of running peers. 37 * Array of running peers.
37 */ 38 */
@@ -97,7 +98,8 @@ struct GNUNET_CADET_TEST_Context {
97/** 98/**
98 * Context for a cadet adapter callback. 99 * Context for a cadet adapter callback.
99 */ 100 */
100struct GNUNET_CADET_TEST_AdapterContext { 101struct GNUNET_CADET_TEST_AdapterContext
102{
101 /** 103 /**
102 * Peer number for the particular peer. 104 * Peer number for the particular peer.
103 */ 105 */
@@ -126,33 +128,33 @@ struct GNUNET_CADET_TEST_AdapterContext {
126 * @return service handle to return in 'op_result', NULL on error 128 * @return service handle to return in 'op_result', NULL on error
127 */ 129 */
128static void * 130static void *
129cadet_connect_adapter(void *cls, 131cadet_connect_adapter (void *cls,
130 const struct GNUNET_CONFIGURATION_Handle *cfg) 132 const struct GNUNET_CONFIGURATION_Handle *cfg)
131{ 133{
132 struct GNUNET_CADET_TEST_AdapterContext *actx = cls; 134 struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
133 struct GNUNET_CADET_TEST_Context *ctx = actx->ctx; 135 struct GNUNET_CADET_TEST_Context *ctx = actx->ctx;
134 struct GNUNET_CADET_Handle *h; 136 struct GNUNET_CADET_Handle *h;
135 137
136 h = GNUNET_CADET_connect(cfg); 138 h = GNUNET_CADET_connect (cfg);
137 if (NULL == h) 139 if (NULL == h)
138 { 140 {
139 GNUNET_break(0); 141 GNUNET_break (0);
140 return NULL; 142 return NULL;
141 } 143 }
142 if (NULL == ctx->ports) 144 if (NULL == ctx->ports)
143 return h; 145 return h;
144 actx->ports = GNUNET_new_array(ctx->port_count, 146 actx->ports = GNUNET_new_array (ctx->port_count,
145 struct GNUNET_CADET_Port *); 147 struct GNUNET_CADET_Port *);
146 for (unsigned int i = 0; i < ctx->port_count; i++) 148 for (unsigned int i = 0; i < ctx->port_count; i++)
147 { 149 {
148 actx->ports[i] = GNUNET_CADET_open_port(h, 150 actx->ports[i] = GNUNET_CADET_open_port (h,
149 ctx->ports[i], 151 ctx->ports[i],
150 ctx->connects, 152 ctx->connects,
151 (void *)(long)actx->peer, 153 (void *) (long) actx->peer,
152 ctx->window_changes, 154 ctx->window_changes,
153 ctx->disconnects, 155 ctx->disconnects,
154 ctx->handlers); 156 ctx->handlers);
155 } 157 }
156 return h; 158 return h;
157} 159}
158 160
@@ -165,23 +167,23 @@ cadet_connect_adapter(void *cls,
165 * @param op_result service handle returned from the connect adapter 167 * @param op_result service handle returned from the connect adapter
166 */ 168 */
167static void 169static void
168cadet_disconnect_adapter(void *cls, 170cadet_disconnect_adapter (void *cls,
169 void *op_result) 171 void *op_result)
170{ 172{
171 struct GNUNET_CADET_Handle *cadet = op_result; 173 struct GNUNET_CADET_Handle *cadet = op_result;
172 struct GNUNET_CADET_TEST_AdapterContext *actx = cls; 174 struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
173 175
174 if (NULL != actx->ports) 176 if (NULL != actx->ports)
177 {
178 for (unsigned int i = 0; i < actx->ctx->port_count; i++)
175 { 179 {
176 for (unsigned int i = 0; i < actx->ctx->port_count; i++) 180 GNUNET_CADET_close_port (actx->ports[i]);
177 { 181 actx->ports[i] = NULL;
178 GNUNET_CADET_close_port(actx->ports[i]);
179 actx->ports[i] = NULL;
180 }
181 GNUNET_free(actx->ports);
182 } 182 }
183 GNUNET_free(actx); 183 GNUNET_free (actx->ports);
184 GNUNET_CADET_disconnect(cadet); 184 }
185 GNUNET_free (actx);
186 GNUNET_CADET_disconnect (cadet);
185} 187}
186 188
187 189
@@ -196,56 +198,56 @@ cadet_disconnect_adapter(void *cls,
196 * NULL if operation has executed successfully. 198 * NULL if operation has executed successfully.
197 */ 199 */
198static void 200static void
199cadet_connect_cb(void *cls, 201cadet_connect_cb (void *cls,
200 struct GNUNET_TESTBED_Operation *op, 202 struct GNUNET_TESTBED_Operation *op,
201 void *ca_result, 203 void *ca_result,
202 const char *emsg) 204 const char *emsg)
203{ 205{
204 struct GNUNET_CADET_TEST_Context *ctx = cls; 206 struct GNUNET_CADET_TEST_Context *ctx = cls;
205 207
206 if (NULL != emsg) 208 if (NULL != emsg)
207 { 209 {
208 fprintf(stderr, 210 fprintf (stderr,
209 "Failed to connect to CADET service: %s\n", 211 "Failed to connect to CADET service: %s\n",
210 emsg); 212 emsg);
211 GNUNET_SCHEDULER_shutdown(); 213 GNUNET_SCHEDULER_shutdown ();
212 return; 214 return;
213 } 215 }
214 for (unsigned int i = 0; i < ctx->num_peers; i++) 216 for (unsigned int i = 0; i < ctx->num_peers; i++)
215 if (op == ctx->ops[i]) 217 if (op == ctx->ops[i])
216 { 218 {
217 ctx->cadets[i] = ca_result; 219 ctx->cadets[i] = ca_result;
218 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 220 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
219 "...cadet %u connected\n", 221 "...cadet %u connected\n",
220 i); 222 i);
221 } 223 }
222 for (unsigned int i = 0; i < ctx->num_peers; i++) 224 for (unsigned int i = 0; i < ctx->num_peers; i++)
223 if (NULL == ctx->cadets[i]) 225 if (NULL == ctx->cadets[i])
224 return; 226 return;
225 /* still some CADET connections missing */ 227 /* still some CADET connections missing */
226 /* all CADET connections ready! */ 228 /* all CADET connections ready! */
227 ctx->app_main(ctx->app_main_cls, 229 ctx->app_main (ctx->app_main_cls,
228 ctx, 230 ctx,
229 ctx->num_peers, 231 ctx->num_peers,
230 ctx->peers, 232 ctx->peers,
231 ctx->cadets); 233 ctx->cadets);
232} 234}
233 235
234 236
235void 237void
236GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx) 238GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx)
237{ 239{
238 for (unsigned int i = 0; i < ctx->num_peers; i++) 240 for (unsigned int i = 0; i < ctx->num_peers; i++)
239 { 241 {
240 GNUNET_assert(NULL != ctx->ops[i]); 242 GNUNET_assert (NULL != ctx->ops[i]);
241 GNUNET_TESTBED_operation_done(ctx->ops[i]); 243 GNUNET_TESTBED_operation_done (ctx->ops[i]);
242 ctx->ops[i] = NULL; 244 ctx->ops[i] = NULL;
243 } 245 }
244 GNUNET_free(ctx->ops); 246 GNUNET_free (ctx->ops);
245 GNUNET_free(ctx->cadets); 247 GNUNET_free (ctx->cadets);
246 GNUNET_free(ctx->handlers); 248 GNUNET_free (ctx->handlers);
247 GNUNET_free(ctx); 249 GNUNET_free (ctx);
248 GNUNET_SCHEDULER_shutdown(); 250 GNUNET_SCHEDULER_shutdown ();
249} 251}
250 252
251 253
@@ -263,57 +265,57 @@ GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx)
263 * failed 265 * failed
264 */ 266 */
265static void 267static void
266cadet_test_run(void *cls, 268cadet_test_run (void *cls,
267 struct GNUNET_TESTBED_RunHandle *h, 269 struct GNUNET_TESTBED_RunHandle *h,
268 unsigned int num_peers, 270 unsigned int num_peers,
269 struct GNUNET_TESTBED_Peer **peers, 271 struct GNUNET_TESTBED_Peer **peers,
270 unsigned int links_succeeded, 272 unsigned int links_succeeded,
271 unsigned int links_failed) 273 unsigned int links_failed)
272{ 274{
273 struct GNUNET_CADET_TEST_Context *ctx = cls; 275 struct GNUNET_CADET_TEST_Context *ctx = cls;
274 276
275 if (0 != links_failed) 277 if (0 != links_failed)
276 { 278 {
277 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
278 "Some links failed (%u), ending\n", 280 "Some links failed (%u), ending\n",
279 links_failed); 281 links_failed);
280 exit(77); 282 exit (77);
281 } 283 }
282 if (num_peers != ctx->num_peers) 284 if (num_peers != ctx->num_peers)
283 { 285 {
284 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 286 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
285 "Peers started %u/%u, ending\n", 287 "Peers started %u/%u, ending\n",
286 num_peers, 288 num_peers,
287 ctx->num_peers); 289 ctx->num_peers);
288 exit(1); 290 exit (1);
289 } 291 }
290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
291 "Testbed up, %u peers and %u links\n", 293 "Testbed up, %u peers and %u links\n",
292 num_peers, 294 num_peers,
293 links_succeeded); 295 links_succeeded);
294 ctx->peers = peers; 296 ctx->peers = peers;
295 for (unsigned int i = 0; i < num_peers; i++) 297 for (unsigned int i = 0; i < num_peers; i++)
296 { 298 {
297 struct GNUNET_CADET_TEST_AdapterContext *newctx; 299 struct GNUNET_CADET_TEST_AdapterContext *newctx;
298 300
299 newctx = GNUNET_new(struct GNUNET_CADET_TEST_AdapterContext); 301 newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext);
300 newctx->peer = i; 302 newctx->peer = i;
301 newctx->ctx = ctx; 303 newctx->ctx = ctx;
302 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 304 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
303 "Connecting to cadet %u\n", 305 "Connecting to cadet %u\n",
304 i); 306 i);
305 ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx, 307 ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx,
306 peers[i], 308 peers[i],
307 "cadet", 309 "cadet",
308 &cadet_connect_cb, 310 &cadet_connect_cb,
309 ctx, 311 ctx,
310 &cadet_connect_adapter, 312 &cadet_connect_adapter,
311 &cadet_disconnect_adapter, 313 &cadet_disconnect_adapter,
312 newctx); 314 newctx);
313 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
314 "op handle %p\n", 316 "op handle %p\n",
315 ctx->ops[i]); 317 ctx->ops[i]);
316 } 318 }
317} 319}
318 320
319 321
@@ -333,41 +335,41 @@ cadet_test_run(void *cls,
333 * @param ports Ports the peers offer, NULL-terminated. 335 * @param ports Ports the peers offer, NULL-terminated.
334 */ 336 */
335void 337void
336GNUNET_CADET_TEST_ruN(const char *testname, 338GNUNET_CADET_TEST_ruN (const char *testname,
337 const char *cfgfile, 339 const char *cfgfile,
338 unsigned int num_peers, 340 unsigned int num_peers,
339 GNUNET_CADET_TEST_AppMain tmain, 341 GNUNET_CADET_TEST_AppMain tmain,
340 void *tmain_cls, 342 void *tmain_cls,
341 GNUNET_CADET_ConnectEventHandler connects, 343 GNUNET_CADET_ConnectEventHandler connects,
342 GNUNET_CADET_WindowSizeEventHandler window_changes, 344 GNUNET_CADET_WindowSizeEventHandler window_changes,
343 GNUNET_CADET_DisconnectEventHandler disconnects, 345 GNUNET_CADET_DisconnectEventHandler disconnects,
344 struct GNUNET_MQ_MessageHandler *handlers, 346 struct GNUNET_MQ_MessageHandler *handlers,
345 const struct GNUNET_HashCode **ports) 347 const struct GNUNET_HashCode **ports)
346{ 348{
347 struct GNUNET_CADET_TEST_Context *ctx; 349 struct GNUNET_CADET_TEST_Context *ctx;
348 350
349 ctx = GNUNET_new(struct GNUNET_CADET_TEST_Context); 351 ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context);
350 ctx->num_peers = num_peers; 352 ctx->num_peers = num_peers;
351 ctx->ops = GNUNET_new_array(num_peers, 353 ctx->ops = GNUNET_new_array (num_peers,
352 struct GNUNET_TESTBED_Operation *); 354 struct GNUNET_TESTBED_Operation *);
353 ctx->cadets = GNUNET_new_array(num_peers, 355 ctx->cadets = GNUNET_new_array (num_peers,
354 struct GNUNET_CADET_Handle *); 356 struct GNUNET_CADET_Handle *);
355 ctx->app_main = tmain; 357 ctx->app_main = tmain;
356 ctx->app_main_cls = tmain_cls; 358 ctx->app_main_cls = tmain_cls;
357 ctx->connects = connects; 359 ctx->connects = connects;
358 ctx->window_changes = window_changes; 360 ctx->window_changes = window_changes;
359 ctx->disconnects = disconnects; 361 ctx->disconnects = disconnects;
360 ctx->handlers = GNUNET_MQ_copy_handlers(handlers); 362 ctx->handlers = GNUNET_MQ_copy_handlers (handlers);
361 ctx->ports = ports; 363 ctx->ports = ports;
362 ctx->port_count = 0; 364 ctx->port_count = 0;
363 while (NULL != ctx->ports[ctx->port_count]) 365 while (NULL != ctx->ports[ctx->port_count])
364 ctx->port_count++; 366 ctx->port_count++;
365 GNUNET_TESTBED_test_run(testname, 367 GNUNET_TESTBED_test_run (testname,
366 cfgfile, 368 cfgfile,
367 num_peers, 369 num_peers,
368 0LL, NULL, NULL, 370 0LL, NULL, NULL,
369 &cadet_test_run, 371 &cadet_test_run,
370 ctx); 372 ctx);
371} 373}
372 374
373/* end of cadet_test_lib.c */ 375/* end of cadet_test_lib.c */