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