diff options
Diffstat (limited to 'src/testbed/testbed_api_testbed.c')
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 1143 |
1 files changed, 582 insertions, 561 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index 4615afca9..3c56dd024 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -37,13 +37,13 @@ | |||
37 | * Generic loggins shorthand | 37 | * Generic loggins shorthand |
38 | */ | 38 | */ |
39 | #define LOG(kind, ...) \ | 39 | #define LOG(kind, ...) \ |
40 | GNUNET_log_from(kind, "testbed-api-testbed", __VA_ARGS__) | 40 | GNUNET_log_from (kind, "testbed-api-testbed", __VA_ARGS__) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Debug logging shortcut | 43 | * Debug logging shortcut |
44 | */ | 44 | */ |
45 | #define DEBUG(...) \ | 45 | #define DEBUG(...) \ |
46 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 46 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * The default setup timeout in seconds | 49 | * The default setup timeout in seconds |
@@ -71,7 +71,8 @@ | |||
71 | /** | 71 | /** |
72 | * Context information for the operation we start | 72 | * Context information for the operation we start |
73 | */ | 73 | */ |
74 | struct RunContextOperation { | 74 | struct RunContextOperation |
75 | { | ||
75 | /** | 76 | /** |
76 | * The testbed operation handle | 77 | * The testbed operation handle |
77 | */ | 78 | */ |
@@ -92,7 +93,8 @@ struct RunContextOperation { | |||
92 | /** | 93 | /** |
93 | * States of RunContext | 94 | * States of RunContext |
94 | */ | 95 | */ |
95 | enum State { | 96 | enum State |
97 | { | ||
96 | /** | 98 | /** |
97 | * Initial state | 99 | * Initial state |
98 | */ | 100 | */ |
@@ -135,7 +137,8 @@ enum State { | |||
135 | /** | 137 | /** |
136 | * Context for host compability checks | 138 | * Context for host compability checks |
137 | */ | 139 | */ |
138 | struct CompatibilityCheckContext { | 140 | struct CompatibilityCheckContext |
141 | { | ||
139 | /** | 142 | /** |
140 | * The run context | 143 | * The run context |
141 | */ | 144 | */ |
@@ -156,7 +159,8 @@ struct CompatibilityCheckContext { | |||
156 | /** | 159 | /** |
157 | * Testbed Run Handle | 160 | * Testbed Run Handle |
158 | */ | 161 | */ |
159 | struct GNUNET_TESTBED_RunHandle { | 162 | struct GNUNET_TESTBED_RunHandle |
163 | { | ||
160 | /** | 164 | /** |
161 | * The controller handle | 165 | * The controller handle |
162 | */ | 166 | */ |
@@ -248,12 +252,12 @@ struct GNUNET_TESTBED_RunHandle { | |||
248 | /** | 252 | /** |
249 | * Host registration task | 253 | * Host registration task |
250 | */ | 254 | */ |
251 | struct GNUNET_SCHEDULER_Task * register_hosts_task; | 255 | struct GNUNET_SCHEDULER_Task *register_hosts_task; |
252 | 256 | ||
253 | /** | 257 | /** |
254 | * Task to be run of a timeout | 258 | * Task to be run of a timeout |
255 | */ | 259 | */ |
256 | struct GNUNET_SCHEDULER_Task * timeout_task; | 260 | struct GNUNET_SCHEDULER_Task *timeout_task; |
257 | 261 | ||
258 | /** | 262 | /** |
259 | * Task run upon shutdown interrupts | 263 | * Task run upon shutdown interrupts |
@@ -331,16 +335,17 @@ struct GNUNET_TESTBED_RunHandle { | |||
331 | * @return 32-bit key | 335 | * @return 32-bit key |
332 | */ | 336 | */ |
333 | static uint32_t | 337 | static uint32_t |
334 | rcop_key(void *rcop) | 338 | rcop_key (void *rcop) |
335 | { | 339 | { |
336 | return *((uint32_t *)&rcop); | 340 | return *((uint32_t *) &rcop); |
337 | } | 341 | } |
338 | 342 | ||
339 | 343 | ||
340 | /** | 344 | /** |
341 | * Context information used for finding a pointer in the rcop_map | 345 | * Context information used for finding a pointer in the rcop_map |
342 | */ | 346 | */ |
343 | struct SearchContext { | 347 | struct SearchContext |
348 | { | ||
344 | /** | 349 | /** |
345 | * The operation pointer to look for | 350 | * The operation pointer to look for |
346 | */ | 351 | */ |
@@ -362,18 +367,18 @@ struct SearchContext { | |||
362 | * @return GNUNET_YES to continue iteration; GNUNET_NO to cancel it | 367 | * @return GNUNET_YES to continue iteration; GNUNET_NO to cancel it |
363 | */ | 368 | */ |
364 | static int | 369 | static int |
365 | search_iterator(void *cls, uint32_t key, void *value) | 370 | search_iterator (void *cls, uint32_t key, void *value) |
366 | { | 371 | { |
367 | struct RunContextOperation *rcop = value; | 372 | struct RunContextOperation *rcop = value; |
368 | struct SearchContext *sc = cls; | 373 | struct SearchContext *sc = cls; |
369 | 374 | ||
370 | GNUNET_assert(NULL != rcop); | 375 | GNUNET_assert (NULL != rcop); |
371 | if (sc->query == rcop->op) | 376 | if (sc->query == rcop->op) |
372 | { | 377 | { |
373 | GNUNET_assert(NULL == sc->result); | 378 | GNUNET_assert (NULL == sc->result); |
374 | sc->result = rcop; | 379 | sc->result = rcop; |
375 | return GNUNET_NO; | 380 | return GNUNET_NO; |
376 | } | 381 | } |
377 | return GNUNET_YES; | 382 | return GNUNET_YES; |
378 | } | 383 | } |
379 | 384 | ||
@@ -387,21 +392,22 @@ search_iterator(void *cls, uint32_t key, void *value) | |||
387 | * @return the matching RunContextOperation if found; NULL if not | 392 | * @return the matching RunContextOperation if found; NULL if not |
388 | */ | 393 | */ |
389 | static struct RunContextOperation * | 394 | static struct RunContextOperation * |
390 | search_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operation *op) | 395 | search_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct |
396 | GNUNET_TESTBED_Operation *op) | ||
391 | { | 397 | { |
392 | struct SearchContext sc; | 398 | struct SearchContext sc; |
393 | 399 | ||
394 | sc.query = op; | 400 | sc.query = op; |
395 | sc.result = NULL; | 401 | sc.result = NULL; |
396 | if (GNUNET_SYSERR == | 402 | if (GNUNET_SYSERR == |
397 | GNUNET_CONTAINER_multihashmap32_get_multiple(rc->rcop_map, | 403 | GNUNET_CONTAINER_multihashmap32_get_multiple (rc->rcop_map, |
398 | rcop_key(op), | 404 | rcop_key (op), |
399 | &search_iterator, | 405 | &search_iterator, |
400 | &sc)) | 406 | &sc)) |
401 | { | 407 | { |
402 | GNUNET_assert(NULL != sc.result); | 408 | GNUNET_assert (NULL != sc.result); |
403 | return sc.result; | 409 | return sc.result; |
404 | } | 410 | } |
405 | return NULL; | 411 | return NULL; |
406 | } | 412 | } |
407 | 413 | ||
@@ -413,12 +419,13 @@ search_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operation | |||
413 | * @param rcop the RunContextOperation to insert | 419 | * @param rcop the RunContextOperation to insert |
414 | */ | 420 | */ |
415 | static void | 421 | static void |
416 | insert_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) | 422 | insert_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct |
423 | RunContextOperation *rcop) | ||
417 | { | 424 | { |
418 | GNUNET_assert(GNUNET_OK == | 425 | GNUNET_assert (GNUNET_OK == |
419 | GNUNET_CONTAINER_multihashmap32_put(rc->rcop_map, | 426 | GNUNET_CONTAINER_multihashmap32_put (rc->rcop_map, |
420 | rcop_key(rcop->op), rcop, | 427 | rcop_key (rcop->op), rcop, |
421 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 428 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
422 | } | 429 | } |
423 | 430 | ||
424 | 431 | ||
@@ -430,12 +437,13 @@ insert_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rco | |||
430 | * @param rcop the RunContextOperation | 437 | * @param rcop the RunContextOperation |
431 | */ | 438 | */ |
432 | static void | 439 | static void |
433 | remove_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) | 440 | remove_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct |
441 | RunContextOperation *rcop) | ||
434 | { | 442 | { |
435 | GNUNET_assert(GNUNET_YES == | 443 | GNUNET_assert (GNUNET_YES == |
436 | GNUNET_CONTAINER_multihashmap32_remove(rc->rcop_map, | 444 | GNUNET_CONTAINER_multihashmap32_remove (rc->rcop_map, |
437 | rcop_key(rcop->op), | 445 | rcop_key (rcop->op), |
438 | rcop)); | 446 | rcop)); |
439 | } | 447 | } |
440 | 448 | ||
441 | /** | 449 | /** |
@@ -444,31 +452,31 @@ remove_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rco | |||
444 | * @param rc the run context | 452 | * @param rc the run context |
445 | */ | 453 | */ |
446 | static void | 454 | static void |
447 | cleanup(struct GNUNET_TESTBED_RunHandle *rc) | 455 | cleanup (struct GNUNET_TESTBED_RunHandle *rc) |
448 | { | 456 | { |
449 | unsigned int hid; | 457 | unsigned int hid; |
450 | 458 | ||
451 | GNUNET_assert(NULL == rc->register_hosts_task); | 459 | GNUNET_assert (NULL == rc->register_hosts_task); |
452 | GNUNET_assert(NULL == rc->reg_handle); | 460 | GNUNET_assert (NULL == rc->reg_handle); |
453 | GNUNET_assert(NULL == rc->peers); | 461 | GNUNET_assert (NULL == rc->peers); |
454 | GNUNET_assert(NULL == rc->hclist); | 462 | GNUNET_assert (NULL == rc->hclist); |
455 | GNUNET_assert(RC_PEERS_SHUTDOWN == rc->state); | 463 | GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state); |
456 | GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(rc->rcop_map)); | 464 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map)); |
457 | GNUNET_CONTAINER_multihashmap32_destroy(rc->rcop_map); | 465 | GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map); |
458 | if (NULL != rc->c) | 466 | if (NULL != rc->c) |
459 | GNUNET_TESTBED_controller_disconnect(rc->c); | 467 | GNUNET_TESTBED_controller_disconnect (rc->c); |
460 | if (NULL != rc->cproc) | 468 | if (NULL != rc->cproc) |
461 | GNUNET_TESTBED_controller_stop(rc->cproc); | 469 | GNUNET_TESTBED_controller_stop (rc->cproc); |
462 | if (NULL != rc->h) | 470 | if (NULL != rc->h) |
463 | GNUNET_TESTBED_host_destroy(rc->h); | 471 | GNUNET_TESTBED_host_destroy (rc->h); |
464 | for (hid = 0; hid < rc->num_hosts; hid++) | 472 | for (hid = 0; hid < rc->num_hosts; hid++) |
465 | GNUNET_TESTBED_host_destroy(rc->hosts[hid]); | 473 | GNUNET_TESTBED_host_destroy (rc->hosts[hid]); |
466 | GNUNET_free_non_null(rc->hosts); | 474 | GNUNET_free_non_null (rc->hosts); |
467 | if (NULL != rc->cfg) | 475 | if (NULL != rc->cfg) |
468 | GNUNET_CONFIGURATION_destroy(rc->cfg); | 476 | GNUNET_CONFIGURATION_destroy (rc->cfg); |
469 | GNUNET_free_non_null(rc->topo_file); | 477 | GNUNET_free_non_null (rc->topo_file); |
470 | GNUNET_free_non_null(rc->trusted_ip); | 478 | GNUNET_free_non_null (rc->trusted_ip); |
471 | GNUNET_free(rc); | 479 | GNUNET_free (rc); |
472 | } | 480 | } |
473 | 481 | ||
474 | 482 | ||
@@ -481,15 +489,15 @@ cleanup(struct GNUNET_TESTBED_RunHandle *rc) | |||
481 | * @return always GNUNET_YES | 489 | * @return always GNUNET_YES |
482 | */ | 490 | */ |
483 | static int | 491 | static int |
484 | rcop_cleanup_iterator(void *cls, uint32_t key, void *value) | 492 | rcop_cleanup_iterator (void *cls, uint32_t key, void *value) |
485 | { | 493 | { |
486 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 494 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
487 | struct RunContextOperation *rcop = value; | 495 | struct RunContextOperation *rcop = value; |
488 | 496 | ||
489 | GNUNET_assert(rc == rcop->rc); | 497 | GNUNET_assert (rc == rcop->rc); |
490 | remove_rcop(rc, rcop); | 498 | remove_rcop (rc, rcop); |
491 | GNUNET_TESTBED_operation_done(rcop->op); | 499 | GNUNET_TESTBED_operation_done (rcop->op); |
492 | GNUNET_free(rcop); | 500 | GNUNET_free (rcop); |
493 | return GNUNET_YES; | 501 | return GNUNET_YES; |
494 | } | 502 | } |
495 | 503 | ||
@@ -500,48 +508,48 @@ rcop_cleanup_iterator(void *cls, uint32_t key, void *value) | |||
500 | * @param rc the RunContext | 508 | * @param rc the RunContext |
501 | */ | 509 | */ |
502 | static void | 510 | static void |
503 | rc_cleanup_operations(struct GNUNET_TESTBED_RunHandle *rc) | 511 | rc_cleanup_operations (struct GNUNET_TESTBED_RunHandle *rc) |
504 | { | 512 | { |
505 | struct CompatibilityCheckContext *hc; | 513 | struct CompatibilityCheckContext *hc; |
506 | unsigned int nhost; | 514 | unsigned int nhost; |
507 | 515 | ||
508 | if (NULL != rc->hclist) | 516 | if (NULL != rc->hclist) |
517 | { | ||
518 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | ||
509 | { | 519 | { |
510 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | 520 | hc = &rc->hclist[nhost]; |
511 | { | 521 | if (NULL != hc->h) |
512 | hc = &rc->hclist[nhost]; | 522 | GNUNET_TESTBED_is_host_habitable_cancel (hc->h); |
513 | if (NULL != hc->h) | ||
514 | GNUNET_TESTBED_is_host_habitable_cancel(hc->h); | ||
515 | } | ||
516 | GNUNET_free(rc->hclist); | ||
517 | rc->hclist = NULL; | ||
518 | } | 523 | } |
524 | GNUNET_free (rc->hclist); | ||
525 | rc->hclist = NULL; | ||
526 | } | ||
519 | /* Stop register hosts task if it is running */ | 527 | /* Stop register hosts task if it is running */ |
520 | if (NULL != rc->register_hosts_task) | 528 | if (NULL != rc->register_hosts_task) |
521 | { | 529 | { |
522 | GNUNET_SCHEDULER_cancel(rc->register_hosts_task); | 530 | GNUNET_SCHEDULER_cancel (rc->register_hosts_task); |
523 | rc->register_hosts_task = NULL; | 531 | rc->register_hosts_task = NULL; |
524 | } | 532 | } |
525 | if (NULL != rc->timeout_task) | 533 | if (NULL != rc->timeout_task) |
526 | { | 534 | { |
527 | GNUNET_SCHEDULER_cancel(rc->timeout_task); | 535 | GNUNET_SCHEDULER_cancel (rc->timeout_task); |
528 | rc->timeout_task = NULL; | 536 | rc->timeout_task = NULL; |
529 | } | 537 | } |
530 | if (NULL != rc->reg_handle) | 538 | if (NULL != rc->reg_handle) |
531 | { | 539 | { |
532 | GNUNET_TESTBED_cancel_registration(rc->reg_handle); | 540 | GNUNET_TESTBED_cancel_registration (rc->reg_handle); |
533 | rc->reg_handle = NULL; | 541 | rc->reg_handle = NULL; |
534 | } | 542 | } |
535 | if (NULL != rc->topology_operation) | 543 | if (NULL != rc->topology_operation) |
536 | { | 544 | { |
537 | GNUNET_TESTBED_operation_done(rc->topology_operation); | 545 | GNUNET_TESTBED_operation_done (rc->topology_operation); |
538 | rc->topology_operation = NULL; | 546 | rc->topology_operation = NULL; |
539 | } | 547 | } |
540 | /* cancel any exiting operations */ | 548 | /* cancel any exiting operations */ |
541 | GNUNET_assert(GNUNET_SYSERR != | 549 | GNUNET_assert (GNUNET_SYSERR != |
542 | GNUNET_CONTAINER_multihashmap32_iterate(rc->rcop_map, | 550 | GNUNET_CONTAINER_multihashmap32_iterate (rc->rcop_map, |
543 | &rcop_cleanup_iterator, | 551 | &rcop_cleanup_iterator, |
544 | rc)); | 552 | rc)); |
545 | } | 553 | } |
546 | 554 | ||
547 | 555 | ||
@@ -551,9 +559,9 @@ rc_cleanup_operations(struct GNUNET_TESTBED_RunHandle *rc) | |||
551 | * @param rc the run context | 559 | * @param rc the run context |
552 | */ | 560 | */ |
553 | static void | 561 | static void |
554 | cancel_interrupt_task(struct GNUNET_TESTBED_RunHandle *rc) | 562 | cancel_interrupt_task (struct GNUNET_TESTBED_RunHandle *rc) |
555 | { | 563 | { |
556 | GNUNET_SCHEDULER_cancel(rc->interrupt_task); | 564 | GNUNET_SCHEDULER_cancel (rc->interrupt_task); |
557 | rc->interrupt_task = NULL; | 565 | rc->interrupt_task = NULL; |
558 | } | 566 | } |
559 | 567 | ||
@@ -565,7 +573,7 @@ cancel_interrupt_task(struct GNUNET_TESTBED_RunHandle *rc) | |||
565 | * @param cls run context | 573 | * @param cls run context |
566 | */ | 574 | */ |
567 | static void | 575 | static void |
568 | wait_op_completion(void *cls) | 576 | wait_op_completion (void *cls) |
569 | { | 577 | { |
570 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 578 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
571 | struct RunContextOperation *rcop; | 579 | struct RunContextOperation *rcop; |
@@ -573,30 +581,30 @@ wait_op_completion(void *cls) | |||
573 | if ((NULL == rc->cproc) | 581 | if ((NULL == rc->cproc) |
574 | || (NULL == rc->c) | 582 | || (NULL == rc->c) |
575 | || (GNUNET_YES == rc->shutdown)) | 583 | || (GNUNET_YES == rc->shutdown)) |
584 | { | ||
585 | if (NULL != rc->peers) | ||
576 | { | 586 | { |
577 | if (NULL != rc->peers) | 587 | GNUNET_free (rc->peers); |
578 | { | 588 | rc->peers = NULL; |
579 | GNUNET_free(rc->peers); | ||
580 | rc->peers = NULL; | ||
581 | } | ||
582 | goto cleanup_; | ||
583 | } | 589 | } |
590 | goto cleanup_; | ||
591 | } | ||
584 | if (NULL == rc->peers) | 592 | if (NULL == rc->peers) |
585 | goto cleanup_; | 593 | goto cleanup_; |
586 | rc->shutdown = GNUNET_YES; | 594 | rc->shutdown = GNUNET_YES; |
587 | rcop = GNUNET_new(struct RunContextOperation); | 595 | rcop = GNUNET_new (struct RunContextOperation); |
588 | rcop->rc = rc; | 596 | rcop->rc = rc; |
589 | rcop->op = GNUNET_TESTBED_shutdown_peers(rc->c, rcop, NULL, NULL); | 597 | rcop->op = GNUNET_TESTBED_shutdown_peers (rc->c, rcop, NULL, NULL); |
590 | GNUNET_assert(NULL != rcop->op); | 598 | GNUNET_assert (NULL != rcop->op); |
591 | DEBUG("Shutting down peers\n"); | 599 | DEBUG ("Shutting down peers\n"); |
592 | rc->pstart_time = GNUNET_TIME_absolute_get(); | 600 | rc->pstart_time = GNUNET_TIME_absolute_get (); |
593 | insert_rcop(rc, rcop); | 601 | insert_rcop (rc, rcop); |
594 | return; | 602 | return; |
595 | 603 | ||
596 | cleanup_: | 604 | cleanup_: |
597 | rc->state = RC_PEERS_SHUTDOWN; | 605 | rc->state = RC_PEERS_SHUTDOWN; |
598 | cancel_interrupt_task(rc); | 606 | cancel_interrupt_task (rc); |
599 | cleanup(rc); | 607 | cleanup (rc); |
600 | } | 608 | } |
601 | 609 | ||
602 | 610 | ||
@@ -606,28 +614,28 @@ cleanup_: | |||
606 | * @param cls the RunContext which has to be acted upon | 614 | * @param cls the RunContext which has to be acted upon |
607 | */ | 615 | */ |
608 | static void | 616 | static void |
609 | interrupt(void *cls) | 617 | interrupt (void *cls) |
610 | { | 618 | { |
611 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 619 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
612 | struct GNUNET_TESTBED_Controller *c = rc->c; | 620 | struct GNUNET_TESTBED_Controller *c = rc->c; |
613 | unsigned int size; | 621 | unsigned int size; |
614 | 622 | ||
615 | /* reschedule */ | 623 | /* reschedule */ |
616 | rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown(&interrupt, rc); | 624 | rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown (&interrupt, rc); |
617 | rc_cleanup_operations(rc); | 625 | rc_cleanup_operations (rc); |
618 | if ((GNUNET_NO == rc->shutdown) && | 626 | if ((GNUNET_NO == rc->shutdown) && |
619 | (NULL != c) && | 627 | (NULL != c) && |
620 | (NULL != c->opc_map) && | 628 | (NULL != c->opc_map) && |
621 | (0 != (size = GNUNET_CONTAINER_multihashmap32_size(c->opc_map)))) | 629 | (0 != (size = GNUNET_CONTAINER_multihashmap32_size (c->opc_map)))) |
622 | { | 630 | { |
623 | LOG(GNUNET_ERROR_TYPE_WARNING, | 631 | LOG (GNUNET_ERROR_TYPE_WARNING, |
624 | "Shutdown postponed as there are %u operations currently active\n", | 632 | "Shutdown postponed as there are %u operations currently active\n", |
625 | size); | 633 | size); |
626 | c->opcq_empty_cb = &wait_op_completion; | 634 | c->opcq_empty_cb = &wait_op_completion; |
627 | c->opcq_empty_cls = rc; | 635 | c->opcq_empty_cls = rc; |
628 | return; | 636 | return; |
629 | } | 637 | } |
630 | wait_op_completion(rc); | 638 | wait_op_completion (rc); |
631 | } | 639 | } |
632 | 640 | ||
633 | 641 | ||
@@ -639,12 +647,12 @@ interrupt(void *cls) | |||
639 | * @return the representation string; this is NOT reentrant | 647 | * @return the representation string; this is NOT reentrant |
640 | */ | 648 | */ |
641 | static const char * | 649 | static const char * |
642 | prof_time(struct GNUNET_TESTBED_RunHandle *rc) | 650 | prof_time (struct GNUNET_TESTBED_RunHandle *rc) |
643 | { | 651 | { |
644 | struct GNUNET_TIME_Relative ptime; | 652 | struct GNUNET_TIME_Relative ptime; |
645 | 653 | ||
646 | ptime = GNUNET_TIME_absolute_get_duration(rc->pstart_time); | 654 | ptime = GNUNET_TIME_absolute_get_duration (rc->pstart_time); |
647 | return GNUNET_STRINGS_relative_time_to_string(ptime, GNUNET_YES); | 655 | return GNUNET_STRINGS_relative_time_to_string (ptime, GNUNET_YES); |
648 | } | 656 | } |
649 | 657 | ||
650 | 658 | ||
@@ -654,23 +662,23 @@ prof_time(struct GNUNET_TESTBED_RunHandle *rc) | |||
654 | * @param cls the RunHandle | 662 | * @param cls the RunHandle |
655 | */ | 663 | */ |
656 | static void | 664 | static void |
657 | start_peers_task(void *cls) | 665 | start_peers_task (void *cls) |
658 | { | 666 | { |
659 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 667 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
660 | struct RunContextOperation *rcop; | 668 | struct RunContextOperation *rcop; |
661 | unsigned int peer; | 669 | unsigned int peer; |
662 | 670 | ||
663 | DEBUG("Starting Peers\n"); | 671 | DEBUG ("Starting Peers\n"); |
664 | rc->pstart_time = GNUNET_TIME_absolute_get(); | 672 | rc->pstart_time = GNUNET_TIME_absolute_get (); |
665 | for (peer = 0; peer < rc->num_peers; peer++) | 673 | for (peer = 0; peer < rc->num_peers; peer++) |
666 | { | 674 | { |
667 | rcop = GNUNET_new(struct RunContextOperation); | 675 | rcop = GNUNET_new (struct RunContextOperation); |
668 | rcop->rc = rc; | 676 | rcop->rc = rc; |
669 | rcop->op = GNUNET_TESTBED_peer_start(NULL, rc->peers[peer], NULL, NULL); | 677 | rcop->op = GNUNET_TESTBED_peer_start (NULL, rc->peers[peer], NULL, NULL); |
670 | GNUNET_assert(NULL != rcop->op); | 678 | GNUNET_assert (NULL != rcop->op); |
671 | rcop->cls = rc->peers[peer]; | 679 | rcop->cls = rc->peers[peer]; |
672 | insert_rcop(rc, rcop); | 680 | insert_rcop (rc, rcop); |
673 | } | 681 | } |
674 | rc->peer_count = 0; | 682 | rc->peer_count = 0; |
675 | } | 683 | } |
676 | 684 | ||
@@ -685,31 +693,31 @@ start_peers_task(void *cls) | |||
685 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | 693 | * @param emsg NULL if peer is not NULL; else MAY contain the error description |
686 | */ | 694 | */ |
687 | static void | 695 | static void |
688 | peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | 696 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) |
689 | { | 697 | { |
690 | struct RunContextOperation *rcop = cls; | 698 | struct RunContextOperation *rcop = cls; |
691 | struct GNUNET_TESTBED_RunHandle *rc; | 699 | struct GNUNET_TESTBED_RunHandle *rc; |
692 | 700 | ||
693 | GNUNET_assert(NULL != rcop); | 701 | GNUNET_assert (NULL != rcop); |
694 | GNUNET_assert(NULL != (rc = rcop->rc)); | 702 | GNUNET_assert (NULL != (rc = rcop->rc)); |
695 | remove_rcop(rc, rcop); | 703 | remove_rcop (rc, rcop); |
696 | GNUNET_TESTBED_operation_done(rcop->op); | 704 | GNUNET_TESTBED_operation_done (rcop->op); |
697 | GNUNET_free(rcop); | 705 | GNUNET_free (rcop); |
698 | if (NULL == peer) | 706 | if (NULL == peer) |
699 | { | 707 | { |
700 | if (NULL != emsg) | 708 | if (NULL != emsg) |
701 | LOG(GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n", | 709 | LOG (GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n", |
702 | emsg); | 710 | emsg); |
703 | GNUNET_SCHEDULER_shutdown(); | 711 | GNUNET_SCHEDULER_shutdown (); |
704 | return; | 712 | return; |
705 | } | 713 | } |
706 | rc->peers[rc->peer_count] = peer; | 714 | rc->peers[rc->peer_count] = peer; |
707 | rc->peer_count++; | 715 | rc->peer_count++; |
708 | if (rc->peer_count < rc->num_peers) | 716 | if (rc->peer_count < rc->num_peers) |
709 | return; | 717 | return; |
710 | DEBUG("%u peers created in %s\n", rc->num_peers, prof_time(rc)); | 718 | DEBUG ("%u peers created in %s\n", rc->num_peers, prof_time (rc)); |
711 | rc->state = RC_PEERS_CREATED; | 719 | rc->state = RC_PEERS_CREATED; |
712 | GNUNET_SCHEDULER_add_now(&start_peers_task, rc); | 720 | GNUNET_SCHEDULER_add_now (&start_peers_task, rc); |
713 | } | 721 | } |
714 | 722 | ||
715 | 723 | ||
@@ -719,13 +727,13 @@ peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | |||
719 | * @param rc the RunContext | 727 | * @param rc the RunContext |
720 | */ | 728 | */ |
721 | static void | 729 | static void |
722 | call_master(struct GNUNET_TESTBED_RunHandle *rc) | 730 | call_master (struct GNUNET_TESTBED_RunHandle *rc) |
723 | { | 731 | { |
724 | GNUNET_SCHEDULER_cancel(rc->timeout_task); | 732 | GNUNET_SCHEDULER_cancel (rc->timeout_task); |
725 | rc->timeout_task = NULL; | 733 | rc->timeout_task = NULL; |
726 | if (NULL != rc->test_master) | 734 | if (NULL != rc->test_master) |
727 | rc->test_master(rc->test_master_cls, rc, rc->num_peers, rc->peers, | 735 | rc->test_master (rc->test_master_cls, rc, rc->num_peers, rc->peers, |
728 | rc->links_succeeded, rc->links_failed); | 736 | rc->links_succeeded, rc->links_failed); |
729 | } | 737 | } |
730 | 738 | ||
731 | 739 | ||
@@ -739,18 +747,18 @@ call_master(struct GNUNET_TESTBED_RunHandle *rc) | |||
739 | * @param nfailures the number of overlay connects which failed | 747 | * @param nfailures the number of overlay connects which failed |
740 | */ | 748 | */ |
741 | static void | 749 | static void |
742 | topology_completion_callback(void *cls, unsigned int nsuccess, | 750 | topology_completion_callback (void *cls, unsigned int nsuccess, |
743 | unsigned int nfailures) | 751 | unsigned int nfailures) |
744 | { | 752 | { |
745 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 753 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
746 | 754 | ||
747 | DEBUG("Overlay topology generated in %s\n", prof_time(rc)); | 755 | DEBUG ("Overlay topology generated in %s\n", prof_time (rc)); |
748 | GNUNET_TESTBED_operation_done(rc->topology_operation); | 756 | GNUNET_TESTBED_operation_done (rc->topology_operation); |
749 | rc->topology_operation = NULL; | 757 | rc->topology_operation = NULL; |
750 | rc->links_succeeded = nsuccess; | 758 | rc->links_succeeded = nsuccess; |
751 | rc->links_failed = nfailures; | 759 | rc->links_failed = nfailures; |
752 | rc->state = RC_READY; | 760 | rc->state = RC_READY; |
753 | call_master(rc); | 761 | call_master (rc); |
754 | } | 762 | } |
755 | 763 | ||
756 | 764 | ||
@@ -760,30 +768,31 @@ topology_completion_callback(void *cls, unsigned int nsuccess, | |||
760 | * @param rc the RunContext | 768 | * @param rc the RunContext |
761 | */ | 769 | */ |
762 | static void | 770 | static void |
763 | create_peers(struct GNUNET_TESTBED_RunHandle *rc) | 771 | create_peers (struct GNUNET_TESTBED_RunHandle *rc) |
764 | { | 772 | { |
765 | struct RunContextOperation *rcop; | 773 | struct RunContextOperation *rcop; |
766 | unsigned int peer; | 774 | unsigned int peer; |
767 | 775 | ||
768 | DEBUG("Creating peers\n"); | 776 | DEBUG ("Creating peers\n"); |
769 | rc->pstart_time = GNUNET_TIME_absolute_get(); | 777 | rc->pstart_time = GNUNET_TIME_absolute_get (); |
770 | rc->peers = | 778 | rc->peers = |
771 | GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Peer *) * rc->num_peers); | 779 | GNUNET_malloc (sizeof(struct GNUNET_TESTBED_Peer *) * rc->num_peers); |
772 | GNUNET_assert(NULL != rc->c); | 780 | GNUNET_assert (NULL != rc->c); |
773 | rc->peer_count = 0; | 781 | rc->peer_count = 0; |
774 | for (peer = 0; peer < rc->num_peers; peer++) | 782 | for (peer = 0; peer < rc->num_peers; peer++) |
775 | { | 783 | { |
776 | rcop = GNUNET_new(struct RunContextOperation); | 784 | rcop = GNUNET_new (struct RunContextOperation); |
777 | rcop->rc = rc; | 785 | rcop->rc = rc; |
778 | rcop->op = | 786 | rcop->op = |
779 | GNUNET_TESTBED_peer_create(rc->c, | 787 | GNUNET_TESTBED_peer_create (rc->c, |
780 | (0 == | 788 | (0 == |
781 | rc->num_hosts) ? rc->h : rc->hosts[peer % | 789 | rc->num_hosts) ? rc->h : rc->hosts[peer |
782 | rc->num_hosts], | 790 | % rc-> |
783 | rc->cfg, &peer_create_cb, rcop); | 791 | num_hosts], |
784 | GNUNET_assert(NULL != rcop->op); | 792 | rc->cfg, &peer_create_cb, rcop); |
785 | insert_rcop(rc, rcop); | 793 | GNUNET_assert (NULL != rcop->op); |
786 | } | 794 | insert_rcop (rc, rcop); |
795 | } | ||
787 | } | 796 | } |
788 | 797 | ||
789 | 798 | ||
@@ -795,166 +804,170 @@ create_peers(struct GNUNET_TESTBED_RunHandle *rc) | |||
795 | * @param event information about the event | 804 | * @param event information about the event |
796 | */ | 805 | */ |
797 | static void | 806 | static void |
798 | event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 807 | event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
799 | { | 808 | { |
800 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 809 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
801 | struct RunContextOperation *rcop; | 810 | struct RunContextOperation *rcop; |
802 | 811 | ||
803 | if (RC_INIT == rc->state) | 812 | if (RC_INIT == rc->state) |
813 | { | ||
814 | switch (event->type) | ||
804 | { | 815 | { |
805 | switch (event->type) | 816 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
806 | { | 817 | rcop = event->op_cls; |
807 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | 818 | if (NULL != event->details.operation_finished.emsg) |
808 | rcop = event->op_cls; | 819 | { |
809 | if (NULL != event->details.operation_finished.emsg) | 820 | LOG (GNUNET_ERROR_TYPE_ERROR, _ ( |
810 | { | 821 | "Linking controllers failed. Exiting")); |
811 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting")); | 822 | GNUNET_SCHEDULER_shutdown (); |
812 | GNUNET_SCHEDULER_shutdown(); | 823 | } |
813 | } | 824 | else |
814 | else | 825 | rc->reg_hosts++; |
815 | rc->reg_hosts++; | 826 | GNUNET_assert (event->op == rcop->op); |
816 | GNUNET_assert(event->op == rcop->op); | 827 | remove_rcop (rc, rcop); |
817 | remove_rcop(rc, rcop); | 828 | GNUNET_TESTBED_operation_done (rcop->op); |
818 | GNUNET_TESTBED_operation_done(rcop->op); | 829 | GNUNET_free (rcop); |
819 | GNUNET_free(rcop); | 830 | if (rc->reg_hosts == rc->num_hosts) |
820 | if (rc->reg_hosts == rc->num_hosts) | 831 | { |
821 | { | 832 | rc->state = RC_LINKED; |
822 | rc->state = RC_LINKED; | 833 | create_peers (rc); |
823 | create_peers(rc); | 834 | } |
824 | } | 835 | return; |
825 | return; | 836 | |
826 | 837 | default: | |
827 | default: | 838 | GNUNET_break (0); |
828 | GNUNET_break(0); | 839 | GNUNET_SCHEDULER_shutdown (); |
829 | GNUNET_SCHEDULER_shutdown(); | 840 | return; |
830 | return; | ||
831 | } | ||
832 | } | 841 | } |
842 | } | ||
833 | if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) | 843 | if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) |
834 | goto call_cc; | 844 | goto call_cc; |
835 | if (NULL == (rcop = search_rcop(rc, event->op))) | 845 | if (NULL == (rcop = search_rcop (rc, event->op))) |
836 | goto call_cc; | 846 | goto call_cc; |
837 | remove_rcop(rc, rcop); | 847 | remove_rcop (rc, rcop); |
838 | GNUNET_TESTBED_operation_done(rcop->op); | 848 | GNUNET_TESTBED_operation_done (rcop->op); |
839 | GNUNET_free(rcop); | 849 | GNUNET_free (rcop); |
840 | if ((GNUNET_NO == rc->shutdown) | 850 | if ((GNUNET_NO == rc->shutdown) |
841 | && (NULL != event->details.operation_finished.emsg)) | 851 | && (NULL != event->details.operation_finished.emsg)) |
842 | { | 852 | { |
843 | LOG(GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n", | 853 | LOG (GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n", |
844 | event->details.operation_finished.emsg); | 854 | event->details.operation_finished.emsg); |
845 | GNUNET_SCHEDULER_shutdown(); | 855 | GNUNET_SCHEDULER_shutdown (); |
846 | return; | 856 | return; |
847 | } | 857 | } |
848 | GNUNET_assert(GNUNET_YES == rc->shutdown); | 858 | GNUNET_assert (GNUNET_YES == rc->shutdown); |
849 | switch (rc->state) | 859 | switch (rc->state) |
850 | { | 860 | { |
851 | case RC_LINKED: | 861 | case RC_LINKED: |
852 | case RC_PEERS_CREATED: | 862 | case RC_PEERS_CREATED: |
853 | case RC_READY: | 863 | case RC_READY: |
854 | rc->state = RC_PEERS_SHUTDOWN; | 864 | rc->state = RC_PEERS_SHUTDOWN; |
855 | GNUNET_free_non_null(rc->peers); | 865 | GNUNET_free_non_null (rc->peers); |
856 | rc->peers = NULL; | 866 | rc->peers = NULL; |
857 | DEBUG("Peers shut down in %s\n", prof_time(rc)); | 867 | DEBUG ("Peers shut down in %s\n", prof_time (rc)); |
858 | GNUNET_SCHEDULER_shutdown(); | 868 | GNUNET_SCHEDULER_shutdown (); |
859 | break; | 869 | break; |
860 | 870 | ||
861 | default: | 871 | default: |
862 | GNUNET_assert(0); | 872 | GNUNET_assert (0); |
863 | } | 873 | } |
864 | return; | 874 | return; |
865 | 875 | ||
866 | call_cc: | 876 | call_cc: |
867 | if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc)) | 877 | if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc)) |
868 | rc->cc(rc->cc_cls, event); | 878 | rc->cc (rc->cc_cls, event); |
869 | if (GNUNET_TESTBED_ET_PEER_START != event->type) | 879 | if (GNUNET_TESTBED_ET_PEER_START != event->type) |
870 | return; | 880 | return; |
871 | if (NULL == (rcop = search_rcop(rc, event->op))) /* Not our operation */ | 881 | if (NULL == (rcop = search_rcop (rc, event->op))) /* Not our operation */ |
872 | return; | 882 | return; |
873 | remove_rcop(rc, rcop); | 883 | remove_rcop (rc, rcop); |
874 | GNUNET_TESTBED_operation_done(rcop->op); | 884 | GNUNET_TESTBED_operation_done (rcop->op); |
875 | GNUNET_free(rcop); | 885 | GNUNET_free (rcop); |
876 | rc->peer_count++; | 886 | rc->peer_count++; |
877 | if (rc->peer_count < rc->num_peers) | 887 | if (rc->peer_count < rc->num_peers) |
878 | return; | 888 | return; |
879 | DEBUG("%u peers started in %s\n", rc->num_peers, prof_time(rc)); | 889 | DEBUG ("%u peers started in %s\n", rc->num_peers, prof_time (rc)); |
880 | if (GNUNET_TESTBED_TOPOLOGY_NONE != rc->topology) | 890 | if (GNUNET_TESTBED_TOPOLOGY_NONE != rc->topology) |
891 | { | ||
892 | switch (rc->topology) | ||
881 | { | 893 | { |
882 | switch (rc->topology) | 894 | case GNUNET_TESTBED_TOPOLOGY_NONE: |
883 | { | 895 | GNUNET_assert (0); |
884 | case GNUNET_TESTBED_TOPOLOGY_NONE: | 896 | |
885 | GNUNET_assert(0); | 897 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: |
886 | 898 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | |
887 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | 899 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: |
888 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | 900 | rc->topology_operation = |
889 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | 901 | GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, |
890 | rc->topology_operation = | 902 | rc->peers, &rc->num_oc, |
891 | GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, | 903 | &topology_completion_callback, |
892 | rc->peers, &rc->num_oc, | 904 | rc, |
893 | &topology_completion_callback, | 905 | rc->topology, |
894 | rc, | 906 | rc->random_links, |
895 | rc->topology, | 907 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
896 | rc->random_links, | 908 | break; |
897 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 909 | |
898 | break; | 910 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: |
899 | 911 | GNUNET_assert (NULL != rc->topo_file); | |
900 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | 912 | rc->topology_operation = |
901 | GNUNET_assert(NULL != rc->topo_file); | 913 | GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, |
902 | rc->topology_operation = | 914 | rc->peers, &rc->num_oc, |
903 | GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, | 915 | &topology_completion_callback, |
904 | rc->peers, &rc->num_oc, | 916 | rc, |
905 | &topology_completion_callback, | 917 | rc->topology, |
906 | rc, | 918 | rc->topo_file, |
907 | rc->topology, | 919 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
908 | rc->topo_file, | 920 | break; |
909 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 921 | |
910 | break; | 922 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: |
911 | 923 | { | |
912 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | 924 | unsigned long long number; |
913 | { | 925 | unsigned int cap; |
914 | unsigned long long number; | 926 | GNUNET_assert (GNUNET_OK == |
915 | unsigned int cap; | 927 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, |
916 | GNUNET_assert(GNUNET_OK == | 928 | TESTBED_CONFIG_SECTION, |
917 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, | ||
918 | SCALE_FREE_CAP, | 929 | SCALE_FREE_CAP, |
919 | &number)); | 930 | &number)); |
920 | cap = (unsigned int)number; | 931 | cap = (unsigned int) number; |
921 | GNUNET_assert(GNUNET_OK == | 932 | GNUNET_assert (GNUNET_OK == |
922 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, | 933 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, |
934 | TESTBED_CONFIG_SECTION, | ||
923 | SCALE_FREE_M, | 935 | SCALE_FREE_M, |
924 | &number)); | 936 | &number)); |
925 | rc->topology_operation = | 937 | rc->topology_operation = |
926 | GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, | 938 | GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, |
927 | rc->peers, &rc->num_oc, | 939 | rc->peers, &rc->num_oc, |
928 | &topology_completion_callback, | 940 | & |
929 | rc, | 941 | topology_completion_callback, |
930 | rc->topology, | 942 | rc, |
931 | cap, /* uint16_t */ | 943 | rc->topology, |
932 | (unsigned int)number, /* uint8_t */ | 944 | cap, /* uint16_t */ |
933 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 945 | (unsigned int) number, /* uint8_t */ |
934 | } | 946 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
935 | break; | 947 | } |
936 | 948 | break; | |
937 | default: | 949 | |
938 | rc->topology_operation = | 950 | default: |
939 | GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, | 951 | rc->topology_operation = |
940 | rc->peers, &rc->num_oc, | 952 | GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, |
941 | &topology_completion_callback, | 953 | rc->peers, &rc->num_oc, |
942 | rc, | 954 | &topology_completion_callback, |
943 | rc->topology, | 955 | rc, |
944 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 956 | rc->topology, |
945 | } | 957 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
946 | if (NULL == rc->topology_operation) | 958 | } |
947 | LOG(GNUNET_ERROR_TYPE_WARNING, | 959 | if (NULL == rc->topology_operation) |
948 | "Not generating a topology. Check number of peers\n"); | 960 | LOG (GNUNET_ERROR_TYPE_WARNING, |
949 | else | 961 | "Not generating a topology. Check number of peers\n"); |
950 | { | 962 | else |
951 | DEBUG("Creating overlay topology\n"); | 963 | { |
952 | rc->pstart_time = GNUNET_TIME_absolute_get(); | 964 | DEBUG ("Creating overlay topology\n"); |
953 | return; | 965 | rc->pstart_time = GNUNET_TIME_absolute_get (); |
954 | } | 966 | return; |
955 | } | 967 | } |
968 | } | ||
956 | rc->state = RC_READY; | 969 | rc->state = RC_READY; |
957 | call_master(rc); | 970 | call_master (rc); |
958 | } | 971 | } |
959 | 972 | ||
960 | 973 | ||
@@ -964,7 +977,7 @@ call_cc: | |||
964 | * @param cls the RunContext | 977 | * @param cls the RunContext |
965 | */ | 978 | */ |
966 | static void | 979 | static void |
967 | register_hosts(void *cls); | 980 | register_hosts (void *cls); |
968 | 981 | ||
969 | 982 | ||
970 | /** | 983 | /** |
@@ -974,20 +987,20 @@ register_hosts(void *cls); | |||
974 | * @param emsg the error message; NULL if host registration is successful | 987 | * @param emsg the error message; NULL if host registration is successful |
975 | */ | 988 | */ |
976 | static void | 989 | static void |
977 | host_registration_completion(void *cls, const char *emsg) | 990 | host_registration_completion (void *cls, const char *emsg) |
978 | { | 991 | { |
979 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 992 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
980 | 993 | ||
981 | rc->reg_handle = NULL; | 994 | rc->reg_handle = NULL; |
982 | if (NULL != emsg) | 995 | if (NULL != emsg) |
983 | { | 996 | { |
984 | LOG(GNUNET_ERROR_TYPE_WARNING, | 997 | LOG (GNUNET_ERROR_TYPE_WARNING, |
985 | _("Host registration failed for a host. Error: %s\n"), emsg); | 998 | _ ("Host registration failed for a host. Error: %s\n"), emsg); |
986 | GNUNET_SCHEDULER_shutdown(); | 999 | GNUNET_SCHEDULER_shutdown (); |
987 | return; | 1000 | return; |
988 | } | 1001 | } |
989 | rc->register_hosts_task = GNUNET_SCHEDULER_add_now(®ister_hosts, | 1002 | rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, |
990 | rc); | 1003 | rc); |
991 | } | 1004 | } |
992 | 1005 | ||
993 | 1006 | ||
@@ -997,7 +1010,7 @@ host_registration_completion(void *cls, const char *emsg) | |||
997 | * @param cls RunContext | 1010 | * @param cls RunContext |
998 | */ | 1011 | */ |
999 | static void | 1012 | static void |
1000 | register_hosts(void *cls) | 1013 | register_hosts (void *cls) |
1001 | { | 1014 | { |
1002 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 1015 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
1003 | struct RunContextOperation *rcop; | 1016 | struct RunContextOperation *rcop; |
@@ -1005,25 +1018,25 @@ register_hosts(void *cls) | |||
1005 | 1018 | ||
1006 | rc->register_hosts_task = NULL; | 1019 | rc->register_hosts_task = NULL; |
1007 | if (rc->reg_hosts == rc->num_hosts) | 1020 | if (rc->reg_hosts == rc->num_hosts) |
1021 | { | ||
1022 | DEBUG ("All hosts successfully registered\n"); | ||
1023 | /* Start slaves */ | ||
1024 | for (slave = 0; slave < rc->num_hosts; slave++) | ||
1008 | { | 1025 | { |
1009 | DEBUG("All hosts successfully registered\n"); | 1026 | rcop = GNUNET_new (struct RunContextOperation); |
1010 | /* Start slaves */ | 1027 | rcop->rc = rc; |
1011 | for (slave = 0; slave < rc->num_hosts; slave++) | 1028 | rcop->op = |
1012 | { | 1029 | GNUNET_TESTBED_controller_link (rcop, rc->c, rc->hosts[slave], |
1013 | rcop = GNUNET_new(struct RunContextOperation); | 1030 | rc->h, GNUNET_YES); |
1014 | rcop->rc = rc; | 1031 | GNUNET_assert (NULL != rcop->op); |
1015 | rcop->op = | 1032 | insert_rcop (rc, rcop); |
1016 | GNUNET_TESTBED_controller_link(rcop, rc->c, rc->hosts[slave], | ||
1017 | rc->h, GNUNET_YES); | ||
1018 | GNUNET_assert(NULL != rcop->op); | ||
1019 | insert_rcop(rc, rcop); | ||
1020 | } | ||
1021 | rc->reg_hosts = 0; | ||
1022 | return; | ||
1023 | } | 1033 | } |
1034 | rc->reg_hosts = 0; | ||
1035 | return; | ||
1036 | } | ||
1024 | rc->reg_handle = | 1037 | rc->reg_handle = |
1025 | GNUNET_TESTBED_register_host(rc->c, rc->hosts[rc->reg_hosts], | 1038 | GNUNET_TESTBED_register_host (rc->c, rc->hosts[rc->reg_hosts], |
1026 | host_registration_completion, rc); | 1039 | host_registration_completion, rc); |
1027 | rc->reg_hosts++; | 1040 | rc->reg_hosts++; |
1028 | } | 1041 | } |
1029 | 1042 | ||
@@ -1038,37 +1051,37 @@ register_hosts(void *cls) | |||
1038 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 1051 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
1039 | */ | 1052 | */ |
1040 | static void | 1053 | static void |
1041 | controller_status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | 1054 | controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
1042 | int status) | 1055 | int status) |
1043 | { | 1056 | { |
1044 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 1057 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
1045 | uint64_t event_mask; | 1058 | uint64_t event_mask; |
1046 | 1059 | ||
1047 | if (status != GNUNET_OK) | 1060 | if (status != GNUNET_OK) |
1048 | { | 1061 | { |
1049 | rc->cproc = NULL; | 1062 | rc->cproc = NULL; |
1050 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1063 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1051 | _("Controller crash detected. Shutting down.\n")); | 1064 | _ ("Controller crash detected. Shutting down.\n")); |
1052 | GNUNET_SCHEDULER_shutdown(); | 1065 | GNUNET_SCHEDULER_shutdown (); |
1053 | return; | 1066 | return; |
1054 | } | 1067 | } |
1055 | GNUNET_CONFIGURATION_destroy(rc->cfg); | 1068 | GNUNET_CONFIGURATION_destroy (rc->cfg); |
1056 | rc->cfg = GNUNET_CONFIGURATION_dup(cfg); | 1069 | rc->cfg = GNUNET_CONFIGURATION_dup (cfg); |
1057 | event_mask = rc->event_mask; | 1070 | event_mask = rc->event_mask; |
1058 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 1071 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
1059 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 1072 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
1060 | if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE) | 1073 | if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE) |
1061 | event_mask |= GNUNET_TESTBED_ET_CONNECT; | 1074 | event_mask |= GNUNET_TESTBED_ET_CONNECT; |
1062 | rc->c = | 1075 | rc->c = |
1063 | GNUNET_TESTBED_controller_connect(rc->h, event_mask, &event_cb, rc); | 1076 | GNUNET_TESTBED_controller_connect (rc->h, event_mask, &event_cb, rc); |
1064 | if (0 < rc->num_hosts) | 1077 | if (0 < rc->num_hosts) |
1065 | { | 1078 | { |
1066 | rc->reg_hosts = 0; | 1079 | rc->reg_hosts = 0; |
1067 | rc->register_hosts_task = GNUNET_SCHEDULER_add_now(®ister_hosts, rc); | 1080 | rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, rc); |
1068 | return; | 1081 | return; |
1069 | } | 1082 | } |
1070 | rc->state = RC_LINKED; | 1083 | rc->state = RC_LINKED; |
1071 | create_peers(rc); | 1084 | create_peers (rc); |
1072 | } | 1085 | } |
1073 | 1086 | ||
1074 | 1087 | ||
@@ -1085,9 +1098,9 @@ controller_status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1085 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort | 1098 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort |
1086 | */ | 1099 | */ |
1087 | static int | 1100 | static int |
1088 | netint_proc(void *cls, const char *name, int isDefault, | 1101 | netint_proc (void *cls, const char *name, int isDefault, |
1089 | const struct sockaddr *addr, const struct sockaddr *broadcast_addr, | 1102 | const struct sockaddr *addr, const struct sockaddr *broadcast_addr, |
1090 | const struct sockaddr *netmask, socklen_t addrlen) | 1103 | const struct sockaddr *netmask, socklen_t addrlen) |
1091 | { | 1104 | { |
1092 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 1105 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
1093 | char hostip[NI_MAXHOST]; | 1106 | char hostip[NI_MAXHOST]; |
@@ -1096,15 +1109,15 @@ netint_proc(void *cls, const char *name, int isDefault, | |||
1096 | if (sizeof(struct sockaddr_in) != addrlen) | 1109 | if (sizeof(struct sockaddr_in) != addrlen) |
1097 | return GNUNET_OK; /* Only consider IPv4 for now */ | 1110 | return GNUNET_OK; /* Only consider IPv4 for now */ |
1098 | if (0 != | 1111 | if (0 != |
1099 | getnameinfo(addr, addrlen, hostip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) | 1112 | getnameinfo (addr, addrlen, hostip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) |
1100 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "getnameinfo"); | 1113 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getnameinfo"); |
1101 | if (NULL == rc->trusted_ip) | 1114 | if (NULL == rc->trusted_ip) |
1102 | { | 1115 | { |
1103 | rc->trusted_ip = GNUNET_strdup(hostip); | 1116 | rc->trusted_ip = GNUNET_strdup (hostip); |
1104 | return GNUNET_YES; | 1117 | return GNUNET_YES; |
1105 | } | 1118 | } |
1106 | (void)GNUNET_asprintf(&buf, "%s; %s", rc->trusted_ip, hostip); | 1119 | (void) GNUNET_asprintf (&buf, "%s; %s", rc->trusted_ip, hostip); |
1107 | GNUNET_free(rc->trusted_ip); | 1120 | GNUNET_free (rc->trusted_ip); |
1108 | rc->trusted_ip = buf; | 1121 | rc->trusted_ip = buf; |
1109 | return GNUNET_YES; | 1122 | return GNUNET_YES; |
1110 | } | 1123 | } |
@@ -1121,67 +1134,67 @@ netint_proc(void *cls, const char *name, int isDefault, | |||
1121 | * @param status GNUNET_YES if it is habitable; GNUNET_NO if not | 1134 | * @param status GNUNET_YES if it is habitable; GNUNET_NO if not |
1122 | */ | 1135 | */ |
1123 | static void | 1136 | static void |
1124 | host_habitable_cb(void *cls, const struct GNUNET_TESTBED_Host *host, | 1137 | host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, |
1125 | int status) | 1138 | int status) |
1126 | { | 1139 | { |
1127 | struct CompatibilityCheckContext *hc = cls; | 1140 | struct CompatibilityCheckContext *hc = cls; |
1128 | struct GNUNET_TESTBED_RunHandle *rc; | 1141 | struct GNUNET_TESTBED_RunHandle *rc; |
1129 | struct GNUNET_TESTBED_Host **old_hosts; | 1142 | struct GNUNET_TESTBED_Host **old_hosts; |
1130 | unsigned int nhost; | 1143 | unsigned int nhost; |
1131 | 1144 | ||
1132 | GNUNET_assert(NULL != (rc = hc->rc)); | 1145 | GNUNET_assert (NULL != (rc = hc->rc)); |
1133 | nhost = hc->index; | 1146 | nhost = hc->index; |
1134 | GNUNET_assert(nhost <= rc->num_hosts); | 1147 | GNUNET_assert (nhost <= rc->num_hosts); |
1135 | GNUNET_assert(host == rc->hosts[nhost]); | 1148 | GNUNET_assert (host == rc->hosts[nhost]); |
1136 | hc->h = NULL; | 1149 | hc->h = NULL; |
1137 | if (GNUNET_NO == status) | 1150 | if (GNUNET_NO == status) |
1138 | { | 1151 | { |
1139 | if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname(host))) | 1152 | if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname (host))) |
1140 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Host %s cannot start testbed\n"), | 1153 | LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Host %s cannot start testbed\n"), |
1141 | GNUNET_TESTBED_host_get_hostname(host)); | 1154 | GNUNET_TESTBED_host_get_hostname (host)); |
1142 | else | 1155 | else |
1143 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1156 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1144 | _("Testbed cannot be started on localhost\n")); | 1157 | _ ("Testbed cannot be started on localhost\n")); |
1145 | GNUNET_SCHEDULER_shutdown(); | 1158 | GNUNET_SCHEDULER_shutdown (); |
1146 | return; | 1159 | return; |
1147 | } | 1160 | } |
1148 | rc->reg_hosts++; | 1161 | rc->reg_hosts++; |
1149 | if (rc->reg_hosts < rc->num_hosts) | 1162 | if (rc->reg_hosts < rc->num_hosts) |
1150 | return; | 1163 | return; |
1151 | GNUNET_free(rc->hclist); | 1164 | GNUNET_free (rc->hclist); |
1152 | rc->hclist = NULL; | 1165 | rc->hclist = NULL; |
1153 | rc->h = rc->hosts[0]; | 1166 | rc->h = rc->hosts[0]; |
1154 | rc->num_hosts--; | 1167 | rc->num_hosts--; |
1155 | if (0 < rc->num_hosts) | 1168 | if (0 < rc->num_hosts) |
1156 | { | 1169 | { |
1157 | old_hosts = rc->hosts; | 1170 | old_hosts = rc->hosts; |
1158 | rc->hosts = | 1171 | rc->hosts = |
1159 | GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts); | 1172 | GNUNET_malloc (sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts); |
1160 | GNUNET_memcpy(rc->hosts, &old_hosts[1], | 1173 | GNUNET_memcpy (rc->hosts, &old_hosts[1], |
1161 | (sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts)); | 1174 | (sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts)); |
1162 | GNUNET_free(old_hosts); | 1175 | GNUNET_free (old_hosts); |
1163 | } | 1176 | } |
1164 | else | 1177 | else |
1165 | { | 1178 | { |
1166 | GNUNET_free(rc->hosts); | 1179 | GNUNET_free (rc->hosts); |
1167 | rc->hosts = NULL; | 1180 | rc->hosts = NULL; |
1168 | } | 1181 | } |
1169 | GNUNET_TESTBED_host_resolve_(rc->h); | 1182 | GNUNET_TESTBED_host_resolve_ (rc->h); |
1170 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | 1183 | for (nhost = 0; nhost < rc->num_hosts; nhost++) |
1171 | GNUNET_TESTBED_host_resolve_(rc->hosts[nhost]); | 1184 | GNUNET_TESTBED_host_resolve_ (rc->hosts[nhost]); |
1172 | GNUNET_OS_network_interfaces_list(netint_proc, rc); | 1185 | GNUNET_OS_network_interfaces_list (netint_proc, rc); |
1173 | if (NULL == rc->trusted_ip) | 1186 | if (NULL == rc->trusted_ip) |
1174 | rc->trusted_ip = GNUNET_strdup("127.0.0.1"); | 1187 | rc->trusted_ip = GNUNET_strdup ("127.0.0.1"); |
1175 | rc->cproc = | 1188 | rc->cproc = |
1176 | GNUNET_TESTBED_controller_start(rc->trusted_ip, rc->h, | 1189 | GNUNET_TESTBED_controller_start (rc->trusted_ip, rc->h, |
1177 | &controller_status_cb, rc); | 1190 | &controller_status_cb, rc); |
1178 | GNUNET_free(rc->trusted_ip); | 1191 | GNUNET_free (rc->trusted_ip); |
1179 | rc->trusted_ip = NULL; | 1192 | rc->trusted_ip = NULL; |
1180 | if (NULL == rc->cproc) | 1193 | if (NULL == rc->cproc) |
1181 | { | 1194 | { |
1182 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Cannot start the master controller")); | 1195 | LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot start the master controller")); |
1183 | GNUNET_SCHEDULER_shutdown(); | 1196 | GNUNET_SCHEDULER_shutdown (); |
1184 | } | 1197 | } |
1185 | } | 1198 | } |
1186 | 1199 | ||
1187 | 1200 | ||
@@ -1191,16 +1204,16 @@ host_habitable_cb(void *cls, const struct GNUNET_TESTBED_Host *host, | |||
1191 | * @param cls the RunContext | 1204 | * @param cls the RunContext |
1192 | */ | 1205 | */ |
1193 | static void | 1206 | static void |
1194 | timeout_task(void *cls) | 1207 | timeout_task (void *cls) |
1195 | { | 1208 | { |
1196 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 1209 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
1197 | 1210 | ||
1198 | rc->timeout_task = NULL; | 1211 | rc->timeout_task = NULL; |
1199 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1212 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1200 | _("Shutting down testbed due to timeout while setup.\n")); | 1213 | _ ("Shutting down testbed due to timeout while setup.\n")); |
1201 | GNUNET_SCHEDULER_shutdown(); | 1214 | GNUNET_SCHEDULER_shutdown (); |
1202 | if (NULL != rc->test_master) | 1215 | if (NULL != rc->test_master) |
1203 | rc->test_master(rc->test_master_cls, rc, 0, NULL, 0, 0); | 1216 | rc->test_master (rc->test_master_cls, rc, 0, NULL, 0, 0); |
1204 | rc->test_master = NULL; | 1217 | rc->test_master = NULL; |
1205 | } | 1218 | } |
1206 | 1219 | ||
@@ -1233,12 +1246,12 @@ timeout_task(void *cls) | |||
1233 | * @param test_master_cls closure for 'test_master'. | 1246 | * @param test_master_cls closure for 'test_master'. |
1234 | */ | 1247 | */ |
1235 | void | 1248 | void |
1236 | GNUNET_TESTBED_run(const char *host_filename, | 1249 | GNUNET_TESTBED_run (const char *host_filename, |
1237 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1250 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1238 | unsigned int num_peers, uint64_t event_mask, | 1251 | unsigned int num_peers, uint64_t event_mask, |
1239 | GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, | 1252 | GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, |
1240 | GNUNET_TESTBED_TestMaster test_master, | 1253 | GNUNET_TESTBED_TestMaster test_master, |
1241 | void *test_master_cls) | 1254 | void *test_master_cls) |
1242 | { | 1255 | { |
1243 | struct GNUNET_TESTBED_RunHandle *rc; | 1256 | struct GNUNET_TESTBED_RunHandle *rc; |
1244 | char *topology; | 1257 | char *topology; |
@@ -1248,33 +1261,33 @@ GNUNET_TESTBED_run(const char *host_filename, | |||
1248 | unsigned int hid; | 1261 | unsigned int hid; |
1249 | unsigned int nhost; | 1262 | unsigned int nhost; |
1250 | 1263 | ||
1251 | GNUNET_assert(num_peers > 0); | 1264 | GNUNET_assert (num_peers > 0); |
1252 | rc = GNUNET_new(struct GNUNET_TESTBED_RunHandle); | 1265 | rc = GNUNET_new (struct GNUNET_TESTBED_RunHandle); |
1253 | rc->cfg = GNUNET_CONFIGURATION_dup(cfg); | 1266 | rc->cfg = GNUNET_CONFIGURATION_dup (cfg); |
1254 | #if ENABLE_SUPERMUC | 1267 | #if ENABLE_SUPERMUC |
1255 | rc->num_hosts = GNUNET_TESTBED_hosts_load_from_loadleveler(rc->cfg, | 1268 | rc->num_hosts = GNUNET_TESTBED_hosts_load_from_loadleveler (rc->cfg, |
1256 | &rc->hosts); | 1269 | &rc->hosts); |
1257 | if (0 == rc->num_hosts) | 1270 | if (0 == rc->num_hosts) |
1258 | { | 1271 | { |
1259 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1272 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1260 | _("No hosts loaded from LoadLeveler. Need at least one host\n")); | 1273 | _ ("No hosts loaded from LoadLeveler. Need at least one host\n")); |
1261 | goto error_cleanup; | 1274 | goto error_cleanup; |
1262 | } | 1275 | } |
1263 | #else | 1276 | #else |
1264 | if (NULL != host_filename) | 1277 | if (NULL != host_filename) |
1278 | { | ||
1279 | rc->num_hosts = | ||
1280 | GNUNET_TESTBED_hosts_load_from_file (host_filename, rc->cfg, | ||
1281 | &rc->hosts); | ||
1282 | if (0 == rc->num_hosts) | ||
1265 | { | 1283 | { |
1266 | rc->num_hosts = | 1284 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1267 | GNUNET_TESTBED_hosts_load_from_file(host_filename, rc->cfg, | 1285 | _ ("No hosts loaded. Need at least one host\n")); |
1268 | &rc->hosts); | 1286 | goto error_cleanup; |
1269 | if (0 == rc->num_hosts) | ||
1270 | { | ||
1271 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
1272 | _("No hosts loaded. Need at least one host\n")); | ||
1273 | goto error_cleanup; | ||
1274 | } | ||
1275 | } | 1287 | } |
1288 | } | ||
1276 | else | 1289 | else |
1277 | rc->h = GNUNET_TESTBED_host_create(NULL, NULL, rc->cfg, 0); | 1290 | rc->h = GNUNET_TESTBED_host_create (NULL, NULL, rc->cfg, 0); |
1278 | #endif | 1291 | #endif |
1279 | rc->num_peers = num_peers; | 1292 | rc->num_peers = num_peers; |
1280 | rc->event_mask = event_mask; | 1293 | rc->event_mask = event_mask; |
@@ -1285,162 +1298,170 @@ GNUNET_TESTBED_run(const char *host_filename, | |||
1285 | rc->state = RC_INIT; | 1298 | rc->state = RC_INIT; |
1286 | rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE; | 1299 | rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE; |
1287 | if (GNUNET_OK == | 1300 | if (GNUNET_OK == |
1288 | GNUNET_CONFIGURATION_get_value_string(rc->cfg, TESTBED_CONFIG_SECTION, | 1301 | GNUNET_CONFIGURATION_get_value_string (rc->cfg, TESTBED_CONFIG_SECTION, |
1289 | "OVERLAY_TOPOLOGY", &topology)) | 1302 | "OVERLAY_TOPOLOGY", &topology)) |
1303 | { | ||
1304 | if (GNUNET_NO == GNUNET_TESTBED_topology_get_ (&rc->topology, topology)) | ||
1290 | { | 1305 | { |
1291 | if (GNUNET_NO == GNUNET_TESTBED_topology_get_(&rc->topology, topology)) | 1306 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
1292 | { | 1307 | TESTBED_CONFIG_SECTION, |
1293 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | 1308 | "OVERLAY_TOPLOGY", |
1294 | "OVERLAY_TOPLOGY", | 1309 | _ |
1295 | _ | 1310 | ( |
1296 | ("Specified topology must be supported by testbed")); | 1311 | "Specified topology must be supported by testbed")); |
1297 | } | ||
1298 | GNUNET_free(topology); | ||
1299 | } | 1312 | } |
1313 | GNUNET_free (topology); | ||
1314 | } | ||
1300 | switch (rc->topology) | 1315 | switch (rc->topology) |
1316 | { | ||
1317 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | ||
1318 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | ||
1319 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | ||
1320 | if (GNUNET_OK != | ||
1321 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, | ||
1322 | "OVERLAY_RANDOM_LINKS", | ||
1323 | &number)) | ||
1301 | { | 1324 | { |
1302 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | 1325 | /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS |
1303 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | 1326 | * option to be set to the number of random links to be established */ |
1304 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | 1327 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1305 | if (GNUNET_OK != | 1328 | TESTBED_CONFIG_SECTION, |
1306 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, | 1329 | "OVERLAY_RANDOM_LINKS"); |
1307 | "OVERLAY_RANDOM_LINKS", | 1330 | goto error_cleanup; |
1308 | &number)) | 1331 | } |
1309 | { | 1332 | if (number > UINT32_MAX) |
1310 | /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS | 1333 | { |
1311 | * option to be set to the number of random links to be established */ | 1334 | GNUNET_break (0); /* Too big number */ |
1312 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | 1335 | goto error_cleanup; |
1313 | "OVERLAY_RANDOM_LINKS"); | 1336 | } |
1314 | goto error_cleanup; | 1337 | rc->random_links = (unsigned int) number; |
1315 | } | 1338 | break; |
1316 | if (number > UINT32_MAX) | 1339 | |
1317 | { | 1340 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: |
1318 | GNUNET_break(0); /* Too big number */ | 1341 | if (GNUNET_OK != |
1319 | goto error_cleanup; | 1342 | GNUNET_CONFIGURATION_get_value_filename (rc->cfg, |
1320 | } | 1343 | TESTBED_CONFIG_SECTION, |
1321 | rc->random_links = (unsigned int)number; | 1344 | "OVERLAY_TOPOLOGY_FILE", |
1322 | break; | 1345 | &rc->topo_file)) |
1323 | 1346 | { | |
1324 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | 1347 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1325 | if (GNUNET_OK != | 1348 | TESTBED_CONFIG_SECTION, |
1326 | GNUNET_CONFIGURATION_get_value_filename(rc->cfg, TESTBED_CONFIG_SECTION, | 1349 | "OVERLAY_TOPOLOGY_FILE"); |
1327 | "OVERLAY_TOPOLOGY_FILE", | 1350 | goto error_cleanup; |
1328 | &rc->topo_file)) | 1351 | } |
1329 | { | 1352 | goto warn_ignore; |
1330 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | ||
1331 | "OVERLAY_TOPOLOGY_FILE"); | ||
1332 | goto error_cleanup; | ||
1333 | } | ||
1334 | goto warn_ignore; | ||
1335 | 1353 | ||
1336 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | 1354 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: |
1337 | if (GNUNET_OK != | 1355 | if (GNUNET_OK != |
1338 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, | 1356 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, |
1339 | SCALE_FREE_CAP, &number)) | 1357 | SCALE_FREE_CAP, &number)) |
1340 | { | 1358 | { |
1341 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | 1359 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1342 | SCALE_FREE_CAP); | 1360 | TESTBED_CONFIG_SECTION, |
1343 | goto error_cleanup; | 1361 | SCALE_FREE_CAP); |
1344 | } | 1362 | goto error_cleanup; |
1345 | if (UINT16_MAX < number) | 1363 | } |
1346 | { | 1364 | if (UINT16_MAX < number) |
1347 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1365 | { |
1348 | _("Maximum number of edges a peer can have in a scale free topology" | 1366 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1349 | " cannot be more than %u. Given `%s = %llu'"), UINT16_MAX, | 1367 | _ ("Maximum number of edges a peer can have in a scale free topology" |
1350 | SCALE_FREE_CAP, number); | 1368 | " cannot be more than %u. Given `%s = %llu'"), UINT16_MAX, |
1351 | goto error_cleanup; | 1369 | SCALE_FREE_CAP, number); |
1352 | } | 1370 | goto error_cleanup; |
1353 | if (GNUNET_OK != | 1371 | } |
1354 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, | 1372 | if (GNUNET_OK != |
1355 | SCALE_FREE_M, &number)) | 1373 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, |
1356 | { | 1374 | SCALE_FREE_M, &number)) |
1357 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | 1375 | { |
1358 | SCALE_FREE_M); | 1376 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
1359 | goto error_cleanup; | 1377 | TESTBED_CONFIG_SECTION, |
1360 | } | 1378 | SCALE_FREE_M); |
1361 | if (UINT8_MAX < number) | 1379 | goto error_cleanup; |
1362 | { | 1380 | } |
1363 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1381 | if (UINT8_MAX < number) |
1364 | _("The number of edges that can established when adding a new node" | 1382 | { |
1365 | " to scale free topology cannot be more than %u. Given `%s = %llu'"), | 1383 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1366 | UINT8_MAX, SCALE_FREE_M, number); | 1384 | _ ("The number of edges that can established when adding a new node" |
1367 | goto error_cleanup; | 1385 | " to scale free topology cannot be more than %u. Given `%s = %llu'"), |
1368 | } | 1386 | UINT8_MAX, SCALE_FREE_M, number); |
1369 | goto warn_ignore; | 1387 | goto error_cleanup; |
1388 | } | ||
1389 | goto warn_ignore; | ||
1370 | 1390 | ||
1371 | case GNUNET_TESTBED_TOPOLOGY_OPTION_END: | 1391 | case GNUNET_TESTBED_TOPOLOGY_OPTION_END: |
1372 | /* not allowed! */ | 1392 | /* not allowed! */ |
1373 | GNUNET_assert(0); | 1393 | GNUNET_assert (0); |
1374 | 1394 | ||
1375 | default: | 1395 | default: |
1376 | warn_ignore: | 1396 | warn_ignore: |
1377 | /* Warn if OVERLAY_RANDOM_LINKS is present that it will be ignored */ | 1397 | /* Warn if OVERLAY_RANDOM_LINKS is present that it will be ignored */ |
1378 | if (GNUNET_YES == | 1398 | if (GNUNET_YES == |
1379 | GNUNET_CONFIGURATION_have_value(rc->cfg, TESTBED_CONFIG_SECTION, | 1399 | GNUNET_CONFIGURATION_have_value (rc->cfg, TESTBED_CONFIG_SECTION, |
1380 | "OVERLAY_RANDOM_LINKS")) | 1400 | "OVERLAY_RANDOM_LINKS")) |
1381 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1401 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1382 | "Ignoring value of `OVERLAY_RANDOM_LINKS' in given configuration\n"); | 1402 | "Ignoring value of `OVERLAY_RANDOM_LINKS' in given configuration\n"); |
1383 | break; | 1403 | break; |
1384 | } | 1404 | } |
1385 | if (0 != rc->num_hosts) | 1405 | if (0 != rc->num_hosts) |
1406 | { | ||
1407 | rc->hclist = GNUNET_malloc (sizeof(struct CompatibilityCheckContext) | ||
1408 | * rc->num_hosts); | ||
1409 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | ||
1386 | { | 1410 | { |
1387 | rc->hclist = GNUNET_malloc(sizeof(struct CompatibilityCheckContext) | 1411 | hc = &rc->hclist[nhost]; |
1388 | * rc->num_hosts); | 1412 | hc->index = nhost; |
1389 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | 1413 | hc->rc = rc; |
1414 | hc->h = GNUNET_TESTBED_is_host_habitable (rc->hosts[nhost], rc->cfg, | ||
1415 | &host_habitable_cb, hc); | ||
1416 | if (NULL == hc->h) | ||
1417 | { | ||
1418 | GNUNET_break (0); | ||
1419 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | ||
1390 | { | 1420 | { |
1391 | hc = &rc->hclist[nhost]; | 1421 | hc = &rc->hclist[nhost]; |
1392 | hc->index = nhost; | 1422 | if (NULL != hc->h) |
1393 | hc->rc = rc; | 1423 | GNUNET_TESTBED_is_host_habitable_cancel (hc->h); |
1394 | hc->h = GNUNET_TESTBED_is_host_habitable(rc->hosts[nhost], rc->cfg, | ||
1395 | &host_habitable_cb, hc); | ||
1396 | if (NULL == hc->h) | ||
1397 | { | ||
1398 | GNUNET_break(0); | ||
1399 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | ||
1400 | { | ||
1401 | hc = &rc->hclist[nhost]; | ||
1402 | if (NULL != hc->h) | ||
1403 | GNUNET_TESTBED_is_host_habitable_cancel(hc->h); | ||
1404 | } | ||
1405 | GNUNET_free(rc->hclist); | ||
1406 | rc->hclist = NULL; | ||
1407 | goto error_cleanup; | ||
1408 | } | ||
1409 | } | 1424 | } |
1425 | GNUNET_free (rc->hclist); | ||
1426 | rc->hclist = NULL; | ||
1427 | goto error_cleanup; | ||
1428 | } | ||
1410 | } | 1429 | } |
1430 | } | ||
1411 | else | 1431 | else |
1412 | rc->cproc = | 1432 | rc->cproc = |
1413 | GNUNET_TESTBED_controller_start("127.0.0.1", rc->h, | 1433 | GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h, |
1414 | &controller_status_cb, rc); | 1434 | &controller_status_cb, rc); |
1415 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, TESTBED_CONFIG_SECTION, | 1435 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, |
1416 | "SETUP_TIMEOUT", | 1436 | TESTBED_CONFIG_SECTION, |
1417 | &timeout)) | 1437 | "SETUP_TIMEOUT", |
1418 | { | 1438 | &timeout)) |
1419 | timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 1439 | { |
1420 | DEFAULT_SETUP_TIMEOUT); | 1440 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
1421 | } | 1441 | DEFAULT_SETUP_TIMEOUT); |
1422 | rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create(256); | 1442 | } |
1443 | rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create (256); | ||
1423 | rc->timeout_task = | 1444 | rc->timeout_task = |
1424 | GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task, rc); | 1445 | GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc); |
1425 | GNUNET_assert(NULL == rc->interrupt_task); | 1446 | GNUNET_assert (NULL == rc->interrupt_task); |
1426 | rc->interrupt_task = | 1447 | rc->interrupt_task = |
1427 | GNUNET_SCHEDULER_add_shutdown(&interrupt, | 1448 | GNUNET_SCHEDULER_add_shutdown (&interrupt, |
1428 | rc); | 1449 | rc); |
1429 | return; | 1450 | return; |
1430 | 1451 | ||
1431 | error_cleanup: | 1452 | error_cleanup: |
1432 | if (NULL != rc->h) | 1453 | if (NULL != rc->h) |
1433 | GNUNET_TESTBED_host_destroy(rc->h); | 1454 | GNUNET_TESTBED_host_destroy (rc->h); |
1434 | if (NULL != rc->hosts) | 1455 | if (NULL != rc->hosts) |
1435 | { | 1456 | { |
1436 | for (hid = 0; hid < rc->num_hosts; hid++) | 1457 | for (hid = 0; hid < rc->num_hosts; hid++) |
1437 | if (NULL != rc->hosts[hid]) | 1458 | if (NULL != rc->hosts[hid]) |
1438 | GNUNET_TESTBED_host_destroy(rc->hosts[hid]); | 1459 | GNUNET_TESTBED_host_destroy (rc->hosts[hid]); |
1439 | GNUNET_free(rc->hosts); | 1460 | GNUNET_free (rc->hosts); |
1440 | } | 1461 | } |
1441 | if (NULL != rc->cfg) | 1462 | if (NULL != rc->cfg) |
1442 | GNUNET_CONFIGURATION_destroy(rc->cfg); | 1463 | GNUNET_CONFIGURATION_destroy (rc->cfg); |
1443 | GNUNET_free(rc); | 1464 | GNUNET_free (rc); |
1444 | } | 1465 | } |
1445 | 1466 | ||
1446 | 1467 | ||
@@ -1452,7 +1473,7 @@ error_cleanup: | |||
1452 | * @return handle to the master controller | 1473 | * @return handle to the master controller |
1453 | */ | 1474 | */ |
1454 | struct GNUNET_TESTBED_Controller * | 1475 | struct GNUNET_TESTBED_Controller * |
1455 | GNUNET_TESTBED_run_get_controller_handle(struct GNUNET_TESTBED_RunHandle *h) | 1476 | GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h) |
1456 | { | 1477 | { |
1457 | return h->c; | 1478 | return h->c; |
1458 | } | 1479 | } |