/*
This file is part of GNUnet
- (C) 2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2014 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
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.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
*/
static struct GNUNET_TIME_Relative timeout;
+/**
+ * When should dkg communication start?
+ */
+static struct GNUNET_TIME_Relative delay;
+
/**
* Handles for secretsharing sessions.
*/
static struct GNUNET_SECRETSHARING_PublicKey common_pubkey;
-/**
- * ???
- */
-static struct GNUNET_TESTBED_Operation **testbed_operations;
static unsigned int num_connected_sessions;
static unsigned int num_connected_decrypt;
+/**
+ * Handles to the running peers.
+ * When peers[i] is NULL, the i-th peer has stopped.
+ */
static struct GNUNET_TESTBED_Peer **peers;
static struct GNUNET_PeerIdentity *peer_ids;
static int verbose;
-struct GNUNET_SECRETSHARING_Plaintext reference_plaintext;
+static struct GNUNET_SECRETSHARING_Plaintext reference_plaintext;
+
+static struct GNUNET_SECRETSHARING_Ciphertext ciphertext;
+
+static struct GNUNET_TIME_Absolute dkg_start;
+
+static struct GNUNET_TIME_Absolute dkg_deadline;
-struct GNUNET_SECRETSHARING_Ciphertext ciphertext;
+
+static struct GNUNET_TIME_Absolute decrypt_start;
+
+static struct GNUNET_TIME_Absolute decrypt_deadline;
+
+/**
+ * Connect operations, one for every peer.
+ */
+static struct GNUNET_TESTBED_Operation **connect_ops;
+
+/**
+ * Are we performing a shutdown right now?
+ */
+static int in_shutdown;
/**
*dhp = NULL;
+ // we should still be connected if this is called
+ GNUNET_assert (NULL != connect_ops[n]);
+
+ GNUNET_TESTBED_operation_done (connect_ops[n]);
+
if (NULL == plaintext)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decrypt failed for peer %u\n", n);
"decrypt connect adapter, %d peers\n",
num_peers);
*hp = GNUNET_SECRETSHARING_decrypt (cfg, shares[n], &ciphertext,
- GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
+ decrypt_start, decrypt_deadline,
decrypt_cb,
hp);
decrypt_disconnect_adapter(void *cls, void *op_result)
{
struct GNUNET_SECRETSHARING_DecryptionHandle **dh = cls;
+ unsigned int n = dh - decrypt_handles;
+
+ GNUNET_assert (*dh == decrypt_handles[n]);
+
if (NULL != *dh)
{
GNUNET_SECRETSHARING_decrypt_cancel (*dh);
*dh = NULL;
}
+
+ GNUNET_assert (NULL != connect_ops[n]);
+ connect_ops[n] = NULL;
}
struct GNUNET_SECRETSHARING_Share *my_share,
struct GNUNET_SECRETSHARING_PublicKey *public_key,
unsigned int num_ready_peers,
- struct GNUNET_PeerIdentity *ready_peers)
+ const struct GNUNET_PeerIdentity *ready_peers)
{
struct GNUNET_SECRETSHARING_Session **sp = cls;
unsigned int n = sp - session_handles;
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "secret ready for peer #%u\n", n);
+ ret = GNUNET_STRINGS_data_to_string (public_key, sizeof *public_key, pubkey_str, 1024);
+ GNUNET_assert (NULL != ret);
+ *ret = '\0';
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "key generation successful for peer #%u, pubkey %s\n", n,
+ pubkey_str);
+
/* we're the first to get the key -> store it */
if (num_generated == 1)
{
}
}
- ret = GNUNET_STRINGS_data_to_string (public_key, sizeof *public_key, pubkey_str, 1024);
- GNUNET_assert (NULL != ret);
- *ret = '\0';
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "key generation successful for peer #%u, pubkey %s\n", n,
- pubkey_str);
-
- // FIXME: destroy testbed operation
-
- if (num_generated == num_peers)
- {
- int i;
- if (GNUNET_NO == decrypt)
- {
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ // we should still be connected
+ GNUNET_assert (NULL != connect_ops[n]);
- // compute g^42
- GNUNET_SECRETSHARING_plaintext_generate_i (&reference_plaintext, 42);
- GNUNET_SECRETSHARING_encrypt (&common_pubkey, &reference_plaintext, &ciphertext);
+ // disconnect from the service, will call the disconnect callback
+ GNUNET_TESTBED_operation_done (connect_ops[n]);
- // FIXME: store the ops somewhere!
- for (i = 0; i < num_peers; i++)
- GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", &decrypt_connect_complete, NULL,
- &decrypt_connect_adapter, &decrypt_disconnect_adapter, &decrypt_handles[i]);
- }
}
num_peers,
peer_ids,
&session_id,
- GNUNET_TIME_relative_to_absolute (timeout),
+ dkg_start,
+ dkg_deadline,
threshold,
&secret_ready_cb, sp);
return *sp;
session_disconnect_adapter (void *cls, void *op_result)
{
struct GNUNET_SECRETSHARING_Session **sp = cls;
+ unsigned int n = (sp - session_handles);
+
+ GNUNET_assert (*sp == session_handles[n]);
+
if (NULL != *sp)
{
GNUNET_SECRETSHARING_session_destroy (*sp);
*sp = NULL;
}
+
+ GNUNET_assert (NULL != connect_ops[n]);
+ connect_ops[n] = NULL;
+
+ if (GNUNET_YES == in_shutdown)
+ return;
+
+ // all peers received their secret
+ if (num_generated == num_peers)
+ {
+ int i;
+
+ // only do decryption if requested by the user
+ if (GNUNET_NO == decrypt)
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
+ decrypt_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
+ decrypt_deadline = GNUNET_TIME_absolute_add (decrypt_start, timeout);
+
+ // compute g^42 as the plaintext which we will decrypt and then
+ // cooperatively decrypt
+ GNUNET_SECRETSHARING_plaintext_generate_i (&reference_plaintext, 42);
+ GNUNET_SECRETSHARING_encrypt (&common_pubkey, &reference_plaintext, &ciphertext);
+
+ for (i = 0; i < num_peers; i++)
+ connect_ops[i] =
+ GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", &decrypt_connect_complete, NULL,
+ &decrypt_connect_adapter, &decrypt_disconnect_adapter, &decrypt_handles[i]);
+ }
}
num_retrieved_peer_ids++;
if (num_retrieved_peer_ids == num_peers)
for (i = 0; i < num_peers; i++)
- testbed_operations[i] =
+ connect_ops[i] =
GNUNET_TESTBED_service_connect (NULL, peers[i], "secretsharing", session_connect_complete, NULL,
session_connect_adapter, session_disconnect_adapter, &session_handles[i]);
}
}
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ */
+static void
+handle_shutdown (void *cls)
+{
+ in_shutdown = GNUNET_YES;
+
+ if (NULL != connect_ops)
+ {
+ unsigned int i;
+ for (i = 0; i < num_peers; i++)
+ if (NULL != connect_ops[i])
+ {
+ // the disconnect callback will set the op to NULL
+ GNUNET_TESTBED_operation_done (connect_ops[i]);
+ }
+ GNUNET_free (connect_ops);
+ }
+
+ // killing the testbed operation will take care of remaining
+ // service handles in the disconnect callback
+}
+
+
/**
* Signature of a main function for a testcase.
*
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n");
+ GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
+
peers = started_peers;
peer_ids = GNUNET_malloc (num_peers * sizeof (struct GNUNET_PeerIdentity));
session_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Session *);
decrypt_handles = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_DecryptionHandle *);
- testbed_operations = GNUNET_new_array (num_peers, struct GNUNET_TESTBED_Operation *);
+ connect_ops = GNUNET_new_array (num_peers, struct GNUNET_TESTBED_Operation *);
shares = GNUNET_new_array (num_peers, struct GNUNET_SECRETSHARING_Share *);
-
for (i = 0; i < num_peers; i++)
+ {
+ // we do not store the returned operation, as peer_info_cb
+ // will receive it as a parameter and call GNUNET_TESTBED_operation_done.
GNUNET_TESTBED_peer_get_information (peers[i],
GNUNET_TESTBED_PIT_IDENTITY,
peer_info_cb,
&peer_ids[i]);
+ }
}
char *topology;
int topology_cmp_result;
+ dkg_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
+ dkg_deadline = GNUNET_TIME_absolute_add (dkg_start, timeout);
+
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", "OVERLAY_TOPOLOGY", &topology))
{
fprintf (stderr,
{ 'n', "num-peers", NULL,
gettext_noop ("number of peers in consensus"),
GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers },
+ { 'D', "delay", NULL,
+ gettext_noop ("dkg start delay"),
+ GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &delay },
{ 't', "timeout", NULL,
gettext_noop ("dkg timeout"),
GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &timeout },
GNUNET_NO, &GNUNET_GETOPT_set_one, &verbose },
GNUNET_GETOPT_OPTION_END
};
- timeout = GNUNET_TIME_UNIT_SECONDS;
+ delay = GNUNET_TIME_UNIT_ZERO;
+ timeout = GNUNET_TIME_UNIT_MINUTES;
GNUNET_PROGRAM_run2 (argc, argv, "gnunet-secretsharing-profiler",
"help",
options, &run, NULL, GNUNET_YES);
return 0;
}
-