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