diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-08-13 23:39:08 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-08-13 23:39:08 +0000 |
commit | 4d3806a259258dcacc6c2a858967700c34b12086 (patch) | |
tree | 1b92d8346f28826ab5481cfa47321d3ea7d778ef /src/consensus | |
parent | a23b776478202335270b516010466a660fed4ad1 (diff) | |
download | gnunet-4d3806a259258dcacc6c2a858967700c34b12086.tar.gz gnunet-4d3806a259258dcacc6c2a858967700c34b12086.zip |
- profiler can be verbose
Diffstat (limited to 'src/consensus')
-rw-r--r-- | src/consensus/gnunet-consensus-profiler.c | 15 | ||||
-rw-r--r-- | src/consensus/gnunet-service-consensus.c | 29 |
2 files changed, 37 insertions, 7 deletions
diff --git a/src/consensus/gnunet-consensus-profiler.c b/src/consensus/gnunet-consensus-profiler.c index 42040527f..baa6a3623 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; | |||
55 | 55 | ||
56 | static unsigned *results_for_peer; | 56 | static unsigned *results_for_peer; |
57 | 57 | ||
58 | static int verbose; | ||
59 | |||
58 | 60 | ||
59 | /** | 61 | /** |
60 | * Signature of the event handler function called by the | 62 | * Signature of the event handler function called by the |
@@ -202,10 +204,18 @@ new_element_cb (void *cls, | |||
202 | const struct GNUNET_SET_Element *element) | 204 | const struct GNUNET_SET_Element *element) |
203 | { | 205 | { |
204 | struct GNUNET_CONSENSUS_Handle **chp = cls; | 206 | struct GNUNET_CONSENSUS_Handle **chp = cls; |
207 | int idx = chp - consensus_handles; | ||
205 | 208 | ||
206 | GNUNET_assert (NULL != cls); | 209 | GNUNET_assert (NULL != cls); |
207 | 210 | ||
208 | results_for_peer[chp - consensus_handles]++; | 211 | results_for_peer[idx]++; |
212 | |||
213 | GNUNET_assert (sizeof (struct GNUNET_HashCode) == element->size); | ||
214 | |||
215 | if (GNUNET_YES == verbose) | ||
216 | { | ||
217 | printf ("P%d received %s\n", idx, GNUNET_h2s ((struct GNUNET_HashCode *) element->data)); | ||
218 | } | ||
209 | } | 219 | } |
210 | 220 | ||
211 | 221 | ||
@@ -389,6 +399,9 @@ main (int argc, char **argv) | |||
389 | { 't', "timeout", NULL, | 399 | { 't', "timeout", NULL, |
390 | gettext_noop ("consensus timeout"), | 400 | gettext_noop ("consensus timeout"), |
391 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &conclude_timeout }, | 401 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &conclude_timeout }, |
402 | { 'V', "verbose", NULL, | ||
403 | gettext_noop ("be more verbose (print received values)"), | ||
404 | GNUNET_NO, &GNUNET_GETOPT_set_one, &verbose }, | ||
392 | GNUNET_GETOPT_OPTION_END | 405 | GNUNET_GETOPT_OPTION_END |
393 | }; | 406 | }; |
394 | conclude_timeout = GNUNET_TIME_UNIT_SECONDS; | 407 | conclude_timeout = GNUNET_TIME_UNIT_SECONDS; |
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c index 94d532c3d..3e1d1ad95 100644 --- a/src/consensus/gnunet-service-consensus.c +++ b/src/consensus/gnunet-service-consensus.c | |||
@@ -177,11 +177,15 @@ struct ConsensusSession | |||
177 | 177 | ||
178 | /** | 178 | /** |
179 | * Permutation of peers for the current round, | 179 | * Permutation of peers for the current round, |
180 | * maps logical index (for current round) to physical index (location in info array) | ||
181 | */ | 180 | */ |
182 | uint32_t *shuffle; | 181 | uint32_t *shuffle; |
183 | 182 | ||
184 | /** | 183 | /** |
184 | * Inverse permutation of peers for the current round, | ||
185 | */ | ||
186 | uint32_t *shuffle_inv; | ||
187 | |||
188 | /** | ||
185 | * Current round of the exponential scheme. | 189 | * Current round of the exponential scheme. |
186 | */ | 190 | */ |
187 | uint32_t exp_round; | 191 | uint32_t exp_round; |
@@ -331,6 +335,11 @@ destroy_session (struct ConsensusSession *session) | |||
331 | GNUNET_free (session->shuffle); | 335 | GNUNET_free (session->shuffle); |
332 | session->shuffle = NULL; | 336 | session->shuffle = NULL; |
333 | } | 337 | } |
338 | if (NULL != session->shuffle_inv) | ||
339 | { | ||
340 | GNUNET_free (session->shuffle_inv); | ||
341 | session->shuffle_inv = NULL; | ||
342 | } | ||
334 | if (NULL != session->info) | 343 | if (NULL != session->info) |
335 | { | 344 | { |
336 | for (i = 0; i < session->num_peers; i++) | 345 | for (i = 0; i < session->num_peers; i++) |
@@ -448,6 +457,8 @@ shuffle (struct ConsensusSession *session) | |||
448 | 457 | ||
449 | if (NULL == session->shuffle) | 458 | if (NULL == session->shuffle) |
450 | session->shuffle = GNUNET_malloc (session->num_peers * sizeof (*session->shuffle)); | 459 | session->shuffle = GNUNET_malloc (session->num_peers * sizeof (*session->shuffle)); |
460 | if (NULL == session->shuffle_inv) | ||
461 | session->shuffle_inv = GNUNET_malloc (session->num_peers * sizeof (*session->shuffle_inv)); | ||
451 | 462 | ||
452 | GNUNET_CRYPTO_kdf (randomness, sizeof (randomness), | 463 | GNUNET_CRYPTO_kdf (randomness, sizeof (randomness), |
453 | &session->exp_round, sizeof (uint32_t), | 464 | &session->exp_round, sizeof (uint32_t), |
@@ -466,6 +477,10 @@ shuffle (struct ConsensusSession *session) | |||
466 | session->shuffle[x] = session->shuffle[i]; | 477 | session->shuffle[x] = session->shuffle[i]; |
467 | session->shuffle[i] = tmp; | 478 | session->shuffle[i] = tmp; |
468 | } | 479 | } |
480 | |||
481 | /* create the inverse */ | ||
482 | for (i = 0; i < session->num_peers; i++) | ||
483 | session->shuffle_inv[session->shuffle[i]] = i; | ||
469 | } | 484 | } |
470 | 485 | ||
471 | 486 | ||
@@ -501,7 +516,7 @@ find_partners (struct ConsensusSession *session) | |||
501 | { | 516 | { |
502 | /* we are outgoing */ | 517 | /* we are outgoing */ |
503 | partner_idx = (my_idx + arc) % session->num_peers; | 518 | partner_idx = (my_idx + arc) % session->num_peers; |
504 | session->partner_outgoing = &session->info[session->shuffle[partner_idx]]; | 519 | session->partner_outgoing = &session->info[session->shuffle_inv[partner_idx]]; |
505 | session->partner_outgoing->exp_subround_finished = GNUNET_NO; | 520 | session->partner_outgoing->exp_subround_finished = GNUNET_NO; |
506 | /* are we a 'ghost' of a peer that would exist if | 521 | /* are we a 'ghost' of a peer that would exist if |
507 | * the number of peers was a power of two, and thus have to partner | 522 | * the number of peers was a power of two, and thus have to partner |
@@ -519,7 +534,7 @@ find_partners (struct ConsensusSession *session) | |||
519 | if (0 == (ghost_partner_idx & arc)) | 534 | if (0 == (ghost_partner_idx & arc)) |
520 | { | 535 | { |
521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ghost partner is %d\n", ghost_partner_idx); | 536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ghost partner is %d\n", ghost_partner_idx); |
522 | session->partner_incoming = &session->info[session->shuffle[ghost_partner_idx]]; | 537 | session->partner_incoming = &session->info[session->shuffle_inv[ghost_partner_idx]]; |
523 | session->partner_incoming->exp_subround_finished = GNUNET_NO; | 538 | session->partner_incoming->exp_subround_finished = GNUNET_NO; |
524 | return; | 539 | return; |
525 | } | 540 | } |
@@ -532,7 +547,7 @@ find_partners (struct ConsensusSession *session) | |||
532 | if (partner_idx < 0) | 547 | if (partner_idx < 0) |
533 | partner_idx += session->num_peers; | 548 | partner_idx += session->num_peers; |
534 | session->partner_outgoing = NULL; | 549 | session->partner_outgoing = NULL; |
535 | session->partner_incoming = &session->info[session->shuffle[partner_idx]]; | 550 | session->partner_incoming = &session->info[session->shuffle_inv[partner_idx]]; |
536 | session->partner_incoming->exp_subround_finished = GNUNET_NO; | 551 | session->partner_incoming->exp_subround_finished = GNUNET_NO; |
537 | } | 552 | } |
538 | 553 | ||
@@ -674,15 +689,17 @@ subround_over (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
674 | session->exp_subround = 0; | 689 | session->exp_subround = 0; |
675 | if (NULL == session->shuffle) | 690 | if (NULL == session->shuffle) |
676 | session->shuffle = GNUNET_malloc ((sizeof (int)) * session->num_peers); | 691 | session->shuffle = GNUNET_malloc ((sizeof (int)) * session->num_peers); |
692 | if (NULL == session->shuffle_inv) | ||
693 | session->shuffle_inv = GNUNET_malloc ((sizeof (int)) * session->num_peers); | ||
677 | for (i = 0; i < session->num_peers; i++) | 694 | for (i = 0; i < session->num_peers; i++) |
678 | session->shuffle[i] = i; | 695 | session->shuffle[i] = session->shuffle_inv[i] = i; |
679 | } | 696 | } |
680 | else if (session->exp_subround + 1 >= (int) ceil (log2 (session->num_peers))) | 697 | else if (session->exp_subround + 1 >= (int) ceil (log2 (session->num_peers))) |
681 | { | 698 | { |
682 | /* subrounds done, start new log-round */ | 699 | /* subrounds done, start new log-round */ |
683 | session->exp_round++; | 700 | session->exp_round++; |
684 | session->exp_subround = 0; | 701 | session->exp_subround = 0; |
685 | //shuffle (session); | 702 | shuffle (session); |
686 | } | 703 | } |
687 | else | 704 | else |
688 | { | 705 | { |