aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_topology.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/testbed_api_topology.c')
-rw-r--r--src/testbed/testbed_api_topology.c1236
1 files changed, 627 insertions, 609 deletions
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c
index 58ccf4580..191dbab66 100644
--- a/src/testbed/testbed_api_topology.c
+++ b/src/testbed/testbed_api_topology.c
@@ -34,7 +34,7 @@
34 * Generic loggins shorthand 34 * Generic loggins shorthand
35 */ 35 */
36#define LOG(kind, ...) \ 36#define LOG(kind, ...) \
37 GNUNET_log_from(kind, "testbed-api-topology", __VA_ARGS__) 37 GNUNET_log_from (kind, "testbed-api-topology", __VA_ARGS__)
38 38
39 39
40/** 40/**
@@ -52,7 +52,8 @@ struct TopologyContext;
52/** 52/**
53 * Representation of an overlay link 53 * Representation of an overlay link
54 */ 54 */
55struct OverlayLink { 55struct OverlayLink
56{
56 /** 57 /**
57 * An operation corresponding to this link 58 * An operation corresponding to this link
58 */ 59 */
@@ -78,7 +79,8 @@ struct OverlayLink {
78/** 79/**
79 * Representation of an underlay link 80 * Representation of an underlay link
80 */ 81 */
81struct UnderlayLink { 82struct UnderlayLink
83{
82 /** 84 /**
83 * position of peer A's handle in peers array 85 * position of peer A's handle in peers array
84 */ 86 */
@@ -106,7 +108,8 @@ struct UnderlayLink {
106}; 108};
107 109
108 110
109struct RetryListEntry { 111struct RetryListEntry
112{
110 /** 113 /**
111 * the next pointer for the DLL 114 * the next pointer for the DLL
112 */ 115 */
@@ -127,7 +130,8 @@ struct RetryListEntry {
127/** 130/**
128 * Context information for overlay topologies 131 * Context information for overlay topologies
129 */ 132 */
130struct TopologyContextOverlay { 133struct TopologyContextOverlay
134{
131 /** 135 /**
132 * The array of peers 136 * The array of peers
133 */ 137 */
@@ -193,7 +197,8 @@ struct TopologyContextOverlay {
193/** 197/**
194 * Topology context information for underlay topologies 198 * Topology context information for underlay topologies
195 */ 199 */
196struct TopologyContextUnderlay { 200struct TopologyContextUnderlay
201{
197 /** 202 /**
198 * The link array 203 * The link array
199 */ 204 */
@@ -204,11 +209,13 @@ struct TopologyContextUnderlay {
204/** 209/**
205 * Context information for topology operations 210 * Context information for topology operations
206 */ 211 */
207struct TopologyContext { 212struct TopologyContext
213{
208 /** 214 /**
209 * The type of this context 215 * The type of this context
210 */ 216 */
211 enum { 217 enum
218 {
212 /** 219 /**
213 * Type for underlay topology 220 * Type for underlay topology
214 */ 221 */
@@ -220,7 +227,8 @@ struct TopologyContext {
220 TOPOLOGYCONTEXT_TYPE_OVERLAY 227 TOPOLOGYCONTEXT_TYPE_OVERLAY
221 } type; 228 } type;
222 229
223 union { 230 union
231 {
224 /** 232 /**
225 * Topology context information for overlay topology 233 * Topology context information for overlay topology
226 */ 234 */
@@ -333,69 +341,69 @@ static const char *topology_strings[] = {
333 * operation has executed successfully. 341 * operation has executed successfully.
334 */ 342 */
335static void 343static void
336overlay_link_completed(void *cls, 344overlay_link_completed (void *cls,
337 struct GNUNET_TESTBED_Operation *op, 345 struct GNUNET_TESTBED_Operation *op,
338 const char *emsg) 346 const char *emsg)
339{ 347{
340 struct OverlayLink *link = cls; 348 struct OverlayLink *link = cls;
341 struct TopologyContext *tc; 349 struct TopologyContext *tc;
342 struct TopologyContextOverlay *overlay; 350 struct TopologyContextOverlay *overlay;
343 struct RetryListEntry *retry_entry; 351 struct RetryListEntry *retry_entry;
344 352
345 GNUNET_assert(op == link->op); 353 GNUNET_assert (op == link->op);
346 GNUNET_TESTBED_operation_done(op); 354 GNUNET_TESTBED_operation_done (op);
347 link->op = NULL; 355 link->op = NULL;
348 tc = link->tc; 356 tc = link->tc;
349 GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); 357 GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
350 overlay = &tc->u.overlay; 358 overlay = &tc->u.overlay;
351 if (NULL != emsg) 359 if (NULL != emsg)
360 {
361 overlay->nfailures++;
362 if (0 != overlay->retry_cnt)
352 { 363 {
353 overlay->nfailures++; 364 LOG (GNUNET_ERROR_TYPE_WARNING,
354 if (0 != overlay->retry_cnt) 365 "Error while establishing a link: %s -- Retrying\n",
355 { 366 emsg);
356 LOG(GNUNET_ERROR_TYPE_WARNING, 367 retry_entry = GNUNET_new (struct RetryListEntry);
357 "Error while establishing a link: %s -- Retrying\n", 368 retry_entry->link = link;
358 emsg); 369 GNUNET_CONTAINER_DLL_insert_tail (overlay->rl_head,
359 retry_entry = GNUNET_new(struct RetryListEntry); 370 overlay->rl_tail,
360 retry_entry->link = link; 371 retry_entry);
361 GNUNET_CONTAINER_DLL_insert_tail(overlay->rl_head,
362 overlay->rl_tail,
363 retry_entry);
364 }
365 } 372 }
373 }
366 else 374 else
367 overlay->nsuccess++; 375 overlay->nsuccess++;
368 overlay->ncompleted++; 376 overlay->ncompleted++;
369 if (overlay->ncompleted < overlay->nlinks) 377 if (overlay->ncompleted < overlay->nlinks)
370 return; 378 return;
371 if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head)) 379 if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head))
380 {
381 overlay->retry_cnt--;
382 overlay->ncompleted = 0;
383 overlay->nlinks = 0;
384 while (NULL != (retry_entry = overlay->rl_head))
372 { 385 {
373 overlay->retry_cnt--; 386 link = retry_entry->link;
374 overlay->ncompleted = 0; 387 link->op =
375 overlay->nlinks = 0; 388 GNUNET_TESTBED_overlay_connect (overlay->op_cls,
376 while (NULL != (retry_entry = overlay->rl_head)) 389 &overlay_link_completed,
377 { 390 link,
378 link = retry_entry->link; 391 overlay->peers[link->A],
379 link->op = 392 overlay->peers[link->B]);
380 GNUNET_TESTBED_overlay_connect(overlay->op_cls, 393 overlay->nlinks++;
381 &overlay_link_completed, 394 GNUNET_CONTAINER_DLL_remove (overlay->rl_head,
382 link, 395 overlay->rl_tail,
383 overlay->peers[link->A], 396 retry_entry);
384 overlay->peers[link->B]); 397 GNUNET_free (retry_entry);
385 overlay->nlinks++;
386 GNUNET_CONTAINER_DLL_remove(overlay->rl_head,
387 overlay->rl_tail,
388 retry_entry);
389 GNUNET_free(retry_entry);
390 }
391 return;
392 } 398 }
399 return;
400 }
393 if (NULL != overlay->comp_cb) 401 if (NULL != overlay->comp_cb)
394 { 402 {
395 overlay->comp_cb(overlay->comp_cb_cls, 403 overlay->comp_cb (overlay->comp_cb_cls,
396 overlay->nsuccess, 404 overlay->nsuccess,
397 overlay->nfailures); 405 overlay->nfailures);
398 } 406 }
399} 407}
400 408
401 409
@@ -406,24 +414,24 @@ overlay_link_completed(void *cls,
406 * @param cls the Topology context 414 * @param cls the Topology context
407 */ 415 */
408static void 416static void
409opstart_overlay_configure_topology(void *cls) 417opstart_overlay_configure_topology (void *cls)
410{ 418{
411 struct TopologyContext *tc = cls; 419 struct TopologyContext *tc = cls;
412 struct TopologyContextOverlay *overlay; 420 struct TopologyContextOverlay *overlay;
413 unsigned int p; 421 unsigned int p;
414 422
415 GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); 423 GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
416 overlay = &tc->u.overlay; 424 overlay = &tc->u.overlay;
417 overlay->nlinks = tc->link_array_size; 425 overlay->nlinks = tc->link_array_size;
418 for (p = 0; p < tc->link_array_size; p++) 426 for (p = 0; p < tc->link_array_size; p++)
419 { 427 {
420 overlay->link_array[p].op = 428 overlay->link_array[p].op =
421 GNUNET_TESTBED_overlay_connect(overlay->op_cls, 429 GNUNET_TESTBED_overlay_connect (overlay->op_cls,
422 &overlay_link_completed, 430 &overlay_link_completed,
423 &overlay->link_array[p], 431 &overlay->link_array[p],
424 overlay->peers[overlay->link_array[p].A], 432 overlay->peers[overlay->link_array[p].A],
425 overlay->peers[overlay->link_array[p].B]); 433 overlay->peers[overlay->link_array[p].B]);
426 } 434 }
427} 435}
428 436
429 437
@@ -433,28 +441,29 @@ opstart_overlay_configure_topology(void *cls)
433 * @param cls the Topology context 441 * @param cls the Topology context
434 */ 442 */
435static void 443static void
436oprelease_overlay_configure_topology(void *cls) 444oprelease_overlay_configure_topology (void *cls)
437{ 445{
438 struct TopologyContext *tc = cls; 446 struct TopologyContext *tc = cls;
439 struct TopologyContextOverlay *overlay; 447 struct TopologyContextOverlay *overlay;
440 struct RetryListEntry *retry_entry; 448 struct RetryListEntry *retry_entry;
441 unsigned int p; 449 unsigned int p;
442 450
443 GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); 451 GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
444 overlay = &tc->u.overlay; 452 overlay = &tc->u.overlay;
445 while (NULL != (retry_entry = overlay->rl_head)) 453 while (NULL != (retry_entry = overlay->rl_head))
446 { 454 {
447 GNUNET_CONTAINER_DLL_remove(overlay->rl_head, overlay->rl_tail, retry_entry); 455 GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail,
448 GNUNET_free(retry_entry); 456 retry_entry);
449 } 457 GNUNET_free (retry_entry);
458 }
450 if (NULL != overlay->link_array) 459 if (NULL != overlay->link_array)
451 { 460 {
452 for (p = 0; p < tc->link_array_size; p++) 461 for (p = 0; p < tc->link_array_size; p++)
453 if (NULL != overlay->link_array[p].op) 462 if (NULL != overlay->link_array[p].op)
454 GNUNET_TESTBED_operation_done(overlay->link_array[p].op); 463 GNUNET_TESTBED_operation_done (overlay->link_array[p].op);
455 GNUNET_free(overlay->link_array); 464 GNUNET_free (overlay->link_array);
456 } 465 }
457 GNUNET_free(tc); 466 GNUNET_free (tc);
458} 467}
459 468
460 469
@@ -468,23 +477,23 @@ oprelease_overlay_configure_topology(void *cls)
468 * @return 477 * @return
469 */ 478 */
470static void 479static void
471make_link(unsigned int offset, 480make_link (unsigned int offset,
472 uint32_t A, 481 uint32_t A,
473 uint32_t B, 482 uint32_t B,
474 struct TopologyContext *tc) 483 struct TopologyContext *tc)
475{ 484{
476 GNUNET_assert(A != B); 485 GNUNET_assert (A != B);
477 switch (tc->type) 486 switch (tc->type)
478 { 487 {
479 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 488 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
480 { 489 {
481 struct TopologyContextOverlay *overlay; 490 struct TopologyContextOverlay *overlay;
482 struct OverlayLink *olink; 491 struct OverlayLink *olink;
483 492
484 overlay = &tc->u.overlay; 493 overlay = &tc->u.overlay;
485 GNUNET_assert(offset < tc->link_array_size); 494 GNUNET_assert (offset < tc->link_array_size);
486 olink = &overlay->link_array[offset]; 495 olink = &overlay->link_array[offset];
487 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A); 496 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A);
488 olink->A = A; 497 olink->A = A;
489 olink->B = B; 498 olink->B = B;
490 olink->op = NULL; 499 olink->op = NULL;
@@ -492,19 +501,19 @@ make_link(unsigned int offset,
492 } 501 }
493 break; 502 break;
494 503
495 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 504 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
496 { 505 {
497 struct TopologyContextUnderlay *underlay; 506 struct TopologyContextUnderlay *underlay;
498 struct UnderlayLink *ulink; 507 struct UnderlayLink *ulink;
499 508
500 underlay = &tc->u.underlay; 509 underlay = &tc->u.underlay;
501 GNUNET_assert(offset < tc->link_array_size); 510 GNUNET_assert (offset < tc->link_array_size);
502 ulink = &underlay->link_array[offset]; 511 ulink = &underlay->link_array[offset];
503 ulink->A = A; 512 ulink->A = A;
504 ulink->B = B; 513 ulink->B = B;
505 } 514 }
506 break; 515 break;
507 } 516 }
508} 517}
509 518
510 519
@@ -514,37 +523,37 @@ make_link(unsigned int offset,
514 * @param tc the topology context 523 * @param tc the topology context
515 */ 524 */
516static void 525static void
517gen_topo_line(struct TopologyContext *tc) 526gen_topo_line (struct TopologyContext *tc)
518{ 527{
519 unsigned int cnt; 528 unsigned int cnt;
520 529
521 tc->link_array_size = tc->num_peers - 1; 530 tc->link_array_size = tc->num_peers - 1;
522 switch (tc->type) 531 switch (tc->type)
523 { 532 {
524 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 533 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
525 { 534 {
526 struct TopologyContextOverlay *overlay; 535 struct TopologyContextOverlay *overlay;
527 536
528 overlay = &tc->u.overlay; 537 overlay = &tc->u.overlay;
529 overlay->link_array = 538 overlay->link_array =
530 GNUNET_new_array(tc->link_array_size, 539 GNUNET_new_array (tc->link_array_size,
531 struct OverlayLink); 540 struct OverlayLink);
532 } 541 }
533 break; 542 break;
534 543
535 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 544 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
536 { 545 {
537 struct TopologyContextUnderlay *underlay; 546 struct TopologyContextUnderlay *underlay;
538 547
539 underlay = &tc->u.underlay; 548 underlay = &tc->u.underlay;
540 underlay->link_array = 549 underlay->link_array =
541 GNUNET_new_array(tc->link_array_size, 550 GNUNET_new_array (tc->link_array_size,
542 struct UnderlayLink); 551 struct UnderlayLink);
543 } 552 }
544 break; 553 break;
545 } 554 }
546 for (cnt = 0; cnt < (tc->link_array_size); cnt++) 555 for (cnt = 0; cnt < (tc->link_array_size); cnt++)
547 make_link(cnt, cnt, cnt + 1, tc); 556 make_link (cnt, cnt, cnt + 1, tc);
548} 557}
549 558
550 559
@@ -554,40 +563,40 @@ gen_topo_line(struct TopologyContext *tc)
554 * @param tc the topology context 563 * @param tc the topology context
555 */ 564 */
556static void 565static void
557gen_topo_star(struct TopologyContext *tc) 566gen_topo_star (struct TopologyContext *tc)
558{ 567{
559 unsigned int cnt; 568 unsigned int cnt;
560 569
561 tc->link_array_size = tc->num_peers - 1; 570 tc->link_array_size = tc->num_peers - 1;
562 switch (tc->type) 571 switch (tc->type)
563 { 572 {
564 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 573 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
565 { 574 {
566 struct TopologyContextOverlay *overlay; 575 struct TopologyContextOverlay *overlay;
567 576
568 overlay = &tc->u.overlay; 577 overlay = &tc->u.overlay;
569 overlay->link_array = 578 overlay->link_array =
570 GNUNET_new_array(tc->link_array_size, 579 GNUNET_new_array (tc->link_array_size,
571 struct OverlayLink); 580 struct OverlayLink);
572 } 581 }
573 break; 582 break;
574 583
575 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 584 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
576 { 585 {
577 struct TopologyContextUnderlay *underlay; 586 struct TopologyContextUnderlay *underlay;
578 587
579 underlay = &tc->u.underlay; 588 underlay = &tc->u.underlay;
580 underlay->link_array = 589 underlay->link_array =
581 GNUNET_new_array(tc->link_array_size, 590 GNUNET_new_array (tc->link_array_size,
582 struct UnderlayLink); 591 struct UnderlayLink);
583 } 592 }
584 break; 593 break;
585 } 594 }
586 for (cnt = tc->link_array_size; cnt; cnt--) 595 for (cnt = tc->link_array_size; cnt; cnt--)
587 make_link(cnt - 1, 596 make_link (cnt - 1,
588 0, 597 0,
589 cnt, 598 cnt,
590 tc); 599 tc);
591} 600}
592 601
593 602
@@ -597,35 +606,35 @@ gen_topo_star(struct TopologyContext *tc)
597 * @param tc the topology context 606 * @param tc the topology context
598 */ 607 */
599static void 608static void
600gen_topo_ring(struct TopologyContext *tc) 609gen_topo_ring (struct TopologyContext *tc)
601{ 610{
602 gen_topo_line(tc); 611 gen_topo_line (tc);
603 tc->link_array_size++; 612 tc->link_array_size++;
604 switch (tc->type) 613 switch (tc->type)
605 { 614 {
606 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 615 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
607 { 616 {
608 struct TopologyContextOverlay *overlay; 617 struct TopologyContextOverlay *overlay;
609 618
610 overlay = &tc->u.overlay; 619 overlay = &tc->u.overlay;
611 overlay->link_array = 620 overlay->link_array =
612 GNUNET_realloc(overlay->link_array, sizeof(struct OverlayLink) * 621 GNUNET_realloc (overlay->link_array, sizeof(struct OverlayLink)
613 tc->link_array_size); 622 * tc->link_array_size);
614 } 623 }
615 break; 624 break;
616 625
617 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 626 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
618 { 627 {
619 struct TopologyContextUnderlay *underlay; 628 struct TopologyContextUnderlay *underlay;
620 629
621 underlay = &tc->u.underlay; 630 underlay = &tc->u.underlay;
622 underlay->link_array = 631 underlay->link_array =
623 GNUNET_realloc(underlay->link_array, sizeof(struct UnderlayLink) * 632 GNUNET_realloc (underlay->link_array, sizeof(struct UnderlayLink)
624 tc->link_array_size); 633 * tc->link_array_size);
625 } 634 }
626 break; 635 break;
627 } 636 }
628 make_link(tc->link_array_size - 1, tc->num_peers - 1, 0, tc); 637 make_link (tc->link_array_size - 1, tc->num_peers - 1, 0, tc);
629} 638}
630 639
631 640
@@ -642,8 +651,8 @@ gen_topo_ring(struct TopologyContext *tc)
642 * given number of peers 651 * given number of peers
643 */ 652 */
644unsigned int 653unsigned int
645GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows, 654GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows,
646 unsigned int **rows_len) 655 unsigned int **rows_len)
647{ 656{
648 double sq; 657 double sq;
649 unsigned int sq_floor; 658 unsigned int sq_floor;
@@ -654,11 +663,11 @@ GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows,
654 unsigned int _num_peers; 663 unsigned int _num_peers;
655 unsigned int cnt; 664 unsigned int cnt;
656 665
657 sq = sqrt(num_peers); 666 sq = sqrt (num_peers);
658 sq = floor(sq); 667 sq = floor (sq);
659 sq_floor = (unsigned int)sq; 668 sq_floor = (unsigned int) sq;
660 _rows = (sq_floor + 1); 669 _rows = (sq_floor + 1);
661 _rows_len = GNUNET_malloc(sizeof(unsigned int) * _rows); 670 _rows_len = GNUNET_malloc (sizeof(unsigned int) * _rows);
662 for (y = 0; y < _rows - 1; y++) 671 for (y = 0; y < _rows - 1; y++)
663 _rows_len[y] = sq_floor; 672 _rows_len[y] = sq_floor;
664 _num_peers = sq_floor * sq_floor; 673 _num_peers = sq_floor * sq_floor;
@@ -666,13 +675,13 @@ GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows,
666 x = 0; 675 x = 0;
667 y = 0; 676 y = 0;
668 while (_num_peers < num_peers) 677 while (_num_peers < num_peers)
669 { 678 {
670 if (x < y) 679 if (x < y)
671 _rows_len[_rows - 1] = ++x; 680 _rows_len[_rows - 1] = ++x;
672 else 681 else
673 _rows_len[y++]++; 682 _rows_len[y++]++;
674 _num_peers++; 683 _num_peers++;
675 } 684 }
676 cnt += (x < 2) ? x : 2 * x; 685 cnt += (x < 2) ? x : 2 * x;
677 cnt += (y < 2) ? y : 2 * y; 686 cnt += (y < 2) ? y : 2 * y;
678 if (0 == _rows_len[_rows - 1]) 687 if (0 == _rows_len[_rows - 1])
@@ -682,7 +691,7 @@ GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows,
682 if (NULL != rows_len) 691 if (NULL != rows_len)
683 *rows_len = _rows_len; 692 *rows_len = _rows_len;
684 else 693 else
685 GNUNET_free(_rows_len); 694 GNUNET_free (_rows_len);
686 return cnt; 695 return cnt;
687} 696}
688 697
@@ -693,7 +702,7 @@ GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows,
693 * @param tc the topology context 702 * @param tc the topology context
694 */ 703 */
695static void 704static void
696gen_topo_2dtorus(struct TopologyContext *tc) 705gen_topo_2dtorus (struct TopologyContext *tc)
697{ 706{
698 unsigned int rows; 707 unsigned int rows;
699 unsigned int *rows_len; 708 unsigned int *rows_len;
@@ -703,63 +712,63 @@ gen_topo_2dtorus(struct TopologyContext *tc)
703 unsigned int offset; 712 unsigned int offset;
704 713
705 tc->link_array_size = 714 tc->link_array_size =
706 GNUNET_TESTBED_2dtorus_calc_links(tc->num_peers, &rows, &rows_len); 715 GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len);
707 switch (tc->type) 716 switch (tc->type)
708 { 717 {
709 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 718 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
710 { 719 {
711 struct TopologyContextOverlay *overlay; 720 struct TopologyContextOverlay *overlay;
712 721
713 overlay = &tc->u.overlay; 722 overlay = &tc->u.overlay;
714 overlay->link_array = 723 overlay->link_array =
715 GNUNET_malloc(sizeof(struct OverlayLink) * tc->link_array_size); 724 GNUNET_malloc (sizeof(struct OverlayLink) * tc->link_array_size);
716 } 725 }
717 break; 726 break;
718 727
719 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 728 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
720 { 729 {
721 struct TopologyContextUnderlay *underlay; 730 struct TopologyContextUnderlay *underlay;
722 731
723 underlay = &tc->u.underlay; 732 underlay = &tc->u.underlay;
724 underlay->link_array = 733 underlay->link_array =
725 GNUNET_malloc(sizeof(struct UnderlayLink) * tc->link_array_size); 734 GNUNET_malloc (sizeof(struct UnderlayLink) * tc->link_array_size);
726 break; 735 break;
727 } 736 }
728 } 737 }
729 cnt = 0; 738 cnt = 0;
730 offset = 0; 739 offset = 0;
731 for (y = 0; y < rows; y++) 740 for (y = 0; y < rows; y++)
741 {
742 for (x = 0; x < rows_len[y] - 1; x++)
732 { 743 {
733 for (x = 0; x < rows_len[y] - 1; x++) 744 make_link (cnt, offset + x, offset + x + 1, tc);
734 {
735 make_link(cnt, offset + x, offset + x + 1, tc);
736 cnt++;
737 }
738 if (0 == x)
739 break;
740 make_link(cnt, offset + x, offset, tc);
741 cnt++; 745 cnt++;
742 offset += rows_len[y];
743 } 746 }
747 if (0 == x)
748 break;
749 make_link (cnt, offset + x, offset, tc);
750 cnt++;
751 offset += rows_len[y];
752 }
744 for (x = 0; x < rows_len[0]; x++) 753 for (x = 0; x < rows_len[0]; x++)
754 {
755 offset = 0;
756 for (y = 0; y < rows - 1; y++)
745 { 757 {
746 offset = 0; 758 if (x >= rows_len[y + 1])
747 for (y = 0; y < rows - 1; y++)
748 {
749 if (x >= rows_len[y + 1])
750 break;
751 GNUNET_assert(x < rows_len[y + 1]);
752 make_link(cnt, offset + x, offset + rows_len[y] + x, tc);
753 offset += rows_len[y];
754 cnt++;
755 }
756 if (0 == offset)
757 break; 759 break;
758 make_link(cnt, offset + x, x, tc); 760 GNUNET_assert (x < rows_len[y + 1]);
761 make_link (cnt, offset + x, offset + rows_len[y] + x, tc);
762 offset += rows_len[y];
759 cnt++; 763 cnt++;
760 } 764 }
761 GNUNET_assert(cnt == tc->link_array_size); 765 if (0 == offset)
762 GNUNET_free(rows_len); 766 break;
767 make_link (cnt, offset + x, x, tc);
768 cnt++;
769 }
770 GNUNET_assert (cnt == tc->link_array_size);
771 GNUNET_free (rows_len);
763} 772}
764 773
765 774
@@ -772,9 +781,9 @@ gen_topo_2dtorus(struct TopologyContext *tc)
772 * create a new link array 781 * create a new link array
773 */ 782 */
774static void 783static void
775gen_topo_random(struct TopologyContext *tc, 784gen_topo_random (struct TopologyContext *tc,
776 unsigned int links, 785 unsigned int links,
777 int append) 786 int append)
778{ 787{
779 unsigned int cnt; 788 unsigned int cnt;
780 unsigned int index; 789 unsigned int index;
@@ -784,67 +793,69 @@ gen_topo_random(struct TopologyContext *tc,
784 if (1 == tc->num_peers) 793 if (1 == tc->num_peers)
785 return; 794 return;
786 if (GNUNET_YES == append) 795 if (GNUNET_YES == append)
787 { 796 {
788 index = tc->link_array_size; 797 index = tc->link_array_size;
789 tc->link_array_size += links; 798 tc->link_array_size += links;
790 } 799 }
791 else 800 else
792 { 801 {
793 index = 0; 802 index = 0;
794 tc->link_array_size = links; 803 tc->link_array_size = links;
795 } 804 }
796 switch (tc->type) 805 switch (tc->type)
797 { 806 {
798 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 807 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
799 { 808 {
800 struct TopologyContextOverlay *overlay; 809 struct TopologyContextOverlay *overlay;
801 810
802 overlay = &tc->u.overlay; 811 overlay = &tc->u.overlay;
803 if (GNUNET_YES != append) 812 if (GNUNET_YES != append)
804 { 813 {
805 GNUNET_assert(NULL == overlay->link_array); 814 GNUNET_assert (NULL == overlay->link_array);
806 overlay->link_array = 815 overlay->link_array =
807 GNUNET_malloc(sizeof(struct OverlayLink) * tc->link_array_size); 816 GNUNET_malloc (sizeof(struct OverlayLink) * tc->link_array_size);
808 break; 817 break;
809 } 818 }
810 GNUNET_assert((0 < tc->link_array_size) && (NULL != overlay->link_array)); 819 GNUNET_assert ((0 < tc->link_array_size) && (NULL !=
820 overlay->link_array));
811 overlay->link_array = 821 overlay->link_array =
812 GNUNET_realloc(overlay->link_array, 822 GNUNET_realloc (overlay->link_array,
813 sizeof(struct OverlayLink) * tc->link_array_size); 823 sizeof(struct OverlayLink) * tc->link_array_size);
814 break; 824 break;
815 } 825 }
816 826
817 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 827 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
818 { 828 {
819 struct TopologyContextUnderlay *underlay; 829 struct TopologyContextUnderlay *underlay;
820 830
821 underlay = &tc->u.underlay; 831 underlay = &tc->u.underlay;
822 if (GNUNET_YES != append) 832 if (GNUNET_YES != append)
823 { 833 {
824 GNUNET_assert(NULL == underlay->link_array); 834 GNUNET_assert (NULL == underlay->link_array);
825 underlay->link_array = 835 underlay->link_array =
826 GNUNET_malloc(sizeof(struct UnderlayLink) * tc->link_array_size); 836 GNUNET_malloc (sizeof(struct UnderlayLink) * tc->link_array_size);
827 break; 837 break;
828 } 838 }
829 GNUNET_assert((0 < tc->link_array_size) && (NULL != underlay->link_array)); 839 GNUNET_assert ((0 < tc->link_array_size) && (NULL !=
840 underlay->link_array));
830 underlay->link_array = 841 underlay->link_array =
831 GNUNET_realloc(underlay->link_array, 842 GNUNET_realloc (underlay->link_array,
832 sizeof(struct UnderlayLink) * tc->link_array_size); 843 sizeof(struct UnderlayLink) * tc->link_array_size);
833 break; 844 break;
834 } 845 }
835 } 846 }
836 for (cnt = 0; cnt < links; cnt++) 847 for (cnt = 0; cnt < links; cnt++)
848 {
849 do
837 { 850 {
838 do 851 A_rand =
839 { 852 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
840 A_rand = 853 B_rand =
841 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); 854 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
842 B_rand =
843 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
844 }
845 while (A_rand == B_rand);
846 make_link(index + cnt, A_rand, B_rand, tc);
847 } 855 }
856 while (A_rand == B_rand);
857 make_link (index + cnt, A_rand, B_rand, tc);
858 }
848} 859}
849 860
850 861
@@ -859,9 +870,9 @@ gen_topo_random(struct TopologyContext *tc,
859 * network 870 * network
860 */ 871 */
861static void 872static void
862gen_topo_scale_free(struct TopologyContext *tc, 873gen_topo_scale_free (struct TopologyContext *tc,
863 uint16_t cap, 874 uint16_t cap,
864 uint8_t m) 875 uint8_t m)
865{ 876{
866 unsigned int *deg; 877 unsigned int *deg;
867 unsigned int *etab; 878 unsigned int *etab;
@@ -878,108 +889,110 @@ gen_topo_scale_free(struct TopologyContext *tc,
878 etaboff = 0; 889 etaboff = 0;
879 tc->link_array_size = tc->num_peers * m; 890 tc->link_array_size = tc->num_peers * m;
880 switch (tc->type) 891 switch (tc->type)
881 { 892 {
882 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 893 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
883 { 894 {
884 struct TopologyContextOverlay *overlay; 895 struct TopologyContextOverlay *overlay;
885 896
886 overlay = &tc->u.overlay; 897 overlay = &tc->u.overlay;
887 overlay->link_array = GNUNET_malloc_large(sizeof(struct OverlayLink) * 898 overlay->link_array = GNUNET_malloc_large (sizeof(struct OverlayLink)
888 tc->link_array_size); 899 * tc->link_array_size);
889 } 900 }
890 break; 901 break;
891 902
892 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 903 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
893 { 904 {
894 struct TopologyContextUnderlay *underlay; 905 struct TopologyContextUnderlay *underlay;
895 906
896 underlay = &tc->u.underlay; 907 underlay = &tc->u.underlay;
897 underlay->link_array = GNUNET_malloc_large(sizeof(struct UnderlayLink) * 908 underlay->link_array = GNUNET_malloc_large (sizeof(struct UnderlayLink)
898 tc->link_array_size); 909 * tc->link_array_size);
899 } 910 }
900 break; 911 break;
901 } 912 }
902 etab = GNUNET_malloc_large(sizeof(unsigned int) * 2 * tc->link_array_size); 913 etab = GNUNET_malloc_large (sizeof(unsigned int) * 2 * tc->link_array_size);
903 deg = GNUNET_malloc(sizeof(unsigned int) * tc->num_peers); 914 deg = GNUNET_malloc (sizeof(unsigned int) * tc->num_peers);
904 used = GNUNET_malloc(sizeof(unsigned int) * m); 915 used = GNUNET_malloc (sizeof(unsigned int) * m);
905 /* start by connecting peer 1 to peer 0 */ 916 /* start by connecting peer 1 to peer 0 */
906 make_link(0, 0, 1, tc); 917 make_link (0, 0, 1, tc);
907 deg[0]++; 918 deg[0]++;
908 deg[1]++; 919 deg[1]++;
909 etab[etaboff++] = 0; 920 etab[etaboff++] = 0;
910 etab[etaboff++] = 1; 921 etab[etaboff++] = 1;
911 links = 1; 922 links = 1;
912 for (peer = 2; peer < tc->num_peers; peer++) 923 for (peer = 2; peer < tc->num_peers; peer++)
924 {
925 if (cap < deg[peer])
926 continue;
927 for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
913 { 928 {
914 if (cap < deg[peer]) 929 redo_threshold = 0;
915 continue; 930redo:
916 for (cnt = 0; cnt < GNUNET_MIN(peer, m); cnt++) 931 off = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, etaboff);
932 random_peer = etab[off];
933 if (cap < deg[random_peer])
934 {
935 if (++redo_threshold > GNUNET_MAX (1, cap / 2))
917 { 936 {
918 redo_threshold = 0; 937 redo_threshold = 0;
919redo: 938 off = 0;
920 off = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, etaboff); 939 for (cnt2 = 0; cnt2 < etaboff; cnt2++)
921 random_peer = etab[off]; 940 {
922 if (cap < deg[random_peer]) 941 if (random_peer == etab[cnt2])
923 { 942 {
924 if (++redo_threshold > GNUNET_MAX(1, cap / 2)) 943 off++;
925 { 944 continue;
926 redo_threshold = 0;
927 off = 0;
928 for (cnt2 = 0; cnt2 < etaboff; cnt2++)
929 {
930 if (random_peer == etab[cnt2])
931 {
932 off++;
933 continue;
934 }
935 etab[cnt2 - off] = etab[cnt2];
936 }
937 etaboff -= off;
938 }
939 goto redo;
940 } 945 }
941 for (cnt2 = 0; cnt2 < cnt; cnt2++) 946 etab[cnt2 - off] = etab[cnt2];
942 if (random_peer == used[cnt2]) 947 }
943 goto redo; 948 etaboff -= off;
944 make_link(links + cnt, random_peer, peer, tc);
945 deg[random_peer]++;
946 deg[peer]++;
947 used[cnt] = random_peer;
948 }
949 for (cnt = 0; cnt < GNUNET_MIN(peer, m); cnt++)
950 {
951 etab[etaboff++] = used[cnt];
952 etab[etaboff++] = peer;
953 } 949 }
954 links += GNUNET_MIN(peer, m); 950 goto redo;
951 }
952 for (cnt2 = 0; cnt2 < cnt; cnt2++)
953 if (random_peer == used[cnt2])
954 goto redo;
955 make_link (links + cnt, random_peer, peer, tc);
956 deg[random_peer]++;
957 deg[peer]++;
958 used[cnt] = random_peer;
955 } 959 }
956 GNUNET_free(etab); 960 for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
957 GNUNET_free(used); 961 {
958 GNUNET_free(deg); 962 etab[etaboff++] = used[cnt];
959 GNUNET_assert(links <= tc->link_array_size); 963 etab[etaboff++] = peer;
964 }
965 links += GNUNET_MIN (peer, m);
966 }
967 GNUNET_free (etab);
968 GNUNET_free (used);
969 GNUNET_free (deg);
970 GNUNET_assert (links <= tc->link_array_size);
960 tc->link_array_size = links; 971 tc->link_array_size = links;
961 switch (tc->type) 972 switch (tc->type)
962 { 973 {
963 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 974 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
964 { 975 {
965 struct TopologyContextOverlay *overlay; 976 struct TopologyContextOverlay *overlay;
966 977
967 overlay = &tc->u.overlay; 978 overlay = &tc->u.overlay;
968 overlay->link_array = 979 overlay->link_array =
969 GNUNET_realloc(overlay->link_array, sizeof(struct OverlayLink) * tc->link_array_size); 980 GNUNET_realloc (overlay->link_array, sizeof(struct OverlayLink)
981 * tc->link_array_size);
970 } 982 }
971 break; 983 break;
972 984
973 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 985 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
974 { 986 {
975 struct TopologyContextUnderlay *underlay; 987 struct TopologyContextUnderlay *underlay;
976 988
977 underlay = &tc->u.underlay; 989 underlay = &tc->u.underlay;
978 underlay->link_array = 990 underlay->link_array =
979 GNUNET_realloc(underlay->link_array, sizeof(struct UnderlayLink) * tc->link_array_size); 991 GNUNET_realloc (underlay->link_array, sizeof(struct UnderlayLink)
992 * tc->link_array_size);
980 } 993 }
981 break; 994 break;
982 } 995 }
983} 996}
984 997
985 998
@@ -990,8 +1003,8 @@ redo:
990 * @param filename the filename of the file containing topology data 1003 * @param filename the filename of the file containing topology data
991 */ 1004 */
992static void 1005static void
993gen_topo_from_file(struct TopologyContext *tc, 1006gen_topo_from_file (struct TopologyContext *tc,
994 const char *filename) 1007 const char *filename)
995{ 1008{
996 char *data; 1009 char *data;
997 char *end; 1010 char *end;
@@ -1000,7 +1013,8 @@ gen_topo_from_file(struct TopologyContext *tc,
1000 uint64_t offset; 1013 uint64_t offset;
1001 unsigned long int peer_id; 1014 unsigned long int peer_id;
1002 unsigned long int other_peer_id; 1015 unsigned long int other_peer_id;
1003 enum ParseState { 1016 enum ParseState
1017 {
1004 /** 1018 /**
1005 * We read the peer index 1019 * We read the peer index
1006 */ 1020 */
@@ -1014,177 +1028,178 @@ gen_topo_from_file(struct TopologyContext *tc,
1014 int status; 1028 int status;
1015 1029
1016 status = GNUNET_SYSERR; 1030 status = GNUNET_SYSERR;
1017 if (GNUNET_YES != GNUNET_DISK_file_test(filename)) 1031 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
1018 { 1032 {
1019 LOG(GNUNET_ERROR_TYPE_ERROR, 1033 LOG (GNUNET_ERROR_TYPE_ERROR,
1020 _("Topology file %s not found\n"), 1034 _ ("Topology file %s not found\n"),
1021 filename); 1035 filename);
1022 return; 1036 return;
1023 } 1037 }
1024 if (GNUNET_OK != 1038 if (GNUNET_OK !=
1025 GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) 1039 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
1026 { 1040 {
1027 LOG(GNUNET_ERROR_TYPE_ERROR, 1041 LOG (GNUNET_ERROR_TYPE_ERROR,
1028 _("Topology file %s has no data\n"), 1042 _ ("Topology file %s has no data\n"),
1029 filename); 1043 filename);
1030 return; 1044 return;
1031 } 1045 }
1032 data = GNUNET_malloc(fs); 1046 data = GNUNET_malloc (fs);
1033 if (fs != GNUNET_DISK_fn_read(filename, data, fs)) 1047 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
1034 { 1048 {
1035 LOG(GNUNET_ERROR_TYPE_ERROR, 1049 LOG (GNUNET_ERROR_TYPE_ERROR,
1036 _("Topology file %s cannot be read\n"), 1050 _ ("Topology file %s cannot be read\n"),
1037 filename); 1051 filename);
1038 goto _exit; 1052 goto _exit;
1039 } 1053 }
1040 1054
1041 offset = 0; 1055 offset = 0;
1042 peer_id = 0; 1056 peer_id = 0;
1043 state = PEER_INDEX; 1057 state = PEER_INDEX;
1044 while (offset < fs) 1058 while (offset < fs)
1059 {
1060 if (0 != isspace ((unsigned char) data[offset]))
1045 { 1061 {
1046 if (0 != isspace((unsigned char)data[offset])) 1062 offset++;
1047 { 1063 continue;
1048 offset++; 1064 }
1049 continue; 1065 switch (state)
1050 } 1066 {
1051 switch (state) 1067 case PEER_INDEX:
1068 buf = strchr (&data[offset], ':');
1069 if (NULL == buf)
1070 {
1071 LOG (GNUNET_ERROR_TYPE_ERROR,
1072 _ ("Failed to read peer index from toology file: %s"), filename);
1073 goto _exit;
1074 }
1075 *buf = '\0';
1076 errno = 0;
1077 peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1078 if (0 != errno)
1079 {
1080 LOG (GNUNET_ERROR_TYPE_ERROR,
1081 _ ("Value in given topology file: %s out of range\n"), filename);
1082 goto _exit;
1083 }
1084 if (&data[offset] == end)
1085 {
1086 LOG (GNUNET_ERROR_TYPE_ERROR,
1087 _ ("Failed to read peer index from topology file: %s"), filename);
1088 goto _exit;
1089 }
1090 if (tc->num_peers <= peer_id)
1091 {
1092 LOG (GNUNET_ERROR_TYPE_ERROR,
1093 _ ("Topology file needs more peers than given ones\n"), filename);
1094 goto _exit;
1095 }
1096 state = OTHER_PEER_INDEX;
1097 offset += ((unsigned int) (buf - &data[offset])) + 1;
1098 break;
1099
1100 case OTHER_PEER_INDEX:
1101 errno = 0;
1102 other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1103 if (0 != errno)
1104 {
1105 LOG (GNUNET_ERROR_TYPE_ERROR,
1106 _ ("Value in given topology file: %s out of range\n"), filename);
1107 goto _exit;
1108 }
1109 if (&data[offset] == end)
1110 {
1111 LOG (GNUNET_ERROR_TYPE_ERROR,
1112 _ ("Failed to read peer index from topology file: %s"), filename);
1113 goto _exit;
1114 }
1115 if (tc->num_peers <= other_peer_id)
1116 {
1117 LOG (GNUNET_ERROR_TYPE_ERROR,
1118 _ ("Topology file needs more peers than given ones\n"), filename);
1119 goto _exit;
1120 }
1121 if (peer_id != other_peer_id)
1122 {
1123 tc->link_array_size++;
1124 switch (tc->type)
1052 { 1125 {
1053 case PEER_INDEX: 1126 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1054 buf = strchr(&data[offset], ':'); 1127 {
1055 if (NULL == buf) 1128 struct TopologyContextOverlay *overlay;
1056 { 1129
1057 LOG(GNUNET_ERROR_TYPE_ERROR, 1130 overlay = &tc->u.overlay;
1058 _("Failed to read peer index from toology file: %s"), filename); 1131 overlay->link_array =
1059 goto _exit; 1132 GNUNET_realloc (overlay->link_array,
1060 } 1133 sizeof(struct OverlayLink) * tc->link_array_size);
1061 *buf = '\0'; 1134 }
1062 errno = 0;
1063 peer_id = (unsigned int)strtoul(&data[offset], &end, 10);
1064 if (0 != errno)
1065 {
1066 LOG(GNUNET_ERROR_TYPE_ERROR,
1067 _("Value in given topology file: %s out of range\n"), filename);
1068 goto _exit;
1069 }
1070 if (&data[offset] == end)
1071 {
1072 LOG(GNUNET_ERROR_TYPE_ERROR,
1073 _("Failed to read peer index from topology file: %s"), filename);
1074 goto _exit;
1075 }
1076 if (tc->num_peers <= peer_id)
1077 {
1078 LOG(GNUNET_ERROR_TYPE_ERROR,
1079 _("Topology file needs more peers than given ones\n"), filename);
1080 goto _exit;
1081 }
1082 state = OTHER_PEER_INDEX;
1083 offset += ((unsigned int)(buf - &data[offset])) + 1;
1084 break; 1135 break;
1085 1136
1086 case OTHER_PEER_INDEX: 1137 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1087 errno = 0; 1138 {
1088 other_peer_id = (unsigned int)strtoul(&data[offset], &end, 10); 1139 struct TopologyContextUnderlay *underlay;
1089 if (0 != errno) 1140
1090 { 1141 underlay = &tc->u.underlay;
1091 LOG(GNUNET_ERROR_TYPE_ERROR, 1142 underlay->link_array =
1092 _("Value in given topology file: %s out of range\n"), filename); 1143 GNUNET_realloc (underlay->link_array,
1093 goto _exit; 1144 sizeof(struct UnderlayLink)
1094 } 1145 * tc->link_array_size);
1095 if (&data[offset] == end) 1146 }
1096 {
1097 LOG(GNUNET_ERROR_TYPE_ERROR,
1098 _("Failed to read peer index from topology file: %s"), filename);
1099 goto _exit;
1100 }
1101 if (tc->num_peers <= other_peer_id)
1102 {
1103 LOG(GNUNET_ERROR_TYPE_ERROR,
1104 _("Topology file needs more peers than given ones\n"), filename);
1105 goto _exit;
1106 }
1107 if (peer_id != other_peer_id)
1108 {
1109 tc->link_array_size++;
1110 switch (tc->type)
1111 {
1112 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1113 {
1114 struct TopologyContextOverlay *overlay;
1115
1116 overlay = &tc->u.overlay;
1117 overlay->link_array =
1118 GNUNET_realloc(overlay->link_array,
1119 sizeof(struct OverlayLink) * tc->link_array_size);
1120 }
1121 break;
1122
1123 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1124 {
1125 struct TopologyContextUnderlay *underlay;
1126
1127 underlay = &tc->u.underlay;
1128 underlay->link_array =
1129 GNUNET_realloc(underlay->link_array,
1130 sizeof(struct UnderlayLink) * tc->link_array_size);
1131 }
1132 break;
1133 }
1134 offset += end - &data[offset];
1135 make_link(tc->link_array_size - 1, peer_id, other_peer_id, tc);
1136 }
1137 else
1138 LOG(GNUNET_ERROR_TYPE_WARNING,
1139 _("Ignoring to connect peer %u to peer %u\n"),
1140 peer_id,
1141 other_peer_id);
1142 while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
1143 offset++;
1144 if ((offset < fs) &&
1145 ('\n' == data[offset]))
1146 state = PEER_INDEX;
1147 else if ((offset < fs) &&
1148 ('|' == data[offset]))
1149 {
1150 state = OTHER_PEER_INDEX;
1151 offset++;
1152 }
1153 break; 1147 break;
1154 } 1148 }
1149 offset += end - &data[offset];
1150 make_link (tc->link_array_size - 1, peer_id, other_peer_id, tc);
1151 }
1152 else
1153 LOG (GNUNET_ERROR_TYPE_WARNING,
1154 _ ("Ignoring to connect peer %u to peer %u\n"),
1155 peer_id,
1156 other_peer_id);
1157 while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
1158 offset++;
1159 if ((offset < fs) &&
1160 ('\n' == data[offset]))
1161 state = PEER_INDEX;
1162 else if ((offset < fs) &&
1163 ('|' == data[offset]))
1164 {
1165 state = OTHER_PEER_INDEX;
1166 offset++;
1167 }
1168 break;
1155 } 1169 }
1170 }
1156 status = GNUNET_OK; 1171 status = GNUNET_OK;
1157 1172
1158_exit: 1173_exit:
1159 GNUNET_free(data); 1174 GNUNET_free (data);
1160 if (GNUNET_OK != status) 1175 if (GNUNET_OK != status)
1176 {
1177 LOG (GNUNET_ERROR_TYPE_WARNING,
1178 "Removing link data read from the file\n");
1179 tc->link_array_size = 0;
1180 switch (tc->type)
1161 { 1181 {
1162 LOG(GNUNET_ERROR_TYPE_WARNING, 1182 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1163 "Removing link data read from the file\n"); 1183 {
1164 tc->link_array_size = 0; 1184 struct TopologyContextOverlay *overlay;
1165 switch (tc->type)
1166 {
1167 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1168 {
1169 struct TopologyContextOverlay *overlay;
1170 1185
1171 overlay = &tc->u.overlay; 1186 overlay = &tc->u.overlay;
1172 GNUNET_free_non_null(overlay->link_array); 1187 GNUNET_free_non_null (overlay->link_array);
1173 overlay->link_array = NULL; 1188 overlay->link_array = NULL;
1174 } 1189 }
1175 break; 1190 break;
1176 1191
1177 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 1192 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1178 { 1193 {
1179 struct TopologyContextUnderlay *underlay; 1194 struct TopologyContextUnderlay *underlay;
1180 1195
1181 underlay = &tc->u.underlay; 1196 underlay = &tc->u.underlay;
1182 GNUNET_free_non_null(underlay->link_array); 1197 GNUNET_free_non_null (underlay->link_array);
1183 underlay->link_array = NULL; 1198 underlay->link_array = NULL;
1184 } 1199 }
1185 break; 1200 break;
1186 }
1187 } 1201 }
1202 }
1188} 1203}
1189 1204
1190 1205
@@ -1194,7 +1209,7 @@ _exit:
1194 * @param tc the topology context 1209 * @param tc the topology context
1195 */ 1210 */
1196static void 1211static void
1197gen_topo_clique(struct TopologyContext *tc) 1212gen_topo_clique (struct TopologyContext *tc)
1198{ 1213{
1199 unsigned int cnt; 1214 unsigned int cnt;
1200 unsigned int offset; 1215 unsigned int offset;
@@ -1202,37 +1217,37 @@ gen_topo_clique(struct TopologyContext *tc)
1202 1217
1203 tc->link_array_size = tc->num_peers * (tc->num_peers - 1); 1218 tc->link_array_size = tc->num_peers * (tc->num_peers - 1);
1204 switch (tc->type) 1219 switch (tc->type)
1205 { 1220 {
1206 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 1221 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1207 { 1222 {
1208 struct TopologyContextOverlay *overlay; 1223 struct TopologyContextOverlay *overlay;
1209 1224
1210 overlay = &tc->u.overlay; 1225 overlay = &tc->u.overlay;
1211 overlay->link_array = GNUNET_new_array(tc->link_array_size, 1226 overlay->link_array = GNUNET_new_array (tc->link_array_size,
1212 struct OverlayLink); 1227 struct OverlayLink);
1213 } 1228 }
1214 break; 1229 break;
1215 1230
1216 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 1231 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1217 { 1232 {
1218 struct TopologyContextUnderlay *underlay; 1233 struct TopologyContextUnderlay *underlay;
1219 1234
1220 underlay = &tc->u.underlay; 1235 underlay = &tc->u.underlay;
1221 underlay->link_array = GNUNET_new_array(tc->link_array_size, 1236 underlay->link_array = GNUNET_new_array (tc->link_array_size,
1222 struct UnderlayLink); 1237 struct UnderlayLink);
1223 }
1224 } 1238 }
1239 }
1225 offset = 0; 1240 offset = 0;
1226 for (cnt = 0; cnt < tc->num_peers; cnt++) 1241 for (cnt = 0; cnt < tc->num_peers; cnt++)
1242 {
1243 for (neighbour = 0; neighbour < tc->num_peers; neighbour++)
1227 { 1244 {
1228 for (neighbour = 0; neighbour < tc->num_peers; neighbour++) 1245 if (neighbour == cnt)
1229 { 1246 continue;
1230 if (neighbour == cnt) 1247 make_link (offset, cnt, neighbour, tc);
1231 continue; 1248 offset++;
1232 make_link(offset, cnt, neighbour, tc);
1233 offset++;
1234 }
1235 } 1249 }
1250 }
1236} 1251}
1237 1252
1238 1253
@@ -1248,15 +1263,15 @@ gen_topo_clique(struct TopologyContext *tc)
1248 * is not allowed at this time 1263 * is not allowed at this time
1249 */ 1264 */
1250struct GNUNET_TESTBED_Operation * 1265struct GNUNET_TESTBED_Operation *
1251GNUNET_TESTBED_underlay_configure_topology_va(void *op_cls, 1266GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1252 unsigned int num_peers, 1267 unsigned int num_peers,
1253 struct GNUNET_TESTBED_Peer 1268 struct GNUNET_TESTBED_Peer
1254 **peers, 1269 **peers,
1255 enum 1270 enum
1256 GNUNET_TESTBED_TopologyOption 1271 GNUNET_TESTBED_TopologyOption
1257 topo, va_list ap) 1272 topo, va_list ap)
1258{ 1273{
1259 GNUNET_break(0); 1274 GNUNET_break (0);
1260 return NULL; 1275 return NULL;
1261} 1276}
1262 1277
@@ -1273,13 +1288,13 @@ GNUNET_TESTBED_underlay_configure_topology_va(void *op_cls,
1273 * is not allowed at this time 1288 * is not allowed at this time
1274 */ 1289 */
1275struct GNUNET_TESTBED_Operation * 1290struct GNUNET_TESTBED_Operation *
1276GNUNET_TESTBED_underlay_configure_topology(void *op_cls, 1291GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1277 unsigned int num_peers, 1292 unsigned int num_peers,
1278 struct GNUNET_TESTBED_Peer **peers, 1293 struct GNUNET_TESTBED_Peer **peers,
1279 enum GNUNET_TESTBED_TopologyOption 1294 enum GNUNET_TESTBED_TopologyOption
1280 topo, ...) 1295 topo, ...)
1281{ 1296{
1282 GNUNET_break(0); 1297 GNUNET_break (0);
1283 return NULL; 1298 return NULL;
1284} 1299}
1285 1300
@@ -1305,15 +1320,16 @@ GNUNET_TESTBED_underlay_configure_topology(void *op_cls,
1305 * not running or underlay disallows) or if num_peers is less than 2 1320 * not running or underlay disallows) or if num_peers is less than 2
1306 */ 1321 */
1307struct GNUNET_TESTBED_Operation * 1322struct GNUNET_TESTBED_Operation *
1308GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls, 1323GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1309 unsigned int num_peers, 1324 unsigned int num_peers,
1310 struct GNUNET_TESTBED_Peer **peers, 1325 struct GNUNET_TESTBED_Peer **peers,
1311 unsigned int *max_connections, 1326 unsigned int *max_connections,
1312 GNUNET_TESTBED_TopologyCompletionCallback 1327 GNUNET_TESTBED_TopologyCompletionCallback
1313 comp_cb, 1328 comp_cb,
1314 void *comp_cb_cls, 1329 void *comp_cb_cls,
1315 enum GNUNET_TESTBED_TopologyOption topo, 1330 enum GNUNET_TESTBED_TopologyOption
1316 va_list va) 1331 topo,
1332 va_list va)
1317{ 1333{
1318 struct TopologyContext *tc; 1334 struct TopologyContext *tc;
1319 struct TopologyContextOverlay *overlay; 1335 struct TopologyContextOverlay *overlay;
@@ -1324,7 +1340,7 @@ GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls,
1324 if (num_peers < 2) 1340 if (num_peers < 2)
1325 return NULL; 1341 return NULL;
1326 c = peers[0]->controller; 1342 c = peers[0]->controller;
1327 tc = GNUNET_new(struct TopologyContext); 1343 tc = GNUNET_new (struct TopologyContext);
1328 tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY; 1344 tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY;
1329 overlay = &tc->u.overlay; 1345 overlay = &tc->u.overlay;
1330 overlay->peers = peers; 1346 overlay->peers = peers;
@@ -1334,100 +1350,100 @@ GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls,
1334 overlay->comp_cb = comp_cb; 1350 overlay->comp_cb = comp_cb;
1335 overlay->comp_cb_cls = comp_cb_cls; 1351 overlay->comp_cb_cls = comp_cb_cls;
1336 switch (topo) 1352 switch (topo)
1337 { 1353 {
1338 case GNUNET_TESTBED_TOPOLOGY_LINE: 1354 case GNUNET_TESTBED_TOPOLOGY_LINE:
1339 gen_topo_line(tc); 1355 gen_topo_line (tc);
1340 break; 1356 break;
1341 1357
1342 case GNUNET_TESTBED_TOPOLOGY_STAR: 1358 case GNUNET_TESTBED_TOPOLOGY_STAR:
1343 gen_topo_star(tc); 1359 gen_topo_star (tc);
1344 break; 1360 break;
1345 1361
1346 case GNUNET_TESTBED_TOPOLOGY_RING: 1362 case GNUNET_TESTBED_TOPOLOGY_RING:
1347 gen_topo_ring(tc); 1363 gen_topo_ring (tc);
1348 break; 1364 break;
1349 1365
1350 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 1366 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
1351 gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_NO); 1367 gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_NO);
1352 break; 1368 break;
1353 1369
1354 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: 1370 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
1355 gen_topo_ring(tc); 1371 gen_topo_ring (tc);
1356 gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_YES); 1372 gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
1357 break; 1373 break;
1358 1374
1359 case GNUNET_TESTBED_TOPOLOGY_CLIQUE: 1375 case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
1360 gen_topo_clique(tc); 1376 gen_topo_clique (tc);
1361 break; 1377 break;
1362 1378
1363 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: 1379 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
1364 gen_topo_2dtorus(tc); 1380 gen_topo_2dtorus (tc);
1365 break; 1381 break;
1366 1382
1367 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: 1383 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
1368 gen_topo_2dtorus(tc); 1384 gen_topo_2dtorus (tc);
1369 gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_YES); 1385 gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
1370 1386
1371 break; 1387 break;
1372 1388
1373 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 1389 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
1374 { 1390 {
1375 uint16_t cap; 1391 uint16_t cap;
1376 uint8_t m; 1392 uint8_t m;
1377 1393
1378 cap = (uint16_t)va_arg(va, unsigned int); 1394 cap = (uint16_t) va_arg (va, unsigned int);
1379 m = (uint8_t)va_arg(va, unsigned int); 1395 m = (uint8_t) va_arg (va, unsigned int);
1380 gen_topo_scale_free(tc, cap, m); 1396 gen_topo_scale_free (tc, cap, m);
1381 } 1397 }
1382 break; 1398 break;
1383 1399
1384 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: 1400 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
1385 { 1401 {
1386 const char *filename; 1402 const char *filename;
1387 1403
1388 filename = va_arg(va, const char *); 1404 filename = va_arg (va, const char *);
1389 1405
1390 GNUNET_assert(NULL != filename); 1406 GNUNET_assert (NULL != filename);
1391 gen_topo_from_file(tc, filename); 1407 gen_topo_from_file (tc, filename);
1392 } 1408 }
1393 break; 1409 break;
1394 1410
1395 default: 1411 default:
1396 GNUNET_break(0); 1412 GNUNET_break (0);
1397 GNUNET_free(tc); 1413 GNUNET_free (tc);
1398 return NULL; 1414 return NULL;
1399 } 1415 }
1400 do 1416 do
1401 { 1417 {
1402 secondary_option = GNUNET_VA_ARG_ENUM(va, GNUNET_TESTBED_TopologyOption); 1418 secondary_option = GNUNET_VA_ARG_ENUM (va, GNUNET_TESTBED_TopologyOption);
1403 1419
1404 switch (secondary_option) 1420 switch (secondary_option)
1405 { 1421 {
1406 case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT: 1422 case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT:
1407 overlay->retry_cnt = va_arg(va, unsigned int); 1423 overlay->retry_cnt = va_arg (va, unsigned int);
1408 break; 1424 break;
1409 1425
1410 case GNUNET_TESTBED_TOPOLOGY_OPTION_END: 1426 case GNUNET_TESTBED_TOPOLOGY_OPTION_END:
1411 break; 1427 break;
1412 1428
1413 default: 1429 default:
1414 GNUNET_break(0); /* Should not use any other option apart from 1430 GNUNET_break (0); /* Should not use any other option apart from
1415 * the ones handled here */ 1431 * the ones handled here */
1416 GNUNET_free_non_null(overlay->link_array); 1432 GNUNET_free_non_null (overlay->link_array);
1417 GNUNET_free(tc); 1433 GNUNET_free (tc);
1418 return NULL; 1434 return NULL;
1419 }
1420 } 1435 }
1436 }
1421 while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option); 1437 while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option);
1422 op = GNUNET_TESTBED_operation_create_(tc, 1438 op = GNUNET_TESTBED_operation_create_ (tc,
1423 &opstart_overlay_configure_topology, 1439 &opstart_overlay_configure_topology,
1424 &oprelease_overlay_configure_topology); 1440 &oprelease_overlay_configure_topology);
1425 GNUNET_TESTBED_operation_queue_insert_ 1441 GNUNET_TESTBED_operation_queue_insert_
1426 (c->opq_parallel_topology_config_operations, op); 1442 (c->opq_parallel_topology_config_operations, op);
1427 GNUNET_TESTBED_operation_begin_wait_(op); 1443 GNUNET_TESTBED_operation_begin_wait_ (op);
1428 LOG(GNUNET_ERROR_TYPE_DEBUG, 1444 LOG (GNUNET_ERROR_TYPE_DEBUG,
1429 "Generated %u connections\n", 1445 "Generated %u connections\n",
1430 tc->link_array_size); 1446 tc->link_array_size);
1431 if (NULL != max_connections) 1447 if (NULL != max_connections)
1432 *max_connections = tc->link_array_size; 1448 *max_connections = tc->link_array_size;
1433 return op; 1449 return op;
@@ -1455,27 +1471,28 @@ GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls,
1455 * not running or underlay disallows) or if num_peers is less than 2 1471 * not running or underlay disallows) or if num_peers is less than 2
1456 */ 1472 */
1457struct GNUNET_TESTBED_Operation * 1473struct GNUNET_TESTBED_Operation *
1458GNUNET_TESTBED_overlay_configure_topology(void *op_cls, 1474GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1459 unsigned int num_peers, 1475 unsigned int num_peers,
1460 struct GNUNET_TESTBED_Peer **peers, 1476 struct GNUNET_TESTBED_Peer **peers,
1461 unsigned int *max_connections, 1477 unsigned int *max_connections,
1462 GNUNET_TESTBED_TopologyCompletionCallback 1478 GNUNET_TESTBED_TopologyCompletionCallback
1463 comp_cb, 1479 comp_cb,
1464 void *comp_cb_cls, 1480 void *comp_cb_cls,
1465 enum GNUNET_TESTBED_TopologyOption topo, 1481 enum GNUNET_TESTBED_TopologyOption
1466 ...) 1482 topo,
1483 ...)
1467{ 1484{
1468 struct GNUNET_TESTBED_Operation *op; 1485 struct GNUNET_TESTBED_Operation *op;
1469 va_list vargs; 1486 va_list vargs;
1470 1487
1471 GNUNET_assert(topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END); 1488 GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END);
1472 va_start(vargs, topo); 1489 va_start (vargs, topo);
1473 op = GNUNET_TESTBED_overlay_configure_topology_va(op_cls, num_peers, peers, 1490 op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers,
1474 max_connections, 1491 max_connections,
1475 comp_cb, comp_cb_cls, 1492 comp_cb, comp_cb_cls,
1476 topo, 1493 topo,
1477 vargs); 1494 vargs);
1478 va_end(vargs); 1495 va_end (vargs);
1479 return op; 1496 return op;
1480} 1497}
1481 1498
@@ -1490,21 +1507,22 @@ GNUNET_TESTBED_overlay_configure_topology(void *op_cls,
1490 * known topology, #GNUNET_NO if not 1507 * known topology, #GNUNET_NO if not
1491 */ 1508 */
1492int 1509int
1493GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology, 1510GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
1494 const char *topology_string) 1511 const char *topology_string)
1495{ 1512{
1496 unsigned int cnt; 1513 unsigned int cnt;
1497 1514
1498 for (cnt = 0; NULL != topology_strings[cnt]; cnt++) 1515 for (cnt = 0; NULL != topology_strings[cnt]; cnt++)
1516 {
1517 if (0 == strcasecmp (topology_string, topology_strings[cnt]))
1499 { 1518 {
1500 if (0 == strcasecmp(topology_string, topology_strings[cnt])) 1519 if (NULL != topology)
1501 { 1520 *topology = (enum GNUNET_TESTBED_TopologyOption) cnt;
1502 if (NULL != topology) 1521 GNUNET_assert (GNUNET_TESTBED_TOPOLOGY_OPTION_END !=
1503 *topology = (enum GNUNET_TESTBED_TopologyOption)cnt; 1522 (enum GNUNET_TESTBED_TopologyOption) cnt);
1504 GNUNET_assert(GNUNET_TESTBED_TOPOLOGY_OPTION_END != (enum GNUNET_TESTBED_TopologyOption)cnt); 1523 return GNUNET_YES;
1505 return GNUNET_YES;
1506 }
1507 } 1524 }
1525 }
1508 return GNUNET_NO; 1526 return GNUNET_NO;
1509} 1527}
1510 1528
@@ -1517,11 +1535,11 @@ GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology,
1517 * expressed as a string 1535 * expressed as a string
1518 */ 1536 */
1519char * 1537char *
1520GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology) 1538GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology)
1521{ 1539{
1522 if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology) 1540 if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology)
1523 return NULL; 1541 return NULL;
1524 return GNUNET_strdup(topology_strings[topology]); 1542 return GNUNET_strdup (topology_strings[topology]);
1525} 1543}
1526 1544
1527 1545
@@ -1542,10 +1560,10 @@ GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology)
1542 * underlay link processor returned #GNUNET_SYSERR 1560 * underlay link processor returned #GNUNET_SYSERR
1543 */ 1561 */
1544int 1562int
1545GNUNET_TESTBED_underlay_construct_(int num_peers, 1563GNUNET_TESTBED_underlay_construct_ (int num_peers,
1546 underlay_link_processor proc, 1564 underlay_link_processor proc,
1547 void *cls, 1565 void *cls,
1548 ...) 1566 ...)
1549{ 1567{
1550 struct TopologyContext tc; 1568 struct TopologyContext tc;
1551 struct TopologyContextUnderlay *underlay; 1569 struct TopologyContextUnderlay *underlay;
@@ -1555,88 +1573,88 @@ GNUNET_TESTBED_underlay_construct_(int num_peers,
1555 unsigned int cnt; 1573 unsigned int cnt;
1556 int ret; 1574 int ret;
1557 1575
1558 GNUNET_assert(NULL != proc); 1576 GNUNET_assert (NULL != proc);
1559 ret = GNUNET_OK; 1577 ret = GNUNET_OK;
1560 memset(&tc, 0, sizeof(tc)); 1578 memset (&tc, 0, sizeof(tc));
1561 tc.num_peers = num_peers; 1579 tc.num_peers = num_peers;
1562 tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY; 1580 tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
1563 underlay = &tc.u.underlay; 1581 underlay = &tc.u.underlay;
1564 va_start(vargs, cls); 1582 va_start (vargs, cls);
1565 topology = GNUNET_VA_ARG_ENUM(vargs, GNUNET_TESTBED_TopologyOption); 1583 topology = GNUNET_VA_ARG_ENUM (vargs, GNUNET_TESTBED_TopologyOption);
1566 switch (topology) 1584 switch (topology)
1567 { 1585 {
1568 case GNUNET_TESTBED_TOPOLOGY_LINE: 1586 case GNUNET_TESTBED_TOPOLOGY_LINE:
1569 gen_topo_line(&tc); 1587 gen_topo_line (&tc);
1570 break; 1588 break;
1571 1589
1572 case GNUNET_TESTBED_TOPOLOGY_STAR: 1590 case GNUNET_TESTBED_TOPOLOGY_STAR:
1573 gen_topo_star(&tc); 1591 gen_topo_star (&tc);
1574 break; 1592 break;
1575 1593
1576 case GNUNET_TESTBED_TOPOLOGY_RING: 1594 case GNUNET_TESTBED_TOPOLOGY_RING:
1577 gen_topo_ring(&tc); 1595 gen_topo_ring (&tc);
1578 break; 1596 break;
1579 1597
1580 case GNUNET_TESTBED_TOPOLOGY_CLIQUE: 1598 case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
1581 gen_topo_clique(&tc); 1599 gen_topo_clique (&tc);
1582 break; 1600 break;
1583 1601
1584 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: 1602 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
1585 gen_topo_2dtorus(&tc); 1603 gen_topo_2dtorus (&tc);
1586 break; 1604 break;
1587 1605
1588 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 1606 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
1589 gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_NO); 1607 gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_NO);
1590 break; 1608 break;
1591 1609
1592 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: 1610 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
1593 gen_topo_ring(&tc); 1611 gen_topo_ring (&tc);
1594 gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES); 1612 gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1595 break; 1613 break;
1596 1614
1597 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: 1615 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
1598 gen_topo_2dtorus(&tc); 1616 gen_topo_2dtorus (&tc);
1599 gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES); 1617 gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1600 break; 1618 break;
1601 1619
1602 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: 1620 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
1603 { 1621 {
1604 const char *filename; 1622 const char *filename;
1605 filename = va_arg(vargs, char *); 1623 filename = va_arg (vargs, char *);
1606 GNUNET_assert(NULL != filename); 1624 GNUNET_assert (NULL != filename);
1607 gen_topo_from_file(&tc, filename); 1625 gen_topo_from_file (&tc, filename);
1608 } 1626 }
1609 break; 1627 break;
1610 1628
1611 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 1629 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
1612 { 1630 {
1613 uint16_t cap; 1631 uint16_t cap;
1614 uint8_t m; 1632 uint8_t m;
1615 cap = (uint16_t)va_arg(vargs, unsigned int); 1633 cap = (uint16_t) va_arg (vargs, unsigned int);
1616 m = (uint8_t)va_arg(vargs, unsigned int); 1634 m = (uint8_t) va_arg (vargs, unsigned int);
1617 gen_topo_scale_free(&tc, cap, m); 1635 gen_topo_scale_free (&tc, cap, m);
1618 } 1636 }
1619 break; 1637 break;
1620 1638
1621 default: 1639 default:
1622 GNUNET_assert(0); 1640 GNUNET_assert (0);
1623 } 1641 }
1624 va_end(vargs); 1642 va_end (vargs);
1625 for (cnt = 0; cnt < tc.link_array_size; cnt++) 1643 for (cnt = 0; cnt < tc.link_array_size; cnt++)
1644 {
1645 ulink = &underlay->link_array[cnt];
1646 if (GNUNET_SYSERR == proc (cls,
1647 ulink->A,
1648 ulink->B,
1649 ulink->bandwidth,
1650 ulink->latency,
1651 ulink->loss))
1626 { 1652 {
1627 ulink = &underlay->link_array[cnt]; 1653 ret = GNUNET_SYSERR;
1628 if (GNUNET_SYSERR == proc(cls, 1654 break;
1629 ulink->A,
1630 ulink->B,
1631 ulink->bandwidth,
1632 ulink->latency,
1633 ulink->loss))
1634 {
1635 ret = GNUNET_SYSERR;
1636 break;
1637 }
1638 } 1655 }
1639 GNUNET_free_non_null(underlay->link_array); 1656 }
1657 GNUNET_free_non_null (underlay->link_array);
1640 return ret; 1658 return ret;
1641} 1659}
1642 1660