3 This file is part of GNUnet
4 (C) 2012 Christian Grothoff (and other contributing authors)
6 GNUnet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2, or (at your
9 option) any later version.
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNUnet; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
23 * @file consensus/gnunet-consensus-start-peers.c
24 * @brief Starts peers with testebed on localhost,
25 * prints their configuration files and waits for ^C.
26 * @author Florian Dold
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testbed_service.h"
33 static char *config_template_file;
34 static unsigned int num_peers_requested = 2;
35 static struct GNUNET_TESTBED_Peer **peers;
39 * Callback to be called when the requested peer information is available
41 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
42 * @param op the operation this callback corresponds to
43 * @param pinfo the result; will be NULL if the operation has failed
44 * @param emsg error message if the operation has failed; will be NULL if the
45 * operation is successfull
48 peer_info_cb (void *cb_cls,
49 struct GNUNET_TESTBED_Operation
52 GNUNET_TESTBED_PeerInformation
56 GNUNET_assert (NULL == emsg);
57 if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY)
59 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
60 GNUNET_CRYPTO_hash_to_enc (&pinfo->result.id->hashPubKey, &enc);
61 printf("peer %td identity:\n", ((struct GNUNET_TESTBED_Peer **) cb_cls) - &peers[0]);
62 printf("%s\n", (char *)&enc);
64 else if (pinfo->pit == GNUNET_TESTBED_PIT_CONFIGURATION)
67 if (NULL == (tmpfilename = GNUNET_DISK_mktemp ("gnunet-consensus")))
70 GNUNET_SCHEDULER_shutdown ();
74 GNUNET_CONFIGURATION_write (pinfo->result.cfg,
80 printf("peer %td config file:\n", ((struct GNUNET_TESTBED_Peer **) cb_cls) - &peers[0]);
81 printf("%s\n", tmpfilename);
92 * Signature of the event handler function called by the
93 * respective event controller.
96 * @param event information about the event
99 controller_cb(void *cls,
100 const struct GNUNET_TESTBED_EventInformation *event)
109 * Signature of a main function for a testcase.
112 * @param num_peers number of peers in 'peers'
113 * @param started_peers handle to peers being run in the testbed. NULL upon
114 * timeout (see GNUNET_TESTBED_test_run()).
115 * @param links_succeeded the number of overlay link connection attempts that
117 * @param links_failed the number of overlay link connection attempts that
121 test_master (void *cls,
122 unsigned int num_peers,
123 struct GNUNET_TESTBED_Peer **started_peers,
124 unsigned int links_succeeded,
125 unsigned int links_failed)
129 printf("started %d peers\n", num_peers);
130 peers = started_peers;
132 for (i = 0; i < num_peers; i++)
134 GNUNET_TESTBED_peer_get_information (peers[i],
135 GNUNET_TESTBED_PIT_IDENTITY,
138 GNUNET_TESTBED_peer_get_information (peers[i],
139 GNUNET_TESTBED_PIT_CONFIGURATION,
147 run (void *cls, char *const *args, const char *cfgfile,
148 const struct GNUNET_CONFIGURATION_Handle *config)
150 if (NULL == config_template_file)
152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "no template file specified\n");
156 (void) GNUNET_TESTBED_test_run ("gnunet-consensus-start-peers",
157 config_template_file,
168 main (int argc, char **argv)
170 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
171 { 't', "config-template", "TEMPLATE",
172 gettext_noop ("start peers with the given template configuration"),
173 GNUNET_YES, &GNUNET_GETOPT_set_string, &config_template_file },
174 { 'n', "num-peers", "NUM",
175 gettext_noop ("number of peers to start"),
176 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers_requested },
177 GNUNET_GETOPT_OPTION_END
180 /* run without scheduler, as test_run already does this */
181 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-consensus-start-peers",
183 options, &run, NULL, GNUNET_YES);