aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_topology.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-01-25 15:28:08 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-01-25 15:28:08 +0000
commit30c5c323f28ade8a1e7c6c593778793e44accb3a (patch)
tree845955ec895d221338b44f0cadce7932932e78cc /src/testbed/testbed_api_topology.c
parent43d558efd13a3245e65efd0acdc9c4ba59cd2bee (diff)
downloadgnunet-30c5c323f28ade8a1e7c6c593778793e44accb3a.tar.gz
gnunet-30c5c323f28ade8a1e7c6c593778793e44accb3a.zip
- indent
Diffstat (limited to 'src/testbed/testbed_api_topology.c')
-rw-r--r--src/testbed/testbed_api_topology.c270
1 files changed, 127 insertions, 143 deletions
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c
index 0b949d3aa..95ac7ae70 100644
--- a/src/testbed/testbed_api_topology.c
+++ b/src/testbed/testbed_api_topology.c
@@ -56,7 +56,7 @@ struct OverlayLink
56 56
57 /** 57 /**
58 * The topology context this link is a part of 58 * The topology context this link is a part of
59 */ 59 */
60 struct TopologyContext *tc; 60 struct TopologyContext *tc;
61 61
62 /** 62 /**
@@ -106,7 +106,7 @@ struct TopologyContext
106 * should the automatic retry be disabled 106 * should the automatic retry be disabled
107 */ 107 */
108 int disable_retry; 108 int disable_retry;
109 109
110}; 110};
111 111
112 112
@@ -114,75 +114,74 @@ struct TopologyContext
114 * A array of names representing topologies. Should be in sync with enum 114 * A array of names representing topologies. Should be in sync with enum
115 * GNUNET_TESTBED_TopologyOption 115 * GNUNET_TESTBED_TopologyOption
116 */ 116 */
117const char * topology_strings[] = { 117const char *topology_strings[] = {
118 118
119 /** 119 /**
120 * A clique (everyone connected to everyone else). No options. If there are N 120 * A clique (everyone connected to everyone else). No options. If there are N
121 * peers this topology results in (N * (N -1)) connections. 121 * peers this topology results in (N * (N -1)) connections.
122 */ 122 */
123 "CLIQUE", 123 "CLIQUE",
124 124
125 /** 125 /**
126 * Small-world network (2d torus plus random links). Followed 126 * Small-world network (2d torus plus random links). Followed
127 * by the number of random links to add (unsigned int). 127 * by the number of random links to add (unsigned int).
128 */ 128 */
129 "SMALL_WORLD", 129 "SMALL_WORLD",
130 130
131 /** 131 /**
132 * Small-world network (ring plus random links). Followed 132 * Small-world network (ring plus random links). Followed
133 * by the number of random links to add (unsigned int). 133 * by the number of random links to add (unsigned int).
134 */ 134 */
135 "SMALL_WORLD_RING", 135 "SMALL_WORLD_RING",
136 136
137 /** 137 /**
138 * Ring topology. No options. 138 * Ring topology. No options.
139 */ 139 */
140 "RING", 140 "RING",
141 141
142 /** 142 /**
143 * 2-d torus. No options. 143 * 2-d torus. No options.
144 */ 144 */
145 "2D_TORUS", 145 "2D_TORUS",
146 146
147 /** 147 /**
148 * Random graph. Followed by the number of random links to be established 148 * Random graph. Followed by the number of random links to be established
149 * (unsigned int) 149 * (unsigned int)
150 */ 150 */
151 "RANDOM", // GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI 151 "RANDOM", // GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI
152 152
153 /** 153 /**
154 * Certain percentage of peers are unable to communicate directly 154 * Certain percentage of peers are unable to communicate directly
155 * replicating NAT conditions. Followed by the fraction of 155 * replicating NAT conditions. Followed by the fraction of
156 * NAT'ed peers (float). 156 * NAT'ed peers (float).
157 */ 157 */
158 "INTERNAT", 158 "INTERNAT",
159 159
160 /** 160 /**
161 * Scale free topology. No options. 161 * Scale free topology. No options.
162 */ 162 */
163 "SCALE_FREE", 163 "SCALE_FREE",
164 164
165 /** 165 /**
166 * Straight line topology. No options. 166 * Straight line topology. No options.
167 */ 167 */
168 "LINE", 168 "LINE",
169 169
170 /** 170 /**
171 * Read a topology from a given file. Followed by the name of the file (const char *). 171 * Read a topology from a given file. Followed by the name of the file (const char *).
172 */ 172 */
173 "FROM_FILE", 173 "FROM_FILE",
174 174
175 /** 175 /**
176 * All peers are disconnected. No options. 176 * All peers are disconnected. No options.
177 */ 177 */
178 "NONE", 178 "NONE",
179 179
180 /** 180 /**
181 * End of strings 181 * End of strings
182 */ 182 */
183 NULL 183 NULL
184 184};
185 };
186 185
187 186
188/** 187/**
@@ -193,10 +192,9 @@ const char * topology_strings[] = {
193 * @param emsg error message in case the operation has failed; will be NULL if 192 * @param emsg error message in case the operation has failed; will be NULL if
194 * operation has executed successfully. 193 * operation has executed successfully.
195 */ 194 */
196static void 195static void
197overlay_link_completed (void *cls, 196overlay_link_completed (void *cls, struct GNUNET_TESTBED_Operation *op,
198 struct GNUNET_TESTBED_Operation *op, 197 const char *emsg)
199 const char *emsg)
200{ 198{
201 struct OverlayLink *link = cls; 199 struct OverlayLink *link = cls;
202 struct TopologyContext *tc; 200 struct TopologyContext *tc;
@@ -208,12 +206,10 @@ overlay_link_completed (void *cls,
208 if ((NULL != emsg) && (GNUNET_NO == tc->disable_retry)) 206 if ((NULL != emsg) && (GNUNET_NO == tc->disable_retry))
209 { 207 {
210 LOG (GNUNET_ERROR_TYPE_WARNING, 208 LOG (GNUNET_ERROR_TYPE_WARNING,
211 "Error while establishing a link: %s -- Retrying\n", emsg); 209 "Error while establishing a link: %s -- Retrying\n", emsg);
212 link->op = 210 link->op =
213 GNUNET_TESTBED_overlay_connect (tc->op_cls, 211 GNUNET_TESTBED_overlay_connect (tc->op_cls, &overlay_link_completed,
214 &overlay_link_completed, 212 link, tc->peers[link->A],
215 link,
216 tc->peers[link->A],
217 tc->peers[link->B]); 213 tc->peers[link->B]);
218 return; 214 return;
219 } 215 }
@@ -231,14 +227,14 @@ opstart_overlay_configure_topology (void *cls)
231{ 227{
232 struct TopologyContext *tc = cls; 228 struct TopologyContext *tc = cls;
233 unsigned int p; 229 unsigned int p;
234 230
235 for (p = 0; p < tc->link_array_size; p++) 231 for (p = 0; p < tc->link_array_size; p++)
236 { 232 {
237 tc->link_array[p].op = 233 tc->link_array[p].op =
238 GNUNET_TESTBED_overlay_connect (tc->op_cls, &overlay_link_completed, 234 GNUNET_TESTBED_overlay_connect (tc->op_cls, &overlay_link_completed,
239 &tc->link_array[p], 235 &tc->link_array[p],
240 tc->peers[tc->link_array[p].A], 236 tc->peers[tc->link_array[p].A],
241 tc->peers[tc->link_array[p].B]); 237 tc->peers[tc->link_array[p].B]);
242 } 238 }
243} 239}
244 240
@@ -253,7 +249,7 @@ oprelease_overlay_configure_topology (void *cls)
253{ 249{
254 struct TopologyContext *tc = cls; 250 struct TopologyContext *tc = cls;
255 unsigned int p; 251 unsigned int p;
256 252
257 if (NULL != tc->link_array) 253 if (NULL != tc->link_array)
258 { 254 {
259 for (p = 0; p < tc->link_array_size; p++) 255 for (p = 0; p < tc->link_array_size; p++)
@@ -272,12 +268,10 @@ oprelease_overlay_configure_topology (void *cls)
272 * @param A the peer A. Should be different from B 268 * @param A the peer A. Should be different from B
273 * @param B the peer B. Should be different from A 269 * @param B the peer B. Should be different from A
274 * @param tc the TopologyContext 270 * @param tc the TopologyContext
275 * @return 271 * @return
276 */ 272 */
277static void 273static void
278make_link (struct OverlayLink *link, 274make_link (struct OverlayLink *link, uint32_t A, uint32_t B,
279 uint32_t A,
280 uint32_t B,
281 struct TopologyContext *tc) 275 struct TopologyContext *tc)
282{ 276{
283 GNUNET_assert (A != B); 277 GNUNET_assert (A != B);
@@ -300,9 +294,9 @@ gen_topo_line (struct TopologyContext *tc)
300 unsigned int cnt; 294 unsigned int cnt;
301 295
302 tc->link_array_size = tc->num_peers - 1; 296 tc->link_array_size = tc->num_peers - 1;
303 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * 297 tc->link_array =
304 tc->link_array_size); 298 GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
305 for (cnt=0; cnt < (tc->num_peers - 1); cnt++) 299 for (cnt = 0; cnt < (tc->num_peers - 1); cnt++)
306 make_link (&tc->link_array[cnt], cnt, cnt + 1, tc); 300 make_link (&tc->link_array[cnt], cnt, cnt + 1, tc);
307} 301}
308 302
@@ -317,12 +311,10 @@ gen_topo_ring (struct TopologyContext *tc)
317{ 311{
318 gen_topo_line (tc); 312 gen_topo_line (tc);
319 tc->link_array_size++; 313 tc->link_array_size++;
320 tc->link_array = GNUNET_realloc (tc->link_array, 314 tc->link_array =
321 sizeof (struct OverlayLink) * 315 GNUNET_realloc (tc->link_array,
322 tc->link_array_size); 316 sizeof (struct OverlayLink) * tc->link_array_size);
323 make_link (&tc->link_array[tc->link_array_size - 1], 317 make_link (&tc->link_array[tc->link_array_size - 1], tc->num_peers - 1, 0,
324 tc->num_peers - 1,
325 0,
326 tc); 318 tc);
327} 319}
328 320
@@ -338,8 +330,7 @@ gen_topo_ring (struct TopologyContext *tc)
338 * fresh. The caller should free it. Can be NULL 330 * fresh. The caller should free it. Can be NULL
339 */ 331 */
340unsigned int 332unsigned int
341GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, 333GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows,
342 unsigned int *rows,
343 unsigned int **rows_len) 334 unsigned int **rows_len)
344{ 335{
345 double sq; 336 double sq;
@@ -350,12 +341,12 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers,
350 unsigned int y; 341 unsigned int y;
351 unsigned int _num_peers; 342 unsigned int _num_peers;
352 unsigned int cnt; 343 unsigned int cnt;
353 344
354 sq = sqrt (num_peers); 345 sq = sqrt (num_peers);
355 sq = floor (sq); 346 sq = floor (sq);
356 sq_floor = (unsigned int) sq; 347 sq_floor = (unsigned int) sq;
357 _rows = (sq_floor + 1); 348 _rows = (sq_floor + 1);
358 _rows_len = GNUNET_malloc (sizeof (unsigned int) * _rows); 349 _rows_len = GNUNET_malloc (sizeof (unsigned int) * _rows);
359 for (y = 0; y < _rows - 1; y++) 350 for (y = 0; y < _rows - 1; y++)
360 _rows_len[y] = sq_floor; 351 _rows_len[y] = sq_floor;
361 _num_peers = sq_floor * sq_floor; 352 _num_peers = sq_floor * sq_floor;
@@ -399,28 +390,22 @@ gen_topo_2dtorus (struct TopologyContext *tc)
399 unsigned int cnt; 390 unsigned int cnt;
400 unsigned int offset; 391 unsigned int offset;
401 392
402 tc->link_array_size = GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, 393 tc->link_array_size =
403 &rows_len); 394 GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len);
404 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * 395 tc->link_array =
405 tc->link_array_size); 396 GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
406 cnt = 0; 397 cnt = 0;
407 offset = 0; 398 offset = 0;
408 for (y = 0; y < rows; y++) 399 for (y = 0; y < rows; y++)
409 { 400 {
410 for (x = 0; x < rows_len[y] - 1; x++) 401 for (x = 0; x < rows_len[y] - 1; x++)
411 { 402 {
412 make_link (&tc->link_array[cnt], 403 make_link (&tc->link_array[cnt], offset + x, offset + x + 1, tc);
413 offset + x,
414 offset + x + 1,
415 tc);
416 cnt++; 404 cnt++;
417 } 405 }
418 if (0 == x) 406 if (0 == x)
419 break; 407 break;
420 make_link (&tc->link_array[cnt], 408 make_link (&tc->link_array[cnt], offset + x, offset, tc);
421 offset + x,
422 offset,
423 tc);
424 cnt++; 409 cnt++;
425 offset += rows_len[y]; 410 offset += rows_len[y];
426 } 411 }
@@ -429,22 +414,17 @@ gen_topo_2dtorus (struct TopologyContext *tc)
429 offset = 0; 414 offset = 0;
430 for (y = 0; y < rows - 1; y++) 415 for (y = 0; y < rows - 1; y++)
431 { 416 {
432 if (x == rows_len[y+1]) 417 if (x == rows_len[y + 1])
433 break; 418 break;
434 GNUNET_assert (x < rows_len[y+1]); 419 GNUNET_assert (x < rows_len[y + 1]);
435 make_link (&tc->link_array[cnt], 420 make_link (&tc->link_array[cnt], offset + x, offset + rows_len[y] + x,
436 offset + x,
437 offset + rows_len[y] + x,
438 tc); 421 tc);
439 offset += rows_len[y]; 422 offset += rows_len[y];
440 cnt++; 423 cnt++;
441 } 424 }
442 if (0 == offset) 425 if (0 == offset)
443 break; 426 break;
444 make_link (&tc->link_array[cnt], 427 make_link (&tc->link_array[cnt], offset + x, x, tc);
445 offset + x,
446 x,
447 tc);
448 cnt++; 428 cnt++;
449 } 429 }
450 GNUNET_assert (cnt == tc->link_array_size); 430 GNUNET_assert (cnt == tc->link_array_size);
@@ -467,33 +447,35 @@ gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
467 unsigned int index; 447 unsigned int index;
468 uint32_t A_rand; 448 uint32_t A_rand;
469 uint32_t B_rand; 449 uint32_t B_rand;
470 450
471 if (GNUNET_YES == append) 451 if (GNUNET_YES == append)
472 { 452 {
473 GNUNET_assert ((0 < tc->link_array_size) && (NULL != tc->link_array)); 453 GNUNET_assert ((0 < tc->link_array_size) && (NULL != tc->link_array));
474 index = tc->link_array_size; 454 index = tc->link_array_size;
475 tc->link_array_size += links; 455 tc->link_array_size += links;
476 tc->link_array = GNUNET_realloc (tc->link_array, 456 tc->link_array =
477 sizeof (struct OverlayLink) * 457 GNUNET_realloc (tc->link_array,
478 tc->link_array_size); 458 sizeof (struct OverlayLink) * tc->link_array_size);
479 } 459 }
480 else 460 else
481 { 461 {
482 GNUNET_assert ((0 == tc->link_array_size) && (NULL == tc->link_array)); 462 GNUNET_assert ((0 == tc->link_array_size) && (NULL == tc->link_array));
483 index = 0; 463 index = 0;
484 tc->link_array_size = links; 464 tc->link_array_size = links;
485 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * 465 tc->link_array =
486 tc->link_array_size); 466 GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
487 } 467 }
488 for (cnt = 0; cnt < links; cnt++) 468 for (cnt = 0; cnt < links; cnt++)
489 { 469 {
490 do { 470 do
491 A_rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 471 {
492 tc->num_peers); 472 A_rand =
493 B_rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 473 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
494 tc->num_peers); 474 B_rand =
495 } while (A_rand == B_rand); 475 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
496 make_link (&tc->link_array[index + cnt], A_rand, B_rand, tc); 476 }
477 while (A_rand == B_rand);
478 make_link (&tc->link_array[index + cnt], A_rand, B_rand, tc);
497 } 479 }
498} 480}
499 481
@@ -518,24 +500,26 @@ gen_scale_free (struct TopologyContext *tc)
518 popularity = GNUNET_malloc (sizeof (uint16_t) * tc->num_peers); 500 popularity = GNUNET_malloc (sizeof (uint16_t) * tc->num_peers);
519 /* Initially connect peer 1 to peer 0 */ 501 /* Initially connect peer 1 to peer 0 */
520 tc->link_array_size = 1; 502 tc->link_array_size = 1;
521 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink)); 503 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink));
522 make_link (&tc->link_array[0], 0, 1, tc); 504 make_link (&tc->link_array[0], 0, 1, tc);
523 popularity[0]++; /* increase popularity of 0 as 1 connected to it*/ 505 popularity[0]++; /* increase popularity of 0 as 1 connected to it */
524 for (cnt = 1; cnt < tc->num_peers; cnt++) 506 for (cnt = 1; cnt < tc->num_peers; cnt++)
525 { 507 {
526 previous_connections = tc->link_array_size; 508 previous_connections = tc->link_array_size;
527 for (i = 0; i < cnt; i++) 509 for (i = 0; i < cnt; i++)
528 { 510 {
529 probability = ((double) popularity[i]) / ((double) previous_connections); 511 probability = ((double) popularity[i]) / ((double) previous_connections);
530 random = ((double) 512 random =
513 ((double)
531 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 514 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
532 UINT64_MAX)) / ((double) UINT64_MAX); 515 UINT64_MAX)) / ((double) UINT64_MAX);
533 if (random < probability) 516 if (random < probability)
534 { 517 {
535 tc->link_array_size++; 518 tc->link_array_size++;
536 tc->link_array = GNUNET_realloc (tc->link_array, 519 tc->link_array =
537 (sizeof (struct OverlayLink) * 520 GNUNET_realloc (tc->link_array,
538 tc->link_array_size)); 521 (sizeof (struct OverlayLink) *
522 tc->link_array_size));
539 make_link (&tc->link_array[tc->link_array_size - 1], cnt, i, tc); 523 make_link (&tc->link_array[tc->link_array_size - 1], cnt, i, tc);
540 popularity[cnt]++; 524 popularity[cnt]++;
541 } 525 }
@@ -561,8 +545,9 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
561 uint64_t offset; 545 uint64_t offset;
562 unsigned long int peer_id; 546 unsigned long int peer_id;
563 unsigned long int other_peer_id; 547 unsigned long int other_peer_id;
564 enum ParseState { 548 enum ParseState
565 549 {
550
566 /** 551 /**
567 * We read the peer index 552 * We read the peer index
568 */ 553 */
@@ -585,7 +570,8 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
585 if (GNUNET_OK != 570 if (GNUNET_OK !=
586 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) 571 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
587 { 572 {
588 LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s has no data\n"), filename); 573 LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s has no data\n"),
574 filename);
589 return; 575 return;
590 } 576 }
591 data = GNUNET_malloc (fs); 577 data = GNUNET_malloc (fs);
@@ -635,8 +621,7 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
635 if (tc->num_peers <= peer_id) 621 if (tc->num_peers <= peer_id)
636 { 622 {
637 LOG (GNUNET_ERROR_TYPE_ERROR, 623 LOG (GNUNET_ERROR_TYPE_ERROR,
638 _("Topology file needs more peers than given ones\n"), 624 _("Topology file needs more peers than given ones\n"), filename);
639 filename);
640 goto _exit; 625 goto _exit;
641 } 626 }
642 state = OTHER_PEER_INDEX; 627 state = OTHER_PEER_INDEX;
@@ -644,7 +629,7 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
644 break; 629 break;
645 case OTHER_PEER_INDEX: 630 case OTHER_PEER_INDEX:
646 errno = 0; 631 errno = 0;
647 other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10); 632 other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
648 if (0 != errno) 633 if (0 != errno)
649 { 634 {
650 LOG (GNUNET_ERROR_TYPE_ERROR, 635 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -660,25 +645,24 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
660 if (tc->num_peers <= other_peer_id) 645 if (tc->num_peers <= other_peer_id)
661 { 646 {
662 LOG (GNUNET_ERROR_TYPE_ERROR, 647 LOG (GNUNET_ERROR_TYPE_ERROR,
663 _("Topology file needs more peers than given ones\n"), 648 _("Topology file needs more peers than given ones\n"), filename);
664 filename);
665 goto _exit; 649 goto _exit;
666 } 650 }
667 if (peer_id != other_peer_id) 651 if (peer_id != other_peer_id)
668 { 652 {
669 tc->link_array_size++; 653 tc->link_array_size++;
670 tc->link_array = GNUNET_realloc (tc->link_array, 654 tc->link_array =
671 sizeof (struct OverlayLink) * 655 GNUNET_realloc (tc->link_array,
672 tc->link_array_size); 656 sizeof (struct OverlayLink) * tc->link_array_size);
673 offset += end - &data[offset]; 657 offset += end - &data[offset];
674 make_link (&tc->link_array[tc->link_array_size - 1], peer_id, 658 make_link (&tc->link_array[tc->link_array_size - 1], peer_id,
675 other_peer_id, tc); 659 other_peer_id, tc);
676 } 660 }
677 else 661 else
678 LOG (GNUNET_ERROR_TYPE_WARNING, 662 LOG (GNUNET_ERROR_TYPE_WARNING,
679 _("Ignoring to connect peer %u to peer %u\n"), peer_id, other_peer_id); 663 _("Ignoring to connect peer %u to peer %u\n"), peer_id,
680 while (('\n' != data[offset]) && ('|' != data[offset]) 664 other_peer_id);
681 && (offset < fs)) 665 while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
682 offset++; 666 offset++;
683 if ('\n' == data[offset]) 667 if ('\n' == data[offset])
684 state = PEER_INDEX; 668 state = PEER_INDEX;
@@ -691,13 +675,12 @@ gen_topo_from_file (struct TopologyContext *tc, const char *filename)
691 } 675 }
692 } 676 }
693 status = GNUNET_OK; 677 status = GNUNET_OK;
694 678
695 _exit: 679_exit:
696 GNUNET_free (data); 680 GNUNET_free (data);
697 if (GNUNET_OK != status) 681 if (GNUNET_OK != status)
698 { 682 {
699 LOG (GNUNET_ERROR_TYPE_WARNING, 683 LOG (GNUNET_ERROR_TYPE_WARNING, "Removing link data read from the file\n");
700 "Removing link data read from the file\n");
701 tc->link_array_size = 0; 684 tc->link_array_size = 0;
702 GNUNET_free_non_null (tc->link_array); 685 GNUNET_free_non_null (tc->link_array);
703 tc->link_array = NULL; 686 tc->link_array = NULL;
@@ -772,7 +755,8 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
772struct GNUNET_TESTBED_Operation * 755struct GNUNET_TESTBED_Operation *
773GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, 756GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
774 unsigned int num_peers, 757 unsigned int num_peers,
775 struct GNUNET_TESTBED_Peer **peers, 758 struct GNUNET_TESTBED_Peer
759 **peers,
776 unsigned int *max_connections, 760 unsigned int *max_connections,
777 enum GNUNET_TESTBED_TopologyOption 761 enum GNUNET_TESTBED_TopologyOption
778 topo, va_list va) 762 topo, va_list va)
@@ -799,29 +783,27 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
799 gen_topo_ring (tc); 783 gen_topo_ring (tc);
800 break; 784 break;
801 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 785 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
802 gen_topo_random (tc, 786 gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_NO);
803 va_arg (va, unsigned int), 787
804 GNUNET_NO);
805 break; 788 break;
806 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: 789 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
807 gen_topo_ring (tc); 790 gen_topo_ring (tc);
808 gen_topo_random (tc, 791 gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
809 va_arg (va, unsigned int), 792
810 GNUNET_YES);
811 break; 793 break;
812 case GNUNET_TESTBED_TOPOLOGY_CLIQUE: 794 case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
813 tc->link_array_size = num_peers * (num_peers - 1); 795 tc->link_array_size = num_peers * (num_peers - 1);
814 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * 796 tc->link_array =
815 tc->link_array_size); 797 GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
816 { 798 {
817 unsigned int offset; 799 unsigned int offset;
818 800
819 offset = 0; 801 offset = 0;
820 for (cnt=0; cnt < num_peers; cnt++) 802 for (cnt = 0; cnt < num_peers; cnt++)
821 { 803 {
822 unsigned int neighbour; 804 unsigned int neighbour;
823 805
824 for (neighbour=0; neighbour < num_peers; neighbour++) 806 for (neighbour = 0; neighbour < num_peers; neighbour++)
825 { 807 {
826 if (neighbour == cnt) 808 if (neighbour == cnt)
827 continue; 809 continue;
@@ -838,21 +820,21 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
838 break; 820 break;
839 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: 821 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
840 gen_topo_2dtorus (tc); 822 gen_topo_2dtorus (tc);
841 gen_topo_random (tc, 823 gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
842 va_arg (va, unsigned int), 824
843 GNUNET_YES);
844 break; 825 break;
845 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 826 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
846 gen_scale_free (tc); 827 gen_scale_free (tc);
847 break; 828 break;
848 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: 829 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
849 { 830 {
850 const char *filename; 831 const char *filename;
851 832
852 filename = va_arg (va, const char *); 833 filename = va_arg (va, const char *);
853 GNUNET_assert (NULL != filename); 834
854 gen_topo_from_file (tc, filename); 835 GNUNET_assert (NULL != filename);
855 } 836 gen_topo_from_file (tc, filename);
837 }
856 break; 838 break;
857 default: 839 default:
858 GNUNET_break (0); 840 GNUNET_break (0);
@@ -862,6 +844,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
862 do 844 do
863 { 845 {
864 secondary_option = va_arg (va, enum GNUNET_TESTBED_TopologyOption); 846 secondary_option = va_arg (va, enum GNUNET_TESTBED_TopologyOption);
847
865 switch (secondary_option) 848 switch (secondary_option)
866 { 849 {
867 case GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY: 850 case GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY:
@@ -871,20 +854,21 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
871 break; 854 break;
872 default: 855 default:
873 GNUNET_break (0); /* Should not use any other option apart from 856 GNUNET_break (0); /* Should not use any other option apart from
874 the ones handled here */ 857 * the ones handled here */
875 GNUNET_free_non_null (tc->link_array); 858 GNUNET_free_non_null (tc->link_array);
876 GNUNET_free (tc); 859 GNUNET_free (tc);
877 return NULL; 860 return NULL;
878 } 861 }
879 } while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option); 862 }
863 while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option);
880 op = GNUNET_TESTBED_operation_create_ (tc, 864 op = GNUNET_TESTBED_operation_create_ (tc,
881 &opstart_overlay_configure_topology, 865 &opstart_overlay_configure_topology,
882 &oprelease_overlay_configure_topology); 866 &oprelease_overlay_configure_topology);
883 GNUNET_TESTBED_operation_queue_insert_ 867 GNUNET_TESTBED_operation_queue_insert_
884 (c->opq_parallel_topology_config_operations, op); 868 (c->opq_parallel_topology_config_operations, op);
885 GNUNET_TESTBED_operation_begin_wait_ (op); 869 GNUNET_TESTBED_operation_begin_wait_ (op);
886 LOG (GNUNET_ERROR_TYPE_DEBUG, 870 LOG (GNUNET_ERROR_TYPE_DEBUG, "Generated %u connections\n",
887 "Generated %u connections\n", tc->link_array_size); 871 tc->link_array_size);
888 if (NULL != max_connections) 872 if (NULL != max_connections)
889 *max_connections = tc->link_array_size; 873 *max_connections = tc->link_array_size;
890 return op; 874 return op;
@@ -920,8 +904,8 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls, unsigned int num_peers,
920 GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END); 904 GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END);
921 va_start (vargs, topo); 905 va_start (vargs, topo);
922 op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers, 906 op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers,
923 max_connections, 907 max_connections, topo,
924 topo, vargs); 908 vargs);
925 va_end (vargs); 909 va_end (vargs);
926 return op; 910 return op;
927} 911}
@@ -939,7 +923,7 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls, unsigned int num_peers,
939int 923int
940GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, 924GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
941 const char *topology_string) 925 const char *topology_string)
942{ 926{
943 unsigned int cnt; 927 unsigned int cnt;
944 928
945 for (cnt = 0; NULL != topology_strings[cnt]; cnt++) 929 for (cnt = 0; NULL != topology_strings[cnt]; cnt++)