aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/test_transport_api.c90
-rw-r--r--src/transport/transport-testing.h7
2 files changed, 64 insertions, 33 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 528b8f2bf..91d129e24 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -243,7 +243,8 @@ sendtask (void *cls)
243 243
244 244
245static void 245static void
246notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 246notify_connect (void *cls,
247 const struct GNUNET_PeerIdentity *peer)
247{ 248{
248 static int c; 249 static int c;
249 250
@@ -267,25 +268,31 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
267 268
268 269
269static void 270static void
270notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 271notify_disconnect (void *cls,
272 const struct GNUNET_PeerIdentity *peer)
271{ 273{
272 struct PeerContext *p = cls; 274 struct PeerContext *p = cls;
273 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); 275 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
274 276
275 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 277 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
276 "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, 278 "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
279 p->no,
280 ps,
277 GNUNET_i2s (peer)); 281 GNUNET_i2s (peer));
278
279 GNUNET_free (ps); 282 GNUNET_free (ps);
280 283
281 if (th != NULL) 284 if (th != NULL)
285 {
282 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 286 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
283 th = NULL; 287 th = NULL;
288 }
284} 289}
285 290
286 291
287static void 292static void
288testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 293testing_connect_cb (struct PeerContext *p1,
294 struct PeerContext *p2,
295 void *cls)
289{ 296{
290 cc = NULL; 297 cc = NULL;
291 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); 298 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
@@ -300,37 +307,45 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
300 307
301 308
302static void 309static void
303start_cb (struct PeerContext *p, void *cls) 310start_cb (struct PeerContext *p,
311 void *cls)
304{ 312{
305 static int started; 313 static int started;
306 314
307 started++; 315 started++;
308 316
309 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer %u (`%s') started\n", p->no, 317 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
318 "Peer %u (`%s') started\n",
319 p->no,
310 GNUNET_i2s (&p->id)); 320 GNUNET_i2s (&p->id));
311
312 if (started != 2) 321 if (started != 2)
313 return; 322 return;
314 else 323 s_started = GNUNET_YES;
315 s_started = GNUNET_YES; 324 {
316 char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); 325 char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
317
318 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
319 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
320 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
321 GNUNET_free (sender_c);
322 326
323 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, 327 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
328 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
329 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
330 GNUNET_free (sender_c);
331 }
332 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth,
333 p1,
334 p2,
335 &testing_connect_cb,
324 NULL); 336 NULL);
325
326} 337}
327 338
328 339
329static void 340static void
330run (void *cls, char *const *args, const char *cfgfile, 341run (void *cls,
342 char *const *args,
343 const char *cfgfile,
331 const struct GNUNET_CONFIGURATION_Handle *cfg) 344 const struct GNUNET_CONFIGURATION_Handle *cfg)
332{ 345{
333 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 346 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
347 &end_badly,
348 NULL);
334 349
335 s_started = GNUNET_NO; 350 s_started = GNUNET_NO;
336 s_connected = GNUNET_NO; 351 s_connected = GNUNET_NO;
@@ -348,7 +363,8 @@ run (void *cls, char *const *args, const char *cfgfile,
348 363
349 if ((p1 == NULL) || (p2 == NULL)) 364 if ((p1 == NULL) || (p2 == NULL))
350 { 365 {
351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); 366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
367 "Fail! Could not start peers!\n");
352 if (die_task != NULL) 368 if (die_task != NULL)
353 GNUNET_SCHEDULER_cancel (die_task); 369 GNUNET_SCHEDULER_cancel (die_task);
354 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 370 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
@@ -360,7 +376,8 @@ run (void *cls, char *const *args, const char *cfgfile,
360static int 376static int
361check () 377check ()
362{ 378{
363 static char *const argv[] = { "test-transport-api", 379 static char *const argv[] = {
380 "test-transport-api",
364 "-c", 381 "-c",
365 "test_transport_api_data.conf", 382 "test_transport_api_data.conf",
366 NULL 383 NULL
@@ -372,20 +389,29 @@ check ()
372 send_task = NULL; 389 send_task = NULL;
373 390
374 ok = 1; 391 ok = 1;
375 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, 392 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
376 "nohelp", options, &run, &ok); 393 argv,
394 test_name,
395 "nohelp",
396 options,
397 &run,
398 &ok);
377 399
378 return ok; 400 return ok;
379} 401}
380 402
403
381int 404int
382main (int argc, char *argv[]) 405main (int argc, char *argv[])
383{ 406{
384 int ret; 407 int ret;
385 408
386 GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); 409 GNUNET_TRANSPORT_TESTING_get_test_name (argv[0],
387 GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); 410 &test_name);
388 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, 411 GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__,
412 &test_source);
413 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0],
414 test_source,
389 &test_plugin); 415 &test_plugin);
390 416
391 GNUNET_log_setup (test_name, 417 GNUNET_log_setup (test_name,
@@ -393,8 +419,12 @@ main (int argc, char *argv[])
393 NULL); 419 NULL);
394 tth = GNUNET_TRANSPORT_TESTING_init (); 420 tth = GNUNET_TRANSPORT_TESTING_init ();
395 421
396 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); 422 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0],
397 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); 423 &cfg_file_p1,
424 1);
425 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0],
426 &cfg_file_p2,
427 2);
398 428
399 ret = check (); 429 ret = check ();
400 430
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 185016255..b3d6f2a2b 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -169,6 +169,7 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest
169 int p2_c; 169 int p2_c;
170}; 170};
171 171
172
172struct GNUNET_TRANSPORT_TESTING_handle 173struct GNUNET_TRANSPORT_TESTING_handle
173{ 174{
174 /** 175 /**
@@ -279,6 +280,7 @@ void
279GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *tth, 280GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *tth,
280 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); 281 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
281 282
283
282/** 284/**
283 * Clean up the transport testing 285 * Clean up the transport testing
284 * @param tth transport testing handle 286 * @param tth transport testing handle
@@ -286,6 +288,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_h
286void 288void
287GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth); 289GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
288 290
291
289/** 292/**
290 * Initialize the transport testing 293 * Initialize the transport testing
291 * @return transport testing handle 294 * @return transport testing handle
@@ -293,9 +296,6 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth);
293struct GNUNET_TRANSPORT_TESTING_handle * 296struct GNUNET_TRANSPORT_TESTING_handle *
294GNUNET_TRANSPORT_TESTING_init (void); 297GNUNET_TRANSPORT_TESTING_init (void);
295 298
296/*
297 * Some utility functions
298 */
299 299
300/** 300/**
301 * Extracts the test filename from an absolute file name and removes the extension 301 * Extracts the test filename from an absolute file name and removes the extension
@@ -306,6 +306,7 @@ void
306GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, 306GNUNET_TRANSPORT_TESTING_get_test_name (const char *file,
307 char **dest); 307 char **dest);
308 308
309
309/** 310/**
310 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and 311 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
311 * if existing ".exe"-prefix and adds the peer-number 312 * if existing ".exe"-prefix and adds the peer-number