diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-07-19 12:28:55 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-07-19 12:28:55 +0000 |
commit | e18a99bf3cfaed5be44befabaff894ccc47c98f6 (patch) | |
tree | a175857c318e3b064dc05cf7bf16ab216f1697bb /src | |
parent | 50e7453045035b43f2a412e21f0cca2a5fd62b84 (diff) | |
download | gnunet-e18a99bf3cfaed5be44befabaff894ccc47c98f6.tar.gz gnunet-e18a99bf3cfaed5be44befabaff894ccc47c98f6.zip |
coverity fix
Diffstat (limited to 'src')
-rwxr-xr-x | src/testing/gnunet-testing-remote-peer-start.pl | 92 | ||||
-rw-r--r-- | src/testing/test_testing_data_topology_stability.conf | 2 | ||||
-rw-r--r-- | src/testing/testing_group.c | 15 | ||||
-rw-r--r-- | src/testing/testing_peergroup.c | 93 |
4 files changed, 186 insertions, 16 deletions
diff --git a/src/testing/gnunet-testing-remote-peer-start.pl b/src/testing/gnunet-testing-remote-peer-start.pl new file mode 100755 index 000000000..e4f72e9d0 --- /dev/null +++ b/src/testing/gnunet-testing-remote-peer-start.pl | |||
@@ -0,0 +1,92 @@ | |||
1 | # | ||
2 | # This file is part of GNUnet | ||
3 | # (C) 2008, 2009 Christian Grothoff (and other contributing authors) | ||
4 | # | ||
5 | # GNUnet is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published | ||
7 | # by the Free Software Foundation; either version 3, or (at your | ||
8 | # option) any later version. | ||
9 | # | ||
10 | # GNUnet is distributed in the hope that it will be useful, but | ||
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | # General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with GNUnet; see the file COPYING. If not, write to the | ||
17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | # Boston, MA 02111-1307, USA. | ||
19 | # | ||
20 | # | ||
21 | # | ||
22 | # @file contrib/peerStartHelper.pl | ||
23 | # @brief Helper process for starting gnunet-testing peers. | ||
24 | # @author Nathan Evans | ||
25 | # | ||
26 | # Finds configuration files (or any files) of the format | ||
27 | # /path/*/gnunet-testing-config* and runs gnunet-arm with | ||
28 | # each as the given configuration. | ||
29 | # | ||
30 | # usage: peerStartHelper.pl /path/to/testing_dir/ | ||
31 | #!/usr/bin/perl | ||
32 | use strict; | ||
33 | |||
34 | my $max_outstanding = 300; | ||
35 | |||
36 | $ARGV[0] || die "No directory provided for peer information, exiting!\n"; | ||
37 | |||
38 | my $directory = $ARGV[0]; | ||
39 | my @config_files = `find $directory -iname gnunet-testing-config*`; | ||
40 | my @child_arr = {}; | ||
41 | my $count = 0; | ||
42 | my $outstanding = 0; | ||
43 | foreach my $file (@config_files) | ||
44 | { | ||
45 | chomp($file); | ||
46 | #print "Starting GNUnet peer with config file $file\n"; | ||
47 | my $pid = fork(); | ||
48 | if ($pid == -1) | ||
49 | { | ||
50 | die; | ||
51 | } | ||
52 | elsif ($pid == 0) | ||
53 | { | ||
54 | exec "gnunet-arm -q -c $file -s" or die; | ||
55 | } | ||
56 | |||
57 | if ($pid != 0) | ||
58 | { | ||
59 | push @child_arr, $pid; | ||
60 | $count++; | ||
61 | $outstanding++; | ||
62 | if ($outstanding > $max_outstanding) | ||
63 | { | ||
64 | for (my $i = 0; $i < $max_outstanding / 5; $i++) | ||
65 | { | ||
66 | #print "Too many outstanding peers, waiting!\n"; | ||
67 | waitpid($child_arr[0], 0); | ||
68 | shift(@child_arr); | ||
69 | $outstanding--; | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | print "All $count peers started (waiting for them to finish!\n"; | ||
76 | |||
77 | while ($outstanding > 0) | ||
78 | { | ||
79 | waitpid($child_arr[0], 0); | ||
80 | shift(@child_arr); | ||
81 | $outstanding--; | ||
82 | if ($outstanding % 50 == 0) | ||
83 | { | ||
84 | print "All $count peers started (waiting for $outstanding to finish!\n"; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | while (wait() != -1) {sleep 1} | ||
89 | |||
90 | print "All $count peers started!\n"; | ||
91 | |||
92 | |||
diff --git a/src/testing/test_testing_data_topology_stability.conf b/src/testing/test_testing_data_topology_stability.conf index efe5d6879..3504200b9 100644 --- a/src/testing/test_testing_data_topology_stability.conf +++ b/src/testing/test_testing_data_topology_stability.conf | |||
@@ -42,7 +42,7 @@ PORT = 2570 | |||
42 | 42 | ||
43 | [testing] | 43 | [testing] |
44 | SETTLE_TIME = 600 | 44 | SETTLE_TIME = 600 |
45 | NUM_PEERS = 10 | 45 | NUM_PEERS = 2 |
46 | WEAKRANDOM = YES | 46 | WEAKRANDOM = YES |
47 | #CONNECT_TOPOLOGY = CLIQUE | 47 | #CONNECT_TOPOLOGY = CLIQUE |
48 | TOPOLOGY = CLIQUE | 48 | TOPOLOGY = CLIQUE |
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 8bda28564..27b3b2cad 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -1308,6 +1308,10 @@ update_config(void *cls, const char *section, const char *option, | |||
1308 | % num_per_host); | 1308 | % num_per_host); |
1309 | value = cval; | 1309 | value = cval; |
1310 | } | 1310 | } |
1311 | |||
1312 | /* FIXME: REMOVE FOREVER HACK HACK HACK */ | ||
1313 | if (0 == strcasecmp (section, "transport-tcp")) | ||
1314 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, "ADVERTISED_PORT", value); | ||
1311 | } | 1315 | } |
1312 | 1316 | ||
1313 | if (0 == strcmp (option, "UNIXPATH")) | 1317 | if (0 == strcmp (option, "UNIXPATH")) |
@@ -4100,17 +4104,6 @@ GNUNET_TESTING_create_topology(struct GNUNET_TESTING_PeerGroup *pg, | |||
4100 | #endif | 4104 | #endif |
4101 | unblacklisted_connections | 4105 | unblacklisted_connections |
4102 | = create_line (pg, &remove_connections, BLACKLIST); | 4106 | = create_line (pg, &remove_connections, BLACKLIST); |
4103 | break; | ||
4104 | case GNUNET_TESTING_TOPOLOGY_NONE: /* Fall through */ | ||
4105 | case GNUNET_TESTING_TOPOLOGY_FROM_FILE: | ||
4106 | #if VERBOSE_TESTING | ||
4107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4108 | _ | ||
4109 | ("Creating no blacklist topology (all peers can connect at transport level)\n")); | ||
4110 | #endif | ||
4111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ | ||
4112 | ("Creating blacklist topology from allowed\n")); | ||
4113 | unblacklisted_connections = copy_allowed (pg, &remove_connections); | ||
4114 | default: | 4107 | default: |
4115 | break; | 4108 | break; |
4116 | } | 4109 | } |
diff --git a/src/testing/testing_peergroup.c b/src/testing/testing_peergroup.c index 05ac50cc3..25a04df07 100644 --- a/src/testing/testing_peergroup.c +++ b/src/testing/testing_peergroup.c | |||
@@ -108,6 +108,13 @@ struct PeerGroupStartupContext | |||
108 | struct GNUNET_DISK_FileHandle *topology_output_file; | 108 | struct GNUNET_DISK_FileHandle *topology_output_file; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | struct TopologyOutputContext | ||
112 | { | ||
113 | struct GNUNET_DISK_FileHandle *file; | ||
114 | GNUNET_TESTING_NotifyCompletion notify_cb; | ||
115 | void *notify_cb_cls; | ||
116 | }; | ||
117 | |||
111 | /** | 118 | /** |
112 | * Simple struct to keep track of progress, and print a | 119 | * Simple struct to keep track of progress, and print a |
113 | * percentage meter for long running tasks. | 120 | * percentage meter for long running tasks. |
@@ -578,6 +585,86 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
578 | 585 | ||
579 | 586 | ||
580 | /** | 587 | /** |
588 | * Prototype of a callback function indicating that two peers | ||
589 | * are currently connected. | ||
590 | * | ||
591 | * @param cls closure | ||
592 | * @param first peer id for first daemon | ||
593 | * @param second peer id for the second daemon | ||
594 | * @param distance distance between the connected peers | ||
595 | * @param emsg error message (NULL on success) | ||
596 | */ | ||
597 | void | ||
598 | write_topology_cb (void *cls, | ||
599 | const struct GNUNET_PeerIdentity *first, | ||
600 | const struct GNUNET_PeerIdentity *second, | ||
601 | const char *emsg) | ||
602 | { | ||
603 | struct TopologyOutputContext *topo_ctx; | ||
604 | int temp; | ||
605 | char *temp_str; | ||
606 | char *temp_pid2; | ||
607 | |||
608 | topo_ctx = (struct TopologyOutputContext *)cls; | ||
609 | GNUNET_assert(topo_ctx->file != NULL); | ||
610 | if (emsg == NULL) | ||
611 | { | ||
612 | GNUNET_assert(first != NULL); | ||
613 | GNUNET_assert(second != NULL); | ||
614 | temp_pid2 = GNUNET_strdup(GNUNET_i2s(second)); | ||
615 | temp = GNUNET_asprintf(&temp_str, "\t%s -> %s\n", GNUNET_i2s(first), temp_pid2); | ||
616 | GNUNET_free(temp_pid2); | ||
617 | GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp); | ||
618 | } | ||
619 | else | ||
620 | { | ||
621 | temp = GNUNET_asprintf(&temp_str, "}\n"); | ||
622 | GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp); | ||
623 | GNUNET_DISK_file_close(topo_ctx->file); | ||
624 | topo_ctx->notify_cb(topo_ctx->notify_cb_cls, NULL); | ||
625 | GNUNET_free(topo_ctx); | ||
626 | } | ||
627 | } | ||
628 | |||
629 | /** | ||
630 | * Print current topology to a graphviz readable file. | ||
631 | * | ||
632 | * @param pg a currently running peergroup to print to file | ||
633 | * @param output_filename the file to write the topology to | ||
634 | * @param notify_cb callback to call upon completion or failure | ||
635 | * @param notify_cb_cls closure for notify_cb | ||
636 | * | ||
637 | */ | ||
638 | void | ||
639 | GNUNET_TESTING_peergroup_topology_to_file(struct GNUNET_TESTING_PeerGroup *pg, | ||
640 | char *output_filename, | ||
641 | GNUNET_TESTING_NotifyCompletion notify_cb, | ||
642 | void *notify_cb_cls) | ||
643 | { | ||
644 | struct TopologyOutputContext *topo_ctx; | ||
645 | int temp; | ||
646 | char *temp_str; | ||
647 | topo_ctx = GNUNET_malloc(sizeof(struct TopologyOutputContext)); | ||
648 | |||
649 | topo_ctx->file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE | ||
650 | | GNUNET_DISK_OPEN_CREATE, | ||
651 | GNUNET_DISK_PERM_USER_READ | | ||
652 | GNUNET_DISK_PERM_USER_WRITE); | ||
653 | if (topo_ctx->file == NULL) | ||
654 | { | ||
655 | notify_cb(notify_cb_cls, "Failed to open output file!"); | ||
656 | return; | ||
657 | } | ||
658 | |||
659 | temp = GNUNET_asprintf(&temp_str, "digraph G {\n"); | ||
660 | if (temp > 0) | ||
661 | GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp); | ||
662 | GNUNET_free_non_null(temp_str); | ||
663 | GNUNET_TESTING_get_topology(pg, &write_topology_cb, topo_ctx); | ||
664 | return; | ||
665 | } | ||
666 | |||
667 | /** | ||
581 | * Start a peer group with a given number of peers. Notify | 668 | * Start a peer group with a given number of peers. Notify |
582 | * on completion of peer startup and connection based on given | 669 | * on completion of peer startup and connection based on given |
583 | * topological constraints. Optionally notify on each | 670 | * topological constraints. Optionally notify on each |
@@ -595,8 +682,7 @@ internal_hostkey_callback(void *cls, const struct GNUNET_PeerIdentity *id, | |||
595 | * @return NULL on error, otherwise handle to control peer group | 682 | * @return NULL on error, otherwise handle to control peer group |
596 | */ | 683 | */ |
597 | struct GNUNET_TESTING_PeerGroup * | 684 | struct GNUNET_TESTING_PeerGroup * |
598 | GNUNET_TESTING_peergroup_start( | 685 | GNUNET_TESTING_peergroup_start(const struct GNUNET_CONFIGURATION_Handle *cfg, |
599 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
600 | unsigned int total, | 686 | unsigned int total, |
601 | struct GNUNET_TIME_Relative timeout, | 687 | struct GNUNET_TIME_Relative timeout, |
602 | GNUNET_TESTING_NotifyConnection connect_cb, | 688 | GNUNET_TESTING_NotifyConnection connect_cb, |
@@ -749,8 +835,7 @@ GNUNET_TESTING_peergroup_start( | |||
749 | GNUNET_free_non_null(temp_str); | 835 | GNUNET_free_non_null(temp_str); |
750 | 836 | ||
751 | if (GNUNET_YES | 837 | if (GNUNET_YES |
752 | == GNUNET_CONFIGURATION_get_value_string ( | 838 | == GNUNET_CONFIGURATION_get_value_string (cfg, |
753 | cfg, | ||
754 | "testing", | 839 | "testing", |
755 | "connect_topology_option_modifier", | 840 | "connect_topology_option_modifier", |
756 | &temp_str)) | 841 | &temp_str)) |