summaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_3peers_3controllers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/test_testbed_api_3peers_3controllers.c')
-rw-r--r--src/testbed/test_testbed_api_3peers_3controllers.c970
1 files changed, 486 insertions, 484 deletions
diff --git a/src/testbed/test_testbed_api_3peers_3controllers.c b/src/testbed/test_testbed_api_3peers_3controllers.c
index ec396d6ca..1de635fd9 100644
--- a/src/testbed/test_testbed_api_3peers_3controllers.c
+++ b/src/testbed/test_testbed_api_3peers_3controllers.c
@@ -52,19 +52,20 @@
52 * Generic logging shortcut 52 * Generic logging shortcut
53 */ 53 */
54#define LOG(kind, ...) \ 54#define LOG(kind, ...) \
55 GNUNET_log(kind, __VA_ARGS__) 55 GNUNET_log (kind, __VA_ARGS__)
56 56
57/** 57/**
58 * Relative time seconds shorthand 58 * Relative time seconds shorthand
59 */ 59 */
60#define TIME_REL_SECS(sec) \ 60#define TIME_REL_SECS(sec) \
61 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) 61 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
62 62
63 63
64/** 64/**
65 * Peer context 65 * Peer context
66 */ 66 */
67struct PeerContext { 67struct PeerContext
68{
68 /** 69 /**
69 * The peer handle 70 * The peer handle
70 */ 71 */
@@ -150,17 +151,18 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle *hc_handle;
150/** 151/**
151 * Abort task identifier 152 * Abort task identifier
152 */ 153 */
153static struct GNUNET_SCHEDULER_Task * abort_task; 154static struct GNUNET_SCHEDULER_Task *abort_task;
154 155
155/** 156/**
156 * Delayed connect job identifier 157 * Delayed connect job identifier
157 */ 158 */
158static struct GNUNET_SCHEDULER_Task * delayed_connect_task; 159static struct GNUNET_SCHEDULER_Task *delayed_connect_task;
159 160
160/** 161/**
161 * Different stages in testing 162 * Different stages in testing
162 */ 163 */
163enum Stage { 164enum Stage
165{
164 /** 166 /**
165 * Initial stage 167 * Initial stage
166 */ 168 */
@@ -253,30 +255,30 @@ static enum Stage result;
253 * @param cls NULL 255 * @param cls NULL
254 */ 256 */
255static void 257static void
256do_shutdown(void *cls) 258do_shutdown (void *cls)
257{ 259{
258 if (NULL != abort_task) 260 if (NULL != abort_task)
259 GNUNET_SCHEDULER_cancel(abort_task); 261 GNUNET_SCHEDULER_cancel (abort_task);
260 if (NULL != hc_handle) 262 if (NULL != hc_handle)
261 GNUNET_TESTBED_is_host_habitable_cancel(hc_handle); 263 GNUNET_TESTBED_is_host_habitable_cancel (hc_handle);
262 GNUNET_assert(NULL == delayed_connect_task); 264 GNUNET_assert (NULL == delayed_connect_task);
263 if (NULL != common_operation) 265 if (NULL != common_operation)
264 GNUNET_TESTBED_operation_done(common_operation); 266 GNUNET_TESTBED_operation_done (common_operation);
265 if (NULL != reg_handle) 267 if (NULL != reg_handle)
266 GNUNET_TESTBED_cancel_registration(reg_handle); 268 GNUNET_TESTBED_cancel_registration (reg_handle);
267 if (NULL != controller1) 269 if (NULL != controller1)
268 GNUNET_TESTBED_controller_disconnect(controller1); 270 GNUNET_TESTBED_controller_disconnect (controller1);
269 GNUNET_CONFIGURATION_destroy(cfg); 271 GNUNET_CONFIGURATION_destroy (cfg);
270 if (NULL != cfg2) 272 if (NULL != cfg2)
271 GNUNET_CONFIGURATION_destroy(cfg2); 273 GNUNET_CONFIGURATION_destroy (cfg2);
272 if (NULL != cp1) 274 if (NULL != cp1)
273 GNUNET_TESTBED_controller_stop(cp1); 275 GNUNET_TESTBED_controller_stop (cp1);
274 if (NULL != host) 276 if (NULL != host)
275 GNUNET_TESTBED_host_destroy(host); 277 GNUNET_TESTBED_host_destroy (host);
276 if (NULL != neighbour1) 278 if (NULL != neighbour1)
277 GNUNET_TESTBED_host_destroy(neighbour1); 279 GNUNET_TESTBED_host_destroy (neighbour1);
278 if (NULL != neighbour2) 280 if (NULL != neighbour2)
279 GNUNET_TESTBED_host_destroy(neighbour2); 281 GNUNET_TESTBED_host_destroy (neighbour2);
280} 282}
281 283
282 284
@@ -286,25 +288,25 @@ do_shutdown(void *cls)
286 * @param cls NULL 288 * @param cls NULL
287 */ 289 */
288static void 290static void
289do_abort(void *cls) 291do_abort (void *cls)
290{ 292{
291 LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); 293 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
292 abort_task = NULL; 294 abort_task = NULL;
293 if (NULL != delayed_connect_task) 295 if (NULL != delayed_connect_task)
294 { 296 {
295 GNUNET_SCHEDULER_cancel(delayed_connect_task); 297 GNUNET_SCHEDULER_cancel (delayed_connect_task);
296 delayed_connect_task = NULL; 298 delayed_connect_task = NULL;
297 } 299 }
298 do_shutdown(cls); 300 do_shutdown (cls);
299} 301}
300 302
301 303
302static void 304static void
303abort_test() 305abort_test ()
304{ 306{
305 if (NULL != abort_task) 307 if (NULL != abort_task)
306 GNUNET_SCHEDULER_cancel(abort_task); 308 GNUNET_SCHEDULER_cancel (abort_task);
307 abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); 309 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
308} 310}
309 311
310 312
@@ -317,7 +319,7 @@ abort_test()
317 * operation has executed successfully. 319 * operation has executed successfully.
318 */ 320 */
319static void 321static void
320op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); 322op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
321 323
322 324
323/** 325/**
@@ -326,18 +328,18 @@ op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
326 * @param cls NULL 328 * @param cls NULL
327 */ 329 */
328static void 330static void
329do_delayed_connect(void *cls) 331do_delayed_connect (void *cls)
330{ 332{
331 delayed_connect_task = NULL; 333 delayed_connect_task = NULL;
332 if (NULL != common_operation) 334 if (NULL != common_operation)
333 { 335 {
334 GNUNET_break(0); 336 GNUNET_break (0);
335 abort_test(); 337 abort_test ();
336 return; 338 return;
337 } 339 }
338 common_operation = 340 common_operation =
339 GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, 341 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
340 peer2.peer); 342 peer2.peer);
341} 343}
342 344
343 345
@@ -350,34 +352,34 @@ do_delayed_connect(void *cls)
350 * operation has executed successfully. 352 * operation has executed successfully.
351 */ 353 */
352static void 354static void
353op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) 355op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
354{ 356{
355 if (common_operation != op) 357 if (common_operation != op)
356 { 358 {
357 GNUNET_break(0); 359 GNUNET_break (0);
358 abort_test(); 360 abort_test ();
359 return; 361 return;
360 } 362 }
361 363
362 switch (result) 364 switch (result)
363 { 365 {
364 case PEER3_STARTED: 366 case PEER3_STARTED:
365 case PEERS_2_3_CONNECTED: 367 case PEERS_2_3_CONNECTED:
366 case PEERS_1_2_CONNECTED: 368 case PEERS_1_2_CONNECTED:
367 break; 369 break;
368 370
369 default: 371 default:
370 GNUNET_break(0); 372 GNUNET_break (0);
371 abort_test(); 373 abort_test ();
372 return; 374 return;
373 } 375 }
374 if ((NULL != peer1.operation) || (NULL != peer2.operation) || 376 if ((NULL != peer1.operation) || (NULL != peer2.operation) ||
375 (NULL != peer3.operation)) 377 (NULL != peer3.operation))
376 { 378 {
377 GNUNET_break(0); 379 GNUNET_break (0);
378 abort_test(); 380 abort_test ();
379 return; 381 return;
380 } 382 }
381} 383}
382 384
383 385
@@ -391,54 +393,54 @@ op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
391 * @param emsg NULL if peer is not NULL; else MAY contain the error description 393 * @param emsg NULL if peer is not NULL; else MAY contain the error description
392 */ 394 */
393static void 395static void
394peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) 396peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
395{ 397{
396 switch (result) 398 switch (result)
399 {
400 case CONTROLLER1_UP:
401 if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer))
397 { 402 {
398 case CONTROLLER1_UP: 403 GNUNET_break (0);
399 if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer)) 404 abort_test ();
400 {
401 GNUNET_break(0);
402 abort_test();
403 return;
404 }
405 peer1.peer = peer;
406 GNUNET_TESTBED_operation_done(peer1.operation);
407 result = PEER1_CREATED;
408 peer1.operation = GNUNET_TESTBED_peer_start(NULL, peer, NULL, NULL);
409 break;
410
411 case CONTROLLER2_UP:
412 if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer))
413 {
414 GNUNET_break(0);
415 abort_test();
416 return;
417 }
418 peer2.peer = peer;
419 GNUNET_TESTBED_operation_done(peer2.operation);
420 result = PEER2_CREATED;
421 peer2.operation = GNUNET_TESTBED_peer_start(NULL, peer, NULL, NULL);
422 break;
423
424 case CONTROLLER3_UP:
425 if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer))
426 {
427 GNUNET_break(0);
428 abort_test();
429 return;
430 }
431 peer3.peer = peer;
432 GNUNET_TESTBED_operation_done(peer3.operation);
433 result = PEER3_CREATED;
434 peer3.operation = GNUNET_TESTBED_peer_start(NULL, peer, NULL, NULL);
435 break;
436
437 default:
438 GNUNET_break(0);
439 abort_test();
440 return; 405 return;
441 } 406 }
407 peer1.peer = peer;
408 GNUNET_TESTBED_operation_done (peer1.operation);
409 result = PEER1_CREATED;
410 peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
411 break;
412
413 case CONTROLLER2_UP:
414 if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer))
415 {
416 GNUNET_break (0);
417 abort_test ();
418 return;
419 }
420 peer2.peer = peer;
421 GNUNET_TESTBED_operation_done (peer2.operation);
422 result = PEER2_CREATED;
423 peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
424 break;
425
426 case CONTROLLER3_UP:
427 if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer))
428 {
429 GNUNET_break (0);
430 abort_test ();
431 return;
432 }
433 peer3.peer = peer;
434 GNUNET_TESTBED_operation_done (peer3.operation);
435 result = PEER3_CREATED;
436 peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
437 break;
438
439 default:
440 GNUNET_break (0);
441 abort_test ();
442 return;
443 }
442} 444}
443 445
444 446
@@ -450,289 +452,289 @@ peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
450 * @param event information about the event 452 * @param event information about the event
451 */ 453 */
452static void 454static void
453controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 455controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
454{ 456{
455 switch (event->type) 457 switch (event->type)
458 {
459 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
460 if ((NULL != event->op_cls) ||
461 (NULL != event->details.operation_finished.emsg))
462 {
463 GNUNET_break (0);
464 abort_test ();
465 return;
466 }
467 switch (result)
456 { 468 {
457 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 469 case PEERS_STOPPED:
458 if ((NULL != event->op_cls) || 470 if (NULL != event->details.operation_finished.generic)
459 (NULL != event->details.operation_finished.emsg)) 471 {
460 { 472 GNUNET_break (0);
461 GNUNET_break(0); 473 abort_test ();
462 abort_test(); 474 return;
463 return; 475 }
464 } 476 if (event->op == peer1.operation)
465 switch (result) 477 {
466 { 478 GNUNET_TESTBED_operation_done (peer1.operation);
467 case PEERS_STOPPED: 479 peer1.operation = NULL;
468 if (NULL != event->details.operation_finished.generic) 480 peer1.peer = NULL;
469 { 481 }
470 GNUNET_break(0); 482 else if (event->op == peer2.operation)
471 abort_test(); 483 {
472 return; 484 GNUNET_TESTBED_operation_done (peer2.operation);
473 } 485 peer2.operation = NULL;
474 if (event->op == peer1.operation) 486 peer2.peer = NULL;
475 { 487 }
476 GNUNET_TESTBED_operation_done(peer1.operation); 488 else if (event->op == peer3.operation)
477 peer1.operation = NULL; 489 {
478 peer1.peer = NULL; 490 GNUNET_TESTBED_operation_done (peer3.operation);
479 } 491 peer3.operation = NULL;
480 else if (event->op == peer2.operation) 492 peer3.peer = NULL;
481 { 493 }
482 GNUNET_TESTBED_operation_done(peer2.operation); 494 else
483 peer2.operation = NULL; 495 {
484 peer2.peer = NULL; 496 GNUNET_break (0);
485 } 497 abort_test ();
486 else if (event->op == peer3.operation) 498 return;
487 { 499 }
488 GNUNET_TESTBED_operation_done(peer3.operation); 500 if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer))
489 peer3.operation = NULL; 501 {
490 peer3.peer = NULL; 502 result = SUCCESS;
491 } 503 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
492 else 504 }
493 {
494 GNUNET_break(0);
495 abort_test();
496 return;
497 }
498 if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer))
499 {
500 result = SUCCESS;
501 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
502 }
503 break;
504
505 case PEER1_STARTED:
506 if ((NULL != event->details.operation_finished.generic) ||
507 (NULL == common_operation))
508 {
509 GNUNET_break(0);
510 abort_test();
511 return;
512 }
513 GNUNET_TESTBED_operation_done(common_operation);
514 common_operation = NULL;
515 result = CONTROLLER2_UP;
516 peer2.operation =
517 GNUNET_TESTBED_peer_create(controller1, neighbour1, cfg,
518 &peer_create_cb, NULL);
519 if (NULL == peer2.operation)
520 {
521 GNUNET_break(0);
522 abort_test();
523 return;
524 }
525 break;
526
527 case PEER2_STARTED:
528 if ((NULL != event->details.operation_finished.generic) ||
529 (NULL == common_operation))
530 {
531 GNUNET_break(0);
532 abort_test();
533 return;
534 }
535 GNUNET_TESTBED_operation_done(common_operation);
536 common_operation = NULL;
537 result = CONTROLLER3_UP;
538 peer3.operation =
539 GNUNET_TESTBED_peer_create(controller1, neighbour2, cfg,
540 &peer_create_cb, NULL);
541 if (NULL == peer3.operation)
542 {
543 GNUNET_break(0);
544 abort_test();
545 return;
546 }
547 break;
548
549 default:
550 GNUNET_break(0);
551 abort_test();
552 return;
553 }
554 break; 505 break;
555 506
556 case GNUNET_TESTBED_ET_PEER_START: 507 case PEER1_STARTED:
557 switch (result) 508 if ((NULL != event->details.operation_finished.generic) ||
558 { 509 (NULL == common_operation))
559 case PEER1_CREATED: 510 {
560 if (event->details.peer_start.host != host) 511 GNUNET_break (0);
561 { 512 abort_test ();
562 GNUNET_break(0); 513 return;
563 abort_test(); 514 }
564 return; 515 GNUNET_TESTBED_operation_done (common_operation);
565 } 516 common_operation = NULL;
566 peer1.is_running = GNUNET_YES; 517 result = CONTROLLER2_UP;
567 GNUNET_TESTBED_operation_done(peer1.operation); 518 peer2.operation =
568 peer1.operation = NULL; 519 GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg,
569 result = PEER1_STARTED; 520 &peer_create_cb, NULL);
570 common_operation = 521 if (NULL == peer2.operation)
571 GNUNET_TESTBED_controller_link(NULL, controller1, neighbour1, NULL, 522 {
572 GNUNET_YES); 523 GNUNET_break (0);
573 break; 524 abort_test ();
574 525 return;
575 case PEER2_CREATED: 526 }
576 if (event->details.peer_start.host != neighbour1)
577 {
578 GNUNET_break(0);
579 abort_test();
580 return;
581 }
582 peer2.is_running = GNUNET_YES;
583 GNUNET_TESTBED_operation_done(peer2.operation);
584 peer2.operation = NULL;
585 result = PEER2_STARTED;
586 if (NULL != common_operation)
587 {
588 GNUNET_break(0);
589 abort_test();
590 return;
591 }
592 common_operation =
593 GNUNET_TESTBED_controller_link(NULL, controller1, neighbour2, NULL,
594 GNUNET_YES);
595 if (NULL == common_operation)
596 {
597 GNUNET_break(0);
598 abort_test();
599 return;
600 }
601 break;
602
603 case PEER3_CREATED:
604 if (event->details.peer_start.host != neighbour2)
605 {
606 GNUNET_break(0);
607 abort_test();
608 return;
609 }
610 peer3.is_running = GNUNET_YES;
611 GNUNET_TESTBED_operation_done(peer3.operation);
612 peer3.operation = NULL;
613 result = PEER3_STARTED;
614 common_operation =
615 GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer2.peer,
616 peer1.peer);
617 break;
618
619 default:
620 GNUNET_break(0);
621 abort_test();
622 return;
623 }
624 break; 527 break;
625 528
626 case GNUNET_TESTBED_ET_PEER_STOP: 529 case PEER2_STARTED:
627 if (PEERS_CONNECTED_2 != result) 530 if ((NULL != event->details.operation_finished.generic) ||
628 { 531 (NULL == common_operation))
629 GNUNET_break(0); 532 {
630 abort_test(); 533 GNUNET_break (0);
631 return; 534 abort_test ();
632 } 535 return;
633 if (event->details.peer_stop.peer == peer1.peer) 536 }
634 { 537 GNUNET_TESTBED_operation_done (common_operation);
635 peer1.is_running = GNUNET_NO; 538 common_operation = NULL;
636 GNUNET_TESTBED_operation_done(peer1.operation); 539 result = CONTROLLER3_UP;
637 } 540 peer3.operation =
638 else if (event->details.peer_stop.peer == peer2.peer) 541 GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg,
639 { 542 &peer_create_cb, NULL);
640 peer2.is_running = GNUNET_NO; 543 if (NULL == peer3.operation)
641 GNUNET_TESTBED_operation_done(peer2.operation); 544 {
642 } 545 GNUNET_break (0);
643 else if (event->details.peer_stop.peer == peer3.peer) 546 abort_test ();
644 { 547 return;
645 peer3.is_running = GNUNET_NO; 548 }
646 GNUNET_TESTBED_operation_done(peer3.operation); 549 break;
647 } 550
648 else 551 default:
649 { 552 GNUNET_break (0);
650 GNUNET_break(0); 553 abort_test ();
651 abort_test(); 554 return;
652 return; 555 }
653 } 556 break;
654 if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) && 557
655 (GNUNET_NO == peer3.is_running)) 558 case GNUNET_TESTBED_ET_PEER_START:
656 { 559 switch (result)
657 result = PEERS_STOPPED; 560 {
658 peer1.operation = GNUNET_TESTBED_peer_destroy(peer1.peer); 561 case PEER1_CREATED:
659 peer2.operation = GNUNET_TESTBED_peer_destroy(peer2.peer); 562 if (event->details.peer_start.host != host)
660 peer3.operation = GNUNET_TESTBED_peer_destroy(peer3.peer); 563 {
661 } 564 GNUNET_break (0);
565 abort_test ();
566 return;
567 }
568 peer1.is_running = GNUNET_YES;
569 GNUNET_TESTBED_operation_done (peer1.operation);
570 peer1.operation = NULL;
571 result = PEER1_STARTED;
572 common_operation =
573 GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL,
574 GNUNET_YES);
662 break; 575 break;
663 576
664 case GNUNET_TESTBED_ET_CONNECT: 577 case PEER2_CREATED:
665 if ((NULL != peer1.operation) || (NULL != peer2.operation) || 578 if (event->details.peer_start.host != neighbour1)
666 (NULL != peer3.operation) || (NULL == common_operation)) 579 {
667 { 580 GNUNET_break (0);
668 GNUNET_break(0); 581 abort_test ();
669 abort_test(); 582 return;
670 return; 583 }
671 } 584 peer2.is_running = GNUNET_YES;
672 switch (result) 585 GNUNET_TESTBED_operation_done (peer2.operation);
673 { 586 peer2.operation = NULL;
674 case PEER3_STARTED: 587 result = PEER2_STARTED;
675 if ((event->details.peer_connect.peer1 != peer2.peer) || 588 if (NULL != common_operation)
676 (event->details.peer_connect.peer2 != peer1.peer)) 589 {
677 { 590 GNUNET_break (0);
678 GNUNET_break(0); 591 abort_test ();
679 abort_test(); 592 return;
680 return; 593 }
681 } 594 common_operation =
682 GNUNET_TESTBED_operation_done(common_operation); 595 GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL,
683 common_operation = NULL; 596 GNUNET_YES);
684 result = PEERS_1_2_CONNECTED; 597 if (NULL == common_operation)
685 LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); 598 {
686 common_operation = 599 GNUNET_break (0);
687 GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer2.peer, 600 abort_test ();
688 peer3.peer); 601 return;
689 break; 602 }
690 603 break;
691 case PEERS_1_2_CONNECTED: 604
692 if ((event->details.peer_connect.peer1 != peer2.peer) || 605 case PEER3_CREATED:
693 (event->details.peer_connect.peer2 != peer3.peer)) 606 if (event->details.peer_start.host != neighbour2)
694 { 607 {
695 GNUNET_break(0); 608 GNUNET_break (0);
696 abort_test(); 609 abort_test ();
697 return; 610 return;
698 } 611 }
699 GNUNET_TESTBED_operation_done(common_operation); 612 peer3.is_running = GNUNET_YES;
700 common_operation = NULL; 613 GNUNET_TESTBED_operation_done (peer3.operation);
701 result = PEERS_2_3_CONNECTED; 614 peer3.operation = NULL;
702 delayed_connect_task = 615 result = PEER3_STARTED;
703 GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(3), &do_delayed_connect, 616 common_operation =
704 NULL); 617 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
705 break; 618 peer1.peer);
706
707 case PEERS_2_3_CONNECTED:
708 if ((event->details.peer_connect.peer1 != peer1.peer) ||
709 (event->details.peer_connect.peer2 != peer2.peer))
710 {
711 GNUNET_break(0);
712 abort_test();
713 return;
714 }
715 GNUNET_TESTBED_operation_done(common_operation);
716 common_operation = NULL;
717 result = PEERS_CONNECTED_2;
718 LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
719 peer1.operation = GNUNET_TESTBED_peer_stop(NULL, peer1.peer, NULL, NULL);
720 peer2.operation = GNUNET_TESTBED_peer_stop(NULL, peer2.peer, NULL, NULL);
721 peer3.operation = GNUNET_TESTBED_peer_stop(NULL, peer3.peer, NULL, NULL);
722 break;
723
724 default:
725 GNUNET_break(0);
726 abort_test();
727 return;
728 }
729 break; 619 break;
730 620
731 default: 621 default:
732 GNUNET_break(0); 622 GNUNET_break (0);
733 abort_test(); 623 abort_test ();
624 return;
625 }
626 break;
627
628 case GNUNET_TESTBED_ET_PEER_STOP:
629 if (PEERS_CONNECTED_2 != result)
630 {
631 GNUNET_break (0);
632 abort_test ();
734 return; 633 return;
735 } 634 }
635 if (event->details.peer_stop.peer == peer1.peer)
636 {
637 peer1.is_running = GNUNET_NO;
638 GNUNET_TESTBED_operation_done (peer1.operation);
639 }
640 else if (event->details.peer_stop.peer == peer2.peer)
641 {
642 peer2.is_running = GNUNET_NO;
643 GNUNET_TESTBED_operation_done (peer2.operation);
644 }
645 else if (event->details.peer_stop.peer == peer3.peer)
646 {
647 peer3.is_running = GNUNET_NO;
648 GNUNET_TESTBED_operation_done (peer3.operation);
649 }
650 else
651 {
652 GNUNET_break (0);
653 abort_test ();
654 return;
655 }
656 if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) &&
657 (GNUNET_NO == peer3.is_running))
658 {
659 result = PEERS_STOPPED;
660 peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
661 peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
662 peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer);
663 }
664 break;
665
666 case GNUNET_TESTBED_ET_CONNECT:
667 if ((NULL != peer1.operation) || (NULL != peer2.operation) ||
668 (NULL != peer3.operation) || (NULL == common_operation))
669 {
670 GNUNET_break (0);
671 abort_test ();
672 return;
673 }
674 switch (result)
675 {
676 case PEER3_STARTED:
677 if ((event->details.peer_connect.peer1 != peer2.peer) ||
678 (event->details.peer_connect.peer2 != peer1.peer))
679 {
680 GNUNET_break (0);
681 abort_test ();
682 return;
683 }
684 GNUNET_TESTBED_operation_done (common_operation);
685 common_operation = NULL;
686 result = PEERS_1_2_CONNECTED;
687 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
688 common_operation =
689 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
690 peer3.peer);
691 break;
692
693 case PEERS_1_2_CONNECTED:
694 if ((event->details.peer_connect.peer1 != peer2.peer) ||
695 (event->details.peer_connect.peer2 != peer3.peer))
696 {
697 GNUNET_break (0);
698 abort_test ();
699 return;
700 }
701 GNUNET_TESTBED_operation_done (common_operation);
702 common_operation = NULL;
703 result = PEERS_2_3_CONNECTED;
704 delayed_connect_task =
705 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect,
706 NULL);
707 break;
708
709 case PEERS_2_3_CONNECTED:
710 if ((event->details.peer_connect.peer1 != peer1.peer) ||
711 (event->details.peer_connect.peer2 != peer2.peer))
712 {
713 GNUNET_break (0);
714 abort_test ();
715 return;
716 }
717 GNUNET_TESTBED_operation_done (common_operation);
718 common_operation = NULL;
719 result = PEERS_CONNECTED_2;
720 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
721 peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL);
722 peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL);
723 peer3.operation = GNUNET_TESTBED_peer_stop (NULL, peer3.peer, NULL, NULL);
724 break;
725
726 default:
727 GNUNET_break (0);
728 abort_test ();
729 return;
730 }
731 break;
732
733 default:
734 GNUNET_break (0);
735 abort_test ();
736 return;
737 }
736} 738}
737 739
738 740
@@ -743,44 +745,44 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
743 * @param emsg the error message; NULL if host registration is successful 745 * @param emsg the error message; NULL if host registration is successful
744 */ 746 */
745static void 747static void
746registration_comp(void *cls, const char *emsg) 748registration_comp (void *cls, const char *emsg)
747{ 749{
748 reg_handle = NULL; 750 reg_handle = NULL;
749 if (cls == neighbour1) 751 if (cls == neighbour1)
752 {
753 neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0);
754 if (NULL == neighbour2)
750 { 755 {
751 neighbour2 = GNUNET_TESTBED_host_create("127.0.0.1", NULL, cfg, 0); 756 GNUNET_break (0);
752 if (NULL == neighbour2) 757 abort_test ();
753 {
754 GNUNET_break(0);
755 abort_test();
756 return;
757 }
758 reg_handle =
759 GNUNET_TESTBED_register_host(controller1, neighbour2,
760 &registration_comp, neighbour2);
761 if (NULL == reg_handle)
762 {
763 GNUNET_break(0);
764 abort_test();
765 return;
766 }
767 return; 758 return;
768 } 759 }
769 if (cls != neighbour2) 760 reg_handle =
761 GNUNET_TESTBED_register_host (controller1, neighbour2,
762 &registration_comp, neighbour2);
763 if (NULL == reg_handle)
770 { 764 {
771 GNUNET_break(0); 765 GNUNET_break (0);
772 abort_test(); 766 abort_test ();
773 return; 767 return;
774 } 768 }
769 return;
770 }
771 if (cls != neighbour2)
772 {
773 GNUNET_break (0);
774 abort_test ();
775 return;
776 }
775 peer1.operation = 777 peer1.operation =
776 GNUNET_TESTBED_peer_create(controller1, host, cfg, &peer_create_cb, 778 GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb,
777 &peer1); 779 &peer1);
778 if (NULL == peer1.operation) 780 if (NULL == peer1.operation)
779 { 781 {
780 GNUNET_break(0); 782 GNUNET_break (0);
781 abort_test(); 783 abort_test ();
782 return; 784 return;
783 } 785 }
784} 786}
785 787
786 788
@@ -794,59 +796,59 @@ registration_comp(void *cls, const char *emsg)
794 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 796 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
795 */ 797 */
796static void 798static void
797status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *config, 799status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
798 int status) 800 int status)
799{ 801{
800 uint64_t event_mask; 802 uint64_t event_mask;
801 803
802 if (GNUNET_OK != status) 804 if (GNUNET_OK != status)
803 { 805 {
804 GNUNET_break(0); 806 GNUNET_break (0);
805 cp1 = NULL; 807 cp1 = NULL;
806 abort_test(); 808 abort_test ();
807 return; 809 return;
808 } 810 }
809 event_mask = 0; 811 event_mask = 0;
810 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); 812 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
811 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); 813 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
812 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); 814 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
813 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); 815 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
814 switch (result) 816 switch (result)
817 {
818 case INIT:
819 controller1 =
820 GNUNET_TESTBED_controller_connect (host, event_mask,
821 &controller_cb, NULL);
822 if (NULL == controller1)
815 { 823 {
816 case INIT: 824 GNUNET_break (0);
817 controller1 = 825 abort_test ();
818 GNUNET_TESTBED_controller_connect(host, event_mask, 826 return;
819 &controller_cb, NULL); 827 }
820 if (NULL == controller1) 828 result = CONTROLLER1_UP;
821 { 829 neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0);
822 GNUNET_break(0); 830 if (NULL == neighbour1)
823 abort_test(); 831 {
824 return; 832 GNUNET_break (0);
825 } 833 abort_test ();
826 result = CONTROLLER1_UP; 834 return;
827 neighbour1 = GNUNET_TESTBED_host_create("127.0.0.1", NULL, cfg, 0); 835 }
828 if (NULL == neighbour1) 836 reg_handle =
829 { 837 GNUNET_TESTBED_register_host (controller1, neighbour1,
830 GNUNET_break(0); 838 &registration_comp, neighbour1);
831 abort_test(); 839 if (NULL == reg_handle)
832 return; 840 {
833 } 841 GNUNET_break (0);
834 reg_handle = 842 abort_test ();
835 GNUNET_TESTBED_register_host(controller1, neighbour1,
836 &registration_comp, neighbour1);
837 if (NULL == reg_handle)
838 {
839 GNUNET_break(0);
840 abort_test();
841 return;
842 }
843 break;
844
845 default:
846 GNUNET_break(0);
847 abort_test();
848 return; 843 return;
849 } 844 }
845 break;
846
847 default:
848 GNUNET_break (0);
849 abort_test ();
850 return;
851 }
850} 852}
851 853
852 854
@@ -861,25 +863,25 @@ status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
861 * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not 863 * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not
862 */ 864 */
863static void 865static void
864host_habitable_cb(void *cls, 866host_habitable_cb (void *cls,
865 const struct GNUNET_TESTBED_Host *_host, 867 const struct GNUNET_TESTBED_Host *_host,
866 int status) 868 int status)
867{ 869{
868 hc_handle = NULL; 870 hc_handle = NULL;
869 if (GNUNET_NO == status) 871 if (GNUNET_NO == status)
870 { 872 {
871 (void)printf("%s", 873 (void) printf ("%s",
872 "Unable to run the test as this system is not configured " 874 "Unable to run the test as this system is not configured "
873 "to use password less SSH logins to localhost.\n" 875 "to use password less SSH logins to localhost.\n"
874 "Skipping test\n"); 876 "Skipping test\n");
875 GNUNET_SCHEDULER_cancel(abort_task); 877 GNUNET_SCHEDULER_cancel (abort_task);
876 abort_task = NULL; 878 abort_task = NULL;
877 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 879 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
878 result = SKIP; 880 result = SKIP;
879 return; 881 return;
880 } 882 }
881 cp1 = 883 cp1 =
882 GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, NULL); 884 GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL);
883} 885}
884 886
885 887
@@ -892,35 +894,35 @@ host_habitable_cb(void *cls,
892 * @param cfg the configuration file handle 894 * @param cfg the configuration file handle
893 */ 895 */
894static void 896static void
895run(void *cls, char *const *args, const char *cfgfile, 897run (void *cls, char *const *args, const char *cfgfile,
896 const struct GNUNET_CONFIGURATION_Handle *config) 898 const struct GNUNET_CONFIGURATION_Handle *config)
897{ 899{
898 cfg = GNUNET_CONFIGURATION_dup(config); 900 cfg = GNUNET_CONFIGURATION_dup (config);
899 host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); 901 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
900 if (NULL == host) 902 if (NULL == host)
901 { 903 {
902 GNUNET_break(0); 904 GNUNET_break (0);
903 abort_test(); 905 abort_test ();
904 return; 906 return;
905 } 907 }
906 if (NULL == 908 if (NULL ==
907 (hc_handle = 909 (hc_handle =
908 GNUNET_TESTBED_is_host_habitable(host, config, &host_habitable_cb, 910 GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb,
909 NULL))) 911 NULL)))
910 { 912 {
911 GNUNET_TESTBED_host_destroy(host); 913 GNUNET_TESTBED_host_destroy (host);
912 host = NULL; 914 host = NULL;
913 (void)printf("%s", 915 (void) printf ("%s",
914 "Unable to run the test as this system is not configured " 916 "Unable to run the test as this system is not configured "
915 "to use password less SSH logins to localhost.\n" 917 "to use password less SSH logins to localhost.\n"
916 "Skipping test\n"); 918 "Skipping test\n");
917 result = SKIP; 919 result = SKIP;
918 return; 920 return;
919 } 921 }
920 abort_task = 922 abort_task =
921 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 923 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
922 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, 924 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
923 NULL); 925 NULL);
924} 926}
925 927
926 928
@@ -928,7 +930,7 @@ run(void *cls, char *const *args, const char *cfgfile,
928 * Main function 930 * Main function
929 */ 931 */
930int 932int
931main(int argc, char **argv) 933main (int argc, char **argv)
932{ 934{
933 char *const argv2[] = { "test_testbed_api_3peers_3controllers", 935 char *const argv2[] = { "test_testbed_api_3peers_3controllers",
934 "-c", "test_testbed_api.conf", 936 "-c", "test_testbed_api.conf",
@@ -940,22 +942,22 @@ main(int argc, char **argv)
940 942
941 result = INIT; 943 result = INIT;
942 ret = 944 ret =
943 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 945 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
944 "test_testbed_api_3peers_3controllers", "nohelp", 946 "test_testbed_api_3peers_3controllers", "nohelp",
945 options, &run, NULL); 947 options, &run, NULL);
946 if (GNUNET_OK != ret) 948 if (GNUNET_OK != ret)
947 return 1; 949 return 1;
948 switch (result) 950 switch (result)
949 { 951 {
950 case SUCCESS: 952 case SUCCESS:
951 return 0; 953 return 0;
952 954
953 case SKIP: 955 case SKIP:
954 return 77; /* Mark test as skipped */ 956 return 77; /* Mark test as skipped */
955 957
956 default: 958 default:
957 return 1; 959 return 1;
958 } 960 }
959} 961}
960 962
961/* end of test_testbed_api_3peers_3controllers.c */ 963/* end of test_testbed_api_3peers_3controllers.c */