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 test_master (void *cls,
110 unsigned int num_peers,
111 struct GNUNET_TESTBED_Peer **started_peers)
115 printf("started %d peers\n", num_peers);
116 peers = started_peers;
118 for (i = 0; i < num_peers; i++)
120 GNUNET_TESTBED_peer_get_information (peers[i],
121 GNUNET_TESTBED_PIT_IDENTITY,
124 GNUNET_TESTBED_peer_get_information (peers[i],
125 GNUNET_TESTBED_PIT_CONFIGURATION,
133 run (void *cls, char *const *args, const char *cfgfile,
134 const struct GNUNET_CONFIGURATION_Handle *config)
136 if (NULL == config_template_file)
138 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "no template file specified\n");
142 (void) GNUNET_TESTBED_test_run ("gnunet-consensus-start-peers",
143 config_template_file,
154 main (int argc, char **argv)
156 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
157 { 't', "config-template", "TEMPLATE",
158 gettext_noop ("start peers with the given template configuration"),
159 GNUNET_YES, &GNUNET_GETOPT_set_string, &config_template_file },
160 { 'n', "num-peers", "NUM",
161 gettext_noop ("number of peers to start"),
162 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers_requested },
163 GNUNET_GETOPT_OPTION_END
166 /* run without scheduler, as test_run already does this */
167 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-consensus-start-peers",
169 options, &run, NULL, GNUNET_YES);