--- /dev/null
+#
+# This file is part of GNUnet
+# (C) 2008, 2009 Christian Grothoff (and other contributing authors)
+#
+# GNUnet is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 3, or (at your
+# option) any later version.
+#
+# GNUnet is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNUnet; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+#
+#
+# @file contrib/peerStartHelper.pl
+# @brief Helper process for starting gnunet-testing peers.
+# @author Nathan Evans
+#
+# Finds configuration files (or any files) of the format
+# /path/*/gnunet-testing-config* and runs gnunet-arm with
+# each as the given configuration.
+#
+# usage: peerStartHelper.pl /path/to/testing_dir/
+#!/usr/bin/perl
+use strict;
+
+my $max_outstanding = 300;
+
+$ARGV[0] || die "No directory provided for peer information, exiting!\n";
+
+my $directory = $ARGV[0];
+my @config_files = `find $directory -iname gnunet-testing-config*`;
+my @child_arr = {};
+my $count = 0;
+my $outstanding = 0;
+foreach my $file (@config_files)
+{
+ chomp($file);
+ #print "Starting GNUnet peer with config file $file\n";
+ my $pid = fork();
+ if ($pid == -1)
+ {
+ die;
+ }
+ elsif ($pid == 0)
+ {
+ exec "gnunet-arm -q -c $file -s" or die;
+ }
+
+ if ($pid != 0)
+ {
+ push @child_arr, $pid;
+ $count++;
+ $outstanding++;
+ if ($outstanding > $max_outstanding)
+ {
+ for (my $i = 0; $i < $max_outstanding / 5; $i++)
+ {
+ #print "Too many outstanding peers, waiting!\n";
+ waitpid($child_arr[0], 0);
+ shift(@child_arr);
+ $outstanding--;
+ }
+ }
+ }
+}
+
+print "All $count peers started (waiting for them to finish!\n";
+
+while ($outstanding > 0)
+{
+ waitpid($child_arr[0], 0);
+ shift(@child_arr);
+ $outstanding--;
+ if ($outstanding % 50 == 0)
+ {
+ print "All $count peers started (waiting for $outstanding to finish!\n";
+ }
+}
+
+while (wait() != -1) {sleep 1}
+
+print "All $count peers started!\n";
+
+
% num_per_host);
value = cval;
}
+
+ /* FIXME: REMOVE FOREVER HACK HACK HACK */
+ if (0 == strcasecmp (section, "transport-tcp"))
+ GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, "ADVERTISED_PORT", value);
}
if (0 == strcmp (option, "UNIXPATH"))
#endif
unblacklisted_connections
= create_line (pg, &remove_connections, BLACKLIST);
- break;
- case GNUNET_TESTING_TOPOLOGY_NONE: /* Fall through */
- case GNUNET_TESTING_TOPOLOGY_FROM_FILE:
-#if VERBOSE_TESTING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Creating no blacklist topology (all peers can connect at transport level)\n"));
-#endif
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _
- ("Creating blacklist topology from allowed\n"));
- unblacklisted_connections = copy_allowed (pg, &remove_connections);
default:
break;
}
struct GNUNET_DISK_FileHandle *topology_output_file;
};
+struct TopologyOutputContext
+{
+ struct GNUNET_DISK_FileHandle *file;
+ GNUNET_TESTING_NotifyCompletion notify_cb;
+ void *notify_cb_cls;
+};
+
/**
* Simple struct to keep track of progress, and print a
* percentage meter for long running tasks.
}
+/**
+ * Prototype of a callback function indicating that two peers
+ * are currently connected.
+ *
+ * @param cls closure
+ * @param first peer id for first daemon
+ * @param second peer id for the second daemon
+ * @param distance distance between the connected peers
+ * @param emsg error message (NULL on success)
+ */
+void
+write_topology_cb (void *cls,
+ const struct GNUNET_PeerIdentity *first,
+ const struct GNUNET_PeerIdentity *second,
+ const char *emsg)
+{
+ struct TopologyOutputContext *topo_ctx;
+ int temp;
+ char *temp_str;
+ char *temp_pid2;
+
+ topo_ctx = (struct TopologyOutputContext *)cls;
+ GNUNET_assert(topo_ctx->file != NULL);
+ if (emsg == NULL)
+ {
+ GNUNET_assert(first != NULL);
+ GNUNET_assert(second != NULL);
+ temp_pid2 = GNUNET_strdup(GNUNET_i2s(second));
+ temp = GNUNET_asprintf(&temp_str, "\t%s -> %s\n", GNUNET_i2s(first), temp_pid2);
+ GNUNET_free(temp_pid2);
+ GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp);
+ }
+ else
+ {
+ temp = GNUNET_asprintf(&temp_str, "}\n");
+ GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp);
+ GNUNET_DISK_file_close(topo_ctx->file);
+ topo_ctx->notify_cb(topo_ctx->notify_cb_cls, NULL);
+ GNUNET_free(topo_ctx);
+ }
+}
+
+/**
+ * Print current topology to a graphviz readable file.
+ *
+ * @param pg a currently running peergroup to print to file
+ * @param output_filename the file to write the topology to
+ * @param notify_cb callback to call upon completion or failure
+ * @param notify_cb_cls closure for notify_cb
+ *
+ */
+void
+GNUNET_TESTING_peergroup_topology_to_file(struct GNUNET_TESTING_PeerGroup *pg,
+ char *output_filename,
+ GNUNET_TESTING_NotifyCompletion notify_cb,
+ void *notify_cb_cls)
+{
+ struct TopologyOutputContext *topo_ctx;
+ int temp;
+ char *temp_str;
+ topo_ctx = GNUNET_malloc(sizeof(struct TopologyOutputContext));
+
+ topo_ctx->file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE
+ | GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ if (topo_ctx->file == NULL)
+ {
+ notify_cb(notify_cb_cls, "Failed to open output file!");
+ return;
+ }
+
+ temp = GNUNET_asprintf(&temp_str, "digraph G {\n");
+ if (temp > 0)
+ GNUNET_DISK_file_write(topo_ctx->file, temp_str, temp);
+ GNUNET_free_non_null(temp_str);
+ GNUNET_TESTING_get_topology(pg, &write_topology_cb, topo_ctx);
+ return;
+}
+
/**
* Start a peer group with a given number of peers. Notify
* on completion of peer startup and connection based on given
* @return NULL on error, otherwise handle to control peer group
*/
struct GNUNET_TESTING_PeerGroup *
-GNUNET_TESTING_peergroup_start(
- const struct GNUNET_CONFIGURATION_Handle *cfg,
+GNUNET_TESTING_peergroup_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
unsigned int total,
struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyConnection connect_cb,
GNUNET_free_non_null(temp_str);
if (GNUNET_YES
- == GNUNET_CONFIGURATION_get_value_string (
- cfg,
+ == GNUNET_CONFIGURATION_get_value_string (cfg,
"testing",
"connect_topology_option_modifier",
&temp_str))