aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-08-13 23:39:08 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-08-13 23:39:08 +0000
commit4d3806a259258dcacc6c2a858967700c34b12086 (patch)
tree1b92d8346f28826ab5481cfa47321d3ea7d778ef
parenta23b776478202335270b516010466a660fed4ad1 (diff)
- profiler can be verbose
-rw-r--r--src/consensus/gnunet-consensus-profiler.c15
-rw-r--r--src/consensus/gnunet-service-consensus.c29
2 files changed, 37 insertions, 7 deletions
diff --git a/src/consensus/gnunet-consensus-profiler.c b/src/consensus/gnunet-consensus-profiler.c
index 42040527f0..baa6a3623c 100644
--- a/src/consensus/gnunet-consensus-profiler.c
+++ b/src/consensus/gnunet-consensus-profiler.c
@@ -55,6 +55,8 @@ static unsigned int peers_done = 0;
static unsigned *results_for_peer;
+static int verbose;
+
/**
* Signature of the event handler function called by the
@@ -202,10 +204,18 @@ new_element_cb (void *cls,
const struct GNUNET_SET_Element *element)
{
struct GNUNET_CONSENSUS_Handle **chp = cls;
+ int idx = chp - consensus_handles;
GNUNET_assert (NULL != cls);
- results_for_peer[chp - consensus_handles]++;
+ results_for_peer[idx]++;
+
+ GNUNET_assert (sizeof (struct GNUNET_HashCode) == element->size);
+
+ if (GNUNET_YES == verbose)
+ {
+ printf ("P%d received %s\n", idx, GNUNET_h2s ((struct GNUNET_HashCode *) element->data));
+ }
}
@@ -389,6 +399,9 @@ main (int argc, char **argv)
{ 't', "timeout", NULL,
gettext_noop ("consensus timeout"),
GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &conclude_timeout },
+ { 'V', "verbose", NULL,
+ gettext_noop ("be more verbose (print received values)"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &verbose },
GNUNET_GETOPT_OPTION_END
};
conclude_timeout = GNUNET_TIME_UNIT_SECONDS;
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c
index 94d532c3d9..3e1d1ad959 100644
--- a/src/consensus/gnunet-service-consensus.c
+++ b/src/consensus/gnunet-service-consensus.c
@@ -177,11 +177,15 @@ struct ConsensusSession
/**
* Permutation of peers for the current round,
- * maps logical index (for current round) to physical index (location in info array)
*/
uint32_t *shuffle;
/**
+ * Inverse permutation of peers for the current round,
+ */
+ uint32_t *shuffle_inv;
+
+ /**
* Current round of the exponential scheme.
*/
uint32_t exp_round;
@@ -331,6 +335,11 @@ destroy_session (struct ConsensusSession *session)
GNUNET_free (session->shuffle);
session->shuffle = NULL;
}
+ if (NULL != session->shuffle_inv)
+ {
+ GNUNET_free (session->shuffle_inv);
+ session->shuffle_inv = NULL;
+ }
if (NULL != session->info)
{
for (i = 0; i < session->num_peers; i++)
@@ -448,6 +457,8 @@ shuffle (struct ConsensusSession *session)
if (NULL == session->shuffle)
session->shuffle = GNUNET_malloc (session->num_peers * sizeof (*session->shuffle));
+ if (NULL == session->shuffle_inv)
+ session->shuffle_inv = GNUNET_malloc (session->num_peers * sizeof (*session->shuffle_inv));
GNUNET_CRYPTO_kdf (randomness, sizeof (randomness),
&session->exp_round, sizeof (uint32_t),
@@ -466,6 +477,10 @@ shuffle (struct ConsensusSession *session)
session->shuffle[x] = session->shuffle[i];
session->shuffle[i] = tmp;
}
+
+ /* create the inverse */
+ for (i = 0; i < session->num_peers; i++)
+ session->shuffle_inv[session->shuffle[i]] = i;
}
@@ -501,7 +516,7 @@ find_partners (struct ConsensusSession *session)
{
/* we are outgoing */
partner_idx = (my_idx + arc) % session->num_peers;
- session->partner_outgoing = &session->info[session->shuffle[partner_idx]];
+ session->partner_outgoing = &session->info[session->shuffle_inv[partner_idx]];
session->partner_outgoing->exp_subround_finished = GNUNET_NO;
/* are we a 'ghost' of a peer that would exist if
* the number of peers was a power of two, and thus have to partner
@@ -519,7 +534,7 @@ find_partners (struct ConsensusSession *session)
if (0 == (ghost_partner_idx & arc))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ghost partner is %d\n", ghost_partner_idx);
- session->partner_incoming = &session->info[session->shuffle[ghost_partner_idx]];
+ session->partner_incoming = &session->info[session->shuffle_inv[ghost_partner_idx]];
session->partner_incoming->exp_subround_finished = GNUNET_NO;
return;
}
@@ -532,7 +547,7 @@ find_partners (struct ConsensusSession *session)
if (partner_idx < 0)
partner_idx += session->num_peers;
session->partner_outgoing = NULL;
- session->partner_incoming = &session->info[session->shuffle[partner_idx]];
+ session->partner_incoming = &session->info[session->shuffle_inv[partner_idx]];
session->partner_incoming->exp_subround_finished = GNUNET_NO;
}
@@ -674,15 +689,17 @@ subround_over (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
session->exp_subround = 0;
if (NULL == session->shuffle)
session->shuffle = GNUNET_malloc ((sizeof (int)) * session->num_peers);
+ if (NULL == session->shuffle_inv)
+ session->shuffle_inv = GNUNET_malloc ((sizeof (int)) * session->num_peers);
for (i = 0; i < session->num_peers; i++)
- session->shuffle[i] = i;
+ session->shuffle[i] = session->shuffle_inv[i] = i;
}
else if (session->exp_subround + 1 >= (int) ceil (log2 (session->num_peers)))
{
/* subrounds done, start new log-round */
session->exp_round++;
session->exp_subround = 0;
- //shuffle (session);
+ shuffle (session);
}
else
{