diff options
author | Julius Bünger <buenger@mytum.de> | 2015-05-19 22:41:42 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-05-19 22:41:42 +0000 |
commit | e8e1d794756b917bfdbe9f6ce163b7898852bf13 (patch) | |
tree | 4e7e72f96093626a860549f3767939045cd6543c /src/rps/test_rps.c | |
parent | 96e5782b634a8026251b240ff3d9c79889f2e6f6 (diff) | |
download | gnunet-e8e1d794756b917bfdbe9f6ce163b7898852bf13.tar.gz gnunet-e8e1d794756b917bfdbe9f6ce163b7898852bf13.zip |
-restructured churn
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r-- | src/rps/test_rps.c | 154 |
1 files changed, 112 insertions, 42 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 3ea8c19af..7d437354a 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -299,17 +299,42 @@ churn_cb (void *cls, | |||
299 | 299 | ||
300 | num_peers_online += entry->delta; | 300 | num_peers_online += entry->delta; |
301 | 301 | ||
302 | if (0 < entry->delta) | 302 | if (0 > entry->delta) |
303 | { /* Peer hopefully just went online */ | ||
304 | GNUNET_break (GNUNET_NO == rps_peers[entry->index].online); | ||
305 | rps_peers[entry->index].online = GNUNET_YES; | ||
306 | } | ||
307 | else if (0 > entry->delta) | ||
308 | { /* Peer hopefully just went offline */ | 303 | { /* Peer hopefully just went offline */ |
309 | GNUNET_break (GNUNET_YES == rps_peers[entry->index].online); | 304 | if (GNUNET_YES != rps_peers[entry->index].online) |
305 | { | ||
306 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
307 | "peer %s was expected to go offline but is still marked as online\n", | ||
308 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
309 | GNUNET_break (0); | ||
310 | } | ||
311 | else | ||
312 | { | ||
313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
314 | "peer %s probably went offline as expected\n", | ||
315 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
316 | } | ||
310 | rps_peers[entry->index].online = GNUNET_NO; | 317 | rps_peers[entry->index].online = GNUNET_NO; |
311 | } | 318 | } |
312 | 319 | ||
320 | else if (0 < entry->delta) | ||
321 | { /* Peer hopefully just went online */ | ||
322 | if (GNUNET_NO != rps_peers[entry->index].online) | ||
323 | { | ||
324 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
325 | "peer %s was expected to go online but is still marked as offline\n", | ||
326 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
327 | GNUNET_break (0); | ||
328 | } | ||
329 | else | ||
330 | { | ||
331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
332 | "peer %s probably went online as expected\n", | ||
333 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
334 | } | ||
335 | rps_peers[entry->index].online = GNUNET_YES; | ||
336 | } | ||
337 | |||
313 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | 338 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); |
314 | GNUNET_free (entry); | 339 | GNUNET_free (entry); |
315 | //if (num_peers_in_round[current_round] == peers_running) | 340 | //if (num_peers_in_round[current_round] == peers_running) |
@@ -676,67 +701,112 @@ churn (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
676 | double portion_go_offline; | 701 | double portion_go_offline; |
677 | uint32_t prob; | 702 | uint32_t prob; |
678 | 703 | ||
679 | portion_online = num_peers_online / NUM_PEERS; | 704 | /* Compute the probability for an online peer to go offline |
705 | * this round */ | ||
706 | portion_online = num_peers_online * 1.0 / num_peers; | ||
707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
708 | "Portion online: %f\n", | ||
709 | portion_online); | ||
680 | portion_go_online = ((1 - portion_online) * .5 * .66); | 710 | portion_go_online = ((1 - portion_online) * .5 * .66); |
711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
712 | "Portion that should go online: %f\n", | ||
713 | portion_go_online); | ||
681 | portion_go_offline = (portion_online + portion_go_online) - .75; | 714 | portion_go_offline = (portion_online + portion_go_online) - .75; |
715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
716 | "Portion that probably goes offline: %f\n", | ||
717 | portion_go_offline); | ||
682 | prob_go_offline = portion_go_offline / (portion_online * .5); | 718 | prob_go_offline = portion_go_offline / (portion_online * .5); |
719 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
720 | "Probability of a selected online peer to go offline: %f\n", | ||
721 | prob_go_offline); | ||
683 | 722 | ||
684 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | 723 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, |
685 | (unsigned int) NUM_PEERS); | 724 | (unsigned int) num_peers); |
686 | 725 | ||
687 | for (i = 0 ; i < .5 * NUM_PEERS ; i++) | 726 | /* Go over 50% randomly chosen peers */ |
727 | for (i = 0 ; i < .5 * num_peers ; i++) | ||
688 | { | 728 | { |
689 | j = permut[i]; | 729 | j = permut[i]; |
690 | 730 | ||
731 | /* If online, shut down with certain probability */ | ||
691 | if (GNUNET_YES == rps_peers[j].online) | 732 | if (GNUNET_YES == rps_peers[j].online) |
692 | { | 733 | { |
693 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
694 | UINT32_MAX); | ||
695 | if (prob < prob_go_offline * UINT32_MAX) | ||
696 | { | ||
697 | entry = make_oplist_entry (); | ||
698 | entry->delta = 1; | ||
699 | entry->index = j; | ||
700 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | ||
701 | testbed_peers[j], | ||
702 | "rps", | ||
703 | &churn_cb, | ||
704 | entry, | ||
705 | 1); | ||
706 | } | ||
707 | } | ||
708 | |||
709 | else if (GNUNET_NO == rps_peers[j].online) | ||
710 | { | ||
711 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 734 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
712 | UINT32_MAX); | 735 | UINT32_MAX); |
713 | if (prob < .66 * UINT32_MAX) | 736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
737 | "%u. selected peer (%u: %s) is online.\n", | ||
738 | i, | ||
739 | j, | ||
740 | GNUNET_i2s (rps_peers[j].peer_id)); | ||
741 | if (prob < prob_go_offline * UINT32_MAX) | ||
714 | { | 742 | { |
743 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
744 | "%s goes offline\n", | ||
745 | GNUNET_i2s (rps_peers[j].peer_id)); | ||
746 | |||
715 | entry = make_oplist_entry (); | 747 | entry = make_oplist_entry (); |
716 | entry->delta = -1; | 748 | entry->delta = -1; |
717 | entry->index = j; | 749 | entry->index = j; |
718 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | 750 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, |
719 | testbed_peers[j], | 751 | testbed_peers[j], |
720 | "rps", | 752 | "rps", |
721 | &churn_cb, | 753 | &churn_cb, |
722 | entry, | 754 | entry, |
723 | 0); | 755 | 0); |
724 | } | 756 | } |
725 | } | 757 | } |
758 | |||
759 | /* If offline, restart with certain probability */ | ||
760 | else if (GNUNET_NO == rps_peers[j].online) | ||
761 | { | ||
762 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
763 | UINT32_MAX); | ||
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
765 | "%u. selected peer (%u: %s) is offline.\n", | ||
766 | i, | ||
767 | j, | ||
768 | GNUNET_i2s (rps_peers[j].peer_id)); | ||
769 | if (prob < .66 * UINT32_MAX) | ||
770 | { | ||
771 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
772 | "%s goes online\n", | ||
773 | GNUNET_i2s (rps_peers[j].peer_id)); | ||
774 | |||
775 | entry = make_oplist_entry (); | ||
776 | entry->delta = 1; | ||
777 | entry->index = j; | ||
778 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | ||
779 | testbed_peers[j], | ||
780 | "rps", | ||
781 | &churn_cb, | ||
782 | entry, | ||
783 | 1); | ||
784 | } | ||
785 | } | ||
726 | } | 786 | } |
727 | 787 | ||
728 | churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 788 | churn_task = GNUNET_SCHEDULER_add_delayed ( |
729 | 10), | 789 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), |
730 | churn, NULL); | 790 | churn, |
791 | NULL); | ||
731 | } | 792 | } |
732 | 793 | ||
794 | |||
733 | static void | 795 | static void |
734 | profiler_pre (void *cls, struct GNUNET_RPS_Handle *h) | 796 | profiler_pre (void *cls, struct GNUNET_RPS_Handle *h) |
735 | { | 797 | { |
736 | churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 798 | //churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
737 | 10), | 799 | // 10), |
738 | churn, NULL); | 800 | // churn, NULL); |
739 | mal_pre (cls, h); | 801 | mal_pre (cls, h); |
802 | |||
803 | if (NULL == churn_task) | ||
804 | { | ||
805 | churn_task = GNUNET_SCHEDULER_add_delayed ( | ||
806 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | ||
807 | churn, | ||
808 | NULL); | ||
809 | } | ||
740 | } | 810 | } |
741 | 811 | ||
742 | static void | 812 | static void |