diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-07-17 16:31:56 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-07-17 16:31:56 +0000 |
commit | 9650c61accea3823bf3e96f9c0e150655e124796 (patch) | |
tree | 0d1b412d9ffd01241316012a4224da0773d59ca9 /src | |
parent | dd8821e8f0a432da4ec5fdacfa16644b9ed4c238 (diff) | |
download | gnunet-9650c61accea3823bf3e96f9c0e150655e124796.tar.gz gnunet-9650c61accea3823bf3e96f9c0e150655e124796.zip |
print topology to file (dot)
Diffstat (limited to 'src')
-rw-r--r-- | src/testing/testing_peergroup.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/testing/testing_peergroup.c b/src/testing/testing_peergroup.c index 709cd8b4f..05ac50cc3 100644 --- a/src/testing/testing_peergroup.c +++ b/src/testing/testing_peergroup.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "gnunet_arm_service.h" | 30 | #include "gnunet_arm_service.h" |
31 | #include "gnunet_testing_lib.h" | 31 | #include "gnunet_testing_lib.h" |
32 | #include "gnunet_core_service.h" | 32 | #include "gnunet_core_service.h" |
33 | #include "gnunet_disk_lib.h" | ||
33 | 34 | ||
34 | /** Globals **/ | 35 | /** Globals **/ |
35 | #define DEFAULT_CONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) | 36 | #define DEFAULT_CONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) |
@@ -100,6 +101,11 @@ struct PeerGroupStartupContext | |||
100 | * The total number of connections that have failed so far. | 101 | * The total number of connections that have failed so far. |
101 | */ | 102 | */ |
102 | unsigned int failed_connections; | 103 | unsigned int failed_connections; |
104 | |||
105 | /** | ||
106 | * File handle to write out topology in dot format. | ||
107 | */ | ||
108 | struct GNUNET_DISK_FileHandle *topology_output_file; | ||
103 | }; | 109 | }; |
104 | 110 | ||
105 | /** | 111 | /** |
@@ -296,6 +302,9 @@ internal_topology_callback( | |||
296 | const char *emsg) | 302 | const char *emsg) |
297 | { | 303 | { |
298 | struct PeerGroupStartupContext *pg_start_ctx = cls; | 304 | struct PeerGroupStartupContext *pg_start_ctx = cls; |
305 | char *temp_str; | ||
306 | char *second_str; | ||
307 | int temp; | ||
299 | #if TIMING | 308 | #if TIMING |
300 | unsigned long long duration; | 309 | unsigned long long duration; |
301 | unsigned long long total_duration; | 310 | unsigned long long total_duration; |
@@ -358,6 +367,15 @@ internal_topology_callback( | |||
358 | second_daemon->shortname, | 367 | second_daemon->shortname, |
359 | distance); | 368 | distance); |
360 | #endif | 369 | #endif |
370 | if (pg_start_ctx->topology_output_file != NULL) | ||
371 | { | ||
372 | second_str = GNUNET_strdup(GNUNET_i2s(second)); | ||
373 | temp = GNUNET_asprintf(&temp_str, "\t\"%s\" -> \"%s\"\n", GNUNET_i2s(first), second_str); | ||
374 | GNUNET_free(second_str); | ||
375 | if (temp > 0) | ||
376 | GNUNET_DISK_file_write(pg_start_ctx->topology_output_file, temp_str, temp); | ||
377 | GNUNET_free(temp_str); | ||
378 | } | ||
361 | } | 379 | } |
362 | else | 380 | else |
363 | { | 381 | { |
@@ -413,6 +431,15 @@ internal_topology_callback( | |||
413 | /* Call final callback, signifying that the peer group has been started and connected */ | 431 | /* Call final callback, signifying that the peer group has been started and connected */ |
414 | if (pg_start_ctx->peergroup_cb != NULL) | 432 | if (pg_start_ctx->peergroup_cb != NULL) |
415 | pg_start_ctx->peergroup_cb(pg_start_ctx->cls, NULL); | 433 | pg_start_ctx->peergroup_cb(pg_start_ctx->cls, NULL); |
434 | |||
435 | if (pg_start_ctx->topology_output_file != NULL) | ||
436 | { | ||
437 | temp = GNUNET_asprintf(&temp_str, "}\n"); | ||
438 | if (temp > 0) | ||
439 | GNUNET_DISK_file_write(pg_start_ctx->topology_output_file, temp_str, temp); | ||
440 | GNUNET_free(temp_str); | ||
441 | GNUNET_DISK_file_close(pg_start_ctx->topology_output_file); | ||
442 | } | ||
416 | } | 443 | } |
417 | } | 444 | } |
418 | 445 | ||
@@ -580,6 +607,7 @@ GNUNET_TESTING_peergroup_start( | |||
580 | struct PeerGroupStartupContext *pg_start_ctx; | 607 | struct PeerGroupStartupContext *pg_start_ctx; |
581 | unsigned long long temp_config_number; | 608 | unsigned long long temp_config_number; |
582 | char *temp_str; | 609 | char *temp_str; |
610 | int temp; | ||
583 | GNUNET_assert(total > 0); | 611 | GNUNET_assert(total > 0); |
584 | GNUNET_assert(cfg != NULL); | 612 | GNUNET_assert(cfg != NULL); |
585 | 613 | ||
@@ -653,6 +681,22 @@ GNUNET_TESTING_peergroup_start( | |||
653 | } | 681 | } |
654 | GNUNET_free_non_null(temp_str); | 682 | GNUNET_free_non_null(temp_str); |
655 | 683 | ||
684 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology_output_file", &temp_str)) | ||
685 | { | ||
686 | pg_start_ctx->topology_output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE | ||
687 | | GNUNET_DISK_OPEN_CREATE, | ||
688 | GNUNET_DISK_PERM_USER_READ | | ||
689 | GNUNET_DISK_PERM_USER_WRITE); | ||
690 | if (pg_start_ctx->topology_output_file != NULL) | ||
691 | { | ||
692 | GNUNET_free(temp_str); | ||
693 | temp = GNUNET_asprintf(&temp_str, "digraph G {\n"); | ||
694 | if (temp > 0) | ||
695 | GNUNET_DISK_file_write(pg_start_ctx->topology_output_file, temp_str, temp); | ||
696 | } | ||
697 | GNUNET_free(temp_str); | ||
698 | } | ||
699 | |||
656 | if (GNUNET_OK | 700 | if (GNUNET_OK |
657 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage", | 701 | != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage", |
658 | &temp_str)) | 702 | &temp_str)) |