diff options
author | Julius Bünger <buenger@mytum.de> | 2018-10-01 20:05:40 +0200 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-10-01 23:15:31 +0200 |
commit | 3823c7a71aa1b16df6c34ef3def45875289a6b3d (patch) | |
tree | 14fa9b007663823983fad8194202e8441a4588c0 /src/rps/gnunet-service-rps.c | |
parent | b3aad5bef2e78487251ef7fc766a510f9fc731c9 (diff) | |
download | gnunet-3823c7a71aa1b16df6c34ef3def45875289a6b3d.tar.gz gnunet-3823c7a71aa1b16df6c34ef3def45875289a6b3d.zip |
Restructure implementation of view (towards subsampling)
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 3d9f9234c..5abbc692f 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -386,6 +386,11 @@ struct SubSampler | |||
386 | unsigned int view_size_est_min; | 386 | unsigned int view_size_est_min; |
387 | 387 | ||
388 | /** | 388 | /** |
389 | * @brief The view. | ||
390 | */ | ||
391 | struct View *view; | ||
392 | |||
393 | /** | ||
389 | * Identifier for the main task that runs periodically. | 394 | * Identifier for the main task that runs periodically. |
390 | */ | 395 | */ |
391 | struct GNUNET_SCHEDULER_Task *do_round_task; | 396 | struct GNUNET_SCHEDULER_Task *do_round_task; |
@@ -2092,8 +2097,8 @@ insert_in_view (const struct GNUNET_PeerIdentity *peer) | |||
2092 | } | 2097 | } |
2093 | /* Open channel towards peer to keep connection open */ | 2098 | /* Open channel towards peer to keep connection open */ |
2094 | indicate_sending_intention (peer); | 2099 | indicate_sending_intention (peer); |
2095 | ret = View_put (peer); | 2100 | ret = View_put (mss->view, peer); |
2096 | GNUNET_STATISTICS_set (stats, "view size", View_size(), GNUNET_NO); | 2101 | GNUNET_STATISTICS_set (stats, "view size", View_size(mss->view), GNUNET_NO); |
2097 | return ret; | 2102 | return ret; |
2098 | } | 2103 | } |
2099 | 2104 | ||
@@ -2115,8 +2120,8 @@ send_view (const struct ClientContext *cli_ctx, | |||
2115 | 2120 | ||
2116 | if (NULL == view_array) | 2121 | if (NULL == view_array) |
2117 | { | 2122 | { |
2118 | view_size = View_size (); | 2123 | view_size = View_size (mss->view); |
2119 | view_array = View_get_as_array(); | 2124 | view_array = View_get_as_array(mss->view); |
2120 | } | 2125 | } |
2121 | 2126 | ||
2122 | ev = GNUNET_MQ_msg_extra (out_msg, | 2127 | ev = GNUNET_MQ_msg_extra (out_msg, |
@@ -2172,8 +2177,8 @@ clients_notify_view_update (void) | |||
2172 | uint64_t num_peers; | 2177 | uint64_t num_peers; |
2173 | const struct GNUNET_PeerIdentity *view_array; | 2178 | const struct GNUNET_PeerIdentity *view_array; |
2174 | 2179 | ||
2175 | num_peers = View_size (); | 2180 | num_peers = View_size (mss->view); |
2176 | view_array = View_get_as_array(); | 2181 | view_array = View_get_as_array(mss->view); |
2177 | /* check size of view is small enough */ | 2182 | /* check size of view is small enough */ |
2178 | if (GNUNET_MAX_MESSAGE_SIZE < num_peers) | 2183 | if (GNUNET_MAX_MESSAGE_SIZE < num_peers) |
2179 | { | 2184 | { |
@@ -2485,7 +2490,7 @@ check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer) | |||
2485 | if (GNUNET_YES == check_sending_channel_exists (peer)) | 2490 | if (GNUNET_YES == check_sending_channel_exists (peer)) |
2486 | { | 2491 | { |
2487 | if ( (0 < RPS_sampler_count_id (mss->sampler, peer)) || | 2492 | if ( (0 < RPS_sampler_count_id (mss->sampler, peer)) || |
2488 | (GNUNET_YES == View_contains_peer (peer)) || | 2493 | (GNUNET_YES == View_contains_peer (mss->view, peer)) || |
2489 | (GNUNET_YES == CustomPeerMap_contains_peer (mss->push_map, peer)) || | 2494 | (GNUNET_YES == CustomPeerMap_contains_peer (mss->push_map, peer)) || |
2490 | (GNUNET_YES == CustomPeerMap_contains_peer (mss->pull_map, peer)) || | 2495 | (GNUNET_YES == CustomPeerMap_contains_peer (mss->pull_map, peer)) || |
2491 | (GNUNET_YES == check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) | 2496 | (GNUNET_YES == check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) |
@@ -2506,7 +2511,7 @@ check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer) | |||
2506 | static void | 2511 | static void |
2507 | remove_peer (const struct GNUNET_PeerIdentity *peer) | 2512 | remove_peer (const struct GNUNET_PeerIdentity *peer) |
2508 | { | 2513 | { |
2509 | (void) View_remove_peer (peer); | 2514 | (void) View_remove_peer (mss->view, peer); |
2510 | CustomPeerMap_remove_peer (mss->pull_map, peer); | 2515 | CustomPeerMap_remove_peer (mss->pull_map, peer); |
2511 | CustomPeerMap_remove_peer (mss->push_map, peer); | 2516 | CustomPeerMap_remove_peer (mss->push_map, peer); |
2512 | RPS_sampler_reinitialise_by_value (mss->sampler, peer); | 2517 | RPS_sampler_reinitialise_by_value (mss->sampler, peer); |
@@ -2538,7 +2543,7 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
2538 | } | 2543 | } |
2539 | 2544 | ||
2540 | if ( (GNUNET_NO == check_peer_send_intention (peer)) && | 2545 | if ( (GNUNET_NO == check_peer_send_intention (peer)) && |
2541 | (GNUNET_NO == View_contains_peer (peer)) && | 2546 | (GNUNET_NO == View_contains_peer (mss->view, peer)) && |
2542 | (GNUNET_NO == CustomPeerMap_contains_peer (mss->push_map, peer)) && | 2547 | (GNUNET_NO == CustomPeerMap_contains_peer (mss->push_map, peer)) && |
2543 | (GNUNET_NO == CustomPeerMap_contains_peer (mss->push_map, peer)) && | 2548 | (GNUNET_NO == CustomPeerMap_contains_peer (mss->push_map, peer)) && |
2544 | (0 == RPS_sampler_count_id (mss->sampler, peer)) && | 2549 | (0 == RPS_sampler_count_id (mss->sampler, peer)) && |
@@ -2682,7 +2687,7 @@ new_subsampler (const char *shared_value, | |||
2682 | ss->push_map = CustomPeerMap_create (4); | 2687 | ss->push_map = CustomPeerMap_create (4); |
2683 | ss->pull_map = CustomPeerMap_create (4); | 2688 | ss->pull_map = CustomPeerMap_create (4); |
2684 | ss->view_size_est_min = sampler_size;; | 2689 | ss->view_size_est_min = sampler_size;; |
2685 | View_create (ss->view_size_est_min); | 2690 | ss->view = View_create (ss->view_size_est_min); |
2686 | GNUNET_STATISTICS_set (stats, | 2691 | GNUNET_STATISTICS_set (stats, |
2687 | "view size aim", | 2692 | "view size aim", |
2688 | ss->view_size_est_min, | 2693 | ss->view_size_est_min, |
@@ -2748,7 +2753,7 @@ nse_callback (void *cls, | |||
2748 | 2753 | ||
2749 | /* If the NSE has changed adapt the lists accordingly */ | 2754 | /* If the NSE has changed adapt the lists accordingly */ |
2750 | resize_wrapper (mss->sampler, mss->sampler_size_est_need); | 2755 | resize_wrapper (mss->sampler, mss->sampler_size_est_need); |
2751 | View_change_len (mss->view_size_est_need); | 2756 | View_change_len (mss->view, mss->view_size_est_need); |
2752 | } | 2757 | } |
2753 | 2758 | ||
2754 | 2759 | ||
@@ -3043,8 +3048,8 @@ handle_peer_pull_request (void *cls, | |||
3043 | 3048 | ||
3044 | GNUNET_break_op (check_peer_known (peer)); | 3049 | GNUNET_break_op (check_peer_known (peer)); |
3045 | GNUNET_CADET_receive_done (channel_ctx->channel); | 3050 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3046 | view_array = View_get_as_array (); | 3051 | view_array = View_get_as_array (mss->view); |
3047 | send_pull_reply (peer, view_array, View_size ()); | 3052 | send_pull_reply (peer, view_array, View_size (mss->view)); |
3048 | } | 3053 | } |
3049 | 3054 | ||
3050 | 3055 | ||
@@ -3579,8 +3584,8 @@ do_round (void *cls) | |||
3579 | "Printing view:\n"); | 3584 | "Printing view:\n"); |
3580 | to_file (mss->file_name_view_log, | 3585 | to_file (mss->file_name_view_log, |
3581 | "___ new round ___"); | 3586 | "___ new round ___"); |
3582 | view_array = View_get_as_array (); | 3587 | view_array = View_get_as_array (mss->view); |
3583 | for (i = 0; i < View_size (); i++) | 3588 | for (i = 0; i < View_size (mss->view); i++) |
3584 | { | 3589 | { |
3585 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3590 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3586 | "\t%s\n", GNUNET_i2s (&view_array[i])); | 3591 | "\t%s\n", GNUNET_i2s (&view_array[i])); |
@@ -3591,17 +3596,17 @@ do_round (void *cls) | |||
3591 | 3596 | ||
3592 | 3597 | ||
3593 | /* Send pushes and pull requests */ | 3598 | /* Send pushes and pull requests */ |
3594 | if (0 < View_size ()) | 3599 | if (0 < View_size (mss->view)) |
3595 | { | 3600 | { |
3596 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, | 3601 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, |
3597 | View_size ()); | 3602 | View_size (mss->view)); |
3598 | 3603 | ||
3599 | /* Send PUSHes */ | 3604 | /* Send PUSHes */ |
3600 | a_peers = ceil (alpha * View_size ()); | 3605 | a_peers = ceil (alpha * View_size (mss->view)); |
3601 | 3606 | ||
3602 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3607 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3603 | "Going to send pushes to %u (ceil (%f * %u)) peers.\n", | 3608 | "Going to send pushes to %u (ceil (%f * %u)) peers.\n", |
3604 | a_peers, alpha, View_size ()); | 3609 | a_peers, alpha, View_size (mss->view)); |
3605 | for (i = 0; i < a_peers; i++) | 3610 | for (i = 0; i < a_peers; i++) |
3606 | { | 3611 | { |
3607 | peer = view_array[permut[i]]; | 3612 | peer = view_array[permut[i]]; |
@@ -3610,17 +3615,17 @@ do_round (void *cls) | |||
3610 | } | 3615 | } |
3611 | 3616 | ||
3612 | /* Send PULL requests */ | 3617 | /* Send PULL requests */ |
3613 | b_peers = ceil (beta * View_size ()); | 3618 | b_peers = ceil (beta * View_size (mss->view)); |
3614 | first_border = a_peers; | 3619 | first_border = a_peers; |
3615 | second_border = a_peers + b_peers; | 3620 | second_border = a_peers + b_peers; |
3616 | if (second_border > View_size ()) | 3621 | if (second_border > View_size (mss->view)) |
3617 | { | 3622 | { |
3618 | first_border = View_size () - b_peers; | 3623 | first_border = View_size (mss->view) - b_peers; |
3619 | second_border = View_size (); | 3624 | second_border = View_size (mss->view); |
3620 | } | 3625 | } |
3621 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3626 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3622 | "Going to send pulls to %u (ceil (%f * %u)) peers.\n", | 3627 | "Going to send pulls to %u (ceil (%f * %u)) peers.\n", |
3623 | b_peers, beta, View_size ()); | 3628 | b_peers, beta, View_size (mss->view)); |
3624 | for (i = first_border; i < second_border; i++) | 3629 | for (i = first_border; i < second_border; i++) |
3625 | { | 3630 | { |
3626 | peer = view_array[permut[i]]; | 3631 | peer = view_array[permut[i]]; |
@@ -3651,13 +3656,15 @@ do_round (void *cls) | |||
3651 | 3656 | ||
3652 | peers_to_clean = NULL; | 3657 | peers_to_clean = NULL; |
3653 | peers_to_clean_size = 0; | 3658 | peers_to_clean_size = 0; |
3654 | GNUNET_array_grow (peers_to_clean, peers_to_clean_size, View_size ()); | 3659 | GNUNET_array_grow (peers_to_clean, |
3660 | peers_to_clean_size, | ||
3661 | View_size (mss->view)); | ||
3655 | GNUNET_memcpy (peers_to_clean, | 3662 | GNUNET_memcpy (peers_to_clean, |
3656 | view_array, | 3663 | view_array, |
3657 | View_size () * sizeof (struct GNUNET_PeerIdentity)); | 3664 | View_size (mss->view) * sizeof (struct GNUNET_PeerIdentity)); |
3658 | 3665 | ||
3659 | /* Seems like recreating is the easiest way of emptying the peermap */ | 3666 | /* Seems like recreating is the easiest way of emptying the peermap */ |
3660 | View_clear (); | 3667 | View_clear (mss->view); |
3661 | to_file (mss->file_name_view_log, | 3668 | to_file (mss->file_name_view_log, |
3662 | "--- emptied ---"); | 3669 | "--- emptied ---"); |
3663 | 3670 | ||
@@ -3724,7 +3731,7 @@ do_round (void *cls) | |||
3724 | NULL); | 3731 | NULL); |
3725 | // TODO change the peer_flags accordingly | 3732 | // TODO change the peer_flags accordingly |
3726 | 3733 | ||
3727 | for (i = 0; i < View_size (); i++) | 3734 | for (i = 0; i < View_size (mss->view); i++) |
3728 | rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]); | 3735 | rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]); |
3729 | 3736 | ||
3730 | /* Clean peers that were removed from the view */ | 3737 | /* Clean peers that were removed from the view */ |
@@ -3741,10 +3748,10 @@ do_round (void *cls) | |||
3741 | } else { | 3748 | } else { |
3742 | LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); | 3749 | LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); |
3743 | GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO); | 3750 | GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO); |
3744 | if (CustomPeerMap_size (mss->push_map) > alpha * View_size () && | 3751 | if (CustomPeerMap_size (mss->push_map) > alpha * View_size (mss->view) && |
3745 | !(0 >= CustomPeerMap_size (mss->pull_map))) | 3752 | !(0 >= CustomPeerMap_size (mss->pull_map))) |
3746 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO); | 3753 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO); |
3747 | if (CustomPeerMap_size (mss->push_map) > alpha * View_size () && | 3754 | if (CustomPeerMap_size (mss->push_map) > alpha * View_size (mss->view) && |
3748 | (0 >= CustomPeerMap_size (mss->pull_map))) | 3755 | (0 >= CustomPeerMap_size (mss->pull_map))) |
3749 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO); | 3756 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO); |
3750 | if (0 >= CustomPeerMap_size (mss->push_map) && | 3757 | if (0 >= CustomPeerMap_size (mss->push_map) && |
@@ -3754,7 +3761,7 @@ do_round (void *cls) | |||
3754 | (0 >= CustomPeerMap_size (mss->pull_map))) | 3761 | (0 >= CustomPeerMap_size (mss->pull_map))) |
3755 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO); | 3762 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO); |
3756 | if (0 >= CustomPeerMap_size (mss->pull_map) && | 3763 | if (0 >= CustomPeerMap_size (mss->pull_map) && |
3757 | CustomPeerMap_size (mss->push_map) > alpha * View_size () && | 3764 | CustomPeerMap_size (mss->push_map) > alpha * View_size (mss->view) && |
3758 | 0 >= CustomPeerMap_size (mss->push_map)) | 3765 | 0 >= CustomPeerMap_size (mss->push_map)) |
3759 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO); | 3766 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO); |
3760 | } | 3767 | } |
@@ -3769,16 +3776,16 @@ do_round (void *cls) | |||
3769 | GNUNET_NO); | 3776 | GNUNET_NO); |
3770 | GNUNET_STATISTICS_set (stats, | 3777 | GNUNET_STATISTICS_set (stats, |
3771 | "# peers in view at end of round", | 3778 | "# peers in view at end of round", |
3772 | View_size (), | 3779 | View_size (mss->view), |
3773 | GNUNET_NO); | 3780 | GNUNET_NO); |
3774 | 3781 | ||
3775 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3782 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3776 | "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (%u) = %.2f)\n", | 3783 | "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (mss->view%u) = %.2f)\n", |
3777 | CustomPeerMap_size (mss->push_map), | 3784 | CustomPeerMap_size (mss->push_map), |
3778 | CustomPeerMap_size (mss->pull_map), | 3785 | CustomPeerMap_size (mss->pull_map), |
3779 | alpha, | 3786 | alpha, |
3780 | View_size (), | 3787 | View_size (mss->view), |
3781 | alpha * View_size ()); | 3788 | alpha * View_size (mss->view)); |
3782 | 3789 | ||
3783 | /* Update samplers */ | 3790 | /* Update samplers */ |
3784 | for (i = 0; i < CustomPeerMap_size (mss->push_map); i++) | 3791 | for (i = 0; i < CustomPeerMap_size (mss->push_map); i++) |
@@ -3808,7 +3815,7 @@ do_round (void *cls) | |||
3808 | 3815 | ||
3809 | GNUNET_STATISTICS_set (stats, | 3816 | GNUNET_STATISTICS_set (stats, |
3810 | "view size", | 3817 | "view size", |
3811 | View_size(), | 3818 | View_size(mss->view), |
3812 | GNUNET_NO); | 3819 | GNUNET_NO); |
3813 | 3820 | ||
3814 | struct GNUNET_TIME_Relative time_next_round; | 3821 | struct GNUNET_TIME_Relative time_next_round; |
@@ -3943,7 +3950,7 @@ shutdown_task (void *cls) | |||
3943 | GNUNET_CADET_close_port (mss->cadet_port); | 3950 | GNUNET_CADET_close_port (mss->cadet_port); |
3944 | GNUNET_CADET_disconnect (mss->cadet_handle); | 3951 | GNUNET_CADET_disconnect (mss->cadet_handle); |
3945 | mss->cadet_handle = NULL; | 3952 | mss->cadet_handle = NULL; |
3946 | View_destroy (); | 3953 | View_destroy (mss->view); |
3947 | CustomPeerMap_destroy (mss->push_map); | 3954 | CustomPeerMap_destroy (mss->push_map); |
3948 | CustomPeerMap_destroy (mss->pull_map); | 3955 | CustomPeerMap_destroy (mss->pull_map); |
3949 | if (NULL != stats) | 3956 | if (NULL != stats) |