aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/test_mesh_small.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/mesh/test_mesh_small.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/mesh/test_mesh_small.c')
-rw-r--r--src/mesh/test_mesh_small.c169
1 files changed, 79 insertions, 90 deletions
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c
index d0d394177..fe0ca631d 100644
--- a/src/mesh/test_mesh_small.c
+++ b/src/mesh/test_mesh_small.c
@@ -213,8 +213,8 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
213} 213}
214 214
215 215
216static void 216static void churn_peers (void *cls,
217churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 217 const struct GNUNET_SCHEDULER_TaskContext *tc);
218 218
219 219
220/** 220/**
@@ -235,9 +235,9 @@ stats_finished_callback (void *cls, int success)
235 { 235 {
236 /* Stats lookup successful, write out data */ 236 /* Stats lookup successful, write out data */
237 buf = NULL; 237 buf = NULL;
238 buf_len = GNUNET_asprintf (&buf, 238 buf_len =
239 "TOTAL_MESH_BYTES: %u\n", 239 GNUNET_asprintf (&buf, "TOTAL_MESH_BYTES: %u\n",
240 stats_context->total_mesh_bytes); 240 stats_context->total_mesh_bytes);
241 if (buf_len > 0) 241 if (buf_len > 0)
242 { 242 {
243 GNUNET_DISK_file_write (data_file, buf, buf_len); 243 GNUNET_DISK_file_write (data_file, buf, buf_len);
@@ -263,10 +263,9 @@ stats_finished_callback (void *cls, int success)
263 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 263 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
264 */ 264 */
265static int 265static int
266statistics_iterator (void *cls, 266statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer,
267 const struct GNUNET_PeerIdentity *peer, 267 const char *subsystem, const char *name, uint64_t value,
268 const char *subsystem, 268 int is_persistent)
269 const char *name, uint64_t value, int is_persistent)
270{ 269{
271 struct StatsContext *stats_context = cls; 270 struct StatsContext *stats_context = cls;
272 271
@@ -300,10 +299,9 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
300// } 299// }
301 300
302 GNUNET_asprintf (&buf, "round%llu", current_round); 301 GNUNET_asprintf (&buf, "round%llu", current_round);
303 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg, 302 if (GNUNET_OK ==
304 "test_mesh_small", 303 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
305 buf, 304 buf, &peers_next_round))
306 &peers_next_round))
307 { 305 {
308 current_round++; 306 current_round++;
309 GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK); 307 GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK);
@@ -314,8 +312,7 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
314 stats_context = GNUNET_malloc (sizeof (struct StatsContext)); 312 stats_context = GNUNET_malloc (sizeof (struct StatsContext));
315 GNUNET_SCHEDULER_cancel (shutdown_handle); 313 GNUNET_SCHEDULER_cancel (shutdown_handle);
316 shutdown_handle = GNUNET_SCHEDULER_NO_TASK; 314 shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
317 GNUNET_TESTING_get_statistics (pg, 315 GNUNET_TESTING_get_statistics (pg, &stats_finished_callback,
318 &stats_finished_callback,
319 &statistics_iterator, stats_context); 316 &statistics_iterator, stats_context);
320 } 317 }
321 GNUNET_free (buf); 318 GNUNET_free (buf);
@@ -331,8 +328,8 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
331static void 328static void
332topology_output_callback (void *cls, const char *emsg) 329topology_output_callback (void *cls, const char *emsg)
333{ 330{
334 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, 331 disconnect_task =
335 &disconnect_mesh_peers, NULL); 332 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
336 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); 333 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
337} 334}
338 335
@@ -354,19 +351,18 @@ churn_callback (void *cls, const char *emsg)
354 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 351 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
355 "Round %llu, churn finished successfully.\n", current_round); 352 "Round %llu, churn finished successfully.\n", current_round);
356 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); 353 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
357 GNUNET_asprintf (&temp_output_file, 354 GNUNET_asprintf (&temp_output_file, "%s_%llu.dot", topology_file,
358 "%s_%llu.dot", topology_file, current_round); 355 current_round);
359 GNUNET_TESTING_peergroup_topology_to_file (pg, 356 GNUNET_TESTING_peergroup_topology_to_file (pg, temp_output_file,
360 temp_output_file,
361 &topology_output_callback, NULL); 357 &topology_output_callback, NULL);
362 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 358 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Writing topology to file %s\n",
363 "Writing topology to file %s\n", temp_output_file); 359 temp_output_file);
364 GNUNET_free (temp_output_file); 360 GNUNET_free (temp_output_file);
365 } 361 }
366 else 362 else
367 { 363 {
368 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 364 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %llu, churn FAILED!!\n",
369 "Round %llu, churn FAILED!!\n", current_round); 365 current_round);
370 GNUNET_SCHEDULER_cancel (shutdown_handle); 366 GNUNET_SCHEDULER_cancel (shutdown_handle);
371 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 367 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
372 } 368 }
@@ -383,9 +379,8 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
383 /* Nothing to do... */ 379 /* Nothing to do... */
384 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); 380 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
385 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); 381 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
386 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, 382 disconnect_task =
387 &disconnect_mesh_peers, 383 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
388 NULL);
389 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n", 384 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n",
390 current_round); 385 current_round);
391 } 386 }
@@ -401,18 +396,18 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
401 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 396 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
402 "Round %llu, turning off %llu peers, turning on %llu peers!\n", 397 "Round %llu, turning off %llu peers, turning on %llu peers!\n",
403 current_round, 398 current_round,
404 (peers_running > peers_next_round) 399 (peers_running >
405 ? peers_running - peers_next_round 400 peers_next_round) ? peers_running - peers_next_round : 0,
406 : 0, 401 (peers_next_round >
407 (peers_next_round > peers_running) 402 peers_running) ? peers_next_round - peers_running : 0);
408 ? peers_next_round - peers_running : 0);
409 GNUNET_TESTING_daemons_churn (pg, "nse", 403 GNUNET_TESTING_daemons_churn (pg, "nse",
410 (peers_running > peers_next_round) 404 (peers_running >
411 ? peers_running - peers_next_round 405 peers_next_round) ? peers_running -
412 : 0, 406 peers_next_round : 0,
413 (peers_next_round > peers_running) 407 (peers_next_round >
414 ? peers_next_round - peers_running 408 peers_running) ? peers_next_round -
415 : 0, wait_time, &churn_callback, NULL); 409 peers_running : 0, wait_time, &churn_callback,
410 NULL);
416 } 411 }
417} 412}
418 413
@@ -435,8 +430,8 @@ my_cb (void *cls, const char *emsg)
435#if VERBOSE 430#if VERBOSE
436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n"); 431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n");
437#endif 432#endif
438 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 433 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n",
439 "Have %u connections\n", total_connections); 434 total_connections);
440 if (data_file != NULL) 435 if (data_file != NULL)
441 { 436 {
442 buf = NULL; 437 buf = NULL;
@@ -469,10 +464,8 @@ my_cb (void *cls, const char *emsg)
469 * @param emsg error message (NULL on success) 464 * @param emsg error message (NULL on success)
470 */ 465 */
471static void 466static void
472connect_cb (void *cls, 467connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
473 const struct GNUNET_PeerIdentity *first, 468 const struct GNUNET_PeerIdentity *second, uint32_t distance,
474 const struct GNUNET_PeerIdentity *second,
475 uint32_t distance,
476 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 469 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
477 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 470 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
478 struct GNUNET_TESTING_Daemon *first_daemon, 471 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -484,9 +477,8 @@ connect_cb (void *cls,
484 477
485 478
486static void 479static void
487run (void *cls, 480run (void *cls, char *const *args, const char *cfgfile,
488 char *const *args, 481 const struct GNUNET_CONFIGURATION_Handle *cfg)
489 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
490{ 482{
491 char *temp_str; 483 char *temp_str;
492 unsigned long long temp_wait; 484 unsigned long long temp_wait;
@@ -496,82 +488,80 @@ run (void *cls,
496 testing_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg; // GNUNET_CONFIGURATION_create(); 488 testing_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg; // GNUNET_CONFIGURATION_create();
497#if VERBOSE 489#if VERBOSE
498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
499 GNUNET_CONFIGURATION_set_value_string (testing_cfg, 491 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
500 "testing", "use_progressbars", "YES"); 492 "use_progressbars", "YES");
501#endif 493#endif
502 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 494 if (GNUNET_OK !=
503 "testing", 495 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
504 "num_peers", 496 "num_peers", &num_peers))
505 &num_peers))
506 { 497 {
507 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 498 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
508 "Option TESTING:NUM_PEERS is required!\n"); 499 "Option TESTING:NUM_PEERS is required!\n");
509 return; 500 return;
510 } 501 }
511 502
512 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 503 if (GNUNET_OK !=
513 "test_mesh_small", 504 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
514 "wait_time", 505 "wait_time", &temp_wait))
515 &temp_wait))
516 { 506 {
517 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 507 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
518 "Option nsetest_mesh_small:wait_time is required!\n"); 508 "Option nsetest_mesh_small:wait_time is required!\n");
519 return; 509 return;
520 } 510 }
521 511
522 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 512 if (GNUNET_OK !=
523 "testing", 513 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing",
524 "topology_output_file", 514 "topology_output_file",
525 &topology_file)) 515 &topology_file))
526 { 516 {
527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 517 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
528 "Option test_mesh_small:topology_output_file is required!\n"); 518 "Option test_mesh_small:topology_output_file is required!\n");
529 return; 519 return;
530 } 520 }
531 521
532 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 522 if (GNUNET_OK !=
533 "test_mesh_small", 523 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
534 "data_output_file", 524 "data_output_file",
535 &data_filename)) 525 &data_filename))
536 { 526 {
537 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
538 "Option test_mesh_small:data_output_file is required!\n"); 528 "Option test_mesh_small:data_output_file is required!\n");
539 return; 529 return;
540 } 530 }
541 531
542 data_file = GNUNET_DISK_file_open (data_filename, 532 data_file =
543 GNUNET_DISK_OPEN_READWRITE 533 GNUNET_DISK_file_open (data_filename,
544 | GNUNET_DISK_OPEN_CREATE, 534 GNUNET_DISK_OPEN_READWRITE |
545 GNUNET_DISK_PERM_USER_READ | 535 GNUNET_DISK_OPEN_CREATE,
546 GNUNET_DISK_PERM_USER_WRITE); 536 GNUNET_DISK_PERM_USER_READ |
537 GNUNET_DISK_PERM_USER_WRITE);
547 if (data_file == NULL) 538 if (data_file == NULL)
548 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 539 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
549 "Failed to open %s for output!\n", data_filename); 540 data_filename);
550 GNUNET_free (data_filename); 541 GNUNET_free (data_filename);
551 542
552 wait_time = 543 wait_time =
553 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); 544 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
554 545
555 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, 546 if (GNUNET_YES ==
556 "test_mesh_small", 547 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
557 "output_file", 548 "output_file", &temp_str))
558 &temp_str))
559 { 549 {
560 output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE 550 output_file =
561 | GNUNET_DISK_OPEN_CREATE, 551 GNUNET_DISK_file_open (temp_str,
562 GNUNET_DISK_PERM_USER_READ | 552 GNUNET_DISK_OPEN_READWRITE |
563 GNUNET_DISK_PERM_USER_WRITE); 553 GNUNET_DISK_OPEN_CREATE,
554 GNUNET_DISK_PERM_USER_READ |
555 GNUNET_DISK_PERM_USER_WRITE);
564 if (output_file == NULL) 556 if (output_file == NULL)
565 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 557 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
566 "Failed to open %s for output!\n", temp_str); 558 temp_str);
567 } 559 }
568 GNUNET_free_non_null (temp_str); 560 GNUNET_free_non_null (temp_str);
569 561
570 hosts = GNUNET_TESTING_hosts_load (testing_cfg); 562 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
571 563
572 pg = GNUNET_TESTING_peergroup_start (testing_cfg, 564 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
573 num_peers,
574 TIMEOUT,
575 &connect_cb, &my_cb, NULL, hosts); 565 &connect_cb, &my_cb, NULL, hosts);
576 GNUNET_assert (pg != NULL); 566 GNUNET_assert (pg != NULL);
577 shutdown_handle = 567 shutdown_handle =
@@ -602,10 +592,9 @@ main (int argc, char *argv[])
602 "WARNING", 592 "WARNING",
603#endif 593#endif
604 NULL); 594 NULL);
605 GNUNET_PROGRAM_run (argc, 595 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small",
606 argv, "test_mesh_small", 596 gettext_noop ("Test mesh in a small network."), options,
607 gettext_noop ("Test mesh in a small network."), 597 &run, NULL);
608 options, &run, NULL);
609#if REMOVE_DIR 598#if REMOVE_DIR
610 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); 599 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
611#endif 600#endif