2 This file is part of GNUnet
3 (C) 2014 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file secretsharing/gnunet-secretsharing-profiler.c
23 * @brief profiling tool for distributed key generation and decryption
24 * @author Florian Dold
27 #include "gnunet_util_lib.h"
28 #include "gnunet_secretsharing_service.h"
29 #include "gnunet_testbed_service.h"
31 static unsigned int num_peers = 3;
33 static unsigned int threshold = 2;
35 static struct GNUNET_TIME_Relative timeout;
37 static struct GNUNET_SECRETSHARING_Session **session_handles;
39 static struct GNUNET_TESTBED_Operation **testbed_operations;
41 static unsigned int num_connected_handles;
43 static struct GNUNET_TESTBED_Peer **peers;
45 static struct GNUNET_PeerIdentity *peer_ids;
47 static unsigned int num_retrieved_peer_ids;
49 static struct GNUNET_HashCode session_id;
55 * Signature of the event handler function called by the
56 * respective event controller.
59 * @param event information about the event
62 controller_cb (void *cls,
63 const struct GNUNET_TESTBED_EventInformation *event)
70 * Callback to be called when a service connect operation is completed
72 * @param cls the callback closure from functions generating an operation
73 * @param op the operation that has been finished
74 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
75 * @param emsg error message in case the operation has failed; will be NULL if
76 * operation has executed successfully.
79 connect_complete (void *cls,
80 struct GNUNET_TESTBED_Operation *op,
87 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
88 "testbed connect emsg: %s\n",
93 num_connected_handles++;
95 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
96 "connect complete\n");
98 if (num_connected_handles == num_peers)
100 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
101 "all peers connected\n");
107 secret_ready_cb (void *cls,
108 const struct GNUNET_SECRETSHARING_Share *my_share,
109 const struct GNUNET_SECRETSHARING_PublicKey *public_key,
110 unsigned int num_ready_peers,
111 const struct GNUNET_PeerIdentity *ready_peers)
113 struct GNUNET_SECRETSHARING_Session **sp = cls;
114 unsigned int n = sp - session_handles;
115 if (NULL == my_share || NULL == public_key)
117 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "key generation failed for peer #%u\n", n);
120 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "secret ready for peer #%u\n", n);
121 // FIXME: end profiler or try decryption if all secrets are ready
126 * Adapter function called to establish a connection to
130 * @param cfg configuration of the peer to connect to; will be available until
131 * GNUNET_TESTBED_operation_done() is called on the operation returned
132 * from GNUNET_TESTBED_service_connect()
133 * @return service handle to return in 'op_result', NULL on error
136 connect_adapter (void *cls,
137 const struct GNUNET_CONFIGURATION_Handle *cfg)
139 struct GNUNET_SECRETSHARING_Session **sp = cls;
141 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
142 "connect adapter, %d peers\n",
144 *sp = GNUNET_SECRETSHARING_create_session (cfg,
148 GNUNET_TIME_relative_to_absolute (timeout),
150 &secret_ready_cb, sp);
156 * Adapter function called to destroy a connection to
160 * @param op_result service handle returned from the connect adapter
163 disconnect_adapter(void *cls, void *op_result)
165 /* FIXME: what to do here? */
170 * Callback to be called when the requested peer information is available
172 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
173 * @param op the operation this callback corresponds to
174 * @param pinfo the result; will be NULL if the operation has failed
175 * @param emsg error message if the operation has failed; will be NULL if the
176 * operation is successfull
179 peer_info_cb (void *cb_cls,
180 struct GNUNET_TESTBED_Operation *op,
181 const struct GNUNET_TESTBED_PeerInformation *pinfo,
184 struct GNUNET_PeerIdentity *p;
187 GNUNET_assert (NULL == emsg);
189 p = (struct GNUNET_PeerIdentity *) cb_cls;
191 if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY)
193 *p = *pinfo->result.id;
194 num_retrieved_peer_ids++;
195 if (num_retrieved_peer_ids == num_peers)
196 for (i = 0; i < num_peers; i++)
197 testbed_operations[i] =
198 GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", connect_complete, NULL,
199 connect_adapter, disconnect_adapter, &session_handles[i]);
206 GNUNET_TESTBED_operation_done (op);
211 * Signature of a main function for a testcase.
214 * @param h the run handle
215 * @param num_peers number of peers in 'peers'
216 * @param started_peers handle to peers run in the testbed. NULL upon timeout (see
217 * GNUNET_TESTBED_test_run()).
218 * @param links_succeeded the number of overlay link connection attempts that
220 * @param links_failed the number of overlay link connection attempts that
224 test_master (void *cls,
225 struct GNUNET_TESTBED_RunHandle *h,
226 unsigned int num_peers,
227 struct GNUNET_TESTBED_Peer **started_peers,
228 unsigned int links_succeeded,
229 unsigned int links_failed)
233 GNUNET_log_setup ("gnunet-secretsharing-profiler", "INFO", NULL);
235 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n");
237 peers = started_peers;
239 peer_ids = GNUNET_malloc (num_peers * sizeof (struct GNUNET_PeerIdentity));
241 session_handles = GNUNET_malloc (num_peers * sizeof (struct GNUNET_SECRETSHARING_Session *));
242 testbed_operations = GNUNET_malloc (num_peers * sizeof (struct GNUNET_TESTBED_Operation *));
244 for (i = 0; i < num_peers; i++)
245 GNUNET_TESTBED_peer_get_information (peers[i],
246 GNUNET_TESTBED_PIT_IDENTITY,
253 run (void *cls, char *const *args, const char *cfgfile,
254 const struct GNUNET_CONFIGURATION_Handle *cfg)
256 static char *session_str = "gnunet-secretsharing/test";
258 int topology_cmp_result;
260 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", "OVERLAY_TOPOLOGY", &topology))
263 "'OVERLAY_TOPOLOGY' not found in 'testbed' config section, "
264 "seems like you passed the wrong configuration file\n");
268 topology_cmp_result = strcasecmp (topology, "NONE");
269 GNUNET_free (topology);
271 if (0 == topology_cmp_result)
274 "'OVERLAY_TOPOLOGY' set to 'NONE', "
275 "seems like you passed the wrong configuration file\n");
279 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
280 "running gnunet-secretsharing-profiler\n");
282 GNUNET_CRYPTO_hash (session_str, strlen (session_str), &session_id);
284 (void) GNUNET_TESTBED_test_run ("gnunet-secretsharing-profiler",
296 main (int argc, char **argv)
298 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
299 { 'n', "num-peers", NULL,
300 gettext_noop ("number of peers in consensus"),
301 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers },
302 { 't', "timeout", NULL,
303 gettext_noop ("dkg timeout"),
304 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &timeout },
305 { 'k', "threshold", NULL,
306 gettext_noop ("threshold"),
307 GNUNET_YES, &GNUNET_GETOPT_set_uint, &threshold },
308 { 'V', "verbose", NULL,
309 gettext_noop ("be more verbose (print received values)"),
310 GNUNET_NO, &GNUNET_GETOPT_set_one, &verbose },
311 GNUNET_GETOPT_OPTION_END
313 timeout = GNUNET_TIME_UNIT_SECONDS;
314 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-secretsharing-profiler",
316 options, &run, NULL, GNUNET_YES);